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