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 struct notifier_block device_notifier = {
278 .notifier_call = device_notify_reboot,
284 static void device_init_rd0_ring(struct vnt_private *pDevice);
285 static void device_init_rd1_ring(struct vnt_private *pDevice);
286 static void device_init_defrag_cb(struct vnt_private *pDevice);
287 static void device_init_td0_ring(struct vnt_private *pDevice);
288 static void device_init_td1_ring(struct vnt_private *pDevice);
290 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev);
291 //2008-0714<Add>by Mike Liu
292 static bool device_release_WPADEV(struct vnt_private *pDevice);
294 static int ethtool_ioctl(struct net_device *dev, void __user *useraddr);
295 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx);
296 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx);
297 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc);
298 static void device_init_registers(struct vnt_private *pDevice);
299 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc);
300 static void device_free_td0_ring(struct vnt_private *pDevice);
301 static void device_free_td1_ring(struct vnt_private *pDevice);
302 static void device_free_rd0_ring(struct vnt_private *pDevice);
303 static void device_free_rd1_ring(struct vnt_private *pDevice);
304 static void device_free_rings(struct vnt_private *pDevice);
305 static void device_free_frag_buf(struct vnt_private *pDevice);
306 static int Config_FileGetParameter(unsigned char *string,
307 unsigned char *dest, unsigned char *source);
309 /*--------------------- Export Variables --------------------------*/
311 /*--------------------- Export Functions --------------------------*/
313 static char *get_chip_name(int chip_id)
317 for (i = 0; chip_info_table[i].name != NULL; i++)
318 if (chip_info_table[i].chip_id == chip_id)
320 return chip_info_table[i].name;
323 static void vt6655_remove(struct pci_dev *pcid)
325 struct vnt_private *pDevice = pci_get_drvdata(pcid);
329 device_free_info(pDevice);
332 static void device_get_options(struct vnt_private *pDevice)
334 POPTIONS pOpts = &(pDevice->sOpts);
336 pOpts->nRxDescs0 = RX_DESC_DEF0;
337 pOpts->nRxDescs1 = RX_DESC_DEF1;
338 pOpts->nTxDescs[0] = TX_DESC_DEF0;
339 pOpts->nTxDescs[1] = TX_DESC_DEF1;
340 pOpts->flags |= DEVICE_FLAGS_IP_ALIGN;
341 pOpts->int_works = INT_WORKS_DEF;
342 pOpts->rts_thresh = RTS_THRESH_DEF;
343 pOpts->frag_thresh = FRAG_THRESH_DEF;
344 pOpts->data_rate = DATA_RATE_DEF;
345 pOpts->channel_num = CHANNEL_DEF;
347 pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE;
348 pOpts->flags |= DEVICE_FLAGS_OP_MODE;
349 pOpts->short_retry = SHORT_RETRY_DEF;
350 pOpts->long_retry = LONG_RETRY_DEF;
351 pOpts->bbp_type = BBP_TYPE_DEF;
352 pOpts->flags |= DEVICE_FLAGS_80211h_MODE;
353 pOpts->flags |= DEVICE_FLAGS_DiversityANT;
357 device_set_options(struct vnt_private *pDevice)
359 unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
360 unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
361 unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
363 ether_addr_copy(pDevice->abyBroadcastAddr, abyBroadcastAddr);
364 ether_addr_copy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042);
365 ether_addr_copy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel);
367 pDevice->uChannel = pDevice->sOpts.channel_num;
368 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
369 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
370 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
371 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
372 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
373 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
374 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
375 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
376 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
377 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
378 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
379 if (pDevice->uConnectionRate < RATE_AUTO)
380 pDevice->bFixRate = true;
381 pDevice->byBBType = pDevice->sOpts.bbp_type;
382 pDevice->byPacketType = (VIA_PKT_TYPE)pDevice->byBBType;
383 pDevice->byAutoFBCtrl = AUTO_FB_0;
384 pDevice->bUpdateBBVGA = true;
385 pDevice->byFOETuning = 0;
386 pDevice->byPreambleType = 0;
388 pr_debug(" uChannel= %d\n", (int)pDevice->uChannel);
389 pr_debug(" byOpMode= %d\n", (int)pDevice->byOpMode);
390 pr_debug(" ePSMode= %d\n", (int)pDevice->ePSMode);
391 pr_debug(" wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
392 pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
393 pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
394 pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType);
395 pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
396 pr_debug(" uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
397 pr_debug(" byBBType= %d\n", (int)pDevice->byBBType);
398 pr_debug(" pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
399 pr_debug(" pDevice->bDiversityRegCtlON= %d\n",
400 (int)pDevice->bDiversityRegCtlON);
404 // Initialisation of MAC & BBP registers
407 static void device_init_registers(struct vnt_private *pDevice)
410 unsigned char byValue;
411 unsigned char byValue1;
412 unsigned char byCCKPwrdBm = 0;
413 unsigned char byOFDMPwrdBm = 0;
416 MACbShutdown(pDevice->PortOffset);
417 BBvSoftwareReset(pDevice->PortOffset);
419 /* Do MACbSoftwareReset in MACvInitialize */
420 MACbSoftwareReset(pDevice->PortOffset);
422 pDevice->bAES = false;
424 /* Only used in 11g type, sync with ERP IE */
425 pDevice->bProtectMode = false;
427 pDevice->bNonERPPresent = false;
428 pDevice->bBarkerPreambleMd = false;
429 pDevice->wCurrentRate = RATE_1M;
430 pDevice->byTopOFDMBasicRate = RATE_24M;
431 pDevice->byTopCCKBasicRate = RATE_1M;
433 /* Target to IF pin while programming to RF chip. */
434 pDevice->byRevId = 0;
437 MACvInitialize(pDevice->PortOffset);
440 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
442 spin_lock_irq(&pDevice->lock);
444 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
446 spin_unlock_irq(&pDevice->lock);
448 /* Get Channel range */
449 pDevice->byMinChannel = 1;
450 pDevice->byMaxChannel = CB_MAX_CHANNEL;
453 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
454 if (byValue & EEP_ANTINV)
455 pDevice->bTxRxAntInv = true;
457 pDevice->bTxRxAntInv = false;
459 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
460 /* if not set default is All */
462 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
464 pDevice->ulDiversityNValue = 100*260;
465 pDevice->ulDiversityMValue = 100*16;
467 pDevice->byTMax2 = 4;
468 pDevice->ulSQ3TH = 0;
469 pDevice->byTMax3 = 64;
471 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
472 pDevice->byAntennaCount = 2;
473 pDevice->byTxAntennaMode = ANT_B;
474 pDevice->dwTxAntennaSel = 1;
475 pDevice->dwRxAntennaSel = 1;
477 if (pDevice->bTxRxAntInv)
478 pDevice->byRxAntennaMode = ANT_A;
480 pDevice->byRxAntennaMode = ANT_B;
482 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset,
485 if ((byValue1 & 0x08) == 0)
486 pDevice->bDiversityEnable = false;
488 pDevice->bDiversityEnable = true;
490 pDevice->bDiversityEnable = false;
491 pDevice->byAntennaCount = 1;
492 pDevice->dwTxAntennaSel = 0;
493 pDevice->dwRxAntennaSel = 0;
495 if (byValue & EEP_ANTENNA_AUX) {
496 pDevice->byTxAntennaMode = ANT_A;
498 if (pDevice->bTxRxAntInv)
499 pDevice->byRxAntennaMode = ANT_B;
501 pDevice->byRxAntennaMode = ANT_A;
503 pDevice->byTxAntennaMode = ANT_B;
505 if (pDevice->bTxRxAntInv)
506 pDevice->byRxAntennaMode = ANT_A;
508 pDevice->byRxAntennaMode = ANT_B;
512 pr_debug("bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
513 pDevice->bDiversityEnable, (int)pDevice->ulDiversityNValue,
514 (int)pDevice->ulDiversityMValue, pDevice->byTMax,
517 /* zonetype initial */
518 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
519 zonetype = Config_FileOperation(pDevice, false, NULL);
522 if ((zonetype == 0) &&
523 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x00)) {
525 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0;
526 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0B;
528 pr_debug("Init Zone Type :USA\n");
529 } else if ((zonetype == 1) &&
530 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x01)) {
532 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x01;
533 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
534 } else if ((zonetype == 2) &&
535 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] != 0x02)) {
537 pDevice->abyEEPROM[EEP_OFS_ZONETYPE] = 0x02;
538 pDevice->abyEEPROM[EEP_OFS_MAXCHANNEL] = 0x0D;
540 pr_debug("Init Zone Type :Europe\n");
542 if (zonetype != pDevice->abyEEPROM[EEP_OFS_ZONETYPE])
543 pr_debug("zonetype in file[%02x] mismatch with in EEPROM[%02x]\n",
545 pDevice->abyEEPROM[EEP_OFS_ZONETYPE]);
547 pr_debug("Read Zonetype file success,use default zonetype setting[%02x]\n",
551 pr_debug("Read Zonetype file fail,use default zonetype setting[%02x]\n",
552 SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ZONETYPE));
556 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
558 /* force change RevID for VT3253 emu */
559 if ((pDevice->byRFType & RF_EMU) != 0)
560 pDevice->byRevId = 0x80;
562 pDevice->byRFType &= RF_MASK;
563 pr_debug("pDevice->byRFType = %x\n", pDevice->byRFType);
565 if (!pDevice->bZoneRegExist)
566 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
568 pr_debug("pDevice->byZoneType = %x\n", pDevice->byZoneType);
573 /* Get Desire Power Value */
574 pDevice->byCurPwr = 0xFF;
575 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
576 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
578 /* Load power Table */
579 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
580 pDevice->abyCCKPwrTbl[ii + 1] =
581 SROMbyReadEmbedded(pDevice->PortOffset,
582 (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
583 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
584 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
586 pDevice->abyOFDMPwrTbl[ii + 1] =
587 SROMbyReadEmbedded(pDevice->PortOffset,
588 (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
589 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
590 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
592 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
593 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
596 /* recover 12,13 ,14channel for EUROPE by 11 channel */
597 if (((pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Japan) ||
598 (pDevice->abyEEPROM[EEP_OFS_ZONETYPE] == ZoneType_Europe)) &&
599 (pDevice->byOriginalZonetype == ZoneType_USA)) {
600 for (ii = 11; ii < 14; ii++) {
601 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
602 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
607 /* Load OFDM A Power Table */
608 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
609 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
610 SROMbyReadEmbedded(pDevice->PortOffset,
611 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
613 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
614 SROMbyReadEmbedded(pDevice->PortOffset,
615 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
618 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
619 MACvSelectPage1(pDevice->PortOffset);
621 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
622 (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
624 MACvSelectPage0(pDevice->PortOffset);
627 /* use relative tx timeout and 802.11i D4 */
628 MACvWordRegBitsOn(pDevice->PortOffset,
629 MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
631 /* set performance parameter by registry */
632 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
633 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
635 /* reset TSF counter */
636 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
637 /* enable TSF counter */
638 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
640 /* initialize BBP registers */
641 BBbVT3253Init(pDevice);
643 if (pDevice->bUpdateBBVGA) {
644 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
645 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
646 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
649 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
650 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
652 /* Set BB and packet type at the same time. */
653 /* Set Short Slot Time, xIFS, and RSPINF. */
654 if (pDevice->uConnectionRate == RATE_AUTO)
655 pDevice->wCurrentRate = RATE_54M;
657 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
659 pDevice->bRadioOff = false;
661 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
663 pDevice->bHWRadioOff = false;
665 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
667 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
669 if (((pDevice->byGPIO & GPIO0_DATA) &&
670 !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
671 (!(pDevice->byGPIO & GPIO0_DATA) &&
672 (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
673 pDevice->bHWRadioOff = true;
676 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
677 CARDbRadioPowerOff(pDevice);
679 /* get Permanent network address */
680 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
681 pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
683 /* reset Tx pointer */
684 CARDvSafeResetRx(pDevice);
685 /* reset Rx pointer */
686 CARDvSafeResetTx(pDevice);
688 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
689 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
692 MACvReceive0(pDevice->PortOffset);
693 MACvReceive1(pDevice->PortOffset);
695 /* start the adapter */
696 MACvStart(pDevice->PortOffset);
699 static void device_init_diversity_timer(struct vnt_private *pDevice)
701 init_timer(&pDevice->TimerSQ3Tmax1);
702 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
703 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
704 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
706 init_timer(&pDevice->TimerSQ3Tmax2);
707 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
708 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
709 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
711 init_timer(&pDevice->TimerSQ3Tmax3);
712 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
713 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
714 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
717 static bool device_release_WPADEV(struct vnt_private *pDevice)
719 viawget_wpa_header *wpahdr;
722 //send device close to wpa_supplicnat layer
723 if (pDevice->bWPADEVUp) {
724 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
725 wpahdr->type = VIAWGET_DEVICECLOSE_MSG;
726 wpahdr->resp_ie_len = 0;
727 wpahdr->req_ie_len = 0;
728 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
729 pDevice->skb->dev = pDevice->wpadev;
730 skb_reset_mac_header(pDevice->skb);
731 pDevice->skb->pkt_type = PACKET_HOST;
732 pDevice->skb->protocol = htons(ETH_P_802_2);
733 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
734 netif_rx(pDevice->skb);
735 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
737 while (pDevice->bWPADEVUp) {
738 set_current_state(TASK_UNINTERRUPTIBLE);
739 schedule_timeout(HZ / 20); //wait 50ms
748 static const struct net_device_ops device_netdev_ops = {
749 .ndo_open = device_open,
750 .ndo_stop = device_close,
751 .ndo_do_ioctl = device_ioctl,
752 .ndo_start_xmit = device_xmit,
753 .ndo_set_rx_mode = device_set_multi,
756 static void device_print_info(struct vnt_private *pDevice)
758 dev_info(&pDevice->pcid->dev, "%s\n", get_chip_name(pDevice->chip_id));
760 dev_info(&pDevice->pcid->dev, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
761 pDevice->abyCurrentNetAddr, (unsigned long)pDevice->ioaddr,
762 (unsigned long)pDevice->PortOffset, pDevice->pcid->irq);
765 static void vt6655_init_info(struct pci_dev *pcid,
766 struct vnt_private **ppDevice,
767 PCHIP_INFO pChip_info)
769 memset(*ppDevice, 0, sizeof(**ppDevice));
771 (*ppDevice)->pcid = pcid;
772 (*ppDevice)->chip_id = pChip_info->chip_id;
773 (*ppDevice)->io_size = pChip_info->io_size;
774 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
775 (*ppDevice)->multicast_limit = 32;
777 spin_lock_init(&((*ppDevice)->lock));
780 static bool device_get_pci_info(struct vnt_private *pDevice,
781 struct pci_dev *pcid)
785 unsigned int cis_addr;
787 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
788 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
789 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
790 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
792 pci_set_master(pcid);
794 pDevice->memaddr = pci_resource_start(pcid, 0);
795 pDevice->ioaddr = pci_resource_start(pcid, 1);
797 cis_addr = pci_resource_start(pcid, 2);
799 pDevice->pcid = pcid;
801 pci_read_config_byte(pcid, PCI_COMMAND, &b);
802 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
807 static void device_free_info(struct vnt_private *pDevice)
813 ieee80211_unregister_hw(pDevice->hw);
815 if (pDevice->PortOffset)
816 iounmap(pDevice->PortOffset);
819 pci_release_regions(pDevice->pcid);
822 ieee80211_free_hw(pDevice->hw);
825 static bool device_init_rings(struct vnt_private *pDevice)
829 /*allocate all RD/TD rings a single pool*/
830 vir_pool = pci_zalloc_consistent(pDevice->pcid,
831 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
832 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
833 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
834 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
836 if (vir_pool == NULL) {
837 dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n");
841 pDevice->aRD0Ring = vir_pool;
842 pDevice->aRD1Ring = vir_pool +
843 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
845 pDevice->rd0_pool_dma = pDevice->pool_dma;
846 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
847 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
849 pDevice->tx0_bufs = pci_zalloc_consistent(pDevice->pcid,
850 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
851 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
854 &pDevice->tx_bufs_dma0);
855 if (pDevice->tx0_bufs == NULL) {
856 dev_err(&pDevice->pcid->dev, "allocate buf dma memory failed\n");
858 pci_free_consistent(pDevice->pcid,
859 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
860 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
861 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
862 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
863 vir_pool, pDevice->pool_dma
868 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
869 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
871 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
872 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
874 // vir_pool: pvoid type
875 pDevice->apTD0Rings = vir_pool
876 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
877 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
879 pDevice->apTD1Rings = vir_pool
880 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
881 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
882 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
884 pDevice->tx1_bufs = pDevice->tx0_bufs +
885 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
887 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
888 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
890 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
893 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
894 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
896 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
897 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
902 static void device_free_rings(struct vnt_private *pDevice)
904 pci_free_consistent(pDevice->pcid,
905 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
906 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
907 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
908 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
910 pDevice->aRD0Ring, pDevice->pool_dma
913 if (pDevice->tx0_bufs)
914 pci_free_consistent(pDevice->pcid,
915 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
916 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
919 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
923 static void device_init_rd0_ring(struct vnt_private *pDevice)
926 dma_addr_t curr = pDevice->rd0_pool_dma;
929 /* Init the RD0 ring entries */
930 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
931 pDesc = &(pDevice->aRD0Ring[i]);
932 pDesc->pRDInfo = alloc_rd_info();
933 ASSERT(pDesc->pRDInfo);
934 if (!device_alloc_rx_buf(pDevice, pDesc))
935 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
937 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
938 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
939 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
943 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
944 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
947 static void device_init_rd1_ring(struct vnt_private *pDevice)
950 dma_addr_t curr = pDevice->rd1_pool_dma;
953 /* Init the RD1 ring entries */
954 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
955 pDesc = &(pDevice->aRD1Ring[i]);
956 pDesc->pRDInfo = alloc_rd_info();
957 ASSERT(pDesc->pRDInfo);
958 if (!device_alloc_rx_buf(pDevice, pDesc))
959 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
961 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
962 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
963 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
967 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
968 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
971 static void device_init_defrag_cb(struct vnt_private *pDevice)
974 PSDeFragControlBlock pDeF;
976 /* Init the fragment ctl entries */
977 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
978 pDeF = &(pDevice->sRxDFCB[i]);
979 if (!device_alloc_frag_buf(pDevice, pDeF))
980 dev_err(&pDevice->pcid->dev, "can not alloc frag bufs\n");
982 pDevice->cbDFCB = CB_MAX_RX_FRAG;
983 pDevice->cbFreeDFCB = pDevice->cbDFCB;
986 static void device_free_rd0_ring(struct vnt_private *pDevice)
990 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
991 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
992 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
994 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
995 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
997 dev_kfree_skb(pRDInfo->skb);
999 kfree(pDesc->pRDInfo);
1003 static void device_free_rd1_ring(struct vnt_private *pDevice)
1007 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
1008 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
1009 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
1011 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
1012 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1014 dev_kfree_skb(pRDInfo->skb);
1016 kfree(pDesc->pRDInfo);
1020 static void device_free_frag_buf(struct vnt_private *pDevice)
1022 PSDeFragControlBlock pDeF;
1025 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
1026 pDeF = &(pDevice->sRxDFCB[i]);
1029 dev_kfree_skb(pDeF->skb);
1034 static void device_init_td0_ring(struct vnt_private *pDevice)
1040 curr = pDevice->td0_pool_dma;
1041 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
1042 pDesc = &(pDevice->apTD0Rings[i]);
1043 pDesc->pTDInfo = alloc_td_info();
1044 ASSERT(pDesc->pTDInfo);
1045 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1046 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
1047 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
1049 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
1050 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1051 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1055 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
1056 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
1059 static void device_init_td1_ring(struct vnt_private *pDevice)
1065 /* Init the TD ring entries */
1066 curr = pDevice->td1_pool_dma;
1067 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
1068 pDesc = &(pDevice->apTD1Rings[i]);
1069 pDesc->pTDInfo = alloc_td_info();
1070 ASSERT(pDesc->pTDInfo);
1071 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
1072 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
1073 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
1075 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
1076 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
1077 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
1081 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
1082 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
1085 static void device_free_td0_ring(struct vnt_private *pDevice)
1089 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
1090 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
1091 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1093 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1094 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1095 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1098 dev_kfree_skb(pTDInfo->skb);
1100 kfree(pDesc->pTDInfo);
1104 static void device_free_td1_ring(struct vnt_private *pDevice)
1108 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1109 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
1110 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1112 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1113 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1114 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1117 dev_kfree_skb(pTDInfo->skb);
1119 kfree(pDesc->pTDInfo);
1123 /*-----------------------------------------------------------------*/
1125 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1130 for (pRD = pDevice->pCurrRD[uIdx];
1131 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1135 if (vnt_receive_frame(pDevice, pRD)) {
1136 if (!device_alloc_rx_buf(pDevice, pRD)) {
1137 dev_err(&pDevice->pcid->dev,
1138 "can not allocate rx buf\n");
1142 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1145 pDevice->pCurrRD[uIdx] = pRD;
1150 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
1152 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1154 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1155 if (pRDInfo->skb == NULL)
1157 ASSERT(pRDInfo->skb);
1160 pci_map_single(pDevice->pcid,
1161 skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)),
1162 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1164 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1166 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1167 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1168 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1169 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1174 bool device_alloc_frag_buf(struct vnt_private *pDevice,
1175 PSDeFragControlBlock pDeF)
1177 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1178 if (pDeF->skb == NULL)
1185 static const u8 fallback_rate0[5][5] = {
1186 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
1187 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
1188 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
1189 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
1190 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
1193 static const u8 fallback_rate1[5][5] = {
1194 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
1195 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
1196 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
1197 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
1198 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
1201 static int vnt_int_report_rate(struct vnt_private *priv,
1202 PDEVICE_TD_INFO context, u8 tsr0, u8 tsr1)
1204 struct vnt_tx_fifo_head *fifo_head;
1205 struct ieee80211_tx_info *info;
1206 struct ieee80211_rate *rate;
1208 u8 tx_retry = (tsr0 & TSR0_NCR);
1217 fifo_head = (struct vnt_tx_fifo_head *)context->buf;
1218 fb_option = (le16_to_cpu(fifo_head->fifo_ctl) &
1219 (FIFOCTL_AUTO_FB_0 | FIFOCTL_AUTO_FB_1));
1221 info = IEEE80211_SKB_CB(context->skb);
1222 idx = info->control.rates[0].idx;
1224 if (fb_option && !(tsr1 & TSR1_TERR)) {
1226 u8 retry = tx_retry;
1228 rate = ieee80211_get_tx_rate(priv->hw, info);
1229 tx_rate = rate->hw_value - RATE_18M;
1234 if (fb_option & FIFOCTL_AUTO_FB_0)
1235 tx_rate = fallback_rate0[tx_rate][retry];
1236 else if (fb_option & FIFOCTL_AUTO_FB_1)
1237 tx_rate = fallback_rate1[tx_rate][retry];
1239 if (info->band == IEEE80211_BAND_5GHZ)
1240 idx = tx_rate - RATE_6M;
1245 ieee80211_tx_info_clear_status(info);
1247 info->status.rates[0].count = tx_retry;
1249 if (!(tsr1 & TSR1_TERR)) {
1250 info->status.rates[0].idx = idx;
1251 info->flags |= IEEE80211_TX_STAT_ACK;
1257 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1261 unsigned char byTsr0;
1262 unsigned char byTsr1;
1264 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1265 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1270 byTsr0 = pTD->m_td0TD0.byTSR0;
1271 byTsr1 = pTD->m_td0TD0.byTSR1;
1273 //Only the status of first TD in the chain is correct
1274 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1275 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1277 vnt_int_report_rate(pDevice, pTD->pTDInfo, byTsr0, byTsr1);
1279 if (!(byTsr1 & TSR1_TERR)) {
1281 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
1286 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
1287 (int)uIdx, byTsr1, byTsr0);
1291 if (byTsr1 & TSR1_TERR) {
1292 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1293 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
1294 (int)uIdx, byTsr1, byTsr0);
1297 device_free_tx_buf(pDevice, pTD);
1298 pDevice->iTDUsed[uIdx]--;
1300 /* Make sure queue is available */
1301 if (AVAIL_TD(pDevice, uIdx))
1302 ieee80211_wake_queues(pDevice->hw);
1306 pDevice->apTailTD[uIdx] = pTD;
1311 static void device_error(struct vnt_private *pDevice, unsigned short status)
1313 if (status & ISR_FETALERR) {
1314 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
1316 MACbShutdown(pDevice->PortOffset);
1321 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
1323 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1324 struct sk_buff *skb = pTDInfo->skb;
1326 // pre-allocated buf_dma can't be unmapped.
1327 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1328 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1332 if (pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)
1333 ieee80211_tx_status_irqsafe(pDevice->hw, skb);
1335 dev_kfree_skb_irq(skb);
1337 pTDInfo->skb_dma = 0;
1338 pTDInfo->skb = NULL;
1339 pTDInfo->byFlags = 0;
1342 static int device_open(struct net_device *dev)
1344 struct vnt_private *pDevice = netdev_priv(dev);
1347 pDevice->rx_buf_sz = PKT_BUF_SZ;
1348 if (!device_init_rings(pDevice))
1351 //2008-5-13 <add> by chester
1352 i = request_irq(pDevice->pcid->irq, &device_intr, IRQF_SHARED, dev->name, dev);
1356 #ifdef WPA_SM_Transtatus
1357 pDevice->fWPA_Authened = false;
1359 pr_debug("call device init rd0 ring\n");
1360 device_init_rd0_ring(pDevice);
1361 device_init_rd1_ring(pDevice);
1362 device_init_defrag_cb(pDevice);
1363 device_init_td0_ring(pDevice);
1364 device_init_td1_ring(pDevice);
1366 if (pDevice->bDiversityRegCtlON)
1367 device_init_diversity_timer(pDevice);
1369 vMgrObjectInit(pDevice);
1370 vMgrTimerInit(pDevice);
1372 pr_debug("call device_init_registers\n");
1373 device_init_registers(pDevice);
1375 MACvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
1376 ether_addr_copy(pDevice->pMgmt->abyMACAddr, pDevice->abyCurrentNetAddr);
1377 device_set_multi(pDevice->dev);
1379 // Init for Key Management
1380 KeyvInitTable(&pDevice->sKey, pDevice->PortOffset);
1381 add_timer(&(pDevice->pMgmt->sTimerSecondCallback));
1383 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1384 pDevice->bwextcount = 0;
1385 pDevice->bWPASuppWextEnabled = false;
1387 pDevice->byReAssocCount = 0;
1388 pDevice->bWPADEVUp = false;
1389 // Patch: if WEP key already set by iwconfig but device not yet open
1390 if (pDevice->bEncryptionEnable && pDevice->bTransmitKey) {
1391 KeybSetDefaultKey(&(pDevice->sKey),
1392 (unsigned long)(pDevice->byKeyIndex | (1 << 31)),
1393 pDevice->uKeyLength,
1397 pDevice->PortOffset,
1400 pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
1403 pr_debug("call MACvIntEnable\n");
1404 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1406 if (pDevice->pMgmt->eConfigMode == WMAC_CONFIG_AP) {
1407 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
1409 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1410 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1412 pDevice->flags |= DEVICE_FLAGS_OPENED;
1414 pr_debug("device_open success..\n");
1418 static int device_close(struct net_device *dev)
1420 struct vnt_private *pDevice = netdev_priv(dev);
1421 PSMgmtObject pMgmt = pDevice->pMgmt;
1422 //2007-1121-02<Add>by EinsnLiu
1423 if (pDevice->bLinkPass) {
1424 bScheduleCommand((void *)pDevice, WLAN_CMD_DISASSOCIATE, NULL);
1428 del_timer(&pDevice->sTimerTxData);
1429 del_timer(&pDevice->sTimerCommand);
1430 del_timer(&pMgmt->sTimerSecondCallback);
1431 if (pDevice->bDiversityRegCtlON) {
1432 del_timer(&pDevice->TimerSQ3Tmax1);
1433 del_timer(&pDevice->TimerSQ3Tmax2);
1434 del_timer(&pDevice->TimerSQ3Tmax3);
1437 netif_stop_queue(dev);
1438 pDevice->bCmdRunning = false;
1439 MACbShutdown(pDevice->PortOffset);
1440 MACbSoftwareReset(pDevice->PortOffset);
1441 CARDbRadioPowerOff(pDevice);
1443 pDevice->bLinkPass = false;
1444 memset(pMgmt->abyCurrBSSID, 0, 6);
1445 pMgmt->eCurrState = WMAC_STATE_IDLE;
1446 device_free_td0_ring(pDevice);
1447 device_free_td1_ring(pDevice);
1448 device_free_rd0_ring(pDevice);
1449 device_free_rd1_ring(pDevice);
1450 device_free_frag_buf(pDevice);
1451 device_free_rings(pDevice);
1452 BSSvClearNodeDBTable(pDevice, 0);
1453 free_irq(dev->irq, dev);
1454 pDevice->flags &= (~DEVICE_FLAGS_OPENED);
1455 //2008-0714-01<Add>by chester
1456 device_release_WPADEV(pDevice);
1458 pr_debug("device_close..\n");
1462 static int device_dma0_tx_80211(struct sk_buff *skb, struct net_device *dev)
1464 struct vnt_private *pDevice = netdev_priv(dev);
1465 unsigned char *pbMPDU;
1466 unsigned int cbMPDULen = 0;
1468 pr_debug("device_dma0_tx_80211\n");
1469 spin_lock_irq(&pDevice->lock);
1471 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1472 pr_debug("device_dma0_tx_80211, td0 <=0\n");
1473 dev_kfree_skb_irq(skb);
1474 spin_unlock_irq(&pDevice->lock);
1478 if (pDevice->bStopTx0Pkt) {
1479 dev_kfree_skb_irq(skb);
1480 spin_unlock_irq(&pDevice->lock);
1484 cbMPDULen = skb->len;
1487 vDMA0_tx_80211(pDevice, skb, pbMPDU, cbMPDULen);
1489 spin_unlock_irq(&pDevice->lock);
1494 bool device_dma0_xmit(struct vnt_private *pDevice,
1495 struct sk_buff *skb, unsigned int uNodeIndex)
1497 PSMgmtObject pMgmt = pDevice->pMgmt;
1498 PSTxDesc pHeadTD, pLastTD;
1499 unsigned int cbFrameBodySize;
1500 unsigned int uMACfragNum;
1501 unsigned char byPktType;
1502 bool bNeedEncryption = false;
1503 PSKeyItem pTransmitKey = NULL;
1504 unsigned int cbHeaderSize;
1508 if (pDevice->bStopTx0Pkt) {
1509 dev_kfree_skb_irq(skb);
1513 if (AVAIL_TD(pDevice, TYPE_TXDMA0) <= 0) {
1514 dev_kfree_skb_irq(skb);
1515 pr_debug("device_dma0_xmit, td0 <=0\n");
1519 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1520 if (pDevice->uAssocCount == 0) {
1521 dev_kfree_skb_irq(skb);
1522 pr_debug("device_dma0_xmit, assocCount = 0\n");
1527 pHeadTD = pDevice->apCurrTD[TYPE_TXDMA0];
1529 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1531 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1532 cbFrameBodySize = skb->len - ETH_HLEN;
1535 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1536 cbFrameBodySize += 8;
1538 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
1540 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_TXDMA0)) {
1541 dev_kfree_skb_irq(skb);
1544 byPktType = (unsigned char)pDevice->byPacketType;
1546 if (pDevice->bFixRate) {
1547 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
1548 if (pDevice->uConnectionRate >= RATE_11M)
1549 pDevice->wCurrentRate = RATE_11M;
1551 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1553 if (pDevice->uConnectionRate >= RATE_54M)
1554 pDevice->wCurrentRate = RATE_54M;
1556 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1559 pDevice->wCurrentRate = pDevice->pMgmt->sNodeDBTable[uNodeIndex].wTxDataRate;
1563 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1564 pDevice->byPreambleType = pDevice->byShortPreamble;
1566 pDevice->byPreambleType = PREAMBLE_LONG;
1568 pr_debug("dma0: pDevice->wCurrentRate = %d\n", pDevice->wCurrentRate);
1570 if (pDevice->wCurrentRate <= RATE_11M) {
1571 byPktType = PK_TYPE_11B;
1572 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1573 byPktType = PK_TYPE_11A;
1575 if (pDevice->bProtectMode)
1576 byPktType = PK_TYPE_11GB;
1578 byPktType = PK_TYPE_11GA;
1581 if (pDevice->bEncryptionEnable)
1582 bNeedEncryption = true;
1584 if (pDevice->bEnableHostWEP) {
1585 pTransmitKey = &STempKey;
1586 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1587 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1588 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1589 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1590 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1591 memcpy(pTransmitKey->abyKey,
1592 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1593 pTransmitKey->uKeyLength
1596 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
1597 cbFrameBodySize, TYPE_TXDMA0, pHeadTD,
1598 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
1603 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1605 MACbPSWakeup(pDevice->PortOffset);
1608 pDevice->bPWBitOn = false;
1611 for (ii = 0; ii < uMACfragNum; ii++) {
1612 // Poll Transmit the adapter
1614 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
1616 if (ii == (uMACfragNum - 1))
1618 pHeadTD = pHeadTD->next;
1621 // Save the information needed by the tx interrupt handler
1622 // to complete the Send request
1623 pLastTD->pTDInfo->skb = skb;
1624 pLastTD->pTDInfo->byFlags = 0;
1625 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
1627 pDevice->apCurrTD[TYPE_TXDMA0] = pHeadTD;
1629 MACvTransmit0(pDevice->PortOffset);
1634 //TYPE_AC0DMA data tx
1635 static int device_xmit(struct sk_buff *skb, struct net_device *dev) {
1636 struct vnt_private *pDevice = netdev_priv(dev);
1637 PSMgmtObject pMgmt = pDevice->pMgmt;
1638 PSTxDesc pHeadTD, pLastTD;
1639 unsigned int uNodeIndex = 0;
1640 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1641 unsigned short wAID;
1642 unsigned int uMACfragNum = 1;
1643 unsigned int cbFrameBodySize;
1644 unsigned char byPktType;
1645 unsigned int cbHeaderSize;
1646 bool bNeedEncryption = false;
1647 PSKeyItem pTransmitKey = NULL;
1650 bool bTKIP_UseGTK = false;
1651 bool bNeedDeAuth = false;
1652 unsigned char *pbyBSSID;
1653 bool bNodeExist = false;
1655 spin_lock_irq(&pDevice->lock);
1656 if (!pDevice->bLinkPass) {
1657 dev_kfree_skb_irq(skb);
1658 spin_unlock_irq(&pDevice->lock);
1662 if (pDevice->bStopDataPkt) {
1663 dev_kfree_skb_irq(skb);
1664 spin_unlock_irq(&pDevice->lock);
1668 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1669 if (pDevice->uAssocCount == 0) {
1670 dev_kfree_skb_irq(skb);
1671 spin_unlock_irq(&pDevice->lock);
1674 if (is_multicast_ether_addr((unsigned char *)(skb->data))) {
1677 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1678 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skb);
1679 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1681 pMgmt->abyPSTxMap[0] |= byMask[0];
1682 spin_unlock_irq(&pDevice->lock);
1686 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data), &uNodeIndex)) {
1687 if (pMgmt->sNodeDBTable[uNodeIndex].bPSEnable) {
1688 skb_queue_tail(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue, skb);
1689 pMgmt->sNodeDBTable[uNodeIndex].wEnQueueCnt++;
1691 wAID = pMgmt->sNodeDBTable[uNodeIndex].wAID;
1692 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1693 pr_debug("Set:pMgmt->abyPSTxMap[%d]= %d\n",
1695 pMgmt->abyPSTxMap[wAID >> 3]);
1696 spin_unlock_irq(&pDevice->lock);
1700 if (pMgmt->sNodeDBTable[uNodeIndex].bShortPreamble)
1701 pDevice->byPreambleType = pDevice->byShortPreamble;
1703 pDevice->byPreambleType = PREAMBLE_LONG;
1711 pr_debug("Unknown STA not found in node DB\n");
1712 dev_kfree_skb_irq(skb);
1713 spin_unlock_irq(&pDevice->lock);
1718 pHeadTD = pDevice->apCurrTD[TYPE_AC0DMA];
1720 pHeadTD->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1722 memcpy(pDevice->sTxEthHeader.abyDstAddr, (unsigned char *)(skb->data), ETH_HLEN);
1723 cbFrameBodySize = skb->len - ETH_HLEN;
1725 if (ntohs(pDevice->sTxEthHeader.wType) > ETH_DATA_LEN)
1726 cbFrameBodySize += 8;
1728 if (pDevice->bEncryptionEnable) {
1729 bNeedEncryption = true;
1732 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
1733 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1734 pbyBSSID = pDevice->abyBSSID;
1736 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == false) {
1738 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == true) {
1739 bTKIP_UseGTK = true;
1740 pr_debug("Get GTK\n");
1744 pr_debug("Get PTK\n");
1747 } else if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1748 pbyBSSID = pDevice->sTxEthHeader.abyDstAddr; //TO_DS = 0 and FROM_DS = 0 --> 802.11 MAC Address1
1749 pr_debug("IBSS Serach Key:\n");
1750 for (ii = 0; ii < 6; ii++)
1751 pr_debug("%x\n", *(pbyBSSID+ii));
1755 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, PAIRWISE_KEY, &pTransmitKey) == true)
1759 pbyBSSID = pDevice->abyBroadcastAddr;
1760 if (KeybGetTransmitKey(&(pDevice->sKey), pbyBSSID, GROUP_KEY, &pTransmitKey) == false) {
1761 pTransmitKey = NULL;
1762 if (pDevice->pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)
1763 pr_debug("IBSS and KEY is NULL. [%d]\n",
1764 pDevice->pMgmt->eCurrMode);
1766 pr_debug("NOT IBSS and KEY is NULL. [%d]\n",
1767 pDevice->pMgmt->eCurrMode);
1769 bTKIP_UseGTK = true;
1770 pr_debug("Get GTK\n");
1775 if (pDevice->bEnableHostWEP) {
1776 pr_debug("acdma0: STA index %d\n", uNodeIndex);
1777 if (pDevice->bEncryptionEnable) {
1778 pTransmitKey = &STempKey;
1779 pTransmitKey->byCipherSuite = pMgmt->sNodeDBTable[uNodeIndex].byCipherSuite;
1780 pTransmitKey->dwKeyIndex = pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex;
1781 pTransmitKey->uKeyLength = pMgmt->sNodeDBTable[uNodeIndex].uWepKeyLength;
1782 pTransmitKey->dwTSC47_16 = pMgmt->sNodeDBTable[uNodeIndex].dwTSC47_16;
1783 pTransmitKey->wTSC15_0 = pMgmt->sNodeDBTable[uNodeIndex].wTSC15_0;
1784 memcpy(pTransmitKey->abyKey,
1785 &pMgmt->sNodeDBTable[uNodeIndex].abyWepKey[0],
1786 pTransmitKey->uKeyLength
1791 uMACfragNum = cbGetFragCount(pDevice, pTransmitKey, cbFrameBodySize, &pDevice->sTxEthHeader);
1793 if (uMACfragNum > AVAIL_TD(pDevice, TYPE_AC0DMA)) {
1794 pr_debug("uMACfragNum > AVAIL_TD(TYPE_AC0DMA) = %d\n",
1796 dev_kfree_skb_irq(skb);
1797 spin_unlock_irq(&pDevice->lock);
1801 if (pTransmitKey != NULL) {
1802 if ((pTransmitKey->byCipherSuite == KEY_CTL_WEP) &&
1803 (pTransmitKey->uKeyLength == WLAN_WEP232_KEYLEN)) {
1804 uMACfragNum = 1; //WEP256 doesn't support fragment
1808 byPktType = (unsigned char)pDevice->byPacketType;
1810 if (pDevice->bFixRate) {
1811 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
1812 if (pDevice->uConnectionRate >= RATE_11M)
1813 pDevice->wCurrentRate = RATE_11M;
1815 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1817 if ((pDevice->eCurrentPHYType == PHY_TYPE_11A) &&
1818 (pDevice->uConnectionRate <= RATE_6M)) {
1819 pDevice->wCurrentRate = RATE_6M;
1821 if (pDevice->uConnectionRate >= RATE_54M)
1822 pDevice->wCurrentRate = RATE_54M;
1824 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
1828 pDevice->byACKRate = (unsigned char) pDevice->wCurrentRate;
1829 pDevice->byTopCCKBasicRate = RATE_1M;
1830 pDevice->byTopOFDMBasicRate = RATE_6M;
1833 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
1834 if (pDevice->eCurrentPHYType != PHY_TYPE_11A) {
1835 pDevice->wCurrentRate = RATE_1M;
1836 pDevice->byACKRate = RATE_1M;
1837 pDevice->byTopCCKBasicRate = RATE_1M;
1838 pDevice->byTopOFDMBasicRate = RATE_6M;
1840 pDevice->wCurrentRate = RATE_6M;
1841 pDevice->byACKRate = RATE_6M;
1842 pDevice->byTopCCKBasicRate = RATE_1M;
1843 pDevice->byTopOFDMBasicRate = RATE_6M;
1846 VNTWIFIvGetTxRate(pDevice->pMgmt,
1847 pDevice->sTxEthHeader.abyDstAddr,
1848 &(pDevice->wCurrentRate),
1849 &(pDevice->byACKRate),
1850 &(pDevice->byTopCCKBasicRate),
1851 &(pDevice->byTopOFDMBasicRate));
1857 if (pDevice->wCurrentRate <= RATE_11M) {
1858 byPktType = PK_TYPE_11B;
1859 } else if (pDevice->eCurrentPHYType == PHY_TYPE_11A) {
1860 byPktType = PK_TYPE_11A;
1862 if (pDevice->bProtectMode)
1863 byPktType = PK_TYPE_11GB;
1865 byPktType = PK_TYPE_11GA;
1868 if (bNeedEncryption) {
1869 pr_debug("ntohs Pkt Type=%04x\n",
1870 ntohs(pDevice->sTxEthHeader.wType));
1871 if ((pDevice->sTxEthHeader.wType) == TYPE_PKT_802_1x) {
1872 bNeedEncryption = false;
1873 pr_debug("Pkt Type=%04x\n",
1874 (pDevice->sTxEthHeader.wType));
1875 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
1876 if (pTransmitKey == NULL) {
1877 pr_debug("Don't Find TX KEY\n");
1880 pr_debug("error: KEY is GTK!!~~\n");
1882 pr_debug("Find PTK [%lX]\n",
1883 pTransmitKey->dwKeyIndex);
1884 bNeedEncryption = true;
1889 if (pDevice->byCntMeasure == 2) {
1891 pDevice->s802_11Counter.TKIPCounterMeasuresInvoked++;
1894 if (pDevice->bEnableHostWEP) {
1895 if ((uNodeIndex != 0) &&
1896 (pMgmt->sNodeDBTable[uNodeIndex].dwKeyIndex & PAIRWISE_KEY)) {
1897 pr_debug("Find PTK [%lX]\n",
1898 pTransmitKey->dwKeyIndex);
1899 bNeedEncryption = true;
1903 if (pTransmitKey == NULL) {
1904 pr_debug("return no tx key\n");
1905 dev_kfree_skb_irq(skb);
1906 spin_unlock_irq(&pDevice->lock);
1912 vGenerateFIFOHeader(pDevice, byPktType, pDevice->pbyTmpBuff, bNeedEncryption,
1913 cbFrameBodySize, TYPE_AC0DMA, pHeadTD,
1914 &pDevice->sTxEthHeader, (unsigned char *)skb->data, pTransmitKey, uNodeIndex,
1919 if (MACbIsRegBitsOn(pDevice->PortOffset, MAC_REG_PSCTL, PSCTL_PS)) {
1921 MACbPSWakeup(pDevice->PortOffset);
1923 pDevice->bPWBitOn = false;
1926 for (ii = 0; ii < uMACfragNum; ii++) {
1927 // Poll Transmit the adapter
1929 pHeadTD->m_td0TD0.f1Owner = OWNED_BY_NIC;
1931 if (ii == uMACfragNum - 1)
1933 pHeadTD = pHeadTD->next;
1936 // Save the information needed by the tx interrupt handler
1937 // to complete the Send request
1938 pLastTD->pTDInfo->skb = skb;
1939 pLastTD->pTDInfo->byFlags = 0;
1940 pLastTD->pTDInfo->byFlags |= TD_FLAGS_NETIF_SKB;
1941 pDevice->nTxDataTimeCout = 0; //2008-8-21 chester <add> for send null packet
1943 if (AVAIL_TD(pDevice, TYPE_AC0DMA) <= 1)
1944 netif_stop_queue(dev);
1946 pDevice->apCurrTD[TYPE_AC0DMA] = pHeadTD;
1948 if (pDevice->bFixRate)
1949 pr_debug("FixRate:Rate is %d,TxPower is %d\n", pDevice->wCurrentRate, pDevice->byCurPwr);
1952 unsigned char Protocol_Version; //802.1x Authentication
1953 unsigned char Packet_Type; //802.1x Authentication
1954 unsigned char Descriptor_type;
1955 unsigned short Key_info;
1956 bool bTxeapol_key = false;
1958 Protocol_Version = skb->data[ETH_HLEN];
1959 Packet_Type = skb->data[ETH_HLEN+1];
1960 Descriptor_type = skb->data[ETH_HLEN+1+1+2];
1961 Key_info = (skb->data[ETH_HLEN+1+1+2+1] << 8)|(skb->data[ETH_HLEN+1+1+2+2]);
1962 if (pDevice->sTxEthHeader.wType == TYPE_PKT_802_1x) {
1963 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
1964 (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame transfer
1965 bTxeapol_key = true;
1966 if ((Descriptor_type == 254) || (Descriptor_type == 2)) { //WPA or RSN
1967 if (!(Key_info & BIT3) && //group-key challenge
1968 (Key_info & BIT8) && (Key_info & BIT9)) { //send 2/2 key
1969 pDevice->fWPA_Authened = true;
1970 if (Descriptor_type == 254)
1974 pr_debug("Authentication completed!!\n");
1981 MACvTransmitAC0(pDevice->PortOffset);
1983 dev->trans_start = jiffies;
1985 spin_unlock_irq(&pDevice->lock);
1989 static irqreturn_t device_intr(int irq, void *dev_instance)
1991 struct vnt_private *pDevice = dev_instance;
1993 unsigned long dwMIBCounter = 0;
1994 unsigned char byOrgPageSel = 0;
1997 unsigned long flags;
1999 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2001 if (pDevice->dwIsr == 0)
2002 return IRQ_RETVAL(handled);
2004 if (pDevice->dwIsr == 0xffffffff) {
2005 pr_debug("dwIsr = 0xffff\n");
2006 return IRQ_RETVAL(handled);
2010 MACvIntDisable(pDevice->PortOffset);
2012 spin_lock_irqsave(&pDevice->lock, flags);
2014 //Make sure current page is 0
2015 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
2016 if (byOrgPageSel == 1)
2017 MACvSelectPage0(pDevice->PortOffset);
2021 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
2023 // Must do this after doing rx/tx, cause ISR bit is slow
2024 // than RD/TD write back
2025 // update ISR counter
2026 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
2027 while (pDevice->dwIsr != 0) {
2028 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
2029 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
2031 if (pDevice->dwIsr & ISR_FETALERR) {
2032 pr_debug(" ISR_FETALERR\n");
2033 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
2034 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
2035 device_error(pDevice, pDevice->dwIsr);
2038 if (pDevice->dwIsr & ISR_TBTT) {
2040 pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
2041 if (pDevice->bUpdateBBVGA &&
2042 pDevice->vif->bss_conf.assoc &&
2043 pDevice->uCurrRSSI) {
2046 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
2047 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
2048 if (ldBm < pDevice->ldBmThreshold[ii]) {
2049 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
2053 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
2054 pDevice->uBBVGADiffCount++;
2055 if (pDevice->uBBVGADiffCount == 1) {
2056 // first VGA diff gain
2057 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2058 pr_debug("First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2060 pDevice->byBBVGANew,
2061 pDevice->byBBVGACurrent,
2062 (int)pDevice->uBBVGADiffCount);
2064 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
2065 pr_debug("RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
2067 pDevice->byBBVGANew,
2068 pDevice->byBBVGACurrent,
2069 (int)pDevice->uBBVGADiffCount);
2070 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
2073 pDevice->uBBVGADiffCount = 1;
2078 pDevice->bBeaconSent = false;
2079 if (pDevice->bEnablePSMode)
2080 PSbIsNextTBTTWakeUp((void *)pDevice);
2082 if ((pDevice->op_mode == NL80211_IFTYPE_AP ||
2083 pDevice->op_mode == NL80211_IFTYPE_ADHOC) &&
2084 pDevice->vif->bss_conf.enable_beacon) {
2085 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
2086 (pDevice->vif->bss_conf.beacon_int - MAKE_BEACON_RESERVED) << 10);
2089 /* TODO: adhoc PS mode */
2093 if (pDevice->dwIsr & ISR_BNTX) {
2094 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
2095 pDevice->bIsBeaconBufReadySet = false;
2096 pDevice->cbBeaconBufReadySetCnt = 0;
2099 pDevice->bBeaconSent = true;
2102 if (pDevice->dwIsr & ISR_RXDMA0)
2103 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
2105 if (pDevice->dwIsr & ISR_RXDMA1)
2106 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
2108 if (pDevice->dwIsr & ISR_TXDMA0)
2109 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
2111 if (pDevice->dwIsr & ISR_AC0DMA)
2112 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
2114 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
2116 if (pDevice->vif->bss_conf.enable_beacon)
2117 vnt_beacon_make(pDevice, pDevice->vif);
2121 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
2123 MACvReceive0(pDevice->PortOffset);
2124 MACvReceive1(pDevice->PortOffset);
2126 if (max_count > pDevice->sOpts.int_works)
2130 if (byOrgPageSel == 1)
2131 MACvSelectPage1(pDevice->PortOffset);
2133 spin_unlock_irqrestore(&pDevice->lock, flags);
2135 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
2137 return IRQ_RETVAL(handled);
2140 //2008-8-4 <add> by chester
2141 static int Config_FileGetParameter(unsigned char *string,
2142 unsigned char *dest, unsigned char *source)
2144 unsigned char buf1[100];
2145 int source_len = strlen(source);
2147 memset(buf1, 0, 100);
2148 strcat(buf1, string);
2150 source += strlen(buf1);
2152 memcpy(dest, source, source_len - strlen(buf1));
2156 int Config_FileOperation(struct vnt_private *pDevice,
2157 bool fwrite, unsigned char *Parameter)
2159 unsigned char *buffer = kmalloc(1024, GFP_KERNEL);
2160 unsigned char tmpbuffer[20];
2165 pr_err("allocate mem for file fail?\n");
2168 file = filp_open(CONFIG_PATH, O_RDONLY, 0);
2171 pr_err("Config_FileOperation:open file fail?\n");
2175 if (kernel_read(file, 0, buffer, 1024) < 0) {
2176 pr_err("read file error?\n");
2181 if (Config_FileGetParameter("ZONETYPE", tmpbuffer, buffer) != true) {
2182 pr_err("get parameter error?\n");
2187 if (memcmp(tmpbuffer, "USA", 3) == 0) {
2188 result = ZoneType_USA;
2189 } else if (memcmp(tmpbuffer, "JAPAN", 5) == 0) {
2190 result = ZoneType_Japan;
2191 } else if (memcmp(tmpbuffer, "EUROPE", 5) == 0) {
2192 result = ZoneType_Europe;
2195 pr_err("Unknown Zonetype[%s]?\n", tmpbuffer);
2204 static void device_set_multi(struct net_device *dev) {
2205 struct vnt_private *pDevice = netdev_priv(dev);
2206 PSMgmtObject pMgmt = pDevice->pMgmt;
2208 struct netdev_hw_addr *ha;
2210 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
2212 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
2213 pr_notice("%s: Promiscuous mode enabled\n", dev->name);
2214 /* Unconditionally log net taps. */
2215 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST|RCR_UNICAST);
2216 } else if ((netdev_mc_count(dev) > pDevice->multicast_limit)
2217 || (dev->flags & IFF_ALLMULTI)) {
2218 MACvSelectPage1(pDevice->PortOffset);
2219 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, 0xffffffff);
2220 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, 0xffffffff);
2221 MACvSelectPage0(pDevice->PortOffset);
2222 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2224 memset(mc_filter, 0, sizeof(mc_filter));
2225 netdev_for_each_mc_addr(ha, dev) {
2226 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
2228 mc_filter[bit_nr >> 5] |= cpu_to_le32(1 << (bit_nr & 31));
2230 MACvSelectPage1(pDevice->PortOffset);
2231 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0, mc_filter[0]);
2232 VNSvOutPortD(pDevice->PortOffset + MAC_REG_MAR0 + 4, mc_filter[1]);
2233 MACvSelectPage0(pDevice->PortOffset);
2234 pDevice->byRxMode &= ~(RCR_UNICAST);
2235 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2238 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2239 // If AP mode, don't enable RCR_UNICAST. Since hw only compare addr1 with local mac.
2240 pDevice->byRxMode |= (RCR_MULTICAST|RCR_BROADCAST);
2241 pDevice->byRxMode &= ~(RCR_UNICAST);
2244 VNSvOutPortB(pDevice->PortOffset + MAC_REG_RCR, pDevice->byRxMode);
2245 pr_debug("pDevice->byRxMode = %x\n", pDevice->byRxMode);
2248 static int device_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2250 struct vnt_private *pDevice = netdev_priv(dev);
2251 struct iwreq *wrq = (struct iwreq *)rq;
2253 PSMgmtObject pMgmt = pDevice->pMgmt;
2256 if (pMgmt == NULL) {
2263 rc = iwctl_giwname(dev, NULL, (char *)&(wrq->u.name), NULL);
2266 case SIOCGIWNWID: //0x8b03 support
2270 // Set frequency/channel
2272 rc = iwctl_siwfreq(dev, NULL, &(wrq->u.freq), NULL);
2275 // Get frequency/channel
2277 rc = iwctl_giwfreq(dev, NULL, &(wrq->u.freq), NULL);
2280 // Set desired network name (ESSID)
2284 char essid[IW_ESSID_MAX_SIZE+1];
2286 if (wrq->u.essid.length > IW_ESSID_MAX_SIZE) {
2290 if (copy_from_user(essid, wrq->u.essid.pointer,
2291 wrq->u.essid.length)) {
2295 rc = iwctl_siwessid(dev, NULL,
2296 &(wrq->u.essid), essid);
2300 // Get current network name (ESSID)
2304 char essid[IW_ESSID_MAX_SIZE+1];
2306 if (wrq->u.essid.pointer)
2307 rc = iwctl_giwessid(dev, NULL,
2308 &(wrq->u.essid), essid);
2309 if (copy_to_user(wrq->u.essid.pointer,
2311 wrq->u.essid.length))
2318 rc = iwctl_siwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2321 // Get current Access Point (BSSID)
2323 rc = iwctl_giwap(dev, NULL, &(wrq->u.ap_addr), NULL);
2326 // Set desired station name
2328 pr_debug(" SIOCSIWNICKN\n");
2332 // Get current station name
2334 pr_debug(" SIOCGIWNICKN\n");
2338 // Set the desired bit-rate
2340 rc = iwctl_siwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2343 // Get the current bit-rate
2346 rc = iwctl_giwrate(dev, NULL, &(wrq->u.bitrate), NULL);
2349 // Set the desired RTS threshold
2352 rc = iwctl_siwrts(dev, NULL, &(wrq->u.rts), NULL);
2355 // Get the current RTS threshold
2358 rc = iwctl_giwrts(dev, NULL, &(wrq->u.rts), NULL);
2361 // Set the desired fragmentation threshold
2364 rc = iwctl_siwfrag(dev, NULL, &(wrq->u.frag), NULL);
2367 // Get the current fragmentation threshold
2370 rc = iwctl_giwfrag(dev, NULL, &(wrq->u.frag), NULL);
2373 // Set mode of operation
2375 rc = iwctl_siwmode(dev, NULL, &(wrq->u.mode), NULL);
2378 // Get mode of operation
2380 rc = iwctl_giwmode(dev, NULL, &(wrq->u.mode), NULL);
2383 // Set WEP keys and mode
2384 case SIOCSIWENCODE: {
2385 char abyKey[WLAN_WEP232_KEYLEN];
2387 if (wrq->u.encoding.pointer) {
2388 if (wrq->u.encoding.length > WLAN_WEP232_KEYLEN) {
2392 memset(abyKey, 0, WLAN_WEP232_KEYLEN);
2393 if (copy_from_user(abyKey,
2394 wrq->u.encoding.pointer,
2395 wrq->u.encoding.length)) {
2399 } else if (wrq->u.encoding.length != 0) {
2403 rc = iwctl_siwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2407 // Get the WEP keys and mode
2410 if (!capable(CAP_NET_ADMIN)) {
2415 char abyKey[WLAN_WEP232_KEYLEN];
2417 rc = iwctl_giwencode(dev, NULL, &(wrq->u.encoding), abyKey);
2420 if (wrq->u.encoding.pointer) {
2421 if (copy_to_user(wrq->u.encoding.pointer,
2423 wrq->u.encoding.length))
2429 // Get the current Tx-Power
2431 pr_debug(" SIOCGIWTXPOW\n");
2436 pr_debug(" SIOCSIWTXPOW\n");
2442 rc = iwctl_siwretry(dev, NULL, &(wrq->u.retry), NULL);
2447 rc = iwctl_giwretry(dev, NULL, &(wrq->u.retry), NULL);
2450 // Get range of parameters
2454 struct iw_range range;
2456 rc = iwctl_giwrange(dev, NULL, &(wrq->u.data), (char *)&range);
2457 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(struct iw_range)))
2465 rc = iwctl_giwpower(dev, NULL, &(wrq->u.power), NULL);
2470 rc = iwctl_siwpower(dev, NULL, &(wrq->u.power), NULL);
2475 rc = iwctl_giwsens(dev, NULL, &(wrq->u.sens), NULL);
2479 pr_debug(" SIOCSIWSENS\n");
2483 case SIOCGIWAPLIST: {
2484 char buffer[IW_MAX_AP * (sizeof(struct sockaddr) + sizeof(struct iw_quality))];
2486 if (wrq->u.data.pointer) {
2487 rc = iwctl_giwaplist(dev, NULL, &(wrq->u.data), buffer);
2489 if (copy_to_user(wrq->u.data.pointer,
2491 (wrq->u.data.length * (sizeof(struct sockaddr) + sizeof(struct iw_quality)))
2503 pr_debug(" SIOCSIWSPY\n");
2510 pr_debug(" SIOCGIWSPY\n");
2514 #endif // WIRELESS_SPY
2517 pr_debug(" SIOCGIWPRIV\n");
2521 //2008-0409-07, <Add> by Einsn Liu
2522 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2524 pr_debug(" SIOCSIWAUTH\n");
2525 rc = iwctl_siwauth(dev, NULL, &(wrq->u.param), NULL);
2529 pr_debug(" SIOCGIWAUTH\n");
2530 rc = iwctl_giwauth(dev, NULL, &(wrq->u.param), NULL);
2534 pr_debug(" SIOCSIWGENIE\n");
2535 rc = iwctl_siwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2539 pr_debug(" SIOCGIWGENIE\n");
2540 rc = iwctl_giwgenie(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2543 case SIOCSIWENCODEEXT: {
2544 char extra[sizeof(struct iw_encode_ext)+MAX_KEY_LEN+1];
2546 pr_debug(" SIOCSIWENCODEEXT\n");
2547 if (wrq->u.encoding.pointer) {
2548 memset(extra, 0, sizeof(struct iw_encode_ext)+MAX_KEY_LEN + 1);
2549 if (wrq->u.encoding.length > (sizeof(struct iw_encode_ext) + MAX_KEY_LEN)) {
2553 if (copy_from_user(extra, wrq->u.encoding.pointer, wrq->u.encoding.length)) {
2557 } else if (wrq->u.encoding.length != 0) {
2561 rc = iwctl_siwencodeext(dev, NULL, &(wrq->u.encoding), extra);
2565 case SIOCGIWENCODEEXT:
2566 pr_debug(" SIOCGIWENCODEEXT\n");
2567 rc = iwctl_giwencodeext(dev, NULL, &(wrq->u.encoding), NULL);
2571 pr_debug(" SIOCSIWMLME\n");
2572 rc = iwctl_siwmlme(dev, NULL, &(wrq->u.data), wrq->u.data.pointer);
2575 #endif // #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2576 //End Add -- //2008-0409-07, <Add> by Einsn Liu
2578 case IOCTL_CMD_TEST:
2580 if (!(pDevice->flags & DEVICE_FLAGS_OPENED)) {
2585 pReq = (PSCmdRequest)rq;
2586 pReq->wResult = MAGIC_CODE;
2591 if (!(pDevice->flags & DEVICE_FLAGS_OPENED) &&
2592 (((PSCmdRequest)rq)->wCmdCode != WLAN_CMD_SET_WPA)) {
2598 if (test_and_set_bit(0, (void *)&(pMgmt->uCmdBusy)))
2601 rc = private_ioctl(pDevice, rq);
2602 clear_bit(0, (void *)&(pMgmt->uCmdBusy));
2605 case IOCTL_CMD_HOSTAPD:
2607 rc = vt6655_hostap_ioctl(pDevice, &wrq->u.data);
2612 rc = wpa_ioctl(pDevice, &wrq->u.data);
2616 return ethtool_ioctl(dev, rq->ifr_data);
2617 // All other calls are currently unsupported
2621 pr_debug("Ioctl command not support..%x\n", cmd);
2625 if (pDevice->bCommit) {
2626 if (pMgmt->eConfigMode == WMAC_CONFIG_AP) {
2627 netif_stop_queue(pDevice->dev);
2628 spin_lock_irq(&pDevice->lock);
2629 bScheduleCommand((void *)pDevice, WLAN_CMD_RUN_AP, NULL);
2630 spin_unlock_irq(&pDevice->lock);
2632 pr_debug("Commit the settings\n");
2633 spin_lock_irq(&pDevice->lock);
2634 pDevice->bLinkPass = false;
2635 memset(pMgmt->abyCurrBSSID, 0, 6);
2636 pMgmt->eCurrState = WMAC_STATE_IDLE;
2637 netif_stop_queue(pDevice->dev);
2638 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
2639 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
2640 if (!pDevice->bWPASuppWextEnabled)
2642 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
2643 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
2644 spin_unlock_irq(&pDevice->lock);
2646 pDevice->bCommit = false;
2652 static int ethtool_ioctl(struct net_device *dev, void __user *useraddr)
2656 if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd)))
2660 case ETHTOOL_GDRVINFO: {
2661 struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO};
2663 strncpy(info.driver, DEVICE_NAME, sizeof(info.driver)-1);
2664 strncpy(info.version, DEVICE_VERSION, sizeof(info.version)-1);
2665 if (copy_to_user(useraddr, &info, sizeof(info)))
2675 static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
2677 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
2679 u32 dma_idx = TYPE_AC0DMA;
2680 unsigned long flags;
2682 spin_lock_irqsave(&priv->lock, flags);
2684 if (!ieee80211_is_data(hdr->frame_control))
2685 dma_idx = TYPE_TXDMA0;
2687 if (AVAIL_TD(priv, dma_idx) < 1) {
2688 spin_unlock_irqrestore(&priv->lock, flags);
2692 head_td = priv->apCurrTD[dma_idx];
2694 head_td->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
2696 head_td->pTDInfo->skb = skb;
2698 priv->iTDUsed[dma_idx]++;
2700 /* Take ownership */
2702 head_td->m_td0TD0.f1Owner = OWNED_BY_NIC;
2706 priv->apCurrTD[dma_idx] = head_td->next;
2708 spin_unlock_irqrestore(&priv->lock, flags);
2710 vnt_generate_fifo_header(priv, dma_idx, head_td, skb);
2712 if (MACbIsRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
2713 MACbPSWakeup(priv->PortOffset);
2715 spin_lock_irqsave(&priv->lock, flags);
2717 priv->bPWBitOn = false;
2719 head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB;
2721 if (dma_idx == TYPE_AC0DMA)
2722 MACvTransmitAC0(priv->PortOffset);
2724 MACvTransmit0(priv->PortOffset);
2726 spin_unlock_irqrestore(&priv->lock, flags);
2731 static void vnt_tx_80211(struct ieee80211_hw *hw,
2732 struct ieee80211_tx_control *control,
2733 struct sk_buff *skb)
2735 struct vnt_private *priv = hw->priv;
2737 ieee80211_stop_queues(hw);
2739 if (vnt_tx_packet(priv, skb)) {
2740 ieee80211_free_txskb(hw, skb);
2742 ieee80211_wake_queues(hw);
2746 static int vnt_start(struct ieee80211_hw *hw)
2748 struct vnt_private *priv = hw->priv;
2751 priv->rx_buf_sz = PKT_BUF_SZ;
2752 if (!device_init_rings(priv))
2755 ret = request_irq(priv->pcid->irq, &device_intr,
2756 IRQF_SHARED, "vt6655", priv);
2758 dev_dbg(&priv->pcid->dev, "failed to start irq\n");
2762 dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
2763 device_init_rd0_ring(priv);
2764 device_init_rd1_ring(priv);
2765 device_init_defrag_cb(priv);
2766 device_init_td0_ring(priv);
2767 device_init_td1_ring(priv);
2769 device_init_registers(priv);
2771 dev_dbg(&priv->pcid->dev, "call MACvIntEnable\n");
2772 MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
2774 ieee80211_wake_queues(hw);
2779 static void vnt_stop(struct ieee80211_hw *hw)
2781 struct vnt_private *priv = hw->priv;
2783 ieee80211_stop_queues(hw);
2785 MACbShutdown(priv->PortOffset);
2786 MACbSoftwareReset(priv->PortOffset);
2787 CARDbRadioPowerOff(priv);
2789 device_free_td0_ring(priv);
2790 device_free_td1_ring(priv);
2791 device_free_rd0_ring(priv);
2792 device_free_rd1_ring(priv);
2793 device_free_frag_buf(priv);
2794 device_free_rings(priv);
2796 free_irq(priv->pcid->irq, priv);
2799 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2801 struct vnt_private *priv = hw->priv;
2805 switch (vif->type) {
2806 case NL80211_IFTYPE_STATION:
2807 if (priv->bDiversityRegCtlON)
2808 device_init_diversity_timer(priv);
2810 case NL80211_IFTYPE_ADHOC:
2811 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
2813 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2816 case NL80211_IFTYPE_AP:
2817 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
2819 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
2826 priv->op_mode = vif->type;
2831 static void vnt_remove_interface(struct ieee80211_hw *hw,
2832 struct ieee80211_vif *vif)
2834 struct vnt_private *priv = hw->priv;
2836 switch (vif->type) {
2837 case NL80211_IFTYPE_STATION:
2838 if (priv->bDiversityRegCtlON) {
2839 del_timer(&priv->TimerSQ3Tmax1);
2840 del_timer(&priv->TimerSQ3Tmax2);
2841 del_timer(&priv->TimerSQ3Tmax3);
2844 case NL80211_IFTYPE_ADHOC:
2845 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
2846 MACvRegBitsOff(priv->PortOffset,
2847 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
2848 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
2850 case NL80211_IFTYPE_AP:
2851 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
2852 MACvRegBitsOff(priv->PortOffset,
2853 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
2854 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
2860 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
2864 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
2866 struct vnt_private *priv = hw->priv;
2867 struct ieee80211_conf *conf = &hw->conf;
2870 if (changed & IEEE80211_CONF_CHANGE_PS) {
2871 if (conf->flags & IEEE80211_CONF_PS)
2872 PSvEnablePowerSaving(priv, conf->listen_interval);
2874 PSvDisablePowerSaving(priv);
2877 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
2878 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
2879 set_channel(priv, conf->chandef.chan->hw_value);
2881 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
2882 bb_type = BB_TYPE_11A;
2884 bb_type = BB_TYPE_11G;
2886 if (priv->byBBType != bb_type) {
2887 priv->byBBType = bb_type;
2889 CARDbSetPhyParameter(priv,
2890 priv->byBBType, 0, 0, NULL, NULL);
2894 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2895 if (priv->byBBType == BB_TYPE_11B)
2896 priv->wCurrentRate = RATE_1M;
2898 priv->wCurrentRate = RATE_54M;
2900 RFbSetPower(priv, priv->wCurrentRate,
2901 conf->chandef.chan->hw_value);
2907 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
2908 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
2911 struct vnt_private *priv = hw->priv;
2913 priv->current_aid = conf->aid;
2915 if (changed & BSS_CHANGED_BSSID)
2916 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid);
2918 if (changed & BSS_CHANGED_BASIC_RATES) {
2919 priv->basic_rates = conf->basic_rates;
2921 CARDvUpdateBasicTopRate(priv);
2923 dev_dbg(&priv->pcid->dev,
2924 "basic rates %x\n", conf->basic_rates);
2927 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2928 if (conf->use_short_preamble) {
2929 MACvEnableBarkerPreambleMd(priv->PortOffset);
2930 priv->byPreambleType = true;
2932 MACvDisableBarkerPreambleMd(priv->PortOffset);
2933 priv->byPreambleType = false;
2937 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2938 if (conf->use_cts_prot)
2939 MACvEnableProtectMD(priv->PortOffset);
2941 MACvDisableProtectMD(priv->PortOffset);
2944 if (changed & BSS_CHANGED_ERP_SLOT) {
2945 if (conf->use_short_slot)
2946 priv->bShortSlotTime = true;
2948 priv->bShortSlotTime = false;
2951 CARDbSetPhyParameter(priv, priv->byBBType, 0, 0, NULL, NULL);
2952 BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
2955 if (changed & BSS_CHANGED_TXPOWER)
2956 RFbSetPower(priv, priv->wCurrentRate,
2957 conf->chandef.chan->hw_value);
2959 if (changed & BSS_CHANGED_BEACON_ENABLED) {
2960 dev_dbg(&priv->pcid->dev,
2961 "Beacon enable %d\n", conf->enable_beacon);
2963 if (conf->enable_beacon) {
2964 vnt_beacon_enable(priv, vif, conf);
2966 MACvRegBitsOn(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
2968 MACvRegBitsOff(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
2972 if (changed & BSS_CHANGED_ASSOC && priv->op_mode != NL80211_IFTYPE_AP) {
2974 CARDbUpdateTSF(priv, conf->beacon_rate->hw_value,
2975 conf->sync_device_ts, conf->sync_tsf);
2977 CARDbSetBeaconPeriod(priv, conf->beacon_int);
2979 CARDvSetFirstNextTBTT(priv->PortOffset,
2985 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
2986 struct netdev_hw_addr_list *mc_list)
2988 struct vnt_private *priv = hw->priv;
2989 struct netdev_hw_addr *ha;
2993 netdev_hw_addr_list_for_each(ha, mc_list) {
2994 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
2996 mc_filter |= 1ULL << (bit_nr & 0x3f);
2999 priv->mc_list_count = mc_list->count;
3004 static void vnt_configure(struct ieee80211_hw *hw,
3005 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
3007 struct vnt_private *priv = hw->priv;
3010 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_PROMISC_IN_BSS |
3011 FIF_BCN_PRBRESP_PROMISC;
3013 VNSvInPortB(priv->PortOffset + MAC_REG_RCR, &rx_mode);
3015 dev_dbg(&priv->pcid->dev, "rx mode in = %x\n", rx_mode);
3017 if (changed_flags & FIF_PROMISC_IN_BSS) {
3018 /* unconditionally log net taps */
3019 if (*total_flags & FIF_PROMISC_IN_BSS)
3020 rx_mode |= RCR_UNICAST;
3022 rx_mode &= ~RCR_UNICAST;
3025 if (changed_flags & FIF_ALLMULTI) {
3026 if (*total_flags & FIF_ALLMULTI) {
3027 if (priv->mc_list_count > 2) {
3028 MACvSelectPage1(priv->PortOffset);
3030 VNSvOutPortD(priv->PortOffset +
3031 MAC_REG_MAR0, 0xffffffff);
3032 VNSvOutPortD(priv->PortOffset +
3033 MAC_REG_MAR0 + 4, 0xffffffff);
3035 MACvSelectPage0(priv->PortOffset);
3037 MACvSelectPage1(priv->PortOffset);
3039 VNSvOutPortD(priv->PortOffset +
3040 MAC_REG_MAR0, (u32)multicast);
3041 VNSvOutPortD(priv->PortOffset +
3043 (u32)(multicast >> 32));
3045 MACvSelectPage0(priv->PortOffset);
3048 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
3050 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
3054 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
3055 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
3057 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
3058 rx_mode &= ~RCR_BSSID;
3060 rx_mode |= RCR_BSSID;
3063 VNSvOutPortB(priv->PortOffset + MAC_REG_RCR, rx_mode);
3065 dev_dbg(&priv->pcid->dev, "rx mode out= %x\n", rx_mode);
3068 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3069 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
3070 struct ieee80211_key_conf *key)
3072 struct vnt_private *priv = hw->priv;
3076 if (vnt_set_keys(hw, sta, vif, key))
3080 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
3081 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
3089 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
3091 struct vnt_private *priv = hw->priv;
3094 CARDbGetCurrentTSF(priv->PortOffset, &tsf);
3099 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
3102 struct vnt_private *priv = hw->priv;
3104 CARDvUpdateNextTBTT(priv->PortOffset, tsf, vif->bss_conf.beacon_int);
3107 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
3109 struct vnt_private *priv = hw->priv;
3111 /* reset TSF counter */
3112 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
3115 static const struct ieee80211_ops vnt_mac_ops = {
3119 .add_interface = vnt_add_interface,
3120 .remove_interface = vnt_remove_interface,
3121 .config = vnt_config,
3122 .bss_info_changed = vnt_bss_info_changed,
3123 .prepare_multicast = vnt_prepare_multicast,
3124 .configure_filter = vnt_configure,
3125 .set_key = vnt_set_key,
3126 .get_tsf = vnt_get_tsf,
3127 .set_tsf = vnt_set_tsf,
3128 .reset_tsf = vnt_reset_tsf,
3131 int vnt_init(struct vnt_private *priv)
3133 SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyCurrentNetAddr);
3135 vnt_init_bands(priv);
3137 if (ieee80211_register_hw(priv->hw))
3140 priv->mac_hw = true;
3142 CARDbRadioPowerOff(priv);
3148 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
3150 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
3151 struct vnt_private *priv;
3152 struct ieee80211_hw *hw;
3153 struct wiphy *wiphy;
3156 dev_notice(&pcid->dev,
3157 "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
3159 dev_notice(&pcid->dev,
3160 "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
3162 hw = ieee80211_alloc_hw(sizeof(*priv), &vnt_mac_ops);
3164 dev_err(&pcid->dev, "could not register ieee80211_hw\n");
3170 vt6655_init_info(pcid, &priv, pChip_info);
3174 SET_IEEE80211_DEV(priv->hw, &pcid->dev);
3176 if (pci_enable_device(pcid)) {
3177 device_free_info(priv);
3182 "Before get pci_info memaddr is %x\n", priv->memaddr);
3184 if (!device_get_pci_info(priv, pcid)) {
3185 dev_err(&pcid->dev, ": Failed to find PCI device.\n");
3186 device_free_info(priv);
3192 "after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",
3193 priv->memaddr, priv->ioaddr, priv->io_size);
3205 for (i = 0; address[i]; i++) {
3206 pci_read_config_dword(pcid, address[i], &bar);
3208 dev_dbg(&pcid->dev, "bar %d is %x\n", i, bar);
3212 "bar %d not implemented\n", i);
3216 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
3219 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xffff);
3220 len = len & ~(len - 1);
3223 "IO space: len in IO %x, BAR %d\n",
3226 len = bar & 0xfffffff0;
3230 "len in MEM %x, BAR %d\n", len, i);
3236 priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK,
3238 if (!priv->PortOffset) {
3239 dev_err(&pcid->dev, ": Failed to IO remapping ..\n");
3240 device_free_info(priv);
3244 rc = pci_request_regions(pcid, DEVICE_NAME);
3246 dev_err(&pcid->dev, ": Failed to find PCI device\n");
3247 device_free_info(priv);
3252 if (!MACbSoftwareReset(priv->PortOffset)) {
3253 dev_err(&pcid->dev, ": Failed to access MAC hardware..\n");
3254 device_free_info(priv);
3257 /* initial to reload eeprom */
3258 MACvInitialize(priv->PortOffset);
3259 MACvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr);
3261 device_get_options(priv);
3262 device_set_options(priv);
3263 /* Mask out the options cannot be set to the chip */
3264 priv->sOpts.flags &= pChip_info->flags;
3266 /* Enable the chip specified capabilities */
3267 priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL);
3268 priv->tx_80211 = device_dma0_tx_80211;
3270 wiphy = priv->hw->wiphy;
3272 wiphy->frag_threshold = FRAG_THRESH_DEF;
3273 wiphy->rts_threshold = RTS_THRESH_DEF;
3274 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
3275 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
3277 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
3278 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
3279 IEEE80211_HW_SIGNAL_DBM |
3280 IEEE80211_HW_TIMING_BEACON_ONLY;
3282 priv->hw->max_signal = 100;
3287 device_print_info(priv);
3288 pci_set_drvdata(pcid, priv);
3293 /*------------------------------------------------------------------*/
3296 static int vt6655_suspend(struct pci_dev *pcid, pm_message_t state)
3298 struct vnt_private *priv = pci_get_drvdata(pcid);
3299 unsigned long flags;
3301 spin_lock_irqsave(&priv->lock, flags);
3303 pci_save_state(pcid);
3305 MACbShutdown(priv->PortOffset);
3307 pci_disable_device(pcid);
3308 pci_set_power_state(pcid, pci_choose_state(pcid, state));
3310 spin_unlock_irqrestore(&priv->lock, flags);
3315 static int vt6655_resume(struct pci_dev *pcid)
3318 pci_set_power_state(pcid, PCI_D0);
3319 pci_enable_wake(pcid, PCI_D0, 0);
3320 pci_restore_state(pcid);
3326 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
3328 static struct pci_driver device_driver = {
3329 .name = DEVICE_NAME,
3330 .id_table = vt6655_pci_id_table,
3331 .probe = vt6655_probe,
3332 .remove = vt6655_remove,
3334 .suspend = vt6655_suspend,
3335 .resume = vt6655_resume,
3339 static int __init vt6655_init_module(void)
3343 ret = pci_register_driver(&device_driver);
3346 register_reboot_notifier(&device_notifier);
3352 static void __exit vt6655_cleanup_module(void)
3355 unregister_reboot_notifier(&device_notifier);
3357 pci_unregister_driver(&device_driver);
3360 module_init(vt6655_init_module);
3361 module_exit(vt6655_cleanup_module);
3365 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
3367 struct pci_dev *pdev = NULL;
3373 for_each_pci_dev(pdev) {
3374 if (pci_dev_driver(pdev) == &device_driver) {
3375 if (pci_get_drvdata(pdev))
3376 vt6655_suspend(pdev, PMSG_HIBERNATE);