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>
138 /*--------------------- Static Definitions -------------------------*/
139 //static int msglevel =MSG_LEVEL_DEBUG;
140 static int msglevel = MSG_LEVEL_INFO;
142 //#define PLICE_DEBUG
144 // Define module options
146 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
147 MODULE_LICENSE("GPL");
148 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
151 static int mlme_kill;
152 //static struct task_struct * mlme_task;
155 #define DEVICE_PARAM(N,D)
157 static const int N[MAX_UINTS]=OPTION_DEFAULT;\
158 MODULE_PARM(N, "1-" __MODULE_STRING(MAX_UINTS) "i");\
159 MODULE_PARM_DESC(N, D);
162 #define RX_DESC_MIN0 16
163 #define RX_DESC_MAX0 128
164 #define RX_DESC_DEF0 32
165 DEVICE_PARAM(RxDescriptors0,"Number of receive descriptors0");
167 #define RX_DESC_MIN1 16
168 #define RX_DESC_MAX1 128
169 #define RX_DESC_DEF1 32
170 DEVICE_PARAM(RxDescriptors1,"Number of receive descriptors1");
172 #define TX_DESC_MIN0 16
173 #define TX_DESC_MAX0 128
174 #define TX_DESC_DEF0 32
175 DEVICE_PARAM(TxDescriptors0,"Number of transmit descriptors0");
177 #define TX_DESC_MIN1 16
178 #define TX_DESC_MAX1 128
179 #define TX_DESC_DEF1 64
180 DEVICE_PARAM(TxDescriptors1,"Number of transmit descriptors1");
183 #define IP_ALIG_DEF 0
184 /* IP_byte_align[] is used for IP header DWORD byte aligned
185 0: indicate the IP header won't be DWORD byte aligned.(Default) .
186 1: indicate the IP header will be DWORD byte aligned.
187 In some enviroment, the IP header should be DWORD byte aligned,
188 or the packet will be droped when we receive it. (eg: IPVS)
190 DEVICE_PARAM(IP_byte_align,"Enable IP header dword aligned");
193 #define INT_WORKS_DEF 20
194 #define INT_WORKS_MIN 10
195 #define INT_WORKS_MAX 64
197 DEVICE_PARAM(int_works,"Number of packets per interrupt services");
199 #define CHANNEL_MIN 1
200 #define CHANNEL_MAX 14
201 #define CHANNEL_DEF 6
203 DEVICE_PARAM(Channel, "Channel number");
206 /* PreambleType[] is the preamble length used for transmit.
207 0: indicate allows long preamble type
208 1: indicate allows short preamble type
211 #define PREAMBLE_TYPE_DEF 1
213 DEVICE_PARAM(PreambleType, "Preamble Type");
216 #define RTS_THRESH_MIN 512
217 #define RTS_THRESH_MAX 2347
218 #define RTS_THRESH_DEF 2347
220 DEVICE_PARAM(RTSThreshold, "RTS threshold");
223 #define FRAG_THRESH_MIN 256
224 #define FRAG_THRESH_MAX 2346
225 #define FRAG_THRESH_DEF 2346
227 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
230 #define DATA_RATE_MIN 0
231 #define DATA_RATE_MAX 13
232 #define DATA_RATE_DEF 13
234 0: indicate 1 Mbps 0x02
235 1: indicate 2 Mbps 0x04
236 2: indicate 5.5 Mbps 0x0B
237 3: indicate 11 Mbps 0x16
238 4: indicate 6 Mbps 0x0c
239 5: indicate 9 Mbps 0x12
240 6: indicate 12 Mbps 0x18
241 7: indicate 18 Mbps 0x24
242 8: indicate 24 Mbps 0x30
243 9: indicate 36 Mbps 0x48
244 10: indicate 48 Mbps 0x60
245 11: indicate 54 Mbps 0x6c
246 12: indicate 72 Mbps 0x90
247 13: indicate auto rate
250 DEVICE_PARAM(ConnectionRate, "Connection data rate");
252 #define OP_MODE_DEF 0
254 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
256 /* OpMode[] is used for transmit.
257 0: indicate infrastruct mode used
258 1: indicate adhoc mode used
259 2: indicate AP mode used
264 0: indicate disable power saving mode
265 1: indicate enable power saving mode
268 #define PS_MODE_DEF 0
270 DEVICE_PARAM(PSMode, "Power saving mode");
273 #define SHORT_RETRY_MIN 0
274 #define SHORT_RETRY_MAX 31
275 #define SHORT_RETRY_DEF 8
278 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
280 #define LONG_RETRY_MIN 0
281 #define LONG_RETRY_MAX 15
282 #define LONG_RETRY_DEF 4
285 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
288 /* BasebandType[] baseband type selected
289 0: indicate 802.11a type
290 1: indicate 802.11b type
291 2: indicate 802.11g type
293 #define BBP_TYPE_MIN 0
294 #define BBP_TYPE_MAX 2
295 #define BBP_TYPE_DEF 2
297 DEVICE_PARAM(BasebandType, "baseband type");
302 0: indicate disable 802.11h
303 1: indicate enable 802.11h
306 #define X80211h_MODE_DEF 0
308 DEVICE_PARAM(b80211hEnable, "802.11h mode");
311 0: indicate disable 802.11h
312 1: indicate enable 802.11h
315 #define DIVERSITY_ANT_DEF 0
317 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
321 // Static vars definitions
325 static int device_nics =0;
326 static PSDevice pDevice_Infos =NULL;
327 static struct net_device *root_device_dev = NULL;
329 static CHIP_INFO chip_info_table[]= {
330 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
331 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
335 DEFINE_PCI_DEVICE_TABLE(device_id_table) = {
336 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
340 /*--------------------- Static Functions --------------------------*/
343 static int device_found1(struct pci_dev *pcid, const struct pci_device_id *ent);
344 static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice, PCHIP_INFO);
345 static void device_free_info(PSDevice pDevice);
346 static BOOL device_get_pci_info(PSDevice, struct pci_dev* pcid);
347 static void device_print_info(PSDevice pDevice);
348 static struct net_device_stats *device_get_stats(struct net_device *dev);
349 static void device_init_diversity_timer(PSDevice pDevice);
350 static int device_open(struct net_device *dev);
351 static int device_xmit(struct sk_buff *skb, struct net_device *dev);
352 static irqreturn_t device_intr(int irq, void*dev_instance);
353 static void device_set_multi(struct net_device *dev);
354 static int device_close(struct net_device *dev);
355 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
358 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
359 static int viawget_suspend(struct pci_dev *pcid, pm_message_t state);
360 static int viawget_resume(struct pci_dev *pcid);
361 struct notifier_block device_notifier = {
362 notifier_call: device_notify_reboot,
369 static void device_init_rd0_ring(PSDevice pDevice);
370 static void device_init_rd1_ring(PSDevice pDevice);
371 static void device_init_defrag_cb(PSDevice pDevice);
372 static void device_init_td0_ring(PSDevice pDevice);
373 static void device_init_td1_ring(PSDevice pDevice);
375 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
376 //2008-0714<Add>by Mike Liu
377 static BOOL device_release_WPADEV(PSDevice pDevice);
379 static int ethtool_ioctl(struct net_device *dev, void *useraddr);
380 static int device_rx_srv(PSDevice pDevice, UINT uIdx);
381 static int device_tx_srv(PSDevice pDevice, UINT uIdx);
382 static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pDesc);
383 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
384 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc);
385 static void device_free_td0_ring(PSDevice pDevice);
386 static void device_free_td1_ring(PSDevice pDevice);
387 static void device_free_rd0_ring(PSDevice pDevice);
388 static void device_free_rd1_ring(PSDevice pDevice);
389 static void device_free_rings(PSDevice pDevice);
390 static void device_free_frag_buf(PSDevice pDevice);
391 static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source);
394 /*--------------------- Export Variables --------------------------*/
396 /*--------------------- Export Functions --------------------------*/
400 static char* get_chip_name(int chip_id) {
402 for (i=0;chip_info_table[i].name!=NULL;i++)
403 if (chip_info_table[i].chip_id==chip_id)
405 return chip_info_table[i].name;
408 static void device_remove1(struct pci_dev *pcid)
410 PSDevice pDevice=pci_get_drvdata(pcid);
414 device_free_info(pDevice);
420 device_set_int_opt(int *opt, int val, int min, int max, int def,char* name,char* devname) {
423 else if (val<min || val>max) {
424 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n" ,
425 devname,name, min,max);
428 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n",
435 device_set_bool_opt(PU32 opt, int val,BOOL def,U32 flag, char* name,char* devname) {
438 *opt|=(def ? flag : 0);
439 else if (val<0 || val>1) {
440 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE
441 "%s: the value of parameter %s is invalid, the valid range is (0-1)\n",devname,name);
442 *opt|=(def ? flag : 0);
444 DEVICE_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: set parameter %s to %s\n",
445 devname,name , val ? "TRUE" : "FALSE");
446 *opt|=(val ? flag : 0);
451 device_get_options(PSDevice pDevice, int index, char* devname) {
453 POPTIONS pOpts = &(pDevice->sOpts);
454 pOpts->nRxDescs0=RX_DESC_DEF0;
455 pOpts->nRxDescs1=RX_DESC_DEF1;
456 pOpts->nTxDescs[0]=TX_DESC_DEF0;
457 pOpts->nTxDescs[1]=TX_DESC_DEF1;
458 pOpts->flags|=DEVICE_FLAGS_IP_ALIGN;
459 pOpts->int_works=INT_WORKS_DEF;
460 pOpts->rts_thresh=RTS_THRESH_DEF;
461 pOpts->frag_thresh=FRAG_THRESH_DEF;
462 pOpts->data_rate=DATA_RATE_DEF;
463 pOpts->channel_num=CHANNEL_DEF;
465 pOpts->flags|=DEVICE_FLAGS_PREAMBLE_TYPE;
466 pOpts->flags|=DEVICE_FLAGS_OP_MODE;
467 //pOpts->flags|=DEVICE_FLAGS_PS_MODE;
468 pOpts->short_retry=SHORT_RETRY_DEF;
469 pOpts->long_retry=LONG_RETRY_DEF;
470 pOpts->bbp_type=BBP_TYPE_DEF;
471 pOpts->flags|=DEVICE_FLAGS_80211h_MODE;
472 pOpts->flags|=DEVICE_FLAGS_DiversityANT;
478 device_set_options(PSDevice pDevice) {
480 BYTE abyBroadcastAddr[U_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
481 BYTE abySNAP_RFC1042[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
482 BYTE abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
485 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, U_ETHER_ADDR_LEN);
486 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, U_ETHER_ADDR_LEN);
487 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, U_ETHER_ADDR_LEN);
489 pDevice->uChannel = pDevice->sOpts.channel_num;
490 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
491 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
492 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
493 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
494 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
495 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
496 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
497 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
498 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
499 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
500 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
501 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE;
502 pDevice->byBBType = pDevice->sOpts.bbp_type;
503 pDevice->byPacketType = pDevice->byBBType;
506 pDevice->byAutoFBCtrl = AUTO_FB_0;
507 //pDevice->byAutoFBCtrl = AUTO_FB_1;
509 pDevice->bUpdateBBVGA = TRUE;
510 pDevice->byFOETuning = 0;
511 pDevice->wCTSDuration = 0;
512 pDevice->byPreambleType = 0;
515 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uChannel= %d\n",(INT)pDevice->uChannel);
516 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byOpMode= %d\n",(INT)pDevice->byOpMode);
517 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ePSMode= %d\n",(INT)pDevice->ePSMode);
518 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" wRTSThreshold= %d\n",(INT)pDevice->wRTSThreshold);
519 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortRetryLimit= %d\n",(INT)pDevice->byShortRetryLimit);
520 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byLongRetryLimit= %d\n",(INT)pDevice->byLongRetryLimit);
521 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byPreambleType= %d\n",(INT)pDevice->byPreambleType);
522 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortPreamble= %d\n",(INT)pDevice->byShortPreamble);
523 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uConnectionRate= %d\n",(INT)pDevice->uConnectionRate);
524 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byBBType= %d\n",(INT)pDevice->byBBType);
525 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->b11hEnable= %d\n",(INT)pDevice->b11hEnable);
526 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->bDiversityRegCtlON= %d\n",(INT)pDevice->bDiversityRegCtlON);
529 static VOID s_vCompleteCurrentMeasure (IN PSDevice pDevice, IN BYTE byResult)
532 DWORD dwDuration = 0;
535 for(ii=1;ii<8;ii++) {
536 pDevice->dwRPIs[ii] *= 255;
537 dwDuration |= *((PWORD) (pDevice->pCurrMeasureEID->sReq.abyDuration));
539 pDevice->dwRPIs[ii] /= dwDuration;
540 pDevice->abyRPIs[ii] = (BYTE) pDevice->dwRPIs[ii];
541 byRPI0 += pDevice->abyRPIs[ii];
543 pDevice->abyRPIs[0] = (0xFF - byRPI0);
545 if (pDevice->uNumOfMeasureEIDs == 0) {
546 VNTWIFIbMeasureReport( pDevice->pMgmt,
548 pDevice->pCurrMeasureEID,
551 pDevice->byCCAFraction,
555 VNTWIFIbMeasureReport( pDevice->pMgmt,
557 pDevice->pCurrMeasureEID,
560 pDevice->byCCAFraction,
563 CARDbStartMeasure (pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
571 // Initialiation of MAC & BBP registers
574 static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
579 BYTE byCCKPwrdBm = 0;
580 BYTE byOFDMPwrdBm = 0;
582 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
583 MACbShutdown(pDevice->PortOffset);
584 BBvSoftwareReset(pDevice->PortOffset);
586 if ((InitType == DEVICE_INIT_COLD) ||
587 (InitType == DEVICE_INIT_DXPL)) {
588 // Do MACbSoftwareReset in MACvInitialize
589 MACbSoftwareReset(pDevice->PortOffset);
591 pDevice->bCCK = TRUE;
592 pDevice->bAES = FALSE;
593 pDevice->bProtectMode = FALSE; //Only used in 11g type, sync with ERP IE
594 pDevice->bNonERPPresent = FALSE;
595 pDevice->bBarkerPreambleMd = FALSE;
596 pDevice->wCurrentRate = RATE_1M;
597 pDevice->byTopOFDMBasicRate = RATE_24M;
598 pDevice->byTopCCKBasicRate = RATE_1M;
600 pDevice->byRevId = 0; //Target to IF pin while programming to RF chip.
603 MACvInitialize(pDevice->PortOffset);
606 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
608 spin_lock_irq(&pDevice->lock);
609 SROMvReadAllContents(pDevice->PortOffset,pDevice->abyEEPROM);
611 spin_unlock_irq(&pDevice->lock);
615 pDevice->byMinChannel = 1;
616 pDevice->byMaxChannel = CB_MAX_CHANNEL;
619 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
620 if (byValue & EEP_ANTINV)
621 pDevice->bTxRxAntInv = TRUE;
623 pDevice->bTxRxAntInv = FALSE;
625 //printk("init_register:TxRxAntInv is %d,byValue is %d\n",pDevice->bTxRxAntInv,byValue);
628 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
629 if (byValue == 0) // if not set default is All
630 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
632 //printk("init_register:byValue is %d\n",byValue);
634 pDevice->ulDiversityNValue = 100*260;//100*SROMbyReadEmbedded(pDevice->PortOffset, 0x51);
635 pDevice->ulDiversityMValue = 100*16;//SROMbyReadEmbedded(pDevice->PortOffset, 0x52);
636 pDevice->byTMax = 1;//SROMbyReadEmbedded(pDevice->PortOffset, 0x53);
637 pDevice->byTMax2 = 4;//SROMbyReadEmbedded(pDevice->PortOffset, 0x54);
638 pDevice->ulSQ3TH = 0;//(ULONG) SROMbyReadEmbedded(pDevice->PortOffset, 0x55);
639 pDevice->byTMax3 = 64;//SROMbyReadEmbedded(pDevice->PortOffset, 0x56);
641 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
642 pDevice->byAntennaCount = 2;
643 pDevice->byTxAntennaMode = ANT_B;
644 pDevice->dwTxAntennaSel = 1;
645 pDevice->dwRxAntennaSel = 1;
646 if (pDevice->bTxRxAntInv == TRUE)
647 pDevice->byRxAntennaMode = ANT_A;
649 pDevice->byRxAntennaMode = ANT_B;
650 // chester for antenna
651 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
652 // if (pDevice->bDiversityRegCtlON)
653 if((byValue1&0x08)==0)
654 pDevice->bDiversityEnable = FALSE;//SROMbyReadEmbedded(pDevice->PortOffset, 0x50);
656 pDevice->bDiversityEnable = TRUE;
658 //printk("aux |main antenna: RxAntennaMode is %d\n",pDevice->byRxAntennaMode);
661 pDevice->bDiversityEnable = FALSE;
662 pDevice->byAntennaCount = 1;
663 pDevice->dwTxAntennaSel = 0;
664 pDevice->dwRxAntennaSel = 0;
665 if (byValue & EEP_ANTENNA_AUX) {
666 pDevice->byTxAntennaMode = ANT_A;
667 if (pDevice->bTxRxAntInv == TRUE)
668 pDevice->byRxAntennaMode = ANT_B;
670 pDevice->byRxAntennaMode = ANT_A;
672 pDevice->byTxAntennaMode = ANT_B;
673 if (pDevice->bTxRxAntInv == TRUE)
674 pDevice->byRxAntennaMode = ANT_A;
676 pDevice->byRxAntennaMode = ANT_B;
680 //printk("init registers: TxAntennaMode is %d\n",pDevice->byTxAntennaMode);
682 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
683 pDevice->bDiversityEnable,(int)pDevice->ulDiversityNValue,(int)pDevice->ulDiversityMValue,pDevice->byTMax,pDevice->byTMax2);
685 //#ifdef ZoneType_DefaultSetting
686 //2008-8-4 <add> by chester
688 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
689 if((zonetype=Config_FileOperation(pDevice,FALSE,NULL)) >= 0) { //read zonetype file ok!
690 if ((zonetype == 0)&&
691 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] !=0x00)){ //for USA
692 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
693 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
694 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :USA\n");
696 else if((zonetype == 1)&&
697 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x01)){ //for Japan
698 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
699 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
701 else if((zonetype == 2)&&
702 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x02)){ //for Europe
703 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
704 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
705 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :Europe\n");
710 if(zonetype!=pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
711 printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",zonetype,pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
713 printk("Read Zonetype file sucess,use default zonetype setting[%02x]\n",zonetype);
717 printk("Read Zonetype file fail,use default zonetype setting[%02x]\n",SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
720 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
722 if ((pDevice->byRFType & RF_EMU) != 0) {
723 // force change RevID for VT3253 emu
724 pDevice->byRevId = 0x80;
727 pDevice->byRFType &= RF_MASK;
728 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
730 if (pDevice->bZoneRegExist == FALSE) {
731 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
733 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
738 //Get Desire Power Value
739 pDevice->byCurPwr = 0xFF;
740 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
741 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
742 //byCCKPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_CCK_PWR_dBm);
744 //byOFDMPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_OFDM_PWR_dBm);
745 //printk("CCKPwrdBm is 0x%x,byOFDMPwrdBm is 0x%x\n",byCCKPwrdBm,byOFDMPwrdBm);
749 for (ii=0;ii<CB_MAX_CHANNEL_24G;ii++) {
750 pDevice->abyCCKPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_CCK_PWR_TBL));
751 if (pDevice->abyCCKPwrTbl[ii+1] == 0) {
752 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
754 pDevice->abyOFDMPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDM_PWR_TBL));
755 if (pDevice->abyOFDMPwrTbl[ii+1] == 0) {
756 pDevice->abyOFDMPwrTbl[ii+1] = pDevice->byOFDMPwrG;
758 pDevice->abyCCKDefaultPwr[ii+1] = byCCKPwrdBm;
759 pDevice->abyOFDMDefaultPwr[ii+1] = byOFDMPwrdBm;
761 //2008-8-4 <add> by chester
762 //recover 12,13 ,14channel for EUROPE by 11 channel
763 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
764 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
765 (pDevice->byOriginalZonetype == ZoneType_USA)) {
766 for(ii=11;ii<14;ii++) {
767 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
768 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
774 // Load OFDM A Power Table
775 for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
776 pDevice->abyOFDMPwrTbl[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_TBL));
777 pDevice->abyOFDMDefaultPwr[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_dBm));
779 CARDvInitChannelTable((PVOID)pDevice);
782 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
783 MACvSelectPage1(pDevice->PortOffset);
784 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
785 MACvSelectPage0(pDevice->PortOffset);
789 // use relative tx timeout and 802.11i D4
790 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
792 // set performance parameter by registry
793 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
794 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
797 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
798 // enable TSF counter
799 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
801 // initialize BBP registers
802 BBbVT3253Init(pDevice);
804 if (pDevice->bUpdateBBVGA) {
805 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
806 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
807 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
810 //printk("init registers:RxAntennaMode is %x,TxAntennaMode is %x\n",pDevice->byRxAntennaMode,pDevice->byTxAntennaMode);
812 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
813 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
815 pDevice->byCurrentCh = 0;
817 //pDevice->NetworkType = Ndis802_11Automode;
818 // Set BB and packet type at the same time.
819 // Set Short Slot Time, xIFS, and RSPINF.
820 if (pDevice->uConnectionRate == RATE_AUTO) {
821 pDevice->wCurrentRate = RATE_54M;
823 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
827 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
828 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
830 pDevice->bRadioOff = FALSE;
832 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
833 pDevice->bHWRadioOff = FALSE;
835 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
837 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
838 //2008-4-14 <add> by chester for led issue
839 #ifdef FOR_LED_ON_NOTEBOOK
840 if (BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA)){pDevice->bHWRadioOff = TRUE;}
841 if (BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA)){pDevice->bHWRadioOff = FALSE;}
844 if ( (pDevice->bRadioControlOff == TRUE)) {
845 CARDbRadioPowerOff(pDevice);
847 else CARDbRadioPowerOn(pDevice);
849 if ((BITbIsBitOn(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOff(pDevice->byRadioCtl, EEP_RADIOCTL_INV)) ||
850 (BITbIsBitOff(pDevice->byGPIO,GPIO0_DATA) && BITbIsBitOn(pDevice->byRadioCtl, EEP_RADIOCTL_INV))) {
851 pDevice->bHWRadioOff = TRUE;
854 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
855 CARDbRadioPowerOff(pDevice);
860 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
861 // get Permanent network address
862 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
863 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %02x-%02x-%02x=%02x-%02x-%02x\n",
864 pDevice->abyCurrentNetAddr[0],
865 pDevice->abyCurrentNetAddr[1],
866 pDevice->abyCurrentNetAddr[2],
867 pDevice->abyCurrentNetAddr[3],
868 pDevice->abyCurrentNetAddr[4],
869 pDevice->abyCurrentNetAddr[5]);
873 CARDvSafeResetRx(pDevice);
875 CARDvSafeResetTx(pDevice);
877 if (pDevice->byLocalID <= REV_ID_VT3253_A1) {
878 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
881 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
884 MACvReceive0(pDevice->PortOffset);
885 MACvReceive1(pDevice->PortOffset);
888 MACvStart(pDevice->PortOffset);
890 netif_stop_queue(pDevice->dev);
897 static VOID device_init_diversity_timer(PSDevice pDevice) {
899 init_timer(&pDevice->TimerSQ3Tmax1);
900 pDevice->TimerSQ3Tmax1.data = (ULONG)pDevice;
901 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
902 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
904 init_timer(&pDevice->TimerSQ3Tmax2);
905 pDevice->TimerSQ3Tmax2.data = (ULONG)pDevice;
906 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
907 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
909 init_timer(&pDevice->TimerSQ3Tmax3);
910 pDevice->TimerSQ3Tmax3.data = (ULONG)pDevice;
911 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
912 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
918 static BOOL device_release_WPADEV(PSDevice pDevice)
920 viawget_wpa_header *wpahdr;
922 // wait_queue_head_t Set_wait;
923 //send device close to wpa_supplicnat layer
924 if (pDevice->bWPADEVUp==TRUE) {
925 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
926 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
927 wpahdr->resp_ie_len = 0;
928 wpahdr->req_ie_len = 0;
929 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
930 pDevice->skb->dev = pDevice->wpadev;
931 skb_reset_mac_header(pDevice->skb);
932 pDevice->skb->pkt_type = PACKET_HOST;
933 pDevice->skb->protocol = htons(ETH_P_802_2);
934 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
935 netif_rx(pDevice->skb);
936 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
938 //wait release WPADEV
939 // init_waitqueue_head(&Set_wait);
940 // wait_event_timeout(Set_wait, ((pDevice->wpadev==NULL)&&(pDevice->skb == NULL)),5*HZ); //1s wait
941 while((pDevice->bWPADEVUp==TRUE)) {
942 set_current_state(TASK_UNINTERRUPTIBLE);
943 schedule_timeout (HZ/20); //wait 50ms
953 static const struct net_device_ops device_netdev_ops = {
954 .ndo_open = device_open,
955 .ndo_stop = device_close,
956 .ndo_do_ioctl = device_ioctl,
957 .ndo_get_stats = device_get_stats,
958 .ndo_start_xmit = device_xmit,
959 .ndo_set_multicast_list = device_set_multi,
965 device_found1(struct pci_dev *pcid, const struct pci_device_id *ent)
967 static BOOL bFirst = TRUE;
968 struct net_device* dev = NULL;
969 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
972 if (device_nics ++>= MAX_UINTS) {
973 printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
978 dev = alloc_etherdev(sizeof(DEVICE_INFO));
980 pDevice = (PSDevice) netdev_priv(dev);
983 printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
987 // Chain it all together
988 // SET_MODULE_OWNER(dev);
989 SET_NETDEV_DEV(dev, &pcid->dev);
992 printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
993 printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
997 if (!device_init_info(pcid, &pDevice, pChip_info)) {
1001 pDevice->next_module = root_device_dev;
1002 root_device_dev = dev;
1003 dev->irq = pcid->irq;
1005 if (pci_enable_device(pcid)) {
1006 device_free_info(pDevice);
1010 printk("Before get pci_info memaddr is %x\n",pDevice->memaddr);
1012 if (device_get_pci_info(pDevice,pcid) == FALSE) {
1013 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
1014 device_free_info(pDevice);
1022 //pci_read_config_byte(pcid, PCI_BASE_ADDRESS_0, &pDevice->byRevId);
1023 printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",pDevice->memaddr,pDevice->ioaddr,pDevice->io_size);
1035 for (i=0;address[i];i++)
1037 //pci_write_config_dword(pcid,address[i], 0xFFFFFFFF);
1038 pci_read_config_dword(pcid, address[i], &bar);
1039 printk("bar %d is %x\n",i,bar);
1042 printk("bar %d not implemented\n",i);
1045 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
1048 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
1049 len = len & ~(len - 1);
1051 printk("IO space: len in IO %x, BAR %d\n", len, i);
1055 len = bar & 0xFFFFFFF0;
1058 printk("len in MEM %x, BAR %d\n", len, i);
1070 pDevice->PortOffset = (DWORD)ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
1071 //pDevice->PortOffset = (DWORD)ioremap(pDevice->ioaddr & PCI_BASE_ADDRESS_IO_MASK, pDevice->io_size);
1073 if(pDevice->PortOffset == 0) {
1074 printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
1075 device_free_info(pDevice);
1082 rc = pci_request_regions(pcid, DEVICE_NAME);
1084 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
1085 device_free_info(pDevice);
1089 dev->base_addr = pDevice->ioaddr;
1093 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1094 printk("Before write: value is %x\n",value);
1095 //VNSvInPortB(pDevice->PortOffset+0x3F, 0x00);
1096 VNSvOutPortB(pDevice->PortOffset,value);
1097 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1098 printk("After write: value is %x\n",value);
1104 pDevice->PortOffset = pDevice->ioaddr;
1107 if (!MACbSoftwareReset(pDevice->PortOffset)) {
1108 printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
1109 device_free_info(pDevice);
1112 // initial to reload eeprom
1113 MACvInitialize(pDevice->PortOffset);
1114 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
1116 device_get_options(pDevice, device_nics-1, dev->name);
1117 device_set_options(pDevice);
1118 //Mask out the options cannot be set to the chip
1119 pDevice->sOpts.flags &= pChip_info->flags;
1121 //Enable the chip specified capbilities
1122 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
1123 pDevice->tx_80211 = device_dma0_tx_80211;
1124 pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;
1125 pDevice->pMgmt = &(pDevice->sMgmtObj);
1127 dev->irq = pcid->irq;
1128 dev->netdev_ops = &device_netdev_ops;
1130 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
1132 rc = register_netdev(dev);
1135 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
1136 device_free_info(pDevice);
1139 //2008-07-21-01<Add>by MikeLiu
1141 if(wpa_set_wpadev(pDevice, 1)!=0) {
1142 printk("Fail to Register WPADEV?\n");
1143 unregister_netdev(pDevice->dev);
1146 device_print_info(pDevice);
1147 pci_set_drvdata(pcid, pDevice);
1152 static void device_print_info(PSDevice pDevice)
1154 struct net_device* dev=pDevice->dev;
1156 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n",dev->name, get_chip_name(pDevice->chip_id));
1157 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
1159 dev->dev_addr[0],dev->dev_addr[1],dev->dev_addr[2],
1160 dev->dev_addr[3],dev->dev_addr[4],dev->dev_addr[5]);
1162 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx ",(ULONG) pDevice->ioaddr);
1163 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1165 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx Mem=0x%lx ",(ULONG) pDevice->ioaddr,(ULONG) pDevice->PortOffset);
1166 DEVICE_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1171 static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice,
1172 PCHIP_INFO pChip_info) {
1176 memset(*ppDevice,0,sizeof(DEVICE_INFO));
1178 if (pDevice_Infos == NULL) {
1179 pDevice_Infos =*ppDevice;
1182 for (p=pDevice_Infos;p->next!=NULL;p=p->next)
1184 p->next = *ppDevice;
1185 (*ppDevice)->prev = p;
1188 (*ppDevice)->pcid = pcid;
1189 (*ppDevice)->chip_id = pChip_info->chip_id;
1190 (*ppDevice)->io_size = pChip_info->io_size;
1191 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
1192 (*ppDevice)->multicast_limit =32;
1194 spin_lock_init(&((*ppDevice)->lock));
1199 static BOOL device_get_pci_info(PSDevice pDevice, struct pci_dev* pcid) {
1205 BYTE pci_config[256];
1209 memset(pci_config,0x00,256);
1212 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
1213 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID,&pDevice->SubSystemID);
1214 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
1215 pci_read_config_word(pcid, PCI_COMMAND, (u16 *) & (pci_cmd));
1217 pci_set_master(pcid);
1219 pDevice->memaddr = pci_resource_start(pcid,0);
1220 pDevice->ioaddr = pci_resource_start(pcid,1);
1223 // pDevice->ioaddr = pci_resource_start(pcid, 0);
1224 // pDevice->memaddr = pci_resource_start(pcid,1);
1227 cis_addr = pci_resource_start(pcid,2);
1229 pDevice->pcid = pcid;
1231 pci_read_config_byte(pcid, PCI_REG_COMMAND, &b);
1232 pci_write_config_byte(pcid, PCI_REG_COMMAND, (b|COMMAND_BUSM));
1235 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1236 //printk("max lat is %x,SubSystemID is %x\n",max_lat,pDevice->SubSystemID);
1237 //for (ii=0;ii<0xFF;ii++)
1238 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1240 //pci_write_config_word(pcid,PCI_REG_MAX_LAT,max_lat);
1241 //pci_read_config_word(pcid,PCI_REG_MAX_LAT,&max_lat);
1242 //printk("max lat is %x\n",max_lat);
1244 for (ii=0;ii<0xFF;ii++)
1246 pci_read_config_byte(pcid,ii,&value);
1247 pci_config[ii] = value;
1249 for (ii=0,j=1;ii<0x100;ii++,j++)
1253 printk("%x:",pci_config[ii]);
1258 printk("%x:",pci_config[ii]);
1265 static void device_free_info(PSDevice pDevice) {
1267 struct net_device* dev=pDevice->dev;
1270 //2008-0714-01<Add>by chester
1271 device_release_WPADEV(pDevice);
1273 //2008-07-21-01<Add>by MikeLiu
1275 if(wpa_set_wpadev(pDevice, 0)!=0)
1276 printk("unregister wpadev fail?\n");
1278 if (pDevice_Infos==NULL)
1281 for (ptr=pDevice_Infos;ptr && (ptr!=pDevice);ptr=ptr->next)
1285 if (ptr==pDevice_Infos)
1286 pDevice_Infos=ptr->next;
1288 ptr->prev->next=ptr->next;
1291 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
1296 hostap_set_hostapd(pDevice, 0, 0);
1299 unregister_netdev(dev);
1301 if (pDevice->PortOffset)
1302 iounmap((PVOID)pDevice->PortOffset);
1305 pci_release_regions(pDevice->pcid);
1309 if (pDevice->pcid) {
1310 pci_set_drvdata(pDevice->pcid,NULL);
1314 static BOOL device_init_rings(PSDevice pDevice) {
1318 /*allocate all RD/TD rings a single pool*/
1319 vir_pool = pci_alloc_consistent(pDevice->pcid,
1320 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1321 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1322 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1323 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1324 &pDevice->pool_dma);
1326 if (vir_pool == NULL) {
1327 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
1332 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1333 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1334 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1335 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1338 pDevice->aRD0Ring = vir_pool;
1339 pDevice->aRD1Ring = vir_pool +
1340 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1343 pDevice->rd0_pool_dma = pDevice->pool_dma;
1344 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1345 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1347 pDevice->tx0_bufs = pci_alloc_consistent(pDevice->pcid,
1348 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1349 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1350 CB_BEACON_BUF_SIZE +
1352 &pDevice->tx_bufs_dma0);
1354 if (pDevice->tx0_bufs == NULL) {
1355 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
1356 pci_free_consistent(pDevice->pcid,
1357 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1358 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1359 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1360 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1361 vir_pool, pDevice->pool_dma
1366 memset(pDevice->tx0_bufs, 0,
1367 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1368 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1369 CB_BEACON_BUF_SIZE +
1373 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1374 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1376 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1377 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1380 // vir_pool: pvoid type
1381 pDevice->apTD0Rings = vir_pool
1382 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1383 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1385 pDevice->apTD1Rings = vir_pool
1386 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1387 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1388 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1391 pDevice->tx1_bufs = pDevice->tx0_bufs +
1392 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1395 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1396 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1398 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1401 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1402 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1405 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1406 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1412 static void device_free_rings(PSDevice pDevice) {
1414 pci_free_consistent(pDevice->pcid,
1415 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1416 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1417 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1418 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1420 pDevice->aRD0Ring, pDevice->pool_dma
1423 if (pDevice->tx0_bufs)
1424 pci_free_consistent(pDevice->pcid,
1425 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1426 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1427 CB_BEACON_BUF_SIZE +
1429 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1433 static void device_init_rd0_ring(PSDevice pDevice) {
1435 dma_addr_t curr = pDevice->rd0_pool_dma;
1438 /* Init the RD0 ring entries */
1439 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1440 pDesc = &(pDevice->aRD0Ring[i]);
1441 pDesc->pRDInfo = alloc_rd_info();
1442 ASSERT(pDesc->pRDInfo);
1443 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1444 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1445 pDevice->dev->name);
1447 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1448 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1449 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1452 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1453 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1457 static void device_init_rd1_ring(PSDevice pDevice) {
1459 dma_addr_t curr = pDevice->rd1_pool_dma;
1462 /* Init the RD1 ring entries */
1463 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1464 pDesc = &(pDevice->aRD1Ring[i]);
1465 pDesc->pRDInfo = alloc_rd_info();
1466 ASSERT(pDesc->pRDInfo);
1467 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1468 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1469 pDevice->dev->name);
1471 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1472 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1473 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1476 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1477 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1481 static void device_init_defrag_cb(PSDevice pDevice) {
1483 PSDeFragControlBlock pDeF;
1485 /* Init the fragment ctl entries */
1486 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1487 pDeF = &(pDevice->sRxDFCB[i]);
1488 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1489 DEVICE_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
1490 pDevice->dev->name);
1493 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1494 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1500 static void device_free_rd0_ring(PSDevice pDevice) {
1503 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1504 PSRxDesc pDesc =&(pDevice->aRD0Ring[i]);
1505 PDEVICE_RD_INFO pRDInfo =pDesc->pRDInfo;
1507 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1508 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1510 dev_kfree_skb(pRDInfo->skb);
1512 kfree((PVOID)pDesc->pRDInfo);
1517 static void device_free_rd1_ring(PSDevice pDevice) {
1521 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1522 PSRxDesc pDesc=&(pDevice->aRD1Ring[i]);
1523 PDEVICE_RD_INFO pRDInfo=pDesc->pRDInfo;
1525 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1526 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1528 dev_kfree_skb(pRDInfo->skb);
1530 kfree((PVOID)pDesc->pRDInfo);
1535 static void device_free_frag_buf(PSDevice pDevice) {
1536 PSDeFragControlBlock pDeF;
1539 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1541 pDeF = &(pDevice->sRxDFCB[i]);
1544 dev_kfree_skb(pDeF->skb);
1550 static void device_init_td0_ring(PSDevice pDevice) {
1555 curr = pDevice->td0_pool_dma;
1556 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1557 pDesc = &(pDevice->apTD0Rings[i]);
1558 pDesc->pTDInfo = alloc_td_info();
1559 ASSERT(pDesc->pTDInfo);
1560 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1561 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1562 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1564 pDesc->next =&(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1565 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1566 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1569 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1570 pDevice->apTailTD[0] = pDevice->apCurrTD[0] =&(pDevice->apTD0Rings[0]);
1574 static void device_init_td1_ring(PSDevice pDevice) {
1579 /* Init the TD ring entries */
1580 curr=pDevice->td1_pool_dma;
1581 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr+=sizeof(STxDesc)) {
1582 pDesc=&(pDevice->apTD1Rings[i]);
1583 pDesc->pTDInfo = alloc_td_info();
1584 ASSERT(pDesc->pTDInfo);
1585 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1586 pDesc->pTDInfo->buf=pDevice->tx1_bufs+(i)*PKT_BUF_SZ;
1587 pDesc->pTDInfo->buf_dma=pDevice->tx_bufs_dma1+(i)*PKT_BUF_SZ;
1589 pDesc->next=&(pDevice->apTD1Rings[(i+1) % pDevice->sOpts.nTxDescs[1]]);
1590 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1591 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1594 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1595 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1600 static void device_free_td0_ring(PSDevice pDevice) {
1602 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1603 PSTxDesc pDesc=&(pDevice->apTD0Rings[i]);
1604 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1606 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1607 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,
1608 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1611 dev_kfree_skb(pTDInfo->skb);
1613 kfree((PVOID)pDesc->pTDInfo);
1617 static void device_free_td1_ring(PSDevice pDevice) {
1620 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1621 PSTxDesc pDesc=&(pDevice->apTD1Rings[i]);
1622 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1624 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1625 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1626 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1629 dev_kfree_skb(pTDInfo->skb);
1631 kfree((PVOID)pDesc->pTDInfo);
1638 /*-----------------------------------------------------------------*/
1640 static int device_rx_srv(PSDevice pDevice, UINT uIdx) {
1645 for (pRD = pDevice->pCurrRD[uIdx];
1646 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1648 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->pCurrRD = %x, works = %d\n", pRD, works);
1651 if (device_receive_frame(pDevice, pRD)) {
1652 if (!device_alloc_rx_buf(pDevice,pRD)) {
1653 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR
1654 "%s: can not allocate rx buf\n", pDevice->dev->name);
1658 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1659 pDevice->dev->last_rx = jiffies;
1662 pDevice->pCurrRD[uIdx]=pRD;
1668 static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD) {
1670 PDEVICE_RD_INFO pRDInfo=pRD->pRDInfo;
1673 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1675 //printk("device_alloc_rx_buf:skb is %x\n",pRDInfo->skb);
1677 if (pRDInfo->skb==NULL)
1679 ASSERT(pRDInfo->skb);
1680 pRDInfo->skb->dev = pDevice->dev;
1681 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
1682 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1683 *((PU32) &(pRD->m_rd0RD0)) = 0;
1685 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1686 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1687 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1688 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1695 BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
1697 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1698 if (pDeF->skb == NULL)
1701 pDeF->skb->dev = pDevice->dev;
1708 static int device_tx_srv(PSDevice pDevice, UINT uIdx) {
1714 UINT uFrameSize, uFIFOHeaderSize;
1715 PSTxBufHead pTxBufHead;
1716 struct net_device_stats* pStats = &pDevice->stats;
1717 struct sk_buff* skb;
1719 PSMgmtObject pMgmt = pDevice->pMgmt;
1722 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] >0; pTD = pTD->next) {
1724 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1729 byTsr0 = pTD->m_td0TD0.byTSR0;
1730 byTsr1 = pTD->m_td0TD0.byTSR1;
1732 //Only the status of first TD in the chain is correct
1733 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1735 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1736 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1737 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1738 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1739 // Update the statistics based on the Transmit status
1740 // now, we DO'NT check TSR0_CDH
1742 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1744 (PBYTE)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1748 BSSvUpdateNodeTxCounter(pDevice,
1750 (PBYTE)(pTD->pTDInfo->buf),
1754 if (BITbIsBitOff(byTsr1, TSR1_TERR)) {
1756 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1757 (INT)uIdx, byTsr1, byTsr0);
1759 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG) {
1760 pDevice->s802_11Counter.TransmittedFragmentCount ++;
1762 pStats->tx_packets++;
1763 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1766 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1767 (INT)uIdx, byTsr1, byTsr0);
1768 pStats->tx_errors++;
1769 pStats->tx_dropped++;
1773 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1774 if (pDevice->bEnableHostapd) {
1775 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif.. \n");
1776 skb = pTD->pTDInfo->skb;
1777 skb->dev = pDevice->apdev;
1778 skb_reset_mac_header(skb);
1779 skb->pkt_type = PACKET_OTHERHOST;
1780 //skb->protocol = htons(ETH_P_802_2);
1781 memset(skb->cb, 0, sizeof(skb->cb));
1786 if (BITbIsBitOn(byTsr1, TSR1_TERR)) {
1787 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1788 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1789 (INT)uIdx, byTsr1, byTsr0);
1792 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1793 // (INT)uIdx, byTsr1, byTsr0);
1795 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1796 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1798 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1800 skb = pTD->pTDInfo->skb;
1801 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
1802 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1803 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1804 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1806 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1807 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1808 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1809 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1810 ,(INT)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1811 pStats->tx_errors--;
1812 pStats->tx_dropped--;
1817 device_free_tx_buf(pDevice,pTD);
1818 pDevice->iTDUsed[uIdx]--;
1823 if (uIdx == TYPE_AC0DMA) {
1824 // RESERV_AC0DMA reserved for relay
1826 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1828 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
1830 if (netif_queue_stopped(pDevice->dev) && (bFull==FALSE)){
1831 netif_wake_queue(pDevice->dev);
1836 pDevice->apTailTD[uIdx] = pTD;
1842 static void device_error(PSDevice pDevice, WORD status) {
1844 if (status & ISR_FETALERR) {
1845 DEVICE_PRT(MSG_LEVEL_ERR, KERN_ERR
1846 "%s: Hardware fatal error.\n",
1847 pDevice->dev->name);
1848 netif_stop_queue(pDevice->dev);
1849 del_timer(&pDevice->sTimerCommand);
1850 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1851 pDevice->bCmdRunning = FALSE;
1852 MACbShutdown(pDevice->PortOffset);
1858 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc) {
1859 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1860 struct sk_buff* skb=pTDInfo->skb;
1862 // pre-allocated buf_dma can't be unmapped.
1863 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1864 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,skb->len,
1868 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1869 dev_kfree_skb_irq(skb);
1871 pTDInfo->skb_dma = 0;
1873 pTDInfo->byFlags = 0;
1879 VOID InitRxManagementQueue(PSDevice pDevice)
1881 pDevice->rxManeQueue.packet_num = 0;
1882 pDevice->rxManeQueue.head = pDevice->rxManeQueue.tail = 0;
1894 PSDevice pDevice = (PSDevice) Context;
1895 PSRxMgmtPacket pRxMgmtPacket;
1897 //complete(&pDevice->notify);
1898 //printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
1900 //printk("Enter MlmeThread,packet _num is %d\n",pDevice->rxManeQueue.packet_num);
1907 //down(&pDevice->mlme_semaphore);
1908 // pRxMgmtPacket = DeQueue(pDevice);
1910 spin_lock_irq(&pDevice->lock);
1911 while(pDevice->rxManeQueue.packet_num != 0)
1913 pRxMgmtPacket = DeQueue(pDevice);
1915 //DequeueManageObject(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
1916 vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
1917 //printk("packet_num is %d\n",pDevice->rxManeQueue.packet_num);
1920 spin_unlock_irq(&pDevice->lock);
1925 //printk("Before schedule thread jiffies is %x\n",jiffies);
1927 //printk("after schedule thread jiffies is %x\n",jiffies);
1930 //printk("i is %d\n",i);
1940 static int device_open(struct net_device *dev) {
1941 PSDevice pDevice=(PSDevice) netdev_priv(dev);
1943 #ifdef WPA_SM_Transtatus
1944 extern SWPAResult wpa_Result;
1947 pDevice->rx_buf_sz = PKT_BUF_SZ;
1948 if (!device_init_rings(pDevice)) {
1951 //2008-5-13 <add> by chester
1952 i=request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1955 //printk("DEBUG1\n");
1956 #ifdef WPA_SM_Transtatus
1957 memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
1958 wpa_Result.proto = 0;
1959 wpa_Result.key_mgmt = 0;
1960 wpa_Result.eap_type = 0;
1961 wpa_Result.authenticated = FALSE;
1962 pDevice->fWPA_Authened = FALSE;
1964 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
1965 device_init_rd0_ring(pDevice);
1966 device_init_rd1_ring(pDevice);
1967 device_init_defrag_cb(pDevice);
1968 device_init_td0_ring(pDevice);
1969 device_init_td1_ring(pDevice);
1970 // VNTWIFIvSet11h(pDevice->pMgmt, pDevice->b11hEnable);
1973 if (pDevice->bDiversityRegCtlON) {
1974 device_init_diversity_timer(pDevice);
1976 vMgrObjectInit(pDevice);
1977 vMgrTimerInit(pDevice);
1981 tasklet_init (&pDevice->RxMngWorkItem,(void *)MngWorkItem,(unsigned long )pDevice);
1984 InitRxManagementQueue(pDevice);
1986 mlme_task = kthread_run(MlmeThread,(void *) pDevice, "MLME");
1987 if (IS_ERR(mlme_task)) {
1988 printk("thread create fail\n");
1998 pDevice->MLMEThr_pid = kernel_thread(MlmeThread, pDevice, CLONE_VM);
1999 if (pDevice->MLMEThr_pid <0 )
2001 printk("unable start thread MlmeThread\n");
2006 //printk("thread id is %d\n",pDevice->MLMEThr_pid);
2007 //printk("Create thread time is %x\n",jiffies);
2008 //wait_for_completion(&pDevice->notify);
2013 // if (( SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL)&0x06)==0x04)
2015 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
2016 device_init_registers(pDevice, DEVICE_INIT_COLD);
2017 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
2018 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, U_ETHER_ADDR_LEN);
2019 device_set_multi(pDevice->dev);
2021 // Init for Key Management
2022 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
2023 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
2025 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2027 pDevice->bwextstep0 = FALSE;
2028 pDevice->bwextstep1 = FALSE;
2029 pDevice->bwextstep2 = FALSE;
2030 pDevice->bwextstep3 = FALSE;
2032 pDevice->bwextcount=0;
2033 pDevice->bWPASuppWextEnabled = FALSE;
2035 pDevice->byReAssocCount = 0;
2036 pDevice->bWPADEVUp = FALSE;
2037 // Patch: if WEP key already set by iwconfig but device not yet open
2038 if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) {
2039 KeybSetDefaultKey(&(pDevice->sKey),
2040 (DWORD)(pDevice->byKeyIndex | (1 << 31)),
2041 pDevice->uKeyLength,
2045 pDevice->PortOffset,
2048 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
2051 //printk("DEBUG2\n");
2054 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
2055 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2057 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2058 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
2061 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
2062 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_SSID, NULL);
2064 pDevice->flags |=DEVICE_FLAGS_OPENED;
2066 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
2071 static int device_close(struct net_device *dev) {
2072 PSDevice pDevice=(PSDevice) netdev_priv(dev);
2073 PSMgmtObject pMgmt = pDevice->pMgmt;
2079 //2007-1121-02<Add>by EinsnLiu
2080 if (pDevice->bLinkPass) {
2081 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2085 del_timer(&pDevice->sTimerTxData);
2087 del_timer(&pDevice->sTimerCommand);
2088 del_timer(&pMgmt->sTimerSecondCallback);
2089 if (pDevice->bDiversityRegCtlON) {
2090 del_timer(&pDevice->TimerSQ3Tmax1);
2091 del_timer(&pDevice->TimerSQ3Tmax2);
2092 del_timer(&pDevice->TimerSQ3Tmax3);
2096 tasklet_kill(&pDevice->RxMngWorkItem);
2098 netif_stop_queue(dev);
2099 pDevice->bCmdRunning = FALSE;
2100 MACbShutdown(pDevice->PortOffset);
2101 MACbSoftwareReset(pDevice->PortOffset);
2102 CARDbRadioPowerOff(pDevice);
2104 pDevice->bLinkPass = FALSE;
2105 memset(pMgmt->abyCurrBSSID, 0, 6);
2106 pMgmt->eCurrState = WMAC_STATE_IDLE;
2107 device_free_td0_ring(pDevice);
2108 device_free_td1_ring(pDevice);
2109 device_free_rd0_ring(pDevice);
2110 device_free_rd1_ring(pDevice);
2111 device_free_frag_buf(pDevice);
2112 device_free_rings(pDevice);
2113 BSSvClearNodeDBTable(pDevice, 0);
2114 free_irq(dev->irq, dev);
2115 pDevice->flags &=(~DEVICE_FLAGS_OPENED);
2116 //2008-0714-01<Add>by chester
2117 device_release_WPADEV(pDevice);
2119 //tasklet_kill(&pDevice->RxMngWorkItem);
2121 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close.. \n");
2127 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
2128 PSDevice pDevice=netdev_priv(dev);
2133 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
2134 spin_lock_irq(&pDevice->lock);
2136 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2137 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
2138 dev_kfree_skb_irq(skb);
2139 spin_unlock_irq(&pDevice->lock);
2143 if (pDevice->bStopTx0Pkt == TRUE) {
2144 dev_kfree_skb_irq(skb);
2145 spin_unlock_irq(&pDevice->lock);
2149 cbMPDULen = skb->len;
2152 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
2154 spin_unlock_irq(&pDevice->lock);
2162 BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, UINT uNodeIndex) {
2163 PSMgmtObject pMgmt = pDevice->pMgmt;
2164 PSTxDesc pHeadTD, pLastTD;
2165 UINT cbFrameBodySize;
2168 BOOL bNeedEncryption = FALSE;
2169 PSKeyItem pTransmitKey = NULL;
2173 // BYTE byKeyIndex = 0;
2176 if (pDevice->bStopTx0Pkt == TRUE) {
2177 dev_kfree_skb_irq(skb);
2181 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2182 dev_kfree_skb_irq(skb);
2183 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
2187 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2188 if (pDevice->uAssocCount == 0) {
2189 dev_kfree_skb_irq(skb);
2190 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
2195 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
2197 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2199 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2200 cbFrameBodySize = skb->len - U_HEADER_LEN;
2203 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2204 cbFrameBodySize += 8;
2206 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2208 if ( uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
2209 dev_kfree_skb_irq(skb);
2212 byPktTyp = (BYTE)pDevice->byPacketType;
2215 if (pDevice->bFixRate) {
2216 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2217 if (pDevice->uConnectionRate >= RATE_11M) {
2218 pDevice->wCurrentRate = RATE_11M;
2220 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2223 if (pDevice->uConnectionRate >= RATE_54M)
2224 pDevice->wCurrentRate = RATE_54M;
2226 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2230 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2234 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2235 pDevice->byPreambleType = pDevice->byShortPreamble;
2238 pDevice->byPreambleType = PREAMBLE_LONG;
2241 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2244 if (pDevice->wCurrentRate <= RATE_11M) {
2245 byPktTyp = PK_TYPE_11B;
2246 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2247 byPktTyp = PK_TYPE_11A;
2249 if (pDevice->bProtectMode == TRUE) {
2250 byPktTyp = PK_TYPE_11GB;
2252 byPktTyp = PK_TYPE_11GA;
2256 if (pDevice->bEncryptionEnable == TRUE)
2257 bNeedEncryption = TRUE;
2259 if (pDevice->bEnableHostWEP) {
2260 pTransmitKey = &STempKey;
2261 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2262 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2263 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2264 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2265 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2266 memcpy(pTransmitKey->abyKey,
2267 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2268 pTransmitKey->uKeyLength
2271 vGenerateFIFOHeader(pDevice, byPktTyp, pDevice->pbyTmpBuff, bNeedEncryption,
2272 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
2273 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2278 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2280 MACbPSWakeup(pDevice->PortOffset);
2283 pDevice->bPWBitOn = FALSE;
2286 for (ii = 0; ii < uMACfragNum; ii++) {
2287 // Poll Transmit the adapter
2289 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2291 if (ii == (uMACfragNum - 1))
2293 pHeadTD = pHeadTD->next;
2296 // Save the information needed by the tx interrupt handler
2297 // to complete the Send request
2298 pLastTD->pTDInfo->skb = skb;
2299 pLastTD->pTDInfo->byFlags = 0;
2300 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2302 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
2304 MACvTransmit0(pDevice->PortOffset);
2310 //TYPE_AC0DMA data tx
2311 static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
2312 PSDevice pDevice=netdev_priv(dev);
2314 PSMgmtObject pMgmt = pDevice->pMgmt;
2315 PSTxDesc pHeadTD, pLastTD;
2316 UINT uNodeIndex = 0;
2317 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2319 UINT uMACfragNum = 1;
2320 UINT cbFrameBodySize;
2323 BOOL bNeedEncryption = FALSE;
2324 PSKeyItem pTransmitKey = NULL;
2327 BOOL bTKIP_UseGTK = FALSE;
2328 BOOL bNeedDeAuth = FALSE;
2330 BOOL bNodeExist = FALSE;
2334 spin_lock_irq(&pDevice->lock);
2335 if (pDevice->bLinkPass == FALSE) {
2336 dev_kfree_skb_irq(skb);
2337 spin_unlock_irq(&pDevice->lock);
2341 if (pDevice->bStopDataPkt) {
2342 dev_kfree_skb_irq(skb);
2343 spin_unlock_irq(&pDevice->lock);
2348 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2349 if (pDevice->uAssocCount == 0) {
2350 dev_kfree_skb_irq(skb);
2351 spin_unlock_irq(&pDevice->lock);
2354 if (IS_MULTICAST_ADDRESS((PBYTE)(skb->data))) {
2357 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2358 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2359 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2361 pMgmt->abyPSTxMap[0] |= byMask[0];
2362 spin_unlock_irq(&pDevice->lock);
2366 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
2367 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2368 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2369 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2371 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2372 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2373 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2374 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2375 spin_unlock_irq(&pDevice->lock);
2379 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2380 pDevice->byPreambleType = pDevice->byShortPreamble;
2383 pDevice->byPreambleType = PREAMBLE_LONG;
2390 if (bNodeExist == FALSE) {
2391 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2392 dev_kfree_skb_irq(skb);
2393 spin_unlock_irq(&pDevice->lock);
2398 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
2400 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2403 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2404 cbFrameBodySize = skb->len - U_HEADER_LEN;
2406 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2407 cbFrameBodySize += 8;
2411 if (pDevice->bEncryptionEnable == TRUE) {
2412 bNeedEncryption = TRUE;
2415 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2416 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2417 pbyBSSID = pDevice->abyBSSID;
2419 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2421 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2422 bTKIP_UseGTK = TRUE;
2423 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2427 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2430 }else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2432 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2433 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2434 for (ii = 0; ii< 6; ii++)
2435 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2436 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2439 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE)
2443 pbyBSSID = pDevice->abyBroadcastAddr;
2444 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2445 pTransmitKey = NULL;
2446 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2447 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2450 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2452 bTKIP_UseGTK = TRUE;
2453 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2458 if (pDevice->bEnableHostWEP) {
2459 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2460 if (pDevice->bEncryptionEnable == TRUE) {
2461 pTransmitKey = &STempKey;
2462 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2463 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2464 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2465 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2466 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2467 memcpy(pTransmitKey->abyKey,
2468 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2469 pTransmitKey->uKeyLength
2474 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2476 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2477 DEVICE_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
2478 dev_kfree_skb_irq(skb);
2479 spin_unlock_irq(&pDevice->lock);
2483 if (pTransmitKey != NULL) {
2484 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2485 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2486 uMACfragNum = 1; //WEP256 doesn't support fragment
2490 byPktTyp = (BYTE)pDevice->byPacketType;
2492 if (pDevice->bFixRate) {
2494 printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n",pDevice->eCurrentPHYType,pDevice->uConnectionRate);
2497 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2498 if (pDevice->uConnectionRate >= RATE_11M) {
2499 pDevice->wCurrentRate = RATE_11M;
2501 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2504 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2505 (pDevice->uConnectionRate <= RATE_6M)) {
2506 pDevice->wCurrentRate = RATE_6M;
2508 if (pDevice->uConnectionRate >= RATE_54M)
2509 pDevice->wCurrentRate = RATE_54M;
2511 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2515 pDevice->byACKRate = (BYTE) pDevice->wCurrentRate;
2516 pDevice->byTopCCKBasicRate = RATE_1M;
2517 pDevice->byTopOFDMBasicRate = RATE_6M;
2521 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2522 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2523 pDevice->wCurrentRate = RATE_1M;
2524 pDevice->byACKRate = RATE_1M;
2525 pDevice->byTopCCKBasicRate = RATE_1M;
2526 pDevice->byTopOFDMBasicRate = RATE_6M;
2528 pDevice->wCurrentRate = RATE_6M;
2529 pDevice->byACKRate = RATE_6M;
2530 pDevice->byTopCCKBasicRate = RATE_1M;
2531 pDevice->byTopOFDMBasicRate = RATE_6M;
2535 VNTWIFIvGetTxRate( pDevice->pMgmt,
2536 pDevice->sTxEthHeader.abyDstAddr,
2537 &(pDevice->wCurrentRate),
2538 &(pDevice->byACKRate),
2539 &(pDevice->byTopCCKBasicRate),
2540 &(pDevice->byTopOFDMBasicRate));
2543 printk("auto rate:Rate : %d,AckRate:%d,TopCCKRate:%d,TopOFDMRate:%d\n",
2544 pDevice->wCurrentRate,pDevice->byACKRate,
2545 pDevice->byTopCCKBasicRate,pDevice->byTopOFDMBasicRate);
2551 pDevice->wCurrentRate = 11;
2552 pDevice->byACKRate = 8;
2553 pDevice->byTopCCKBasicRate = 3;
2554 pDevice->byTopOFDMBasicRate = 8;
2561 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2563 if (pDevice->wCurrentRate <= RATE_11M) {
2564 byPktTyp = PK_TYPE_11B;
2565 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2566 byPktTyp = PK_TYPE_11A;
2568 if (pDevice->bProtectMode == TRUE) {
2569 byPktTyp = PK_TYPE_11GB;
2571 byPktTyp = PK_TYPE_11GA;
2575 //#ifdef PLICE_DEBUG
2576 // printk("FIX RATE:CurrentRate is %d");
2579 if (bNeedEncryption == TRUE) {
2580 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2581 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2582 bNeedEncryption = FALSE;
2583 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2584 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2585 if (pTransmitKey == NULL) {
2586 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2589 if (bTKIP_UseGTK == TRUE) {
2590 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2593 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2594 bNeedEncryption = TRUE;
2599 if (pDevice->byCntMeasure == 2) {
2601 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2604 if (pDevice->bEnableHostWEP) {
2605 if ((uNodeIndex != 0) &&
2606 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2607 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2608 bNeedEncryption = TRUE;
2613 if (pTransmitKey == NULL) {
2614 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2615 dev_kfree_skb_irq(skb);
2616 spin_unlock_irq(&pDevice->lock);
2624 //if (skb->len == 98)
2626 // printk("ping:len is %d\n");
2629 vGenerateFIFOHeader(pDevice, byPktTyp, pDevice->pbyTmpBuff, bNeedEncryption,
2630 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2631 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2636 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2638 MACbPSWakeup(pDevice->PortOffset);
2640 pDevice->bPWBitOn = FALSE;
2643 for (ii = 0; ii < uMACfragNum; ii++) {
2644 // Poll Transmit the adapter
2646 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2648 if (ii == uMACfragNum - 1)
2650 pHeadTD = pHeadTD->next;
2653 // Save the information needed by the tx interrupt handler
2654 // to complete the Send request
2655 pLastTD->pTDInfo->skb = skb;
2656 pLastTD->pTDInfo->byFlags = 0;
2657 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2659 pDevice->nTxDataTimeCout=0; //2008-8-21 chester <add> for send null packet
2661 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1) {
2662 netif_stop_queue(dev);
2665 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2666 //#ifdef PLICE_DEBUG
2667 if (pDevice->bFixRate)
2669 printk("FixRate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2673 //printk("Auto Rate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2678 BYTE Protocol_Version; //802.1x Authentication
2679 BYTE Packet_Type; //802.1x Authentication
2680 BYTE Descriptor_type;
2682 BOOL bTxeapol_key = FALSE;
2683 Protocol_Version = skb->data[U_HEADER_LEN];
2684 Packet_Type = skb->data[U_HEADER_LEN+1];
2685 Descriptor_type = skb->data[U_HEADER_LEN+1+1+2];
2686 Key_info = (skb->data[U_HEADER_LEN+1+1+2+1] << 8)|(skb->data[U_HEADER_LEN+1+1+2+2]);
2687 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2688 if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
2689 (Packet_Type==3)) { //802.1x OR eapol-key challenge frame transfer
2690 bTxeapol_key = TRUE;
2691 if((Descriptor_type==254)||(Descriptor_type==2)) { //WPA or RSN
2692 if(!(Key_info & BIT3) && //group-key challenge
2693 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2694 pDevice->fWPA_Authened = TRUE;
2695 if(Descriptor_type==254)
2699 printk("Authentication completed!!\n");
2706 MACvTransmitAC0(pDevice->PortOffset);
2707 // DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0:pDevice->apCurrTD= %p\n", pHeadTD);
2709 dev->trans_start = jiffies;
2711 spin_unlock_irq(&pDevice->lock);
2716 static irqreturn_t device_intr(int irq, void *dev_instance) {
2717 struct net_device* dev=dev_instance;
2718 PSDevice pDevice=(PSDevice) netdev_priv(dev);
2721 DWORD dwMIBCounter=0;
2722 PSMgmtObject pMgmt = pDevice->pMgmt;
2723 BYTE byOrgPageSel=0;
2730 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2732 if (pDevice->dwIsr == 0)
2733 return IRQ_RETVAL(handled);
2735 if (pDevice->dwIsr == 0xffffffff) {
2736 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
2737 return IRQ_RETVAL(handled);
2740 // 2008-05-21 <mark> by Richardtai, we can't read RSSI here, because no packet bound with RSSI
2742 if ((BITbIsBitOn(pDevice->dwIsr, ISR_RXDMA0)) &&
2743 (pDevice->byLocalID != REV_ID_VT3253_B0) &&
2744 (pDevice->bBSSIDFilter == TRUE)) {
2746 //BBbReadEmbeded(pDevice->PortOffset, 0x3E, &byRSSI);
2747 //pDevice->uCurrRSSI = byRSSI;
2752 MACvIntDisable(pDevice->PortOffset);
2753 spin_lock_irq(&pDevice->lock);
2755 //Make sure current page is 0
2756 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2757 if (byOrgPageSel == 1) {
2758 MACvSelectPage0(pDevice->PortOffset);
2763 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2765 // Must do this after doing rx/tx, cause ISR bit is slow
2766 // than RD/TD write back
2767 // update ISR counter
2768 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2769 while (pDevice->dwIsr != 0) {
2771 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2772 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2774 if (pDevice->dwIsr & ISR_FETALERR){
2775 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR \n");
2776 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2777 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2778 device_error(pDevice, pDevice->dwIsr);
2781 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2783 if (BITbIsBitOn(pDevice->dwIsr, ISR_MEASURESTART)) {
2784 // 802.11h measure start
2785 pDevice->byOrgChannel = pDevice->byCurrentCh;
2786 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2787 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2788 MACvSelectPage1(pDevice->PortOffset);
2789 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2790 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2791 MACvSelectPage0(pDevice->PortOffset);
2793 // WCMDbFlushCommandQueue(pDevice->pMgmt, TRUE);
2794 if (CARDbSetChannel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel) == TRUE) {
2795 pDevice->bMeasureInProgress = TRUE;
2796 MACvSelectPage1(pDevice->PortOffset);
2797 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2798 MACvSelectPage0(pDevice->PortOffset);
2799 pDevice->byBasicMap = 0;
2800 pDevice->byCCAFraction = 0;
2801 for(ii=0;ii<8;ii++) {
2802 pDevice->dwRPIs[ii] = 0;
2805 // can not measure because set channel fail
2806 // WCMDbResetCommandQueue(pDevice->pMgmt);
2807 // clear measure control
2808 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2809 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2810 MACvSelectPage1(pDevice->PortOffset);
2811 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2812 MACvSelectPage0(pDevice->PortOffset);
2815 if (BITbIsBitOn(pDevice->dwIsr, ISR_MEASUREEND)) {
2816 // 802.11h measure end
2817 pDevice->bMeasureInProgress = FALSE;
2818 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2819 MACvSelectPage1(pDevice->PortOffset);
2820 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2821 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2822 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2823 pDevice->byBasicMap |= (byData >> 4);
2824 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2825 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2826 // clear measure control
2827 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2828 MACvSelectPage0(pDevice->PortOffset);
2829 CARDbSetChannel(pDevice, pDevice->byOrgChannel);
2830 // WCMDbResetCommandQueue(pDevice->pMgmt);
2831 MACvSelectPage1(pDevice->PortOffset);
2832 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2833 MACvSelectPage0(pDevice->PortOffset);
2834 if (BITbIsBitOn(byData, MSRCTL_FINISH)) {
2836 s_vCompleteCurrentMeasure(pDevice, 0);
2838 // can not measure because not ready before end of measure time
2839 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2842 if (BITbIsBitOn(pDevice->dwIsr, ISR_QUIETSTART)) {
2845 } while (CARDbStartQuiet(pDevice) == FALSE);
2849 if (pDevice->dwIsr & ISR_TBTT) {
2850 if (pDevice->bEnableFirstQuiet == TRUE) {
2851 pDevice->byQuietStartCount--;
2852 if (pDevice->byQuietStartCount == 0) {
2853 pDevice->bEnableFirstQuiet = FALSE;
2854 MACvSelectPage1(pDevice->PortOffset);
2855 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2856 MACvSelectPage0(pDevice->PortOffset);
2859 if ((pDevice->bChannelSwitch == TRUE) &&
2860 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
2861 pDevice->byChannelSwitchCount--;
2862 if (pDevice->byChannelSwitchCount == 0) {
2863 pDevice->bChannelSwitch = FALSE;
2864 CARDbSetChannel(pDevice, pDevice->byNewChannel);
2865 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2866 MACvSelectPage1(pDevice->PortOffset);
2867 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2868 MACvSelectPage0(pDevice->PortOffset);
2869 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2873 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2874 //pDevice->bBeaconSent = FALSE;
2876 if ((pDevice->bUpdateBBVGA) && (pDevice->bLinkPass == TRUE) && (pDevice->uCurrRSSI != 0)) {
2879 RFvRSSITodBm(pDevice, (BYTE) pDevice->uCurrRSSI, &ldBm);
2880 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
2881 if (ldBm < pDevice->ldBmThreshold[ii]) {
2882 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2886 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2887 pDevice->uBBVGADiffCount++;
2888 if (pDevice->uBBVGADiffCount == 1) {
2889 // first VGA diff gain
2890 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2891 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2892 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2894 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2895 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2896 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2897 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2900 pDevice->uBBVGADiffCount = 1;
2905 pDevice->bBeaconSent = FALSE;
2906 if (pDevice->bEnablePSMode) {
2907 PSbIsNextTBTTWakeUp((HANDLE)pDevice);
2910 if ((pDevice->eOPMode == OP_MODE_AP) ||
2911 (pDevice->eOPMode == OP_MODE_ADHOC)) {
2913 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2914 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2917 if (pDevice->eOPMode == OP_MODE_ADHOC && pDevice->pMgmt->wCurrATIMWindow > 0) {
2918 // todo adhoc PS mode
2923 if (pDevice->dwIsr & ISR_BNTX) {
2925 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2926 pDevice->bIsBeaconBufReadySet = FALSE;
2927 pDevice->cbBeaconBufReadySetCnt = 0;
2930 if (pDevice->eOPMode == OP_MODE_AP) {
2931 if(pMgmt->byDTIMCount > 0) {
2932 pMgmt->byDTIMCount --;
2933 pMgmt->sNodeDBTable[0].bRxPSPoll = FALSE;
2936 if(pMgmt->byDTIMCount == 0) {
2937 // check if mutltcast tx bufferring
2938 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2939 pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE;
2940 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2944 pDevice->bBeaconSent = TRUE;
2946 if (pDevice->bChannelSwitch == TRUE) {
2947 pDevice->byChannelSwitchCount--;
2948 if (pDevice->byChannelSwitchCount == 0) {
2949 pDevice->bChannelSwitch = FALSE;
2950 CARDbSetChannel(pDevice, pDevice->byNewChannel);
2951 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2952 MACvSelectPage1(pDevice->PortOffset);
2953 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2954 MACvSelectPage0(pDevice->PortOffset);
2955 //VNTWIFIbSendBeacon(pDevice->pMgmt);
2956 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2962 if (pDevice->dwIsr & ISR_RXDMA0) {
2963 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2965 if (pDevice->dwIsr & ISR_RXDMA1) {
2966 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2968 if (pDevice->dwIsr & ISR_TXDMA0){
2969 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2971 if (pDevice->dwIsr & ISR_AC0DMA){
2972 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2974 if (pDevice->dwIsr & ISR_SOFTTIMER) {
2977 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2978 if (pDevice->eOPMode == OP_MODE_AP) {
2979 if (pDevice->bShortSlotTime)
2980 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2982 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2984 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2985 pDevice->byCntMeasure = 0;
2988 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2990 MACvReceive0(pDevice->PortOffset);
2991 MACvReceive1(pDevice->PortOffset);
2993 if (max_count>pDevice->sOpts.int_works)
2997 if (byOrgPageSel == 1) {
2998 MACvSelectPage1(pDevice->PortOffset);
3001 spin_unlock_irq(&pDevice->lock);
3002 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3004 return IRQ_RETVAL(handled);
3008 static unsigned const ethernet_polynomial = 0x04c11db7U;
3009 static inline u32 ether_crc(int length, unsigned char *data)
3013 while(--length >= 0) {
3014 unsigned char current_octet = *data++;
3016 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
3018 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
3024 //2008-8-4 <add> by chester
3025 static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source)
3028 int source_len = strlen(source);
3031 strcat(buf1, string);
3033 source+=strlen(buf1);
3035 memcpy(dest,source,source_len-strlen(buf1));
3039 int Config_FileOperation(PSDevice pDevice,BOOL fwrite,unsigned char *Parameter) {
3040 UCHAR *config_path=CONFIG_PATH;
3042 UCHAR tmpbuffer[20];
3043 struct file *filp=NULL;
3044 mm_segment_t old_fs = get_fs();
3045 //int oldfsuid=0,oldfsgid=0;
3050 /* Can't do this anymore, so we rely on correct filesystem permissions:
3051 //Make sure a caller can read or write power as root
3052 oldfsuid=current->cred->fsuid;
3053 oldfsgid=current->cred->fsgid;
3054 current->cred->fsuid = 0;
3055 current->cred->fsgid = 0;
3059 filp = filp_open(config_path, O_RDWR, 0);
3061 printk("Config_FileOperation:open file fail?\n");
3066 if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
3067 printk("file %s cann't readable or writable?\n",config_path);
3072 buffer = (UCHAR *)kmalloc(1024, GFP_KERNEL);
3074 printk("alllocate mem for file fail?\n");
3079 if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
3080 printk("read file error?\n");
3085 if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=TRUE) {
3086 printk("get parameter error?\n");
3091 if(memcmp(tmpbuffer,"USA",3)==0) {
3092 result=ZoneType_USA;
3094 else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
3095 result=ZoneType_Japan;
3097 else if(memcmp(tmpbuffer,"EUROPE",5)==0) {
3098 result=ZoneType_Europe;
3102 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
3109 if(filp_close(filp,NULL))
3110 printk("Config_FileOperation:close file fail\n");
3116 current->cred->fsuid=oldfsuid;
3117 current->cred->fsgid=oldfsgid;
3125 static void device_set_multi(struct net_device *dev) {
3126 PSDevice pDevice = (PSDevice) netdev_priv(dev);
3128 PSMgmtObject pMgmt = pDevice->pMgmt;
3131 struct dev_mc_list *mclist;
3134 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
3136 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
3137 DEVICE_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
3138 /* Unconditionally log net taps. */
3139 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
3141 else if ((dev->mc_count > pDevice->multicast_limit)
3142 || (dev->flags & IFF_ALLMULTI)) {
3143 MACvSelectPage1(pDevice->PortOffset);
3144 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
3145 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
3146 MACvSelectPage0(pDevice->PortOffset);
3147 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3150 memset(mc_filter, 0, sizeof(mc_filter));
3151 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
3152 i++, mclist = mclist->next) {
3153 int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
3154 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
3156 MACvSelectPage1(pDevice->PortOffset);
3157 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
3158 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
3159 MACvSelectPage0(pDevice->PortOffset);
3160 pDevice->byRxMode &= ~(RCR_UNICAST);
3161 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3164 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3165 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
3166 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3167 pDevice->byRxMode &= ~(RCR_UNICAST);
3170 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
3171 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode );
3175 static struct net_device_stats *device_get_stats(struct net_device *dev) {
3176 PSDevice pDevice=(PSDevice) netdev_priv(dev);
3178 return &pDevice->stats;
3183 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
3184 PSDevice pDevice = (PSDevice)netdev_priv(dev);
3186 struct iwreq *wrq = (struct iwreq *) rq;
3188 PSMgmtObject pMgmt = pDevice->pMgmt;
3192 if (pMgmt == NULL) {
3200 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
3203 case SIOCGIWNWID: //0x8b03 support
3204 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3205 rc = iwctl_giwnwid(dev, NULL, &(wrq->u.nwid), NULL);
3211 // Set frequency/channel
3213 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
3216 // Get frequency/channel
3218 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
3221 // Set desired network name (ESSID)
3225 char essid[IW_ESSID_MAX_SIZE+1];
3226 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
3230 if (copy_from_user(essid, wrq->u.essid.pointer,
3231 wrq->u.essid.length)) {
3235 rc = iwctl_siwessid(dev, NULL,
3236 &(wrq->u.essid), essid);
3241 // Get current network name (ESSID)
3245 char essid[IW_ESSID_MAX_SIZE+1];
3246 if (wrq->u.essid.pointer)
3247 rc = iwctl_giwessid(dev, NULL,
3248 &(wrq->u.essid), essid);
3249 if (copy_to_user(wrq->u.essid.pointer,
3251 wrq->u.essid.length) )
3258 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3262 // Get current Access Point (BSSID)
3264 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3268 // Set desired station name
3270 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
3274 // Get current station name
3276 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
3280 // Set the desired bit-rate
3282 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3285 // Get the current bit-rate
3288 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3291 // Set the desired RTS threshold
3294 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
3297 // Get the current RTS threshold
3300 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
3303 // Set the desired fragmentation threshold
3306 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
3309 // Get the current fragmentation threshold
3312 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
3315 // Set mode of operation
3317 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
3320 // Get mode of operation
3322 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
3325 // Set WEP keys and mode
3328 char abyKey[WLAN_WEP232_KEYLEN];
3330 if (wrq->u.encoding.pointer) {
3333 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
3337 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
3338 if (copy_from_user(abyKey,
3339 wrq->u.encoding.pointer,
3340 wrq->u.encoding.length)) {
3344 } else if (wrq->u.encoding.length != 0) {
3348 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3352 // Get the WEP keys and mode
3355 if (!capable(CAP_NET_ADMIN)) {
3360 char abyKey[WLAN_WEP232_KEYLEN];
3362 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3364 if (wrq->u.encoding.pointer) {
3365 if (copy_to_user(wrq->u.encoding.pointer,
3367 wrq->u.encoding.length))
3373 // Get the current Tx-Power
3375 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3380 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3386 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
3391 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
3394 // Get range of parameters
3398 struct iw_range range;
3400 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *) &range);
3401 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
3409 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
3415 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
3421 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
3425 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
3431 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
3433 if (wrq->u.data.pointer) {
3434 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
3436 if (copy_to_user(wrq->u.data.pointer,
3438 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
3451 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3458 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3462 #endif // WIRELESS_SPY
3465 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
3468 if(wrq->u.data.pointer) {
3469 wrq->u.data.length = sizeof(iwctl_private_args) / sizeof( iwctl_private_args[0]);
3471 if(copy_to_user(wrq->u.data.pointer,
3472 (u_char *) iwctl_private_args,
3473 sizeof(iwctl_private_args)))
3480 //2008-0409-07, <Add> by Einsn Liu
3481 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3483 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
3484 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
3488 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH \n");
3489 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
3493 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE \n");
3494 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3498 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE \n");
3499 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3502 case SIOCSIWENCODEEXT:
3504 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
3505 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
3506 if(wrq->u.encoding.pointer){
3507 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1);
3508 if(wrq->u.encoding.length > (sizeof(struct iw_encode_ext)+ MAX_KEY_LEN)){
3512 if(copy_from_user(extra, wrq->u.encoding.pointer,wrq->u.encoding.length)){
3516 }else if(wrq->u.encoding.length != 0){
3520 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
3524 case SIOCGIWENCODEEXT:
3525 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT \n");
3526 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
3530 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME \n");
3531 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3534 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3535 //End Add -- //2008-0409-07, <Add> by Einsn Liu
3537 case IOCTL_CMD_TEST:
3539 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
3545 pReq = (PSCmdRequest)rq;
3546 pReq->wResult = MAGIC_CODE;
3552 if((((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_EVT) &&
3553 !(pDevice->flags & DEVICE_FLAGS_OPENED))
3555 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
3556 (((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_WPA))
3565 if (test_and_set_bit( 0, (void*)&(pMgmt->uCmdBusy))) {
3568 rc = private_ioctl(pDevice, rq);
3569 clear_bit( 0, (void*)&(pMgmt->uCmdBusy));
3572 case IOCTL_CMD_HOSTAPD:
3575 rc = hostap_ioctl(pDevice, &wrq->u.data);
3580 rc = wpa_ioctl(pDevice, &wrq->u.data);
3584 return ethtool_ioctl(dev, (void *) rq->ifr_data);
3585 // All other calls are currently unsupported
3589 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
3594 if (pDevice->bCommit) {
3595 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3596 netif_stop_queue(pDevice->dev);
3597 spin_lock_irq(&pDevice->lock);
3598 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
3599 spin_unlock_irq(&pDevice->lock);
3602 DEVICE_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
3603 spin_lock_irq(&pDevice->lock);
3604 pDevice->bLinkPass = FALSE;
3605 memset(pMgmt->abyCurrBSSID, 0, 6);
3606 pMgmt->eCurrState = WMAC_STATE_IDLE;
3607 netif_stop_queue(pDevice->dev);
3608 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3609 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
3610 if(pDevice->bWPASuppWextEnabled !=TRUE)
3612 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
3613 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3614 spin_unlock_irq(&pDevice->lock);
3616 pDevice->bCommit = FALSE;
3623 static int ethtool_ioctl(struct net_device *dev, void *useraddr)
3627 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
3631 case ETHTOOL_GDRVINFO: {
3632 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3633 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3634 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3635 if (copy_to_user(useraddr, &info, sizeof(info)))
3645 /*------------------------------------------------------------------*/
3647 MODULE_DEVICE_TABLE(pci, device_id_table);
3649 static struct pci_driver device_driver = {
3651 id_table: device_id_table,
3652 probe: device_found1,
3653 remove: device_remove1,
3655 suspend: viawget_suspend,
3656 resume: viawget_resume,
3660 static int __init device_init_module(void)
3665 // ret=pci_module_init(&device_driver);
3666 //ret = pcie_port_service_register(&device_driver);
3667 ret = pci_register_driver(&device_driver);
3670 register_reboot_notifier(&device_notifier);
3676 static void __exit device_cleanup_module(void)
3681 unregister_reboot_notifier(&device_notifier);
3683 pci_unregister_driver(&device_driver);
3687 module_init(device_init_module);
3688 module_exit(device_cleanup_module);
3693 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3695 struct pci_dev *pdev = NULL;
3700 while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
3701 if(pci_dev_driver(pdev) == &device_driver) {
3702 if (pci_get_drvdata(pdev))
3703 viawget_suspend(pdev, PMSG_HIBERNATE);
3711 viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3713 int power_status; // to silence the compiler
3715 PSDevice pDevice=pci_get_drvdata(pcid);
3716 PSMgmtObject pMgmt = pDevice->pMgmt;
3718 netif_stop_queue(pDevice->dev);
3719 spin_lock_irq(&pDevice->lock);
3720 pci_save_state(pcid);
3721 del_timer(&pDevice->sTimerCommand);
3722 del_timer(&pMgmt->sTimerSecondCallback);
3723 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3724 pDevice->uCmdDequeueIdx = 0;
3725 pDevice->uCmdEnqueueIdx = 0;
3726 pDevice->bCmdRunning = FALSE;
3727 MACbShutdown(pDevice->PortOffset);
3728 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3729 pDevice->bLinkPass = FALSE;
3730 memset(pMgmt->abyCurrBSSID, 0, 6);
3731 pMgmt->eCurrState = WMAC_STATE_IDLE;
3732 pci_disable_device(pcid);
3733 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3734 spin_unlock_irq(&pDevice->lock);
3739 viawget_resume(struct pci_dev *pcid)
3741 PSDevice pDevice=pci_get_drvdata(pcid);
3742 PSMgmtObject pMgmt = pDevice->pMgmt;
3743 int power_status; // to silence the compiler
3746 power_status = pci_set_power_state(pcid, 0);
3747 power_status = pci_enable_wake(pcid, 0, 0);
3748 pci_restore_state(pcid);
3749 if (netif_running(pDevice->dev)) {
3750 spin_lock_irq(&pDevice->lock);
3751 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3752 device_init_registers(pDevice, DEVICE_INIT_DXPL);
3753 if (pMgmt->sNodeDBTable[0].bActive == TRUE) { // Assoc with BSS
3754 pMgmt->sNodeDBTable[0].bActive = FALSE;
3755 pDevice->bLinkPass = FALSE;
3756 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3757 // In Adhoc, BSS state set back to started.
3758 pMgmt->eCurrState = WMAC_STATE_STARTED;
3761 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3762 pMgmt->eCurrState = WMAC_STATE_IDLE;
3765 init_timer(&pMgmt->sTimerSecondCallback);
3766 init_timer(&pDevice->sTimerCommand);
3767 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3768 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
3769 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3770 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3771 spin_unlock_irq(&pDevice->lock);