]> Git Repo - linux.git/blob - drivers/staging/vt6656/main_usb.c
clocksource: Exynos_mct: Use irq_force_affinity() in cpu bringup
[linux.git] / drivers / staging / vt6656 / main_usb.c
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * File: 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  *
29  *   vt6656_probe - module initial (insmod) driver entry
30  *   device_remove1 - module remove entry
31  *   device_open - allocate dma/descripter resource & initial mac/bbp function
32  *   device_xmit - asynchronous data tx function
33  *   device_set_multi - set mac filter
34  *   device_ioctl - ioctl entry
35  *   device_close - shutdown mac/bbp & free dma/descriptor resource
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
39  *   device_dma0_xmit- tx PS buffered frame via dma0
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
49 #include <linux/file.h>
50 #include "device.h"
51 #include "card.h"
52 #include "baseband.h"
53 #include "mac.h"
54 #include "tether.h"
55 #include "wmgr.h"
56 #include "wctl.h"
57 #include "power.h"
58 #include "wcmd.h"
59 #include "iocmd.h"
60 #include "tcrc.h"
61 #include "rxtx.h"
62 #include "bssdb.h"
63 #include "hostap.h"
64 #include "wpactl.h"
65 #include "iwctl.h"
66 #include "dpc.h"
67 #include "datarate.h"
68 #include "rf.h"
69 #include "firmware.h"
70 #include "control.h"
71 #include "channel.h"
72 #include "int.h"
73 #include "iowpa.h"
74
75 /* static int msglevel = MSG_LEVEL_DEBUG; */
76 static int          msglevel                =MSG_LEVEL_INFO;
77
78 /*
79  * define module options
80  */
81
82 /* version information */
83 #define DRIVER_AUTHOR \
84         "VIA Networking Technologies, Inc., <[email protected]>"
85 MODULE_AUTHOR(DRIVER_AUTHOR);
86 MODULE_LICENSE("GPL");
87 MODULE_DESCRIPTION(DEVICE_FULL_DRV_NAM);
88
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
94 #define RX_DESC_DEF0     64
95 DEVICE_PARAM(RxDescriptors0,"Number of receive usb desc buffer");
96
97 #define TX_DESC_DEF0     64
98 DEVICE_PARAM(TxDescriptors0,"Number of transmit usb desc buffer");
99
100 #define CHANNEL_DEF     6
101 DEVICE_PARAM(Channel, "Channel number");
102
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
110 DEVICE_PARAM(PreambleType, "Preamble Type");
111
112 #define RTS_THRESH_DEF     2347
113 DEVICE_PARAM(RTSThreshold, "RTS threshold");
114
115 #define FRAG_THRESH_DEF     2346
116 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
117
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
136 DEVICE_PARAM(ConnectionRate, "Connection data rate");
137
138 #define OP_MODE_DEF     0
139 DEVICE_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
147 /* PSMode[]
148    0: indicate disable power saving mode
149    1: indicate enable power saving mode
150 */
151
152 #define PS_MODE_DEF     0
153 DEVICE_PARAM(PSMode, "Power saving mode");
154
155 #define SHORT_RETRY_DEF     8
156 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
157
158 #define LONG_RETRY_DEF     4
159 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
160
161 /* BasebandType[] baseband type selected
162    0: indicate 802.11a type
163    1: indicate 802.11b type
164    2: indicate 802.11g type
165 */
166
167 #define BBP_TYPE_DEF     2
168 DEVICE_PARAM(BasebandType, "baseband type");
169
170 /* 80211hEnable[]
171    0: indicate disable 802.11h
172    1: indicate enable 802.11h
173 */
174
175 #define X80211h_MODE_DEF     0
176
177 DEVICE_PARAM(b80211hEnable, "802.11h mode");
178
179 /*
180  * Static vars definitions
181  */
182
183 static struct usb_device_id vt6656_table[] = {
184         {USB_DEVICE(VNT_USB_VENDOR_ID, VNT_USB_PRODUCT_ID)},
185         {}
186 };
187
188 /* frequency list (map channels to frequencies) */
189 /*
190 static 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
198 static const struct iw_handler_def      iwctl_handler_def;
199 */
200
201 static int vt6656_probe(struct usb_interface *intf,
202                         const struct usb_device_id *id);
203 static void vt6656_disconnect(struct usb_interface *intf);
204
205 #ifdef CONFIG_PM        /* Minimal support for suspend and resume */
206 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message);
207 static int vt6656_resume(struct usb_interface *intf);
208 #endif /* CONFIG_PM */
209
210 static struct net_device_stats *device_get_stats(struct net_device *dev);
211 static int  device_open(struct net_device *dev);
212 static int  device_xmit(struct sk_buff *skb, struct net_device *dev);
213 static void device_set_multi(struct net_device *dev);
214 static int  device_close(struct net_device *dev);
215 static int  device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
216
217 static int device_init_registers(struct vnt_private *pDevice);
218 static bool device_init_defrag_cb(struct vnt_private *pDevice);
219 static void device_init_diversity_timer(struct vnt_private *pDevice);
220 static int  device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
221
222 static int  ethtool_ioctl(struct net_device *dev, struct ifreq *);
223 static void device_free_tx_bufs(struct vnt_private *pDevice);
224 static void device_free_rx_bufs(struct vnt_private *pDevice);
225 static void device_free_int_bufs(struct vnt_private *pDevice);
226 static void device_free_frag_bufs(struct vnt_private *pDevice);
227 static bool device_alloc_bufs(struct vnt_private *pDevice);
228
229 static int Read_config_file(struct vnt_private *pDevice);
230 static unsigned char *Config_FileOperation(struct vnt_private *pDevice);
231 static int Config_FileGetParameter(unsigned char *string,
232                                    unsigned char *dest,
233                                    unsigned char *source);
234
235 static void usb_device_reset(struct vnt_private *pDevice);
236
237 static void
238 device_set_options(struct vnt_private *pDevice) {
239
240     u8    abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
241     u8    abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
242     u8 abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
243
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);
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;
259     pDevice->op_mode = NL80211_IFTYPE_UNSPECIFIED;
260     pDevice->uConnectionRate = DATA_RATE_DEF;
261     if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = true;
262     pDevice->byBBType = BBP_TYPE_DEF;
263     pDevice->byPacketType = pDevice->byBBType;
264     pDevice->byAutoFBCtrl = AUTO_FB_0;
265     pDevice->bUpdateBBVGA = true;
266     pDevice->byFOETuning = 0;
267     pDevice->byAutoPwrTunning = 0;
268     pDevice->byPreambleType = 0;
269     pDevice->bExistSWNetAddr = false;
270     /* pDevice->bDiversityRegCtlON = true; */
271     pDevice->bDiversityRegCtlON = false;
272 }
273
274 static void device_init_diversity_timer(struct vnt_private *pDevice)
275 {
276     init_timer(&pDevice->TimerSQ3Tmax1);
277     pDevice->TimerSQ3Tmax1.data = (unsigned long)pDevice;
278     pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
279     pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
280
281     init_timer(&pDevice->TimerSQ3Tmax2);
282     pDevice->TimerSQ3Tmax2.data = (unsigned long)pDevice;
283     pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
284     pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
285
286     init_timer(&pDevice->TimerSQ3Tmax3);
287     pDevice->TimerSQ3Tmax3.data = (unsigned long)pDevice;
288     pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerSQ3Tmax3CallBack;
289     pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
290
291     return;
292 }
293
294 /*
295  * initialization of MAC & BBP registers
296  */
297 static int device_init_registers(struct vnt_private *pDevice)
298 {
299         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
300         struct vnt_cmd_card_init *init_cmd = &pDevice->init_command;
301         struct vnt_rsp_card_init *init_rsp = &pDevice->init_response;
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;
308         int ntStatus = STATUS_SUCCESS;
309         u8 byTmp;
310         u8 byCalibTXIQ = 0, byCalibTXDC = 0, byCalibRXIQ = 0;
311
312         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---->INIbInitAdapter. [%d][%d]\n",
313                                 DEVICE_INIT_COLD, pDevice->byPacketType);
314
315         spin_lock_irq(&pDevice->lock);
316
317         memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
318         memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
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         }
342
343         init_cmd->init_class = DEVICE_INIT_COLD;
344         init_cmd->exist_sw_net_addr = (u8) pDevice->bExistSWNetAddr;
345         for (ii = 0; ii < 6; ii++)
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;
349
350         /* issue card_init command to device */
351         ntStatus = CONTROLnsRequestOut(pDevice,
352                 MESSAGE_TYPE_CARDINIT, 0, 0,
353                 sizeof(struct vnt_cmd_card_init), (u8 *)init_cmd);
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         }
359
360         ntStatus = CONTROLnsRequestIn(pDevice, MESSAGE_TYPE_INIT_RSP, 0, 0,
361                 sizeof(struct vnt_rsp_card_init), (u8 *)init_rsp);
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         }
368
369         /* local ID for AES functions */
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         }
377
378         /* do MACbSoftwareReset in MACvInitialize */
379
380         /* force CCK */
381         pDevice->bCCK = true;
382         pDevice->bProtectMode = false;
383         /* only used in 11g type, sync with ERP IE */
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         }
394
395         CHvInitChannelTable(pDevice);
396
397         pDevice->byTopOFDMBasicRate = RATE_24M;
398         pDevice->byTopCCKBasicRate = RATE_1M;
399         pDevice->byRevId = 0;
400         /* target to IF pin while programming to RF chip */
401         pDevice->byCurPwr = 0xFF;
402
403         pDevice->byCCKPwr = pDevice->abyEEPROM[EEP_OFS_PWR_CCK];
404         pDevice->byOFDMPwrG = pDevice->abyEEPROM[EEP_OFS_PWR_OFDMG];
405         /* load power table */
406         for (ii = 0; ii < 14; ii++) {
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;
412                 pDevice->abyOFDMPwrTbl[ii] =
413                                 pDevice->abyEEPROM[ii + EEP_OFS_OFDM_PWR_TBL];
414                 if (pDevice->abyOFDMPwrTbl[ii] == 0)
415                         pDevice->abyOFDMPwrTbl[ii] = pDevice->byOFDMPwrG;
416         }
417
418         /*
419          * original zonetype is USA, but custom zonetype is Europe,
420          * then need to recover 12, 13, 14 channels with 11 channel
421          */
422         if (((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
423                 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe)) &&
424                 (pDevice->byOriginalZonetype == ZoneType_USA)) {
425                 for (ii = 11; ii < 14; ii++) {
426                         pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
427                         pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
428                 }
429         }
430
431         pDevice->byOFDMPwrA = 0x34; /* same as RFbMA2829SelectChannel */
432
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         }
441
442         byAntenna = pDevice->abyEEPROM[EEP_OFS_ANTENNA];
443
444         if (byAntenna & EEP_ANTINV)
445                 pDevice->bTxRxAntInv = true;
446         else
447                 pDevice->bTxRxAntInv = false;
448
449         byAntenna &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
450
451         if (byAntenna == 0) /* if not set default is both */
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;
498
499         /* get Auto Fall Back type */
500         pDevice->byAutoFBCtrl = AUTO_FB_0;
501
502         /* set SCAN Time */
503         pDevice->uScanTime = WLAN_SCAN_MINITIME;
504
505         /* default Auto Mode */
506         /* pDevice->NetworkType = Ndis802_11Automode; */
507         pDevice->eConfigPHYMode = PHY_TYPE_AUTO;
508         pDevice->byBBType = BB_TYPE_11G;
509
510         /* initialize BBP registers */
511         pDevice->ulTxPower = 25;
512
513         /* get channel range */
514         pDevice->byMinChannel = 1;
515         pDevice->byMaxChannel = CB_MAX_CHANNEL;
516
517         /* get RFType */
518         pDevice->byRFType = init_rsp->rf_type;
519
520         if ((pDevice->byRFType & RF_EMU) != 0) {
521                 /* force change RevID for VT3253 emu */
522                 pDevice->byRevId = 0x80;
523         }
524
525         /* load vt3266 calibration parameters in EEPROM */
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) {
534                         /* CR255, enable TX/RX IQ and DC compensation mode */
535                                 ControlvWriteByte(pDevice,
536                                         MESSAGE_REQUEST_BBREG,
537                                         0xff,
538                                         0x03);
539                         /* CR251, TX I/Q Imbalance Calibration */
540                                 ControlvWriteByte(pDevice,
541                                         MESSAGE_REQUEST_BBREG,
542                                         0xfb,
543                                         byCalibTXIQ);
544                         /* CR252, TX DC-Offset Calibration */
545                                 ControlvWriteByte(pDevice,
546                                         MESSAGE_REQUEST_BBREG,
547                                         0xfC,
548                                         byCalibTXDC);
549                         /* CR253, RX I/Q Imbalance Calibration */
550                                 ControlvWriteByte(pDevice,
551                                         MESSAGE_REQUEST_BBREG,
552                                         0xfd,
553                                         byCalibRXIQ);
554                         } else {
555                         /* CR255, turn off BB Calibration compensation */
556                                 ControlvWriteByte(pDevice,
557                                         MESSAGE_REQUEST_BBREG,
558                                         0xff,
559                                         0x0);
560                         }
561                 }
562         }
563
564         pMgmt->eScanType = WMAC_SCAN_PASSIVE;
565         pMgmt->uCurrChannel = pDevice->uChannel;
566         pMgmt->uIBSSChannel = pDevice->uChannel;
567         CARDbSetMediaChannel(pDevice, pMgmt->uCurrChannel);
568
569         /* get permanent network address */
570         memcpy(pDevice->abyPermanentNetAddr, init_rsp->net_addr, 6);
571         memcpy(pDevice->abyCurrentNetAddr,
572                                 pDevice->abyPermanentNetAddr, ETH_ALEN);
573
574         /* if exist SW network address, use it */
575         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %pM\n",
576                 pDevice->abyCurrentNetAddr);
577
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;
643 }
644
645 #ifdef CONFIG_PM        /* Minimal support for suspend and resume */
646
647 static int vt6656_suspend(struct usb_interface *intf, pm_message_t message)
648 {
649         struct vnt_private *device = usb_get_intfdata(intf);
650
651         if (!device || !device->dev)
652                 return -ENODEV;
653
654         if (device->flags & DEVICE_FLAGS_OPENED)
655                 device_close(device->dev);
656
657         return 0;
658 }
659
660 static int vt6656_resume(struct usb_interface *intf)
661 {
662         struct vnt_private *device = usb_get_intfdata(intf);
663
664         if (!device || !device->dev)
665                 return -ENODEV;
666
667         if (!(device->flags & DEVICE_FLAGS_OPENED))
668                 device_open(device->dev);
669
670         return 0;
671 }
672
673 #endif /* CONFIG_PM */
674
675 static 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,
681     .ndo_set_rx_mode        = device_set_multi,
682 };
683
684 static int
685 vt6656_probe(struct usb_interface *intf, const struct usb_device_id *id)
686 {
687         u8 fake_mac[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
688         struct usb_device *udev = interface_to_usbdev(intf);
689         int rc = 0;
690         struct net_device *netdev = NULL;
691         struct vnt_private *pDevice;
692
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");
695
696         udev = usb_get_dev(udev);
697         netdev = alloc_etherdev(sizeof(struct vnt_private));
698         if (!netdev) {
699                 printk(KERN_ERR DEVICE_NAME ": allocate net device failed\n");
700                 rc = -ENOMEM;
701                 goto err_nomem;
702         }
703
704         pDevice = netdev_priv(netdev);
705         memset(pDevice, 0, sizeof(struct vnt_private));
706
707         pDevice->dev = netdev;
708         pDevice->usb = udev;
709
710         device_set_options(pDevice);
711         spin_lock_init(&pDevice->lock);
712         INIT_DELAYED_WORK(&pDevice->run_command_work, vRunCommand);
713         INIT_DELAYED_WORK(&pDevice->second_callback_work, BSSvSecondCallBack);
714         INIT_WORK(&pDevice->read_work_item, RXvWorkItem);
715         INIT_WORK(&pDevice->rx_mng_work_item, RXvMngWorkItem);
716
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");
720                 goto err_netdev;
721         }
722
723         pDevice->tx_80211 = device_dma0_tx_80211;
724         pDevice->vnt_mgmt.pAdapter = (void *) pDevice;
725
726         netdev->netdev_ops = &device_netdev_ops;
727         netdev->wireless_handlers =
728                 (struct iw_handler_def *) &iwctl_handler_def;
729
730         usb_set_intfdata(intf, pDevice);
731         SET_NETDEV_DEV(netdev, &intf->dev);
732         memcpy(pDevice->dev->dev_addr, fake_mac, ETH_ALEN);
733
734         usb_device_reset(pDevice);
735
736         rc = register_netdev(netdev);
737         if (rc) {
738                 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
739                 goto err_netdev;
740         }
741
742         return 0;
743
744 err_netdev:
745         free_netdev(netdev);
746 err_nomem:
747         usb_put_dev(udev);
748
749         return rc;
750 }
751
752 static void device_free_tx_bufs(struct vnt_private *priv)
753 {
754         struct vnt_usb_send_context *tx_context;
755         int ii;
756
757         for (ii = 0; ii < priv->cbTD; ii++) {
758                 tx_context = priv->apTD[ii];
759                 /* deallocate URBs */
760                 if (tx_context->pUrb) {
761                         usb_kill_urb(tx_context->pUrb);
762                         usb_free_urb(tx_context->pUrb);
763                 }
764
765                 kfree(tx_context);
766         }
767
768         return;
769 }
770
771 static void device_free_rx_bufs(struct vnt_private *priv)
772 {
773         struct vnt_rcb *rcb;
774         int ii;
775
776         for (ii = 0; ii < priv->cbRD; ii++) {
777                 rcb = priv->apRCB[ii];
778
779                 /* deallocate URBs */
780                 if (rcb->pUrb) {
781                         usb_kill_urb(rcb->pUrb);
782                         usb_free_urb(rcb->pUrb);
783                 }
784
785                 /* deallocate skb */
786                 if (rcb->skb)
787                         dev_kfree_skb(rcb->skb);
788         }
789
790         kfree(priv->pRCBMem);
791
792         return;
793 }
794
795 static void usb_device_reset(struct vnt_private *pDevice)
796 {
797  int status;
798  status = usb_reset_device(pDevice->usb);
799         if (status)
800             printk("usb_device_reset fail status=%d\n",status);
801         return ;
802 }
803
804 static void device_free_int_bufs(struct vnt_private *priv)
805 {
806         kfree(priv->int_buf.data_buf);
807
808         return;
809 }
810
811 static bool device_alloc_bufs(struct vnt_private *priv)
812 {
813         struct vnt_usb_send_context *tx_context;
814         struct vnt_rcb *rcb;
815         int ii;
816
817         for (ii = 0; ii < priv->cbTD; ii++) {
818                 tx_context = kmalloc(sizeof(struct vnt_usb_send_context),
819                                                                 GFP_KERNEL);
820                 if (tx_context == NULL) {
821                         DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
822                                 "%s : allocate tx usb context failed\n",
823                                         priv->dev->name);
824                         goto free_tx;
825                 }
826
827                 priv->apTD[ii] = tx_context;
828                 tx_context->pDevice = priv;
829
830                 /* allocate URBs */
831                 tx_context->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
832                 if (tx_context->pUrb == NULL) {
833                         DBG_PRT(MSG_LEVEL_ERR,
834                                 KERN_ERR "alloc tx urb failed\n");
835                         goto free_tx;
836                 }
837
838                 tx_context->bBoolInUse = false;
839         }
840
841         /* allocate RCB mem */
842         priv->pRCBMem = kzalloc((sizeof(struct vnt_rcb) * priv->cbRD),
843                                                                 GFP_KERNEL);
844         if (priv->pRCBMem == NULL) {
845                 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
846                         "%s : alloc rx usb context failed\n",
847                                 priv->dev->name);
848                 goto free_tx;
849         }
850
851         priv->FirstRecvFreeList = NULL;
852         priv->LastRecvFreeList = NULL;
853         priv->FirstRecvMngList = NULL;
854         priv->LastRecvMngList = NULL;
855         priv->NumRecvFreeList = 0;
856
857         rcb = (struct vnt_rcb *)priv->pRCBMem;
858
859         for (ii = 0; ii < priv->cbRD; ii++) {
860                 priv->apRCB[ii] = rcb;
861                 rcb->pDevice = priv;
862
863                 /* allocate URBs */
864                 rcb->pUrb = usb_alloc_urb(0, GFP_ATOMIC);
865                 if (rcb->pUrb == NULL) {
866                         DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
867                                 " Failed to alloc rx urb\n");
868                         goto free_rx_tx;
869                 }
870
871                 rcb->skb = netdev_alloc_skb(priv->dev, priv->rx_buf_sz);
872                 if (rcb->skb == NULL) {
873                         DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
874                                                 " Failed to alloc rx skb\n");
875                         goto free_rx_tx;
876                 }
877
878                 rcb->bBoolInUse = false;
879
880                 EnqueueRCB(priv->FirstRecvFreeList,
881                                                 priv->LastRecvFreeList, rcb);
882
883                 priv->NumRecvFreeList++;
884                 rcb++;
885         }
886
887         priv->pInterruptURB = usb_alloc_urb(0, GFP_ATOMIC);
888         if (priv->pInterruptURB == NULL) {
889                 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR"Failed to alloc int urb\n");
890                 goto free_rx_tx;
891         }
892
893         priv->int_buf.data_buf = kmalloc(MAX_INTERRUPT_SIZE, GFP_KERNEL);
894         if (priv->int_buf.data_buf == NULL) {
895                 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR"Failed to alloc int buf\n");
896                 usb_free_urb(priv->pInterruptURB);
897                 goto free_rx_tx;
898         }
899
900         return true;
901
902 free_rx_tx:
903         device_free_rx_bufs(priv);
904
905 free_tx:
906         device_free_tx_bufs(priv);
907
908         return false;
909 }
910
911 static bool device_init_defrag_cb(struct vnt_private *pDevice)
912 {
913         int i;
914         PSDeFragControlBlock pDeF;
915
916     /* Init the fragment ctl entries */
917     for (i = 0; i < CB_MAX_RX_FRAG; i++) {
918         pDeF = &(pDevice->sRxDFCB[i]);
919         if (!device_alloc_frag_buf(pDevice, pDeF)) {
920             DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
921                 pDevice->dev->name);
922             goto free_frag;
923         }
924     }
925     pDevice->cbDFCB = CB_MAX_RX_FRAG;
926     pDevice->cbFreeDFCB = pDevice->cbDFCB;
927     return true;
928
929 free_frag:
930     device_free_frag_bufs(pDevice);
931     return false;
932 }
933
934 static void device_free_frag_bufs(struct vnt_private *pDevice)
935 {
936         PSDeFragControlBlock pDeF;
937         int i;
938
939     for (i = 0; i < CB_MAX_RX_FRAG; i++) {
940
941         pDeF = &(pDevice->sRxDFCB[i]);
942
943         if (pDeF->skb)
944             dev_kfree_skb(pDeF->skb);
945     }
946 }
947
948 int device_alloc_frag_buf(struct vnt_private *pDevice,
949                 PSDeFragControlBlock pDeF)
950 {
951         pDeF->skb = netdev_alloc_skb(pDevice->dev, pDevice->rx_buf_sz);
952         if (!pDeF->skb)
953                 return false;
954
955         return true;
956 }
957
958 static int  device_open(struct net_device *dev)
959 {
960         struct vnt_private *pDevice = netdev_priv(dev);
961
962      pDevice->fWPA_Authened = false;
963
964     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_open...\n");
965
966     pDevice->rx_buf_sz = MAX_TOTAL_SIZE_WITH_ALL_HEADERS;
967
968     if (device_alloc_bufs(pDevice) == false) {
969         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " device_alloc_bufs fail... \n");
970         return -ENOMEM;
971     }
972
973     if (device_init_defrag_cb(pDevice)== false) {
974         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Initial defragment cb fail \n");
975         goto free_rx_tx;
976     }
977
978     MP_CLEAR_FLAG(pDevice, fMP_DISCONNECTED);
979     MP_CLEAR_FLAG(pDevice, fMP_CONTROL_READS);
980     MP_CLEAR_FLAG(pDevice, fMP_CONTROL_WRITES);
981     MP_SET_FLAG(pDevice, fMP_POST_READS);
982     MP_SET_FLAG(pDevice, fMP_POST_WRITES);
983
984     /* read config file */
985     Read_config_file(pDevice);
986
987         if (device_init_registers(pDevice) == false) {
988                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " init register fail\n");
989                 goto free_all;
990         }
991
992     /* init for key management */
993     KeyvInitTable(pDevice,&pDevice->sKey);
994         memcpy(pDevice->vnt_mgmt.abyMACAddr,
995                 pDevice->abyCurrentNetAddr, ETH_ALEN);
996     memcpy(pDevice->dev->dev_addr, pDevice->abyCurrentNetAddr, ETH_ALEN);
997     pDevice->bStopTx0Pkt = false;
998     pDevice->bStopDataPkt = false;
999     pDevice->bRoaming = false;
1000     pDevice->bIsRoaming = false;
1001     pDevice->bEnableRoaming = false;
1002     if (pDevice->bDiversityRegCtlON) {
1003         device_init_diversity_timer(pDevice);
1004     }
1005
1006     vMgrObjectInit(pDevice);
1007
1008         schedule_delayed_work(&pDevice->second_callback_work, HZ);
1009
1010         pDevice->int_interval = 1;  /* bInterval is set to 1 */
1011     pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1012
1013     pDevice->bIsRxWorkItemQueued = true;
1014
1015    pDevice->bWPADEVUp = false;
1016      pDevice->bwextstep0 = false;
1017      pDevice->bwextstep1 = false;
1018      pDevice->bwextstep2 = false;
1019      pDevice->bwextstep3 = false;
1020      pDevice->bWPASuppWextEnabled = false;
1021     pDevice->byReAssocCount = 0;
1022
1023         schedule_work(&pDevice->read_work_item);
1024     INTvWorkItem(pDevice);
1025
1026     /* if WEP key already set by iwconfig but device not yet open */
1027     if ((pDevice->bEncryptionEnable == true) && (pDevice->bTransmitKey == true)) {
1028          spin_lock_irq(&pDevice->lock);
1029          KeybSetDefaultKey( pDevice,
1030                             &(pDevice->sKey),
1031                             pDevice->byKeyIndex | (1 << 31),
1032                             pDevice->uKeyLength,
1033                             NULL,
1034                             pDevice->abyKey,
1035                             KEY_CTL_WEP
1036                           );
1037          spin_unlock_irq(&pDevice->lock);
1038          pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1039     }
1040
1041         if (pDevice->vnt_mgmt.eConfigMode == WMAC_CONFIG_AP)
1042                 bScheduleCommand((void *) pDevice, WLAN_CMD_RUN_AP, NULL);
1043         else
1044                 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1045
1046     netif_stop_queue(pDevice->dev);
1047     pDevice->flags |= DEVICE_FLAGS_OPENED;
1048
1049         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success..\n");
1050         return 0;
1051
1052 free_all:
1053     device_free_frag_bufs(pDevice);
1054 free_rx_tx:
1055     device_free_rx_bufs(pDevice);
1056     device_free_tx_bufs(pDevice);
1057     device_free_int_bufs(pDevice);
1058         usb_kill_urb(pDevice->pInterruptURB);
1059     usb_free_urb(pDevice->pInterruptURB);
1060
1061     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open fail.. \n");
1062     return -ENOMEM;
1063 }
1064
1065 static int device_close(struct net_device *dev)
1066 {
1067         struct vnt_private *pDevice = netdev_priv(dev);
1068         struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1069         int uu;
1070
1071         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close1\n");
1072     if (pDevice == NULL)
1073         return -ENODEV;
1074
1075     if (pDevice->bLinkPass) {
1076         bScheduleCommand((void *) pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1077         mdelay(30);
1078     }
1079
1080         memset(pMgmt->abyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
1081         pMgmt->bShareKeyAlgorithm = false;
1082         pDevice->bEncryptionEnable = false;
1083         pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
1084         spin_lock_irq(&pDevice->lock);
1085         for (uu = 0; uu < MAX_KEY_TABLE; uu++)
1086                 MACvDisableKeyEntry(pDevice,uu);
1087         spin_unlock_irq(&pDevice->lock);
1088
1089     if ((pDevice->flags & DEVICE_FLAGS_UNPLUG) == false) {
1090         MACbShutdown(pDevice);
1091     }
1092     netif_stop_queue(pDevice->dev);
1093     MP_SET_FLAG(pDevice, fMP_DISCONNECTED);
1094     MP_CLEAR_FLAG(pDevice, fMP_POST_WRITES);
1095     MP_CLEAR_FLAG(pDevice, fMP_POST_READS);
1096
1097         cancel_delayed_work_sync(&pDevice->run_command_work);
1098         cancel_delayed_work_sync(&pDevice->second_callback_work);
1099
1100     if (pDevice->bDiversityRegCtlON) {
1101         del_timer(&pDevice->TimerSQ3Tmax1);
1102         del_timer(&pDevice->TimerSQ3Tmax2);
1103         del_timer(&pDevice->TimerSQ3Tmax3);
1104     }
1105
1106         cancel_work_sync(&pDevice->rx_mng_work_item);
1107         cancel_work_sync(&pDevice->read_work_item);
1108
1109    pDevice->bRoaming = false;
1110    pDevice->bIsRoaming = false;
1111    pDevice->bEnableRoaming = false;
1112     pDevice->bCmdRunning = false;
1113     pDevice->bLinkPass = false;
1114     memset(pMgmt->abyCurrBSSID, 0, 6);
1115     pMgmt->eCurrState = WMAC_STATE_IDLE;
1116
1117         pDevice->flags &= ~DEVICE_FLAGS_OPENED;
1118
1119     device_free_tx_bufs(pDevice);
1120     device_free_rx_bufs(pDevice);
1121     device_free_int_bufs(pDevice);
1122     device_free_frag_bufs(pDevice);
1123
1124         usb_kill_urb(pDevice->pInterruptURB);
1125     usb_free_urb(pDevice->pInterruptURB);
1126
1127     BSSvClearNodeDBTable(pDevice, 0);
1128
1129     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close2 \n");
1130
1131     return 0;
1132 }
1133
1134 static void vt6656_disconnect(struct usb_interface *intf)
1135 {
1136         struct vnt_private *device = usb_get_intfdata(intf);
1137
1138         if (!device)
1139                 return;
1140
1141         usb_set_intfdata(intf, NULL);
1142         usb_put_dev(interface_to_usbdev(intf));
1143
1144         device->flags |= DEVICE_FLAGS_UNPLUG;
1145
1146         if (device->dev) {
1147                 unregister_netdev(device->dev);
1148
1149                 usb_kill_urb(device->pControlURB);
1150                 usb_free_urb(device->pControlURB);
1151
1152                 free_netdev(device->dev);
1153         }
1154 }
1155
1156 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1157 {
1158         struct vnt_private *pDevice = netdev_priv(dev);
1159
1160         spin_lock_irq(&pDevice->lock);
1161
1162         if (unlikely(pDevice->bStopTx0Pkt))
1163                 dev_kfree_skb_irq(skb);
1164         else
1165                 vDMA0_tx_80211(pDevice, skb);
1166
1167         spin_unlock_irq(&pDevice->lock);
1168
1169         return NETDEV_TX_OK;
1170 }
1171
1172 static int device_xmit(struct sk_buff *skb, struct net_device *dev)
1173 {
1174         struct vnt_private *pDevice = netdev_priv(dev);
1175         struct net_device_stats *stats = &pDevice->stats;
1176
1177         spin_lock_irq(&pDevice->lock);
1178
1179         netif_stop_queue(dev);
1180
1181         if (!pDevice->bLinkPass) {
1182                 dev_kfree_skb_irq(skb);
1183                 goto out;
1184         }
1185
1186         if (pDevice->bStopDataPkt) {
1187                 dev_kfree_skb_irq(skb);
1188                 stats->tx_dropped++;
1189                 goto out;
1190         }
1191
1192         if (nsDMA_tx_packet(pDevice, TYPE_AC0DMA, skb)) {
1193                 if (netif_queue_stopped(dev))
1194                         netif_wake_queue(dev);
1195         }
1196
1197 out:
1198         spin_unlock_irq(&pDevice->lock);
1199
1200         return NETDEV_TX_OK;
1201 }
1202
1203 /* find out the start position of str2 from str1 */
1204 static unsigned char *kstrstr(const unsigned char *str1,
1205                               const unsigned char *str2) {
1206   int str1_len = strlen(str1);
1207   int str2_len = strlen(str2);
1208
1209   while (str1_len >= str2_len) {
1210        str1_len--;
1211       if(memcmp(str1,str2,str2_len)==0)
1212         return (unsigned char *) str1;
1213         str1++;
1214   }
1215   return NULL;
1216 }
1217
1218 static int Config_FileGetParameter(unsigned char *string,
1219                                    unsigned char *dest,
1220                                    unsigned char *source)
1221 {
1222   unsigned char buf1[100];
1223   unsigned char buf2[100];
1224   unsigned char *start_p = NULL, *end_p = NULL, *tmp_p = NULL;
1225   int ii;
1226
1227     memset(buf1,0,100);
1228     strcat(buf1, string);
1229     strcat(buf1, "=");
1230     source+=strlen(buf1);
1231
1232     /* find target string start point */
1233     start_p = kstrstr(source,buf1);
1234     if (start_p == NULL)
1235         return false;
1236
1237     /* check if current config line is marked by "#" */
1238     for (ii = 1; ; ii++) {
1239         if (memcmp(start_p - ii, "\n", 1) == 0)
1240                 break;
1241         if (memcmp(start_p - ii, "#", 1) == 0)
1242                 return false;
1243     }
1244
1245     /* find target string end point */
1246      end_p = kstrstr(start_p,"\n");
1247      if (end_p == NULL) {       /* can't find "\n", but don't care */
1248              end_p = start_p + strlen(start_p);   /* no include "\n" */
1249      }
1250
1251    memset(buf2,0,100);
1252    memcpy(buf2, start_p, end_p-start_p); /* get the target line */
1253    buf2[end_p-start_p]='\0';
1254
1255    /* find value */
1256    start_p = kstrstr(buf2,"=");
1257    if (start_p == NULL)
1258       return false;
1259    memset(buf1,0,100);
1260    strcpy(buf1,start_p+1);
1261
1262    /* except space */
1263   tmp_p = buf1;
1264   while(*tmp_p != 0x00) {
1265         if(*tmp_p==' ')
1266             tmp_p++;
1267          else
1268           break;
1269   }
1270
1271    memcpy(dest,tmp_p,strlen(tmp_p));
1272  return true;
1273 }
1274
1275 /* if read fails, return NULL, or return data pointer */
1276 static unsigned char *Config_FileOperation(struct vnt_private *pDevice)
1277 {
1278         unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
1279         struct file   *file;
1280
1281         if (!buffer) {
1282                 printk("allocate mem for file fail?\n");
1283                 return NULL;
1284         }
1285
1286         file = filp_open(CONFIG_PATH, O_RDONLY, 0);
1287         if (IS_ERR(file)) {
1288                 kfree(buffer);
1289                 printk("Config_FileOperation file Not exist\n");
1290                 return NULL;
1291         }
1292
1293         if (kernel_read(file, 0, buffer, 1024) < 0) {
1294                 printk("read file error?\n");
1295                 kfree(buffer);
1296                 buffer = NULL;
1297         }
1298
1299         fput(file);
1300         return buffer;
1301 }
1302
1303 /* return --->-1:fail; >=0:successful */
1304 static int Read_config_file(struct vnt_private *pDevice)
1305 {
1306         int result = 0;
1307         unsigned char tmpbuffer[100];
1308         unsigned char *buffer = NULL;
1309
1310         /* init config setting */
1311  pDevice->config_file.ZoneType = -1;
1312  pDevice->config_file.eAuthenMode = -1;
1313  pDevice->config_file.eEncryptionStatus = -1;
1314
1315   buffer = Config_FileOperation(pDevice);
1316   if (buffer == NULL) {
1317      result =-1;
1318      return result;
1319   }
1320
1321 /* get zonetype */
1322 {
1323     memset(tmpbuffer,0,sizeof(tmpbuffer));
1324     if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer) ==true) {
1325     if(memcmp(tmpbuffer,"USA",3)==0) {
1326       pDevice->config_file.ZoneType=ZoneType_USA;
1327     }
1328     else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
1329       pDevice->config_file.ZoneType=ZoneType_Japan;
1330     }
1331     else if(memcmp(tmpbuffer,"EUROPE",6)==0) {
1332      pDevice->config_file.ZoneType=ZoneType_Europe;
1333     }
1334     else {
1335       printk("Unknown Zonetype[%s]?\n",tmpbuffer);
1336    }
1337  }
1338 }
1339
1340 /* get other parameter */
1341   {
1342         memset(tmpbuffer,0,sizeof(tmpbuffer));
1343        if(Config_FileGetParameter("AUTHENMODE",tmpbuffer,buffer)==true) {
1344          pDevice->config_file.eAuthenMode = (int) simple_strtol(tmpbuffer, NULL, 10);
1345        }
1346
1347         memset(tmpbuffer,0,sizeof(tmpbuffer));
1348        if(Config_FileGetParameter("ENCRYPTIONMODE",tmpbuffer,buffer)==true) {
1349          pDevice->config_file.eEncryptionStatus= (int) simple_strtol(tmpbuffer, NULL, 10);
1350        }
1351   }
1352
1353   kfree(buffer);
1354   return result;
1355 }
1356
1357 static void device_set_multi(struct net_device *dev)
1358 {
1359         struct vnt_private *priv = netdev_priv(dev);
1360         unsigned long flags;
1361
1362         if (priv->flags & DEVICE_FLAGS_OPENED) {
1363                 spin_lock_irqsave(&priv->lock, flags);
1364
1365                 bScheduleCommand(priv, WLAN_CMD_CONFIGURE_FILTER, NULL);
1366
1367                 spin_unlock_irqrestore(&priv->lock, flags);
1368         }
1369 }
1370
1371 void vnt_configure_filter(struct vnt_private *priv)
1372 {
1373         struct net_device *dev = priv->dev;
1374         struct vnt_manager *mgmt = &priv->vnt_mgmt;
1375         struct netdev_hw_addr *ha;
1376         u64 mc_filter = 0;
1377         u8 tmp = 0;
1378         int rc;
1379
1380         rc = CONTROLnsRequestIn(priv, MESSAGE_TYPE_READ,
1381                 MAC_REG_RCR, MESSAGE_REQUEST_MACREG, 1, &tmp);
1382         if (rc == 0)
1383                 priv->byRxMode = tmp;
1384
1385         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "priv->byRxMode in= %x\n",
1386                                                         priv->byRxMode);
1387
1388         if (dev->flags & IFF_PROMISC) { /* set promiscuous mode */
1389                 DBG_PRT(MSG_LEVEL_ERR, KERN_NOTICE
1390                         "%s: Promiscuous mode enabled.\n", dev->name);
1391                 /* unconditionally log net taps */
1392                 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
1393         } else if ((netdev_mc_count(dev) > priv->multicast_limit) ||
1394                         (dev->flags & IFF_ALLMULTI)) {
1395                 mc_filter = ~0x0;
1396                 MACvWriteMultiAddr(priv, mc_filter);
1397
1398                 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1399         } else {
1400                 netdev_for_each_mc_addr(ha, dev) {
1401                         int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1402
1403                         mc_filter |= 1ULL << (bit_nr & 0x3f);
1404                 }
1405
1406                 MACvWriteMultiAddr(priv, mc_filter);
1407
1408                 priv->byRxMode &= ~(RCR_UNICAST);
1409                 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1410         }
1411
1412         if (mgmt->eConfigMode == WMAC_CONFIG_AP) {
1413                 /*
1414                  * If AP mode, don't enable RCR_UNICAST since HW only compares
1415                  * addr1 with local MAC
1416                  */
1417                 priv->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
1418                 priv->byRxMode &= ~(RCR_UNICAST);
1419         }
1420
1421         ControlvWriteByte(priv, MESSAGE_REQUEST_MACREG,
1422                                         MAC_REG_RCR, priv->byRxMode);
1423
1424         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1425                                 "priv->byRxMode out= %x\n", priv->byRxMode);
1426 }
1427
1428 static struct net_device_stats *device_get_stats(struct net_device *dev)
1429 {
1430         struct vnt_private *pDevice = netdev_priv(dev);
1431
1432         return &pDevice->stats;
1433 }
1434
1435 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1436 {
1437         struct vnt_private *pDevice = netdev_priv(dev);
1438         struct iwreq *wrq = (struct iwreq *) rq;
1439         int rc = 0;
1440
1441         switch (cmd) {
1442
1443         case IOCTL_CMD_HOSTAPD:
1444
1445                 if (!(pDevice->flags & DEVICE_FLAGS_OPENED))
1446                         rc = -EFAULT;
1447
1448                 rc = vt6656_hostap_ioctl(pDevice, &wrq->u.data);
1449                 break;
1450
1451         case SIOCETHTOOL:
1452                 return ethtool_ioctl(dev, rq);
1453
1454         }
1455
1456         return rc;
1457 }
1458
1459 static int ethtool_ioctl(struct net_device *dev, struct ifreq *rq)
1460 {
1461         u32 ethcmd;
1462
1463         if (copy_from_user(&ethcmd, rq->ifr_data, sizeof(ethcmd)))
1464                 return -EFAULT;
1465
1466         switch (ethcmd) {
1467         case ETHTOOL_GDRVINFO: {
1468                 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
1469                 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
1470                 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
1471                 if (copy_to_user(rq->ifr_data, &info, sizeof(info)))
1472                         return -EFAULT;
1473                 return 0;
1474         }
1475
1476         }
1477
1478         return -EOPNOTSUPP;
1479 }
1480
1481 MODULE_DEVICE_TABLE(usb, vt6656_table);
1482
1483 static struct usb_driver vt6656_driver = {
1484         .name =         DEVICE_NAME,
1485         .probe =        vt6656_probe,
1486         .disconnect =   vt6656_disconnect,
1487         .id_table =     vt6656_table,
1488 #ifdef CONFIG_PM
1489         .suspend = vt6656_suspend,
1490         .resume = vt6656_resume,
1491 #endif /* CONFIG_PM */
1492 };
1493
1494 module_usb_driver(vt6656_driver);
This page took 0.11827 seconds and 4 git commands to generate.