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");
102 static int mlme_kill;
105 #define DEVICE_PARAM(N, D)
107 #define RX_DESC_MIN0 16
108 #define RX_DESC_MAX0 128
109 #define RX_DESC_DEF0 32
110 DEVICE_PARAM(RxDescriptors0, "Number of receive descriptors0");
112 #define RX_DESC_MIN1 16
113 #define RX_DESC_MAX1 128
114 #define RX_DESC_DEF1 32
115 DEVICE_PARAM(RxDescriptors1, "Number of receive descriptors1");
117 #define TX_DESC_MIN0 16
118 #define TX_DESC_MAX0 128
119 #define TX_DESC_DEF0 32
120 DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
122 #define TX_DESC_MIN1 16
123 #define TX_DESC_MAX1 128
124 #define TX_DESC_DEF1 64
125 DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
127 #define IP_ALIG_DEF 0
128 /* IP_byte_align[] is used for IP header unsigned long byte aligned
129 0: indicate the IP header won't be unsigned long byte aligned.(Default) .
130 1: indicate the IP header will be unsigned long byte aligned.
131 In some environment, the IP header should be unsigned long byte aligned,
132 or the packet will be droped when we receive it. (eg: IPVS)
134 DEVICE_PARAM(IP_byte_align, "Enable IP header dword aligned");
136 #define INT_WORKS_DEF 20
137 #define INT_WORKS_MIN 10
138 #define INT_WORKS_MAX 64
140 DEVICE_PARAM(int_works, "Number of packets per interrupt services");
142 #define CHANNEL_MIN 1
143 #define CHANNEL_MAX 14
144 #define CHANNEL_DEF 6
146 DEVICE_PARAM(Channel, "Channel number");
148 /* PreambleType[] is the preamble length used for transmit.
149 0: indicate allows long preamble type
150 1: indicate allows short preamble type
153 #define PREAMBLE_TYPE_DEF 1
155 DEVICE_PARAM(PreambleType, "Preamble Type");
157 #define RTS_THRESH_MIN 512
158 #define RTS_THRESH_MAX 2347
159 #define RTS_THRESH_DEF 2347
161 DEVICE_PARAM(RTSThreshold, "RTS threshold");
163 #define FRAG_THRESH_MIN 256
164 #define FRAG_THRESH_MAX 2346
165 #define FRAG_THRESH_DEF 2346
167 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
169 #define DATA_RATE_MIN 0
170 #define DATA_RATE_MAX 13
171 #define DATA_RATE_DEF 13
173 0: indicate 1 Mbps 0x02
174 1: indicate 2 Mbps 0x04
175 2: indicate 5.5 Mbps 0x0B
176 3: indicate 11 Mbps 0x16
177 4: indicate 6 Mbps 0x0c
178 5: indicate 9 Mbps 0x12
179 6: indicate 12 Mbps 0x18
180 7: indicate 18 Mbps 0x24
181 8: indicate 24 Mbps 0x30
182 9: indicate 36 Mbps 0x48
183 10: indicate 48 Mbps 0x60
184 11: indicate 54 Mbps 0x6c
185 12: indicate 72 Mbps 0x90
186 13: indicate auto rate
189 DEVICE_PARAM(ConnectionRate, "Connection data rate");
191 #define OP_MODE_DEF 0
193 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
195 /* OpMode[] is used for transmit.
196 0: indicate infrastruct mode used
197 1: indicate adhoc mode used
198 2: indicate AP mode used
202 0: indicate disable power saving mode
203 1: indicate enable power saving mode
206 #define PS_MODE_DEF 0
208 DEVICE_PARAM(PSMode, "Power saving mode");
210 #define SHORT_RETRY_MIN 0
211 #define SHORT_RETRY_MAX 31
212 #define SHORT_RETRY_DEF 8
214 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
216 #define LONG_RETRY_MIN 0
217 #define LONG_RETRY_MAX 15
218 #define LONG_RETRY_DEF 4
220 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
222 /* BasebandType[] baseband type selected
223 0: indicate 802.11a type
224 1: indicate 802.11b type
225 2: indicate 802.11g type
227 #define BBP_TYPE_MIN 0
228 #define BBP_TYPE_MAX 2
229 #define BBP_TYPE_DEF 2
231 DEVICE_PARAM(BasebandType, "baseband type");
234 0: indicate disable 802.11h
235 1: indicate enable 802.11h
238 #define X80211h_MODE_DEF 0
240 DEVICE_PARAM(b80211hEnable, "802.11h mode");
243 0: indicate disable 802.11h
244 1: indicate enable 802.11h
247 #define DIVERSITY_ANT_DEF 0
249 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
252 // Static vars definitions
255 static int device_nics = 0;
256 static PSDevice pDevice_Infos = NULL;
257 static struct net_device *root_device_dev = NULL;
259 static CHIP_INFO chip_info_table[] = {
260 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
261 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
265 static const struct pci_device_id vt6655_pci_id_table[] = {
266 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
270 /*--------------------- Static Functions --------------------------*/
272 static int vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent);
273 static void vt6655_init_info(struct pci_dev *pcid, PSDevice *ppDevice, PCHIP_INFO);
274 static void device_free_info(PSDevice pDevice);
275 static bool device_get_pci_info(PSDevice, struct pci_dev *pcid);
276 static void device_print_info(PSDevice pDevice);
277 static struct net_device_stats *device_get_stats(struct net_device *dev);
278 static void device_init_diversity_timer(PSDevice pDevice);
279 static int device_open(struct net_device *dev);
280 static int device_xmit(struct sk_buff *skb, struct net_device *dev);
281 static irqreturn_t device_intr(int irq, void *dev_instance);
282 static void device_set_multi(struct net_device *dev);
283 static int device_close(struct net_device *dev);
284 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
287 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
288 static int viawget_suspend(struct pci_dev *pcid, pm_message_t state);
289 static int viawget_resume(struct pci_dev *pcid);
290 static struct notifier_block device_notifier = {
291 .notifier_call = device_notify_reboot,
297 static void device_init_rd0_ring(PSDevice pDevice);
298 static void device_init_rd1_ring(PSDevice pDevice);
299 static void device_init_defrag_cb(PSDevice pDevice);
300 static void device_init_td0_ring(PSDevice pDevice);
301 static void device_init_td1_ring(PSDevice pDevice);
303 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
304 //2008-0714<Add>by Mike Liu
305 static bool device_release_WPADEV(PSDevice pDevice);
307 static int ethtool_ioctl(struct net_device *dev, void __user *useraddr);
308 static int device_rx_srv(PSDevice pDevice, unsigned int uIdx);
309 static int device_tx_srv(PSDevice pDevice, unsigned int uIdx);
310 static bool device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pDesc);
311 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
312 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc);
313 static void device_free_td0_ring(PSDevice pDevice);
314 static void device_free_td1_ring(PSDevice pDevice);
315 static void device_free_rd0_ring(PSDevice pDevice);
316 static void device_free_rd1_ring(PSDevice pDevice);
317 static void device_free_rings(PSDevice pDevice);
318 static void device_free_frag_buf(PSDevice pDevice);
319 static int Config_FileGetParameter(unsigned char *string,
320 unsigned char *dest, unsigned char *source);
322 /*--------------------- Export Variables --------------------------*/
324 /*--------------------- Export Functions --------------------------*/
326 static char *get_chip_name(int chip_id)
329 for (i = 0; chip_info_table[i].name != NULL; i++)
330 if (chip_info_table[i].chip_id == chip_id)
332 return chip_info_table[i].name;
335 static void vt6655_remove(struct pci_dev *pcid)
337 PSDevice pDevice = pci_get_drvdata(pcid);
341 device_free_info(pDevice);
344 static void device_get_options(PSDevice pDevice, int index, char *devname)
346 POPTIONS pOpts = &(pDevice->sOpts);
348 pOpts->nRxDescs0 = RX_DESC_DEF0;
349 pOpts->nRxDescs1 = RX_DESC_DEF1;
350 pOpts->nTxDescs[0] = TX_DESC_DEF0;
351 pOpts->nTxDescs[1] = TX_DESC_DEF1;
352 pOpts->flags |= DEVICE_FLAGS_IP_ALIGN;
353 pOpts->int_works = INT_WORKS_DEF;
354 pOpts->rts_thresh = RTS_THRESH_DEF;
355 pOpts->frag_thresh = FRAG_THRESH_DEF;
356 pOpts->data_rate = DATA_RATE_DEF;
357 pOpts->channel_num = CHANNEL_DEF;
359 pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE;
360 pOpts->flags |= DEVICE_FLAGS_OP_MODE;
361 pOpts->short_retry = SHORT_RETRY_DEF;
362 pOpts->long_retry = LONG_RETRY_DEF;
363 pOpts->bbp_type = BBP_TYPE_DEF;
364 pOpts->flags |= DEVICE_FLAGS_80211h_MODE;
365 pOpts->flags |= DEVICE_FLAGS_DiversityANT;
369 device_set_options(PSDevice pDevice) {
370 unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
371 unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
372 unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
374 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
375 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
376 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
378 pDevice->uChannel = pDevice->sOpts.channel_num;
379 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
380 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
381 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
382 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
383 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
384 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
385 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
386 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
387 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
388 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
389 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
390 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = true;
391 pDevice->byBBType = pDevice->sOpts.bbp_type;
392 pDevice->byPacketType = pDevice->byBBType;
395 pDevice->byAutoFBCtrl = AUTO_FB_0;
397 pDevice->bUpdateBBVGA = true;
398 pDevice->byFOETuning = 0;
399 pDevice->wCTSDuration = 0;
400 pDevice->byPreambleType = 0;
402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " uChannel= %d\n", (int)pDevice->uChannel);
403 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byOpMode= %d\n", (int)pDevice->byOpMode);
404 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ePSMode= %d\n", (int)pDevice->ePSMode);
405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
406 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
407 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byPreambleType= %d\n", (int)pDevice->byPreambleType);
409 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
410 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byBBType= %d\n", (int)pDevice->byBBType);
412 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
413 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pDevice->bDiversityRegCtlON= %d\n", (int)pDevice->bDiversityRegCtlON);
416 static void s_vCompleteCurrentMeasure(PSDevice pDevice, unsigned char byResult)
419 unsigned long dwDuration = 0;
420 unsigned char byRPI0 = 0;
422 for (ii = 1; ii < 8; ii++) {
423 pDevice->dwRPIs[ii] *= 255;
424 dwDuration |= *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
426 pDevice->dwRPIs[ii] /= dwDuration;
427 pDevice->abyRPIs[ii] = (unsigned char)pDevice->dwRPIs[ii];
428 byRPI0 += pDevice->abyRPIs[ii];
430 pDevice->abyRPIs[0] = (0xFF - byRPI0);
432 if (pDevice->uNumOfMeasureEIDs == 0) {
433 VNTWIFIbMeasureReport(pDevice->pMgmt,
435 pDevice->pCurrMeasureEID,
438 pDevice->byCCAFraction,
442 VNTWIFIbMeasureReport(pDevice->pMgmt,
444 pDevice->pCurrMeasureEID,
447 pDevice->byCCAFraction,
450 CARDbStartMeasure(pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
455 // Initialisation of MAC & BBP registers
458 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
461 unsigned char byValue;
462 unsigned char byValue1;
463 unsigned char byCCKPwrdBm = 0;
464 unsigned char byOFDMPwrdBm = 0;
466 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
467 MACbShutdown(pDevice->PortOffset);
468 BBvSoftwareReset(pDevice->PortOffset);
470 if ((InitType == DEVICE_INIT_COLD) ||
471 (InitType == DEVICE_INIT_DXPL)) {
472 // Do MACbSoftwareReset in MACvInitialize
473 MACbSoftwareReset(pDevice->PortOffset);
475 pDevice->bCCK = true;
476 pDevice->bAES = false;
477 pDevice->bProtectMode = false; //Only used in 11g type, sync with ERP IE
478 pDevice->bNonERPPresent = false;
479 pDevice->bBarkerPreambleMd = false;
480 pDevice->wCurrentRate = RATE_1M;
481 pDevice->byTopOFDMBasicRate = RATE_24M;
482 pDevice->byTopCCKBasicRate = RATE_1M;
484 pDevice->byRevId = 0; //Target to IF pin while programming to RF chip.
487 MACvInitialize(pDevice->PortOffset);
490 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
492 spin_lock_irq(&pDevice->lock);
493 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
495 spin_unlock_irq(&pDevice->lock);
499 pDevice->byMinChannel = 1;
500 pDevice->byMaxChannel = CB_MAX_CHANNEL;
503 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
504 if (byValue & EEP_ANTINV)
505 pDevice->bTxRxAntInv = true;
507 pDevice->bTxRxAntInv = false;
509 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
510 if (byValue == 0) // if not set default is All
511 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
513 pDevice->ulDiversityNValue = 100*260;
514 pDevice->ulDiversityMValue = 100*16;
516 pDevice->byTMax2 = 4;
517 pDevice->ulSQ3TH = 0;
518 pDevice->byTMax3 = 64;
520 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
521 pDevice->byAntennaCount = 2;
522 pDevice->byTxAntennaMode = ANT_B;
523 pDevice->dwTxAntennaSel = 1;
524 pDevice->dwRxAntennaSel = 1;
525 if (pDevice->bTxRxAntInv)
526 pDevice->byRxAntennaMode = ANT_A;
528 pDevice->byRxAntennaMode = ANT_B;
529 // chester for antenna
530 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
531 if ((byValue1 & 0x08) == 0)
532 pDevice->bDiversityEnable = false;
534 pDevice->bDiversityEnable = true;
536 pDevice->bDiversityEnable = false;
537 pDevice->byAntennaCount = 1;
538 pDevice->dwTxAntennaSel = 0;
539 pDevice->dwRxAntennaSel = 0;
540 if (byValue & EEP_ANTENNA_AUX) {
541 pDevice->byTxAntennaMode = ANT_A;
542 if (pDevice->bTxRxAntInv)
543 pDevice->byRxAntennaMode = ANT_B;
545 pDevice->byRxAntennaMode = ANT_A;
547 pDevice->byTxAntennaMode = ANT_B;
548 if (pDevice->bTxRxAntInv)
549 pDevice->byRxAntennaMode = ANT_A;
551 pDevice->byRxAntennaMode = ANT_B;
554 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
555 pDevice->bDiversityEnable, (int)pDevice->ulDiversityNValue, (int)pDevice->ulDiversityMValue, pDevice->byTMax, pDevice->byTMax2);
557 //2008-8-4 <add> by chester
559 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
560 zonetype = Config_FileOperation(pDevice, false, NULL);
561 if (zonetype >= 0) { //read zonetype file ok!
562 if ((zonetype == 0) &&
563 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x00)) { //for USA
564 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
565 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
566 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Init Zone Type :USA\n");
567 } else if ((zonetype == 1) &&
568 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x01)) { //for Japan
569 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
570 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
571 } else if ((zonetype == 2) &&
572 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x02)) { //for Europe
573 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
574 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
575 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Init Zone Type :Europe\n");
579 if (zonetype != pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
580 printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n", zonetype, pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
582 printk("Read Zonetype file success,use default zonetype setting[%02x]\n", zonetype);
585 printk("Read Zonetype file fail,use default zonetype setting[%02x]\n", SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
588 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
590 if ((pDevice->byRFType & RF_EMU) != 0) {
591 // force change RevID for VT3253 emu
592 pDevice->byRevId = 0x80;
595 pDevice->byRFType &= RF_MASK;
596 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
598 if (!pDevice->bZoneRegExist)
599 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
601 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
606 //Get Desire Power Value
607 pDevice->byCurPwr = 0xFF;
608 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
609 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
613 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
614 pDevice->abyCCKPwrTbl[ii + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
615 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
616 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
618 pDevice->abyOFDMPwrTbl[ii + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
619 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
620 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
622 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
623 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
625 //2008-8-4 <add> by chester
626 //recover 12,13 ,14channel for EUROPE by 11 channel
627 if (((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
628 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe)) &&
629 (pDevice->byOriginalZonetype == ZoneType_USA)) {
630 for (ii = 11; ii < 14; ii++) {
631 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
632 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
637 // Load OFDM A Power Table
638 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
639 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
640 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] = SROMbyReadEmbedded(pDevice->PortOffset, (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
642 init_channel_table((void *)pDevice);
644 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
645 MACvSelectPage1(pDevice->PortOffset);
646 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
647 MACvSelectPage0(pDevice->PortOffset);
650 // use relative tx timeout and 802.11i D4
651 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
653 // set performance parameter by registry
654 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
655 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
658 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
659 // enable TSF counter
660 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
662 // initialize BBP registers
663 BBbVT3253Init(pDevice);
665 if (pDevice->bUpdateBBVGA) {
666 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
667 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
668 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
670 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
671 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
673 pDevice->byCurrentCh = 0;
675 // Set BB and packet type at the same time.
676 // Set Short Slot Time, xIFS, and RSPINF.
677 if (pDevice->uConnectionRate == RATE_AUTO)
678 pDevice->wCurrentRate = RATE_54M;
680 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
683 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
684 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
686 pDevice->bRadioOff = false;
688 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
689 pDevice->bHWRadioOff = false;
691 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
693 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
694 //2008-4-14 <add> by chester for led issue
695 #ifdef FOR_LED_ON_NOTEBOOK
696 if (pDevice->byGPIO & GPIO0_DATA)
697 pDevice->bHWRadioOff = true;
699 if (!(pDevice->byGPIO & GPIO0_DATA))
700 pDevice->bHWRadioOff = false;
703 if (pDevice->bRadioControlOff)
704 CARDbRadioPowerOff(pDevice);
706 CARDbRadioPowerOn(pDevice);
708 if (((pDevice->byGPIO & GPIO0_DATA) && !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
709 (!(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV))) {
710 pDevice->bHWRadioOff = true;
713 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
714 CARDbRadioPowerOff(pDevice);
718 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
719 // get Permanent network address
720 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
721 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Network address = %pM\n",
722 pDevice->abyCurrentNetAddr);
725 CARDvSafeResetRx(pDevice);
727 CARDvSafeResetTx(pDevice);
729 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
730 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
732 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
735 MACvReceive0(pDevice->PortOffset);
736 MACvReceive1(pDevice->PortOffset);
739 MACvStart(pDevice->PortOffset);
741 netif_stop_queue(pDevice->dev);
744 static void device_init_diversity_timer(PSDevice pDevice) {
745 init_timer(&pDevice->TimerSQ3Tmax1);
746 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
747 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
748 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
750 init_timer(&pDevice->TimerSQ3Tmax2);
751 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
752 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
753 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
755 init_timer(&pDevice->TimerSQ3Tmax3);
756 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
757 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
758 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
763 static bool device_release_WPADEV(PSDevice pDevice)
765 viawget_wpa_header *wpahdr;
768 //send device close to wpa_supplicnat layer
769 if (pDevice->bWPADEVUp) {
770 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
771 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
772 wpahdr->resp_ie_len = 0;
773 wpahdr->req_ie_len = 0;
774 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
775 pDevice->skb->dev = pDevice->wpadev;
776 skb_reset_mac_header(pDevice->skb);
777 pDevice->skb->pkt_type = PACKET_HOST;
778 pDevice->skb->protocol = htons(ETH_P_802_2);
779 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
780 netif_rx(pDevice->skb);
781 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
783 while (pDevice->bWPADEVUp) {
784 set_current_state(TASK_UNINTERRUPTIBLE);
785 schedule_timeout(HZ / 20); //wait 50ms
794 static const struct net_device_ops device_netdev_ops = {
795 .ndo_open = device_open,
796 .ndo_stop = device_close,
797 .ndo_do_ioctl = device_ioctl,
798 .ndo_get_stats = device_get_stats,
799 .ndo_start_xmit = device_xmit,
800 .ndo_set_rx_mode = device_set_multi,
804 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
806 static bool bFirst = true;
807 struct net_device *dev = NULL;
808 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
811 if (device_nics++ >= MAX_UINTS) {
812 printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
816 dev = alloc_etherdev(sizeof(DEVICE_INFO));
818 pDevice = (PSDevice) netdev_priv(dev);
821 printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
825 // Chain it all together
826 SET_NETDEV_DEV(dev, &pcid->dev);
829 printk(KERN_NOTICE "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
830 printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
834 vt6655_init_info(pcid, &pDevice, pChip_info);
836 pDevice->next_module = root_device_dev;
837 root_device_dev = dev;
839 if (pci_enable_device(pcid)) {
840 device_free_info(pDevice);
843 dev->irq = pcid->irq;
846 printk("Before get pci_info memaddr is %x\n", pDevice->memaddr);
848 if (!device_get_pci_info(pDevice, pcid)) {
849 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
850 device_free_info(pDevice);
858 printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n", pDevice->memaddr, pDevice->ioaddr, pDevice->io_size);
870 for (i = 0; address[i]; i++) {
871 pci_read_config_dword(pcid, address[i], &bar);
872 printk("bar %d is %x\n", i, bar);
874 printk("bar %d not implemented\n", i);
877 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
880 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
881 len = len & ~(len - 1);
883 printk("IO space: len in IO %x, BAR %d\n", len, i);
885 len = bar & 0xFFFFFFF0;
888 printk("len in MEM %x, BAR %d\n", len, i);
896 pDevice->PortOffset = ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
898 if (pDevice->PortOffset == NULL) {
899 printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
900 device_free_info(pDevice);
904 rc = pci_request_regions(pcid, DEVICE_NAME);
906 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
907 device_free_info(pDevice);
911 dev->base_addr = pDevice->ioaddr;
915 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
916 printk("Before write: value is %x\n", value);
917 VNSvOutPortB(pDevice->PortOffset, value);
918 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
919 printk("After write: value is %x\n", value);
923 pDevice->PortOffset = pDevice->ioaddr;
926 if (!MACbSoftwareReset(pDevice->PortOffset)) {
927 printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
928 device_free_info(pDevice);
931 // initial to reload eeprom
932 MACvInitialize(pDevice->PortOffset);
933 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
935 device_get_options(pDevice, device_nics-1, dev->name);
936 device_set_options(pDevice);
937 //Mask out the options cannot be set to the chip
938 pDevice->sOpts.flags &= pChip_info->flags;
940 //Enable the chip specified capabilities
941 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
942 pDevice->tx_80211 = device_dma0_tx_80211;
943 pDevice->sMgmtObj.pAdapter = (void *)pDevice;
944 pDevice->pMgmt = &(pDevice->sMgmtObj);
946 dev->irq = pcid->irq;
947 dev->netdev_ops = &device_netdev_ops;
949 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
951 rc = register_netdev(dev);
953 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
954 device_free_info(pDevice);
957 device_print_info(pDevice);
958 pci_set_drvdata(pcid, pDevice);
962 static void device_print_info(PSDevice pDevice)
964 struct net_device *dev = pDevice->dev;
966 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n", dev->name, get_chip_name(pDevice->chip_id));
967 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%pM", dev->name, dev->dev_addr);
969 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IO=0x%lx ", (unsigned long)pDevice->ioaddr);
970 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IRQ=%d \n", pDevice->dev->irq);
972 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IO=0x%lx Mem=0x%lx ",
973 (unsigned long)pDevice->ioaddr, (unsigned long)pDevice->PortOffset);
974 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IRQ=%d \n", pDevice->dev->irq);
978 static void vt6655_init_info(struct pci_dev *pcid, PSDevice *ppDevice,
979 PCHIP_INFO pChip_info) {
982 memset(*ppDevice, 0, sizeof(DEVICE_INFO));
984 if (pDevice_Infos == NULL) {
985 pDevice_Infos = *ppDevice;
987 for (p = pDevice_Infos; p->next != NULL; p = p->next)
990 (*ppDevice)->prev = p;
993 (*ppDevice)->pcid = pcid;
994 (*ppDevice)->chip_id = pChip_info->chip_id;
995 (*ppDevice)->io_size = pChip_info->io_size;
996 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
997 (*ppDevice)->multicast_limit = 32;
999 spin_lock_init(&((*ppDevice)->lock));
1002 static bool device_get_pci_info(PSDevice pDevice, struct pci_dev *pcid) {
1005 unsigned int cis_addr;
1007 unsigned char pci_config[256];
1008 unsigned char value = 0x00;
1010 u16 max_lat = 0x0000;
1011 memset(pci_config, 0x00, 256);
1014 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
1015 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
1016 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
1017 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
1019 pci_set_master(pcid);
1021 pDevice->memaddr = pci_resource_start(pcid, 0);
1022 pDevice->ioaddr = pci_resource_start(pcid, 1);
1024 cis_addr = pci_resource_start(pcid, 2);
1026 pDevice->pcid = pcid;
1028 pci_read_config_byte(pcid, PCI_COMMAND, &b);
1029 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
1032 for (ii = 0; ii < 0xFF; ii++) {
1033 pci_read_config_byte(pcid, ii, &value);
1034 pci_config[ii] = value;
1036 for (ii = 0, j = 1; ii < 0x100; ii++, j++) {
1038 printk("%x:", pci_config[ii]);
1041 printk("%x:", pci_config[ii]);
1048 static void device_free_info(PSDevice pDevice) {
1050 struct net_device *dev = pDevice->dev;
1053 //2008-0714-01<Add>by chester
1054 device_release_WPADEV(pDevice);
1056 //2008-07-21-01<Add>by MikeLiu
1058 if (wpa_set_wpadev(pDevice, 0) != 0)
1059 printk("unregister wpadev fail?\n");
1061 if (pDevice_Infos == NULL)
1064 for (ptr = pDevice_Infos; ptr && (ptr != pDevice); ptr = ptr->next)
1067 if (ptr == pDevice) {
1068 if (ptr == pDevice_Infos)
1069 pDevice_Infos = ptr->next;
1071 ptr->prev->next = ptr->next;
1073 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
1078 vt6655_hostap_set_hostapd(pDevice, 0, 0);
1081 unregister_netdev(dev);
1083 if (pDevice->PortOffset)
1084 iounmap(pDevice->PortOffset);
1087 pci_release_regions(pDevice->pcid);
1092 static bool device_init_rings(PSDevice pDevice) {
1095 /*allocate all RD/TD rings a single pool*/
1096 vir_pool = pci_alloc_consistent(pDevice->pcid,
1097 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1098 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1099 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1100 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1101 &pDevice->pool_dma);
1103 if (vir_pool == NULL) {
1104 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
1109 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1110 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1111 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1112 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1115 pDevice->aRD0Ring = vir_pool;
1116 pDevice->aRD1Ring = vir_pool +
1117 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1119 pDevice->rd0_pool_dma = pDevice->pool_dma;
1120 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1121 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1123 pDevice->tx0_bufs = pci_alloc_consistent(pDevice->pcid,
1124 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1125 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1126 CB_BEACON_BUF_SIZE +
1128 &pDevice->tx_bufs_dma0);
1130 if (pDevice->tx0_bufs == NULL) {
1131 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
1132 pci_free_consistent(pDevice->pcid,
1133 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1134 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1135 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1136 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1137 vir_pool, pDevice->pool_dma
1142 memset(pDevice->tx0_bufs, 0,
1143 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1144 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1145 CB_BEACON_BUF_SIZE +
1149 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1150 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1152 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1153 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1155 // vir_pool: pvoid type
1156 pDevice->apTD0Rings = vir_pool
1157 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1158 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1160 pDevice->apTD1Rings = vir_pool
1161 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1162 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1163 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1165 pDevice->tx1_bufs = pDevice->tx0_bufs +
1166 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1168 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1169 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1171 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1174 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1175 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1177 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1178 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1183 static void device_free_rings(PSDevice pDevice) {
1184 pci_free_consistent(pDevice->pcid,
1185 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1186 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1187 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1188 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1190 pDevice->aRD0Ring, pDevice->pool_dma
1193 if (pDevice->tx0_bufs)
1194 pci_free_consistent(pDevice->pcid,
1195 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1196 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1197 CB_BEACON_BUF_SIZE +
1199 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1203 static void device_init_rd0_ring(PSDevice pDevice) {
1205 dma_addr_t curr = pDevice->rd0_pool_dma;
1208 /* Init the RD0 ring entries */
1209 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1210 pDesc = &(pDevice->aRD0Ring[i]);
1211 pDesc->pRDInfo = alloc_rd_info();
1212 ASSERT(pDesc->pRDInfo);
1213 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1214 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc rx bufs\n",
1215 pDevice->dev->name);
1217 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1218 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1219 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1223 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1224 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1227 static void device_init_rd1_ring(PSDevice pDevice) {
1229 dma_addr_t curr = pDevice->rd1_pool_dma;
1232 /* Init the RD1 ring entries */
1233 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1234 pDesc = &(pDevice->aRD1Ring[i]);
1235 pDesc->pRDInfo = alloc_rd_info();
1236 ASSERT(pDesc->pRDInfo);
1237 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1238 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc rx bufs\n",
1239 pDevice->dev->name);
1241 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1242 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1243 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1247 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1248 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1251 static void device_init_defrag_cb(PSDevice pDevice) {
1253 PSDeFragControlBlock pDeF;
1255 /* Init the fragment ctl entries */
1256 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1257 pDeF = &(pDevice->sRxDFCB[i]);
1258 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1259 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc frag bufs\n",
1260 pDevice->dev->name);
1263 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1264 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1267 static void device_free_rd0_ring(PSDevice pDevice) {
1270 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1271 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
1272 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1274 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1275 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1277 dev_kfree_skb(pRDInfo->skb);
1279 kfree((void *)pDesc->pRDInfo);
1283 static void device_free_rd1_ring(PSDevice pDevice) {
1286 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1287 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
1288 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1290 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1291 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1293 dev_kfree_skb(pRDInfo->skb);
1295 kfree((void *)pDesc->pRDInfo);
1299 static void device_free_frag_buf(PSDevice pDevice) {
1300 PSDeFragControlBlock pDeF;
1303 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1304 pDeF = &(pDevice->sRxDFCB[i]);
1307 dev_kfree_skb(pDeF->skb);
1312 static void device_init_td0_ring(PSDevice pDevice) {
1317 curr = pDevice->td0_pool_dma;
1318 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1319 pDesc = &(pDevice->apTD0Rings[i]);
1320 pDesc->pTDInfo = alloc_td_info();
1321 ASSERT(pDesc->pTDInfo);
1322 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1323 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1324 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1326 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1327 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1328 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1332 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1333 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1336 static void device_init_td1_ring(PSDevice pDevice) {
1341 /* Init the TD ring entries */
1342 curr = pDevice->td1_pool_dma;
1343 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
1344 pDesc = &(pDevice->apTD1Rings[i]);
1345 pDesc->pTDInfo = alloc_td_info();
1346 ASSERT(pDesc->pTDInfo);
1347 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1348 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
1349 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
1351 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
1352 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1353 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1357 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1358 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1361 static void device_free_td0_ring(PSDevice pDevice) {
1363 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1364 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
1365 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1367 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1368 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1369 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1372 dev_kfree_skb(pTDInfo->skb);
1374 kfree((void *)pDesc->pTDInfo);
1378 static void device_free_td1_ring(PSDevice pDevice) {
1381 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1382 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
1383 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1385 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1386 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1387 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1390 dev_kfree_skb(pTDInfo->skb);
1392 kfree((void *)pDesc->pTDInfo);
1396 /*-----------------------------------------------------------------*/
1398 static int device_rx_srv(PSDevice pDevice, unsigned int uIdx) {
1402 for (pRD = pDevice->pCurrRD[uIdx];
1403 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1407 if (device_receive_frame(pDevice, pRD)) {
1408 if (!device_alloc_rx_buf(pDevice, pRD)) {
1409 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1410 "%s: can not allocate rx buf\n", pDevice->dev->name);
1414 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1415 pDevice->dev->last_rx = jiffies;
1418 pDevice->pCurrRD[uIdx] = pRD;
1423 static bool device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD) {
1424 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1426 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1427 if (pRDInfo->skb == NULL)
1429 ASSERT(pRDInfo->skb);
1430 pRDInfo->skb->dev = pDevice->dev;
1431 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
1432 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1433 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1435 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1436 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1437 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1438 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1443 bool device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
1444 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1445 if (pDeF->skb == NULL)
1448 pDeF->skb->dev = pDevice->dev;
1453 static int device_tx_srv(PSDevice pDevice, unsigned int uIdx) {
1457 unsigned char byTsr0;
1458 unsigned char byTsr1;
1459 unsigned int uFrameSize, uFIFOHeaderSize;
1460 PSTxBufHead pTxBufHead;
1461 struct net_device_stats *pStats = &pDevice->stats;
1462 struct sk_buff *skb;
1463 unsigned int uNodeIndex;
1464 PSMgmtObject pMgmt = pDevice->pMgmt;
1466 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1467 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1472 byTsr0 = pTD->m_td0TD0.byTSR0;
1473 byTsr1 = pTD->m_td0TD0.byTSR1;
1475 //Only the status of first TD in the chain is correct
1476 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1477 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1478 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1479 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1480 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1481 // Update the statistics based on the Transmit status
1482 // now, we DONT check TSR0_CDH
1484 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1486 (unsigned char *)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1489 BSSvUpdateNodeTxCounter(pDevice,
1491 (unsigned char *)(pTD->pTDInfo->buf),
1495 if (!(byTsr1 & TSR1_TERR)) {
1497 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1498 (int)uIdx, byTsr1, byTsr0);
1500 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG)
1501 pDevice->s802_11Counter.TransmittedFragmentCount++;
1503 pStats->tx_packets++;
1504 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1506 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1507 (int)uIdx, byTsr1, byTsr0);
1508 pStats->tx_errors++;
1509 pStats->tx_dropped++;
1513 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1514 if (pDevice->bEnableHostapd) {
1515 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif.. \n");
1516 skb = pTD->pTDInfo->skb;
1517 skb->dev = pDevice->apdev;
1518 skb_reset_mac_header(skb);
1519 skb->pkt_type = PACKET_OTHERHOST;
1520 memset(skb->cb, 0, sizeof(skb->cb));
1525 if (byTsr1 & TSR1_TERR) {
1526 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1527 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1528 (int)uIdx, byTsr1, byTsr0);
1532 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1533 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1534 unsigned short wAID;
1535 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1537 skb = pTD->pTDInfo->skb;
1538 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1539 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1540 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1541 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1543 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1544 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1545 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1546 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1547 , (int)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1548 pStats->tx_errors--;
1549 pStats->tx_dropped--;
1554 device_free_tx_buf(pDevice, pTD);
1555 pDevice->iTDUsed[uIdx]--;
1559 if (uIdx == TYPE_AC0DMA) {
1560 // RESERV_AC0DMA reserved for relay
1562 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1564 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
1566 if (netif_queue_stopped(pDevice->dev) && !bFull)
1567 netif_wake_queue(pDevice->dev);
1571 pDevice->apTailTD[uIdx] = pTD;
1576 static void device_error(PSDevice pDevice, unsigned short status) {
1577 if (status & ISR_FETALERR) {
1578 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1579 "%s: Hardware fatal error.\n",
1580 pDevice->dev->name);
1581 netif_stop_queue(pDevice->dev);
1582 del_timer(&pDevice->sTimerCommand);
1583 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1584 pDevice->bCmdRunning = false;
1585 MACbShutdown(pDevice->PortOffset);
1590 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc) {
1591 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1592 struct sk_buff *skb = pTDInfo->skb;
1594 // pre-allocated buf_dma can't be unmapped.
1595 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1596 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1600 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1601 dev_kfree_skb_irq(skb);
1603 pTDInfo->skb_dma = 0;
1605 pTDInfo->byFlags = 0;
1609 void InitRxManagementQueue(PSDevice pDevice)
1611 pDevice->rxManeQueue.packet_num = 0;
1612 pDevice->rxManeQueue.head = pDevice->rxManeQueue.tail = 0;
1618 static int MlmeThread(
1621 PSDevice pDevice = (PSDevice) Context;
1622 PSRxMgmtPacket pRxMgmtPacket;
1625 spin_lock_irq(&pDevice->lock);
1626 while (pDevice->rxManeQueue.packet_num != 0) {
1627 pRxMgmtPacket = DeQueue(pDevice);
1628 vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
1630 spin_unlock_irq(&pDevice->lock);
1643 static int device_open(struct net_device *dev) {
1644 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1646 #ifdef WPA_SM_Transtatus
1647 extern SWPAResult wpa_Result;
1650 pDevice->rx_buf_sz = PKT_BUF_SZ;
1651 if (!device_init_rings(pDevice))
1654 //2008-5-13 <add> by chester
1655 i = request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1659 #ifdef WPA_SM_Transtatus
1660 memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname));
1661 wpa_Result.proto = 0;
1662 wpa_Result.key_mgmt = 0;
1663 wpa_Result.eap_type = 0;
1664 wpa_Result.authenticated = false;
1665 pDevice->fWPA_Authened = false;
1667 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
1668 device_init_rd0_ring(pDevice);
1669 device_init_rd1_ring(pDevice);
1670 device_init_defrag_cb(pDevice);
1671 device_init_td0_ring(pDevice);
1672 device_init_td1_ring(pDevice);
1674 if (pDevice->bDiversityRegCtlON)
1675 device_init_diversity_timer(pDevice);
1677 vMgrObjectInit(pDevice);
1678 vMgrTimerInit(pDevice);
1682 tasklet_init(&pDevice->RxMngWorkItem, (void *)MngWorkItem, (unsigned long)pDevice);
1685 InitRxManagementQueue(pDevice);
1687 mlme_task = kthread_run(MlmeThread, (void *)pDevice, "MLME");
1688 if (IS_ERR(mlme_task)) {
1689 printk("thread create fail\n");
1696 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
1697 device_init_registers(pDevice, DEVICE_INIT_COLD);
1698 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1699 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN);
1700 device_set_multi(pDevice->dev);
1702 // Init for Key Management
1703 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1704 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1706 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1707 pDevice->bwextcount = 0;
1708 pDevice->bWPASuppWextEnabled = false;
1710 pDevice->byReAssocCount = 0;
1711 pDevice->bWPADEVUp = false;
1712 // Patch: if WEP key already set by iwconfig but device not yet open
1713 if (pDevice->bEncryptionEnable && pDevice->bTransmitKey) {
1714 KeybSetDefaultKey(&(pDevice->sKey),
1715 (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
1716 pDevice->uKeyLength,
1720 pDevice->PortOffset,
1723 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1726 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
1727 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1729 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1730 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
1732 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1733 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1735 pDevice->flags |= DEVICE_FLAGS_OPENED;
1737 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
1741 static int device_close(struct net_device *dev) {
1742 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1743 PSMgmtObject pMgmt = pDevice->pMgmt;
1749 //2007-1121-02<Add>by EinsnLiu
1750 if (pDevice->bLinkPass) {
1751 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1755 del_timer(&pDevice->sTimerTxData);
1757 del_timer(&pDevice->sTimerCommand);
1758 del_timer(&pMgmt->sTimerSecondCallback);
1759 if (pDevice->bDiversityRegCtlON) {
1760 del_timer(&pDevice->TimerSQ3Tmax1);
1761 del_timer(&pDevice->TimerSQ3Tmax2);
1762 del_timer(&pDevice->TimerSQ3Tmax3);
1766 tasklet_kill(&pDevice->RxMngWorkItem);
1768 netif_stop_queue(dev);
1769 pDevice->bCmdRunning = false;
1770 MACbShutdown(pDevice->PortOffset);
1771 MACbSoftwareReset(pDevice->PortOffset);
1772 CARDbRadioPowerOff(pDevice);
1774 pDevice->bLinkPass = false;
1775 memset(pMgmt->abyCurrBSSID, 0, 6);
1776 pMgmt->eCurrState = WMAC_STATE_IDLE;
1777 device_free_td0_ring(pDevice);
1778 device_free_td1_ring(pDevice);
1779 device_free_rd0_ring(pDevice);
1780 device_free_rd1_ring(pDevice);
1781 device_free_frag_buf(pDevice);
1782 device_free_rings(pDevice);
1783 BSSvClearNodeDBTable(pDevice, 0);
1784 free_irq(dev->irq, dev);
1785 pDevice->flags &= (~DEVICE_FLAGS_OPENED);
1786 //2008-0714-01<Add>by chester
1787 device_release_WPADEV(pDevice);
1789 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close.. \n");
1793 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
1794 PSDevice pDevice = netdev_priv(dev);
1795 unsigned char *pbMPDU;
1796 unsigned int cbMPDULen = 0;
1798 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
1799 spin_lock_irq(&pDevice->lock);
1801 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1802 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
1803 dev_kfree_skb_irq(skb);
1804 spin_unlock_irq(&pDevice->lock);
1808 if (pDevice->bStopTx0Pkt) {
1809 dev_kfree_skb_irq(skb);
1810 spin_unlock_irq(&pDevice->lock);
1814 cbMPDULen = skb->len;
1817 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
1819 spin_unlock_irq(&pDevice->lock);
1824 bool device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, unsigned int uNodeIndex) {
1825 PSMgmtObject pMgmt = pDevice->pMgmt;
1826 PSTxDesc pHeadTD, pLastTD;
1827 unsigned int cbFrameBodySize;
1828 unsigned int uMACfragNum;
1829 unsigned char byPktType;
1830 bool bNeedEncryption = false;
1831 PSKeyItem pTransmitKey = NULL;
1832 unsigned int cbHeaderSize;
1836 if (pDevice->bStopTx0Pkt) {
1837 dev_kfree_skb_irq(skb);
1841 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1842 dev_kfree_skb_irq(skb);
1843 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
1847 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1848 if (pDevice->uAssocCount == 0) {
1849 dev_kfree_skb_irq(skb);
1850 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
1855 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
1857 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1859 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1860 cbFrameBodySize = skb->len - ETH_HLEN;
1863 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1864 cbFrameBodySize += 8;
1866 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
1868 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
1869 dev_kfree_skb_irq(skb);
1872 byPktType = (unsigned char)pDevice->byPacketType;
1874 if (pDevice->bFixRate) {
1875 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
1876 if (pDevice->uConnectionRate >= RATE_11M)
1877 pDevice->wCurrentRate = RATE_11M;
1879 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1881 if (pDevice->uConnectionRate >= RATE_54M)
1882 pDevice->wCurrentRate = RATE_54M;
1884 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1887 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1891 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1892 pDevice->byPreambleType = pDevice->byShortPreamble;
1894 pDevice->byPreambleType = PREAMBLE_LONG;
1896 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
1898 if (pDevice->wCurrentRate <= RATE_11M) {
1899 byPktType = PK_TYPE_11B;
1900 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1901 byPktType = PK_TYPE_11A;
1903 if (pDevice->bProtectMode)
1904 byPktType = PK_TYPE_11GB;
1906 byPktType = PK_TYPE_11GA;
1909 if (pDevice->bEncryptionEnable)
1910 bNeedEncryption = true;
1912 if (pDevice->bEnableHostWEP) {
1913 pTransmitKey = &STempKey;
1914 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1915 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1916 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1917 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1918 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1919 memcpy(pTransmitKey->abyKey,
1920 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1921 pTransmitKey->uKeyLength
1924 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
1925 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
1926 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
1931 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1933 MACbPSWakeup(pDevice->PortOffset);
1936 pDevice->bPWBitOn = false;
1939 for (ii = 0; ii < uMACfragNum; ii++) {
1940 // Poll Transmit the adapter
1942 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
1944 if (ii == (uMACfragNum - 1))
1946 pHeadTD = pHeadTD->next;
1949 // Save the information needed by the tx interrupt handler
1950 // to complete the Send request
1951 pLastTD->pTDInfo->skb = skb;
1952 pLastTD->pTDInfo->byFlags = 0;
1953 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
1955 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
1957 MACvTransmit0(pDevice->PortOffset);
1962 //TYPE_AC0DMA data tx
1963 static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
1964 PSDevice pDevice = netdev_priv(dev);
1966 PSMgmtObject pMgmt = pDevice->pMgmt;
1967 PSTxDesc pHeadTD, pLastTD;
1968 unsigned int uNodeIndex = 0;
1969 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1970 unsigned short wAID;
1971 unsigned int uMACfragNum = 1;
1972 unsigned int cbFrameBodySize;
1973 unsigned char byPktType;
1974 unsigned int cbHeaderSize;
1975 bool bNeedEncryption = false;
1976 PSKeyItem pTransmitKey = NULL;
1979 bool bTKIP_UseGTK = false;
1980 bool bNeedDeAuth = false;
1981 unsigned char *pbyBSSID;
1982 bool bNodeExist = false;
1984 spin_lock_irq(&pDevice->lock);
1985 if (!pDevice->bLinkPass) {
1986 dev_kfree_skb_irq(skb);
1987 spin_unlock_irq(&pDevice->lock);
1991 if (pDevice->bStopDataPkt) {
1992 dev_kfree_skb_irq(skb);
1993 spin_unlock_irq(&pDevice->lock);
1997 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1998 if (pDevice->uAssocCount == 0) {
1999 dev_kfree_skb_irq(skb);
2000 spin_unlock_irq(&pDevice->lock);
2003 if (is_multicast_ether_addr((unsigned char *)(skb->data))) {
2006 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2007 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2008 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2010 pMgmt->abyPSTxMap[0] |= byMask[0];
2011 spin_unlock_irq(&pDevice->lock);
2015 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
2016 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2017 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2018 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2020 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2021 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2022 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2023 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2024 spin_unlock_irq(&pDevice->lock);
2028 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
2029 pDevice->byPreambleType = pDevice->byShortPreamble;
2031 pDevice->byPreambleType = PREAMBLE_LONG;
2039 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Unknown STA not found in node DB \n");
2040 dev_kfree_skb_irq(skb);
2041 spin_unlock_irq(&pDevice->lock);
2046 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
2048 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2050 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
2051 cbFrameBodySize = skb->len - ETH_HLEN;
2053 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
2054 cbFrameBodySize += 8;
2056 if (pDevice->bEncryptionEnable) {
2057 bNeedEncryption = true;
2060 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2061 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2062 pbyBSSID = pDevice->abyBSSID;
2064 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
2066 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2067 bTKIP_UseGTK = true;
2068 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
2072 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get PTK.\n");
2075 } else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2076 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2077 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "IBSS Serach Key: \n");
2078 for (ii = 0; ii < 6; ii++)
2079 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "%x \n", *(pbyBSSID+ii));
2080 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "\n");
2083 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
2087 pbyBSSID = pDevice->abyBroadcastAddr;
2088 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2089 pTransmitKey = NULL;
2090 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
2091 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2093 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2095 bTKIP_UseGTK = true;
2096 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
2101 if (pDevice->bEnableHostWEP) {
2102 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "acdma0: STA index %d\n", uNodeIndex);
2103 if (pDevice->bEncryptionEnable) {
2104 pTransmitKey = &STempKey;
2105 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2106 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2107 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2108 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2109 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2110 memcpy(pTransmitKey->abyKey,
2111 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2112 pTransmitKey->uKeyLength
2117 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2119 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2120 DBG_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
2121 dev_kfree_skb_irq(skb);
2122 spin_unlock_irq(&pDevice->lock);
2126 if (pTransmitKey != NULL) {
2127 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2128 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2129 uMACfragNum = 1; //WEP256 doesn't support fragment
2133 byPktType = (unsigned char)pDevice->byPacketType;
2135 if (pDevice->bFixRate) {
2137 printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n", pDevice->eCurrentPHYType, pDevice->uConnectionRate);
2140 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2141 if (pDevice->uConnectionRate >= RATE_11M)
2142 pDevice->wCurrentRate = RATE_11M;
2144 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2146 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2147 (pDevice->uConnectionRate <= RATE_6M)) {
2148 pDevice->wCurrentRate = RATE_6M;
2150 if (pDevice->uConnectionRate >= RATE_54M)
2151 pDevice->wCurrentRate = RATE_54M;
2153 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2157 pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate;
2158 pDevice->byTopCCKBasicRate = RATE_1M;
2159 pDevice->byTopOFDMBasicRate = RATE_6M;
2162 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2163 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2164 pDevice->wCurrentRate = RATE_1M;
2165 pDevice->byACKRate = RATE_1M;
2166 pDevice->byTopCCKBasicRate = RATE_1M;
2167 pDevice->byTopOFDMBasicRate = RATE_6M;
2169 pDevice->wCurrentRate = RATE_6M;
2170 pDevice->byACKRate = RATE_6M;
2171 pDevice->byTopCCKBasicRate = RATE_1M;
2172 pDevice->byTopOFDMBasicRate = RATE_6M;
2175 VNTWIFIvGetTxRate(pDevice->pMgmt,
2176 pDevice->sTxEthHeader.abyDstAddr,
2177 &(pDevice->wCurrentRate),
2178 &(pDevice->byACKRate),
2179 &(pDevice->byTopCCKBasicRate),
2180 &(pDevice->byTopOFDMBasicRate));
2186 if (pDevice->wCurrentRate <= RATE_11M) {
2187 byPktType = PK_TYPE_11B;
2188 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2189 byPktType = PK_TYPE_11A;
2191 if (pDevice->bProtectMode)
2192 byPktType = PK_TYPE_11GB;
2194 byPktType = PK_TYPE_11GA;
2197 if (bNeedEncryption) {
2198 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2199 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2200 bNeedEncryption = false;
2201 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2202 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2203 if (pTransmitKey == NULL) {
2204 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Don't Find TX KEY\n");
2207 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "error: KEY is GTK!!~~\n");
2209 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2210 bNeedEncryption = true;
2215 if (pDevice->byCntMeasure == 2) {
2217 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2220 if (pDevice->bEnableHostWEP) {
2221 if ((uNodeIndex != 0) &&
2222 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2223 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2224 bNeedEncryption = true;
2228 if (pTransmitKey == NULL) {
2229 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return no tx key\n");
2230 dev_kfree_skb_irq(skb);
2231 spin_unlock_irq(&pDevice->lock);
2237 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2238 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2239 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
2244 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2246 MACbPSWakeup(pDevice->PortOffset);
2248 pDevice->bPWBitOn = false;
2251 for (ii = 0; ii < uMACfragNum; ii++) {
2252 // Poll Transmit the adapter
2254 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2256 if (ii == uMACfragNum - 1)
2258 pHeadTD = pHeadTD->next;
2261 // Save the information needed by the tx interrupt handler
2262 // to complete the Send request
2263 pLastTD->pTDInfo->skb = skb;
2264 pLastTD->pTDInfo->byFlags = 0;
2265 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2267 pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
2269 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1)
2270 netif_stop_queue(dev);
2272 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2274 if (pDevice->bFixRate)
2275 printk("FixRate:Rate is %d,TxPower is %d\n", pDevice->wCurrentRate, pDevice->byCurPwr);
2278 unsigned char Protocol_Version; //802.1x Authentication
2279 unsigned char Packet_Type; //802.1x Authentication
2280 unsigned char Descriptor_type;
2281 unsigned short Key_info;
2282 bool bTxeapol_key = false;
2283 Protocol_Version = skb->data[ETH_HLEN];
2284 Packet_Type = skb->data[ETH_HLEN+1];
2285 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2286 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2287 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2288 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2289 (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame transfer
2290 bTxeapol_key = true;
2291 if ((Descriptor_type == 254) || (Descriptor_type == 2)) { //WPA or RSN
2292 if (!(Key_info & BIT3) && //group-key challenge
2293 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2294 pDevice->fWPA_Authened = true;
2295 if (Descriptor_type == 254)
2299 printk("Authentication completed!!\n");
2306 MACvTransmitAC0(pDevice->PortOffset);
2308 dev->trans_start = jiffies;
2310 spin_unlock_irq(&pDevice->lock);
2314 static irqreturn_t device_intr(int irq, void *dev_instance) {
2315 struct net_device *dev = dev_instance;
2316 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2319 unsigned long dwMIBCounter = 0;
2320 PSMgmtObject pMgmt = pDevice->pMgmt;
2321 unsigned char byOrgPageSel = 0;
2323 unsigned char byData = 0;
2326 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2328 if (pDevice->dwIsr == 0)
2329 return IRQ_RETVAL(handled);
2331 if (pDevice->dwIsr == 0xffffffff) {
2332 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
2333 return IRQ_RETVAL(handled);
2337 MACvIntDisable(pDevice->PortOffset);
2338 spin_lock_irq(&pDevice->lock);
2340 //Make sure current page is 0
2341 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2342 if (byOrgPageSel == 1)
2343 MACvSelectPage0(pDevice->PortOffset);
2347 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2349 // Must do this after doing rx/tx, cause ISR bit is slow
2350 // than RD/TD write back
2351 // update ISR counter
2352 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2353 while (pDevice->dwIsr != 0) {
2354 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2355 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2357 if (pDevice->dwIsr & ISR_FETALERR) {
2358 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR \n");
2359 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2360 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2361 device_error(pDevice, pDevice->dwIsr);
2364 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2365 if (pDevice->dwIsr & ISR_MEASURESTART) {
2366 // 802.11h measure start
2367 pDevice->byOrgChannel = pDevice->byCurrentCh;
2368 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2369 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2370 MACvSelectPage1(pDevice->PortOffset);
2371 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2372 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2373 MACvSelectPage0(pDevice->PortOffset);
2375 if (set_channel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel)) {
2376 pDevice->bMeasureInProgress = true;
2377 MACvSelectPage1(pDevice->PortOffset);
2378 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2379 MACvSelectPage0(pDevice->PortOffset);
2380 pDevice->byBasicMap = 0;
2381 pDevice->byCCAFraction = 0;
2382 for (ii = 0; ii < 8; ii++)
2383 pDevice->dwRPIs[ii] = 0;
2386 // can not measure because set channel fail
2387 // clear measure control
2388 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2389 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2390 MACvSelectPage1(pDevice->PortOffset);
2391 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2392 MACvSelectPage0(pDevice->PortOffset);
2395 if (pDevice->dwIsr & ISR_MEASUREEND) {
2396 // 802.11h measure end
2397 pDevice->bMeasureInProgress = false;
2398 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2399 MACvSelectPage1(pDevice->PortOffset);
2400 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2401 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2402 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2403 pDevice->byBasicMap |= (byData >> 4);
2404 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2405 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2406 // clear measure control
2407 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2408 MACvSelectPage0(pDevice->PortOffset);
2409 set_channel(pDevice, pDevice->byOrgChannel);
2410 MACvSelectPage1(pDevice->PortOffset);
2411 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2412 MACvSelectPage0(pDevice->PortOffset);
2413 if (byData & MSRCTL_FINISH) {
2415 s_vCompleteCurrentMeasure(pDevice, 0);
2417 // can not measure because not ready before end of measure time
2418 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2421 if (pDevice->dwIsr & ISR_QUIETSTART) {
2424 } while (!CARDbStartQuiet(pDevice));
2428 if (pDevice->dwIsr & ISR_TBTT) {
2429 if (pDevice->bEnableFirstQuiet) {
2430 pDevice->byQuietStartCount--;
2431 if (pDevice->byQuietStartCount == 0) {
2432 pDevice->bEnableFirstQuiet = false;
2433 MACvSelectPage1(pDevice->PortOffset);
2434 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2435 MACvSelectPage0(pDevice->PortOffset);
2438 if (pDevice->bChannelSwitch &&
2439 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
2440 pDevice->byChannelSwitchCount--;
2441 if (pDevice->byChannelSwitchCount == 0) {
2442 pDevice->bChannelSwitch = false;
2443 set_channel(pDevice, pDevice->byNewChannel);
2444 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2445 MACvSelectPage1(pDevice->PortOffset);
2446 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2447 MACvSelectPage0(pDevice->PortOffset);
2448 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2452 if (pDevice->eOPMode != OP_MODE_ADHOC) {
2453 if ((pDevice->bUpdateBBVGA) && pDevice->bLinkPass && (pDevice->uCurrRSSI != 0)) {
2456 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
2457 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
2458 if (ldBm < pDevice->ldBmThreshold[ii]) {
2459 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2463 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2464 pDevice->uBBVGADiffCount++;
2465 if (pDevice->uBBVGADiffCount == 1) {
2466 // first VGA diff gain
2467 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2468 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2469 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2471 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2472 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2473 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2474 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2477 pDevice->uBBVGADiffCount = 1;
2482 pDevice->bBeaconSent = false;
2483 if (pDevice->bEnablePSMode)
2484 PSbIsNextTBTTWakeUp((void *)pDevice);
2486 if ((pDevice->eOPMode == OP_MODE_AP) ||
2487 (pDevice->eOPMode == OP_MODE_ADHOC)) {
2488 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2489 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2492 /* TODO: adhoc PS mode */
2496 if (pDevice->dwIsr & ISR_BNTX) {
2497 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2498 pDevice->bIsBeaconBufReadySet = false;
2499 pDevice->cbBeaconBufReadySetCnt = 0;
2502 if (pDevice->eOPMode == OP_MODE_AP) {
2503 if (pMgmt->byDTIMCount > 0) {
2504 pMgmt->byDTIMCount--;
2505 pMgmt->sNodeDBTable[0].bRxPSPoll = false;
2507 if (pMgmt->byDTIMCount == 0) {
2508 // check if mutltcast tx bufferring
2509 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2510 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
2511 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2515 pDevice->bBeaconSent = true;
2517 if (pDevice->bChannelSwitch) {
2518 pDevice->byChannelSwitchCount--;
2519 if (pDevice->byChannelSwitchCount == 0) {
2520 pDevice->bChannelSwitch = false;
2521 set_channel(pDevice, pDevice->byNewChannel);
2522 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2523 MACvSelectPage1(pDevice->PortOffset);
2524 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2525 MACvSelectPage0(pDevice->PortOffset);
2526 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2532 if (pDevice->dwIsr & ISR_RXDMA0)
2533 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2535 if (pDevice->dwIsr & ISR_RXDMA1)
2536 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2538 if (pDevice->dwIsr & ISR_TXDMA0)
2539 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2541 if (pDevice->dwIsr & ISR_AC0DMA)
2542 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2544 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2545 if (pDevice->eOPMode == OP_MODE_AP) {
2546 if (pDevice->bShortSlotTime)
2547 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2549 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2551 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2552 pDevice->byCntMeasure = 0;
2555 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2557 MACvReceive0(pDevice->PortOffset);
2558 MACvReceive1(pDevice->PortOffset);
2560 if (max_count > pDevice->sOpts.int_works)
2564 if (byOrgPageSel == 1)
2565 MACvSelectPage1(pDevice->PortOffset);
2567 spin_unlock_irq(&pDevice->lock);
2568 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2570 return IRQ_RETVAL(handled);
2573 static unsigned const ethernet_polynomial = 0x04c11db7U;
2574 static inline u32 ether_crc(int length, unsigned char *data)
2578 while (--length >= 0) {
2579 unsigned char current_octet = *data++;
2581 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
2583 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
2589 //2008-8-4 <add> by chester
2590 static int Config_FileGetParameter(unsigned char *string,
2591 unsigned char *dest, unsigned char *source)
2593 unsigned char buf1[100];
2594 int source_len = strlen(source);
2596 memset(buf1, 0, 100);
2597 strcat(buf1, string);
2599 source += strlen(buf1);
2601 memcpy(dest, source, source_len - strlen(buf1));
2605 int Config_FileOperation(PSDevice pDevice,bool fwrite,unsigned char *Parameter)
2607 unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
2608 unsigned char tmpbuffer[20];
2613 printk("allocate mem for file fail?\n");
2616 file = filp_open(CONFIG_PATH, O_RDONLY, 0);
2619 printk("Config_FileOperation:open file fail?\n");
2623 if (kernel_read(file, 0, buffer, 1024) < 0) {
2624 printk("read file error?\n");
2629 if (Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=true) {
2630 printk("get parameter error?\n");
2635 if (memcmp(tmpbuffer,"USA",3)==0) {
2636 result = ZoneType_USA;
2637 } else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
2638 result = ZoneType_Japan;
2639 } else if(memcmp(tmpbuffer,"EUROPE",5)==0) {
2640 result = ZoneType_Europe;
2643 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
2652 static void device_set_multi(struct net_device *dev) {
2653 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2655 PSMgmtObject pMgmt = pDevice->pMgmt;
2657 struct netdev_hw_addr *ha;
2659 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
2661 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
2662 DBG_PRT(MSG_LEVEL_ERR, KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
2663 /* Unconditionally log net taps. */
2664 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
2665 } else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
2666 || (dev->flags & IFF_ALLMULTI)) {
2667 MACvSelectPage1(pDevice->PortOffset);
2668 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
2669 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
2670 MACvSelectPage0(pDevice->PortOffset);
2671 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2673 memset(mc_filter, 0, sizeof(mc_filter));
2674 netdev_for_each_mc_addr(ha, dev) {
2675 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
2676 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
2678 MACvSelectPage1(pDevice->PortOffset);
2679 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
2680 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
2681 MACvSelectPage0(pDevice->PortOffset);
2682 pDevice->byRxMode &= ~(RCR_UNICAST);
2683 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2686 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2687 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
2688 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2689 pDevice->byRxMode &= ~(RCR_UNICAST);
2692 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
2693 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode);
2696 static struct net_device_stats *device_get_stats(struct net_device *dev) {
2697 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2699 return &pDevice->stats;
2702 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
2703 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2705 struct iwreq *wrq = (struct iwreq *)rq;
2707 PSMgmtObject pMgmt = pDevice->pMgmt;
2710 if (pMgmt == NULL) {
2717 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
2720 case SIOCGIWNWID: //0x8b03 support
2724 // Set frequency/channel
2726 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
2729 // Get frequency/channel
2731 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
2734 // Set desired network name (ESSID)
2738 char essid[IW_ESSID_MAX_SIZE+1];
2739 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
2743 if (copy_from_user(essid, wrq->u.essid.pointer,
2744 wrq->u.essid.length)) {
2748 rc = iwctl_siwessid(dev, NULL,
2749 &(wrq->u.essid), essid);
2753 // Get current network name (ESSID)
2757 char essid[IW_ESSID_MAX_SIZE+1];
2758 if (wrq->u.essid.pointer)
2759 rc = iwctl_giwessid(dev, NULL,
2760 &(wrq->u.essid), essid);
2761 if (copy_to_user(wrq->u.essid.pointer,
2763 wrq->u.essid.length))
2770 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2773 // Get current Access Point (BSSID)
2775 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2778 // Set desired station name
2780 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
2784 // Get current station name
2786 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
2790 // Set the desired bit-rate
2792 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2795 // Get the current bit-rate
2798 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2801 // Set the desired RTS threshold
2804 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
2807 // Get the current RTS threshold
2810 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
2813 // Set the desired fragmentation threshold
2816 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
2819 // Get the current fragmentation threshold
2822 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
2825 // Set mode of operation
2827 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
2830 // Get mode of operation
2832 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
2835 // Set WEP keys and mode
2836 case SIOCSIWENCODE: {
2837 char abyKey[WLAN_WEP232_KEYLEN];
2839 if (wrq->u.encoding.pointer) {
2840 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
2844 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
2845 if (copy_from_user(abyKey,
2846 wrq->u.encoding.pointer,
2847 wrq->u.encoding.length)) {
2851 } else if (wrq->u.encoding.length != 0) {
2855 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2859 // Get the WEP keys and mode
2862 if (!capable(CAP_NET_ADMIN)) {
2867 char abyKey[WLAN_WEP232_KEYLEN];
2869 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2871 if (wrq->u.encoding.pointer) {
2872 if (copy_to_user(wrq->u.encoding.pointer,
2874 wrq->u.encoding.length))
2880 // Get the current Tx-Power
2882 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
2887 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWTXPOW \n");
2893 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
2898 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
2901 // Get range of parameters
2905 struct iw_range range;
2907 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *)&range);
2908 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
2916 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
2921 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
2926 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
2930 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
2934 case SIOCGIWAPLIST: {
2935 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
2937 if (wrq->u.data.pointer) {
2938 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
2940 if (copy_to_user(wrq->u.data.pointer,
2942 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
2954 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
2961 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSPY \n");
2965 #endif // WIRELESS_SPY
2968 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
2972 //2008-0409-07, <Add> by Einsn Liu
2973 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2975 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
2976 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
2980 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH \n");
2981 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
2985 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE \n");
2986 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2990 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE \n");
2991 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2994 case SIOCSIWENCODEEXT: {
2995 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
2996 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
2997 if (wrq->u.encoding.pointer) {
2998 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN + 1);
2999 if (wrq->u.encoding.length > (sizeof(struct iw_encode_ext) + MAX_KEY_LEN)) {
3003 if (copy_from_user(extra, wrq->u.encoding.pointer, wrq->u.encoding.length)) {
3007 } else if (wrq->u.encoding.length != 0) {
3011 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
3015 case SIOCGIWENCODEEXT:
3016 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT \n");
3017 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
3021 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME \n");
3022 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3025 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3026 //End Add -- //2008-0409-07, <Add> by Einsn Liu
3028 case IOCTL_CMD_TEST:
3030 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
3036 pReq = (PSCmdRequest)rq;
3037 pReq->wResult = MAGIC_CODE;
3043 if ((((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_EVT) &&
3044 !(pDevice->flags & DEVICE_FLAGS_OPENED))
3046 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
3047 (((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_WPA))
3056 if (test_and_set_bit(0, (void *)&(pMgmt->uCmdBusy)))
3059 rc = private_ioctl(pDevice, rq);
3060 clear_bit(0, (void *)&(pMgmt->uCmdBusy));
3063 case IOCTL_CMD_HOSTAPD:
3065 rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data);
3070 rc = wpa_ioctl(pDevice, &wrq->u.data);
3074 return ethtool_ioctl(dev, rq->ifr_data);
3075 // All other calls are currently unsupported
3079 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
3083 if (pDevice->bCommit) {
3084 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3085 netif_stop_queue(pDevice->dev);
3086 spin_lock_irq(&pDevice->lock);
3087 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
3088 spin_unlock_irq(&pDevice->lock);
3090 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
3091 spin_lock_irq(&pDevice->lock);
3092 pDevice->bLinkPass = false;
3093 memset(pMgmt->abyCurrBSSID, 0, 6);
3094 pMgmt->eCurrState = WMAC_STATE_IDLE;
3095 netif_stop_queue(pDevice->dev);
3096 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3097 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
3098 if (!pDevice->bWPASuppWextEnabled)
3100 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
3101 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3102 spin_unlock_irq(&pDevice->lock);
3104 pDevice->bCommit = false;
3110 static int ethtool_ioctl(struct net_device *dev, void __user *useraddr)
3114 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
3118 case ETHTOOL_GDRVINFO: {
3119 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3120 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3121 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3122 if (copy_to_user(useraddr, &info, sizeof(info)))
3132 /*------------------------------------------------------------------*/
3134 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
3136 static struct pci_driver device_driver = {
3137 .name = DEVICE_NAME,
3138 .id_table = vt6655_pci_id_table,
3139 .probe = vt6655_probe,
3140 .remove = vt6655_remove,
3142 .suspend = viawget_suspend,
3143 .resume = viawget_resume,
3147 static int __init vt6655_init_module(void)
3151 ret = pci_register_driver(&device_driver);
3154 register_reboot_notifier(&device_notifier);
3160 static void __exit vt6655_cleanup_module(void)
3163 unregister_reboot_notifier(&device_notifier);
3165 pci_unregister_driver(&device_driver);
3168 module_init(vt6655_init_module);
3169 module_exit(vt6655_cleanup_module);
3173 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3175 struct pci_dev *pdev = NULL;
3180 for_each_pci_dev(pdev) {
3181 if (pci_dev_driver(pdev) == &device_driver) {
3182 if (pci_get_drvdata(pdev))
3183 viawget_suspend(pdev, PMSG_HIBERNATE);
3191 viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3193 int power_status; // to silence the compiler
3195 PSDevice pDevice = pci_get_drvdata(pcid);
3196 PSMgmtObject pMgmt = pDevice->pMgmt;
3198 netif_stop_queue(pDevice->dev);
3199 spin_lock_irq(&pDevice->lock);
3200 pci_save_state(pcid);
3201 del_timer(&pDevice->sTimerCommand);
3202 del_timer(&pMgmt->sTimerSecondCallback);
3203 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3204 pDevice->uCmdDequeueIdx = 0;
3205 pDevice->uCmdEnqueueIdx = 0;
3206 pDevice->bCmdRunning = false;
3207 MACbShutdown(pDevice->PortOffset);
3208 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3209 pDevice->bLinkPass = false;
3210 memset(pMgmt->abyCurrBSSID, 0, 6);
3211 pMgmt->eCurrState = WMAC_STATE_IDLE;
3212 pci_disable_device(pcid);
3213 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3214 spin_unlock_irq(&pDevice->lock);
3219 viawget_resume(struct pci_dev *pcid)
3221 PSDevice pDevice = pci_get_drvdata(pcid);
3222 PSMgmtObject pMgmt = pDevice->pMgmt;
3223 int power_status; // to silence the compiler
3225 power_status = pci_set_power_state(pcid, PCI_D0);
3226 power_status = pci_enable_wake(pcid, PCI_D0, 0);
3227 pci_restore_state(pcid);
3228 if (netif_running(pDevice->dev)) {
3229 spin_lock_irq(&pDevice->lock);
3230 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3231 device_init_registers(pDevice, DEVICE_INIT_DXPL);
3232 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
3233 pMgmt->sNodeDBTable[0].bActive = false;
3234 pDevice->bLinkPass = false;
3235 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3236 // In Adhoc, BSS state set back to started.
3237 pMgmt->eCurrState = WMAC_STATE_STARTED;
3239 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3240 pMgmt->eCurrState = WMAC_STATE_IDLE;
3243 init_timer(&pMgmt->sTimerSecondCallback);
3244 init_timer(&pDevice->sTimerCommand);
3245 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3246 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
3247 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3248 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3249 spin_unlock_irq(&pDevice->lock);