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