staging: vt6656: device.h convert sTimerCommand to delayed_work
[deliverable/linux.git] / drivers / staging / vt6656 / main_usb.c
CommitLineData
92b96797
FB
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: main_usb.c
20 *
21 * Purpose: driver entry for initial, open, close, tx and rx.
22 *
23 * Author: Lyndon Chen
24 *
25 * Date: Dec 8, 2005
26 *
27 * Functions:
28 *
26e5b65b 29 * vt6656_probe - module initial (insmod) driver entry
92b96797
FB
30 * device_remove1 - module remove entry
31 * device_open - allocate dma/descripter resource & initial mac/bbp function
a0a1f61a 32 * device_xmit - asynchronous data tx function
92b96797
FB
33 * device_set_multi - set mac filter
34 * device_ioctl - ioctl entry
a0a1f61a 35 * device_close - shutdown mac/bbp & free dma/descriptor resource
92b96797
FB
36 * device_alloc_frag_buf - rx fragement pre-allocated function
37 * device_free_tx_bufs - free tx buffer function
38 * device_dma0_tx_80211- tx 802.11 frame via dma0
a0a1f61a 39 * device_dma0_xmit- tx PS buffered frame via dma0
92b96797
FB
40 * device_init_registers- initial MAC & BBP & RF internal registers.
41 * device_init_rings- initial tx/rx ring buffer
42 * device_init_defrag_cb- initial & allocate de-fragement buffer.
43 * device_tx_srv- tx interrupt service function
44 *
45 * Revision History:
46 */
47#undef __NO_VERSION__
48
7c51d177 49#include <linux/file.h>
92b96797 50#include "device.h"
92b96797 51#include "card.h"
92b96797 52#include "baseband.h"
92b96797 53#include "mac.h"
92b96797 54#include "tether.h"
92b96797 55#include "wmgr.h"
92b96797 56#include "wctl.h"
92b96797 57#include "power.h"
92b96797 58#include "wcmd.h"
92b96797 59#include "iocmd.h"
92b96797 60#include "tcrc.h"
92b96797 61#include "rxtx.h"
92b96797 62#include "bssdb.h"
92b96797 63#include "hostap.h"
92b96797 64#include "wpactl.h"
92b96797 65#include "iwctl.h"
92b96797 66#include "dpc.h"
92b96797 67#include "datarate.h"
92b96797 68#include "rf.h"
92b96797 69#include "firmware.h"
92b96797 70#include "rndis.h"
92b96797 71#include "control.h"
92b96797 72#include "channel.h"
92b96797 73#include "int.h"
92b96797 74#include "iowpa.h"
92b96797 75
ec6e0f63 76/* static int msglevel = MSG_LEVEL_DEBUG; */
92b96797
FB
77static int msglevel =MSG_LEVEL_INFO;
78
ec6e0f63
AM
79/*
80 * define module options
81 */
92b96797 82
ec6e0f63
AM
83/* version information */
84#define DRIVER_AUTHOR \
85 "VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>"
92b96797
FB
86MODULE_AUTHOR(DRIVER_AUTHOR);
87MODULE_LICENSE("GPL");
88MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
89
92b96797
FB
90#define DEVICE_PARAM(N,D) \
91 static int N[MAX_UINTS]=OPTION_DEFAULT;\
92 module_param_array(N, int, NULL, 0);\
93 MODULE_PARM_DESC(N, D);
94
92b96797
FB
95#define RX_DESC_DEF0 64
96DEVICE_PARAM(RxDescriptors0,"Number of receive usb desc buffer");
97
92b96797
FB
98#define TX_DESC_DEF0 64
99DEVICE_PARAM(TxDescriptors0,"Number of transmit usb desc buffer");
100
92b96797 101#define CHANNEL_DEF 6
92b96797
FB
102DEVICE_PARAM(Channel, "Channel number");
103
92b96797
FB
104/* PreambleType[] is the preamble length used for transmit.
105 0: indicate allows long preamble type
106 1: indicate allows short preamble type
107*/
108
109#define PREAMBLE_TYPE_DEF 1
110
111DEVICE_PARAM(PreambleType, "Preamble Type");
112
92b96797 113#define RTS_THRESH_DEF 2347
92b96797
FB
114DEVICE_PARAM(RTSThreshold, "RTS threshold");
115
92b96797 116#define FRAG_THRESH_DEF 2346
92b96797
FB
117DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
118
92b96797
FB
119#define DATA_RATE_DEF 13
120/* datarate[] index
121 0: indicate 1 Mbps 0x02
122 1: indicate 2 Mbps 0x04
123 2: indicate 5.5 Mbps 0x0B
124 3: indicate 11 Mbps 0x16
125 4: indicate 6 Mbps 0x0c
126 5: indicate 9 Mbps 0x12
127 6: indicate 12 Mbps 0x18
128 7: indicate 18 Mbps 0x24
129 8: indicate 24 Mbps 0x30
130 9: indicate 36 Mbps 0x48
131 10: indicate 48 Mbps 0x60
132 11: indicate 54 Mbps 0x6c
133 12: indicate 72 Mbps 0x90
134 13: indicate auto rate
135*/
136
137DEVICE_PARAM(ConnectionRate, "Connection data rate");
138
92b96797 139#define OP_MODE_DEF 0
92b96797
FB
140DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
141
142/* OpMode[] is used for transmit.
143 0: indicate infrastruct mode used
144 1: indicate adhoc mode used
145 2: indicate AP mode used
146*/
147
92b96797
FB
148/* PSMode[]
149 0: indicate disable power saving mode
150 1: indicate enable power saving mode
151*/
152
153#define PS_MODE_DEF 0
92b96797
FB
154DEVICE_PARAM(PSMode, "Power saving mode");
155
92b96797 156#define SHORT_RETRY_DEF 8
92b96797
FB
157DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
158
92b96797 159#define LONG_RETRY_DEF 4
92b96797
FB
160DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
161
92b96797
FB
162/* BasebandType[] baseband type selected
163 0: indicate 802.11a type
164 1: indicate 802.11b type
165 2: indicate 802.11g type
166*/
92b96797 167
24b46f9e 168#define BBP_TYPE_DEF 2
92b96797
FB
169DEVICE_PARAM(BasebandType, "baseband type");
170
92b96797
FB
171/* 80211hEnable[]
172 0: indicate disable 802.11h
173 1: indicate enable 802.11h
174*/
175
176#define X80211h_MODE_DEF 0
177
178DEVICE_PARAM(b80211hEnable, "802.11h mode");
179
ec6e0f63
AM
180/*
181 * Static vars definitions
182 */
92b96797 183
4d088876 184static struct usb_device_id vt6656_table[] = {
92b96797
FB
185 {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
186 {}
187};
188
ec6e0f63 189/* frequency list (map channels to frequencies) */
92b96797
FB
190/*
191static const long frequency_list[] = {
192 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
193 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
194 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
195 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
196 5700, 5745, 5765, 5785, 5805, 5825
197 };
198
92b96797 199static const struct iw_handler_def iwctl_handler_def;
92b96797
FB
200*/
201
26e5b65b
AM
202static int vt6656_probe(struct usb_interface *intf,
203 const struct usb_device_id *id);
204static void vt6656_disconnect(struct usb_interface *intf);
92b96797 205
92b96797 206#ifdef CONFIG_PM /* Minimal support for suspend and resume */
26e5b65b
AM
207static int vt6656_suspend(struct usb_interface *intf, pm_message_t message);
208static int vt6656_resume(struct usb_interface *intf);
209#endif /* CONFIG_PM */
210
92b96797
FB
211static struct net_device_stats *device_get_stats(struct net_device *dev);
212static int device_open(struct net_device *dev);
213static int device_xmit(struct sk_buff *skb, struct net_device *dev);
214static void device_set_multi(struct net_device *dev);
215static int device_close(struct net_device *dev);
216static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
217
dd0a774f
MP
218static int device_init_registers(struct vnt_private *pDevice,
219 DEVICE_INIT_TYPE InitType);
dfdcc425 220static bool device_init_defrag_cb(struct vnt_private *pDevice);
dd0a774f 221static void device_init_diversity_timer(struct vnt_private *pDevice);
92b96797
FB
222static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
223
224static int ethtool_ioctl(struct net_device *dev, void *useraddr);
dd0a774f
MP
225static void device_free_tx_bufs(struct vnt_private *pDevice);
226static void device_free_rx_bufs(struct vnt_private *pDevice);
227static void device_free_int_bufs(struct vnt_private *pDevice);
228static void device_free_frag_bufs(struct vnt_private *pDevice);
dfdcc425 229static bool device_alloc_bufs(struct vnt_private *pDevice);
dd0a774f
MP
230
231static int Read_config_file(struct vnt_private *pDevice);
232static unsigned char *Config_FileOperation(struct vnt_private *pDevice);
cc856e61
AM
233static int Config_FileGetParameter(unsigned char *string,
234 unsigned char *dest,
235 unsigned char *source);
92b96797 236
dd0a774f 237static void usb_device_reset(struct vnt_private *pDevice);
92b96797 238
92b96797 239static void
dd0a774f 240device_set_options(struct vnt_private *pDevice) {
92b96797 241
b902fbfe
AM
242 u8 abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
243 u8 abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
9a0e756c 244 u8 abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
92b96797 245
9a0e756c
AM
246 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
247 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
248 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
92b96797
FB
249
250 pDevice->cbTD = TX_DESC_DEF0;
251 pDevice->cbRD = RX_DESC_DEF0;
252 pDevice->uChannel = CHANNEL_DEF;
253 pDevice->wRTSThreshold = RTS_THRESH_DEF;
254 pDevice->wFragmentationThreshold = FRAG_THRESH_DEF;
255 pDevice->byShortRetryLimit = SHORT_RETRY_DEF;
256 pDevice->byLongRetryLimit = LONG_RETRY_DEF;
257 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
258 pDevice->byShortPreamble = PREAMBLE_TYPE_DEF;
259 pDevice->ePSMode = PS_MODE_DEF;
260 pDevice->b11hEnable = X80211h_MODE_DEF;
261 pDevice->eOPMode = OP_MODE_DEF;
262 pDevice->uConnectionRate = DATA_RATE_DEF;
4e9b5e2b 263 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = true;
92b96797
FB
264 pDevice->byBBType = BBP_TYPE_DEF;
265 pDevice->byPacketType = pDevice->byBBType;
266 pDevice->byAutoFBCtrl = AUTO_FB_0;
4e9b5e2b 267 pDevice->bUpdateBBVGA = true;
92b96797
FB
268 pDevice->byFOETuning = 0;
269 pDevice->byAutoPwrTunning = 0;
92b96797 270 pDevice->byPreambleType = 0;
e269fc2d 271 pDevice->bExistSWNetAddr = false;
4e9b5e2b 272 /* pDevice->bDiversityRegCtlON = true; */
e269fc2d 273 pDevice->bDiversityRegCtlON = false;
92b96797
FB
274}
275
dd0a774f 276static void device_init_diversity_timer(struct vnt_private *pDevice)
8611a29a 277{
92b96797 278 init_timer(&pDevice->TimerSQ3Tmax1);
cc856e61 279 pDevice->TimerSQ3Tmax1.data = (unsigned long)pDevice;
92b96797
FB
280 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
281 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
282
283 init_timer(&pDevice->TimerSQ3Tmax2);
cc856e61 284 pDevice->TimerSQ3Tmax2.data = (unsigned long)pDevice;
92b96797
FB
285 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
286 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
287
288 init_timer(&pDevice->TimerSQ3Tmax3);
cc856e61 289 pDevice->TimerSQ3Tmax3.data = (unsigned long)pDevice;
92b96797
FB
290 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerSQ3Tmax3CallBack;
291 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
292
293 return;
294}
295
ec6e0f63
AM
296/*
297 * initialization of MAC & BBP registers
298 */
92b96797 299
dd0a774f
MP
300static int device_init_registers(struct vnt_private *pDevice,
301 DEVICE_INIT_TYPE InitType)
92b96797 302{
dd0a774f
MP
303 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
304 u8 abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
305 u8 abySNAP_RFC1042[ETH_ALEN] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
306 u8 abySNAP_Bridgetunnel[ETH_ALEN]
307 = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8};
308 u8 byAntenna;
309 int ii;
310 CMD_CARD_INIT sInitCmd;
311 int ntStatus = STATUS_SUCCESS;
312 RSP_CARD_INIT sInitRsp;
313 u8 byTmp;
314 u8 byCalibTXIQ = 0, byCalibTXDC = 0, byCalibRXIQ = 0;
92b96797
FB
315
316 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n", InitType, pDevice->byPacketType);
317 spin_lock_irq(&pDevice->lock);
9a0e756c
AM
318 if (InitType == DEVICE_INIT_COLD) {
319 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
320 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
321 memcpy(pDevice->abySNAP_Bridgetunnel,
322 abySNAP_Bridgetunnel,
323 ETH_ALEN);
92b96797
FB
324
325 if ( !FIRMWAREbCheckVersion(pDevice) ) {
4e9b5e2b 326 if (FIRMWAREbDownload(pDevice) == true) {
e269fc2d 327 if (FIRMWAREbBrach2Sram(pDevice) == false) {
92b96797
FB
328 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbBrach2Sram fail \n");
329 spin_unlock_irq(&pDevice->lock);
e269fc2d 330 return false;
92b96797
FB
331 }
332 } else {
333
334 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" FIRMWAREbDownload fail \n");
335 spin_unlock_irq(&pDevice->lock);
e269fc2d 336 return false;
92b96797
FB
337 }
338 }
339
340 if ( !BBbVT3184Init(pDevice) ) {
341 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" BBbVT3184Init fail \n");
342 spin_unlock_irq(&pDevice->lock);
e269fc2d 343 return false;
92b96797
FB
344 }
345 }
346
b902fbfe
AM
347 sInitCmd.byInitClass = (u8)InitType;
348 sInitCmd.bExistSWNetAddr = (u8) pDevice->bExistSWNetAddr;
33d33e42
AM
349 for (ii = 0; ii < 6; ii++)
350 sInitCmd.bySWNetAddr[ii] = pDevice->abyCurrentNetAddr[ii];
92b96797
FB
351 sInitCmd.byShortRetryLimit = pDevice->byShortRetryLimit;
352 sInitCmd.byLongRetryLimit = pDevice->byLongRetryLimit;
353
ec6e0f63 354 /* issue card_init command to device */
92b96797
FB
355 ntStatus = CONTROLnsRequestOut(pDevice,
356 MESSAGE_TYPE_CARDINIT,
357 0,
358 0,
359 sizeof(CMD_CARD_INIT),
b902fbfe 360 (u8 *) &(sInitCmd));
92b96797
FB
361
362 if ( ntStatus != STATUS_SUCCESS ) {
363 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Issue Card init fail \n");
364 spin_unlock_irq(&pDevice->lock);
e269fc2d 365 return false;
92b96797
FB
366 }
367 if (InitType == DEVICE_INIT_COLD) {
368
b902fbfe 369 ntStatus = CONTROLnsRequestIn(pDevice,MESSAGE_TYPE_INIT_RSP,0,0,sizeof(RSP_CARD_INIT), (u8 *) &(sInitRsp));
92b96797
FB
370
371 if (ntStatus != STATUS_SUCCESS) {
372 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Cardinit request in status fail!\n");
373 spin_unlock_irq(&pDevice->lock);
e269fc2d 374 return false;
92b96797
FB
375 }
376
ec6e0f63 377 /* local ID for AES functions */
92b96797
FB
378 ntStatus = CONTROLnsRequestIn(pDevice,
379 MESSAGE_TYPE_READ,
380 MAC_REG_LOCALID,
381 MESSAGE_REQUEST_MACREG,
382 1,
383 &pDevice->byLocalID);
384
385 if ( ntStatus != STATUS_SUCCESS ) {
386 spin_unlock_irq(&pDevice->lock);
e269fc2d 387 return false;
92b96797
FB
388 }
389
ec6e0f63
AM
390 /* do MACbSoftwareReset in MACvInitialize */
391
392 /* force CCK */
4e9b5e2b 393 pDevice->bCCK = true;
e269fc2d 394 pDevice->bProtectMode = false;
ec6e0f63 395 /* only used in 11g type, sync with ERP IE */
e269fc2d
AM
396 pDevice->bNonERPPresent = false;
397 pDevice->bBarkerPreambleMd = false;
92b96797 398 if ( pDevice->bFixRate ) {
3eaca0d2 399 pDevice->wCurrentRate = (u16) pDevice->uConnectionRate;
92b96797
FB
400 } else {
401 if ( pDevice->byBBType == BB_TYPE_11B )
402 pDevice->wCurrentRate = RATE_11M;
403 else
404 pDevice->wCurrentRate = RATE_54M;
405 }
406
407 CHvInitChannelTable(pDevice);
408
409 pDevice->byTopOFDMBasicRate = RATE_24M;
410 pDevice->byTopCCKBasicRate = RATE_1M;
ec6e0f63
AM
411 pDevice->byRevId = 0;
412 /* target to IF pin while programming to RF chip */
92b96797
FB
413 pDevice->byCurPwr = 0xFF;
414
415 pDevice->byCCKPwr = pDevice->abyEEPROM[EEP_OFS_PWR_CCK];
416 pDevice->byOFDMPwrG = pDevice->abyEEPROM[EEP_OFS_PWR_OFDMG];
ec6e0f63
AM
417 /* load power table */
418 for (ii = 0; ii < 14; ii++) {
92b96797
FB
419 pDevice->abyCCKPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_CCK_PWR_TBL];
420 if (pDevice->abyCCKPwrTbl[ii] == 0)
421 pDevice->abyCCKPwrTbl[ii] = pDevice->byCCKPwr;
422 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDM_PWR_TBL];
423 if (pDevice->abyOFDMPwrTbl[ii] == 0)
424 pDevice->abyOFDMPwrTbl[ii] = pDevice->byOFDMPwrG;
425 }
426
ec6e0f63
AM
427 /*
428 * original zonetype is USA, but custom zonetype is Europe,
429 * then need to recover 12, 13, 14 channels with 11 channel
430 */
92b96797
FB
431 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
432 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
433 (pDevice->byOriginalZonetype == ZoneType_USA)) {
33d33e42
AM
434 for (ii = 11; ii < 14; ii++) {
435 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
436 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
437 }
92b96797
FB
438 }
439
ec6e0f63
AM
440 pDevice->byOFDMPwrA = 0x34; /* same as RFbMA2829SelectChannel */
441
442 /* load OFDM A power table */
443 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
92b96797
FB
444 pDevice->abyOFDMAPwrTbl[ii] = pDevice->abyEEPROM[ii + EEP_OFS_OFDMA_PWR_TBL];
445 if (pDevice->abyOFDMAPwrTbl[ii] == 0)
446 pDevice->abyOFDMAPwrTbl[ii] = pDevice->byOFDMPwrA;
447 }
92b96797
FB
448
449 byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA];
450 if (byAntenna & EEP_ANTINV)
4e9b5e2b 451 pDevice->bTxRxAntInv = true;
92b96797 452 else
e269fc2d 453 pDevice->bTxRxAntInv = false;
92b96797
FB
454
455 byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
456
ec6e0f63 457 if (byAntenna == 0) /* if not set default is both */
92b96797
FB
458 byAntenna = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
459
460 if (byAntenna == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
461 pDevice->byAntennaCount = 2;
462 pDevice->byTxAntennaMode = ANT_B;
463 pDevice->dwTxAntennaSel = 1;
464 pDevice->dwRxAntennaSel = 1;
4e9b5e2b 465 if (pDevice->bTxRxAntInv == true)
92b96797
FB
466 pDevice->byRxAntennaMode = ANT_A;
467 else
468 pDevice->byRxAntennaMode = ANT_B;
469
470 if (pDevice->bDiversityRegCtlON)
4e9b5e2b 471 pDevice->bDiversityEnable = true;
92b96797 472 else
e269fc2d 473 pDevice->bDiversityEnable = false;
92b96797 474 } else {
e269fc2d 475 pDevice->bDiversityEnable = false;
92b96797
FB
476 pDevice->byAntennaCount = 1;
477 pDevice->dwTxAntennaSel = 0;
478 pDevice->dwRxAntennaSel = 0;
479 if (byAntenna & EEP_ANTENNA_AUX) {
480 pDevice->byTxAntennaMode = ANT_A;
4e9b5e2b 481 if (pDevice->bTxRxAntInv == true)
92b96797
FB
482 pDevice->byRxAntennaMode = ANT_B;
483 else
484 pDevice->byRxAntennaMode = ANT_A;
485 } else {
486 pDevice->byTxAntennaMode = ANT_B;
4e9b5e2b 487 if (pDevice->bTxRxAntInv == true)
92b96797
FB
488 pDevice->byRxAntennaMode = ANT_A;
489 else
490 pDevice->byRxAntennaMode = ANT_B;
491 }
492 }
493 pDevice->ulDiversityNValue = 100*255;
494 pDevice->ulDiversityMValue = 100*16;
495 pDevice->byTMax = 1;
496 pDevice->byTMax2 = 4;
497 pDevice->ulSQ3TH = 0;
498 pDevice->byTMax3 = 64;
92b96797 499
ec6e0f63 500 /* get Auto Fall Back type */
92b96797
FB
501 pDevice->byAutoFBCtrl = AUTO_FB_0;
502
ec6e0f63 503 /* set SCAN Time */
92b96797
FB
504 pDevice->uScanTime = WLAN_SCAN_MINITIME;
505
ec6e0f63
AM
506 /* default Auto Mode */
507 /* pDevice->NetworkType = Ndis802_11Automode; */
92b96797
FB
508 pDevice->eConfigPHYMode = PHY_TYPE_AUTO;
509 pDevice->byBBType = BB_TYPE_11G;
510
ec6e0f63 511 /* initialize BBP registers */
92b96797
FB
512 pDevice->ulTxPower = 25;
513
ec6e0f63 514 /* get channel range */
92b96797
FB
515 pDevice->byMinChannel = 1;
516 pDevice->byMaxChannel = CB_MAX_CHANNEL;
517
ec6e0f63 518 /* get RFType */
92b96797
FB
519 pDevice->byRFType = sInitRsp.byRFType;
520
521 if ((pDevice->byRFType & RF_EMU) != 0) {
ec6e0f63
AM
522 /* force change RevID for VT3253 emu */
523 pDevice->byRevId = 0x80;
92b96797
FB
524 }
525
ec6e0f63 526 /* load vt3266 calibration parameters in EEPROM */
92b96797
FB
527 if (pDevice->byRFType == RF_VT3226D0) {
528 if((pDevice->abyEEPROM[EEP_OFS_MAJOR_VER] == 0x1) &&
529 (pDevice->abyEEPROM[EEP_OFS_MINOR_VER] >= 0x4)) {
530 byCalibTXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_IQ];
531 byCalibTXDC = pDevice->abyEEPROM[EEP_OFS_CALIB_TX_DC];
532 byCalibRXIQ = pDevice->abyEEPROM[EEP_OFS_CALIB_RX_IQ];
533 if( (byCalibTXIQ || byCalibTXDC || byCalibRXIQ) ) {
ec6e0f63
AM
534 /* CR255, enable TX/RX IQ and DC compensation mode */
535 ControlvWriteByte(pDevice,
536 MESSAGE_REQUEST_BBREG,
537 0xFF,
538 0x03);
539 /* CR251, TX I/Q Imbalance Calibration */
540 ControlvWriteByte(pDevice,
541 MESSAGE_REQUEST_BBREG,
542 0xFB,
543 byCalibTXIQ);
544 /* CR252, TX DC-Offset Calibration */
545 ControlvWriteByte(pDevice,
546 MESSAGE_REQUEST_BBREG,
547 0xFC,
548 byCalibTXDC);
549 /* CR253, RX I/Q Imbalance Calibration */
550 ControlvWriteByte(pDevice,
551 MESSAGE_REQUEST_BBREG,
552 0xFD,
553 byCalibRXIQ);
92b96797 554 } else {
ec6e0f63
AM
555 /* CR255, turn off BB Calibration compensation */
556 ControlvWriteByte(pDevice,
557 MESSAGE_REQUEST_BBREG,
558 0xFF,
559 0x0);
92b96797
FB
560 }
561 }
562 }
563 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
564 pMgmt->uCurrChannel = pDevice->uChannel;
565 pMgmt->uIBSSChannel = pDevice->uChannel;
566 CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
567
ec6e0f63 568 /* get permanent network address */
3e362598 569 memcpy(pDevice->abyPermanentNetAddr,&(sInitRsp.byNetAddr[0]),6);
9a0e756c
AM
570 memcpy(pDevice->abyCurrentNetAddr,
571 pDevice->abyPermanentNetAddr,
572 ETH_ALEN);
92b96797 573
ec6e0f63 574 /* if exist SW network address, use it */
d6a32aa1
AS
575 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %pM\n",
576 pDevice->abyCurrentNetAddr);
92b96797
FB
577 }
578
ec6e0f63
AM
579 /*
580 * set BB and packet type at the same time
581 * set Short Slot Time, xIFS, and RSPINF
582 */
92b96797
FB
583 if (pDevice->byBBType == BB_TYPE_11A) {
584 CARDbAddBasicRate(pDevice, RATE_6M);
4e9b5e2b 585 pDevice->bShortSlotTime = true;
92b96797
FB
586 } else {
587 CARDbAddBasicRate(pDevice, RATE_1M);
e269fc2d 588 pDevice->bShortSlotTime = false;
92b96797
FB
589 }
590 BBvSetShortSlotTime(pDevice);
591 CARDvSetBSSMode(pDevice);
592
593 if (pDevice->bUpdateBBVGA) {
594 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
595 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
596 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
597 }
598
599 pDevice->byRadioCtl = pDevice->abyEEPROM[EEP_OFS_RADIOCTL];
e269fc2d 600 pDevice->bHWRadioOff = false;
92b96797
FB
601 if ( (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) != 0 ) {
602 ntStatus = CONTROLnsRequestIn(pDevice,
603 MESSAGE_TYPE_READ,
604 MAC_REG_GPIOCTL1,
605 MESSAGE_REQUEST_MACREG,
606 1,
607 &byTmp);
608
609 if ( ntStatus != STATUS_SUCCESS ) {
610 spin_unlock_irq(&pDevice->lock);
e269fc2d 611 return false;
92b96797
FB
612 }
613 if ( (byTmp & GPIO3_DATA) == 0 ) {
4e9b5e2b 614 pDevice->bHWRadioOff = true;
92b96797
FB
615 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
616 } else {
617 MACvRegBitsOff(pDevice,MAC_REG_GPIOCTL1,GPIO3_INTMD);
e269fc2d 618 pDevice->bHWRadioOff = false;
92b96797
FB
619 }
620
ec6e0f63 621 }
92b96797
FB
622
623 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_TMLEN,0x38);
624 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
625 MACvRegBitsOn(pDevice,MAC_REG_GPIOCTL0,0x01);
626
4e9b5e2b 627 if ((pDevice->bHWRadioOff == true) || (pDevice->bRadioControlOff == true)) {
92b96797
FB
628 CARDbRadioPowerOff(pDevice);
629 } else {
630 CARDbRadioPowerOn(pDevice);
631 }
632
633 spin_unlock_irq(&pDevice->lock);
634 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----INIbInitAdapter Exit\n");
4e9b5e2b 635 return true;
92b96797
FB
636}
637
92b96797 638#ifdef CONFIG_PM /* Minimal support for suspend and resume */
26e5b65b
AM
639
640static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
92b96797 641{
dd0a774f 642 struct vnt_private *device = usb_get_intfdata(intf);
92b96797 643
e54d9eb9
AM
644 if (!device || !device->dev)
645 return -ENODEV;
646
647 if (device->flags & DEVICE_FLAGS_OPENED)
648 device_close(device->dev);
92b96797 649
e54d9eb9 650 return 0;
92b96797
FB
651}
652
26e5b65b 653static int vt6656_resume(struct usb_interface *intf)
92b96797 654{
dd0a774f 655 struct vnt_private *device = usb_get_intfdata(intf);
e54d9eb9
AM
656
657 if (!device || !device->dev)
658 return -ENODEV;
659
e54d9eb9
AM
660 if (!(device->flags & DEVICE_FLAGS_OPENED))
661 device_open(device->dev);
662
663 return 0;
92b96797 664}
92b96797 665
26e5b65b 666#endif /* CONFIG_PM */
dd8db704
FB
667
668static const struct net_device_ops device_netdev_ops = {
669 .ndo_open = device_open,
670 .ndo_stop = device_close,
671 .ndo_do_ioctl = device_ioctl,
672 .ndo_get_stats = device_get_stats,
673 .ndo_start_xmit = device_xmit,
afc4b13d 674 .ndo_set_rx_mode = device_set_multi,
dd8db704
FB
675};
676
59cb218e 677static int
26e5b65b 678vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
92b96797 679{
9a0e756c 680 u8 fake_mac[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
92b96797 681 struct usb_device *udev = interface_to_usbdev(intf);
7a8b0055
AM
682 int rc = 0;
683 struct net_device *netdev = NULL;
dd0a774f 684 struct vnt_private *pDevice;
92b96797 685
7a8b0055
AM
686 printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
687 printk(KERN_NOTICE "Copyright (c) 2004 VIA Networking Technologies, Inc.\n");
92b96797 688
7a8b0055 689 udev = usb_get_dev(udev);
dd0a774f 690 netdev = alloc_etherdev(sizeof(struct vnt_private));
7a8b0055
AM
691 if (!netdev) {
692 printk(KERN_ERR DEVICE_NAME ": allocate net device failed\n");
e3a92cde 693 rc = -ENOMEM;
7a8b0055
AM
694 goto err_nomem;
695 }
1e28efa3 696
7a8b0055 697 pDevice = netdev_priv(netdev);
dd0a774f 698 memset(pDevice, 0, sizeof(struct vnt_private));
92b96797 699
7a8b0055
AM
700 pDevice->dev = netdev;
701 pDevice->usb = udev;
92b96797 702
7a8b0055
AM
703 device_set_options(pDevice);
704 spin_lock_init(&pDevice->lock);
94488a7e 705 INIT_DELAYED_WORK(&pDevice->run_command_work, vRunCommand);
92b96797 706
7a8b0055 707 pDevice->tx_80211 = device_dma0_tx_80211;
14c5ef57 708 pDevice->vnt_mgmt.pAdapter = (void *) pDevice;
dd8db704 709
7a8b0055
AM
710 netdev->netdev_ops = &device_netdev_ops;
711 netdev->wireless_handlers =
712 (struct iw_handler_def *) &iwctl_handler_def;
92b96797 713
7a8b0055 714 usb_set_intfdata(intf, pDevice);
92b96797 715 SET_NETDEV_DEV(netdev, &intf->dev);
7a8b0055
AM
716 memcpy(pDevice->dev->dev_addr, fake_mac, ETH_ALEN);
717 rc = register_netdev(netdev);
718 if (rc) {
719 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
e3a92cde 720 goto err_netdev;
7a8b0055 721 }
92b96797 722
7a8b0055 723 usb_device_reset(pDevice);
92b96797 724
92b96797 725 return 0;
92b96797 726
e3a92cde
DC
727err_netdev:
728 free_netdev(netdev);
92b96797 729err_nomem:
7a8b0055 730 usb_put_dev(udev);
92b96797 731
e3a92cde 732 return rc;
92b96797
FB
733}
734
dd0a774f 735static void device_free_tx_bufs(struct vnt_private *pDevice)
8611a29a 736{
dcdf1d03 737 struct vnt_usb_send_context *pTxContext;
92b96797
FB
738 int ii;
739
740 for (ii = 0; ii < pDevice->cbTD; ii++) {
741
742 pTxContext = pDevice->apTD[ii];
ec6e0f63 743 /* deallocate URBs */
92b96797 744 if (pTxContext->pUrb) {
dad72fed 745 usb_kill_urb(pTxContext->pUrb);
92b96797
FB
746 usb_free_urb(pTxContext->pUrb);
747 }
1d5c536e 748 kfree(pTxContext);
92b96797
FB
749 }
750 return;
751}
752
dd0a774f 753static void device_free_rx_bufs(struct vnt_private *pDevice)
8611a29a 754{
115cac2e
MP
755 struct vnt_rcb *pRCB;
756 int ii;
92b96797
FB
757
758 for (ii = 0; ii < pDevice->cbRD; ii++) {
759
760 pRCB = pDevice->apRCB[ii];
ec6e0f63 761 /* deallocate URBs */
92b96797 762 if (pRCB->pUrb) {
dad72fed 763 usb_kill_urb(pRCB->pUrb);
92b96797
FB
764 usb_free_urb(pRCB->pUrb);
765 }
ec6e0f63 766 /* deallocate skb */
92b96797
FB
767 if (pRCB->skb)
768 dev_kfree_skb(pRCB->skb);
769 }
1d5c536e 770 kfree(pDevice->pRCBMem);
92b96797
FB
771
772 return;
773}
774
dd0a774f 775static void usb_device_reset(struct vnt_private *pDevice)
92b96797
FB
776{
777 int status;
778 status = usb_reset_device(pDevice->usb);
779 if (status)
780 printk("usb_device_reset fail status=%d\n",status);
781 return ;
782}
92b96797 783
dd0a774f 784static void device_free_int_bufs(struct vnt_private *pDevice)
8611a29a 785{
1d5c536e 786 kfree(pDevice->intBuf.pDataBuf);
92b96797
FB
787 return;
788}
789
dfdcc425 790static bool device_alloc_bufs(struct vnt_private *pDevice)
dd0a774f 791{
dcdf1d03 792 struct vnt_usb_send_context *pTxContext;
115cac2e
MP
793 struct vnt_rcb *pRCB;
794 int ii;
92b96797 795
92b96797
FB
796 for (ii = 0; ii < pDevice->cbTD; ii++) {
797
dcdf1d03 798 pTxContext = kmalloc(sizeof(struct vnt_usb_send_context), GFP_KERNEL);
92b96797
FB
799 if (pTxContext == NULL) {
800 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate tx usb context failed\n", pDevice->dev->name);
801 goto free_tx;
802 }
803 pDevice->apTD[ii] = pTxContext;
8611a29a 804 pTxContext->pDevice = (void *) pDevice;
ec6e0f63 805 /* allocate URBs */
dad72fed 806 pTxContext->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
92b96797
FB
807 if (pTxContext->pUrb == NULL) {
808 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "alloc tx urb failed\n");
809 goto free_tx;
810 }
e269fc2d 811 pTxContext->bBoolInUse = false;
92b96797
FB
812 }
813
ec6e0f63 814 /* allocate RCB mem */
115cac2e
MP
815 pDevice->pRCBMem = kzalloc((sizeof(struct vnt_rcb) * pDevice->cbRD),
816 GFP_KERNEL);
92b96797
FB
817 if (pDevice->pRCBMem == NULL) {
818 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : alloc rx usb context failed\n", pDevice->dev->name);
819 goto free_tx;
820 }
821
92b96797
FB
822 pDevice->FirstRecvFreeList = NULL;
823 pDevice->LastRecvFreeList = NULL;
824 pDevice->FirstRecvMngList = NULL;
825 pDevice->LastRecvMngList = NULL;
826 pDevice->NumRecvFreeList = 0;
115cac2e
MP
827
828 pRCB = (struct vnt_rcb *)pDevice->pRCBMem;
92b96797
FB
829
830 for (ii = 0; ii < pDevice->cbRD; ii++) {
831
832 pDevice->apRCB[ii] = pRCB;
8611a29a 833 pRCB->pDevice = (void *) pDevice;
ec6e0f63 834 /* allocate URBs */
dad72fed 835 pRCB->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
92b96797
FB
836
837 if (pRCB->pUrb == NULL) {
838 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx urb\n");
839 goto free_rx_tx;
840 }
841 pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
842 if (pRCB->skb == NULL) {
843 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to alloc rx skb\n");
844 goto free_rx_tx;
845 }
846 pRCB->skb->dev = pDevice->dev;
e269fc2d 847 pRCB->bBoolInUse = false;
92b96797
FB
848 EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB);
849 pDevice->NumRecvFreeList++;
850 pRCB++;
851 }
852
dad72fed 853 pDevice->pControlURB = usb_alloc_urb(0, GFP_ATOMIC);
92b96797
FB
854 if (pDevice->pControlURB == NULL) {
855 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc control urb\n");
856 goto free_rx_tx;
857 }
858
dad72fed 859 pDevice->pInterruptURB = usb_alloc_urb(0, GFP_ATOMIC);
92b96797
FB
860 if (pDevice->pInterruptURB == NULL) {
861 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int urb\n");
92b96797
FB
862 usb_free_urb(pDevice->pControlURB);
863 goto free_rx_tx;
864 }
865
866 pDevice->intBuf.pDataBuf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
867 if (pDevice->intBuf.pDataBuf == NULL) {
868 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR"Failed to alloc int buf\n");
92b96797
FB
869 usb_free_urb(pDevice->pControlURB);
870 usb_free_urb(pDevice->pInterruptURB);
871 goto free_rx_tx;
872 }
873
4e9b5e2b 874 return true;
92b96797
FB
875
876free_rx_tx:
877 device_free_rx_bufs(pDevice);
878
879free_tx:
880 device_free_tx_bufs(pDevice);
881
e269fc2d 882 return false;
92b96797
FB
883}
884
dfdcc425 885static bool device_init_defrag_cb(struct vnt_private *pDevice)
dd0a774f
MP
886{
887 int i;
888 PSDeFragControlBlock pDeF;
92b96797
FB
889
890 /* Init the fragment ctl entries */
891 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
892 pDeF = &(pDevice->sRxDFCB[i]);
893 if (!device_alloc_frag_buf(pDevice, pDeF)) {
894 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
895 pDevice->dev->name);
896 goto free_frag;
9fc86028 897 }
92b96797
FB
898 }
899 pDevice->cbDFCB = CB_MAX_RX_FRAG;
900 pDevice->cbFreeDFCB = pDevice->cbDFCB;
4e9b5e2b 901 return true;
92b96797
FB
902
903free_frag:
904 device_free_frag_bufs(pDevice);
e269fc2d 905 return false;
92b96797
FB
906}
907
dd0a774f
MP
908static void device_free_frag_bufs(struct vnt_private *pDevice)
909{
910 PSDeFragControlBlock pDeF;
911 int i;
92b96797
FB
912
913 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
914
915 pDeF = &(pDevice->sRxDFCB[i]);
916
917 if (pDeF->skb)
918 dev_kfree_skb(pDeF->skb);
919 }
920}
921
dd0a774f
MP
922int device_alloc_frag_buf(struct vnt_private *pDevice,
923 PSDeFragControlBlock pDeF)
924{
92b96797
FB
925
926 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
927 if (pDeF->skb == NULL)
e269fc2d 928 return false;
92b96797
FB
929 pDeF->skb->dev = pDevice->dev;
930
4e9b5e2b 931 return true;
92b96797
FB
932}
933
dd0a774f
MP
934static int device_open(struct net_device *dev)
935{
936 struct vnt_private *pDevice = netdev_priv(dev);
92b96797 937
e269fc2d 938 pDevice->fWPA_Authened = false;
92b96797
FB
939
940 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n");
941
92b96797
FB
942 pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
943
e269fc2d 944 if (device_alloc_bufs(pDevice) == false) {
92b96797
FB
945 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n");
946 return -ENOMEM;
947 }
948
e269fc2d 949 if (device_init_defrag_cb(pDevice)== false) {
a0a1f61a 950 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragment cb fail \n");
92b96797
FB
951 goto free_rx_tx;
952 }
953
954 MP_CLEAR_FLAG(pDevice, fMP_DISCONNECTED);
955 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
956 MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
957 MP_SET_FLAG(pDevice, fMP_POST_READS);
958 MP_SET_FLAG(pDevice, fMP_POST_WRITES);
959
ec6e0f63 960 /* read config file */
92b96797
FB
961 Read_config_file(pDevice);
962
e269fc2d 963 if (device_init_registers(pDevice, DEVICE_INIT_COLD) == false) {
92b96797
FB
964 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n");
965 goto free_all;
966 }
967
968 device_set_multi(pDevice->dev);
92b96797 969
ec6e0f63 970 /* init for key management */
92b96797 971 KeyvInitTable(pDevice,&pDevice->sKey);
14c5ef57
MP
972 memcpy(pDevice->vnt_mgmt.abyMACAddr,
973 pDevice->abyCurrentNetAddr, ETH_ALEN);
9a0e756c 974 memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN);
e269fc2d
AM
975 pDevice->bStopTx0Pkt = false;
976 pDevice->bStopDataPkt = false;
977 pDevice->bRoaming = false;
978 pDevice->bIsRoaming = false;
979 pDevice->bEnableRoaming = false;
92b96797
FB
980 if (pDevice->bDiversityRegCtlON) {
981 device_init_diversity_timer(pDevice);
982 }
983
984 vMgrObjectInit(pDevice);
985 tasklet_init(&pDevice->RxMngWorkItem, (void *)RXvMngWorkItem, (unsigned long)pDevice);
986 tasklet_init(&pDevice->ReadWorkItem, (void *)RXvWorkItem, (unsigned long)pDevice);
987 tasklet_init(&pDevice->EventWorkItem, (void *)INTvWorkItem, (unsigned long)pDevice);
14c5ef57 988 add_timer(&pDevice->vnt_mgmt.sTimerSecondCallback);
ec6e0f63 989 pDevice->int_interval = 100; /* max 100 microframes */
92b96797
FB
990 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
991
4e9b5e2b 992 pDevice->bIsRxWorkItemQueued = true;
e269fc2d
AM
993 pDevice->fKillEventPollingThread = false;
994 pDevice->bEventAvailable = false;
995
996 pDevice->bWPADEVUp = false;
997 pDevice->bwextstep0 = false;
998 pDevice->bwextstep1 = false;
999 pDevice->bwextstep2 = false;
1000 pDevice->bwextstep3 = false;
1001 pDevice->bWPASuppWextEnabled = false;
92b96797
FB
1002 pDevice->byReAssocCount = 0;
1003
1004 RXvWorkItem(pDevice);
1005 INTvWorkItem(pDevice);
1006
ec6e0f63 1007 /* if WEP key already set by iwconfig but device not yet open */
4e9b5e2b 1008 if ((pDevice->bEncryptionEnable == true) && (pDevice->bTransmitKey == true)) {
92b96797
FB
1009 spin_lock_irq(&pDevice->lock);
1010 KeybSetDefaultKey( pDevice,
1011 &(pDevice->sKey),
1012 pDevice->byKeyIndex | (1 << 31),
1013 pDevice->uKeyLength,
1014 NULL,
1015 pDevice->abyKey,
1016 KEY_CTL_WEP
1017 );
1018 spin_unlock_irq(&pDevice->lock);
1019 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1020 }
1021
14c5ef57 1022 if (pDevice->vnt_mgmt.eConfigMode == WMAC_CONFIG_AP)
0cbd8d98 1023 bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL);
14c5ef57
MP
1024 else
1025 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
92b96797 1026
92b96797
FB
1027 netif_stop_queue(pDevice->dev);
1028 pDevice->flags |= DEVICE_FLAGS_OPENED;
1029
179f823d
MP
1030 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success..\n");
1031 return 0;
92b96797
FB
1032
1033free_all:
1034 device_free_frag_bufs(pDevice);
1035free_rx_tx:
1036 device_free_rx_bufs(pDevice);
1037 device_free_tx_bufs(pDevice);
1038 device_free_int_bufs(pDevice);
dad72fed
JL
1039 usb_kill_urb(pDevice->pControlURB);
1040 usb_kill_urb(pDevice->pInterruptURB);
92b96797
FB
1041 usb_free_urb(pDevice->pControlURB);
1042 usb_free_urb(pDevice->pInterruptURB);
1043
1044 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open fail.. \n");
1045 return -ENOMEM;
1046}
1047
dd0a774f
MP
1048static int device_close(struct net_device *dev)
1049{
1050 struct vnt_private *pDevice = netdev_priv(dev);
1051 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1052 int uu;
92b96797 1053
dd0a774f 1054 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1\n");
92b96797
FB
1055 if (pDevice == NULL)
1056 return -ENODEV;
1057
92b96797 1058 if (pDevice->bLinkPass) {
0cbd8d98 1059 bScheduleCommand((void *) pDevice, WLAN_CMD_DISASSOCIATE, NULL);
92b96797
FB
1060 mdelay(30);
1061 }
92b96797 1062
92b96797 1063 memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
e269fc2d
AM
1064 pMgmt->bShareKeyAlgorithm = false;
1065 pDevice->bEncryptionEnable = false;
92b96797 1066 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
33d33e42
AM
1067 spin_lock_irq(&pDevice->lock);
1068 for (uu = 0; uu < MAX_KEY_TABLE; uu++)
92b96797 1069 MACvDisableKeyEntry(pDevice,uu);
33d33e42 1070 spin_unlock_irq(&pDevice->lock);
92b96797 1071
e269fc2d 1072 if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == false) {
92b96797
FB
1073 MACbShutdown(pDevice);
1074 }
1075 netif_stop_queue(pDevice->dev);
1076 MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
1077 MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES);
1078 MP_CLEAR_FLAG(pDevice, fMP_POST_READS);
4e9b5e2b 1079 pDevice->fKillEventPollingThread = true;
94488a7e
MP
1080
1081 cancel_delayed_work_sync(&pDevice->run_command_work);
1082
92b96797
FB
1083 del_timer(&pMgmt->sTimerSecondCallback);
1084
92b96797 1085 del_timer(&pDevice->sTimerTxData);
92b96797
FB
1086
1087 if (pDevice->bDiversityRegCtlON) {
1088 del_timer(&pDevice->TimerSQ3Tmax1);
1089 del_timer(&pDevice->TimerSQ3Tmax2);
1090 del_timer(&pDevice->TimerSQ3Tmax3);
1091 }
1092 tasklet_kill(&pDevice->RxMngWorkItem);
1093 tasklet_kill(&pDevice->ReadWorkItem);
1094 tasklet_kill(&pDevice->EventWorkItem);
1095
e269fc2d
AM
1096 pDevice->bRoaming = false;
1097 pDevice->bIsRoaming = false;
1098 pDevice->bEnableRoaming = false;
1099 pDevice->bCmdRunning = false;
1100 pDevice->bLinkPass = false;
92b96797
FB
1101 memset(pMgmt->abyCurrBSSID, 0, 6);
1102 pMgmt->eCurrState = WMAC_STATE_IDLE;
1103
e3eb270f
MP
1104 pDevice->flags &= ~DEVICE_FLAGS_OPENED;
1105
92b96797
FB
1106 device_free_tx_bufs(pDevice);
1107 device_free_rx_bufs(pDevice);
1108 device_free_int_bufs(pDevice);
1109 device_free_frag_bufs(pDevice);
1110
dad72fed
JL
1111 usb_kill_urb(pDevice->pControlURB);
1112 usb_kill_urb(pDevice->pInterruptURB);
92b96797
FB
1113 usb_free_urb(pDevice->pControlURB);
1114 usb_free_urb(pDevice->pInterruptURB);
1115
1116 BSSvClearNodeDBTable(pDevice, 0);
92b96797
FB
1117
1118 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close2 \n");
1119
1120 return 0;
1121}
1122
0d7fe14f 1123static void vt6656_disconnect(struct usb_interface *intf)
92b96797 1124{
dd0a774f 1125 struct vnt_private *device = usb_get_intfdata(intf);
92b96797 1126
6cda24f5
AM
1127 if (!device)
1128 return;
92b96797 1129
92b96797 1130 usb_set_intfdata(intf, NULL);
6cda24f5 1131 usb_put_dev(interface_to_usbdev(intf));
92b96797 1132
6cda24f5 1133 device->flags |= DEVICE_FLAGS_UNPLUG;
92b96797 1134
6cda24f5
AM
1135 if (device->dev) {
1136 unregister_netdev(device->dev);
6cda24f5
AM
1137 free_netdev(device->dev);
1138 }
b3a6db9c 1139
92b96797
FB
1140}
1141
e1669ed0
AM
1142static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1143{
dd0a774f 1144 struct vnt_private *pDevice = netdev_priv(dev);
92b96797 1145
e1669ed0 1146 spin_lock_irq(&pDevice->lock);
92b96797 1147
e1669ed0
AM
1148 if (unlikely(pDevice->bStopTx0Pkt))
1149 dev_kfree_skb_irq(skb);
1150 else
1151 vDMA0_tx_80211(pDevice, skb);
92b96797 1152
e1669ed0 1153 spin_unlock_irq(&pDevice->lock);
92b96797 1154
e1669ed0 1155 return NETDEV_TX_OK;
92b96797
FB
1156}
1157
529e5b32
AM
1158static int device_xmit(struct sk_buff *skb, struct net_device *dev)
1159{
dd0a774f 1160 struct vnt_private *pDevice = netdev_priv(dev);
529e5b32 1161 struct net_device_stats *stats = &pDevice->stats;
92b96797 1162
529e5b32 1163 spin_lock_irq(&pDevice->lock);
92b96797 1164
529e5b32 1165 netif_stop_queue(dev);
92b96797 1166
529e5b32
AM
1167 if (!pDevice->bLinkPass) {
1168 dev_kfree_skb_irq(skb);
1169 goto out;
1170 }
92b96797 1171
529e5b32
AM
1172 if (pDevice->bStopDataPkt) {
1173 dev_kfree_skb_irq(skb);
1174 stats->tx_dropped++;
1175 goto out;
1176 }
92b96797 1177
529e5b32
AM
1178 if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb)) {
1179 if (netif_queue_stopped(dev))
1180 netif_wake_queue(dev);
1181 }
92b96797 1182
529e5b32
AM
1183out:
1184 spin_unlock_irq(&pDevice->lock);
92b96797 1185
529e5b32 1186 return NETDEV_TX_OK;
92b96797
FB
1187}
1188
92b96797
FB
1189static unsigned const ethernet_polynomial = 0x04c11db7U;
1190static inline u32 ether_crc(int length, unsigned char *data)
1191{
1192 int crc = -1;
1193
1194 while(--length >= 0) {
1195 unsigned char current_octet = *data++;
1196 int bit;
1197 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
1198 crc = (crc << 1) ^
1199 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
1200 }
1201 }
1202 return crc;
1203}
1204
ec6e0f63 1205/* find out the start position of str2 from str1 */
cc856e61
AM
1206static unsigned char *kstrstr(const unsigned char *str1,
1207 const unsigned char *str2) {
1208 int str1_len = strlen(str1);
1209 int str2_len = strlen(str2);
92b96797
FB
1210
1211 while (str1_len >= str2_len) {
1212 str1_len--;
1213 if(memcmp(str1,str2,str2_len)==0)
cc856e61 1214 return (unsigned char *) str1;
92b96797
FB
1215 str1++;
1216 }
1217 return NULL;
1218}
1219
cc856e61
AM
1220static int Config_FileGetParameter(unsigned char *string,
1221 unsigned char *dest,
1222 unsigned char *source)
92b96797 1223{
cc856e61
AM
1224 unsigned char buf1[100];
1225 unsigned char buf2[100];
1226 unsigned char *start_p = NULL, *end_p = NULL, *tmp_p = NULL;
92b96797
FB
1227 int ii;
1228
1229 memset(buf1,0,100);
1230 strcat(buf1, string);
1231 strcat(buf1, "=");
1232 source+=strlen(buf1);
1233
ec6e0f63 1234 /* find target string start point */
bfbfeecc
JP
1235 start_p = kstrstr(source,buf1);
1236 if (start_p == NULL)
e269fc2d 1237 return false;
92b96797 1238
ec6e0f63 1239 /* check if current config line is marked by "#" */
33d33e42
AM
1240 for (ii = 1; ; ii++) {
1241 if (memcmp(start_p - ii, "\n", 1) == 0)
1242 break;
1243 if (memcmp(start_p - ii, "#", 1) == 0)
e269fc2d 1244 return false;
33d33e42 1245 }
92b96797 1246
ec6e0f63 1247 /* find target string end point */
bfbfeecc 1248 end_p = kstrstr(start_p,"\n");
ec6e0f63
AM
1249 if (end_p == NULL) { /* can't find "\n", but don't care */
1250 end_p = start_p + strlen(start_p); /* no include "\n" */
1251 }
92b96797
FB
1252
1253 memset(buf2,0,100);
ec6e0f63 1254 memcpy(buf2, start_p, end_p-start_p); /* get the target line */
92b96797
FB
1255 buf2[end_p-start_p]='\0';
1256
ec6e0f63 1257 /* find value */
bfbfeecc
JP
1258 start_p = kstrstr(buf2,"=");
1259 if (start_p == NULL)
e269fc2d 1260 return false;
92b96797
FB
1261 memset(buf1,0,100);
1262 strcpy(buf1,start_p+1);
1263
ec6e0f63 1264 /* except space */
92b96797
FB
1265 tmp_p = buf1;
1266 while(*tmp_p != 0x00) {
1267 if(*tmp_p==' ')
1268 tmp_p++;
1269 else
1270 break;
1271 }
1272
1273 memcpy(dest,tmp_p,strlen(tmp_p));
4e9b5e2b 1274 return true;
92b96797
FB
1275}
1276
ec6e0f63 1277/* if read fails, return NULL, or return data pointer */
dd0a774f 1278static unsigned char *Config_FileOperation(struct vnt_private *pDevice)
cc856e61 1279{
7c51d177
AV
1280 unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
1281 struct file *file;
ec6e0f63 1282
7c51d177
AV
1283 if (!buffer) {
1284 printk("allocate mem for file fail?\n");
1285 return NULL;
1286 }
92b96797 1287
7c51d177
AV
1288 file = filp_open(CONFIG_PATH, O_RDONLY, 0);
1289 if (IS_ERR(file)) {
1290 kfree(buffer);
1291 printk("Config_FileOperation file Not exist\n");
1292 return NULL;
1293 }
92b96797 1294
7c51d177
AV
1295 if (kernel_read(file, 0, buffer, 1024) < 0) {
1296 printk("read file error?\n");
1297 kfree(buffer);
1298 buffer = NULL;
1299 }
8f9c466f 1300
7c51d177
AV
1301 fput(file);
1302 return buffer;
92b96797
FB
1303}
1304
ec6e0f63 1305/* return --->-1:fail; >=0:successful */
dd0a774f
MP
1306static int Read_config_file(struct vnt_private *pDevice)
1307{
1308 int result = 0;
1309 unsigned char tmpbuffer[100];
1310 unsigned char *buffer = NULL;
92b96797 1311
ec6e0f63 1312 /* init config setting */
92b96797
FB
1313 pDevice->config_file.ZoneType = -1;
1314 pDevice->config_file.eAuthenMode = -1;
1315 pDevice->config_file.eEncryptionStatus = -1;
1316
bfbfeecc
JP
1317 buffer = Config_FileOperation(pDevice);
1318 if (buffer == NULL) {
92b96797
FB
1319 result =-1;
1320 return result;
1321 }
1322
ec6e0f63 1323/* get zonetype */
92b96797
FB
1324{
1325 memset(tmpbuffer,0,sizeof(tmpbuffer));
4e9b5e2b 1326 if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==true) {
92b96797
FB
1327 if(memcmp(tmpbuffer,"USA",3)==0) {
1328 pDevice->config_file.ZoneType=ZoneType_USA;
1329 }
1330 else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
1331 pDevice->config_file.ZoneType=ZoneType_Japan;
1332 }
1333 else if(memcmp(tmpbuffer,"EUROPE",6)==0) {
1334 pDevice->config_file.ZoneType=ZoneType_Europe;
1335 }
1336 else {
1337 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
1338 }
1339 }
1340}
1341
ec6e0f63 1342/* get other parameter */
92b96797
FB
1343 {
1344 memset(tmpbuffer,0,sizeof(tmpbuffer));
4e9b5e2b 1345 if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==true) {
92b96797
FB
1346 pDevice->config_file.eAuthenMode = (int) simple_strtol(tmpbuffer, NULL, 10);
1347 }
1348
1349 memset(tmpbuffer,0,sizeof(tmpbuffer));
4e9b5e2b 1350 if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==true) {
92b96797
FB
1351 pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10);
1352 }
1353 }
92b96797
FB
1354
1355 kfree(buffer);
1356 return result;
1357}
1358
dd0a774f
MP
1359static void device_set_multi(struct net_device *dev)
1360{
1361 struct vnt_private *pDevice = netdev_priv(dev);
1362 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1363 struct netdev_hw_addr *ha;
1364 u32 mc_filter[2];
1365 int ii;
1366 u8 pbyData[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1367 u8 byTmpMode = 0;
1368 int rc;
92b96797 1369
92b96797
FB
1370 spin_lock_irq(&pDevice->lock);
1371 rc = CONTROLnsRequestIn(pDevice,
1372 MESSAGE_TYPE_READ,
1373 MAC_REG_RCR,
1374 MESSAGE_REQUEST_MACREG,
1375 1,
1376 &byTmpMode
1377 );
1378 if (rc == 0) pDevice->byRxMode = byTmpMode;
1379
1380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode in= %x\n", pDevice->byRxMode);
1381
ec6e0f63 1382 if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
92b96797 1383 DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
ec6e0f63 1384 /* unconditionally log net taps */
92b96797
FB
1385 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
1386 }
4cd24eaf
JP
1387 else if ((netdev_mc_count(dev) > pDevice->multicast_limit) ||
1388 (dev->flags & IFF_ALLMULTI)) {
92b96797
FB
1389 CONTROLnsRequestOut(pDevice,
1390 MESSAGE_TYPE_WRITE,
1391 MAC_REG_MAR0,
1392 MESSAGE_REQUEST_MACREG,
1393 8,
1394 pbyData
1395 );
1396 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1397 }
1398 else {
1399 memset(mc_filter, 0, sizeof(mc_filter));
22bedad3
JP
1400 netdev_for_each_mc_addr(ha, dev) {
1401 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
92b96797
FB
1402 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
1403 }
1404 for (ii = 0; ii < 4; ii++) {
b902fbfe
AM
1405 MACvWriteMultiAddr(pDevice, ii, *((u8 *)&mc_filter[0] + ii));
1406 MACvWriteMultiAddr(pDevice, ii+ 4, *((u8 *)&mc_filter[1] + ii));
92b96797
FB
1407 }
1408 pDevice->byRxMode &= ~(RCR_UNICAST);
1409 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1410 }
1411
1412 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
ec6e0f63
AM
1413 /*
1414 * If AP mode, don't enable RCR_UNICAST since HW only compares
1415 * addr1 with local MAC
1416 */
92b96797
FB
1417 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1418 pDevice->byRxMode &= ~(RCR_UNICAST);
1419 }
1420 ControlvWriteByte(pDevice, MESSAGE_REQUEST_MACREG, MAC_REG_RCR, pDevice->byRxMode);
1421 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode out= %x\n", pDevice->byRxMode);
1422 spin_unlock_irq(&pDevice->lock);
1423
1424}
1425
7055a075
MP
1426static struct net_device_stats *device_get_stats(struct net_device *dev)
1427{
dd0a774f 1428 struct vnt_private *pDevice = netdev_priv(dev);
92b96797 1429
dd0a774f 1430 return &pDevice->stats;
92b96797
FB
1431}
1432
7055a075
MP
1433static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1434{
dd0a774f 1435 struct vnt_private *pDevice = netdev_priv(dev);
92b96797 1436 struct iwreq *wrq = (struct iwreq *) rq;
848ce511 1437 int rc = 0;
92b96797 1438
7055a075 1439 switch (cmd) {
92b96797 1440
7055a075 1441 case IOCTL_CMD_HOSTAPD:
92b96797 1442
7055a075
MP
1443 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
1444 rc = -EFAULT;
92b96797 1445
c30d7973 1446 rc = vt6656_hostap_ioctl(pDevice, &wrq->u.data);
7055a075 1447 break;
92b96797
FB
1448
1449 case SIOCETHTOOL:
7055a075 1450 return ethtool_ioctl(dev, (void *) rq->ifr_data);
92b96797 1451
7055a075 1452 }
92b96797 1453
7055a075 1454 return rc;
92b96797
FB
1455}
1456
92b96797
FB
1457static int ethtool_ioctl(struct net_device *dev, void *useraddr)
1458{
1459 u32 ethcmd;
1460
1461 if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
1462 return -EFAULT;
1463
1464 switch (ethcmd) {
1465 case ETHTOOL_GDRVINFO: {
1466 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
1467 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
1468 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
1469 if (copy_to_user(useraddr, &info, sizeof(info)))
1470 return -EFAULT;
1471 return 0;
1472 }
1473
1474 }
1475
1476 return -EOPNOTSUPP;
1477}
1478
26e5b65b 1479MODULE_DEVICE_TABLE(usb, vt6656_table);
92b96797 1480
26e5b65b
AM
1481static struct usb_driver vt6656_driver = {
1482 .name = DEVICE_NAME,
1483 .probe = vt6656_probe,
1484 .disconnect = vt6656_disconnect,
1485 .id_table = vt6656_table,
92b96797 1486#ifdef CONFIG_PM
26e5b65b
AM
1487 .suspend = vt6656_suspend,
1488 .resume = vt6656_resume,
1489#endif /* CONFIG_PM */
92b96797
FB
1490};
1491
bac2c126 1492module_usb_driver(vt6656_driver);
This page took 0.6882 seconds and 5 git commands to generate.