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 -------------------------*/
93 // Define module options
95 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
96 MODULE_LICENSE("GPL");
97 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
99 #define DEVICE_PARAM(N, D)
101 #define RX_DESC_MIN0 16
102 #define RX_DESC_MAX0 128
103 #define RX_DESC_DEF0 32
104 DEVICE_PARAM(RxDescriptors0, "Number of receive descriptors0");
106 #define RX_DESC_MIN1 16
107 #define RX_DESC_MAX1 128
108 #define RX_DESC_DEF1 32
109 DEVICE_PARAM(RxDescriptors1, "Number of receive descriptors1");
111 #define TX_DESC_MIN0 16
112 #define TX_DESC_MAX0 128
113 #define TX_DESC_DEF0 32
114 DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
116 #define TX_DESC_MIN1 16
117 #define TX_DESC_MAX1 128
118 #define TX_DESC_DEF1 64
119 DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
121 #define IP_ALIG_DEF 0
122 /* IP_byte_align[] is used for IP header unsigned long byte aligned
123 0: indicate the IP header won't be unsigned long byte aligned.(Default) .
124 1: indicate the IP header will be unsigned long byte aligned.
125 In some environment, the IP header should be unsigned long byte aligned,
126 or the packet will be droped when we receive it. (eg: IPVS)
128 DEVICE_PARAM(IP_byte_align, "Enable IP header dword aligned");
130 #define INT_WORKS_DEF 20
131 #define INT_WORKS_MIN 10
132 #define INT_WORKS_MAX 64
134 DEVICE_PARAM(int_works, "Number of packets per interrupt services");
136 #define CHANNEL_MIN 1
137 #define CHANNEL_MAX 14
138 #define CHANNEL_DEF 6
140 DEVICE_PARAM(Channel, "Channel number");
142 /* PreambleType[] is the preamble length used for transmit.
143 0: indicate allows long preamble type
144 1: indicate allows short preamble type
147 #define PREAMBLE_TYPE_DEF 1
149 DEVICE_PARAM(PreambleType, "Preamble Type");
151 #define RTS_THRESH_MIN 512
152 #define RTS_THRESH_MAX 2347
153 #define RTS_THRESH_DEF 2347
155 DEVICE_PARAM(RTSThreshold, "RTS threshold");
157 #define FRAG_THRESH_MIN 256
158 #define FRAG_THRESH_MAX 2346
159 #define FRAG_THRESH_DEF 2346
161 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
163 #define DATA_RATE_MIN 0
164 #define DATA_RATE_MAX 13
165 #define DATA_RATE_DEF 13
167 0: indicate 1 Mbps 0x02
168 1: indicate 2 Mbps 0x04
169 2: indicate 5.5 Mbps 0x0B
170 3: indicate 11 Mbps 0x16
171 4: indicate 6 Mbps 0x0c
172 5: indicate 9 Mbps 0x12
173 6: indicate 12 Mbps 0x18
174 7: indicate 18 Mbps 0x24
175 8: indicate 24 Mbps 0x30
176 9: indicate 36 Mbps 0x48
177 10: indicate 48 Mbps 0x60
178 11: indicate 54 Mbps 0x6c
179 12: indicate 72 Mbps 0x90
180 13: indicate auto rate
183 DEVICE_PARAM(ConnectionRate, "Connection data rate");
185 #define OP_MODE_DEF 0
187 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
189 /* OpMode[] is used for transmit.
190 0: indicate infrastruct mode used
191 1: indicate adhoc mode used
192 2: indicate AP mode used
196 0: indicate disable power saving mode
197 1: indicate enable power saving mode
200 #define PS_MODE_DEF 0
202 DEVICE_PARAM(PSMode, "Power saving mode");
204 #define SHORT_RETRY_MIN 0
205 #define SHORT_RETRY_MAX 31
206 #define SHORT_RETRY_DEF 8
208 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
210 #define LONG_RETRY_MIN 0
211 #define LONG_RETRY_MAX 15
212 #define LONG_RETRY_DEF 4
214 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
216 /* BasebandType[] baseband type selected
217 0: indicate 802.11a type
218 1: indicate 802.11b type
219 2: indicate 802.11g type
221 #define BBP_TYPE_MIN 0
222 #define BBP_TYPE_MAX 2
223 #define BBP_TYPE_DEF 2
225 DEVICE_PARAM(BasebandType, "baseband type");
228 0: indicate disable 802.11h
229 1: indicate enable 802.11h
232 #define X80211h_MODE_DEF 0
234 DEVICE_PARAM(b80211hEnable, "802.11h mode");
237 0: indicate disable 802.11h
238 1: indicate enable 802.11h
241 #define DIVERSITY_ANT_DEF 0
243 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
246 // Static vars definitions
248 static CHIP_INFO chip_info_table[] = {
249 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
250 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
254 static const struct pci_device_id vt6655_pci_id_table[] = {
255 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
259 /*--------------------- Static Functions --------------------------*/
261 static int vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent);
262 static void vt6655_init_info(struct pci_dev *pcid,
263 struct vnt_private **ppDevice, PCHIP_INFO);
264 static void device_free_info(struct vnt_private *pDevice);
265 static bool device_get_pci_info(struct vnt_private *, struct pci_dev *pcid);
266 static void device_print_info(struct vnt_private *pDevice);
267 static void device_init_diversity_timer(struct vnt_private *pDevice);
268 static int device_open(struct net_device *dev);
269 static int device_xmit(struct sk_buff *skb, struct net_device *dev);
270 static irqreturn_t device_intr(int irq, void *dev_instance);
271 static void device_set_multi(struct net_device *dev);
272 static int device_close(struct net_device *dev);
273 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
276 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
277 static int viawget_suspend(struct pci_dev *pcid, pm_message_t state);
278 static int viawget_resume(struct pci_dev *pcid);
279 static struct notifier_block device_notifier = {
280 .notifier_call = device_notify_reboot,
286 static void device_init_rd0_ring(struct vnt_private *pDevice);
287 static void device_init_rd1_ring(struct vnt_private *pDevice);
288 static void device_init_defrag_cb(struct vnt_private *pDevice);
289 static void device_init_td0_ring(struct vnt_private *pDevice);
290 static void device_init_td1_ring(struct vnt_private *pDevice);
292 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
293 //2008-0714<Add>by Mike Liu
294 static bool device_release_WPADEV(struct vnt_private *pDevice);
296 static int ethtool_ioctl(struct net_device *dev, void __user *useraddr);
297 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx);
298 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx);
299 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc);
300 static void device_init_registers(struct vnt_private *pDevice);
301 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc);
302 static void device_free_td0_ring(struct vnt_private *pDevice);
303 static void device_free_td1_ring(struct vnt_private *pDevice);
304 static void device_free_rd0_ring(struct vnt_private *pDevice);
305 static void device_free_rd1_ring(struct vnt_private *pDevice);
306 static void device_free_rings(struct vnt_private *pDevice);
307 static void device_free_frag_buf(struct vnt_private *pDevice);
308 static int Config_FileGetParameter(unsigned char *string,
309 unsigned char *dest, unsigned char *source);
311 /*--------------------- Export Variables --------------------------*/
313 /*--------------------- Export Functions --------------------------*/
315 static char *get_chip_name(int chip_id)
319 for (i = 0; chip_info_table[i].name != NULL; i++)
320 if (chip_info_table[i].chip_id == chip_id)
322 return chip_info_table[i].name;
325 static void vt6655_remove(struct pci_dev *pcid)
327 struct vnt_private *pDevice = pci_get_drvdata(pcid);
331 device_free_info(pDevice);
334 static void device_get_options(struct vnt_private *pDevice)
336 POPTIONS pOpts = &(pDevice->sOpts);
338 pOpts->nRxDescs0 = RX_DESC_DEF0;
339 pOpts->nRxDescs1 = RX_DESC_DEF1;
340 pOpts->nTxDescs[0] = TX_DESC_DEF0;
341 pOpts->nTxDescs[1] = TX_DESC_DEF1;
342 pOpts->flags |= DEVICE_FLAGS_IP_ALIGN;
343 pOpts->int_works = INT_WORKS_DEF;
344 pOpts->rts_thresh = RTS_THRESH_DEF;
345 pOpts->frag_thresh = FRAG_THRESH_DEF;
346 pOpts->data_rate = DATA_RATE_DEF;
347 pOpts->channel_num = CHANNEL_DEF;
349 pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE;
350 pOpts->flags |= DEVICE_FLAGS_OP_MODE;
351 pOpts->short_retry = SHORT_RETRY_DEF;
352 pOpts->long_retry = LONG_RETRY_DEF;
353 pOpts->bbp_type = BBP_TYPE_DEF;
354 pOpts->flags |= DEVICE_FLAGS_80211h_MODE;
355 pOpts->flags |= DEVICE_FLAGS_DiversityANT;
359 device_set_options(struct vnt_private *pDevice)
361 unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
362 unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
363 unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
365 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
366 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
367 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
369 pDevice->uChannel = pDevice->sOpts.channel_num;
370 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
371 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
372 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
373 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
374 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
375 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
376 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
377 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
378 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
379 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
380 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
381 if (pDevice->uConnectionRate < RATE_AUTO)
382 pDevice->bFixRate = true;
383 pDevice->byBBType = pDevice->sOpts.bbp_type;
384 pDevice->byPacketType = (VIA_PKT_TYPE)pDevice->byBBType;
385 pDevice->byAutoFBCtrl = AUTO_FB_0;
386 pDevice->bUpdateBBVGA = true;
387 pDevice->byFOETuning = 0;
388 pDevice->byPreambleType = 0;
390 pr_debug(" uChannel= %d\n", (int)pDevice->uChannel);
391 pr_debug(" byOpMode= %d\n", (int)pDevice->byOpMode);
392 pr_debug(" ePSMode= %d\n", (int)pDevice->ePSMode);
393 pr_debug(" wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
394 pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
395 pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
396 pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType);
397 pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
398 pr_debug(" uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
399 pr_debug(" byBBType= %d\n", (int)pDevice->byBBType);
400 pr_debug(" pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
401 pr_debug(" pDevice->bDiversityRegCtlON= %d\n",
402 (int)pDevice->bDiversityRegCtlON);
405 static void s_vCompleteCurrentMeasure(struct vnt_private *pDevice,
406 unsigned char byResult)
409 unsigned long dwDuration = 0;
410 unsigned char byRPI0 = 0;
412 for (ii = 1; ii < 8; ii++) {
413 pDevice->dwRPIs[ii] *= 255;
414 dwDuration |= *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
416 pDevice->dwRPIs[ii] /= dwDuration;
417 pDevice->abyRPIs[ii] = (unsigned char)pDevice->dwRPIs[ii];
418 byRPI0 += pDevice->abyRPIs[ii];
420 pDevice->abyRPIs[0] = (0xFF - byRPI0);
422 if (pDevice->uNumOfMeasureEIDs == 0) {
423 VNTWIFIbMeasureReport(pDevice->pMgmt,
425 pDevice->pCurrMeasureEID,
428 pDevice->byCCAFraction,
432 VNTWIFIbMeasureReport(pDevice->pMgmt,
434 pDevice->pCurrMeasureEID,
437 pDevice->byCCAFraction,
440 CARDbStartMeasure(pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
445 // Initialisation of MAC & BBP registers
448 static void device_init_registers(struct vnt_private *pDevice)
451 unsigned char byValue;
452 unsigned char byValue1;
453 unsigned char byCCKPwrdBm = 0;
454 unsigned char byOFDMPwrdBm = 0;
456 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
458 MACbShutdown(pDevice->PortOffset);
459 BBvSoftwareReset(pDevice->PortOffset);
461 /* Do MACbSoftwareReset in MACvInitialize */
462 MACbSoftwareReset(pDevice->PortOffset);
464 pDevice->bAES = false;
466 /* Only used in 11g type, sync with ERP IE */
467 pDevice->bProtectMode = false;
469 pDevice->bNonERPPresent = false;
470 pDevice->bBarkerPreambleMd = false;
471 pDevice->wCurrentRate = RATE_1M;
472 pDevice->byTopOFDMBasicRate = RATE_24M;
473 pDevice->byTopCCKBasicRate = RATE_1M;
475 /* Target to IF pin while programming to RF chip. */
476 pDevice->byRevId = 0;
479 MACvInitialize(pDevice->PortOffset);
482 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
484 spin_lock_irq(&pDevice->lock);
486 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
488 spin_unlock_irq(&pDevice->lock);
490 /* Get Channel range */
491 pDevice->byMinChannel = 1;
492 pDevice->byMaxChannel = CB_MAX_CHANNEL;
495 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
496 if (byValue & EEP_ANTINV)
497 pDevice->bTxRxAntInv = true;
499 pDevice->bTxRxAntInv = false;
501 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
502 /* if not set default is All */
504 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
506 pDevice->ulDiversityNValue = 100*260;
507 pDevice->ulDiversityMValue = 100*16;
509 pDevice->byTMax2 = 4;
510 pDevice->ulSQ3TH = 0;
511 pDevice->byTMax3 = 64;
513 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
514 pDevice->byAntennaCount = 2;
515 pDevice->byTxAntennaMode = ANT_B;
516 pDevice->dwTxAntennaSel = 1;
517 pDevice->dwRxAntennaSel = 1;
519 if (pDevice->bTxRxAntInv)
520 pDevice->byRxAntennaMode = ANT_A;
522 pDevice->byRxAntennaMode = ANT_B;
524 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset,
527 if ((byValue1 & 0x08) == 0)
528 pDevice->bDiversityEnable = false;
530 pDevice->bDiversityEnable = true;
532 pDevice->bDiversityEnable = false;
533 pDevice->byAntennaCount = 1;
534 pDevice->dwTxAntennaSel = 0;
535 pDevice->dwRxAntennaSel = 0;
537 if (byValue & EEP_ANTENNA_AUX) {
538 pDevice->byTxAntennaMode = ANT_A;
540 if (pDevice->bTxRxAntInv)
541 pDevice->byRxAntennaMode = ANT_B;
543 pDevice->byRxAntennaMode = ANT_A;
545 pDevice->byTxAntennaMode = ANT_B;
547 if (pDevice->bTxRxAntInv)
548 pDevice->byRxAntennaMode = ANT_A;
550 pDevice->byRxAntennaMode = ANT_B;
554 pr_debug("bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
555 pDevice->bDiversityEnable, (int)pDevice->ulDiversityNValue,
556 (int)pDevice->ulDiversityMValue, pDevice->byTMax,
559 /* zonetype initial */
560 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
561 zonetype = Config_FileOperation(pDevice, false, NULL);
564 if ((zonetype == 0) &&
565 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x00)) {
567 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
568 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
570 pr_debug("Init Zone Type :USA\n");
571 } else if ((zonetype == 1) &&
572 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x01)) {
574 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
575 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
576 } else if ((zonetype == 2) &&
577 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x02)) {
579 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
580 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
582 pr_debug("Init Zone Type :Europe\n");
584 if (zonetype != pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
585 pr_debug("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",
587 pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
589 pr_debug("Read Zonetype file success,use default zonetype setting[%02x]\n",
593 pr_debug("Read Zonetype file fail,use default zonetype setting[%02x]\n",
594 SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
598 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
600 /* force change RevID for VT3253 emu */
601 if ((pDevice->byRFType & RF_EMU) != 0)
602 pDevice->byRevId = 0x80;
604 pDevice->byRFType &= RF_MASK;
605 pr_debug("pDevice->byRFType = %x\n", pDevice->byRFType);
607 if (!pDevice->bZoneRegExist)
608 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
610 pr_debug("pDevice->byZoneType = %x\n", pDevice->byZoneType);
615 /* Get Desire Power Value */
616 pDevice->byCurPwr = 0xFF;
617 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
618 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
620 /* Load power Table */
621 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
622 pDevice->abyCCKPwrTbl[ii + 1] =
623 SROMbyReadEmbedded(pDevice->PortOffset,
624 (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
625 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
626 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
628 pDevice->abyOFDMPwrTbl[ii + 1] =
629 SROMbyReadEmbedded(pDevice->PortOffset,
630 (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
631 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
632 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
634 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
635 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
638 /* recover 12,13 ,14channel for EUROPE by 11 channel */
639 if (((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
640 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe)) &&
641 (pDevice->byOriginalZonetype == ZoneType_USA)) {
642 for (ii = 11; ii < 14; ii++) {
643 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
644 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
649 /* Load OFDM A Power Table */
650 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
651 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
652 SROMbyReadEmbedded(pDevice->PortOffset,
653 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
655 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
656 SROMbyReadEmbedded(pDevice->PortOffset,
657 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
660 init_channel_table((void *)pDevice);
662 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
663 MACvSelectPage1(pDevice->PortOffset);
665 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
666 (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
668 MACvSelectPage0(pDevice->PortOffset);
671 /* use relative tx timeout and 802.11i D4 */
672 MACvWordRegBitsOn(pDevice->PortOffset,
673 MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
675 /* set performance parameter by registry */
676 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
677 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
679 /* reset TSF counter */
680 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
681 /* enable TSF counter */
682 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
684 /* initialize BBP registers */
685 BBbVT3253Init(pDevice);
687 if (pDevice->bUpdateBBVGA) {
688 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
689 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
690 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
693 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
694 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
696 pDevice->byCurrentCh = 0;
698 /* Set BB and packet type at the same time. */
699 /* Set Short Slot Time, xIFS, and RSPINF. */
700 if (pDevice->uConnectionRate == RATE_AUTO)
701 pDevice->wCurrentRate = RATE_54M;
703 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
706 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
707 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
709 pDevice->bRadioOff = false;
711 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
713 pDevice->bHWRadioOff = false;
715 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
717 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
719 if (((pDevice->byGPIO & GPIO0_DATA) &&
720 !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
721 (!(pDevice->byGPIO & GPIO0_DATA) &&
722 (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
723 pDevice->bHWRadioOff = true;
726 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
727 CARDbRadioPowerOff(pDevice);
729 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
731 /* get Permanent network address */
732 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
733 pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
735 /* reset Tx pointer */
736 CARDvSafeResetRx(pDevice);
737 /* reset Rx pointer */
738 CARDvSafeResetTx(pDevice);
740 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
741 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
743 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
746 MACvReceive0(pDevice->PortOffset);
747 MACvReceive1(pDevice->PortOffset);
749 /* start the adapter */
750 MACvStart(pDevice->PortOffset);
752 netif_stop_queue(pDevice->dev);
755 static void device_init_diversity_timer(struct vnt_private *pDevice)
757 init_timer(&pDevice->TimerSQ3Tmax1);
758 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
759 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
760 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
762 init_timer(&pDevice->TimerSQ3Tmax2);
763 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
764 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
765 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
767 init_timer(&pDevice->TimerSQ3Tmax3);
768 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
769 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
770 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
773 static bool device_release_WPADEV(struct vnt_private *pDevice)
775 viawget_wpa_header *wpahdr;
778 //send device close to wpa_supplicnat layer
779 if (pDevice->bWPADEVUp) {
780 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
781 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
782 wpahdr->resp_ie_len = 0;
783 wpahdr->req_ie_len = 0;
784 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
785 pDevice->skb->dev = pDevice->wpadev;
786 skb_reset_mac_header(pDevice->skb);
787 pDevice->skb->pkt_type = PACKET_HOST;
788 pDevice->skb->protocol = htons(ETH_P_802_2);
789 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
790 netif_rx(pDevice->skb);
791 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
793 while (pDevice->bWPADEVUp) {
794 set_current_state(TASK_UNINTERRUPTIBLE);
795 schedule_timeout(HZ / 20); //wait 50ms
804 static const struct net_device_ops device_netdev_ops = {
805 .ndo_open = device_open,
806 .ndo_stop = device_close,
807 .ndo_do_ioctl = device_ioctl,
808 .ndo_start_xmit = device_xmit,
809 .ndo_set_rx_mode = device_set_multi,
813 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
815 static bool bFirst = true;
816 struct net_device *dev = NULL;
817 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
818 struct vnt_private *pDevice;
821 dev = alloc_etherdev(sizeof(*pDevice));
823 pDevice = netdev_priv(dev);
826 pr_err(DEVICE_NAME ": allocate net device failed\n");
830 // Chain it all together
831 SET_NETDEV_DEV(dev, &pcid->dev);
834 pr_notice("%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
835 pr_notice("Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
839 vt6655_init_info(pcid, &pDevice, pChip_info);
842 if (pci_enable_device(pcid)) {
843 device_free_info(pDevice);
846 dev->irq = pcid->irq;
849 pr_debug("Before get pci_info memaddr is %x\n", pDevice->memaddr);
851 if (!device_get_pci_info(pDevice, pcid)) {
852 pr_err(DEVICE_NAME ": Failed to find PCI device.\n");
853 device_free_info(pDevice);
861 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);
873 for (i = 0; address[i]; i++) {
874 pci_read_config_dword(pcid, address[i], &bar);
875 pr_debug("bar %d is %x\n", i, bar);
877 pr_debug("bar %d not implemented\n", i);
880 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
883 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
884 len = len & ~(len - 1);
886 pr_debug("IO space: len in IO %x, BAR %d\n", len, i);
888 len = bar & 0xFFFFFFF0;
891 pr_debug("len in MEM %x, BAR %d\n", len, i);
899 pDevice->PortOffset = ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
901 if (pDevice->PortOffset == NULL) {
902 pr_err(DEVICE_NAME ": Failed to IO remapping ..\n");
903 device_free_info(pDevice);
907 rc = pci_request_regions(pcid, DEVICE_NAME);
909 pr_err(DEVICE_NAME ": Failed to find PCI device\n");
910 device_free_info(pDevice);
914 dev->base_addr = pDevice->ioaddr;
916 if (!MACbSoftwareReset(pDevice->PortOffset)) {
917 pr_err(DEVICE_NAME ": Failed to access MAC hardware..\n");
918 device_free_info(pDevice);
921 // initial to reload eeprom
922 MACvInitialize(pDevice->PortOffset);
923 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
925 device_get_options(pDevice);
926 device_set_options(pDevice);
927 //Mask out the options cannot be set to the chip
928 pDevice->sOpts.flags &= pChip_info->flags;
930 //Enable the chip specified capabilities
931 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
932 pDevice->tx_80211 = device_dma0_tx_80211;
933 pDevice->sMgmtObj.pAdapter = (void *)pDevice;
934 pDevice->pMgmt = &(pDevice->sMgmtObj);
936 dev->irq = pcid->irq;
937 dev->netdev_ops = &device_netdev_ops;
939 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
941 rc = register_netdev(dev);
943 pr_err(DEVICE_NAME " Failed to register netdev\n");
944 device_free_info(pDevice);
947 device_print_info(pDevice);
948 pci_set_drvdata(pcid, pDevice);
952 static void device_print_info(struct vnt_private *pDevice)
954 struct net_device *dev = pDevice->dev;
956 pr_info("%s: %s\n", dev->name, get_chip_name(pDevice->chip_id));
957 pr_info("%s: MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
958 dev->name, dev->dev_addr, (unsigned long)pDevice->ioaddr,
959 (unsigned long)pDevice->PortOffset, pDevice->dev->irq);
962 static void vt6655_init_info(struct pci_dev *pcid,
963 struct vnt_private **ppDevice,
964 PCHIP_INFO pChip_info)
966 memset(*ppDevice, 0, sizeof(**ppDevice));
968 (*ppDevice)->pcid = pcid;
969 (*ppDevice)->chip_id = pChip_info->chip_id;
970 (*ppDevice)->io_size = pChip_info->io_size;
971 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
972 (*ppDevice)->multicast_limit = 32;
974 spin_lock_init(&((*ppDevice)->lock));
977 static bool device_get_pci_info(struct vnt_private *pDevice,
978 struct pci_dev *pcid)
982 unsigned int cis_addr;
984 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
985 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
986 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
987 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
989 pci_set_master(pcid);
991 pDevice->memaddr = pci_resource_start(pcid, 0);
992 pDevice->ioaddr = pci_resource_start(pcid, 1);
994 cis_addr = pci_resource_start(pcid, 2);
996 pDevice->pcid = pcid;
998 pci_read_config_byte(pcid, PCI_COMMAND, &b);
999 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
1004 static void device_free_info(struct vnt_private *pDevice)
1006 struct net_device *dev = pDevice->dev;
1009 //2008-0714-01<Add>by chester
1010 device_release_WPADEV(pDevice);
1012 //2008-07-21-01<Add>by MikeLiu
1014 if (wpa_set_wpadev(pDevice, 0) != 0)
1015 pr_err("unregister wpadev fail?\n");
1019 vt6655_hostap_set_hostapd(pDevice, 0, 0);
1022 unregister_netdev(dev);
1024 if (pDevice->PortOffset)
1025 iounmap(pDevice->PortOffset);
1028 pci_release_regions(pDevice->pcid);
1033 static bool device_init_rings(struct vnt_private *pDevice)
1037 /*allocate all RD/TD rings a single pool*/
1038 vir_pool = pci_zalloc_consistent(pDevice->pcid,
1039 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1040 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1041 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1042 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1043 &pDevice->pool_dma);
1044 if (vir_pool == NULL) {
1045 dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n");
1049 pDevice->aRD0Ring = vir_pool;
1050 pDevice->aRD1Ring = vir_pool +
1051 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1053 pDevice->rd0_pool_dma = pDevice->pool_dma;
1054 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1055 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1057 pDevice->tx0_bufs = pci_zalloc_consistent(pDevice->pcid,
1058 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1059 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1060 CB_BEACON_BUF_SIZE +
1062 &pDevice->tx_bufs_dma0);
1063 if (pDevice->tx0_bufs == NULL) {
1064 dev_err(&pDevice->pcid->dev, "allocate buf dma memory failed\n");
1066 pci_free_consistent(pDevice->pcid,
1067 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1068 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1069 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1070 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1071 vir_pool, pDevice->pool_dma
1076 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1077 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1079 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1080 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1082 // vir_pool: pvoid type
1083 pDevice->apTD0Rings = vir_pool
1084 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1085 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1087 pDevice->apTD1Rings = vir_pool
1088 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1089 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1090 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1092 pDevice->tx1_bufs = pDevice->tx0_bufs +
1093 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1095 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1096 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1098 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1101 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1102 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1104 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1105 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1110 static void device_free_rings(struct vnt_private *pDevice)
1112 pci_free_consistent(pDevice->pcid,
1113 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1114 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1115 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1116 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
1118 pDevice->aRD0Ring, pDevice->pool_dma
1121 if (pDevice->tx0_bufs)
1122 pci_free_consistent(pDevice->pcid,
1123 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1124 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1125 CB_BEACON_BUF_SIZE +
1127 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1131 static void device_init_rd0_ring(struct vnt_private *pDevice)
1134 dma_addr_t curr = pDevice->rd0_pool_dma;
1137 /* Init the RD0 ring entries */
1138 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1139 pDesc = &(pDevice->aRD0Ring[i]);
1140 pDesc->pRDInfo = alloc_rd_info();
1141 ASSERT(pDesc->pRDInfo);
1142 if (!device_alloc_rx_buf(pDevice, pDesc))
1143 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
1145 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1146 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1147 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1151 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1152 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1155 static void device_init_rd1_ring(struct vnt_private *pDevice)
1158 dma_addr_t curr = pDevice->rd1_pool_dma;
1161 /* Init the RD1 ring entries */
1162 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1163 pDesc = &(pDevice->aRD1Ring[i]);
1164 pDesc->pRDInfo = alloc_rd_info();
1165 ASSERT(pDesc->pRDInfo);
1166 if (!device_alloc_rx_buf(pDevice, pDesc))
1167 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
1169 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1170 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1171 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1175 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1176 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1179 static void device_init_defrag_cb(struct vnt_private *pDevice)
1182 PSDeFragControlBlock pDeF;
1184 /* Init the fragment ctl entries */
1185 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1186 pDeF = &(pDevice->sRxDFCB[i]);
1187 if (!device_alloc_frag_buf(pDevice, pDeF))
1188 dev_err(&pDevice->pcid->dev, "can not alloc frag bufs\n");
1190 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1191 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1194 static void device_free_rd0_ring(struct vnt_private *pDevice)
1198 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1199 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
1200 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1202 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1203 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1205 dev_kfree_skb(pRDInfo->skb);
1207 kfree((void *)pDesc->pRDInfo);
1211 static void device_free_rd1_ring(struct vnt_private *pDevice)
1215 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1216 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
1217 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1219 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1220 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1222 dev_kfree_skb(pRDInfo->skb);
1224 kfree((void *)pDesc->pRDInfo);
1228 static void device_free_frag_buf(struct vnt_private *pDevice)
1230 PSDeFragControlBlock pDeF;
1233 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1234 pDeF = &(pDevice->sRxDFCB[i]);
1237 dev_kfree_skb(pDeF->skb);
1242 static void device_init_td0_ring(struct vnt_private *pDevice)
1248 curr = pDevice->td0_pool_dma;
1249 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1250 pDesc = &(pDevice->apTD0Rings[i]);
1251 pDesc->pTDInfo = alloc_td_info();
1252 ASSERT(pDesc->pTDInfo);
1253 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1254 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1255 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1257 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1258 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1259 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1263 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1264 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1267 static void device_init_td1_ring(struct vnt_private *pDevice)
1273 /* Init the TD ring entries */
1274 curr = pDevice->td1_pool_dma;
1275 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
1276 pDesc = &(pDevice->apTD1Rings[i]);
1277 pDesc->pTDInfo = alloc_td_info();
1278 ASSERT(pDesc->pTDInfo);
1279 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1280 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
1281 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
1283 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
1284 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1285 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1289 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1290 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1293 static void device_free_td0_ring(struct vnt_private *pDevice)
1297 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1298 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
1299 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1301 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1302 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1303 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1306 dev_kfree_skb(pTDInfo->skb);
1308 kfree((void *)pDesc->pTDInfo);
1312 static void device_free_td1_ring(struct vnt_private *pDevice)
1316 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1317 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
1318 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1320 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1321 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1322 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1325 dev_kfree_skb(pTDInfo->skb);
1327 kfree((void *)pDesc->pTDInfo);
1331 /*-----------------------------------------------------------------*/
1333 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1338 for (pRD = pDevice->pCurrRD[uIdx];
1339 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1343 if (device_receive_frame(pDevice, pRD)) {
1344 if (!device_alloc_rx_buf(pDevice, pRD)) {
1345 dev_err(&pDevice->pcid->dev,
1346 "can not allocate rx buf\n");
1350 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1351 pDevice->dev->last_rx = jiffies;
1354 pDevice->pCurrRD[uIdx] = pRD;
1359 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
1361 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1363 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1364 if (pRDInfo->skb == NULL)
1366 ASSERT(pRDInfo->skb);
1367 pRDInfo->skb->dev = pDevice->dev;
1368 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
1369 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1370 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1372 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1373 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1374 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1375 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1380 bool device_alloc_frag_buf(struct vnt_private *pDevice,
1381 PSDeFragControlBlock pDeF)
1383 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1384 if (pDeF->skb == NULL)
1387 pDeF->skb->dev = pDevice->dev;
1392 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1397 unsigned char byTsr0;
1398 unsigned char byTsr1;
1399 unsigned int uFrameSize, uFIFOHeaderSize;
1400 PSTxBufHead pTxBufHead;
1401 struct net_device_stats *pStats = &pDevice->dev->stats;
1402 struct sk_buff *skb;
1403 unsigned int uNodeIndex;
1404 PSMgmtObject pMgmt = pDevice->pMgmt;
1406 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1407 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1412 byTsr0 = pTD->m_td0TD0.byTSR0;
1413 byTsr1 = pTD->m_td0TD0.byTSR1;
1415 //Only the status of first TD in the chain is correct
1416 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1417 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1418 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1419 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1420 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1421 // Update the statistics based on the Transmit status
1422 // now, we DONT check TSR0_CDH
1424 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1426 (unsigned char *)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1429 BSSvUpdateNodeTxCounter(pDevice,
1431 (unsigned char *)(pTD->pTDInfo->buf),
1435 if (!(byTsr1 & TSR1_TERR)) {
1437 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
1441 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG)
1442 pDevice->s802_11Counter.TransmittedFragmentCount++;
1444 pStats->tx_packets++;
1445 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1447 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
1448 (int)uIdx, byTsr1, byTsr0);
1449 pStats->tx_errors++;
1450 pStats->tx_dropped++;
1454 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1455 if (pDevice->bEnableHostapd) {
1456 pr_debug("tx call back netif..\n");
1457 skb = pTD->pTDInfo->skb;
1458 skb->dev = pDevice->apdev;
1459 skb_reset_mac_header(skb);
1460 skb->pkt_type = PACKET_OTHERHOST;
1461 memset(skb->cb, 0, sizeof(skb->cb));
1466 if (byTsr1 & TSR1_TERR) {
1467 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1468 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
1469 (int)uIdx, byTsr1, byTsr0);
1473 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1474 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1475 unsigned short wAID;
1476 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1478 skb = pTD->pTDInfo->skb;
1479 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1480 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1481 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1482 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1484 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1485 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1486 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1487 pr_debug("tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n",
1489 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1490 pStats->tx_errors--;
1491 pStats->tx_dropped--;
1496 device_free_tx_buf(pDevice, pTD);
1497 pDevice->iTDUsed[uIdx]--;
1501 if (uIdx == TYPE_AC0DMA) {
1502 // RESERV_AC0DMA reserved for relay
1504 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1506 pr_debug(" AC0DMA is Full = %d\n",
1507 pDevice->iTDUsed[uIdx]);
1509 if (netif_queue_stopped(pDevice->dev) && !bFull)
1510 netif_wake_queue(pDevice->dev);
1514 pDevice->apTailTD[uIdx] = pTD;
1519 static void device_error(struct vnt_private *pDevice, unsigned short status)
1521 if (status & ISR_FETALERR) {
1522 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
1524 netif_stop_queue(pDevice->dev);
1525 del_timer(&pDevice->sTimerCommand);
1526 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1527 pDevice->bCmdRunning = false;
1528 MACbShutdown(pDevice->PortOffset);
1533 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
1535 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1536 struct sk_buff *skb = pTDInfo->skb;
1538 // pre-allocated buf_dma can't be unmapped.
1539 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1540 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1544 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1545 dev_kfree_skb_irq(skb);
1547 pTDInfo->skb_dma = 0;
1548 pTDInfo->skb = NULL;
1549 pTDInfo->byFlags = 0;
1552 static int device_open(struct net_device *dev)
1554 struct vnt_private *pDevice = netdev_priv(dev);
1556 #ifdef WPA_SM_Transtatus
1557 extern SWPAResult wpa_Result;
1560 pDevice->rx_buf_sz = PKT_BUF_SZ;
1561 if (!device_init_rings(pDevice))
1564 //2008-5-13 <add> by chester
1565 i = request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1569 #ifdef WPA_SM_Transtatus
1570 memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname));
1571 wpa_Result.proto = 0;
1572 wpa_Result.key_mgmt = 0;
1573 wpa_Result.eap_type = 0;
1574 wpa_Result.authenticated = false;
1575 pDevice->fWPA_Authened = false;
1577 pr_debug("call device init rd0 ring\n");
1578 device_init_rd0_ring(pDevice);
1579 device_init_rd1_ring(pDevice);
1580 device_init_defrag_cb(pDevice);
1581 device_init_td0_ring(pDevice);
1582 device_init_td1_ring(pDevice);
1584 if (pDevice->bDiversityRegCtlON)
1585 device_init_diversity_timer(pDevice);
1587 vMgrObjectInit(pDevice);
1588 vMgrTimerInit(pDevice);
1590 pr_debug("call device_init_registers\n");
1591 device_init_registers(pDevice);
1593 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1594 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN);
1595 device_set_multi(pDevice->dev);
1597 // Init for Key Management
1598 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1599 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1601 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1602 pDevice->bwextcount = 0;
1603 pDevice->bWPASuppWextEnabled = false;
1605 pDevice->byReAssocCount = 0;
1606 pDevice->bWPADEVUp = false;
1607 // Patch: if WEP key already set by iwconfig but device not yet open
1608 if (pDevice->bEncryptionEnable && pDevice->bTransmitKey) {
1609 KeybSetDefaultKey(&(pDevice->sKey),
1610 (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
1611 pDevice->uKeyLength,
1615 pDevice->PortOffset,
1618 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1621 pr_debug("call MACvIntEnable\n");
1622 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1624 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1625 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
1627 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1628 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1630 pDevice->flags |= DEVICE_FLAGS_OPENED;
1632 pr_debug("device_open success..\n");
1636 static int device_close(struct net_device *dev)
1638 struct vnt_private *pDevice = netdev_priv(dev);
1639 PSMgmtObject pMgmt = pDevice->pMgmt;
1640 //2007-1121-02<Add>by EinsnLiu
1641 if (pDevice->bLinkPass) {
1642 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1646 del_timer(&pDevice->sTimerTxData);
1647 del_timer(&pDevice->sTimerCommand);
1648 del_timer(&pMgmt->sTimerSecondCallback);
1649 if (pDevice->bDiversityRegCtlON) {
1650 del_timer(&pDevice->TimerSQ3Tmax1);
1651 del_timer(&pDevice->TimerSQ3Tmax2);
1652 del_timer(&pDevice->TimerSQ3Tmax3);
1655 netif_stop_queue(dev);
1656 pDevice->bCmdRunning = false;
1657 MACbShutdown(pDevice->PortOffset);
1658 MACbSoftwareReset(pDevice->PortOffset);
1659 CARDbRadioPowerOff(pDevice);
1661 pDevice->bLinkPass = false;
1662 memset(pMgmt->abyCurrBSSID, 0, 6);
1663 pMgmt->eCurrState = WMAC_STATE_IDLE;
1664 device_free_td0_ring(pDevice);
1665 device_free_td1_ring(pDevice);
1666 device_free_rd0_ring(pDevice);
1667 device_free_rd1_ring(pDevice);
1668 device_free_frag_buf(pDevice);
1669 device_free_rings(pDevice);
1670 BSSvClearNodeDBTable(pDevice, 0);
1671 free_irq(dev->irq, dev);
1672 pDevice->flags &= (~DEVICE_FLAGS_OPENED);
1673 //2008-0714-01<Add>by chester
1674 device_release_WPADEV(pDevice);
1676 pr_debug("device_close..\n");
1680 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1682 struct vnt_private *pDevice = netdev_priv(dev);
1683 unsigned char *pbMPDU;
1684 unsigned int cbMPDULen = 0;
1686 pr_debug("device_dma0_tx_80211\n");
1687 spin_lock_irq(&pDevice->lock);
1689 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1690 pr_debug("device_dma0_tx_80211, td0 <=0\n");
1691 dev_kfree_skb_irq(skb);
1692 spin_unlock_irq(&pDevice->lock);
1696 if (pDevice->bStopTx0Pkt) {
1697 dev_kfree_skb_irq(skb);
1698 spin_unlock_irq(&pDevice->lock);
1702 cbMPDULen = skb->len;
1705 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
1707 spin_unlock_irq(&pDevice->lock);
1712 bool device_dma0_xmit(struct vnt_private *pDevice,
1713 struct sk_buff *skb, unsigned int uNodeIndex)
1715 PSMgmtObject pMgmt = pDevice->pMgmt;
1716 PSTxDesc pHeadTD, pLastTD;
1717 unsigned int cbFrameBodySize;
1718 unsigned int uMACfragNum;
1719 unsigned char byPktType;
1720 bool bNeedEncryption = false;
1721 PSKeyItem pTransmitKey = NULL;
1722 unsigned int cbHeaderSize;
1726 if (pDevice->bStopTx0Pkt) {
1727 dev_kfree_skb_irq(skb);
1731 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1732 dev_kfree_skb_irq(skb);
1733 pr_debug("device_dma0_xmit, td0 <=0\n");
1737 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1738 if (pDevice->uAssocCount == 0) {
1739 dev_kfree_skb_irq(skb);
1740 pr_debug("device_dma0_xmit, assocCount = 0\n");
1745 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
1747 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1749 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1750 cbFrameBodySize = skb->len - ETH_HLEN;
1753 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1754 cbFrameBodySize += 8;
1756 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
1758 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
1759 dev_kfree_skb_irq(skb);
1762 byPktType = (unsigned char)pDevice->byPacketType;
1764 if (pDevice->bFixRate) {
1765 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
1766 if (pDevice->uConnectionRate >= RATE_11M)
1767 pDevice->wCurrentRate = RATE_11M;
1769 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1771 if (pDevice->uConnectionRate >= RATE_54M)
1772 pDevice->wCurrentRate = RATE_54M;
1774 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1777 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1781 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1782 pDevice->byPreambleType = pDevice->byShortPreamble;
1784 pDevice->byPreambleType = PREAMBLE_LONG;
1786 pr_debug("dma0: pDevice->wCurrentRate = %d\n", pDevice->wCurrentRate);
1788 if (pDevice->wCurrentRate <= RATE_11M) {
1789 byPktType = PK_TYPE_11B;
1790 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1791 byPktType = PK_TYPE_11A;
1793 if (pDevice->bProtectMode)
1794 byPktType = PK_TYPE_11GB;
1796 byPktType = PK_TYPE_11GA;
1799 if (pDevice->bEncryptionEnable)
1800 bNeedEncryption = true;
1802 if (pDevice->bEnableHostWEP) {
1803 pTransmitKey = &STempKey;
1804 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1805 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1806 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1807 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1808 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1809 memcpy(pTransmitKey->abyKey,
1810 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1811 pTransmitKey->uKeyLength
1814 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
1815 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
1816 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
1821 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1823 MACbPSWakeup(pDevice->PortOffset);
1826 pDevice->bPWBitOn = false;
1829 for (ii = 0; ii < uMACfragNum; ii++) {
1830 // Poll Transmit the adapter
1832 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
1834 if (ii == (uMACfragNum - 1))
1836 pHeadTD = pHeadTD->next;
1839 // Save the information needed by the tx interrupt handler
1840 // to complete the Send request
1841 pLastTD->pTDInfo->skb = skb;
1842 pLastTD->pTDInfo->byFlags = 0;
1843 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
1845 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
1847 MACvTransmit0(pDevice->PortOffset);
1852 //TYPE_AC0DMA data tx
1853 static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
1854 struct vnt_private *pDevice = netdev_priv(dev);
1855 PSMgmtObject pMgmt = pDevice->pMgmt;
1856 PSTxDesc pHeadTD, pLastTD;
1857 unsigned int uNodeIndex = 0;
1858 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1859 unsigned short wAID;
1860 unsigned int uMACfragNum = 1;
1861 unsigned int cbFrameBodySize;
1862 unsigned char byPktType;
1863 unsigned int cbHeaderSize;
1864 bool bNeedEncryption = false;
1865 PSKeyItem pTransmitKey = NULL;
1868 bool bTKIP_UseGTK = false;
1869 bool bNeedDeAuth = false;
1870 unsigned char *pbyBSSID;
1871 bool bNodeExist = false;
1873 spin_lock_irq(&pDevice->lock);
1874 if (!pDevice->bLinkPass) {
1875 dev_kfree_skb_irq(skb);
1876 spin_unlock_irq(&pDevice->lock);
1880 if (pDevice->bStopDataPkt) {
1881 dev_kfree_skb_irq(skb);
1882 spin_unlock_irq(&pDevice->lock);
1886 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1887 if (pDevice->uAssocCount == 0) {
1888 dev_kfree_skb_irq(skb);
1889 spin_unlock_irq(&pDevice->lock);
1892 if (is_multicast_ether_addr((unsigned char *)(skb->data))) {
1895 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1896 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1897 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1899 pMgmt->abyPSTxMap[0] |= byMask[0];
1900 spin_unlock_irq(&pDevice->lock);
1904 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1905 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1906 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1907 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1909 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1910 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1911 pr_debug("Set:pMgmt->abyPSTxMap[%d]= %d\n",
1913 pMgmt->abyPSTxMap[wAID >> 3]);
1914 spin_unlock_irq(&pDevice->lock);
1918 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1919 pDevice->byPreambleType = pDevice->byShortPreamble;
1921 pDevice->byPreambleType = PREAMBLE_LONG;
1929 pr_debug("Unknown STA not found in node DB\n");
1930 dev_kfree_skb_irq(skb);
1931 spin_unlock_irq(&pDevice->lock);
1936 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
1938 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1940 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1941 cbFrameBodySize = skb->len - ETH_HLEN;
1943 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1944 cbFrameBodySize += 8;
1946 if (pDevice->bEncryptionEnable) {
1947 bNeedEncryption = true;
1950 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1951 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1952 pbyBSSID = pDevice->abyBSSID;
1954 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
1956 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1957 bTKIP_UseGTK = true;
1958 pr_debug("Get GTK\n");
1962 pr_debug("Get PTK\n");
1965 } else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1966 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
1967 pr_debug("IBSS Serach Key:\n");
1968 for (ii = 0; ii < 6; ii++)
1969 pr_debug("%x\n", *(pbyBSSID+ii));
1973 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
1977 pbyBSSID = pDevice->abyBroadcastAddr;
1978 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
1979 pTransmitKey = NULL;
1980 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
1981 pr_debug("IBSS and KEY is NULL. [%d]\n",
1982 pDevice->pMgmt->eCurrMode);
1984 pr_debug("NOT IBSS and KEY is NULL. [%d]\n",
1985 pDevice->pMgmt->eCurrMode);
1987 bTKIP_UseGTK = true;
1988 pr_debug("Get GTK\n");
1993 if (pDevice->bEnableHostWEP) {
1994 pr_debug("acdma0: STA index %d\n", uNodeIndex);
1995 if (pDevice->bEncryptionEnable) {
1996 pTransmitKey = &STempKey;
1997 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1998 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1999 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2000 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2001 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2002 memcpy(pTransmitKey->abyKey,
2003 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2004 pTransmitKey->uKeyLength
2009 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2011 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2012 pr_debug("uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n",
2014 dev_kfree_skb_irq(skb);
2015 spin_unlock_irq(&pDevice->lock);
2019 if (pTransmitKey != NULL) {
2020 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2021 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2022 uMACfragNum = 1; //WEP256 doesn't support fragment
2026 byPktType = (unsigned char)pDevice->byPacketType;
2028 if (pDevice->bFixRate) {
2029 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2030 if (pDevice->uConnectionRate >= RATE_11M)
2031 pDevice->wCurrentRate = RATE_11M;
2033 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2035 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2036 (pDevice->uConnectionRate <= RATE_6M)) {
2037 pDevice->wCurrentRate = RATE_6M;
2039 if (pDevice->uConnectionRate >= RATE_54M)
2040 pDevice->wCurrentRate = RATE_54M;
2042 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2046 pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate;
2047 pDevice->byTopCCKBasicRate = RATE_1M;
2048 pDevice->byTopOFDMBasicRate = RATE_6M;
2051 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2052 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2053 pDevice->wCurrentRate = RATE_1M;
2054 pDevice->byACKRate = RATE_1M;
2055 pDevice->byTopCCKBasicRate = RATE_1M;
2056 pDevice->byTopOFDMBasicRate = RATE_6M;
2058 pDevice->wCurrentRate = RATE_6M;
2059 pDevice->byACKRate = RATE_6M;
2060 pDevice->byTopCCKBasicRate = RATE_1M;
2061 pDevice->byTopOFDMBasicRate = RATE_6M;
2064 VNTWIFIvGetTxRate(pDevice->pMgmt,
2065 pDevice->sTxEthHeader.abyDstAddr,
2066 &(pDevice->wCurrentRate),
2067 &(pDevice->byACKRate),
2068 &(pDevice->byTopCCKBasicRate),
2069 &(pDevice->byTopOFDMBasicRate));
2075 if (pDevice->wCurrentRate <= RATE_11M) {
2076 byPktType = PK_TYPE_11B;
2077 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2078 byPktType = PK_TYPE_11A;
2080 if (pDevice->bProtectMode)
2081 byPktType = PK_TYPE_11GB;
2083 byPktType = PK_TYPE_11GA;
2086 if (bNeedEncryption) {
2087 pr_debug("ntohs Pkt Type=%04x\n",
2088 ntohs(pDevice->sTxEthHeader.wType));
2089 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2090 bNeedEncryption = false;
2091 pr_debug("Pkt Type=%04x\n",
2092 (pDevice->sTxEthHeader.wType));
2093 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2094 if (pTransmitKey == NULL) {
2095 pr_debug("Don't Find TX KEY\n");
2098 pr_debug("error: KEY is GTK!!~~\n");
2100 pr_debug("Find PTK [%lX]\n",
2101 pTransmitKey->dwKeyIndex);
2102 bNeedEncryption = true;
2107 if (pDevice->byCntMeasure == 2) {
2109 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2112 if (pDevice->bEnableHostWEP) {
2113 if ((uNodeIndex != 0) &&
2114 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2115 pr_debug("Find PTK [%lX]\n",
2116 pTransmitKey->dwKeyIndex);
2117 bNeedEncryption = true;
2121 if (pTransmitKey == NULL) {
2122 pr_debug("return no tx key\n");
2123 dev_kfree_skb_irq(skb);
2124 spin_unlock_irq(&pDevice->lock);
2130 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2131 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2132 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
2137 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2139 MACbPSWakeup(pDevice->PortOffset);
2141 pDevice->bPWBitOn = false;
2144 for (ii = 0; ii < uMACfragNum; ii++) {
2145 // Poll Transmit the adapter
2147 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2149 if (ii == uMACfragNum - 1)
2151 pHeadTD = pHeadTD->next;
2154 // Save the information needed by the tx interrupt handler
2155 // to complete the Send request
2156 pLastTD->pTDInfo->skb = skb;
2157 pLastTD->pTDInfo->byFlags = 0;
2158 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2159 pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
2161 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1)
2162 netif_stop_queue(dev);
2164 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2166 if (pDevice->bFixRate)
2167 pr_debug("FixRate:Rate is %d,TxPower is %d\n", pDevice->wCurrentRate, pDevice->byCurPwr);
2170 unsigned char Protocol_Version; //802.1x Authentication
2171 unsigned char Packet_Type; //802.1x Authentication
2172 unsigned char Descriptor_type;
2173 unsigned short Key_info;
2174 bool bTxeapol_key = false;
2176 Protocol_Version = skb->data[ETH_HLEN];
2177 Packet_Type = skb->data[ETH_HLEN+1];
2178 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2179 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2180 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2181 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2182 (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame transfer
2183 bTxeapol_key = true;
2184 if ((Descriptor_type == 254) || (Descriptor_type == 2)) { //WPA or RSN
2185 if (!(Key_info & BIT3) && //group-key challenge
2186 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2187 pDevice->fWPA_Authened = true;
2188 if (Descriptor_type == 254)
2192 pr_debug("Authentication completed!!\n");
2199 MACvTransmitAC0(pDevice->PortOffset);
2201 dev->trans_start = jiffies;
2203 spin_unlock_irq(&pDevice->lock);
2207 static irqreturn_t device_intr(int irq, void *dev_instance)
2209 struct net_device *dev = dev_instance;
2210 struct vnt_private *pDevice = netdev_priv(dev);
2212 unsigned long dwMIBCounter = 0;
2213 PSMgmtObject pMgmt = pDevice->pMgmt;
2214 unsigned char byOrgPageSel = 0;
2216 unsigned char byData = 0;
2218 unsigned long flags;
2220 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2222 if (pDevice->dwIsr == 0)
2223 return IRQ_RETVAL(handled);
2225 if (pDevice->dwIsr == 0xffffffff) {
2226 pr_debug("dwIsr = 0xffff\n");
2227 return IRQ_RETVAL(handled);
2231 MACvIntDisable(pDevice->PortOffset);
2233 spin_lock_irqsave(&pDevice->lock, flags);
2235 //Make sure current page is 0
2236 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2237 if (byOrgPageSel == 1)
2238 MACvSelectPage0(pDevice->PortOffset);
2242 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2244 // Must do this after doing rx/tx, cause ISR bit is slow
2245 // than RD/TD write back
2246 // update ISR counter
2247 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2248 while (pDevice->dwIsr != 0) {
2249 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2250 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2252 if (pDevice->dwIsr & ISR_FETALERR) {
2253 pr_debug(" ISR_FETALERR\n");
2254 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2255 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2256 device_error(pDevice, pDevice->dwIsr);
2259 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2260 if (pDevice->dwIsr & ISR_MEASURESTART) {
2261 // 802.11h measure start
2262 pDevice->byOrgChannel = pDevice->byCurrentCh;
2263 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2264 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2265 MACvSelectPage1(pDevice->PortOffset);
2266 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2267 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2268 MACvSelectPage0(pDevice->PortOffset);
2270 if (set_channel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel)) {
2271 pDevice->bMeasureInProgress = true;
2272 MACvSelectPage1(pDevice->PortOffset);
2273 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2274 MACvSelectPage0(pDevice->PortOffset);
2275 pDevice->byBasicMap = 0;
2276 pDevice->byCCAFraction = 0;
2277 for (ii = 0; ii < 8; ii++)
2278 pDevice->dwRPIs[ii] = 0;
2281 // can not measure because set channel fail
2282 // clear measure control
2283 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2284 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2285 MACvSelectPage1(pDevice->PortOffset);
2286 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2287 MACvSelectPage0(pDevice->PortOffset);
2290 if (pDevice->dwIsr & ISR_MEASUREEND) {
2291 // 802.11h measure end
2292 pDevice->bMeasureInProgress = false;
2293 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2294 MACvSelectPage1(pDevice->PortOffset);
2295 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2296 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2297 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2298 pDevice->byBasicMap |= (byData >> 4);
2299 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2300 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2301 // clear measure control
2302 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2303 MACvSelectPage0(pDevice->PortOffset);
2304 set_channel(pDevice, pDevice->byOrgChannel);
2305 MACvSelectPage1(pDevice->PortOffset);
2306 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2307 MACvSelectPage0(pDevice->PortOffset);
2308 if (byData & MSRCTL_FINISH) {
2310 s_vCompleteCurrentMeasure(pDevice, 0);
2312 // can not measure because not ready before end of measure time
2313 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2316 if (pDevice->dwIsr & ISR_QUIETSTART) {
2319 } while (!CARDbStartQuiet(pDevice));
2323 if (pDevice->dwIsr & ISR_TBTT) {
2324 if (pDevice->bEnableFirstQuiet) {
2325 pDevice->byQuietStartCount--;
2326 if (pDevice->byQuietStartCount == 0) {
2327 pDevice->bEnableFirstQuiet = false;
2328 MACvSelectPage1(pDevice->PortOffset);
2329 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2330 MACvSelectPage0(pDevice->PortOffset);
2333 if (pDevice->bChannelSwitch &&
2334 (pDevice->op_mode == NL80211_IFTYPE_STATION)) {
2335 pDevice->byChannelSwitchCount--;
2336 if (pDevice->byChannelSwitchCount == 0) {
2337 pDevice->bChannelSwitch = false;
2338 set_channel(pDevice, pDevice->byNewChannel);
2339 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2340 MACvSelectPage1(pDevice->PortOffset);
2341 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2342 MACvSelectPage0(pDevice->PortOffset);
2343 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2347 if (pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
2348 if ((pDevice->bUpdateBBVGA) && pDevice->bLinkPass && (pDevice->uCurrRSSI != 0)) {
2351 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
2352 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
2353 if (ldBm < pDevice->ldBmThreshold[ii]) {
2354 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2358 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2359 pDevice->uBBVGADiffCount++;
2360 if (pDevice->uBBVGADiffCount == 1) {
2361 // first VGA diff gain
2362 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2363 pr_debug("First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2365 pDevice->byBBVGANew,
2366 pDevice->byBBVGACurrent,
2367 (int)pDevice->uBBVGADiffCount);
2369 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2370 pr_debug("RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2372 pDevice->byBBVGANew,
2373 pDevice->byBBVGACurrent,
2374 (int)pDevice->uBBVGADiffCount);
2375 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2378 pDevice->uBBVGADiffCount = 1;
2383 pDevice->bBeaconSent = false;
2384 if (pDevice->bEnablePSMode)
2385 PSbIsNextTBTTWakeUp((void *)pDevice);
2387 if ((pDevice->op_mode == NL80211_IFTYPE_AP) ||
2388 (pDevice->op_mode == NL80211_IFTYPE_ADHOC)) {
2389 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2390 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2393 /* TODO: adhoc PS mode */
2397 if (pDevice->dwIsr & ISR_BNTX) {
2398 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
2399 pDevice->bIsBeaconBufReadySet = false;
2400 pDevice->cbBeaconBufReadySetCnt = 0;
2403 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
2404 if (pMgmt->byDTIMCount > 0) {
2405 pMgmt->byDTIMCount--;
2406 pMgmt->sNodeDBTable[0].bRxPSPoll = false;
2408 if (pMgmt->byDTIMCount == 0) {
2409 // check if mutltcast tx bufferring
2410 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2411 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
2412 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2416 pDevice->bBeaconSent = true;
2418 if (pDevice->bChannelSwitch) {
2419 pDevice->byChannelSwitchCount--;
2420 if (pDevice->byChannelSwitchCount == 0) {
2421 pDevice->bChannelSwitch = false;
2422 set_channel(pDevice, pDevice->byNewChannel);
2423 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2424 MACvSelectPage1(pDevice->PortOffset);
2425 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2426 MACvSelectPage0(pDevice->PortOffset);
2427 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2433 if (pDevice->dwIsr & ISR_RXDMA0)
2434 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2436 if (pDevice->dwIsr & ISR_RXDMA1)
2437 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2439 if (pDevice->dwIsr & ISR_TXDMA0)
2440 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2442 if (pDevice->dwIsr & ISR_AC0DMA)
2443 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2445 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2446 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
2447 if (pDevice->bShortSlotTime)
2448 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2450 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2452 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2453 pDevice->byCntMeasure = 0;
2456 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2458 MACvReceive0(pDevice->PortOffset);
2459 MACvReceive1(pDevice->PortOffset);
2461 if (max_count > pDevice->sOpts.int_works)
2465 if (byOrgPageSel == 1)
2466 MACvSelectPage1(pDevice->PortOffset);
2468 spin_unlock_irqrestore(&pDevice->lock, flags);
2470 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2472 return IRQ_RETVAL(handled);
2475 //2008-8-4 <add> by chester
2476 static int Config_FileGetParameter(unsigned char *string,
2477 unsigned char *dest, unsigned char *source)
2479 unsigned char buf1[100];
2480 int source_len = strlen(source);
2482 memset(buf1, 0, 100);
2483 strcat(buf1, string);
2485 source += strlen(buf1);
2487 memcpy(dest, source, source_len - strlen(buf1));
2491 int Config_FileOperation(struct vnt_private *pDevice,
2492 bool fwrite, unsigned char *Parameter)
2494 unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
2495 unsigned char tmpbuffer[20];
2500 pr_err("allocate mem for file fail?\n");
2503 file = filp_open(CONFIG_PATH, O_RDONLY, 0);
2506 pr_err("Config_FileOperation:open file fail?\n");
2510 if (kernel_read(file, 0, buffer, 1024) < 0) {
2511 pr_err("read file error?\n");
2516 if (Config_FileGetParameter("ZONETYPE", tmpbuffer, buffer) != true) {
2517 pr_err("get parameter error?\n");
2522 if (memcmp(tmpbuffer, "USA", 3) == 0) {
2523 result = ZoneType_USA;
2524 } else if (memcmp(tmpbuffer, "JAPAN", 5) == 0) {
2525 result = ZoneType_Japan;
2526 } else if (memcmp(tmpbuffer, "EUROPE", 5) == 0) {
2527 result = ZoneType_Europe;
2530 pr_err("Unknown Zonetype[%s]?\n", tmpbuffer);
2539 static void device_set_multi(struct net_device *dev) {
2540 struct vnt_private *pDevice = netdev_priv(dev);
2541 PSMgmtObject pMgmt = pDevice->pMgmt;
2543 struct netdev_hw_addr *ha;
2545 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
2547 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
2548 pr_notice("%s: Promiscuous mode enabled\n", dev->name);
2549 /* Unconditionally log net taps. */
2550 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
2551 } else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
2552 || (dev->flags & IFF_ALLMULTI)) {
2553 MACvSelectPage1(pDevice->PortOffset);
2554 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
2555 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
2556 MACvSelectPage0(pDevice->PortOffset);
2557 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2559 memset(mc_filter, 0, sizeof(mc_filter));
2560 netdev_for_each_mc_addr(ha, dev) {
2561 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
2563 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
2565 MACvSelectPage1(pDevice->PortOffset);
2566 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
2567 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
2568 MACvSelectPage0(pDevice->PortOffset);
2569 pDevice->byRxMode &= ~(RCR_UNICAST);
2570 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2573 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2574 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
2575 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2576 pDevice->byRxMode &= ~(RCR_UNICAST);
2579 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
2580 pr_debug("pDevice->byRxMode = %x\n", pDevice->byRxMode);
2583 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2585 struct vnt_private *pDevice = netdev_priv(dev);
2586 struct iwreq *wrq = (struct iwreq *)rq;
2588 PSMgmtObject pMgmt = pDevice->pMgmt;
2591 if (pMgmt == NULL) {
2598 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
2601 case SIOCGIWNWID: //0x8b03 support
2605 // Set frequency/channel
2607 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
2610 // Get frequency/channel
2612 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
2615 // Set desired network name (ESSID)
2619 char essid[IW_ESSID_MAX_SIZE+1];
2621 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
2625 if (copy_from_user(essid, wrq->u.essid.pointer,
2626 wrq->u.essid.length)) {
2630 rc = iwctl_siwessid(dev, NULL,
2631 &(wrq->u.essid), essid);
2635 // Get current network name (ESSID)
2639 char essid[IW_ESSID_MAX_SIZE+1];
2641 if (wrq->u.essid.pointer)
2642 rc = iwctl_giwessid(dev, NULL,
2643 &(wrq->u.essid), essid);
2644 if (copy_to_user(wrq->u.essid.pointer,
2646 wrq->u.essid.length))
2653 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2656 // Get current Access Point (BSSID)
2658 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2661 // Set desired station name
2663 pr_debug(" SIOCSIWNICKN\n");
2667 // Get current station name
2669 pr_debug(" SIOCGIWNICKN\n");
2673 // Set the desired bit-rate
2675 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2678 // Get the current bit-rate
2681 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2684 // Set the desired RTS threshold
2687 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
2690 // Get the current RTS threshold
2693 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
2696 // Set the desired fragmentation threshold
2699 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
2702 // Get the current fragmentation threshold
2705 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
2708 // Set mode of operation
2710 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
2713 // Get mode of operation
2715 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
2718 // Set WEP keys and mode
2719 case SIOCSIWENCODE: {
2720 char abyKey[WLAN_WEP232_KEYLEN];
2722 if (wrq->u.encoding.pointer) {
2723 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
2727 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
2728 if (copy_from_user(abyKey,
2729 wrq->u.encoding.pointer,
2730 wrq->u.encoding.length)) {
2734 } else if (wrq->u.encoding.length != 0) {
2738 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2742 // Get the WEP keys and mode
2745 if (!capable(CAP_NET_ADMIN)) {
2750 char abyKey[WLAN_WEP232_KEYLEN];
2752 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2755 if (wrq->u.encoding.pointer) {
2756 if (copy_to_user(wrq->u.encoding.pointer,
2758 wrq->u.encoding.length))
2764 // Get the current Tx-Power
2766 pr_debug(" SIOCGIWTXPOW\n");
2771 pr_debug(" SIOCSIWTXPOW\n");
2777 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
2782 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
2785 // Get range of parameters
2789 struct iw_range range;
2791 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *)&range);
2792 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
2800 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
2805 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
2810 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
2814 pr_debug(" SIOCSIWSENS\n");
2818 case SIOCGIWAPLIST: {
2819 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
2821 if (wrq->u.data.pointer) {
2822 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
2824 if (copy_to_user(wrq->u.data.pointer,
2826 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
2838 pr_debug(" SIOCSIWSPY\n");
2845 pr_debug(" SIOCGIWSPY\n");
2849 #endif // WIRELESS_SPY
2852 pr_debug(" SIOCGIWPRIV\n");
2856 //2008-0409-07, <Add> by Einsn Liu
2857 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2859 pr_debug(" SIOCSIWAUTH\n");
2860 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
2864 pr_debug(" SIOCGIWAUTH\n");
2865 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
2869 pr_debug(" SIOCSIWGENIE\n");
2870 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2874 pr_debug(" SIOCGIWGENIE\n");
2875 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2878 case SIOCSIWENCODEEXT: {
2879 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
2881 pr_debug(" SIOCSIWENCODEEXT\n");
2882 if (wrq->u.encoding.pointer) {
2883 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN + 1);
2884 if (wrq->u.encoding.length > (sizeof(struct iw_encode_ext) + MAX_KEY_LEN)) {
2888 if (copy_from_user(extra, wrq->u.encoding.pointer, wrq->u.encoding.length)) {
2892 } else if (wrq->u.encoding.length != 0) {
2896 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
2900 case SIOCGIWENCODEEXT:
2901 pr_debug(" SIOCGIWENCODEEXT\n");
2902 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
2906 pr_debug(" SIOCSIWMLME\n");
2907 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2910 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2911 //End Add -- //2008-0409-07, <Add> by Einsn Liu
2913 case IOCTL_CMD_TEST:
2915 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
2921 pReq = (PSCmdRequest)rq;
2922 pReq->wResult = MAGIC_CODE;
2928 if ((((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_EVT) &&
2929 !(pDevice->flags & DEVICE_FLAGS_OPENED))
2931 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
2932 (((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_WPA))
2941 if (test_and_set_bit(0, (void *)&(pMgmt->uCmdBusy)))
2944 rc = private_ioctl(pDevice, rq);
2945 clear_bit(0, (void *)&(pMgmt->uCmdBusy));
2948 case IOCTL_CMD_HOSTAPD:
2950 rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data);
2955 rc = wpa_ioctl(pDevice, &wrq->u.data);
2959 return ethtool_ioctl(dev, rq->ifr_data);
2960 // All other calls are currently unsupported
2964 pr_debug("Ioctl command not support..%x\n", cmd);
2968 if (pDevice->bCommit) {
2969 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2970 netif_stop_queue(pDevice->dev);
2971 spin_lock_irq(&pDevice->lock);
2972 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
2973 spin_unlock_irq(&pDevice->lock);
2975 pr_debug("Commit the settings\n");
2976 spin_lock_irq(&pDevice->lock);
2977 pDevice->bLinkPass = false;
2978 memset(pMgmt->abyCurrBSSID, 0, 6);
2979 pMgmt->eCurrState = WMAC_STATE_IDLE;
2980 netif_stop_queue(pDevice->dev);
2981 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2982 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
2983 if (!pDevice->bWPASuppWextEnabled)
2985 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
2986 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
2987 spin_unlock_irq(&pDevice->lock);
2989 pDevice->bCommit = false;
2995 static int ethtool_ioctl(struct net_device *dev, void __user *useraddr)
2999 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
3003 case ETHTOOL_GDRVINFO: {
3004 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3006 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3007 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3008 if (copy_to_user(useraddr, &info, sizeof(info)))
3018 /*------------------------------------------------------------------*/
3020 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
3022 static struct pci_driver device_driver = {
3023 .name = DEVICE_NAME,
3024 .id_table = vt6655_pci_id_table,
3025 .probe = vt6655_probe,
3026 .remove = vt6655_remove,
3028 .suspend = viawget_suspend,
3029 .resume = viawget_resume,
3033 static int __init vt6655_init_module(void)
3037 ret = pci_register_driver(&device_driver);
3040 register_reboot_notifier(&device_notifier);
3046 static void __exit vt6655_cleanup_module(void)
3049 unregister_reboot_notifier(&device_notifier);
3051 pci_unregister_driver(&device_driver);
3054 module_init(vt6655_init_module);
3055 module_exit(vt6655_cleanup_module);
3059 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3061 struct pci_dev *pdev = NULL;
3067 for_each_pci_dev(pdev) {
3068 if (pci_dev_driver(pdev) == &device_driver) {
3069 if (pci_get_drvdata(pdev))
3070 viawget_suspend(pdev, PMSG_HIBERNATE);
3078 viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3080 int power_status; // to silence the compiler
3082 struct vnt_private *pDevice = pci_get_drvdata(pcid);
3083 PSMgmtObject pMgmt = pDevice->pMgmt;
3085 netif_stop_queue(pDevice->dev);
3086 spin_lock_irq(&pDevice->lock);
3087 pci_save_state(pcid);
3088 del_timer(&pDevice->sTimerCommand);
3089 del_timer(&pMgmt->sTimerSecondCallback);
3090 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3091 pDevice->uCmdDequeueIdx = 0;
3092 pDevice->uCmdEnqueueIdx = 0;
3093 pDevice->bCmdRunning = false;
3094 MACbShutdown(pDevice->PortOffset);
3095 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3096 pDevice->bLinkPass = false;
3097 memset(pMgmt->abyCurrBSSID, 0, 6);
3098 pMgmt->eCurrState = WMAC_STATE_IDLE;
3099 pci_disable_device(pcid);
3100 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3101 spin_unlock_irq(&pDevice->lock);
3106 viawget_resume(struct pci_dev *pcid)
3108 struct vnt_private *pDevice = pci_get_drvdata(pcid);
3109 PSMgmtObject pMgmt = pDevice->pMgmt;
3110 int power_status; // to silence the compiler
3112 power_status = pci_set_power_state(pcid, PCI_D0);
3113 power_status = pci_enable_wake(pcid, PCI_D0, 0);
3114 pci_restore_state(pcid);
3115 if (netif_running(pDevice->dev)) {
3116 spin_lock_irq(&pDevice->lock);
3117 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3118 device_init_registers(pDevice);
3119 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
3120 pMgmt->sNodeDBTable[0].bActive = false;
3121 pDevice->bLinkPass = false;
3122 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3123 // In Adhoc, BSS state set back to started.
3124 pMgmt->eCurrState = WMAC_STATE_STARTED;
3126 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3127 pMgmt->eCurrState = WMAC_STATE_IDLE;
3130 init_timer(&pMgmt->sTimerSecondCallback);
3131 init_timer(&pDevice->sTimerCommand);
3132 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3133 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
3134 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3135 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3136 spin_unlock_irq(&pDevice->lock);