2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: driver entry for initial, open, close, tx and rx.
29 * vt6655_probe - module initial (insmod) driver entry
30 * vt6655_remove - module remove entry
31 * vt6655_init_info - device structure resource allocation function
32 * device_free_info - device structure resource free function
33 * device_get_pci_info - get allocated pci io/mem resource
34 * device_print_info - print out resource
35 * device_open - allocate dma/descripter resource & initial mac/bbp function
36 * device_xmit - asynchrous data tx function
37 * device_intr - interrupt handle function
38 * device_set_multi - set mac filter
39 * device_ioctl - ioctl entry
40 * device_close - shutdown mac/bbp & free dma/descripter resource
41 * device_rx_srv - rx service function
42 * device_receive_frame - rx data function
43 * device_alloc_rx_buf - rx buffer pre-allocated function
44 * device_alloc_frag_buf - rx fragement pre-allocated function
45 * device_free_tx_buf - free tx buffer function
46 * device_free_frag_buf- free de-fragement buffer
47 * device_dma0_tx_80211- tx 802.11 frame via dma0
48 * device_dma0_xmit- tx PS bufferred frame via dma0
49 * device_init_rd0_ring- initial rd dma0 ring
50 * device_init_rd1_ring- initial rd dma1 ring
51 * device_init_td0_ring- initial tx dma0 ring buffer
52 * device_init_td1_ring- initial tx dma1 ring buffer
53 * device_init_registers- initial MAC & BBP & RF internal registers.
54 * device_init_rings- initial tx/rx ring buffer
55 * device_init_defrag_cb- initial & allocate de-fragement buffer.
56 * device_free_rings- free all allocated ring buffer
57 * device_tx_srv- tx interrupt service function
63 #include <linux/file.h>
87 #include <linux/delay.h>
88 #include <linux/kthread.h>
89 #include <linux/slab.h>
91 /*--------------------- Static Definitions -------------------------*/
92 static int msglevel = MSG_LEVEL_INFO;
95 // Define module options
97 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
98 MODULE_LICENSE("GPL");
99 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
101 #define DEVICE_PARAM(N, D)
103 #define RX_DESC_MIN0 16
104 #define RX_DESC_MAX0 128
105 #define RX_DESC_DEF0 32
106 DEVICE_PARAM(RxDescriptors0, "Number of receive descriptors0");
108 #define RX_DESC_MIN1 16
109 #define RX_DESC_MAX1 128
110 #define RX_DESC_DEF1 32
111 DEVICE_PARAM(RxDescriptors1, "Number of receive descriptors1");
113 #define TX_DESC_MIN0 16
114 #define TX_DESC_MAX0 128
115 #define TX_DESC_DEF0 32
116 DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
118 #define TX_DESC_MIN1 16
119 #define TX_DESC_MAX1 128
120 #define TX_DESC_DEF1 64
121 DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
123 #define IP_ALIG_DEF 0
124 /* IP_byte_align[] is used for IP header unsigned long byte aligned
125 0: indicate the IP header won't be unsigned long byte aligned.(Default) .
126 1: indicate the IP header will be unsigned long byte aligned.
127 In some environment, the IP header should be unsigned long byte aligned,
128 or the packet will be droped when we receive it. (eg: IPVS)
130 DEVICE_PARAM(IP_byte_align, "Enable IP header dword aligned");
132 #define INT_WORKS_DEF 20
133 #define INT_WORKS_MIN 10
134 #define INT_WORKS_MAX 64
136 DEVICE_PARAM(int_works, "Number of packets per interrupt services");
138 #define CHANNEL_MIN 1
139 #define CHANNEL_MAX 14
140 #define CHANNEL_DEF 6
142 DEVICE_PARAM(Channel, "Channel number");
144 /* PreambleType[] is the preamble length used for transmit.
145 0: indicate allows long preamble type
146 1: indicate allows short preamble type
149 #define PREAMBLE_TYPE_DEF 1
151 DEVICE_PARAM(PreambleType, "Preamble Type");
153 #define RTS_THRESH_MIN 512
154 #define RTS_THRESH_MAX 2347
155 #define RTS_THRESH_DEF 2347
157 DEVICE_PARAM(RTSThreshold, "RTS threshold");
159 #define FRAG_THRESH_MIN 256
160 #define FRAG_THRESH_MAX 2346
161 #define FRAG_THRESH_DEF 2346
163 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
165 #define DATA_RATE_MIN 0
166 #define DATA_RATE_MAX 13
167 #define DATA_RATE_DEF 13
169 0: indicate 1 Mbps 0x02
170 1: indicate 2 Mbps 0x04
171 2: indicate 5.5 Mbps 0x0B
172 3: indicate 11 Mbps 0x16
173 4: indicate 6 Mbps 0x0c
174 5: indicate 9 Mbps 0x12
175 6: indicate 12 Mbps 0x18
176 7: indicate 18 Mbps 0x24
177 8: indicate 24 Mbps 0x30
178 9: indicate 36 Mbps 0x48
179 10: indicate 48 Mbps 0x60
180 11: indicate 54 Mbps 0x6c
181 12: indicate 72 Mbps 0x90
182 13: indicate auto rate
185 DEVICE_PARAM(ConnectionRate, "Connection data rate");
187 #define OP_MODE_DEF 0
189 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
191 /* OpMode[] is used for transmit.
192 0: indicate infrastruct mode used
193 1: indicate adhoc mode used
194 2: indicate AP mode used
198 0: indicate disable power saving mode
199 1: indicate enable power saving mode
202 #define PS_MODE_DEF 0
204 DEVICE_PARAM(PSMode, "Power saving mode");
206 #define SHORT_RETRY_MIN 0
207 #define SHORT_RETRY_MAX 31
208 #define SHORT_RETRY_DEF 8
210 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
212 #define LONG_RETRY_MIN 0
213 #define LONG_RETRY_MAX 15
214 #define LONG_RETRY_DEF 4
216 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
218 /* BasebandType[] baseband type selected
219 0: indicate 802.11a type
220 1: indicate 802.11b type
221 2: indicate 802.11g type
223 #define BBP_TYPE_MIN 0
224 #define BBP_TYPE_MAX 2
225 #define BBP_TYPE_DEF 2
227 DEVICE_PARAM(BasebandType, "baseband type");
230 0: indicate disable 802.11h
231 1: indicate enable 802.11h
234 #define X80211h_MODE_DEF 0
236 DEVICE_PARAM(b80211hEnable, "802.11h mode");
239 0: indicate disable 802.11h
240 1: indicate enable 802.11h
243 #define DIVERSITY_ANT_DEF 0
245 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
248 // Static vars definitions
251 static int device_nics = 0;
252 static PSDevice pDevice_Infos = NULL;
253 static struct net_device *root_device_dev = NULL;
255 static CHIP_INFO chip_info_table[] = {
256 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
257 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
261 static const struct pci_device_id vt6655_pci_id_table[] = {
262 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
266 /*--------------------- Static Functions --------------------------*/
268 static int vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent);
269 static void vt6655_init_info(struct pci_dev *pcid, PSDevice *ppDevice, PCHIP_INFO);
270 static void device_free_info(PSDevice pDevice);
271 static bool device_get_pci_info(PSDevice, struct pci_dev *pcid);
272 static void device_print_info(PSDevice pDevice);
273 static struct net_device_stats *device_get_stats(struct net_device *dev);
274 static void device_init_diversity_timer(PSDevice pDevice);
275 static int device_open(struct net_device *dev);
276 static int device_xmit(struct sk_buff *skb, struct net_device *dev);
277 static irqreturn_t device_intr(int irq, void *dev_instance);
278 static void device_set_multi(struct net_device *dev);
279 static int device_close(struct net_device *dev);
280 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
283 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
284 static int viawget_suspend(struct pci_dev *pcid, pm_message_t state);
285 static int viawget_resume(struct pci_dev *pcid);
286 static struct notifier_block device_notifier = {
287 .notifier_call = device_notify_reboot,
293 static void device_init_rd0_ring(PSDevice pDevice);
294 static void device_init_rd1_ring(PSDevice pDevice);
295 static void device_init_defrag_cb(PSDevice pDevice);
296 static void device_init_td0_ring(PSDevice pDevice);
297 static void device_init_td1_ring(PSDevice pDevice);
299 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
300 //2008-0714<Add>by Mike Liu
301 static bool device_release_WPADEV(PSDevice pDevice);
303 static int ethtool_ioctl(struct net_device *dev, void __user *useraddr);
304 static int device_rx_srv(PSDevice pDevice, unsigned int uIdx);
305 static int device_tx_srv(PSDevice pDevice, unsigned int uIdx);
306 static bool device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pDesc);
307 static void device_init_registers(PSDevice pDevice);
308 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc);
309 static void device_free_td0_ring(PSDevice pDevice);
310 static void device_free_td1_ring(PSDevice pDevice);
311 static void device_free_rd0_ring(PSDevice pDevice);
312 static void device_free_rd1_ring(PSDevice pDevice);
313 static void device_free_rings(PSDevice pDevice);
314 static void device_free_frag_buf(PSDevice pDevice);
315 static int Config_FileGetParameter(unsigned char *string,
316 unsigned char *dest, unsigned char *source);
318 /*--------------------- Export Variables --------------------------*/
320 /*--------------------- Export Functions --------------------------*/
322 static char *get_chip_name(int chip_id)
326 for (i = 0; chip_info_table[i].name != NULL; i++)
327 if (chip_info_table[i].chip_id == chip_id)
329 return chip_info_table[i].name;
332 static void vt6655_remove(struct pci_dev *pcid)
334 PSDevice pDevice = pci_get_drvdata(pcid);
338 device_free_info(pDevice);
341 static void device_get_options(PSDevice pDevice, int index, char *devname)
343 POPTIONS pOpts = &(pDevice->sOpts);
345 pOpts->nRxDescs0 = RX_DESC_DEF0;
346 pOpts->nRxDescs1 = RX_DESC_DEF1;
347 pOpts->nTxDescs[0] = TX_DESC_DEF0;
348 pOpts->nTxDescs[1] = TX_DESC_DEF1;
349 pOpts->flags |= DEVICE_FLAGS_IP_ALIGN;
350 pOpts->int_works = INT_WORKS_DEF;
351 pOpts->rts_thresh = RTS_THRESH_DEF;
352 pOpts->frag_thresh = FRAG_THRESH_DEF;
353 pOpts->data_rate = DATA_RATE_DEF;
354 pOpts->channel_num = CHANNEL_DEF;
356 pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE;
357 pOpts->flags |= DEVICE_FLAGS_OP_MODE;
358 pOpts->short_retry = SHORT_RETRY_DEF;
359 pOpts->long_retry = LONG_RETRY_DEF;
360 pOpts->bbp_type = BBP_TYPE_DEF;
361 pOpts->flags |= DEVICE_FLAGS_80211h_MODE;
362 pOpts->flags |= DEVICE_FLAGS_DiversityANT;
366 device_set_options(PSDevice pDevice) {
367 unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
368 unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
369 unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
371 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
372 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
373 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
375 pDevice->uChannel = pDevice->sOpts.channel_num;
376 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
377 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
378 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
379 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
380 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
381 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
382 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
383 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
384 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
385 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
386 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
387 if (pDevice->uConnectionRate < RATE_AUTO)
388 pDevice->bFixRate = true;
389 pDevice->byBBType = pDevice->sOpts.bbp_type;
390 pDevice->byPacketType = pDevice->byBBType;
393 pDevice->byAutoFBCtrl = AUTO_FB_0;
395 pDevice->bUpdateBBVGA = true;
396 pDevice->byFOETuning = 0;
397 pDevice->wCTSDuration = 0;
398 pDevice->byPreambleType = 0;
400 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " uChannel= %d\n", (int)pDevice->uChannel);
401 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byOpMode= %d\n", (int)pDevice->byOpMode);
402 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ePSMode= %d\n", (int)pDevice->ePSMode);
403 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
404 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
405 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
406 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byPreambleType= %d\n", (int)pDevice->byPreambleType);
407 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
409 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " byBBType= %d\n", (int)pDevice->byBBType);
410 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " pDevice->bDiversityRegCtlON= %d\n", (int)pDevice->bDiversityRegCtlON);
414 static void s_vCompleteCurrentMeasure(PSDevice pDevice, unsigned char byResult)
417 unsigned long dwDuration = 0;
418 unsigned char byRPI0 = 0;
420 for (ii = 1; ii < 8; ii++) {
421 pDevice->dwRPIs[ii] *= 255;
422 dwDuration |= *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
424 pDevice->dwRPIs[ii] /= dwDuration;
425 pDevice->abyRPIs[ii] = (unsigned char)pDevice->dwRPIs[ii];
426 byRPI0 += pDevice->abyRPIs[ii];
428 pDevice->abyRPIs[0] = (0xFF - byRPI0);
430 if (pDevice->uNumOfMeasureEIDs == 0) {
431 VNTWIFIbMeasureReport(pDevice->pMgmt,
433 pDevice->pCurrMeasureEID,
436 pDevice->byCCAFraction,
440 VNTWIFIbMeasureReport(pDevice->pMgmt,
442 pDevice->pCurrMeasureEID,
445 pDevice->byCCAFraction,
448 CARDbStartMeasure(pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
453 // Initialisation of MAC & BBP registers
456 static void device_init_registers(PSDevice pDevice)
459 unsigned char byValue;
460 unsigned char byValue1;
461 unsigned char byCCKPwrdBm = 0;
462 unsigned char byOFDMPwrdBm = 0;
464 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
466 MACbShutdown(pDevice->PortOffset);
467 BBvSoftwareReset(pDevice->PortOffset);
469 /* Do MACbSoftwareReset in MACvInitialize */
470 MACbSoftwareReset(pDevice->PortOffset);
473 pDevice->bCCK = true;
474 pDevice->bAES = false;
476 /* Only used in 11g type, sync with ERP IE */
477 pDevice->bProtectMode = false;
479 pDevice->bNonERPPresent = false;
480 pDevice->bBarkerPreambleMd = false;
481 pDevice->wCurrentRate = RATE_1M;
482 pDevice->byTopOFDMBasicRate = RATE_24M;
483 pDevice->byTopCCKBasicRate = RATE_1M;
485 /* Target to IF pin while programming to RF chip. */
486 pDevice->byRevId = 0;
489 MACvInitialize(pDevice->PortOffset);
492 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
494 spin_lock_irq(&pDevice->lock);
496 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
498 spin_unlock_irq(&pDevice->lock);
500 /* Get Channel range */
501 pDevice->byMinChannel = 1;
502 pDevice->byMaxChannel = CB_MAX_CHANNEL;
505 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
506 if (byValue & EEP_ANTINV)
507 pDevice->bTxRxAntInv = true;
509 pDevice->bTxRxAntInv = false;
511 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
512 /* if not set default is All */
514 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
516 pDevice->ulDiversityNValue = 100*260;
517 pDevice->ulDiversityMValue = 100*16;
519 pDevice->byTMax2 = 4;
520 pDevice->ulSQ3TH = 0;
521 pDevice->byTMax3 = 64;
523 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
524 pDevice->byAntennaCount = 2;
525 pDevice->byTxAntennaMode = ANT_B;
526 pDevice->dwTxAntennaSel = 1;
527 pDevice->dwRxAntennaSel = 1;
529 if (pDevice->bTxRxAntInv)
530 pDevice->byRxAntennaMode = ANT_A;
532 pDevice->byRxAntennaMode = ANT_B;
534 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset,
537 if ((byValue1 & 0x08) == 0)
538 pDevice->bDiversityEnable = false;
540 pDevice->bDiversityEnable = true;
542 pDevice->bDiversityEnable = false;
543 pDevice->byAntennaCount = 1;
544 pDevice->dwTxAntennaSel = 0;
545 pDevice->dwRxAntennaSel = 0;
547 if (byValue & EEP_ANTENNA_AUX) {
548 pDevice->byTxAntennaMode = ANT_A;
550 if (pDevice->bTxRxAntInv)
551 pDevice->byRxAntennaMode = ANT_B;
553 pDevice->byRxAntennaMode = ANT_A;
555 pDevice->byTxAntennaMode = ANT_B;
557 if (pDevice->bTxRxAntInv)
558 pDevice->byRxAntennaMode = ANT_A;
560 pDevice->byRxAntennaMode = ANT_B;
564 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
565 "bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
566 pDevice->bDiversityEnable, (int)pDevice->ulDiversityNValue,
567 (int)pDevice->ulDiversityMValue, pDevice->byTMax, pDevice->byTMax2);
569 /* zonetype initial */
570 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
571 zonetype = Config_FileOperation(pDevice, false, NULL);
574 if ((zonetype == 0) &&
575 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x00)) {
577 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
578 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
580 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Init Zone Type :USA\n");
581 } else if ((zonetype == 1) &&
582 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x01)) {
584 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
585 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
586 } else if ((zonetype == 2) &&
587 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x02)) {
589 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
590 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
592 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Init Zone Type :Europe\n");
594 if (zonetype != pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
595 pr_debug("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",
597 pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
599 pr_debug("Read Zonetype file success,use default zonetype setting[%02x]\n",
603 pr_debug("Read Zonetype file fail,use default zonetype setting[%02x]\n",
604 SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
608 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
610 /* force change RevID for VT3253 emu */
611 if ((pDevice->byRFType & RF_EMU) != 0)
612 pDevice->byRevId = 0x80;
614 pDevice->byRFType &= RF_MASK;
615 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRFType = %x\n", pDevice->byRFType);
617 if (!pDevice->bZoneRegExist)
618 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
620 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byZoneType = %x\n", pDevice->byZoneType);
625 /* Get Desire Power Value */
626 pDevice->byCurPwr = 0xFF;
627 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
628 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
630 /* Load power Table */
631 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
632 pDevice->abyCCKPwrTbl[ii + 1] =
633 SROMbyReadEmbedded(pDevice->PortOffset,
634 (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
635 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
636 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
638 pDevice->abyOFDMPwrTbl[ii + 1] =
639 SROMbyReadEmbedded(pDevice->PortOffset,
640 (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
641 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
642 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
644 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
645 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
648 /* recover 12,13 ,14channel for EUROPE by 11 channel */
649 if (((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
650 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe)) &&
651 (pDevice->byOriginalZonetype == ZoneType_USA)) {
652 for (ii = 11; ii < 14; ii++) {
653 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
654 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
659 /* Load OFDM A Power Table */
660 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
661 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
662 SROMbyReadEmbedded(pDevice->PortOffset,
663 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
665 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
666 SROMbyReadEmbedded(pDevice->PortOffset,
667 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
670 init_channel_table((void *)pDevice);
672 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
673 MACvSelectPage1(pDevice->PortOffset);
675 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
676 (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
678 MACvSelectPage0(pDevice->PortOffset);
681 /* use relative tx timeout and 802.11i D4 */
682 MACvWordRegBitsOn(pDevice->PortOffset,
683 MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
685 /* set performance parameter by registry */
686 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
687 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
689 /* reset TSF counter */
690 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
691 /* enable TSF counter */
692 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
694 /* initialize BBP registers */
695 BBbVT3253Init(pDevice);
697 if (pDevice->bUpdateBBVGA) {
698 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
699 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
700 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
703 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
704 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
706 pDevice->byCurrentCh = 0;
708 /* Set BB and packet type at the same time. */
709 /* Set Short Slot Time, xIFS, and RSPINF. */
710 if (pDevice->uConnectionRate == RATE_AUTO)
711 pDevice->wCurrentRate = RATE_54M;
713 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
716 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
717 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
719 pDevice->bRadioOff = false;
721 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
723 pDevice->bHWRadioOff = false;
725 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
727 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
729 if (((pDevice->byGPIO & GPIO0_DATA) &&
730 !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
731 (!(pDevice->byGPIO & GPIO0_DATA) &&
732 (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
733 pDevice->bHWRadioOff = true;
736 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
737 CARDbRadioPowerOff(pDevice);
739 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
741 /* get Permanent network address */
742 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
743 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Network address = %pM\n",
744 pDevice->abyCurrentNetAddr);
746 /* reset Tx pointer */
747 CARDvSafeResetRx(pDevice);
748 /* reset Rx pointer */
749 CARDvSafeResetTx(pDevice);
751 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
752 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
754 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
757 MACvReceive0(pDevice->PortOffset);
758 MACvReceive1(pDevice->PortOffset);
760 /* start the adapter */
761 MACvStart(pDevice->PortOffset);
763 netif_stop_queue(pDevice->dev);
766 static void device_init_diversity_timer(PSDevice pDevice)
768 init_timer(&pDevice->TimerSQ3Tmax1);
769 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
770 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
771 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
773 init_timer(&pDevice->TimerSQ3Tmax2);
774 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
775 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
776 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
778 init_timer(&pDevice->TimerSQ3Tmax3);
779 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
780 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
781 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
784 static bool device_release_WPADEV(PSDevice pDevice)
786 viawget_wpa_header *wpahdr;
789 //send device close to wpa_supplicnat layer
790 if (pDevice->bWPADEVUp) {
791 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
792 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
793 wpahdr->resp_ie_len = 0;
794 wpahdr->req_ie_len = 0;
795 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
796 pDevice->skb->dev = pDevice->wpadev;
797 skb_reset_mac_header(pDevice->skb);
798 pDevice->skb->pkt_type = PACKET_HOST;
799 pDevice->skb->protocol = htons(ETH_P_802_2);
800 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
801 netif_rx(pDevice->skb);
802 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
804 while (pDevice->bWPADEVUp) {
805 set_current_state(TASK_UNINTERRUPTIBLE);
806 schedule_timeout(HZ / 20); //wait 50ms
815 static const struct net_device_ops device_netdev_ops = {
816 .ndo_open = device_open,
817 .ndo_stop = device_close,
818 .ndo_do_ioctl = device_ioctl,
819 .ndo_get_stats = device_get_stats,
820 .ndo_start_xmit = device_xmit,
821 .ndo_set_rx_mode = device_set_multi,
825 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
827 static bool bFirst = true;
828 struct net_device *dev = NULL;
829 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
833 if (device_nics++ >= MAX_UINTS) {
834 pr_notice(DEVICE_NAME ": already found %d NICs\n", device_nics);
838 dev = alloc_etherdev(sizeof(DEVICE_INFO));
840 pDevice = (PSDevice) netdev_priv(dev);
843 pr_err(DEVICE_NAME ": allocate net device failed\n");
847 // Chain it all together
848 SET_NETDEV_DEV(dev, &pcid->dev);
851 pr_notice("%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
852 pr_notice("Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
856 vt6655_init_info(pcid, &pDevice, pChip_info);
858 pDevice->next_module = root_device_dev;
859 root_device_dev = dev;
861 if (pci_enable_device(pcid)) {
862 device_free_info(pDevice);
865 dev->irq = pcid->irq;
868 pr_debug("Before get pci_info memaddr is %x\n", pDevice->memaddr);
870 if (!device_get_pci_info(pDevice, pcid)) {
871 pr_err(DEVICE_NAME ": Failed to find PCI device.\n");
872 device_free_info(pDevice);
880 pr_debug("after get pci_info memaddr is %x, io addr is %x,io_size is %d\n", pDevice->memaddr, pDevice->ioaddr, pDevice->io_size);
892 for (i = 0; address[i]; i++) {
893 pci_read_config_dword(pcid, address[i], &bar);
894 pr_debug("bar %d is %x\n", i, bar);
896 pr_debug("bar %d not implemented\n", i);
899 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
902 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
903 len = len & ~(len - 1);
905 pr_debug("IO space: len in IO %x, BAR %d\n", len, i);
907 len = bar & 0xFFFFFFF0;
910 pr_debug("len in MEM %x, BAR %d\n", len, i);
918 pDevice->PortOffset = ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
920 if (pDevice->PortOffset == NULL) {
921 pr_err(DEVICE_NAME ": Failed to IO remapping ..\n");
922 device_free_info(pDevice);
926 rc = pci_request_regions(pcid, DEVICE_NAME);
928 pr_err(DEVICE_NAME ": Failed to find PCI device\n");
929 device_free_info(pDevice);
933 dev->base_addr = pDevice->ioaddr;
937 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
938 pr_debug("Before write: value is %x\n", value);
939 VNSvOutPortB(pDevice->PortOffset, value);
940 VNSvInPortB(pDevice->PortOffset+0x4F, &value);
941 pr_debug("After write: value is %x\n", value);
944 if (!MACbSoftwareReset(pDevice->PortOffset)) {
945 pr_err(DEVICE_NAME ": Failed to access MAC hardware..\n");
946 device_free_info(pDevice);
949 // initial to reload eeprom
950 MACvInitialize(pDevice->PortOffset);
951 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
953 device_get_options(pDevice, device_nics-1, dev->name);
954 device_set_options(pDevice);
955 //Mask out the options cannot be set to the chip
956 pDevice->sOpts.flags &= pChip_info->flags;
958 //Enable the chip specified capabilities
959 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
960 pDevice->tx_80211 = device_dma0_tx_80211;
961 pDevice->sMgmtObj.pAdapter = (void *)pDevice;
962 pDevice->pMgmt = &(pDevice->sMgmtObj);
964 dev->irq = pcid->irq;
965 dev->netdev_ops = &device_netdev_ops;
967 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
969 rc = register_netdev(dev);
971 pr_err(DEVICE_NAME " Failed to register netdev\n");
972 device_free_info(pDevice);
975 device_print_info(pDevice);
976 pci_set_drvdata(pcid, pDevice);
980 static void device_print_info(PSDevice pDevice)
982 struct net_device *dev = pDevice->dev;
984 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: %s\n", dev->name, get_chip_name(pDevice->chip_id));
985 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: MAC=%pM", dev->name, dev->dev_addr);
987 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IO=0x%lx Mem=0x%lx ",
988 (unsigned long)pDevice->ioaddr, (unsigned long)pDevice->PortOffset);
989 DBG_PRT(MSG_LEVEL_INFO, KERN_INFO " IRQ=%d\n", pDevice->dev->irq);
992 static void vt6655_init_info(struct pci_dev *pcid, PSDevice *ppDevice,
993 PCHIP_INFO pChip_info) {
996 memset(*ppDevice, 0, sizeof(DEVICE_INFO));
998 if (pDevice_Infos == NULL) {
999 pDevice_Infos = *ppDevice;
1001 for (p = pDevice_Infos; p->next != NULL; p = p->next)
1003 p->next = *ppDevice;
1004 (*ppDevice)->prev = p;
1007 (*ppDevice)->pcid = pcid;
1008 (*ppDevice)->chip_id = pChip_info->chip_id;
1009 (*ppDevice)->io_size = pChip_info->io_size;
1010 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
1011 (*ppDevice)->multicast_limit = 32;
1013 spin_lock_init(&((*ppDevice)->lock));
1016 static bool device_get_pci_info(PSDevice pDevice, struct pci_dev *pcid)
1020 unsigned int cis_addr;
1022 unsigned char pci_config[256];
1023 unsigned char value = 0x00;
1025 u16 max_lat = 0x0000;
1027 memset(pci_config, 0x00, 256);
1030 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
1031 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
1032 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
1033 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
1035 pci_set_master(pcid);
1037 pDevice->memaddr = pci_resource_start(pcid, 0);
1038 pDevice->ioaddr = pci_resource_start(pcid, 1);
1040 cis_addr = pci_resource_start(pcid, 2);
1042 pDevice->pcid = pcid;
1044 pci_read_config_byte(pcid, PCI_COMMAND, &b);
1045 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
1048 for (ii = 0; ii < 0xFF; ii++) {
1049 pci_read_config_byte(pcid, ii, &value);
1050 pci_config[ii] = value;
1052 for (ii = 0, j = 1; ii < 0x100; ii++, j++) {
1054 pr_debug("%x:", pci_config[ii]);
1057 pr_debug("%x:", pci_config[ii]);
1064 static void device_free_info(PSDevice pDevice)
1067 struct net_device *dev = pDevice->dev;
1070 //2008-0714-01<Add>by chester
1071 device_release_WPADEV(pDevice);
1073 //2008-07-21-01<Add>by MikeLiu
1075 if (wpa_set_wpadev(pDevice, 0) != 0)
1076 pr_err("unregister wpadev fail?\n");
1078 if (pDevice_Infos == NULL)
1081 for (ptr = pDevice_Infos; ptr && (ptr != pDevice); ptr = ptr->next)
1084 if (ptr == pDevice) {
1085 if (ptr == pDevice_Infos)
1086 pDevice_Infos = ptr->next;
1088 ptr->prev->next = ptr->next;
1090 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "info struct not found\n");
1095 vt6655_hostap_set_hostapd(pDevice, 0, 0);
1098 unregister_netdev(dev);
1100 if (pDevice->PortOffset)
1101 iounmap(pDevice->PortOffset);
1104 pci_release_regions(pDevice->pcid);
1109 static bool device_init_rings(PSDevice pDevice)
1113 /*allocate all RD/TD rings a single pool*/
1114 vir_pool = pci_zalloc_consistent(pDevice->pcid,
1115 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1116 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1117 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1118 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1119 &pDevice->pool_dma);
1120 if (vir_pool == NULL) {
1121 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
1125 pDevice->aRD0Ring = vir_pool;
1126 pDevice->aRD1Ring = vir_pool +
1127 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1129 pDevice->rd0_pool_dma = pDevice->pool_dma;
1130 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1131 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1133 pDevice->tx0_bufs = pci_zalloc_consistent(pDevice->pcid,
1134 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1135 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1136 CB_BEACON_BUF_SIZE +
1138 &pDevice->tx_bufs_dma0);
1139 if (pDevice->tx0_bufs == NULL) {
1140 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
1141 pci_free_consistent(pDevice->pcid,
1142 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1143 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1144 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1145 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1146 vir_pool, pDevice->pool_dma
1151 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1152 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1154 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1155 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1157 // vir_pool: pvoid type
1158 pDevice->apTD0Rings = vir_pool
1159 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1160 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1162 pDevice->apTD1Rings = vir_pool
1163 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1164 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1165 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1167 pDevice->tx1_bufs = pDevice->tx0_bufs +
1168 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1170 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1171 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1173 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1176 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1177 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1179 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1180 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1185 static void device_free_rings(PSDevice pDevice)
1187 pci_free_consistent(pDevice->pcid,
1188 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1189 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1190 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1191 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1193 pDevice->aRD0Ring, pDevice->pool_dma
1196 if (pDevice->tx0_bufs)
1197 pci_free_consistent(pDevice->pcid,
1198 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1199 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1200 CB_BEACON_BUF_SIZE +
1202 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1206 static void device_init_rd0_ring(PSDevice pDevice)
1209 dma_addr_t curr = pDevice->rd0_pool_dma;
1212 /* Init the RD0 ring entries */
1213 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1214 pDesc = &(pDevice->aRD0Ring[i]);
1215 pDesc->pRDInfo = alloc_rd_info();
1216 ASSERT(pDesc->pRDInfo);
1217 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1218 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc rx bufs\n",
1219 pDevice->dev->name);
1221 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1222 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1223 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1227 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1228 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1231 static void device_init_rd1_ring(PSDevice pDevice)
1234 dma_addr_t curr = pDevice->rd1_pool_dma;
1237 /* Init the RD1 ring entries */
1238 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1239 pDesc = &(pDevice->aRD1Ring[i]);
1240 pDesc->pRDInfo = alloc_rd_info();
1241 ASSERT(pDesc->pRDInfo);
1242 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1243 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc rx bufs\n",
1244 pDevice->dev->name);
1246 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1247 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1248 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1252 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1253 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1256 static void device_init_defrag_cb(PSDevice pDevice)
1259 PSDeFragControlBlock pDeF;
1261 /* Init the fragment ctl entries */
1262 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1263 pDeF = &(pDevice->sRxDFCB[i]);
1264 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1265 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc frag bufs\n",
1266 pDevice->dev->name);
1269 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1270 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1273 static void device_free_rd0_ring(PSDevice pDevice)
1277 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1278 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
1279 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1281 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1282 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1284 dev_kfree_skb(pRDInfo->skb);
1286 kfree((void *)pDesc->pRDInfo);
1290 static void device_free_rd1_ring(PSDevice pDevice)
1294 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1295 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
1296 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1298 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1299 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1301 dev_kfree_skb(pRDInfo->skb);
1303 kfree((void *)pDesc->pRDInfo);
1307 static void device_free_frag_buf(PSDevice pDevice)
1309 PSDeFragControlBlock pDeF;
1312 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1313 pDeF = &(pDevice->sRxDFCB[i]);
1316 dev_kfree_skb(pDeF->skb);
1321 static void device_init_td0_ring(PSDevice pDevice)
1327 curr = pDevice->td0_pool_dma;
1328 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1329 pDesc = &(pDevice->apTD0Rings[i]);
1330 pDesc->pTDInfo = alloc_td_info();
1331 ASSERT(pDesc->pTDInfo);
1332 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1333 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1334 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1336 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1337 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1338 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1342 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1343 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1346 static void device_init_td1_ring(PSDevice pDevice)
1352 /* Init the TD ring entries */
1353 curr = pDevice->td1_pool_dma;
1354 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
1355 pDesc = &(pDevice->apTD1Rings[i]);
1356 pDesc->pTDInfo = alloc_td_info();
1357 ASSERT(pDesc->pTDInfo);
1358 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1359 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
1360 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
1362 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
1363 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1364 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1368 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1369 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1372 static void device_free_td0_ring(PSDevice pDevice)
1376 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1377 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
1378 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1380 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1381 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1382 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1385 dev_kfree_skb(pTDInfo->skb);
1387 kfree((void *)pDesc->pTDInfo);
1391 static void device_free_td1_ring(PSDevice pDevice)
1395 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1396 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
1397 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1399 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1400 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1401 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1404 dev_kfree_skb(pTDInfo->skb);
1406 kfree((void *)pDesc->pTDInfo);
1410 /*-----------------------------------------------------------------*/
1412 static int device_rx_srv(PSDevice pDevice, unsigned int uIdx)
1417 for (pRD = pDevice->pCurrRD[uIdx];
1418 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1422 if (device_receive_frame(pDevice, pRD)) {
1423 if (!device_alloc_rx_buf(pDevice, pRD)) {
1424 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1425 "%s: can not allocate rx buf\n", pDevice->dev->name);
1429 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1430 pDevice->dev->last_rx = jiffies;
1433 pDevice->pCurrRD[uIdx] = pRD;
1438 static bool device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD)
1440 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1442 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1443 if (pRDInfo->skb == NULL)
1445 ASSERT(pRDInfo->skb);
1446 pRDInfo->skb->dev = pDevice->dev;
1447 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
1448 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1449 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1451 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1452 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1453 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1454 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1459 bool device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF)
1461 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1462 if (pDeF->skb == NULL)
1465 pDeF->skb->dev = pDevice->dev;
1470 static int device_tx_srv(PSDevice pDevice, unsigned int uIdx)
1475 unsigned char byTsr0;
1476 unsigned char byTsr1;
1477 unsigned int uFrameSize, uFIFOHeaderSize;
1478 PSTxBufHead pTxBufHead;
1479 struct net_device_stats *pStats = &pDevice->stats;
1480 struct sk_buff *skb;
1481 unsigned int uNodeIndex;
1482 PSMgmtObject pMgmt = pDevice->pMgmt;
1484 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1485 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1490 byTsr0 = pTD->m_td0TD0.byTSR0;
1491 byTsr1 = pTD->m_td0TD0.byTSR1;
1493 //Only the status of first TD in the chain is correct
1494 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1495 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1496 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1497 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1498 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1499 // Update the statistics based on the Transmit status
1500 // now, we DONT check TSR0_CDH
1502 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1504 (unsigned char *)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1507 BSSvUpdateNodeTxCounter(pDevice,
1509 (unsigned char *)(pTD->pTDInfo->buf),
1513 if (!(byTsr1 & TSR1_TERR)) {
1515 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1516 (int)uIdx, byTsr1, byTsr0);
1518 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG)
1519 pDevice->s802_11Counter.TransmittedFragmentCount++;
1521 pStats->tx_packets++;
1522 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1524 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1525 (int)uIdx, byTsr1, byTsr0);
1526 pStats->tx_errors++;
1527 pStats->tx_dropped++;
1531 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1532 if (pDevice->bEnableHostapd) {
1533 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif..\n");
1534 skb = pTD->pTDInfo->skb;
1535 skb->dev = pDevice->apdev;
1536 skb_reset_mac_header(skb);
1537 skb->pkt_type = PACKET_OTHERHOST;
1538 memset(skb->cb, 0, sizeof(skb->cb));
1543 if (byTsr1 & TSR1_TERR) {
1544 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1545 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1546 (int)uIdx, byTsr1, byTsr0);
1550 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1551 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1552 unsigned short wAID;
1553 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1555 skb = pTD->pTDInfo->skb;
1556 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1557 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1558 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1559 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1561 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1562 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1563 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1564 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1565 , (int)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1566 pStats->tx_errors--;
1567 pStats->tx_dropped--;
1572 device_free_tx_buf(pDevice, pTD);
1573 pDevice->iTDUsed[uIdx]--;
1577 if (uIdx == TYPE_AC0DMA) {
1578 // RESERV_AC0DMA reserved for relay
1580 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1582 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
1584 if (netif_queue_stopped(pDevice->dev) && !bFull)
1585 netif_wake_queue(pDevice->dev);
1589 pDevice->apTailTD[uIdx] = pTD;
1594 static void device_error(PSDevice pDevice, unsigned short status)
1596 if (status & ISR_FETALERR) {
1597 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1598 "%s: Hardware fatal error.\n",
1599 pDevice->dev->name);
1600 netif_stop_queue(pDevice->dev);
1601 del_timer(&pDevice->sTimerCommand);
1602 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1603 pDevice->bCmdRunning = false;
1604 MACbShutdown(pDevice->PortOffset);
1609 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc)
1611 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1612 struct sk_buff *skb = pTDInfo->skb;
1614 // pre-allocated buf_dma can't be unmapped.
1615 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1616 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1620 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1621 dev_kfree_skb_irq(skb);
1623 pTDInfo->skb_dma = 0;
1624 pTDInfo->skb = NULL;
1625 pTDInfo->byFlags = 0;
1628 static int device_open(struct net_device *dev)
1630 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1632 #ifdef WPA_SM_Transtatus
1633 extern SWPAResult wpa_Result;
1636 pDevice->rx_buf_sz = PKT_BUF_SZ;
1637 if (!device_init_rings(pDevice))
1640 //2008-5-13 <add> by chester
1641 i = request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1645 #ifdef WPA_SM_Transtatus
1646 memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname));
1647 wpa_Result.proto = 0;
1648 wpa_Result.key_mgmt = 0;
1649 wpa_Result.eap_type = 0;
1650 wpa_Result.authenticated = false;
1651 pDevice->fWPA_Authened = false;
1653 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
1654 device_init_rd0_ring(pDevice);
1655 device_init_rd1_ring(pDevice);
1656 device_init_defrag_cb(pDevice);
1657 device_init_td0_ring(pDevice);
1658 device_init_td1_ring(pDevice);
1660 if (pDevice->bDiversityRegCtlON)
1661 device_init_diversity_timer(pDevice);
1663 vMgrObjectInit(pDevice);
1664 vMgrTimerInit(pDevice);
1666 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
1667 device_init_registers(pDevice);
1669 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1670 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN);
1671 device_set_multi(pDevice->dev);
1673 // Init for Key Management
1674 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1675 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1677 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1678 pDevice->bwextcount = 0;
1679 pDevice->bWPASuppWextEnabled = false;
1681 pDevice->byReAssocCount = 0;
1682 pDevice->bWPADEVUp = false;
1683 // Patch: if WEP key already set by iwconfig but device not yet open
1684 if (pDevice->bEncryptionEnable && pDevice->bTransmitKey) {
1685 KeybSetDefaultKey(&(pDevice->sKey),
1686 (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
1687 pDevice->uKeyLength,
1691 pDevice->PortOffset,
1694 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1697 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
1698 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1700 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1701 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
1703 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1704 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1706 pDevice->flags |= DEVICE_FLAGS_OPENED;
1708 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success..\n");
1712 static int device_close(struct net_device *dev)
1714 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1715 PSMgmtObject pMgmt = pDevice->pMgmt;
1718 //2007-1121-02<Add>by EinsnLiu
1719 if (pDevice->bLinkPass) {
1720 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1724 del_timer(&pDevice->sTimerTxData);
1726 del_timer(&pDevice->sTimerCommand);
1727 del_timer(&pMgmt->sTimerSecondCallback);
1728 if (pDevice->bDiversityRegCtlON) {
1729 del_timer(&pDevice->TimerSQ3Tmax1);
1730 del_timer(&pDevice->TimerSQ3Tmax2);
1731 del_timer(&pDevice->TimerSQ3Tmax3);
1734 netif_stop_queue(dev);
1735 pDevice->bCmdRunning = false;
1736 MACbShutdown(pDevice->PortOffset);
1737 MACbSoftwareReset(pDevice->PortOffset);
1738 CARDbRadioPowerOff(pDevice);
1740 pDevice->bLinkPass = false;
1741 memset(pMgmt->abyCurrBSSID, 0, 6);
1742 pMgmt->eCurrState = WMAC_STATE_IDLE;
1743 device_free_td0_ring(pDevice);
1744 device_free_td1_ring(pDevice);
1745 device_free_rd0_ring(pDevice);
1746 device_free_rd1_ring(pDevice);
1747 device_free_frag_buf(pDevice);
1748 device_free_rings(pDevice);
1749 BSSvClearNodeDBTable(pDevice, 0);
1750 free_irq(dev->irq, dev);
1751 pDevice->flags &= (~DEVICE_FLAGS_OPENED);
1752 //2008-0714-01<Add>by chester
1753 device_release_WPADEV(pDevice);
1755 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close..\n");
1759 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1761 PSDevice pDevice = netdev_priv(dev);
1762 unsigned char *pbMPDU;
1763 unsigned int cbMPDULen = 0;
1765 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
1766 spin_lock_irq(&pDevice->lock);
1768 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1769 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
1770 dev_kfree_skb_irq(skb);
1771 spin_unlock_irq(&pDevice->lock);
1775 if (pDevice->bStopTx0Pkt) {
1776 dev_kfree_skb_irq(skb);
1777 spin_unlock_irq(&pDevice->lock);
1781 cbMPDULen = skb->len;
1784 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
1786 spin_unlock_irq(&pDevice->lock);
1791 bool device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, unsigned int uNodeIndex)
1793 PSMgmtObject pMgmt = pDevice->pMgmt;
1794 PSTxDesc pHeadTD, pLastTD;
1795 unsigned int cbFrameBodySize;
1796 unsigned int uMACfragNum;
1797 unsigned char byPktType;
1798 bool bNeedEncryption = false;
1799 PSKeyItem pTransmitKey = NULL;
1800 unsigned int cbHeaderSize;
1804 if (pDevice->bStopTx0Pkt) {
1805 dev_kfree_skb_irq(skb);
1809 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1810 dev_kfree_skb_irq(skb);
1811 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
1815 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1816 if (pDevice->uAssocCount == 0) {
1817 dev_kfree_skb_irq(skb);
1818 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
1823 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
1825 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1827 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1828 cbFrameBodySize = skb->len - ETH_HLEN;
1831 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1832 cbFrameBodySize += 8;
1834 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
1836 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
1837 dev_kfree_skb_irq(skb);
1840 byPktType = (unsigned char)pDevice->byPacketType;
1842 if (pDevice->bFixRate) {
1843 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
1844 if (pDevice->uConnectionRate >= RATE_11M)
1845 pDevice->wCurrentRate = RATE_11M;
1847 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1849 if (pDevice->uConnectionRate >= RATE_54M)
1850 pDevice->wCurrentRate = RATE_54M;
1852 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1855 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1859 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1860 pDevice->byPreambleType = pDevice->byShortPreamble;
1862 pDevice->byPreambleType = PREAMBLE_LONG;
1864 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d\n", pDevice->wCurrentRate);
1866 if (pDevice->wCurrentRate <= RATE_11M) {
1867 byPktType = PK_TYPE_11B;
1868 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1869 byPktType = PK_TYPE_11A;
1871 if (pDevice->bProtectMode)
1872 byPktType = PK_TYPE_11GB;
1874 byPktType = PK_TYPE_11GA;
1877 if (pDevice->bEncryptionEnable)
1878 bNeedEncryption = true;
1880 if (pDevice->bEnableHostWEP) {
1881 pTransmitKey = &STempKey;
1882 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1883 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1884 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1885 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1886 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1887 memcpy(pTransmitKey->abyKey,
1888 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1889 pTransmitKey->uKeyLength
1892 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
1893 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
1894 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
1899 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1901 MACbPSWakeup(pDevice->PortOffset);
1904 pDevice->bPWBitOn = false;
1907 for (ii = 0; ii < uMACfragNum; ii++) {
1908 // Poll Transmit the adapter
1910 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
1912 if (ii == (uMACfragNum - 1))
1914 pHeadTD = pHeadTD->next;
1917 // Save the information needed by the tx interrupt handler
1918 // to complete the Send request
1919 pLastTD->pTDInfo->skb = skb;
1920 pLastTD->pTDInfo->byFlags = 0;
1921 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
1923 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
1925 MACvTransmit0(pDevice->PortOffset);
1930 //TYPE_AC0DMA data tx
1931 static int device_xmit(struct sk_buff *skb, struct net_device *dev)
1933 PSDevice pDevice = netdev_priv(dev);
1935 PSMgmtObject pMgmt = pDevice->pMgmt;
1936 PSTxDesc pHeadTD, pLastTD;
1937 unsigned int uNodeIndex = 0;
1938 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1939 unsigned short wAID;
1940 unsigned int uMACfragNum = 1;
1941 unsigned int cbFrameBodySize;
1942 unsigned char byPktType;
1943 unsigned int cbHeaderSize;
1944 bool bNeedEncryption = false;
1945 PSKeyItem pTransmitKey = NULL;
1948 bool bTKIP_UseGTK = false;
1949 bool bNeedDeAuth = false;
1950 unsigned char *pbyBSSID;
1951 bool bNodeExist = false;
1953 spin_lock_irq(&pDevice->lock);
1954 if (!pDevice->bLinkPass) {
1955 dev_kfree_skb_irq(skb);
1956 spin_unlock_irq(&pDevice->lock);
1960 if (pDevice->bStopDataPkt) {
1961 dev_kfree_skb_irq(skb);
1962 spin_unlock_irq(&pDevice->lock);
1966 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1967 if (pDevice->uAssocCount == 0) {
1968 dev_kfree_skb_irq(skb);
1969 spin_unlock_irq(&pDevice->lock);
1972 if (is_multicast_ether_addr((unsigned char *)(skb->data))) {
1975 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1976 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1977 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1979 pMgmt->abyPSTxMap[0] |= byMask[0];
1980 spin_unlock_irq(&pDevice->lock);
1984 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1985 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1986 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1987 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1989 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1990 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1991 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
1992 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1993 spin_unlock_irq(&pDevice->lock);
1997 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1998 pDevice->byPreambleType = pDevice->byShortPreamble;
2000 pDevice->byPreambleType = PREAMBLE_LONG;
2008 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Unknown STA not found in node DB\n");
2009 dev_kfree_skb_irq(skb);
2010 spin_unlock_irq(&pDevice->lock);
2015 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
2017 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2019 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
2020 cbFrameBodySize = skb->len - ETH_HLEN;
2022 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
2023 cbFrameBodySize += 8;
2025 if (pDevice->bEncryptionEnable) {
2026 bNeedEncryption = true;
2029 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2030 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2031 pbyBSSID = pDevice->abyBSSID;
2033 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
2035 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2036 bTKIP_UseGTK = true;
2037 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
2041 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get PTK.\n");
2044 } else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2045 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2046 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "IBSS Serach Key:\n");
2047 for (ii = 0; ii < 6; ii++)
2048 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "%x\n", *(pbyBSSID+ii));
2049 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "\n");
2052 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
2056 pbyBSSID = pDevice->abyBroadcastAddr;
2057 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2058 pTransmitKey = NULL;
2059 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
2060 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2062 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2064 bTKIP_UseGTK = true;
2065 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
2070 if (pDevice->bEnableHostWEP) {
2071 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "acdma0: STA index %d\n", uNodeIndex);
2072 if (pDevice->bEncryptionEnable) {
2073 pTransmitKey = &STempKey;
2074 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2075 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2076 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2077 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2078 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2079 memcpy(pTransmitKey->abyKey,
2080 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2081 pTransmitKey->uKeyLength
2086 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2088 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2089 DBG_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
2090 dev_kfree_skb_irq(skb);
2091 spin_unlock_irq(&pDevice->lock);
2095 if (pTransmitKey != NULL) {
2096 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2097 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2098 uMACfragNum = 1; //WEP256 doesn't support fragment
2102 byPktType = (unsigned char)pDevice->byPacketType;
2104 if (pDevice->bFixRate) {
2106 pr_debug("Fix Rate: PhyType is %d,ConnectionRate is %d\n", pDevice->eCurrentPHYType, pDevice->uConnectionRate);
2109 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2110 if (pDevice->uConnectionRate >= RATE_11M)
2111 pDevice->wCurrentRate = RATE_11M;
2113 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2115 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2116 (pDevice->uConnectionRate <= RATE_6M)) {
2117 pDevice->wCurrentRate = RATE_6M;
2119 if (pDevice->uConnectionRate >= RATE_54M)
2120 pDevice->wCurrentRate = RATE_54M;
2122 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2126 pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate;
2127 pDevice->byTopCCKBasicRate = RATE_1M;
2128 pDevice->byTopOFDMBasicRate = RATE_6M;
2131 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2132 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2133 pDevice->wCurrentRate = RATE_1M;
2134 pDevice->byACKRate = RATE_1M;
2135 pDevice->byTopCCKBasicRate = RATE_1M;
2136 pDevice->byTopOFDMBasicRate = RATE_6M;
2138 pDevice->wCurrentRate = RATE_6M;
2139 pDevice->byACKRate = RATE_6M;
2140 pDevice->byTopCCKBasicRate = RATE_1M;
2141 pDevice->byTopOFDMBasicRate = RATE_6M;
2144 VNTWIFIvGetTxRate(pDevice->pMgmt,
2145 pDevice->sTxEthHeader.abyDstAddr,
2146 &(pDevice->wCurrentRate),
2147 &(pDevice->byACKRate),
2148 &(pDevice->byTopCCKBasicRate),
2149 &(pDevice->byTopOFDMBasicRate));
2155 if (pDevice->wCurrentRate <= RATE_11M) {
2156 byPktType = PK_TYPE_11B;
2157 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2158 byPktType = PK_TYPE_11A;
2160 if (pDevice->bProtectMode)
2161 byPktType = PK_TYPE_11GB;
2163 byPktType = PK_TYPE_11GA;
2166 if (bNeedEncryption) {
2167 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2168 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2169 bNeedEncryption = false;
2170 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2171 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2172 if (pTransmitKey == NULL) {
2173 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Don't Find TX KEY\n");
2176 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "error: KEY is GTK!!~~\n");
2178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2179 bNeedEncryption = true;
2184 if (pDevice->byCntMeasure == 2) {
2186 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2189 if (pDevice->bEnableHostWEP) {
2190 if ((uNodeIndex != 0) &&
2191 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2192 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2193 bNeedEncryption = true;
2197 if (pTransmitKey == NULL) {
2198 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return no tx key\n");
2199 dev_kfree_skb_irq(skb);
2200 spin_unlock_irq(&pDevice->lock);
2206 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2207 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2208 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
2213 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2215 MACbPSWakeup(pDevice->PortOffset);
2217 pDevice->bPWBitOn = false;
2220 for (ii = 0; ii < uMACfragNum; ii++) {
2221 // Poll Transmit the adapter
2223 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2225 if (ii == uMACfragNum - 1)
2227 pHeadTD = pHeadTD->next;
2230 // Save the information needed by the tx interrupt handler
2231 // to complete the Send request
2232 pLastTD->pTDInfo->skb = skb;
2233 pLastTD->pTDInfo->byFlags = 0;
2234 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2236 pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
2238 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1)
2239 netif_stop_queue(dev);
2241 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2243 if (pDevice->bFixRate)
2244 pr_debug("FixRate:Rate is %d,TxPower is %d\n", pDevice->wCurrentRate, pDevice->byCurPwr);
2247 unsigned char Protocol_Version; //802.1x Authentication
2248 unsigned char Packet_Type; //802.1x Authentication
2249 unsigned char Descriptor_type;
2250 unsigned short Key_info;
2251 bool bTxeapol_key = false;
2253 Protocol_Version = skb->data[ETH_HLEN];
2254 Packet_Type = skb->data[ETH_HLEN+1];
2255 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2256 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2257 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2258 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2259 (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame transfer
2260 bTxeapol_key = true;
2261 if ((Descriptor_type == 254) || (Descriptor_type == 2)) { //WPA or RSN
2262 if (!(Key_info & BIT3) && //group-key challenge
2263 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2264 pDevice->fWPA_Authened = true;
2265 if (Descriptor_type == 254)
2269 pr_debug("Authentication completed!!\n");
2276 MACvTransmitAC0(pDevice->PortOffset);
2278 dev->trans_start = jiffies;
2280 spin_unlock_irq(&pDevice->lock);
2284 static irqreturn_t device_intr(int irq, void *dev_instance)
2286 struct net_device *dev = dev_instance;
2287 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2290 unsigned long dwMIBCounter = 0;
2291 PSMgmtObject pMgmt = pDevice->pMgmt;
2292 unsigned char byOrgPageSel = 0;
2294 unsigned char byData = 0;
2296 unsigned long flags;
2298 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2300 if (pDevice->dwIsr == 0)
2301 return IRQ_RETVAL(handled);
2303 if (pDevice->dwIsr == 0xffffffff) {
2304 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
2305 return IRQ_RETVAL(handled);
2309 MACvIntDisable(pDevice->PortOffset);
2311 spin_lock_irqsave(&pDevice->lock, flags);
2313 //Make sure current page is 0
2314 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2315 if (byOrgPageSel == 1)
2316 MACvSelectPage0(pDevice->PortOffset);
2320 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2322 // Must do this after doing rx/tx, cause ISR bit is slow
2323 // than RD/TD write back
2324 // update ISR counter
2325 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2326 while (pDevice->dwIsr != 0) {
2327 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2328 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2330 if (pDevice->dwIsr & ISR_FETALERR) {
2331 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR\n");
2332 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2333 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2334 device_error(pDevice, pDevice->dwIsr);
2337 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2338 if (pDevice->dwIsr & ISR_MEASURESTART) {
2339 // 802.11h measure start
2340 pDevice->byOrgChannel = pDevice->byCurrentCh;
2341 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2342 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2343 MACvSelectPage1(pDevice->PortOffset);
2344 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2345 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2346 MACvSelectPage0(pDevice->PortOffset);
2348 if (set_channel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel)) {
2349 pDevice->bMeasureInProgress = true;
2350 MACvSelectPage1(pDevice->PortOffset);
2351 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2352 MACvSelectPage0(pDevice->PortOffset);
2353 pDevice->byBasicMap = 0;
2354 pDevice->byCCAFraction = 0;
2355 for (ii = 0; ii < 8; ii++)
2356 pDevice->dwRPIs[ii] = 0;
2359 // can not measure because set channel fail
2360 // clear measure control
2361 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2362 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2363 MACvSelectPage1(pDevice->PortOffset);
2364 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2365 MACvSelectPage0(pDevice->PortOffset);
2368 if (pDevice->dwIsr & ISR_MEASUREEND) {
2369 // 802.11h measure end
2370 pDevice->bMeasureInProgress = false;
2371 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2372 MACvSelectPage1(pDevice->PortOffset);
2373 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2374 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2375 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2376 pDevice->byBasicMap |= (byData >> 4);
2377 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2378 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2379 // clear measure control
2380 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2381 MACvSelectPage0(pDevice->PortOffset);
2382 set_channel(pDevice, pDevice->byOrgChannel);
2383 MACvSelectPage1(pDevice->PortOffset);
2384 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2385 MACvSelectPage0(pDevice->PortOffset);
2386 if (byData & MSRCTL_FINISH) {
2388 s_vCompleteCurrentMeasure(pDevice, 0);
2390 // can not measure because not ready before end of measure time
2391 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2394 if (pDevice->dwIsr & ISR_QUIETSTART) {
2397 } while (!CARDbStartQuiet(pDevice));
2401 if (pDevice->dwIsr & ISR_TBTT) {
2402 if (pDevice->bEnableFirstQuiet) {
2403 pDevice->byQuietStartCount--;
2404 if (pDevice->byQuietStartCount == 0) {
2405 pDevice->bEnableFirstQuiet = false;
2406 MACvSelectPage1(pDevice->PortOffset);
2407 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2408 MACvSelectPage0(pDevice->PortOffset);
2411 if (pDevice->bChannelSwitch &&
2412 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
2413 pDevice->byChannelSwitchCount--;
2414 if (pDevice->byChannelSwitchCount == 0) {
2415 pDevice->bChannelSwitch = false;
2416 set_channel(pDevice, pDevice->byNewChannel);
2417 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2418 MACvSelectPage1(pDevice->PortOffset);
2419 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2420 MACvSelectPage0(pDevice->PortOffset);
2421 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2425 if (pDevice->eOPMode != OP_MODE_ADHOC) {
2426 if ((pDevice->bUpdateBBVGA) && pDevice->bLinkPass && (pDevice->uCurrRSSI != 0)) {
2429 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
2430 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
2431 if (ldBm < pDevice->ldBmThreshold[ii]) {
2432 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2436 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2437 pDevice->uBBVGADiffCount++;
2438 if (pDevice->uBBVGADiffCount == 1) {
2439 // first VGA diff gain
2440 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2441 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2442 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2444 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2445 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2446 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2447 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2450 pDevice->uBBVGADiffCount = 1;
2455 pDevice->bBeaconSent = false;
2456 if (pDevice->bEnablePSMode)
2457 PSbIsNextTBTTWakeUp((void *)pDevice);
2459 if ((pDevice->eOPMode == OP_MODE_AP) ||
2460 (pDevice->eOPMode == OP_MODE_ADHOC)) {
2461 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2462 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2465 /* TODO: adhoc PS mode */
2469 if (pDevice->dwIsr & ISR_BNTX) {
2470 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2471 pDevice->bIsBeaconBufReadySet = false;
2472 pDevice->cbBeaconBufReadySetCnt = 0;
2475 if (pDevice->eOPMode == OP_MODE_AP) {
2476 if (pMgmt->byDTIMCount > 0) {
2477 pMgmt->byDTIMCount--;
2478 pMgmt->sNodeDBTable[0].bRxPSPoll = false;
2480 if (pMgmt->byDTIMCount == 0) {
2481 // check if mutltcast tx bufferring
2482 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2483 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
2484 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2488 pDevice->bBeaconSent = true;
2490 if (pDevice->bChannelSwitch) {
2491 pDevice->byChannelSwitchCount--;
2492 if (pDevice->byChannelSwitchCount == 0) {
2493 pDevice->bChannelSwitch = false;
2494 set_channel(pDevice, pDevice->byNewChannel);
2495 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2496 MACvSelectPage1(pDevice->PortOffset);
2497 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2498 MACvSelectPage0(pDevice->PortOffset);
2499 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2505 if (pDevice->dwIsr & ISR_RXDMA0)
2506 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2508 if (pDevice->dwIsr & ISR_RXDMA1)
2509 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2511 if (pDevice->dwIsr & ISR_TXDMA0)
2512 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2514 if (pDevice->dwIsr & ISR_AC0DMA)
2515 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2517 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2518 if (pDevice->eOPMode == OP_MODE_AP) {
2519 if (pDevice->bShortSlotTime)
2520 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2522 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2524 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2525 pDevice->byCntMeasure = 0;
2528 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2530 MACvReceive0(pDevice->PortOffset);
2531 MACvReceive1(pDevice->PortOffset);
2533 if (max_count > pDevice->sOpts.int_works)
2537 if (byOrgPageSel == 1)
2538 MACvSelectPage1(pDevice->PortOffset);
2540 spin_unlock_irqrestore(&pDevice->lock, flags);
2542 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2544 return IRQ_RETVAL(handled);
2547 static unsigned const ethernet_polynomial = 0x04c11db7U;
2548 static inline u32 ether_crc(int length, unsigned char *data)
2552 while (--length >= 0) {
2553 unsigned char current_octet = *data++;
2556 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
2558 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
2564 //2008-8-4 <add> by chester
2565 static int Config_FileGetParameter(unsigned char *string,
2566 unsigned char *dest, unsigned char *source)
2568 unsigned char buf1[100];
2569 int source_len = strlen(source);
2571 memset(buf1, 0, 100);
2572 strcat(buf1, string);
2574 source += strlen(buf1);
2576 memcpy(dest, source, source_len - strlen(buf1));
2580 int Config_FileOperation(PSDevice pDevice, bool fwrite, unsigned char *Parameter)
2582 unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
2583 unsigned char tmpbuffer[20];
2588 pr_err("allocate mem for file fail?\n");
2591 file = filp_open(CONFIG_PATH, O_RDONLY, 0);
2594 pr_err("Config_FileOperation:open file fail?\n");
2598 if (kernel_read(file, 0, buffer, 1024) < 0) {
2599 pr_err("read file error?\n");
2604 if (Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=true) {
2605 pr_err("get parameter error?\n");
2610 if (memcmp(tmpbuffer, "USA", 3) == 0) {
2611 result = ZoneType_USA;
2612 } else if(memcmp(tmpbuffer, "JAPAN", 5) == 0) {
2613 result = ZoneType_Japan;
2614 } else if(memcmp(tmpbuffer, "EUROPE", 5) == 0) {
2615 result = ZoneType_Europe;
2618 pr_err("Unknown Zonetype[%s]?\n", tmpbuffer);
2627 static void device_set_multi(struct net_device *dev)
2629 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2631 PSMgmtObject pMgmt = pDevice->pMgmt;
2633 struct netdev_hw_addr *ha;
2635 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
2637 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
2638 DBG_PRT(MSG_LEVEL_ERR, KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
2639 /* Unconditionally log net taps. */
2640 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
2641 } else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
2642 || (dev->flags & IFF_ALLMULTI)) {
2643 MACvSelectPage1(pDevice->PortOffset);
2644 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
2645 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
2646 MACvSelectPage0(pDevice->PortOffset);
2647 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2649 memset(mc_filter, 0, sizeof(mc_filter));
2650 netdev_for_each_mc_addr(ha, dev) {
2651 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
2653 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
2655 MACvSelectPage1(pDevice->PortOffset);
2656 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
2657 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
2658 MACvSelectPage0(pDevice->PortOffset);
2659 pDevice->byRxMode &= ~(RCR_UNICAST);
2660 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2663 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2664 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
2665 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2666 pDevice->byRxMode &= ~(RCR_UNICAST);
2669 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
2670 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode);
2673 static struct net_device_stats *device_get_stats(struct net_device *dev)
2675 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2677 return &pDevice->stats;
2680 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2682 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2684 struct iwreq *wrq = (struct iwreq *)rq;
2686 PSMgmtObject pMgmt = pDevice->pMgmt;
2689 if (pMgmt == NULL) {
2696 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
2699 case SIOCGIWNWID: //0x8b03 support
2703 // Set frequency/channel
2705 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
2708 // Get frequency/channel
2710 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
2713 // Set desired network name (ESSID)
2717 char essid[IW_ESSID_MAX_SIZE+1];
2719 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
2723 if (copy_from_user(essid, wrq->u.essid.pointer,
2724 wrq->u.essid.length)) {
2728 rc = iwctl_siwessid(dev, NULL,
2729 &(wrq->u.essid), essid);
2733 // Get current network name (ESSID)
2737 char essid[IW_ESSID_MAX_SIZE+1];
2739 if (wrq->u.essid.pointer)
2740 rc = iwctl_giwessid(dev, NULL,
2741 &(wrq->u.essid), essid);
2742 if (copy_to_user(wrq->u.essid.pointer,
2744 wrq->u.essid.length))
2751 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2754 // Get current Access Point (BSSID)
2756 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2759 // Set desired station name
2761 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN\n");
2765 // Get current station name
2767 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN\n");
2771 // Set the desired bit-rate
2773 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2776 // Get the current bit-rate
2779 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2782 // Set the desired RTS threshold
2785 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
2788 // Get the current RTS threshold
2791 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
2794 // Set the desired fragmentation threshold
2797 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
2800 // Get the current fragmentation threshold
2803 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
2806 // Set mode of operation
2808 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
2811 // Get mode of operation
2813 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
2816 // Set WEP keys and mode
2817 case SIOCSIWENCODE: {
2818 char abyKey[WLAN_WEP232_KEYLEN];
2820 if (wrq->u.encoding.pointer) {
2821 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
2825 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
2826 if (copy_from_user(abyKey,
2827 wrq->u.encoding.pointer,
2828 wrq->u.encoding.length)) {
2832 } else if (wrq->u.encoding.length != 0) {
2836 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2840 // Get the WEP keys and mode
2843 if (!capable(CAP_NET_ADMIN)) {
2848 char abyKey[WLAN_WEP232_KEYLEN];
2850 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2853 if (wrq->u.encoding.pointer) {
2854 if (copy_to_user(wrq->u.encoding.pointer,
2856 wrq->u.encoding.length))
2862 // Get the current Tx-Power
2864 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW\n");
2869 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWTXPOW\n");
2875 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
2880 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
2883 // Get range of parameters
2887 struct iw_range range;
2889 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *)&range);
2890 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
2898 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
2903 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
2908 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
2912 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS\n");
2916 case SIOCGIWAPLIST: {
2917 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
2919 if (wrq->u.data.pointer) {
2920 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
2922 if (copy_to_user(wrq->u.data.pointer,
2924 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
2936 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY\n");
2943 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSPY\n");
2947 #endif // WIRELESS_SPY
2950 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV\n");
2954 //2008-0409-07, <Add> by Einsn Liu
2955 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2957 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH\n");
2958 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
2962 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH\n");
2963 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
2967 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE\n");
2968 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2972 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE\n");
2973 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2976 case SIOCSIWENCODEEXT: {
2977 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
2979 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT\n");
2980 if (wrq->u.encoding.pointer) {
2981 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN + 1);
2982 if (wrq->u.encoding.length > (sizeof(struct iw_encode_ext) + MAX_KEY_LEN)) {
2986 if (copy_from_user(extra, wrq->u.encoding.pointer, wrq->u.encoding.length)) {
2990 } else if (wrq->u.encoding.length != 0) {
2994 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
2998 case SIOCGIWENCODEEXT:
2999 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT\n");
3000 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
3004 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME\n");
3005 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3008 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3009 //End Add -- //2008-0409-07, <Add> by Einsn Liu
3011 case IOCTL_CMD_TEST:
3013 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
3019 pReq = (PSCmdRequest)rq;
3020 pReq->wResult = MAGIC_CODE;
3026 if ((((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_EVT) &&
3027 !(pDevice->flags & DEVICE_FLAGS_OPENED))
3029 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
3030 (((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_WPA))
3039 if (test_and_set_bit(0, (void *)&(pMgmt->uCmdBusy)))
3042 rc = private_ioctl(pDevice, rq);
3043 clear_bit(0, (void *)&(pMgmt->uCmdBusy));
3046 case IOCTL_CMD_HOSTAPD:
3048 rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data);
3053 rc = wpa_ioctl(pDevice, &wrq->u.data);
3057 return ethtool_ioctl(dev, rq->ifr_data);
3058 // All other calls are currently unsupported
3062 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
3066 if (pDevice->bCommit) {
3067 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3068 netif_stop_queue(pDevice->dev);
3069 spin_lock_irq(&pDevice->lock);
3070 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
3071 spin_unlock_irq(&pDevice->lock);
3073 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
3074 spin_lock_irq(&pDevice->lock);
3075 pDevice->bLinkPass = false;
3076 memset(pMgmt->abyCurrBSSID, 0, 6);
3077 pMgmt->eCurrState = WMAC_STATE_IDLE;
3078 netif_stop_queue(pDevice->dev);
3079 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3080 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
3081 if (!pDevice->bWPASuppWextEnabled)
3083 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
3084 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3085 spin_unlock_irq(&pDevice->lock);
3087 pDevice->bCommit = false;
3093 static int ethtool_ioctl(struct net_device *dev, void __user *useraddr)
3097 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
3101 case ETHTOOL_GDRVINFO: {
3102 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3104 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3105 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3106 if (copy_to_user(useraddr, &info, sizeof(info)))
3116 /*------------------------------------------------------------------*/
3118 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
3120 static struct pci_driver device_driver = {
3121 .name = DEVICE_NAME,
3122 .id_table = vt6655_pci_id_table,
3123 .probe = vt6655_probe,
3124 .remove = vt6655_remove,
3126 .suspend = viawget_suspend,
3127 .resume = viawget_resume,
3131 static int __init vt6655_init_module(void)
3135 ret = pci_register_driver(&device_driver);
3138 register_reboot_notifier(&device_notifier);
3144 static void __exit vt6655_cleanup_module(void)
3147 unregister_reboot_notifier(&device_notifier);
3149 pci_unregister_driver(&device_driver);
3152 module_init(vt6655_init_module);
3153 module_exit(vt6655_cleanup_module);
3157 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3159 struct pci_dev *pdev = NULL;
3165 for_each_pci_dev(pdev) {
3166 if (pci_dev_driver(pdev) == &device_driver) {
3167 if (pci_get_drvdata(pdev))
3168 viawget_suspend(pdev, PMSG_HIBERNATE);
3176 viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3178 int power_status; // to silence the compiler
3180 PSDevice pDevice = pci_get_drvdata(pcid);
3181 PSMgmtObject pMgmt = pDevice->pMgmt;
3183 netif_stop_queue(pDevice->dev);
3184 spin_lock_irq(&pDevice->lock);
3185 pci_save_state(pcid);
3186 del_timer(&pDevice->sTimerCommand);
3187 del_timer(&pMgmt->sTimerSecondCallback);
3188 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3189 pDevice->uCmdDequeueIdx = 0;
3190 pDevice->uCmdEnqueueIdx = 0;
3191 pDevice->bCmdRunning = false;
3192 MACbShutdown(pDevice->PortOffset);
3193 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3194 pDevice->bLinkPass = false;
3195 memset(pMgmt->abyCurrBSSID, 0, 6);
3196 pMgmt->eCurrState = WMAC_STATE_IDLE;
3197 pci_disable_device(pcid);
3198 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3199 spin_unlock_irq(&pDevice->lock);
3204 viawget_resume(struct pci_dev *pcid)
3206 PSDevice pDevice = pci_get_drvdata(pcid);
3207 PSMgmtObject pMgmt = pDevice->pMgmt;
3208 int power_status; // to silence the compiler
3210 power_status = pci_set_power_state(pcid, PCI_D0);
3211 power_status = pci_enable_wake(pcid, PCI_D0, 0);
3212 pci_restore_state(pcid);
3213 if (netif_running(pDevice->dev)) {
3214 spin_lock_irq(&pDevice->lock);
3215 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3216 device_init_registers(pDevice);
3217 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
3218 pMgmt->sNodeDBTable[0].bActive = false;
3219 pDevice->bLinkPass = false;
3220 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3221 // In Adhoc, BSS state set back to started.
3222 pMgmt->eCurrState = WMAC_STATE_STARTED;
3224 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3225 pMgmt->eCurrState = WMAC_STATE_IDLE;
3228 init_timer(&pMgmt->sTimerSecondCallback);
3229 init_timer(&pDevice->sTimerCommand);
3230 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3231 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
3232 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3233 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3234 spin_unlock_irq(&pDevice->lock);