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_alloc_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);
1121 if (vir_pool == NULL) {
1122 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s : allocate desc dma memory failed\n", pDevice->dev->name);
1127 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1128 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1129 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1130 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1133 pDevice->aRD0Ring = vir_pool;
1134 pDevice->aRD1Ring = vir_pool +
1135 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1137 pDevice->rd0_pool_dma = pDevice->pool_dma;
1138 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1139 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1141 pDevice->tx0_bufs = pci_alloc_consistent(pDevice->pcid,
1142 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1143 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1144 CB_BEACON_BUF_SIZE +
1146 &pDevice->tx_bufs_dma0);
1148 if (pDevice->tx0_bufs == NULL) {
1149 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: allocate buf dma memory failed\n", pDevice->dev->name);
1150 pci_free_consistent(pDevice->pcid,
1151 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1152 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1153 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1154 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1155 vir_pool, pDevice->pool_dma
1160 memset(pDevice->tx0_bufs, 0,
1161 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1162 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1163 CB_BEACON_BUF_SIZE +
1167 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1168 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1170 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1171 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1173 // vir_pool: pvoid type
1174 pDevice->apTD0Rings = vir_pool
1175 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1176 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1178 pDevice->apTD1Rings = vir_pool
1179 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1180 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1181 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1183 pDevice->tx1_bufs = pDevice->tx0_bufs +
1184 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1186 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1187 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1189 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1192 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1193 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1195 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1196 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1201 static void device_free_rings(PSDevice pDevice)
1203 pci_free_consistent(pDevice->pcid,
1204 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1205 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1206 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1207 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1209 pDevice->aRD0Ring, pDevice->pool_dma
1212 if (pDevice->tx0_bufs)
1213 pci_free_consistent(pDevice->pcid,
1214 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1215 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1216 CB_BEACON_BUF_SIZE +
1218 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1222 static void device_init_rd0_ring(PSDevice pDevice)
1225 dma_addr_t curr = pDevice->rd0_pool_dma;
1228 /* Init the RD0 ring entries */
1229 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1230 pDesc = &(pDevice->aRD0Ring[i]);
1231 pDesc->pRDInfo = alloc_rd_info();
1232 ASSERT(pDesc->pRDInfo);
1233 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1234 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc rx bufs\n",
1235 pDevice->dev->name);
1237 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1238 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1239 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1243 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1244 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1247 static void device_init_rd1_ring(PSDevice pDevice)
1250 dma_addr_t curr = pDevice->rd1_pool_dma;
1253 /* Init the RD1 ring entries */
1254 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1255 pDesc = &(pDevice->aRD1Ring[i]);
1256 pDesc->pRDInfo = alloc_rd_info();
1257 ASSERT(pDesc->pRDInfo);
1258 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1259 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc rx bufs\n",
1260 pDevice->dev->name);
1262 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1263 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1264 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1268 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1269 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1272 static void device_init_defrag_cb(PSDevice pDevice)
1275 PSDeFragControlBlock pDeF;
1277 /* Init the fragment ctl entries */
1278 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1279 pDeF = &(pDevice->sRxDFCB[i]);
1280 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1281 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc frag bufs\n",
1282 pDevice->dev->name);
1285 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1286 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1289 static void device_free_rd0_ring(PSDevice pDevice)
1293 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1294 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
1295 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1297 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1298 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1300 dev_kfree_skb(pRDInfo->skb);
1302 kfree((void *)pDesc->pRDInfo);
1306 static void device_free_rd1_ring(PSDevice pDevice)
1310 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1311 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
1312 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1314 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1315 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1317 dev_kfree_skb(pRDInfo->skb);
1319 kfree((void *)pDesc->pRDInfo);
1323 static void device_free_frag_buf(PSDevice pDevice)
1325 PSDeFragControlBlock pDeF;
1328 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1329 pDeF = &(pDevice->sRxDFCB[i]);
1332 dev_kfree_skb(pDeF->skb);
1337 static void device_init_td0_ring(PSDevice pDevice)
1343 curr = pDevice->td0_pool_dma;
1344 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1345 pDesc = &(pDevice->apTD0Rings[i]);
1346 pDesc->pTDInfo = alloc_td_info();
1347 ASSERT(pDesc->pTDInfo);
1348 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1349 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1350 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1352 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1353 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1354 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1358 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1359 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1362 static void device_init_td1_ring(PSDevice pDevice)
1368 /* Init the TD ring entries */
1369 curr = pDevice->td1_pool_dma;
1370 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
1371 pDesc = &(pDevice->apTD1Rings[i]);
1372 pDesc->pTDInfo = alloc_td_info();
1373 ASSERT(pDesc->pTDInfo);
1374 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1375 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
1376 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
1378 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
1379 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1380 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1384 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1385 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1388 static void device_free_td0_ring(PSDevice pDevice)
1392 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1393 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
1394 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1396 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1397 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1398 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1401 dev_kfree_skb(pTDInfo->skb);
1403 kfree((void *)pDesc->pTDInfo);
1407 static void device_free_td1_ring(PSDevice pDevice)
1411 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1412 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
1413 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1415 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1416 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1417 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1420 dev_kfree_skb(pTDInfo->skb);
1422 kfree((void *)pDesc->pTDInfo);
1426 /*-----------------------------------------------------------------*/
1428 static int device_rx_srv(PSDevice pDevice, unsigned int uIdx)
1433 for (pRD = pDevice->pCurrRD[uIdx];
1434 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1438 if (device_receive_frame(pDevice, pRD)) {
1439 if (!device_alloc_rx_buf(pDevice, pRD)) {
1440 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1441 "%s: can not allocate rx buf\n", pDevice->dev->name);
1445 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1446 pDevice->dev->last_rx = jiffies;
1449 pDevice->pCurrRD[uIdx] = pRD;
1454 static bool device_alloc_rx_buf(PSDevice pDevice, PSRxDesc pRD)
1456 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1458 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1459 if (pRDInfo->skb == NULL)
1461 ASSERT(pRDInfo->skb);
1462 pRDInfo->skb->dev = pDevice->dev;
1463 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
1464 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1465 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1467 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1468 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1469 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1470 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1475 bool device_alloc_frag_buf(PSDevice pDevice, PSDeFragControlBlock pDeF)
1477 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1478 if (pDeF->skb == NULL)
1481 pDeF->skb->dev = pDevice->dev;
1486 static int device_tx_srv(PSDevice pDevice, unsigned int uIdx)
1491 unsigned char byTsr0;
1492 unsigned char byTsr1;
1493 unsigned int uFrameSize, uFIFOHeaderSize;
1494 PSTxBufHead pTxBufHead;
1495 struct net_device_stats *pStats = &pDevice->stats;
1496 struct sk_buff *skb;
1497 unsigned int uNodeIndex;
1498 PSMgmtObject pMgmt = pDevice->pMgmt;
1500 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1501 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1506 byTsr0 = pTD->m_td0TD0.byTSR0;
1507 byTsr1 = pTD->m_td0TD0.byTSR1;
1509 //Only the status of first TD in the chain is correct
1510 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1511 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1512 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1513 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1514 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1515 // Update the statistics based on the Transmit status
1516 // now, we DONT check TSR0_CDH
1518 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1520 (unsigned char *)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1523 BSSvUpdateNodeTxCounter(pDevice,
1525 (unsigned char *)(pTD->pTDInfo->buf),
1529 if (!(byTsr1 & TSR1_TERR)) {
1531 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X].\n",
1532 (int)uIdx, byTsr1, byTsr0);
1534 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG)
1535 pDevice->s802_11Counter.TransmittedFragmentCount++;
1537 pStats->tx_packets++;
1538 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1540 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] dropped & tsr1[%02X] tsr0[%02X].\n",
1541 (int)uIdx, byTsr1, byTsr0);
1542 pStats->tx_errors++;
1543 pStats->tx_dropped++;
1547 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1548 if (pDevice->bEnableHostapd) {
1549 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx call back netif..\n");
1550 skb = pTD->pTDInfo->skb;
1551 skb->dev = pDevice->apdev;
1552 skb_reset_mac_header(skb);
1553 skb->pkt_type = PACKET_OTHERHOST;
1554 memset(skb->cb, 0, sizeof(skb->cb));
1559 if (byTsr1 & TSR1_TERR) {
1560 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1561 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " Tx[%d] fail has error. tsr1[%02X] tsr0[%02X].\n",
1562 (int)uIdx, byTsr1, byTsr0);
1566 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1567 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1568 unsigned short wAID;
1569 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1571 skb = pTD->pTDInfo->skb;
1572 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1573 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1574 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1575 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1577 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1578 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1579 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1580 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n"
1581 , (int)uNodeIndex, pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1582 pStats->tx_errors--;
1583 pStats->tx_dropped--;
1588 device_free_tx_buf(pDevice, pTD);
1589 pDevice->iTDUsed[uIdx]--;
1593 if (uIdx == TYPE_AC0DMA) {
1594 // RESERV_AC0DMA reserved for relay
1596 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1598 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " AC0DMA is Full = %d\n", pDevice->iTDUsed[uIdx]);
1600 if (netif_queue_stopped(pDevice->dev) && !bFull)
1601 netif_wake_queue(pDevice->dev);
1605 pDevice->apTailTD[uIdx] = pTD;
1610 static void device_error(PSDevice pDevice, unsigned short status)
1612 if (status & ISR_FETALERR) {
1613 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR
1614 "%s: Hardware fatal error.\n",
1615 pDevice->dev->name);
1616 netif_stop_queue(pDevice->dev);
1617 del_timer(&pDevice->sTimerCommand);
1618 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1619 pDevice->bCmdRunning = false;
1620 MACbShutdown(pDevice->PortOffset);
1625 static void device_free_tx_buf(PSDevice pDevice, PSTxDesc pDesc)
1627 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1628 struct sk_buff *skb = pTDInfo->skb;
1630 // pre-allocated buf_dma can't be unmapped.
1631 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1632 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1636 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1637 dev_kfree_skb_irq(skb);
1639 pTDInfo->skb_dma = 0;
1640 pTDInfo->skb = NULL;
1641 pTDInfo->byFlags = 0;
1644 static int device_open(struct net_device *dev)
1646 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1648 #ifdef WPA_SM_Transtatus
1649 extern SWPAResult wpa_Result;
1652 pDevice->rx_buf_sz = PKT_BUF_SZ;
1653 if (!device_init_rings(pDevice))
1656 //2008-5-13 <add> by chester
1657 i = request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1661 #ifdef WPA_SM_Transtatus
1662 memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname));
1663 wpa_Result.proto = 0;
1664 wpa_Result.key_mgmt = 0;
1665 wpa_Result.eap_type = 0;
1666 wpa_Result.authenticated = false;
1667 pDevice->fWPA_Authened = false;
1669 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device init rd0 ring\n");
1670 device_init_rd0_ring(pDevice);
1671 device_init_rd1_ring(pDevice);
1672 device_init_defrag_cb(pDevice);
1673 device_init_td0_ring(pDevice);
1674 device_init_td1_ring(pDevice);
1676 if (pDevice->bDiversityRegCtlON)
1677 device_init_diversity_timer(pDevice);
1679 vMgrObjectInit(pDevice);
1680 vMgrTimerInit(pDevice);
1682 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call device_init_registers\n");
1683 device_init_registers(pDevice);
1685 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1686 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN);
1687 device_set_multi(pDevice->dev);
1689 // Init for Key Management
1690 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1691 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1693 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1694 pDevice->bwextcount = 0;
1695 pDevice->bWPASuppWextEnabled = false;
1697 pDevice->byReAssocCount = 0;
1698 pDevice->bWPADEVUp = false;
1699 // Patch: if WEP key already set by iwconfig but device not yet open
1700 if (pDevice->bEncryptionEnable && pDevice->bTransmitKey) {
1701 KeybSetDefaultKey(&(pDevice->sKey),
1702 (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
1703 pDevice->uKeyLength,
1707 pDevice->PortOffset,
1710 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1713 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "call MACvIntEnable\n");
1714 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1716 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1717 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
1719 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1720 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1722 pDevice->flags |= DEVICE_FLAGS_OPENED;
1724 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_open success..\n");
1728 static int device_close(struct net_device *dev)
1730 PSDevice pDevice = (PSDevice)netdev_priv(dev);
1731 PSMgmtObject pMgmt = pDevice->pMgmt;
1734 //2007-1121-02<Add>by EinsnLiu
1735 if (pDevice->bLinkPass) {
1736 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1740 del_timer(&pDevice->sTimerTxData);
1742 del_timer(&pDevice->sTimerCommand);
1743 del_timer(&pMgmt->sTimerSecondCallback);
1744 if (pDevice->bDiversityRegCtlON) {
1745 del_timer(&pDevice->TimerSQ3Tmax1);
1746 del_timer(&pDevice->TimerSQ3Tmax2);
1747 del_timer(&pDevice->TimerSQ3Tmax3);
1750 netif_stop_queue(dev);
1751 pDevice->bCmdRunning = false;
1752 MACbShutdown(pDevice->PortOffset);
1753 MACbSoftwareReset(pDevice->PortOffset);
1754 CARDbRadioPowerOff(pDevice);
1756 pDevice->bLinkPass = false;
1757 memset(pMgmt->abyCurrBSSID, 0, 6);
1758 pMgmt->eCurrState = WMAC_STATE_IDLE;
1759 device_free_td0_ring(pDevice);
1760 device_free_td1_ring(pDevice);
1761 device_free_rd0_ring(pDevice);
1762 device_free_rd1_ring(pDevice);
1763 device_free_frag_buf(pDevice);
1764 device_free_rings(pDevice);
1765 BSSvClearNodeDBTable(pDevice, 0);
1766 free_irq(dev->irq, dev);
1767 pDevice->flags &= (~DEVICE_FLAGS_OPENED);
1768 //2008-0714-01<Add>by chester
1769 device_release_WPADEV(pDevice);
1771 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_close..\n");
1775 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1777 PSDevice pDevice = netdev_priv(dev);
1778 unsigned char *pbMPDU;
1779 unsigned int cbMPDULen = 0;
1781 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211\n");
1782 spin_lock_irq(&pDevice->lock);
1784 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1785 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_tx_80211, td0 <=0\n");
1786 dev_kfree_skb_irq(skb);
1787 spin_unlock_irq(&pDevice->lock);
1791 if (pDevice->bStopTx0Pkt) {
1792 dev_kfree_skb_irq(skb);
1793 spin_unlock_irq(&pDevice->lock);
1797 cbMPDULen = skb->len;
1800 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
1802 spin_unlock_irq(&pDevice->lock);
1807 bool device_dma0_xmit(PSDevice pDevice, struct sk_buff *skb, unsigned int uNodeIndex)
1809 PSMgmtObject pMgmt = pDevice->pMgmt;
1810 PSTxDesc pHeadTD, pLastTD;
1811 unsigned int cbFrameBodySize;
1812 unsigned int uMACfragNum;
1813 unsigned char byPktType;
1814 bool bNeedEncryption = false;
1815 PSKeyItem pTransmitKey = NULL;
1816 unsigned int cbHeaderSize;
1820 if (pDevice->bStopTx0Pkt) {
1821 dev_kfree_skb_irq(skb);
1825 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1826 dev_kfree_skb_irq(skb);
1827 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, td0 <=0\n");
1831 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1832 if (pDevice->uAssocCount == 0) {
1833 dev_kfree_skb_irq(skb);
1834 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "device_dma0_xmit, assocCount = 0\n");
1839 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
1841 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1843 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1844 cbFrameBodySize = skb->len - ETH_HLEN;
1847 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1848 cbFrameBodySize += 8;
1850 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
1852 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
1853 dev_kfree_skb_irq(skb);
1856 byPktType = (unsigned char)pDevice->byPacketType;
1858 if (pDevice->bFixRate) {
1859 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
1860 if (pDevice->uConnectionRate >= RATE_11M)
1861 pDevice->wCurrentRate = RATE_11M;
1863 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1865 if (pDevice->uConnectionRate >= RATE_54M)
1866 pDevice->wCurrentRate = RATE_54M;
1868 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1871 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1875 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1876 pDevice->byPreambleType = pDevice->byShortPreamble;
1878 pDevice->byPreambleType = PREAMBLE_LONG;
1880 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dma0: pDevice->wCurrentRate = %d\n", pDevice->wCurrentRate);
1882 if (pDevice->wCurrentRate <= RATE_11M) {
1883 byPktType = PK_TYPE_11B;
1884 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1885 byPktType = PK_TYPE_11A;
1887 if (pDevice->bProtectMode)
1888 byPktType = PK_TYPE_11GB;
1890 byPktType = PK_TYPE_11GA;
1893 if (pDevice->bEncryptionEnable)
1894 bNeedEncryption = true;
1896 if (pDevice->bEnableHostWEP) {
1897 pTransmitKey = &STempKey;
1898 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1899 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1900 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1901 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1902 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1903 memcpy(pTransmitKey->abyKey,
1904 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1905 pTransmitKey->uKeyLength
1908 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
1909 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
1910 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
1915 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1917 MACbPSWakeup(pDevice->PortOffset);
1920 pDevice->bPWBitOn = false;
1923 for (ii = 0; ii < uMACfragNum; ii++) {
1924 // Poll Transmit the adapter
1926 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
1928 if (ii == (uMACfragNum - 1))
1930 pHeadTD = pHeadTD->next;
1933 // Save the information needed by the tx interrupt handler
1934 // to complete the Send request
1935 pLastTD->pTDInfo->skb = skb;
1936 pLastTD->pTDInfo->byFlags = 0;
1937 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
1939 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
1941 MACvTransmit0(pDevice->PortOffset);
1946 //TYPE_AC0DMA data tx
1947 static int device_xmit(struct sk_buff *skb, struct net_device *dev)
1949 PSDevice pDevice = netdev_priv(dev);
1951 PSMgmtObject pMgmt = pDevice->pMgmt;
1952 PSTxDesc pHeadTD, pLastTD;
1953 unsigned int uNodeIndex = 0;
1954 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1955 unsigned short wAID;
1956 unsigned int uMACfragNum = 1;
1957 unsigned int cbFrameBodySize;
1958 unsigned char byPktType;
1959 unsigned int cbHeaderSize;
1960 bool bNeedEncryption = false;
1961 PSKeyItem pTransmitKey = NULL;
1964 bool bTKIP_UseGTK = false;
1965 bool bNeedDeAuth = false;
1966 unsigned char *pbyBSSID;
1967 bool bNodeExist = false;
1969 spin_lock_irq(&pDevice->lock);
1970 if (!pDevice->bLinkPass) {
1971 dev_kfree_skb_irq(skb);
1972 spin_unlock_irq(&pDevice->lock);
1976 if (pDevice->bStopDataPkt) {
1977 dev_kfree_skb_irq(skb);
1978 spin_unlock_irq(&pDevice->lock);
1982 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1983 if (pDevice->uAssocCount == 0) {
1984 dev_kfree_skb_irq(skb);
1985 spin_unlock_irq(&pDevice->lock);
1988 if (is_multicast_ether_addr((unsigned char *)(skb->data))) {
1991 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1992 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1993 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1995 pMgmt->abyPSTxMap[0] |= byMask[0];
1996 spin_unlock_irq(&pDevice->lock);
2000 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
2001 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
2002 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
2003 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
2005 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
2006 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
2007 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Set:pMgmt->abyPSTxMap[%d]= %d\n",
2008 (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
2009 spin_unlock_irq(&pDevice->lock);
2013 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
2014 pDevice->byPreambleType = pDevice->byShortPreamble;
2016 pDevice->byPreambleType = PREAMBLE_LONG;
2024 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Unknown STA not found in node DB\n");
2025 dev_kfree_skb_irq(skb);
2026 spin_unlock_irq(&pDevice->lock);
2031 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
2033 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2035 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
2036 cbFrameBodySize = skb->len - ETH_HLEN;
2038 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
2039 cbFrameBodySize += 8;
2041 if (pDevice->bEncryptionEnable) {
2042 bNeedEncryption = true;
2045 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
2046 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2047 pbyBSSID = pDevice->abyBSSID;
2049 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
2051 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
2052 bTKIP_UseGTK = true;
2053 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
2057 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get PTK.\n");
2060 } else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
2061 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
2062 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "IBSS Serach Key:\n");
2063 for (ii = 0; ii < 6; ii++)
2064 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "%x\n", *(pbyBSSID+ii));
2065 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "\n");
2068 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
2072 pbyBSSID = pDevice->abyBroadcastAddr;
2073 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
2074 pTransmitKey = NULL;
2075 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
2076 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2078 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "NOT IBSS and KEY is NULL. [%d]\n", pDevice->pMgmt->eCurrMode);
2080 bTKIP_UseGTK = true;
2081 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "Get GTK.\n");
2086 if (pDevice->bEnableHostWEP) {
2087 DBG_PRT(MSG_LEVEL_DEBUG, KERN_DEBUG "acdma0: STA index %d\n", uNodeIndex);
2088 if (pDevice->bEncryptionEnable) {
2089 pTransmitKey = &STempKey;
2090 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2091 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2092 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2093 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2094 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2095 memcpy(pTransmitKey->abyKey,
2096 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2097 pTransmitKey->uKeyLength
2102 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2104 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2105 DBG_PRT(MSG_LEVEL_ERR, KERN_DEBUG "uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n", uMACfragNum);
2106 dev_kfree_skb_irq(skb);
2107 spin_unlock_irq(&pDevice->lock);
2111 if (pTransmitKey != NULL) {
2112 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2113 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2114 uMACfragNum = 1; //WEP256 doesn't support fragment
2118 byPktType = (unsigned char)pDevice->byPacketType;
2120 if (pDevice->bFixRate) {
2122 pr_debug("Fix Rate: PhyType is %d,ConnectionRate is %d\n", pDevice->eCurrentPHYType, pDevice->uConnectionRate);
2125 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2126 if (pDevice->uConnectionRate >= RATE_11M)
2127 pDevice->wCurrentRate = RATE_11M;
2129 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2131 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2132 (pDevice->uConnectionRate <= RATE_6M)) {
2133 pDevice->wCurrentRate = RATE_6M;
2135 if (pDevice->uConnectionRate >= RATE_54M)
2136 pDevice->wCurrentRate = RATE_54M;
2138 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2142 pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate;
2143 pDevice->byTopCCKBasicRate = RATE_1M;
2144 pDevice->byTopOFDMBasicRate = RATE_6M;
2147 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2148 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2149 pDevice->wCurrentRate = RATE_1M;
2150 pDevice->byACKRate = RATE_1M;
2151 pDevice->byTopCCKBasicRate = RATE_1M;
2152 pDevice->byTopOFDMBasicRate = RATE_6M;
2154 pDevice->wCurrentRate = RATE_6M;
2155 pDevice->byACKRate = RATE_6M;
2156 pDevice->byTopCCKBasicRate = RATE_1M;
2157 pDevice->byTopOFDMBasicRate = RATE_6M;
2160 VNTWIFIvGetTxRate(pDevice->pMgmt,
2161 pDevice->sTxEthHeader.abyDstAddr,
2162 &(pDevice->wCurrentRate),
2163 &(pDevice->byACKRate),
2164 &(pDevice->byTopCCKBasicRate),
2165 &(pDevice->byTopOFDMBasicRate));
2171 if (pDevice->wCurrentRate <= RATE_11M) {
2172 byPktType = PK_TYPE_11B;
2173 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2174 byPktType = PK_TYPE_11A;
2176 if (pDevice->bProtectMode)
2177 byPktType = PK_TYPE_11GB;
2179 byPktType = PK_TYPE_11GA;
2182 if (bNeedEncryption) {
2183 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ntohs Pkt Type=%04x\n", ntohs(pDevice->sTxEthHeader.wType));
2184 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2185 bNeedEncryption = false;
2186 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pkt Type=%04x\n", (pDevice->sTxEthHeader.wType));
2187 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2188 if (pTransmitKey == NULL) {
2189 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Don't Find TX KEY\n");
2192 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "error: KEY is GTK!!~~\n");
2194 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2195 bNeedEncryption = true;
2200 if (pDevice->byCntMeasure == 2) {
2202 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2205 if (pDevice->bEnableHostWEP) {
2206 if ((uNodeIndex != 0) &&
2207 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2208 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Find PTK [%lX]\n", pTransmitKey->dwKeyIndex);
2209 bNeedEncryption = true;
2213 if (pTransmitKey == NULL) {
2214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return no tx key\n");
2215 dev_kfree_skb_irq(skb);
2216 spin_unlock_irq(&pDevice->lock);
2222 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2223 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2224 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
2229 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2231 MACbPSWakeup(pDevice->PortOffset);
2233 pDevice->bPWBitOn = false;
2236 for (ii = 0; ii < uMACfragNum; ii++) {
2237 // Poll Transmit the adapter
2239 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2241 if (ii == uMACfragNum - 1)
2243 pHeadTD = pHeadTD->next;
2246 // Save the information needed by the tx interrupt handler
2247 // to complete the Send request
2248 pLastTD->pTDInfo->skb = skb;
2249 pLastTD->pTDInfo->byFlags = 0;
2250 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2252 pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
2254 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1)
2255 netif_stop_queue(dev);
2257 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2259 if (pDevice->bFixRate)
2260 pr_debug("FixRate:Rate is %d,TxPower is %d\n", pDevice->wCurrentRate, pDevice->byCurPwr);
2263 unsigned char Protocol_Version; //802.1x Authentication
2264 unsigned char Packet_Type; //802.1x Authentication
2265 unsigned char Descriptor_type;
2266 unsigned short Key_info;
2267 bool bTxeapol_key = false;
2269 Protocol_Version = skb->data[ETH_HLEN];
2270 Packet_Type = skb->data[ETH_HLEN+1];
2271 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2272 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2273 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2274 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2275 (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame transfer
2276 bTxeapol_key = true;
2277 if ((Descriptor_type == 254) || (Descriptor_type == 2)) { //WPA or RSN
2278 if (!(Key_info & BIT3) && //group-key challenge
2279 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2280 pDevice->fWPA_Authened = true;
2281 if (Descriptor_type == 254)
2285 pr_debug("Authentication completed!!\n");
2292 MACvTransmitAC0(pDevice->PortOffset);
2294 dev->trans_start = jiffies;
2296 spin_unlock_irq(&pDevice->lock);
2300 static irqreturn_t device_intr(int irq, void *dev_instance)
2302 struct net_device *dev = dev_instance;
2303 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2306 unsigned long dwMIBCounter = 0;
2307 PSMgmtObject pMgmt = pDevice->pMgmt;
2308 unsigned char byOrgPageSel = 0;
2310 unsigned char byData = 0;
2312 unsigned long flags;
2314 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2316 if (pDevice->dwIsr == 0)
2317 return IRQ_RETVAL(handled);
2319 if (pDevice->dwIsr == 0xffffffff) {
2320 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dwIsr = 0xffff\n");
2321 return IRQ_RETVAL(handled);
2325 MACvIntDisable(pDevice->PortOffset);
2327 spin_lock_irqsave(&pDevice->lock, flags);
2329 //Make sure current page is 0
2330 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2331 if (byOrgPageSel == 1)
2332 MACvSelectPage0(pDevice->PortOffset);
2336 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2338 // Must do this after doing rx/tx, cause ISR bit is slow
2339 // than RD/TD write back
2340 // update ISR counter
2341 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2342 while (pDevice->dwIsr != 0) {
2343 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2344 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2346 if (pDevice->dwIsr & ISR_FETALERR) {
2347 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " ISR_FETALERR\n");
2348 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2349 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2350 device_error(pDevice, pDevice->dwIsr);
2353 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2354 if (pDevice->dwIsr & ISR_MEASURESTART) {
2355 // 802.11h measure start
2356 pDevice->byOrgChannel = pDevice->byCurrentCh;
2357 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2358 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2359 MACvSelectPage1(pDevice->PortOffset);
2360 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2361 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2362 MACvSelectPage0(pDevice->PortOffset);
2364 if (set_channel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel)) {
2365 pDevice->bMeasureInProgress = true;
2366 MACvSelectPage1(pDevice->PortOffset);
2367 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2368 MACvSelectPage0(pDevice->PortOffset);
2369 pDevice->byBasicMap = 0;
2370 pDevice->byCCAFraction = 0;
2371 for (ii = 0; ii < 8; ii++)
2372 pDevice->dwRPIs[ii] = 0;
2375 // can not measure because set channel fail
2376 // clear measure control
2377 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2378 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2379 MACvSelectPage1(pDevice->PortOffset);
2380 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2381 MACvSelectPage0(pDevice->PortOffset);
2384 if (pDevice->dwIsr & ISR_MEASUREEND) {
2385 // 802.11h measure end
2386 pDevice->bMeasureInProgress = false;
2387 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2388 MACvSelectPage1(pDevice->PortOffset);
2389 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2390 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2391 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2392 pDevice->byBasicMap |= (byData >> 4);
2393 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2394 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2395 // clear measure control
2396 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2397 MACvSelectPage0(pDevice->PortOffset);
2398 set_channel(pDevice, pDevice->byOrgChannel);
2399 MACvSelectPage1(pDevice->PortOffset);
2400 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2401 MACvSelectPage0(pDevice->PortOffset);
2402 if (byData & MSRCTL_FINISH) {
2404 s_vCompleteCurrentMeasure(pDevice, 0);
2406 // can not measure because not ready before end of measure time
2407 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2410 if (pDevice->dwIsr & ISR_QUIETSTART) {
2413 } while (!CARDbStartQuiet(pDevice));
2417 if (pDevice->dwIsr & ISR_TBTT) {
2418 if (pDevice->bEnableFirstQuiet) {
2419 pDevice->byQuietStartCount--;
2420 if (pDevice->byQuietStartCount == 0) {
2421 pDevice->bEnableFirstQuiet = false;
2422 MACvSelectPage1(pDevice->PortOffset);
2423 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2424 MACvSelectPage0(pDevice->PortOffset);
2427 if (pDevice->bChannelSwitch &&
2428 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE)) {
2429 pDevice->byChannelSwitchCount--;
2430 if (pDevice->byChannelSwitchCount == 0) {
2431 pDevice->bChannelSwitch = false;
2432 set_channel(pDevice, pDevice->byNewChannel);
2433 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2434 MACvSelectPage1(pDevice->PortOffset);
2435 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2436 MACvSelectPage0(pDevice->PortOffset);
2437 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2441 if (pDevice->eOPMode != OP_MODE_ADHOC) {
2442 if ((pDevice->bUpdateBBVGA) && pDevice->bLinkPass && (pDevice->uCurrRSSI != 0)) {
2445 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
2446 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
2447 if (ldBm < pDevice->ldBmThreshold[ii]) {
2448 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2452 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2453 pDevice->uBBVGADiffCount++;
2454 if (pDevice->uBBVGADiffCount == 1) {
2455 // first VGA diff gain
2456 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2457 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2458 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2460 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2461 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2462 (int)ldBm, pDevice->byBBVGANew, pDevice->byBBVGACurrent, (int)pDevice->uBBVGADiffCount);
2463 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2466 pDevice->uBBVGADiffCount = 1;
2471 pDevice->bBeaconSent = false;
2472 if (pDevice->bEnablePSMode)
2473 PSbIsNextTBTTWakeUp((void *)pDevice);
2475 if ((pDevice->eOPMode == OP_MODE_AP) ||
2476 (pDevice->eOPMode == OP_MODE_ADHOC)) {
2477 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2478 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2481 /* TODO: adhoc PS mode */
2485 if (pDevice->dwIsr & ISR_BNTX) {
2486 if (pDevice->eOPMode == OP_MODE_ADHOC) {
2487 pDevice->bIsBeaconBufReadySet = false;
2488 pDevice->cbBeaconBufReadySetCnt = 0;
2491 if (pDevice->eOPMode == OP_MODE_AP) {
2492 if (pMgmt->byDTIMCount > 0) {
2493 pMgmt->byDTIMCount--;
2494 pMgmt->sNodeDBTable[0].bRxPSPoll = false;
2496 if (pMgmt->byDTIMCount == 0) {
2497 // check if mutltcast tx bufferring
2498 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2499 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
2500 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2504 pDevice->bBeaconSent = true;
2506 if (pDevice->bChannelSwitch) {
2507 pDevice->byChannelSwitchCount--;
2508 if (pDevice->byChannelSwitchCount == 0) {
2509 pDevice->bChannelSwitch = false;
2510 set_channel(pDevice, pDevice->byNewChannel);
2511 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2512 MACvSelectPage1(pDevice->PortOffset);
2513 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2514 MACvSelectPage0(pDevice->PortOffset);
2515 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2521 if (pDevice->dwIsr & ISR_RXDMA0)
2522 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2524 if (pDevice->dwIsr & ISR_RXDMA1)
2525 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2527 if (pDevice->dwIsr & ISR_TXDMA0)
2528 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2530 if (pDevice->dwIsr & ISR_AC0DMA)
2531 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2533 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2534 if (pDevice->eOPMode == OP_MODE_AP) {
2535 if (pDevice->bShortSlotTime)
2536 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2538 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2540 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2541 pDevice->byCntMeasure = 0;
2544 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2546 MACvReceive0(pDevice->PortOffset);
2547 MACvReceive1(pDevice->PortOffset);
2549 if (max_count > pDevice->sOpts.int_works)
2553 if (byOrgPageSel == 1)
2554 MACvSelectPage1(pDevice->PortOffset);
2556 spin_unlock_irqrestore(&pDevice->lock, flags);
2558 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2560 return IRQ_RETVAL(handled);
2563 static unsigned const ethernet_polynomial = 0x04c11db7U;
2564 static inline u32 ether_crc(int length, unsigned char *data)
2568 while (--length >= 0) {
2569 unsigned char current_octet = *data++;
2572 for (bit = 0; bit < 8; bit++, current_octet >>= 1) {
2574 ((crc < 0) ^ (current_octet & 1) ? ethernet_polynomial : 0);
2580 //2008-8-4 <add> by chester
2581 static int Config_FileGetParameter(unsigned char *string,
2582 unsigned char *dest, unsigned char *source)
2584 unsigned char buf1[100];
2585 int source_len = strlen(source);
2587 memset(buf1, 0, 100);
2588 strcat(buf1, string);
2590 source += strlen(buf1);
2592 memcpy(dest, source, source_len - strlen(buf1));
2596 int Config_FileOperation(PSDevice pDevice, bool fwrite, unsigned char *Parameter)
2598 unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
2599 unsigned char tmpbuffer[20];
2604 pr_err("allocate mem for file fail?\n");
2607 file = filp_open(CONFIG_PATH, O_RDONLY, 0);
2610 pr_err("Config_FileOperation:open file fail?\n");
2614 if (kernel_read(file, 0, buffer, 1024) < 0) {
2615 pr_err("read file error?\n");
2620 if (Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=true) {
2621 pr_err("get parameter error?\n");
2626 if (memcmp(tmpbuffer, "USA", 3) == 0) {
2627 result = ZoneType_USA;
2628 } else if(memcmp(tmpbuffer, "JAPAN", 5) == 0) {
2629 result = ZoneType_Japan;
2630 } else if(memcmp(tmpbuffer, "EUROPE", 5) == 0) {
2631 result = ZoneType_Europe;
2634 pr_err("Unknown Zonetype[%s]?\n", tmpbuffer);
2643 static void device_set_multi(struct net_device *dev)
2645 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2647 PSMgmtObject pMgmt = pDevice->pMgmt;
2649 struct netdev_hw_addr *ha;
2651 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
2653 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
2654 DBG_PRT(MSG_LEVEL_ERR, KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name);
2655 /* Unconditionally log net taps. */
2656 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
2657 } else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
2658 || (dev->flags & IFF_ALLMULTI)) {
2659 MACvSelectPage1(pDevice->PortOffset);
2660 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
2661 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
2662 MACvSelectPage0(pDevice->PortOffset);
2663 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2665 memset(mc_filter, 0, sizeof(mc_filter));
2666 netdev_for_each_mc_addr(ha, dev) {
2667 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
2669 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
2671 MACvSelectPage1(pDevice->PortOffset);
2672 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
2673 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
2674 MACvSelectPage0(pDevice->PortOffset);
2675 pDevice->byRxMode &= ~(RCR_UNICAST);
2676 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2679 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2680 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
2681 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2682 pDevice->byRxMode &= ~(RCR_UNICAST);
2685 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
2686 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pDevice->byRxMode = %x\n", pDevice->byRxMode);
2689 static struct net_device_stats *device_get_stats(struct net_device *dev)
2691 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2693 return &pDevice->stats;
2696 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2698 PSDevice pDevice = (PSDevice)netdev_priv(dev);
2700 struct iwreq *wrq = (struct iwreq *)rq;
2702 PSMgmtObject pMgmt = pDevice->pMgmt;
2705 if (pMgmt == NULL) {
2712 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
2715 case SIOCGIWNWID: //0x8b03 support
2719 // Set frequency/channel
2721 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
2724 // Get frequency/channel
2726 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
2729 // Set desired network name (ESSID)
2733 char essid[IW_ESSID_MAX_SIZE+1];
2735 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
2739 if (copy_from_user(essid, wrq->u.essid.pointer,
2740 wrq->u.essid.length)) {
2744 rc = iwctl_siwessid(dev, NULL,
2745 &(wrq->u.essid), essid);
2749 // Get current network name (ESSID)
2753 char essid[IW_ESSID_MAX_SIZE+1];
2755 if (wrq->u.essid.pointer)
2756 rc = iwctl_giwessid(dev, NULL,
2757 &(wrq->u.essid), essid);
2758 if (copy_to_user(wrq->u.essid.pointer,
2760 wrq->u.essid.length))
2767 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2770 // Get current Access Point (BSSID)
2772 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2775 // Set desired station name
2777 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWNICKN\n");
2781 // Get current station name
2783 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWNICKN\n");
2787 // Set the desired bit-rate
2789 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2792 // Get the current bit-rate
2795 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2798 // Set the desired RTS threshold
2801 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
2804 // Get the current RTS threshold
2807 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
2810 // Set the desired fragmentation threshold
2813 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
2816 // Get the current fragmentation threshold
2819 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
2822 // Set mode of operation
2824 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
2827 // Get mode of operation
2829 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
2832 // Set WEP keys and mode
2833 case SIOCSIWENCODE: {
2834 char abyKey[WLAN_WEP232_KEYLEN];
2836 if (wrq->u.encoding.pointer) {
2837 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
2841 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
2842 if (copy_from_user(abyKey,
2843 wrq->u.encoding.pointer,
2844 wrq->u.encoding.length)) {
2848 } else if (wrq->u.encoding.length != 0) {
2852 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2856 // Get the WEP keys and mode
2859 if (!capable(CAP_NET_ADMIN)) {
2864 char abyKey[WLAN_WEP232_KEYLEN];
2866 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2869 if (wrq->u.encoding.pointer) {
2870 if (copy_to_user(wrq->u.encoding.pointer,
2872 wrq->u.encoding.length))
2878 // Get the current Tx-Power
2880 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWTXPOW\n");
2885 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWTXPOW\n");
2891 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
2896 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
2899 // Get range of parameters
2903 struct iw_range range;
2905 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *)&range);
2906 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
2914 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
2919 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
2924 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
2928 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSENS\n");
2932 case SIOCGIWAPLIST: {
2933 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
2935 if (wrq->u.data.pointer) {
2936 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
2938 if (copy_to_user(wrq->u.data.pointer,
2940 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
2952 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWSPY\n");
2959 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWSPY\n");
2963 #endif // WIRELESS_SPY
2966 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWPRIV\n");
2970 //2008-0409-07, <Add> by Einsn Liu
2971 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2973 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWAUTH\n");
2974 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
2978 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWAUTH\n");
2979 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
2983 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWGENIE\n");
2984 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2988 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWGENIE\n");
2989 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2992 case SIOCSIWENCODEEXT: {
2993 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
2995 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWENCODEEXT\n");
2996 if (wrq->u.encoding.pointer) {
2997 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN + 1);
2998 if (wrq->u.encoding.length > (sizeof(struct iw_encode_ext) + MAX_KEY_LEN)) {
3002 if (copy_from_user(extra, wrq->u.encoding.pointer, wrq->u.encoding.length)) {
3006 } else if (wrq->u.encoding.length != 0) {
3010 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
3014 case SIOCGIWENCODEEXT:
3015 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCGIWENCODEEXT\n");
3016 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
3020 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " SIOCSIWMLME\n");
3021 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
3024 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3025 //End Add -- //2008-0409-07, <Add> by Einsn Liu
3027 case IOCTL_CMD_TEST:
3029 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
3035 pReq = (PSCmdRequest)rq;
3036 pReq->wResult = MAGIC_CODE;
3042 if ((((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_EVT) &&
3043 !(pDevice->flags & DEVICE_FLAGS_OPENED))
3045 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
3046 (((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_WPA))
3055 if (test_and_set_bit(0, (void *)&(pMgmt->uCmdBusy)))
3058 rc = private_ioctl(pDevice, rq);
3059 clear_bit(0, (void *)&(pMgmt->uCmdBusy));
3062 case IOCTL_CMD_HOSTAPD:
3064 rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data);
3069 rc = wpa_ioctl(pDevice, &wrq->u.data);
3073 return ethtool_ioctl(dev, rq->ifr_data);
3074 // All other calls are currently unsupported
3078 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Ioctl command not support..%x\n", cmd);
3082 if (pDevice->bCommit) {
3083 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
3084 netif_stop_queue(pDevice->dev);
3085 spin_lock_irq(&pDevice->lock);
3086 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
3087 spin_unlock_irq(&pDevice->lock);
3089 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Commit the settings\n");
3090 spin_lock_irq(&pDevice->lock);
3091 pDevice->bLinkPass = false;
3092 memset(pMgmt->abyCurrBSSID, 0, 6);
3093 pMgmt->eCurrState = WMAC_STATE_IDLE;
3094 netif_stop_queue(pDevice->dev);
3095 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
3096 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
3097 if (!pDevice->bWPASuppWextEnabled)
3099 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
3100 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3101 spin_unlock_irq(&pDevice->lock);
3103 pDevice->bCommit = false;
3109 static int ethtool_ioctl(struct net_device *dev, void __user *useraddr)
3113 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
3117 case ETHTOOL_GDRVINFO: {
3118 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3120 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3121 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3122 if (copy_to_user(useraddr, &info, sizeof(info)))
3132 /*------------------------------------------------------------------*/
3134 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
3136 static struct pci_driver device_driver = {
3137 .name = DEVICE_NAME,
3138 .id_table = vt6655_pci_id_table,
3139 .probe = vt6655_probe,
3140 .remove = vt6655_remove,
3142 .suspend = viawget_suspend,
3143 .resume = viawget_resume,
3147 static int __init vt6655_init_module(void)
3151 ret = pci_register_driver(&device_driver);
3154 register_reboot_notifier(&device_notifier);
3160 static void __exit vt6655_cleanup_module(void)
3163 unregister_reboot_notifier(&device_notifier);
3165 pci_unregister_driver(&device_driver);
3168 module_init(vt6655_init_module);
3169 module_exit(vt6655_cleanup_module);
3173 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3175 struct pci_dev *pdev = NULL;
3181 for_each_pci_dev(pdev) {
3182 if (pci_dev_driver(pdev) == &device_driver) {
3183 if (pci_get_drvdata(pdev))
3184 viawget_suspend(pdev, PMSG_HIBERNATE);
3192 viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3194 int power_status; // to silence the compiler
3196 PSDevice pDevice = pci_get_drvdata(pcid);
3197 PSMgmtObject pMgmt = pDevice->pMgmt;
3199 netif_stop_queue(pDevice->dev);
3200 spin_lock_irq(&pDevice->lock);
3201 pci_save_state(pcid);
3202 del_timer(&pDevice->sTimerCommand);
3203 del_timer(&pMgmt->sTimerSecondCallback);
3204 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3205 pDevice->uCmdDequeueIdx = 0;
3206 pDevice->uCmdEnqueueIdx = 0;
3207 pDevice->bCmdRunning = false;
3208 MACbShutdown(pDevice->PortOffset);
3209 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3210 pDevice->bLinkPass = false;
3211 memset(pMgmt->abyCurrBSSID, 0, 6);
3212 pMgmt->eCurrState = WMAC_STATE_IDLE;
3213 pci_disable_device(pcid);
3214 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3215 spin_unlock_irq(&pDevice->lock);
3220 viawget_resume(struct pci_dev *pcid)
3222 PSDevice pDevice = pci_get_drvdata(pcid);
3223 PSMgmtObject pMgmt = pDevice->pMgmt;
3224 int power_status; // to silence the compiler
3226 power_status = pci_set_power_state(pcid, PCI_D0);
3227 power_status = pci_enable_wake(pcid, PCI_D0, 0);
3228 pci_restore_state(pcid);
3229 if (netif_running(pDevice->dev)) {
3230 spin_lock_irq(&pDevice->lock);
3231 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3232 device_init_registers(pDevice);
3233 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
3234 pMgmt->sNodeDBTable[0].bActive = false;
3235 pDevice->bLinkPass = false;
3236 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3237 // In Adhoc, BSS state set back to started.
3238 pMgmt->eCurrState = WMAC_STATE_STARTED;
3240 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3241 pMgmt->eCurrState = WMAC_STATE_IDLE;
3244 init_timer(&pMgmt->sTimerSecondCallback);
3245 init_timer(&pDevice->sTimerCommand);
3246 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3247 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
3248 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3249 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3250 spin_unlock_irq(&pDevice->lock);