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
63 #if !defined(__DEVICE_H__)
66 #if !defined(__CARD_H__)
69 #if !defined(__TBIT_H__)
72 #if !defined(__BASEBAND_H__)
75 #if !defined(__MAC_H__)
78 #if !defined(__TETHER_H__)
81 #if !defined(__WMGR_H__)
84 #if !defined(__WCTL_H__)
87 #if !defined(__POWER_H__)
90 #if !defined(__WCMD_H__)
93 #if !defined(__IOCMD_H__)
96 #if !defined(__TCRC_H__)
99 #if !defined(__RXTX_H__)
102 #if !defined(__WROUTE_H__)
105 #if !defined(__BSSDB_H__)
108 #if !defined(__HOSTAP_H__)
111 #if !defined(__WPACTL_H__)
114 #if !defined(__IOCTL_H__)
117 #if !defined(__IWCTL_H__)
120 #if !defined(__DPC_H__)
123 #if !defined(__DATARATE_H__)
124 #include "datarate.h"
126 #if !defined(__RF_H__)
129 #if !defined(__IOWPA_H__)
133 #include <linux/delay.h>
134 #include <linux/kthread.h>
135 // #ifdef PRIVATE_OBJ
136 //#if !defined(__DEVICE_EXP_H)
137 //#include "device_exp.h"
139 //#if !defined(__DEVICE_MODULE_H)
140 //#include "device_module.h"
146 /*--------------------- Static Definitions -------------------------*/
147 //static int msglevel =MSG_LEVEL_DEBUG;
148 static int msglevel = MSG_LEVEL_INFO;
150 //#define PLICE_DEBUG
152 // Define module options
155 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
156 MODULE_LICENSE("GPL");
157 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
161 static int mlme_kill;
162 //static struct task_struct * mlme_task;
165 #define DEVICE_PARAM(N,D)
167 static const int N[MAX_UINTS]=OPTION_DEFAULT;\
168 MODULE_PARM(N, "1-" __MODULE_STRING(MAX_UINTS) "i");\
169 MODULE_PARM_DESC(N, D);
172 #define RX_DESC_MIN0 16
173 #define RX_DESC_MAX0 128
174 #define RX_DESC_DEF0 32
175 DEVICE_PARAM(RxDescriptors0,"Number of receive descriptors0");
177 #define RX_DESC_MIN1 16
178 #define RX_DESC_MAX1 128
179 #define RX_DESC_DEF1 32
180 DEVICE_PARAM(RxDescriptors1,"Number of receive descriptors1");
182 #define TX_DESC_MIN0 16
183 #define TX_DESC_MAX0 128
184 #define TX_DESC_DEF0 32
185 DEVICE_PARAM(TxDescriptors0,"Number of transmit descriptors0");
187 #define TX_DESC_MIN1 16
188 #define TX_DESC_MAX1 128
189 #define TX_DESC_DEF1 64
190 DEVICE_PARAM(TxDescriptors1,"Number of transmit descriptors1");
193 #define IP_ALIG_DEF 0
194 /* IP_byte_align[] is used for IP header DWORD byte aligned
195 0: indicate the IP header won't be DWORD byte aligned.(Default) .
196 1: indicate the IP header will be DWORD byte aligned.
197 In some enviroment, the IP header should be DWORD byte aligned,
198 or the packet will be droped when we receive it. (eg: IPVS)
200 DEVICE_PARAM(IP_byte_align,"Enable IP header dword aligned");
203 #define INT_WORKS_DEF 20
204 #define INT_WORKS_MIN 10
205 #define INT_WORKS_MAX 64
207 DEVICE_PARAM(int_works,"Number of packets per interrupt services");
209 #define CHANNEL_MIN 1
210 #define CHANNEL_MAX 14
211 #define CHANNEL_DEF 6
213 DEVICE_PARAM(Channel, "Channel number");
216 /* PreambleType[] is the preamble length used for transmit.
217 0: indicate allows long preamble type
218 1: indicate allows short preamble type
221 #define PREAMBLE_TYPE_DEF 1
223 DEVICE_PARAM(PreambleType, "Preamble Type");
226 #define RTS_THRESH_MIN 512
227 #define RTS_THRESH_MAX 2347
228 #define RTS_THRESH_DEF 2347
230 DEVICE_PARAM(RTSThreshold, "RTS threshold");
233 #define FRAG_THRESH_MIN 256
234 #define FRAG_THRESH_MAX 2346
235 #define FRAG_THRESH_DEF 2346
237 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
240 #define DATA_RATE_MIN 0
241 #define DATA_RATE_MAX 13
242 #define DATA_RATE_DEF 13
244 0: indicate 1 Mbps 0x02
245 1: indicate 2 Mbps 0x04
246 2: indicate 5.5 Mbps 0x0B
247 3: indicate 11 Mbps 0x16
248 4: indicate 6 Mbps 0x0c
249 5: indicate 9 Mbps 0x12
250 6: indicate 12 Mbps 0x18
251 7: indicate 18 Mbps 0x24
252 8: indicate 24 Mbps 0x30
253 9: indicate 36 Mbps 0x48
254 10: indicate 48 Mbps 0x60
255 11: indicate 54 Mbps 0x6c
256 12: indicate 72 Mbps 0x90
257 13: indicate auto rate
260 DEVICE_PARAM(ConnectionRate, "Connection data rate");
262 #define OP_MODE_DEF 0
264 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
266 /* OpMode[] is used for transmit.
267 0: indicate infrastruct mode used
268 1: indicate adhoc mode used
269 2: indicate AP mode used
274 0: indicate disable power saving mode
275 1: indicate enable power saving mode
278 #define PS_MODE_DEF 0
280 DEVICE_PARAM(PSMode, "Power saving mode");
283 #define SHORT_RETRY_MIN 0
284 #define SHORT_RETRY_MAX 31
285 #define SHORT_RETRY_DEF 8
288 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
290 #define LONG_RETRY_MIN 0
291 #define LONG_RETRY_MAX 15
292 #define LONG_RETRY_DEF 4
295 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
298 /* BasebandType[] baseband type selected
299 0: indicate 802.11a type
300 1: indicate 802.11b type
301 2: indicate 802.11g type
303 #define BBP_TYPE_MIN 0
304 #define BBP_TYPE_MAX 2
305 #define BBP_TYPE_DEF 2
307 DEVICE_PARAM(BasebandType, "baseband type");
312 0: indicate disable 802.11h
313 1: indicate enable 802.11h
316 #define X80211h_MODE_DEF 0
318 DEVICE_PARAM(b80211hEnable, "802.11h mode");
321 0: indicate disable 802.11h
322 1: indicate enable 802.11h
325 #define DIVERSITY_ANT_DEF 0
327 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
331 // Static vars definitions
336 static int device_nics =0;
337 static PSDevice pDevice_Infos =NULL;
338 static struct net_device *root_device_dev = NULL;
340 static CHIP_INFO chip_info_table[]= {
341 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
342 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
346 static struct pci_device_id device_id_table[] __devinitdata = {
347 { 0x1106, 0x3253, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (int)&chip_info_table[0]},
352 /*--------------------- Static Functions --------------------------*/
356 static int device_found1(struct pci_dev *pcid, const struct pci_device_id *ent);
357 static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice, PCHIP_INFO);
358 static void device_free_info(PSDevice pDevice);
359 static BOOL device_get_pci_info(PSDevice, struct pci_dev* pcid);
360 static void device_print_info(PSDevice pDevice);
361 static struct net_device_stats *device_get_stats(struct net_device *dev);
362 static void device_init_diversity_timer(PSDevice pDevice);
363 static int device_open(struct net_device *dev);
364 static int device_xmit(struct sk_buff *skb, struct net_device *dev);
365 static irqreturn_t device_intr(int irq, void*dev_instance);
366 static void device_set_multi(struct net_device *dev);
367 static int device_close(struct net_device *dev);
368 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
370 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
372 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
373 static int viawget_suspend(struct pci_dev *pcid, u32 state);
374 static int viawget_resume(struct pci_dev *pcid);
375 struct notifier_block device_notifier = {
376 notifier_call: device_notify_reboot,
383 #endif // #ifndef PRIVATE_OBJ
385 static void device_init_rd0_ring(PSDevice pDevice);
386 static void device_init_rd1_ring(PSDevice pDevice);
387 static void device_init_defrag_cb(PSDevice pDevice);
388 static void device_init_td0_ring(PSDevice pDevice);
389 static void device_init_td1_ring(PSDevice pDevice);
392 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
394 //2008-0714<Add>by Mike Liu
395 static BOOL device_release_WPADEV(PSDevice pDevice);
397 static int ethtool_ioctl(struct net_device *dev, void *useraddr);
398 static int device_rx_srv(PSDevice pDevice, UINT uIdx);
399 static int device_tx_srv(PSDevice pDevice, UINT uIdx);
400 static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pDesc);
401 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
402 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc);
403 static void device_free_td0_ring(PSDevice pDevice);
404 static void device_free_td1_ring(PSDevice pDevice);
405 static void device_free_rd0_ring(PSDevice pDevice);
406 static void device_free_rd1_ring(PSDevice pDevice);
407 static void device_free_rings(PSDevice pDevice);
408 static void device_free_frag_buf(PSDevice pDevice);
409 static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source);
412 /*--------------------- Export Variables --------------------------*/
414 /*--------------------- Export Functions --------------------------*/
419 static char* get_chip_name(int chip_id) {
421 for (i=0;chip_info_table[i].name!=NULL;i++)
422 if (chip_info_table[i].chip_id==chip_id)
424 return chip_info_table[i].name;
427 static void __devexit device_remove1(struct pci_dev *pcid)
429 PSDevice pDevice=pci_get_drvdata(pcid);
433 device_free_info(pDevice);
440 device_set_int_opt(int *opt, int val, int min, int max, int def,char* name,char* devname) {
443 else if (val<min || val>max) {
444 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n" ,
445 devname,name, min,max);
448 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n",
455 device_set_bool_opt(PU32 opt, int val,BOOL def,U32 flag, char* name,char* devname) {
458 *opt|=(def ? flag : 0);
459 else if (val<0 || val>1) {
460 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE
461 "%s: the value of parameter %s is invalid, the valid range is (0-1)\n",devname,name);
462 *opt|=(def ? flag : 0);
464 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: set parameter %s to %s\n",
465 devname,name , val ? "TRUE" : "FALSE");
466 *opt|=(val ? flag : 0);
471 device_get_options(PSDevice pDevice, int index, char* devname) {
473 POPTIONS pOpts = &(pDevice->sOpts);
474 pOpts->nRxDescs0=RX_DESC_DEF0;
475 pOpts->nRxDescs1=RX_DESC_DEF1;
476 pOpts->nTxDescs[0]=TX_DESC_DEF0;
477 pOpts->nTxDescs[1]=TX_DESC_DEF1;
478 pOpts->flags|=DEVICE_FLAGS_IP_ALIGN;
479 pOpts->int_works=INT_WORKS_DEF;
480 pOpts->rts_thresh=RTS_THRESH_DEF;
481 pOpts->frag_thresh=FRAG_THRESH_DEF;
482 pOpts->data_rate=DATA_RATE_DEF;
483 pOpts->channel_num=CHANNEL_DEF;
485 pOpts->flags|=DEVICE_FLAGS_PREAMBLE_TYPE;
486 pOpts->flags|=DEVICE_FLAGS_OP_MODE;
487 //pOpts->flags|=DEVICE_FLAGS_PS_MODE;
488 pOpts->short_retry=SHORT_RETRY_DEF;
489 pOpts->long_retry=LONG_RETRY_DEF;
490 pOpts->bbp_type=BBP_TYPE_DEF;
491 pOpts->flags|=DEVICE_FLAGS_80211h_MODE;
492 pOpts->flags|=DEVICE_FLAGS_DiversityANT;
498 device_set_options(PSDevice pDevice) {
500 BYTE abyBroadcastAddr[U_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
501 BYTE abySNAP_RFC1042[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
502 BYTE abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
505 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, U_ETHER_ADDR_LEN);
506 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, U_ETHER_ADDR_LEN);
507 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, U_ETHER_ADDR_LEN);
509 pDevice->uChannel = pDevice->sOpts.channel_num;
510 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
511 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
512 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
513 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
514 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
515 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
516 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
517 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
518 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
519 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
520 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
521 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE;
522 pDevice->byBBType = pDevice->sOpts.bbp_type;
523 pDevice->byPacketType = pDevice->byBBType;
526 pDevice->byAutoFBCtrl = AUTO_FB_0;
527 //pDevice->byAutoFBCtrl = AUTO_FB_1;
529 pDevice->bUpdateBBVGA = TRUE;
530 pDevice->byFOETuning = 0;
531 pDevice->wCTSDuration = 0;
532 pDevice->byPreambleType = 0;
535 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uChannel= %d\n",(INT)pDevice->uChannel);
536 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byOpMode= %d\n",(INT)pDevice->byOpMode);
537 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ePSMode= %d\n",(INT)pDevice->ePSMode);
538 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" wRTSThreshold= %d\n",(INT)pDevice->wRTSThreshold);
539 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortRetryLimit= %d\n",(INT)pDevice->byShortRetryLimit);
540 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byLongRetryLimit= %d\n",(INT)pDevice->byLongRetryLimit);
541 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byPreambleType= %d\n",(INT)pDevice->byPreambleType);
542 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortPreamble= %d\n",(INT)pDevice->byShortPreamble);
543 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uConnectionRate= %d\n",(INT)pDevice->uConnectionRate);
544 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byBBType= %d\n",(INT)pDevice->byBBType);
545 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->b11hEnable= %d\n",(INT)pDevice->b11hEnable);
546 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->bDiversityRegCtlON= %d\n",(INT)pDevice->bDiversityRegCtlON);
549 static VOID s_vCompleteCurrentMeasure (IN PSDevice pDevice, IN BYTE byResult)
552 DWORD dwDuration = 0;
555 for(ii=1;ii<8;ii++) {
556 pDevice->dwRPIs[ii] *= 255;
557 dwDuration |= *((PWORD) (pDevice->pCurrMeasureEID->sReq.abyDuration));
559 pDevice->dwRPIs[ii] /= dwDuration;
560 pDevice->abyRPIs[ii] = (BYTE) pDevice->dwRPIs[ii];
561 byRPI0 += pDevice->abyRPIs[ii];
563 pDevice->abyRPIs[0] = (0xFF - byRPI0);
565 if (pDevice->uNumOfMeasureEIDs == 0) {
566 VNTWIFIbMeasureReport( pDevice->pMgmt,
568 pDevice->pCurrMeasureEID,
571 pDevice->byCCAFraction,
575 VNTWIFIbMeasureReport( pDevice->pMgmt,
577 pDevice->pCurrMeasureEID,
580 pDevice->byCCAFraction,
583 CARDbStartMeasure (pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
591 // Initialiation of MAC & BBP registers
594 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
599 BYTE byCCKPwrdBm = 0;
600 BYTE byOFDMPwrdBm = 0;
602 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
603 MACbShutdown(pDevice->PortOffset);
604 BBvSoftwareReset(pDevice->PortOffset);
606 if ((InitType == DEVICE_INIT_COLD) ||
607 (InitType == DEVICE_INIT_DXPL)) {
608 // Do MACbSoftwareReset in MACvInitialize
609 MACbSoftwareReset(pDevice->PortOffset);
611 pDevice->bCCK = TRUE;
612 pDevice->bAES = FALSE;
613 pDevice->bProtectMode = FALSE; //Only used in 11g type, sync with ERP IE
614 pDevice->bNonERPPresent = FALSE;
615 pDevice->bBarkerPreambleMd = FALSE;
616 pDevice->wCurrentRate = RATE_1M;
617 pDevice->byTopOFDMBasicRate = RATE_24M;
618 pDevice->byTopCCKBasicRate = RATE_1M;
620 pDevice->byRevId = 0; //Target to IF pin while programming to RF chip.
623 MACvInitialize(pDevice->PortOffset);
626 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
628 spin_lock_irq(&pDevice->lock);
629 SROMvReadAllContents(pDevice->PortOffset,pDevice->abyEEPROM);
631 spin_unlock_irq(&pDevice->lock);
635 pDevice->byMinChannel = 1;
636 pDevice->byMaxChannel = CB_MAX_CHANNEL;
639 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
640 if (byValue & EEP_ANTINV)
641 pDevice->bTxRxAntInv = TRUE;
643 pDevice->bTxRxAntInv = FALSE;
645 //printk("init_register:TxRxAntInv is %d,byValue is %d\n",pDevice->bTxRxAntInv,byValue);
648 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
649 if (byValue == 0) // if not set default is All
650 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
652 //printk("init_register:byValue is %d\n",byValue);
654 pDevice->ulDiversityNValue = 100*260;//100*SROMbyReadEmbedded(pDevice->PortOffset, 0x51);
655 pDevice->ulDiversityMValue = 100*16;//SROMbyReadEmbedded(pDevice->PortOffset, 0x52);
656 pDevice->byTMax = 1;//SROMbyReadEmbedded(pDevice->PortOffset, 0x53);
657 pDevice->byTMax2 = 4;//SROMbyReadEmbedded(pDevice->PortOffset, 0x54);
658 pDevice->ulSQ3TH = 0;//(ULONG) SROMbyReadEmbedded(pDevice->PortOffset, 0x55);
659 pDevice->byTMax3 = 64;//SROMbyReadEmbedded(pDevice->PortOffset, 0x56);
661 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
662 pDevice->byAntennaCount = 2;
663 pDevice->byTxAntennaMode = ANT_B;
664 pDevice->dwTxAntennaSel = 1;
665 pDevice->dwRxAntennaSel = 1;
666 if (pDevice->bTxRxAntInv == TRUE)
667 pDevice->byRxAntennaMode = ANT_A;
669 pDevice->byRxAntennaMode = ANT_B;
670 // chester for antenna
671 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
672 // if (pDevice->bDiversityRegCtlON)
673 if((byValue1&0x08)==0)
674 pDevice->bDiversityEnable = FALSE;//SROMbyReadEmbedded(pDevice->PortOffset, 0x50);
676 pDevice->bDiversityEnable = TRUE;
678 //printk("aux |main antenna: RxAntennaMode is %d\n",pDevice->byRxAntennaMode);
681 pDevice->bDiversityEnable = FALSE;
682 pDevice->byAntennaCount = 1;
683 pDevice->dwTxAntennaSel = 0;
684 pDevice->dwRxAntennaSel = 0;
685 if (byValue & EEP_ANTENNA_AUX) {
686 pDevice->byTxAntennaMode = ANT_A;
687 if (pDevice->bTxRxAntInv == TRUE)
688 pDevice->byRxAntennaMode = ANT_B;
690 pDevice->byRxAntennaMode = ANT_A;
692 pDevice->byTxAntennaMode = ANT_B;
693 if (pDevice->bTxRxAntInv == TRUE)
694 pDevice->byRxAntennaMode = ANT_A;
696 pDevice->byRxAntennaMode = ANT_B;
700 //printk("init registers: TxAntennaMode is %d\n",pDevice->byTxAntennaMode);
702 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
703 pDevice->bDiversityEnable,(int)pDevice->ulDiversityNValue,(int)pDevice->ulDiversityMValue,pDevice->byTMax,pDevice->byTMax2);
705 //#ifdef ZoneType_DefaultSetting
706 //2008-8-4 <add> by chester
708 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
709 if((zonetype=Config_FileOperation(pDevice,FALSE,NULL)) >= 0) { //read zonetype file ok!
710 if ((zonetype == 0)&&
711 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] !=0x00)){ //for USA
712 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
713 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
714 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :USA\n");
716 else if((zonetype == 1)&&
717 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x01)){ //for Japan
718 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
719 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
721 else if((zonetype == 2)&&
722 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x02)){ //for Europe
723 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
724 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
725 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :Europe\n");
730 if(zonetype!=pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
731 printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",zonetype,pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
733 printk("Read Zonetype file sucess,use default zonetype setting[%02x]\n",zonetype);
737 printk("Read Zonetype file fail,use default zonetype setting[%02x]\n",SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
740 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
742 if ((pDevice->byRFType & RF_EMU) != 0) {
743 // force change RevID for VT3253 emu
744 pDevice->byRevId = 0x80;
747 pDevice->byRFType &= RF_MASK;
748 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
750 if (pDevice->bZoneRegExist == FALSE) {
751 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
753 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
758 //Get Desire Power Value
759 pDevice->byCurPwr = 0xFF;
760 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
761 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
762 //byCCKPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_CCK_PWR_dBm);
764 //byOFDMPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_OFDM_PWR_dBm);
765 //printk("CCKPwrdBm is 0x%x,byOFDMPwrdBm is 0x%x\n",byCCKPwrdBm,byOFDMPwrdBm);
769 for (ii=0;ii<CB_MAX_CHANNEL_24G;ii++) {
770 pDevice->abyCCKPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_CCK_PWR_TBL));
771 if (pDevice->abyCCKPwrTbl[ii+1] == 0) {
772 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
774 pDevice->abyOFDMPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDM_PWR_TBL));
775 if (pDevice->abyOFDMPwrTbl[ii+1] == 0) {
776 pDevice->abyOFDMPwrTbl[ii+1] = pDevice->byOFDMPwrG;
778 pDevice->abyCCKDefaultPwr[ii+1] = byCCKPwrdBm;
779 pDevice->abyOFDMDefaultPwr[ii+1] = byOFDMPwrdBm;
781 //2008-8-4 <add> by chester
782 //recover 12,13 ,14channel for EUROPE by 11 channel
783 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
784 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
785 (pDevice->byOriginalZonetype == ZoneType_USA)) {
786 for(ii=11;ii<14;ii++) {
787 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
788 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
794 // Load OFDM A Power Table
795 for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
796 pDevice->abyOFDMPwrTbl[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_TBL));
797 pDevice->abyOFDMDefaultPwr[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_dBm));
799 CARDvInitChannelTable((PVOID)pDevice);
802 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
803 MACvSelectPage1(pDevice->PortOffset);
804 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
805 MACvSelectPage0(pDevice->PortOffset);
809 // use relative tx timeout and 802.11i D4
810 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
812 // set performance parameter by registry
813 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
814 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
817 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
818 // enable TSF counter
819 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
821 // initialize BBP registers
822 BBbVT3253Init(pDevice);
824 if (pDevice->bUpdateBBVGA) {
825 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
826 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
827 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
830 //printk("init registers:RxAntennaMode is %x,TxAntennaMode is %x\n",pDevice->byRxAntennaMode,pDevice->byTxAntennaMode);
832 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
833 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
835 pDevice->byCurrentCh = 0;
837 //pDevice->NetworkType = Ndis802_11Automode;
838 // Set BB and packet type at the same time.
839 // Set Short Slot Time, xIFS, and RSPINF.
840 if (pDevice->uConnectionRate == RATE_AUTO) {
841 pDevice->wCurrentRate = RATE_54M;
843 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
847 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
848 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
850 pDevice->bRadioOff = FALSE;
852 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
853 pDevice->bHWRadioOff = FALSE;
855 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
857 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
858 //2008-4-14 <add> by chester for led issue
859 #ifdef FOR_LED_ON_NOTEBOOK
860 if (BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA)){pDevice->bHWRadioOff = TRUE;}
861 if (BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA)){pDevice->bHWRadioOff = FALSE;}
864 if ( (pDevice->bRadioControlOff == TRUE)) {
865 CARDbRadioPowerOff(pDevice);
867 else CARDbRadioPowerOn(pDevice);
869 if ((BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOff(pDevice->byRadioCtl, EEP_RADIOCTL_INV)) ||
870 (BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOn(pDevice->byRadioCtl, EEP_RADIOCTL_INV))) {
871 pDevice->bHWRadioOff = TRUE;
874 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
875 CARDbRadioPowerOff(pDevice);
880 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
881 // get Permanent network address
882 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
883 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %02x-%02x-%02x=%02x-%02x-%02x\n",
884 pDevice->abyCurrentNetAddr[0],
885 pDevice->abyCurrentNetAddr[1],
886 pDevice->abyCurrentNetAddr[2],
887 pDevice->abyCurrentNetAddr[3],
888 pDevice->abyCurrentNetAddr[4],
889 pDevice->abyCurrentNetAddr[5]);
893 CARDvSafeResetRx(pDevice);
895 CARDvSafeResetTx(pDevice);
897 if (pDevice->byLocalID <= REV_ID_VT3253_A1) {
898 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
901 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
904 MACvReceive0(pDevice->PortOffset);
905 MACvReceive1(pDevice->PortOffset);
908 MACvStart(pDevice->PortOffset);
910 netif_stop_queue(pDevice->dev);
917 static VOID device_init_diversity_timer(PSDevice pDevice) {
919 init_timer(&pDevice->TimerSQ3Tmax1);
920 pDevice->TimerSQ3Tmax1.data = (ULONG)pDevice;
921 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
922 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
924 init_timer(&pDevice->TimerSQ3Tmax2);
925 pDevice->TimerSQ3Tmax2.data = (ULONG)pDevice;
926 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
927 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
929 init_timer(&pDevice->TimerSQ3Tmax3);
930 pDevice->TimerSQ3Tmax3.data = (ULONG)pDevice;
931 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
932 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
938 static BOOL device_release_WPADEV(PSDevice pDevice)
940 viawget_wpa_header *wpahdr;
942 // wait_queue_head_t Set_wait;
943 //send device close to wpa_supplicnat layer
944 if (pDevice->bWPADEVUp==TRUE) {
945 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
946 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
947 wpahdr->resp_ie_len = 0;
948 wpahdr->req_ie_len = 0;
949 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
950 pDevice->skb->dev = pDevice->wpadev;
951 //2008-4-3 modify by Chester for wpa
952 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
953 pDevice->skb->mac_header = pDevice->skb->data;
955 pDevice->skb->mac.raw = pDevice->skb->data;
957 pDevice->skb->pkt_type = PACKET_HOST;
958 pDevice->skb->protocol = htons(ETH_P_802_2);
959 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
960 netif_rx(pDevice->skb);
961 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
963 //wait release WPADEV
964 // init_waitqueue_head(&Set_wait);
965 // wait_event_timeout(Set_wait, ((pDevice->wpadev==NULL)&&(pDevice->skb == NULL)),5*HZ); //1s wait
966 while((pDevice->bWPADEVUp==TRUE)) {
967 set_current_state(TASK_UNINTERRUPTIBLE);
968 schedule_timeout (HZ/20); //wait 50ms
981 device_found1(struct pci_dev *pcid, const struct pci_device_id *ent)
983 static BOOL bFirst = TRUE;
984 struct net_device* dev = NULL;
985 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
987 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
990 //#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
991 // BYTE fake_mac[U_ETHER_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x01};//fake MAC address
993 if (device_nics ++>= MAX_UINTS) {
994 printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
999 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1000 dev = alloc_etherdev(sizeof(DEVICE_INFO));
1002 dev = init_etherdev(dev, 0);
1005 pDevice = (PSDevice) netdev_priv(dev);
1008 printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
1012 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1013 // Chain it all together
1014 // SET_MODULE_OWNER(dev);
1015 SET_NETDEV_DEV(dev, &pcid->dev);
1019 printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1020 printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
1024 if (!device_init_info(pcid, &pDevice, pChip_info)) {
1028 pDevice->next_module = root_device_dev;
1029 root_device_dev = dev;
1030 dev->irq = pcid->irq;
1032 if (pci_enable_device(pcid)) {
1033 device_free_info(pDevice);
1037 printk("Before get pci_info memaddr is %x\n",pDevice->memaddr);
1039 if (device_get_pci_info(pDevice,pcid) == FALSE) {
1040 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
1041 device_free_info(pDevice);
1049 //pci_read_config_byte(pcid, PCI_BASE_ADDRESS_0, &pDevice->byRevId);
1050 printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",pDevice->memaddr,pDevice->ioaddr,pDevice->io_size);
1062 for (i=0;address[i];i++)
1064 //pci_write_config_dword(pcid,address[i], 0xFFFFFFFF);
1065 pci_read_config_dword(pcid, address[i], &bar);
1066 printk("bar %d is %x\n",i,bar);
1069 printk("bar %d not implemented\n",i);
1072 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
1075 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
1076 len = len & ~(len - 1);
1078 printk("IO space: len in IO %x, BAR %d\n", len, i);
1082 len = bar & 0xFFFFFFF0;
1085 printk("len in MEM %x, BAR %d\n", len, i);
1097 pDevice->PortOffset = (DWORD)ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
1098 //pDevice->PortOffset = (DWORD)ioremap(pDevice->ioaddr & PCI_BASE_ADDRESS_IO_MASK, pDevice->io_size);
1100 if(pDevice->PortOffset == 0) {
1101 printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
1102 device_free_info(pDevice);
1109 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1110 rc = pci_request_regions(pcid, DEVICE_NAME);
1112 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
1113 device_free_info(pDevice);
1117 if (check_region(pDevice->ioaddr, pDevice->io_size)) {
1118 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
1119 device_free_info(pDevice);
1122 request_region(pDevice->ioaddr, pDevice->io_size, DEVICE_NAME);
1125 dev->base_addr = pDevice->ioaddr;
1129 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1130 printk("Before write: value is %x\n",value);
1131 //VNSvInPortB(pDevice->PortOffset+0x3F, 0x00);
1132 VNSvOutPortB(pDevice->PortOffset,value);
1133 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1134 printk("After write: value is %x\n",value);
1140 pDevice->PortOffset = pDevice->ioaddr;
1143 if (!MACbSoftwareReset(pDevice->PortOffset)) {
1144 printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
1145 device_free_info(pDevice);
1148 // initial to reload eeprom
1149 MACvInitialize(pDevice->PortOffset);
1150 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
1152 device_get_options(pDevice, device_nics-1, dev->name);
1153 device_set_options(pDevice);
1154 //Mask out the options cannot be set to the chip
1155 pDevice->sOpts.flags &= pChip_info->flags;
1157 //Enable the chip specified capbilities
1158 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
1159 pDevice->tx_80211 = device_dma0_tx_80211;
1160 pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;
1161 pDevice->pMgmt = &(pDevice->sMgmtObj);
1163 dev->irq = pcid->irq;
1164 dev->open = device_open;
1165 dev->hard_start_xmit = device_xmit;
1166 dev->stop = device_close;
1167 dev->get_stats = device_get_stats;
1168 dev->set_multicast_list = device_set_multi;
1169 dev->do_ioctl = device_ioctl;
1172 //Einsn Modify for ubuntu-7.04
1173 // dev->wireless_handlers->get_wireless_stats = iwctl_get_wireless_stats;
1174 #if WIRELESS_EXT > 12
1175 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
1176 // netdev->wireless_handlers = NULL;
1177 #endif /* WIRELESS_EXT > 12 */
1178 #endif /* WIRELESS_EXT */
1180 // #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
1181 // memcpy(pDevice->dev->dev_addr, fake_mac, U_ETHER_ADDR_LEN); //use fake mac address
1183 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1184 rc = register_netdev(dev);
1187 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
1188 device_free_info(pDevice);
1192 //2008-07-21-01<Add>by MikeLiu
1194 if(wpa_set_wpadev(pDevice, 1)!=0) {
1195 printk("Fail to Register WPADEV?\n");
1196 unregister_netdev(pDevice->dev);
1199 device_print_info(pDevice);
1200 pci_set_drvdata(pcid, pDevice);
1205 static void device_print_info(PSDevice pDevice)
1207 struct net_device* dev=pDevice->dev;
1209 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n",dev->name, get_chip_name(pDevice->chip_id));
1210 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
1212 dev->dev_addr[0],dev->dev_addr[1],dev->dev_addr[2],
1213 dev->dev_addr[3],dev->dev_addr[4],dev->dev_addr[5]);
1215 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx ",(ULONG) pDevice->ioaddr);
1216 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1218 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx Mem=0x%lx ",(ULONG) pDevice->ioaddr,(ULONG) pDevice->PortOffset);
1219 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1224 static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice,
1225 PCHIP_INFO pChip_info) {
1229 memset(*ppDevice,0,sizeof(DEVICE_INFO));
1231 if (pDevice_Infos == NULL) {
1232 pDevice_Infos =*ppDevice;
1235 for (p=pDevice_Infos;p->next!=NULL;p=p->next)
1237 p->next = *ppDevice;
1238 (*ppDevice)->prev = p;
1241 (*ppDevice)->pcid = pcid;
1242 (*ppDevice)->chip_id = pChip_info->chip_id;
1243 (*ppDevice)->io_size = pChip_info->io_size;
1244 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
1245 (*ppDevice)->multicast_limit =32;
1247 spin_lock_init(&((*ppDevice)->lock));
1252 static BOOL device_get_pci_info(PSDevice pDevice, struct pci_dev* pcid) {
1258 BYTE pci_config[256];
1262 memset(pci_config,0x00,256);
1265 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
1266 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID,&pDevice->SubSystemID);
1267 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
1268 pci_read_config_word(pcid, PCI_COMMAND, (u16 *) & (pci_cmd));
1270 pci_set_master(pcid);
1272 pDevice->memaddr = pci_resource_start(pcid,0);
1273 pDevice->ioaddr = pci_resource_start(pcid,1);
1276 // pDevice->ioaddr = pci_resource_start(pcid, 0);
1277 // pDevice->memaddr = pci_resource_start(pcid,1);
1280 cis_addr = pci_resource_start(pcid,2);
1282 pDevice->pcid = pcid;
1284 pci_read_config_byte(pcid, PCI_REG_COMMAND, &b);
1285 pci_write_config_byte(pcid, PCI_REG_COMMAND, (b|COMMAND_BUSM));
1288 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1289 //printk("max lat is %x,SubSystemID is %x\n",max_lat,pDevice->SubSystemID);
1290 //for (ii=0;ii<0xFF;ii++)
1291 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1293 //pci_write_config_word(pcid,PCI_REG_MAX_LAT,max_lat);
1294 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1295 //printk("max lat is %x\n",max_lat);
1297 for (ii=0;ii<0xFF;ii++)
1299 pci_read_config_byte(pcid,ii,&value);
1300 pci_config[ii] = value;
1302 for (ii=0,j=1;ii<0x100;ii++,j++)
1306 printk("%x:",pci_config[ii]);
1311 printk("%x:",pci_config[ii]);
1318 static void device_free_info(PSDevice pDevice) {
1320 struct net_device* dev=pDevice->dev;
1323 //2008-0714-01<Add>by chester
1324 device_release_WPADEV(pDevice);
1326 //2008-07-21-01<Add>by MikeLiu
1328 if(wpa_set_wpadev(pDevice, 0)!=0)
1329 printk("unregister wpadev fail?\n");
1331 if (pDevice_Infos==NULL)
1334 for (ptr=pDevice_Infos;ptr && (ptr!=pDevice);ptr=ptr->next)
1338 if (ptr==pDevice_Infos)
1339 pDevice_Infos=ptr->next;
1341 ptr->prev->next=ptr->next;
1344 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
1349 hostap_set_hostapd(pDevice, 0, 0);
1352 unregister_netdev(dev);
1354 if (pDevice->PortOffset)
1355 iounmap((PVOID)pDevice->PortOffset);
1357 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
1359 pci_release_regions(pDevice->pcid);
1363 if (pDevice->ioaddr)
1364 release_region(pDevice->ioaddr,pDevice->io_size);
1369 if (pDevice->pcid) {
1370 pci_set_drvdata(pDevice->pcid,NULL);
1373 #endif// ifndef PRIVATE_OBJ
1375 static BOOL device_init_rings(PSDevice pDevice) {
1379 /*allocate all RD/TD rings a single pool*/
1380 vir_pool = pci_alloc_consistent(pDevice->pcid,
1381 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1382 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1383 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1384 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1385 &pDevice->pool_dma);
1387 if (vir_pool == NULL) {
1388 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
1393 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1394 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1395 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1396 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1399 pDevice->aRD0Ring = vir_pool;
1400 pDevice->aRD1Ring = vir_pool +
1401 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1404 pDevice->rd0_pool_dma = pDevice->pool_dma;
1405 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1406 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1408 pDevice->tx0_bufs = pci_alloc_consistent(pDevice->pcid,
1409 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1410 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1411 CB_BEACON_BUF_SIZE +
1413 &pDevice->tx_bufs_dma0);
1415 if (pDevice->tx0_bufs == NULL) {
1416 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
1417 pci_free_consistent(pDevice->pcid,
1418 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1419 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1420 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1421 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1422 vir_pool, pDevice->pool_dma
1427 memset(pDevice->tx0_bufs, 0,
1428 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1429 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1430 CB_BEACON_BUF_SIZE +
1434 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1435 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1437 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1438 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1441 // vir_pool: pvoid type
1442 pDevice->apTD0Rings = vir_pool
1443 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1444 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1446 pDevice->apTD1Rings = vir_pool
1447 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1448 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1449 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1452 pDevice->tx1_bufs = pDevice->tx0_bufs +
1453 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1456 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1457 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1459 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1462 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1463 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1466 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1467 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1473 static void device_free_rings(PSDevice pDevice) {
1475 pci_free_consistent(pDevice->pcid,
1476 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1477 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1478 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1479 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1481 pDevice->aRD0Ring, pDevice->pool_dma
1484 if (pDevice->tx0_bufs)
1485 pci_free_consistent(pDevice->pcid,
1486 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1487 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1488 CB_BEACON_BUF_SIZE +
1490 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1494 static void device_init_rd0_ring(PSDevice pDevice) {
1496 dma_addr_t curr = pDevice->rd0_pool_dma;
1499 /* Init the RD0 ring entries */
1500 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1501 pDesc = &(pDevice->aRD0Ring[i]);
1502 pDesc->pRDInfo = alloc_rd_info();
1503 ASSERT(pDesc->pRDInfo);
1504 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1505 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1506 pDevice->dev->name);
1508 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1509 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1510 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1513 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1514 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1518 static void device_init_rd1_ring(PSDevice pDevice) {
1520 dma_addr_t curr = pDevice->rd1_pool_dma;
1523 /* Init the RD1 ring entries */
1524 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1525 pDesc = &(pDevice->aRD1Ring[i]);
1526 pDesc->pRDInfo = alloc_rd_info();
1527 ASSERT(pDesc->pRDInfo);
1528 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1529 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1530 pDevice->dev->name);
1532 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1533 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1534 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1537 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1538 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1542 static void device_init_defrag_cb(PSDevice pDevice) {
1544 PSDeFragControlBlock pDeF;
1546 /* Init the fragment ctl entries */
1547 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1548 pDeF = &(pDevice->sRxDFCB[i]);
1549 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1550 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
1551 pDevice->dev->name);
1554 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1555 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1561 static void device_free_rd0_ring(PSDevice pDevice) {
1564 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1565 PSRxDesc pDesc =&(pDevice->aRD0Ring[i]);
1566 PDEVICE_RD_INFO pRDInfo =pDesc->pRDInfo;
1568 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1569 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1571 dev_kfree_skb(pRDInfo->skb);
1573 kfree((PVOID)pDesc->pRDInfo);
1578 static void device_free_rd1_ring(PSDevice pDevice) {
1582 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1583 PSRxDesc pDesc=&(pDevice->aRD1Ring[i]);
1584 PDEVICE_RD_INFO pRDInfo=pDesc->pRDInfo;
1586 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1587 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1589 dev_kfree_skb(pRDInfo->skb);
1591 kfree((PVOID)pDesc->pRDInfo);
1596 static void device_free_frag_buf(PSDevice pDevice) {
1597 PSDeFragControlBlock pDeF;
1600 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1602 pDeF = &(pDevice->sRxDFCB[i]);
1605 dev_kfree_skb(pDeF->skb);
1611 static void device_init_td0_ring(PSDevice pDevice) {
1616 curr = pDevice->td0_pool_dma;
1617 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1618 pDesc = &(pDevice->apTD0Rings[i]);
1619 pDesc->pTDInfo = alloc_td_info();
1620 ASSERT(pDesc->pTDInfo);
1621 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1622 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1623 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1625 pDesc->next =&(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1626 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1627 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1630 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1631 pDevice->apTailTD[0] = pDevice->apCurrTD[0] =&(pDevice->apTD0Rings[0]);
1635 static void device_init_td1_ring(PSDevice pDevice) {
1640 /* Init the TD ring entries */
1641 curr=pDevice->td1_pool_dma;
1642 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr+=sizeof(STxDesc)) {
1643 pDesc=&(pDevice->apTD1Rings[i]);
1644 pDesc->pTDInfo = alloc_td_info();
1645 ASSERT(pDesc->pTDInfo);
1646 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1647 pDesc->pTDInfo->buf=pDevice->tx1_bufs+(i)*PKT_BUF_SZ;
1648 pDesc->pTDInfo->buf_dma=pDevice->tx_bufs_dma1+(i)*PKT_BUF_SZ;
1650 pDesc->next=&(pDevice->apTD1Rings[(i+1) % pDevice->sOpts.nTxDescs[1]]);
1651 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1652 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1655 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1656 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1661 static void device_free_td0_ring(PSDevice pDevice) {
1663 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1664 PSTxDesc pDesc=&(pDevice->apTD0Rings[i]);
1665 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1667 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1668 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,
1669 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1672 dev_kfree_skb(pTDInfo->skb);
1674 kfree((PVOID)pDesc->pTDInfo);
1678 static void device_free_td1_ring(PSDevice pDevice) {
1681 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1682 PSTxDesc pDesc=&(pDevice->apTD1Rings[i]);
1683 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1685 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1686 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1687 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1690 dev_kfree_skb(pTDInfo->skb);
1692 kfree((PVOID)pDesc->pTDInfo);
1699 /*-----------------------------------------------------------------*/
1701 static int device_rx_srv(PSDevice pDevice, UINT uIdx) {
1706 for (pRD = pDevice->pCurrRD[uIdx];
1707 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1709 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->pCurrRD = %x, works = %d\n", pRD, works);
1712 if (device_receive_frame(pDevice, pRD)) {
1713 if (!device_alloc_rx_buf(pDevice,pRD)) {
1714 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR
1715 "%s: can not allocate rx buf\n", pDevice->dev->name);
1719 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1721 ref_set_rx_jiffies(pDevice->dev);
1723 pDevice->dev->last_rx = jiffies;
1727 pDevice->pCurrRD[uIdx]=pRD;
1733 static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD) {
1735 PDEVICE_RD_INFO pRDInfo=pRD->pRDInfo;
1739 pRDInfo->skb=dev_alloc_skb(pDevice->rx_buf_sz);
1740 if (pRDInfo->skb==NULL)
1742 ref_skb_remap(pDevice->dev, &(pRDInfo->ref_skb), pRDInfo->skb);
1743 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, pRDInfo->ref_skb.tail, pDevice->rx_buf_sz,
1744 PCI_DMA_FROMDEVICE);
1747 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1749 //printk("device_alloc_rx_buf:skb is %x\n",pRDInfo->skb);
1751 if (pRDInfo->skb==NULL)
1753 ASSERT(pRDInfo->skb);
1754 pRDInfo->skb->dev = pDevice->dev;
1755 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, pRDInfo->skb->tail, pDevice->rx_buf_sz,
1756 PCI_DMA_FROMDEVICE);
1758 *((PU32) &(pRD->m_rd0RD0)) = 0;
1760 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1761 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1762 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1763 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1770 BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
1774 pDeF->skb=dev_alloc_skb(pDevice->rx_buf_sz);
1775 if (pDeF->skb==NULL)
1777 ref_skb_remap(pDevice->dev, &(pDeF->ref_skb), pDeF->skb);
1780 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1781 if (pDeF->skb == NULL)
1784 pDeF->skb->dev = pDevice->dev;
1792 static int device_tx_srv(PSDevice pDevice, UINT uIdx) {
1798 UINT uFrameSize, uFIFOHeaderSize;
1799 PSTxBufHead pTxBufHead;
1800 struct net_device_stats* pStats = &pDevice->stats;
1801 struct sk_buff* skb;
1803 PSMgmtObject pMgmt = pDevice->pMgmt;
1805 ref_sk_buff ref_skb;
1809 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] >0; pTD = pTD->next) {
1811 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1816 byTsr0 = pTD->m_td0TD0.byTSR0;
1817 byTsr1 = pTD->m_td0TD0.byTSR1;
1819 //Only the status of first TD in the chain is correct
1820 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1822 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1823 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1824 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1825 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1827 ref_skb_remap(pDevice->dev, &ref_skb, pTD->pTDInfo->skb);
1829 // Update the statistics based on the Transmit status
1830 // now, we DO'NT check TSR0_CDH
1832 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1834 (PBYTE)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1838 BSSvUpdateNodeTxCounter(pDevice,
1840 (PBYTE)(pTD->pTDInfo->buf),
1844 if (BITbIsBitOff(byTsr1, TSR1_TERR)) {
1846 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1847 (INT)uIdx, byTsr1, byTsr0);
1849 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG) {
1850 pDevice->s802_11Counter.TransmittedFragmentCount ++;
1852 pStats->tx_packets++;
1854 pStats->tx_bytes += *(ref_skb.len);
1856 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1860 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1861 (INT)uIdx, byTsr1, byTsr0);
1862 pStats->tx_errors++;
1863 pStats->tx_dropped++;
1867 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1868 if (pDevice->bEnableHostapd) {
1869 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif.. \n");
1871 ref_skb_remap(pDevice->apdev, &(ref_skb), pTD->pTDInfo->skb);
1872 ref_skb.mac.raw = ref_skb.data;
1873 *(ref_skb.pkt_type) = PACKET_OTHERHOST;
1874 //*(ref_skb.protocol) = htons(ETH_P_802_2);
1875 memset(ref_skb.cb, 0, sizeof(ref_skb.cb));
1876 netif_rx(ref_skb.skb);
1878 skb = pTD->pTDInfo->skb;
1879 skb->dev = pDevice->apdev;
1880 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
1881 skb->mac_header = skb->data;
1883 skb->mac.raw = skb->data;
1885 skb->pkt_type = PACKET_OTHERHOST;
1886 //skb->protocol = htons(ETH_P_802_2);
1887 memset(skb->cb, 0, sizeof(skb->cb));
1893 if (BITbIsBitOn(byTsr1, TSR1_TERR)) {
1894 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1895 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1896 (INT)uIdx, byTsr1, byTsr0);
1899 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1900 // (INT)uIdx, byTsr1, byTsr0);
1902 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1903 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1905 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1907 skb = pTD->pTDInfo->skb;
1908 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
1909 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1910 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1911 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1913 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1914 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1915 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1916 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1917 ,(INT)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1918 pStats->tx_errors--;
1919 pStats->tx_dropped--;
1924 device_free_tx_buf(pDevice,pTD);
1925 pDevice->iTDUsed[uIdx]--;
1930 if (uIdx == TYPE_AC0DMA) {
1931 // RESERV_AC0DMA reserved for relay
1933 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1935 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
1937 if (netif_queue_stopped(pDevice->dev) && (bFull==FALSE)){
1938 netif_wake_queue(pDevice->dev);
1943 pDevice->apTailTD[uIdx] = pTD;
1949 static void device_error(PSDevice pDevice, WORD status) {
1951 if (status & ISR_FETALERR) {
1952 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR
1953 "%s: Hardware fatal error.\n",
1954 pDevice->dev->name);
1955 netif_stop_queue(pDevice->dev);
1956 del_timer(&pDevice->sTimerCommand);
1957 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1958 pDevice->bCmdRunning = FALSE;
1959 MACbShutdown(pDevice->PortOffset);
1965 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc) {
1966 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1967 struct sk_buff* skb=pTDInfo->skb;
1969 // pre-allocated buf_dma can't be unmapped.
1970 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1971 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,skb->len,
1975 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1976 dev_kfree_skb_irq(skb);
1978 pTDInfo->skb_dma = 0;
1980 pTDInfo->byFlags = 0;
1986 VOID InitRxManagementQueue(PSDevice pDevice)
1988 pDevice->rxManeQueue.packet_num = 0;
1989 pDevice->rxManeQueue.head = pDevice->rxManeQueue.tail = 0;
2001 PSDevice pDevice = (PSDevice) Context;
2002 PSRxMgmtPacket pRxMgmtPacket;
2004 //complete(&pDevice->notify);
2005 //printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
2007 //printk("Enter MlmeThread,packet _num is %d\n",pDevice->rxManeQueue.packet_num);
2014 //down(&pDevice->mlme_semaphore);
2015 // pRxMgmtPacket = DeQueue(pDevice);
2017 spin_lock_irq(&pDevice->lock);
2018 while(pDevice->rxManeQueue.packet_num != 0)
2020 pRxMgmtPacket = DeQueue(pDevice);
2022 //DequeueManageObject(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
2023 vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
2024 //printk("packet_num is %d\n",pDevice->rxManeQueue.packet_num);
2027 spin_unlock_irq(&pDevice->lock);
2032 //printk("Before schedule thread jiffies is %x\n",jiffies);
2034 //printk("after schedule thread jiffies is %x\n",jiffies);
2037 //printk("i is %d\n",i);
2048 int __device_open(HANDLE pExDevice) {
2049 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
2050 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
2054 static int device_open(struct net_device *dev) {
2055 PSDevice pDevice=(PSDevice) netdev_priv(dev);
2058 pDevice->rx_buf_sz = PKT_BUF_SZ;
2059 if (!device_init_rings(pDevice)) {
2062 //2008-5-13 <add> by chester
2064 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,16)
2065 i=request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
2067 i=request_irq(pDevice->pcid->irq, &device_intr, (unsigned long)SA_SHIRQ, dev->name, dev);
2072 //printk("DEBUG1\n");
2073 #ifdef WPA_SM_Transtatus
2074 extern SWPAResult wpa_Result;
2075 memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
2076 wpa_Result.proto = 0;
2077 wpa_Result.key_mgmt = 0;
2078 wpa_Result.eap_type = 0;
2079 wpa_Result.authenticated = FALSE;
2080 pDevice->fWPA_Authened = FALSE;
2082 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
2083 device_init_rd0_ring(pDevice);
2084 device_init_rd1_ring(pDevice);
2085 device_init_defrag_cb(pDevice);
2086 device_init_td0_ring(pDevice);
2087 device_init_td1_ring(pDevice);
2088 // VNTWIFIvSet11h(pDevice->pMgmt, pDevice->b11hEnable);
2091 if (pDevice->bDiversityRegCtlON) {
2092 device_init_diversity_timer(pDevice);
2094 vMgrObjectInit(pDevice);
2095 vMgrTimerInit(pDevice);
2099 tasklet_init (&pDevice->RxMngWorkItem,(void *)MngWorkItem,(unsigned long )pDevice);
2102 InitRxManagementQueue(pDevice);
2104 mlme_task = kthread_run(MlmeThread,(void *) pDevice, "MLME");
2105 if (IS_ERR(mlme_task)) {
2106 printk("thread create fail\n");
2116 pDevice->MLMEThr_pid = kernel_thread(MlmeThread, pDevice, CLONE_VM);
2117 if (pDevice->MLMEThr_pid <0 )
2119 printk("unable start thread MlmeThread\n");
2124 //printk("thread id is %d\n",pDevice->MLMEThr_pid);
2125 //printk("Create thread time is %x\n",jiffies);
2126 //wait_for_completion(&pDevice->notify);
2131 // if (( SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL)&0x06)==0x04)
2133 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
2134 device_init_registers(pDevice, DEVICE_INIT_COLD);
2135 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
2136 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, U_ETHER_ADDR_LEN);
2138 __device_set_multi(pExDevice);
2140 device_set_multi(pDevice->dev);
2143 // Init for Key Management
2144 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
2145 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
2147 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2149 pDevice->bwextstep0 = FALSE;
2150 pDevice->bwextstep1 = FALSE;
2151 pDevice->bwextstep2 = FALSE;
2152 pDevice->bwextstep3 = FALSE;
2154 pDevice->bwextcount=0;
2155 pDevice->bWPASuppWextEnabled = FALSE;
2157 pDevice->byReAssocCount = 0;
2158 pDevice->bWPADEVUp = FALSE;
2159 // Patch: if WEP key already set by iwconfig but device not yet open
2160 if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) {
2161 KeybSetDefaultKey(&(pDevice->sKey),
2162 (DWORD)(pDevice->byKeyIndex | (1 << 31)),
2163 pDevice->uKeyLength,
2167 pDevice->PortOffset,
2170 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
2173 //printk("DEBUG2\n");
2176 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
2177 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2179 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2180 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
2183 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
2184 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_SSID, NULL);
2186 pDevice->flags |=DEVICE_FLAGS_OPENED;
2189 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
2194 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
2201 int __device_close(HANDLE pExDevice) {
2202 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
2203 struct net_device *dev = pDevice_info->dev;
2204 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
2207 static int device_close(struct net_device *dev) {
2208 PSDevice pDevice=(PSDevice) netdev_priv(dev);
2210 PSMgmtObject pMgmt = pDevice->pMgmt;
2216 //2007-1121-02<Add>by EinsnLiu
2217 if (pDevice->bLinkPass) {
2218 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2222 del_timer(&pDevice->sTimerTxData);
2224 del_timer(&pDevice->sTimerCommand);
2225 del_timer(&pMgmt->sTimerSecondCallback);
2226 if (pDevice->bDiversityRegCtlON) {
2227 del_timer(&pDevice->TimerSQ3Tmax1);
2228 del_timer(&pDevice->TimerSQ3Tmax2);
2229 del_timer(&pDevice->TimerSQ3Tmax3);
2233 tasklet_kill(&pDevice->RxMngWorkItem);
2235 netif_stop_queue(dev);
2236 pDevice->bCmdRunning = FALSE;
2237 MACbShutdown(pDevice->PortOffset);
2238 MACbSoftwareReset(pDevice->PortOffset);
2239 CARDbRadioPowerOff(pDevice);
2241 pDevice->bLinkPass = FALSE;
2242 memset(pMgmt->abyCurrBSSID, 0, 6);
2243 pMgmt->eCurrState = WMAC_STATE_IDLE;
2244 device_free_td0_ring(pDevice);
2245 device_free_td1_ring(pDevice);
2246 device_free_rd0_ring(pDevice);
2247 device_free_rd1_ring(pDevice);
2248 device_free_frag_buf(pDevice);
2249 device_free_rings(pDevice);
2250 BSSvClearNodeDBTable(pDevice, 0);
2251 free_irq(dev->irq, dev);
2252 pDevice->flags &=(~DEVICE_FLAGS_OPENED);
2253 //2008-0714-01<Add>by chester
2254 device_release_WPADEV(pDevice);
2256 //tasklet_kill(&pDevice->RxMngWorkItem);
2259 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
2263 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close.. \n");
2269 int __device_dma0_tx_80211(HANDLE pExDevice, struct sk_buff *skb) {
2270 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
2271 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
2272 ref_sk_buff ref_skb;
2277 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
2278 PSDevice pDevice=netdev_priv(dev);
2284 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
2285 spin_lock_irq(&pDevice->lock);
2287 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2288 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
2289 dev_kfree_skb_irq(skb);
2290 spin_unlock_irq(&pDevice->lock);
2294 if (pDevice->bStopTx0Pkt == TRUE) {
2295 dev_kfree_skb_irq(skb);
2296 spin_unlock_irq(&pDevice->lock);
2301 ref_skb_remap(pDevice->dev, &ref_skb, skb);
2302 cbMPDULen = *(ref_skb.len);
2303 pbMPDU = ref_skb.data;
2305 cbMPDULen = skb->len;
2309 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
2311 spin_unlock_irq(&pDevice->lock);
2319 BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, UINT uNodeIndex) {
2320 PSMgmtObject pMgmt = pDevice->pMgmt;
2321 PSTxDesc pHeadTD, pLastTD;
2322 UINT cbFrameBodySize;
2325 BOOL bNeedEncryption = FALSE;
2326 PSKeyItem pTransmitKey = NULL;
2330 // BYTE byKeyIndex = 0;
2332 ref_sk_buff ref_skb;
2336 if (pDevice->bStopTx0Pkt == TRUE) {
2337 dev_kfree_skb_irq(skb);
2341 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2342 dev_kfree_skb_irq(skb);
2343 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
2347 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2348 if (pDevice->uAssocCount == 0) {
2349 dev_kfree_skb_irq(skb);
2350 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
2356 ref_skb_remap(pDevice->dev, &(ref_skb), skb);
2358 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
2360 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2363 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(ref_skb.data), U_HEADER_LEN);
2364 cbFrameBodySize = *(ref_skb.len) - U_HEADER_LEN;
2367 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2368 cbFrameBodySize = skb->len - U_HEADER_LEN;
2372 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2373 cbFrameBodySize += 8;
2375 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2377 if ( uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
2378 dev_kfree_skb_irq(skb);
2381 byPktTyp = (BYTE)pDevice->byPacketType;
2384 if (pDevice->bFixRate) {
2385 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2386 if (pDevice->uConnectionRate >= RATE_11M) {
2387 pDevice->wCurrentRate = RATE_11M;
2389 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2392 if (pDevice->uConnectionRate >= RATE_54M)
2393 pDevice->wCurrentRate = RATE_54M;
2395 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2399 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2403 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2404 pDevice->byPreambleType = pDevice->byShortPreamble;
2407 pDevice->byPreambleType = PREAMBLE_LONG;
2410 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2413 if (pDevice->wCurrentRate <= RATE_11M) {
2414 byPktTyp = PK_TYPE_11B;
2415 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2416 byPktTyp = PK_TYPE_11A;
2418 if (pDevice->bProtectMode == TRUE) {
2419 byPktTyp = PK_TYPE_11GB;
2421 byPktTyp = PK_TYPE_11GA;
2425 if (pDevice->bEncryptionEnable == TRUE)
2426 bNeedEncryption = TRUE;
2428 if (pDevice->bEnableHostWEP) {
2429 pTransmitKey = &STempKey;
2430 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2431 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2432 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2433 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2434 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2435 memcpy(pTransmitKey->abyKey,
2436 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2437 pTransmitKey->uKeyLength
2440 vGenerateFIFOHeader(pDevice, byPktTyp, pDevice->pbyTmpBuff, bNeedEncryption,
2441 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
2442 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2447 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2449 MACbPSWakeup(pDevice->PortOffset);
2452 pDevice->bPWBitOn = FALSE;
2455 for (ii = 0; ii < uMACfragNum; ii++) {
2456 // Poll Transmit the adapter
2458 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2460 if (ii == (uMACfragNum - 1))
2462 pHeadTD = pHeadTD->next;
2465 // Save the information needed by the tx interrupt handler
2466 // to complete the Send request
2467 pLastTD->pTDInfo->skb = skb;
2468 pLastTD->pTDInfo->byFlags = 0;
2469 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2471 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
2473 MACvTransmit0(pDevice->PortOffset);
2479 //TYPE_AC0DMA data tx
2482 int __device_xmit(HANDLE pExDevice, struct sk_buff *skb) {
2483 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
2484 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
2485 struct net_device *dev = pDevice_info->dev;
2486 ref_sk_buff ref_skb;
2489 static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
2490 PSDevice pDevice=netdev_priv(dev);
2493 PSMgmtObject pMgmt = pDevice->pMgmt;
2494 PSTxDesc pHeadTD, pLastTD;
2495 UINT uNodeIndex = 0;
2496 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2498 UINT uMACfragNum = 1;
2499 UINT cbFrameBodySize;
2502 BOOL bNeedEncryption = FALSE;
2503 PSKeyItem pTransmitKey = NULL;
2506 BOOL bTKIP_UseGTK = FALSE;
2507 BOOL bNeedDeAuth = FALSE;
2509 BOOL bNodeExist = FALSE;
2513 spin_lock_irq(&pDevice->lock);
2514 if (pDevice->bLinkPass == FALSE) {
2515 dev_kfree_skb_irq(skb);
2516 spin_unlock_irq(&pDevice->lock);
2520 if (pDevice->bStopDataPkt) {
2521 dev_kfree_skb_irq(skb);
2522 spin_unlock_irq(&pDevice->lock);
2527 ref_skb_remap(pDevice->dev, &ref_skb, skb);
2530 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2531 if (pDevice->uAssocCount == 0) {
2532 dev_kfree_skb_irq(skb);
2533 spin_unlock_irq(&pDevice->lock);
2537 if (IS_MULTICAST_ADDRESS((PBYTE)(ref_skb.data))) {
2539 if (IS_MULTICAST_ADDRESS((PBYTE)(skb->data))) {
2543 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2545 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), ref_skb.skb);
2547 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2549 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2551 pMgmt->abyPSTxMap[0] |= byMask[0];
2552 spin_unlock_irq(&pDevice->lock);
2557 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(ref_skb.data), &uNodeIndex)) {
2559 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
2561 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2563 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, ref_skb.skb);
2565 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2567 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2569 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2570 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2571 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2572 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2573 spin_unlock_irq(&pDevice->lock);
2577 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2578 pDevice->byPreambleType = pDevice->byShortPreamble;
2581 pDevice->byPreambleType = PREAMBLE_LONG;
2588 if (bNodeExist == FALSE) {
2589 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2590 dev_kfree_skb_irq(skb);
2591 spin_unlock_irq(&pDevice->lock);
2596 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
2598 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2602 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(ref_skb.data), U_HEADER_LEN);
2603 cbFrameBodySize = *(ref_skb.len) - U_HEADER_LEN;
2605 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2606 cbFrameBodySize = skb->len - U_HEADER_LEN;
2609 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2610 cbFrameBodySize += 8;
2614 if (pDevice->bEncryptionEnable == TRUE) {
2615 bNeedEncryption = TRUE;
2618 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2619 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2620 pbyBSSID = pDevice->abyBSSID;
2622 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2624 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2625 bTKIP_UseGTK = TRUE;
2626 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2630 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2633 }else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2635 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2636 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2637 for (ii = 0; ii< 6; ii++)
2638 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2639 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2642 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE)
2646 pbyBSSID = pDevice->abyBroadcastAddr;
2647 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2648 pTransmitKey = NULL;
2649 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2650 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2653 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2655 bTKIP_UseGTK = TRUE;
2656 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2661 if (pDevice->bEnableHostWEP) {
2662 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2663 if (pDevice->bEncryptionEnable == TRUE) {
2664 pTransmitKey = &STempKey;
2665 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2666 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2667 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2668 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2669 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2670 memcpy(pTransmitKey->abyKey,
2671 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2672 pTransmitKey->uKeyLength
2677 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2679 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2680 DEVICE_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
2681 dev_kfree_skb_irq(skb);
2682 spin_unlock_irq(&pDevice->lock);
2686 if (pTransmitKey != NULL) {
2687 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2688 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2689 uMACfragNum = 1; //WEP256 doesn't support fragment
2693 byPktTyp = (BYTE)pDevice->byPacketType;
2695 if (pDevice->bFixRate) {
2697 printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n",pDevice->eCurrentPHYType,pDevice->uConnectionRate);
2700 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2701 if (pDevice->uConnectionRate >= RATE_11M) {
2702 pDevice->wCurrentRate = RATE_11M;
2704 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2707 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2708 (pDevice->uConnectionRate <= RATE_6M)) {
2709 pDevice->wCurrentRate = RATE_6M;
2711 if (pDevice->uConnectionRate >= RATE_54M)
2712 pDevice->wCurrentRate = RATE_54M;
2714 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2718 pDevice->byACKRate = (BYTE) pDevice->wCurrentRate;
2719 pDevice->byTopCCKBasicRate = RATE_1M;
2720 pDevice->byTopOFDMBasicRate = RATE_6M;
2724 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2725 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2726 pDevice->wCurrentRate = RATE_1M;
2727 pDevice->byACKRate = RATE_1M;
2728 pDevice->byTopCCKBasicRate = RATE_1M;
2729 pDevice->byTopOFDMBasicRate = RATE_6M;
2731 pDevice->wCurrentRate = RATE_6M;
2732 pDevice->byACKRate = RATE_6M;
2733 pDevice->byTopCCKBasicRate = RATE_1M;
2734 pDevice->byTopOFDMBasicRate = RATE_6M;
2738 VNTWIFIvGetTxRate( pDevice->pMgmt,
2739 pDevice->sTxEthHeader.abyDstAddr,
2740 &(pDevice->wCurrentRate),
2741 &(pDevice->byACKRate),
2742 &(pDevice->byTopCCKBasicRate),
2743 &(pDevice->byTopOFDMBasicRate));
2746 printk("auto rate:Rate : %d,AckRate:%d,TopCCKRate:%d,TopOFDMRate:%d\n",
2747 pDevice->wCurrentRate,pDevice->byACKRate,
2748 pDevice->byTopCCKBasicRate,pDevice->byTopOFDMBasicRate);
2754 pDevice->wCurrentRate = 11;
2755 pDevice->byACKRate = 8;
2756 pDevice->byTopCCKBasicRate = 3;
2757 pDevice->byTopOFDMBasicRate = 8;
2764 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2766 if (pDevice->wCurrentRate <= RATE_11M) {
2767 byPktTyp = PK_TYPE_11B;
2768 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2769 byPktTyp = PK_TYPE_11A;
2771 if (pDevice->bProtectMode == TRUE) {
2772 byPktTyp = PK_TYPE_11GB;
2774 byPktTyp = PK_TYPE_11GA;
2778 //#ifdef PLICE_DEBUG
2779 // printk("FIX RATE:CurrentRate is %d");
2782 if (bNeedEncryption == TRUE) {
2783 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2784 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2785 bNeedEncryption = FALSE;
2786 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2787 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2788 if (pTransmitKey == NULL) {
2789 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2792 if (bTKIP_UseGTK == TRUE) {
2793 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2796 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2797 bNeedEncryption = TRUE;
2802 if (pDevice->byCntMeasure == 2) {
2804 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2807 if (pDevice->bEnableHostWEP) {
2808 if ((uNodeIndex != 0) &&
2809 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2810 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2811 bNeedEncryption = TRUE;
2816 if (pTransmitKey == NULL) {
2817 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2818 dev_kfree_skb_irq(skb);
2819 spin_unlock_irq(&pDevice->lock);
2827 vGenerateFIFOHeader(pDevice, byPktTyp, pDevice->pbyTmpBuff, bNeedEncryption,
2828 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2829 &pDevice->sTxEthHeader, (PBYTE)ref_skb.data, pTransmitKey, uNodeIndex,
2835 //if (skb->len == 98)
2837 // printk("ping:len is %d\n");
2840 vGenerateFIFOHeader(pDevice, byPktTyp, pDevice->pbyTmpBuff, bNeedEncryption,
2841 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2842 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2848 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2850 MACbPSWakeup(pDevice->PortOffset);
2852 pDevice->bPWBitOn = FALSE;
2855 for (ii = 0; ii < uMACfragNum; ii++) {
2856 // Poll Transmit the adapter
2858 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2860 if (ii == uMACfragNum - 1)
2862 pHeadTD = pHeadTD->next;
2865 // Save the information needed by the tx interrupt handler
2866 // to complete the Send request
2868 pLastTD->pTDInfo->skb = ref_skb.skb;
2870 pLastTD->pTDInfo->skb = skb;
2872 pLastTD->pTDInfo->byFlags = 0;
2873 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2875 pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
2877 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1) {
2878 netif_stop_queue(dev);
2881 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2882 //#ifdef PLICE_DEBUG
2883 if (pDevice->bFixRate)
2885 printk("FixRate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2889 //printk("Auto Rate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2894 BYTE Protocol_Version; //802.1x Authentication
2895 BYTE Packet_Type; //802.1x Authentication
2896 BYTE Descriptor_type;
2898 BOOL bTxeapol_key = FALSE;
2899 Protocol_Version = skb->data[U_HEADER_LEN];
2900 Packet_Type = skb->data[U_HEADER_LEN+1];
2901 Descriptor_type = skb->data[U_HEADER_LEN+1+1+2];
2902 Key_info = (skb->data[U_HEADER_LEN+1+1+2+1] << 8)|(skb->data[U_HEADER_LEN+1+1+2+2]);
2903 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2904 if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
2905 (Packet_Type==3)) { //802.1x OR eapol-key challenge frame transfer
2906 bTxeapol_key = TRUE;
2907 if((Descriptor_type==254)||(Descriptor_type==2)) { //WPA or RSN
2908 if(!(Key_info & BIT3) && //group-key challenge
2909 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2910 pDevice->fWPA_Authened = TRUE;
2911 if(Descriptor_type==254)
2915 printk("Authentication completed!!\n");
2922 MACvTransmitAC0(pDevice->PortOffset);
2923 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0:pDevice->apCurrTD= %p\n", pHeadTD);
2926 ref_set_tx_jiffies(pDevice->dev);
2928 dev->trans_start = jiffies;
2931 spin_unlock_irq(&pDevice->lock);
2938 int __device_intr(int irq, HANDLE pExDevice, struct pt_regs *regs) {
2939 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
2940 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
2944 static irqreturn_t device_intr(int irq, void *dev_instance) {
2945 struct net_device* dev=dev_instance;
2946 PSDevice pDevice=(PSDevice) netdev_priv(dev);
2950 DWORD dwMIBCounter=0;
2951 PSMgmtObject pMgmt = pDevice->pMgmt;
2952 BYTE byOrgPageSel=0;
2959 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2961 if (pDevice->dwIsr == 0)
2962 return IRQ_RETVAL(handled);
2964 if (pDevice->dwIsr == 0xffffffff) {
2965 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
2966 return IRQ_RETVAL(handled);
2969 // 2008-05-21 <mark> by Richardtai, we can't read RSSI here, because no packet bound with RSSI
2971 if ((BITbIsBitOn(pDevice->dwIsr, ISR_RXDMA0)) &&
2972 (pDevice->byLocalID != REV_ID_VT3253_B0) &&
2973 (pDevice->bBSSIDFilter == TRUE)) {
2975 //BBbReadEmbeded(pDevice->PortOffset, 0x3E, &byRSSI);
2976 //pDevice->uCurrRSSI = byRSSI;
2981 MACvIntDisable(pDevice->PortOffset);
2982 spin_lock_irq(&pDevice->lock);
2984 //Make sure current page is 0
2985 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2986 if (byOrgPageSel == 1) {
2987 MACvSelectPage0(pDevice->PortOffset);
2992 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2994 // Must do this after doing rx/tx, cause ISR bit is slow
2995 // than RD/TD write back
2996 // update ISR counter
2997 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2998 while (pDevice->dwIsr != 0) {
3000 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
3001 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
3003 if (pDevice->dwIsr & ISR_FETALERR){
3004 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR \n");
3005 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
3006 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
3007 device_error(pDevice, pDevice->dwIsr);
3010 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
3012 if (BITbIsBitOn(pDevice->dwIsr, ISR_MEASURESTART)) {
3013 // 802.11h measure start
3014 pDevice->byOrgChannel = pDevice->byCurrentCh;
3015 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
3016 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
3017 MACvSelectPage1(pDevice->PortOffset);
3018 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
3019 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
3020 MACvSelectPage0(pDevice->PortOffset);
3022 // WCMDbFlushCommandQueue(pDevice->pMgmt, TRUE);
3023 if (CARDbSetChannel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel) == TRUE) {
3024 pDevice->bMeasureInProgress = TRUE;
3025 MACvSelectPage1(pDevice->PortOffset);
3026 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
3027 MACvSelectPage0(pDevice->PortOffset);
3028 pDevice->byBasicMap = 0;
3029 pDevice->byCCAFraction = 0;
3030 for(ii=0;ii<8;ii++) {
3031 pDevice->dwRPIs[ii] = 0;
3034 // can not measure because set channel fail
3035 // WCMDbResetCommandQueue(pDevice->pMgmt);
3036 // clear measure control
3037 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
3038 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
3039 MACvSelectPage1(pDevice->PortOffset);
3040 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
3041 MACvSelectPage0(pDevice->PortOffset);
3044 if (BITbIsBitOn(pDevice->dwIsr, ISR_MEASUREEND)) {
3045 // 802.11h measure end
3046 pDevice->bMeasureInProgress = FALSE;
3047 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
3048 MACvSelectPage1(pDevice->PortOffset);
3049 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
3050 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
3051 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
3052 pDevice->byBasicMap |= (byData >> 4);
3053 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
3054 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
3055 // clear measure control
3056 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
3057 MACvSelectPage0(pDevice->PortOffset);
3058 CARDbSetChannel(pDevice, pDevice->byOrgChannel);
3059 // WCMDbResetCommandQueue(pDevice->pMgmt);
3060 MACvSelectPage1(pDevice->PortOffset);
3061 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
3062 MACvSelectPage0(pDevice->PortOffset);
3063 if (BITbIsBitOn(byData, MSRCTL_FINISH)) {
3065 s_vCompleteCurrentMeasure(pDevice, 0);
3067 // can not measure because not ready before end of measure time
3068 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
3071 if (BITbIsBitOn(pDevice->dwIsr, ISR_QUIETSTART)) {
3074 } while (CARDbStartQuiet(pDevice) == FALSE);
3078 if (pDevice->dwIsr & ISR_TBTT) {
3079 if (pDevice->bEnableFirstQuiet == TRUE) {
3080 pDevice->byQuietStartCount--;
3081 if (pDevice->byQuietStartCount == 0) {
3082 pDevice->bEnableFirstQuiet = FALSE;
3083 MACvSelectPage1(pDevice->PortOffset);
3084 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
3085 MACvSelectPage0(pDevice->PortOffset);
3088 if ((pDevice->bChannelSwitch == TRUE) &&
3089 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
3090 pDevice->byChannelSwitchCount--;
3091 if (pDevice->byChannelSwitchCount == 0) {
3092 pDevice->bChannelSwitch = FALSE;
3093 CARDbSetChannel(pDevice, pDevice->byNewChannel);
3094 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
3095 MACvSelectPage1(pDevice->PortOffset);
3096 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
3097 MACvSelectPage0(pDevice->PortOffset);
3098 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
3102 if (pDevice->eOPMode == OP_MODE_ADHOC) {
3103 //pDevice->bBeaconSent = FALSE;
3105 if ((pDevice->bUpdateBBVGA) && (pDevice->bLinkPass == TRUE) && (pDevice->uCurrRSSI != 0)) {
3108 RFvRSSITodBm(pDevice, (BYTE) pDevice->uCurrRSSI, &ldBm);
3109 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
3110 if (ldBm < pDevice->ldBmThreshold[ii]) {
3111 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
3115 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
3116 pDevice->uBBVGADiffCount++;
3117 if (pDevice->uBBVGADiffCount == 1) {
3118 // first VGA diff gain
3119 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
3120 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
3121 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
3123 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
3124 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
3125 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
3126 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
3129 pDevice->uBBVGADiffCount = 1;
3134 pDevice->bBeaconSent = FALSE;
3135 if (pDevice->bEnablePSMode) {
3136 PSbIsNextTBTTWakeUp((HANDLE)pDevice);
3139 if ((pDevice->eOPMode == OP_MODE_AP) ||
3140 (pDevice->eOPMode == OP_MODE_ADHOC)) {
3142 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
3143 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
3146 if (pDevice->eOPMode == OP_MODE_ADHOC && pDevice->pMgmt->wCurrATIMWindow > 0) {
3147 // todo adhoc PS mode
3152 if (pDevice->dwIsr & ISR_BNTX) {
3154 if (pDevice->eOPMode == OP_MODE_ADHOC) {
3155 pDevice->bIsBeaconBufReadySet = FALSE;
3156 pDevice->cbBeaconBufReadySetCnt = 0;
3159 if (pDevice->eOPMode == OP_MODE_AP) {
3160 if(pMgmt->byDTIMCount > 0) {
3161 pMgmt->byDTIMCount --;
3162 pMgmt->sNodeDBTable[0].bRxPSPoll = FALSE;
3165 if(pMgmt->byDTIMCount == 0) {
3166 // check if mutltcast tx bufferring
3167 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
3168 pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE;
3169 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
3173 pDevice->bBeaconSent = TRUE;
3175 if (pDevice->bChannelSwitch == TRUE) {
3176 pDevice->byChannelSwitchCount--;
3177 if (pDevice->byChannelSwitchCount == 0) {
3178 pDevice->bChannelSwitch = FALSE;
3179 CARDbSetChannel(pDevice, pDevice->byNewChannel);
3180 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
3181 MACvSelectPage1(pDevice->PortOffset);
3182 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
3183 MACvSelectPage0(pDevice->PortOffset);
3184 //VNTWIFIbSendBeacon(pDevice->pMgmt);
3185 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
3191 if (pDevice->dwIsr & ISR_RXDMA0) {
3192 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
3194 if (pDevice->dwIsr & ISR_RXDMA1) {
3195 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
3197 if (pDevice->dwIsr & ISR_TXDMA0){
3198 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
3200 if (pDevice->dwIsr & ISR_AC0DMA){
3201 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
3203 if (pDevice->dwIsr & ISR_SOFTTIMER) {
3206 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
3207 if (pDevice->eOPMode == OP_MODE_AP) {
3208 if (pDevice->bShortSlotTime)
3209 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
3211 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
3213 bMgrPrepareBeaconToSend(pDevice, pMgmt);
3214 pDevice->byCntMeasure = 0;
3217 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
3219 MACvReceive0(pDevice->PortOffset);
3220 MACvReceive1(pDevice->PortOffset);
3222 if (max_count>pDevice->sOpts.int_works)
3226 if (byOrgPageSel == 1) {
3227 MACvSelectPage1(pDevice->PortOffset);
3230 spin_unlock_irq(&pDevice->lock);
3231 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3233 return IRQ_RETVAL(handled);
3237 static unsigned const ethernet_polynomial = 0x04c11db7U;
3238 static inline u32 ether_crc(int length, unsigned char *data)
3242 while(--length >= 0) {
3243 unsigned char current_octet = *data++;
3245 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
3247 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
3253 //2008-8-4 <add> by chester
3254 static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source)
3257 int source_len = strlen(source);
3260 strcat(buf1, string);
3262 source+=strlen(buf1);
3264 memcpy(dest,source,source_len-strlen(buf1));
3268 int Config_FileOperation(PSDevice pDevice,BOOL fwrite,unsigned char *Parameter) {
3269 UCHAR *config_path=CONFIG_PATH;
3271 UCHAR tmpbuffer[20];
3272 struct file *filp=NULL;
3273 mm_segment_t old_fs = get_fs();
3274 //int oldfsuid=0,oldfsgid=0;
3279 /* Can't do this anymore, so we rely on correct filesystem permissions:
3280 //Make sure a caller can read or write power as root
3281 oldfsuid=current->cred->fsuid;
3282 oldfsgid=current->cred->fsgid;
3283 current->cred->fsuid = 0;
3284 current->cred->fsgid = 0;
3288 filp = filp_open(config_path, O_RDWR, 0);
3290 printk("Config_FileOperation:open file fail?\n");
3295 if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
3296 printk("file %s cann't readable or writable?\n",config_path);
3301 buffer = (UCHAR *)kmalloc(1024, GFP_KERNEL);
3303 printk("alllocate mem for file fail?\n");
3308 if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
3309 printk("read file error?\n");
3314 if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=TRUE) {
3315 printk("get parameter error?\n");
3320 if(memcmp(tmpbuffer,"USA",3)==0) {
3321 result=ZoneType_USA;
3323 else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
3324 result=ZoneType_Japan;
3326 else if(memcmp(tmpbuffer,"EUROPE",5)==0) {
3327 result=ZoneType_Europe;
3331 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
3338 if(filp_close(filp,NULL))
3339 printk("Config_FileOperation:close file fail\n");
3345 current->cred->fsuid=oldfsuid;
3346 current->cred->fsgid=oldfsgid;
3355 void __device_set_multi(HANDLE pExDevice) {
3356 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
3357 ref_net_device *dev = &(pDevice_info->ref_dev);
3358 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
3362 static void device_set_multi(struct net_device *dev) {
3363 PSDevice pDevice = (PSDevice) netdev_priv(dev);
3366 PSMgmtObject pMgmt = pDevice->pMgmt;
3369 struct dev_mc_list *mclist;
3372 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
3375 if (*(dev->flags) & IFF_PROMISC) { /* Set promiscuous. */
3376 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: Promiscuous mode enabled.\n", pDevice->dev->name);
3379 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
3380 DEVICE_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
3382 /* Unconditionally log net taps. */
3383 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
3386 else if ((*(dev->mc_count) > pDevice->multicast_limit)
3387 || (*(dev->flags) & IFF_ALLMULTI)) {
3389 else if ((dev->mc_count > pDevice->multicast_limit)
3390 || (dev->flags & IFF_ALLMULTI)) {
3392 MACvSelectPage1(pDevice->PortOffset);
3393 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
3394 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
3395 MACvSelectPage0(pDevice->PortOffset);
3396 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3399 memset(mc_filter, 0, sizeof(mc_filter));
3401 for (i = 0, mclist = dev->mc_list; mclist && i < *(dev->mc_count);
3402 i++, mclist = mclist->next) {
3404 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
3405 i++, mclist = mclist->next) {
3407 int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
3408 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
3410 MACvSelectPage1(pDevice->PortOffset);
3411 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
3412 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
3413 MACvSelectPage0(pDevice->PortOffset);
3414 pDevice->byRxMode &= ~(RCR_UNICAST);
3415 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3418 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3419 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
3420 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3421 pDevice->byRxMode &= ~(RCR_UNICAST);
3424 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
3425 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode );
3431 struct net_device_stats *__device_get_stats(HANDLE pExDevice) {
3432 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
3433 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
3436 static struct net_device_stats *device_get_stats(struct net_device *dev) {
3437 PSDevice pDevice=(PSDevice) netdev_priv(dev);
3440 return &pDevice->stats;
3446 int __device_ioctl(HANDLE pExDevice, struct ifreq *rq, int cmd) {
3447 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
3448 struct net_device *dev = pDevice_info->dev;
3449 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
3453 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
3454 PSDevice pDevice = (PSDevice)netdev_priv(dev);
3458 struct iwreq *wrq = (struct iwreq *) rq;
3461 PSMgmtObject pMgmt = pDevice->pMgmt;
3465 if (pMgmt == NULL) {
3473 //#if WIRELESS_EXT < 13
3476 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
3479 case SIOCGIWNWID: //0x8b03 support
3480 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3481 rc = iwctl_giwnwid(dev, NULL, &(wrq->u.nwid), NULL);
3487 // Set frequency/channel
3489 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
3492 // Get frequency/channel
3494 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
3497 // Set desired network name (ESSID)
3501 char essid[IW_ESSID_MAX_SIZE+1];
3502 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
3506 if (copy_from_user(essid, wrq->u.essid.pointer,
3507 wrq->u.essid.length)) {
3511 rc = iwctl_siwessid(dev, NULL,
3512 &(wrq->u.essid), essid);
3517 // Get current network name (ESSID)
3521 char essid[IW_ESSID_MAX_SIZE+1];
3522 if (wrq->u.essid.pointer)
3523 rc = iwctl_giwessid(dev, NULL,
3524 &(wrq->u.essid), essid);
3525 if (copy_to_user(wrq->u.essid.pointer,
3527 wrq->u.essid.length) )
3534 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3538 // Get current Access Point (BSSID)
3540 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3544 // Set desired station name
3546 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
3550 // Get current station name
3552 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
3556 // Set the desired bit-rate
3558 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3561 // Get the current bit-rate
3564 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3567 // Set the desired RTS threshold
3570 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
3573 // Get the current RTS threshold
3576 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
3579 // Set the desired fragmentation threshold
3582 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
3585 // Get the current fragmentation threshold
3588 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
3591 // Set mode of operation
3593 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
3596 // Get mode of operation
3598 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
3601 // Set WEP keys and mode
3604 char abyKey[WLAN_WEP232_KEYLEN];
3606 if (wrq->u.encoding.pointer) {
3609 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
3613 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
3614 if (copy_from_user(abyKey,
3615 wrq->u.encoding.pointer,
3616 wrq->u.encoding.length)) {
3620 } else if (wrq->u.encoding.length != 0) {
3624 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3628 // Get the WEP keys and mode
3631 if (!capable(CAP_NET_ADMIN)) {
3636 char abyKey[WLAN_WEP232_KEYLEN];
3638 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3640 if (wrq->u.encoding.pointer) {
3641 if (copy_to_user(wrq->u.encoding.pointer,
3643 wrq->u.encoding.length))
3649 #if WIRELESS_EXT > 9
3650 // Get the current Tx-Power
3652 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3657 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3661 #endif // WIRELESS_EXT > 9
3663 #if WIRELESS_EXT > 10
3666 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
3671 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
3674 #endif // WIRELESS_EXT > 10
3676 // Get range of parameters
3680 struct iw_range range;
3682 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *) &range);
3683 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
3691 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
3697 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
3703 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
3707 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
3713 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
3715 if (wrq->u.data.pointer) {
3716 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
3718 if (copy_to_user(wrq->u.data.pointer,
3720 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
3733 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3740 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3744 #endif // WIRELESS_SPY
3747 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
3750 if(wrq->u.data.pointer) {
3751 wrq->u.data.length = sizeof(iwctl_private_args) / sizeof( iwctl_private_args[0]);
3753 if(copy_to_user(wrq->u.data.pointer,
3754 (u_char *) iwctl_private_args,
3755 sizeof(iwctl_private_args)))
3762 //#endif // WIRELESS_EXT < 13
3763 //2008-0409-07, <Add> by Einsn Liu
3764 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3766 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
3767 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
3771 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH \n");
3772 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
3776 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE \n");
3777 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3781 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE \n");
3782 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3785 case SIOCSIWENCODEEXT:
3787 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
3788 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
3789 if(wrq->u.encoding.pointer){
3790 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1);
3791 if(wrq->u.encoding.length > (sizeof(struct iw_encode_ext)+ MAX_KEY_LEN)){
3795 if(copy_from_user(extra, wrq->u.encoding.pointer,wrq->u.encoding.length)){
3799 }else if(wrq->u.encoding.length != 0){
3803 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
3807 case SIOCGIWENCODEEXT:
3808 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT \n");
3809 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
3813 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME \n");
3814 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3817 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3818 //End Add -- //2008-0409-07, <Add> by Einsn Liu
3820 #endif // WIRELESS_EXT
3822 case IOCTL_CMD_TEST:
3824 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
3830 pReq = (PSCmdRequest)rq;
3831 pReq->wResult = MAGIC_CODE;
3837 if((((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_EVT) &&
3838 !(pDevice->flags & DEVICE_FLAGS_OPENED))
3840 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
3841 (((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_WPA))
3850 if (test_and_set_bit( 0, (void*)&(pMgmt->uCmdBusy))) {
3853 rc = private_ioctl(pDevice, rq);
3854 clear_bit( 0, (void*)&(pMgmt->uCmdBusy));
3857 case IOCTL_CMD_HOSTAPD:
3860 #if WIRELESS_EXT > 8
3861 rc = hostap_ioctl(pDevice, &wrq->u.data);
3862 #else // WIRELESS_EXT > 8
3863 rc = hostap_ioctl(pDevice, (struct iw_point *) &wrq->u.data);
3864 #endif // WIRELESS_EXT > 8
3869 #if WIRELESS_EXT > 8
3870 rc = wpa_ioctl(pDevice, &wrq->u.data);
3871 #else // WIRELESS_EXT > 8
3872 rc = wpa_ioctl(pDevice, (struct iw_point *) &wrq->u.data);
3873 #endif // WIRELESS_EXT > 8
3877 return ethtool_ioctl(dev, (void *) rq->ifr_data);
3878 // All other calls are currently unsupported
3882 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
3887 if (pDevice->bCommit) {
3888 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3889 netif_stop_queue(pDevice->dev);
3890 spin_lock_irq(&pDevice->lock);
3891 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
3892 spin_unlock_irq(&pDevice->lock);
3895 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
3896 spin_lock_irq(&pDevice->lock);
3897 pDevice->bLinkPass = FALSE;
3898 memset(pMgmt->abyCurrBSSID, 0, 6);
3899 pMgmt->eCurrState = WMAC_STATE_IDLE;
3900 netif_stop_queue(pDevice->dev);
3901 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3902 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
3903 if(pDevice->bWPASuppWextEnabled !=TRUE)
3905 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
3906 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3907 spin_unlock_irq(&pDevice->lock);
3909 pDevice->bCommit = FALSE;
3916 static int ethtool_ioctl(struct net_device *dev, void *useraddr)
3920 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
3924 case ETHTOOL_GDRVINFO: {
3925 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3926 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3927 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3928 if (copy_to_user(useraddr, &info, sizeof(info)))
3938 /*------------------------------------------------------------------*/
3941 MODULE_DEVICE_TABLE(pci, device_id_table);
3943 static struct pci_driver device_driver = {
3945 id_table: device_id_table,
3946 probe: device_found1,
3947 remove: device_remove1,
3948 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
3950 suspend: viawget_suspend,
3951 resume: viawget_resume,
3956 static int __init device_init_module(void)
3961 // ret=pci_module_init(&device_driver);
3962 //ret = pcie_port_service_register(&device_driver);
3963 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
3964 ret = pci_register_driver(&device_driver);
3966 ret = pci_module_init(&device_driver);
3968 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
3971 register_reboot_notifier(&device_notifier);
3978 static void __exit device_cleanup_module(void)
3982 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
3984 unregister_reboot_notifier(&device_notifier);
3987 pci_unregister_driver(&device_driver);
3991 module_init(device_init_module);
3992 module_exit(device_cleanup_module);
3995 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
3998 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
4000 struct pci_dev *pdev = NULL;
4005 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
4006 while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
4008 pci_for_each_dev(pdev) {
4010 if(pci_dev_driver(pdev) == &device_driver) {
4011 if (pci_get_drvdata(pdev))
4012 viawget_suspend(pdev, 3);
4020 viawget_suspend(struct pci_dev *pcid, u32 state)
4022 int power_status; // to silence the compiler
4024 PSDevice pDevice=pci_get_drvdata(pcid);
4025 PSMgmtObject pMgmt = pDevice->pMgmt;
4027 netif_stop_queue(pDevice->dev);
4028 spin_lock_irq(&pDevice->lock);
4029 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
4030 pci_save_state(pcid);
4032 pci_save_state(pcid, pDevice->pci_state);
4034 del_timer(&pDevice->sTimerCommand);
4035 del_timer(&pMgmt->sTimerSecondCallback);
4036 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
4037 pDevice->uCmdDequeueIdx = 0;
4038 pDevice->uCmdEnqueueIdx = 0;
4039 pDevice->bCmdRunning = FALSE;
4040 MACbShutdown(pDevice->PortOffset);
4041 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
4042 pDevice->bLinkPass = FALSE;
4043 memset(pMgmt->abyCurrBSSID, 0, 6);
4044 pMgmt->eCurrState = WMAC_STATE_IDLE;
4045 pci_disable_device(pcid);
4046 power_status = pci_set_power_state(pcid, state);
4047 spin_unlock_irq(&pDevice->lock);
4052 viawget_resume(struct pci_dev *pcid)
4054 PSDevice pDevice=pci_get_drvdata(pcid);
4055 PSMgmtObject pMgmt = pDevice->pMgmt;
4056 int power_status; // to silence the compiler
4059 power_status = pci_set_power_state(pcid, 0);
4060 power_status = pci_enable_wake(pcid, 0, 0);
4061 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10)
4062 pci_restore_state(pcid);
4064 pci_restore_state(pcid, pDevice->pci_state);
4066 if (netif_running(pDevice->dev)) {
4067 spin_lock_irq(&pDevice->lock);
4068 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
4069 device_init_registers(pDevice, DEVICE_INIT_DXPL);
4070 if (pMgmt->sNodeDBTable[0].bActive == TRUE) { // Assoc with BSS
4071 pMgmt->sNodeDBTable[0].bActive = FALSE;
4072 pDevice->bLinkPass = FALSE;
4073 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
4074 // In Adhoc, BSS state set back to started.
4075 pMgmt->eCurrState = WMAC_STATE_STARTED;
4078 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
4079 pMgmt->eCurrState = WMAC_STATE_IDLE;
4082 init_timer(&pMgmt->sTimerSecondCallback);
4083 init_timer(&pDevice->sTimerCommand);
4084 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
4085 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
4086 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
4087 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
4088 spin_unlock_irq(&pDevice->lock);
4096 #endif //#ifndef PRIVATE_OBJ
4101 int __device_hw_reset(HANDLE pExDevice){
4102 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
4104 return MACbSoftwareReset(pDevice_info->port_offset);
4108 int __device_hw_init(HANDLE pExDevice){
4109 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
4112 pDevice = (PSDevice)kmalloc(sizeof(DEVICE_INFO), (int)GFP_ATOMIC);
4113 if (pDevice == NULL)
4116 memset(pDevice, 0, sizeof(DEVICE_INFO));
4117 pDevice_info->pWDevice = pDevice;
4118 pDevice->PortOffset = pDevice_info->port_offset;
4119 pDevice->dev = pDevice_info->dev;
4120 pDevice->pcid = pDevice_info->pcid;
4121 pDevice->chip_id = pDevice_info->chip_id;
4122 pDevice->memaddr = pDevice_info->mem_addr;
4123 pDevice->ioaddr = pDevice_info->io_addr;
4124 pDevice->io_size = pDevice_info->io_size;
4125 pDevice->nTxQueues = pDevice_info->nTxQueues;
4126 pDevice->multicast_limit = pDevice_info->multicast_limit;
4127 pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;
4128 pDevice->pMgmt = &(pDevice->sMgmtObj);
4129 MACvInitialize(pDevice->PortOffset);
4130 device_get_options(pDevice, 0 , pDevice_info->dev->name);
4131 device_set_options(pDevice);
4132 pDevice->sOpts.flags &= pDevice_info->flags;
4133 pDevice->flags = pDevice->sOpts.flags | (pDevice_info->flags & 0xFF000000UL);
4134 spin_lock_init(&(pDevice->lock));
4140 void __device_read_mac(HANDLE pExDevice, PBYTE dev_addr){
4141 PSDevice_info pDevice_info = (PSDevice_info)pExDevice;
4142 PSDevice pDevice = (PSDevice)(pDevice_info->pWDevice);
4144 MACvReadEtherAddress(pDevice->PortOffset, dev_addr);