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 * device_found1 - module initial (insmod) driver entry
30 * device_remove1 - module remove entry
31 * device_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
85 #include <linux/delay.h>
86 #include <linux/kthread.h>
87 #include <linux/slab.h>
90 /*--------------------- Static Definitions -------------------------*/
91 //static int msglevel =MSG_LEVEL_DEBUG;
92 static int msglevel = MSG_LEVEL_INFO;
96 // Define module options
98 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
99 MODULE_LICENSE("GPL");
100 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
103 static int mlme_kill;
104 //static struct task_struct * mlme_task;
107 #define DEVICE_PARAM(N,D)
109 static const int N[MAX_UINTS]=OPTION_DEFAULT;\
110 MODULE_PARM(N, "1-" __MODULE_STRING(MAX_UINTS) "i");\
111 MODULE_PARM_DESC(N, D);
114 #define RX_DESC_MIN0 16
115 #define RX_DESC_MAX0 128
116 #define RX_DESC_DEF0 32
117 DEVICE_PARAM(RxDescriptors0,"Number of receive descriptors0");
119 #define RX_DESC_MIN1 16
120 #define RX_DESC_MAX1 128
121 #define RX_DESC_DEF1 32
122 DEVICE_PARAM(RxDescriptors1,"Number of receive descriptors1");
124 #define TX_DESC_MIN0 16
125 #define TX_DESC_MAX0 128
126 #define TX_DESC_DEF0 32
127 DEVICE_PARAM(TxDescriptors0,"Number of transmit descriptors0");
129 #define TX_DESC_MIN1 16
130 #define TX_DESC_MAX1 128
131 #define TX_DESC_DEF1 64
132 DEVICE_PARAM(TxDescriptors1,"Number of transmit descriptors1");
135 #define IP_ALIG_DEF 0
136 /* IP_byte_align[] is used for IP header DWORD byte aligned
137 0: indicate the IP header won't be DWORD byte aligned.(Default) .
138 1: indicate the IP header will be DWORD byte aligned.
139 In some enviroment, the IP header should be DWORD byte aligned,
140 or the packet will be droped when we receive it. (eg: IPVS)
142 DEVICE_PARAM(IP_byte_align,"Enable IP header dword aligned");
145 #define INT_WORKS_DEF 20
146 #define INT_WORKS_MIN 10
147 #define INT_WORKS_MAX 64
149 DEVICE_PARAM(int_works,"Number of packets per interrupt services");
151 #define CHANNEL_MIN 1
152 #define CHANNEL_MAX 14
153 #define CHANNEL_DEF 6
155 DEVICE_PARAM(Channel, "Channel number");
158 /* PreambleType[] is the preamble length used for transmit.
159 0: indicate allows long preamble type
160 1: indicate allows short preamble type
163 #define PREAMBLE_TYPE_DEF 1
165 DEVICE_PARAM(PreambleType, "Preamble Type");
168 #define RTS_THRESH_MIN 512
169 #define RTS_THRESH_MAX 2347
170 #define RTS_THRESH_DEF 2347
172 DEVICE_PARAM(RTSThreshold, "RTS threshold");
175 #define FRAG_THRESH_MIN 256
176 #define FRAG_THRESH_MAX 2346
177 #define FRAG_THRESH_DEF 2346
179 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
182 #define DATA_RATE_MIN 0
183 #define DATA_RATE_MAX 13
184 #define DATA_RATE_DEF 13
186 0: indicate 1 Mbps 0x02
187 1: indicate 2 Mbps 0x04
188 2: indicate 5.5 Mbps 0x0B
189 3: indicate 11 Mbps 0x16
190 4: indicate 6 Mbps 0x0c
191 5: indicate 9 Mbps 0x12
192 6: indicate 12 Mbps 0x18
193 7: indicate 18 Mbps 0x24
194 8: indicate 24 Mbps 0x30
195 9: indicate 36 Mbps 0x48
196 10: indicate 48 Mbps 0x60
197 11: indicate 54 Mbps 0x6c
198 12: indicate 72 Mbps 0x90
199 13: indicate auto rate
202 DEVICE_PARAM(ConnectionRate, "Connection data rate");
204 #define OP_MODE_DEF 0
206 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
208 /* OpMode[] is used for transmit.
209 0: indicate infrastruct mode used
210 1: indicate adhoc mode used
211 2: indicate AP mode used
216 0: indicate disable power saving mode
217 1: indicate enable power saving mode
220 #define PS_MODE_DEF 0
222 DEVICE_PARAM(PSMode, "Power saving mode");
225 #define SHORT_RETRY_MIN 0
226 #define SHORT_RETRY_MAX 31
227 #define SHORT_RETRY_DEF 8
230 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
232 #define LONG_RETRY_MIN 0
233 #define LONG_RETRY_MAX 15
234 #define LONG_RETRY_DEF 4
237 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
240 /* BasebandType[] baseband type selected
241 0: indicate 802.11a type
242 1: indicate 802.11b type
243 2: indicate 802.11g type
245 #define BBP_TYPE_MIN 0
246 #define BBP_TYPE_MAX 2
247 #define BBP_TYPE_DEF 2
249 DEVICE_PARAM(BasebandType, "baseband type");
254 0: indicate disable 802.11h
255 1: indicate enable 802.11h
258 #define X80211h_MODE_DEF 0
260 DEVICE_PARAM(b80211hEnable, "802.11h mode");
263 0: indicate disable 802.11h
264 1: indicate enable 802.11h
267 #define DIVERSITY_ANT_DEF 0
269 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
273 // Static vars definitions
277 static int device_nics =0;
278 static PSDevice pDevice_Infos =NULL;
279 static struct net_device *root_device_dev = NULL;
281 static CHIP_INFO chip_info_table[]= {
282 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
283 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
287 DEFINE_PCI_DEVICE_TABLE(device_id_table) = {
288 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
292 /*--------------------- Static Functions --------------------------*/
295 static int device_found1(struct pci_dev *pcid, const struct pci_device_id *ent);
296 static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice, PCHIP_INFO);
297 static void device_free_info(PSDevice pDevice);
298 static BOOL device_get_pci_info(PSDevice, struct pci_dev* pcid);
299 static void device_print_info(PSDevice pDevice);
300 static struct net_device_stats *device_get_stats(struct net_device *dev);
301 static void device_init_diversity_timer(PSDevice pDevice);
302 static int device_open(struct net_device *dev);
303 static int device_xmit(struct sk_buff *skb, struct net_device *dev);
304 static irqreturn_t device_intr(int irq, void*dev_instance);
305 static void device_set_multi(struct net_device *dev);
306 static int device_close(struct net_device *dev);
307 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
310 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
311 static int viawget_suspend(struct pci_dev *pcid, pm_message_t state);
312 static int viawget_resume(struct pci_dev *pcid);
313 struct notifier_block device_notifier = {
314 notifier_call: device_notify_reboot,
321 static void device_init_rd0_ring(PSDevice pDevice);
322 static void device_init_rd1_ring(PSDevice pDevice);
323 static void device_init_defrag_cb(PSDevice pDevice);
324 static void device_init_td0_ring(PSDevice pDevice);
325 static void device_init_td1_ring(PSDevice pDevice);
327 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
328 //2008-0714<Add>by Mike Liu
329 static BOOL device_release_WPADEV(PSDevice pDevice);
331 static int ethtool_ioctl(struct net_device *dev, void *useraddr);
332 static int device_rx_srv(PSDevice pDevice, UINT uIdx);
333 static int device_tx_srv(PSDevice pDevice, UINT uIdx);
334 static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pDesc);
335 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
336 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc);
337 static void device_free_td0_ring(PSDevice pDevice);
338 static void device_free_td1_ring(PSDevice pDevice);
339 static void device_free_rd0_ring(PSDevice pDevice);
340 static void device_free_rd1_ring(PSDevice pDevice);
341 static void device_free_rings(PSDevice pDevice);
342 static void device_free_frag_buf(PSDevice pDevice);
343 static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source);
346 /*--------------------- Export Variables --------------------------*/
348 /*--------------------- Export Functions --------------------------*/
352 static char* get_chip_name(int chip_id) {
354 for (i=0;chip_info_table[i].name!=NULL;i++)
355 if (chip_info_table[i].chip_id==chip_id)
357 return chip_info_table[i].name;
360 static void device_remove1(struct pci_dev *pcid)
362 PSDevice pDevice=pci_get_drvdata(pcid);
366 device_free_info(pDevice);
372 device_set_int_opt(int *opt, int val, int min, int max, int def,char* name,char* devname) {
375 else if (val<min || val>max) {
376 DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n" ,
377 devname,name, min,max);
380 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n",
387 device_set_bool_opt(unsigned int *opt, int val,BOOL def,U32 flag, char* name,char* devname) {
390 *opt|=(def ? flag : 0);
391 else if (val<0 || val>1) {
392 DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE
393 "%s: the value of parameter %s is invalid, the valid range is (0-1)\n",devname,name);
394 *opt|=(def ? flag : 0);
396 DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: set parameter %s to %s\n",
397 devname,name , val ? "TRUE" : "FALSE");
398 *opt|=(val ? flag : 0);
403 device_get_options(PSDevice pDevice, int index, char* devname) {
405 POPTIONS pOpts = &(pDevice->sOpts);
406 pOpts->nRxDescs0=RX_DESC_DEF0;
407 pOpts->nRxDescs1=RX_DESC_DEF1;
408 pOpts->nTxDescs[0]=TX_DESC_DEF0;
409 pOpts->nTxDescs[1]=TX_DESC_DEF1;
410 pOpts->flags|=DEVICE_FLAGS_IP_ALIGN;
411 pOpts->int_works=INT_WORKS_DEF;
412 pOpts->rts_thresh=RTS_THRESH_DEF;
413 pOpts->frag_thresh=FRAG_THRESH_DEF;
414 pOpts->data_rate=DATA_RATE_DEF;
415 pOpts->channel_num=CHANNEL_DEF;
417 pOpts->flags|=DEVICE_FLAGS_PREAMBLE_TYPE;
418 pOpts->flags|=DEVICE_FLAGS_OP_MODE;
419 //pOpts->flags|=DEVICE_FLAGS_PS_MODE;
420 pOpts->short_retry=SHORT_RETRY_DEF;
421 pOpts->long_retry=LONG_RETRY_DEF;
422 pOpts->bbp_type=BBP_TYPE_DEF;
423 pOpts->flags|=DEVICE_FLAGS_80211h_MODE;
424 pOpts->flags|=DEVICE_FLAGS_DiversityANT;
430 device_set_options(PSDevice pDevice) {
432 BYTE abyBroadcastAddr[U_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
433 BYTE abySNAP_RFC1042[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
434 BYTE abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
437 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, U_ETHER_ADDR_LEN);
438 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, U_ETHER_ADDR_LEN);
439 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, U_ETHER_ADDR_LEN);
441 pDevice->uChannel = pDevice->sOpts.channel_num;
442 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
443 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
444 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
445 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
446 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
447 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
448 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
449 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
450 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
451 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
452 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
453 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE;
454 pDevice->byBBType = pDevice->sOpts.bbp_type;
455 pDevice->byPacketType = pDevice->byBBType;
458 pDevice->byAutoFBCtrl = AUTO_FB_0;
459 //pDevice->byAutoFBCtrl = AUTO_FB_1;
461 pDevice->bUpdateBBVGA = TRUE;
462 pDevice->byFOETuning = 0;
463 pDevice->wCTSDuration = 0;
464 pDevice->byPreambleType = 0;
467 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uChannel= %d\n",(INT)pDevice->uChannel);
468 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byOpMode= %d\n",(INT)pDevice->byOpMode);
469 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ePSMode= %d\n",(INT)pDevice->ePSMode);
470 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" wRTSThreshold= %d\n",(INT)pDevice->wRTSThreshold);
471 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortRetryLimit= %d\n",(INT)pDevice->byShortRetryLimit);
472 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byLongRetryLimit= %d\n",(INT)pDevice->byLongRetryLimit);
473 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byPreambleType= %d\n",(INT)pDevice->byPreambleType);
474 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortPreamble= %d\n",(INT)pDevice->byShortPreamble);
475 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uConnectionRate= %d\n",(INT)pDevice->uConnectionRate);
476 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byBBType= %d\n",(INT)pDevice->byBBType);
477 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->b11hEnable= %d\n",(INT)pDevice->b11hEnable);
478 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->bDiversityRegCtlON= %d\n",(INT)pDevice->bDiversityRegCtlON);
481 static VOID s_vCompleteCurrentMeasure (IN PSDevice pDevice, IN BYTE byResult)
484 DWORD dwDuration = 0;
487 for(ii=1;ii<8;ii++) {
488 pDevice->dwRPIs[ii] *= 255;
489 dwDuration |= *((PWORD) (pDevice->pCurrMeasureEID->sReq.abyDuration));
491 pDevice->dwRPIs[ii] /= dwDuration;
492 pDevice->abyRPIs[ii] = (BYTE) pDevice->dwRPIs[ii];
493 byRPI0 += pDevice->abyRPIs[ii];
495 pDevice->abyRPIs[0] = (0xFF - byRPI0);
497 if (pDevice->uNumOfMeasureEIDs == 0) {
498 VNTWIFIbMeasureReport( pDevice->pMgmt,
500 pDevice->pCurrMeasureEID,
503 pDevice->byCCAFraction,
507 VNTWIFIbMeasureReport( pDevice->pMgmt,
509 pDevice->pCurrMeasureEID,
512 pDevice->byCCAFraction,
515 CARDbStartMeasure (pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
523 // Initialiation of MAC & BBP registers
526 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
531 BYTE byCCKPwrdBm = 0;
532 BYTE byOFDMPwrdBm = 0;
534 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
535 MACbShutdown(pDevice->PortOffset);
536 BBvSoftwareReset(pDevice->PortOffset);
538 if ((InitType == DEVICE_INIT_COLD) ||
539 (InitType == DEVICE_INIT_DXPL)) {
540 // Do MACbSoftwareReset in MACvInitialize
541 MACbSoftwareReset(pDevice->PortOffset);
543 pDevice->bCCK = TRUE;
544 pDevice->bAES = FALSE;
545 pDevice->bProtectMode = FALSE; //Only used in 11g type, sync with ERP IE
546 pDevice->bNonERPPresent = FALSE;
547 pDevice->bBarkerPreambleMd = FALSE;
548 pDevice->wCurrentRate = RATE_1M;
549 pDevice->byTopOFDMBasicRate = RATE_24M;
550 pDevice->byTopCCKBasicRate = RATE_1M;
552 pDevice->byRevId = 0; //Target to IF pin while programming to RF chip.
555 MACvInitialize(pDevice->PortOffset);
558 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
560 spin_lock_irq(&pDevice->lock);
561 SROMvReadAllContents(pDevice->PortOffset,pDevice->abyEEPROM);
563 spin_unlock_irq(&pDevice->lock);
567 pDevice->byMinChannel = 1;
568 pDevice->byMaxChannel = CB_MAX_CHANNEL;
571 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
572 if (byValue & EEP_ANTINV)
573 pDevice->bTxRxAntInv = TRUE;
575 pDevice->bTxRxAntInv = FALSE;
577 //printk("init_register:TxRxAntInv is %d,byValue is %d\n",pDevice->bTxRxAntInv,byValue);
580 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
581 if (byValue == 0) // if not set default is All
582 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
584 //printk("init_register:byValue is %d\n",byValue);
586 pDevice->ulDiversityNValue = 100*260;//100*SROMbyReadEmbedded(pDevice->PortOffset, 0x51);
587 pDevice->ulDiversityMValue = 100*16;//SROMbyReadEmbedded(pDevice->PortOffset, 0x52);
588 pDevice->byTMax = 1;//SROMbyReadEmbedded(pDevice->PortOffset, 0x53);
589 pDevice->byTMax2 = 4;//SROMbyReadEmbedded(pDevice->PortOffset, 0x54);
590 pDevice->ulSQ3TH = 0;//(ULONG) SROMbyReadEmbedded(pDevice->PortOffset, 0x55);
591 pDevice->byTMax3 = 64;//SROMbyReadEmbedded(pDevice->PortOffset, 0x56);
593 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
594 pDevice->byAntennaCount = 2;
595 pDevice->byTxAntennaMode = ANT_B;
596 pDevice->dwTxAntennaSel = 1;
597 pDevice->dwRxAntennaSel = 1;
598 if (pDevice->bTxRxAntInv == TRUE)
599 pDevice->byRxAntennaMode = ANT_A;
601 pDevice->byRxAntennaMode = ANT_B;
602 // chester for antenna
603 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
604 // if (pDevice->bDiversityRegCtlON)
605 if((byValue1&0x08)==0)
606 pDevice->bDiversityEnable = FALSE;//SROMbyReadEmbedded(pDevice->PortOffset, 0x50);
608 pDevice->bDiversityEnable = TRUE;
610 //printk("aux |main antenna: RxAntennaMode is %d\n",pDevice->byRxAntennaMode);
613 pDevice->bDiversityEnable = FALSE;
614 pDevice->byAntennaCount = 1;
615 pDevice->dwTxAntennaSel = 0;
616 pDevice->dwRxAntennaSel = 0;
617 if (byValue & EEP_ANTENNA_AUX) {
618 pDevice->byTxAntennaMode = ANT_A;
619 if (pDevice->bTxRxAntInv == TRUE)
620 pDevice->byRxAntennaMode = ANT_B;
622 pDevice->byRxAntennaMode = ANT_A;
624 pDevice->byTxAntennaMode = ANT_B;
625 if (pDevice->bTxRxAntInv == TRUE)
626 pDevice->byRxAntennaMode = ANT_A;
628 pDevice->byRxAntennaMode = ANT_B;
632 //printk("init registers: TxAntennaMode is %d\n",pDevice->byTxAntennaMode);
634 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
635 pDevice->bDiversityEnable,(int)pDevice->ulDiversityNValue,(int)pDevice->ulDiversityMValue,pDevice->byTMax,pDevice->byTMax2);
637 //#ifdef ZoneType_DefaultSetting
638 //2008-8-4 <add> by chester
640 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
641 if((zonetype=Config_FileOperation(pDevice,FALSE,NULL)) >= 0) { //read zonetype file ok!
642 if ((zonetype == 0)&&
643 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] !=0x00)){ //for USA
644 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
645 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
646 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :USA\n");
648 else if((zonetype == 1)&&
649 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x01)){ //for Japan
650 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
651 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
653 else if((zonetype == 2)&&
654 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x02)){ //for Europe
655 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
656 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
657 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :Europe\n");
662 if(zonetype!=pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
663 printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",zonetype,pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
665 printk("Read Zonetype file success,use default zonetype setting[%02x]\n",zonetype);
669 printk("Read Zonetype file fail,use default zonetype setting[%02x]\n",SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
672 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
674 if ((pDevice->byRFType & RF_EMU) != 0) {
675 // force change RevID for VT3253 emu
676 pDevice->byRevId = 0x80;
679 pDevice->byRFType &= RF_MASK;
680 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
682 if (pDevice->bZoneRegExist == FALSE) {
683 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
685 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
690 //Get Desire Power Value
691 pDevice->byCurPwr = 0xFF;
692 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
693 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
694 //byCCKPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_CCK_PWR_dBm);
696 //byOFDMPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_OFDM_PWR_dBm);
697 //printk("CCKPwrdBm is 0x%x,byOFDMPwrdBm is 0x%x\n",byCCKPwrdBm,byOFDMPwrdBm);
701 for (ii=0;ii<CB_MAX_CHANNEL_24G;ii++) {
702 pDevice->abyCCKPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_CCK_PWR_TBL));
703 if (pDevice->abyCCKPwrTbl[ii+1] == 0) {
704 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
706 pDevice->abyOFDMPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDM_PWR_TBL));
707 if (pDevice->abyOFDMPwrTbl[ii+1] == 0) {
708 pDevice->abyOFDMPwrTbl[ii+1] = pDevice->byOFDMPwrG;
710 pDevice->abyCCKDefaultPwr[ii+1] = byCCKPwrdBm;
711 pDevice->abyOFDMDefaultPwr[ii+1] = byOFDMPwrdBm;
713 //2008-8-4 <add> by chester
714 //recover 12,13 ,14channel for EUROPE by 11 channel
715 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
716 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
717 (pDevice->byOriginalZonetype == ZoneType_USA)) {
718 for(ii=11;ii<14;ii++) {
719 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
720 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
726 // Load OFDM A Power Table
727 for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
728 pDevice->abyOFDMPwrTbl[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_TBL));
729 pDevice->abyOFDMDefaultPwr[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_dBm));
731 CARDvInitChannelTable((PVOID)pDevice);
734 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
735 MACvSelectPage1(pDevice->PortOffset);
736 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
737 MACvSelectPage0(pDevice->PortOffset);
741 // use relative tx timeout and 802.11i D4
742 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
744 // set performance parameter by registry
745 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
746 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
749 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
750 // enable TSF counter
751 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
753 // initialize BBP registers
754 BBbVT3253Init(pDevice);
756 if (pDevice->bUpdateBBVGA) {
757 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
758 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
759 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
762 //printk("init registers:RxAntennaMode is %x,TxAntennaMode is %x\n",pDevice->byRxAntennaMode,pDevice->byTxAntennaMode);
764 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
765 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
767 pDevice->byCurrentCh = 0;
769 //pDevice->NetworkType = Ndis802_11Automode;
770 // Set BB and packet type at the same time.
771 // Set Short Slot Time, xIFS, and RSPINF.
772 if (pDevice->uConnectionRate == RATE_AUTO) {
773 pDevice->wCurrentRate = RATE_54M;
775 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
779 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
780 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
782 pDevice->bRadioOff = FALSE;
784 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
785 pDevice->bHWRadioOff = FALSE;
787 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
789 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
790 //2008-4-14 <add> by chester for led issue
791 #ifdef FOR_LED_ON_NOTEBOOK
792 if (pDevice->byGPIO & GPIO0_DATA){pDevice->bHWRadioOff = TRUE;}
793 if ( !(pDevice->byGPIO & GPIO0_DATA)){pDevice->bHWRadioOff = FALSE;}
796 if ( (pDevice->bRadioControlOff == TRUE)) {
797 CARDbRadioPowerOff(pDevice);
799 else CARDbRadioPowerOn(pDevice);
801 if (((pDevice->byGPIO & GPIO0_DATA) && !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
802 ( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV))) {
803 pDevice->bHWRadioOff = TRUE;
806 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
807 CARDbRadioPowerOff(pDevice);
812 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
813 // get Permanent network address
814 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
815 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %02x-%02x-%02x=%02x-%02x-%02x\n",
816 pDevice->abyCurrentNetAddr[0],
817 pDevice->abyCurrentNetAddr[1],
818 pDevice->abyCurrentNetAddr[2],
819 pDevice->abyCurrentNetAddr[3],
820 pDevice->abyCurrentNetAddr[4],
821 pDevice->abyCurrentNetAddr[5]);
825 CARDvSafeResetRx(pDevice);
827 CARDvSafeResetTx(pDevice);
829 if (pDevice->byLocalID <= REV_ID_VT3253_A1) {
830 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
833 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
836 MACvReceive0(pDevice->PortOffset);
837 MACvReceive1(pDevice->PortOffset);
840 MACvStart(pDevice->PortOffset);
842 netif_stop_queue(pDevice->dev);
849 static VOID device_init_diversity_timer(PSDevice pDevice) {
851 init_timer(&pDevice->TimerSQ3Tmax1);
852 pDevice->TimerSQ3Tmax1.data = (ULONG)pDevice;
853 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
854 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
856 init_timer(&pDevice->TimerSQ3Tmax2);
857 pDevice->TimerSQ3Tmax2.data = (ULONG)pDevice;
858 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
859 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
861 init_timer(&pDevice->TimerSQ3Tmax3);
862 pDevice->TimerSQ3Tmax3.data = (ULONG)pDevice;
863 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
864 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
870 static BOOL device_release_WPADEV(PSDevice pDevice)
872 viawget_wpa_header *wpahdr;
874 // wait_queue_head_t Set_wait;
875 //send device close to wpa_supplicnat layer
876 if (pDevice->bWPADEVUp==TRUE) {
877 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
878 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
879 wpahdr->resp_ie_len = 0;
880 wpahdr->req_ie_len = 0;
881 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
882 pDevice->skb->dev = pDevice->wpadev;
883 skb_reset_mac_header(pDevice->skb);
884 pDevice->skb->pkt_type = PACKET_HOST;
885 pDevice->skb->protocol = htons(ETH_P_802_2);
886 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
887 netif_rx(pDevice->skb);
888 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
890 //wait release WPADEV
891 // init_waitqueue_head(&Set_wait);
892 // wait_event_timeout(Set_wait, ((pDevice->wpadev==NULL)&&(pDevice->skb == NULL)),5*HZ); //1s wait
893 while((pDevice->bWPADEVUp==TRUE)) {
894 set_current_state(TASK_UNINTERRUPTIBLE);
895 schedule_timeout (HZ/20); //wait 50ms
905 static const struct net_device_ops device_netdev_ops = {
906 .ndo_open = device_open,
907 .ndo_stop = device_close,
908 .ndo_do_ioctl = device_ioctl,
909 .ndo_get_stats = device_get_stats,
910 .ndo_start_xmit = device_xmit,
911 .ndo_set_multicast_list = device_set_multi,
917 device_found1(struct pci_dev *pcid, const struct pci_device_id *ent)
919 static BOOL bFirst = TRUE;
920 struct net_device* dev = NULL;
921 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
924 if (device_nics ++>= MAX_UINTS) {
925 printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
930 dev = alloc_etherdev(sizeof(DEVICE_INFO));
932 pDevice = (PSDevice) netdev_priv(dev);
935 printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
939 // Chain it all together
940 // SET_MODULE_OWNER(dev);
941 SET_NETDEV_DEV(dev, &pcid->dev);
944 printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
945 printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
949 if (!device_init_info(pcid, &pDevice, pChip_info)) {
953 pDevice->next_module = root_device_dev;
954 root_device_dev = dev;
955 dev->irq = pcid->irq;
957 if (pci_enable_device(pcid)) {
958 device_free_info(pDevice);
962 printk("Before get pci_info memaddr is %x\n",pDevice->memaddr);
964 if (device_get_pci_info(pDevice,pcid) == FALSE) {
965 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
966 device_free_info(pDevice);
974 //pci_read_config_byte(pcid, PCI_BASE_ADDRESS_0, &pDevice->byRevId);
975 printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",pDevice->memaddr,pDevice->ioaddr,pDevice->io_size);
987 for (i=0;address[i];i++)
989 //pci_write_config_dword(pcid,address[i], 0xFFFFFFFF);
990 pci_read_config_dword(pcid, address[i], &bar);
991 printk("bar %d is %x\n",i,bar);
994 printk("bar %d not implemented\n",i);
997 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
1000 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
1001 len = len & ~(len - 1);
1003 printk("IO space: len in IO %x, BAR %d\n", len, i);
1007 len = bar & 0xFFFFFFF0;
1010 printk("len in MEM %x, BAR %d\n", len, i);
1022 pDevice->PortOffset = (DWORD)ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
1023 //pDevice->PortOffset = (DWORD)ioremap(pDevice->ioaddr & PCI_BASE_ADDRESS_IO_MASK, pDevice->io_size);
1025 if(pDevice->PortOffset == 0) {
1026 printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
1027 device_free_info(pDevice);
1034 rc = pci_request_regions(pcid, DEVICE_NAME);
1036 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
1037 device_free_info(pDevice);
1041 dev->base_addr = pDevice->ioaddr;
1045 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1046 printk("Before write: value is %x\n",value);
1047 //VNSvInPortB(pDevice->PortOffset+0x3F, 0x00);
1048 VNSvOutPortB(pDevice->PortOffset,value);
1049 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1050 printk("After write: value is %x\n",value);
1056 pDevice->PortOffset = pDevice->ioaddr;
1059 if (!MACbSoftwareReset(pDevice->PortOffset)) {
1060 printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
1061 device_free_info(pDevice);
1064 // initial to reload eeprom
1065 MACvInitialize(pDevice->PortOffset);
1066 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
1068 device_get_options(pDevice, device_nics-1, dev->name);
1069 device_set_options(pDevice);
1070 //Mask out the options cannot be set to the chip
1071 pDevice->sOpts.flags &= pChip_info->flags;
1073 //Enable the chip specified capbilities
1074 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
1075 pDevice->tx_80211 = device_dma0_tx_80211;
1076 pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;
1077 pDevice->pMgmt = &(pDevice->sMgmtObj);
1079 dev->irq = pcid->irq;
1080 dev->netdev_ops = &device_netdev_ops;
1082 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
1084 rc = register_netdev(dev);
1087 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
1088 device_free_info(pDevice);
1091 //2008-07-21-01<Add>by MikeLiu
1093 if(wpa_set_wpadev(pDevice, 1)!=0) {
1094 printk("Fail to Register WPADEV?\n");
1095 unregister_netdev(pDevice->dev);
1098 device_print_info(pDevice);
1099 pci_set_drvdata(pcid, pDevice);
1104 static void device_print_info(PSDevice pDevice)
1106 struct net_device* dev=pDevice->dev;
1108 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n",dev->name, get_chip_name(pDevice->chip_id));
1109 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%pM", dev->name, dev->dev_addr);
1111 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx ",(ULONG) pDevice->ioaddr);
1112 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1114 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx Mem=0x%lx ",(ULONG) pDevice->ioaddr,(ULONG) pDevice->PortOffset);
1115 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1120 static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice,
1121 PCHIP_INFO pChip_info) {
1125 memset(*ppDevice,0,sizeof(DEVICE_INFO));
1127 if (pDevice_Infos == NULL) {
1128 pDevice_Infos =*ppDevice;
1131 for (p=pDevice_Infos;p->next!=NULL;p=p->next)
1133 p->next = *ppDevice;
1134 (*ppDevice)->prev = p;
1137 (*ppDevice)->pcid = pcid;
1138 (*ppDevice)->chip_id = pChip_info->chip_id;
1139 (*ppDevice)->io_size = pChip_info->io_size;
1140 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
1141 (*ppDevice)->multicast_limit =32;
1143 spin_lock_init(&((*ppDevice)->lock));
1148 static BOOL device_get_pci_info(PSDevice pDevice, struct pci_dev* pcid) {
1154 BYTE pci_config[256];
1158 memset(pci_config,0x00,256);
1161 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
1162 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID,&pDevice->SubSystemID);
1163 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
1164 pci_read_config_word(pcid, PCI_COMMAND, (u16 *) & (pci_cmd));
1166 pci_set_master(pcid);
1168 pDevice->memaddr = pci_resource_start(pcid,0);
1169 pDevice->ioaddr = pci_resource_start(pcid,1);
1172 // pDevice->ioaddr = pci_resource_start(pcid, 0);
1173 // pDevice->memaddr = pci_resource_start(pcid,1);
1176 cis_addr = pci_resource_start(pcid,2);
1178 pDevice->pcid = pcid;
1180 pci_read_config_byte(pcid, PCI_COMMAND, &b);
1181 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
1184 //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
1185 //printk("max lat is %x,SubSystemID is %x\n",max_lat,pDevice->SubSystemID);
1186 //for (ii=0;ii<0xFF;ii++)
1187 //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
1189 //pci_write_config_word(pcid,PCI_MAX_LAT,max_lat);
1190 //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
1191 //printk("max lat is %x\n",max_lat);
1193 for (ii=0;ii<0xFF;ii++)
1195 pci_read_config_byte(pcid,ii,&value);
1196 pci_config[ii] = value;
1198 for (ii=0,j=1;ii<0x100;ii++,j++)
1202 printk("%x:",pci_config[ii]);
1207 printk("%x:",pci_config[ii]);
1214 static void device_free_info(PSDevice pDevice) {
1216 struct net_device* dev=pDevice->dev;
1219 //2008-0714-01<Add>by chester
1220 device_release_WPADEV(pDevice);
1222 //2008-07-21-01<Add>by MikeLiu
1224 if(wpa_set_wpadev(pDevice, 0)!=0)
1225 printk("unregister wpadev fail?\n");
1227 if (pDevice_Infos==NULL)
1230 for (ptr=pDevice_Infos;ptr && (ptr!=pDevice);ptr=ptr->next)
1234 if (ptr==pDevice_Infos)
1235 pDevice_Infos=ptr->next;
1237 ptr->prev->next=ptr->next;
1240 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
1245 hostap_set_hostapd(pDevice, 0, 0);
1248 unregister_netdev(dev);
1250 if (pDevice->PortOffset)
1251 iounmap((PVOID)pDevice->PortOffset);
1254 pci_release_regions(pDevice->pcid);
1258 if (pDevice->pcid) {
1259 pci_set_drvdata(pDevice->pcid,NULL);
1263 static BOOL device_init_rings(PSDevice pDevice) {
1267 /*allocate all RD/TD rings a single pool*/
1268 vir_pool = pci_alloc_consistent(pDevice->pcid,
1269 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1270 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1271 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1272 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1273 &pDevice->pool_dma);
1275 if (vir_pool == NULL) {
1276 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
1281 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1282 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1283 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1284 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1287 pDevice->aRD0Ring = vir_pool;
1288 pDevice->aRD1Ring = vir_pool +
1289 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1292 pDevice->rd0_pool_dma = pDevice->pool_dma;
1293 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1294 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1296 pDevice->tx0_bufs = pci_alloc_consistent(pDevice->pcid,
1297 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1298 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1299 CB_BEACON_BUF_SIZE +
1301 &pDevice->tx_bufs_dma0);
1303 if (pDevice->tx0_bufs == NULL) {
1304 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
1305 pci_free_consistent(pDevice->pcid,
1306 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1307 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1308 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1309 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1310 vir_pool, pDevice->pool_dma
1315 memset(pDevice->tx0_bufs, 0,
1316 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1317 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1318 CB_BEACON_BUF_SIZE +
1322 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1323 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1325 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1326 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1329 // vir_pool: pvoid type
1330 pDevice->apTD0Rings = vir_pool
1331 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1332 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1334 pDevice->apTD1Rings = vir_pool
1335 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1336 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1337 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1340 pDevice->tx1_bufs = pDevice->tx0_bufs +
1341 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1344 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1345 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1347 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1350 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1351 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1354 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1355 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1361 static void device_free_rings(PSDevice pDevice) {
1363 pci_free_consistent(pDevice->pcid,
1364 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1365 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1366 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1367 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1369 pDevice->aRD0Ring, pDevice->pool_dma
1372 if (pDevice->tx0_bufs)
1373 pci_free_consistent(pDevice->pcid,
1374 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1375 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1376 CB_BEACON_BUF_SIZE +
1378 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1382 static void device_init_rd0_ring(PSDevice pDevice) {
1384 dma_addr_t curr = pDevice->rd0_pool_dma;
1387 /* Init the RD0 ring entries */
1388 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1389 pDesc = &(pDevice->aRD0Ring[i]);
1390 pDesc->pRDInfo = alloc_rd_info();
1391 ASSERT(pDesc->pRDInfo);
1392 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1393 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1394 pDevice->dev->name);
1396 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1397 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1398 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1402 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1403 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1407 static void device_init_rd1_ring(PSDevice pDevice) {
1409 dma_addr_t curr = pDevice->rd1_pool_dma;
1412 /* Init the RD1 ring entries */
1413 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1414 pDesc = &(pDevice->aRD1Ring[i]);
1415 pDesc->pRDInfo = alloc_rd_info();
1416 ASSERT(pDesc->pRDInfo);
1417 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1418 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1419 pDevice->dev->name);
1421 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1422 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1423 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1427 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1428 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1432 static void device_init_defrag_cb(PSDevice pDevice) {
1434 PSDeFragControlBlock pDeF;
1436 /* Init the fragment ctl entries */
1437 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1438 pDeF = &(pDevice->sRxDFCB[i]);
1439 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1440 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
1441 pDevice->dev->name);
1444 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1445 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1451 static void device_free_rd0_ring(PSDevice pDevice) {
1454 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1455 PSRxDesc pDesc =&(pDevice->aRD0Ring[i]);
1456 PDEVICE_RD_INFO pRDInfo =pDesc->pRDInfo;
1458 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1459 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1461 dev_kfree_skb(pRDInfo->skb);
1463 kfree((PVOID)pDesc->pRDInfo);
1468 static void device_free_rd1_ring(PSDevice pDevice) {
1472 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1473 PSRxDesc pDesc=&(pDevice->aRD1Ring[i]);
1474 PDEVICE_RD_INFO pRDInfo=pDesc->pRDInfo;
1476 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1477 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1479 dev_kfree_skb(pRDInfo->skb);
1481 kfree((PVOID)pDesc->pRDInfo);
1486 static void device_free_frag_buf(PSDevice pDevice) {
1487 PSDeFragControlBlock pDeF;
1490 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1492 pDeF = &(pDevice->sRxDFCB[i]);
1495 dev_kfree_skb(pDeF->skb);
1501 static void device_init_td0_ring(PSDevice pDevice) {
1506 curr = pDevice->td0_pool_dma;
1507 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1508 pDesc = &(pDevice->apTD0Rings[i]);
1509 pDesc->pTDInfo = alloc_td_info();
1510 ASSERT(pDesc->pTDInfo);
1511 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1512 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1513 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1515 pDesc->next =&(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1516 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1517 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1521 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1522 pDevice->apTailTD[0] = pDevice->apCurrTD[0] =&(pDevice->apTD0Rings[0]);
1526 static void device_init_td1_ring(PSDevice pDevice) {
1531 /* Init the TD ring entries */
1532 curr=pDevice->td1_pool_dma;
1533 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr+=sizeof(STxDesc)) {
1534 pDesc=&(pDevice->apTD1Rings[i]);
1535 pDesc->pTDInfo = alloc_td_info();
1536 ASSERT(pDesc->pTDInfo);
1537 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1538 pDesc->pTDInfo->buf=pDevice->tx1_bufs+(i)*PKT_BUF_SZ;
1539 pDesc->pTDInfo->buf_dma=pDevice->tx_bufs_dma1+(i)*PKT_BUF_SZ;
1541 pDesc->next=&(pDevice->apTD1Rings[(i+1) % pDevice->sOpts.nTxDescs[1]]);
1542 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1543 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1547 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1548 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1553 static void device_free_td0_ring(PSDevice pDevice) {
1555 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1556 PSTxDesc pDesc=&(pDevice->apTD0Rings[i]);
1557 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1559 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1560 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,
1561 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1564 dev_kfree_skb(pTDInfo->skb);
1566 kfree((PVOID)pDesc->pTDInfo);
1570 static void device_free_td1_ring(PSDevice pDevice) {
1573 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1574 PSTxDesc pDesc=&(pDevice->apTD1Rings[i]);
1575 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1577 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1578 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1579 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1582 dev_kfree_skb(pTDInfo->skb);
1584 kfree((PVOID)pDesc->pTDInfo);
1591 /*-----------------------------------------------------------------*/
1593 static int device_rx_srv(PSDevice pDevice, UINT uIdx) {
1598 for (pRD = pDevice->pCurrRD[uIdx];
1599 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1601 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->pCurrRD = %x, works = %d\n", pRD, works);
1604 if (device_receive_frame(pDevice, pRD)) {
1605 if (!device_alloc_rx_buf(pDevice,pRD)) {
1606 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1607 "%s: can not allocate rx buf\n", pDevice->dev->name);
1611 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1612 pDevice->dev->last_rx = jiffies;
1615 pDevice->pCurrRD[uIdx]=pRD;
1621 static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD) {
1623 PDEVICE_RD_INFO pRDInfo=pRD->pRDInfo;
1626 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1628 //printk("device_alloc_rx_buf:skb is %x\n",pRDInfo->skb);
1630 if (pRDInfo->skb==NULL)
1632 ASSERT(pRDInfo->skb);
1633 pRDInfo->skb->dev = pDevice->dev;
1634 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
1635 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1636 *((unsigned int *) &(pRD->m_rd0RD0)) = 0; /* FIX cast */
1638 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1639 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1640 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1641 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1648 BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
1650 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1651 if (pDeF->skb == NULL)
1654 pDeF->skb->dev = pDevice->dev;
1661 static int device_tx_srv(PSDevice pDevice, UINT uIdx) {
1667 UINT uFrameSize, uFIFOHeaderSize;
1668 PSTxBufHead pTxBufHead;
1669 struct net_device_stats* pStats = &pDevice->stats;
1670 struct sk_buff* skb;
1672 PSMgmtObject pMgmt = pDevice->pMgmt;
1675 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] >0; pTD = pTD->next) {
1677 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1682 byTsr0 = pTD->m_td0TD0.byTSR0;
1683 byTsr1 = pTD->m_td0TD0.byTSR1;
1685 //Only the status of first TD in the chain is correct
1686 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1688 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1689 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1690 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1691 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1692 // Update the statistics based on the Transmit status
1693 // now, we DO'NT check TSR0_CDH
1695 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1697 (PBYTE)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1701 BSSvUpdateNodeTxCounter(pDevice,
1703 (PBYTE)(pTD->pTDInfo->buf),
1707 if ( !(byTsr1 & TSR1_TERR)) {
1709 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1710 (INT)uIdx, byTsr1, byTsr0);
1712 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG) {
1713 pDevice->s802_11Counter.TransmittedFragmentCount ++;
1715 pStats->tx_packets++;
1716 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1719 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1720 (INT)uIdx, byTsr1, byTsr0);
1721 pStats->tx_errors++;
1722 pStats->tx_dropped++;
1726 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1727 if (pDevice->bEnableHostapd) {
1728 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif.. \n");
1729 skb = pTD->pTDInfo->skb;
1730 skb->dev = pDevice->apdev;
1731 skb_reset_mac_header(skb);
1732 skb->pkt_type = PACKET_OTHERHOST;
1733 //skb->protocol = htons(ETH_P_802_2);
1734 memset(skb->cb, 0, sizeof(skb->cb));
1739 if (byTsr1 & TSR1_TERR) {
1740 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1741 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1742 (INT)uIdx, byTsr1, byTsr0);
1745 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1746 // (INT)uIdx, byTsr1, byTsr0);
1748 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1749 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1751 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1753 skb = pTD->pTDInfo->skb;
1754 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
1755 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1756 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1757 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1759 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1760 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1761 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1762 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1763 ,(INT)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1764 pStats->tx_errors--;
1765 pStats->tx_dropped--;
1770 device_free_tx_buf(pDevice,pTD);
1771 pDevice->iTDUsed[uIdx]--;
1776 if (uIdx == TYPE_AC0DMA) {
1777 // RESERV_AC0DMA reserved for relay
1779 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1781 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
1783 if (netif_queue_stopped(pDevice->dev) && (bFull==FALSE)){
1784 netif_wake_queue(pDevice->dev);
1789 pDevice->apTailTD[uIdx] = pTD;
1795 static void device_error(PSDevice pDevice, WORD status) {
1797 if (status & ISR_FETALERR) {
1798 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1799 "%s: Hardware fatal error.\n",
1800 pDevice->dev->name);
1801 netif_stop_queue(pDevice->dev);
1802 del_timer(&pDevice->sTimerCommand);
1803 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1804 pDevice->bCmdRunning = FALSE;
1805 MACbShutdown(pDevice->PortOffset);
1811 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc) {
1812 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1813 struct sk_buff* skb=pTDInfo->skb;
1815 // pre-allocated buf_dma can't be unmapped.
1816 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1817 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,skb->len,
1821 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1822 dev_kfree_skb_irq(skb);
1824 pTDInfo->skb_dma = 0;
1826 pTDInfo->byFlags = 0;
1832 VOID InitRxManagementQueue(PSDevice pDevice)
1834 pDevice->rxManeQueue.packet_num = 0;
1835 pDevice->rxManeQueue.head = pDevice->rxManeQueue.tail = 0;
1847 PSDevice pDevice = (PSDevice) Context;
1848 PSRxMgmtPacket pRxMgmtPacket;
1850 //complete(&pDevice->notify);
1851 //printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
1853 //printk("Enter MlmeThread,packet _num is %d\n",pDevice->rxManeQueue.packet_num);
1860 //down(&pDevice->mlme_semaphore);
1861 // pRxMgmtPacket = DeQueue(pDevice);
1863 spin_lock_irq(&pDevice->lock);
1864 while(pDevice->rxManeQueue.packet_num != 0)
1866 pRxMgmtPacket = DeQueue(pDevice);
1868 //DequeueManageObject(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
1869 vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
1870 //printk("packet_num is %d\n",pDevice->rxManeQueue.packet_num);
1873 spin_unlock_irq(&pDevice->lock);
1878 //printk("Before schedule thread jiffies is %x\n",jiffies);
1880 //printk("after schedule thread jiffies is %x\n",jiffies);
1883 //printk("i is %d\n",i);
1893 static int device_open(struct net_device *dev) {
1894 PSDevice pDevice=(PSDevice) netdev_priv(dev);
1896 #ifdef WPA_SM_Transtatus
1897 extern SWPAResult wpa_Result;
1900 pDevice->rx_buf_sz = PKT_BUF_SZ;
1901 if (!device_init_rings(pDevice)) {
1904 //2008-5-13 <add> by chester
1905 i=request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1908 //printk("DEBUG1\n");
1909 #ifdef WPA_SM_Transtatus
1910 memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
1911 wpa_Result.proto = 0;
1912 wpa_Result.key_mgmt = 0;
1913 wpa_Result.eap_type = 0;
1914 wpa_Result.authenticated = FALSE;
1915 pDevice->fWPA_Authened = FALSE;
1917 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
1918 device_init_rd0_ring(pDevice);
1919 device_init_rd1_ring(pDevice);
1920 device_init_defrag_cb(pDevice);
1921 device_init_td0_ring(pDevice);
1922 device_init_td1_ring(pDevice);
1923 // VNTWIFIvSet11h(pDevice->pMgmt, pDevice->b11hEnable);
1926 if (pDevice->bDiversityRegCtlON) {
1927 device_init_diversity_timer(pDevice);
1929 vMgrObjectInit(pDevice);
1930 vMgrTimerInit(pDevice);
1934 tasklet_init (&pDevice->RxMngWorkItem,(void *)MngWorkItem,(unsigned long )pDevice);
1937 InitRxManagementQueue(pDevice);
1939 mlme_task = kthread_run(MlmeThread,(void *) pDevice, "MLME");
1940 if (IS_ERR(mlme_task)) {
1941 printk("thread create fail\n");
1951 pDevice->MLMEThr_pid = kernel_thread(MlmeThread, pDevice, CLONE_VM);
1952 if (pDevice->MLMEThr_pid <0 )
1954 printk("unable start thread MlmeThread\n");
1959 //printk("thread id is %d\n",pDevice->MLMEThr_pid);
1960 //printk("Create thread time is %x\n",jiffies);
1961 //wait_for_completion(&pDevice->notify);
1966 // if (( SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL)&0x06)==0x04)
1968 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
1969 device_init_registers(pDevice, DEVICE_INIT_COLD);
1970 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1971 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, U_ETHER_ADDR_LEN);
1972 device_set_multi(pDevice->dev);
1974 // Init for Key Management
1975 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1976 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1978 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1980 pDevice->bwextstep0 = FALSE;
1981 pDevice->bwextstep1 = FALSE;
1982 pDevice->bwextstep2 = FALSE;
1983 pDevice->bwextstep3 = FALSE;
1985 pDevice->bwextcount=0;
1986 pDevice->bWPASuppWextEnabled = FALSE;
1988 pDevice->byReAssocCount = 0;
1989 pDevice->bWPADEVUp = FALSE;
1990 // Patch: if WEP key already set by iwconfig but device not yet open
1991 if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) {
1992 KeybSetDefaultKey(&(pDevice->sKey),
1993 (DWORD)(pDevice->byKeyIndex | (1 << 31)),
1994 pDevice->uKeyLength,
1998 pDevice->PortOffset,
2001 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
2004 //printk("DEBUG2\n");
2007 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
2008 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2010 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2011 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
2014 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
2015 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_SSID, NULL);
2017 pDevice->flags |=DEVICE_FLAGS_OPENED;
2019 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
2024 static int device_close(struct net_device *dev) {
2025 PSDevice pDevice=(PSDevice) netdev_priv(dev);
2026 PSMgmtObject pMgmt = pDevice->pMgmt;
2032 //2007-1121-02<Add>by EinsnLiu
2033 if (pDevice->bLinkPass) {
2034 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2038 del_timer(&pDevice->sTimerTxData);
2040 del_timer(&pDevice->sTimerCommand);
2041 del_timer(&pMgmt->sTimerSecondCallback);
2042 if (pDevice->bDiversityRegCtlON) {
2043 del_timer(&pDevice->TimerSQ3Tmax1);
2044 del_timer(&pDevice->TimerSQ3Tmax2);
2045 del_timer(&pDevice->TimerSQ3Tmax3);
2049 tasklet_kill(&pDevice->RxMngWorkItem);
2051 netif_stop_queue(dev);
2052 pDevice->bCmdRunning = FALSE;
2053 MACbShutdown(pDevice->PortOffset);
2054 MACbSoftwareReset(pDevice->PortOffset);
2055 CARDbRadioPowerOff(pDevice);
2057 pDevice->bLinkPass = FALSE;
2058 memset(pMgmt->abyCurrBSSID, 0, 6);
2059 pMgmt->eCurrState = WMAC_STATE_IDLE;
2060 device_free_td0_ring(pDevice);
2061 device_free_td1_ring(pDevice);
2062 device_free_rd0_ring(pDevice);
2063 device_free_rd1_ring(pDevice);
2064 device_free_frag_buf(pDevice);
2065 device_free_rings(pDevice);
2066 BSSvClearNodeDBTable(pDevice, 0);
2067 free_irq(dev->irq, dev);
2068 pDevice->flags &=(~DEVICE_FLAGS_OPENED);
2069 //2008-0714-01<Add>by chester
2070 device_release_WPADEV(pDevice);
2072 //tasklet_kill(&pDevice->RxMngWorkItem);
2074 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close.. \n");
2080 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
2081 PSDevice pDevice=netdev_priv(dev);
2086 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
2087 spin_lock_irq(&pDevice->lock);
2089 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2090 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
2091 dev_kfree_skb_irq(skb);
2092 spin_unlock_irq(&pDevice->lock);
2096 if (pDevice->bStopTx0Pkt == TRUE) {
2097 dev_kfree_skb_irq(skb);
2098 spin_unlock_irq(&pDevice->lock);
2102 cbMPDULen = skb->len;
2105 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
2107 spin_unlock_irq(&pDevice->lock);
2115 BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, UINT uNodeIndex) {
2116 PSMgmtObject pMgmt = pDevice->pMgmt;
2117 PSTxDesc pHeadTD, pLastTD;
2118 UINT cbFrameBodySize;
2121 BOOL bNeedEncryption = FALSE;
2122 PSKeyItem pTransmitKey = NULL;
2126 // BYTE byKeyIndex = 0;
2129 if (pDevice->bStopTx0Pkt == TRUE) {
2130 dev_kfree_skb_irq(skb);
2134 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2135 dev_kfree_skb_irq(skb);
2136 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
2140 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2141 if (pDevice->uAssocCount == 0) {
2142 dev_kfree_skb_irq(skb);
2143 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
2148 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
2150 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2152 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2153 cbFrameBodySize = skb->len - U_HEADER_LEN;
2156 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2157 cbFrameBodySize += 8;
2159 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2161 if ( uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
2162 dev_kfree_skb_irq(skb);
2165 byPktType = (BYTE)pDevice->byPacketType;
2168 if (pDevice->bFixRate) {
2169 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2170 if (pDevice->uConnectionRate >= RATE_11M) {
2171 pDevice->wCurrentRate = RATE_11M;
2173 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2176 if (pDevice->uConnectionRate >= RATE_54M)
2177 pDevice->wCurrentRate = RATE_54M;
2179 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2183 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2187 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2188 pDevice->byPreambleType = pDevice->byShortPreamble;
2191 pDevice->byPreambleType = PREAMBLE_LONG;
2194 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2197 if (pDevice->wCurrentRate <= RATE_11M) {
2198 byPktType = PK_TYPE_11B;
2199 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2200 byPktType = PK_TYPE_11A;
2202 if (pDevice->bProtectMode == TRUE) {
2203 byPktType = PK_TYPE_11GB;
2205 byPktType = PK_TYPE_11GA;
2209 if (pDevice->bEncryptionEnable == TRUE)
2210 bNeedEncryption = TRUE;
2212 if (pDevice->bEnableHostWEP) {
2213 pTransmitKey = &STempKey;
2214 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2215 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2216 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2217 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2218 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2219 memcpy(pTransmitKey->abyKey,
2220 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2221 pTransmitKey->uKeyLength
2224 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2225 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
2226 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2231 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2233 MACbPSWakeup(pDevice->PortOffset);
2236 pDevice->bPWBitOn = FALSE;
2239 for (ii = 0; ii < uMACfragNum; ii++) {
2240 // Poll Transmit the adapter
2242 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2244 if (ii == (uMACfragNum - 1))
2246 pHeadTD = pHeadTD->next;
2249 // Save the information needed by the tx interrupt handler
2250 // to complete the Send request
2251 pLastTD->pTDInfo->skb = skb;
2252 pLastTD->pTDInfo->byFlags = 0;
2253 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2255 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
2257 MACvTransmit0(pDevice->PortOffset);
2263 //TYPE_AC0DMA data tx
2264 static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
2265 PSDevice pDevice=netdev_priv(dev);
2267 PSMgmtObject pMgmt = pDevice->pMgmt;
2268 PSTxDesc pHeadTD, pLastTD;
2269 UINT uNodeIndex = 0;
2270 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2272 UINT uMACfragNum = 1;
2273 UINT cbFrameBodySize;
2276 BOOL bNeedEncryption = FALSE;
2277 PSKeyItem pTransmitKey = NULL;
2280 BOOL bTKIP_UseGTK = FALSE;
2281 BOOL bNeedDeAuth = FALSE;
2283 BOOL bNodeExist = FALSE;
2287 spin_lock_irq(&pDevice->lock);
2288 if (pDevice->bLinkPass == FALSE) {
2289 dev_kfree_skb_irq(skb);
2290 spin_unlock_irq(&pDevice->lock);
2294 if (pDevice->bStopDataPkt) {
2295 dev_kfree_skb_irq(skb);
2296 spin_unlock_irq(&pDevice->lock);
2301 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2302 if (pDevice->uAssocCount == 0) {
2303 dev_kfree_skb_irq(skb);
2304 spin_unlock_irq(&pDevice->lock);
2307 if (IS_MULTICAST_ADDRESS((PBYTE)(skb->data))) {
2310 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2311 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2312 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2314 pMgmt->abyPSTxMap[0] |= byMask[0];
2315 spin_unlock_irq(&pDevice->lock);
2319 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
2320 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2321 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2322 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2324 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2325 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2326 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2327 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2328 spin_unlock_irq(&pDevice->lock);
2332 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2333 pDevice->byPreambleType = pDevice->byShortPreamble;
2336 pDevice->byPreambleType = PREAMBLE_LONG;
2343 if (bNodeExist == FALSE) {
2344 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2345 dev_kfree_skb_irq(skb);
2346 spin_unlock_irq(&pDevice->lock);
2351 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
2353 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2356 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2357 cbFrameBodySize = skb->len - U_HEADER_LEN;
2359 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2360 cbFrameBodySize += 8;
2364 if (pDevice->bEncryptionEnable == TRUE) {
2365 bNeedEncryption = TRUE;
2368 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2369 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2370 pbyBSSID = pDevice->abyBSSID;
2372 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2374 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2375 bTKIP_UseGTK = TRUE;
2376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2383 }else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2385 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2386 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2387 for (ii = 0; ii< 6; ii++)
2388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2389 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2392 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE)
2396 pbyBSSID = pDevice->abyBroadcastAddr;
2397 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2398 pTransmitKey = NULL;
2399 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2400 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2403 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2405 bTKIP_UseGTK = TRUE;
2406 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2411 if (pDevice->bEnableHostWEP) {
2412 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2413 if (pDevice->bEncryptionEnable == TRUE) {
2414 pTransmitKey = &STempKey;
2415 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2416 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2417 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2418 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2419 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2420 memcpy(pTransmitKey->abyKey,
2421 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2422 pTransmitKey->uKeyLength
2427 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2429 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2430 DBG_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
2431 dev_kfree_skb_irq(skb);
2432 spin_unlock_irq(&pDevice->lock);
2436 if (pTransmitKey != NULL) {
2437 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2438 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2439 uMACfragNum = 1; //WEP256 doesn't support fragment
2443 byPktType = (BYTE)pDevice->byPacketType;
2445 if (pDevice->bFixRate) {
2447 printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n",pDevice->eCurrentPHYType,pDevice->uConnectionRate);
2450 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2451 if (pDevice->uConnectionRate >= RATE_11M) {
2452 pDevice->wCurrentRate = RATE_11M;
2454 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2457 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2458 (pDevice->uConnectionRate <= RATE_6M)) {
2459 pDevice->wCurrentRate = RATE_6M;
2461 if (pDevice->uConnectionRate >= RATE_54M)
2462 pDevice->wCurrentRate = RATE_54M;
2464 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2468 pDevice->byACKRate = (BYTE) pDevice->wCurrentRate;
2469 pDevice->byTopCCKBasicRate = RATE_1M;
2470 pDevice->byTopOFDMBasicRate = RATE_6M;
2474 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2475 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2476 pDevice->wCurrentRate = RATE_1M;
2477 pDevice->byACKRate = RATE_1M;
2478 pDevice->byTopCCKBasicRate = RATE_1M;
2479 pDevice->byTopOFDMBasicRate = RATE_6M;
2481 pDevice->wCurrentRate = RATE_6M;
2482 pDevice->byACKRate = RATE_6M;
2483 pDevice->byTopCCKBasicRate = RATE_1M;
2484 pDevice->byTopOFDMBasicRate = RATE_6M;
2488 VNTWIFIvGetTxRate( pDevice->pMgmt,
2489 pDevice->sTxEthHeader.abyDstAddr,
2490 &(pDevice->wCurrentRate),
2491 &(pDevice->byACKRate),
2492 &(pDevice->byTopCCKBasicRate),
2493 &(pDevice->byTopOFDMBasicRate));
2496 printk("auto rate:Rate : %d,AckRate:%d,TopCCKRate:%d,TopOFDMRate:%d\n",
2497 pDevice->wCurrentRate,pDevice->byACKRate,
2498 pDevice->byTopCCKBasicRate,pDevice->byTopOFDMBasicRate);
2504 pDevice->wCurrentRate = 11;
2505 pDevice->byACKRate = 8;
2506 pDevice->byTopCCKBasicRate = 3;
2507 pDevice->byTopOFDMBasicRate = 8;
2514 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2516 if (pDevice->wCurrentRate <= RATE_11M) {
2517 byPktType = PK_TYPE_11B;
2518 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2519 byPktType = PK_TYPE_11A;
2521 if (pDevice->bProtectMode == TRUE) {
2522 byPktType = PK_TYPE_11GB;
2524 byPktType = PK_TYPE_11GA;
2528 //#ifdef PLICE_DEBUG
2529 // printk("FIX RATE:CurrentRate is %d");
2532 if (bNeedEncryption == TRUE) {
2533 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2534 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2535 bNeedEncryption = FALSE;
2536 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2537 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2538 if (pTransmitKey == NULL) {
2539 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2542 if (bTKIP_UseGTK == TRUE) {
2543 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2546 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2547 bNeedEncryption = TRUE;
2552 if (pDevice->byCntMeasure == 2) {
2554 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2557 if (pDevice->bEnableHostWEP) {
2558 if ((uNodeIndex != 0) &&
2559 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2560 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2561 bNeedEncryption = TRUE;
2566 if (pTransmitKey == NULL) {
2567 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2568 dev_kfree_skb_irq(skb);
2569 spin_unlock_irq(&pDevice->lock);
2577 //if (skb->len == 98)
2579 // printk("ping:len is %d\n");
2582 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2583 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2584 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2589 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2591 MACbPSWakeup(pDevice->PortOffset);
2593 pDevice->bPWBitOn = FALSE;
2596 for (ii = 0; ii < uMACfragNum; ii++) {
2597 // Poll Transmit the adapter
2599 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2601 if (ii == uMACfragNum - 1)
2603 pHeadTD = pHeadTD->next;
2606 // Save the information needed by the tx interrupt handler
2607 // to complete the Send request
2608 pLastTD->pTDInfo->skb = skb;
2609 pLastTD->pTDInfo->byFlags = 0;
2610 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2612 pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
2614 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1) {
2615 netif_stop_queue(dev);
2618 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2619 //#ifdef PLICE_DEBUG
2620 if (pDevice->bFixRate)
2622 printk("FixRate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2626 //printk("Auto Rate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2631 BYTE Protocol_Version; //802.1x Authentication
2632 BYTE Packet_Type; //802.1x Authentication
2633 BYTE Descriptor_type;
2635 BOOL bTxeapol_key = FALSE;
2636 Protocol_Version = skb->data[U_HEADER_LEN];
2637 Packet_Type = skb->data[U_HEADER_LEN+1];
2638 Descriptor_type = skb->data[U_HEADER_LEN+1+1+2];
2639 Key_info = (skb->data[U_HEADER_LEN+1+1+2+1] << 8)|(skb->data[U_HEADER_LEN+1+1+2+2]);
2640 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2641 if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
2642 (Packet_Type==3)) { //802.1x OR eapol-key challenge frame transfer
2643 bTxeapol_key = TRUE;
2644 if((Descriptor_type==254)||(Descriptor_type==2)) { //WPA or RSN
2645 if(!(Key_info & BIT3) && //group-key challenge
2646 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2647 pDevice->fWPA_Authened = TRUE;
2648 if(Descriptor_type==254)
2652 printk("Authentication completed!!\n");
2659 MACvTransmitAC0(pDevice->PortOffset);
2660 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0:pDevice->apCurrTD= %p\n", pHeadTD);
2662 dev->trans_start = jiffies;
2664 spin_unlock_irq(&pDevice->lock);
2669 static irqreturn_t device_intr(int irq, void *dev_instance) {
2670 struct net_device* dev=dev_instance;
2671 PSDevice pDevice=(PSDevice) netdev_priv(dev);
2674 DWORD dwMIBCounter=0;
2675 PSMgmtObject pMgmt = pDevice->pMgmt;
2676 BYTE byOrgPageSel=0;
2683 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2685 if (pDevice->dwIsr == 0)
2686 return IRQ_RETVAL(handled);
2688 if (pDevice->dwIsr == 0xffffffff) {
2689 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
2690 return IRQ_RETVAL(handled);
2693 // 2008-05-21 <mark> by Richardtai, we can't read RSSI here, because no packet bound with RSSI
2695 if ((pDevice->dwIsr & ISR_RXDMA0) &&
2696 (pDevice->byLocalID != REV_ID_VT3253_B0) &&
2697 (pDevice->bBSSIDFilter == TRUE)) {
2699 //BBbReadEmbeded(pDevice->PortOffset, 0x3E, &byRSSI);
2700 //pDevice->uCurrRSSI = byRSSI;
2705 MACvIntDisable(pDevice->PortOffset);
2706 spin_lock_irq(&pDevice->lock);
2708 //Make sure current page is 0
2709 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2710 if (byOrgPageSel == 1) {
2711 MACvSelectPage0(pDevice->PortOffset);
2716 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2718 // Must do this after doing rx/tx, cause ISR bit is slow
2719 // than RD/TD write back
2720 // update ISR counter
2721 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2722 while (pDevice->dwIsr != 0) {
2724 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2725 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2727 if (pDevice->dwIsr & ISR_FETALERR){
2728 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR \n");
2729 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2730 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2731 device_error(pDevice, pDevice->dwIsr);
2734 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2736 if (pDevice->dwIsr & ISR_MEASURESTART) {
2737 // 802.11h measure start
2738 pDevice->byOrgChannel = pDevice->byCurrentCh;
2739 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2740 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2741 MACvSelectPage1(pDevice->PortOffset);
2742 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2743 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2744 MACvSelectPage0(pDevice->PortOffset);
2746 // WCMDbFlushCommandQueue(pDevice->pMgmt, TRUE);
2747 if (CARDbSetChannel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel) == TRUE) {
2748 pDevice->bMeasureInProgress = TRUE;
2749 MACvSelectPage1(pDevice->PortOffset);
2750 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2751 MACvSelectPage0(pDevice->PortOffset);
2752 pDevice->byBasicMap = 0;
2753 pDevice->byCCAFraction = 0;
2754 for(ii=0;ii<8;ii++) {
2755 pDevice->dwRPIs[ii] = 0;
2758 // can not measure because set channel fail
2759 // WCMDbResetCommandQueue(pDevice->pMgmt);
2760 // clear measure control
2761 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2762 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2763 MACvSelectPage1(pDevice->PortOffset);
2764 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2765 MACvSelectPage0(pDevice->PortOffset);
2768 if (pDevice->dwIsr & ISR_MEASUREEND) {
2769 // 802.11h measure end
2770 pDevice->bMeasureInProgress = FALSE;
2771 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2772 MACvSelectPage1(pDevice->PortOffset);
2773 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2774 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2775 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2776 pDevice->byBasicMap |= (byData >> 4);
2777 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2778 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2779 // clear measure control
2780 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2781 MACvSelectPage0(pDevice->PortOffset);
2782 CARDbSetChannel(pDevice, pDevice->byOrgChannel);
2783 // WCMDbResetCommandQueue(pDevice->pMgmt);
2784 MACvSelectPage1(pDevice->PortOffset);
2785 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2786 MACvSelectPage0(pDevice->PortOffset);
2787 if (byData & MSRCTL_FINISH) {
2789 s_vCompleteCurrentMeasure(pDevice, 0);
2791 // can not measure because not ready before end of measure time
2792 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2795 if (pDevice->dwIsr & ISR_QUIETSTART) {
2798 } while (CARDbStartQuiet(pDevice) == FALSE);
2802 if (pDevice->dwIsr & ISR_TBTT) {
2803 if (pDevice->bEnableFirstQuiet == TRUE) {
2804 pDevice->byQuietStartCount--;
2805 if (pDevice->byQuietStartCount == 0) {
2806 pDevice->bEnableFirstQuiet = FALSE;
2807 MACvSelectPage1(pDevice->PortOffset);
2808 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2809 MACvSelectPage0(pDevice->PortOffset);
2812 if ((pDevice->bChannelSwitch == TRUE) &&
2813 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
2814 pDevice->byChannelSwitchCount--;
2815 if (pDevice->byChannelSwitchCount == 0) {
2816 pDevice->bChannelSwitch = FALSE;
2817 CARDbSetChannel(pDevice, pDevice->byNewChannel);
2818 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2819 MACvSelectPage1(pDevice->PortOffset);
2820 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2821 MACvSelectPage0(pDevice->PortOffset);
2822 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2826 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2827 //pDevice->bBeaconSent = FALSE;
2829 if ((pDevice->bUpdateBBVGA) && (pDevice->bLinkPass == TRUE) && (pDevice->uCurrRSSI != 0)) {
2832 RFvRSSITodBm(pDevice, (BYTE) pDevice->uCurrRSSI, &ldBm);
2833 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
2834 if (ldBm < pDevice->ldBmThreshold[ii]) {
2835 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2839 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2840 pDevice->uBBVGADiffCount++;
2841 if (pDevice->uBBVGADiffCount == 1) {
2842 // first VGA diff gain
2843 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2844 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2845 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2847 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2848 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2849 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2850 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2853 pDevice->uBBVGADiffCount = 1;
2858 pDevice->bBeaconSent = FALSE;
2859 if (pDevice->bEnablePSMode) {
2860 PSbIsNextTBTTWakeUp((HANDLE)pDevice);
2863 if ((pDevice->eOPMode == OP_MODE_AP) ||
2864 (pDevice->eOPMode == OP_MODE_ADHOC)) {
2866 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2867 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2870 if (pDevice->eOPMode == OP_MODE_ADHOC && pDevice->pMgmt->wCurrATIMWindow > 0) {
2871 // todo adhoc PS mode
2876 if (pDevice->dwIsr & ISR_BNTX) {
2878 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2879 pDevice->bIsBeaconBufReadySet = FALSE;
2880 pDevice->cbBeaconBufReadySetCnt = 0;
2883 if (pDevice->eOPMode == OP_MODE_AP) {
2884 if(pMgmt->byDTIMCount > 0) {
2885 pMgmt->byDTIMCount --;
2886 pMgmt->sNodeDBTable[0].bRxPSPoll = FALSE;
2889 if(pMgmt->byDTIMCount == 0) {
2890 // check if mutltcast tx bufferring
2891 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2892 pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE;
2893 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2897 pDevice->bBeaconSent = TRUE;
2899 if (pDevice->bChannelSwitch == TRUE) {
2900 pDevice->byChannelSwitchCount--;
2901 if (pDevice->byChannelSwitchCount == 0) {
2902 pDevice->bChannelSwitch = FALSE;
2903 CARDbSetChannel(pDevice, pDevice->byNewChannel);
2904 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2905 MACvSelectPage1(pDevice->PortOffset);
2906 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2907 MACvSelectPage0(pDevice->PortOffset);
2908 //VNTWIFIbSendBeacon(pDevice->pMgmt);
2909 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2915 if (pDevice->dwIsr & ISR_RXDMA0) {
2916 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2918 if (pDevice->dwIsr & ISR_RXDMA1) {
2919 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2921 if (pDevice->dwIsr & ISR_TXDMA0){
2922 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2924 if (pDevice->dwIsr & ISR_AC0DMA){
2925 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2927 if (pDevice->dwIsr & ISR_SOFTTIMER) {
2930 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2931 if (pDevice->eOPMode == OP_MODE_AP) {
2932 if (pDevice->bShortSlotTime)
2933 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2935 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2937 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2938 pDevice->byCntMeasure = 0;
2941 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2943 MACvReceive0(pDevice->PortOffset);
2944 MACvReceive1(pDevice->PortOffset);
2946 if (max_count>pDevice->sOpts.int_works)
2950 if (byOrgPageSel == 1) {
2951 MACvSelectPage1(pDevice->PortOffset);
2954 spin_unlock_irq(&pDevice->lock);
2955 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2957 return IRQ_RETVAL(handled);
2961 static unsigned const ethernet_polynomial = 0x04c11db7U;
2962 static inline u32 ether_crc(int length, unsigned char *data)
2966 while(--length >= 0) {
2967 unsigned char current_octet = *data++;
2969 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
2971 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
2977 //2008-8-4 <add> by chester
2978 static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source)
2981 int source_len = strlen(source);
2984 strcat(buf1, string);
2986 source+=strlen(buf1);
2988 memcpy(dest,source,source_len-strlen(buf1));
2992 int Config_FileOperation(PSDevice pDevice,BOOL fwrite,unsigned char *Parameter) {
2993 UCHAR *config_path=CONFIG_PATH;
2995 UCHAR tmpbuffer[20];
2996 struct file *filp=NULL;
2997 mm_segment_t old_fs = get_fs();
2998 //int oldfsuid=0,oldfsgid=0;
3003 /* Can't do this anymore, so we rely on correct filesystem permissions:
3004 //Make sure a caller can read or write power as root
3005 oldfsuid=current->cred->fsuid;
3006 oldfsgid=current->cred->fsgid;
3007 current->cred->fsuid = 0;
3008 current->cred->fsgid = 0;
3012 filp = filp_open(config_path, O_RDWR, 0);
3014 printk("Config_FileOperation:open file fail?\n");
3019 if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
3020 printk("file %s cann't readable or writable?\n",config_path);
3025 buffer = (UCHAR *)kmalloc(1024, GFP_KERNEL);
3027 printk("alllocate mem for file fail?\n");
3032 if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
3033 printk("read file error?\n");
3038 if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=TRUE) {
3039 printk("get parameter error?\n");
3044 if(memcmp(tmpbuffer,"USA",3)==0) {
3045 result=ZoneType_USA;
3047 else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
3048 result=ZoneType_Japan;
3050 else if(memcmp(tmpbuffer,"EUROPE",5)==0) {
3051 result=ZoneType_Europe;
3055 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
3062 if(filp_close(filp,NULL))
3063 printk("Config_FileOperation:close file fail\n");
3069 current->cred->fsuid=oldfsuid;
3070 current->cred->fsgid=oldfsgid;
3078 static void device_set_multi(struct net_device *dev) {
3079 PSDevice pDevice = (PSDevice) netdev_priv(dev);
3081 PSMgmtObject pMgmt = pDevice->pMgmt;
3083 struct dev_mc_list *mclist;
3086 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
3088 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
3089 DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
3090 /* Unconditionally log net taps. */
3091 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
3093 else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
3094 || (dev->flags & IFF_ALLMULTI)) {
3095 MACvSelectPage1(pDevice->PortOffset);
3096 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
3097 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
3098 MACvSelectPage0(pDevice->PortOffset);
3099 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3102 memset(mc_filter, 0, sizeof(mc_filter));
3103 netdev_for_each_mc_addr(mclist, dev) {
3104 int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
3105 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
3107 MACvSelectPage1(pDevice->PortOffset);
3108 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
3109 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
3110 MACvSelectPage0(pDevice->PortOffset);
3111 pDevice->byRxMode &= ~(RCR_UNICAST);
3112 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3115 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3116 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
3117 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3118 pDevice->byRxMode &= ~(RCR_UNICAST);
3121 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
3122 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode );
3126 static struct net_device_stats *device_get_stats(struct net_device *dev) {
3127 PSDevice pDevice=(PSDevice) netdev_priv(dev);
3129 return &pDevice->stats;
3134 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
3135 PSDevice pDevice = (PSDevice)netdev_priv(dev);
3137 struct iwreq *wrq = (struct iwreq *) rq;
3139 PSMgmtObject pMgmt = pDevice->pMgmt;
3143 if (pMgmt == NULL) {
3151 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
3154 case SIOCGIWNWID: //0x8b03 support
3155 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3156 rc = iwctl_giwnwid(dev, NULL, &(wrq->u.nwid), NULL);
3162 // Set frequency/channel
3164 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
3167 // Get frequency/channel
3169 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
3172 // Set desired network name (ESSID)
3176 char essid[IW_ESSID_MAX_SIZE+1];
3177 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
3181 if (copy_from_user(essid, wrq->u.essid.pointer,
3182 wrq->u.essid.length)) {
3186 rc = iwctl_siwessid(dev, NULL,
3187 &(wrq->u.essid), essid);
3192 // Get current network name (ESSID)
3196 char essid[IW_ESSID_MAX_SIZE+1];
3197 if (wrq->u.essid.pointer)
3198 rc = iwctl_giwessid(dev, NULL,
3199 &(wrq->u.essid), essid);
3200 if (copy_to_user(wrq->u.essid.pointer,
3202 wrq->u.essid.length) )
3209 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3213 // Get current Access Point (BSSID)
3215 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3219 // Set desired station name
3221 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
3225 // Get current station name
3227 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
3231 // Set the desired bit-rate
3233 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3236 // Get the current bit-rate
3239 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3242 // Set the desired RTS threshold
3245 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
3248 // Get the current RTS threshold
3251 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
3254 // Set the desired fragmentation threshold
3257 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
3260 // Get the current fragmentation threshold
3263 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
3266 // Set mode of operation
3268 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
3271 // Get mode of operation
3273 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
3276 // Set WEP keys and mode
3279 char abyKey[WLAN_WEP232_KEYLEN];
3281 if (wrq->u.encoding.pointer) {
3284 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
3288 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
3289 if (copy_from_user(abyKey,
3290 wrq->u.encoding.pointer,
3291 wrq->u.encoding.length)) {
3295 } else if (wrq->u.encoding.length != 0) {
3299 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3303 // Get the WEP keys and mode
3306 if (!capable(CAP_NET_ADMIN)) {
3311 char abyKey[WLAN_WEP232_KEYLEN];
3313 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3315 if (wrq->u.encoding.pointer) {
3316 if (copy_to_user(wrq->u.encoding.pointer,
3318 wrq->u.encoding.length))
3324 // Get the current Tx-Power
3326 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3331 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3337 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
3342 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
3345 // Get range of parameters
3349 struct iw_range range;
3351 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *) &range);
3352 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
3360 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
3366 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
3372 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
3376 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
3382 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
3384 if (wrq->u.data.pointer) {
3385 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
3387 if (copy_to_user(wrq->u.data.pointer,
3389 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
3402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3409 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3413 #endif // WIRELESS_SPY
3416 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
3419 if(wrq->u.data.pointer) {
3420 wrq->u.data.length = sizeof(iwctl_private_args) / sizeof( iwctl_private_args[0]);
3422 if(copy_to_user(wrq->u.data.pointer,
3423 (u_char *) iwctl_private_args,
3424 sizeof(iwctl_private_args)))
3431 //2008-0409-07, <Add> by Einsn Liu
3432 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3434 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
3435 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
3439 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH \n");
3440 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
3444 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE \n");
3445 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3449 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE \n");
3450 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3453 case SIOCSIWENCODEEXT:
3455 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
3456 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
3457 if(wrq->u.encoding.pointer){
3458 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1);
3459 if(wrq->u.encoding.length > (sizeof(struct iw_encode_ext)+ MAX_KEY_LEN)){
3463 if(copy_from_user(extra, wrq->u.encoding.pointer,wrq->u.encoding.length)){
3467 }else if(wrq->u.encoding.length != 0){
3471 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
3475 case SIOCGIWENCODEEXT:
3476 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT \n");
3477 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
3481 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME \n");
3482 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3485 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3486 //End Add -- //2008-0409-07, <Add> by Einsn Liu
3488 case IOCTL_CMD_TEST:
3490 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
3496 pReq = (PSCmdRequest)rq;
3497 pReq->wResult = MAGIC_CODE;
3503 if((((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_EVT) &&
3504 !(pDevice->flags & DEVICE_FLAGS_OPENED))
3506 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
3507 (((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_WPA))
3516 if (test_and_set_bit( 0, (void*)&(pMgmt->uCmdBusy))) {
3519 rc = private_ioctl(pDevice, rq);
3520 clear_bit( 0, (void*)&(pMgmt->uCmdBusy));
3523 case IOCTL_CMD_HOSTAPD:
3526 rc = hostap_ioctl(pDevice, &wrq->u.data);
3531 rc = wpa_ioctl(pDevice, &wrq->u.data);
3535 return ethtool_ioctl(dev, (void *) rq->ifr_data);
3536 // All other calls are currently unsupported
3540 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
3545 if (pDevice->bCommit) {
3546 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3547 netif_stop_queue(pDevice->dev);
3548 spin_lock_irq(&pDevice->lock);
3549 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
3550 spin_unlock_irq(&pDevice->lock);
3553 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
3554 spin_lock_irq(&pDevice->lock);
3555 pDevice->bLinkPass = FALSE;
3556 memset(pMgmt->abyCurrBSSID, 0, 6);
3557 pMgmt->eCurrState = WMAC_STATE_IDLE;
3558 netif_stop_queue(pDevice->dev);
3559 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3560 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
3561 if(pDevice->bWPASuppWextEnabled !=TRUE)
3563 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
3564 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3565 spin_unlock_irq(&pDevice->lock);
3567 pDevice->bCommit = FALSE;
3574 static int ethtool_ioctl(struct net_device *dev, void *useraddr)
3578 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
3582 case ETHTOOL_GDRVINFO: {
3583 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3584 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3585 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3586 if (copy_to_user(useraddr, &info, sizeof(info)))
3596 /*------------------------------------------------------------------*/
3598 MODULE_DEVICE_TABLE(pci, device_id_table);
3600 static struct pci_driver device_driver = {
3602 id_table: device_id_table,
3603 probe: device_found1,
3604 remove: device_remove1,
3606 suspend: viawget_suspend,
3607 resume: viawget_resume,
3611 static int __init device_init_module(void)
3616 // ret=pci_module_init(&device_driver);
3617 //ret = pcie_port_service_register(&device_driver);
3618 ret = pci_register_driver(&device_driver);
3621 register_reboot_notifier(&device_notifier);
3627 static void __exit device_cleanup_module(void)
3632 unregister_reboot_notifier(&device_notifier);
3634 pci_unregister_driver(&device_driver);
3638 module_init(device_init_module);
3639 module_exit(device_cleanup_module);
3644 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3646 struct pci_dev *pdev = NULL;
3651 while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
3652 if(pci_dev_driver(pdev) == &device_driver) {
3653 if (pci_get_drvdata(pdev))
3654 viawget_suspend(pdev, PMSG_HIBERNATE);
3662 viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3664 int power_status; // to silence the compiler
3666 PSDevice pDevice=pci_get_drvdata(pcid);
3667 PSMgmtObject pMgmt = pDevice->pMgmt;
3669 netif_stop_queue(pDevice->dev);
3670 spin_lock_irq(&pDevice->lock);
3671 pci_save_state(pcid);
3672 del_timer(&pDevice->sTimerCommand);
3673 del_timer(&pMgmt->sTimerSecondCallback);
3674 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3675 pDevice->uCmdDequeueIdx = 0;
3676 pDevice->uCmdEnqueueIdx = 0;
3677 pDevice->bCmdRunning = FALSE;
3678 MACbShutdown(pDevice->PortOffset);
3679 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3680 pDevice->bLinkPass = FALSE;
3681 memset(pMgmt->abyCurrBSSID, 0, 6);
3682 pMgmt->eCurrState = WMAC_STATE_IDLE;
3683 pci_disable_device(pcid);
3684 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3685 spin_unlock_irq(&pDevice->lock);
3690 viawget_resume(struct pci_dev *pcid)
3692 PSDevice pDevice=pci_get_drvdata(pcid);
3693 PSMgmtObject pMgmt = pDevice->pMgmt;
3694 int power_status; // to silence the compiler
3697 power_status = pci_set_power_state(pcid, 0);
3698 power_status = pci_enable_wake(pcid, 0, 0);
3699 pci_restore_state(pcid);
3700 if (netif_running(pDevice->dev)) {
3701 spin_lock_irq(&pDevice->lock);
3702 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3703 device_init_registers(pDevice, DEVICE_INIT_DXPL);
3704 if (pMgmt->sNodeDBTable[0].bActive == TRUE) { // Assoc with BSS
3705 pMgmt->sNodeDBTable[0].bActive = FALSE;
3706 pDevice->bLinkPass = FALSE;
3707 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3708 // In Adhoc, BSS state set back to started.
3709 pMgmt->eCurrState = WMAC_STATE_STARTED;
3712 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3713 pMgmt->eCurrState = WMAC_STATE_IDLE;
3716 init_timer(&pMgmt->sTimerSecondCallback);
3717 init_timer(&pDevice->sTimerCommand);
3718 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3719 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
3720 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3721 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3722 spin_unlock_irq(&pDevice->lock);