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,
337 POPTIONS pOpts = &(pDevice->sOpts);
339 pOpts->nRxDescs0 = RX_DESC_DEF0;
340 pOpts->nRxDescs1 = RX_DESC_DEF1;
341 pOpts->nTxDescs[0] = TX_DESC_DEF0;
342 pOpts->nTxDescs[1] = TX_DESC_DEF1;
343 pOpts->flags |= DEVICE_FLAGS_IP_ALIGN;
344 pOpts->int_works = INT_WORKS_DEF;
345 pOpts->rts_thresh = RTS_THRESH_DEF;
346 pOpts->frag_thresh = FRAG_THRESH_DEF;
347 pOpts->data_rate = DATA_RATE_DEF;
348 pOpts->channel_num = CHANNEL_DEF;
350 pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE;
351 pOpts->flags |= DEVICE_FLAGS_OP_MODE;
352 pOpts->short_retry = SHORT_RETRY_DEF;
353 pOpts->long_retry = LONG_RETRY_DEF;
354 pOpts->bbp_type = BBP_TYPE_DEF;
355 pOpts->flags |= DEVICE_FLAGS_80211h_MODE;
356 pOpts->flags |= DEVICE_FLAGS_DiversityANT;
360 device_set_options(struct vnt_private *pDevice)
362 unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
363 unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
364 unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
366 memcpy(pDevice->abyBroadcastAddr, abyBroadcastAddr, ETH_ALEN);
367 memcpy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042, ETH_ALEN);
368 memcpy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel, ETH_ALEN);
370 pDevice->uChannel = pDevice->sOpts.channel_num;
371 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
372 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
373 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
374 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
375 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
376 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
377 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
378 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
379 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
380 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
381 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
382 if (pDevice->uConnectionRate < RATE_AUTO)
383 pDevice->bFixRate = true;
384 pDevice->byBBType = pDevice->sOpts.bbp_type;
385 pDevice->byPacketType = pDevice->byBBType;
386 pDevice->byAutoFBCtrl = AUTO_FB_0;
387 pDevice->bUpdateBBVGA = true;
388 pDevice->byFOETuning = 0;
389 pDevice->byPreambleType = 0;
391 pr_debug(" uChannel= %d\n", (int)pDevice->uChannel);
392 pr_debug(" byOpMode= %d\n", (int)pDevice->byOpMode);
393 pr_debug(" ePSMode= %d\n", (int)pDevice->ePSMode);
394 pr_debug(" wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
395 pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
396 pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
397 pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType);
398 pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
399 pr_debug(" uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
400 pr_debug(" byBBType= %d\n", (int)pDevice->byBBType);
401 pr_debug(" pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
402 pr_debug(" pDevice->bDiversityRegCtlON= %d\n",
403 (int)pDevice->bDiversityRegCtlON);
406 static void s_vCompleteCurrentMeasure(struct vnt_private *pDevice,
407 unsigned char byResult)
410 unsigned long dwDuration = 0;
411 unsigned char byRPI0 = 0;
413 for (ii = 1; ii < 8; ii++) {
414 pDevice->dwRPIs[ii] *= 255;
415 dwDuration |= *((unsigned short *)(pDevice->pCurrMeasureEID->sReq.abyDuration));
417 pDevice->dwRPIs[ii] /= dwDuration;
418 pDevice->abyRPIs[ii] = (unsigned char)pDevice->dwRPIs[ii];
419 byRPI0 += pDevice->abyRPIs[ii];
421 pDevice->abyRPIs[0] = (0xFF - byRPI0);
423 if (pDevice->uNumOfMeasureEIDs == 0) {
424 VNTWIFIbMeasureReport(pDevice->pMgmt,
426 pDevice->pCurrMeasureEID,
429 pDevice->byCCAFraction,
433 VNTWIFIbMeasureReport(pDevice->pMgmt,
435 pDevice->pCurrMeasureEID,
438 pDevice->byCCAFraction,
441 CARDbStartMeasure(pDevice, pDevice->pCurrMeasureEID++, pDevice->uNumOfMeasureEIDs);
446 // Initialisation of MAC & BBP registers
449 static void device_init_registers(struct vnt_private *pDevice)
452 unsigned char byValue;
453 unsigned char byValue1;
454 unsigned char byCCKPwrdBm = 0;
455 unsigned char byOFDMPwrdBm = 0;
457 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
459 MACbShutdown(pDevice->PortOffset);
460 BBvSoftwareReset(pDevice->PortOffset);
462 /* Do MACbSoftwareReset in MACvInitialize */
463 MACbSoftwareReset(pDevice->PortOffset);
465 pDevice->bAES = false;
467 /* Only used in 11g type, sync with ERP IE */
468 pDevice->bProtectMode = false;
470 pDevice->bNonERPPresent = false;
471 pDevice->bBarkerPreambleMd = false;
472 pDevice->wCurrentRate = RATE_1M;
473 pDevice->byTopOFDMBasicRate = RATE_24M;
474 pDevice->byTopCCKBasicRate = RATE_1M;
476 /* Target to IF pin while programming to RF chip. */
477 pDevice->byRevId = 0;
480 MACvInitialize(pDevice->PortOffset);
483 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
485 spin_lock_irq(&pDevice->lock);
487 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
489 spin_unlock_irq(&pDevice->lock);
491 /* Get Channel range */
492 pDevice->byMinChannel = 1;
493 pDevice->byMaxChannel = CB_MAX_CHANNEL;
496 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
497 if (byValue & EEP_ANTINV)
498 pDevice->bTxRxAntInv = true;
500 pDevice->bTxRxAntInv = false;
502 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
503 /* if not set default is All */
505 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
507 pDevice->ulDiversityNValue = 100*260;
508 pDevice->ulDiversityMValue = 100*16;
510 pDevice->byTMax2 = 4;
511 pDevice->ulSQ3TH = 0;
512 pDevice->byTMax3 = 64;
514 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
515 pDevice->byAntennaCount = 2;
516 pDevice->byTxAntennaMode = ANT_B;
517 pDevice->dwTxAntennaSel = 1;
518 pDevice->dwRxAntennaSel = 1;
520 if (pDevice->bTxRxAntInv)
521 pDevice->byRxAntennaMode = ANT_A;
523 pDevice->byRxAntennaMode = ANT_B;
525 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset,
528 if ((byValue1 & 0x08) == 0)
529 pDevice->bDiversityEnable = false;
531 pDevice->bDiversityEnable = true;
533 pDevice->bDiversityEnable = false;
534 pDevice->byAntennaCount = 1;
535 pDevice->dwTxAntennaSel = 0;
536 pDevice->dwRxAntennaSel = 0;
538 if (byValue & EEP_ANTENNA_AUX) {
539 pDevice->byTxAntennaMode = ANT_A;
541 if (pDevice->bTxRxAntInv)
542 pDevice->byRxAntennaMode = ANT_B;
544 pDevice->byRxAntennaMode = ANT_A;
546 pDevice->byTxAntennaMode = ANT_B;
548 if (pDevice->bTxRxAntInv)
549 pDevice->byRxAntennaMode = ANT_A;
551 pDevice->byRxAntennaMode = ANT_B;
555 pr_debug("bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
556 pDevice->bDiversityEnable, (int)pDevice->ulDiversityNValue,
557 (int)pDevice->ulDiversityMValue, pDevice->byTMax,
560 /* zonetype initial */
561 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
562 zonetype = Config_FileOperation(pDevice, false, NULL);
565 if ((zonetype == 0) &&
566 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x00)) {
568 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
569 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
571 pr_debug("Init Zone Type :USA\n");
572 } else if ((zonetype == 1) &&
573 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x01)) {
575 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
576 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
577 } else if ((zonetype == 2) &&
578 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x02)) {
580 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
581 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
583 pr_debug("Init Zone Type :Europe\n");
585 if (zonetype != pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
586 pr_debug("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",
588 pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
590 pr_debug("Read Zonetype file success,use default zonetype setting[%02x]\n",
594 pr_debug("Read Zonetype file fail,use default zonetype setting[%02x]\n",
595 SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
599 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
601 /* force change RevID for VT3253 emu */
602 if ((pDevice->byRFType & RF_EMU) != 0)
603 pDevice->byRevId = 0x80;
605 pDevice->byRFType &= RF_MASK;
606 pr_debug("pDevice->byRFType = %x\n", pDevice->byRFType);
608 if (!pDevice->bZoneRegExist)
609 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
611 pr_debug("pDevice->byZoneType = %x\n", pDevice->byZoneType);
616 /* Get Desire Power Value */
617 pDevice->byCurPwr = 0xFF;
618 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
619 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
621 /* Load power Table */
622 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
623 pDevice->abyCCKPwrTbl[ii + 1] =
624 SROMbyReadEmbedded(pDevice->PortOffset,
625 (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
626 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
627 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
629 pDevice->abyOFDMPwrTbl[ii + 1] =
630 SROMbyReadEmbedded(pDevice->PortOffset,
631 (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
632 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
633 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
635 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
636 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
639 /* recover 12,13 ,14channel for EUROPE by 11 channel */
640 if (((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
641 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe)) &&
642 (pDevice->byOriginalZonetype == ZoneType_USA)) {
643 for (ii = 11; ii < 14; ii++) {
644 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
645 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
650 /* Load OFDM A Power Table */
651 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
652 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
653 SROMbyReadEmbedded(pDevice->PortOffset,
654 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
656 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
657 SROMbyReadEmbedded(pDevice->PortOffset,
658 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
661 init_channel_table((void *)pDevice);
663 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
664 MACvSelectPage1(pDevice->PortOffset);
666 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
667 (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
669 MACvSelectPage0(pDevice->PortOffset);
672 /* use relative tx timeout and 802.11i D4 */
673 MACvWordRegBitsOn(pDevice->PortOffset,
674 MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
676 /* set performance parameter by registry */
677 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
678 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
680 /* reset TSF counter */
681 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
682 /* enable TSF counter */
683 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
685 /* initialize BBP registers */
686 BBbVT3253Init(pDevice);
688 if (pDevice->bUpdateBBVGA) {
689 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
690 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
691 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
694 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
695 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
697 pDevice->byCurrentCh = 0;
699 /* Set BB and packet type at the same time. */
700 /* Set Short Slot Time, xIFS, and RSPINF. */
701 if (pDevice->uConnectionRate == RATE_AUTO)
702 pDevice->wCurrentRate = RATE_54M;
704 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
707 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_11G);
708 VNTWIFIbConfigPhyMode(pDevice->pMgmt, PHY_TYPE_AUTO);
710 pDevice->bRadioOff = false;
712 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
714 pDevice->bHWRadioOff = false;
716 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
718 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
720 if (((pDevice->byGPIO & GPIO0_DATA) &&
721 !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
722 (!(pDevice->byGPIO & GPIO0_DATA) &&
723 (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
724 pDevice->bHWRadioOff = true;
727 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
728 CARDbRadioPowerOff(pDevice);
730 pMgmt->eScanType = WMAC_SCAN_PASSIVE;
732 /* get Permanent network address */
733 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
734 pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
736 /* reset Tx pointer */
737 CARDvSafeResetRx(pDevice);
738 /* reset Rx pointer */
739 CARDvSafeResetTx(pDevice);
741 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
742 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
744 pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
747 MACvReceive0(pDevice->PortOffset);
748 MACvReceive1(pDevice->PortOffset);
750 /* start the adapter */
751 MACvStart(pDevice->PortOffset);
753 netif_stop_queue(pDevice->dev);
756 static void device_init_diversity_timer(struct vnt_private *pDevice)
758 init_timer(&pDevice->TimerSQ3Tmax1);
759 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
760 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
761 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
763 init_timer(&pDevice->TimerSQ3Tmax2);
764 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
765 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
766 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
768 init_timer(&pDevice->TimerSQ3Tmax3);
769 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
770 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
771 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
774 static bool device_release_WPADEV(struct vnt_private *pDevice)
776 viawget_wpa_header *wpahdr;
779 //send device close to wpa_supplicnat layer
780 if (pDevice->bWPADEVUp) {
781 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
782 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
783 wpahdr->resp_ie_len = 0;
784 wpahdr->req_ie_len = 0;
785 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
786 pDevice->skb->dev = pDevice->wpadev;
787 skb_reset_mac_header(pDevice->skb);
788 pDevice->skb->pkt_type = PACKET_HOST;
789 pDevice->skb->protocol = htons(ETH_P_802_2);
790 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
791 netif_rx(pDevice->skb);
792 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
794 while (pDevice->bWPADEVUp) {
795 set_current_state(TASK_UNINTERRUPTIBLE);
796 schedule_timeout(HZ / 20); //wait 50ms
805 static const struct net_device_ops device_netdev_ops = {
806 .ndo_open = device_open,
807 .ndo_stop = device_close,
808 .ndo_do_ioctl = device_ioctl,
809 .ndo_start_xmit = device_xmit,
810 .ndo_set_rx_mode = device_set_multi,
814 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
816 static bool bFirst = true;
817 struct net_device *dev = NULL;
818 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
819 struct vnt_private *pDevice;
822 dev = alloc_etherdev(sizeof(*pDevice));
824 pDevice = netdev_priv(dev);
827 pr_err(DEVICE_NAME ": allocate net device failed\n");
831 // Chain it all together
832 SET_NETDEV_DEV(dev, &pcid->dev);
835 pr_notice("%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
836 pr_notice("Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
840 vt6655_init_info(pcid, &pDevice, pChip_info);
843 if (pci_enable_device(pcid)) {
844 device_free_info(pDevice);
847 dev->irq = pcid->irq;
850 pr_debug("Before get pci_info memaddr is %x\n", pDevice->memaddr);
852 if (!device_get_pci_info(pDevice, pcid)) {
853 pr_err(DEVICE_NAME ": Failed to find PCI device.\n");
854 device_free_info(pDevice);
862 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);
874 for (i = 0; address[i]; i++) {
875 pci_read_config_dword(pcid, address[i], &bar);
876 pr_debug("bar %d is %x\n", i, bar);
878 pr_debug("bar %d not implemented\n", i);
881 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
884 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xFFFF);
885 len = len & ~(len - 1);
887 pr_debug("IO space: len in IO %x, BAR %d\n", len, i);
889 len = bar & 0xFFFFFFF0;
892 pr_debug("len in MEM %x, BAR %d\n", len, i);
900 pDevice->PortOffset = ioremap(pDevice->memaddr & PCI_BASE_ADDRESS_MEM_MASK, pDevice->io_size);
902 if (pDevice->PortOffset == NULL) {
903 pr_err(DEVICE_NAME ": Failed to IO remapping ..\n");
904 device_free_info(pDevice);
908 rc = pci_request_regions(pcid, DEVICE_NAME);
910 pr_err(DEVICE_NAME ": Failed to find PCI device\n");
911 device_free_info(pDevice);
915 dev->base_addr = pDevice->ioaddr;
917 if (!MACbSoftwareReset(pDevice->PortOffset)) {
918 pr_err(DEVICE_NAME ": Failed to access MAC hardware..\n");
919 device_free_info(pDevice);
922 // initial to reload eeprom
923 MACvInitialize(pDevice->PortOffset);
924 MACvReadEtherAddress(pDevice->PortOffset, dev->dev_addr);
926 device_get_options(pDevice, dev->name);
927 device_set_options(pDevice);
928 //Mask out the options cannot be set to the chip
929 pDevice->sOpts.flags &= pChip_info->flags;
931 //Enable the chip specified capabilities
932 pDevice->flags = pDevice->sOpts.flags | (pChip_info->flags & 0xFF000000UL);
933 pDevice->tx_80211 = device_dma0_tx_80211;
934 pDevice->sMgmtObj.pAdapter = (void *)pDevice;
935 pDevice->pMgmt = &(pDevice->sMgmtObj);
937 dev->irq = pcid->irq;
938 dev->netdev_ops = &device_netdev_ops;
940 dev->wireless_handlers = (struct iw_handler_def *)&iwctl_handler_def;
942 rc = register_netdev(dev);
944 pr_err(DEVICE_NAME " Failed to register netdev\n");
945 device_free_info(pDevice);
948 device_print_info(pDevice);
949 pci_set_drvdata(pcid, pDevice);
953 static void device_print_info(struct vnt_private *pDevice)
955 struct net_device *dev = pDevice->dev;
957 pr_info("%s: %s\n", dev->name, get_chip_name(pDevice->chip_id));
958 pr_info("%s: MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
959 dev->name, dev->dev_addr, (unsigned long)pDevice->ioaddr,
960 (unsigned long)pDevice->PortOffset, pDevice->dev->irq);
963 static void vt6655_init_info(struct pci_dev *pcid,
964 struct vnt_private **ppDevice,
965 PCHIP_INFO pChip_info)
967 memset(*ppDevice, 0, sizeof(**ppDevice));
969 (*ppDevice)->pcid = pcid;
970 (*ppDevice)->chip_id = pChip_info->chip_id;
971 (*ppDevice)->io_size = pChip_info->io_size;
972 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
973 (*ppDevice)->multicast_limit = 32;
975 spin_lock_init(&((*ppDevice)->lock));
978 static bool device_get_pci_info(struct vnt_private *pDevice,
979 struct pci_dev *pcid)
983 unsigned int cis_addr;
985 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
986 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
987 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
988 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
990 pci_set_master(pcid);
992 pDevice->memaddr = pci_resource_start(pcid, 0);
993 pDevice->ioaddr = pci_resource_start(pcid, 1);
995 cis_addr = pci_resource_start(pcid, 2);
997 pDevice->pcid = pcid;
999 pci_read_config_byte(pcid, PCI_COMMAND, &b);
1000 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
1005 static void device_free_info(struct vnt_private *pDevice)
1007 struct net_device *dev = pDevice->dev;
1010 //2008-0714-01<Add>by chester
1011 device_release_WPADEV(pDevice);
1013 //2008-07-21-01<Add>by MikeLiu
1015 if (wpa_set_wpadev(pDevice, 0) != 0)
1016 pr_err("unregister wpadev fail?\n");
1020 vt6655_hostap_set_hostapd(pDevice, 0, 0);
1023 unregister_netdev(dev);
1025 if (pDevice->PortOffset)
1026 iounmap(pDevice->PortOffset);
1029 pci_release_regions(pDevice->pcid);
1034 static bool device_init_rings(struct vnt_private *pDevice)
1038 /*allocate all RD/TD rings a single pool*/
1039 vir_pool = pci_zalloc_consistent(pDevice->pcid,
1040 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1041 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1042 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1043 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1044 &pDevice->pool_dma);
1045 if (vir_pool == NULL) {
1046 pr_err("%s : allocate desc dma memory failed\n",
1047 pDevice->dev->name);
1051 pDevice->aRD0Ring = vir_pool;
1052 pDevice->aRD1Ring = vir_pool +
1053 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1055 pDevice->rd0_pool_dma = pDevice->pool_dma;
1056 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
1057 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
1059 pDevice->tx0_bufs = pci_zalloc_consistent(pDevice->pcid,
1060 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1061 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1062 CB_BEACON_BUF_SIZE +
1064 &pDevice->tx_bufs_dma0);
1065 if (pDevice->tx0_bufs == NULL) {
1066 pr_err("%s: allocate buf dma memory failed\n",
1067 pDevice->dev->name);
1068 pci_free_consistent(pDevice->pcid,
1069 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
1070 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
1071 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
1072 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
1073 vir_pool, pDevice->pool_dma
1078 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
1079 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1081 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
1082 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1084 // vir_pool: pvoid type
1085 pDevice->apTD0Rings = vir_pool
1086 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1087 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
1089 pDevice->apTD1Rings = vir_pool
1090 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
1091 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
1092 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
1094 pDevice->tx1_bufs = pDevice->tx0_bufs +
1095 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1097 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
1098 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1100 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
1103 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
1104 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
1106 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
1107 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
1112 static void device_free_rings(struct vnt_private *pDevice)
1114 pci_free_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)
1120 pDevice->aRD0Ring, pDevice->pool_dma
1123 if (pDevice->tx0_bufs)
1124 pci_free_consistent(pDevice->pcid,
1125 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
1126 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
1127 CB_BEACON_BUF_SIZE +
1129 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
1133 static void device_init_rd0_ring(struct vnt_private *pDevice)
1136 dma_addr_t curr = pDevice->rd0_pool_dma;
1139 /* Init the RD0 ring entries */
1140 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
1141 pDesc = &(pDevice->aRD0Ring[i]);
1142 pDesc->pRDInfo = alloc_rd_info();
1143 ASSERT(pDesc->pRDInfo);
1144 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1145 pr_err("%s: can not alloc rx bufs\n",
1146 pDevice->dev->name);
1148 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1149 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1150 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1154 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1155 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1158 static void device_init_rd1_ring(struct vnt_private *pDevice)
1161 dma_addr_t curr = pDevice->rd1_pool_dma;
1164 /* Init the RD1 ring entries */
1165 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1166 pDesc = &(pDevice->aRD1Ring[i]);
1167 pDesc->pRDInfo = alloc_rd_info();
1168 ASSERT(pDesc->pRDInfo);
1169 if (!device_alloc_rx_buf(pDevice, pDesc)) {
1170 pr_err("%s: can not alloc rx bufs\n",
1171 pDevice->dev->name);
1173 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1174 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1175 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1179 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1180 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1183 static void device_init_defrag_cb(struct vnt_private *pDevice)
1186 PSDeFragControlBlock pDeF;
1188 /* Init the fragment ctl entries */
1189 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1190 pDeF = &(pDevice->sRxDFCB[i]);
1191 if (!device_alloc_frag_buf(pDevice, pDeF)) {
1192 pr_err("%s: can not alloc frag bufs\n",
1193 pDevice->dev->name);
1196 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1197 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1200 static void device_free_rd0_ring(struct vnt_private *pDevice)
1204 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1205 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
1206 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1208 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1209 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1211 dev_kfree_skb(pRDInfo->skb);
1213 kfree((void *)pDesc->pRDInfo);
1217 static void device_free_rd1_ring(struct vnt_private *pDevice)
1221 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1222 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
1223 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1225 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1226 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1228 dev_kfree_skb(pRDInfo->skb);
1230 kfree((void *)pDesc->pRDInfo);
1234 static void device_free_frag_buf(struct vnt_private *pDevice)
1236 PSDeFragControlBlock pDeF;
1239 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1240 pDeF = &(pDevice->sRxDFCB[i]);
1243 dev_kfree_skb(pDeF->skb);
1248 static void device_init_td0_ring(struct vnt_private *pDevice)
1254 curr = pDevice->td0_pool_dma;
1255 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1256 pDesc = &(pDevice->apTD0Rings[i]);
1257 pDesc->pTDInfo = alloc_td_info();
1258 ASSERT(pDesc->pTDInfo);
1259 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1260 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1261 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1263 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1264 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1265 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1269 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1270 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1273 static void device_init_td1_ring(struct vnt_private *pDevice)
1279 /* Init the TD ring entries */
1280 curr = pDevice->td1_pool_dma;
1281 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
1282 pDesc = &(pDevice->apTD1Rings[i]);
1283 pDesc->pTDInfo = alloc_td_info();
1284 ASSERT(pDesc->pTDInfo);
1285 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1286 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
1287 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
1289 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
1290 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1291 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1295 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1296 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1299 static void device_free_td0_ring(struct vnt_private *pDevice)
1303 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1304 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
1305 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1307 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1308 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1309 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1312 dev_kfree_skb(pTDInfo->skb);
1314 kfree((void *)pDesc->pTDInfo);
1318 static void device_free_td1_ring(struct vnt_private *pDevice)
1322 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1323 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
1324 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1326 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1327 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1328 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1331 dev_kfree_skb(pTDInfo->skb);
1333 kfree((void *)pDesc->pTDInfo);
1337 /*-----------------------------------------------------------------*/
1339 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1344 for (pRD = pDevice->pCurrRD[uIdx];
1345 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1349 if (device_receive_frame(pDevice, pRD)) {
1350 if (!device_alloc_rx_buf(pDevice, pRD)) {
1351 pr_err("%s: can not allocate rx buf\n",
1352 pDevice->dev->name);
1356 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1357 pDevice->dev->last_rx = jiffies;
1360 pDevice->pCurrRD[uIdx] = pRD;
1365 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
1367 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1369 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1370 if (pRDInfo->skb == NULL)
1372 ASSERT(pRDInfo->skb);
1373 pRDInfo->skb->dev = pDevice->dev;
1374 pRDInfo->skb_dma = pci_map_single(pDevice->pcid, skb_tail_pointer(pRDInfo->skb),
1375 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1376 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1378 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1379 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1380 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1381 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1386 bool device_alloc_frag_buf(struct vnt_private *pDevice,
1387 PSDeFragControlBlock pDeF)
1389 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1390 if (pDeF->skb == NULL)
1393 pDeF->skb->dev = pDevice->dev;
1398 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1403 unsigned char byTsr0;
1404 unsigned char byTsr1;
1405 unsigned int uFrameSize, uFIFOHeaderSize;
1406 PSTxBufHead pTxBufHead;
1407 struct net_device_stats *pStats = &pDevice->dev->stats;
1408 struct sk_buff *skb;
1409 unsigned int uNodeIndex;
1410 PSMgmtObject pMgmt = pDevice->pMgmt;
1412 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1413 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1418 byTsr0 = pTD->m_td0TD0.byTSR0;
1419 byTsr1 = pTD->m_td0TD0.byTSR1;
1421 //Only the status of first TD in the chain is correct
1422 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1423 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1424 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1425 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1426 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1427 // Update the statistics based on the Transmit status
1428 // now, we DONT check TSR0_CDH
1430 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1432 (unsigned char *)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1435 BSSvUpdateNodeTxCounter(pDevice,
1437 (unsigned char *)(pTD->pTDInfo->buf),
1441 if (!(byTsr1 & TSR1_TERR)) {
1443 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
1447 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG)
1448 pDevice->s802_11Counter.TransmittedFragmentCount++;
1450 pStats->tx_packets++;
1451 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1453 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
1454 (int)uIdx, byTsr1, byTsr0);
1455 pStats->tx_errors++;
1456 pStats->tx_dropped++;
1460 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1461 if (pDevice->bEnableHostapd) {
1462 pr_debug("tx call back netif..\n");
1463 skb = pTD->pTDInfo->skb;
1464 skb->dev = pDevice->apdev;
1465 skb_reset_mac_header(skb);
1466 skb->pkt_type = PACKET_OTHERHOST;
1467 memset(skb->cb, 0, sizeof(skb->cb));
1472 if (byTsr1 & TSR1_TERR) {
1473 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1474 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
1475 (int)uIdx, byTsr1, byTsr0);
1479 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1480 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1481 unsigned short wAID;
1482 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1484 skb = pTD->pTDInfo->skb;
1485 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1486 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1487 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1488 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1490 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1491 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1492 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1493 pr_debug("tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n",
1495 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1496 pStats->tx_errors--;
1497 pStats->tx_dropped--;
1502 device_free_tx_buf(pDevice, pTD);
1503 pDevice->iTDUsed[uIdx]--;
1507 if (uIdx == TYPE_AC0DMA) {
1508 // RESERV_AC0DMA reserved for relay
1510 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1512 pr_debug(" AC0DMA is Full = %d\n",
1513 pDevice->iTDUsed[uIdx]);
1515 if (netif_queue_stopped(pDevice->dev) && !bFull)
1516 netif_wake_queue(pDevice->dev);
1520 pDevice->apTailTD[uIdx] = pTD;
1525 static void device_error(struct vnt_private *pDevice, unsigned short status)
1527 if (status & ISR_FETALERR) {
1528 pr_err("%s: Hardware fatal error\n", pDevice->dev->name);
1529 netif_stop_queue(pDevice->dev);
1530 del_timer(&pDevice->sTimerCommand);
1531 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1532 pDevice->bCmdRunning = false;
1533 MACbShutdown(pDevice->PortOffset);
1538 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
1540 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1541 struct sk_buff *skb = pTDInfo->skb;
1543 // pre-allocated buf_dma can't be unmapped.
1544 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1545 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1549 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1550 dev_kfree_skb_irq(skb);
1552 pTDInfo->skb_dma = 0;
1553 pTDInfo->skb = NULL;
1554 pTDInfo->byFlags = 0;
1557 static int device_open(struct net_device *dev)
1559 struct vnt_private *pDevice = netdev_priv(dev);
1561 #ifdef WPA_SM_Transtatus
1562 extern SWPAResult wpa_Result;
1565 pDevice->rx_buf_sz = PKT_BUF_SZ;
1566 if (!device_init_rings(pDevice))
1569 //2008-5-13 <add> by chester
1570 i = request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1574 #ifdef WPA_SM_Transtatus
1575 memset(wpa_Result.ifname, 0, sizeof(wpa_Result.ifname));
1576 wpa_Result.proto = 0;
1577 wpa_Result.key_mgmt = 0;
1578 wpa_Result.eap_type = 0;
1579 wpa_Result.authenticated = false;
1580 pDevice->fWPA_Authened = false;
1582 pr_debug("call device init rd0 ring\n");
1583 device_init_rd0_ring(pDevice);
1584 device_init_rd1_ring(pDevice);
1585 device_init_defrag_cb(pDevice);
1586 device_init_td0_ring(pDevice);
1587 device_init_td1_ring(pDevice);
1589 if (pDevice->bDiversityRegCtlON)
1590 device_init_diversity_timer(pDevice);
1592 vMgrObjectInit(pDevice);
1593 vMgrTimerInit(pDevice);
1595 pr_debug("call device_init_registers\n");
1596 device_init_registers(pDevice);
1598 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1599 memcpy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr, ETH_ALEN);
1600 device_set_multi(pDevice->dev);
1602 // Init for Key Management
1603 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1604 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1606 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1607 pDevice->bwextcount = 0;
1608 pDevice->bWPASuppWextEnabled = false;
1610 pDevice->byReAssocCount = 0;
1611 pDevice->bWPADEVUp = false;
1612 // Patch: if WEP key already set by iwconfig but device not yet open
1613 if (pDevice->bEncryptionEnable && pDevice->bTransmitKey) {
1614 KeybSetDefaultKey(&(pDevice->sKey),
1615 (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
1616 pDevice->uKeyLength,
1620 pDevice->PortOffset,
1623 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1626 pr_debug("call MACvIntEnable\n");
1627 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1629 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1630 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
1632 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1633 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1635 pDevice->flags |= DEVICE_FLAGS_OPENED;
1637 pr_debug("device_open success..\n");
1641 static int device_close(struct net_device *dev)
1643 struct vnt_private *pDevice = netdev_priv(dev);
1644 PSMgmtObject pMgmt = pDevice->pMgmt;
1645 //2007-1121-02<Add>by EinsnLiu
1646 if (pDevice->bLinkPass) {
1647 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1651 del_timer(&pDevice->sTimerTxData);
1652 del_timer(&pDevice->sTimerCommand);
1653 del_timer(&pMgmt->sTimerSecondCallback);
1654 if (pDevice->bDiversityRegCtlON) {
1655 del_timer(&pDevice->TimerSQ3Tmax1);
1656 del_timer(&pDevice->TimerSQ3Tmax2);
1657 del_timer(&pDevice->TimerSQ3Tmax3);
1660 netif_stop_queue(dev);
1661 pDevice->bCmdRunning = false;
1662 MACbShutdown(pDevice->PortOffset);
1663 MACbSoftwareReset(pDevice->PortOffset);
1664 CARDbRadioPowerOff(pDevice);
1666 pDevice->bLinkPass = false;
1667 memset(pMgmt->abyCurrBSSID, 0, 6);
1668 pMgmt->eCurrState = WMAC_STATE_IDLE;
1669 device_free_td0_ring(pDevice);
1670 device_free_td1_ring(pDevice);
1671 device_free_rd0_ring(pDevice);
1672 device_free_rd1_ring(pDevice);
1673 device_free_frag_buf(pDevice);
1674 device_free_rings(pDevice);
1675 BSSvClearNodeDBTable(pDevice, 0);
1676 free_irq(dev->irq, dev);
1677 pDevice->flags &= (~DEVICE_FLAGS_OPENED);
1678 //2008-0714-01<Add>by chester
1679 device_release_WPADEV(pDevice);
1681 pr_debug("device_close..\n");
1685 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1687 struct vnt_private *pDevice = netdev_priv(dev);
1688 unsigned char *pbMPDU;
1689 unsigned int cbMPDULen = 0;
1691 pr_debug("device_dma0_tx_80211\n");
1692 spin_lock_irq(&pDevice->lock);
1694 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1695 pr_debug("device_dma0_tx_80211, td0 <=0\n");
1696 dev_kfree_skb_irq(skb);
1697 spin_unlock_irq(&pDevice->lock);
1701 if (pDevice->bStopTx0Pkt) {
1702 dev_kfree_skb_irq(skb);
1703 spin_unlock_irq(&pDevice->lock);
1707 cbMPDULen = skb->len;
1710 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
1712 spin_unlock_irq(&pDevice->lock);
1717 bool device_dma0_xmit(struct vnt_private *pDevice,
1718 struct sk_buff *skb, unsigned int uNodeIndex)
1720 PSMgmtObject pMgmt = pDevice->pMgmt;
1721 PSTxDesc pHeadTD, pLastTD;
1722 unsigned int cbFrameBodySize;
1723 unsigned int uMACfragNum;
1724 unsigned char byPktType;
1725 bool bNeedEncryption = false;
1726 PSKeyItem pTransmitKey = NULL;
1727 unsigned int cbHeaderSize;
1731 if (pDevice->bStopTx0Pkt) {
1732 dev_kfree_skb_irq(skb);
1736 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1737 dev_kfree_skb_irq(skb);
1738 pr_debug("device_dma0_xmit, td0 <=0\n");
1742 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1743 if (pDevice->uAssocCount == 0) {
1744 dev_kfree_skb_irq(skb);
1745 pr_debug("device_dma0_xmit, assocCount = 0\n");
1750 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
1752 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1754 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1755 cbFrameBodySize = skb->len - ETH_HLEN;
1758 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1759 cbFrameBodySize += 8;
1761 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
1763 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
1764 dev_kfree_skb_irq(skb);
1767 byPktType = (unsigned char)pDevice->byPacketType;
1769 if (pDevice->bFixRate) {
1770 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
1771 if (pDevice->uConnectionRate >= RATE_11M)
1772 pDevice->wCurrentRate = RATE_11M;
1774 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1776 if (pDevice->uConnectionRate >= RATE_54M)
1777 pDevice->wCurrentRate = RATE_54M;
1779 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1782 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1786 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1787 pDevice->byPreambleType = pDevice->byShortPreamble;
1789 pDevice->byPreambleType = PREAMBLE_LONG;
1791 pr_debug("dma0: pDevice->wCurrentRate = %d\n", pDevice->wCurrentRate);
1793 if (pDevice->wCurrentRate <= RATE_11M) {
1794 byPktType = PK_TYPE_11B;
1795 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1796 byPktType = PK_TYPE_11A;
1798 if (pDevice->bProtectMode)
1799 byPktType = PK_TYPE_11GB;
1801 byPktType = PK_TYPE_11GA;
1804 if (pDevice->bEncryptionEnable)
1805 bNeedEncryption = true;
1807 if (pDevice->bEnableHostWEP) {
1808 pTransmitKey = &STempKey;
1809 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1810 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1811 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1812 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1813 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1814 memcpy(pTransmitKey->abyKey,
1815 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1816 pTransmitKey->uKeyLength
1819 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
1820 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
1821 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
1826 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1828 MACbPSWakeup(pDevice->PortOffset);
1831 pDevice->bPWBitOn = false;
1834 for (ii = 0; ii < uMACfragNum; ii++) {
1835 // Poll Transmit the adapter
1837 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
1839 if (ii == (uMACfragNum - 1))
1841 pHeadTD = pHeadTD->next;
1844 // Save the information needed by the tx interrupt handler
1845 // to complete the Send request
1846 pLastTD->pTDInfo->skb = skb;
1847 pLastTD->pTDInfo->byFlags = 0;
1848 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
1850 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
1852 MACvTransmit0(pDevice->PortOffset);
1857 //TYPE_AC0DMA data tx
1858 static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
1859 struct vnt_private *pDevice = netdev_priv(dev);
1860 PSMgmtObject pMgmt = pDevice->pMgmt;
1861 PSTxDesc pHeadTD, pLastTD;
1862 unsigned int uNodeIndex = 0;
1863 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1864 unsigned short wAID;
1865 unsigned int uMACfragNum = 1;
1866 unsigned int cbFrameBodySize;
1867 unsigned char byPktType;
1868 unsigned int cbHeaderSize;
1869 bool bNeedEncryption = false;
1870 PSKeyItem pTransmitKey = NULL;
1873 bool bTKIP_UseGTK = false;
1874 bool bNeedDeAuth = false;
1875 unsigned char *pbyBSSID;
1876 bool bNodeExist = false;
1878 spin_lock_irq(&pDevice->lock);
1879 if (!pDevice->bLinkPass) {
1880 dev_kfree_skb_irq(skb);
1881 spin_unlock_irq(&pDevice->lock);
1885 if (pDevice->bStopDataPkt) {
1886 dev_kfree_skb_irq(skb);
1887 spin_unlock_irq(&pDevice->lock);
1891 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1892 if (pDevice->uAssocCount == 0) {
1893 dev_kfree_skb_irq(skb);
1894 spin_unlock_irq(&pDevice->lock);
1897 if (is_multicast_ether_addr((unsigned char *)(skb->data))) {
1900 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1901 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1902 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1904 pMgmt->abyPSTxMap[0] |= byMask[0];
1905 spin_unlock_irq(&pDevice->lock);
1909 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1910 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1911 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1912 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1914 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1915 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1916 pr_debug("Set:pMgmt->abyPSTxMap[%d]= %d\n",
1918 pMgmt->abyPSTxMap[wAID >> 3]);
1919 spin_unlock_irq(&pDevice->lock);
1923 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1924 pDevice->byPreambleType = pDevice->byShortPreamble;
1926 pDevice->byPreambleType = PREAMBLE_LONG;
1934 pr_debug("Unknown STA not found in node DB\n");
1935 dev_kfree_skb_irq(skb);
1936 spin_unlock_irq(&pDevice->lock);
1941 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
1943 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1945 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1946 cbFrameBodySize = skb->len - ETH_HLEN;
1948 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1949 cbFrameBodySize += 8;
1951 if (pDevice->bEncryptionEnable) {
1952 bNeedEncryption = true;
1955 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1956 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1957 pbyBSSID = pDevice->abyBSSID;
1959 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
1961 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1962 bTKIP_UseGTK = true;
1963 pr_debug("Get GTK\n");
1967 pr_debug("Get PTK\n");
1970 } else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1971 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
1972 pr_debug("IBSS Serach Key:\n");
1973 for (ii = 0; ii < 6; ii++)
1974 pr_debug("%x\n", *(pbyBSSID+ii));
1978 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
1982 pbyBSSID = pDevice->abyBroadcastAddr;
1983 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
1984 pTransmitKey = NULL;
1985 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
1986 pr_debug("IBSS and KEY is NULL. [%d]\n",
1987 pDevice->pMgmt->eCurrMode);
1989 pr_debug("NOT IBSS and KEY is NULL. [%d]\n",
1990 pDevice->pMgmt->eCurrMode);
1992 bTKIP_UseGTK = true;
1993 pr_debug("Get GTK\n");
1998 if (pDevice->bEnableHostWEP) {
1999 pr_debug("acdma0: STA index %d\n", uNodeIndex);
2000 if (pDevice->bEncryptionEnable) {
2001 pTransmitKey = &STempKey;
2002 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
2003 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
2004 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
2005 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
2006 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
2007 memcpy(pTransmitKey->abyKey,
2008 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
2009 pTransmitKey->uKeyLength
2014 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
2016 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
2017 pr_debug("uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n",
2019 dev_kfree_skb_irq(skb);
2020 spin_unlock_irq(&pDevice->lock);
2024 if (pTransmitKey != NULL) {
2025 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
2026 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
2027 uMACfragNum = 1; //WEP256 doesn't support fragment
2031 byPktType = (unsigned char)pDevice->byPacketType;
2033 if (pDevice->bFixRate) {
2034 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
2035 if (pDevice->uConnectionRate >= RATE_11M)
2036 pDevice->wCurrentRate = RATE_11M;
2038 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2040 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
2041 (pDevice->uConnectionRate <= RATE_6M)) {
2042 pDevice->wCurrentRate = RATE_6M;
2044 if (pDevice->uConnectionRate >= RATE_54M)
2045 pDevice->wCurrentRate = RATE_54M;
2047 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
2051 pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate;
2052 pDevice->byTopCCKBasicRate = RATE_1M;
2053 pDevice->byTopOFDMBasicRate = RATE_6M;
2056 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2057 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
2058 pDevice->wCurrentRate = RATE_1M;
2059 pDevice->byACKRate = RATE_1M;
2060 pDevice->byTopCCKBasicRate = RATE_1M;
2061 pDevice->byTopOFDMBasicRate = RATE_6M;
2063 pDevice->wCurrentRate = RATE_6M;
2064 pDevice->byACKRate = RATE_6M;
2065 pDevice->byTopCCKBasicRate = RATE_1M;
2066 pDevice->byTopOFDMBasicRate = RATE_6M;
2069 VNTWIFIvGetTxRate(pDevice->pMgmt,
2070 pDevice->sTxEthHeader.abyDstAddr,
2071 &(pDevice->wCurrentRate),
2072 &(pDevice->byACKRate),
2073 &(pDevice->byTopCCKBasicRate),
2074 &(pDevice->byTopOFDMBasicRate));
2080 if (pDevice->wCurrentRate <= RATE_11M) {
2081 byPktType = PK_TYPE_11B;
2082 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
2083 byPktType = PK_TYPE_11A;
2085 if (pDevice->bProtectMode)
2086 byPktType = PK_TYPE_11GB;
2088 byPktType = PK_TYPE_11GA;
2091 if (bNeedEncryption) {
2092 pr_debug("ntohs Pkt Type=%04x\n",
2093 ntohs(pDevice->sTxEthHeader.wType));
2094 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
2095 bNeedEncryption = false;
2096 pr_debug("Pkt Type=%04x\n",
2097 (pDevice->sTxEthHeader.wType));
2098 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
2099 if (pTransmitKey == NULL) {
2100 pr_debug("Don't Find TX KEY\n");
2103 pr_debug("error: KEY is GTK!!~~\n");
2105 pr_debug("Find PTK [%lX]\n",
2106 pTransmitKey->dwKeyIndex);
2107 bNeedEncryption = true;
2112 if (pDevice->byCntMeasure == 2) {
2114 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
2117 if (pDevice->bEnableHostWEP) {
2118 if ((uNodeIndex != 0) &&
2119 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
2120 pr_debug("Find PTK [%lX]\n",
2121 pTransmitKey->dwKeyIndex);
2122 bNeedEncryption = true;
2126 if (pTransmitKey == NULL) {
2127 pr_debug("return no tx key\n");
2128 dev_kfree_skb_irq(skb);
2129 spin_unlock_irq(&pDevice->lock);
2135 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
2136 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
2137 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
2142 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
2144 MACbPSWakeup(pDevice->PortOffset);
2146 pDevice->bPWBitOn = false;
2149 for (ii = 0; ii < uMACfragNum; ii++) {
2150 // Poll Transmit the adapter
2152 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2154 if (ii == uMACfragNum - 1)
2156 pHeadTD = pHeadTD->next;
2159 // Save the information needed by the tx interrupt handler
2160 // to complete the Send request
2161 pLastTD->pTDInfo->skb = skb;
2162 pLastTD->pTDInfo->byFlags = 0;
2163 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2164 pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
2166 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1)
2167 netif_stop_queue(dev);
2169 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2171 if (pDevice->bFixRate)
2172 pr_debug("FixRate:Rate is %d,TxPower is %d\n", pDevice->wCurrentRate, pDevice->byCurPwr);
2175 unsigned char Protocol_Version; //802.1x Authentication
2176 unsigned char Packet_Type; //802.1x Authentication
2177 unsigned char Descriptor_type;
2178 unsigned short Key_info;
2179 bool bTxeapol_key = false;
2181 Protocol_Version = skb->data[ETH_HLEN];
2182 Packet_Type = skb->data[ETH_HLEN+1];
2183 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2184 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2185 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2186 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2187 (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame transfer
2188 bTxeapol_key = true;
2189 if ((Descriptor_type == 254) || (Descriptor_type == 2)) { //WPA or RSN
2190 if (!(Key_info & BIT3) && //group-key challenge
2191 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2192 pDevice->fWPA_Authened = true;
2193 if (Descriptor_type == 254)
2197 pr_debug("Authentication completed!!\n");
2204 MACvTransmitAC0(pDevice->PortOffset);
2206 dev->trans_start = jiffies;
2208 spin_unlock_irq(&pDevice->lock);
2212 static irqreturn_t device_intr(int irq, void *dev_instance)
2214 struct net_device *dev = dev_instance;
2215 struct vnt_private *pDevice = netdev_priv(dev);
2217 unsigned long dwMIBCounter = 0;
2218 PSMgmtObject pMgmt = pDevice->pMgmt;
2219 unsigned char byOrgPageSel = 0;
2221 unsigned char byData = 0;
2223 unsigned long flags;
2225 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2227 if (pDevice->dwIsr == 0)
2228 return IRQ_RETVAL(handled);
2230 if (pDevice->dwIsr == 0xffffffff) {
2231 pr_debug("dwIsr = 0xffff\n");
2232 return IRQ_RETVAL(handled);
2236 MACvIntDisable(pDevice->PortOffset);
2238 spin_lock_irqsave(&pDevice->lock, flags);
2240 //Make sure current page is 0
2241 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2242 if (byOrgPageSel == 1)
2243 MACvSelectPage0(pDevice->PortOffset);
2247 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2249 // Must do this after doing rx/tx, cause ISR bit is slow
2250 // than RD/TD write back
2251 // update ISR counter
2252 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2253 while (pDevice->dwIsr != 0) {
2254 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2255 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2257 if (pDevice->dwIsr & ISR_FETALERR) {
2258 pr_debug(" ISR_FETALERR\n");
2259 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2260 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2261 device_error(pDevice, pDevice->dwIsr);
2264 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2265 if (pDevice->dwIsr & ISR_MEASURESTART) {
2266 // 802.11h measure start
2267 pDevice->byOrgChannel = pDevice->byCurrentCh;
2268 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2269 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2270 MACvSelectPage1(pDevice->PortOffset);
2271 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2272 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2273 MACvSelectPage0(pDevice->PortOffset);
2275 if (set_channel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel)) {
2276 pDevice->bMeasureInProgress = true;
2277 MACvSelectPage1(pDevice->PortOffset);
2278 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2279 MACvSelectPage0(pDevice->PortOffset);
2280 pDevice->byBasicMap = 0;
2281 pDevice->byCCAFraction = 0;
2282 for (ii = 0; ii < 8; ii++)
2283 pDevice->dwRPIs[ii] = 0;
2286 // can not measure because set channel fail
2287 // clear measure control
2288 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2289 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2290 MACvSelectPage1(pDevice->PortOffset);
2291 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2292 MACvSelectPage0(pDevice->PortOffset);
2295 if (pDevice->dwIsr & ISR_MEASUREEND) {
2296 // 802.11h measure end
2297 pDevice->bMeasureInProgress = false;
2298 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2299 MACvSelectPage1(pDevice->PortOffset);
2300 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2301 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2302 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2303 pDevice->byBasicMap |= (byData >> 4);
2304 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2305 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2306 // clear measure control
2307 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2308 MACvSelectPage0(pDevice->PortOffset);
2309 set_channel(pDevice, pDevice->byOrgChannel);
2310 MACvSelectPage1(pDevice->PortOffset);
2311 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2312 MACvSelectPage0(pDevice->PortOffset);
2313 if (byData & MSRCTL_FINISH) {
2315 s_vCompleteCurrentMeasure(pDevice, 0);
2317 // can not measure because not ready before end of measure time
2318 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2321 if (pDevice->dwIsr & ISR_QUIETSTART) {
2324 } while (!CARDbStartQuiet(pDevice));
2328 if (pDevice->dwIsr & ISR_TBTT) {
2329 if (pDevice->bEnableFirstQuiet) {
2330 pDevice->byQuietStartCount--;
2331 if (pDevice->byQuietStartCount == 0) {
2332 pDevice->bEnableFirstQuiet = false;
2333 MACvSelectPage1(pDevice->PortOffset);
2334 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2335 MACvSelectPage0(pDevice->PortOffset);
2338 if (pDevice->bChannelSwitch &&
2339 (pDevice->op_mode == NL80211_IFTYPE_STATION)) {
2340 pDevice->byChannelSwitchCount--;
2341 if (pDevice->byChannelSwitchCount == 0) {
2342 pDevice->bChannelSwitch = false;
2343 set_channel(pDevice, pDevice->byNewChannel);
2344 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2345 MACvSelectPage1(pDevice->PortOffset);
2346 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2347 MACvSelectPage0(pDevice->PortOffset);
2348 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2352 if (pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
2353 if ((pDevice->bUpdateBBVGA) && pDevice->bLinkPass && (pDevice->uCurrRSSI != 0)) {
2356 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
2357 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
2358 if (ldBm < pDevice->ldBmThreshold[ii]) {
2359 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2363 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2364 pDevice->uBBVGADiffCount++;
2365 if (pDevice->uBBVGADiffCount == 1) {
2366 // first VGA diff gain
2367 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2368 pr_debug("First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2370 pDevice->byBBVGANew,
2371 pDevice->byBBVGACurrent,
2372 (int)pDevice->uBBVGADiffCount);
2374 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2375 pr_debug("RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2377 pDevice->byBBVGANew,
2378 pDevice->byBBVGACurrent,
2379 (int)pDevice->uBBVGADiffCount);
2380 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2383 pDevice->uBBVGADiffCount = 1;
2388 pDevice->bBeaconSent = false;
2389 if (pDevice->bEnablePSMode)
2390 PSbIsNextTBTTWakeUp((void *)pDevice);
2392 if ((pDevice->op_mode == NL80211_IFTYPE_AP) ||
2393 (pDevice->op_mode == NL80211_IFTYPE_ADHOC)) {
2394 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2395 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2398 /* TODO: adhoc PS mode */
2402 if (pDevice->dwIsr & ISR_BNTX) {
2403 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
2404 pDevice->bIsBeaconBufReadySet = false;
2405 pDevice->cbBeaconBufReadySetCnt = 0;
2408 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
2409 if (pMgmt->byDTIMCount > 0) {
2410 pMgmt->byDTIMCount--;
2411 pMgmt->sNodeDBTable[0].bRxPSPoll = false;
2413 if (pMgmt->byDTIMCount == 0) {
2414 // check if mutltcast tx bufferring
2415 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2416 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
2417 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2421 pDevice->bBeaconSent = true;
2423 if (pDevice->bChannelSwitch) {
2424 pDevice->byChannelSwitchCount--;
2425 if (pDevice->byChannelSwitchCount == 0) {
2426 pDevice->bChannelSwitch = false;
2427 set_channel(pDevice, pDevice->byNewChannel);
2428 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2429 MACvSelectPage1(pDevice->PortOffset);
2430 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2431 MACvSelectPage0(pDevice->PortOffset);
2432 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2438 if (pDevice->dwIsr & ISR_RXDMA0)
2439 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2441 if (pDevice->dwIsr & ISR_RXDMA1)
2442 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2444 if (pDevice->dwIsr & ISR_TXDMA0)
2445 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2447 if (pDevice->dwIsr & ISR_AC0DMA)
2448 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2450 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2451 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
2452 if (pDevice->bShortSlotTime)
2453 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2455 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2457 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2458 pDevice->byCntMeasure = 0;
2461 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2463 MACvReceive0(pDevice->PortOffset);
2464 MACvReceive1(pDevice->PortOffset);
2466 if (max_count > pDevice->sOpts.int_works)
2470 if (byOrgPageSel == 1)
2471 MACvSelectPage1(pDevice->PortOffset);
2473 spin_unlock_irqrestore(&pDevice->lock, flags);
2475 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2477 return IRQ_RETVAL(handled);
2480 //2008-8-4 <add> by chester
2481 static int Config_FileGetParameter(unsigned char *string,
2482 unsigned char *dest, unsigned char *source)
2484 unsigned char buf1[100];
2485 int source_len = strlen(source);
2487 memset(buf1, 0, 100);
2488 strcat(buf1, string);
2490 source += strlen(buf1);
2492 memcpy(dest, source, source_len - strlen(buf1));
2496 int Config_FileOperation(struct vnt_private *pDevice,
2497 bool fwrite, unsigned char *Parameter)
2499 unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
2500 unsigned char tmpbuffer[20];
2505 pr_err("allocate mem for file fail?\n");
2508 file = filp_open(CONFIG_PATH, O_RDONLY, 0);
2511 pr_err("Config_FileOperation:open file fail?\n");
2515 if (kernel_read(file, 0, buffer, 1024) < 0) {
2516 pr_err("read file error?\n");
2521 if (Config_FileGetParameter("ZONETYPE",tmpbuffer,buffer)!=true) {
2522 pr_err("get parameter error?\n");
2527 if (memcmp(tmpbuffer, "USA", 3) == 0) {
2528 result = ZoneType_USA;
2529 } else if(memcmp(tmpbuffer, "JAPAN", 5) == 0) {
2530 result = ZoneType_Japan;
2531 } else if(memcmp(tmpbuffer, "EUROPE", 5) == 0) {
2532 result = ZoneType_Europe;
2535 pr_err("Unknown Zonetype[%s]?\n", tmpbuffer);
2544 static void device_set_multi(struct net_device *dev) {
2545 struct vnt_private *pDevice = netdev_priv(dev);
2546 PSMgmtObject pMgmt = pDevice->pMgmt;
2548 struct netdev_hw_addr *ha;
2550 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
2552 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
2553 pr_notice("%s: Promiscuous mode enabled\n", dev->name);
2554 /* Unconditionally log net taps. */
2555 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
2556 } else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
2557 || (dev->flags & IFF_ALLMULTI)) {
2558 MACvSelectPage1(pDevice->PortOffset);
2559 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
2560 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
2561 MACvSelectPage0(pDevice->PortOffset);
2562 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2564 memset(mc_filter, 0, sizeof(mc_filter));
2565 netdev_for_each_mc_addr(ha, dev) {
2566 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
2568 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
2570 MACvSelectPage1(pDevice->PortOffset);
2571 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
2572 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
2573 MACvSelectPage0(pDevice->PortOffset);
2574 pDevice->byRxMode &= ~(RCR_UNICAST);
2575 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2578 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2579 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
2580 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2581 pDevice->byRxMode &= ~(RCR_UNICAST);
2584 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
2585 pr_debug("pDevice->byRxMode = %x\n", pDevice->byRxMode);
2588 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2590 struct vnt_private *pDevice = netdev_priv(dev);
2591 struct iwreq *wrq = (struct iwreq *)rq;
2593 PSMgmtObject pMgmt = pDevice->pMgmt;
2596 if (pMgmt == NULL) {
2603 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
2606 case SIOCGIWNWID: //0x8b03 support
2610 // Set frequency/channel
2612 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
2615 // Get frequency/channel
2617 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
2620 // Set desired network name (ESSID)
2624 char essid[IW_ESSID_MAX_SIZE+1];
2626 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
2630 if (copy_from_user(essid, wrq->u.essid.pointer,
2631 wrq->u.essid.length)) {
2635 rc = iwctl_siwessid(dev, NULL,
2636 &(wrq->u.essid), essid);
2640 // Get current network name (ESSID)
2644 char essid[IW_ESSID_MAX_SIZE+1];
2646 if (wrq->u.essid.pointer)
2647 rc = iwctl_giwessid(dev, NULL,
2648 &(wrq->u.essid), essid);
2649 if (copy_to_user(wrq->u.essid.pointer,
2651 wrq->u.essid.length))
2658 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2661 // Get current Access Point (BSSID)
2663 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2666 // Set desired station name
2668 pr_debug(" SIOCSIWNICKN\n");
2672 // Get current station name
2674 pr_debug(" SIOCGIWNICKN\n");
2678 // Set the desired bit-rate
2680 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2683 // Get the current bit-rate
2686 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2689 // Set the desired RTS threshold
2692 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
2695 // Get the current RTS threshold
2698 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
2701 // Set the desired fragmentation threshold
2704 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
2707 // Get the current fragmentation threshold
2710 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
2713 // Set mode of operation
2715 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
2718 // Get mode of operation
2720 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
2723 // Set WEP keys and mode
2724 case SIOCSIWENCODE: {
2725 char abyKey[WLAN_WEP232_KEYLEN];
2727 if (wrq->u.encoding.pointer) {
2728 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
2732 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
2733 if (copy_from_user(abyKey,
2734 wrq->u.encoding.pointer,
2735 wrq->u.encoding.length)) {
2739 } else if (wrq->u.encoding.length != 0) {
2743 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2747 // Get the WEP keys and mode
2750 if (!capable(CAP_NET_ADMIN)) {
2755 char abyKey[WLAN_WEP232_KEYLEN];
2757 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2760 if (wrq->u.encoding.pointer) {
2761 if (copy_to_user(wrq->u.encoding.pointer,
2763 wrq->u.encoding.length))
2769 // Get the current Tx-Power
2771 pr_debug(" SIOCGIWTXPOW\n");
2776 pr_debug(" SIOCSIWTXPOW\n");
2782 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
2787 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
2790 // Get range of parameters
2794 struct iw_range range;
2796 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *)&range);
2797 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
2805 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
2810 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
2815 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
2819 pr_debug(" SIOCSIWSENS\n");
2823 case SIOCGIWAPLIST: {
2824 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
2826 if (wrq->u.data.pointer) {
2827 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
2829 if (copy_to_user(wrq->u.data.pointer,
2831 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
2843 pr_debug(" SIOCSIWSPY\n");
2850 pr_debug(" SIOCGIWSPY\n");
2854 #endif // WIRELESS_SPY
2857 pr_debug(" SIOCGIWPRIV\n");
2861 //2008-0409-07, <Add> by Einsn Liu
2862 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2864 pr_debug(" SIOCSIWAUTH\n");
2865 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
2869 pr_debug(" SIOCGIWAUTH\n");
2870 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
2874 pr_debug(" SIOCSIWGENIE\n");
2875 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2879 pr_debug(" SIOCGIWGENIE\n");
2880 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2883 case SIOCSIWENCODEEXT: {
2884 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
2886 pr_debug(" SIOCSIWENCODEEXT\n");
2887 if (wrq->u.encoding.pointer) {
2888 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN + 1);
2889 if (wrq->u.encoding.length > (sizeof(struct iw_encode_ext) + MAX_KEY_LEN)) {
2893 if (copy_from_user(extra, wrq->u.encoding.pointer, wrq->u.encoding.length)) {
2897 } else if (wrq->u.encoding.length != 0) {
2901 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
2905 case SIOCGIWENCODEEXT:
2906 pr_debug(" SIOCGIWENCODEEXT\n");
2907 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
2911 pr_debug(" SIOCSIWMLME\n");
2912 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2915 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2916 //End Add -- //2008-0409-07, <Add> by Einsn Liu
2918 case IOCTL_CMD_TEST:
2920 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
2926 pReq = (PSCmdRequest)rq;
2927 pReq->wResult = MAGIC_CODE;
2933 if ((((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_EVT) &&
2934 !(pDevice->flags & DEVICE_FLAGS_OPENED))
2936 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
2937 (((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_WPA))
2946 if (test_and_set_bit(0, (void *)&(pMgmt->uCmdBusy)))
2949 rc = private_ioctl(pDevice, rq);
2950 clear_bit(0, (void *)&(pMgmt->uCmdBusy));
2953 case IOCTL_CMD_HOSTAPD:
2955 rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data);
2960 rc = wpa_ioctl(pDevice, &wrq->u.data);
2964 return ethtool_ioctl(dev, rq->ifr_data);
2965 // All other calls are currently unsupported
2969 pr_debug("Ioctl command not support..%x\n", cmd);
2973 if (pDevice->bCommit) {
2974 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2975 netif_stop_queue(pDevice->dev);
2976 spin_lock_irq(&pDevice->lock);
2977 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
2978 spin_unlock_irq(&pDevice->lock);
2980 pr_debug("Commit the settings\n");
2981 spin_lock_irq(&pDevice->lock);
2982 pDevice->bLinkPass = false;
2983 memset(pMgmt->abyCurrBSSID, 0, 6);
2984 pMgmt->eCurrState = WMAC_STATE_IDLE;
2985 netif_stop_queue(pDevice->dev);
2986 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2987 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
2988 if (!pDevice->bWPASuppWextEnabled)
2990 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
2991 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
2992 spin_unlock_irq(&pDevice->lock);
2994 pDevice->bCommit = false;
3000 static int ethtool_ioctl(struct net_device *dev, void __user *useraddr)
3004 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
3008 case ETHTOOL_GDRVINFO: {
3009 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
3011 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
3012 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
3013 if (copy_to_user(useraddr, &info, sizeof(info)))
3023 /*------------------------------------------------------------------*/
3025 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
3027 static struct pci_driver device_driver = {
3028 .name = DEVICE_NAME,
3029 .id_table = vt6655_pci_id_table,
3030 .probe = vt6655_probe,
3031 .remove = vt6655_remove,
3033 .suspend = viawget_suspend,
3034 .resume = viawget_resume,
3038 static int __init vt6655_init_module(void)
3042 ret = pci_register_driver(&device_driver);
3045 register_reboot_notifier(&device_notifier);
3051 static void __exit vt6655_cleanup_module(void)
3054 unregister_reboot_notifier(&device_notifier);
3056 pci_unregister_driver(&device_driver);
3059 module_init(vt6655_init_module);
3060 module_exit(vt6655_cleanup_module);
3064 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3066 struct pci_dev *pdev = NULL;
3072 for_each_pci_dev(pdev) {
3073 if (pci_dev_driver(pdev) == &device_driver) {
3074 if (pci_get_drvdata(pdev))
3075 viawget_suspend(pdev, PMSG_HIBERNATE);
3083 viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3085 int power_status; // to silence the compiler
3087 struct vnt_private *pDevice = pci_get_drvdata(pcid);
3088 PSMgmtObject pMgmt = pDevice->pMgmt;
3090 netif_stop_queue(pDevice->dev);
3091 spin_lock_irq(&pDevice->lock);
3092 pci_save_state(pcid);
3093 del_timer(&pDevice->sTimerCommand);
3094 del_timer(&pMgmt->sTimerSecondCallback);
3095 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3096 pDevice->uCmdDequeueIdx = 0;
3097 pDevice->uCmdEnqueueIdx = 0;
3098 pDevice->bCmdRunning = false;
3099 MACbShutdown(pDevice->PortOffset);
3100 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3101 pDevice->bLinkPass = false;
3102 memset(pMgmt->abyCurrBSSID, 0, 6);
3103 pMgmt->eCurrState = WMAC_STATE_IDLE;
3104 pci_disable_device(pcid);
3105 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3106 spin_unlock_irq(&pDevice->lock);
3111 viawget_resume(struct pci_dev *pcid)
3113 struct vnt_private *pDevice = pci_get_drvdata(pcid);
3114 PSMgmtObject pMgmt = pDevice->pMgmt;
3115 int power_status; // to silence the compiler
3117 power_status = pci_set_power_state(pcid, PCI_D0);
3118 power_status = pci_enable_wake(pcid, PCI_D0, 0);
3119 pci_restore_state(pcid);
3120 if (netif_running(pDevice->dev)) {
3121 spin_lock_irq(&pDevice->lock);
3122 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3123 device_init_registers(pDevice);
3124 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
3125 pMgmt->sNodeDBTable[0].bActive = false;
3126 pDevice->bLinkPass = false;
3127 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3128 // In Adhoc, BSS state set back to started.
3129 pMgmt->eCurrState = WMAC_STATE_STARTED;
3131 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3132 pMgmt->eCurrState = WMAC_STATE_IDLE;
3135 init_timer(&pMgmt->sTimerSecondCallback);
3136 init_timer(&pDevice->sTimerCommand);
3137 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3138 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
3139 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3140 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3141 spin_unlock_irq(&pDevice->lock);