2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: driver entry for initial, open, close, tx and rx.
29 * vt6655_probe - module initial (insmod) driver entry
30 * vt6655_remove - module remove entry
31 * vt6655_init_info - device structure resource allocation function
32 * device_free_info - device structure resource free function
33 * device_get_pci_info - get allocated pci io/mem resource
34 * device_print_info - print out resource
35 * device_open - allocate dma/descripter resource & initial mac/bbp function
36 * device_xmit - asynchrous data tx function
37 * device_intr - interrupt handle function
38 * device_set_multi - set mac filter
39 * device_ioctl - ioctl entry
40 * device_close - shutdown mac/bbp & free dma/descripter resource
41 * device_rx_srv - rx service function
42 * device_receive_frame - rx data function
43 * device_alloc_rx_buf - rx buffer pre-allocated function
44 * device_alloc_frag_buf - rx fragement pre-allocated function
45 * device_free_tx_buf - free tx buffer function
46 * device_free_frag_buf- free de-fragement buffer
47 * device_dma0_tx_80211- tx 802.11 frame via dma0
48 * device_dma0_xmit- tx PS bufferred frame via dma0
49 * device_init_rd0_ring- initial rd dma0 ring
50 * device_init_rd1_ring- initial rd dma1 ring
51 * device_init_td0_ring- initial tx dma0 ring buffer
52 * device_init_td1_ring- initial tx dma1 ring buffer
53 * device_init_registers- initial MAC & BBP & RF internal registers.
54 * device_init_rings- initial tx/rx ring buffer
55 * device_init_defrag_cb- initial & allocate de-fragement buffer.
56 * device_free_rings- free all allocated ring buffer
57 * device_tx_srv- tx interrupt service function
86 #include <linux/delay.h>
87 #include <linux/kthread.h>
88 #include <linux/slab.h>
90 /*--------------------- Static Definitions -------------------------*/
91 //static int msglevel =MSG_LEVEL_DEBUG;
92 static int msglevel
= MSG_LEVEL_INFO
;
95 // Define module options
97 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
98 MODULE_LICENSE("GPL");
99 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
101 static int mlme_kill
;
102 //static struct task_struct * mlme_task;
104 #define DEVICE_PARAM(N,D)
106 static const int N[MAX_UINTS]=OPTION_DEFAULT;\
107 MODULE_PARM(N, "1-" __MODULE_STRING(MAX_UINTS) "i");\
108 MODULE_PARM_DESC(N, D);
111 #define RX_DESC_MIN0 16
112 #define RX_DESC_MAX0 128
113 #define RX_DESC_DEF0 32
114 DEVICE_PARAM(RxDescriptors0
,"Number of receive descriptors0");
116 #define RX_DESC_MIN1 16
117 #define RX_DESC_MAX1 128
118 #define RX_DESC_DEF1 32
119 DEVICE_PARAM(RxDescriptors1
,"Number of receive descriptors1");
121 #define TX_DESC_MIN0 16
122 #define TX_DESC_MAX0 128
123 #define TX_DESC_DEF0 32
124 DEVICE_PARAM(TxDescriptors0
,"Number of transmit descriptors0");
126 #define TX_DESC_MIN1 16
127 #define TX_DESC_MAX1 128
128 #define TX_DESC_DEF1 64
129 DEVICE_PARAM(TxDescriptors1
,"Number of transmit descriptors1");
132 #define IP_ALIG_DEF 0
133 /* IP_byte_align[] is used for IP header unsigned long byte aligned
134 0: indicate the IP header won't be unsigned long byte aligned.(Default) .
135 1: indicate the IP header will be unsigned long byte aligned.
136 In some environment, the IP header should be unsigned long byte aligned,
137 or the packet will be droped when we receive it. (eg: IPVS)
139 DEVICE_PARAM(IP_byte_align
,"Enable IP header dword aligned");
142 #define INT_WORKS_DEF 20
143 #define INT_WORKS_MIN 10
144 #define INT_WORKS_MAX 64
146 DEVICE_PARAM(int_works
,"Number of packets per interrupt services");
148 #define CHANNEL_MIN 1
149 #define CHANNEL_MAX 14
150 #define CHANNEL_DEF 6
152 DEVICE_PARAM(Channel
, "Channel number");
155 /* PreambleType[] is the preamble length used for transmit.
156 0: indicate allows long preamble type
157 1: indicate allows short preamble type
160 #define PREAMBLE_TYPE_DEF 1
162 DEVICE_PARAM(PreambleType
, "Preamble Type");
165 #define RTS_THRESH_MIN 512
166 #define RTS_THRESH_MAX 2347
167 #define RTS_THRESH_DEF 2347
169 DEVICE_PARAM(RTSThreshold
, "RTS threshold");
172 #define FRAG_THRESH_MIN 256
173 #define FRAG_THRESH_MAX 2346
174 #define FRAG_THRESH_DEF 2346
176 DEVICE_PARAM(FragThreshold
, "Fragmentation threshold");
179 #define DATA_RATE_MIN 0
180 #define DATA_RATE_MAX 13
181 #define DATA_RATE_DEF 13
183 0: indicate 1 Mbps 0x02
184 1: indicate 2 Mbps 0x04
185 2: indicate 5.5 Mbps 0x0B
186 3: indicate 11 Mbps 0x16
187 4: indicate 6 Mbps 0x0c
188 5: indicate 9 Mbps 0x12
189 6: indicate 12 Mbps 0x18
190 7: indicate 18 Mbps 0x24
191 8: indicate 24 Mbps 0x30
192 9: indicate 36 Mbps 0x48
193 10: indicate 48 Mbps 0x60
194 11: indicate 54 Mbps 0x6c
195 12: indicate 72 Mbps 0x90
196 13: indicate auto rate
199 DEVICE_PARAM(ConnectionRate
, "Connection data rate");
201 #define OP_MODE_DEF 0
203 DEVICE_PARAM(OPMode
, "Infrastruct, adhoc, AP mode ");
205 /* OpMode[] is used for transmit.
206 0: indicate infrastruct mode used
207 1: indicate adhoc mode used
208 2: indicate AP mode used
213 0: indicate disable power saving mode
214 1: indicate enable power saving mode
217 #define PS_MODE_DEF 0
219 DEVICE_PARAM(PSMode
, "Power saving mode");
222 #define SHORT_RETRY_MIN 0
223 #define SHORT_RETRY_MAX 31
224 #define SHORT_RETRY_DEF 8
227 DEVICE_PARAM(ShortRetryLimit
, "Short frame retry limits");
229 #define LONG_RETRY_MIN 0
230 #define LONG_RETRY_MAX 15
231 #define LONG_RETRY_DEF 4
234 DEVICE_PARAM(LongRetryLimit
, "long frame retry limits");
237 /* BasebandType[] baseband type selected
238 0: indicate 802.11a type
239 1: indicate 802.11b type
240 2: indicate 802.11g type
242 #define BBP_TYPE_MIN 0
243 #define BBP_TYPE_MAX 2
244 #define BBP_TYPE_DEF 2
246 DEVICE_PARAM(BasebandType
, "baseband type");
251 0: indicate disable 802.11h
252 1: indicate enable 802.11h
255 #define X80211h_MODE_DEF 0
257 DEVICE_PARAM(b80211hEnable
, "802.11h mode");
260 0: indicate disable 802.11h
261 1: indicate enable 802.11h
264 #define DIVERSITY_ANT_DEF 0
266 DEVICE_PARAM(bDiversityANTEnable
, "ANT diversity mode");
270 // Static vars definitions
274 static int device_nics
=0;
275 static PSDevice pDevice_Infos
=NULL
;
276 static struct net_device
*root_device_dev
= NULL
;
278 static CHIP_INFO chip_info_table
[]= {
279 { VT3253
, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
280 256, 1, DEVICE_FLAGS_IP_ALIGN
|DEVICE_FLAGS_TX_ALIGN
},
284 DEFINE_PCI_DEVICE_TABLE(vt6655_pci_id_table
) = {
285 { PCI_VDEVICE(VIA
, 0x3253), (kernel_ulong_t
)chip_info_table
},
289 /*--------------------- Static Functions --------------------------*/
292 static int vt6655_probe(struct pci_dev
*pcid
, const struct pci_device_id
*ent
);
293 static bool vt6655_init_info(struct pci_dev
* pcid
, PSDevice
* ppDevice
, PCHIP_INFO
);
294 static void device_free_info(PSDevice pDevice
);
295 static bool device_get_pci_info(PSDevice
, struct pci_dev
* pcid
);
296 static void device_print_info(PSDevice pDevice
);
297 static struct net_device_stats
*device_get_stats(struct net_device
*dev
);
298 static void device_init_diversity_timer(PSDevice pDevice
);
299 static int device_open(struct net_device
*dev
);
300 static int device_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
301 static irqreturn_t
device_intr(int irq
, void*dev_instance
);
302 static void device_set_multi(struct net_device
*dev
);
303 static int device_close(struct net_device
*dev
);
304 static int device_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
307 static int device_notify_reboot(struct notifier_block
*, unsigned long event
, void *ptr
);
308 static int viawget_suspend(struct pci_dev
*pcid
, pm_message_t state
);
309 static int viawget_resume(struct pci_dev
*pcid
);
310 struct notifier_block device_notifier
= {
311 .notifier_call
= device_notify_reboot
,
318 static void device_init_rd0_ring(PSDevice pDevice
);
319 static void device_init_rd1_ring(PSDevice pDevice
);
320 static void device_init_defrag_cb(PSDevice pDevice
);
321 static void device_init_td0_ring(PSDevice pDevice
);
322 static void device_init_td1_ring(PSDevice pDevice
);
324 static int device_dma0_tx_80211(struct sk_buff
*skb
, struct net_device
*dev
);
325 //2008-0714<Add>by Mike Liu
326 static bool device_release_WPADEV(PSDevice pDevice
);
328 static int ethtool_ioctl(struct net_device
*dev
, void *useraddr
);
329 static int device_rx_srv(PSDevice pDevice
, unsigned int uIdx
);
330 static int device_tx_srv(PSDevice pDevice
, unsigned int uIdx
);
331 static bool device_alloc_rx_buf(PSDevice pDevice
, PSRxDesc pDesc
);
332 static void device_init_registers(PSDevice pDevice
, DEVICE_INIT_TYPE InitType
);
333 static void device_free_tx_buf(PSDevice pDevice
, PSTxDesc pDesc
);
334 static void device_free_td0_ring(PSDevice pDevice
);
335 static void device_free_td1_ring(PSDevice pDevice
);
336 static void device_free_rd0_ring(PSDevice pDevice
);
337 static void device_free_rd1_ring(PSDevice pDevice
);
338 static void device_free_rings(PSDevice pDevice
);
339 static void device_free_frag_buf(PSDevice pDevice
);
340 static int Config_FileGetParameter(unsigned char *string
,
341 unsigned char *dest
, unsigned char *source
);
344 /*--------------------- Export Variables --------------------------*/
346 /*--------------------- Export Functions --------------------------*/
350 static char* get_chip_name(int chip_id
)
353 for (i
= 0; chip_info_table
[i
].name
!= NULL
; i
++)
354 if (chip_info_table
[i
].chip_id
== chip_id
)
356 return chip_info_table
[i
].name
;
359 static void __devexit
vt6655_remove(struct pci_dev
*pcid
)
361 PSDevice pDevice
= pci_get_drvdata(pcid
);
365 device_free_info(pDevice
);
371 device_set_int_opt(int *opt, int val, int min, int max, int def,char* name,char* devname) {
374 else if (val<min || val>max) {
375 DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n" ,
376 devname,name, min,max);
379 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n",
386 device_set_bool_opt(unsigned int *opt, int val,bool def,u32 flag, char* name,char* devname) {
389 *opt|=(def ? flag : 0);
390 else if (val<0 || val>1) {
391 DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE
392 "%s: the value of parameter %s is invalid, the valid range is (0-1)\n",devname,name);
393 *opt|=(def ? flag : 0);
395 DBG_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: set parameter %s to %s\n",
396 devname,name , val ? "true" : "false");
397 *opt|=(val ? flag : 0);
401 static void device_get_options(PSDevice pDevice
, int index
, char* devname
)
403 POPTIONS pOpts
= &(pDevice
->sOpts
);
405 pOpts
->nRxDescs0
= RX_DESC_DEF0
;
406 pOpts
->nRxDescs1
= RX_DESC_DEF1
;
407 pOpts
->nTxDescs
[0] = TX_DESC_DEF0
;
408 pOpts
->nTxDescs
[1] = TX_DESC_DEF1
;
409 pOpts
->flags
|= DEVICE_FLAGS_IP_ALIGN
;
410 pOpts
->int_works
= INT_WORKS_DEF
;
411 pOpts
->rts_thresh
= RTS_THRESH_DEF
;
412 pOpts
->frag_thresh
= FRAG_THRESH_DEF
;
413 pOpts
->data_rate
= DATA_RATE_DEF
;
414 pOpts
->channel_num
= CHANNEL_DEF
;
416 pOpts
->flags
|= DEVICE_FLAGS_PREAMBLE_TYPE
;
417 pOpts
->flags
|= DEVICE_FLAGS_OP_MODE
;
418 //pOpts->flags|=DEVICE_FLAGS_PS_MODE;
419 pOpts
->short_retry
= SHORT_RETRY_DEF
;
420 pOpts
->long_retry
= LONG_RETRY_DEF
;
421 pOpts
->bbp_type
= BBP_TYPE_DEF
;
422 pOpts
->flags
|= DEVICE_FLAGS_80211h_MODE
;
423 pOpts
->flags
|= DEVICE_FLAGS_DiversityANT
;
427 device_set_options(PSDevice pDevice
) {
429 unsigned char abyBroadcastAddr
[ETH_ALEN
] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
430 unsigned char abySNAP_RFC1042
[ETH_ALEN
] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
431 unsigned char abySNAP_Bridgetunnel
[ETH_ALEN
] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
434 memcpy(pDevice
->abyBroadcastAddr
, abyBroadcastAddr
, ETH_ALEN
);
435 memcpy(pDevice
->abySNAP_RFC1042
, abySNAP_RFC1042
, ETH_ALEN
);
436 memcpy(pDevice
->abySNAP_Bridgetunnel
, abySNAP_Bridgetunnel
, ETH_ALEN
);
438 pDevice
->uChannel
= pDevice
->sOpts
.channel_num
;
439 pDevice
->wRTSThreshold
= pDevice
->sOpts
.rts_thresh
;
440 pDevice
->wFragmentationThreshold
= pDevice
->sOpts
.frag_thresh
;
441 pDevice
->byShortRetryLimit
= pDevice
->sOpts
.short_retry
;
442 pDevice
->byLongRetryLimit
= pDevice
->sOpts
.long_retry
;
443 pDevice
->wMaxTransmitMSDULifetime
= DEFAULT_MSDU_LIFETIME
;
444 pDevice
->byShortPreamble
= (pDevice
->sOpts
.flags
& DEVICE_FLAGS_PREAMBLE_TYPE
) ? 1 : 0;
445 pDevice
->byOpMode
= (pDevice
->sOpts
.flags
& DEVICE_FLAGS_OP_MODE
) ? 1 : 0;
446 pDevice
->ePSMode
= (pDevice
->sOpts
.flags
& DEVICE_FLAGS_PS_MODE
) ? 1 : 0;
447 pDevice
->b11hEnable
= (pDevice
->sOpts
.flags
& DEVICE_FLAGS_80211h_MODE
) ? 1 : 0;
448 pDevice
->bDiversityRegCtlON
= (pDevice
->sOpts
.flags
& DEVICE_FLAGS_DiversityANT
) ? 1 : 0;
449 pDevice
->uConnectionRate
= pDevice
->sOpts
.data_rate
;
450 if (pDevice
->uConnectionRate
< RATE_AUTO
) pDevice
->bFixRate
= true;
451 pDevice
->byBBType
= pDevice
->sOpts
.bbp_type
;
452 pDevice
->byPacketType
= pDevice
->byBBType
;
455 pDevice
->byAutoFBCtrl
= AUTO_FB_0
;
456 //pDevice->byAutoFBCtrl = AUTO_FB_1;
458 pDevice
->bUpdateBBVGA
= true;
459 pDevice
->byFOETuning
= 0;
460 pDevice
->wCTSDuration
= 0;
461 pDevice
->byPreambleType
= 0;
464 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" uChannel= %d\n",(int)pDevice
->uChannel
);
465 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" byOpMode= %d\n",(int)pDevice
->byOpMode
);
466 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" ePSMode= %d\n",(int)pDevice
->ePSMode
);
467 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" wRTSThreshold= %d\n",(int)pDevice
->wRTSThreshold
);
468 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" byShortRetryLimit= %d\n",(int)pDevice
->byShortRetryLimit
);
469 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" byLongRetryLimit= %d\n",(int)pDevice
->byLongRetryLimit
);
470 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" byPreambleType= %d\n",(int)pDevice
->byPreambleType
);
471 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" byShortPreamble= %d\n",(int)pDevice
->byShortPreamble
);
472 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" uConnectionRate= %d\n",(int)pDevice
->uConnectionRate
);
473 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" byBBType= %d\n",(int)pDevice
->byBBType
);
474 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" pDevice->b11hEnable= %d\n",(int)pDevice
->b11hEnable
);
475 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" pDevice->bDiversityRegCtlON= %d\n",(int)pDevice
->bDiversityRegCtlON
);
478 static void s_vCompleteCurrentMeasure (PSDevice pDevice
, unsigned char byResult
)
481 unsigned long dwDuration
= 0;
482 unsigned char byRPI0
= 0;
484 for(ii
=1;ii
<8;ii
++) {
485 pDevice
->dwRPIs
[ii
] *= 255;
486 dwDuration
|= *((unsigned short *) (pDevice
->pCurrMeasureEID
->sReq
.abyDuration
));
488 pDevice
->dwRPIs
[ii
] /= dwDuration
;
489 pDevice
->abyRPIs
[ii
] = (unsigned char) pDevice
->dwRPIs
[ii
];
490 byRPI0
+= pDevice
->abyRPIs
[ii
];
492 pDevice
->abyRPIs
[0] = (0xFF - byRPI0
);
494 if (pDevice
->uNumOfMeasureEIDs
== 0) {
495 VNTWIFIbMeasureReport( pDevice
->pMgmt
,
497 pDevice
->pCurrMeasureEID
,
500 pDevice
->byCCAFraction
,
504 VNTWIFIbMeasureReport( pDevice
->pMgmt
,
506 pDevice
->pCurrMeasureEID
,
509 pDevice
->byCCAFraction
,
512 CARDbStartMeasure (pDevice
, pDevice
->pCurrMeasureEID
++, pDevice
->uNumOfMeasureEIDs
);
520 // Initialisation of MAC & BBP registers
523 static void device_init_registers(PSDevice pDevice
, DEVICE_INIT_TYPE InitType
)
526 unsigned char byValue
;
527 unsigned char byValue1
;
528 unsigned char byCCKPwrdBm
= 0;
529 unsigned char byOFDMPwrdBm
= 0;
531 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
532 MACbShutdown(pDevice
->PortOffset
);
533 BBvSoftwareReset(pDevice
->PortOffset
);
535 if ((InitType
== DEVICE_INIT_COLD
) ||
536 (InitType
== DEVICE_INIT_DXPL
)) {
537 // Do MACbSoftwareReset in MACvInitialize
538 MACbSoftwareReset(pDevice
->PortOffset
);
540 pDevice
->bCCK
= true;
541 pDevice
->bAES
= false;
542 pDevice
->bProtectMode
= false; //Only used in 11g type, sync with ERP IE
543 pDevice
->bNonERPPresent
= false;
544 pDevice
->bBarkerPreambleMd
= false;
545 pDevice
->wCurrentRate
= RATE_1M
;
546 pDevice
->byTopOFDMBasicRate
= RATE_24M
;
547 pDevice
->byTopCCKBasicRate
= RATE_1M
;
549 pDevice
->byRevId
= 0; //Target to IF pin while programming to RF chip.
552 MACvInitialize(pDevice
->PortOffset
);
555 VNSvInPortB(pDevice
->PortOffset
+ MAC_REG_LOCALID
, &(pDevice
->byLocalID
));
557 spin_lock_irq(&pDevice
->lock
);
558 SROMvReadAllContents(pDevice
->PortOffset
,pDevice
->abyEEPROM
);
560 spin_unlock_irq(&pDevice
->lock
);
564 pDevice
->byMinChannel
= 1;
565 pDevice
->byMaxChannel
= CB_MAX_CHANNEL
;
568 byValue
= SROMbyReadEmbedded(pDevice
->PortOffset
, EEP_OFS_ANTENNA
);
569 if (byValue
& EEP_ANTINV
)
570 pDevice
->bTxRxAntInv
= true;
572 pDevice
->bTxRxAntInv
= false;
574 //printk("init_register:TxRxAntInv is %d,byValue is %d\n",pDevice->bTxRxAntInv,byValue);
577 byValue
&= (EEP_ANTENNA_AUX
| EEP_ANTENNA_MAIN
);
578 if (byValue
== 0) // if not set default is All
579 byValue
= (EEP_ANTENNA_AUX
| EEP_ANTENNA_MAIN
);
581 //printk("init_register:byValue is %d\n",byValue);
583 pDevice
->ulDiversityNValue
= 100*260;//100*SROMbyReadEmbedded(pDevice->PortOffset, 0x51);
584 pDevice
->ulDiversityMValue
= 100*16;//SROMbyReadEmbedded(pDevice->PortOffset, 0x52);
585 pDevice
->byTMax
= 1;//SROMbyReadEmbedded(pDevice->PortOffset, 0x53);
586 pDevice
->byTMax2
= 4;//SROMbyReadEmbedded(pDevice->PortOffset, 0x54);
587 pDevice
->ulSQ3TH
= 0;//(unsigned long) SROMbyReadEmbedded(pDevice->PortOffset, 0x55);
588 pDevice
->byTMax3
= 64;//SROMbyReadEmbedded(pDevice->PortOffset, 0x56);
590 if (byValue
== (EEP_ANTENNA_AUX
| EEP_ANTENNA_MAIN
)) {
591 pDevice
->byAntennaCount
= 2;
592 pDevice
->byTxAntennaMode
= ANT_B
;
593 pDevice
->dwTxAntennaSel
= 1;
594 pDevice
->dwRxAntennaSel
= 1;
595 if (pDevice
->bTxRxAntInv
== true)
596 pDevice
->byRxAntennaMode
= ANT_A
;
598 pDevice
->byRxAntennaMode
= ANT_B
;
599 // chester for antenna
600 byValue1
= SROMbyReadEmbedded(pDevice
->PortOffset
, EEP_OFS_ANTENNA
);
601 // if (pDevice->bDiversityRegCtlON)
602 if((byValue1
&0x08)==0)
603 pDevice
->bDiversityEnable
= false;//SROMbyReadEmbedded(pDevice->PortOffset, 0x50);
605 pDevice
->bDiversityEnable
= true;
607 //printk("aux |main antenna: RxAntennaMode is %d\n",pDevice->byRxAntennaMode);
610 pDevice
->bDiversityEnable
= false;
611 pDevice
->byAntennaCount
= 1;
612 pDevice
->dwTxAntennaSel
= 0;
613 pDevice
->dwRxAntennaSel
= 0;
614 if (byValue
& EEP_ANTENNA_AUX
) {
615 pDevice
->byTxAntennaMode
= ANT_A
;
616 if (pDevice
->bTxRxAntInv
== true)
617 pDevice
->byRxAntennaMode
= ANT_B
;
619 pDevice
->byRxAntennaMode
= ANT_A
;
621 pDevice
->byTxAntennaMode
= ANT_B
;
622 if (pDevice
->bTxRxAntInv
== true)
623 pDevice
->byRxAntennaMode
= ANT_A
;
625 pDevice
->byRxAntennaMode
= ANT_B
;
629 //printk("init registers: TxAntennaMode is %d\n",pDevice->byTxAntennaMode);
631 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
632 pDevice
->bDiversityEnable
,(int)pDevice
->ulDiversityNValue
,(int)pDevice
->ulDiversityMValue
,pDevice
->byTMax
,pDevice
->byTMax2
);
634 //#ifdef ZoneType_DefaultSetting
635 //2008-8-4 <add> by chester
637 pDevice
->byOriginalZonetype
= pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
];
638 zonetype
= Config_FileOperation(pDevice
,false,NULL
);
639 if (zonetype
>= 0) { //read zonetype file ok!
640 if ((zonetype
== 0)&&
641 (pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
] !=0x00)){ //for USA
642 pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
] = 0;
643 pDevice
->abyEEPROM
[EEP_OFS_MAXCHANNEL
] = 0x0B;
644 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Init Zone Type :USA\n");
646 else if((zonetype
== 1)&&
647 (pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
]!=0x01)){ //for Japan
648 pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
] = 0x01;
649 pDevice
->abyEEPROM
[EEP_OFS_MAXCHANNEL
] = 0x0D;
651 else if((zonetype
== 2)&&
652 (pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
]!=0x02)){ //for Europe
653 pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
] = 0x02;
654 pDevice
->abyEEPROM
[EEP_OFS_MAXCHANNEL
] = 0x0D;
655 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Init Zone Type :Europe\n");
660 if(zonetype
!=pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
])
661 printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",zonetype
,pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
]);
663 printk("Read Zonetype file success,use default zonetype setting[%02x]\n",zonetype
);
667 printk("Read Zonetype file fail,use default zonetype setting[%02x]\n",SROMbyReadEmbedded(pDevice
->PortOffset
, EEP_OFS_ZONETYPE
));
670 pDevice
->byRFType
= SROMbyReadEmbedded(pDevice
->PortOffset
, EEP_OFS_RFTYPE
);
672 if ((pDevice
->byRFType
& RF_EMU
) != 0) {
673 // force change RevID for VT3253 emu
674 pDevice
->byRevId
= 0x80;
677 pDevice
->byRFType
&= RF_MASK
;
678 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pDevice->byRFType = %x\n", pDevice
->byRFType
);
680 if (pDevice
->bZoneRegExist
== false) {
681 pDevice
->byZoneType
= pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
];
683 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pDevice->byZoneType = %x\n", pDevice
->byZoneType
);
688 //Get Desire Power Value
689 pDevice
->byCurPwr
= 0xFF;
690 pDevice
->byCCKPwr
= SROMbyReadEmbedded(pDevice
->PortOffset
, EEP_OFS_PWR_CCK
);
691 pDevice
->byOFDMPwrG
= SROMbyReadEmbedded(pDevice
->PortOffset
, EEP_OFS_PWR_OFDMG
);
692 //byCCKPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_CCK_PWR_dBm);
694 //byOFDMPwrdBm = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_OFDM_PWR_dBm);
695 //printk("CCKPwrdBm is 0x%x,byOFDMPwrdBm is 0x%x\n",byCCKPwrdBm,byOFDMPwrdBm);
699 for (ii
=0;ii
<CB_MAX_CHANNEL_24G
;ii
++) {
700 pDevice
->abyCCKPwrTbl
[ii
+1] = SROMbyReadEmbedded(pDevice
->PortOffset
, (unsigned char)(ii
+ EEP_OFS_CCK_PWR_TBL
));
701 if (pDevice
->abyCCKPwrTbl
[ii
+1] == 0) {
702 pDevice
->abyCCKPwrTbl
[ii
+1] = pDevice
->byCCKPwr
;
704 pDevice
->abyOFDMPwrTbl
[ii
+1] = SROMbyReadEmbedded(pDevice
->PortOffset
, (unsigned char)(ii
+ EEP_OFS_OFDM_PWR_TBL
));
705 if (pDevice
->abyOFDMPwrTbl
[ii
+1] == 0) {
706 pDevice
->abyOFDMPwrTbl
[ii
+1] = pDevice
->byOFDMPwrG
;
708 pDevice
->abyCCKDefaultPwr
[ii
+1] = byCCKPwrdBm
;
709 pDevice
->abyOFDMDefaultPwr
[ii
+1] = byOFDMPwrdBm
;
711 //2008-8-4 <add> by chester
712 //recover 12,13 ,14channel for EUROPE by 11 channel
713 if(((pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
] == ZoneType_Japan
) ||
714 (pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
] == ZoneType_Europe
))&&
715 (pDevice
->byOriginalZonetype
== ZoneType_USA
)) {
716 for(ii
=11;ii
<14;ii
++) {
717 pDevice
->abyCCKPwrTbl
[ii
] = pDevice
->abyCCKPwrTbl
[10];
718 pDevice
->abyOFDMPwrTbl
[ii
] = pDevice
->abyOFDMPwrTbl
[10];
724 // Load OFDM A Power Table
725 for (ii
=0;ii
<CB_MAX_CHANNEL_5G
;ii
++) { //RobertYu:20041224, bug using CB_MAX_CHANNEL
726 pDevice
->abyOFDMPwrTbl
[ii
+CB_MAX_CHANNEL_24G
+1] = SROMbyReadEmbedded(pDevice
->PortOffset
, (unsigned char)(ii
+ EEP_OFS_OFDMA_PWR_TBL
));
727 pDevice
->abyOFDMDefaultPwr
[ii
+CB_MAX_CHANNEL_24G
+1] = SROMbyReadEmbedded(pDevice
->PortOffset
, (unsigned char)(ii
+ EEP_OFS_OFDMA_PWR_dBm
));
729 init_channel_table((void *)pDevice
);
732 if (pDevice
->byLocalID
> REV_ID_VT3253_B1
) {
733 MACvSelectPage1(pDevice
->PortOffset
);
734 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_MSRCTL
+ 1, (MSRCTL1_TXPWR
| MSRCTL1_CSAPAREN
));
735 MACvSelectPage0(pDevice
->PortOffset
);
739 // use relative tx timeout and 802.11i D4
740 MACvWordRegBitsOn(pDevice
->PortOffset
, MAC_REG_CFG
, (CFG_TKIPOPT
| CFG_NOTXTIMEOUT
));
742 // set performance parameter by registry
743 MACvSetShortRetryLimit(pDevice
->PortOffset
, pDevice
->byShortRetryLimit
);
744 MACvSetLongRetryLimit(pDevice
->PortOffset
, pDevice
->byLongRetryLimit
);
747 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_TFTCTL
, TFTCTL_TSFCNTRST
);
748 // enable TSF counter
749 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_TFTCTL
, TFTCTL_TSFCNTREN
);
751 // initialize BBP registers
752 BBbVT3253Init(pDevice
);
754 if (pDevice
->bUpdateBBVGA
) {
755 pDevice
->byBBVGACurrent
= pDevice
->abyBBVGA
[0];
756 pDevice
->byBBVGANew
= pDevice
->byBBVGACurrent
;
757 BBvSetVGAGainOffset(pDevice
, pDevice
->abyBBVGA
[0]);
760 //printk("init registers:RxAntennaMode is %x,TxAntennaMode is %x\n",pDevice->byRxAntennaMode,pDevice->byTxAntennaMode);
762 BBvSetRxAntennaMode(pDevice
->PortOffset
, pDevice
->byRxAntennaMode
);
763 BBvSetTxAntennaMode(pDevice
->PortOffset
, pDevice
->byTxAntennaMode
);
765 pDevice
->byCurrentCh
= 0;
767 //pDevice->NetworkType = Ndis802_11Automode;
768 // Set BB and packet type at the same time.
769 // Set Short Slot Time, xIFS, and RSPINF.
770 if (pDevice
->uConnectionRate
== RATE_AUTO
) {
771 pDevice
->wCurrentRate
= RATE_54M
;
773 pDevice
->wCurrentRate
= (unsigned short)pDevice
->uConnectionRate
;
777 VNTWIFIbConfigPhyMode(pDevice
->pMgmt
, PHY_TYPE_11G
);
778 VNTWIFIbConfigPhyMode(pDevice
->pMgmt
, PHY_TYPE_AUTO
);
780 pDevice
->bRadioOff
= false;
782 pDevice
->byRadioCtl
= SROMbyReadEmbedded(pDevice
->PortOffset
, EEP_OFS_RADIOCTL
);
783 pDevice
->bHWRadioOff
= false;
785 if (pDevice
->byRadioCtl
& EEP_RADIOCTL_ENABLE
) {
787 MACvGPIOIn(pDevice
->PortOffset
, &pDevice
->byGPIO
);
788 //2008-4-14 <add> by chester for led issue
789 #ifdef FOR_LED_ON_NOTEBOOK
790 if (pDevice
->byGPIO
& GPIO0_DATA
){pDevice
->bHWRadioOff
= true;}
791 if ( !(pDevice
->byGPIO
& GPIO0_DATA
)){pDevice
->bHWRadioOff
= false;}
794 if ( (pDevice
->bRadioControlOff
== true)) {
795 CARDbRadioPowerOff(pDevice
);
797 else CARDbRadioPowerOn(pDevice
);
799 if (((pDevice
->byGPIO
& GPIO0_DATA
) && !(pDevice
->byRadioCtl
& EEP_RADIOCTL_INV
)) ||
800 ( !(pDevice
->byGPIO
& GPIO0_DATA
) && (pDevice
->byRadioCtl
& EEP_RADIOCTL_INV
))) {
801 pDevice
->bHWRadioOff
= true;
804 if ((pDevice
->bHWRadioOff
== true) || (pDevice
->bRadioControlOff
== true)) {
805 CARDbRadioPowerOff(pDevice
);
810 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
811 // get Permanent network address
812 SROMvReadEtherAddress(pDevice
->PortOffset
, pDevice
->abyCurrentNetAddr
);
813 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Network address = %pM\n",
814 pDevice
->abyCurrentNetAddr
);
817 CARDvSafeResetRx(pDevice
);
819 CARDvSafeResetTx(pDevice
);
821 if (pDevice
->byLocalID
<= REV_ID_VT3253_A1
) {
822 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_RCR
, RCR_WPAERR
);
825 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
828 MACvReceive0(pDevice
->PortOffset
);
829 MACvReceive1(pDevice
->PortOffset
);
832 MACvStart(pDevice
->PortOffset
);
834 netif_stop_queue(pDevice
->dev
);
841 static void device_init_diversity_timer(PSDevice pDevice
) {
843 init_timer(&pDevice
->TimerSQ3Tmax1
);
844 pDevice
->TimerSQ3Tmax1
.data
= (unsigned long) pDevice
;
845 pDevice
->TimerSQ3Tmax1
.function
= (TimerFunction
)TimerSQ3CallBack
;
846 pDevice
->TimerSQ3Tmax1
.expires
= RUN_AT(HZ
);
848 init_timer(&pDevice
->TimerSQ3Tmax2
);
849 pDevice
->TimerSQ3Tmax2
.data
= (unsigned long) pDevice
;
850 pDevice
->TimerSQ3Tmax2
.function
= (TimerFunction
)TimerSQ3CallBack
;
851 pDevice
->TimerSQ3Tmax2
.expires
= RUN_AT(HZ
);
853 init_timer(&pDevice
->TimerSQ3Tmax3
);
854 pDevice
->TimerSQ3Tmax3
.data
= (unsigned long) pDevice
;
855 pDevice
->TimerSQ3Tmax3
.function
= (TimerFunction
)TimerState1CallBack
;
856 pDevice
->TimerSQ3Tmax3
.expires
= RUN_AT(HZ
);
862 static bool device_release_WPADEV(PSDevice pDevice
)
864 viawget_wpa_header
*wpahdr
;
866 // wait_queue_head_t Set_wait;
867 //send device close to wpa_supplicnat layer
868 if (pDevice
->bWPADEVUp
==true) {
869 wpahdr
= (viawget_wpa_header
*)pDevice
->skb
->data
;
870 wpahdr
->type
= VIAWGET_DEVICECLOSE_MSG
;
871 wpahdr
->resp_ie_len
= 0;
872 wpahdr
->req_ie_len
= 0;
873 skb_put(pDevice
->skb
, sizeof(viawget_wpa_header
));
874 pDevice
->skb
->dev
= pDevice
->wpadev
;
875 skb_reset_mac_header(pDevice
->skb
);
876 pDevice
->skb
->pkt_type
= PACKET_HOST
;
877 pDevice
->skb
->protocol
= htons(ETH_P_802_2
);
878 memset(pDevice
->skb
->cb
, 0, sizeof(pDevice
->skb
->cb
));
879 netif_rx(pDevice
->skb
);
880 pDevice
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
882 //wait release WPADEV
883 // init_waitqueue_head(&Set_wait);
884 // wait_event_timeout(Set_wait, ((pDevice->wpadev==NULL)&&(pDevice->skb == NULL)),5*HZ); //1s wait
885 while((pDevice
->bWPADEVUp
==true)) {
886 set_current_state(TASK_UNINTERRUPTIBLE
);
887 schedule_timeout (HZ
/20); //wait 50ms
896 static const struct net_device_ops device_netdev_ops
= {
897 .ndo_open
= device_open
,
898 .ndo_stop
= device_close
,
899 .ndo_do_ioctl
= device_ioctl
,
900 .ndo_get_stats
= device_get_stats
,
901 .ndo_start_xmit
= device_xmit
,
902 .ndo_set_rx_mode
= device_set_multi
,
906 vt6655_probe(struct pci_dev
*pcid
, const struct pci_device_id
*ent
)
908 static bool bFirst
= true;
909 struct net_device
* dev
= NULL
;
910 PCHIP_INFO pChip_info
= (PCHIP_INFO
)ent
->driver_data
;
913 if (device_nics
++>= MAX_UINTS
) {
914 printk(KERN_NOTICE DEVICE_NAME
": already found %d NICs\n", device_nics
);
919 dev
= alloc_etherdev(sizeof(DEVICE_INFO
));
921 pDevice
= (PSDevice
) netdev_priv(dev
);
924 printk(KERN_ERR DEVICE_NAME
": allocate net device failed \n");
928 // Chain it all together
929 // SET_MODULE_OWNER(dev);
930 SET_NETDEV_DEV(dev
, &pcid
->dev
);
933 printk(KERN_NOTICE
"%s Ver. %s\n",DEVICE_FULL_DRV_NAM
, DEVICE_VERSION
);
934 printk(KERN_NOTICE
"Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
938 if (!vt6655_init_info(pcid
, &pDevice
, pChip_info
)) {
942 pDevice
->next_module
= root_device_dev
;
943 root_device_dev
= dev
;
945 if (pci_enable_device(pcid
)) {
946 device_free_info(pDevice
);
949 dev
->irq
= pcid
->irq
;
952 printk("Before get pci_info memaddr is %x\n",pDevice
->memaddr
);
954 if (device_get_pci_info(pDevice
,pcid
) == false) {
955 printk(KERN_ERR DEVICE_NAME
": Failed to find PCI device.\n");
956 device_free_info(pDevice
);
964 //pci_read_config_byte(pcid, PCI_BASE_ADDRESS_0, &pDevice->byRevId);
965 printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",pDevice
->memaddr
,pDevice
->ioaddr
,pDevice
->io_size
);
977 for (i
=0;address
[i
];i
++)
979 //pci_write_config_dword(pcid,address[i], 0xFFFFFFFF);
980 pci_read_config_dword(pcid
, address
[i
], &bar
);
981 printk("bar %d is %x\n",i
,bar
);
984 printk("bar %d not implemented\n",i
);
987 if (bar
& PCI_BASE_ADDRESS_SPACE_IO
) {
990 len
= bar
& (PCI_BASE_ADDRESS_IO_MASK
& 0xFFFF);
991 len
= len
& ~(len
- 1);
993 printk("IO space: len in IO %x, BAR %d\n", len
, i
);
997 len
= bar
& 0xFFFFFFF0;
1000 printk("len in MEM %x, BAR %d\n", len
, i
);
1012 pDevice
->PortOffset
= (unsigned long)ioremap(pDevice
->memaddr
& PCI_BASE_ADDRESS_MEM_MASK
, pDevice
->io_size
);
1013 //pDevice->PortOffset = (unsigned long)ioremap(pDevice->ioaddr & PCI_BASE_ADDRESS_IO_MASK, pDevice->io_size);
1015 if(pDevice
->PortOffset
== 0) {
1016 printk(KERN_ERR DEVICE_NAME
": Failed to IO remapping ..\n");
1017 device_free_info(pDevice
);
1024 rc
= pci_request_regions(pcid
, DEVICE_NAME
);
1026 printk(KERN_ERR DEVICE_NAME
": Failed to find PCI device\n");
1027 device_free_info(pDevice
);
1031 dev
->base_addr
= pDevice
->ioaddr
;
1033 unsigned char value
;
1035 VNSvInPortB(pDevice
->PortOffset
+0x4F, &value
);
1036 printk("Before write: value is %x\n",value
);
1037 //VNSvInPortB(pDevice->PortOffset+0x3F, 0x00);
1038 VNSvOutPortB(pDevice
->PortOffset
,value
);
1039 VNSvInPortB(pDevice
->PortOffset
+0x4F, &value
);
1040 printk("After write: value is %x\n",value
);
1046 pDevice
->PortOffset
= pDevice
->ioaddr
;
1049 if (!MACbSoftwareReset(pDevice
->PortOffset
)) {
1050 printk(KERN_ERR DEVICE_NAME
": Failed to access MAC hardware..\n");
1051 device_free_info(pDevice
);
1054 // initial to reload eeprom
1055 MACvInitialize(pDevice
->PortOffset
);
1056 MACvReadEtherAddress(pDevice
->PortOffset
, dev
->dev_addr
);
1058 device_get_options(pDevice
, device_nics
-1, dev
->name
);
1059 device_set_options(pDevice
);
1060 //Mask out the options cannot be set to the chip
1061 pDevice
->sOpts
.flags
&= pChip_info
->flags
;
1063 //Enable the chip specified capabilities
1064 pDevice
->flags
= pDevice
->sOpts
.flags
| (pChip_info
->flags
& 0xFF000000UL
);
1065 pDevice
->tx_80211
= device_dma0_tx_80211
;
1066 pDevice
->sMgmtObj
.pAdapter
= (void *)pDevice
;
1067 pDevice
->pMgmt
= &(pDevice
->sMgmtObj
);
1069 dev
->irq
= pcid
->irq
;
1070 dev
->netdev_ops
= &device_netdev_ops
;
1072 dev
->wireless_handlers
= (struct iw_handler_def
*)&iwctl_handler_def
;
1074 rc
= register_netdev(dev
);
1077 printk(KERN_ERR DEVICE_NAME
" Failed to register netdev\n");
1078 device_free_info(pDevice
);
1081 device_print_info(pDevice
);
1082 pci_set_drvdata(pcid
, pDevice
);
1087 static void device_print_info(PSDevice pDevice
)
1089 struct net_device
* dev
=pDevice
->dev
;
1091 DBG_PRT(MSG_LEVEL_INFO
, KERN_INFO
"%s: %s\n",dev
->name
, get_chip_name(pDevice
->chip_id
));
1092 DBG_PRT(MSG_LEVEL_INFO
, KERN_INFO
"%s: MAC=%pM", dev
->name
, dev
->dev_addr
);
1094 DBG_PRT(MSG_LEVEL_INFO
, KERN_INFO
" IO=0x%lx ",(unsigned long) pDevice
->ioaddr
);
1095 DBG_PRT(MSG_LEVEL_INFO
, KERN_INFO
" IRQ=%d \n", pDevice
->dev
->irq
);
1097 DBG_PRT(MSG_LEVEL_INFO
, KERN_INFO
" IO=0x%lx Mem=0x%lx ",
1098 (unsigned long) pDevice
->ioaddr
,(unsigned long) pDevice
->PortOffset
);
1099 DBG_PRT(MSG_LEVEL_INFO
, KERN_INFO
" IRQ=%d \n", pDevice
->dev
->irq
);
1104 static bool __devinit
vt6655_init_info(struct pci_dev
* pcid
, PSDevice
* ppDevice
,
1105 PCHIP_INFO pChip_info
) {
1109 memset(*ppDevice
,0,sizeof(DEVICE_INFO
));
1111 if (pDevice_Infos
== NULL
) {
1112 pDevice_Infos
=*ppDevice
;
1115 for (p
=pDevice_Infos
;p
->next
!=NULL
;p
=p
->next
)
1117 p
->next
= *ppDevice
;
1118 (*ppDevice
)->prev
= p
;
1121 (*ppDevice
)->pcid
= pcid
;
1122 (*ppDevice
)->chip_id
= pChip_info
->chip_id
;
1123 (*ppDevice
)->io_size
= pChip_info
->io_size
;
1124 (*ppDevice
)->nTxQueues
= pChip_info
->nTxQueue
;
1125 (*ppDevice
)->multicast_limit
=32;
1127 spin_lock_init(&((*ppDevice
)->lock
));
1132 static bool device_get_pci_info(PSDevice pDevice
, struct pci_dev
* pcid
) {
1136 unsigned int cis_addr
;
1138 unsigned char pci_config
[256];
1139 unsigned char value
=0x00;
1142 memset(pci_config
,0x00,256);
1145 pci_read_config_byte(pcid
, PCI_REVISION_ID
, &pDevice
->byRevId
);
1146 pci_read_config_word(pcid
, PCI_SUBSYSTEM_ID
,&pDevice
->SubSystemID
);
1147 pci_read_config_word(pcid
, PCI_SUBSYSTEM_VENDOR_ID
, &pDevice
->SubVendorID
);
1148 pci_read_config_word(pcid
, PCI_COMMAND
, (u16
*) & (pci_cmd
));
1150 pci_set_master(pcid
);
1152 pDevice
->memaddr
= pci_resource_start(pcid
,0);
1153 pDevice
->ioaddr
= pci_resource_start(pcid
,1);
1156 // pDevice->ioaddr = pci_resource_start(pcid, 0);
1157 // pDevice->memaddr = pci_resource_start(pcid,1);
1160 cis_addr
= pci_resource_start(pcid
,2);
1162 pDevice
->pcid
= pcid
;
1164 pci_read_config_byte(pcid
, PCI_COMMAND
, &b
);
1165 pci_write_config_byte(pcid
, PCI_COMMAND
, (b
|PCI_COMMAND_MASTER
));
1168 //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
1169 //printk("max lat is %x,SubSystemID is %x\n",max_lat,pDevice->SubSystemID);
1170 //for (ii=0;ii<0xFF;ii++)
1171 //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
1173 //pci_write_config_word(pcid,PCI_MAX_LAT,max_lat);
1174 //pci_read_config_word(pcid,PCI_MAX_LAT,&max_lat);
1175 //printk("max lat is %x\n",max_lat);
1177 for (ii
=0;ii
<0xFF;ii
++)
1179 pci_read_config_byte(pcid
,ii
,&value
);
1180 pci_config
[ii
] = value
;
1182 for (ii
=0,j
=1;ii
<0x100;ii
++,j
++)
1186 printk("%x:",pci_config
[ii
]);
1191 printk("%x:",pci_config
[ii
]);
1198 static void device_free_info(PSDevice pDevice
) {
1200 struct net_device
* dev
=pDevice
->dev
;
1203 //2008-0714-01<Add>by chester
1204 device_release_WPADEV(pDevice
);
1206 //2008-07-21-01<Add>by MikeLiu
1208 if(wpa_set_wpadev(pDevice
, 0)!=0)
1209 printk("unregister wpadev fail?\n");
1211 if (pDevice_Infos
==NULL
)
1214 for (ptr
=pDevice_Infos
;ptr
&& (ptr
!=pDevice
);ptr
=ptr
->next
)
1218 if (ptr
==pDevice_Infos
)
1219 pDevice_Infos
=ptr
->next
;
1221 ptr
->prev
->next
=ptr
->next
;
1224 DBG_PRT(MSG_LEVEL_ERR
, KERN_ERR
"info struct not found\n");
1229 vt6655_hostap_set_hostapd(pDevice
, 0, 0);
1232 unregister_netdev(dev
);
1234 if (pDevice
->PortOffset
)
1235 iounmap((void *)pDevice
->PortOffset
);
1238 pci_release_regions(pDevice
->pcid
);
1242 if (pDevice
->pcid
) {
1243 pci_set_drvdata(pDevice
->pcid
,NULL
);
1247 static bool device_init_rings(PSDevice pDevice
) {
1251 /*allocate all RD/TD rings a single pool*/
1252 vir_pool
= pci_alloc_consistent(pDevice
->pcid
,
1253 pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
) +
1254 pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
) +
1255 pDevice
->sOpts
.nTxDescs
[0] * sizeof(STxDesc
) +
1256 pDevice
->sOpts
.nTxDescs
[1] * sizeof(STxDesc
),
1257 &pDevice
->pool_dma
);
1259 if (vir_pool
== NULL
) {
1260 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s : allocate desc dma memory failed\n", pDevice
->dev
->name
);
1265 pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
) +
1266 pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
) +
1267 pDevice
->sOpts
.nTxDescs
[0] * sizeof(STxDesc
) +
1268 pDevice
->sOpts
.nTxDescs
[1] * sizeof(STxDesc
)
1271 pDevice
->aRD0Ring
= vir_pool
;
1272 pDevice
->aRD1Ring
= vir_pool
+
1273 pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
);
1276 pDevice
->rd0_pool_dma
= pDevice
->pool_dma
;
1277 pDevice
->rd1_pool_dma
= pDevice
->rd0_pool_dma
+
1278 pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
);
1280 pDevice
->tx0_bufs
= pci_alloc_consistent(pDevice
->pcid
,
1281 pDevice
->sOpts
.nTxDescs
[0] * PKT_BUF_SZ
+
1282 pDevice
->sOpts
.nTxDescs
[1] * PKT_BUF_SZ
+
1283 CB_BEACON_BUF_SIZE
+
1285 &pDevice
->tx_bufs_dma0
);
1287 if (pDevice
->tx0_bufs
== NULL
) {
1288 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: allocate buf dma memory failed\n", pDevice
->dev
->name
);
1289 pci_free_consistent(pDevice
->pcid
,
1290 pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
) +
1291 pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
) +
1292 pDevice
->sOpts
.nTxDescs
[0] * sizeof(STxDesc
) +
1293 pDevice
->sOpts
.nTxDescs
[1] * sizeof(STxDesc
),
1294 vir_pool
, pDevice
->pool_dma
1299 memset(pDevice
->tx0_bufs
, 0,
1300 pDevice
->sOpts
.nTxDescs
[0] * PKT_BUF_SZ
+
1301 pDevice
->sOpts
.nTxDescs
[1] * PKT_BUF_SZ
+
1302 CB_BEACON_BUF_SIZE
+
1306 pDevice
->td0_pool_dma
= pDevice
->rd1_pool_dma
+
1307 pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
);
1309 pDevice
->td1_pool_dma
= pDevice
->td0_pool_dma
+
1310 pDevice
->sOpts
.nTxDescs
[0] * sizeof(STxDesc
);
1313 // vir_pool: pvoid type
1314 pDevice
->apTD0Rings
= vir_pool
1315 + pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
)
1316 + pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
);
1318 pDevice
->apTD1Rings
= vir_pool
1319 + pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
)
1320 + pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
)
1321 + pDevice
->sOpts
.nTxDescs
[0] * sizeof(STxDesc
);
1324 pDevice
->tx1_bufs
= pDevice
->tx0_bufs
+
1325 pDevice
->sOpts
.nTxDescs
[0] * PKT_BUF_SZ
;
1328 pDevice
->tx_beacon_bufs
= pDevice
->tx1_bufs
+
1329 pDevice
->sOpts
.nTxDescs
[1] * PKT_BUF_SZ
;
1331 pDevice
->pbyTmpBuff
= pDevice
->tx_beacon_bufs
+
1334 pDevice
->tx_bufs_dma1
= pDevice
->tx_bufs_dma0
+
1335 pDevice
->sOpts
.nTxDescs
[0] * PKT_BUF_SZ
;
1338 pDevice
->tx_beacon_dma
= pDevice
->tx_bufs_dma1
+
1339 pDevice
->sOpts
.nTxDescs
[1] * PKT_BUF_SZ
;
1345 static void device_free_rings(PSDevice pDevice
) {
1347 pci_free_consistent(pDevice
->pcid
,
1348 pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
) +
1349 pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
) +
1350 pDevice
->sOpts
.nTxDescs
[0] * sizeof(STxDesc
) +
1351 pDevice
->sOpts
.nTxDescs
[1] * sizeof(STxDesc
)
1353 pDevice
->aRD0Ring
, pDevice
->pool_dma
1356 if (pDevice
->tx0_bufs
)
1357 pci_free_consistent(pDevice
->pcid
,
1358 pDevice
->sOpts
.nTxDescs
[0] * PKT_BUF_SZ
+
1359 pDevice
->sOpts
.nTxDescs
[1] * PKT_BUF_SZ
+
1360 CB_BEACON_BUF_SIZE
+
1362 pDevice
->tx0_bufs
, pDevice
->tx_bufs_dma0
1366 static void device_init_rd0_ring(PSDevice pDevice
) {
1368 dma_addr_t curr
= pDevice
->rd0_pool_dma
;
1371 /* Init the RD0 ring entries */
1372 for (i
= 0; i
< pDevice
->sOpts
.nRxDescs0
; i
++, curr
+= sizeof(SRxDesc
)) {
1373 pDesc
= &(pDevice
->aRD0Ring
[i
]);
1374 pDesc
->pRDInfo
= alloc_rd_info();
1375 ASSERT(pDesc
->pRDInfo
);
1376 if (!device_alloc_rx_buf(pDevice
, pDesc
)) {
1377 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc rx bufs\n",
1378 pDevice
->dev
->name
);
1380 pDesc
->next
= &(pDevice
->aRD0Ring
[(i
+1) % pDevice
->sOpts
.nRxDescs0
]);
1381 pDesc
->pRDInfo
->curr_desc
= cpu_to_le32(curr
);
1382 pDesc
->next_desc
= cpu_to_le32(curr
+ sizeof(SRxDesc
));
1386 pDevice
->aRD0Ring
[i
-1].next_desc
= cpu_to_le32(pDevice
->rd0_pool_dma
);
1387 pDevice
->pCurrRD
[0] = &(pDevice
->aRD0Ring
[0]);
1391 static void device_init_rd1_ring(PSDevice pDevice
) {
1393 dma_addr_t curr
= pDevice
->rd1_pool_dma
;
1396 /* Init the RD1 ring entries */
1397 for (i
= 0; i
< pDevice
->sOpts
.nRxDescs1
; i
++, curr
+= sizeof(SRxDesc
)) {
1398 pDesc
= &(pDevice
->aRD1Ring
[i
]);
1399 pDesc
->pRDInfo
= alloc_rd_info();
1400 ASSERT(pDesc
->pRDInfo
);
1401 if (!device_alloc_rx_buf(pDevice
, pDesc
)) {
1402 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc rx bufs\n",
1403 pDevice
->dev
->name
);
1405 pDesc
->next
= &(pDevice
->aRD1Ring
[(i
+1) % pDevice
->sOpts
.nRxDescs1
]);
1406 pDesc
->pRDInfo
->curr_desc
= cpu_to_le32(curr
);
1407 pDesc
->next_desc
= cpu_to_le32(curr
+ sizeof(SRxDesc
));
1411 pDevice
->aRD1Ring
[i
-1].next_desc
= cpu_to_le32(pDevice
->rd1_pool_dma
);
1412 pDevice
->pCurrRD
[1] = &(pDevice
->aRD1Ring
[0]);
1416 static void device_init_defrag_cb(PSDevice pDevice
) {
1418 PSDeFragControlBlock pDeF
;
1420 /* Init the fragment ctl entries */
1421 for (i
= 0; i
< CB_MAX_RX_FRAG
; i
++) {
1422 pDeF
= &(pDevice
->sRxDFCB
[i
]);
1423 if (!device_alloc_frag_buf(pDevice
, pDeF
)) {
1424 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc frag bufs\n",
1425 pDevice
->dev
->name
);
1428 pDevice
->cbDFCB
= CB_MAX_RX_FRAG
;
1429 pDevice
->cbFreeDFCB
= pDevice
->cbDFCB
;
1435 static void device_free_rd0_ring(PSDevice pDevice
) {
1438 for (i
= 0; i
< pDevice
->sOpts
.nRxDescs0
; i
++) {
1439 PSRxDesc pDesc
=&(pDevice
->aRD0Ring
[i
]);
1440 PDEVICE_RD_INFO pRDInfo
=pDesc
->pRDInfo
;
1442 pci_unmap_single(pDevice
->pcid
,pRDInfo
->skb_dma
,
1443 pDevice
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1445 dev_kfree_skb(pRDInfo
->skb
);
1447 kfree((void *)pDesc
->pRDInfo
);
1452 static void device_free_rd1_ring(PSDevice pDevice
) {
1456 for (i
= 0; i
< pDevice
->sOpts
.nRxDescs1
; i
++) {
1457 PSRxDesc pDesc
=&(pDevice
->aRD1Ring
[i
]);
1458 PDEVICE_RD_INFO pRDInfo
=pDesc
->pRDInfo
;
1460 pci_unmap_single(pDevice
->pcid
,pRDInfo
->skb_dma
,
1461 pDevice
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1463 dev_kfree_skb(pRDInfo
->skb
);
1465 kfree((void *)pDesc
->pRDInfo
);
1470 static void device_free_frag_buf(PSDevice pDevice
) {
1471 PSDeFragControlBlock pDeF
;
1474 for (i
= 0; i
< CB_MAX_RX_FRAG
; i
++) {
1476 pDeF
= &(pDevice
->sRxDFCB
[i
]);
1479 dev_kfree_skb(pDeF
->skb
);
1485 static void device_init_td0_ring(PSDevice pDevice
) {
1490 curr
= pDevice
->td0_pool_dma
;
1491 for (i
= 0; i
< pDevice
->sOpts
.nTxDescs
[0]; i
++, curr
+= sizeof(STxDesc
)) {
1492 pDesc
= &(pDevice
->apTD0Rings
[i
]);
1493 pDesc
->pTDInfo
= alloc_td_info();
1494 ASSERT(pDesc
->pTDInfo
);
1495 if (pDevice
->flags
& DEVICE_FLAGS_TX_ALIGN
) {
1496 pDesc
->pTDInfo
->buf
= pDevice
->tx0_bufs
+ (i
)*PKT_BUF_SZ
;
1497 pDesc
->pTDInfo
->buf_dma
= pDevice
->tx_bufs_dma0
+ (i
)*PKT_BUF_SZ
;
1499 pDesc
->next
=&(pDevice
->apTD0Rings
[(i
+1) % pDevice
->sOpts
.nTxDescs
[0]]);
1500 pDesc
->pTDInfo
->curr_desc
= cpu_to_le32(curr
);
1501 pDesc
->next_desc
= cpu_to_le32(curr
+sizeof(STxDesc
));
1505 pDevice
->apTD0Rings
[i
-1].next_desc
= cpu_to_le32(pDevice
->td0_pool_dma
);
1506 pDevice
->apTailTD
[0] = pDevice
->apCurrTD
[0] =&(pDevice
->apTD0Rings
[0]);
1510 static void device_init_td1_ring(PSDevice pDevice
) {
1515 /* Init the TD ring entries */
1516 curr
=pDevice
->td1_pool_dma
;
1517 for (i
= 0; i
< pDevice
->sOpts
.nTxDescs
[1]; i
++, curr
+=sizeof(STxDesc
)) {
1518 pDesc
=&(pDevice
->apTD1Rings
[i
]);
1519 pDesc
->pTDInfo
= alloc_td_info();
1520 ASSERT(pDesc
->pTDInfo
);
1521 if (pDevice
->flags
& DEVICE_FLAGS_TX_ALIGN
) {
1522 pDesc
->pTDInfo
->buf
=pDevice
->tx1_bufs
+(i
)*PKT_BUF_SZ
;
1523 pDesc
->pTDInfo
->buf_dma
=pDevice
->tx_bufs_dma1
+(i
)*PKT_BUF_SZ
;
1525 pDesc
->next
=&(pDevice
->apTD1Rings
[(i
+1) % pDevice
->sOpts
.nTxDescs
[1]]);
1526 pDesc
->pTDInfo
->curr_desc
= cpu_to_le32(curr
);
1527 pDesc
->next_desc
= cpu_to_le32(curr
+sizeof(STxDesc
));
1531 pDevice
->apTD1Rings
[i
-1].next_desc
= cpu_to_le32(pDevice
->td1_pool_dma
);
1532 pDevice
->apTailTD
[1] = pDevice
->apCurrTD
[1] = &(pDevice
->apTD1Rings
[0]);
1537 static void device_free_td0_ring(PSDevice pDevice
) {
1539 for (i
= 0; i
< pDevice
->sOpts
.nTxDescs
[0]; i
++) {
1540 PSTxDesc pDesc
=&(pDevice
->apTD0Rings
[i
]);
1541 PDEVICE_TD_INFO pTDInfo
=pDesc
->pTDInfo
;
1543 if (pTDInfo
->skb_dma
&& (pTDInfo
->skb_dma
!= pTDInfo
->buf_dma
))
1544 pci_unmap_single(pDevice
->pcid
,pTDInfo
->skb_dma
,
1545 pTDInfo
->skb
->len
, PCI_DMA_TODEVICE
);
1548 dev_kfree_skb(pTDInfo
->skb
);
1550 kfree((void *)pDesc
->pTDInfo
);
1554 static void device_free_td1_ring(PSDevice pDevice
) {
1557 for (i
= 0; i
< pDevice
->sOpts
.nTxDescs
[1]; i
++) {
1558 PSTxDesc pDesc
=&(pDevice
->apTD1Rings
[i
]);
1559 PDEVICE_TD_INFO pTDInfo
=pDesc
->pTDInfo
;
1561 if (pTDInfo
->skb_dma
&& (pTDInfo
->skb_dma
!= pTDInfo
->buf_dma
))
1562 pci_unmap_single(pDevice
->pcid
, pTDInfo
->skb_dma
,
1563 pTDInfo
->skb
->len
, PCI_DMA_TODEVICE
);
1566 dev_kfree_skb(pTDInfo
->skb
);
1568 kfree((void *)pDesc
->pTDInfo
);
1575 /*-----------------------------------------------------------------*/
1577 static int device_rx_srv(PSDevice pDevice
, unsigned int uIdx
) {
1582 for (pRD
= pDevice
->pCurrRD
[uIdx
];
1583 pRD
->m_rd0RD0
.f1Owner
== OWNED_BY_HOST
;
1585 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->pCurrRD = %x, works = %d\n", pRD, works);
1588 if (device_receive_frame(pDevice
, pRD
)) {
1589 if (!device_alloc_rx_buf(pDevice
,pRD
)) {
1590 DBG_PRT(MSG_LEVEL_ERR
, KERN_ERR
1591 "%s: can not allocate rx buf\n", pDevice
->dev
->name
);
1595 pRD
->m_rd0RD0
.f1Owner
= OWNED_BY_NIC
;
1596 pDevice
->dev
->last_rx
= jiffies
;
1599 pDevice
->pCurrRD
[uIdx
]=pRD
;
1605 static bool device_alloc_rx_buf(PSDevice pDevice
, PSRxDesc pRD
) {
1607 PDEVICE_RD_INFO pRDInfo
=pRD
->pRDInfo
;
1610 pRDInfo
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1612 //printk("device_alloc_rx_buf:skb is %x\n",pRDInfo->skb);
1614 if (pRDInfo
->skb
==NULL
)
1616 ASSERT(pRDInfo
->skb
);
1617 pRDInfo
->skb
->dev
= pDevice
->dev
;
1618 pRDInfo
->skb_dma
= pci_map_single(pDevice
->pcid
, skb_tail_pointer(pRDInfo
->skb
),
1619 pDevice
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
1620 *((unsigned int *) &(pRD
->m_rd0RD0
)) = 0; /* FIX cast */
1622 pRD
->m_rd0RD0
.wResCount
= cpu_to_le16(pDevice
->rx_buf_sz
);
1623 pRD
->m_rd0RD0
.f1Owner
= OWNED_BY_NIC
;
1624 pRD
->m_rd1RD1
.wReqCount
= cpu_to_le16(pDevice
->rx_buf_sz
);
1625 pRD
->buff_addr
= cpu_to_le32(pRDInfo
->skb_dma
);
1632 bool device_alloc_frag_buf(PSDevice pDevice
, PSDeFragControlBlock pDeF
) {
1634 pDeF
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1635 if (pDeF
->skb
== NULL
)
1638 pDeF
->skb
->dev
= pDevice
->dev
;
1645 static int device_tx_srv(PSDevice pDevice
, unsigned int uIdx
) {
1649 unsigned char byTsr0
;
1650 unsigned char byTsr1
;
1651 unsigned int uFrameSize
, uFIFOHeaderSize
;
1652 PSTxBufHead pTxBufHead
;
1653 struct net_device_stats
* pStats
= &pDevice
->stats
;
1654 struct sk_buff
* skb
;
1655 unsigned int uNodeIndex
;
1656 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1659 for (pTD
= pDevice
->apTailTD
[uIdx
]; pDevice
->iTDUsed
[uIdx
] >0; pTD
= pTD
->next
) {
1661 if (pTD
->m_td0TD0
.f1Owner
== OWNED_BY_NIC
)
1666 byTsr0
= pTD
->m_td0TD0
.byTSR0
;
1667 byTsr1
= pTD
->m_td0TD0
.byTSR1
;
1669 //Only the status of first TD in the chain is correct
1670 if (pTD
->m_td1TD1
.byTCR
& TCR_STP
) {
1672 if ((pTD
->pTDInfo
->byFlags
& TD_FLAGS_NETIF_SKB
) != 0) {
1673 uFIFOHeaderSize
= pTD
->pTDInfo
->dwHeaderLength
;
1674 uFrameSize
= pTD
->pTDInfo
->dwReqCount
- uFIFOHeaderSize
;
1675 pTxBufHead
= (PSTxBufHead
) (pTD
->pTDInfo
->buf
);
1676 // Update the statistics based on the Transmit status
1677 // now, we DONT check TSR0_CDH
1679 STAvUpdateTDStatCounter(&pDevice
->scStatistic
,
1681 (unsigned char *)(pTD
->pTDInfo
->buf
+ uFIFOHeaderSize
),
1685 BSSvUpdateNodeTxCounter(pDevice
,
1687 (unsigned char *)(pTD
->pTDInfo
->buf
),
1691 if ( !(byTsr1
& TSR1_TERR
)) {
1693 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1694 (int)uIdx
, byTsr1
, byTsr0
);
1696 if ((pTxBufHead
->wFragCtl
& FRAGCTL_ENDFRAG
) != FRAGCTL_NONFRAG
) {
1697 pDevice
->s802_11Counter
.TransmittedFragmentCount
++;
1699 pStats
->tx_packets
++;
1700 pStats
->tx_bytes
+= pTD
->pTDInfo
->skb
->len
;
1703 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1704 (int)uIdx
, byTsr1
, byTsr0
);
1705 pStats
->tx_errors
++;
1706 pStats
->tx_dropped
++;
1710 if ((pTD
->pTDInfo
->byFlags
& TD_FLAGS_PRIV_SKB
) != 0) {
1711 if (pDevice
->bEnableHostapd
) {
1712 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"tx call back netif.. \n");
1713 skb
= pTD
->pTDInfo
->skb
;
1714 skb
->dev
= pDevice
->apdev
;
1715 skb_reset_mac_header(skb
);
1716 skb
->pkt_type
= PACKET_OTHERHOST
;
1717 //skb->protocol = htons(ETH_P_802_2);
1718 memset(skb
->cb
, 0, sizeof(skb
->cb
));
1723 if (byTsr1
& TSR1_TERR
) {
1724 if ((pTD
->pTDInfo
->byFlags
& TD_FLAGS_PRIV_SKB
) != 0) {
1725 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1726 (int)uIdx
, byTsr1
, byTsr0
);
1729 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1730 // (int)uIdx, byTsr1, byTsr0);
1732 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) &&
1733 (pTD
->pTDInfo
->byFlags
& TD_FLAGS_NETIF_SKB
)) {
1734 unsigned short wAID
;
1735 unsigned char byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1737 skb
= pTD
->pTDInfo
->skb
;
1738 if (BSSDBbIsSTAInNodeDB(pMgmt
, (unsigned char *)(skb
->data
), &uNodeIndex
)) {
1739 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bPSEnable
) {
1740 skb_queue_tail(&pMgmt
->sNodeDBTable
[uNodeIndex
].sTxPSQueue
, skb
);
1741 pMgmt
->sNodeDBTable
[uNodeIndex
].wEnQueueCnt
++;
1743 wAID
= pMgmt
->sNodeDBTable
[uNodeIndex
].wAID
;
1744 pMgmt
->abyPSTxMap
[wAID
>> 3] |= byMask
[wAID
& 7];
1745 pTD
->pTDInfo
->byFlags
&= ~(TD_FLAGS_NETIF_SKB
);
1746 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1747 ,(int)uNodeIndex
, pMgmt
->sNodeDBTable
[uNodeIndex
].wEnQueueCnt
);
1748 pStats
->tx_errors
--;
1749 pStats
->tx_dropped
--;
1754 device_free_tx_buf(pDevice
,pTD
);
1755 pDevice
->iTDUsed
[uIdx
]--;
1760 if (uIdx
== TYPE_AC0DMA
) {
1761 // RESERV_AC0DMA reserved for relay
1763 if (AVAIL_TD(pDevice
, uIdx
) < RESERV_AC0DMA
) {
1765 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" AC0DMA is Full = %d\n", pDevice
->iTDUsed
[uIdx
]);
1767 if (netif_queue_stopped(pDevice
->dev
) && (bFull
==false)){
1768 netif_wake_queue(pDevice
->dev
);
1773 pDevice
->apTailTD
[uIdx
] = pTD
;
1779 static void device_error(PSDevice pDevice
, unsigned short status
) {
1781 if (status
& ISR_FETALERR
) {
1782 DBG_PRT(MSG_LEVEL_ERR
, KERN_ERR
1783 "%s: Hardware fatal error.\n",
1784 pDevice
->dev
->name
);
1785 netif_stop_queue(pDevice
->dev
);
1786 del_timer(&pDevice
->sTimerCommand
);
1787 del_timer(&(pDevice
->pMgmt
->sTimerSecondCallback
));
1788 pDevice
->bCmdRunning
= false;
1789 MACbShutdown(pDevice
->PortOffset
);
1795 static void device_free_tx_buf(PSDevice pDevice
, PSTxDesc pDesc
) {
1796 PDEVICE_TD_INFO pTDInfo
=pDesc
->pTDInfo
;
1797 struct sk_buff
* skb
=pTDInfo
->skb
;
1799 // pre-allocated buf_dma can't be unmapped.
1800 if (pTDInfo
->skb_dma
&& (pTDInfo
->skb_dma
!= pTDInfo
->buf_dma
)) {
1801 pci_unmap_single(pDevice
->pcid
,pTDInfo
->skb_dma
,skb
->len
,
1805 if ((pTDInfo
->byFlags
& TD_FLAGS_NETIF_SKB
) != 0)
1806 dev_kfree_skb_irq(skb
);
1808 pTDInfo
->skb_dma
= 0;
1810 pTDInfo
->byFlags
= 0;
1816 void InitRxManagementQueue(PSDevice pDevice
)
1818 pDevice
->rxManeQueue
.packet_num
= 0;
1819 pDevice
->rxManeQueue
.head
= pDevice
->rxManeQueue
.tail
= 0;
1831 PSDevice pDevice
= (PSDevice
) Context
;
1832 PSRxMgmtPacket pRxMgmtPacket
;
1834 //complete(&pDevice->notify);
1835 //printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
1837 //printk("Enter MlmeThread,packet _num is %d\n",pDevice->rxManeQueue.packet_num);
1844 //down(&pDevice->mlme_semaphore);
1845 // pRxMgmtPacket = DeQueue(pDevice);
1847 spin_lock_irq(&pDevice
->lock
);
1848 while(pDevice
->rxManeQueue
.packet_num
!= 0)
1850 pRxMgmtPacket
= DeQueue(pDevice
);
1852 //DequeueManageObject(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
1853 vMgrRxManagePacket(pDevice
, pDevice
->pMgmt
, pRxMgmtPacket
);
1854 //printk("packet_num is %d\n",pDevice->rxManeQueue.packet_num);
1857 spin_unlock_irq(&pDevice
->lock
);
1862 //printk("Before schedule thread jiffies is %x\n",jiffies);
1864 //printk("after schedule thread jiffies is %x\n",jiffies);
1867 //printk("i is %d\n",i);
1877 static int device_open(struct net_device
*dev
) {
1878 PSDevice pDevice
=(PSDevice
) netdev_priv(dev
);
1880 #ifdef WPA_SM_Transtatus
1881 extern SWPAResult wpa_Result
;
1884 pDevice
->rx_buf_sz
= PKT_BUF_SZ
;
1885 if (!device_init_rings(pDevice
)) {
1888 //2008-5-13 <add> by chester
1889 i
=request_irq(pDevice
->pcid
->irq
, &device_intr
, IRQF_SHARED
, dev
->name
, dev
);
1892 //printk("DEBUG1\n");
1893 #ifdef WPA_SM_Transtatus
1894 memset(wpa_Result
.ifname
,0,sizeof(wpa_Result
.ifname
));
1895 wpa_Result
.proto
= 0;
1896 wpa_Result
.key_mgmt
= 0;
1897 wpa_Result
.eap_type
= 0;
1898 wpa_Result
.authenticated
= false;
1899 pDevice
->fWPA_Authened
= false;
1901 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"call device init rd0 ring\n");
1902 device_init_rd0_ring(pDevice
);
1903 device_init_rd1_ring(pDevice
);
1904 device_init_defrag_cb(pDevice
);
1905 device_init_td0_ring(pDevice
);
1906 device_init_td1_ring(pDevice
);
1907 // VNTWIFIvSet11h(pDevice->pMgmt, pDevice->b11hEnable);
1910 if (pDevice
->bDiversityRegCtlON
) {
1911 device_init_diversity_timer(pDevice
);
1913 vMgrObjectInit(pDevice
);
1914 vMgrTimerInit(pDevice
);
1918 tasklet_init (&pDevice
->RxMngWorkItem
,(void *)MngWorkItem
,(unsigned long )pDevice
);
1921 InitRxManagementQueue(pDevice
);
1923 mlme_task
= kthread_run(MlmeThread
,(void *) pDevice
, "MLME");
1924 if (IS_ERR(mlme_task
)) {
1925 printk("thread create fail\n");
1934 //printk("thread id is %d\n",pDevice->MLMEThr_pid);
1935 //printk("Create thread time is %x\n",jiffies);
1936 //wait_for_completion(&pDevice->notify);
1941 // if (( SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL)&0x06)==0x04)
1943 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"call device_init_registers\n");
1944 device_init_registers(pDevice
, DEVICE_INIT_COLD
);
1945 MACvReadEtherAddress(pDevice
->PortOffset
, pDevice
->abyCurrentNetAddr
);
1946 memcpy(pDevice
->pMgmt
->abyMACAddr
, pDevice
->abyCurrentNetAddr
, ETH_ALEN
);
1947 device_set_multi(pDevice
->dev
);
1949 // Init for Key Management
1950 KeyvInitTable(&pDevice
->sKey
, pDevice
->PortOffset
);
1951 add_timer(&(pDevice
->pMgmt
->sTimerSecondCallback
));
1953 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1955 pDevice->bwextstep0 = false;
1956 pDevice->bwextstep1 = false;
1957 pDevice->bwextstep2 = false;
1958 pDevice->bwextstep3 = false;
1960 pDevice
->bwextcount
=0;
1961 pDevice
->bWPASuppWextEnabled
= false;
1963 pDevice
->byReAssocCount
= 0;
1964 pDevice
->bWPADEVUp
= false;
1965 // Patch: if WEP key already set by iwconfig but device not yet open
1966 if ((pDevice
->bEncryptionEnable
== true) && (pDevice
->bTransmitKey
== true)) {
1967 KeybSetDefaultKey(&(pDevice
->sKey
),
1968 (unsigned long)(pDevice
->byKeyIndex
| (1 << 31)),
1969 pDevice
->uKeyLength
,
1973 pDevice
->PortOffset
,
1976 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1979 //printk("DEBUG2\n");
1982 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"call MACvIntEnable\n");
1983 MACvIntEnable(pDevice
->PortOffset
, IMR_MASK_VALUE
);
1985 if (pDevice
->pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
1986 bScheduleCommand((void *)pDevice
, WLAN_CMD_RUN_AP
, NULL
);
1989 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
1990 bScheduleCommand((void *)pDevice
, WLAN_CMD_SSID
, NULL
);
1992 pDevice
->flags
|=DEVICE_FLAGS_OPENED
;
1994 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_open success.. \n");
1999 static int device_close(struct net_device
*dev
) {
2000 PSDevice pDevice
=(PSDevice
) netdev_priv(dev
);
2001 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
2007 //2007-1121-02<Add>by EinsnLiu
2008 if (pDevice
->bLinkPass
) {
2009 bScheduleCommand((void *)pDevice
, WLAN_CMD_DISASSOCIATE
, NULL
);
2013 del_timer(&pDevice
->sTimerTxData
);
2015 del_timer(&pDevice
->sTimerCommand
);
2016 del_timer(&pMgmt
->sTimerSecondCallback
);
2017 if (pDevice
->bDiversityRegCtlON
) {
2018 del_timer(&pDevice
->TimerSQ3Tmax1
);
2019 del_timer(&pDevice
->TimerSQ3Tmax2
);
2020 del_timer(&pDevice
->TimerSQ3Tmax3
);
2024 tasklet_kill(&pDevice
->RxMngWorkItem
);
2026 netif_stop_queue(dev
);
2027 pDevice
->bCmdRunning
= false;
2028 MACbShutdown(pDevice
->PortOffset
);
2029 MACbSoftwareReset(pDevice
->PortOffset
);
2030 CARDbRadioPowerOff(pDevice
);
2032 pDevice
->bLinkPass
= false;
2033 memset(pMgmt
->abyCurrBSSID
, 0, 6);
2034 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
2035 device_free_td0_ring(pDevice
);
2036 device_free_td1_ring(pDevice
);
2037 device_free_rd0_ring(pDevice
);
2038 device_free_rd1_ring(pDevice
);
2039 device_free_frag_buf(pDevice
);
2040 device_free_rings(pDevice
);
2041 BSSvClearNodeDBTable(pDevice
, 0);
2042 free_irq(dev
->irq
, dev
);
2043 pDevice
->flags
&=(~DEVICE_FLAGS_OPENED
);
2044 //2008-0714-01<Add>by chester
2045 device_release_WPADEV(pDevice
);
2047 //tasklet_kill(&pDevice->RxMngWorkItem);
2049 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_close.. \n");
2055 static int device_dma0_tx_80211(struct sk_buff
*skb
, struct net_device
*dev
) {
2056 PSDevice pDevice
=netdev_priv(dev
);
2057 unsigned char *pbMPDU
;
2058 unsigned int cbMPDULen
= 0;
2061 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_dma0_tx_80211\n");
2062 spin_lock_irq(&pDevice
->lock
);
2064 if (AVAIL_TD(pDevice
, TYPE_TXDMA0
) <= 0) {
2065 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_dma0_tx_80211, td0 <=0\n");
2066 dev_kfree_skb_irq(skb
);
2067 spin_unlock_irq(&pDevice
->lock
);
2071 if (pDevice
->bStopTx0Pkt
== true) {
2072 dev_kfree_skb_irq(skb
);
2073 spin_unlock_irq(&pDevice
->lock
);
2077 cbMPDULen
= skb
->len
;
2080 vDMA0_tx_80211(pDevice
, skb
, pbMPDU
, cbMPDULen
);
2082 spin_unlock_irq(&pDevice
->lock
);
2090 bool device_dma0_xmit(PSDevice pDevice
, struct sk_buff
*skb
, unsigned int uNodeIndex
) {
2091 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
2092 PSTxDesc pHeadTD
, pLastTD
;
2093 unsigned int cbFrameBodySize
;
2094 unsigned int uMACfragNum
;
2095 unsigned char byPktType
;
2096 bool bNeedEncryption
= false;
2097 PSKeyItem pTransmitKey
= NULL
;
2098 unsigned int cbHeaderSize
;
2101 // unsigned char byKeyIndex = 0;
2104 if (pDevice
->bStopTx0Pkt
== true) {
2105 dev_kfree_skb_irq(skb
);
2109 if (AVAIL_TD(pDevice
, TYPE_TXDMA0
) <= 0) {
2110 dev_kfree_skb_irq(skb
);
2111 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_dma0_xmit, td0 <=0\n");
2115 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
2116 if (pDevice
->uAssocCount
== 0) {
2117 dev_kfree_skb_irq(skb
);
2118 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"device_dma0_xmit, assocCount = 0\n");
2123 pHeadTD
= pDevice
->apCurrTD
[TYPE_TXDMA0
];
2125 pHeadTD
->m_td1TD1
.byTCR
= (TCR_EDP
|TCR_STP
);
2127 memcpy(pDevice
->sTxEthHeader
.abyDstAddr
, (unsigned char *)(skb
->data
), ETH_HLEN
);
2128 cbFrameBodySize
= skb
->len
- ETH_HLEN
;
2131 if (ntohs(pDevice
->sTxEthHeader
.wType
) > ETH_DATA_LEN
) {
2132 cbFrameBodySize
+= 8;
2134 uMACfragNum
= cbGetFragCount(pDevice
, pTransmitKey
, cbFrameBodySize
, &pDevice
->sTxEthHeader
);
2136 if ( uMACfragNum
> AVAIL_TD(pDevice
, TYPE_TXDMA0
)) {
2137 dev_kfree_skb_irq(skb
);
2140 byPktType
= (unsigned char)pDevice
->byPacketType
;
2143 if (pDevice
->bFixRate
) {
2144 if (pDevice
->eCurrentPHYType
== PHY_TYPE_11B
) {
2145 if (pDevice
->uConnectionRate
>= RATE_11M
) {
2146 pDevice
->wCurrentRate
= RATE_11M
;
2148 pDevice
->wCurrentRate
= (unsigned short)pDevice
->uConnectionRate
;
2151 if (pDevice
->uConnectionRate
>= RATE_54M
)
2152 pDevice
->wCurrentRate
= RATE_54M
;
2154 pDevice
->wCurrentRate
= (unsigned short)pDevice
->uConnectionRate
;
2158 pDevice
->wCurrentRate
= pDevice
->pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
;
2162 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bShortPreamble
) {
2163 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2166 pDevice
->byPreambleType
= PREAMBLE_LONG
;
2169 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dma0: pDevice->wCurrentRate = %d \n", pDevice
->wCurrentRate
);
2172 if (pDevice
->wCurrentRate
<= RATE_11M
) {
2173 byPktType
= PK_TYPE_11B
;
2174 } else if (pDevice
->eCurrentPHYType
== PHY_TYPE_11A
) {
2175 byPktType
= PK_TYPE_11A
;
2177 if (pDevice
->bProtectMode
== true) {
2178 byPktType
= PK_TYPE_11GB
;
2180 byPktType
= PK_TYPE_11GA
;
2184 if (pDevice
->bEncryptionEnable
== true)
2185 bNeedEncryption
= true;
2187 if (pDevice
->bEnableHostWEP
) {
2188 pTransmitKey
= &STempKey
;
2189 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2190 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2191 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2192 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2193 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2194 memcpy(pTransmitKey
->abyKey
,
2195 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2196 pTransmitKey
->uKeyLength
2199 vGenerateFIFOHeader(pDevice
, byPktType
, pDevice
->pbyTmpBuff
, bNeedEncryption
,
2200 cbFrameBodySize
, TYPE_TXDMA0
, pHeadTD
,
2201 &pDevice
->sTxEthHeader
, (unsigned char *)skb
->data
, pTransmitKey
, uNodeIndex
,
2206 if (MACbIsRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PS
)) {
2208 MACbPSWakeup(pDevice
->PortOffset
);
2211 pDevice
->bPWBitOn
= false;
2214 for (ii
= 0; ii
< uMACfragNum
; ii
++) {
2215 // Poll Transmit the adapter
2217 pHeadTD
->m_td0TD0
.f1Owner
=OWNED_BY_NIC
;
2219 if (ii
== (uMACfragNum
- 1))
2221 pHeadTD
= pHeadTD
->next
;
2224 // Save the information needed by the tx interrupt handler
2225 // to complete the Send request
2226 pLastTD
->pTDInfo
->skb
= skb
;
2227 pLastTD
->pTDInfo
->byFlags
= 0;
2228 pLastTD
->pTDInfo
->byFlags
|= TD_FLAGS_NETIF_SKB
;
2230 pDevice
->apCurrTD
[TYPE_TXDMA0
] = pHeadTD
;
2232 MACvTransmit0(pDevice
->PortOffset
);
2238 //TYPE_AC0DMA data tx
2239 static int device_xmit(struct sk_buff
*skb
, struct net_device
*dev
) {
2240 PSDevice pDevice
=netdev_priv(dev
);
2242 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
2243 PSTxDesc pHeadTD
, pLastTD
;
2244 unsigned int uNodeIndex
= 0;
2245 unsigned char byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2246 unsigned short wAID
;
2247 unsigned int uMACfragNum
= 1;
2248 unsigned int cbFrameBodySize
;
2249 unsigned char byPktType
;
2250 unsigned int cbHeaderSize
;
2251 bool bNeedEncryption
= false;
2252 PSKeyItem pTransmitKey
= NULL
;
2255 bool bTKIP_UseGTK
= false;
2256 bool bNeedDeAuth
= false;
2257 unsigned char *pbyBSSID
;
2258 bool bNodeExist
= false;
2262 spin_lock_irq(&pDevice
->lock
);
2263 if (pDevice
->bLinkPass
== false) {
2264 dev_kfree_skb_irq(skb
);
2265 spin_unlock_irq(&pDevice
->lock
);
2269 if (pDevice
->bStopDataPkt
) {
2270 dev_kfree_skb_irq(skb
);
2271 spin_unlock_irq(&pDevice
->lock
);
2276 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
2277 if (pDevice
->uAssocCount
== 0) {
2278 dev_kfree_skb_irq(skb
);
2279 spin_unlock_irq(&pDevice
->lock
);
2282 if (is_multicast_ether_addr((unsigned char *)(skb
->data
))) {
2285 if (pMgmt
->sNodeDBTable
[0].bPSEnable
) {
2286 skb_queue_tail(&(pMgmt
->sNodeDBTable
[0].sTxPSQueue
), skb
);
2287 pMgmt
->sNodeDBTable
[0].wEnQueueCnt
++;
2289 pMgmt
->abyPSTxMap
[0] |= byMask
[0];
2290 spin_unlock_irq(&pDevice
->lock
);
2294 if (BSSDBbIsSTAInNodeDB(pMgmt
, (unsigned char *)(skb
->data
), &uNodeIndex
)) {
2295 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bPSEnable
) {
2296 skb_queue_tail(&pMgmt
->sNodeDBTable
[uNodeIndex
].sTxPSQueue
, skb
);
2297 pMgmt
->sNodeDBTable
[uNodeIndex
].wEnQueueCnt
++;
2299 wAID
= pMgmt
->sNodeDBTable
[uNodeIndex
].wAID
;
2300 pMgmt
->abyPSTxMap
[wAID
>> 3] |= byMask
[wAID
& 7];
2301 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set:pMgmt->abyPSTxMap[%d]= %d\n",
2302 (wAID
>> 3), pMgmt
->abyPSTxMap
[wAID
>> 3]);
2303 spin_unlock_irq(&pDevice
->lock
);
2307 if (pMgmt
->sNodeDBTable
[uNodeIndex
].bShortPreamble
) {
2308 pDevice
->byPreambleType
= pDevice
->byShortPreamble
;
2311 pDevice
->byPreambleType
= PREAMBLE_LONG
;
2318 if (bNodeExist
== false) {
2319 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Unknown STA not found in node DB \n");
2320 dev_kfree_skb_irq(skb
);
2321 spin_unlock_irq(&pDevice
->lock
);
2326 pHeadTD
= pDevice
->apCurrTD
[TYPE_AC0DMA
];
2328 pHeadTD
->m_td1TD1
.byTCR
= (TCR_EDP
|TCR_STP
);
2331 memcpy(pDevice
->sTxEthHeader
.abyDstAddr
, (unsigned char *)(skb
->data
), ETH_HLEN
);
2332 cbFrameBodySize
= skb
->len
- ETH_HLEN
;
2334 if (ntohs(pDevice
->sTxEthHeader
.wType
) > ETH_DATA_LEN
) {
2335 cbFrameBodySize
+= 8;
2339 if (pDevice
->bEncryptionEnable
== true) {
2340 bNeedEncryption
= true;
2343 if ((pDevice
->pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
2344 (pDevice
->pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
2345 pbyBSSID
= pDevice
->abyBSSID
;
2347 if (KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == false) {
2349 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == true) {
2350 bTKIP_UseGTK
= true;
2351 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2355 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get PTK.\n");
2358 }else if (pDevice
->pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
2360 pbyBSSID
= pDevice
->sTxEthHeader
.abyDstAddr
; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2361 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"IBSS Serach Key: \n");
2362 for (ii
= 0; ii
< 6; ii
++)
2363 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"%x \n", *(pbyBSSID
+ii
));
2364 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"\n");
2367 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == true)
2371 pbyBSSID
= pDevice
->abyBroadcastAddr
;
2372 if(KeybGetTransmitKey(&(pDevice
->sKey
), pbyBSSID
, GROUP_KEY
, &pTransmitKey
) == false) {
2373 pTransmitKey
= NULL
;
2374 if (pDevice
->pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
2375 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"IBSS and KEY is NULL. [%d]\n", pDevice
->pMgmt
->eCurrMode
);
2378 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"NOT IBSS and KEY is NULL. [%d]\n", pDevice
->pMgmt
->eCurrMode
);
2380 bTKIP_UseGTK
= true;
2381 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"Get GTK.\n");
2386 if (pDevice
->bEnableHostWEP
) {
2387 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_DEBUG
"acdma0: STA index %d\n", uNodeIndex
);
2388 if (pDevice
->bEncryptionEnable
== true) {
2389 pTransmitKey
= &STempKey
;
2390 pTransmitKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[uNodeIndex
].byCipherSuite
;
2391 pTransmitKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
;
2392 pTransmitKey
->uKeyLength
= pMgmt
->sNodeDBTable
[uNodeIndex
].uWepKeyLength
;
2393 pTransmitKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[uNodeIndex
].dwTSC47_16
;
2394 pTransmitKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[uNodeIndex
].wTSC15_0
;
2395 memcpy(pTransmitKey
->abyKey
,
2396 &pMgmt
->sNodeDBTable
[uNodeIndex
].abyWepKey
[0],
2397 pTransmitKey
->uKeyLength
2402 uMACfragNum
= cbGetFragCount(pDevice
, pTransmitKey
, cbFrameBodySize
, &pDevice
->sTxEthHeader
);
2404 if (uMACfragNum
> AVAIL_TD(pDevice
, TYPE_AC0DMA
)) {
2405 DBG_PRT(MSG_LEVEL_ERR
, KERN_DEBUG
"uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum
);
2406 dev_kfree_skb_irq(skb
);
2407 spin_unlock_irq(&pDevice
->lock
);
2411 if (pTransmitKey
!= NULL
) {
2412 if ((pTransmitKey
->byCipherSuite
== KEY_CTL_WEP
) &&
2413 (pTransmitKey
->uKeyLength
== WLAN_WEP232_KEYLEN
)) {
2414 uMACfragNum
= 1; //WEP256 doesn't support fragment
2418 byPktType
= (unsigned char)pDevice
->byPacketType
;
2420 if (pDevice
->bFixRate
) {
2422 printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n",pDevice
->eCurrentPHYType
,pDevice
->uConnectionRate
);
2425 if (pDevice
->eCurrentPHYType
== PHY_TYPE_11B
) {
2426 if (pDevice
->uConnectionRate
>= RATE_11M
) {
2427 pDevice
->wCurrentRate
= RATE_11M
;
2429 pDevice
->wCurrentRate
= (unsigned short)pDevice
->uConnectionRate
;
2432 if ((pDevice
->eCurrentPHYType
== PHY_TYPE_11A
) &&
2433 (pDevice
->uConnectionRate
<= RATE_6M
)) {
2434 pDevice
->wCurrentRate
= RATE_6M
;
2436 if (pDevice
->uConnectionRate
>= RATE_54M
)
2437 pDevice
->wCurrentRate
= RATE_54M
;
2439 pDevice
->wCurrentRate
= (unsigned short)pDevice
->uConnectionRate
;
2443 pDevice
->byACKRate
= (unsigned char) pDevice
->wCurrentRate
;
2444 pDevice
->byTopCCKBasicRate
= RATE_1M
;
2445 pDevice
->byTopOFDMBasicRate
= RATE_6M
;
2449 if (pDevice
->sTxEthHeader
.wType
== TYPE_PKT_802_1x
) {
2450 if (pDevice
->eCurrentPHYType
!= PHY_TYPE_11A
) {
2451 pDevice
->wCurrentRate
= RATE_1M
;
2452 pDevice
->byACKRate
= RATE_1M
;
2453 pDevice
->byTopCCKBasicRate
= RATE_1M
;
2454 pDevice
->byTopOFDMBasicRate
= RATE_6M
;
2456 pDevice
->wCurrentRate
= RATE_6M
;
2457 pDevice
->byACKRate
= RATE_6M
;
2458 pDevice
->byTopCCKBasicRate
= RATE_1M
;
2459 pDevice
->byTopOFDMBasicRate
= RATE_6M
;
2463 VNTWIFIvGetTxRate( pDevice
->pMgmt
,
2464 pDevice
->sTxEthHeader
.abyDstAddr
,
2465 &(pDevice
->wCurrentRate
),
2466 &(pDevice
->byACKRate
),
2467 &(pDevice
->byTopCCKBasicRate
),
2468 &(pDevice
->byTopOFDMBasicRate
));
2474 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2476 if (pDevice
->wCurrentRate
<= RATE_11M
) {
2477 byPktType
= PK_TYPE_11B
;
2478 } else if (pDevice
->eCurrentPHYType
== PHY_TYPE_11A
) {
2479 byPktType
= PK_TYPE_11A
;
2481 if (pDevice
->bProtectMode
== true) {
2482 byPktType
= PK_TYPE_11GB
;
2484 byPktType
= PK_TYPE_11GA
;
2488 //#ifdef PLICE_DEBUG
2489 // printk("FIX RATE:CurrentRate is %d");
2492 if (bNeedEncryption
== true) {
2493 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ntohs Pkt Type=%04x\n", ntohs(pDevice
->sTxEthHeader
.wType
));
2494 if ((pDevice
->sTxEthHeader
.wType
) == TYPE_PKT_802_1x
) {
2495 bNeedEncryption
= false;
2496 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Pkt Type=%04x\n", (pDevice
->sTxEthHeader
.wType
));
2497 if ((pDevice
->pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) && (pDevice
->pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
2498 if (pTransmitKey
== NULL
) {
2499 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Don't Find TX KEY\n");
2502 if (bTKIP_UseGTK
== true) {
2503 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"error: KEY is GTK!!~~\n");
2506 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Find PTK [%lX]\n", pTransmitKey
->dwKeyIndex
);
2507 bNeedEncryption
= true;
2512 if (pDevice
->byCntMeasure
== 2) {
2514 pDevice
->s802_11Counter
.TKIPCounterMeasuresInvoked
++;
2517 if (pDevice
->bEnableHostWEP
) {
2518 if ((uNodeIndex
!= 0) &&
2519 (pMgmt
->sNodeDBTable
[uNodeIndex
].dwKeyIndex
& PAIRWISE_KEY
)) {
2520 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Find PTK [%lX]\n", pTransmitKey
->dwKeyIndex
);
2521 bNeedEncryption
= true;
2526 if (pTransmitKey
== NULL
) {
2527 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"return no tx key\n");
2528 dev_kfree_skb_irq(skb
);
2529 spin_unlock_irq(&pDevice
->lock
);
2537 //if (skb->len == 98)
2539 // printk("ping:len is %d\n");
2542 vGenerateFIFOHeader(pDevice
, byPktType
, pDevice
->pbyTmpBuff
, bNeedEncryption
,
2543 cbFrameBodySize
, TYPE_AC0DMA
, pHeadTD
,
2544 &pDevice
->sTxEthHeader
, (unsigned char *)skb
->data
, pTransmitKey
, uNodeIndex
,
2549 if (MACbIsRegBitsOn(pDevice
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PS
)) {
2551 MACbPSWakeup(pDevice
->PortOffset
);
2553 pDevice
->bPWBitOn
= false;
2556 for (ii
= 0; ii
< uMACfragNum
; ii
++) {
2557 // Poll Transmit the adapter
2559 pHeadTD
->m_td0TD0
.f1Owner
=OWNED_BY_NIC
;
2561 if (ii
== uMACfragNum
- 1)
2563 pHeadTD
= pHeadTD
->next
;
2566 // Save the information needed by the tx interrupt handler
2567 // to complete the Send request
2568 pLastTD
->pTDInfo
->skb
= skb
;
2569 pLastTD
->pTDInfo
->byFlags
= 0;
2570 pLastTD
->pTDInfo
->byFlags
|= TD_FLAGS_NETIF_SKB
;
2572 pDevice
->nTxDataTimeCout
=0; //2008-8-21 chester <add> for send null packet
2574 if (AVAIL_TD(pDevice
, TYPE_AC0DMA
) <= 1) {
2575 netif_stop_queue(dev
);
2578 pDevice
->apCurrTD
[TYPE_AC0DMA
] = pHeadTD
;
2579 //#ifdef PLICE_DEBUG
2580 if (pDevice
->bFixRate
)
2582 printk("FixRate:Rate is %d,TxPower is %d\n",pDevice
->wCurrentRate
,pDevice
->byCurPwr
);
2586 //printk("Auto Rate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2591 unsigned char Protocol_Version
; //802.1x Authentication
2592 unsigned char Packet_Type
; //802.1x Authentication
2593 unsigned char Descriptor_type
;
2594 unsigned short Key_info
;
2595 bool bTxeapol_key
= false;
2596 Protocol_Version
= skb
->data
[ETH_HLEN
];
2597 Packet_Type
= skb
->data
[ETH_HLEN
+1];
2598 Descriptor_type
= skb
->data
[ETH_HLEN
+1+1+2];
2599 Key_info
= (skb
->data
[ETH_HLEN
+1+1+2+1] << 8)|(skb
->data
[ETH_HLEN
+1+1+2+2]);
2600 if (pDevice
->sTxEthHeader
.wType
== TYPE_PKT_802_1x
) {
2601 if(((Protocol_Version
==1) ||(Protocol_Version
==2)) &&
2602 (Packet_Type
==3)) { //802.1x OR eapol-key challenge frame transfer
2603 bTxeapol_key
= true;
2604 if((Descriptor_type
==254)||(Descriptor_type
==2)) { //WPA or RSN
2605 if(!(Key_info
& BIT3
) && //group-key challenge
2606 (Key_info
& BIT8
) && (Key_info
& BIT9
)) { //send 2/2 key
2607 pDevice
->fWPA_Authened
= true;
2608 if(Descriptor_type
==254)
2612 printk("Authentication completed!!\n");
2619 MACvTransmitAC0(pDevice
->PortOffset
);
2620 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "acdma0:pDevice->apCurrTD= %p\n", pHeadTD);
2622 dev
->trans_start
= jiffies
;
2624 spin_unlock_irq(&pDevice
->lock
);
2629 static irqreturn_t
device_intr(int irq
, void *dev_instance
) {
2630 struct net_device
* dev
=dev_instance
;
2631 PSDevice pDevice
=(PSDevice
) netdev_priv(dev
);
2634 unsigned long dwMIBCounter
=0;
2635 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
2636 unsigned char byOrgPageSel
=0;
2638 unsigned char byData
= 0;
2640 // unsigned char byRSSI;
2643 MACvReadISR(pDevice
->PortOffset
, &pDevice
->dwIsr
);
2645 if (pDevice
->dwIsr
== 0)
2646 return IRQ_RETVAL(handled
);
2648 if (pDevice
->dwIsr
== 0xffffffff) {
2649 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dwIsr = 0xffff\n");
2650 return IRQ_RETVAL(handled
);
2653 // 2008-05-21 <mark> by Richardtai, we can't read RSSI here, because no packet bound with RSSI
2655 if ((pDevice->dwIsr & ISR_RXDMA0) &&
2656 (pDevice->byLocalID != REV_ID_VT3253_B0) &&
2657 (pDevice->bBSSIDFilter == true)) {
2659 //BBbReadEmbedded(pDevice->PortOffset, 0x3E, &byRSSI);
2660 //pDevice->uCurrRSSI = byRSSI;
2665 MACvIntDisable(pDevice
->PortOffset
);
2666 spin_lock_irq(&pDevice
->lock
);
2668 //Make sure current page is 0
2669 VNSvInPortB(pDevice
->PortOffset
+ MAC_REG_PAGE1SEL
, &byOrgPageSel
);
2670 if (byOrgPageSel
== 1) {
2671 MACvSelectPage0(pDevice
->PortOffset
);
2676 MACvReadMIBCounter(pDevice
->PortOffset
, &dwMIBCounter
);
2678 // Must do this after doing rx/tx, cause ISR bit is slow
2679 // than RD/TD write back
2680 // update ISR counter
2681 STAvUpdate802_11Counter(&pDevice
->s802_11Counter
, &pDevice
->scStatistic
, dwMIBCounter
);
2682 while (pDevice
->dwIsr
!= 0) {
2684 STAvUpdateIsrStatCounter(&pDevice
->scStatistic
, pDevice
->dwIsr
);
2685 MACvWriteISR(pDevice
->PortOffset
, pDevice
->dwIsr
);
2687 if (pDevice
->dwIsr
& ISR_FETALERR
){
2688 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" ISR_FETALERR \n");
2689 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SOFTPWRCTL
, 0);
2690 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPECTI
);
2691 device_error(pDevice
, pDevice
->dwIsr
);
2694 if (pDevice
->byLocalID
> REV_ID_VT3253_B1
) {
2696 if (pDevice
->dwIsr
& ISR_MEASURESTART
) {
2697 // 802.11h measure start
2698 pDevice
->byOrgChannel
= pDevice
->byCurrentCh
;
2699 VNSvInPortB(pDevice
->PortOffset
+ MAC_REG_RCR
, &(pDevice
->byOrgRCR
));
2700 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_RCR
, (RCR_RXALLTYPE
| RCR_UNICAST
| RCR_BROADCAST
| RCR_MULTICAST
| RCR_WPAERR
));
2701 MACvSelectPage1(pDevice
->PortOffset
);
2702 VNSvInPortD(pDevice
->PortOffset
+ MAC_REG_MAR0
, &(pDevice
->dwOrgMAR0
));
2703 VNSvInPortD(pDevice
->PortOffset
+ MAC_REG_MAR4
, &(pDevice
->dwOrgMAR4
));
2704 MACvSelectPage0(pDevice
->PortOffset
);
2706 // WCMDbFlushCommandQueue(pDevice->pMgmt, true);
2707 if (set_channel(pDevice
, pDevice
->pCurrMeasureEID
->sReq
.byChannel
) == true) {
2708 pDevice
->bMeasureInProgress
= true;
2709 MACvSelectPage1(pDevice
->PortOffset
);
2710 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
, MSRCTL_READY
);
2711 MACvSelectPage0(pDevice
->PortOffset
);
2712 pDevice
->byBasicMap
= 0;
2713 pDevice
->byCCAFraction
= 0;
2714 for(ii
=0;ii
<8;ii
++) {
2715 pDevice
->dwRPIs
[ii
] = 0;
2718 // can not measure because set channel fail
2719 // WCMDbResetCommandQueue(pDevice->pMgmt);
2720 // clear measure control
2721 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_MSRCTL
, MSRCTL_EN
);
2722 s_vCompleteCurrentMeasure(pDevice
, MEASURE_MODE_INCAPABLE
);
2723 MACvSelectPage1(pDevice
->PortOffset
);
2724 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
+1, MSRCTL1_TXPAUSE
);
2725 MACvSelectPage0(pDevice
->PortOffset
);
2728 if (pDevice
->dwIsr
& ISR_MEASUREEND
) {
2729 // 802.11h measure end
2730 pDevice
->bMeasureInProgress
= false;
2731 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_RCR
, pDevice
->byOrgRCR
);
2732 MACvSelectPage1(pDevice
->PortOffset
);
2733 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MAR0
, pDevice
->dwOrgMAR0
);
2734 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MAR4
, pDevice
->dwOrgMAR4
);
2735 VNSvInPortB(pDevice
->PortOffset
+ MAC_REG_MSRBBSTS
, &byData
);
2736 pDevice
->byBasicMap
|= (byData
>> 4);
2737 VNSvInPortB(pDevice
->PortOffset
+ MAC_REG_CCAFRACTION
, &pDevice
->byCCAFraction
);
2738 VNSvInPortB(pDevice
->PortOffset
+ MAC_REG_MSRCTL
, &byData
);
2739 // clear measure control
2740 MACvRegBitsOff(pDevice
->PortOffset
, MAC_REG_MSRCTL
, MSRCTL_EN
);
2741 MACvSelectPage0(pDevice
->PortOffset
);
2742 set_channel(pDevice
, pDevice
->byOrgChannel
);
2743 // WCMDbResetCommandQueue(pDevice->pMgmt);
2744 MACvSelectPage1(pDevice
->PortOffset
);
2745 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
+1, MSRCTL1_TXPAUSE
);
2746 MACvSelectPage0(pDevice
->PortOffset
);
2747 if (byData
& MSRCTL_FINISH
) {
2749 s_vCompleteCurrentMeasure(pDevice
, 0);
2751 // can not measure because not ready before end of measure time
2752 s_vCompleteCurrentMeasure(pDevice
, MEASURE_MODE_LATE
);
2755 if (pDevice
->dwIsr
& ISR_QUIETSTART
) {
2758 } while (CARDbStartQuiet(pDevice
) == false);
2762 if (pDevice
->dwIsr
& ISR_TBTT
) {
2763 if (pDevice
->bEnableFirstQuiet
== true) {
2764 pDevice
->byQuietStartCount
--;
2765 if (pDevice
->byQuietStartCount
== 0) {
2766 pDevice
->bEnableFirstQuiet
= false;
2767 MACvSelectPage1(pDevice
->PortOffset
);
2768 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
, (MSRCTL_QUIETTXCHK
| MSRCTL_QUIETEN
));
2769 MACvSelectPage0(pDevice
->PortOffset
);
2772 if ((pDevice
->bChannelSwitch
== true) &&
2773 (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
)) {
2774 pDevice
->byChannelSwitchCount
--;
2775 if (pDevice
->byChannelSwitchCount
== 0) {
2776 pDevice
->bChannelSwitch
= false;
2777 set_channel(pDevice
, pDevice
->byNewChannel
);
2778 VNTWIFIbChannelSwitch(pDevice
->pMgmt
, pDevice
->byNewChannel
);
2779 MACvSelectPage1(pDevice
->PortOffset
);
2780 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
+1, MSRCTL1_TXPAUSE
);
2781 MACvSelectPage0(pDevice
->PortOffset
);
2782 CARDbStartTxPacket(pDevice
, PKT_TYPE_802_11_ALL
);
2786 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
2787 //pDevice->bBeaconSent = false;
2789 if ((pDevice
->bUpdateBBVGA
) && (pDevice
->bLinkPass
== true) && (pDevice
->uCurrRSSI
!= 0)) {
2792 RFvRSSITodBm(pDevice
, (unsigned char) pDevice
->uCurrRSSI
, &ldBm
);
2793 for (ii
=0;ii
<BB_VGA_LEVEL
;ii
++) {
2794 if (ldBm
< pDevice
->ldBmThreshold
[ii
]) {
2795 pDevice
->byBBVGANew
= pDevice
->abyBBVGA
[ii
];
2799 if (pDevice
->byBBVGANew
!= pDevice
->byBBVGACurrent
) {
2800 pDevice
->uBBVGADiffCount
++;
2801 if (pDevice
->uBBVGADiffCount
== 1) {
2802 // first VGA diff gain
2803 BBvSetVGAGainOffset(pDevice
, pDevice
->byBBVGANew
);
2804 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2805 (int)ldBm
, pDevice
->byBBVGANew
, pDevice
->byBBVGACurrent
, (int)pDevice
->uBBVGADiffCount
);
2807 if (pDevice
->uBBVGADiffCount
>= BB_VGA_CHANGE_THRESHOLD
) {
2808 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2809 (int)ldBm
, pDevice
->byBBVGANew
, pDevice
->byBBVGACurrent
, (int)pDevice
->uBBVGADiffCount
);
2810 BBvSetVGAGainOffset(pDevice
, pDevice
->byBBVGANew
);
2813 pDevice
->uBBVGADiffCount
= 1;
2818 pDevice
->bBeaconSent
= false;
2819 if (pDevice
->bEnablePSMode
) {
2820 PSbIsNextTBTTWakeUp((void *)pDevice
);
2823 if ((pDevice
->eOPMode
== OP_MODE_AP
) ||
2824 (pDevice
->eOPMode
== OP_MODE_ADHOC
)) {
2826 MACvOneShotTimer1MicroSec(pDevice
->PortOffset
,
2827 (pMgmt
->wIBSSBeaconPeriod
- MAKE_BEACON_RESERVED
) << 10);
2830 if (pDevice
->eOPMode
== OP_MODE_ADHOC
&& pDevice
->pMgmt
->wCurrATIMWindow
> 0) {
2831 // todo adhoc PS mode
2836 if (pDevice
->dwIsr
& ISR_BNTX
) {
2838 if (pDevice
->eOPMode
== OP_MODE_ADHOC
) {
2839 pDevice
->bIsBeaconBufReadySet
= false;
2840 pDevice
->cbBeaconBufReadySetCnt
= 0;
2843 if (pDevice
->eOPMode
== OP_MODE_AP
) {
2844 if(pMgmt
->byDTIMCount
> 0) {
2845 pMgmt
->byDTIMCount
--;
2846 pMgmt
->sNodeDBTable
[0].bRxPSPoll
= false;
2849 if(pMgmt
->byDTIMCount
== 0) {
2850 // check if mutltcast tx bufferring
2851 pMgmt
->byDTIMCount
= pMgmt
->byDTIMPeriod
- 1;
2852 pMgmt
->sNodeDBTable
[0].bRxPSPoll
= true;
2853 bScheduleCommand((void *)pDevice
, WLAN_CMD_RX_PSPOLL
, NULL
);
2857 pDevice
->bBeaconSent
= true;
2859 if (pDevice
->bChannelSwitch
== true) {
2860 pDevice
->byChannelSwitchCount
--;
2861 if (pDevice
->byChannelSwitchCount
== 0) {
2862 pDevice
->bChannelSwitch
= false;
2863 set_channel(pDevice
, pDevice
->byNewChannel
);
2864 VNTWIFIbChannelSwitch(pDevice
->pMgmt
, pDevice
->byNewChannel
);
2865 MACvSelectPage1(pDevice
->PortOffset
);
2866 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_MSRCTL
+1, MSRCTL1_TXPAUSE
);
2867 MACvSelectPage0(pDevice
->PortOffset
);
2868 //VNTWIFIbSendBeacon(pDevice->pMgmt);
2869 CARDbStartTxPacket(pDevice
, PKT_TYPE_802_11_ALL
);
2875 if (pDevice
->dwIsr
& ISR_RXDMA0
) {
2876 max_count
+= device_rx_srv(pDevice
, TYPE_RXDMA0
);
2878 if (pDevice
->dwIsr
& ISR_RXDMA1
) {
2879 max_count
+= device_rx_srv(pDevice
, TYPE_RXDMA1
);
2881 if (pDevice
->dwIsr
& ISR_TXDMA0
){
2882 max_count
+= device_tx_srv(pDevice
, TYPE_TXDMA0
);
2884 if (pDevice
->dwIsr
& ISR_AC0DMA
){
2885 max_count
+= device_tx_srv(pDevice
, TYPE_AC0DMA
);
2887 if (pDevice
->dwIsr
& ISR_SOFTTIMER
) {
2890 if (pDevice
->dwIsr
& ISR_SOFTTIMER1
) {
2891 if (pDevice
->eOPMode
== OP_MODE_AP
) {
2892 if (pDevice
->bShortSlotTime
)
2893 pMgmt
->wCurrCapInfo
|= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2895 pMgmt
->wCurrCapInfo
&= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2897 bMgrPrepareBeaconToSend(pDevice
, pMgmt
);
2898 pDevice
->byCntMeasure
= 0;
2901 MACvReadISR(pDevice
->PortOffset
, &pDevice
->dwIsr
);
2903 MACvReceive0(pDevice
->PortOffset
);
2904 MACvReceive1(pDevice
->PortOffset
);
2906 if (max_count
>pDevice
->sOpts
.int_works
)
2910 if (byOrgPageSel
== 1) {
2911 MACvSelectPage1(pDevice
->PortOffset
);
2914 spin_unlock_irq(&pDevice
->lock
);
2915 MACvIntEnable(pDevice
->PortOffset
, IMR_MASK_VALUE
);
2917 return IRQ_RETVAL(handled
);
2921 static unsigned const ethernet_polynomial
= 0x04c11db7U
;
2922 static inline u32
ether_crc(int length
, unsigned char *data
)
2926 while(--length
>= 0) {
2927 unsigned char current_octet
= *data
++;
2929 for (bit
= 0; bit
< 8; bit
++, current_octet
>>= 1) {
2931 ((crc
< 0) ^ (current_octet
& 1) ? ethernet_polynomial
: 0);
2937 //2008-8-4 <add> by chester
2938 static int Config_FileGetParameter(unsigned char *string
,
2939 unsigned char *dest
, unsigned char *source
)
2941 unsigned char buf1
[100];
2942 int source_len
= strlen(source
);
2945 strcat(buf1
, string
);
2947 source
+=strlen(buf1
);
2949 memcpy(dest
,source
,source_len
-strlen(buf1
));
2953 int Config_FileOperation(PSDevice pDevice
,bool fwrite
,unsigned char *Parameter
) {
2954 unsigned char *config_path
= CONFIG_PATH
;
2955 unsigned char *buffer
= NULL
;
2956 unsigned char tmpbuffer
[20];
2957 struct file
*filp
=NULL
;
2958 mm_segment_t old_fs
= get_fs();
2959 //int oldfsuid=0,oldfsgid=0;
2964 /* Can't do this anymore, so we rely on correct filesystem permissions:
2965 //Make sure a caller can read or write power as root
2966 oldfsuid=current->cred->fsuid;
2967 oldfsgid=current->cred->fsgid;
2968 current->cred->fsuid = 0;
2969 current->cred->fsgid = 0;
2973 filp
= filp_open(config_path
, O_RDWR
, 0);
2975 printk("Config_FileOperation:open file fail?\n");
2980 if(!(filp
->f_op
) || !(filp
->f_op
->read
) ||!(filp
->f_op
->write
)) {
2981 printk("file %s cann't readable or writable?\n",config_path
);
2986 buffer
= kmalloc(1024, GFP_KERNEL
);
2988 printk("allocate mem for file fail?\n");
2993 if(filp
->f_op
->read(filp
, buffer
, 1024, &filp
->f_pos
)<0) {
2994 printk("read file error?\n");
2999 if(Config_FileGetParameter("ZONETYPE",tmpbuffer
,buffer
)!=true) {
3000 printk("get parameter error?\n");
3005 if(memcmp(tmpbuffer
,"USA",3)==0) {
3006 result
=ZoneType_USA
;
3008 else if(memcmp(tmpbuffer
,"JAPAN",5)==0) {
3009 result
=ZoneType_Japan
;
3011 else if(memcmp(tmpbuffer
,"EUROPE",5)==0) {
3012 result
=ZoneType_Europe
;
3016 printk("Unknown Zonetype[%s]?\n",tmpbuffer
);
3022 if(filp_close(filp
,NULL
))
3023 printk("Config_FileOperation:close file fail\n");
3029 current->cred->fsuid=oldfsuid;
3030 current->cred->fsgid=oldfsgid;
3038 static void device_set_multi(struct net_device
*dev
) {
3039 PSDevice pDevice
= (PSDevice
) netdev_priv(dev
);
3041 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
3043 struct netdev_hw_addr
*ha
;
3046 VNSvInPortB(pDevice
->PortOffset
+ MAC_REG_RCR
, &(pDevice
->byRxMode
));
3048 if (dev
->flags
& IFF_PROMISC
) { /* Set promiscuous. */
3049 DBG_PRT(MSG_LEVEL_ERR
,KERN_NOTICE
"%s: Promiscuous mode enabled.\n", dev
->name
);
3050 /* Unconditionally log net taps. */
3051 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
|RCR_UNICAST
);
3053 else if ((netdev_mc_count(dev
) > pDevice
->multicast_limit
)
3054 || (dev
->flags
& IFF_ALLMULTI
)) {
3055 MACvSelectPage1(pDevice
->PortOffset
);
3056 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MAR0
, 0xffffffff);
3057 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MAR0
+ 4, 0xffffffff);
3058 MACvSelectPage0(pDevice
->PortOffset
);
3059 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
3062 memset(mc_filter
, 0, sizeof(mc_filter
));
3063 netdev_for_each_mc_addr(ha
, dev
) {
3064 int bit_nr
= ether_crc(ETH_ALEN
, ha
->addr
) >> 26;
3065 mc_filter
[bit_nr
>> 5] |= cpu_to_le32(1 << (bit_nr
& 31));
3067 MACvSelectPage1(pDevice
->PortOffset
);
3068 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MAR0
, mc_filter
[0]);
3069 VNSvOutPortD(pDevice
->PortOffset
+ MAC_REG_MAR0
+ 4, mc_filter
[1]);
3070 MACvSelectPage0(pDevice
->PortOffset
);
3071 pDevice
->byRxMode
&= ~(RCR_UNICAST
);
3072 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
3075 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
3076 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
3077 pDevice
->byRxMode
|= (RCR_MULTICAST
|RCR_BROADCAST
);
3078 pDevice
->byRxMode
&= ~(RCR_UNICAST
);
3081 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_RCR
, pDevice
->byRxMode
);
3082 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pDevice->byRxMode = %x\n", pDevice
->byRxMode
);
3086 static struct net_device_stats
*device_get_stats(struct net_device
*dev
) {
3087 PSDevice pDevice
=(PSDevice
) netdev_priv(dev
);
3089 return &pDevice
->stats
;
3094 static int device_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
) {
3095 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
3097 struct iwreq
*wrq
= (struct iwreq
*) rq
;
3099 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
3103 if (pMgmt
== NULL
) {
3111 rc
= iwctl_giwname(dev
, NULL
, (char *)&(wrq
->u
.name
), NULL
);
3114 case SIOCGIWNWID
: //0x8b03 support
3118 // Set frequency/channel
3120 rc
= iwctl_siwfreq(dev
, NULL
, &(wrq
->u
.freq
), NULL
);
3123 // Get frequency/channel
3125 rc
= iwctl_giwfreq(dev
, NULL
, &(wrq
->u
.freq
), NULL
);
3128 // Set desired network name (ESSID)
3132 char essid
[IW_ESSID_MAX_SIZE
+1];
3133 if (wrq
->u
.essid
.length
> IW_ESSID_MAX_SIZE
) {
3137 if (copy_from_user(essid
, wrq
->u
.essid
.pointer
,
3138 wrq
->u
.essid
.length
)) {
3142 rc
= iwctl_siwessid(dev
, NULL
,
3143 &(wrq
->u
.essid
), essid
);
3148 // Get current network name (ESSID)
3152 char essid
[IW_ESSID_MAX_SIZE
+1];
3153 if (wrq
->u
.essid
.pointer
)
3154 rc
= iwctl_giwessid(dev
, NULL
,
3155 &(wrq
->u
.essid
), essid
);
3156 if (copy_to_user(wrq
->u
.essid
.pointer
,
3158 wrq
->u
.essid
.length
) )
3165 rc
= iwctl_siwap(dev
, NULL
, &(wrq
->u
.ap_addr
), NULL
);
3169 // Get current Access Point (BSSID)
3171 rc
= iwctl_giwap(dev
, NULL
, &(wrq
->u
.ap_addr
), NULL
);
3175 // Set desired station name
3177 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWNICKN \n");
3181 // Get current station name
3183 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWNICKN \n");
3187 // Set the desired bit-rate
3189 rc
= iwctl_siwrate(dev
, NULL
, &(wrq
->u
.bitrate
), NULL
);
3192 // Get the current bit-rate
3195 rc
= iwctl_giwrate(dev
, NULL
, &(wrq
->u
.bitrate
), NULL
);
3198 // Set the desired RTS threshold
3201 rc
= iwctl_siwrts(dev
, NULL
, &(wrq
->u
.rts
), NULL
);
3204 // Get the current RTS threshold
3207 rc
= iwctl_giwrts(dev
, NULL
, &(wrq
->u
.rts
), NULL
);
3210 // Set the desired fragmentation threshold
3213 rc
= iwctl_siwfrag(dev
, NULL
, &(wrq
->u
.frag
), NULL
);
3216 // Get the current fragmentation threshold
3219 rc
= iwctl_giwfrag(dev
, NULL
, &(wrq
->u
.frag
), NULL
);
3222 // Set mode of operation
3224 rc
= iwctl_siwmode(dev
, NULL
, &(wrq
->u
.mode
), NULL
);
3227 // Get mode of operation
3229 rc
= iwctl_giwmode(dev
, NULL
, &(wrq
->u
.mode
), NULL
);
3232 // Set WEP keys and mode
3235 char abyKey
[WLAN_WEP232_KEYLEN
];
3237 if (wrq
->u
.encoding
.pointer
) {
3240 if (wrq
->u
.encoding
.length
> WLAN_WEP232_KEYLEN
) {
3244 memset(abyKey
, 0, WLAN_WEP232_KEYLEN
);
3245 if (copy_from_user(abyKey
,
3246 wrq
->u
.encoding
.pointer
,
3247 wrq
->u
.encoding
.length
)) {
3251 } else if (wrq
->u
.encoding
.length
!= 0) {
3255 rc
= iwctl_siwencode(dev
, NULL
, &(wrq
->u
.encoding
), abyKey
);
3259 // Get the WEP keys and mode
3262 if (!capable(CAP_NET_ADMIN
)) {
3267 char abyKey
[WLAN_WEP232_KEYLEN
];
3269 rc
= iwctl_giwencode(dev
, NULL
, &(wrq
->u
.encoding
), abyKey
);
3271 if (wrq
->u
.encoding
.pointer
) {
3272 if (copy_to_user(wrq
->u
.encoding
.pointer
,
3274 wrq
->u
.encoding
.length
))
3280 // Get the current Tx-Power
3282 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWTXPOW \n");
3287 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWTXPOW \n");
3293 rc
= iwctl_siwretry(dev
, NULL
, &(wrq
->u
.retry
), NULL
);
3298 rc
= iwctl_giwretry(dev
, NULL
, &(wrq
->u
.retry
), NULL
);
3301 // Get range of parameters
3305 struct iw_range range
;
3307 rc
= iwctl_giwrange(dev
, NULL
, &(wrq
->u
.data
), (char *) &range
);
3308 if (copy_to_user(wrq
->u
.data
.pointer
, &range
, sizeof(struct iw_range
)))
3316 rc
= iwctl_giwpower(dev
, NULL
, &(wrq
->u
.power
), NULL
);
3322 rc
= iwctl_siwpower(dev
, NULL
, &(wrq
->u
.power
), NULL
);
3328 rc
= iwctl_giwsens(dev
, NULL
, &(wrq
->u
.sens
), NULL
);
3332 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWSENS \n");
3338 char buffer
[IW_MAX_AP
* (sizeof(struct sockaddr
) + sizeof(struct iw_quality
))];
3340 if (wrq
->u
.data
.pointer
) {
3341 rc
= iwctl_giwaplist(dev
, NULL
, &(wrq
->u
.data
), buffer
);
3343 if (copy_to_user(wrq
->u
.data
.pointer
,
3345 (wrq
->u
.data
.length
* (sizeof(struct sockaddr
) + sizeof(struct iw_quality
)))
3358 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWSPY \n");
3365 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSPY \n");
3369 #endif // WIRELESS_SPY
3372 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWPRIV \n");
3375 if(wrq->u.data.pointer) {
3376 wrq->u.data.length = sizeof(iwctl_private_args) / sizeof( iwctl_private_args[0]);
3378 if(copy_to_user(wrq->u.data.pointer,
3379 (u_char *) iwctl_private_args,
3380 sizeof(iwctl_private_args)))
3387 //2008-0409-07, <Add> by Einsn Liu
3388 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3390 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWAUTH \n");
3391 rc
= iwctl_siwauth(dev
, NULL
, &(wrq
->u
.param
), NULL
);
3395 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAUTH \n");
3396 rc
= iwctl_giwauth(dev
, NULL
, &(wrq
->u
.param
), NULL
);
3400 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWGENIE \n");
3401 rc
= iwctl_siwgenie(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
3405 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWGENIE \n");
3406 rc
= iwctl_giwgenie(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
3409 case SIOCSIWENCODEEXT
:
3411 char extra
[sizeof(struct iw_encode_ext
)+MAX_KEY_LEN
+1];
3412 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWENCODEEXT \n");
3413 if(wrq
->u
.encoding
.pointer
){
3414 memset(extra
, 0, sizeof(struct iw_encode_ext
)+MAX_KEY_LEN
+1);
3415 if(wrq
->u
.encoding
.length
> (sizeof(struct iw_encode_ext
)+ MAX_KEY_LEN
)){
3419 if(copy_from_user(extra
, wrq
->u
.encoding
.pointer
,wrq
->u
.encoding
.length
)){
3423 }else if(wrq
->u
.encoding
.length
!= 0){
3427 rc
= iwctl_siwencodeext(dev
, NULL
, &(wrq
->u
.encoding
), extra
);
3431 case SIOCGIWENCODEEXT
:
3432 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWENCODEEXT \n");
3433 rc
= iwctl_giwencodeext(dev
, NULL
, &(wrq
->u
.encoding
), NULL
);
3437 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMLME \n");
3438 rc
= iwctl_siwmlme(dev
, NULL
, &(wrq
->u
.data
), wrq
->u
.data
.pointer
);
3441 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3442 //End Add -- //2008-0409-07, <Add> by Einsn Liu
3444 case IOCTL_CMD_TEST
:
3446 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
3452 pReq
= (PSCmdRequest
)rq
;
3453 pReq
->wResult
= MAGIC_CODE
;
3459 if((((PSCmdRequest
)rq
)->wCmdCode
!=WLAN_CMD_SET_EVT
) &&
3460 !(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
3462 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
) &&
3463 (((PSCmdRequest
)rq
)->wCmdCode
!=WLAN_CMD_SET_WPA
))
3472 if (test_and_set_bit( 0, (void*)&(pMgmt
->uCmdBusy
))) {
3475 rc
= private_ioctl(pDevice
, rq
);
3476 clear_bit( 0, (void*)&(pMgmt
->uCmdBusy
));
3479 case IOCTL_CMD_HOSTAPD
:
3482 rc
= vt6655_hostap_ioctl(pDevice
, &wrq
->u
.data
);
3487 rc
= wpa_ioctl(pDevice
, &wrq
->u
.data
);
3491 return ethtool_ioctl(dev
, (void *) rq
->ifr_data
);
3492 // All other calls are currently unsupported
3496 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Ioctl command not support..%x\n", cmd
);
3501 if (pDevice
->bCommit
) {
3502 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
3503 netif_stop_queue(pDevice
->dev
);
3504 spin_lock_irq(&pDevice
->lock
);
3505 bScheduleCommand((void *)pDevice
, WLAN_CMD_RUN_AP
, NULL
);
3506 spin_unlock_irq(&pDevice
->lock
);
3509 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Commit the settings\n");
3510 spin_lock_irq(&pDevice
->lock
);
3511 pDevice
->bLinkPass
= false;
3512 memset(pMgmt
->abyCurrBSSID
, 0, 6);
3513 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
3514 netif_stop_queue(pDevice
->dev
);
3515 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3516 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
3517 if(pDevice
->bWPASuppWextEnabled
!=true)
3519 bScheduleCommand((void *) pDevice
, WLAN_CMD_BSSID_SCAN
, pMgmt
->abyDesireSSID
);
3520 bScheduleCommand((void *) pDevice
, WLAN_CMD_SSID
, NULL
);
3521 spin_unlock_irq(&pDevice
->lock
);
3523 pDevice
->bCommit
= false;
3530 static int ethtool_ioctl(struct net_device
*dev
, void *useraddr
)
3534 if (copy_from_user(ðcmd
, useraddr
, sizeof(ethcmd
)))
3538 case ETHTOOL_GDRVINFO
: {
3539 struct ethtool_drvinfo info
= {ETHTOOL_GDRVINFO
};
3540 strncpy(info
.driver
, DEVICE_NAME
, sizeof(info
.driver
)-1);
3541 strncpy(info
.version
, DEVICE_VERSION
, sizeof(info
.version
)-1);
3542 if (copy_to_user(useraddr
, &info
, sizeof(info
)))
3552 /*------------------------------------------------------------------*/
3554 MODULE_DEVICE_TABLE(pci
, vt6655_pci_id_table
);
3556 static struct pci_driver device_driver
= {
3557 .name
= DEVICE_NAME
,
3558 .id_table
= vt6655_pci_id_table
,
3559 .probe
= vt6655_probe
,
3560 .remove
= vt6655_remove
,
3562 .suspend
= viawget_suspend
,
3563 .resume
= viawget_resume
,
3567 static int __init
vt6655_init_module(void)
3572 // ret=pci_module_init(&device_driver);
3573 //ret = pcie_port_service_register(&device_driver);
3574 ret
= pci_register_driver(&device_driver
);
3577 register_reboot_notifier(&device_notifier
);
3583 static void __exit
vt6655_cleanup_module(void)
3588 unregister_reboot_notifier(&device_notifier
);
3590 pci_unregister_driver(&device_driver
);
3594 module_init(vt6655_init_module
);
3595 module_exit(vt6655_cleanup_module
);
3600 device_notify_reboot(struct notifier_block
*nb
, unsigned long event
, void *p
)
3602 struct pci_dev
*pdev
= NULL
;
3607 for_each_pci_dev(pdev
) {
3608 if(pci_dev_driver(pdev
) == &device_driver
) {
3609 if (pci_get_drvdata(pdev
))
3610 viawget_suspend(pdev
, PMSG_HIBERNATE
);
3618 viawget_suspend(struct pci_dev
*pcid
, pm_message_t state
)
3620 int power_status
; // to silence the compiler
3622 PSDevice pDevice
=pci_get_drvdata(pcid
);
3623 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
3625 netif_stop_queue(pDevice
->dev
);
3626 spin_lock_irq(&pDevice
->lock
);
3627 pci_save_state(pcid
);
3628 del_timer(&pDevice
->sTimerCommand
);
3629 del_timer(&pMgmt
->sTimerSecondCallback
);
3630 pDevice
->cbFreeCmdQueue
= CMD_Q_SIZE
;
3631 pDevice
->uCmdDequeueIdx
= 0;
3632 pDevice
->uCmdEnqueueIdx
= 0;
3633 pDevice
->bCmdRunning
= false;
3634 MACbShutdown(pDevice
->PortOffset
);
3635 MACvSaveContext(pDevice
->PortOffset
, pDevice
->abyMacContext
);
3636 pDevice
->bLinkPass
= false;
3637 memset(pMgmt
->abyCurrBSSID
, 0, 6);
3638 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
3639 pci_disable_device(pcid
);
3640 power_status
= pci_set_power_state(pcid
, pci_choose_state(pcid
, state
));
3641 spin_unlock_irq(&pDevice
->lock
);
3646 viawget_resume(struct pci_dev
*pcid
)
3648 PSDevice pDevice
=pci_get_drvdata(pcid
);
3649 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
3650 int power_status
; // to silence the compiler
3653 power_status
= pci_set_power_state(pcid
, 0);
3654 power_status
= pci_enable_wake(pcid
, 0, 0);
3655 pci_restore_state(pcid
);
3656 if (netif_running(pDevice
->dev
)) {
3657 spin_lock_irq(&pDevice
->lock
);
3658 MACvRestoreContext(pDevice
->PortOffset
, pDevice
->abyMacContext
);
3659 device_init_registers(pDevice
, DEVICE_INIT_DXPL
);
3660 if (pMgmt
->sNodeDBTable
[0].bActive
== true) { // Assoc with BSS
3661 pMgmt
->sNodeDBTable
[0].bActive
= false;
3662 pDevice
->bLinkPass
= false;
3663 if(pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
3664 // In Adhoc, BSS state set back to started.
3665 pMgmt
->eCurrState
= WMAC_STATE_STARTED
;
3668 pMgmt
->eCurrMode
= WMAC_MODE_STANDBY
;
3669 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
3672 init_timer(&pMgmt
->sTimerSecondCallback
);
3673 init_timer(&pDevice
->sTimerCommand
);
3674 MACvIntEnable(pDevice
->PortOffset
, IMR_MASK_VALUE
);
3675 BSSvClearBSSList((void *)pDevice
, pDevice
->bLinkPass
);
3676 bScheduleCommand((void *) pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
3677 bScheduleCommand((void *) pDevice
, WLAN_CMD_SSID
, NULL
);
3678 spin_unlock_irq(&pDevice
->lock
);