staging: vt6656: wcmd Remove command WLAN_CMD_RADIO
[cascardo/linux.git] / drivers / staging / vt6656 / wcmd.c
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * File: wcmd.c
20  *
21  * Purpose: Handles the management command interface functions
22  *
23  * Author: Lyndon Chen
24  *
25  * Date: May 8, 2003
26  *
27  * Functions:
28  *      s_vProbeChannel - Active scan channel
29  *      s_MgrMakeProbeRequest - Make ProbeRequest packet
30  *      CommandTimer - Timer function to handle command
31  *      s_bCommandComplete - Command Complete function
32  *      bScheduleCommand - Push Command and wait Command Scheduler to do
33  *      vCommandTimer- Command call back functions
34  *      vCommandTimerWait- Call back timer
35  *      s_bClearBSSID_SCAN- Clear BSSID_SCAN cmd in CMD Queue
36  *
37  * Revision History:
38  *
39  */
40
41 #include "device.h"
42 #include "mac.h"
43 #include "card.h"
44 #include "wcmd.h"
45 #include "power.h"
46 #include "baseband.h"
47 #include "usbpipe.h"
48 #include "rxtx.h"
49 #include "rf.h"
50 #include "channel.h"
51
52 static int msglevel = MSG_LEVEL_INFO;
53 //static int msglevel = MSG_LEVEL_DEBUG;
54
55 static int s_bCommandComplete(struct vnt_private *);
56
57 static void vCommandTimerWait(struct vnt_private *priv, unsigned long msecs)
58 {
59         schedule_delayed_work(&priv->run_command_work, msecs_to_jiffies(msecs));
60 }
61
62 void vRunCommand(struct work_struct *work)
63 {
64         struct vnt_private *pDevice =
65                 container_of(work, struct vnt_private, run_command_work.work);
66         u8 byData;
67
68         if (pDevice->Flags & fMP_DISCONNECTED)
69                 return;
70
71         if (pDevice->bCmdRunning != true)
72                 return;
73
74         switch (pDevice->eCommandState) {
75         case WLAN_CMD_INIT_MAC80211_START:
76                 if (pDevice->mac_hw)
77                         break;
78
79                 dev_info(&pDevice->usb->dev, "Starting mac80211\n");
80
81                 if (vnt_init(pDevice)) {
82                         /* If fail all ends TODO retry */
83                         dev_err(&pDevice->usb->dev, "failed to start\n");
84                         ieee80211_free_hw(pDevice->hw);
85                         return;
86                 }
87
88                 break;
89
90         case WLAN_CMD_CHANGE_BBSENSITIVITY_START:
91
92                 pDevice->bStopDataPkt = true;
93                 pDevice->byBBVGACurrent = pDevice->byBBVGANew;
94                 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGACurrent);
95                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change sensitivity pDevice->byBBVGACurrent = %x\n", pDevice->byBBVGACurrent);
96                 pDevice->bStopDataPkt = false;
97                 break;
98
99         case WLAN_CMD_TBTT_WAKEUP_START:
100                 vnt_next_tbtt_wakeup(pDevice);
101                 break;
102
103         case WLAN_CMD_BECON_SEND_START:
104                 if (!pDevice->vif)
105                         break;
106
107                 vnt_beacon_make(pDevice, pDevice->vif);
108
109                 vnt_mac_reg_bits_on(pDevice, MAC_REG_TCR, TCR_AUTOBCNTX);
110
111                 break;
112
113         case WLAN_CMD_SETPOWER_START:
114
115                 vnt_rf_setpower(pDevice, pDevice->wCurrentRate,
116                                 pDevice->hw->conf.chandef.chan->hw_value);
117
118                 break;
119
120         case WLAN_CMD_CHANGE_ANTENNA_START:
121                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Change from Antenna%d to", (int)pDevice->dwRxAntennaSel);
122                 if (pDevice->dwRxAntennaSel == 0) {
123                         pDevice->dwRxAntennaSel = 1;
124                         if (pDevice->bTxRxAntInv == true)
125                                 BBvSetAntennaMode(pDevice, ANT_RXA);
126                         else
127                                 BBvSetAntennaMode(pDevice, ANT_RXB);
128                 } else {
129                         pDevice->dwRxAntennaSel = 0;
130                         if (pDevice->bTxRxAntInv == true)
131                                 BBvSetAntennaMode(pDevice, ANT_RXB);
132                         else
133                                 BBvSetAntennaMode(pDevice, ANT_RXA);
134                 }
135                 break;
136
137         case WLAN_CMD_MAC_DISPOWERSAVING_START:
138                 vnt_control_in_u8(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_PSCTL, &byData);
139                 if ((byData & PSCTL_PS) != 0) {
140                         // disable power saving hw function
141                         vnt_control_out(pDevice,
142                                         MESSAGE_TYPE_DISABLE_PS,
143                                         0,
144                                         0,
145                                         0,
146                                         NULL
147                                         );
148                 }
149                 break;
150
151         case WLAN_CMD_11H_CHSW_START:
152                 vnt_set_channel(pDevice, pDevice->hw->conf.chandef.chan->hw_value);
153                 break;
154
155         case WLAN_CMD_CONFIGURE_FILTER_START:
156                 break;
157         default:
158                 break;
159         } //switch
160
161         s_bCommandComplete(pDevice);
162
163         return;
164 }
165
166 static int s_bCommandComplete(struct vnt_private *pDevice)
167 {
168         int bRadioCmd = false;
169         int bForceSCAN = true;
170
171         pDevice->eCommandState = WLAN_CMD_IDLE;
172         if (pDevice->cbFreeCmdQueue == CMD_Q_SIZE) {
173                 //Command Queue Empty
174                 pDevice->bCmdRunning = false;
175                 return true;
176         } else {
177                 pDevice->eCommand = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].eCmd;
178                 bRadioCmd = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bRadioCmd;
179                 bForceSCAN = pDevice->eCmdQueue[pDevice->uCmdDequeueIdx].bForceSCAN;
180                 ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdDequeueIdx, CMD_Q_SIZE);
181                 pDevice->cbFreeCmdQueue++;
182                 pDevice->bCmdRunning = true;
183                 switch (pDevice->eCommand) {
184                 case WLAN_CMD_INIT_MAC80211:
185                         pDevice->eCommandState = WLAN_CMD_INIT_MAC80211_START;
186                         break;
187
188                 case WLAN_CMD_CHANGE_BBSENSITIVITY:
189                         pDevice->eCommandState = WLAN_CMD_CHANGE_BBSENSITIVITY_START;
190                         break;
191
192                 case WLAN_CMD_TBTT_WAKEUP:
193                         pDevice->eCommandState = WLAN_CMD_TBTT_WAKEUP_START;
194                         break;
195
196                 case WLAN_CMD_BECON_SEND:
197                         pDevice->eCommandState = WLAN_CMD_BECON_SEND_START;
198                         break;
199
200                 case WLAN_CMD_SETPOWER:
201                         pDevice->eCommandState = WLAN_CMD_SETPOWER_START;
202                         break;
203
204                 case WLAN_CMD_CHANGE_ANTENNA:
205                         pDevice->eCommandState = WLAN_CMD_CHANGE_ANTENNA_START;
206                         break;
207
208                 case WLAN_CMD_MAC_DISPOWERSAVING:
209                         pDevice->eCommandState = WLAN_CMD_MAC_DISPOWERSAVING_START;
210                         break;
211
212                 case WLAN_CMD_11H_CHSW:
213                         pDevice->eCommandState = WLAN_CMD_11H_CHSW_START;
214                         break;
215
216                 default:
217                         break;
218                 }
219                 vCommandTimerWait(pDevice, 0);
220         }
221
222         return true;
223 }
224
225 int bScheduleCommand(struct vnt_private *pDevice,
226                 CMD_CODE eCommand, u8 *pbyItem0)
227 {
228
229         if (pDevice->cbFreeCmdQueue == 0)
230                 return false;
231         pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].eCmd = eCommand;
232         pDevice->eCmdQueue[pDevice->uCmdEnqueueIdx].bForceSCAN = true;
233
234         ADD_ONE_WITH_WRAP_AROUND(pDevice->uCmdEnqueueIdx, CMD_Q_SIZE);
235         pDevice->cbFreeCmdQueue--;
236
237         if (pDevice->bCmdRunning == false)
238                 s_bCommandComplete(pDevice);
239
240         return true;
241
242 }
243
244 void vResetCommandTimer(struct vnt_private *pDevice)
245 {
246         pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
247         pDevice->uCmdDequeueIdx = 0;
248         pDevice->uCmdEnqueueIdx = 0;
249         pDevice->eCommandState = WLAN_CMD_IDLE;
250         pDevice->bCmdRunning = false;
251         pDevice->bCmdClear = false;
252 }