root/drivers/staging/vt6656/wcmd.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. vnt_cmd_timer_wait
  2. vnt_cmd_complete
  3. vnt_run_command
  4. vnt_schedule_command
  5. vnt_reset_command_timer

   1 // SPDX-License-Identifier: GPL-2.0+
   2 /*
   3  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
   4  * All rights reserved.
   5  *
   6  * File: wcmd.c
   7  *
   8  * Purpose: Handles the management command interface functions
   9  *
  10  * Author: Lyndon Chen
  11  *
  12  * Date: May 8, 2003
  13  *
  14  * Functions:
  15  *      vnt_cmd_complete - Command Complete function
  16  *      vnt_schedule_command - Push Command and wait Command Scheduler to do
  17  *      vnt_cmd_timer_wait- Call back timer
  18  *
  19  * Revision History:
  20  *
  21  */
  22 
  23 #include "device.h"
  24 #include "mac.h"
  25 #include "wcmd.h"
  26 #include "power.h"
  27 #include "usbpipe.h"
  28 #include "rxtx.h"
  29 #include "rf.h"
  30 
  31 static void vnt_cmd_timer_wait(struct vnt_private *priv, unsigned long msecs)
  32 {
  33         schedule_delayed_work(&priv->run_command_work, msecs_to_jiffies(msecs));
  34 }
  35 
  36 static int vnt_cmd_complete(struct vnt_private *priv)
  37 {
  38         priv->command_state = WLAN_CMD_IDLE;
  39         if (priv->free_cmd_queue == CMD_Q_SIZE) {
  40                 /* Command Queue Empty */
  41                 priv->cmd_running = false;
  42                 return true;
  43         }
  44 
  45         priv->command = priv->cmd_queue[priv->cmd_dequeue_idx];
  46 
  47         ADD_ONE_WITH_WRAP_AROUND(priv->cmd_dequeue_idx, CMD_Q_SIZE);
  48         priv->free_cmd_queue++;
  49         priv->cmd_running = true;
  50 
  51         switch (priv->command) {
  52         case WLAN_CMD_INIT_MAC80211:
  53                 priv->command_state = WLAN_CMD_INIT_MAC80211_START;
  54                 break;
  55 
  56         case WLAN_CMD_TBTT_WAKEUP:
  57                 priv->command_state = WLAN_CMD_TBTT_WAKEUP_START;
  58                 break;
  59 
  60         case WLAN_CMD_BECON_SEND:
  61                 priv->command_state = WLAN_CMD_BECON_SEND_START;
  62                 break;
  63 
  64         case WLAN_CMD_SETPOWER:
  65                 priv->command_state = WLAN_CMD_SETPOWER_START;
  66                 break;
  67 
  68         case WLAN_CMD_CHANGE_ANTENNA:
  69                 priv->command_state = WLAN_CMD_CHANGE_ANTENNA_START;
  70                 break;
  71 
  72         default:
  73                 break;
  74         }
  75 
  76         vnt_cmd_timer_wait(priv, 0);
  77 
  78         return true;
  79 }
  80 
  81 void vnt_run_command(struct work_struct *work)
  82 {
  83         struct vnt_private *priv =
  84                 container_of(work, struct vnt_private, run_command_work.work);
  85 
  86         if (test_bit(DEVICE_FLAGS_DISCONNECTED, &priv->flags))
  87                 return;
  88 
  89         if (!priv->cmd_running)
  90                 return;
  91 
  92         switch (priv->command_state) {
  93         case WLAN_CMD_INIT_MAC80211_START:
  94                 if (priv->mac_hw)
  95                         break;
  96 
  97                 dev_info(&priv->usb->dev, "Starting mac80211\n");
  98 
  99                 if (vnt_init(priv)) {
 100                         /* If fail all ends TODO retry */
 101                         dev_err(&priv->usb->dev, "failed to start\n");
 102                         usb_set_intfdata(priv->intf, NULL);
 103                         ieee80211_free_hw(priv->hw);
 104                         return;
 105                 }
 106 
 107                 break;
 108 
 109         case WLAN_CMD_TBTT_WAKEUP_START:
 110                 vnt_next_tbtt_wakeup(priv);
 111                 break;
 112 
 113         case WLAN_CMD_BECON_SEND_START:
 114                 if (!priv->vif)
 115                         break;
 116 
 117                 vnt_beacon_make(priv, priv->vif);
 118 
 119                 vnt_mac_reg_bits_on(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
 120 
 121                 break;
 122 
 123         case WLAN_CMD_SETPOWER_START:
 124 
 125                 vnt_rf_setpower(priv, priv->current_rate,
 126                                 priv->hw->conf.chandef.chan->hw_value);
 127 
 128                 break;
 129 
 130         case WLAN_CMD_CHANGE_ANTENNA_START:
 131                 dev_dbg(&priv->usb->dev, "Change from Antenna%d to",
 132                         priv->rx_antenna_sel);
 133 
 134                 if (priv->rx_antenna_sel == 0) {
 135                         priv->rx_antenna_sel = 1;
 136                         if (priv->tx_rx_ant_inv)
 137                                 vnt_set_antenna_mode(priv, ANT_RXA);
 138                         else
 139                                 vnt_set_antenna_mode(priv, ANT_RXB);
 140                 } else {
 141                         priv->rx_antenna_sel = 0;
 142                         if (priv->tx_rx_ant_inv)
 143                                 vnt_set_antenna_mode(priv, ANT_RXB);
 144                         else
 145                                 vnt_set_antenna_mode(priv, ANT_RXA);
 146                 }
 147                 break;
 148 
 149         default:
 150                 break;
 151         }
 152 
 153         vnt_cmd_complete(priv);
 154 }
 155 
 156 int vnt_schedule_command(struct vnt_private *priv, enum vnt_cmd command)
 157 {
 158         if (priv->free_cmd_queue == 0)
 159                 return false;
 160 
 161         priv->cmd_queue[priv->cmd_enqueue_idx] = command;
 162 
 163         ADD_ONE_WITH_WRAP_AROUND(priv->cmd_enqueue_idx, CMD_Q_SIZE);
 164         priv->free_cmd_queue--;
 165 
 166         if (!priv->cmd_running)
 167                 vnt_cmd_complete(priv);
 168 
 169         return true;
 170 }
 171 
 172 void vnt_reset_command_timer(struct vnt_private *priv)
 173 {
 174         priv->free_cmd_queue = CMD_Q_SIZE;
 175         priv->cmd_dequeue_idx = 0;
 176         priv->cmd_enqueue_idx = 0;
 177         priv->command_state = WLAN_CMD_IDLE;
 178         priv->cmd_running = false;
 179 }

/* [<][>][^][v][top][bottom][index][help] */