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 ether_addr_copy(pDevice->abyBroadcastAddr, abyBroadcastAddr);
366 ether_addr_copy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042);
367 ether_addr_copy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel);
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,
812 static void device_print_info(struct vnt_private *pDevice)
814 struct net_device *dev = pDevice->dev;
816 pr_info("%s: %s\n", dev->name, get_chip_name(pDevice->chip_id));
817 pr_info("%s: MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
818 dev->name, dev->dev_addr, (unsigned long)pDevice->ioaddr,
819 (unsigned long)pDevice->PortOffset, pDevice->dev->irq);
822 static void vt6655_init_info(struct pci_dev *pcid,
823 struct vnt_private **ppDevice,
824 PCHIP_INFO pChip_info)
826 memset(*ppDevice, 0, sizeof(**ppDevice));
828 (*ppDevice)->pcid = pcid;
829 (*ppDevice)->chip_id = pChip_info->chip_id;
830 (*ppDevice)->io_size = pChip_info->io_size;
831 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
832 (*ppDevice)->multicast_limit = 32;
834 spin_lock_init(&((*ppDevice)->lock));
837 static bool device_get_pci_info(struct vnt_private *pDevice,
838 struct pci_dev *pcid)
842 unsigned int cis_addr;
844 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
845 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
846 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
847 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
849 pci_set_master(pcid);
851 pDevice->memaddr = pci_resource_start(pcid, 0);
852 pDevice->ioaddr = pci_resource_start(pcid, 1);
854 cis_addr = pci_resource_start(pcid, 2);
856 pDevice->pcid = pcid;
858 pci_read_config_byte(pcid, PCI_COMMAND, &b);
859 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
864 static void device_free_info(struct vnt_private *pDevice)
866 struct net_device *dev = pDevice->dev;
869 //2008-0714-01<Add>by chester
870 device_release_WPADEV(pDevice);
872 //2008-07-21-01<Add>by MikeLiu
874 if (wpa_set_wpadev(pDevice, 0) != 0)
875 pr_err("unregister wpadev fail?\n");
879 vt6655_hostap_set_hostapd(pDevice, 0, 0);
882 unregister_netdev(dev);
884 if (pDevice->PortOffset)
885 iounmap(pDevice->PortOffset);
888 pci_release_regions(pDevice->pcid);
893 static bool device_init_rings(struct vnt_private *pDevice)
897 /*allocate all RD/TD rings a single pool*/
898 vir_pool = pci_zalloc_consistent(pDevice->pcid,
899 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
900 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
901 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
902 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
904 if (vir_pool == NULL) {
905 dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n");
909 pDevice->aRD0Ring = vir_pool;
910 pDevice->aRD1Ring = vir_pool +
911 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
913 pDevice->rd0_pool_dma = pDevice->pool_dma;
914 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
915 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
917 pDevice->tx0_bufs = pci_zalloc_consistent(pDevice->pcid,
918 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
919 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
922 &pDevice->tx_bufs_dma0);
923 if (pDevice->tx0_bufs == NULL) {
924 dev_err(&pDevice->pcid->dev, "allocate buf dma memory failed\n");
926 pci_free_consistent(pDevice->pcid,
927 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
928 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
929 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
930 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
931 vir_pool, pDevice->pool_dma
936 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
937 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
939 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
940 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
942 // vir_pool: pvoid type
943 pDevice->apTD0Rings = vir_pool
944 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
945 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
947 pDevice->apTD1Rings = vir_pool
948 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
949 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
950 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
952 pDevice->tx1_bufs = pDevice->tx0_bufs +
953 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
955 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
956 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
958 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
961 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
962 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
964 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
965 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
970 static void device_free_rings(struct vnt_private *pDevice)
972 pci_free_consistent(pDevice->pcid,
973 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
974 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
975 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
976 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
978 pDevice->aRD0Ring, pDevice->pool_dma
981 if (pDevice->tx0_bufs)
982 pci_free_consistent(pDevice->pcid,
983 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
984 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
987 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
991 static void device_init_rd0_ring(struct vnt_private *pDevice)
994 dma_addr_t curr = pDevice->rd0_pool_dma;
997 /* Init the RD0 ring entries */
998 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
999 pDesc = &(pDevice->aRD0Ring[i]);
1000 pDesc->pRDInfo = alloc_rd_info();
1001 ASSERT(pDesc->pRDInfo);
1002 if (!device_alloc_rx_buf(pDevice, pDesc))
1003 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
1005 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
1006 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1007 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1011 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
1012 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
1015 static void device_init_rd1_ring(struct vnt_private *pDevice)
1018 dma_addr_t curr = pDevice->rd1_pool_dma;
1021 /* Init the RD1 ring entries */
1022 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
1023 pDesc = &(pDevice->aRD1Ring[i]);
1024 pDesc->pRDInfo = alloc_rd_info();
1025 ASSERT(pDesc->pRDInfo);
1026 if (!device_alloc_rx_buf(pDevice, pDesc))
1027 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
1029 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
1030 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
1031 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
1035 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
1036 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
1039 static void device_init_defrag_cb(struct vnt_private *pDevice)
1042 PSDeFragControlBlock pDeF;
1044 /* Init the fragment ctl entries */
1045 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1046 pDeF = &(pDevice->sRxDFCB[i]);
1047 if (!device_alloc_frag_buf(pDevice, pDeF))
1048 dev_err(&pDevice->pcid->dev, "can not alloc frag bufs\n");
1050 pDevice->cbDFCB = CB_MAX_RX_FRAG;
1051 pDevice->cbFreeDFCB = pDevice->cbDFCB;
1054 static void device_free_rd0_ring(struct vnt_private *pDevice)
1058 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
1059 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
1060 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1062 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1063 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1065 dev_kfree_skb(pRDInfo->skb);
1067 kfree(pDesc->pRDInfo);
1071 static void device_free_rd1_ring(struct vnt_private *pDevice)
1075 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1076 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
1077 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1079 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1080 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1082 dev_kfree_skb(pRDInfo->skb);
1084 kfree(pDesc->pRDInfo);
1088 static void device_free_frag_buf(struct vnt_private *pDevice)
1090 PSDeFragControlBlock pDeF;
1093 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1094 pDeF = &(pDevice->sRxDFCB[i]);
1097 dev_kfree_skb(pDeF->skb);
1102 static void device_init_td0_ring(struct vnt_private *pDevice)
1108 curr = pDevice->td0_pool_dma;
1109 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1110 pDesc = &(pDevice->apTD0Rings[i]);
1111 pDesc->pTDInfo = alloc_td_info();
1112 ASSERT(pDesc->pTDInfo);
1113 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1114 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1115 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1117 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1118 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1119 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1123 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1124 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1127 static void device_init_td1_ring(struct vnt_private *pDevice)
1133 /* Init the TD ring entries */
1134 curr = pDevice->td1_pool_dma;
1135 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
1136 pDesc = &(pDevice->apTD1Rings[i]);
1137 pDesc->pTDInfo = alloc_td_info();
1138 ASSERT(pDesc->pTDInfo);
1139 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1140 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
1141 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
1143 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
1144 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1145 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1149 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1150 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1153 static void device_free_td0_ring(struct vnt_private *pDevice)
1157 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1158 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
1159 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1161 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1162 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1163 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1166 dev_kfree_skb(pTDInfo->skb);
1168 kfree(pDesc->pTDInfo);
1172 static void device_free_td1_ring(struct vnt_private *pDevice)
1176 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1177 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
1178 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1180 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1181 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1182 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1185 dev_kfree_skb(pTDInfo->skb);
1187 kfree(pDesc->pTDInfo);
1191 /*-----------------------------------------------------------------*/
1193 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1198 for (pRD = pDevice->pCurrRD[uIdx];
1199 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1203 if (vnt_receive_frame(pDevice, pRD)) {
1204 if (!device_alloc_rx_buf(pDevice, pRD)) {
1205 dev_err(&pDevice->pcid->dev,
1206 "can not allocate rx buf\n");
1210 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1213 pDevice->pCurrRD[uIdx] = pRD;
1218 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
1220 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1222 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1223 if (pRDInfo->skb == NULL)
1225 ASSERT(pRDInfo->skb);
1228 pci_map_single(pDevice->pcid,
1229 skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)),
1230 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1232 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1234 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1235 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1236 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1237 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1242 bool device_alloc_frag_buf(struct vnt_private *pDevice,
1243 PSDeFragControlBlock pDeF)
1245 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1246 if (pDeF->skb == NULL)
1253 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1258 unsigned char byTsr0;
1259 unsigned char byTsr1;
1260 unsigned int uFrameSize, uFIFOHeaderSize;
1261 PSTxBufHead pTxBufHead;
1262 struct net_device_stats *pStats = &pDevice->dev->stats;
1263 struct sk_buff *skb;
1264 unsigned int uNodeIndex;
1265 PSMgmtObject pMgmt = pDevice->pMgmt;
1267 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1268 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1273 byTsr0 = pTD->m_td0TD0.byTSR0;
1274 byTsr1 = pTD->m_td0TD0.byTSR1;
1276 //Only the status of first TD in the chain is correct
1277 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1278 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1279 uFIFOHeaderSize = pTD->pTDInfo->dwHeaderLength;
1280 uFrameSize = pTD->pTDInfo->dwReqCount - uFIFOHeaderSize;
1281 pTxBufHead = (PSTxBufHead) (pTD->pTDInfo->buf);
1282 // Update the statistics based on the Transmit status
1283 // now, we DONT check TSR0_CDH
1285 STAvUpdateTDStatCounter(&pDevice->scStatistic,
1287 (unsigned char *)(pTD->pTDInfo->buf + uFIFOHeaderSize),
1290 BSSvUpdateNodeTxCounter(pDevice,
1292 (unsigned char *)(pTD->pTDInfo->buf),
1296 if (!(byTsr1 & TSR1_TERR)) {
1298 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
1302 if ((pTxBufHead->wFragCtl & FRAGCTL_ENDFRAG) != FRAGCTL_NONFRAG)
1303 pDevice->s802_11Counter.TransmittedFragmentCount++;
1305 pStats->tx_packets++;
1306 pStats->tx_bytes += pTD->pTDInfo->skb->len;
1308 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
1309 (int)uIdx, byTsr1, byTsr0);
1310 pStats->tx_errors++;
1311 pStats->tx_dropped++;
1315 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1316 if (pDevice->bEnableHostapd) {
1317 pr_debug("tx call back netif..\n");
1318 skb = pTD->pTDInfo->skb;
1319 skb->dev = pDevice->apdev;
1320 skb_reset_mac_header(skb);
1321 skb->pkt_type = PACKET_OTHERHOST;
1322 memset(skb->cb, 0, sizeof(skb->cb));
1327 if (byTsr1 & TSR1_TERR) {
1328 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1329 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
1330 (int)uIdx, byTsr1, byTsr0);
1334 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) &&
1335 (pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)) {
1336 unsigned short wAID;
1337 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1339 skb = pTD->pTDInfo->skb;
1340 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1341 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1342 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1343 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1345 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1346 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1347 pTD->pTDInfo->byFlags &= ~(TD_FLAGS_NETIF_SKB);
1348 pr_debug("tx_srv:tx fail re-queue sta index= %d, QueCnt= %d\n",
1350 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt);
1351 pStats->tx_errors--;
1352 pStats->tx_dropped--;
1357 device_free_tx_buf(pDevice, pTD);
1358 pDevice->iTDUsed[uIdx]--;
1362 if (uIdx == TYPE_AC0DMA) {
1363 // RESERV_AC0DMA reserved for relay
1365 if (AVAIL_TD(pDevice, uIdx) < RESERV_AC0DMA) {
1367 pr_debug(" AC0DMA is Full = %d\n",
1368 pDevice->iTDUsed[uIdx]);
1370 if (netif_queue_stopped(pDevice->dev) && !bFull)
1371 netif_wake_queue(pDevice->dev);
1375 pDevice->apTailTD[uIdx] = pTD;
1380 static void device_error(struct vnt_private *pDevice, unsigned short status)
1382 if (status & ISR_FETALERR) {
1383 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
1385 netif_stop_queue(pDevice->dev);
1386 del_timer(&pDevice->sTimerCommand);
1387 del_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1388 pDevice->bCmdRunning = false;
1389 MACbShutdown(pDevice->PortOffset);
1394 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
1396 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1397 struct sk_buff *skb = pTDInfo->skb;
1399 // pre-allocated buf_dma can't be unmapped.
1400 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1401 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1405 if ((pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0)
1406 dev_kfree_skb_irq(skb);
1408 pTDInfo->skb_dma = 0;
1409 pTDInfo->skb = NULL;
1410 pTDInfo->byFlags = 0;
1413 static int device_open(struct net_device *dev)
1415 struct vnt_private *pDevice = netdev_priv(dev);
1418 pDevice->rx_buf_sz = PKT_BUF_SZ;
1419 if (!device_init_rings(pDevice))
1422 //2008-5-13 <add> by chester
1423 i = request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1427 #ifdef WPA_SM_Transtatus
1428 pDevice->fWPA_Authened = false;
1430 pr_debug("call device init rd0 ring\n");
1431 device_init_rd0_ring(pDevice);
1432 device_init_rd1_ring(pDevice);
1433 device_init_defrag_cb(pDevice);
1434 device_init_td0_ring(pDevice);
1435 device_init_td1_ring(pDevice);
1437 if (pDevice->bDiversityRegCtlON)
1438 device_init_diversity_timer(pDevice);
1440 vMgrObjectInit(pDevice);
1441 vMgrTimerInit(pDevice);
1443 pr_debug("call device_init_registers\n");
1444 device_init_registers(pDevice);
1446 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1447 ether_addr_copy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr);
1448 device_set_multi(pDevice->dev);
1450 // Init for Key Management
1451 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1452 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1454 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1455 pDevice->bwextcount = 0;
1456 pDevice->bWPASuppWextEnabled = false;
1458 pDevice->byReAssocCount = 0;
1459 pDevice->bWPADEVUp = false;
1460 // Patch: if WEP key already set by iwconfig but device not yet open
1461 if (pDevice->bEncryptionEnable && pDevice->bTransmitKey) {
1462 KeybSetDefaultKey(&(pDevice->sKey),
1463 (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
1464 pDevice->uKeyLength,
1468 pDevice->PortOffset,
1471 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1474 pr_debug("call MACvIntEnable\n");
1475 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1477 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1478 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
1480 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1481 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1483 pDevice->flags |= DEVICE_FLAGS_OPENED;
1485 pr_debug("device_open success..\n");
1489 static int device_close(struct net_device *dev)
1491 struct vnt_private *pDevice = netdev_priv(dev);
1492 PSMgmtObject pMgmt = pDevice->pMgmt;
1493 //2007-1121-02<Add>by EinsnLiu
1494 if (pDevice->bLinkPass) {
1495 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1499 del_timer(&pDevice->sTimerTxData);
1500 del_timer(&pDevice->sTimerCommand);
1501 del_timer(&pMgmt->sTimerSecondCallback);
1502 if (pDevice->bDiversityRegCtlON) {
1503 del_timer(&pDevice->TimerSQ3Tmax1);
1504 del_timer(&pDevice->TimerSQ3Tmax2);
1505 del_timer(&pDevice->TimerSQ3Tmax3);
1508 netif_stop_queue(dev);
1509 pDevice->bCmdRunning = false;
1510 MACbShutdown(pDevice->PortOffset);
1511 MACbSoftwareReset(pDevice->PortOffset);
1512 CARDbRadioPowerOff(pDevice);
1514 pDevice->bLinkPass = false;
1515 memset(pMgmt->abyCurrBSSID, 0, 6);
1516 pMgmt->eCurrState = WMAC_STATE_IDLE;
1517 device_free_td0_ring(pDevice);
1518 device_free_td1_ring(pDevice);
1519 device_free_rd0_ring(pDevice);
1520 device_free_rd1_ring(pDevice);
1521 device_free_frag_buf(pDevice);
1522 device_free_rings(pDevice);
1523 BSSvClearNodeDBTable(pDevice, 0);
1524 free_irq(dev->irq, dev);
1525 pDevice->flags &= (~DEVICE_FLAGS_OPENED);
1526 //2008-0714-01<Add>by chester
1527 device_release_WPADEV(pDevice);
1529 pr_debug("device_close..\n");
1533 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1535 struct vnt_private *pDevice = netdev_priv(dev);
1536 unsigned char *pbMPDU;
1537 unsigned int cbMPDULen = 0;
1539 pr_debug("device_dma0_tx_80211\n");
1540 spin_lock_irq(&pDevice->lock);
1542 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1543 pr_debug("device_dma0_tx_80211, td0 <=0\n");
1544 dev_kfree_skb_irq(skb);
1545 spin_unlock_irq(&pDevice->lock);
1549 if (pDevice->bStopTx0Pkt) {
1550 dev_kfree_skb_irq(skb);
1551 spin_unlock_irq(&pDevice->lock);
1555 cbMPDULen = skb->len;
1558 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
1560 spin_unlock_irq(&pDevice->lock);
1565 bool device_dma0_xmit(struct vnt_private *pDevice,
1566 struct sk_buff *skb, unsigned int uNodeIndex)
1568 PSMgmtObject pMgmt = pDevice->pMgmt;
1569 PSTxDesc pHeadTD, pLastTD;
1570 unsigned int cbFrameBodySize;
1571 unsigned int uMACfragNum;
1572 unsigned char byPktType;
1573 bool bNeedEncryption = false;
1574 PSKeyItem pTransmitKey = NULL;
1575 unsigned int cbHeaderSize;
1579 if (pDevice->bStopTx0Pkt) {
1580 dev_kfree_skb_irq(skb);
1584 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1585 dev_kfree_skb_irq(skb);
1586 pr_debug("device_dma0_xmit, td0 <=0\n");
1590 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1591 if (pDevice->uAssocCount == 0) {
1592 dev_kfree_skb_irq(skb);
1593 pr_debug("device_dma0_xmit, assocCount = 0\n");
1598 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
1600 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1602 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1603 cbFrameBodySize = skb->len - ETH_HLEN;
1606 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1607 cbFrameBodySize += 8;
1609 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
1611 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
1612 dev_kfree_skb_irq(skb);
1615 byPktType = (unsigned char)pDevice->byPacketType;
1617 if (pDevice->bFixRate) {
1618 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
1619 if (pDevice->uConnectionRate >= RATE_11M)
1620 pDevice->wCurrentRate = RATE_11M;
1622 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1624 if (pDevice->uConnectionRate >= RATE_54M)
1625 pDevice->wCurrentRate = RATE_54M;
1627 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1630 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1634 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1635 pDevice->byPreambleType = pDevice->byShortPreamble;
1637 pDevice->byPreambleType = PREAMBLE_LONG;
1639 pr_debug("dma0: pDevice->wCurrentRate = %d\n", pDevice->wCurrentRate);
1641 if (pDevice->wCurrentRate <= RATE_11M) {
1642 byPktType = PK_TYPE_11B;
1643 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1644 byPktType = PK_TYPE_11A;
1646 if (pDevice->bProtectMode)
1647 byPktType = PK_TYPE_11GB;
1649 byPktType = PK_TYPE_11GA;
1652 if (pDevice->bEncryptionEnable)
1653 bNeedEncryption = true;
1655 if (pDevice->bEnableHostWEP) {
1656 pTransmitKey = &STempKey;
1657 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1658 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1659 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1660 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1661 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1662 memcpy(pTransmitKey->abyKey,
1663 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1664 pTransmitKey->uKeyLength
1667 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
1668 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
1669 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
1674 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1676 MACbPSWakeup(pDevice->PortOffset);
1679 pDevice->bPWBitOn = false;
1682 for (ii = 0; ii < uMACfragNum; ii++) {
1683 // Poll Transmit the adapter
1685 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
1687 if (ii == (uMACfragNum - 1))
1689 pHeadTD = pHeadTD->next;
1692 // Save the information needed by the tx interrupt handler
1693 // to complete the Send request
1694 pLastTD->pTDInfo->skb = skb;
1695 pLastTD->pTDInfo->byFlags = 0;
1696 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
1698 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
1700 MACvTransmit0(pDevice->PortOffset);
1705 //TYPE_AC0DMA data tx
1706 static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
1707 struct vnt_private *pDevice = netdev_priv(dev);
1708 PSMgmtObject pMgmt = pDevice->pMgmt;
1709 PSTxDesc pHeadTD, pLastTD;
1710 unsigned int uNodeIndex = 0;
1711 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1712 unsigned short wAID;
1713 unsigned int uMACfragNum = 1;
1714 unsigned int cbFrameBodySize;
1715 unsigned char byPktType;
1716 unsigned int cbHeaderSize;
1717 bool bNeedEncryption = false;
1718 PSKeyItem pTransmitKey = NULL;
1721 bool bTKIP_UseGTK = false;
1722 bool bNeedDeAuth = false;
1723 unsigned char *pbyBSSID;
1724 bool bNodeExist = false;
1726 spin_lock_irq(&pDevice->lock);
1727 if (!pDevice->bLinkPass) {
1728 dev_kfree_skb_irq(skb);
1729 spin_unlock_irq(&pDevice->lock);
1733 if (pDevice->bStopDataPkt) {
1734 dev_kfree_skb_irq(skb);
1735 spin_unlock_irq(&pDevice->lock);
1739 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1740 if (pDevice->uAssocCount == 0) {
1741 dev_kfree_skb_irq(skb);
1742 spin_unlock_irq(&pDevice->lock);
1745 if (is_multicast_ether_addr((unsigned char *)(skb->data))) {
1748 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1749 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1750 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1752 pMgmt->abyPSTxMap[0] |= byMask[0];
1753 spin_unlock_irq(&pDevice->lock);
1757 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1758 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1759 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1760 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1762 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1763 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1764 pr_debug("Set:pMgmt->abyPSTxMap[%d]= %d\n",
1766 pMgmt->abyPSTxMap[wAID >> 3]);
1767 spin_unlock_irq(&pDevice->lock);
1771 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1772 pDevice->byPreambleType = pDevice->byShortPreamble;
1774 pDevice->byPreambleType = PREAMBLE_LONG;
1782 pr_debug("Unknown STA not found in node DB\n");
1783 dev_kfree_skb_irq(skb);
1784 spin_unlock_irq(&pDevice->lock);
1789 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
1791 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1793 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1794 cbFrameBodySize = skb->len - ETH_HLEN;
1796 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1797 cbFrameBodySize += 8;
1799 if (pDevice->bEncryptionEnable) {
1800 bNeedEncryption = true;
1803 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1804 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1805 pbyBSSID = pDevice->abyBSSID;
1807 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
1809 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1810 bTKIP_UseGTK = true;
1811 pr_debug("Get GTK\n");
1815 pr_debug("Get PTK\n");
1818 } else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1819 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
1820 pr_debug("IBSS Serach Key:\n");
1821 for (ii = 0; ii < 6; ii++)
1822 pr_debug("%x\n", *(pbyBSSID+ii));
1826 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
1830 pbyBSSID = pDevice->abyBroadcastAddr;
1831 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
1832 pTransmitKey = NULL;
1833 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
1834 pr_debug("IBSS and KEY is NULL. [%d]\n",
1835 pDevice->pMgmt->eCurrMode);
1837 pr_debug("NOT IBSS and KEY is NULL. [%d]\n",
1838 pDevice->pMgmt->eCurrMode);
1840 bTKIP_UseGTK = true;
1841 pr_debug("Get GTK\n");
1846 if (pDevice->bEnableHostWEP) {
1847 pr_debug("acdma0: STA index %d\n", uNodeIndex);
1848 if (pDevice->bEncryptionEnable) {
1849 pTransmitKey = &STempKey;
1850 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1851 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1852 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1853 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1854 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1855 memcpy(pTransmitKey->abyKey,
1856 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1857 pTransmitKey->uKeyLength
1862 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
1864 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
1865 pr_debug("uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n",
1867 dev_kfree_skb_irq(skb);
1868 spin_unlock_irq(&pDevice->lock);
1872 if (pTransmitKey != NULL) {
1873 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
1874 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
1875 uMACfragNum = 1; //WEP256 doesn't support fragment
1879 byPktType = (unsigned char)pDevice->byPacketType;
1881 if (pDevice->bFixRate) {
1882 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
1883 if (pDevice->uConnectionRate >= RATE_11M)
1884 pDevice->wCurrentRate = RATE_11M;
1886 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1888 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
1889 (pDevice->uConnectionRate <= RATE_6M)) {
1890 pDevice->wCurrentRate = RATE_6M;
1892 if (pDevice->uConnectionRate >= RATE_54M)
1893 pDevice->wCurrentRate = RATE_54M;
1895 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1899 pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate;
1900 pDevice->byTopCCKBasicRate = RATE_1M;
1901 pDevice->byTopOFDMBasicRate = RATE_6M;
1904 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
1905 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
1906 pDevice->wCurrentRate = RATE_1M;
1907 pDevice->byACKRate = RATE_1M;
1908 pDevice->byTopCCKBasicRate = RATE_1M;
1909 pDevice->byTopOFDMBasicRate = RATE_6M;
1911 pDevice->wCurrentRate = RATE_6M;
1912 pDevice->byACKRate = RATE_6M;
1913 pDevice->byTopCCKBasicRate = RATE_1M;
1914 pDevice->byTopOFDMBasicRate = RATE_6M;
1917 VNTWIFIvGetTxRate(pDevice->pMgmt,
1918 pDevice->sTxEthHeader.abyDstAddr,
1919 &(pDevice->wCurrentRate),
1920 &(pDevice->byACKRate),
1921 &(pDevice->byTopCCKBasicRate),
1922 &(pDevice->byTopOFDMBasicRate));
1928 if (pDevice->wCurrentRate <= RATE_11M) {
1929 byPktType = PK_TYPE_11B;
1930 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1931 byPktType = PK_TYPE_11A;
1933 if (pDevice->bProtectMode)
1934 byPktType = PK_TYPE_11GB;
1936 byPktType = PK_TYPE_11GA;
1939 if (bNeedEncryption) {
1940 pr_debug("ntohs Pkt Type=%04x\n",
1941 ntohs(pDevice->sTxEthHeader.wType));
1942 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
1943 bNeedEncryption = false;
1944 pr_debug("Pkt Type=%04x\n",
1945 (pDevice->sTxEthHeader.wType));
1946 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1947 if (pTransmitKey == NULL) {
1948 pr_debug("Don't Find TX KEY\n");
1951 pr_debug("error: KEY is GTK!!~~\n");
1953 pr_debug("Find PTK [%lX]\n",
1954 pTransmitKey->dwKeyIndex);
1955 bNeedEncryption = true;
1960 if (pDevice->byCntMeasure == 2) {
1962 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
1965 if (pDevice->bEnableHostWEP) {
1966 if ((uNodeIndex != 0) &&
1967 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
1968 pr_debug("Find PTK [%lX]\n",
1969 pTransmitKey->dwKeyIndex);
1970 bNeedEncryption = true;
1974 if (pTransmitKey == NULL) {
1975 pr_debug("return no tx key\n");
1976 dev_kfree_skb_irq(skb);
1977 spin_unlock_irq(&pDevice->lock);
1983 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
1984 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
1985 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
1990 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1992 MACbPSWakeup(pDevice->PortOffset);
1994 pDevice->bPWBitOn = false;
1997 for (ii = 0; ii < uMACfragNum; ii++) {
1998 // Poll Transmit the adapter
2000 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
2002 if (ii == uMACfragNum - 1)
2004 pHeadTD = pHeadTD->next;
2007 // Save the information needed by the tx interrupt handler
2008 // to complete the Send request
2009 pLastTD->pTDInfo->skb = skb;
2010 pLastTD->pTDInfo->byFlags = 0;
2011 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
2012 pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
2014 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1)
2015 netif_stop_queue(dev);
2017 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
2019 if (pDevice->bFixRate)
2020 pr_debug("FixRate:Rate is %d,TxPower is %d\n", pDevice->wCurrentRate, pDevice->byCurPwr);
2023 unsigned char Protocol_Version; //802.1x Authentication
2024 unsigned char Packet_Type; //802.1x Authentication
2025 unsigned char Descriptor_type;
2026 unsigned short Key_info;
2027 bool bTxeapol_key = false;
2029 Protocol_Version = skb->data[ETH_HLEN];
2030 Packet_Type = skb->data[ETH_HLEN+1];
2031 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
2032 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
2033 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
2034 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
2035 (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame transfer
2036 bTxeapol_key = true;
2037 if ((Descriptor_type == 254) || (Descriptor_type == 2)) { //WPA or RSN
2038 if (!(Key_info & BIT3) && //group-key challenge
2039 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
2040 pDevice->fWPA_Authened = true;
2041 if (Descriptor_type == 254)
2045 pr_debug("Authentication completed!!\n");
2052 MACvTransmitAC0(pDevice->PortOffset);
2054 dev->trans_start = jiffies;
2056 spin_unlock_irq(&pDevice->lock);
2060 static irqreturn_t device_intr(int irq, void *dev_instance)
2062 struct net_device *dev = dev_instance;
2063 struct vnt_private *pDevice = netdev_priv(dev);
2065 unsigned long dwMIBCounter = 0;
2066 PSMgmtObject pMgmt = pDevice->pMgmt;
2067 unsigned char byOrgPageSel = 0;
2069 unsigned char byData = 0;
2071 unsigned long flags;
2073 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2075 if (pDevice->dwIsr == 0)
2076 return IRQ_RETVAL(handled);
2078 if (pDevice->dwIsr == 0xffffffff) {
2079 pr_debug("dwIsr = 0xffff\n");
2080 return IRQ_RETVAL(handled);
2084 MACvIntDisable(pDevice->PortOffset);
2086 spin_lock_irqsave(&pDevice->lock, flags);
2088 //Make sure current page is 0
2089 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2090 if (byOrgPageSel == 1)
2091 MACvSelectPage0(pDevice->PortOffset);
2095 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2097 // Must do this after doing rx/tx, cause ISR bit is slow
2098 // than RD/TD write back
2099 // update ISR counter
2100 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2101 while (pDevice->dwIsr != 0) {
2102 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2103 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2105 if (pDevice->dwIsr & ISR_FETALERR) {
2106 pr_debug(" ISR_FETALERR\n");
2107 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2108 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2109 device_error(pDevice, pDevice->dwIsr);
2112 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
2113 if (pDevice->dwIsr & ISR_MEASURESTART) {
2114 // 802.11h measure start
2115 pDevice->byOrgChannel = pDevice->byCurrentCh;
2116 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byOrgRCR));
2117 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, (RCR_RXALLTYPE | RCR_UNICAST | RCR_BROADCAST | RCR_MULTICAST | RCR_WPAERR));
2118 MACvSelectPage1(pDevice->PortOffset);
2119 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR0, &(pDevice->dwOrgMAR0));
2120 VNSvInPortD(pDevice->PortOffset + MAC_REG_MAR4, &(pDevice->dwOrgMAR4));
2121 MACvSelectPage0(pDevice->PortOffset);
2123 if (set_channel(pDevice, pDevice->pCurrMeasureEID->sReq.byChannel)) {
2124 pDevice->bMeasureInProgress = true;
2125 MACvSelectPage1(pDevice->PortOffset);
2126 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_READY);
2127 MACvSelectPage0(pDevice->PortOffset);
2128 pDevice->byBasicMap = 0;
2129 pDevice->byCCAFraction = 0;
2130 for (ii = 0; ii < 8; ii++)
2131 pDevice->dwRPIs[ii] = 0;
2134 // can not measure because set channel fail
2135 // clear measure control
2136 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2137 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_INCAPABLE);
2138 MACvSelectPage1(pDevice->PortOffset);
2139 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2140 MACvSelectPage0(pDevice->PortOffset);
2143 if (pDevice->dwIsr & ISR_MEASUREEND) {
2144 // 802.11h measure end
2145 pDevice->bMeasureInProgress = false;
2146 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byOrgRCR);
2147 MACvSelectPage1(pDevice->PortOffset);
2148 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, pDevice->dwOrgMAR0);
2149 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR4, pDevice->dwOrgMAR4);
2150 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRBBSTS, &byData);
2151 pDevice->byBasicMap |= (byData >> 4);
2152 VNSvInPortB(pDevice->PortOffset + MAC_REG_CCAFRACTION, &pDevice->byCCAFraction);
2153 VNSvInPortB(pDevice->PortOffset + MAC_REG_MSRCTL, &byData);
2154 // clear measure control
2155 MACvRegBitsOff(pDevice->PortOffset, MAC_REG_MSRCTL, MSRCTL_EN);
2156 MACvSelectPage0(pDevice->PortOffset);
2157 set_channel(pDevice, pDevice->byOrgChannel);
2158 MACvSelectPage1(pDevice->PortOffset);
2159 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2160 MACvSelectPage0(pDevice->PortOffset);
2161 if (byData & MSRCTL_FINISH) {
2163 s_vCompleteCurrentMeasure(pDevice, 0);
2165 // can not measure because not ready before end of measure time
2166 s_vCompleteCurrentMeasure(pDevice, MEASURE_MODE_LATE);
2169 if (pDevice->dwIsr & ISR_QUIETSTART) {
2172 } while (!CARDbStartQuiet(pDevice));
2176 if (pDevice->dwIsr & ISR_TBTT) {
2177 if (pDevice->bEnableFirstQuiet) {
2178 pDevice->byQuietStartCount--;
2179 if (pDevice->byQuietStartCount == 0) {
2180 pDevice->bEnableFirstQuiet = false;
2181 MACvSelectPage1(pDevice->PortOffset);
2182 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL, (MSRCTL_QUIETTXCHK | MSRCTL_QUIETEN));
2183 MACvSelectPage0(pDevice->PortOffset);
2186 if (pDevice->bChannelSwitch &&
2187 (pDevice->op_mode == NL80211_IFTYPE_STATION)) {
2188 pDevice->byChannelSwitchCount--;
2189 if (pDevice->byChannelSwitchCount == 0) {
2190 pDevice->bChannelSwitch = false;
2191 set_channel(pDevice, pDevice->byNewChannel);
2192 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2193 MACvSelectPage1(pDevice->PortOffset);
2194 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2195 MACvSelectPage0(pDevice->PortOffset);
2196 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2200 if (pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
2201 if ((pDevice->bUpdateBBVGA) && pDevice->bLinkPass && (pDevice->uCurrRSSI != 0)) {
2204 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
2205 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
2206 if (ldBm < pDevice->ldBmThreshold[ii]) {
2207 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2211 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2212 pDevice->uBBVGADiffCount++;
2213 if (pDevice->uBBVGADiffCount == 1) {
2214 // first VGA diff gain
2215 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2216 pr_debug("First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2218 pDevice->byBBVGANew,
2219 pDevice->byBBVGACurrent,
2220 (int)pDevice->uBBVGADiffCount);
2222 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2223 pr_debug("RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2225 pDevice->byBBVGANew,
2226 pDevice->byBBVGACurrent,
2227 (int)pDevice->uBBVGADiffCount);
2228 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2231 pDevice->uBBVGADiffCount = 1;
2236 pDevice->bBeaconSent = false;
2237 if (pDevice->bEnablePSMode)
2238 PSbIsNextTBTTWakeUp((void *)pDevice);
2240 if ((pDevice->op_mode == NL80211_IFTYPE_AP) ||
2241 (pDevice->op_mode == NL80211_IFTYPE_ADHOC)) {
2242 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2243 (pMgmt->wIBSSBeaconPeriod - MAKE_BEACON_RESERVED) << 10);
2246 /* TODO: adhoc PS mode */
2250 if (pDevice->dwIsr & ISR_BNTX) {
2251 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
2252 pDevice->bIsBeaconBufReadySet = false;
2253 pDevice->cbBeaconBufReadySetCnt = 0;
2256 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
2257 if (pMgmt->byDTIMCount > 0) {
2258 pMgmt->byDTIMCount--;
2259 pMgmt->sNodeDBTable[0].bRxPSPoll = false;
2261 if (pMgmt->byDTIMCount == 0) {
2262 // check if mutltcast tx bufferring
2263 pMgmt->byDTIMCount = pMgmt->byDTIMPeriod - 1;
2264 pMgmt->sNodeDBTable[0].bRxPSPoll = true;
2265 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
2269 pDevice->bBeaconSent = true;
2271 if (pDevice->bChannelSwitch) {
2272 pDevice->byChannelSwitchCount--;
2273 if (pDevice->byChannelSwitchCount == 0) {
2274 pDevice->bChannelSwitch = false;
2275 set_channel(pDevice, pDevice->byNewChannel);
2276 VNTWIFIbChannelSwitch(pDevice->pMgmt, pDevice->byNewChannel);
2277 MACvSelectPage1(pDevice->PortOffset);
2278 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_MSRCTL+1, MSRCTL1_TXPAUSE);
2279 MACvSelectPage0(pDevice->PortOffset);
2280 CARDbStartTxPacket(pDevice, PKT_TYPE_802_11_ALL);
2286 if (pDevice->dwIsr & ISR_RXDMA0)
2287 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2289 if (pDevice->dwIsr & ISR_RXDMA1)
2290 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2292 if (pDevice->dwIsr & ISR_TXDMA0)
2293 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2295 if (pDevice->dwIsr & ISR_AC0DMA)
2296 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2298 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2299 if (pDevice->op_mode == NL80211_IFTYPE_AP) {
2300 if (pDevice->bShortSlotTime)
2301 pMgmt->wCurrCapInfo |= WLAN_SET_CAP_INFO_SHORTSLOTTIME(1);
2303 pMgmt->wCurrCapInfo &= ~(WLAN_SET_CAP_INFO_SHORTSLOTTIME(1));
2305 bMgrPrepareBeaconToSend(pDevice, pMgmt);
2306 pDevice->byCntMeasure = 0;
2309 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2311 MACvReceive0(pDevice->PortOffset);
2312 MACvReceive1(pDevice->PortOffset);
2314 if (max_count > pDevice->sOpts.int_works)
2318 if (byOrgPageSel == 1)
2319 MACvSelectPage1(pDevice->PortOffset);
2321 spin_unlock_irqrestore(&pDevice->lock, flags);
2323 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2325 return IRQ_RETVAL(handled);
2328 //2008-8-4 <add> by chester
2329 static int Config_FileGetParameter(unsigned char *string,
2330 unsigned char *dest, unsigned char *source)
2332 unsigned char buf1[100];
2333 int source_len = strlen(source);
2335 memset(buf1, 0, 100);
2336 strcat(buf1, string);
2338 source += strlen(buf1);
2340 memcpy(dest, source, source_len - strlen(buf1));
2344 int Config_FileOperation(struct vnt_private *pDevice,
2345 bool fwrite, unsigned char *Parameter)
2347 unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
2348 unsigned char tmpbuffer[20];
2353 pr_err("allocate mem for file fail?\n");
2356 file = filp_open(CONFIG_PATH, O_RDONLY, 0);
2359 pr_err("Config_FileOperation:open file fail?\n");
2363 if (kernel_read(file, 0, buffer, 1024) < 0) {
2364 pr_err("read file error?\n");
2369 if (Config_FileGetParameter("ZONETYPE", tmpbuffer, buffer) != true) {
2370 pr_err("get parameter error?\n");
2375 if (memcmp(tmpbuffer, "USA", 3) == 0) {
2376 result = ZoneType_USA;
2377 } else if (memcmp(tmpbuffer, "JAPAN", 5) == 0) {
2378 result = ZoneType_Japan;
2379 } else if (memcmp(tmpbuffer, "EUROPE", 5) == 0) {
2380 result = ZoneType_Europe;
2383 pr_err("Unknown Zonetype[%s]?\n", tmpbuffer);
2392 static void device_set_multi(struct net_device *dev) {
2393 struct vnt_private *pDevice = netdev_priv(dev);
2394 PSMgmtObject pMgmt = pDevice->pMgmt;
2396 struct netdev_hw_addr *ha;
2398 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
2400 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
2401 pr_notice("%s: Promiscuous mode enabled\n", dev->name);
2402 /* Unconditionally log net taps. */
2403 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
2404 } else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
2405 || (dev->flags & IFF_ALLMULTI)) {
2406 MACvSelectPage1(pDevice->PortOffset);
2407 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
2408 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
2409 MACvSelectPage0(pDevice->PortOffset);
2410 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2412 memset(mc_filter, 0, sizeof(mc_filter));
2413 netdev_for_each_mc_addr(ha, dev) {
2414 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
2416 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
2418 MACvSelectPage1(pDevice->PortOffset);
2419 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
2420 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
2421 MACvSelectPage0(pDevice->PortOffset);
2422 pDevice->byRxMode &= ~(RCR_UNICAST);
2423 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2426 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2427 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
2428 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2429 pDevice->byRxMode &= ~(RCR_UNICAST);
2432 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
2433 pr_debug("pDevice->byRxMode = %x\n", pDevice->byRxMode);
2436 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2438 struct vnt_private *pDevice = netdev_priv(dev);
2439 struct iwreq *wrq = (struct iwreq *)rq;
2441 PSMgmtObject pMgmt = pDevice->pMgmt;
2444 if (pMgmt == NULL) {
2451 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
2454 case SIOCGIWNWID: //0x8b03 support
2458 // Set frequency/channel
2460 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
2463 // Get frequency/channel
2465 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
2468 // Set desired network name (ESSID)
2472 char essid[IW_ESSID_MAX_SIZE+1];
2474 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
2478 if (copy_from_user(essid, wrq->u.essid.pointer,
2479 wrq->u.essid.length)) {
2483 rc = iwctl_siwessid(dev, NULL,
2484 &(wrq->u.essid), essid);
2488 // Get current network name (ESSID)
2492 char essid[IW_ESSID_MAX_SIZE+1];
2494 if (wrq->u.essid.pointer)
2495 rc = iwctl_giwessid(dev, NULL,
2496 &(wrq->u.essid), essid);
2497 if (copy_to_user(wrq->u.essid.pointer,
2499 wrq->u.essid.length))
2506 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2509 // Get current Access Point (BSSID)
2511 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2514 // Set desired station name
2516 pr_debug(" SIOCSIWNICKN\n");
2520 // Get current station name
2522 pr_debug(" SIOCGIWNICKN\n");
2526 // Set the desired bit-rate
2528 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2531 // Get the current bit-rate
2534 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2537 // Set the desired RTS threshold
2540 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
2543 // Get the current RTS threshold
2546 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
2549 // Set the desired fragmentation threshold
2552 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
2555 // Get the current fragmentation threshold
2558 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
2561 // Set mode of operation
2563 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
2566 // Get mode of operation
2568 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
2571 // Set WEP keys and mode
2572 case SIOCSIWENCODE: {
2573 char abyKey[WLAN_WEP232_KEYLEN];
2575 if (wrq->u.encoding.pointer) {
2576 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
2580 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
2581 if (copy_from_user(abyKey,
2582 wrq->u.encoding.pointer,
2583 wrq->u.encoding.length)) {
2587 } else if (wrq->u.encoding.length != 0) {
2591 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2595 // Get the WEP keys and mode
2598 if (!capable(CAP_NET_ADMIN)) {
2603 char abyKey[WLAN_WEP232_KEYLEN];
2605 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2608 if (wrq->u.encoding.pointer) {
2609 if (copy_to_user(wrq->u.encoding.pointer,
2611 wrq->u.encoding.length))
2617 // Get the current Tx-Power
2619 pr_debug(" SIOCGIWTXPOW\n");
2624 pr_debug(" SIOCSIWTXPOW\n");
2630 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
2635 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
2638 // Get range of parameters
2642 struct iw_range range;
2644 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *)&range);
2645 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
2653 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
2658 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
2663 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
2667 pr_debug(" SIOCSIWSENS\n");
2671 case SIOCGIWAPLIST: {
2672 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
2674 if (wrq->u.data.pointer) {
2675 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
2677 if (copy_to_user(wrq->u.data.pointer,
2679 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
2691 pr_debug(" SIOCSIWSPY\n");
2698 pr_debug(" SIOCGIWSPY\n");
2702 #endif // WIRELESS_SPY
2705 pr_debug(" SIOCGIWPRIV\n");
2709 //2008-0409-07, <Add> by Einsn Liu
2710 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2712 pr_debug(" SIOCSIWAUTH\n");
2713 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
2717 pr_debug(" SIOCGIWAUTH\n");
2718 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
2722 pr_debug(" SIOCSIWGENIE\n");
2723 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2727 pr_debug(" SIOCGIWGENIE\n");
2728 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2731 case SIOCSIWENCODEEXT: {
2732 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
2734 pr_debug(" SIOCSIWENCODEEXT\n");
2735 if (wrq->u.encoding.pointer) {
2736 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN + 1);
2737 if (wrq->u.encoding.length > (sizeof(struct iw_encode_ext) + MAX_KEY_LEN)) {
2741 if (copy_from_user(extra, wrq->u.encoding.pointer, wrq->u.encoding.length)) {
2745 } else if (wrq->u.encoding.length != 0) {
2749 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
2753 case SIOCGIWENCODEEXT:
2754 pr_debug(" SIOCGIWENCODEEXT\n");
2755 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
2759 pr_debug(" SIOCSIWMLME\n");
2760 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2763 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2764 //End Add -- //2008-0409-07, <Add> by Einsn Liu
2766 case IOCTL_CMD_TEST:
2768 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
2773 pReq = (PSCmdRequest)rq;
2774 pReq->wResult = MAGIC_CODE;
2779 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
2780 (((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_WPA)) {
2786 if (test_and_set_bit(0, (void *)&(pMgmt->uCmdBusy)))
2789 rc = private_ioctl(pDevice, rq);
2790 clear_bit(0, (void *)&(pMgmt->uCmdBusy));
2793 case IOCTL_CMD_HOSTAPD:
2795 rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data);
2800 rc = wpa_ioctl(pDevice, &wrq->u.data);
2804 return ethtool_ioctl(dev, rq->ifr_data);
2805 // All other calls are currently unsupported
2809 pr_debug("Ioctl command not support..%x\n", cmd);
2813 if (pDevice->bCommit) {
2814 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2815 netif_stop_queue(pDevice->dev);
2816 spin_lock_irq(&pDevice->lock);
2817 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
2818 spin_unlock_irq(&pDevice->lock);
2820 pr_debug("Commit the settings\n");
2821 spin_lock_irq(&pDevice->lock);
2822 pDevice->bLinkPass = false;
2823 memset(pMgmt->abyCurrBSSID, 0, 6);
2824 pMgmt->eCurrState = WMAC_STATE_IDLE;
2825 netif_stop_queue(pDevice->dev);
2826 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2827 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
2828 if (!pDevice->bWPASuppWextEnabled)
2830 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
2831 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
2832 spin_unlock_irq(&pDevice->lock);
2834 pDevice->bCommit = false;
2840 static int ethtool_ioctl(struct net_device *dev, void __user *useraddr)
2844 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
2848 case ETHTOOL_GDRVINFO: {
2849 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
2851 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
2852 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
2853 if (copy_to_user(useraddr, &info, sizeof(info)))
2863 static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
2865 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2867 u32 dma_idx = TYPE_AC0DMA;
2868 unsigned long flags;
2870 spin_lock_irqsave(&priv->lock, flags);
2872 if (!ieee80211_is_data(hdr->frame_control))
2873 dma_idx = TYPE_TXDMA0;
2875 if (AVAIL_TD(priv, dma_idx) < 1) {
2876 spin_unlock_irqrestore(&priv->lock, flags);
2880 head_td = priv->apCurrTD[dma_idx];
2882 head_td->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2884 head_td->pTDInfo->skb = skb;
2886 priv->iTDUsed[dma_idx]++;
2888 /* Take ownership */
2890 head_td->m_td0TD0.f1Owner = OWNED_BY_NIC;
2894 priv->apCurrTD[dma_idx] = head_td->next;
2896 spin_unlock_irqrestore(&priv->lock, flags);
2898 vnt_generate_fifo_header(priv, dma_idx, head_td, skb);
2900 if (MACbIsRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
2901 MACbPSWakeup(priv->PortOffset);
2903 spin_lock_irqsave(&priv->lock, flags);
2905 priv->bPWBitOn = false;
2907 head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB;
2909 if (dma_idx == TYPE_AC0DMA)
2910 MACvTransmitAC0(priv->PortOffset);
2912 MACvTransmit0(priv->PortOffset);
2914 spin_unlock_irqrestore(&priv->lock, flags);
2919 static void vnt_tx_80211(struct ieee80211_hw *hw,
2920 struct ieee80211_tx_control *control,
2921 struct sk_buff *skb)
2923 struct vnt_private *priv = hw->priv;
2925 ieee80211_stop_queues(hw);
2927 if (vnt_tx_packet(priv, skb)) {
2928 ieee80211_free_txskb(hw, skb);
2930 ieee80211_wake_queues(hw);
2934 static int vnt_start(struct ieee80211_hw *hw)
2936 struct vnt_private *priv = hw->priv;
2939 priv->rx_buf_sz = PKT_BUF_SZ;
2940 if (!device_init_rings(priv))
2943 ret = request_irq(priv->pcid->irq, &device_intr,
2944 IRQF_SHARED, "vt6655", priv);
2946 dev_dbg(&priv->pcid->dev, "failed to start irq\n");
2950 dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
2951 device_init_rd0_ring(priv);
2952 device_init_rd1_ring(priv);
2953 device_init_defrag_cb(priv);
2954 device_init_td0_ring(priv);
2955 device_init_td1_ring(priv);
2957 device_init_registers(priv);
2959 dev_dbg(&priv->pcid->dev, "call MACvIntEnable\n");
2960 MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
2962 ieee80211_wake_queues(hw);
2967 static void vnt_stop(struct ieee80211_hw *hw)
2969 struct vnt_private *priv = hw->priv;
2971 ieee80211_stop_queues(hw);
2973 MACbShutdown(priv->PortOffset);
2974 MACbSoftwareReset(priv->PortOffset);
2975 CARDbRadioPowerOff(priv);
2977 device_free_td0_ring(priv);
2978 device_free_td1_ring(priv);
2979 device_free_rd0_ring(priv);
2980 device_free_rd1_ring(priv);
2981 device_free_frag_buf(priv);
2982 device_free_rings(priv);
2984 free_irq(priv->pcid->irq, priv);
2987 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2989 struct vnt_private *priv = hw->priv;
2993 switch (vif->type) {
2994 case NL80211_IFTYPE_STATION:
2995 if (priv->bDiversityRegCtlON)
2996 device_init_diversity_timer(priv);
2998 case NL80211_IFTYPE_ADHOC:
2999 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
3001 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
3004 case NL80211_IFTYPE_AP:
3005 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
3007 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
3014 priv->op_mode = vif->type;
3019 static void vnt_remove_interface(struct ieee80211_hw *hw,
3020 struct ieee80211_vif *vif)
3022 struct vnt_private *priv = hw->priv;
3024 switch (vif->type) {
3025 case NL80211_IFTYPE_STATION:
3026 if (priv->bDiversityRegCtlON) {
3027 del_timer(&priv->TimerSQ3Tmax1);
3028 del_timer(&priv->TimerSQ3Tmax2);
3029 del_timer(&priv->TimerSQ3Tmax3);
3032 case NL80211_IFTYPE_ADHOC:
3033 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
3034 MACvRegBitsOff(priv->PortOffset,
3035 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
3036 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
3038 case NL80211_IFTYPE_AP:
3039 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
3040 MACvRegBitsOff(priv->PortOffset,
3041 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
3042 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
3048 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
3052 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
3054 struct vnt_private *priv = hw->priv;
3055 struct ieee80211_conf *conf = &hw->conf;
3058 if (changed & IEEE80211_CONF_CHANGE_PS) {
3059 if (conf->flags & IEEE80211_CONF_PS)
3060 PSvEnablePowerSaving(priv, conf->listen_interval);
3062 PSvDisablePowerSaving(priv);
3065 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
3066 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
3067 set_channel(priv, conf->chandef.chan->hw_value);
3069 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
3070 bb_type = BB_TYPE_11A;
3072 bb_type = BB_TYPE_11G;
3074 if (priv->byBBType != bb_type) {
3075 priv->byBBType = bb_type;
3077 CARDbSetPhyParameter(priv,
3078 priv->byBBType, 0, 0, NULL, NULL);
3082 if (changed & IEEE80211_CONF_CHANGE_POWER) {
3083 if (priv->byBBType == BB_TYPE_11B)
3084 priv->wCurrentRate = RATE_1M;
3086 priv->wCurrentRate = RATE_54M;
3088 RFbSetPower(priv, priv->wCurrentRate,
3089 conf->chandef.chan->hw_value);
3095 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
3096 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
3099 struct vnt_private *priv = hw->priv;
3101 priv->current_aid = conf->aid;
3103 if (changed & BSS_CHANGED_BSSID)
3104 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid);
3106 if (changed & BSS_CHANGED_BASIC_RATES) {
3107 priv->basic_rates = conf->basic_rates;
3109 CARDvUpdateBasicTopRate(priv);
3111 dev_dbg(&priv->pcid->dev,
3112 "basic rates %x\n", conf->basic_rates);
3115 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3116 if (conf->use_short_preamble) {
3117 MACvEnableBarkerPreambleMd(priv->PortOffset);
3118 priv->byPreambleType = true;
3120 MACvDisableBarkerPreambleMd(priv->PortOffset);
3121 priv->byPreambleType = false;
3125 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3126 if (conf->use_cts_prot)
3127 MACvEnableProtectMD(priv->PortOffset);
3129 MACvDisableProtectMD(priv->PortOffset);
3132 if (changed & BSS_CHANGED_ERP_SLOT) {
3133 if (conf->use_short_slot)
3134 priv->bShortSlotTime = true;
3136 priv->bShortSlotTime = false;
3139 CARDbSetPhyParameter(priv, priv->byBBType, 0, 0, NULL, NULL);
3140 BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
3143 if (changed & BSS_CHANGED_TXPOWER)
3144 RFbSetPower(priv, priv->wCurrentRate,
3145 conf->chandef.chan->hw_value);
3147 if (changed & BSS_CHANGED_BEACON_ENABLED) {
3148 dev_dbg(&priv->pcid->dev,
3149 "Beacon enable %d\n", conf->enable_beacon);
3151 if (conf->enable_beacon) {
3152 vnt_beacon_enable(priv, vif, conf);
3154 MACvRegBitsOn(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
3156 MACvRegBitsOff(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
3160 if (changed & BSS_CHANGED_ASSOC && priv->op_mode != NL80211_IFTYPE_AP) {
3162 CARDbUpdateTSF(priv, conf->beacon_rate->hw_value,
3163 conf->sync_device_ts, conf->sync_tsf);
3165 CARDbSetBeaconPeriod(priv, conf->beacon_int);
3167 CARDvSetFirstNextTBTT(priv->PortOffset,
3173 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
3174 struct netdev_hw_addr_list *mc_list)
3176 struct vnt_private *priv = hw->priv;
3177 struct netdev_hw_addr *ha;
3181 netdev_hw_addr_list_for_each(ha, mc_list) {
3182 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
3184 mc_filter |= 1ULL << (bit_nr & 0x3f);
3187 priv->mc_list_count = mc_list->count;
3192 static void vnt_configure(struct ieee80211_hw *hw,
3193 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
3195 struct vnt_private *priv = hw->priv;
3198 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_PROMISC_IN_BSS |
3199 FIF_BCN_PRBRESP_PROMISC;
3201 VNSvInPortB(priv->PortOffset + MAC_REG_RCR, &rx_mode);
3203 dev_dbg(&priv->pcid->dev, "rx mode in = %x\n", rx_mode);
3205 if (changed_flags & FIF_PROMISC_IN_BSS) {
3206 /* unconditionally log net taps */
3207 if (*total_flags & FIF_PROMISC_IN_BSS)
3208 rx_mode |= RCR_UNICAST;
3210 rx_mode &= ~RCR_UNICAST;
3213 if (changed_flags & FIF_ALLMULTI) {
3214 if (*total_flags & FIF_ALLMULTI) {
3215 if (priv->mc_list_count > 2) {
3216 MACvSelectPage1(priv->PortOffset);
3218 VNSvOutPortD(priv->PortOffset +
3219 MAC_REG_MAR0, 0xffffffff);
3220 VNSvOutPortD(priv->PortOffset +
3221 MAC_REG_MAR0 + 4, 0xffffffff);
3223 MACvSelectPage0(priv->PortOffset);
3225 MACvSelectPage1(priv->PortOffset);
3227 VNSvOutPortD(priv->PortOffset +
3228 MAC_REG_MAR0, (u32)multicast);
3229 VNSvOutPortD(priv->PortOffset +
3231 (u32)(multicast >> 32));
3233 MACvSelectPage0(priv->PortOffset);
3236 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
3238 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
3242 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
3243 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
3245 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
3246 rx_mode &= ~RCR_BSSID;
3248 rx_mode |= RCR_BSSID;
3251 VNSvOutPortB(priv->PortOffset + MAC_REG_RCR, rx_mode);
3253 dev_dbg(&priv->pcid->dev, "rx mode out= %x\n", rx_mode);
3256 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3257 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3258 struct ieee80211_key_conf *key)
3260 struct vnt_private *priv = hw->priv;
3264 if (vnt_set_keys(hw, sta, vif, key))
3268 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
3269 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
3277 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
3279 struct vnt_private *priv = hw->priv;
3282 CARDbGetCurrentTSF(priv->PortOffset, &tsf);
3287 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3290 struct vnt_private *priv = hw->priv;
3292 CARDvUpdateNextTBTT(priv->PortOffset, tsf, vif->bss_conf.beacon_int);
3295 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
3297 struct vnt_private *priv = hw->priv;
3299 /* reset TSF counter */
3300 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
3303 static const struct ieee80211_ops vnt_mac_ops = {
3307 .add_interface = vnt_add_interface,
3308 .remove_interface = vnt_remove_interface,
3309 .config = vnt_config,
3310 .bss_info_changed = vnt_bss_info_changed,
3311 .prepare_multicast = vnt_prepare_multicast,
3312 .configure_filter = vnt_configure,
3313 .set_key = vnt_set_key,
3314 .get_tsf = vnt_get_tsf,
3315 .set_tsf = vnt_set_tsf,
3316 .reset_tsf = vnt_reset_tsf,
3319 int vnt_init(struct vnt_private *priv)
3321 SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyCurrentNetAddr);
3323 if (ieee80211_register_hw(priv->hw))
3326 priv->mac_hw = true;
3328 CARDbRadioPowerOff(priv);
3334 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
3336 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
3337 struct vnt_private *priv;
3338 struct ieee80211_hw *hw;
3339 struct wiphy *wiphy;
3342 dev_notice(&pcid->dev,
3343 "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
3345 dev_notice(&pcid->dev,
3346 "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
3348 hw = ieee80211_alloc_hw(sizeof(*priv), &vnt_mac_ops);
3350 dev_err(&pcid->dev, "could not register ieee80211_hw\n");
3356 vt6655_init_info(pcid, &priv, pChip_info);
3360 SET_IEEE80211_DEV(priv->hw, &pcid->dev);
3362 if (pci_enable_device(pcid)) {
3363 device_free_info(priv);
3368 "Before get pci_info memaddr is %x\n", priv->memaddr);
3370 if (!device_get_pci_info(priv, pcid)) {
3371 dev_err(&pcid->dev, ": Failed to find PCI device.\n");
3372 device_free_info(priv);
3378 "after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",
3379 priv->memaddr, priv->ioaddr, priv->io_size);
3391 for (i = 0; address[i]; i++) {
3392 pci_read_config_dword(pcid, address[i], &bar);
3394 dev_dbg(&pcid->dev, "bar %d is %x\n", i, bar);
3398 "bar %d not implemented\n", i);
3402 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
3405 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xffff);
3406 len = len & ~(len - 1);
3409 "IO space: len in IO %x, BAR %d\n",
3412 len = bar & 0xfffffff0;
3416 "len in MEM %x, BAR %d\n", len, i);
3422 priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK,
3424 if (!priv->PortOffset) {
3425 dev_err(&pcid->dev, ": Failed to IO remapping ..\n");
3426 device_free_info(priv);
3430 rc = pci_request_regions(pcid, DEVICE_NAME);
3432 dev_err(&pcid->dev, ": Failed to find PCI device\n");
3433 device_free_info(priv);
3438 if (!MACbSoftwareReset(priv->PortOffset)) {
3439 dev_err(&pcid->dev, ": Failed to access MAC hardware..\n");
3440 device_free_info(priv);
3443 /* initial to reload eeprom */
3444 MACvInitialize(priv->PortOffset);
3445 MACvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr);
3447 device_get_options(priv);
3448 device_set_options(priv);
3449 /* Mask out the options cannot be set to the chip */
3450 priv->sOpts.flags &= pChip_info->flags;
3452 /* Enable the chip specified capabilities */
3453 priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL);
3454 priv->tx_80211 = device_dma0_tx_80211;
3455 priv->sMgmtObj.pAdapter = (void *)priv;
3456 priv->pMgmt = &(priv->sMgmtObj);
3458 wiphy = priv->hw->wiphy;
3460 wiphy->frag_threshold = FRAG_THRESH_DEF;
3461 wiphy->rts_threshold = RTS_THRESH_DEF;
3462 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3463 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
3465 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
3466 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3467 IEEE80211_HW_SIGNAL_DBM |
3468 IEEE80211_HW_TIMING_BEACON_ONLY;
3470 priv->hw->max_signal = 100;
3475 device_print_info(priv);
3476 pci_set_drvdata(pcid, priv);
3481 /*------------------------------------------------------------------*/
3483 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
3485 static struct pci_driver device_driver = {
3486 .name = DEVICE_NAME,
3487 .id_table = vt6655_pci_id_table,
3488 .probe = vt6655_probe,
3489 .remove = vt6655_remove,
3491 .suspend = viawget_suspend,
3492 .resume = viawget_resume,
3496 static int __init vt6655_init_module(void)
3500 ret = pci_register_driver(&device_driver);
3503 register_reboot_notifier(&device_notifier);
3509 static void __exit vt6655_cleanup_module(void)
3512 unregister_reboot_notifier(&device_notifier);
3514 pci_unregister_driver(&device_driver);
3517 module_init(vt6655_init_module);
3518 module_exit(vt6655_cleanup_module);
3522 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3524 struct pci_dev *pdev = NULL;
3530 for_each_pci_dev(pdev) {
3531 if (pci_dev_driver(pdev) == &device_driver) {
3532 if (pci_get_drvdata(pdev))
3533 viawget_suspend(pdev, PMSG_HIBERNATE);
3541 viawget_suspend(struct pci_dev *pcid, pm_message_t state)
3543 int power_status; // to silence the compiler
3545 struct vnt_private *pDevice = pci_get_drvdata(pcid);
3546 PSMgmtObject pMgmt = pDevice->pMgmt;
3548 netif_stop_queue(pDevice->dev);
3549 spin_lock_irq(&pDevice->lock);
3550 pci_save_state(pcid);
3551 del_timer(&pDevice->sTimerCommand);
3552 del_timer(&pMgmt->sTimerSecondCallback);
3553 pDevice->cbFreeCmdQueue = CMD_Q_SIZE;
3554 pDevice->uCmdDequeueIdx = 0;
3555 pDevice->uCmdEnqueueIdx = 0;
3556 pDevice->bCmdRunning = false;
3557 MACbShutdown(pDevice->PortOffset);
3558 MACvSaveContext(pDevice->PortOffset, pDevice->abyMacContext);
3559 pDevice->bLinkPass = false;
3560 memset(pMgmt->abyCurrBSSID, 0, 6);
3561 pMgmt->eCurrState = WMAC_STATE_IDLE;
3562 pci_disable_device(pcid);
3563 power_status = pci_set_power_state(pcid, pci_choose_state(pcid, state));
3564 spin_unlock_irq(&pDevice->lock);
3569 viawget_resume(struct pci_dev *pcid)
3571 struct vnt_private *pDevice = pci_get_drvdata(pcid);
3572 PSMgmtObject pMgmt = pDevice->pMgmt;
3573 int power_status; // to silence the compiler
3575 power_status = pci_set_power_state(pcid, PCI_D0);
3576 power_status = pci_enable_wake(pcid, PCI_D0, 0);
3577 pci_restore_state(pcid);
3578 if (netif_running(pDevice->dev)) {
3579 spin_lock_irq(&pDevice->lock);
3580 MACvRestoreContext(pDevice->PortOffset, pDevice->abyMacContext);
3581 device_init_registers(pDevice);
3582 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
3583 pMgmt->sNodeDBTable[0].bActive = false;
3584 pDevice->bLinkPass = false;
3585 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
3586 // In Adhoc, BSS state set back to started.
3587 pMgmt->eCurrState = WMAC_STATE_STARTED;
3589 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
3590 pMgmt->eCurrState = WMAC_STATE_IDLE;
3593 init_timer(&pMgmt->sTimerSecondCallback);
3594 init_timer(&pDevice->sTimerCommand);
3595 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
3596 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
3597 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
3598 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
3599 spin_unlock_irq(&pDevice->lock);