2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
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.
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.
21 * Purpose: driver entry for initial, open, close, tx and rx.
29 * vt6655_probe - module initial (insmod) driver entry
30 * vt6655_remove - module remove entry
31 * vt6655_init_info - device structure resource allocation function
32 * device_free_info - device structure resource free function
33 * device_get_pci_info - get allocated pci io/mem resource
34 * device_print_info - print out resource
35 * device_open - allocate dma/descripter resource & initial mac/bbp function
36 * device_xmit - asynchrous data tx function
37 * device_intr - interrupt handle function
38 * device_set_multi - set mac filter
39 * device_ioctl - ioctl entry
40 * device_close - shutdown mac/bbp & free dma/descripter resource
41 * device_rx_srv - rx service function
42 * device_receive_frame - rx data function
43 * device_alloc_rx_buf - rx buffer pre-allocated function
44 * device_alloc_frag_buf - rx fragement pre-allocated function
45 * device_free_tx_buf - free tx buffer function
46 * device_free_frag_buf- free de-fragement buffer
47 * device_dma0_tx_80211- tx 802.11 frame via dma0
48 * device_dma0_xmit- tx PS bufferred frame via dma0
49 * device_init_rd0_ring- initial rd dma0 ring
50 * device_init_rd1_ring- initial rd dma1 ring
51 * device_init_td0_ring- initial tx dma0 ring buffer
52 * device_init_td1_ring- initial tx dma1 ring buffer
53 * device_init_registers- initial MAC & BBP & RF internal registers.
54 * device_init_rings- initial tx/rx ring buffer
55 * device_init_defrag_cb- initial & allocate de-fragement buffer.
56 * device_free_rings- free all allocated ring buffer
57 * device_tx_srv- tx interrupt service function
63 #include <linux/file.h>
87 #include <linux/delay.h>
88 #include <linux/kthread.h>
89 #include <linux/slab.h>
91 /*--------------------- Static Definitions -------------------------*/
92 static int msglevel = MSG_LEVEL_INFO;
95 // Define module options
97 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
98 MODULE_LICENSE("GPL");
99 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
101 static int mlme_kill;
103 #define DEVICE_PARAM(N, D)
105 #define RX_DESC_MIN0 16
106 #define RX_DESC_MAX0 128
107 #define RX_DESC_DEF0 32
108 DEVICE_PARAM(RxDescriptors0, "Number of receive descriptors0");
110 #define RX_DESC_MIN1 16
111 #define RX_DESC_MAX1 128
112 #define RX_DESC_DEF1 32
113 DEVICE_PARAM(RxDescriptors1, "Number of receive descriptors1");
115 #define TX_DESC_MIN0 16
116 #define TX_DESC_MAX0 128
117 #define TX_DESC_DEF0 32
118 DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
120 #define TX_DESC_MIN1 16
121 #define TX_DESC_MAX1 128
122 #define TX_DESC_DEF1 64
123 DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
125 #define IP_ALIG_DEF 0
126 /* IP_byte_align[] is used for IP header unsigned long byte aligned
127 0: indicate the IP header won't be unsigned long byte aligned.(Default) .
128 1: indicate the IP header will be unsigned long byte aligned.
129 In some environment, the IP header should be unsigned long byte aligned,
130 or the packet will be droped when we receive it. (eg: IPVS)
132 DEVICE_PARAM(IP_byte_align, "Enable IP header dword aligned");
134 #define INT_WORKS_DEF 20
135 #define INT_WORKS_MIN 10
136 #define INT_WORKS_MAX 64
138 DEVICE_PARAM(int_works, "Number of packets per interrupt services");
140 #define CHANNEL_MIN 1
141 #define CHANNEL_MAX 14
142 #define CHANNEL_DEF 6
144 DEVICE_PARAM(Channel, "Channel number");
146 /* PreambleType[] is the preamble length used for transmit.
147 0: indicate allows long preamble type
148 1: indicate allows short preamble type
151 #define PREAMBLE_TYPE_DEF 1
153 DEVICE_PARAM(PreambleType, "Preamble Type");
155 #define RTS_THRESH_MIN 512
156 #define RTS_THRESH_MAX 2347
157 #define RTS_THRESH_DEF 2347
159 DEVICE_PARAM(RTSThreshold, "RTS threshold");
161 #define FRAG_THRESH_MIN 256
162 #define FRAG_THRESH_MAX 2346
163 #define FRAG_THRESH_DEF 2346
165 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
167 #define DATA_RATE_MIN 0
168 #define DATA_RATE_MAX 13
169 #define DATA_RATE_DEF 13
171 0: indicate 1 Mbps 0x02
172 1: indicate 2 Mbps 0x04
173 2: indicate 5.5 Mbps 0x0B
174 3: indicate 11 Mbps 0x16
175 4: indicate 6 Mbps 0x0c
176 5: indicate 9 Mbps 0x12
177 6: indicate 12 Mbps 0x18
178 7: indicate 18 Mbps 0x24
179 8: indicate 24 Mbps 0x30
180 9: indicate 36 Mbps 0x48
181 10: indicate 48 Mbps 0x60
182 11: indicate 54 Mbps 0x6c
183 12: indicate 72 Mbps 0x90
184 13: indicate auto rate
187 DEVICE_PARAM(ConnectionRate, "Connection data rate");
189 #define OP_MODE_DEF 0
191 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
193 /* OpMode[] is used for transmit.
194 0: indicate infrastruct mode used
195 1: indicate adhoc mode used
196 2: indicate AP mode used
200 0: indicate disable power saving mode
201 1: indicate enable power saving mode
204 #define PS_MODE_DEF 0
206 DEVICE_PARAM(PSMode, "Power saving mode");
208 #define SHORT_RETRY_MIN 0
209 #define SHORT_RETRY_MAX 31
210 #define SHORT_RETRY_DEF 8
212 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
214 #define LONG_RETRY_MIN 0
215 #define LONG_RETRY_MAX 15
216 #define LONG_RETRY_DEF 4
218 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
220 /* BasebandType[] baseband type selected
221 0: indicate 802.11a type
222 1: indicate 802.11b type
223 2: indicate 802.11g type
225 #define BBP_TYPE_MIN 0
226 #define BBP_TYPE_MAX 2
227 #define BBP_TYPE_DEF 2
229 DEVICE_PARAM(BasebandType, "baseband type");
232 0: indicate disable 802.11h
233 1: indicate enable 802.11h
236 #define X80211h_MODE_DEF 0
238 DEVICE_PARAM(b80211hEnable, "802.11h mode");
241 0: indicate disable 802.11h
242 1: indicate enable 802.11h
245 #define DIVERSITY_ANT_DEF 0
247 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
250 // Static vars definitions
253 static int device_nics = 0;
254 static PSDevice pDevice_Infos = NULL;
255 static struct net_device *root_device_dev = NULL;
257 static CHIP_INFO chip_info_table[] = {
258 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
259 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
263 const struct pci_device_id vt6655_pci_id_table[] = {
264 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
268 /*--------------------- Static Functions --------------------------*/
270 static int vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent);
271 static void vt6655_init_info(struct pci_dev *pcid, PSDevice *ppDevice, PCHIP_INFO);
272 static void device_free_info(PSDevice pDevice);
273 static bool device_get_pci_info(PSDevice, struct pci_dev *pcid);
274 static void device_print_info(PSDevice pDevice);
275 static struct net_device_stats *device_get_stats(struct net_device *dev);
276 static void device_init_diversity_timer(PSDevice pDevice);
277 static int device_open(struct net_device *dev);
278 static int device_xmit(struct sk_buff *skb, struct net_device *dev);
279 static irqreturn_t device_intr(int irq, void *dev_instance);
280 static void device_set_multi(struct net_device *dev);
281 static int device_close(struct net_device *dev);
282 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
285 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
286 static int viawget_suspend(struct pci_dev *pcid, pm_message_t state);
287 static int viawget_resume(struct pci_dev *pcid);
288 struct notifier_block device_notifier = {
289 .notifier_call = device_notify_reboot,
295 static void device_init_rd0_ring(PSDevice pDevice);
296 static void device_init_rd1_ring(PSDevice pDevice);
297 static void device_init_defrag_cb(PSDevice pDevice);
298 static void device_init_td0_ring(PSDevice pDevice);
299 static void device_init_td1_ring(PSDevice pDevice);
301 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
302 //2008-0714<Add>by Mike Liu
303 static bool device_release_WPADEV(PSDevice pDevice);
305 static int ethtool_ioctl(struct net_device *dev, void *useraddr);
306 static int device_rx_srv(PSDevice pDevice, unsigned int uIdx);
307 static int device_tx_srv(PSDevice pDevice, unsigned int uIdx);
308 static bool device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pDesc);
309 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
310 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc);
311 static void device_free_td0_ring(PSDevice pDevice);
312 static void device_free_td1_ring(PSDevice pDevice);
313 static void device_free_rd0_ring(PSDevice pDevice);
314 static void device_free_rd1_ring(PSDevice pDevice);
315 static void device_free_rings(PSDevice pDevice);
316 static void device_free_frag_buf(PSDevice pDevice);
317 static int Config_FileGetParameter(unsigned char *string,
318 unsigned char *dest, unsigned char *source);
320 /*--------------------- Export Variables --------------------------*/
322 /*--------------------- Export Functions --------------------------*/
324 static char *get_chip_name(int chip_id)
327 for (i = 0; chip_info_table[i].name != NULL; i++)
328 if (chip_info_table[i].chip_id == chip_id)
330 return chip_info_table[i].name;
333 static void vt6655_remove(struct pci_dev *pcid)
335 PSDevice pDevice = pci_get_drvdata(pcid);
339 device_free_info(pDevice);
342 static void device_get_options(PSDevice pDevice, int index, char *devname)
344 POPTIONS pOpts = &(pDevice->sOpts);
346 pOpts->nRxDescs0 = RX_DESC_DEF0;
347 pOpts->nRxDescs1 = RX_DESC_DEF1;
348 pOpts->nTxDescs[0] = TX_DESC_DEF0;
349 pOpts->nTxDescs[1] = TX_DESC_DEF1;
350 pOpts->flags |= DEVICE_FLAGS_IP_ALIGN;
351 pOpts->int_works = INT_WORKS_DEF;
352 pOpts->rts_thresh = RTS_THRESH_DEF;
353 pOpts->frag_thresh = FRAG_THRESH_DEF;
354 pOpts->data_rate = DATA_RATE_DEF;
355 pOpts->channel_num = CHANNEL_DEF;
357 pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE;
358 pOpts->flags |= DEVICE_FLAGS_OP_MODE;
359 pOpts->short_retry = SHORT_RETRY_DEF;
360 pOpts->long_retry = LONG_RETRY_DEF;
361 pOpts->bbp_type = BBP_TYPE_DEF;
362 pOpts->flags |= DEVICE_FLAGS_80211h_MODE;
363 pOpts->flags |= DEVICE_FLAGS_DiversityANT;
367 device_set_options(PSDevice pDevice) {
368 unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
369 unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
370 unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
372 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
373 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
374 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
376 pDevice->uChannel = pDevice->sOpts.channel_num;
377 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
378 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
379 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
380 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
381 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
382 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
383 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
384 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
385 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
386 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
387 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
388 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = true;
389 pDevice->byBBType = pDevice->sOpts.bbp_type;
390 pDevice->byPacketType = pDevice->byBBType;
393 pDevice->byAutoFBCtrl = AUTO_FB_0;
395 pDevice->bUpdateBBVGA = true;
396 pDevice->byFOETuning = 0;
397 pDevice->wCTSDuration = 0;
398 pDevice->byPreambleType = 0;
400 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " uChannel= %d\n", (int)pDevice->uChannel);
401 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byOpMode= %d\n", (int)pDevice->byOpMode);
402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ePSMode= %d\n", (int)pDevice->ePSMode);
403 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
404 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
406 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byPreambleType= %d\n", (int)pDevice->byPreambleType);
407 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
409 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byBBType= %d\n", (int)pDevice->byBBType);
410 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pDevice->bDiversityRegCtlON= %d\n", (int)pDevice->bDiversityRegCtlON);
414 static void s_vCompleteCurrentMeasure(PSDevice pDevice, unsigned char byResult)
417 unsigned long dwDuration = 0;
418 unsigned char byRPI0 = 0;
420 for (ii = 1; ii < 8; ii++) {
421 pDevice->dwRPIs[ii] *= 255;
422 dwDuration |= *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
424 pDevice->dwRPIs[ii] /= dwDuration;
425 pDevice->abyRPIs[ii] = (unsigned char)pDevice->dwRPIs[ii];
426 byRPI0 += pDevice->abyRPIs[ii];
428 pDevice->abyRPIs[0] = (0xFF - byRPI0);
430 if (pDevice->uNumOfMeasureEIDs == 0) {
431 VNTWIFIbMeasureReport(pDevice->pMgmt,
433 pDevice->pCurrMeasureEID,
436 pDevice->byCCAFraction,
440 VNTWIFIbMeasureReport(pDevice->pMgmt,
442 pDevice->pCurrMeasureEID,
445 pDevice->byCCAFraction,
448 CARDbStartMeasure(pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
453 // Initialisation of MAC & BBP registers
456 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
459 unsigned char byValue;
460 unsigned char byValue1;
461 unsigned char byCCKPwrdBm = 0;
462 unsigned char byOFDMPwrdBm = 0;
464 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
465 MACbShutdown(pDevice->PortOffset);
466 BBvSoftwareReset(pDevice->PortOffset);
468 if ((InitType == DEVICE_INIT_COLD) ||
469 (InitType == DEVICE_INIT_DXPL)) {
470 // Do MACbSoftwareReset in MACvInitialize
471 MACbSoftwareReset(pDevice->PortOffset);
473 pDevice->bCCK = true;
474 pDevice->bAES = false;
475 pDevice->bProtectMode = false; //Only used in 11g type, sync with ERP IE
476 pDevice->bNonERPPresent = false;
477 pDevice->bBarkerPreambleMd = false;
478 pDevice->wCurrentRate = RATE_1M;
479 pDevice->byTopOFDMBasicRate = RATE_24M;
480 pDevice->byTopCCKBasicRate = RATE_1M;
482 pDevice->byRevId = 0; //Target to IF pin while programming to RF chip.
485 MACvInitialize(pDevice->PortOffset);
488 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
490 spin_lock_irq(&pDevice->lock);
491 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
493 spin_unlock_irq(&pDevice->lock);
497 pDevice->byMinChannel = 1;
498 pDevice->byMaxChannel = CB_MAX_CHANNEL;
501 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
502 if (byValue & EEP_ANTINV)
503 pDevice->bTxRxAntInv = true;
505 pDevice->bTxRxAntInv = false;
507 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
508 if (byValue == 0) // if not set default is All
509 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
511 pDevice->ulDiversityNValue = 100*260;
512 pDevice->ulDiversityMValue = 100*16;
514 pDevice->byTMax2 = 4;
515 pDevice->ulSQ3TH = 0;
516 pDevice->byTMax3 = 64;
518 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
519 pDevice->byAntennaCount = 2;
520 pDevice->byTxAntennaMode = ANT_B;
521 pDevice->dwTxAntennaSel = 1;
522 pDevice->dwRxAntennaSel = 1;
523 if (pDevice->bTxRxAntInv)
524 pDevice->byRxAntennaMode = ANT_A;
526 pDevice->byRxAntennaMode = ANT_B;
527 // chester for antenna
528 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
529 if ((byValue1 & 0x08) == 0)
530 pDevice->bDiversityEnable = false;
532 pDevice->bDiversityEnable = true;
534 pDevice->bDiversityEnable = false;
535 pDevice->byAntennaCount = 1;
536 pDevice->dwTxAntennaSel = 0;
537 pDevice->dwRxAntennaSel = 0;
538 if (byValue & EEP_ANTENNA_AUX) {
539 pDevice->byTxAntennaMode = ANT_A;
540 if (pDevice->bTxRxAntInv)
541 pDevice->byRxAntennaMode = ANT_B;
543 pDevice->byRxAntennaMode = ANT_A;
545 pDevice->byTxAntennaMode = ANT_B;
546 if (pDevice->bTxRxAntInv)
547 pDevice->byRxAntennaMode = ANT_A;
549 pDevice->byRxAntennaMode = ANT_B;
552 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
553 pDevice->bDiversityEnable, (int)pDevice->ulDiversityNValue, (int)pDevice->ulDiversityMValue, pDevice->byTMax, pDevice->byTMax2);
555 //2008-8-4 <add> by chester
557 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
558 zonetype = Config_FileOperation(pDevice, false, NULL);
559 if (zonetype >= 0) { //read zonetype file ok!
560 if ((zonetype == 0) &&
561 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x00)) { //for USA
562 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
563 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
564 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Init Zone Type :USA\n");
565 } else if ((zonetype == 1) &&
566 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x01)) { //for Japan
567 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
568 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
569 } else if ((zonetype == 2) &&
570 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x02)) { //for Europe
571 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
572 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
573 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Init Zone Type :Europe\n");
577 if (zonetype != pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
578 printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n", zonetype, pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
580 printk("Read Zonetype file success,use default zonetype setting[%02x]\n", zonetype);
583 printk("Read Zonetype file fail,use default zonetype setting[%02x]\n", SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
586 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
588 if ((pDevice->byRFType & RF_EMU) != 0) {
589 // force change RevID for VT3253 emu
590 pDevice->byRevId = 0x80;
593 pDevice->byRFType &= RF_MASK;
594 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
596 if (!pDevice->bZoneRegExist)
597 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
599 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
604 //Get Desire Power Value
605 pDevice->byCurPwr = 0xFF;
606 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
607 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
611 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
612 pDevice->abyCCKPwrTbl[ii + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
613 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
614 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
616 pDevice->abyOFDMPwrTbl[ii + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
617 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
618 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
620 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
621 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
623 //2008-8-4 <add> by chester
624 //recover 12,13 ,14channel for EUROPE by 11 channel
625 if (((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
626 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe)) &&
627 (pDevice->byOriginalZonetype == ZoneType_USA)) {
628 for (ii = 11; ii < 14; ii++) {
629 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
630 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
635 // Load OFDM A Power Table
636 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
637 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
638 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
640 init_channel_table((void *)pDevice);
642 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
643 MACvSelectPage1(pDevice->PortOffset);
644 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
645 MACvSelectPage0(pDevice->PortOffset);
648 // use relative tx timeout and 802.11i D4
649 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
651 // set performance parameter by registry
652 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
653 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
656 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
657 // enable TSF counter
658 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
660 // initialize BBP registers
661 BBbVT3253Init(pDevice);
663 if (pDevice->bUpdateBBVGA) {
664 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
665 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
666 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
668 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
669 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
671 pDevice->byCurrentCh = 0;
673 // Set BB and packet type at the same time.
674 // Set Short Slot Time, xIFS, and RSPINF.
675 if (pDevice->uConnectionRate == RATE_AUTO)
676 pDevice->wCurrentRate = RATE_54M;
678 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
681 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
682 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
684 pDevice->bRadioOff = false;
686 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
687 pDevice->bHWRadioOff = false;
689 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
691 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
692 //2008-4-14 <add> by chester for led issue
693 #ifdef FOR_LED_ON_NOTEBOOK
694 if (pDevice->byGPIO & GPIO0_DATA)
695 pDevice->bHWRadioOff = true;
697 if (!(pDevice->byGPIO & GPIO0_DATA))
698 pDevice->bHWRadioOff = false;
701 if (pDevice->bRadioControlOff)
702 CARDbRadioPowerOff(pDevice);
704 CARDbRadioPowerOn(pDevice);
706 if (((pDevice->byGPIO & GPIO0_DATA) && !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
707 (!(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV))) {
708 pDevice->bHWRadioOff = true;
711 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
712 CARDbRadioPowerOff(pDevice);
716 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
717 // get Permanent network address
718 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
719 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Network address = %pM\n",
720 pDevice->abyCurrentNetAddr);
723 CARDvSafeResetRx(pDevice);
725 CARDvSafeResetTx(pDevice);
727 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
728 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
730 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
733 MACvReceive0(pDevice->PortOffset);
734 MACvReceive1(pDevice->PortOffset);
737 MACvStart(pDevice->PortOffset);
739 netif_stop_queue(pDevice->dev);
742 static void device_init_diversity_timer(PSDevice pDevice) {
743 init_timer(&pDevice->TimerSQ3Tmax1);
744 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
745 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
746 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
748 init_timer(&pDevice->TimerSQ3Tmax2);
749 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
750 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
751 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
753 init_timer(&pDevice->TimerSQ3Tmax3);
754 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
755 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
756 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
761 static bool device_release_WPADEV(PSDevice pDevice)
763 viawget_wpa_header *wpahdr;
766 //send device close to wpa_supplicnat layer
767 if (pDevice->bWPADEVUp) {
768 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
769 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
770 wpahdr->resp_ie_len = 0;
771 wpahdr->req_ie_len = 0;
772 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
773 pDevice->skb->dev = pDevice->wpadev;
774 skb_reset_mac_header(pDevice->skb);
775 pDevice->skb->pkt_type = PACKET_HOST;
776 pDevice->skb->protocol = htons(ETH_P_802_2);
777 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
778 netif_rx(pDevice->skb);
779 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
781 while (pDevice->bWPADEVUp) {
782 set_current_state(TASK_UNINTERRUPTIBLE);
783 schedule_timeout(HZ / 20); //wait 50ms
792 static const struct net_device_ops device_netdev_ops = {
793 .ndo_open = device_open,
794 .ndo_stop = device_close,
795 .ndo_do_ioctl = device_ioctl,
796 .ndo_get_stats = device_get_stats,
797 .ndo_start_xmit = device_xmit,
798 .ndo_set_rx_mode = device_set_multi,
802 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
804 static bool bFirst = true;
805 struct net_device *dev = NULL;
806 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
809 if (device_nics++ >= MAX_UINTS) {
810 printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
814 dev = alloc_etherdev(sizeof(DEVICE_INFO));
816 pDevice = (PSDevice) netdev_priv(dev);
819 printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
823 // Chain it all together
824 SET_NETDEV_DEV(dev, &pcid->dev);
827 printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
828 printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
832 vt6655_init_info(pcid, &pDevice, pChip_info);
834 pDevice->next_module = root_device_dev;
835 root_device_dev = dev;
837 if (pci_enable_device(pcid)) {
838 device_free_info(pDevice);
841 dev->irq = pcid->irq;
844 printk("Before get pci_info memaddr is %x\n", pDevice->memaddr);
846 if (!device_get_pci_info(pDevice, pcid)) {
847 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
848 device_free_info(pDevice);
856 printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n", pDevice->memaddr, pDevice->ioaddr, pDevice->io_size);
868 for (i = 0; address[i]; i++) {
869 pci_read_config_dword(pcid, address[i], &bar);
870 printk("bar %d is %x\n", i, bar);
872 printk("bar %d not implemented\n", i);
875 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
878 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
879 len = len & ~(len - 1);
881 printk("IO space: len in IO %x, BAR %d\n", len, i);
883 len = bar & 0xFFFFFFF0;
886 printk("len in MEM %x, BAR %d\n", len, i);
894 pDevice->PortOffset = (unsigned long)ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
896 if (pDevice->PortOffset == 0) {
897 printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
898 device_free_info(pDevice);
902 rc = pci_request_regions(pcid, DEVICE_NAME);
904 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
905 device_free_info(pDevice);
909 dev->base_addr = pDevice->ioaddr;
913 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
914 printk("Before write: value is %x\n", value);
915 VNSvOutPortB(pDevice->PortOffset, value);
916 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
917 printk("After write: value is %x\n", value);
921 pDevice->PortOffset = pDevice->ioaddr;
924 if (!MACbSoftwareReset(pDevice->PortOffset)) {
925 printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
926 device_free_info(pDevice);
929 // initial to reload eeprom
930 MACvInitialize(pDevice->PortOffset);
931 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
933 device_get_options(pDevice, device_nics-1, dev->name);
934 device_set_options(pDevice);
935 //Mask out the options cannot be set to the chip
936 pDevice->sOpts.flags &= pChip_info->flags;
938 //Enable the chip specified capabilities
939 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
940 pDevice->tx_80211 = device_dma0_tx_80211;
941 pDevice->sMgmtObj.pAdapter = (void *)pDevice;
942 pDevice->pMgmt = &(pDevice->sMgmtObj);
944 dev->irq = pcid->irq;
945 dev->netdev_ops = &device_netdev_ops;
947 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
949 rc = register_netdev(dev);
951 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
952 device_free_info(pDevice);
955 device_print_info(pDevice);
956 pci_set_drvdata(pcid, pDevice);
960 static void device_print_info(PSDevice pDevice)
962 struct net_device *dev = pDevice->dev;
964 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n", dev->name, get_chip_name(pDevice->chip_id));
965 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%pM", dev->name, dev->dev_addr);
967 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IO=0x%lx ", (unsigned long)pDevice->ioaddr);
968 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IRQ=%d \n", pDevice->dev->irq);
970 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IO=0x%lx Mem=0x%lx ",
971 (unsigned long)pDevice->ioaddr, (unsigned long)pDevice->PortOffset);
972 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IRQ=%d \n", pDevice->dev->irq);
976 static void vt6655_init_info(struct pci_dev *pcid, PSDevice *ppDevice,
977 PCHIP_INFO pChip_info) {
980 memset(*ppDevice, 0, sizeof(DEVICE_INFO));
982 if (pDevice_Infos == NULL) {
983 pDevice_Infos = *ppDevice;
985 for (p = pDevice_Infos; p->next != NULL; p = p->next)
988 (*ppDevice)->prev = p;
991 (*ppDevice)->pcid = pcid;
992 (*ppDevice)->chip_id = pChip_info->chip_id;
993 (*ppDevice)->io_size = pChip_info->io_size;
994 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
995 (*ppDevice)->multicast_limit = 32;
997 spin_lock_init(&((*ppDevice)->lock));
1000 static bool device_get_pci_info(PSDevice pDevice, struct pci_dev *pcid) {
1003 unsigned int cis_addr;
1005 unsigned char pci_config[256];
1006 unsigned char value = 0x00;
1008 u16 max_lat = 0x0000;
1009 memset(pci_config, 0x00, 256);
1012 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
1013 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
1014 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
1015 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
1017 pci_set_master(pcid);
1019 pDevice->memaddr = pci_resource_start(pcid, 0);
1020 pDevice->ioaddr = pci_resource_start(pcid, 1);
1022 cis_addr = pci_resource_start(pcid, 2);
1024 pDevice->pcid = pcid;
1026 pci_read_config_byte(pcid, PCI_COMMAND, &b);
1027 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
1030 for (ii = 0; ii < 0xFF; ii++) {
1031 pci_read_config_byte(pcid, ii, &value);
1032 pci_config[ii] = value;
1034 for (ii = 0, j = 1; ii < 0x100; ii++, j++) {
1036 printk("%x:", pci_config[ii]);
1039 printk("%x:", pci_config[ii]);
1046 static void device_free_info(PSDevice pDevice) {
1048 struct net_device *dev = pDevice->dev;
1051 //2008-0714-01<Add>by chester
1052 device_release_WPADEV(pDevice);
1054 //2008-07-21-01<Add>by MikeLiu
1056 if (wpa_set_wpadev(pDevice, 0) != 0)
1057 printk("unregister wpadev fail?\n");
1059 if (pDevice_Infos == NULL)
1062 for (ptr = pDevice_Infos; ptr && (ptr != pDevice); ptr = ptr->next)
1065 if (ptr == pDevice) {
1066 if (ptr == pDevice_Infos)
1067 pDevice_Infos = ptr->next;
1069 ptr->prev->next = ptr->next;
1071 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
1076 vt6655_hostap_set_hostapd(pDevice, 0, 0);
1079 unregister_netdev(dev);
1081 if (pDevice->PortOffset)
1082 iounmap((void *)pDevice->PortOffset);
1085 pci_release_regions(pDevice->pcid);
1090 static bool device_init_rings(PSDevice pDevice) {
1093 /*allocate all RD/TD rings a single pool*/
1094 vir_pool = pci_alloc_consistent(pDevice->pcid,
1095 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1096 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1097 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1098 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1099 &pDevice->pool_dma);
1101 if (vir_pool == NULL) {
1102 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
1107 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1108 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1109 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1110 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1113 pDevice->aRD0Ring = vir_pool;
1114 pDevice->aRD1Ring = vir_pool +
1115 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1117 pDevice->rd0_pool_dma = pDevice->pool_dma;
1118 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1119 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1121 pDevice->tx0_bufs = pci_alloc_consistent(pDevice->pcid,
1122 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1123 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1124 CB_BEACON_BUF_SIZE +
1126 &pDevice->tx_bufs_dma0);
1128 if (pDevice->tx0_bufs == NULL) {
1129 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
1130 pci_free_consistent(pDevice->pcid,
1131 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1132 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1133 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1134 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1135 vir_pool, pDevice->pool_dma
1140 memset(pDevice->tx0_bufs, 0,
1141 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1142 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1143 CB_BEACON_BUF_SIZE +
1147 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1148 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1150 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1151 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1153 // vir_pool: pvoid type
1154 pDevice->apTD0Rings = vir_pool
1155 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1156 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1158 pDevice->apTD1Rings = vir_pool
1159 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1160 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1161 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1163 pDevice->tx1_bufs = pDevice->tx0_bufs +
1164 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1166 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1167 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1169 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1172 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1173 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1175 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1176 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1181 static void device_free_rings(PSDevice pDevice) {
1182 pci_free_consistent(pDevice->pcid,
1183 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1184 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1185 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1186 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1188 pDevice->aRD0Ring, pDevice->pool_dma
1191 if (pDevice->tx0_bufs)
1192 pci_free_consistent(pDevice->pcid,
1193 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1194 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1195 CB_BEACON_BUF_SIZE +
1197 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1201 static void device_init_rd0_ring(PSDevice pDevice) {
1203 dma_addr_t curr = pDevice->rd0_pool_dma;
1206 /* Init the RD0 ring entries */
1207 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1208 pDesc = &(pDevice->aRD0Ring[i]);
1209 pDesc->pRDInfo = alloc_rd_info();
1210 ASSERT(pDesc->pRDInfo);
1211 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1212 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc rx bufs\n",
1213 pDevice->dev->name);
1215 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1216 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1217 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1221 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1222 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1225 static void device_init_rd1_ring(PSDevice pDevice) {
1227 dma_addr_t curr = pDevice->rd1_pool_dma;
1230 /* Init the RD1 ring entries */
1231 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1232 pDesc = &(pDevice->aRD1Ring[i]);
1233 pDesc->pRDInfo = alloc_rd_info();
1234 ASSERT(pDesc->pRDInfo);
1235 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1236 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc rx bufs\n",
1237 pDevice->dev->name);
1239 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1240 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1241 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1245 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1246 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1249 static void device_init_defrag_cb(PSDevice pDevice) {
1251 PSDeFragControlBlock pDeF;
1253 /* Init the fragment ctl entries */
1254 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1255 pDeF = &(pDevice->sRxDFCB[i]);
1256 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1257 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc frag bufs\n",
1258 pDevice->dev->name);
1261 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1262 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1265 static void device_free_rd0_ring(PSDevice pDevice) {
1268 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1269 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
1270 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1272 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1273 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1275 dev_kfree_skb(pRDInfo->skb);
1277 kfree((void *)pDesc->pRDInfo);
1281 static void device_free_rd1_ring(PSDevice pDevice) {
1284 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1285 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
1286 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1288 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1289 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1291 dev_kfree_skb(pRDInfo->skb);
1293 kfree((void *)pDesc->pRDInfo);
1297 static void device_free_frag_buf(PSDevice pDevice) {
1298 PSDeFragControlBlock pDeF;
1301 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1302 pDeF = &(pDevice->sRxDFCB[i]);
1305 dev_kfree_skb(pDeF->skb);
1310 static void device_init_td0_ring(PSDevice pDevice) {
1315 curr = pDevice->td0_pool_dma;
1316 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1317 pDesc = &(pDevice->apTD0Rings[i]);
1318 pDesc->pTDInfo = alloc_td_info();
1319 ASSERT(pDesc->pTDInfo);
1320 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1321 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1322 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1324 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1325 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1326 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1330 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1331 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1334 static void device_init_td1_ring(PSDevice pDevice) {
1339 /* Init the TD ring entries */
1340 curr = pDevice->td1_pool_dma;
1341 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
1342 pDesc = &(pDevice->apTD1Rings[i]);
1343 pDesc->pTDInfo = alloc_td_info();
1344 ASSERT(pDesc->pTDInfo);
1345 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1346 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
1347 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
1349 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
1350 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1351 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1355 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1356 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1359 static void device_free_td0_ring(PSDevice pDevice) {
1361 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1362 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
1363 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1365 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1366 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1367 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1370 dev_kfree_skb(pTDInfo->skb);
1372 kfree((void *)pDesc->pTDInfo);
1376 static void device_free_td1_ring(PSDevice pDevice) {
1379 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1380 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
1381 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1383 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1384 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1385 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1388 dev_kfree_skb(pTDInfo->skb);
1390 kfree((void *)pDesc->pTDInfo);
1394 /*-----------------------------------------------------------------*/
1396 static int device_rx_srv(PSDevice pDevice, unsigned int uIdx) {
1400 for (pRD = pDevice->pCurrRD[uIdx];
1401 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1405 if (device_receive_frame(pDevice, pRD)) {
1406 if (!device_alloc_rx_buf(pDevice, pRD)) {
1407 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1408 "%s: can not allocate rx buf\n", pDevice->dev->name);
1412 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1413 pDevice->dev->last_rx = jiffies;
1416 pDevice->pCurrRD[uIdx] = pRD;
1421 static bool device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD) {
1422 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1424 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1425 if (pRDInfo->skb == NULL)
1427 ASSERT(pRDInfo->skb);
1428 pRDInfo->skb->dev = pDevice->dev;
1429 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
1430 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1431 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1433 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1434 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1435 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1436 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1441 bool device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
1442 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1443 if (pDeF->skb == NULL)
1446 pDeF->skb->dev = pDevice->dev;
1451 static int device_tx_srv(PSDevice pDevice, unsigned int uIdx) {
1455 unsigned char byTsr0;
1456 unsigned char byTsr1;
1457 unsigned int uFrameSize, uFIFOHeaderSize;
1458 PSTxBufHead pTxBufHead;
1459 struct net_device_stats *pStats = &pDevice->stats;
1460 struct sk_buff *skb;
1461 unsigned int uNodeIndex;
1462 PSMgmtObject pMgmt = pDevice->pMgmt;
1464 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1465 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1470 byTsr0 = pTD->m_td0TD0.byTSR0;
1471 byTsr1 = pTD->m_td0TD0.byTSR1;
1473 //Only the status of first TD in the chain is correct
1474 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1475 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1476 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1477 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1478 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1479 // Update the statistics based on the Transmit status
1480 // now, we DONT check TSR0_CDH
1482 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1484 (unsigned char *)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1487 BSSvUpdateNodeTxCounter(pDevice,
1489 (unsigned char *)(pTD->pTDInfo->buf),
1493 if (!(byTsr1 & TSR1_TERR)) {
1495 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1496 (int)uIdx, byTsr1, byTsr0);
1498 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG)
1499 pDevice->s802_11Counter.TransmittedFragmentCount++;
1501 pStats->tx_packets++;
1502 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1504 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1505 (int)uIdx, byTsr1, byTsr0);
1506 pStats->tx_errors++;
1507 pStats->tx_dropped++;
1511 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1512 if (pDevice->bEnableHostapd) {
1513 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif.. \n");
1514 skb = pTD->pTDInfo->skb;
1515 skb->dev = pDevice->apdev;
1516 skb_reset_mac_header(skb);
1517 skb->pkt_type = PACKET_OTHERHOST;
1518 memset(skb->cb, 0, sizeof(skb->cb));
1523 if (byTsr1 & TSR1_TERR) {
1524 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1525 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1526 (int)uIdx, byTsr1, byTsr0);
1530 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1531 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1532 unsigned short wAID;
1533 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1535 skb = pTD->pTDInfo->skb;
1536 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1537 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1538 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1539 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1541 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1542 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1543 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1544 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1545 , (int)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1546 pStats->tx_errors--;
1547 pStats->tx_dropped--;
1552 device_free_tx_buf(pDevice, pTD);
1553 pDevice->iTDUsed[uIdx]--;
1557 if (uIdx == TYPE_AC0DMA) {
1558 // RESERV_AC0DMA reserved for relay
1560 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1562 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
1564 if (netif_queue_stopped(pDevice->dev) && !bFull)
1565 netif_wake_queue(pDevice->dev);
1569 pDevice->apTailTD[uIdx] = pTD;
1574 static void device_error(PSDevice pDevice, unsigned short status) {
1575 if (status & ISR_FETALERR) {
1576 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1577 "%s: Hardware fatal error.\n",
1578 pDevice->dev->name);
1579 netif_stop_queue(pDevice->dev);
1580 del_timer(&pDevice->sTimerCommand);
1581 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1582 pDevice->bCmdRunning = false;
1583 MACbShutdown(pDevice->PortOffset);
1588 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc) {
1589 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1590 struct sk_buff *skb = pTDInfo->skb;
1592 // pre-allocated buf_dma can't be unmapped.
1593 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1594 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1598 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1599 dev_kfree_skb_irq(skb);
1601 pTDInfo->skb_dma = 0;
1603 pTDInfo->byFlags = 0;
1607 void InitRxManagementQueue(PSDevice pDevice)
1609 pDevice->rxManeQueue.packet_num = 0;
1610 pDevice->rxManeQueue.head = pDevice->rxManeQueue.tail = 0;
1618 PSDevice pDevice = (PSDevice) Context;
1619 PSRxMgmtPacket pRxMgmtPacket;
1622 spin_lock_irq(&pDevice->lock);
1623 while (pDevice->rxManeQueue.packet_num != 0) {
1624 pRxMgmtPacket = DeQueue(pDevice);
1625 vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
1627 spin_unlock_irq(&pDevice->lock);
1639 static int device_open(struct net_device *dev) {
1640 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1642 #ifdef WPA_SM_Transtatus
1643 extern SWPAResult wpa_Result;
1646 pDevice->rx_buf_sz = PKT_BUF_SZ;
1647 if (!device_init_rings(pDevice))
1650 //2008-5-13 <add> by chester
1651 i = request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1655 #ifdef WPA_SM_Transtatus
1656 memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname));
1657 wpa_Result.proto = 0;
1658 wpa_Result.key_mgmt = 0;
1659 wpa_Result.eap_type = 0;
1660 wpa_Result.authenticated = false;
1661 pDevice->fWPA_Authened = false;
1663 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
1664 device_init_rd0_ring(pDevice);
1665 device_init_rd1_ring(pDevice);
1666 device_init_defrag_cb(pDevice);
1667 device_init_td0_ring(pDevice);
1668 device_init_td1_ring(pDevice);
1670 if (pDevice->bDiversityRegCtlON)
1671 device_init_diversity_timer(pDevice);
1673 vMgrObjectInit(pDevice);
1674 vMgrTimerInit(pDevice);
1678 tasklet_init(&pDevice->RxMngWorkItem, (void *)MngWorkItem, (unsigned long)pDevice);
1681 InitRxManagementQueue(pDevice);
1683 mlme_task = kthread_run(MlmeThread, (void *)pDevice, "MLME");
1684 if (IS_ERR(mlme_task)) {
1685 printk("thread create fail\n");
1692 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
1693 device_init_registers(pDevice, DEVICE_INIT_COLD);
1694 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1695 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN);
1696 device_set_multi(pDevice->dev);
1698 // Init for Key Management
1699 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1700 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1702 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1703 pDevice->bwextcount = 0;
1704 pDevice->bWPASuppWextEnabled = false;
1706 pDevice->byReAssocCount = 0;
1707 pDevice->bWPADEVUp = false;
1708 // Patch: if WEP key already set by iwconfig but device not yet open
1709 if (pDevice->bEncryptionEnable && pDevice->bTransmitKey) {
1710 KeybSetDefaultKey(&(pDevice->sKey),
1711 (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
1712 pDevice->uKeyLength,
1716 pDevice->PortOffset,
1719 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1722 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
1723 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1725 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1726 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
1728 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1729 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1731 pDevice->flags |= DEVICE_FLAGS_OPENED;
1733 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
1737 static int device_close(struct net_device *dev) {
1738 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1739 PSMgmtObject pMgmt = pDevice->pMgmt;
1745 //2007-1121-02<Add>by EinsnLiu
1746 if (pDevice->bLinkPass) {
1747 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1751 del_timer(&pDevice->sTimerTxData);
1753 del_timer(&pDevice->sTimerCommand);
1754 del_timer(&pMgmt->sTimerSecondCallback);
1755 if (pDevice->bDiversityRegCtlON) {
1756 del_timer(&pDevice->TimerSQ3Tmax1);
1757 del_timer(&pDevice->TimerSQ3Tmax2);
1758 del_timer(&pDevice->TimerSQ3Tmax3);
1762 tasklet_kill(&pDevice->RxMngWorkItem);
1764 netif_stop_queue(dev);
1765 pDevice->bCmdRunning = false;
1766 MACbShutdown(pDevice->PortOffset);
1767 MACbSoftwareReset(pDevice->PortOffset);
1768 CARDbRadioPowerOff(pDevice);
1770 pDevice->bLinkPass = false;
1771 memset(pMgmt->abyCurrBSSID, 0, 6);
1772 pMgmt->eCurrState = WMAC_STATE_IDLE;
1773 device_free_td0_ring(pDevice);
1774 device_free_td1_ring(pDevice);
1775 device_free_rd0_ring(pDevice);
1776 device_free_rd1_ring(pDevice);
1777 device_free_frag_buf(pDevice);
1778 device_free_rings(pDevice);
1779 BSSvClearNodeDBTable(pDevice, 0);
1780 free_irq(dev->irq, dev);
1781 pDevice->flags &= (~DEVICE_FLAGS_OPENED);
1782 //2008-0714-01<Add>by chester
1783 device_release_WPADEV(pDevice);
1785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close.. \n");
1789 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
1790 PSDevice pDevice = netdev_priv(dev);
1791 unsigned char *pbMPDU;
1792 unsigned int cbMPDULen = 0;
1794 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
1795 spin_lock_irq(&pDevice->lock);
1797 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1798 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
1799 dev_kfree_skb_irq(skb);
1800 spin_unlock_irq(&pDevice->lock);
1804 if (pDevice->bStopTx0Pkt) {
1805 dev_kfree_skb_irq(skb);
1806 spin_unlock_irq(&pDevice->lock);
1810 cbMPDULen = skb->len;
1813 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
1815 spin_unlock_irq(&pDevice->lock);
1820 bool device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, unsigned int uNodeIndex) {
1821 PSMgmtObject pMgmt = pDevice->pMgmt;
1822 PSTxDesc pHeadTD, pLastTD;
1823 unsigned int cbFrameBodySize;
1824 unsigned int uMACfragNum;
1825 unsigned char byPktType;
1826 bool bNeedEncryption = false;
1827 PSKeyItem pTransmitKey = NULL;
1828 unsigned int cbHeaderSize;
1832 if (pDevice->bStopTx0Pkt) {
1833 dev_kfree_skb_irq(skb);
1837 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1838 dev_kfree_skb_irq(skb);
1839 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
1843 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1844 if (pDevice->uAssocCount == 0) {
1845 dev_kfree_skb_irq(skb);
1846 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
1851 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
1853 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1855 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1856 cbFrameBodySize = skb->len - ETH_HLEN;
1859 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1860 cbFrameBodySize += 8;
1862 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
1864 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
1865 dev_kfree_skb_irq(skb);
1868 byPktType = (unsigned char)pDevice->byPacketType;
1870 if (pDevice->bFixRate) {
1871 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
1872 if (pDevice->uConnectionRate >= RATE_11M)
1873 pDevice->wCurrentRate = RATE_11M;
1875 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1877 if (pDevice->uConnectionRate >= RATE_54M)
1878 pDevice->wCurrentRate = RATE_54M;
1880 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1883 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1887 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1888 pDevice->byPreambleType = pDevice->byShortPreamble;
1890 pDevice->byPreambleType = PREAMBLE_LONG;
1892 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
1894 if (pDevice->wCurrentRate <= RATE_11M) {
1895 byPktType = PK_TYPE_11B;
1896 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1897 byPktType = PK_TYPE_11A;
1899 if (pDevice->bProtectMode)
1900 byPktType = PK_TYPE_11GB;
1902 byPktType = PK_TYPE_11GA;
1905 if (pDevice->bEncryptionEnable)
1906 bNeedEncryption = true;
1908 if (pDevice->bEnableHostWEP) {
1909 pTransmitKey = &STempKey;
1910 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1911 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1912 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1913 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1914 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1915 memcpy(pTransmitKey->abyKey,
1916 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1917 pTransmitKey->uKeyLength
1920 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
1921 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
1922 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
1927 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1929 MACbPSWakeup(pDevice->PortOffset);
1932 pDevice->bPWBitOn = false;
1935 for (ii = 0; ii < uMACfragNum; ii++) {
1936 // Poll Transmit the adapter
1938 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
1940 if (ii == (uMACfragNum - 1))
1942 pHeadTD = pHeadTD->next;
1945 // Save the information needed by the tx interrupt handler
1946 // to complete the Send request
1947 pLastTD->pTDInfo->skb = skb;
1948 pLastTD->pTDInfo->byFlags = 0;
1949 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
1951 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
1953 MACvTransmit0(pDevice->PortOffset);
1958 //TYPE_AC0DMA data tx
1959 static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
1960 PSDevice pDevice = netdev_priv(dev);
1962 PSMgmtObject pMgmt = pDevice->pMgmt;
1963 PSTxDesc pHeadTD, pLastTD;
1964 unsigned int uNodeIndex = 0;
1965 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1966 unsigned short wAID;
1967 unsigned int uMACfragNum = 1;
1968 unsigned int cbFrameBodySize;
1969 unsigned char byPktType;
1970 unsigned int cbHeaderSize;
1971 bool bNeedEncryption = false;
1972 PSKeyItem pTransmitKey = NULL;
1975 bool bTKIP_UseGTK = false;
1976 bool bNeedDeAuth = false;
1977 unsigned char *pbyBSSID;
1978 bool bNodeExist = false;
1980 spin_lock_irq(&pDevice->lock);
1981 if (!pDevice->bLinkPass) {
1982 dev_kfree_skb_irq(skb);
1983 spin_unlock_irq(&pDevice->lock);
1987 if (pDevice->bStopDataPkt) {
1988 dev_kfree_skb_irq(skb);
1989 spin_unlock_irq(&pDevice->lock);
1993 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1994 if (pDevice->uAssocCount == 0) {
1995 dev_kfree_skb_irq(skb);
1996 spin_unlock_irq(&pDevice->lock);
1999 if (is_multicast_ether_addr((unsigned char *)(skb->data))) {
2002 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2003 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2004 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2006 pMgmt->abyPSTxMap[0] |= byMask[0];
2007 spin_unlock_irq(&pDevice->lock);
2011 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
2012 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2013 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2014 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2016 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2017 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2018 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2019 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2020 spin_unlock_irq(&pDevice->lock);
2024 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
2025 pDevice->byPreambleType = pDevice->byShortPreamble;
2027 pDevice->byPreambleType = PREAMBLE_LONG;
2035 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Unknown STA not found in node DB \n");
2036 dev_kfree_skb_irq(skb);
2037 spin_unlock_irq(&pDevice->lock);
2042 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
2044 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2046 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
2047 cbFrameBodySize = skb->len - ETH_HLEN;
2049 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
2050 cbFrameBodySize += 8;
2052 if (pDevice->bEncryptionEnable) {
2053 bNeedEncryption = true;
2056 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2057 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2058 pbyBSSID = pDevice->abyBSSID;
2060 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
2062 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2063 bTKIP_UseGTK = true;
2064 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
2068 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get PTK.\n");
2071 } else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2072 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2073 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "IBSS Serach Key: \n");
2074 for (ii = 0; ii < 6; ii++)
2075 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "%x \n", *(pbyBSSID+ii));
2076 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "\n");
2079 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
2083 pbyBSSID = pDevice->abyBroadcastAddr;
2084 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2085 pTransmitKey = NULL;
2086 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
2087 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2089 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2091 bTKIP_UseGTK = true;
2092 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
2097 if (pDevice->bEnableHostWEP) {
2098 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "acdma0: STA index %d\n", uNodeIndex);
2099 if (pDevice->bEncryptionEnable) {
2100 pTransmitKey = &STempKey;
2101 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2102 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2103 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2104 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2105 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2106 memcpy(pTransmitKey->abyKey,
2107 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2108 pTransmitKey->uKeyLength
2113 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2115 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2116 DBG_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
2117 dev_kfree_skb_irq(skb);
2118 spin_unlock_irq(&pDevice->lock);
2122 if (pTransmitKey != NULL) {
2123 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2124 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2125 uMACfragNum = 1; //WEP256 doesn't support fragment
2129 byPktType = (unsigned char)pDevice->byPacketType;
2131 if (pDevice->bFixRate) {
2133 printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n", pDevice->eCurrentPHYType, pDevice->uConnectionRate);
2136 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2137 if (pDevice->uConnectionRate >= RATE_11M)
2138 pDevice->wCurrentRate = RATE_11M;
2140 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2142 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2143 (pDevice->uConnectionRate <= RATE_6M)) {
2144 pDevice->wCurrentRate = RATE_6M;
2146 if (pDevice->uConnectionRate >= RATE_54M)
2147 pDevice->wCurrentRate = RATE_54M;
2149 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2153 pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate;
2154 pDevice->byTopCCKBasicRate = RATE_1M;
2155 pDevice->byTopOFDMBasicRate = RATE_6M;
2158 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2159 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2160 pDevice->wCurrentRate = RATE_1M;
2161 pDevice->byACKRate = RATE_1M;
2162 pDevice->byTopCCKBasicRate = RATE_1M;
2163 pDevice->byTopOFDMBasicRate = RATE_6M;
2165 pDevice->wCurrentRate = RATE_6M;
2166 pDevice->byACKRate = RATE_6M;
2167 pDevice->byTopCCKBasicRate = RATE_1M;
2168 pDevice->byTopOFDMBasicRate = RATE_6M;
2171 VNTWIFIvGetTxRate(pDevice->pMgmt,
2172 pDevice->sTxEthHeader.abyDstAddr,
2173 &(pDevice->wCurrentRate),
2174 &(pDevice->byACKRate),
2175 &(pDevice->byTopCCKBasicRate),
2176 &(pDevice->byTopOFDMBasicRate));
2182 if (pDevice->wCurrentRate <= RATE_11M) {
2183 byPktType = PK_TYPE_11B;
2184 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2185 byPktType = PK_TYPE_11A;
2187 if (pDevice->bProtectMode)
2188 byPktType = PK_TYPE_11GB;
2190 byPktType = PK_TYPE_11GA;
2193 if (bNeedEncryption) {
2194 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2195 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2196 bNeedEncryption = false;
2197 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2198 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2199 if (pTransmitKey == NULL) {
2200 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Don't Find TX KEY\n");
2203 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "error: KEY is GTK!!~~\n");
2205 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2206 bNeedEncryption = true;
2211 if (pDevice->byCntMeasure == 2) {
2213 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2216 if (pDevice->bEnableHostWEP) {
2217 if ((uNodeIndex != 0) &&
2218 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2219 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2220 bNeedEncryption = true;
2224 if (pTransmitKey == NULL) {
2225 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return no tx key\n");
2226 dev_kfree_skb_irq(skb);
2227 spin_unlock_irq(&pDevice->lock);
2233 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2234 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2235 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
2240 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2242 MACbPSWakeup(pDevice->PortOffset);
2244 pDevice->bPWBitOn = false;
2247 for (ii = 0; ii < uMACfragNum; ii++) {
2248 // Poll Transmit the adapter
2250 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2252 if (ii == uMACfragNum - 1)
2254 pHeadTD = pHeadTD->next;
2257 // Save the information needed by the tx interrupt handler
2258 // to complete the Send request
2259 pLastTD->pTDInfo->skb = skb;
2260 pLastTD->pTDInfo->byFlags = 0;
2261 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2263 pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
2265 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1)
2266 netif_stop_queue(dev);
2268 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2270 if (pDevice->bFixRate)
2271 printk("FixRate:Rate is %d,TxPower is %d\n", pDevice->wCurrentRate, pDevice->byCurPwr);
2274 unsigned char Protocol_Version; //802.1x Authentication
2275 unsigned char Packet_Type; //802.1x Authentication
2276 unsigned char Descriptor_type;
2277 unsigned short Key_info;
2278 bool bTxeapol_key = false;
2279 Protocol_Version = skb->data[ETH_HLEN];
2280 Packet_Type = skb->data[ETH_HLEN+1];
2281 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2282 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2283 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2284 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2285 (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame transfer
2286 bTxeapol_key = true;
2287 if ((Descriptor_type == 254) || (Descriptor_type == 2)) { //WPA or RSN
2288 if (!(Key_info & BIT3) && //group-key challenge
2289 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2290 pDevice->fWPA_Authened = true;
2291 if (Descriptor_type == 254)
2295 printk("Authentication completed!!\n");
2302 MACvTransmitAC0(pDevice->PortOffset);
2304 dev->trans_start = jiffies;
2306 spin_unlock_irq(&pDevice->lock);
2310 static irqreturn_t device_intr(int irq, void *dev_instance) {
2311 struct net_device *dev = dev_instance;
2312 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2315 unsigned long dwMIBCounter = 0;
2316 PSMgmtObject pMgmt = pDevice->pMgmt;
2317 unsigned char byOrgPageSel = 0;
2319 unsigned char byData = 0;
2322 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2324 if (pDevice->dwIsr == 0)
2325 return IRQ_RETVAL(handled);
2327 if (pDevice->dwIsr == 0xffffffff) {
2328 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
2329 return IRQ_RETVAL(handled);
2333 MACvIntDisable(pDevice->PortOffset);
2334 spin_lock_irq(&pDevice->lock);
2336 //Make sure current page is 0
2337 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2338 if (byOrgPageSel == 1)
2339 MACvSelectPage0(pDevice->PortOffset);
2343 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2345 // Must do this after doing rx/tx, cause ISR bit is slow
2346 // than RD/TD write back
2347 // update ISR counter
2348 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2349 while (pDevice->dwIsr != 0) {
2350 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2351 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2353 if (pDevice->dwIsr & ISR_FETALERR) {
2354 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR \n");
2355 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2356 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2357 device_error(pDevice, pDevice->dwIsr);
2360 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2361 if (pDevice->dwIsr & ISR_MEASURESTART) {
2362 // 802.11h measure start
2363 pDevice->byOrgChannel = pDevice->byCurrentCh;
2364 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2365 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2366 MACvSelectPage1(pDevice->PortOffset);
2367 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2368 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2369 MACvSelectPage0(pDevice->PortOffset);
2371 if (set_channel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel)) {
2372 pDevice->bMeasureInProgress = true;
2373 MACvSelectPage1(pDevice->PortOffset);
2374 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2375 MACvSelectPage0(pDevice->PortOffset);
2376 pDevice->byBasicMap = 0;
2377 pDevice->byCCAFraction = 0;
2378 for (ii = 0; ii < 8; ii++)
2379 pDevice->dwRPIs[ii] = 0;
2382 // can not measure because set channel fail
2383 // clear measure control
2384 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2385 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2386 MACvSelectPage1(pDevice->PortOffset);
2387 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2388 MACvSelectPage0(pDevice->PortOffset);
2391 if (pDevice->dwIsr & ISR_MEASUREEND) {
2392 // 802.11h measure end
2393 pDevice->bMeasureInProgress = false;
2394 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2395 MACvSelectPage1(pDevice->PortOffset);
2396 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2397 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2398 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2399 pDevice->byBasicMap |= (byData >> 4);
2400 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2401 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2402 // clear measure control
2403 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2404 MACvSelectPage0(pDevice->PortOffset);
2405 set_channel(pDevice, pDevice->byOrgChannel);
2406 MACvSelectPage1(pDevice->PortOffset);
2407 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2408 MACvSelectPage0(pDevice->PortOffset);
2409 if (byData & MSRCTL_FINISH) {
2411 s_vCompleteCurrentMeasure(pDevice, 0);
2413 // can not measure because not ready before end of measure time
2414 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2417 if (pDevice->dwIsr & ISR_QUIETSTART) {
2420 } while (!CARDbStartQuiet(pDevice));
2424 if (pDevice->dwIsr & ISR_TBTT) {
2425 if (pDevice->bEnableFirstQuiet) {
2426 pDevice->byQuietStartCount--;
2427 if (pDevice->byQuietStartCount == 0) {
2428 pDevice->bEnableFirstQuiet = false;
2429 MACvSelectPage1(pDevice->PortOffset);
2430 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2431 MACvSelectPage0(pDevice->PortOffset);
2434 if (pDevice->bChannelSwitch &&
2435 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
2436 pDevice->byChannelSwitchCount--;
2437 if (pDevice->byChannelSwitchCount == 0) {
2438 pDevice->bChannelSwitch = false;
2439 set_channel(pDevice, pDevice->byNewChannel);
2440 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2441 MACvSelectPage1(pDevice->PortOffset);
2442 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2443 MACvSelectPage0(pDevice->PortOffset);
2444 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2448 if (pDevice->eOPMode != OP_MODE_ADHOC) {
2449 if ((pDevice->bUpdateBBVGA) && pDevice->bLinkPass && (pDevice->uCurrRSSI != 0)) {
2452 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
2453 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
2454 if (ldBm < pDevice->ldBmThreshold[ii]) {
2455 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2459 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2460 pDevice->uBBVGADiffCount++;
2461 if (pDevice->uBBVGADiffCount == 1) {
2462 // first VGA diff gain
2463 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2464 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2465 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2467 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2468 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2469 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2470 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2473 pDevice->uBBVGADiffCount = 1;
2478 pDevice->bBeaconSent = false;
2479 if (pDevice->bEnablePSMode)
2480 PSbIsNextTBTTWakeUp((void *)pDevice);
2482 if ((pDevice->eOPMode == OP_MODE_AP) ||
2483 (pDevice->eOPMode == OP_MODE_ADHOC)) {
2484 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2485 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2488 /* TODO: adhoc PS mode */
2492 if (pDevice->dwIsr & ISR_BNTX) {
2493 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2494 pDevice->bIsBeaconBufReadySet = false;
2495 pDevice->cbBeaconBufReadySetCnt = 0;
2498 if (pDevice->eOPMode == OP_MODE_AP) {
2499 if (pMgmt->byDTIMCount > 0) {
2500 pMgmt->byDTIMCount--;
2501 pMgmt->sNodeDBTable[0].bRxPSPoll = false;
2503 if (pMgmt->byDTIMCount == 0) {
2504 // check if mutltcast tx bufferring
2505 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2506 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
2507 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2511 pDevice->bBeaconSent = true;
2513 if (pDevice->bChannelSwitch) {
2514 pDevice->byChannelSwitchCount--;
2515 if (pDevice->byChannelSwitchCount == 0) {
2516 pDevice->bChannelSwitch = false;
2517 set_channel(pDevice, pDevice->byNewChannel);
2518 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2519 MACvSelectPage1(pDevice->PortOffset);
2520 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2521 MACvSelectPage0(pDevice->PortOffset);
2522 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2528 if (pDevice->dwIsr & ISR_RXDMA0)
2529 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2531 if (pDevice->dwIsr & ISR_RXDMA1)
2532 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2534 if (pDevice->dwIsr & ISR_TXDMA0)
2535 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2537 if (pDevice->dwIsr & ISR_AC0DMA)
2538 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2540 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2541 if (pDevice->eOPMode == OP_MODE_AP) {
2542 if (pDevice->bShortSlotTime)
2543 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2545 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2547 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2548 pDevice->byCntMeasure = 0;
2551 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2553 MACvReceive0(pDevice->PortOffset);
2554 MACvReceive1(pDevice->PortOffset);
2556 if (max_count > pDevice->sOpts.int_works)
2560 if (byOrgPageSel == 1)
2561 MACvSelectPage1(pDevice->PortOffset);
2563 spin_unlock_irq(&pDevice->lock);
2564 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2566 return IRQ_RETVAL(handled);
2569 static unsigned const ethernet_polynomial = 0x04c11db7U;
2570 static inline u32 ether_crc(int length, unsigned char *data)
2574 while (--length >= 0) {
2575 unsigned char current_octet = *data++;
2577 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
2579 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
2585 //2008-8-4 <add> by chester
2586 static int Config_FileGetParameter(unsigned char *string,
2587 unsigned char *dest, unsigned char *source)
2589 unsigned char buf1[100];
2590 int source_len = strlen(source);
2592 memset(buf1, 0, 100);
2593 strcat(buf1, string);
2595 source += strlen(buf1);
2597 memcpy(dest, source, source_len - strlen(buf1));
2601 int Config_FileOperation(PSDevice pDevice,bool fwrite,unsigned char *Parameter)
2603 unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
2604 unsigned char tmpbuffer[20];
2609 printk("allocate mem for file fail?\n");
2612 file = filp_open(CONFIG_PATH, O_RDONLY, 0);
2615 printk("Config_FileOperation:open file fail?\n");
2619 if (kernel_read(file, 0, buffer, 1024) < 0) {
2620 printk("read file error?\n");
2625 if (Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=true) {
2626 printk("get parameter error?\n");
2631 if (memcmp(tmpbuffer,"USA",3)==0) {
2632 result = ZoneType_USA;
2633 } else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
2634 result = ZoneType_Japan;
2635 } else if(memcmp(tmpbuffer,"EUROPE",5)==0) {
2636 result = ZoneType_Europe;
2639 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
2648 static void device_set_multi(struct net_device *dev) {
2649 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2651 PSMgmtObject pMgmt = pDevice->pMgmt;
2653 struct netdev_hw_addr *ha;
2655 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
2657 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
2658 DBG_PRT(MSG_LEVEL_ERR, KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
2659 /* Unconditionally log net taps. */
2660 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
2661 } else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
2662 || (dev->flags & IFF_ALLMULTI)) {
2663 MACvSelectPage1(pDevice->PortOffset);
2664 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
2665 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
2666 MACvSelectPage0(pDevice->PortOffset);
2667 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2669 memset(mc_filter, 0, sizeof(mc_filter));
2670 netdev_for_each_mc_addr(ha, dev) {
2671 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
2672 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
2674 MACvSelectPage1(pDevice->PortOffset);
2675 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
2676 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
2677 MACvSelectPage0(pDevice->PortOffset);
2678 pDevice->byRxMode &= ~(RCR_UNICAST);
2679 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2682 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2683 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
2684 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2685 pDevice->byRxMode &= ~(RCR_UNICAST);
2688 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
2689 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode);
2692 static struct net_device_stats *device_get_stats(struct net_device *dev) {
2693 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2695 return &pDevice->stats;
2698 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
2699 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2701 struct iwreq *wrq = (struct iwreq *)rq;
2703 PSMgmtObject pMgmt = pDevice->pMgmt;
2706 if (pMgmt == NULL) {
2713 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
2716 case SIOCGIWNWID: //0x8b03 support
2720 // Set frequency/channel
2722 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
2725 // Get frequency/channel
2727 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
2730 // Set desired network name (ESSID)
2734 char essid[IW_ESSID_MAX_SIZE+1];
2735 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
2739 if (copy_from_user(essid, wrq->u.essid.pointer,
2740 wrq->u.essid.length)) {
2744 rc = iwctl_siwessid(dev, NULL,
2745 &(wrq->u.essid), essid);
2749 // Get current network name (ESSID)
2753 char essid[IW_ESSID_MAX_SIZE+1];
2754 if (wrq->u.essid.pointer)
2755 rc = iwctl_giwessid(dev, NULL,
2756 &(wrq->u.essid), essid);
2757 if (copy_to_user(wrq->u.essid.pointer,
2759 wrq->u.essid.length))
2766 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2769 // Get current Access Point (BSSID)
2771 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2774 // Set desired station name
2776 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
2780 // Get current station name
2782 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
2786 // Set the desired bit-rate
2788 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2791 // Get the current bit-rate
2794 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2797 // Set the desired RTS threshold
2800 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
2803 // Get the current RTS threshold
2806 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
2809 // Set the desired fragmentation threshold
2812 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
2815 // Get the current fragmentation threshold
2818 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
2821 // Set mode of operation
2823 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
2826 // Get mode of operation
2828 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
2831 // Set WEP keys and mode
2832 case SIOCSIWENCODE: {
2833 char abyKey[WLAN_WEP232_KEYLEN];
2835 if (wrq->u.encoding.pointer) {
2836 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
2840 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
2841 if (copy_from_user(abyKey,
2842 wrq->u.encoding.pointer,
2843 wrq->u.encoding.length)) {
2847 } else if (wrq->u.encoding.length != 0) {
2851 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2855 // Get the WEP keys and mode
2858 if (!capable(CAP_NET_ADMIN)) {
2863 char abyKey[WLAN_WEP232_KEYLEN];
2865 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2867 if (wrq->u.encoding.pointer) {
2868 if (copy_to_user(wrq->u.encoding.pointer,
2870 wrq->u.encoding.length))
2876 // Get the current Tx-Power
2878 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
2883 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWTXPOW \n");
2889 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
2894 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
2897 // Get range of parameters
2901 struct iw_range range;
2903 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *)&range);
2904 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
2912 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
2917 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
2922 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
2926 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
2930 case SIOCGIWAPLIST: {
2931 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
2933 if (wrq->u.data.pointer) {
2934 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
2936 if (copy_to_user(wrq->u.data.pointer,
2938 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
2950 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
2957 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSPY \n");
2961 #endif // WIRELESS_SPY
2964 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
2968 //2008-0409-07, <Add> by Einsn Liu
2969 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2971 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
2972 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
2976 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH \n");
2977 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
2981 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE \n");
2982 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2986 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE \n");
2987 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2990 case SIOCSIWENCODEEXT: {
2991 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
2992 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
2993 if (wrq->u.encoding.pointer) {
2994 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN + 1);
2995 if (wrq->u.encoding.length > (sizeof(struct iw_encode_ext) + MAX_KEY_LEN)) {
2999 if (copy_from_user(extra, wrq->u.encoding.pointer, wrq->u.encoding.length)) {
3003 } else if (wrq->u.encoding.length != 0) {
3007 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
3011 case SIOCGIWENCODEEXT:
3012 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT \n");
3013 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
3017 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME \n");
3018 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3021 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3022 //End Add -- //2008-0409-07, <Add> by Einsn Liu
3024 case IOCTL_CMD_TEST:
3026 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
3032 pReq = (PSCmdRequest)rq;
3033 pReq->wResult = MAGIC_CODE;
3039 if ((((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_EVT) &&
3040 !(pDevice->flags & DEVICE_FLAGS_OPENED))
3042 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
3043 (((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_WPA))
3052 if (test_and_set_bit(0, (void *)&(pMgmt->uCmdBusy)))
3055 rc = private_ioctl(pDevice, rq);
3056 clear_bit(0, (void *)&(pMgmt->uCmdBusy));
3059 case IOCTL_CMD_HOSTAPD:
3061 rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data);
3066 rc = wpa_ioctl(pDevice, &wrq->u.data);
3070 return ethtool_ioctl(dev, (void *)rq->ifr_data);
3071 // All other calls are currently unsupported
3075 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
3079 if (pDevice->bCommit) {
3080 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3081 netif_stop_queue(pDevice->dev);
3082 spin_lock_irq(&pDevice->lock);
3083 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
3084 spin_unlock_irq(&pDevice->lock);
3086 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
3087 spin_lock_irq(&pDevice->lock);
3088 pDevice->bLinkPass = false;
3089 memset(pMgmt->abyCurrBSSID, 0, 6);
3090 pMgmt->eCurrState = WMAC_STATE_IDLE;
3091 netif_stop_queue(pDevice->dev);
3092 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3093 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
3094 if (!pDevice->bWPASuppWextEnabled)
3096 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
3097 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3098 spin_unlock_irq(&pDevice->lock);
3100 pDevice->bCommit = false;
3106 static int ethtool_ioctl(struct net_device *dev, void *useraddr)
3110 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
3114 case ETHTOOL_GDRVINFO: {
3115 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3116 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3117 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3118 if (copy_to_user(useraddr, &info, sizeof(info)))
3128 /*------------------------------------------------------------------*/
3130 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
3132 static struct pci_driver device_driver = {
3133 .name = DEVICE_NAME,
3134 .id_table = vt6655_pci_id_table,
3135 .probe = vt6655_probe,
3136 .remove = vt6655_remove,
3138 .suspend = viawget_suspend,
3139 .resume = viawget_resume,
3143 static int __init vt6655_init_module(void)
3147 ret = pci_register_driver(&device_driver);
3150 register_reboot_notifier(&device_notifier);
3156 static void __exit vt6655_cleanup_module(void)
3159 unregister_reboot_notifier(&device_notifier);
3161 pci_unregister_driver(&device_driver);
3164 module_init(vt6655_init_module);
3165 module_exit(vt6655_cleanup_module);
3169 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3171 struct pci_dev *pdev = NULL;
3176 for_each_pci_dev(pdev) {
3177 if (pci_dev_driver(pdev) == &device_driver) {
3178 if (pci_get_drvdata(pdev))
3179 viawget_suspend(pdev, PMSG_HIBERNATE);
3187 viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3189 int power_status; // to silence the compiler
3191 PSDevice pDevice = pci_get_drvdata(pcid);
3192 PSMgmtObject pMgmt = pDevice->pMgmt;
3194 netif_stop_queue(pDevice->dev);
3195 spin_lock_irq(&pDevice->lock);
3196 pci_save_state(pcid);
3197 del_timer(&pDevice->sTimerCommand);
3198 del_timer(&pMgmt->sTimerSecondCallback);
3199 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3200 pDevice->uCmdDequeueIdx = 0;
3201 pDevice->uCmdEnqueueIdx = 0;
3202 pDevice->bCmdRunning = false;
3203 MACbShutdown(pDevice->PortOffset);
3204 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3205 pDevice->bLinkPass = false;
3206 memset(pMgmt->abyCurrBSSID, 0, 6);
3207 pMgmt->eCurrState = WMAC_STATE_IDLE;
3208 pci_disable_device(pcid);
3209 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3210 spin_unlock_irq(&pDevice->lock);
3215 viawget_resume(struct pci_dev *pcid)
3217 PSDevice pDevice = pci_get_drvdata(pcid);
3218 PSMgmtObject pMgmt = pDevice->pMgmt;
3219 int power_status; // to silence the compiler
3221 power_status = pci_set_power_state(pcid, PCI_D0);
3222 power_status = pci_enable_wake(pcid, PCI_D0, 0);
3223 pci_restore_state(pcid);
3224 if (netif_running(pDevice->dev)) {
3225 spin_lock_irq(&pDevice->lock);
3226 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3227 device_init_registers(pDevice, DEVICE_INIT_DXPL);
3228 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
3229 pMgmt->sNodeDBTable[0].bActive = false;
3230 pDevice->bLinkPass = false;
3231 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3232 // In Adhoc, BSS state set back to started.
3233 pMgmt->eCurrState = WMAC_STATE_STARTED;
3235 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3236 pMgmt->eCurrState = WMAC_STATE_IDLE;
3239 init_timer(&pMgmt->sTimerSecondCallback);
3240 init_timer(&pDevice->sTimerCommand);
3241 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3242 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
3243 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3244 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3245 spin_unlock_irq(&pDevice->lock);