1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61#undef __NO_VERSION__
62
63#include "device.h"
64#include "card.h"
65#include "baseband.h"
66#include "mac.h"
67#include "tether.h"
68#include "wmgr.h"
69#include "wctl.h"
70#include "power.h"
71#include "wcmd.h"
72#include "iocmd.h"
73#include "tcrc.h"
74#include "rxtx.h"
75#include "wroute.h"
76#include "bssdb.h"
77#include "hostap.h"
78#include "wpactl.h"
79#include "ioctl.h"
80#include "iwctl.h"
81#include "dpc.h"
82#include "datarate.h"
83#include "rf.h"
84#include "iowpa.h"
85#include <linux/delay.h>
86#include <linux/kthread.h>
87
88
89
90
91static int msglevel = MSG_LEVEL_INFO;
92
93
94
95
96
97MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
98MODULE_LICENSE("GPL");
99MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
100
101
102 static int mlme_kill;
103
104
105
106#define DEVICE_PARAM(N,D)
107
108
109
110
111
112
113#define RX_DESC_MIN0 16
114#define RX_DESC_MAX0 128
115#define RX_DESC_DEF0 32
116DEVICE_PARAM(RxDescriptors0,"Number of receive descriptors0");
117
118#define RX_DESC_MIN1 16
119#define RX_DESC_MAX1 128
120#define RX_DESC_DEF1 32
121DEVICE_PARAM(RxDescriptors1,"Number of receive descriptors1");
122
123#define TX_DESC_MIN0 16
124#define TX_DESC_MAX0 128
125#define TX_DESC_DEF0 32
126DEVICE_PARAM(TxDescriptors0,"Number of transmit descriptors0");
127
128#define TX_DESC_MIN1 16
129#define TX_DESC_MAX1 128
130#define TX_DESC_DEF1 64
131DEVICE_PARAM(TxDescriptors1,"Number of transmit descriptors1");
132
133
134#define IP_ALIG_DEF 0
135
136
137
138
139
140
141DEVICE_PARAM(IP_byte_align,"Enable IP header dword aligned");
142
143
144#define INT_WORKS_DEF 20
145#define INT_WORKS_MIN 10
146#define INT_WORKS_MAX 64
147
148DEVICE_PARAM(int_works,"Number of packets per interrupt services");
149
150#define CHANNEL_MIN 1
151#define CHANNEL_MAX 14
152#define CHANNEL_DEF 6
153
154DEVICE_PARAM(Channel, "Channel number");
155
156
157
158
159
160
161
162#define PREAMBLE_TYPE_DEF 1
163
164DEVICE_PARAM(PreambleType, "Preamble Type");
165
166
167#define RTS_THRESH_MIN 512
168#define RTS_THRESH_MAX 2347
169#define RTS_THRESH_DEF 2347
170
171DEVICE_PARAM(RTSThreshold, "RTS threshold");
172
173
174#define FRAG_THRESH_MIN 256
175#define FRAG_THRESH_MAX 2346
176#define FRAG_THRESH_DEF 2346
177
178DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
179
180
181#define DATA_RATE_MIN 0
182#define DATA_RATE_MAX 13
183#define DATA_RATE_DEF 13
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201DEVICE_PARAM(ConnectionRate, "Connection data rate");
202
203#define OP_MODE_DEF 0
204
205DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
206
207
208
209
210
211
212
213
214
215
216
217
218
219#define PS_MODE_DEF 0
220
221DEVICE_PARAM(PSMode, "Power saving mode");
222
223
224#define SHORT_RETRY_MIN 0
225#define SHORT_RETRY_MAX 31
226#define SHORT_RETRY_DEF 8
227
228
229DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
230
231#define LONG_RETRY_MIN 0
232#define LONG_RETRY_MAX 15
233#define LONG_RETRY_DEF 4
234
235
236DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
237
238
239
240
241
242
243
244#define BBP_TYPE_MIN 0
245#define BBP_TYPE_MAX 2
246#define BBP_TYPE_DEF 2
247
248DEVICE_PARAM(BasebandType, "baseband type");
249
250
251
252
253
254
255
256
257#define X80211h_MODE_DEF 0
258
259DEVICE_PARAM(b80211hEnable, "802.11h mode");
260
261
262
263
264
265
266#define DIVERSITY_ANT_DEF 0
267
268DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
269
270
271
272
273
274
275
276static int device_nics =0;
277static PSDevice pDevice_Infos =NULL;
278static struct net_device *root_device_dev = NULL;
279
280static CHIP_INFO chip_info_table[]= {
281 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
282 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
283 {0,NULL}
284};
285
286DEFINE_PCI_DEVICE_TABLE(device_id_table) = {
287 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
288 { 0, }
289};
290
291
292
293
294static int device_found1(struct pci_dev *pcid, const struct pci_device_id *ent);
295static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice, PCHIP_INFO);
296static void device_free_info(PSDevice pDevice);
297static BOOL device_get_pci_info(PSDevice, struct pci_dev* pcid);
298static void device_print_info(PSDevice pDevice);
299static struct net_device_stats *device_get_stats(struct net_device *dev);
300static void device_init_diversity_timer(PSDevice pDevice);
301static int device_open(struct net_device *dev);
302static int device_xmit(struct sk_buff *skb, struct net_device *dev);
303static irqreturn_t device_intr(int irq, void*dev_instance);
304static void device_set_multi(struct net_device *dev);
305static int device_close(struct net_device *dev);
306static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
307
308#ifdef CONFIG_PM
309static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
310static int viawget_suspend(struct pci_dev *pcid, pm_message_t state);
311static int viawget_resume(struct pci_dev *pcid);
312struct notifier_block device_notifier = {
313 notifier_call: device_notify_reboot,
314 next: NULL,
315 priority: 0
316};
317#endif
318
319
320static void device_init_rd0_ring(PSDevice pDevice);
321static void device_init_rd1_ring(PSDevice pDevice);
322static void device_init_defrag_cb(PSDevice pDevice);
323static void device_init_td0_ring(PSDevice pDevice);
324static void device_init_td1_ring(PSDevice pDevice);
325
326static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
327
328static BOOL device_release_WPADEV(PSDevice pDevice);
329
330static int ethtool_ioctl(struct net_device *dev, void *useraddr);
331static int device_rx_srv(PSDevice pDevice, UINT uIdx);
332static int device_tx_srv(PSDevice pDevice, UINT uIdx);
333static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pDesc);
334static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType);
335static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc);
336static void device_free_td0_ring(PSDevice pDevice);
337static void device_free_td1_ring(PSDevice pDevice);
338static void device_free_rd0_ring(PSDevice pDevice);
339static void device_free_rd1_ring(PSDevice pDevice);
340static void device_free_rings(PSDevice pDevice);
341static void device_free_frag_buf(PSDevice pDevice);
342static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source);
343
344
345
346
347
348
349
350
351static char* get_chip_name(int chip_id) {
352 int i;
353 for (i=0;chip_info_table[i].name!=NULL;i++)
354 if (chip_info_table[i].chip_id==chip_id)
355 break;
356 return chip_info_table[i].name;
357}
358
359static void device_remove1(struct pci_dev *pcid)
360{
361 PSDevice pDevice=pci_get_drvdata(pcid);
362
363 if (pDevice==NULL)
364 return;
365 device_free_info(pDevice);
366
367}
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401static void
402device_get_options(PSDevice pDevice, int index, char* devname) {
403
404 POPTIONS pOpts = &(pDevice->sOpts);
405 pOpts->nRxDescs0=RX_DESC_DEF0;
406 pOpts->nRxDescs1=RX_DESC_DEF1;
407 pOpts->nTxDescs[0]=TX_DESC_DEF0;
408 pOpts->nTxDescs[1]=TX_DESC_DEF1;
409pOpts->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;
415
416pOpts->flags|=DEVICE_FLAGS_PREAMBLE_TYPE;
417pOpts->flags|=DEVICE_FLAGS_OP_MODE;
418
419 pOpts->short_retry=SHORT_RETRY_DEF;
420 pOpts->long_retry=LONG_RETRY_DEF;
421 pOpts->bbp_type=BBP_TYPE_DEF;
422pOpts->flags|=DEVICE_FLAGS_80211h_MODE;
423pOpts->flags|=DEVICE_FLAGS_DiversityANT;
424
425
426}
427
428static void
429device_set_options(PSDevice pDevice) {
430
431 BYTE abyBroadcastAddr[U_ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
432 BYTE abySNAP_RFC1042[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
433 BYTE abySNAP_Bridgetunnel[U_ETHER_ADDR_LEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
434
435
436 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, U_ETHER_ADDR_LEN);
437 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, U_ETHER_ADDR_LEN);
438 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, U_ETHER_ADDR_LEN);
439
440 pDevice->uChannel = pDevice->sOpts.channel_num;
441 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
442 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
443 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
444 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
445 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
446 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
447 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
448 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
449 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
450 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
451 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
452 if (pDevice->uConnectionRate < RATE_AUTO) pDevice->bFixRate = TRUE;
453 pDevice->byBBType = pDevice->sOpts.bbp_type;
454 pDevice->byPacketType = pDevice->byBBType;
455
456
457 pDevice->byAutoFBCtrl = AUTO_FB_0;
458
459
460pDevice->bUpdateBBVGA = TRUE;
461 pDevice->byFOETuning = 0;
462 pDevice->wCTSDuration = 0;
463 pDevice->byPreambleType = 0;
464
465
466 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uChannel= %d\n",(INT)pDevice->uChannel);
467 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byOpMode= %d\n",(INT)pDevice->byOpMode);
468 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" ePSMode= %d\n",(INT)pDevice->ePSMode);
469 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" wRTSThreshold= %d\n",(INT)pDevice->wRTSThreshold);
470 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortRetryLimit= %d\n",(INT)pDevice->byShortRetryLimit);
471 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byLongRetryLimit= %d\n",(INT)pDevice->byLongRetryLimit);
472 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byPreambleType= %d\n",(INT)pDevice->byPreambleType);
473 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byShortPreamble= %d\n",(INT)pDevice->byShortPreamble);
474 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" uConnectionRate= %d\n",(INT)pDevice->uConnectionRate);
475 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" byBBType= %d\n",(INT)pDevice->byBBType);
476 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->b11hEnable= %d\n",(INT)pDevice->b11hEnable);
477 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" pDevice->bDiversityRegCtlON= %d\n",(INT)pDevice->bDiversityRegCtlON);
478}
479
480static VOID s_vCompleteCurrentMeasure (IN PSDevice pDevice, IN BYTE byResult)
481{
482 UINT ii;
483 DWORD dwDuration = 0;
484 BYTE byRPI0 = 0;
485
486 for(ii=1;ii<8;ii++) {
487 pDevice->dwRPIs[ii] *= 255;
488 dwDuration |= *((PWORD) (pDevice->pCurrMeasureEID->sReq.abyDuration));
489 dwDuration <<= 10;
490 pDevice->dwRPIs[ii] /= dwDuration;
491 pDevice->abyRPIs[ii] = (BYTE) pDevice->dwRPIs[ii];
492 byRPI0 += pDevice->abyRPIs[ii];
493 }
494 pDevice->abyRPIs[0] = (0xFF - byRPI0);
495
496 if (pDevice->uNumOfMeasureEIDs == 0) {
497 VNTWIFIbMeasureReport( pDevice->pMgmt,
498 TRUE,
499 pDevice->pCurrMeasureEID,
500 byResult,
501 pDevice->byBasicMap,
502 pDevice->byCCAFraction,
503 pDevice->abyRPIs
504 );
505 } else {
506 VNTWIFIbMeasureReport( pDevice->pMgmt,
507 FALSE,
508 pDevice->pCurrMeasureEID,
509 byResult,
510 pDevice->byBasicMap,
511 pDevice->byCCAFraction,
512 pDevice->abyRPIs
513 );
514 CARDbStartMeasure (pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
515 }
516
517}
518
519
520
521
522
523
524
525static void device_init_registers(PSDevice pDevice, DEVICE_INIT_TYPE InitType)
526{
527 UINT ii;
528 BYTE byValue;
529 BYTE byValue1;
530 BYTE byCCKPwrdBm = 0;
531 BYTE byOFDMPwrdBm = 0;
532 INT zonetype=0;
533 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
534 MACbShutdown(pDevice->PortOffset);
535 BBvSoftwareReset(pDevice->PortOffset);
536
537 if ((InitType == DEVICE_INIT_COLD) ||
538 (InitType == DEVICE_INIT_DXPL)) {
539
540 MACbSoftwareReset(pDevice->PortOffset);
541
542 pDevice->bCCK = TRUE;
543 pDevice->bAES = FALSE;
544 pDevice->bProtectMode = FALSE;
545 pDevice->bNonERPPresent = FALSE;
546 pDevice->bBarkerPreambleMd = FALSE;
547 pDevice->wCurrentRate = RATE_1M;
548 pDevice->byTopOFDMBasicRate = RATE_24M;
549 pDevice->byTopCCKBasicRate = RATE_1M;
550
551 pDevice->byRevId = 0;
552
553
554 MACvInitialize(pDevice->PortOffset);
555
556
557 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &(pDevice->byLocalID));
558
559 spin_lock_irq(&pDevice->lock);
560 SROMvReadAllContents(pDevice->PortOffset,pDevice->abyEEPROM);
561
562 spin_unlock_irq(&pDevice->lock);
563
564
565
566 pDevice->byMinChannel = 1;
567 pDevice->byMaxChannel = CB_MAX_CHANNEL;
568
569
570 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
571 if (byValue & EEP_ANTINV)
572 pDevice->bTxRxAntInv = TRUE;
573 else
574 pDevice->bTxRxAntInv = FALSE;
575#ifdef PLICE_DEBUG
576
577#endif
578
579 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
580 if (byValue == 0)
581 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
582#ifdef PLICE_DEBUG
583
584#endif
585 pDevice->ulDiversityNValue = 100*260;
586 pDevice->ulDiversityMValue = 100*16;
587 pDevice->byTMax = 1;
588 pDevice->byTMax2 = 4;
589 pDevice->ulSQ3TH = 0;
590 pDevice->byTMax3 = 64;
591
592 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
593 pDevice->byAntennaCount = 2;
594 pDevice->byTxAntennaMode = ANT_B;
595 pDevice->dwTxAntennaSel = 1;
596 pDevice->dwRxAntennaSel = 1;
597 if (pDevice->bTxRxAntInv == TRUE)
598 pDevice->byRxAntennaMode = ANT_A;
599 else
600 pDevice->byRxAntennaMode = ANT_B;
601
602byValue1 = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
603
604 if((byValue1&0x08)==0)
605 pDevice->bDiversityEnable = FALSE;
606 else
607 pDevice->bDiversityEnable = TRUE;
608#ifdef PLICE_DEBUG
609
610#endif
611 } else {
612 pDevice->bDiversityEnable = FALSE;
613 pDevice->byAntennaCount = 1;
614 pDevice->dwTxAntennaSel = 0;
615 pDevice->dwRxAntennaSel = 0;
616 if (byValue & EEP_ANTENNA_AUX) {
617 pDevice->byTxAntennaMode = ANT_A;
618 if (pDevice->bTxRxAntInv == TRUE)
619 pDevice->byRxAntennaMode = ANT_B;
620 else
621 pDevice->byRxAntennaMode = ANT_A;
622 } else {
623 pDevice->byTxAntennaMode = ANT_B;
624 if (pDevice->bTxRxAntInv == TRUE)
625 pDevice->byRxAntennaMode = ANT_A;
626 else
627 pDevice->byRxAntennaMode = ANT_B;
628 }
629 }
630#ifdef PLICE_DEBUG
631
632#endif
633 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
634 pDevice->bDiversityEnable,(int)pDevice->ulDiversityNValue,(int)pDevice->ulDiversityMValue,pDevice->byTMax,pDevice->byTMax2);
635
636
637
638
639 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
640 if((zonetype=Config_FileOperation(pDevice,FALSE,NULL)) >= 0) {
641 if ((zonetype == 0)&&
642 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] !=0x00)){
643 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
644 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
645 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :USA\n");
646 }
647 else if((zonetype == 1)&&
648 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x01)){
649 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
650 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
651 }
652 else if((zonetype == 2)&&
653 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE]!=0x02)){
654 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
655 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
656 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Init Zone Type :Europe\n");
657 }
658
659else
660{
661 if(zonetype!=pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
662 printk("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",zonetype,pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
663 else
664 printk("Read Zonetype file sucess,use default zonetype setting[%02x]\n",zonetype);
665 }
666 }
667 else
668 printk("Read Zonetype file fail,use default zonetype setting[%02x]\n",SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
669
670
671 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
672
673 if ((pDevice->byRFType & RF_EMU) != 0) {
674
675 pDevice->byRevId = 0x80;
676 }
677
678 pDevice->byRFType &= RF_MASK;
679 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
680
681 if (pDevice->bZoneRegExist == FALSE) {
682 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
683 }
684 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
685
686
687 RFbInit(pDevice);
688
689
690 pDevice->byCurPwr = 0xFF;
691 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
692 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
693
694
695
696
697
698
699
700 for (ii=0;ii<CB_MAX_CHANNEL_24G;ii++) {
701 pDevice->abyCCKPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_CCK_PWR_TBL));
702 if (pDevice->abyCCKPwrTbl[ii+1] == 0) {
703 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
704 }
705 pDevice->abyOFDMPwrTbl[ii+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDM_PWR_TBL));
706 if (pDevice->abyOFDMPwrTbl[ii+1] == 0) {
707 pDevice->abyOFDMPwrTbl[ii+1] = pDevice->byOFDMPwrG;
708 }
709 pDevice->abyCCKDefaultPwr[ii+1] = byCCKPwrdBm;
710 pDevice->abyOFDMDefaultPwr[ii+1] = byOFDMPwrdBm;
711 }
712
713
714 if(((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
715 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe))&&
716 (pDevice->byOriginalZonetype == ZoneType_USA)) {
717 for(ii=11;ii<14;ii++) {
718 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
719 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
720
721 }
722 }
723
724
725
726 for (ii=0;ii<CB_MAX_CHANNEL_5G;ii++) {
727 pDevice->abyOFDMPwrTbl[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_TBL));
728 pDevice->abyOFDMDefaultPwr[ii+CB_MAX_CHANNEL_24G+1] = SROMbyReadEmbedded(pDevice->PortOffset, (BYTE)(ii + EEP_OFS_OFDMA_PWR_dBm));
729 }
730 CARDvInitChannelTable((PVOID)pDevice);
731
732
733 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
734 MACvSelectPage1(pDevice->PortOffset);
735 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1, (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
736 MACvSelectPage0(pDevice->PortOffset);
737 }
738
739
740
741 MACvWordRegBitsOn(pDevice->PortOffset, MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
742
743
744 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
745 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
746
747
748 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
749
750 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
751
752
753 BBbVT3253Init(pDevice);
754
755 if (pDevice->bUpdateBBVGA) {
756 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
757 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
758 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
759 }
760#ifdef PLICE_DEBUG
761
762#endif
763 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
764 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
765
766 pDevice->byCurrentCh = 0;
767
768
769
770
771 if (pDevice->uConnectionRate == RATE_AUTO) {
772 pDevice->wCurrentRate = RATE_54M;
773 } else {
774 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
775 }
776
777
778 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
779 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
780
781 pDevice->bRadioOff = FALSE;
782
783 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RADIOCTL);
784 pDevice->bHWRadioOff = FALSE;
785
786 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
787
788 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
789
790 #ifdef FOR_LED_ON_NOTEBOOK
791if (pDevice->byGPIO & GPIO0_DATA){pDevice->bHWRadioOff = TRUE;}
792if ( !(pDevice->byGPIO & GPIO0_DATA)){pDevice->bHWRadioOff = FALSE;}
793
794 }
795 if ( (pDevice->bRadioControlOff == TRUE)) {
796 CARDbRadioPowerOff(pDevice);
797 }
798else CARDbRadioPowerOn(pDevice);
799#else
800 if (((pDevice->byGPIO & GPIO0_DATA) && !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
801 ( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV))) {
802 pDevice->bHWRadioOff = TRUE;
803 }
804 }
805 if ((pDevice->bHWRadioOff == TRUE) || (pDevice->bRadioControlOff == TRUE)) {
806 CARDbRadioPowerOff(pDevice);
807 }
808
809#endif
810 }
811 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
812
813 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
814 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Network address = %02x-%02x-%02x=%02x-%02x-%02x\n",
815 pDevice->abyCurrentNetAddr[0],
816 pDevice->abyCurrentNetAddr[1],
817 pDevice->abyCurrentNetAddr[2],
818 pDevice->abyCurrentNetAddr[3],
819 pDevice->abyCurrentNetAddr[4],
820 pDevice->abyCurrentNetAddr[5]);
821
822
823
824 CARDvSafeResetRx(pDevice);
825
826 CARDvSafeResetTx(pDevice);
827
828 if (pDevice->byLocalID <= REV_ID_VT3253_A1) {
829 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
830 }
831
832 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
833
834
835 MACvReceive0(pDevice->PortOffset);
836 MACvReceive1(pDevice->PortOffset);
837
838
839 MACvStart(pDevice->PortOffset);
840
841 netif_stop_queue(pDevice->dev);
842
843
844}
845
846
847
848static VOID device_init_diversity_timer(PSDevice pDevice) {
849
850 init_timer(&pDevice->TimerSQ3Tmax1);
851 pDevice->TimerSQ3Tmax1.data = (ULONG)pDevice;
852 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
853 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
854
855 init_timer(&pDevice->TimerSQ3Tmax2);
856 pDevice->TimerSQ3Tmax2.data = (ULONG)pDevice;
857 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
858 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
859
860 init_timer(&pDevice->TimerSQ3Tmax3);
861 pDevice->TimerSQ3Tmax3.data = (ULONG)pDevice;
862 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
863 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
864
865 return;
866}
867
868
869static BOOL device_release_WPADEV(PSDevice pDevice)
870{
871 viawget_wpa_header *wpahdr;
872 int ii=0;
873
874
875 if (pDevice->bWPADEVUp==TRUE) {
876 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
877 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
878 wpahdr->resp_ie_len = 0;
879 wpahdr->req_ie_len = 0;
880 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
881 pDevice->skb->dev = pDevice->wpadev;
882 skb_reset_mac_header(pDevice->skb);
883 pDevice->skb->pkt_type = PACKET_HOST;
884 pDevice->skb->protocol = htons(ETH_P_802_2);
885 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
886 netif_rx(pDevice->skb);
887 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
888
889
890
891
892 while((pDevice->bWPADEVUp==TRUE)) {
893 set_current_state(TASK_UNINTERRUPTIBLE);
894 schedule_timeout (HZ/20);
895 ii++;
896 if(ii>20)
897 break;
898 }
899 };
900 return TRUE;
901}
902
903
904static const struct net_device_ops device_netdev_ops = {
905 .ndo_open = device_open,
906 .ndo_stop = device_close,
907 .ndo_do_ioctl = device_ioctl,
908 .ndo_get_stats = device_get_stats,
909 .ndo_start_xmit = device_xmit,
910 .ndo_set_multicast_list = device_set_multi,
911};
912
913
914
915static int
916device_found1(struct pci_dev *pcid, const struct pci_device_id *ent)
917{
918 static BOOL bFirst = TRUE;
919 struct net_device* dev = NULL;
920 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
921 PSDevice pDevice;
922 int rc;
923 if (device_nics ++>= MAX_UINTS) {
924 printk(KERN_NOTICE DEVICE_NAME ": already found %d NICs\n", device_nics);
925 return -ENODEV;
926 }
927
928
929 dev = alloc_etherdev(sizeof(DEVICE_INFO));
930
931 pDevice = (PSDevice) netdev_priv(dev);
932
933 if (dev == NULL) {
934 printk(KERN_ERR DEVICE_NAME ": allocate net device failed \n");
935 return -ENODEV;
936 }
937
938
939
940 SET_NETDEV_DEV(dev, &pcid->dev);
941
942 if (bFirst) {
943 printk(KERN_NOTICE "%s Ver. %s\n",DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
944 printk(KERN_NOTICE "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
945 bFirst=FALSE;
946 }
947
948 if (!device_init_info(pcid, &pDevice, pChip_info)) {
949 return -ENOMEM;
950 }
951 pDevice->dev = dev;
952 pDevice->next_module = root_device_dev;
953 root_device_dev = dev;
954 dev->irq = pcid->irq;
955
956 if (pci_enable_device(pcid)) {
957 device_free_info(pDevice);
958 return -ENODEV;
959 }
960#ifdef DEBUG
961 printk("Before get pci_info memaddr is %x\n",pDevice->memaddr);
962#endif
963 if (device_get_pci_info(pDevice,pcid) == FALSE) {
964 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device.\n");
965 device_free_info(pDevice);
966 return -ENODEV;
967 }
968
969#if 1
970
971#ifdef DEBUG
972
973
974 printk("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",pDevice->memaddr,pDevice->ioaddr,pDevice->io_size);
975 {
976 int i;
977 U32 bar,len;
978 u32 address[] = {
979 PCI_BASE_ADDRESS_0,
980 PCI_BASE_ADDRESS_1,
981 PCI_BASE_ADDRESS_2,
982 PCI_BASE_ADDRESS_3,
983 PCI_BASE_ADDRESS_4,
984 PCI_BASE_ADDRESS_5,
985 0};
986 for (i=0;address[i];i++)
987 {
988
989 pci_read_config_dword(pcid, address[i], &bar);
990 printk("bar %d is %x\n",i,bar);
991 if (!bar)
992 {
993 printk("bar %d not implemented\n",i);
994 continue;
995 }
996 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
997
998
999 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
1000 len = len & ~(len - 1);
1001
1002 printk("IO space: len in IO %x, BAR %d\n", len, i);
1003 }
1004 else
1005 {
1006 len = bar & 0xFFFFFFF0;
1007 len = ~len + 1;
1008
1009 printk("len in MEM %x, BAR %d\n", len, i);
1010 }
1011 }
1012 }
1013#endif
1014
1015
1016#endif
1017
1018#ifdef DEBUG
1019
1020#endif
1021 pDevice->PortOffset = (DWORD)ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
1022
1023
1024 if(pDevice->PortOffset == 0) {
1025 printk(KERN_ERR DEVICE_NAME ": Failed to IO remapping ..\n");
1026 device_free_info(pDevice);
1027 return -ENODEV;
1028 }
1029
1030
1031
1032
1033 rc = pci_request_regions(pcid, DEVICE_NAME);
1034 if (rc) {
1035 printk(KERN_ERR DEVICE_NAME ": Failed to find PCI device\n");
1036 device_free_info(pDevice);
1037 return -ENODEV;
1038 }
1039
1040 dev->base_addr = pDevice->ioaddr;
1041#ifdef PLICE_DEBUG
1042 BYTE value;
1043
1044 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1045 printk("Before write: value is %x\n",value);
1046
1047 VNSvOutPortB(pDevice->PortOffset,value);
1048 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
1049 printk("After write: value is %x\n",value);
1050#endif
1051
1052
1053
1054#ifdef IO_MAP
1055 pDevice->PortOffset = pDevice->ioaddr;
1056#endif
1057
1058 if (!MACbSoftwareReset(pDevice->PortOffset)) {
1059 printk(KERN_ERR DEVICE_NAME ": Failed to access MAC hardware..\n");
1060 device_free_info(pDevice);
1061 return -ENODEV;
1062 }
1063
1064 MACvInitialize(pDevice->PortOffset);
1065 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
1066
1067 device_get_options(pDevice, device_nics-1, dev->name);
1068 device_set_options(pDevice);
1069
1070 pDevice->sOpts.flags &= pChip_info->flags;
1071
1072
1073 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
1074 pDevice->tx_80211 = device_dma0_tx_80211;
1075 pDevice->sMgmtObj.pAdapter = (PVOID)pDevice;
1076 pDevice->pMgmt = &(pDevice->sMgmtObj);
1077
1078 dev->irq = pcid->irq;
1079 dev->netdev_ops = &device_netdev_ops;
1080
1081 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
1082
1083 rc = register_netdev(dev);
1084 if (rc)
1085 {
1086 printk(KERN_ERR DEVICE_NAME " Failed to register netdev\n");
1087 device_free_info(pDevice);
1088 return -ENODEV;
1089 }
1090
1091
1092 if(wpa_set_wpadev(pDevice, 1)!=0) {
1093 printk("Fail to Register WPADEV?\n");
1094 unregister_netdev(pDevice->dev);
1095 free_netdev(dev);
1096 }
1097 device_print_info(pDevice);
1098 pci_set_drvdata(pcid, pDevice);
1099 return 0;
1100
1101}
1102
1103static void device_print_info(PSDevice pDevice)
1104{
1105 struct net_device* dev=pDevice->dev;
1106
1107 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n",dev->name, get_chip_name(pDevice->chip_id));
1108 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
1109 dev->name,
1110 dev->dev_addr[0],dev->dev_addr[1],dev->dev_addr[2],
1111 dev->dev_addr[3],dev->dev_addr[4],dev->dev_addr[5]);
1112#ifdef IO_MAP
1113 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx ",(ULONG) pDevice->ioaddr);
1114 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1115#else
1116 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IO=0x%lx Mem=0x%lx ",(ULONG) pDevice->ioaddr,(ULONG) pDevice->PortOffset);
1117 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO" IRQ=%d \n", pDevice->dev->irq);
1118#endif
1119
1120}
1121
1122static BOOL device_init_info(struct pci_dev* pcid, PSDevice* ppDevice,
1123 PCHIP_INFO pChip_info) {
1124
1125 PSDevice p;
1126
1127 memset(*ppDevice,0,sizeof(DEVICE_INFO));
1128
1129 if (pDevice_Infos == NULL) {
1130 pDevice_Infos =*ppDevice;
1131 }
1132 else {
1133 for (p=pDevice_Infos;p->next!=NULL;p=p->next)
1134 do {} while (0);
1135 p->next = *ppDevice;
1136 (*ppDevice)->prev = p;
1137 }
1138
1139 (*ppDevice)->pcid = pcid;
1140 (*ppDevice)->chip_id = pChip_info->chip_id;
1141 (*ppDevice)->io_size = pChip_info->io_size;
1142 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
1143 (*ppDevice)->multicast_limit =32;
1144
1145 spin_lock_init(&((*ppDevice)->lock));
1146
1147 return TRUE;
1148}
1149
1150static BOOL device_get_pci_info(PSDevice pDevice, struct pci_dev* pcid) {
1151
1152 U16 pci_cmd;
1153 U8 b;
1154 UINT cis_addr;
1155#ifdef PLICE_DEBUG
1156 BYTE pci_config[256];
1157 BYTE value =0x00;
1158 int ii,j;
1159 U16 max_lat=0x0000;
1160 memset(pci_config,0x00,256);
1161#endif
1162
1163 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
1164 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID,&pDevice->SubSystemID);
1165 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
1166 pci_read_config_word(pcid, PCI_COMMAND, (u16 *) & (pci_cmd));
1167
1168 pci_set_master(pcid);
1169
1170 pDevice->memaddr = pci_resource_start(pcid,0);
1171 pDevice->ioaddr = pci_resource_start(pcid,1);
1172
1173#ifdef DEBUG
1174
1175
1176#endif
1177
1178 cis_addr = pci_resource_start(pcid,2);
1179
1180 pDevice->pcid = pcid;
1181
1182 pci_read_config_byte(pcid, PCI_COMMAND, &b);
1183 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
1184
1185#ifdef PLICE_DEBUG
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195 for (ii=0;ii<0xFF;ii++)
1196 {
1197 pci_read_config_byte(pcid,ii,&value);
1198 pci_config[ii] = value;
1199 }
1200 for (ii=0,j=1;ii<0x100;ii++,j++)
1201 {
1202 if (j %16 == 0)
1203 {
1204 printk("%x:",pci_config[ii]);
1205 printk("\n");
1206 }
1207 else
1208 {
1209 printk("%x:",pci_config[ii]);
1210 }
1211 }
1212#endif
1213 return TRUE;
1214}
1215
1216static void device_free_info(PSDevice pDevice) {
1217 PSDevice ptr;
1218 struct net_device* dev=pDevice->dev;
1219
1220 ASSERT(pDevice);
1221
1222device_release_WPADEV(pDevice);
1223
1224
1225
1226 if(wpa_set_wpadev(pDevice, 0)!=0)
1227 printk("unregister wpadev fail?\n");
1228
1229 if (pDevice_Infos==NULL)
1230 return;
1231
1232 for (ptr=pDevice_Infos;ptr && (ptr!=pDevice);ptr=ptr->next)
1233 do {} while (0);
1234
1235 if (ptr==pDevice) {
1236 if (ptr==pDevice_Infos)
1237 pDevice_Infos=ptr->next;
1238 else
1239 ptr->prev->next=ptr->next;
1240 }
1241 else {
1242 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
1243 return;
1244 }
1245#ifdef HOSTAP
1246 if (dev)
1247 hostap_set_hostapd(pDevice, 0, 0);
1248#endif
1249 if (dev)
1250 unregister_netdev(dev);
1251
1252 if (pDevice->PortOffset)
1253 iounmap((PVOID)pDevice->PortOffset);
1254
1255 if (pDevice->pcid)
1256 pci_release_regions(pDevice->pcid);
1257 if (dev)
1258 free_netdev(dev);
1259
1260 if (pDevice->pcid) {
1261 pci_set_drvdata(pDevice->pcid,NULL);
1262 }
1263}
1264
1265static BOOL device_init_rings(PSDevice pDevice) {
1266 void* vir_pool;
1267
1268
1269
1270 vir_pool = pci_alloc_consistent(pDevice->pcid,
1271 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1272 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1273 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1274 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1275 &pDevice->pool_dma);
1276
1277 if (vir_pool == NULL) {
1278 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
1279 return FALSE;
1280 }
1281
1282 memset(vir_pool, 0,
1283 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1284 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1285 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1286 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1287 );
1288
1289 pDevice->aRD0Ring = vir_pool;
1290 pDevice->aRD1Ring = vir_pool +
1291 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1292
1293
1294 pDevice->rd0_pool_dma = pDevice->pool_dma;
1295 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1296 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1297
1298 pDevice->tx0_bufs = pci_alloc_consistent(pDevice->pcid,
1299 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1300 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1301 CB_BEACON_BUF_SIZE +
1302 CB_MAX_BUF_SIZE,
1303 &pDevice->tx_bufs_dma0);
1304
1305 if (pDevice->tx0_bufs == NULL) {
1306 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
1307 pci_free_consistent(pDevice->pcid,
1308 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1309 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1310 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1311 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1312 vir_pool, pDevice->pool_dma
1313 );
1314 return FALSE;
1315 }
1316
1317 memset(pDevice->tx0_bufs, 0,
1318 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1319 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1320 CB_BEACON_BUF_SIZE +
1321 CB_MAX_BUF_SIZE
1322 );
1323
1324 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1325 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1326
1327 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1328 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1329
1330
1331
1332 pDevice->apTD0Rings = vir_pool
1333 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1334 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1335
1336 pDevice->apTD1Rings = vir_pool
1337 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1338 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1339 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1340
1341
1342 pDevice->tx1_bufs = pDevice->tx0_bufs +
1343 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1344
1345
1346 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1347 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1348
1349 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1350 CB_BEACON_BUF_SIZE;
1351
1352 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1353 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1354
1355
1356 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1357 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1358
1359
1360 return TRUE;
1361}
1362
1363static void device_free_rings(PSDevice pDevice) {
1364
1365 pci_free_consistent(pDevice->pcid,
1366 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1367 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1368 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1369 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1370 ,
1371 pDevice->aRD0Ring, pDevice->pool_dma
1372 );
1373
1374 if (pDevice->tx0_bufs)
1375 pci_free_consistent(pDevice->pcid,
1376 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1377 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1378 CB_BEACON_BUF_SIZE +
1379 CB_MAX_BUF_SIZE,
1380 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1381 );
1382}
1383
1384static void device_init_rd0_ring(PSDevice pDevice) {
1385 int i;
1386 dma_addr_t curr = pDevice->rd0_pool_dma;
1387 PSRxDesc pDesc;
1388
1389
1390 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1391 pDesc = &(pDevice->aRD0Ring[i]);
1392 pDesc->pRDInfo = alloc_rd_info();
1393 ASSERT(pDesc->pRDInfo);
1394 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1395 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1396 pDevice->dev->name);
1397 }
1398 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1399 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1400 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1401 }
1402
1403 if (i > 0)
1404 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1405 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1406}
1407
1408
1409static void device_init_rd1_ring(PSDevice pDevice) {
1410 int i;
1411 dma_addr_t curr = pDevice->rd1_pool_dma;
1412 PSRxDesc pDesc;
1413
1414
1415 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1416 pDesc = &(pDevice->aRD1Ring[i]);
1417 pDesc->pRDInfo = alloc_rd_info();
1418 ASSERT(pDesc->pRDInfo);
1419 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1420 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc rx bufs\n",
1421 pDevice->dev->name);
1422 }
1423 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1424 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1425 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1426 }
1427
1428 if (i > 0)
1429 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1430 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1431}
1432
1433
1434static void device_init_defrag_cb(PSDevice pDevice) {
1435 int i;
1436 PSDeFragControlBlock pDeF;
1437
1438
1439 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1440 pDeF = &(pDevice->sRxDFCB[i]);
1441 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1442 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc frag bufs\n",
1443 pDevice->dev->name);
1444 };
1445 }
1446 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1447 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1448}
1449
1450
1451
1452
1453static void device_free_rd0_ring(PSDevice pDevice) {
1454 int i;
1455
1456 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1457 PSRxDesc pDesc =&(pDevice->aRD0Ring[i]);
1458 PDEVICE_RD_INFO pRDInfo =pDesc->pRDInfo;
1459
1460 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1461 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1462
1463 dev_kfree_skb(pRDInfo->skb);
1464
1465 kfree((PVOID)pDesc->pRDInfo);
1466 }
1467
1468}
1469
1470static void device_free_rd1_ring(PSDevice pDevice) {
1471 int i;
1472
1473
1474 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1475 PSRxDesc pDesc=&(pDevice->aRD1Ring[i]);
1476 PDEVICE_RD_INFO pRDInfo=pDesc->pRDInfo;
1477
1478 pci_unmap_single(pDevice->pcid,pRDInfo->skb_dma,
1479 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1480
1481 dev_kfree_skb(pRDInfo->skb);
1482
1483 kfree((PVOID)pDesc->pRDInfo);
1484 }
1485
1486}
1487
1488static void device_free_frag_buf(PSDevice pDevice) {
1489 PSDeFragControlBlock pDeF;
1490 int i;
1491
1492 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1493
1494 pDeF = &(pDevice->sRxDFCB[i]);
1495
1496 if (pDeF->skb)
1497 dev_kfree_skb(pDeF->skb);
1498
1499 }
1500
1501}
1502
1503static void device_init_td0_ring(PSDevice pDevice) {
1504 int i;
1505 dma_addr_t curr;
1506 PSTxDesc pDesc;
1507
1508 curr = pDevice->td0_pool_dma;
1509 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1510 pDesc = &(pDevice->apTD0Rings[i]);
1511 pDesc->pTDInfo = alloc_td_info();
1512 ASSERT(pDesc->pTDInfo);
1513 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1514 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1515 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1516 }
1517 pDesc->next =&(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1518 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1519 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1520 }
1521
1522 if (i > 0)
1523 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1524 pDevice->apTailTD[0] = pDevice->apCurrTD[0] =&(pDevice->apTD0Rings[0]);
1525
1526}
1527
1528static void device_init_td1_ring(PSDevice pDevice) {
1529 int i;
1530 dma_addr_t curr;
1531 PSTxDesc pDesc;
1532
1533
1534 curr=pDevice->td1_pool_dma;
1535 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr+=sizeof(STxDesc)) {
1536 pDesc=&(pDevice->apTD1Rings[i]);
1537 pDesc->pTDInfo = alloc_td_info();
1538 ASSERT(pDesc->pTDInfo);
1539 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1540 pDesc->pTDInfo->buf=pDevice->tx1_bufs+(i)*PKT_BUF_SZ;
1541 pDesc->pTDInfo->buf_dma=pDevice->tx_bufs_dma1+(i)*PKT_BUF_SZ;
1542 }
1543 pDesc->next=&(pDevice->apTD1Rings[(i+1) % pDevice->sOpts.nTxDescs[1]]);
1544 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1545 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1546 }
1547
1548 if (i > 0)
1549 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1550 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1551}
1552
1553
1554
1555static void device_free_td0_ring(PSDevice pDevice) {
1556 int i;
1557 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1558 PSTxDesc pDesc=&(pDevice->apTD0Rings[i]);
1559 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1560
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);
1564
1565 if (pTDInfo->skb)
1566 dev_kfree_skb(pTDInfo->skb);
1567
1568 kfree((PVOID)pDesc->pTDInfo);
1569 }
1570}
1571
1572static void device_free_td1_ring(PSDevice pDevice) {
1573 int i;
1574
1575 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1576 PSTxDesc pDesc=&(pDevice->apTD1Rings[i]);
1577 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1578
1579 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1580 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1581 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1582
1583 if (pTDInfo->skb)
1584 dev_kfree_skb(pTDInfo->skb);
1585
1586 kfree((PVOID)pDesc->pTDInfo);
1587 }
1588
1589}
1590
1591
1592
1593
1594
1595static int device_rx_srv(PSDevice pDevice, UINT uIdx) {
1596 PSRxDesc pRD;
1597 int works = 0;
1598
1599
1600 for (pRD = pDevice->pCurrRD[uIdx];
1601 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1602 pRD = pRD->next) {
1603
1604 if (works++>15)
1605 break;
1606 if (device_receive_frame(pDevice, pRD)) {
1607 if (!device_alloc_rx_buf(pDevice,pRD)) {
1608 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1609 "%s: can not allocate rx buf\n", pDevice->dev->name);
1610 break;
1611 }
1612 }
1613 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1614 pDevice->dev->last_rx = jiffies;
1615 }
1616
1617 pDevice->pCurrRD[uIdx]=pRD;
1618
1619 return works;
1620}
1621
1622
1623static BOOL device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD) {
1624
1625 PDEVICE_RD_INFO pRDInfo=pRD->pRDInfo;
1626
1627
1628 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1629#ifdef PLICE_DEBUG
1630
1631#endif
1632 if (pRDInfo->skb==NULL)
1633 return FALSE;
1634 ASSERT(pRDInfo->skb);
1635 pRDInfo->skb->dev = pDevice->dev;
1636 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
1637 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1638 *((unsigned int *) &(pRD->m_rd0RD0)) = 0;
1639
1640 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1641 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1642 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1643 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1644
1645 return TRUE;
1646}
1647
1648
1649
1650BOOL device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF) {
1651
1652 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1653 if (pDeF->skb == NULL)
1654 return FALSE;
1655 ASSERT(pDeF->skb);
1656 pDeF->skb->dev = pDevice->dev;
1657
1658 return TRUE;
1659}
1660
1661
1662
1663static int device_tx_srv(PSDevice pDevice, UINT uIdx) {
1664 PSTxDesc pTD;
1665 BOOL bFull=FALSE;
1666 int works = 0;
1667 BYTE byTsr0;
1668 BYTE byTsr1;
1669 UINT uFrameSize, uFIFOHeaderSize;
1670 PSTxBufHead pTxBufHead;
1671 struct net_device_stats* pStats = &pDevice->stats;
1672 struct sk_buff* skb;
1673 UINT uNodeIndex;
1674 PSMgmtObject pMgmt = pDevice->pMgmt;
1675
1676
1677 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] >0; pTD = pTD->next) {
1678
1679 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1680 break;
1681 if (works++>15)
1682 break;
1683
1684 byTsr0 = pTD->m_td0TD0.byTSR0;
1685 byTsr1 = pTD->m_td0TD0.byTSR1;
1686
1687
1688 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1689
1690 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1691 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1692 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1693 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1694
1695
1696
1697 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1698 byTsr0, byTsr1,
1699 (PBYTE)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1700 uFrameSize, uIdx);
1701
1702
1703 BSSvUpdateNodeTxCounter(pDevice,
1704 byTsr0, byTsr1,
1705 (PBYTE)(pTD->pTDInfo->buf),
1706 uFIFOHeaderSize
1707 );
1708
1709 if ( !(byTsr1 & TSR1_TERR)) {
1710 if (byTsr0 != 0) {
1711 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1712 (INT)uIdx, byTsr1, byTsr0);
1713 }
1714 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG) {
1715 pDevice->s802_11Counter.TransmittedFragmentCount ++;
1716 }
1717 pStats->tx_packets++;
1718 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1719 }
1720 else {
1721 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1722 (INT)uIdx, byTsr1, byTsr0);
1723 pStats->tx_errors++;
1724 pStats->tx_dropped++;
1725 }
1726 }
1727
1728 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1729 if (pDevice->bEnableHostapd) {
1730 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif.. \n");
1731 skb = pTD->pTDInfo->skb;
1732 skb->dev = pDevice->apdev;
1733 skb_reset_mac_header(skb);
1734 skb->pkt_type = PACKET_OTHERHOST;
1735
1736 memset(skb->cb, 0, sizeof(skb->cb));
1737 netif_rx(skb);
1738 }
1739 }
1740
1741 if (byTsr1 & TSR1_TERR) {
1742 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1743 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1744 (INT)uIdx, byTsr1, byTsr0);
1745 }
1746
1747
1748
1749
1750 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1751 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1752 WORD wAID;
1753 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1754
1755 skb = pTD->pTDInfo->skb;
1756 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
1757 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1758 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1759 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1760
1761 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1762 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1763 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1764 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1765 ,(INT)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1766 pStats->tx_errors--;
1767 pStats->tx_dropped--;
1768 }
1769 }
1770 }
1771 }
1772 device_free_tx_buf(pDevice,pTD);
1773 pDevice->iTDUsed[uIdx]--;
1774 }
1775 }
1776
1777
1778 if (uIdx == TYPE_AC0DMA) {
1779
1780
1781 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1782 bFull = TRUE;
1783 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
1784 }
1785 if (netif_queue_stopped(pDevice->dev) && (bFull==FALSE)){
1786 netif_wake_queue(pDevice->dev);
1787 }
1788 }
1789
1790
1791 pDevice->apTailTD[uIdx] = pTD;
1792
1793 return works;
1794}
1795
1796
1797static void device_error(PSDevice pDevice, WORD status) {
1798
1799 if (status & ISR_FETALERR) {
1800 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1801 "%s: Hardware fatal error.\n",
1802 pDevice->dev->name);
1803 netif_stop_queue(pDevice->dev);
1804 del_timer(&pDevice->sTimerCommand);
1805 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1806 pDevice->bCmdRunning = FALSE;
1807 MACbShutdown(pDevice->PortOffset);
1808 return;
1809 }
1810
1811}
1812
1813static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc) {
1814 PDEVICE_TD_INFO pTDInfo=pDesc->pTDInfo;
1815 struct sk_buff* skb=pTDInfo->skb;
1816
1817
1818 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1819 pci_unmap_single(pDevice->pcid,pTDInfo->skb_dma,skb->len,
1820 PCI_DMA_TODEVICE);
1821 }
1822
1823 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1824 dev_kfree_skb_irq(skb);
1825
1826 pTDInfo->skb_dma = 0;
1827 pTDInfo->skb = 0;
1828 pTDInfo->byFlags = 0;
1829}
1830
1831
1832
1833
1834VOID InitRxManagementQueue(PSDevice pDevice)
1835{
1836 pDevice->rxManeQueue.packet_num = 0;
1837 pDevice->rxManeQueue.head = pDevice->rxManeQueue.tail = 0;
1838}
1839
1840
1841
1842
1843
1844
1845
1846INT MlmeThread(
1847 void * Context)
1848{
1849 PSDevice pDevice = (PSDevice) Context;
1850 PSRxMgmtPacket pRxMgmtPacket;
1851
1852
1853
1854
1855
1856
1857#if 1
1858 while (1)
1859 {
1860
1861
1862
1863
1864#if 1
1865 spin_lock_irq(&pDevice->lock);
1866 while(pDevice->rxManeQueue.packet_num != 0)
1867 {
1868 pRxMgmtPacket = DeQueue(pDevice);
1869
1870
1871 vMgrRxManagePacket(pDevice, pDevice->pMgmt, pRxMgmtPacket);
1872
1873
1874 }
1875 spin_unlock_irq(&pDevice->lock);
1876 if (mlme_kill == 0)
1877 break;
1878
1879#endif
1880
1881 schedule();
1882
1883 if (mlme_kill == 0)
1884 break;
1885
1886 }
1887
1888#endif
1889 return 0;
1890
1891}
1892
1893
1894
1895static int device_open(struct net_device *dev) {
1896 PSDevice pDevice=(PSDevice) netdev_priv(dev);
1897 int i;
1898#ifdef WPA_SM_Transtatus
1899 extern SWPAResult wpa_Result;
1900#endif
1901
1902 pDevice->rx_buf_sz = PKT_BUF_SZ;
1903 if (!device_init_rings(pDevice)) {
1904 return -ENOMEM;
1905 }
1906
1907 i=request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1908 if (i)
1909 return i;
1910
1911#ifdef WPA_SM_Transtatus
1912 memset(wpa_Result.ifname,0,sizeof(wpa_Result.ifname));
1913 wpa_Result.proto = 0;
1914 wpa_Result.key_mgmt = 0;
1915 wpa_Result.eap_type = 0;
1916 wpa_Result.authenticated = FALSE;
1917 pDevice->fWPA_Authened = FALSE;
1918#endif
1919DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
1920device_init_rd0_ring(pDevice);
1921 device_init_rd1_ring(pDevice);
1922 device_init_defrag_cb(pDevice);
1923 device_init_td0_ring(pDevice);
1924 device_init_td1_ring(pDevice);
1925
1926
1927
1928 if (pDevice->bDiversityRegCtlON) {
1929 device_init_diversity_timer(pDevice);
1930 }
1931 vMgrObjectInit(pDevice);
1932 vMgrTimerInit(pDevice);
1933
1934
1935#ifdef TASK_LET
1936 tasklet_init (&pDevice->RxMngWorkItem,(void *)MngWorkItem,(unsigned long )pDevice);
1937#endif
1938#ifdef THREAD
1939 InitRxManagementQueue(pDevice);
1940 mlme_kill = 0;
1941 mlme_task = kthread_run(MlmeThread,(void *) pDevice, "MLME");
1942 if (IS_ERR(mlme_task)) {
1943 printk("thread create fail\n");
1944 return -1;
1945 }
1946
1947 mlme_kill = 1;
1948#endif
1949
1950
1951
1952#if 0
1953 pDevice->MLMEThr_pid = kernel_thread(MlmeThread, pDevice, CLONE_VM);
1954 if (pDevice->MLMEThr_pid <0 )
1955 {
1956 printk("unable start thread MlmeThread\n");
1957 return -1;
1958 }
1959#endif
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
1971 device_init_registers(pDevice, DEVICE_INIT_COLD);
1972 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1973 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, U_ETHER_ADDR_LEN);
1974 device_set_multi(pDevice->dev);
1975
1976
1977 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1978 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1979
1980 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1981
1982
1983
1984
1985
1986
1987 pDevice->bwextcount=0;
1988 pDevice->bWPASuppWextEnabled = FALSE;
1989#endif
1990 pDevice->byReAssocCount = 0;
1991 pDevice->bWPADEVUp = FALSE;
1992
1993 if ((pDevice->bEncryptionEnable == TRUE) && (pDevice->bTransmitKey == TRUE)) {
1994 KeybSetDefaultKey(&(pDevice->sKey),
1995 (DWORD)(pDevice->byKeyIndex | (1 << 31)),
1996 pDevice->uKeyLength,
1997 NULL,
1998 pDevice->abyKey,
1999 KEY_CTL_WEP,
2000 pDevice->PortOffset,
2001 pDevice->byLocalID
2002 );
2003 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
2004 }
2005
2006
2007
2008
2009DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
2010 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2011
2012 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2013 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
2014 }
2015 else {
2016 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
2017 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_SSID, NULL);
2018 }
2019 pDevice->flags |=DEVICE_FLAGS_OPENED;
2020
2021 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success.. \n");
2022 return 0;
2023}
2024
2025
2026static int device_close(struct net_device *dev) {
2027 PSDevice pDevice=(PSDevice) netdev_priv(dev);
2028 PSMgmtObject pMgmt = pDevice->pMgmt;
2029
2030#ifdef THREAD
2031 mlme_kill = 0;
2032#endif
2033
2034
2035 if (pDevice->bLinkPass) {
2036 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
2037 mdelay(30);
2038 }
2039#ifdef TxInSleep
2040 del_timer(&pDevice->sTimerTxData);
2041#endif
2042 del_timer(&pDevice->sTimerCommand);
2043 del_timer(&pMgmt->sTimerSecondCallback);
2044 if (pDevice->bDiversityRegCtlON) {
2045 del_timer(&pDevice->TimerSQ3Tmax1);
2046 del_timer(&pDevice->TimerSQ3Tmax2);
2047 del_timer(&pDevice->TimerSQ3Tmax3);
2048 }
2049
2050#ifdef TASK_LET
2051 tasklet_kill(&pDevice->RxMngWorkItem);
2052#endif
2053 netif_stop_queue(dev);
2054 pDevice->bCmdRunning = FALSE;
2055 MACbShutdown(pDevice->PortOffset);
2056 MACbSoftwareReset(pDevice->PortOffset);
2057 CARDbRadioPowerOff(pDevice);
2058
2059 pDevice->bLinkPass = FALSE;
2060 memset(pMgmt->abyCurrBSSID, 0, 6);
2061 pMgmt->eCurrState = WMAC_STATE_IDLE;
2062 device_free_td0_ring(pDevice);
2063 device_free_td1_ring(pDevice);
2064 device_free_rd0_ring(pDevice);
2065 device_free_rd1_ring(pDevice);
2066 device_free_frag_buf(pDevice);
2067 device_free_rings(pDevice);
2068 BSSvClearNodeDBTable(pDevice, 0);
2069 free_irq(dev->irq, dev);
2070 pDevice->flags &=(~DEVICE_FLAGS_OPENED);
2071
2072device_release_WPADEV(pDevice);
2073
2074
2075
2076 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close.. \n");
2077 return 0;
2078}
2079
2080
2081
2082static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev) {
2083 PSDevice pDevice=netdev_priv(dev);
2084 PBYTE pbMPDU;
2085 UINT cbMPDULen = 0;
2086
2087
2088 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
2089 spin_lock_irq(&pDevice->lock);
2090
2091 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2092 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
2093 dev_kfree_skb_irq(skb);
2094 spin_unlock_irq(&pDevice->lock);
2095 return 0;
2096 }
2097
2098 if (pDevice->bStopTx0Pkt == TRUE) {
2099 dev_kfree_skb_irq(skb);
2100 spin_unlock_irq(&pDevice->lock);
2101 return 0;
2102 };
2103
2104 cbMPDULen = skb->len;
2105 pbMPDU = skb->data;
2106
2107 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
2108
2109 spin_unlock_irq(&pDevice->lock);
2110
2111 return 0;
2112
2113}
2114
2115
2116
2117BOOL device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, UINT uNodeIndex) {
2118 PSMgmtObject pMgmt = pDevice->pMgmt;
2119 PSTxDesc pHeadTD, pLastTD;
2120 UINT cbFrameBodySize;
2121 UINT uMACfragNum;
2122 BYTE byPktType;
2123 BOOL bNeedEncryption = FALSE;
2124 PSKeyItem pTransmitKey = NULL;
2125 UINT cbHeaderSize;
2126 UINT ii;
2127 SKeyItem STempKey;
2128
2129
2130
2131 if (pDevice->bStopTx0Pkt == TRUE) {
2132 dev_kfree_skb_irq(skb);
2133 return FALSE;
2134 };
2135
2136 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
2137 dev_kfree_skb_irq(skb);
2138 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
2139 return FALSE;
2140 }
2141
2142 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2143 if (pDevice->uAssocCount == 0) {
2144 dev_kfree_skb_irq(skb);
2145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
2146 return FALSE;
2147 }
2148 }
2149
2150 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
2151
2152 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2153
2154 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2155 cbFrameBodySize = skb->len - U_HEADER_LEN;
2156
2157
2158 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2159 cbFrameBodySize += 8;
2160 }
2161 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2162
2163 if ( uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
2164 dev_kfree_skb_irq(skb);
2165 return FALSE;
2166 }
2167 byPktType = (BYTE)pDevice->byPacketType;
2168
2169
2170 if (pDevice->bFixRate) {
2171 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2172 if (pDevice->uConnectionRate >= RATE_11M) {
2173 pDevice->wCurrentRate = RATE_11M;
2174 } else {
2175 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2176 }
2177 } else {
2178 if (pDevice->uConnectionRate >= RATE_54M)
2179 pDevice->wCurrentRate = RATE_54M;
2180 else
2181 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2182 }
2183 }
2184 else {
2185 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
2186 }
2187
2188
2189 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2190 pDevice->byPreambleType = pDevice->byShortPreamble;
2191 }
2192 else {
2193 pDevice->byPreambleType = PREAMBLE_LONG;
2194 }
2195
2196 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d \n", pDevice->wCurrentRate);
2197
2198
2199 if (pDevice->wCurrentRate <= RATE_11M) {
2200 byPktType = PK_TYPE_11B;
2201 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2202 byPktType = PK_TYPE_11A;
2203 } else {
2204 if (pDevice->bProtectMode == TRUE) {
2205 byPktType = PK_TYPE_11GB;
2206 } else {
2207 byPktType = PK_TYPE_11GA;
2208 }
2209 }
2210
2211 if (pDevice->bEncryptionEnable == TRUE)
2212 bNeedEncryption = TRUE;
2213
2214 if (pDevice->bEnableHostWEP) {
2215 pTransmitKey = &STempKey;
2216 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2217 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2218 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2219 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2220 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2221 memcpy(pTransmitKey->abyKey,
2222 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2223 pTransmitKey->uKeyLength
2224 );
2225 }
2226 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2227 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
2228 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2229 &uMACfragNum,
2230 &cbHeaderSize
2231 );
2232
2233 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2234
2235 MACbPSWakeup(pDevice->PortOffset);
2236 }
2237
2238 pDevice->bPWBitOn = FALSE;
2239
2240 pLastTD = pHeadTD;
2241 for (ii = 0; ii < uMACfragNum; ii++) {
2242
2243 wmb();
2244 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2245 wmb();
2246 if (ii == (uMACfragNum - 1))
2247 pLastTD = pHeadTD;
2248 pHeadTD = pHeadTD->next;
2249 }
2250
2251
2252
2253 pLastTD->pTDInfo->skb = skb;
2254 pLastTD->pTDInfo->byFlags = 0;
2255 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2256
2257 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
2258
2259 MACvTransmit0(pDevice->PortOffset);
2260
2261
2262 return TRUE;
2263}
2264
2265
2266static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
2267 PSDevice pDevice=netdev_priv(dev);
2268
2269 PSMgmtObject pMgmt = pDevice->pMgmt;
2270 PSTxDesc pHeadTD, pLastTD;
2271 UINT uNodeIndex = 0;
2272 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
2273 WORD wAID;
2274 UINT uMACfragNum = 1;
2275 UINT cbFrameBodySize;
2276 BYTE byPktType;
2277 UINT cbHeaderSize;
2278 BOOL bNeedEncryption = FALSE;
2279 PSKeyItem pTransmitKey = NULL;
2280 SKeyItem STempKey;
2281 UINT ii;
2282 BOOL bTKIP_UseGTK = FALSE;
2283 BOOL bNeedDeAuth = FALSE;
2284 PBYTE pbyBSSID;
2285 BOOL bNodeExist = FALSE;
2286
2287
2288
2289 spin_lock_irq(&pDevice->lock);
2290 if (pDevice->bLinkPass == FALSE) {
2291 dev_kfree_skb_irq(skb);
2292 spin_unlock_irq(&pDevice->lock);
2293 return 0;
2294 }
2295
2296 if (pDevice->bStopDataPkt) {
2297 dev_kfree_skb_irq(skb);
2298 spin_unlock_irq(&pDevice->lock);
2299 return 0;
2300 }
2301
2302
2303 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
2304 if (pDevice->uAssocCount == 0) {
2305 dev_kfree_skb_irq(skb);
2306 spin_unlock_irq(&pDevice->lock);
2307 return 0;
2308 }
2309 if (IS_MULTICAST_ADDRESS((PBYTE)(skb->data))) {
2310 uNodeIndex = 0;
2311 bNodeExist = TRUE;
2312 if (pMgmt->sNodeDBTable[0].bPSEnable) {
2313 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
2314 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
2315
2316 pMgmt->abyPSTxMap[0] |= byMask[0];
2317 spin_unlock_irq(&pDevice->lock);
2318 return 0;
2319 }
2320}else {
2321 if (BSSDBbIsSTAInNodeDB(pMgmt, (PBYTE)(skb->data), &uNodeIndex)) {
2322 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2323 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2324 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2325
2326 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2327 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2328 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2329 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2330 spin_unlock_irq(&pDevice->lock);
2331 return 0;
2332 }
2333
2334 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble) {
2335 pDevice->byPreambleType = pDevice->byShortPreamble;
2336
2337 }else {
2338 pDevice->byPreambleType = PREAMBLE_LONG;
2339 }
2340 bNodeExist = TRUE;
2341
2342 }
2343 }
2344
2345 if (bNodeExist == FALSE) {
2346 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Unknown STA not found in node DB \n");
2347 dev_kfree_skb_irq(skb);
2348 spin_unlock_irq(&pDevice->lock);
2349 return 0;
2350 }
2351 }
2352
2353 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
2354
2355 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2356
2357
2358 memcpy(pDevice->sTxEthHeader.abyDstAddr, (PBYTE)(skb->data), U_HEADER_LEN);
2359 cbFrameBodySize = skb->len - U_HEADER_LEN;
2360
2361 if (ntohs(pDevice->sTxEthHeader.wType) > MAX_DATA_LEN) {
2362 cbFrameBodySize += 8;
2363 }
2364
2365
2366 if (pDevice->bEncryptionEnable == TRUE) {
2367 bNeedEncryption = TRUE;
2368
2369 do {
2370 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2371 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2372 pbyBSSID = pDevice->abyBSSID;
2373
2374 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == FALSE) {
2375
2376 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == TRUE) {
2377 bTKIP_UseGTK = TRUE;
2378 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2379 break;
2380 }
2381 } else {
2382 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get PTK.\n");
2383 break;
2384 }
2385 }else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2386
2387 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr;
2388 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS Serach Key: \n");
2389 for (ii = 0; ii< 6; ii++)
2390 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"%x \n", *(pbyBSSID+ii));
2391 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"\n");
2392
2393
2394 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE)
2395 break;
2396 }
2397
2398 pbyBSSID = pDevice->abyBroadcastAddr;
2399 if(KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == FALSE) {
2400 pTransmitKey = NULL;
2401 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2403 }
2404 else
2405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2406 } else {
2407 bTKIP_UseGTK = TRUE;
2408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"Get GTK.\n");
2409 }
2410 } while(FALSE);
2411 }
2412
2413 if (pDevice->bEnableHostWEP) {
2414 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG"acdma0: STA index %d\n", uNodeIndex);
2415 if (pDevice->bEncryptionEnable == TRUE) {
2416 pTransmitKey = &STempKey;
2417 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2418 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2419 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2420 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2421 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2422 memcpy(pTransmitKey->abyKey,
2423 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2424 pTransmitKey->uKeyLength
2425 );
2426 }
2427 }
2428
2429 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2430
2431 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2432 DBG_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
2433 dev_kfree_skb_irq(skb);
2434 spin_unlock_irq(&pDevice->lock);
2435 return 0;
2436 }
2437
2438 if (pTransmitKey != NULL) {
2439 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2440 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2441 uMACfragNum = 1;
2442 }
2443 }
2444
2445 byPktType = (BYTE)pDevice->byPacketType;
2446
2447 if (pDevice->bFixRate) {
2448#ifdef PLICE_DEBUG
2449 printk("Fix Rate: PhyType is %d,ConnectionRate is %d\n",pDevice->eCurrentPHYType,pDevice->uConnectionRate);
2450#endif
2451
2452 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2453 if (pDevice->uConnectionRate >= RATE_11M) {
2454 pDevice->wCurrentRate = RATE_11M;
2455 } else {
2456 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2457 }
2458 } else {
2459 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2460 (pDevice->uConnectionRate <= RATE_6M)) {
2461 pDevice->wCurrentRate = RATE_6M;
2462 } else {
2463 if (pDevice->uConnectionRate >= RATE_54M)
2464 pDevice->wCurrentRate = RATE_54M;
2465 else
2466 pDevice->wCurrentRate = (WORD)pDevice->uConnectionRate;
2467
2468 }
2469 }
2470 pDevice->byACKRate = (BYTE) pDevice->wCurrentRate;
2471 pDevice->byTopCCKBasicRate = RATE_1M;
2472 pDevice->byTopOFDMBasicRate = RATE_6M;
2473 }
2474 else {
2475
2476 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2477 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2478 pDevice->wCurrentRate = RATE_1M;
2479 pDevice->byACKRate = RATE_1M;
2480 pDevice->byTopCCKBasicRate = RATE_1M;
2481 pDevice->byTopOFDMBasicRate = RATE_6M;
2482 } else {
2483 pDevice->wCurrentRate = RATE_6M;
2484 pDevice->byACKRate = RATE_6M;
2485 pDevice->byTopCCKBasicRate = RATE_1M;
2486 pDevice->byTopOFDMBasicRate = RATE_6M;
2487 }
2488 }
2489 else {
2490 VNTWIFIvGetTxRate( pDevice->pMgmt,
2491 pDevice->sTxEthHeader.abyDstAddr,
2492 &(pDevice->wCurrentRate),
2493 &(pDevice->byACKRate),
2494 &(pDevice->byTopCCKBasicRate),
2495 &(pDevice->byTopOFDMBasicRate));
2496
2497#if 0
2498printk("auto rate:Rate : %d,AckRate:%d,TopCCKRate:%d,TopOFDMRate:%d\n",
2499pDevice->wCurrentRate,pDevice->byACKRate,
2500pDevice->byTopCCKBasicRate,pDevice->byTopOFDMBasicRate);
2501
2502#endif
2503
2504#if 0
2505
2506 pDevice->wCurrentRate = 11;
2507 pDevice->byACKRate = 8;
2508 pDevice->byTopCCKBasicRate = 3;
2509 pDevice->byTopOFDMBasicRate = 8;
2510#endif
2511
2512
2513 }
2514 }
2515
2516
2517
2518 if (pDevice->wCurrentRate <= RATE_11M) {
2519 byPktType = PK_TYPE_11B;
2520 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2521 byPktType = PK_TYPE_11A;
2522 } else {
2523 if (pDevice->bProtectMode == TRUE) {
2524 byPktType = PK_TYPE_11GB;
2525 } else {
2526 byPktType = PK_TYPE_11GA;
2527 }
2528 }
2529
2530
2531
2532
2533
2534 if (bNeedEncryption == TRUE) {
2535 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2536 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2537 bNeedEncryption = FALSE;
2538 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2539 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2540 if (pTransmitKey == NULL) {
2541 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Don't Find TX KEY\n");
2542 }
2543 else {
2544 if (bTKIP_UseGTK == TRUE) {
2545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"error: KEY is GTK!!~~\n");
2546 }
2547 else {
2548 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2549 bNeedEncryption = TRUE;
2550 }
2551 }
2552 }
2553
2554 if (pDevice->byCntMeasure == 2) {
2555 bNeedDeAuth = TRUE;
2556 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2557 }
2558
2559 if (pDevice->bEnableHostWEP) {
2560 if ((uNodeIndex != 0) &&
2561 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2562 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2563 bNeedEncryption = TRUE;
2564 }
2565 }
2566 }
2567 else {
2568 if (pTransmitKey == NULL) {
2569 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"return no tx key\n");
2570 dev_kfree_skb_irq(skb);
2571 spin_unlock_irq(&pDevice->lock);
2572 return 0;
2573 }
2574 }
2575 }
2576
2577
2578#ifdef PLICE_DEBUG
2579
2580
2581
2582
2583#endif
2584 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2585 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2586 &pDevice->sTxEthHeader, (PBYTE)skb->data, pTransmitKey, uNodeIndex,
2587 &uMACfragNum,
2588 &cbHeaderSize
2589 );
2590
2591 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2592
2593 MACbPSWakeup(pDevice->PortOffset);
2594 }
2595 pDevice->bPWBitOn = FALSE;
2596
2597 pLastTD = pHeadTD;
2598 for (ii = 0; ii < uMACfragNum; ii++) {
2599
2600 wmb();
2601 pHeadTD->m_td0TD0.f1Owner=OWNED_BY_NIC;
2602 wmb();
2603 if (ii == uMACfragNum - 1)
2604 pLastTD = pHeadTD;
2605 pHeadTD = pHeadTD->next;
2606 }
2607
2608
2609
2610 pLastTD->pTDInfo->skb = skb;
2611 pLastTD->pTDInfo->byFlags = 0;
2612 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2613#ifdef TxInSleep
2614 pDevice->nTxDataTimeCout=0;
2615 #endif
2616 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1) {
2617 netif_stop_queue(dev);
2618 }
2619
2620 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2621
2622 if (pDevice->bFixRate)
2623 {
2624 printk("FixRate:Rate is %d,TxPower is %d\n",pDevice->wCurrentRate,pDevice->byCurPwr);
2625 }
2626 else
2627 {
2628
2629 }
2630
2631
2632{
2633 BYTE Protocol_Version;
2634 BYTE Packet_Type;
2635 BYTE Descriptor_type;
2636 WORD Key_info;
2637BOOL bTxeapol_key = FALSE;
2638 Protocol_Version = skb->data[U_HEADER_LEN];
2639 Packet_Type = skb->data[U_HEADER_LEN+1];
2640 Descriptor_type = skb->data[U_HEADER_LEN+1+1+2];
2641 Key_info = (skb->data[U_HEADER_LEN+1+1+2+1] << 8)|(skb->data[U_HEADER_LEN+1+1+2+2]);
2642 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2643 if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
2644 (Packet_Type==3)) {
2645 bTxeapol_key = TRUE;
2646 if((Descriptor_type==254)||(Descriptor_type==2)) {
2647 if(!(Key_info & BIT3) &&
2648 (Key_info & BIT8) && (Key_info & BIT9)) {
2649 pDevice->fWPA_Authened = TRUE;
2650 if(Descriptor_type==254)
2651 printk("WPA ");
2652 else
2653 printk("WPA2 ");
2654 printk("Authentication completed!!\n");
2655 }
2656 }
2657 }
2658 }
2659}
2660
2661 MACvTransmitAC0(pDevice->PortOffset);
2662
2663
2664 dev->trans_start = jiffies;
2665
2666 spin_unlock_irq(&pDevice->lock);
2667 return 0;
2668
2669}
2670
2671static irqreturn_t device_intr(int irq, void *dev_instance) {
2672 struct net_device* dev=dev_instance;
2673 PSDevice pDevice=(PSDevice) netdev_priv(dev);
2674
2675 int max_count=0;
2676 DWORD dwMIBCounter=0;
2677 PSMgmtObject pMgmt = pDevice->pMgmt;
2678 BYTE byOrgPageSel=0;
2679 int handled = 0;
2680 BYTE byData = 0;
2681 int ii= 0;
2682
2683
2684
2685 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2686
2687 if (pDevice->dwIsr == 0)
2688 return IRQ_RETVAL(handled);
2689
2690 if (pDevice->dwIsr == 0xffffffff) {
2691 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
2692 return IRQ_RETVAL(handled);
2693 }
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706 handled = 1;
2707 MACvIntDisable(pDevice->PortOffset);
2708 spin_lock_irq(&pDevice->lock);
2709
2710
2711 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2712 if (byOrgPageSel == 1) {
2713 MACvSelectPage0(pDevice->PortOffset);
2714 }
2715 else
2716 byOrgPageSel = 0;
2717
2718 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2719
2720
2721
2722
2723 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2724 while (pDevice->dwIsr != 0) {
2725
2726 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2727 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2728
2729 if (pDevice->dwIsr & ISR_FETALERR){
2730 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR \n");
2731 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2732 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2733 device_error(pDevice, pDevice->dwIsr);
2734 }
2735
2736 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2737
2738 if (pDevice->dwIsr & ISR_MEASURESTART) {
2739
2740 pDevice->byOrgChannel = pDevice->byCurrentCh;
2741 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2742 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2743 MACvSelectPage1(pDevice->PortOffset);
2744 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2745 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2746 MACvSelectPage0(pDevice->PortOffset);
2747
2748
2749 if (CARDbSetChannel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel) == TRUE) {
2750 pDevice->bMeasureInProgress = TRUE;
2751 MACvSelectPage1(pDevice->PortOffset);
2752 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2753 MACvSelectPage0(pDevice->PortOffset);
2754 pDevice->byBasicMap = 0;
2755 pDevice->byCCAFraction = 0;
2756 for(ii=0;ii<8;ii++) {
2757 pDevice->dwRPIs[ii] = 0;
2758 }
2759 } else {
2760
2761
2762
2763 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2764 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2765 MACvSelectPage1(pDevice->PortOffset);
2766 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2767 MACvSelectPage0(pDevice->PortOffset);
2768 }
2769 }
2770 if (pDevice->dwIsr & ISR_MEASUREEND) {
2771
2772 pDevice->bMeasureInProgress = FALSE;
2773 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2774 MACvSelectPage1(pDevice->PortOffset);
2775 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2776 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2777 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2778 pDevice->byBasicMap |= (byData >> 4);
2779 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2780 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2781
2782 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2783 MACvSelectPage0(pDevice->PortOffset);
2784 CARDbSetChannel(pDevice, pDevice->byOrgChannel);
2785
2786 MACvSelectPage1(pDevice->PortOffset);
2787 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2788 MACvSelectPage0(pDevice->PortOffset);
2789 if (byData & MSRCTL_FINISH) {
2790
2791 s_vCompleteCurrentMeasure(pDevice, 0);
2792 } else {
2793
2794 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2795 }
2796 }
2797 if (pDevice->dwIsr & ISR_QUIETSTART) {
2798 do {
2799 ;
2800 } while (CARDbStartQuiet(pDevice) == FALSE);
2801 }
2802 }
2803
2804 if (pDevice->dwIsr & ISR_TBTT) {
2805 if (pDevice->bEnableFirstQuiet == TRUE) {
2806 pDevice->byQuietStartCount--;
2807 if (pDevice->byQuietStartCount == 0) {
2808 pDevice->bEnableFirstQuiet = FALSE;
2809 MACvSelectPage1(pDevice->PortOffset);
2810 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2811 MACvSelectPage0(pDevice->PortOffset);
2812 }
2813 }
2814 if ((pDevice->bChannelSwitch == TRUE) &&
2815 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
2816 pDevice->byChannelSwitchCount--;
2817 if (pDevice->byChannelSwitchCount == 0) {
2818 pDevice->bChannelSwitch = FALSE;
2819 CARDbSetChannel(pDevice, pDevice->byNewChannel);
2820 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2821 MACvSelectPage1(pDevice->PortOffset);
2822 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2823 MACvSelectPage0(pDevice->PortOffset);
2824 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2825
2826 }
2827 }
2828 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2829
2830 } else {
2831 if ((pDevice->bUpdateBBVGA) && (pDevice->bLinkPass == TRUE) && (pDevice->uCurrRSSI != 0)) {
2832 LONG ldBm;
2833
2834 RFvRSSITodBm(pDevice, (BYTE) pDevice->uCurrRSSI, &ldBm);
2835 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
2836 if (ldBm < pDevice->ldBmThreshold[ii]) {
2837 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2838 break;
2839 }
2840 }
2841 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2842 pDevice->uBBVGADiffCount++;
2843 if (pDevice->uBBVGADiffCount == 1) {
2844
2845 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2846 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2847 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2848 }
2849 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2850 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2851 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2852 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2853 }
2854 } else {
2855 pDevice->uBBVGADiffCount = 1;
2856 }
2857 }
2858 }
2859
2860 pDevice->bBeaconSent = FALSE;
2861 if (pDevice->bEnablePSMode) {
2862 PSbIsNextTBTTWakeUp((HANDLE)pDevice);
2863 };
2864
2865 if ((pDevice->eOPMode == OP_MODE_AP) ||
2866 (pDevice->eOPMode == OP_MODE_ADHOC)) {
2867
2868 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2869 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2870 }
2871
2872 if (pDevice->eOPMode == OP_MODE_ADHOC && pDevice->pMgmt->wCurrATIMWindow > 0) {
2873
2874 };
2875
2876 }
2877
2878 if (pDevice->dwIsr & ISR_BNTX) {
2879
2880 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2881 pDevice->bIsBeaconBufReadySet = FALSE;
2882 pDevice->cbBeaconBufReadySetCnt = 0;
2883 };
2884
2885 if (pDevice->eOPMode == OP_MODE_AP) {
2886 if(pMgmt->byDTIMCount > 0) {
2887 pMgmt->byDTIMCount --;
2888 pMgmt->sNodeDBTable[0].bRxPSPoll = FALSE;
2889 }
2890 else {
2891 if(pMgmt->byDTIMCount == 0) {
2892
2893 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2894 pMgmt->sNodeDBTable[0].bRxPSPoll = TRUE;
2895 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2896 }
2897 }
2898 }
2899 pDevice->bBeaconSent = TRUE;
2900
2901 if (pDevice->bChannelSwitch == TRUE) {
2902 pDevice->byChannelSwitchCount--;
2903 if (pDevice->byChannelSwitchCount == 0) {
2904 pDevice->bChannelSwitch = FALSE;
2905 CARDbSetChannel(pDevice, pDevice->byNewChannel);
2906 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2907 MACvSelectPage1(pDevice->PortOffset);
2908 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2909 MACvSelectPage0(pDevice->PortOffset);
2910
2911 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2912 }
2913 }
2914
2915 }
2916
2917 if (pDevice->dwIsr & ISR_RXDMA0) {
2918 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2919 }
2920 if (pDevice->dwIsr & ISR_RXDMA1) {
2921 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2922 }
2923 if (pDevice->dwIsr & ISR_TXDMA0){
2924 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2925 }
2926 if (pDevice->dwIsr & ISR_AC0DMA){
2927 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2928 }
2929 if (pDevice->dwIsr & ISR_SOFTTIMER) {
2930
2931 }
2932 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2933 if (pDevice->eOPMode == OP_MODE_AP) {
2934 if (pDevice->bShortSlotTime)
2935 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2936 else
2937 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2938 }
2939 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2940 pDevice->byCntMeasure = 0;
2941 }
2942
2943 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2944
2945 MACvReceive0(pDevice->PortOffset);
2946 MACvReceive1(pDevice->PortOffset);
2947
2948 if (max_count>pDevice->sOpts.int_works)
2949 break;
2950 }
2951
2952 if (byOrgPageSel == 1) {
2953 MACvSelectPage1(pDevice->PortOffset);
2954 }
2955
2956 spin_unlock_irq(&pDevice->lock);
2957 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2958
2959 return IRQ_RETVAL(handled);
2960}
2961
2962
2963static unsigned const ethernet_polynomial = 0x04c11db7U;
2964static inline u32 ether_crc(int length, unsigned char *data)
2965{
2966 int crc = -1;
2967
2968 while(--length >= 0) {
2969 unsigned char current_octet = *data++;
2970 int bit;
2971 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
2972 crc = (crc << 1) ^
2973 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
2974 }
2975 }
2976 return crc;
2977}
2978
2979
2980static int Config_FileGetParameter(UCHAR *string, UCHAR *dest,UCHAR *source)
2981{
2982 UCHAR buf1[100];
2983 int source_len = strlen(source);
2984
2985 memset(buf1,0,100);
2986 strcat(buf1, string);
2987 strcat(buf1, "=");
2988 source+=strlen(buf1);
2989
2990 memcpy(dest,source,source_len-strlen(buf1));
2991 return TRUE;
2992}
2993
2994int Config_FileOperation(PSDevice pDevice,BOOL fwrite,unsigned char *Parameter) {
2995 UCHAR *config_path=CONFIG_PATH;
2996 UCHAR *buffer=NULL;
2997 UCHAR tmpbuffer[20];
2998 struct file *filp=NULL;
2999 mm_segment_t old_fs = get_fs();
3000
3001 int result=0;
3002
3003 set_fs (KERNEL_DS);
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014 filp = filp_open(config_path, O_RDWR, 0);
3015 if (IS_ERR(filp)) {
3016 printk("Config_FileOperation:open file fail?\n");
3017 result=-1;
3018 goto error2;
3019 }
3020
3021 if(!(filp->f_op) || !(filp->f_op->read) ||!(filp->f_op->write)) {
3022 printk("file %s cann't readable or writable?\n",config_path);
3023 result = -1;
3024 goto error1;
3025 }
3026
3027buffer = (UCHAR *)kmalloc(1024, GFP_KERNEL);
3028if(buffer==NULL) {
3029 printk("alllocate mem for file fail?\n");
3030 result = -1;
3031 goto error1;
3032}
3033
3034if(filp->f_op->read(filp, buffer, 1024, &filp->f_pos)<0) {
3035 printk("read file error?\n");
3036 result = -1;
3037 goto error1;
3038}
3039
3040if(Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=TRUE) {
3041 printk("get parameter error?\n");
3042 result = -1;
3043 goto error1;
3044}
3045
3046if(memcmp(tmpbuffer,"USA",3)==0) {
3047 result=ZoneType_USA;
3048}
3049else if(memcmp(tmpbuffer,"JAPAN",5)==0) {
3050 result=ZoneType_Japan;
3051}
3052else if(memcmp(tmpbuffer,"EUROPE",5)==0) {
3053 result=ZoneType_Europe;
3054}
3055else {
3056 result = -1;
3057 printk("Unknown Zonetype[%s]?\n",tmpbuffer);
3058}
3059
3060error1:
3061 if(buffer)
3062 kfree(buffer);
3063
3064 if(filp_close(filp,NULL))
3065 printk("Config_FileOperation:close file fail\n");
3066
3067error2:
3068 set_fs (old_fs);
3069
3070
3071
3072
3073
3074
3075 return result;
3076}
3077
3078
3079
3080static void device_set_multi(struct net_device *dev) {
3081 PSDevice pDevice = (PSDevice) netdev_priv(dev);
3082
3083 PSMgmtObject pMgmt = pDevice->pMgmt;
3084 u32 mc_filter[2];
3085 int i;
3086 struct dev_mc_list *mclist;
3087
3088
3089 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
3090
3091 if (dev->flags & IFF_PROMISC) {
3092 DBG_PRT(MSG_LEVEL_ERR,KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
3093
3094 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
3095 }
3096 else if ((dev->mc_count > pDevice->multicast_limit)
3097 || (dev->flags & IFF_ALLMULTI)) {
3098 MACvSelectPage1(pDevice->PortOffset);
3099 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
3100 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
3101 MACvSelectPage0(pDevice->PortOffset);
3102 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3103 }
3104 else {
3105 memset(mc_filter, 0, sizeof(mc_filter));
3106 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
3107 i++, mclist = mclist->next) {
3108 int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26;
3109 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
3110 }
3111 MACvSelectPage1(pDevice->PortOffset);
3112 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
3113 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
3114 MACvSelectPage0(pDevice->PortOffset);
3115 pDevice->byRxMode &= ~(RCR_UNICAST);
3116 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3117 }
3118
3119 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3120
3121 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
3122 pDevice->byRxMode &= ~(RCR_UNICAST);
3123 }
3124
3125 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
3126 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode );
3127}
3128
3129
3130static struct net_device_stats *device_get_stats(struct net_device *dev) {
3131 PSDevice pDevice=(PSDevice) netdev_priv(dev);
3132
3133 return &pDevice->stats;
3134}
3135
3136
3137
3138static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) {
3139 PSDevice pDevice = (PSDevice)netdev_priv(dev);
3140
3141 struct iwreq *wrq = (struct iwreq *) rq;
3142 int rc =0;
3143 PSMgmtObject pMgmt = pDevice->pMgmt;
3144 PSCmdRequest pReq;
3145
3146
3147 if (pMgmt == NULL) {
3148 rc = -EFAULT;
3149 return rc;
3150 }
3151
3152 switch(cmd) {
3153
3154 case SIOCGIWNAME:
3155 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
3156 break;
3157
3158 case SIOCGIWNWID:
3159 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3160 rc = iwctl_giwnwid(dev, NULL, &(wrq->u.nwid), NULL);
3161 #else
3162 rc = -EOPNOTSUPP;
3163 #endif
3164 break;
3165
3166
3167 case SIOCSIWFREQ:
3168 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
3169 break;
3170
3171
3172 case SIOCGIWFREQ:
3173 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
3174 break;
3175
3176
3177 case SIOCSIWESSID:
3178
3179 {
3180 char essid[IW_ESSID_MAX_SIZE+1];
3181 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
3182 rc = -E2BIG;
3183 break;
3184 }
3185 if (copy_from_user(essid, wrq->u.essid.pointer,
3186 wrq->u.essid.length)) {
3187 rc = -EFAULT;
3188 break;
3189 }
3190 rc = iwctl_siwessid(dev, NULL,
3191 &(wrq->u.essid), essid);
3192 }
3193 break;
3194
3195
3196
3197 case SIOCGIWESSID:
3198
3199 {
3200 char essid[IW_ESSID_MAX_SIZE+1];
3201 if (wrq->u.essid.pointer)
3202 rc = iwctl_giwessid(dev, NULL,
3203 &(wrq->u.essid), essid);
3204 if (copy_to_user(wrq->u.essid.pointer,
3205 essid,
3206 wrq->u.essid.length) )
3207 rc = -EFAULT;
3208 }
3209 break;
3210
3211 case SIOCSIWAP:
3212
3213 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3214 break;
3215
3216
3217
3218 case SIOCGIWAP:
3219 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
3220 break;
3221
3222
3223
3224 case SIOCSIWNICKN:
3225 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN \n");
3226 rc = -EOPNOTSUPP;
3227 break;
3228
3229
3230 case SIOCGIWNICKN:
3231 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN \n");
3232 rc = -EOPNOTSUPP;
3233 break;
3234
3235
3236 case SIOCSIWRATE:
3237 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3238 break;
3239
3240
3241 case SIOCGIWRATE:
3242
3243 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
3244 break;
3245
3246
3247 case SIOCSIWRTS:
3248
3249 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
3250 break;
3251
3252
3253 case SIOCGIWRTS:
3254
3255 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
3256 break;
3257
3258
3259 case SIOCSIWFRAG:
3260
3261 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
3262 break;
3263
3264
3265 case SIOCGIWFRAG:
3266
3267 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
3268 break;
3269
3270
3271 case SIOCSIWMODE:
3272 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
3273 break;
3274
3275
3276 case SIOCGIWMODE:
3277 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
3278 break;
3279
3280
3281 case SIOCSIWENCODE:
3282 {
3283 char abyKey[WLAN_WEP232_KEYLEN];
3284
3285 if (wrq->u.encoding.pointer) {
3286
3287
3288 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
3289 rc = -E2BIG;
3290 break;
3291 }
3292 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
3293 if (copy_from_user(abyKey,
3294 wrq->u.encoding.pointer,
3295 wrq->u.encoding.length)) {
3296 rc = -EFAULT;
3297 break;
3298 }
3299 } else if (wrq->u.encoding.length != 0) {
3300 rc = -EINVAL;
3301 break;
3302 }
3303 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3304 }
3305 break;
3306
3307
3308 case SIOCGIWENCODE:
3309
3310 if (!capable(CAP_NET_ADMIN)) {
3311 rc = -EPERM;
3312 break;
3313 }
3314 {
3315 char abyKey[WLAN_WEP232_KEYLEN];
3316
3317 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
3318 if (rc != 0) break;
3319 if (wrq->u.encoding.pointer) {
3320 if (copy_to_user(wrq->u.encoding.pointer,
3321 abyKey,
3322 wrq->u.encoding.length))
3323 rc = -EFAULT;
3324 }
3325 }
3326 break;
3327
3328
3329 case SIOCGIWTXPOW:
3330 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3331 rc = -EOPNOTSUPP;
3332 break;
3333
3334 case SIOCSIWTXPOW:
3335 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW \n");
3336 rc = -EOPNOTSUPP;
3337 break;
3338
3339 case SIOCSIWRETRY:
3340
3341 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
3342 break;
3343
3344 case SIOCGIWRETRY:
3345
3346 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
3347 break;
3348
3349
3350 case SIOCGIWRANGE:
3351
3352 {
3353 struct iw_range range;
3354
3355 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *) &range);
3356 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
3357 rc = -EFAULT;
3358 }
3359
3360 break;
3361
3362 case SIOCGIWPOWER:
3363
3364 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
3365 break;
3366
3367
3368 case SIOCSIWPOWER:
3369
3370 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
3371 break;
3372
3373
3374 case SIOCGIWSENS:
3375
3376 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
3377 break;
3378
3379 case SIOCSIWSENS:
3380 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS \n");
3381 rc = -EOPNOTSUPP;
3382 break;
3383
3384 case SIOCGIWAPLIST:
3385 {
3386 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
3387
3388 if (wrq->u.data.pointer) {
3389 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
3390 if (rc == 0) {
3391 if (copy_to_user(wrq->u.data.pointer,
3392 buffer,
3393 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
3394 ))
3395 rc = -EFAULT;
3396 }
3397 }
3398 }
3399 break;
3400
3401
3402#ifdef WIRELESS_SPY
3403
3404 case SIOCSIWSPY:
3405
3406 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3407 rc = -EOPNOTSUPP;
3408 break;
3409
3410
3411 case SIOCGIWSPY:
3412
3413 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY \n");
3414 rc = -EOPNOTSUPP;
3415 break;
3416
3417#endif
3418
3419 case SIOCGIWPRIV:
3420 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV \n");
3421 rc = -EOPNOTSUPP;
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432 break;
3433
3434
3435
3436#ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3437 case SIOCSIWAUTH:
3438 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH \n");
3439 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
3440 break;
3441
3442 case SIOCGIWAUTH:
3443 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH \n");
3444 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
3445 break;
3446
3447 case SIOCSIWGENIE:
3448 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE \n");
3449 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3450 break;
3451
3452 case SIOCGIWGENIE:
3453 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE \n");
3454 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3455 break;
3456
3457 case SIOCSIWENCODEEXT:
3458 {
3459 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
3460 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT \n");
3461 if(wrq->u.encoding.pointer){
3462 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1);
3463 if(wrq->u.encoding.length > (sizeof(struct iw_encode_ext)+ MAX_KEY_LEN)){
3464 rc = -E2BIG;
3465 break;
3466 }
3467 if(copy_from_user(extra, wrq->u.encoding.pointer,wrq->u.encoding.length)){
3468 rc = -EFAULT;
3469 break;
3470 }
3471 }else if(wrq->u.encoding.length != 0){
3472 rc = -EINVAL;
3473 break;
3474 }
3475 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
3476 }
3477 break;
3478
3479 case SIOCGIWENCODEEXT:
3480 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT \n");
3481 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
3482 break;
3483
3484 case SIOCSIWMLME:
3485 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME \n");
3486 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3487 break;
3488
3489#endif
3490
3491
3492 case IOCTL_CMD_TEST:
3493
3494 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
3495 rc = -EFAULT;
3496 break;
3497 } else {
3498 rc = 0;
3499 }
3500 pReq = (PSCmdRequest)rq;
3501 pReq->wResult = MAGIC_CODE;
3502 break;
3503
3504 case IOCTL_CMD_SET:
3505
3506 #ifdef SndEvt_ToAPI
3507 if((((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_EVT) &&
3508 !(pDevice->flags & DEVICE_FLAGS_OPENED))
3509 #else
3510 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
3511 (((PSCmdRequest)rq)->wCmdCode !=WLAN_CMD_SET_WPA))
3512 #endif
3513 {
3514 rc = -EFAULT;
3515 break;
3516 } else {
3517 rc = 0;
3518 }
3519
3520 if (test_and_set_bit( 0, (void*)&(pMgmt->uCmdBusy))) {
3521 return -EBUSY;
3522 }
3523 rc = private_ioctl(pDevice, rq);
3524 clear_bit( 0, (void*)&(pMgmt->uCmdBusy));
3525 break;
3526
3527 case IOCTL_CMD_HOSTAPD:
3528
3529
3530 rc = hostap_ioctl(pDevice, &wrq->u.data);
3531 break;
3532
3533 case IOCTL_CMD_WPA:
3534
3535 rc = wpa_ioctl(pDevice, &wrq->u.data);
3536 break;
3537
3538 case SIOCETHTOOL:
3539 return ethtool_ioctl(dev, (void *) rq->ifr_data);
3540
3541
3542 default:
3543 rc = -EOPNOTSUPP;
3544 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
3545
3546
3547 }
3548
3549 if (pDevice->bCommit) {
3550 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3551 netif_stop_queue(pDevice->dev);
3552 spin_lock_irq(&pDevice->lock);
3553 bScheduleCommand((HANDLE)pDevice, WLAN_CMD_RUN_AP, NULL);
3554 spin_unlock_irq(&pDevice->lock);
3555 }
3556 else {
3557 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
3558 spin_lock_irq(&pDevice->lock);
3559 pDevice->bLinkPass = FALSE;
3560 memset(pMgmt->abyCurrBSSID, 0, 6);
3561 pMgmt->eCurrState = WMAC_STATE_IDLE;
3562 netif_stop_queue(pDevice->dev);
3563 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3564 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
3565 if(pDevice->bWPASuppWextEnabled !=TRUE)
3566 #endif
3567 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
3568 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3569 spin_unlock_irq(&pDevice->lock);
3570 }
3571 pDevice->bCommit = FALSE;
3572 }
3573
3574 return rc;
3575}
3576
3577
3578static int ethtool_ioctl(struct net_device *dev, void *useraddr)
3579{
3580 u32 ethcmd;
3581
3582 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
3583 return -EFAULT;
3584
3585 switch (ethcmd) {
3586 case ETHTOOL_GDRVINFO: {
3587 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3588 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3589 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3590 if (copy_to_user(useraddr, &info, sizeof(info)))
3591 return -EFAULT;
3592 return 0;
3593 }
3594
3595 }
3596
3597 return -EOPNOTSUPP;
3598}
3599
3600
3601
3602MODULE_DEVICE_TABLE(pci, device_id_table);
3603
3604static struct pci_driver device_driver = {
3605 name: DEVICE_NAME,
3606 id_table: device_id_table,
3607 probe: device_found1,
3608 remove: device_remove1,
3609#ifdef CONFIG_PM
3610 suspend: viawget_suspend,
3611 resume: viawget_resume,
3612#endif
3613};
3614
3615static int __init device_init_module(void)
3616{
3617 int ret;
3618
3619
3620
3621
3622 ret = pci_register_driver(&device_driver);
3623#ifdef CONFIG_PM
3624 if(ret >= 0)
3625 register_reboot_notifier(&device_notifier);
3626#endif
3627
3628 return ret;
3629}
3630
3631static void __exit device_cleanup_module(void)
3632{
3633
3634
3635#ifdef CONFIG_PM
3636 unregister_reboot_notifier(&device_notifier);
3637#endif
3638 pci_unregister_driver(&device_driver);
3639
3640}
3641
3642module_init(device_init_module);
3643module_exit(device_cleanup_module);
3644
3645
3646#ifdef CONFIG_PM
3647static int
3648device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3649{
3650 struct pci_dev *pdev = NULL;
3651 switch(event) {
3652 case SYS_DOWN:
3653 case SYS_HALT:
3654 case SYS_POWER_OFF:
3655 while ((pdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) {
3656 if(pci_dev_driver(pdev) == &device_driver) {
3657 if (pci_get_drvdata(pdev))
3658 viawget_suspend(pdev, PMSG_HIBERNATE);
3659 }
3660 }
3661 }
3662 return NOTIFY_DONE;
3663}
3664
3665static int
3666viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3667{
3668 int power_status;
3669
3670 PSDevice pDevice=pci_get_drvdata(pcid);
3671 PSMgmtObject pMgmt = pDevice->pMgmt;
3672
3673 netif_stop_queue(pDevice->dev);
3674 spin_lock_irq(&pDevice->lock);
3675 pci_save_state(pcid);
3676 del_timer(&pDevice->sTimerCommand);
3677 del_timer(&pMgmt->sTimerSecondCallback);
3678 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3679 pDevice->uCmdDequeueIdx = 0;
3680 pDevice->uCmdEnqueueIdx = 0;
3681 pDevice->bCmdRunning = FALSE;
3682 MACbShutdown(pDevice->PortOffset);
3683 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3684 pDevice->bLinkPass = FALSE;
3685 memset(pMgmt->abyCurrBSSID, 0, 6);
3686 pMgmt->eCurrState = WMAC_STATE_IDLE;
3687 pci_disable_device(pcid);
3688 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3689 spin_unlock_irq(&pDevice->lock);
3690 return 0;
3691}
3692
3693static int
3694viawget_resume(struct pci_dev *pcid)
3695{
3696 PSDevice pDevice=pci_get_drvdata(pcid);
3697 PSMgmtObject pMgmt = pDevice->pMgmt;
3698 int power_status;
3699
3700
3701 power_status = pci_set_power_state(pcid, 0);
3702 power_status = pci_enable_wake(pcid, 0, 0);
3703 pci_restore_state(pcid);
3704 if (netif_running(pDevice->dev)) {
3705 spin_lock_irq(&pDevice->lock);
3706 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3707 device_init_registers(pDevice, DEVICE_INIT_DXPL);
3708 if (pMgmt->sNodeDBTable[0].bActive == TRUE) {
3709 pMgmt->sNodeDBTable[0].bActive = FALSE;
3710 pDevice->bLinkPass = FALSE;
3711 if(pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3712
3713 pMgmt->eCurrState = WMAC_STATE_STARTED;
3714 }
3715 else {
3716 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3717 pMgmt->eCurrState = WMAC_STATE_IDLE;
3718 }
3719 }
3720 init_timer(&pMgmt->sTimerSecondCallback);
3721 init_timer(&pDevice->sTimerCommand);
3722 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3723 BSSvClearBSSList((HANDLE)pDevice, pDevice->bLinkPass);
3724 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3725 bScheduleCommand((HANDLE) pDevice, WLAN_CMD_SSID, NULL);
3726 spin_unlock_irq(&pDevice->lock);
3727 }
3728 return 0;
3729}
3730
3731#endif
3732
3733
3734
3735
3736