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>
89 /*--------------------- Static Definitions -------------------------*/
90 //static int msglevel =MSG_LEVEL_DEBUG;
91 static int msglevel = MSG_LEVEL_INFO;
95 // Define module options
97 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
98 MODULE_LICENSE("GPL");
99 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
102 static int mlme_kill;
103 //static struct task_struct * mlme_task;
106 #define DEVICE_PARAM(N,D)
108 static const int N[MAX_UINTS]=OPTION_DEFAULT;\
109 MODULE_PARM(N, "1-" __MODULE_STRING(MAX_UINTS) "i");\
110 MODULE_PARM_DESC(N, D);
113 #define RX_DESC_MIN0 16
114 #define RX_DESC_MAX0 128
115 #define RX_DESC_DEF0 32
116 DEVICE_PARAM(RxDescriptors0,"Number of receive descriptors0");
118 #define RX_DESC_MIN1 16
119 #define RX_DESC_MAX1 128
120 #define RX_DESC_DEF1 32
121 DEVICE_PARAM(RxDescriptors1,"Number of receive descriptors1");
123 #define TX_DESC_MIN0 16
124 #define TX_DESC_MAX0 128
125 #define TX_DESC_DEF0 32
126 DEVICE_PARAM(TxDescriptors0,"Number of transmit descriptors0");
128 #define TX_DESC_MIN1 16
129 #define TX_DESC_MAX1 128
130 #define TX_DESC_DEF1 64
131 DEVICE_PARAM(TxDescriptors1,"Number of transmit descriptors1");
134 #define IP_ALIG_DEF 0
135 /* IP_byte_align[] is used for IP header DWORD byte aligned
136 0: indicate the IP header won't be DWORD byte aligned.(Default) .
137 1: indicate the IP header will be DWORD byte aligned.
138 In some enviroment, the IP header should be DWORD byte aligned,
139 or the packet will be droped when we receive it. (eg: IPVS)
141 DEVICE_PARAM(IP_byte_align,"Enable IP header dword aligned");
144 #define INT_WORKS_DEF 20
145 #define INT_WORKS_MIN 10
146 #define INT_WORKS_MAX 64
148 DEVICE_PARAM(int_works,"Number of packets per interrupt services");
150 #define CHANNEL_MIN 1
151 #define CHANNEL_MAX 14
152 #define CHANNEL_DEF 6
154 DEVICE_PARAM(Channel, "Channel number");
157 /* PreambleType[] is the preamble length used for transmit.
158 0: indicate allows long preamble type
159 1: indicate allows short preamble type
162 #define PREAMBLE_TYPE_DEF 1
164 DEVICE_PARAM(PreambleType, "Preamble Type");
167 #define RTS_THRESH_MIN 512
168 #define RTS_THRESH_MAX 2347
169 #define RTS_THRESH_DEF 2347
171 DEVICE_PARAM(RTSThreshold, "RTS threshold");
174 #define FRAG_THRESH_MIN 256
175 #define FRAG_THRESH_MAX 2346
176 #define FRAG_THRESH_DEF 2346
178 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
181 #define DATA_RATE_MIN 0
182 #define DATA_RATE_MAX 13
183 #define DATA_RATE_DEF 13
185 0: indicate 1 Mbps 0x02
186 1: indicate 2 Mbps 0x04
187 2: indicate 5.5 Mbps 0x0B
188 3: indicate 11 Mbps 0x16
189 4: indicate 6 Mbps 0x0c
190 5: indicate 9 Mbps 0x12
191 6: indicate 12 Mbps 0x18
192 7: indicate 18 Mbps 0x24
193 8: indicate 24 Mbps 0x30
194 9: indicate 36 Mbps 0x48
195 10: indicate 48 Mbps 0x60
196 11: indicate 54 Mbps 0x6c
197 12: indicate 72 Mbps 0x90
198 13: indicate auto rate
201 DEVICE_PARAM(ConnectionRate, "Connection data rate");
203 #define OP_MODE_DEF 0
205 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
207 /* OpMode[] is used for transmit.
208 0: indicate infrastruct mode used
209 1: indicate adhoc mode used
210 2: indicate AP mode used
215 0: indicate disable power saving mode
216 1: indicate enable power saving mode
219 #define PS_MODE_DEF 0
221 DEVICE_PARAM(PSMode, "Power saving mode");
224 #define SHORT_RETRY_MIN 0
225 #define SHORT_RETRY_MAX 31
226 #define SHORT_RETRY_DEF 8
229 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
231 #define LONG_RETRY_MIN 0
232 #define LONG_RETRY_MAX 15
233 #define LONG_RETRY_DEF 4
236 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
239 /* BasebandType[] baseband type selected
240 0: indicate 802.11a type
241 1: indicate 802.11b type
242 2: indicate 802.11g type
244 #define BBP_TYPE_MIN 0
245 #define BBP_TYPE_MAX 2
246 #define BBP_TYPE_DEF 2
248 DEVICE_PARAM(BasebandType, "baseband type");
253 0: indicate disable 802.11h
254 1: indicate enable 802.11h
257 #define X80211h_MODE_DEF 0
259 DEVICE_PARAM(b80211hEnable, "802.11h mode");
262 0: indicate disable 802.11h
263 1: indicate enable 802.11h
266 #define DIVERSITY_ANT_DEF 0
268 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
272 // Static vars definitions
276 static int device_nics =0;
277 static PSDevice pDevice_Infos =NULL;
278 static struct net_device *root_device_dev = NULL;
280 static CHIP_INFO chip_info_table[]= {
281 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
282 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
286 DEFINE_PCI_DEVICE_TABLE(device_id_table) = {
287 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
291 /*--------------------- Static Functions --------------------------*/
294 static int device_found1(struct pci_dev *pcid, const struct pci_device_id *ent);
295 static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice, PCHIP_INFO);
296 static void device_free_info(PSDevice pDevice);
297 static BOOL device_get_pci_info(PSDevice, struct pci_dev* pcid);
298 static void device_print_info(PSDevice pDevice);
299 static struct net_device_stats *device_get_stats(struct net_device *dev);
300 static void device_init_diversity_timer(PSDevice pDevice);
301 static int device_open(struct net_device *dev);
302 static int device_xmit(struct sk_buff *skb, struct net_device *dev);
303 static irqreturn_t device_intr(int irq, void*dev_instance);
304 static void device_set_multi(struct net_device *dev);
305 static int device_close(struct net_device *dev);
306 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
309 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
310 static int viawget_suspend(struct pci_dev *pcid, pm_message_t state);
311 static int viawget_resume(struct pci_dev *pcid);
312 struct notifier_block device_notifier = {
313 notifier_call: device_notify_reboot,
320 static void device_init_rd0_ring(PSDevice pDevice);
321 static void device_init_rd1_ring(PSDevice pDevice);
322 static void device_init_defrag_cb(PSDevice pDevice);
323 static void device_init_td0_ring(PSDevice pDevice);
324 static void device_init_td1_ring(PSDevice pDevice);
326 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
327 //2008-0714<Add>by Mike Liu
328 static BOOL device_release_WPADEV(PSDevice pDevice);
330 static int ethtool_ioctl(struct net_device *dev, void *useraddr);
331 static int device_rx_srv(PSDevice pDevice, UINT uIdx);
332 static int device_tx_srv(PSDevice pDevice, UINT uIdx);
333 static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pDesc);
334 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
335 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc);
336 static void device_free_td0_ring(PSDevice pDevice);
337 static void device_free_td1_ring(PSDevice pDevice);
338 static void device_free_rd0_ring(PSDevice pDevice);
339 static void device_free_rd1_ring(PSDevice pDevice);
340 static void device_free_rings(PSDevice pDevice);
341 static void device_free_frag_buf(PSDevice pDevice);
342 static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source);
345 /*--------------------- Export Variables --------------------------*/
347 /*--------------------- Export Functions --------------------------*/
351 static char* get_chip_name(int chip_id) {
353 for (i=0;chip_info_table[i].name!=NULL;i++)
354 if (chip_info_table[i].chip_id==chip_id)
356 return chip_info_table[i].name;
359 static void device_remove1(struct pci_dev *pcid)
361 PSDevice pDevice=pci_get_drvdata(pcid);
365 device_free_info(pDevice);
371 device_set_int_opt(int *opt, int val, int min, int max, int def,char* name,char* devname) {
374 else if (val<min || val>max) {
375 DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n" ,
376 devname,name, min,max);
379 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n",
386 device_set_bool_opt(unsigned int *opt, int val,BOOL def,U32 flag, char* name,char* devname) {
389 *opt|=(def ? flag : 0);
390 else if (val<0 || val>1) {
391 DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE
392 "%s: the value of parameter %s is invalid, the valid range is (0-1)\n",devname,name);
393 *opt|=(def ? flag : 0);
395 DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: set parameter %s to %s\n",
396 devname,name , val ? "TRUE" : "FALSE");
397 *opt|=(val ? flag : 0);
402 device_get_options(PSDevice pDevice, int index, char* devname) {
404 POPTIONS pOpts = &(pDevice->sOpts);
405 pOpts->nRxDescs0=RX_DESC_DEF0;
406 pOpts->nRxDescs1=RX_DESC_DEF1;
407 pOpts->nTxDescs[0]=TX_DESC_DEF0;
408 pOpts->nTxDescs[1]=TX_DESC_DEF1;
409 pOpts->flags|=DEVICE_FLAGS_IP_ALIGN;
410 pOpts->int_works=INT_WORKS_DEF;
411 pOpts->rts_thresh=RTS_THRESH_DEF;
412 pOpts->frag_thresh=FRAG_THRESH_DEF;
413 pOpts->data_rate=DATA_RATE_DEF;
414 pOpts->channel_num=CHANNEL_DEF;
416 pOpts->flags|=DEVICE_FLAGS_PREAMBLE_TYPE;
417 pOpts->flags|=DEVICE_FLAGS_OP_MODE;
418 //pOpts->flags|=DEVICE_FLAGS_PS_MODE;
419 pOpts->short_retry=SHORT_RETRY_DEF;
420 pOpts->long_retry=LONG_RETRY_DEF;
421 pOpts->bbp_type=BBP_TYPE_DEF;
422 pOpts->flags|=DEVICE_FLAGS_80211h_MODE;
423 pOpts->flags|=DEVICE_FLAGS_DiversityANT;
429 device_set_options(PSDevice pDevice) {
431 BYTE abyBroadcastAddr[U_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
432 BYTE abySNAP_RFC1042[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
433 BYTE abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
436 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, U_ETHER_ADDR_LEN);
437 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, U_ETHER_ADDR_LEN);
438 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, U_ETHER_ADDR_LEN);
440 pDevice->uChannel = pDevice->sOpts.channel_num;
441 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
442 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
443 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
444 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
445 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
446 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
447 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
448 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
449 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
450 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
451 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
452 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE;
453 pDevice->byBBType = pDevice->sOpts.bbp_type;
454 pDevice->byPacketType = pDevice->byBBType;
457 pDevice->byAutoFBCtrl = AUTO_FB_0;
458 //pDevice->byAutoFBCtrl = AUTO_FB_1;
460 pDevice->bUpdateBBVGA = TRUE;
461 pDevice->byFOETuning = 0;
462 pDevice->wCTSDuration = 0;
463 pDevice->byPreambleType = 0;
466 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uChannel= %d\n",(INT)pDevice->uChannel);
467 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byOpMode= %d\n",(INT)pDevice->byOpMode);
468 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ePSMode= %d\n",(INT)pDevice->ePSMode);
469 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" wRTSThreshold= %d\n",(INT)pDevice->wRTSThreshold);
470 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortRetryLimit= %d\n",(INT)pDevice->byShortRetryLimit);
471 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byLongRetryLimit= %d\n",(INT)pDevice->byLongRetryLimit);
472 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byPreambleType= %d\n",(INT)pDevice->byPreambleType);
473 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortPreamble= %d\n",(INT)pDevice->byShortPreamble);
474 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uConnectionRate= %d\n",(INT)pDevice->uConnectionRate);
475 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byBBType= %d\n",(INT)pDevice->byBBType);
476 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->b11hEnable= %d\n",(INT)pDevice->b11hEnable);
477 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->bDiversityRegCtlON= %d\n",(INT)pDevice->bDiversityRegCtlON);
480 static VOID s_vCompleteCurrentMeasure (IN PSDevice pDevice, IN BYTE byResult)
483 DWORD dwDuration = 0;
486 for(ii=1;ii<8;ii++) {
487 pDevice->dwRPIs[ii] *= 255;
488 dwDuration |= *((PWORD) (pDevice->pCurrMeasureEID->sReq.abyDuration));
490 pDevice->dwRPIs[ii] /= dwDuration;
491 pDevice->abyRPIs[ii] = (BYTE) pDevice->dwRPIs[ii];
492 byRPI0 += pDevice->abyRPIs[ii];
494 pDevice->abyRPIs[0] = (0xFF - byRPI0);
496 if (pDevice->uNumOfMeasureEIDs == 0) {
497 VNTWIFIbMeasureReport( pDevice->pMgmt,
499 pDevice->pCurrMeasureEID,
502 pDevice->byCCAFraction,
506 VNTWIFIbMeasureReport( pDevice->pMgmt,
508 pDevice->pCurrMeasureEID,
511 pDevice->byCCAFraction,
514 CARDbStartMeasure (pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
522 // Initialiation of MAC & BBP registers
525 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
530 BYTE byCCKPwrdBm = 0;
531 BYTE byOFDMPwrdBm = 0;
533 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
534 MACbShutdown(pDevice->PortOffset);
535 BBvSoftwareReset(pDevice->PortOffset);
537 if ((InitType == DEVICE_INIT_COLD) ||
538 (InitType == DEVICE_INIT_DXPL)) {
539 // Do MACbSoftwareReset in MACvInitialize
540 MACbSoftwareReset(pDevice->PortOffset);
542 pDevice->bCCK = TRUE;
543 pDevice->bAES = FALSE;
544 pDevice->bProtectMode = FALSE; //Only used in 11g type, sync with ERP IE
545 pDevice->bNonERPPresent = FALSE;
546 pDevice->bBarkerPreambleMd = FALSE;
547 pDevice->wCurrentRate = RATE_1M;
548 pDevice->byTopOFDMBasicRate = RATE_24M;
549 pDevice->byTopCCKBasicRate = RATE_1M;
551 pDevice->byRevId = 0; //Target to IF pin while programming to RF chip.
554 MACvInitialize(pDevice->PortOffset);
557 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
559 spin_lock_irq(&pDevice->lock);
560 SROMvReadAllContents(pDevice->PortOffset,pDevice->abyEEPROM);
562 spin_unlock_irq(&pDevice->lock);
566 pDevice->byMinChannel = 1;
567 pDevice->byMaxChannel = CB_MAX_CHANNEL;
570 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
571 if (byValue & EEP_ANTINV)
572 pDevice->bTxRxAntInv = TRUE;
574 pDevice->bTxRxAntInv = FALSE;
576 //printk("init_register:TxRxAntInv is %d,byValue is %d\n",pDevice->bTxRxAntInv,byValue);
579 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
580 if (byValue == 0) // if not set default is All
581 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
583 //printk("init_register:byValue is %d\n",byValue);
585 pDevice->ulDiversityNValue = 100*260;//100*SROMbyReadEmbedded(pDevice->PortOffset, 0x51);
586 pDevice->ulDiversityMValue = 100*16;//SROMbyReadEmbedded(pDevice->PortOffset, 0x52);
587 pDevice->byTMax = 1;//SROMbyReadEmbedded(pDevice->PortOffset, 0x53);
588 pDevice->byTMax2 = 4;//SROMbyReadEmbedded(pDevice->PortOffset, 0x54);
589 pDevice->ulSQ3TH = 0;//(ULONG) SROMbyReadEmbedded(pDevice->PortOffset, 0x55);
590 pDevice->byTMax3 = 64;//SROMbyReadEmbedded(pDevice->PortOffset, 0x56);
592 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
593 pDevice->byAntennaCount = 2;
594 pDevice->byTxAntennaMode = ANT_B;
595 pDevice->dwTxAntennaSel = 1;
596 pDevice->dwRxAntennaSel = 1;
597 if (pDevice->bTxRxAntInv == TRUE)
598 pDevice->byRxAntennaMode = ANT_A;
600 pDevice->byRxAntennaMode = ANT_B;
601 // chester for antenna
602 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
603 // if (pDevice->bDiversityRegCtlON)
604 if((byValue1&0x08)==0)
605 pDevice->bDiversityEnable = FALSE;//SROMbyReadEmbedded(pDevice->PortOffset, 0x50);
607 pDevice->bDiversityEnable = TRUE;
609 //printk("aux |main antenna: RxAntennaMode is %d\n",pDevice->byRxAntennaMode);
612 pDevice->bDiversityEnable = FALSE;
613 pDevice->byAntennaCount = 1;
614 pDevice->dwTxAntennaSel = 0;
615 pDevice->dwRxAntennaSel = 0;
616 if (byValue & EEP_ANTENNA_AUX) {
617 pDevice->byTxAntennaMode = ANT_A;
618 if (pDevice->bTxRxAntInv == TRUE)
619 pDevice->byRxAntennaMode = ANT_B;
621 pDevice->byRxAntennaMode = ANT_A;
623 pDevice->byTxAntennaMode = ANT_B;
624 if (pDevice->bTxRxAntInv == TRUE)
625 pDevice->byRxAntennaMode = ANT_A;
627 pDevice->byRxAntennaMode = ANT_B;
631 //printk("init registers: TxAntennaMode is %d\n",pDevice->byTxAntennaMode);
633 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
634 pDevice->bDiversityEnable,(int)pDevice->ulDiversityNValue,(int)pDevice->ulDiversityMValue,pDevice->byTMax,pDevice->byTMax2);
636 //#ifdef ZoneType_DefaultSetting
637 //2008-8-4 <add> by chester
639 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
640 if((zonetype=Config_FileOperation(pDevice,FALSE,NULL)) >= 0) { //read zonetype file ok!
641 if ((zonetype == 0)&&
642 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] !=0x00)){ //for USA
643 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
644 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
645 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :USA\n");
647 else if((zonetype == 1)&&
648 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x01)){ //for Japan
649 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
650 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
652 else if((zonetype == 2)&&
653 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x02)){ //for Europe
654 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
655 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :Europe\n");
661 if(zonetype!=pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
662 printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",zonetype,pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
664 printk("Read Zonetype file success,use default zonetype setting[%02x]\n",zonetype);
668 printk("Read Zonetype file fail,use default zonetype setting[%02x]\n",SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
671 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
673 if ((pDevice->byRFType & RF_EMU) != 0) {
674 // force change RevID for VT3253 emu
675 pDevice->byRevId = 0x80;
678 pDevice->byRFType &= RF_MASK;
679 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
681 if (pDevice->bZoneRegExist == FALSE) {
682 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
684 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
689 //Get Desire Power Value
690 pDevice->byCurPwr = 0xFF;
691 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
692 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
693 //byCCKPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_CCK_PWR_dBm);
695 //byOFDMPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_OFDM_PWR_dBm);
696 //printk("CCKPwrdBm is 0x%x,byOFDMPwrdBm is 0x%x\n",byCCKPwrdBm,byOFDMPwrdBm);
700 for (ii=0;ii<CB_MAX_CHANNEL_24G;ii++) {
701 pDevice->abyCCKPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_CCK_PWR_TBL));
702 if (pDevice->abyCCKPwrTbl[ii+1] == 0) {
703 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
705 pDevice->abyOFDMPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDM_PWR_TBL));
706 if (pDevice->abyOFDMPwrTbl[ii+1] == 0) {
707 pDevice->abyOFDMPwrTbl[ii+1] = pDevice->byOFDMPwrG;
709 pDevice->abyCCKDefaultPwr[ii+1] = byCCKPwrdBm;
710 pDevice->abyOFDMDefaultPwr[ii+1] = byOFDMPwrdBm;
712 //2008-8-4 <add> by chester
713 //recover 12,13 ,14channel for EUROPE by 11 channel
714 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
715 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
716 (pDevice->byOriginalZonetype == ZoneType_USA)) {
717 for(ii=11;ii<14;ii++) {
718 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
719 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
725 // Load OFDM A Power Table
726 for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
727 pDevice->abyOFDMPwrTbl[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_TBL));
728 pDevice->abyOFDMDefaultPwr[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_dBm));
730 CARDvInitChannelTable((PVOID)pDevice);
733 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
734 MACvSelectPage1(pDevice->PortOffset);
735 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
736 MACvSelectPage0(pDevice->PortOffset);
740 // use relative tx timeout and 802.11i D4
741 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
743 // set performance parameter by registry
744 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
745 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
748 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
749 // enable TSF counter
750 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
752 // initialize BBP registers
753 BBbVT3253Init(pDevice);
755 if (pDevice->bUpdateBBVGA) {
756 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
757 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
758 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
761 //printk("init registers:RxAntennaMode is %x,TxAntennaMode is %x\n",pDevice->byRxAntennaMode,pDevice->byTxAntennaMode);
763 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
764 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
766 pDevice->byCurrentCh = 0;
768 //pDevice->NetworkType = Ndis802_11Automode;
769 // Set BB and packet type at the same time.
770 // Set Short Slot Time, xIFS, and RSPINF.
771 if (pDevice->uConnectionRate == RATE_AUTO) {
772 pDevice->wCurrentRate = RATE_54M;
774 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
778 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
779 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
781 pDevice->bRadioOff = FALSE;
783 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
784 pDevice->bHWRadioOff = FALSE;
786 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
788 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
789 //2008-4-14 <add> by chester for led issue
790 #ifdef FOR_LED_ON_NOTEBOOK
791 if (pDevice->byGPIO & GPIO0_DATA){pDevice->bHWRadioOff = TRUE;}
792 if ( !(pDevice->byGPIO & GPIO0_DATA)){pDevice->bHWRadioOff = FALSE;}
795 if ( (pDevice->bRadioControlOff == TRUE)) {
796 CARDbRadioPowerOff(pDevice);
798 else CARDbRadioPowerOn(pDevice);
800 if (((pDevice->byGPIO & GPIO0_DATA) && !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
801 ( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV))) {
802 pDevice->bHWRadioOff = TRUE;
805 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
806 CARDbRadioPowerOff(pDevice);
811 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
812 // get Permanent network address
813 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
814 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %02x-%02x-%02x=%02x-%02x-%02x\n",
815 pDevice->abyCurrentNetAddr[0],
816 pDevice->abyCurrentNetAddr[1],
817 pDevice->abyCurrentNetAddr[2],
818 pDevice->abyCurrentNetAddr[3],
819 pDevice->abyCurrentNetAddr[4],
820 pDevice->abyCurrentNetAddr[5]);
824 CARDvSafeResetRx(pDevice);
826 CARDvSafeResetTx(pDevice);
828 if (pDevice->byLocalID <= REV_ID_VT3253_A1) {
829 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
832 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
835 MACvReceive0(pDevice->PortOffset);
836 MACvReceive1(pDevice->PortOffset);
839 MACvStart(pDevice->PortOffset);
841 netif_stop_queue(pDevice->dev);
848 static VOID device_init_diversity_timer(PSDevice pDevice) {
850 init_timer(&pDevice->TimerSQ3Tmax1);
851 pDevice->TimerSQ3Tmax1.data = (ULONG)pDevice;
852 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
853 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
855 init_timer(&pDevice->TimerSQ3Tmax2);
856 pDevice->TimerSQ3Tmax2.data = (ULONG)pDevice;
857 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
858 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
860 init_timer(&pDevice->TimerSQ3Tmax3);
861 pDevice->TimerSQ3Tmax3.data = (ULONG)pDevice;
862 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
863 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
869 static BOOL device_release_WPADEV(PSDevice pDevice)
871 viawget_wpa_header *wpahdr;
873 // wait_queue_head_t Set_wait;
874 //send device close to wpa_supplicnat layer
875 if (pDevice->bWPADEVUp==TRUE) {
876 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
877 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
878 wpahdr->resp_ie_len = 0;
879 wpahdr->req_ie_len = 0;
880 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
881 pDevice->skb->dev = pDevice->wpadev;
882 skb_reset_mac_header(pDevice->skb);
883 pDevice->skb->pkt_type = PACKET_HOST;
884 pDevice->skb->protocol = htons(ETH_P_802_2);
885 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
886 netif_rx(pDevice->skb);
887 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
889 //wait release WPADEV
890 // init_waitqueue_head(&Set_wait);
891 // wait_event_timeout(Set_wait, ((pDevice->wpadev==NULL)&&(pDevice->skb == NULL)),5*HZ); //1s wait
892 while((pDevice->bWPADEVUp==TRUE)) {
893 set_current_state(TASK_UNINTERRUPTIBLE);
894 schedule_timeout (HZ/20); //wait 50ms
904 static const struct net_device_ops device_netdev_ops = {
905 .ndo_open = device_open,
906 .ndo_stop = device_close,
907 .ndo_do_ioctl = device_ioctl,
908 .ndo_get_stats = device_get_stats,
909 .ndo_start_xmit = device_xmit,
910 .ndo_set_multicast_list = device_set_multi,
916 device_found1(struct pci_dev *pcid, const struct pci_device_id *ent)
918 static BOOL bFirst = TRUE;
919 struct net_device* dev = NULL;
920 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
923 if (device_nics ++>= MAX_UINTS) {
924 printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
929 dev = alloc_etherdev(sizeof(DEVICE_INFO));
931 pDevice = (PSDevice) netdev_priv(dev);
934 printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
938 // Chain it all together
939 // SET_MODULE_OWNER(dev);
940 SET_NETDEV_DEV(dev, &pcid->dev);
943 printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
944 printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
948 if (!device_init_info(pcid, &pDevice, pChip_info)) {
952 pDevice->next_module = root_device_dev;
953 root_device_dev = dev;
954 dev->irq = pcid->irq;
956 if (pci_enable_device(pcid)) {
957 device_free_info(pDevice);
961 printk("Before get pci_info memaddr is %x\n",pDevice->memaddr);
963 if (device_get_pci_info(pDevice,pcid) == FALSE) {
964 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
965 device_free_info(pDevice);
973 //pci_read_config_byte(pcid, PCI_BASE_ADDRESS_0, &pDevice->byRevId);
974 printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",pDevice->memaddr,pDevice->ioaddr,pDevice->io_size);
986 for (i=0;address[i];i++)
988 //pci_write_config_dword(pcid,address[i], 0xFFFFFFFF);
989 pci_read_config_dword(pcid, address[i], &bar);
990 printk("bar %d is %x\n",i,bar);
993 printk("bar %d not implemented\n",i);
996 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
999 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
1000 len = len & ~(len - 1);
1002 printk("IO space: len in IO %x, BAR %d\n", len, i);
1006 len = bar & 0xFFFFFFF0;
1009 printk("len in MEM %x, BAR %d\n", len, i);
1021 pDevice->PortOffset = (DWORD)ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
1022 //pDevice->PortOffset = (DWORD)ioremap(pDevice->ioaddr & PCI_BASE_ADDRESS_IO_MASK, pDevice->io_size);
1024 if(pDevice->PortOffset == 0) {
1025 printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
1026 device_free_info(pDevice);
1033 rc = pci_request_regions(pcid, DEVICE_NAME);
1035 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
1036 device_free_info(pDevice);
1040 dev->base_addr = pDevice->ioaddr;
1044 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1045 printk("Before write: value is %x\n",value);
1046 //VNSvInPortB(pDevice->PortOffset+0x3F, 0x00);
1047 VNSvOutPortB(pDevice->PortOffset,value);
1048 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1049 printk("After write: value is %x\n",value);
1055 pDevice->PortOffset = pDevice->ioaddr;
1058 if (!MACbSoftwareReset(pDevice->PortOffset)) {
1059 printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
1060 device_free_info(pDevice);
1063 // initial to reload eeprom
1064 MACvInitialize(pDevice->PortOffset);
1065 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
1067 device_get_options(pDevice, device_nics-1, dev->name);
1068 device_set_options(pDevice);
1069 //Mask out the options cannot be set to the chip
1070 pDevice->sOpts.flags &= pChip_info->flags;
1072 //Enable the chip specified capbilities
1073 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
1074 pDevice->tx_80211 = device_dma0_tx_80211;
1075 pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;
1076 pDevice->pMgmt = &(pDevice->sMgmtObj);
1078 dev->irq = pcid->irq;
1079 dev->netdev_ops = &device_netdev_ops;
1081 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
1083 rc = register_netdev(dev);
1086 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
1087 device_free_info(pDevice);
1090 //2008-07-21-01<Add>by MikeLiu
1092 if(wpa_set_wpadev(pDevice, 1)!=0) {
1093 printk("Fail to Register WPADEV?\n");
1094 unregister_netdev(pDevice->dev);
1097 device_print_info(pDevice);
1098 pci_set_drvdata(pcid, pDevice);
1103 static void device_print_info(PSDevice pDevice)
1105 struct net_device* dev=pDevice->dev;
1107 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n",dev->name, get_chip_name(pDevice->chip_id));
1108 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%pM", dev->name, dev->dev_addr);
1110 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx ",(ULONG) pDevice->ioaddr);
1111 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1113 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx Mem=0x%lx ",(ULONG) pDevice->ioaddr,(ULONG) pDevice->PortOffset);
1114 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1119 static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice,
1120 PCHIP_INFO pChip_info) {
1124 memset(*ppDevice,0,sizeof(DEVICE_INFO));
1126 if (pDevice_Infos == NULL) {
1127 pDevice_Infos =*ppDevice;
1130 for (p=pDevice_Infos;p->next!=NULL;p=p->next)
1132 p->next = *ppDevice;
1133 (*ppDevice)->prev = p;
1136 (*ppDevice)->pcid = pcid;
1137 (*ppDevice)->chip_id = pChip_info->chip_id;
1138 (*ppDevice)->io_size = pChip_info->io_size;
1139 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
1140 (*ppDevice)->multicast_limit =32;
1142 spin_lock_init(&((*ppDevice)->lock));
1147 static BOOL device_get_pci_info(PSDevice pDevice, struct pci_dev* pcid) {
1153 BYTE pci_config[256];
1157 memset(pci_config,0x00,256);
1160 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
1161 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID,&pDevice->SubSystemID);
1162 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
1163 pci_read_config_word(pcid, PCI_COMMAND, (u16 *) & (pci_cmd));
1165 pci_set_master(pcid);
1167 pDevice->memaddr = pci_resource_start(pcid,0);
1168 pDevice->ioaddr = pci_resource_start(pcid,1);
1171 // pDevice->ioaddr = pci_resource_start(pcid, 0);
1172 // pDevice->memaddr = pci_resource_start(pcid,1);
1175 cis_addr = pci_resource_start(pcid,2);
1177 pDevice->pcid = pcid;
1179 pci_read_config_byte(pcid, PCI_COMMAND, &b);
1180 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
1183 //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
1184 //printk("max lat is %x,SubSystemID is %x\n",max_lat,pDevice->SubSystemID);
1185 //for (ii=0;ii<0xFF;ii++)
1186 //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
1188 //pci_write_config_word(pcid,PCI_MAX_LAT,max_lat);
1189 //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
1190 //printk("max lat is %x\n",max_lat);
1192 for (ii=0;ii<0xFF;ii++)
1194 pci_read_config_byte(pcid,ii,&value);
1195 pci_config[ii] = value;
1197 for (ii=0,j=1;ii<0x100;ii++,j++)
1201 printk("%x:",pci_config[ii]);
1206 printk("%x:",pci_config[ii]);
1213 static void device_free_info(PSDevice pDevice) {
1215 struct net_device* dev=pDevice->dev;
1218 //2008-0714-01<Add>by chester
1219 device_release_WPADEV(pDevice);
1221 //2008-07-21-01<Add>by MikeLiu
1223 if(wpa_set_wpadev(pDevice, 0)!=0)
1224 printk("unregister wpadev fail?\n");
1226 if (pDevice_Infos==NULL)
1229 for (ptr=pDevice_Infos;ptr && (ptr!=pDevice);ptr=ptr->next)
1233 if (ptr==pDevice_Infos)
1234 pDevice_Infos=ptr->next;
1236 ptr->prev->next=ptr->next;
1239 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
1244 hostap_set_hostapd(pDevice, 0, 0);
1247 unregister_netdev(dev);
1249 if (pDevice->PortOffset)
1250 iounmap((PVOID)pDevice->PortOffset);
1253 pci_release_regions(pDevice->pcid);
1257 if (pDevice->pcid) {
1258 pci_set_drvdata(pDevice->pcid,NULL);
1262 static BOOL device_init_rings(PSDevice pDevice) {
1266 /*allocate all RD/TD rings a single pool*/
1267 vir_pool = pci_alloc_consistent(pDevice->pcid,
1268 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1269 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1270 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1271 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1272 &pDevice->pool_dma);
1274 if (vir_pool == NULL) {
1275 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
1280 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1281 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1282 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1283 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1286 pDevice->aRD0Ring = vir_pool;
1287 pDevice->aRD1Ring = vir_pool +
1288 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1291 pDevice->rd0_pool_dma = pDevice->pool_dma;
1292 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1293 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1295 pDevice->tx0_bufs = pci_alloc_consistent(pDevice->pcid,
1296 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1297 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1298 CB_BEACON_BUF_SIZE +
1300 &pDevice->tx_bufs_dma0);
1302 if (pDevice->tx0_bufs == NULL) {
1303 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
1304 pci_free_consistent(pDevice->pcid,
1305 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1306 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1307 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1308 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1309 vir_pool, pDevice->pool_dma
1314 memset(pDevice->tx0_bufs, 0,
1315 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1316 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1317 CB_BEACON_BUF_SIZE +
1321 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1322 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1324 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1325 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1328 // vir_pool: pvoid type
1329 pDevice->apTD0Rings = vir_pool
1330 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1331 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1333 pDevice->apTD1Rings = vir_pool
1334 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1335 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1336 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1339 pDevice->tx1_bufs = pDevice->tx0_bufs +
1340 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1343 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1344 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1346 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1349 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1350 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1353 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1354 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1360 static void device_free_rings(PSDevice pDevice) {
1362 pci_free_consistent(pDevice->pcid,
1363 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1364 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1365 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1366 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1368 pDevice->aRD0Ring, pDevice->pool_dma
1371 if (pDevice->tx0_bufs)
1372 pci_free_consistent(pDevice->pcid,
1373 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1374 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1375 CB_BEACON_BUF_SIZE +
1377 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1381 static void device_init_rd0_ring(PSDevice pDevice) {
1383 dma_addr_t curr = pDevice->rd0_pool_dma;
1386 /* Init the RD0 ring entries */
1387 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1388 pDesc = &(pDevice->aRD0Ring[i]);
1389 pDesc->pRDInfo = alloc_rd_info();
1390 ASSERT(pDesc->pRDInfo);
1391 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1392 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1393 pDevice->dev->name);
1395 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1396 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1397 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1401 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1402 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1406 static void device_init_rd1_ring(PSDevice pDevice) {
1408 dma_addr_t curr = pDevice->rd1_pool_dma;
1411 /* Init the RD1 ring entries */
1412 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1413 pDesc = &(pDevice->aRD1Ring[i]);
1414 pDesc->pRDInfo = alloc_rd_info();
1415 ASSERT(pDesc->pRDInfo);
1416 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1417 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1418 pDevice->dev->name);
1420 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1421 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1422 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1426 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1427 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1431 static void device_init_defrag_cb(PSDevice pDevice) {
1433 PSDeFragControlBlock pDeF;
1435 /* Init the fragment ctl entries */
1436 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1437 pDeF = &(pDevice->sRxDFCB[i]);
1438 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1439 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
1440 pDevice->dev->name);
1443 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1444 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1450 static void device_free_rd0_ring(PSDevice pDevice) {
1453 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1454 PSRxDesc pDesc =&(pDevice->aRD0Ring[i]);
1455 PDEVICE_RD_INFO pRDInfo =pDesc->pRDInfo;
1457 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1458 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1460 dev_kfree_skb(pRDInfo->skb);
1462 kfree((PVOID)pDesc->pRDInfo);
1467 static void device_free_rd1_ring(PSDevice pDevice) {
1471 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1472 PSRxDesc pDesc=&(pDevice->aRD1Ring[i]);
1473 PDEVICE_RD_INFO pRDInfo=pDesc->pRDInfo;
1475 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1476 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1478 dev_kfree_skb(pRDInfo->skb);
1480 kfree((PVOID)pDesc->pRDInfo);
1485 static void device_free_frag_buf(PSDevice pDevice) {
1486 PSDeFragControlBlock pDeF;
1489 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1491 pDeF = &(pDevice->sRxDFCB[i]);
1494 dev_kfree_skb(pDeF->skb);
1500 static void device_init_td0_ring(PSDevice pDevice) {
1505 curr = pDevice->td0_pool_dma;
1506 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1507 pDesc = &(pDevice->apTD0Rings[i]);
1508 pDesc->pTDInfo = alloc_td_info();
1509 ASSERT(pDesc->pTDInfo);
1510 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1511 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1512 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1514 pDesc->next =&(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1515 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1516 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1520 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1521 pDevice->apTailTD[0] = pDevice->apCurrTD[0] =&(pDevice->apTD0Rings[0]);
1525 static void device_init_td1_ring(PSDevice pDevice) {
1530 /* Init the TD ring entries */
1531 curr=pDevice->td1_pool_dma;
1532 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr+=sizeof(STxDesc)) {
1533 pDesc=&(pDevice->apTD1Rings[i]);
1534 pDesc->pTDInfo = alloc_td_info();
1535 ASSERT(pDesc->pTDInfo);
1536 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1537 pDesc->pTDInfo->buf=pDevice->tx1_bufs+(i)*PKT_BUF_SZ;
1538 pDesc->pTDInfo->buf_dma=pDevice->tx_bufs_dma1+(i)*PKT_BUF_SZ;
1540 pDesc->next=&(pDevice->apTD1Rings[(i+1) % pDevice->sOpts.nTxDescs[1]]);
1541 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1542 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1546 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1547 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1552 static void device_free_td0_ring(PSDevice pDevice) {
1554 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1555 PSTxDesc pDesc=&(pDevice->apTD0Rings[i]);
1556 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1558 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1559 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,
1560 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1563 dev_kfree_skb(pTDInfo->skb);
1565 kfree((PVOID)pDesc->pTDInfo);
1569 static void device_free_td1_ring(PSDevice pDevice) {
1572 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1573 PSTxDesc pDesc=&(pDevice->apTD1Rings[i]);
1574 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1576 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1577 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1578 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1581 dev_kfree_skb(pTDInfo->skb);
1583 kfree((PVOID)pDesc->pTDInfo);
1590 /*-----------------------------------------------------------------*/
1592 static int device_rx_srv(PSDevice pDevice, UINT uIdx) {
1597 for (pRD = pDevice->pCurrRD[uIdx];
1598 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1600 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->pCurrRD = %x, works = %d\n", pRD, works);
1603 if (device_receive_frame(pDevice, pRD)) {
1604 if (!device_alloc_rx_buf(pDevice,pRD)) {
1605 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1606 "%s: can not allocate rx buf\n", pDevice->dev->name);
1610 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1611 pDevice->dev->last_rx = jiffies;
1614 pDevice->pCurrRD[uIdx]=pRD;
1620 static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD) {
1622 PDEVICE_RD_INFO pRDInfo=pRD->pRDInfo;
1625 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1627 //printk("device_alloc_rx_buf:skb is %x\n",pRDInfo->skb);
1629 if (pRDInfo->skb==NULL)
1631 ASSERT(pRDInfo->skb);
1632 pRDInfo->skb->dev = pDevice->dev;
1633 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
1634 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1635 *((unsigned int *) &(pRD->m_rd0RD0)) = 0; /* FIX cast */
1637 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1638 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1639 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1640 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1647 BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
1649 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1650 if (pDeF->skb == NULL)
1653 pDeF->skb->dev = pDevice->dev;
1660 static int device_tx_srv(PSDevice pDevice, UINT uIdx) {
1666 UINT uFrameSize, uFIFOHeaderSize;
1667 PSTxBufHead pTxBufHead;
1668 struct net_device_stats* pStats = &pDevice->stats;
1669 struct sk_buff* skb;
1671 PSMgmtObject pMgmt = pDevice->pMgmt;
1674 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] >0; pTD = pTD->next) {
1676 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1681 byTsr0 = pTD->m_td0TD0.byTSR0;
1682 byTsr1 = pTD->m_td0TD0.byTSR1;
1684 //Only the status of first TD in the chain is correct
1685 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1687 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1688 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1689 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1690 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1691 // Update the statistics based on the Transmit status
1692 // now, we DO'NT check TSR0_CDH
1694 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1696 (PBYTE)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1700 BSSvUpdateNodeTxCounter(pDevice,
1702 (PBYTE)(pTD->pTDInfo->buf),
1706 if ( !(byTsr1 & TSR1_TERR)) {
1708 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1709 (INT)uIdx, byTsr1, byTsr0);
1711 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG) {
1712 pDevice->s802_11Counter.TransmittedFragmentCount ++;
1714 pStats->tx_packets++;
1715 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1718 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1719 (INT)uIdx, byTsr1, byTsr0);
1720 pStats->tx_errors++;
1721 pStats->tx_dropped++;
1725 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1726 if (pDevice->bEnableHostapd) {
1727 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif.. \n");
1728 skb = pTD->pTDInfo->skb;
1729 skb->dev = pDevice->apdev;
1730 skb_reset_mac_header(skb);
1731 skb->pkt_type = PACKET_OTHERHOST;
1732 //skb->protocol = htons(ETH_P_802_2);
1733 memset(skb->cb, 0, sizeof(skb->cb));
1738 if (byTsr1 & TSR1_TERR) {
1739 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1740 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1741 (INT)uIdx, byTsr1, byTsr0);
1744 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1745 // (INT)uIdx, byTsr1, byTsr0);
1747 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1748 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1750 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1752 skb = pTD->pTDInfo->skb;
1753 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
1754 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1755 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1756 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1758 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1759 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1760 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1761 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1762 ,(INT)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1763 pStats->tx_errors--;
1764 pStats->tx_dropped--;
1769 device_free_tx_buf(pDevice,pTD);
1770 pDevice->iTDUsed[uIdx]--;
1775 if (uIdx == TYPE_AC0DMA) {
1776 // RESERV_AC0DMA reserved for relay
1778 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1780 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
1782 if (netif_queue_stopped(pDevice->dev) && (bFull==FALSE)){
1783 netif_wake_queue(pDevice->dev);
1788 pDevice->apTailTD[uIdx] = pTD;
1794 static void device_error(PSDevice pDevice, WORD status) {
1796 if (status & ISR_FETALERR) {
1797 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1798 "%s: Hardware fatal error.\n",
1799 pDevice->dev->name);
1800 netif_stop_queue(pDevice->dev);
1801 del_timer(&pDevice->sTimerCommand);
1802 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1803 pDevice->bCmdRunning = FALSE;
1804 MACbShutdown(pDevice->PortOffset);
1810 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc) {
1811 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1812 struct sk_buff* skb=pTDInfo->skb;
1814 // pre-allocated buf_dma can't be unmapped.
1815 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1816 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,skb->len,
1820 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1821 dev_kfree_skb_irq(skb);
1823 pTDInfo->skb_dma = 0;
1825 pTDInfo->byFlags = 0;
1831 VOID InitRxManagementQueue(PSDevice pDevice)
1833 pDevice->rxManeQueue.packet_num = 0;
1834 pDevice->rxManeQueue.head = pDevice->rxManeQueue.tail = 0;
1846 PSDevice pDevice = (PSDevice) Context;
1847 PSRxMgmtPacket pRxMgmtPacket;
1849 //complete(&pDevice->notify);
1850 //printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
1852 //printk("Enter MlmeThread,packet _num is %d\n",pDevice->rxManeQueue.packet_num);
1859 //down(&pDevice->mlme_semaphore);
1860 // pRxMgmtPacket = DeQueue(pDevice);
1862 spin_lock_irq(&pDevice->lock);
1863 while(pDevice->rxManeQueue.packet_num != 0)
1865 pRxMgmtPacket = DeQueue(pDevice);
1867 //DequeueManageObject(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
1868 vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
1869 //printk("packet_num is %d\n",pDevice->rxManeQueue.packet_num);
1872 spin_unlock_irq(&pDevice->lock);
1877 //printk("Before schedule thread jiffies is %x\n",jiffies);
1879 //printk("after schedule thread jiffies is %x\n",jiffies);
1882 //printk("i is %d\n",i);
1892 static int device_open(struct net_device *dev) {
1893 PSDevice pDevice=(PSDevice) netdev_priv(dev);
1895 #ifdef WPA_SM_Transtatus
1896 extern SWPAResult wpa_Result;
1899 pDevice->rx_buf_sz = PKT_BUF_SZ;
1900 if (!device_init_rings(pDevice)) {
1903 //2008-5-13 <add> by chester
1904 i=request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1907 //printk("DEBUG1\n");
1908 #ifdef WPA_SM_Transtatus
1909 memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
1910 wpa_Result.proto = 0;
1911 wpa_Result.key_mgmt = 0;
1912 wpa_Result.eap_type = 0;
1913 wpa_Result.authenticated = FALSE;
1914 pDevice->fWPA_Authened = FALSE;
1916 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
1917 device_init_rd0_ring(pDevice);
1918 device_init_rd1_ring(pDevice);
1919 device_init_defrag_cb(pDevice);
1920 device_init_td0_ring(pDevice);
1921 device_init_td1_ring(pDevice);
1922 // VNTWIFIvSet11h(pDevice->pMgmt, pDevice->b11hEnable);
1925 if (pDevice->bDiversityRegCtlON) {
1926 device_init_diversity_timer(pDevice);
1928 vMgrObjectInit(pDevice);
1929 vMgrTimerInit(pDevice);
1933 tasklet_init (&pDevice->RxMngWorkItem,(void *)MngWorkItem,(unsigned long )pDevice);
1936 InitRxManagementQueue(pDevice);
1938 mlme_task = kthread_run(MlmeThread,(void *) pDevice, "MLME");
1939 if (IS_ERR(mlme_task)) {
1940 printk("thread create fail\n");
1950 pDevice->MLMEThr_pid = kernel_thread(MlmeThread, pDevice, CLONE_VM);
1951 if (pDevice->MLMEThr_pid <0 )
1953 printk("unable start thread MlmeThread\n");
1958 //printk("thread id is %d\n",pDevice->MLMEThr_pid);
1959 //printk("Create thread time is %x\n",jiffies);
1960 //wait_for_completion(&pDevice->notify);
1965 // if (( SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL)&0x06)==0x04)
1967 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
1968 device_init_registers(pDevice, DEVICE_INIT_COLD);
1969 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1970 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, U_ETHER_ADDR_LEN);
1971 device_set_multi(pDevice->dev);
1973 // Init for Key Management
1974 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1975 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1977 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1979 pDevice->bwextstep0 = FALSE;
1980 pDevice->bwextstep1 = FALSE;
1981 pDevice->bwextstep2 = FALSE;
1982 pDevice->bwextstep3 = FALSE;
1984 pDevice->bwextcount=0;
1985 pDevice->bWPASuppWextEnabled = FALSE;
1987 pDevice->byReAssocCount = 0;
1988 pDevice->bWPADEVUp = FALSE;
1989 // Patch: if WEP key already set by iwconfig but device not yet open
1990 if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) {
1991 KeybSetDefaultKey(&(pDevice->sKey),
1992 (DWORD)(pDevice->byKeyIndex | (1 << 31)),
1993 pDevice->uKeyLength,
1997 pDevice->PortOffset,
2000 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
2003 //printk("DEBUG2\n");
2006 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
2007 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2009 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2010 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
2013 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
2014 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_SSID, NULL);
2016 pDevice->flags |=DEVICE_FLAGS_OPENED;
2018 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
2023 static int device_close(struct net_device *dev) {
2024 PSDevice pDevice=(PSDevice) netdev_priv(dev);
2025 PSMgmtObject pMgmt = pDevice->pMgmt;
2031 //2007-1121-02<Add>by EinsnLiu
2032 if (pDevice->bLinkPass) {
2033 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2037 del_timer(&pDevice->sTimerTxData);
2039 del_timer(&pDevice->sTimerCommand);
2040 del_timer(&pMgmt->sTimerSecondCallback);
2041 if (pDevice->bDiversityRegCtlON) {
2042 del_timer(&pDevice->TimerSQ3Tmax1);
2043 del_timer(&pDevice->TimerSQ3Tmax2);
2044 del_timer(&pDevice->TimerSQ3Tmax3);
2048 tasklet_kill(&pDevice->RxMngWorkItem);
2050 netif_stop_queue(dev);
2051 pDevice->bCmdRunning = FALSE;
2052 MACbShutdown(pDevice->PortOffset);
2053 MACbSoftwareReset(pDevice->PortOffset);
2054 CARDbRadioPowerOff(pDevice);
2056 pDevice->bLinkPass = FALSE;
2057 memset(pMgmt->abyCurrBSSID, 0, 6);
2058 pMgmt->eCurrState = WMAC_STATE_IDLE;
2059 device_free_td0_ring(pDevice);
2060 device_free_td1_ring(pDevice);
2061 device_free_rd0_ring(pDevice);
2062 device_free_rd1_ring(pDevice);
2063 device_free_frag_buf(pDevice);
2064 device_free_rings(pDevice);
2065 BSSvClearNodeDBTable(pDevice, 0);
2066 free_irq(dev->irq, dev);
2067 pDevice->flags &=(~DEVICE_FLAGS_OPENED);
2068 //2008-0714-01<Add>by chester
2069 device_release_WPADEV(pDevice);
2071 //tasklet_kill(&pDevice->RxMngWorkItem);
2073 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close.. \n");
2079 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
2080 PSDevice pDevice=netdev_priv(dev);
2085 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
2086 spin_lock_irq(&pDevice->lock);
2088 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2089 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
2090 dev_kfree_skb_irq(skb);
2091 spin_unlock_irq(&pDevice->lock);
2095 if (pDevice->bStopTx0Pkt == TRUE) {
2096 dev_kfree_skb_irq(skb);
2097 spin_unlock_irq(&pDevice->lock);
2101 cbMPDULen = skb->len;
2104 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
2106 spin_unlock_irq(&pDevice->lock);
2114 BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, UINT uNodeIndex) {
2115 PSMgmtObject pMgmt = pDevice->pMgmt;
2116 PSTxDesc pHeadTD, pLastTD;
2117 UINT cbFrameBodySize;
2120 BOOL bNeedEncryption = FALSE;
2121 PSKeyItem pTransmitKey = NULL;
2125 // BYTE byKeyIndex = 0;
2128 if (pDevice->bStopTx0Pkt == TRUE) {
2129 dev_kfree_skb_irq(skb);
2133 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2134 dev_kfree_skb_irq(skb);
2135 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
2139 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2140 if (pDevice->uAssocCount == 0) {
2141 dev_kfree_skb_irq(skb);
2142 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
2147 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
2149 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2151 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2152 cbFrameBodySize = skb->len - U_HEADER_LEN;
2155 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2156 cbFrameBodySize += 8;
2158 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2160 if ( uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
2161 dev_kfree_skb_irq(skb);
2164 byPktType = (BYTE)pDevice->byPacketType;
2167 if (pDevice->bFixRate) {
2168 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2169 if (pDevice->uConnectionRate >= RATE_11M) {
2170 pDevice->wCurrentRate = RATE_11M;
2172 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2175 if (pDevice->uConnectionRate >= RATE_54M)
2176 pDevice->wCurrentRate = RATE_54M;
2178 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2182 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2186 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2187 pDevice->byPreambleType = pDevice->byShortPreamble;
2190 pDevice->byPreambleType = PREAMBLE_LONG;
2193 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2196 if (pDevice->wCurrentRate <= RATE_11M) {
2197 byPktType = PK_TYPE_11B;
2198 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2199 byPktType = PK_TYPE_11A;
2201 if (pDevice->bProtectMode == TRUE) {
2202 byPktType = PK_TYPE_11GB;
2204 byPktType = PK_TYPE_11GA;
2208 if (pDevice->bEncryptionEnable == TRUE)
2209 bNeedEncryption = TRUE;
2211 if (pDevice->bEnableHostWEP) {
2212 pTransmitKey = &STempKey;
2213 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2214 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2215 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2216 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2217 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2218 memcpy(pTransmitKey->abyKey,
2219 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2220 pTransmitKey->uKeyLength
2223 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2224 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
2225 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2230 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2232 MACbPSWakeup(pDevice->PortOffset);
2235 pDevice->bPWBitOn = FALSE;
2238 for (ii = 0; ii < uMACfragNum; ii++) {
2239 // Poll Transmit the adapter
2241 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2243 if (ii == (uMACfragNum - 1))
2245 pHeadTD = pHeadTD->next;
2248 // Save the information needed by the tx interrupt handler
2249 // to complete the Send request
2250 pLastTD->pTDInfo->skb = skb;
2251 pLastTD->pTDInfo->byFlags = 0;
2252 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2254 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
2256 MACvTransmit0(pDevice->PortOffset);
2262 //TYPE_AC0DMA data tx
2263 static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
2264 PSDevice pDevice=netdev_priv(dev);
2266 PSMgmtObject pMgmt = pDevice->pMgmt;
2267 PSTxDesc pHeadTD, pLastTD;
2268 UINT uNodeIndex = 0;
2269 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2271 UINT uMACfragNum = 1;
2272 UINT cbFrameBodySize;
2275 BOOL bNeedEncryption = FALSE;
2276 PSKeyItem pTransmitKey = NULL;
2279 BOOL bTKIP_UseGTK = FALSE;
2280 BOOL bNeedDeAuth = FALSE;
2282 BOOL bNodeExist = FALSE;
2286 spin_lock_irq(&pDevice->lock);
2287 if (pDevice->bLinkPass == FALSE) {
2288 dev_kfree_skb_irq(skb);
2289 spin_unlock_irq(&pDevice->lock);
2293 if (pDevice->bStopDataPkt) {
2294 dev_kfree_skb_irq(skb);
2295 spin_unlock_irq(&pDevice->lock);
2300 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2301 if (pDevice->uAssocCount == 0) {
2302 dev_kfree_skb_irq(skb);
2303 spin_unlock_irq(&pDevice->lock);
2306 if (IS_MULTICAST_ADDRESS((PBYTE)(skb->data))) {
2309 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2310 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2311 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2313 pMgmt->abyPSTxMap[0] |= byMask[0];
2314 spin_unlock_irq(&pDevice->lock);
2318 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
2319 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2320 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2321 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2323 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2324 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2325 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2326 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2327 spin_unlock_irq(&pDevice->lock);
2331 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2332 pDevice->byPreambleType = pDevice->byShortPreamble;
2335 pDevice->byPreambleType = PREAMBLE_LONG;
2342 if (bNodeExist == FALSE) {
2343 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2344 dev_kfree_skb_irq(skb);
2345 spin_unlock_irq(&pDevice->lock);
2350 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
2352 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2355 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2356 cbFrameBodySize = skb->len - U_HEADER_LEN;
2358 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2359 cbFrameBodySize += 8;
2363 if (pDevice->bEncryptionEnable == TRUE) {
2364 bNeedEncryption = TRUE;
2367 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2368 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2369 pbyBSSID = pDevice->abyBSSID;
2371 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2373 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2374 bTKIP_UseGTK = TRUE;
2375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2382 }else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2384 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2385 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2386 for (ii = 0; ii< 6; ii++)
2387 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2391 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE)
2395 pbyBSSID = pDevice->abyBroadcastAddr;
2396 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2397 pTransmitKey = NULL;
2398 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2399 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2404 bTKIP_UseGTK = TRUE;
2405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2410 if (pDevice->bEnableHostWEP) {
2411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2412 if (pDevice->bEncryptionEnable == TRUE) {
2413 pTransmitKey = &STempKey;
2414 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2415 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2416 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2417 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2418 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2419 memcpy(pTransmitKey->abyKey,
2420 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2421 pTransmitKey->uKeyLength
2426 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2428 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2429 DBG_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
2430 dev_kfree_skb_irq(skb);
2431 spin_unlock_irq(&pDevice->lock);
2435 if (pTransmitKey != NULL) {
2436 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2437 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2438 uMACfragNum = 1; //WEP256 doesn't support fragment
2442 byPktType = (BYTE)pDevice->byPacketType;
2444 if (pDevice->bFixRate) {
2446 printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n",pDevice->eCurrentPHYType,pDevice->uConnectionRate);
2449 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2450 if (pDevice->uConnectionRate >= RATE_11M) {
2451 pDevice->wCurrentRate = RATE_11M;
2453 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2456 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2457 (pDevice->uConnectionRate <= RATE_6M)) {
2458 pDevice->wCurrentRate = RATE_6M;
2460 if (pDevice->uConnectionRate >= RATE_54M)
2461 pDevice->wCurrentRate = RATE_54M;
2463 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2467 pDevice->byACKRate = (BYTE) pDevice->wCurrentRate;
2468 pDevice->byTopCCKBasicRate = RATE_1M;
2469 pDevice->byTopOFDMBasicRate = RATE_6M;
2473 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2474 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2475 pDevice->wCurrentRate = RATE_1M;
2476 pDevice->byACKRate = RATE_1M;
2477 pDevice->byTopCCKBasicRate = RATE_1M;
2478 pDevice->byTopOFDMBasicRate = RATE_6M;
2480 pDevice->wCurrentRate = RATE_6M;
2481 pDevice->byACKRate = RATE_6M;
2482 pDevice->byTopCCKBasicRate = RATE_1M;
2483 pDevice->byTopOFDMBasicRate = RATE_6M;
2487 VNTWIFIvGetTxRate( pDevice->pMgmt,
2488 pDevice->sTxEthHeader.abyDstAddr,
2489 &(pDevice->wCurrentRate),
2490 &(pDevice->byACKRate),
2491 &(pDevice->byTopCCKBasicRate),
2492 &(pDevice->byTopOFDMBasicRate));
2495 printk("auto rate:Rate : %d,AckRate:%d,TopCCKRate:%d,TopOFDMRate:%d\n",
2496 pDevice->wCurrentRate,pDevice->byACKRate,
2497 pDevice->byTopCCKBasicRate,pDevice->byTopOFDMBasicRate);
2503 pDevice->wCurrentRate = 11;
2504 pDevice->byACKRate = 8;
2505 pDevice->byTopCCKBasicRate = 3;
2506 pDevice->byTopOFDMBasicRate = 8;
2513 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2515 if (pDevice->wCurrentRate <= RATE_11M) {
2516 byPktType = PK_TYPE_11B;
2517 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2518 byPktType = PK_TYPE_11A;
2520 if (pDevice->bProtectMode == TRUE) {
2521 byPktType = PK_TYPE_11GB;
2523 byPktType = PK_TYPE_11GA;
2527 //#ifdef PLICE_DEBUG
2528 // printk("FIX RATE:CurrentRate is %d");
2531 if (bNeedEncryption == TRUE) {
2532 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2533 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2534 bNeedEncryption = FALSE;
2535 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2536 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2537 if (pTransmitKey == NULL) {
2538 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2541 if (bTKIP_UseGTK == TRUE) {
2542 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2546 bNeedEncryption = TRUE;
2551 if (pDevice->byCntMeasure == 2) {
2553 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2556 if (pDevice->bEnableHostWEP) {
2557 if ((uNodeIndex != 0) &&
2558 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2559 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2560 bNeedEncryption = TRUE;
2565 if (pTransmitKey == NULL) {
2566 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2567 dev_kfree_skb_irq(skb);
2568 spin_unlock_irq(&pDevice->lock);
2576 //if (skb->len == 98)
2578 // printk("ping:len is %d\n");
2581 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2582 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2583 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2588 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2590 MACbPSWakeup(pDevice->PortOffset);
2592 pDevice->bPWBitOn = FALSE;
2595 for (ii = 0; ii < uMACfragNum; ii++) {
2596 // Poll Transmit the adapter
2598 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2600 if (ii == uMACfragNum - 1)
2602 pHeadTD = pHeadTD->next;
2605 // Save the information needed by the tx interrupt handler
2606 // to complete the Send request
2607 pLastTD->pTDInfo->skb = skb;
2608 pLastTD->pTDInfo->byFlags = 0;
2609 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2611 pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
2613 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1) {
2614 netif_stop_queue(dev);
2617 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2618 //#ifdef PLICE_DEBUG
2619 if (pDevice->bFixRate)
2621 printk("FixRate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2625 //printk("Auto Rate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2630 BYTE Protocol_Version; //802.1x Authentication
2631 BYTE Packet_Type; //802.1x Authentication
2632 BYTE Descriptor_type;
2634 BOOL bTxeapol_key = FALSE;
2635 Protocol_Version = skb->data[U_HEADER_LEN];
2636 Packet_Type = skb->data[U_HEADER_LEN+1];
2637 Descriptor_type = skb->data[U_HEADER_LEN+1+1+2];
2638 Key_info = (skb->data[U_HEADER_LEN+1+1+2+1] << 8)|(skb->data[U_HEADER_LEN+1+1+2+2]);
2639 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2640 if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
2641 (Packet_Type==3)) { //802.1x OR eapol-key challenge frame transfer
2642 bTxeapol_key = TRUE;
2643 if((Descriptor_type==254)||(Descriptor_type==2)) { //WPA or RSN
2644 if(!(Key_info & BIT3) && //group-key challenge
2645 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2646 pDevice->fWPA_Authened = TRUE;
2647 if(Descriptor_type==254)
2651 printk("Authentication completed!!\n");
2658 MACvTransmitAC0(pDevice->PortOffset);
2659 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0:pDevice->apCurrTD= %p\n", pHeadTD);
2661 dev->trans_start = jiffies;
2663 spin_unlock_irq(&pDevice->lock);
2668 static irqreturn_t device_intr(int irq, void *dev_instance) {
2669 struct net_device* dev=dev_instance;
2670 PSDevice pDevice=(PSDevice) netdev_priv(dev);
2673 DWORD dwMIBCounter=0;
2674 PSMgmtObject pMgmt = pDevice->pMgmt;
2675 BYTE byOrgPageSel=0;
2682 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2684 if (pDevice->dwIsr == 0)
2685 return IRQ_RETVAL(handled);
2687 if (pDevice->dwIsr == 0xffffffff) {
2688 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
2689 return IRQ_RETVAL(handled);
2692 // 2008-05-21 <mark> by Richardtai, we can't read RSSI here, because no packet bound with RSSI
2694 if ((pDevice->dwIsr & ISR_RXDMA0) &&
2695 (pDevice->byLocalID != REV_ID_VT3253_B0) &&
2696 (pDevice->bBSSIDFilter == TRUE)) {
2698 //BBbReadEmbeded(pDevice->PortOffset, 0x3E, &byRSSI);
2699 //pDevice->uCurrRSSI = byRSSI;
2704 MACvIntDisable(pDevice->PortOffset);
2705 spin_lock_irq(&pDevice->lock);
2707 //Make sure current page is 0
2708 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2709 if (byOrgPageSel == 1) {
2710 MACvSelectPage0(pDevice->PortOffset);
2715 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2717 // Must do this after doing rx/tx, cause ISR bit is slow
2718 // than RD/TD write back
2719 // update ISR counter
2720 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2721 while (pDevice->dwIsr != 0) {
2723 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2724 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2726 if (pDevice->dwIsr & ISR_FETALERR){
2727 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR \n");
2728 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2729 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2730 device_error(pDevice, pDevice->dwIsr);
2733 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2735 if (pDevice->dwIsr & ISR_MEASURESTART) {
2736 // 802.11h measure start
2737 pDevice->byOrgChannel = pDevice->byCurrentCh;
2738 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2739 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2740 MACvSelectPage1(pDevice->PortOffset);
2741 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2742 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2743 MACvSelectPage0(pDevice->PortOffset);
2745 // WCMDbFlushCommandQueue(pDevice->pMgmt, TRUE);
2746 if (CARDbSetChannel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel) == TRUE) {
2747 pDevice->bMeasureInProgress = TRUE;
2748 MACvSelectPage1(pDevice->PortOffset);
2749 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2750 MACvSelectPage0(pDevice->PortOffset);
2751 pDevice->byBasicMap = 0;
2752 pDevice->byCCAFraction = 0;
2753 for(ii=0;ii<8;ii++) {
2754 pDevice->dwRPIs[ii] = 0;
2757 // can not measure because set channel fail
2758 // WCMDbResetCommandQueue(pDevice->pMgmt);
2759 // clear measure control
2760 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2761 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2762 MACvSelectPage1(pDevice->PortOffset);
2763 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2764 MACvSelectPage0(pDevice->PortOffset);
2767 if (pDevice->dwIsr & ISR_MEASUREEND) {
2768 // 802.11h measure end
2769 pDevice->bMeasureInProgress = FALSE;
2770 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2771 MACvSelectPage1(pDevice->PortOffset);
2772 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2773 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2774 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2775 pDevice->byBasicMap |= (byData >> 4);
2776 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2777 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2778 // clear measure control
2779 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2780 MACvSelectPage0(pDevice->PortOffset);
2781 CARDbSetChannel(pDevice, pDevice->byOrgChannel);
2782 // WCMDbResetCommandQueue(pDevice->pMgmt);
2783 MACvSelectPage1(pDevice->PortOffset);
2784 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2785 MACvSelectPage0(pDevice->PortOffset);
2786 if (byData & MSRCTL_FINISH) {
2788 s_vCompleteCurrentMeasure(pDevice, 0);
2790 // can not measure because not ready before end of measure time
2791 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2794 if (pDevice->dwIsr & ISR_QUIETSTART) {
2797 } while (CARDbStartQuiet(pDevice) == FALSE);
2801 if (pDevice->dwIsr & ISR_TBTT) {
2802 if (pDevice->bEnableFirstQuiet == TRUE) {
2803 pDevice->byQuietStartCount--;
2804 if (pDevice->byQuietStartCount == 0) {
2805 pDevice->bEnableFirstQuiet = FALSE;
2806 MACvSelectPage1(pDevice->PortOffset);
2807 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2808 MACvSelectPage0(pDevice->PortOffset);
2811 if ((pDevice->bChannelSwitch == TRUE) &&
2812 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
2813 pDevice->byChannelSwitchCount--;
2814 if (pDevice->byChannelSwitchCount == 0) {
2815 pDevice->bChannelSwitch = FALSE;
2816 CARDbSetChannel(pDevice, pDevice->byNewChannel);
2817 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2818 MACvSelectPage1(pDevice->PortOffset);
2819 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2820 MACvSelectPage0(pDevice->PortOffset);
2821 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2825 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2826 //pDevice->bBeaconSent = FALSE;
2828 if ((pDevice->bUpdateBBVGA) && (pDevice->bLinkPass == TRUE) && (pDevice->uCurrRSSI != 0)) {
2831 RFvRSSITodBm(pDevice, (BYTE) pDevice->uCurrRSSI, &ldBm);
2832 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
2833 if (ldBm < pDevice->ldBmThreshold[ii]) {
2834 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2838 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2839 pDevice->uBBVGADiffCount++;
2840 if (pDevice->uBBVGADiffCount == 1) {
2841 // first VGA diff gain
2842 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2843 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2844 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2846 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2847 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2848 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2849 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2852 pDevice->uBBVGADiffCount = 1;
2857 pDevice->bBeaconSent = FALSE;
2858 if (pDevice->bEnablePSMode) {
2859 PSbIsNextTBTTWakeUp((HANDLE)pDevice);
2862 if ((pDevice->eOPMode == OP_MODE_AP) ||
2863 (pDevice->eOPMode == OP_MODE_ADHOC)) {
2865 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2866 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2869 if (pDevice->eOPMode == OP_MODE_ADHOC && pDevice->pMgmt->wCurrATIMWindow > 0) {
2870 // todo adhoc PS mode
2875 if (pDevice->dwIsr & ISR_BNTX) {
2877 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2878 pDevice->bIsBeaconBufReadySet = FALSE;
2879 pDevice->cbBeaconBufReadySetCnt = 0;
2882 if (pDevice->eOPMode == OP_MODE_AP) {
2883 if(pMgmt->byDTIMCount > 0) {
2884 pMgmt->byDTIMCount --;
2885 pMgmt->sNodeDBTable[0].bRxPSPoll = FALSE;
2888 if(pMgmt->byDTIMCount == 0) {
2889 // check if mutltcast tx bufferring
2890 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2891 pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE;
2892 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2896 pDevice->bBeaconSent = TRUE;
2898 if (pDevice->bChannelSwitch == TRUE) {
2899 pDevice->byChannelSwitchCount--;
2900 if (pDevice->byChannelSwitchCount == 0) {
2901 pDevice->bChannelSwitch = FALSE;
2902 CARDbSetChannel(pDevice, pDevice->byNewChannel);
2903 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2904 MACvSelectPage1(pDevice->PortOffset);
2905 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2906 MACvSelectPage0(pDevice->PortOffset);
2907 //VNTWIFIbSendBeacon(pDevice->pMgmt);
2908 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2914 if (pDevice->dwIsr & ISR_RXDMA0) {
2915 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2917 if (pDevice->dwIsr & ISR_RXDMA1) {
2918 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2920 if (pDevice->dwIsr & ISR_TXDMA0){
2921 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2923 if (pDevice->dwIsr & ISR_AC0DMA){
2924 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2926 if (pDevice->dwIsr & ISR_SOFTTIMER) {
2929 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2930 if (pDevice->eOPMode == OP_MODE_AP) {
2931 if (pDevice->bShortSlotTime)
2932 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2934 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2936 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2937 pDevice->byCntMeasure = 0;
2940 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2942 MACvReceive0(pDevice->PortOffset);
2943 MACvReceive1(pDevice->PortOffset);
2945 if (max_count>pDevice->sOpts.int_works)
2949 if (byOrgPageSel == 1) {
2950 MACvSelectPage1(pDevice->PortOffset);
2953 spin_unlock_irq(&pDevice->lock);
2954 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2956 return IRQ_RETVAL(handled);
2960 static unsigned const ethernet_polynomial = 0x04c11db7U;
2961 static inline u32 ether_crc(int length, unsigned char *data)
2965 while(--length >= 0) {
2966 unsigned char current_octet = *data++;
2968 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
2970 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
2976 //2008-8-4 <add> by chester
2977 static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source)
2980 int source_len = strlen(source);
2983 strcat(buf1, string);
2985 source+=strlen(buf1);
2987 memcpy(dest,source,source_len-strlen(buf1));
2991 int Config_FileOperation(PSDevice pDevice,BOOL fwrite,unsigned char *Parameter) {
2992 UCHAR *config_path=CONFIG_PATH;
2994 UCHAR tmpbuffer[20];
2995 struct file *filp=NULL;
2996 mm_segment_t old_fs = get_fs();
2997 //int oldfsuid=0,oldfsgid=0;
3002 /* Can't do this anymore, so we rely on correct filesystem permissions:
3003 //Make sure a caller can read or write power as root
3004 oldfsuid=current->cred->fsuid;
3005 oldfsgid=current->cred->fsgid;
3006 current->cred->fsuid = 0;
3007 current->cred->fsgid = 0;
3011 filp = filp_open(config_path, O_RDWR, 0);
3013 printk("Config_FileOperation:open file fail?\n");
3018 if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
3019 printk("file %s cann't readable or writable?\n",config_path);
3024 buffer = (UCHAR *)kmalloc(1024, GFP_KERNEL);
3026 printk("alllocate mem for file fail?\n");
3031 if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
3032 printk("read file error?\n");
3037 if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=TRUE) {
3038 printk("get parameter error?\n");
3043 if(memcmp(tmpbuffer,"USA",3)==0) {
3044 result=ZoneType_USA;
3046 else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
3047 result=ZoneType_Japan;
3049 else if(memcmp(tmpbuffer,"EUROPE",5)==0) {
3050 result=ZoneType_Europe;
3054 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
3061 if(filp_close(filp,NULL))
3062 printk("Config_FileOperation:close file fail\n");
3068 current->cred->fsuid=oldfsuid;
3069 current->cred->fsgid=oldfsgid;
3077 static void device_set_multi(struct net_device *dev) {
3078 PSDevice pDevice = (PSDevice) netdev_priv(dev);
3080 PSMgmtObject pMgmt = pDevice->pMgmt;
3082 struct dev_mc_list *mclist;
3085 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
3087 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
3088 DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
3089 /* Unconditionally log net taps. */
3090 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
3092 else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
3093 || (dev->flags & IFF_ALLMULTI)) {
3094 MACvSelectPage1(pDevice->PortOffset);
3095 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
3096 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
3097 MACvSelectPage0(pDevice->PortOffset);
3098 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3101 memset(mc_filter, 0, sizeof(mc_filter));
3102 netdev_for_each_mc_addr(mclist, dev) {
3103 int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
3104 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
3106 MACvSelectPage1(pDevice->PortOffset);
3107 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
3108 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
3109 MACvSelectPage0(pDevice->PortOffset);
3110 pDevice->byRxMode &= ~(RCR_UNICAST);
3111 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3114 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3115 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
3116 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3117 pDevice->byRxMode &= ~(RCR_UNICAST);
3120 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
3121 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode );
3125 static struct net_device_stats *device_get_stats(struct net_device *dev) {
3126 PSDevice pDevice=(PSDevice) netdev_priv(dev);
3128 return &pDevice->stats;
3133 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
3134 PSDevice pDevice = (PSDevice)netdev_priv(dev);
3136 struct iwreq *wrq = (struct iwreq *) rq;
3138 PSMgmtObject pMgmt = pDevice->pMgmt;
3142 if (pMgmt == NULL) {
3150 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
3153 case SIOCGIWNWID: //0x8b03 support
3154 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3155 rc = iwctl_giwnwid(dev, NULL, &(wrq->u.nwid), NULL);
3161 // Set frequency/channel
3163 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
3166 // Get frequency/channel
3168 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
3171 // Set desired network name (ESSID)
3175 char essid[IW_ESSID_MAX_SIZE+1];
3176 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
3180 if (copy_from_user(essid, wrq->u.essid.pointer,
3181 wrq->u.essid.length)) {
3185 rc = iwctl_siwessid(dev, NULL,
3186 &(wrq->u.essid), essid);
3191 // Get current network name (ESSID)
3195 char essid[IW_ESSID_MAX_SIZE+1];
3196 if (wrq->u.essid.pointer)
3197 rc = iwctl_giwessid(dev, NULL,
3198 &(wrq->u.essid), essid);
3199 if (copy_to_user(wrq->u.essid.pointer,
3201 wrq->u.essid.length) )
3208 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3212 // Get current Access Point (BSSID)
3214 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3218 // Set desired station name
3220 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
3224 // Get current station name
3226 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
3230 // Set the desired bit-rate
3232 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3235 // Get the current bit-rate
3238 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3241 // Set the desired RTS threshold
3244 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
3247 // Get the current RTS threshold
3250 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
3253 // Set the desired fragmentation threshold
3256 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
3259 // Get the current fragmentation threshold
3262 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
3265 // Set mode of operation
3267 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
3270 // Get mode of operation
3272 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
3275 // Set WEP keys and mode
3278 char abyKey[WLAN_WEP232_KEYLEN];
3280 if (wrq->u.encoding.pointer) {
3283 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
3287 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
3288 if (copy_from_user(abyKey,
3289 wrq->u.encoding.pointer,
3290 wrq->u.encoding.length)) {
3294 } else if (wrq->u.encoding.length != 0) {
3298 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3302 // Get the WEP keys and mode
3305 if (!capable(CAP_NET_ADMIN)) {
3310 char abyKey[WLAN_WEP232_KEYLEN];
3312 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3314 if (wrq->u.encoding.pointer) {
3315 if (copy_to_user(wrq->u.encoding.pointer,
3317 wrq->u.encoding.length))
3323 // Get the current Tx-Power
3325 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3330 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3336 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
3341 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
3344 // Get range of parameters
3348 struct iw_range range;
3350 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *) &range);
3351 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
3359 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
3365 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
3371 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
3375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
3381 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
3383 if (wrq->u.data.pointer) {
3384 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
3386 if (copy_to_user(wrq->u.data.pointer,
3388 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
3401 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3412 #endif // WIRELESS_SPY
3415 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
3418 if(wrq->u.data.pointer) {
3419 wrq->u.data.length = sizeof(iwctl_private_args) / sizeof( iwctl_private_args[0]);
3421 if(copy_to_user(wrq->u.data.pointer,
3422 (u_char *) iwctl_private_args,
3423 sizeof(iwctl_private_args)))
3430 //2008-0409-07, <Add> by Einsn Liu
3431 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3433 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
3434 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
3438 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH \n");
3439 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
3443 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE \n");
3444 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3448 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE \n");
3449 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3452 case SIOCSIWENCODEEXT:
3454 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
3455 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
3456 if(wrq->u.encoding.pointer){
3457 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1);
3458 if(wrq->u.encoding.length > (sizeof(struct iw_encode_ext)+ MAX_KEY_LEN)){
3462 if(copy_from_user(extra, wrq->u.encoding.pointer,wrq->u.encoding.length)){
3466 }else if(wrq->u.encoding.length != 0){
3470 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
3474 case SIOCGIWENCODEEXT:
3475 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT \n");
3476 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
3480 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME \n");
3481 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3484 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3485 //End Add -- //2008-0409-07, <Add> by Einsn Liu
3487 case IOCTL_CMD_TEST:
3489 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
3495 pReq = (PSCmdRequest)rq;
3496 pReq->wResult = MAGIC_CODE;
3502 if((((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_EVT) &&
3503 !(pDevice->flags & DEVICE_FLAGS_OPENED))
3505 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
3506 (((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_WPA))
3515 if (test_and_set_bit( 0, (void*)&(pMgmt->uCmdBusy))) {
3518 rc = private_ioctl(pDevice, rq);
3519 clear_bit( 0, (void*)&(pMgmt->uCmdBusy));
3522 case IOCTL_CMD_HOSTAPD:
3525 rc = hostap_ioctl(pDevice, &wrq->u.data);
3530 rc = wpa_ioctl(pDevice, &wrq->u.data);
3534 return ethtool_ioctl(dev, (void *) rq->ifr_data);
3535 // All other calls are currently unsupported
3539 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
3544 if (pDevice->bCommit) {
3545 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3546 netif_stop_queue(pDevice->dev);
3547 spin_lock_irq(&pDevice->lock);
3548 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
3549 spin_unlock_irq(&pDevice->lock);
3552 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
3553 spin_lock_irq(&pDevice->lock);
3554 pDevice->bLinkPass = FALSE;
3555 memset(pMgmt->abyCurrBSSID, 0, 6);
3556 pMgmt->eCurrState = WMAC_STATE_IDLE;
3557 netif_stop_queue(pDevice->dev);
3558 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3559 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
3560 if(pDevice->bWPASuppWextEnabled !=TRUE)
3562 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
3563 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3564 spin_unlock_irq(&pDevice->lock);
3566 pDevice->bCommit = FALSE;
3573 static int ethtool_ioctl(struct net_device *dev, void *useraddr)
3577 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
3581 case ETHTOOL_GDRVINFO: {
3582 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3583 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3584 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3585 if (copy_to_user(useraddr, &info, sizeof(info)))
3595 /*------------------------------------------------------------------*/
3597 MODULE_DEVICE_TABLE(pci, device_id_table);
3599 static struct pci_driver device_driver = {
3601 id_table: device_id_table,
3602 probe: device_found1,
3603 remove: device_remove1,
3605 suspend: viawget_suspend,
3606 resume: viawget_resume,
3610 static int __init device_init_module(void)
3615 // ret=pci_module_init(&device_driver);
3616 //ret = pcie_port_service_register(&device_driver);
3617 ret = pci_register_driver(&device_driver);
3620 register_reboot_notifier(&device_notifier);
3626 static void __exit device_cleanup_module(void)
3631 unregister_reboot_notifier(&device_notifier);
3633 pci_unregister_driver(&device_driver);
3637 module_init(device_init_module);
3638 module_exit(device_cleanup_module);
3643 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3645 struct pci_dev *pdev = NULL;
3650 while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
3651 if(pci_dev_driver(pdev) == &device_driver) {
3652 if (pci_get_drvdata(pdev))
3653 viawget_suspend(pdev, PMSG_HIBERNATE);
3661 viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3663 int power_status; // to silence the compiler
3665 PSDevice pDevice=pci_get_drvdata(pcid);
3666 PSMgmtObject pMgmt = pDevice->pMgmt;
3668 netif_stop_queue(pDevice->dev);
3669 spin_lock_irq(&pDevice->lock);
3670 pci_save_state(pcid);
3671 del_timer(&pDevice->sTimerCommand);
3672 del_timer(&pMgmt->sTimerSecondCallback);
3673 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3674 pDevice->uCmdDequeueIdx = 0;
3675 pDevice->uCmdEnqueueIdx = 0;
3676 pDevice->bCmdRunning = FALSE;
3677 MACbShutdown(pDevice->PortOffset);
3678 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3679 pDevice->bLinkPass = FALSE;
3680 memset(pMgmt->abyCurrBSSID, 0, 6);
3681 pMgmt->eCurrState = WMAC_STATE_IDLE;
3682 pci_disable_device(pcid);
3683 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3684 spin_unlock_irq(&pDevice->lock);
3689 viawget_resume(struct pci_dev *pcid)
3691 PSDevice pDevice=pci_get_drvdata(pcid);
3692 PSMgmtObject pMgmt = pDevice->pMgmt;
3693 int power_status; // to silence the compiler
3696 power_status = pci_set_power_state(pcid, 0);
3697 power_status = pci_enable_wake(pcid, 0, 0);
3698 pci_restore_state(pcid);
3699 if (netif_running(pDevice->dev)) {
3700 spin_lock_irq(&pDevice->lock);
3701 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3702 device_init_registers(pDevice, DEVICE_INIT_DXPL);
3703 if (pMgmt->sNodeDBTable[0].bActive == TRUE) { // Assoc with BSS
3704 pMgmt->sNodeDBTable[0].bActive = FALSE;
3705 pDevice->bLinkPass = FALSE;
3706 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3707 // In Adhoc, BSS state set back to started.
3708 pMgmt->eCurrState = WMAC_STATE_STARTED;
3711 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3712 pMgmt->eCurrState = WMAC_STATE_IDLE;
3715 init_timer(&pMgmt->sTimerSecondCallback);
3716 init_timer(&pDevice->sTimerCommand);
3717 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3718 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
3719 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3720 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3721 spin_unlock_irq(&pDevice->lock);