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_intr - interrupt handle function
36 * device_rx_srv - rx service function
37 * device_alloc_rx_buf - rx buffer pre-allocated function
38 * device_alloc_frag_buf - rx fragement pre-allocated function
39 * device_free_tx_buf - free tx buffer function
40 * device_free_frag_buf- free de-fragement buffer
41 * device_init_rd0_ring- initial rd dma0 ring
42 * device_init_rd1_ring- initial rd dma1 ring
43 * device_init_td0_ring- initial tx dma0 ring buffer
44 * device_init_td1_ring- initial tx dma1 ring buffer
45 * device_init_registers- initial MAC & BBP & RF internal registers.
46 * device_init_rings- initial tx/rx ring buffer
47 * device_init_defrag_cb- initial & allocate de-fragement buffer.
48 * device_free_rings- free all allocated ring buffer
49 * device_tx_srv- tx interrupt service function
55 #include <linux/file.h>
65 #include <linux/delay.h>
66 #include <linux/kthread.h>
67 #include <linux/slab.h>
69 /*--------------------- Static Definitions -------------------------*/
71 // Define module options
73 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
74 MODULE_LICENSE("GPL");
75 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
77 #define DEVICE_PARAM(N, D)
79 #define RX_DESC_MIN0 16
80 #define RX_DESC_MAX0 128
81 #define RX_DESC_DEF0 32
82 DEVICE_PARAM(RxDescriptors0, "Number of receive descriptors0");
84 #define RX_DESC_MIN1 16
85 #define RX_DESC_MAX1 128
86 #define RX_DESC_DEF1 32
87 DEVICE_PARAM(RxDescriptors1, "Number of receive descriptors1");
89 #define TX_DESC_MIN0 16
90 #define TX_DESC_MAX0 128
91 #define TX_DESC_DEF0 32
92 DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
94 #define TX_DESC_MIN1 16
95 #define TX_DESC_MAX1 128
96 #define TX_DESC_DEF1 64
97 DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
100 /* IP_byte_align[] is used for IP header unsigned long byte aligned
101 0: indicate the IP header won't be unsigned long byte aligned.(Default) .
102 1: indicate the IP header will be unsigned long byte aligned.
103 In some environment, the IP header should be unsigned long byte aligned,
104 or the packet will be droped when we receive it. (eg: IPVS)
106 DEVICE_PARAM(IP_byte_align, "Enable IP header dword aligned");
108 #define INT_WORKS_DEF 20
109 #define INT_WORKS_MIN 10
110 #define INT_WORKS_MAX 64
112 DEVICE_PARAM(int_works, "Number of packets per interrupt services");
114 #define CHANNEL_MIN 1
115 #define CHANNEL_MAX 14
116 #define CHANNEL_DEF 6
118 DEVICE_PARAM(Channel, "Channel number");
120 /* PreambleType[] is the preamble length used for transmit.
121 0: indicate allows long preamble type
122 1: indicate allows short preamble type
125 #define PREAMBLE_TYPE_DEF 1
127 DEVICE_PARAM(PreambleType, "Preamble Type");
129 #define RTS_THRESH_MIN 512
130 #define RTS_THRESH_MAX 2347
131 #define RTS_THRESH_DEF 2347
133 DEVICE_PARAM(RTSThreshold, "RTS threshold");
135 #define FRAG_THRESH_MIN 256
136 #define FRAG_THRESH_MAX 2346
137 #define FRAG_THRESH_DEF 2346
139 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
141 #define DATA_RATE_MIN 0
142 #define DATA_RATE_MAX 13
143 #define DATA_RATE_DEF 13
145 0: indicate 1 Mbps 0x02
146 1: indicate 2 Mbps 0x04
147 2: indicate 5.5 Mbps 0x0B
148 3: indicate 11 Mbps 0x16
149 4: indicate 6 Mbps 0x0c
150 5: indicate 9 Mbps 0x12
151 6: indicate 12 Mbps 0x18
152 7: indicate 18 Mbps 0x24
153 8: indicate 24 Mbps 0x30
154 9: indicate 36 Mbps 0x48
155 10: indicate 48 Mbps 0x60
156 11: indicate 54 Mbps 0x6c
157 12: indicate 72 Mbps 0x90
158 13: indicate auto rate
161 DEVICE_PARAM(ConnectionRate, "Connection data rate");
163 #define OP_MODE_DEF 0
165 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
167 /* OpMode[] is used for transmit.
168 0: indicate infrastruct mode used
169 1: indicate adhoc mode used
170 2: indicate AP mode used
174 0: indicate disable power saving mode
175 1: indicate enable power saving mode
178 #define PS_MODE_DEF 0
180 DEVICE_PARAM(PSMode, "Power saving mode");
182 #define SHORT_RETRY_MIN 0
183 #define SHORT_RETRY_MAX 31
184 #define SHORT_RETRY_DEF 8
186 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
188 #define LONG_RETRY_MIN 0
189 #define LONG_RETRY_MAX 15
190 #define LONG_RETRY_DEF 4
192 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
194 /* BasebandType[] baseband type selected
195 0: indicate 802.11a type
196 1: indicate 802.11b type
197 2: indicate 802.11g type
199 #define BBP_TYPE_MIN 0
200 #define BBP_TYPE_MAX 2
201 #define BBP_TYPE_DEF 2
203 DEVICE_PARAM(BasebandType, "baseband type");
206 0: indicate disable 802.11h
207 1: indicate enable 802.11h
210 #define X80211h_MODE_DEF 0
212 DEVICE_PARAM(b80211hEnable, "802.11h mode");
215 0: indicate disable 802.11h
216 1: indicate enable 802.11h
219 #define DIVERSITY_ANT_DEF 0
221 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
224 // Static vars definitions
226 static CHIP_INFO chip_info_table[] = {
227 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
228 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
232 static const struct pci_device_id vt6655_pci_id_table[] = {
233 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
237 /*--------------------- Static Functions --------------------------*/
239 static int vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent);
240 static void vt6655_init_info(struct pci_dev *pcid,
241 struct vnt_private **ppDevice, PCHIP_INFO);
242 static void device_free_info(struct vnt_private *pDevice);
243 static bool device_get_pci_info(struct vnt_private *, struct pci_dev *pcid);
244 static void device_print_info(struct vnt_private *pDevice);
245 static void device_init_diversity_timer(struct vnt_private *pDevice);
246 static irqreturn_t device_intr(int irq, void *dev_instance);
249 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
250 static struct notifier_block device_notifier = {
251 .notifier_call = device_notify_reboot,
257 static void device_init_rd0_ring(struct vnt_private *pDevice);
258 static void device_init_rd1_ring(struct vnt_private *pDevice);
259 static void device_init_defrag_cb(struct vnt_private *pDevice);
260 static void device_init_td0_ring(struct vnt_private *pDevice);
261 static void device_init_td1_ring(struct vnt_private *pDevice);
263 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx);
264 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx);
265 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc);
266 static void device_init_registers(struct vnt_private *pDevice);
267 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc);
268 static void device_free_td0_ring(struct vnt_private *pDevice);
269 static void device_free_td1_ring(struct vnt_private *pDevice);
270 static void device_free_rd0_ring(struct vnt_private *pDevice);
271 static void device_free_rd1_ring(struct vnt_private *pDevice);
272 static void device_free_rings(struct vnt_private *pDevice);
273 static void device_free_frag_buf(struct vnt_private *pDevice);
275 /*--------------------- Export Variables --------------------------*/
277 /*--------------------- Export Functions --------------------------*/
279 static char *get_chip_name(int chip_id)
283 for (i = 0; chip_info_table[i].name != NULL; i++)
284 if (chip_info_table[i].chip_id == chip_id)
286 return chip_info_table[i].name;
289 static void vt6655_remove(struct pci_dev *pcid)
291 struct vnt_private *pDevice = pci_get_drvdata(pcid);
295 device_free_info(pDevice);
298 static void device_get_options(struct vnt_private *pDevice)
300 POPTIONS pOpts = &(pDevice->sOpts);
302 pOpts->nRxDescs0 = RX_DESC_DEF0;
303 pOpts->nRxDescs1 = RX_DESC_DEF1;
304 pOpts->nTxDescs[0] = TX_DESC_DEF0;
305 pOpts->nTxDescs[1] = TX_DESC_DEF1;
306 pOpts->flags |= DEVICE_FLAGS_IP_ALIGN;
307 pOpts->int_works = INT_WORKS_DEF;
308 pOpts->rts_thresh = RTS_THRESH_DEF;
309 pOpts->frag_thresh = FRAG_THRESH_DEF;
310 pOpts->data_rate = DATA_RATE_DEF;
311 pOpts->channel_num = CHANNEL_DEF;
313 pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE;
314 pOpts->flags |= DEVICE_FLAGS_OP_MODE;
315 pOpts->short_retry = SHORT_RETRY_DEF;
316 pOpts->long_retry = LONG_RETRY_DEF;
317 pOpts->bbp_type = BBP_TYPE_DEF;
318 pOpts->flags |= DEVICE_FLAGS_80211h_MODE;
319 pOpts->flags |= DEVICE_FLAGS_DiversityANT;
323 device_set_options(struct vnt_private *pDevice)
325 unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
326 unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
327 unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
329 ether_addr_copy(pDevice->abyBroadcastAddr, abyBroadcastAddr);
330 ether_addr_copy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042);
331 ether_addr_copy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel);
333 pDevice->uChannel = pDevice->sOpts.channel_num;
334 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
335 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
336 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
337 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
338 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
339 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
340 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
341 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
342 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
343 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
344 if (pDevice->uConnectionRate < RATE_AUTO)
345 pDevice->bFixRate = true;
346 pDevice->byBBType = pDevice->sOpts.bbp_type;
347 pDevice->byPacketType = (VIA_PKT_TYPE)pDevice->byBBType;
348 pDevice->byAutoFBCtrl = AUTO_FB_0;
349 pDevice->bUpdateBBVGA = true;
350 pDevice->byFOETuning = 0;
351 pDevice->byPreambleType = 0;
353 pr_debug(" uChannel= %d\n", (int)pDevice->uChannel);
354 pr_debug(" byOpMode= %d\n", (int)pDevice->byOpMode);
355 pr_debug(" wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
356 pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
357 pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
358 pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType);
359 pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
360 pr_debug(" uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
361 pr_debug(" byBBType= %d\n", (int)pDevice->byBBType);
362 pr_debug(" pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
363 pr_debug(" pDevice->bDiversityRegCtlON= %d\n",
364 (int)pDevice->bDiversityRegCtlON);
368 // Initialisation of MAC & BBP registers
371 static void device_init_registers(struct vnt_private *pDevice)
375 unsigned char byValue;
376 unsigned char byValue1;
377 unsigned char byCCKPwrdBm = 0;
378 unsigned char byOFDMPwrdBm = 0;
380 MACbShutdown(pDevice->PortOffset);
381 BBvSoftwareReset(pDevice->PortOffset);
383 /* Do MACbSoftwareReset in MACvInitialize */
384 MACbSoftwareReset(pDevice->PortOffset);
386 pDevice->bAES = false;
388 /* Only used in 11g type, sync with ERP IE */
389 pDevice->bProtectMode = false;
391 pDevice->bNonERPPresent = false;
392 pDevice->bBarkerPreambleMd = false;
393 pDevice->wCurrentRate = RATE_1M;
394 pDevice->byTopOFDMBasicRate = RATE_24M;
395 pDevice->byTopCCKBasicRate = RATE_1M;
397 /* Target to IF pin while programming to RF chip. */
398 pDevice->byRevId = 0;
401 MACvInitialize(pDevice->PortOffset);
404 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
406 spin_lock_irqsave(&pDevice->lock, flags);
408 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
410 spin_unlock_irqrestore(&pDevice->lock, flags);
412 /* Get Channel range */
413 pDevice->byMinChannel = 1;
414 pDevice->byMaxChannel = CB_MAX_CHANNEL;
417 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
418 if (byValue & EEP_ANTINV)
419 pDevice->bTxRxAntInv = true;
421 pDevice->bTxRxAntInv = false;
423 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
424 /* if not set default is All */
426 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
428 pDevice->ulDiversityNValue = 100*260;
429 pDevice->ulDiversityMValue = 100*16;
431 pDevice->byTMax2 = 4;
432 pDevice->ulSQ3TH = 0;
433 pDevice->byTMax3 = 64;
435 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
436 pDevice->byAntennaCount = 2;
437 pDevice->byTxAntennaMode = ANT_B;
438 pDevice->dwTxAntennaSel = 1;
439 pDevice->dwRxAntennaSel = 1;
441 if (pDevice->bTxRxAntInv)
442 pDevice->byRxAntennaMode = ANT_A;
444 pDevice->byRxAntennaMode = ANT_B;
446 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset,
449 if ((byValue1 & 0x08) == 0)
450 pDevice->bDiversityEnable = false;
452 pDevice->bDiversityEnable = true;
454 pDevice->bDiversityEnable = false;
455 pDevice->byAntennaCount = 1;
456 pDevice->dwTxAntennaSel = 0;
457 pDevice->dwRxAntennaSel = 0;
459 if (byValue & EEP_ANTENNA_AUX) {
460 pDevice->byTxAntennaMode = ANT_A;
462 if (pDevice->bTxRxAntInv)
463 pDevice->byRxAntennaMode = ANT_B;
465 pDevice->byRxAntennaMode = ANT_A;
467 pDevice->byTxAntennaMode = ANT_B;
469 if (pDevice->bTxRxAntInv)
470 pDevice->byRxAntennaMode = ANT_A;
472 pDevice->byRxAntennaMode = ANT_B;
476 pr_debug("bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
477 pDevice->bDiversityEnable, (int)pDevice->ulDiversityNValue,
478 (int)pDevice->ulDiversityMValue, pDevice->byTMax,
481 /* zonetype initial */
482 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
485 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
487 /* force change RevID for VT3253 emu */
488 if ((pDevice->byRFType & RF_EMU) != 0)
489 pDevice->byRevId = 0x80;
491 pDevice->byRFType &= RF_MASK;
492 pr_debug("pDevice->byRFType = %x\n", pDevice->byRFType);
494 if (!pDevice->bZoneRegExist)
495 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
497 pr_debug("pDevice->byZoneType = %x\n", pDevice->byZoneType);
502 /* Get Desire Power Value */
503 pDevice->byCurPwr = 0xFF;
504 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
505 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
507 /* Load power Table */
508 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
509 pDevice->abyCCKPwrTbl[ii + 1] =
510 SROMbyReadEmbedded(pDevice->PortOffset,
511 (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
512 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
513 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
515 pDevice->abyOFDMPwrTbl[ii + 1] =
516 SROMbyReadEmbedded(pDevice->PortOffset,
517 (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
518 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
519 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
521 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
522 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
525 /* recover 12,13 ,14channel for EUROPE by 11 channel */
526 for (ii = 11; ii < 14; ii++) {
527 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
528 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
531 /* Load OFDM A Power Table */
532 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
533 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
534 SROMbyReadEmbedded(pDevice->PortOffset,
535 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
537 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
538 SROMbyReadEmbedded(pDevice->PortOffset,
539 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
542 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
543 MACvSelectPage1(pDevice->PortOffset);
545 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
546 (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
548 MACvSelectPage0(pDevice->PortOffset);
551 /* use relative tx timeout and 802.11i D4 */
552 MACvWordRegBitsOn(pDevice->PortOffset,
553 MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
555 /* set performance parameter by registry */
556 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
557 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
559 /* reset TSF counter */
560 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
561 /* enable TSF counter */
562 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
564 /* initialize BBP registers */
565 BBbVT3253Init(pDevice);
567 if (pDevice->bUpdateBBVGA) {
568 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
569 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
570 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
573 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
574 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
576 /* Set BB and packet type at the same time. */
577 /* Set Short Slot Time, xIFS, and RSPINF. */
578 if (pDevice->uConnectionRate == RATE_AUTO)
579 pDevice->wCurrentRate = RATE_54M;
581 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
583 pDevice->bRadioOff = false;
585 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
587 pDevice->bHWRadioOff = false;
589 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
591 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
593 if (((pDevice->byGPIO & GPIO0_DATA) &&
594 !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
595 (!(pDevice->byGPIO & GPIO0_DATA) &&
596 (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
597 pDevice->bHWRadioOff = true;
600 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
601 CARDbRadioPowerOff(pDevice);
603 /* get Permanent network address */
604 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
605 pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
607 /* reset Tx pointer */
608 CARDvSafeResetRx(pDevice);
609 /* reset Rx pointer */
610 CARDvSafeResetTx(pDevice);
612 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
613 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
616 MACvReceive0(pDevice->PortOffset);
617 MACvReceive1(pDevice->PortOffset);
619 /* start the adapter */
620 MACvStart(pDevice->PortOffset);
623 static void device_init_diversity_timer(struct vnt_private *pDevice)
625 init_timer(&pDevice->TimerSQ3Tmax1);
626 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
627 pDevice->TimerSQ3Tmax1.function = TimerSQ3CallBack;
628 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
630 init_timer(&pDevice->TimerSQ3Tmax2);
631 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
632 pDevice->TimerSQ3Tmax2.function = TimerSQ3CallBack;
633 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
635 init_timer(&pDevice->TimerSQ3Tmax3);
636 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
637 pDevice->TimerSQ3Tmax3.function = TimerState1CallBack;
638 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
641 static void device_print_info(struct vnt_private *pDevice)
643 dev_info(&pDevice->pcid->dev, "%s\n", get_chip_name(pDevice->chip_id));
645 dev_info(&pDevice->pcid->dev, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
646 pDevice->abyCurrentNetAddr, (unsigned long)pDevice->ioaddr,
647 (unsigned long)pDevice->PortOffset, pDevice->pcid->irq);
650 static void vt6655_init_info(struct pci_dev *pcid,
651 struct vnt_private **ppDevice,
652 PCHIP_INFO pChip_info)
654 memset(*ppDevice, 0, sizeof(**ppDevice));
656 (*ppDevice)->pcid = pcid;
657 (*ppDevice)->chip_id = pChip_info->chip_id;
658 (*ppDevice)->io_size = pChip_info->io_size;
659 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
660 (*ppDevice)->multicast_limit = 32;
662 spin_lock_init(&((*ppDevice)->lock));
665 static bool device_get_pci_info(struct vnt_private *pDevice,
666 struct pci_dev *pcid)
670 unsigned int cis_addr;
672 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
673 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
674 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
675 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
677 pci_set_master(pcid);
679 pDevice->memaddr = pci_resource_start(pcid, 0);
680 pDevice->ioaddr = pci_resource_start(pcid, 1);
682 cis_addr = pci_resource_start(pcid, 2);
684 pDevice->pcid = pcid;
686 pci_read_config_byte(pcid, PCI_COMMAND, &b);
687 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
692 static void device_free_info(struct vnt_private *pDevice)
698 ieee80211_unregister_hw(pDevice->hw);
700 if (pDevice->PortOffset)
701 iounmap(pDevice->PortOffset);
704 pci_release_regions(pDevice->pcid);
707 ieee80211_free_hw(pDevice->hw);
710 static bool device_init_rings(struct vnt_private *pDevice)
714 /*allocate all RD/TD rings a single pool*/
715 vir_pool = pci_zalloc_consistent(pDevice->pcid,
716 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
717 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
718 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
719 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
721 if (vir_pool == NULL) {
722 dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n");
726 pDevice->aRD0Ring = vir_pool;
727 pDevice->aRD1Ring = vir_pool +
728 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
730 pDevice->rd0_pool_dma = pDevice->pool_dma;
731 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
732 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
734 pDevice->tx0_bufs = pci_zalloc_consistent(pDevice->pcid,
735 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
736 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
739 &pDevice->tx_bufs_dma0);
740 if (pDevice->tx0_bufs == NULL) {
741 dev_err(&pDevice->pcid->dev, "allocate buf dma memory failed\n");
743 pci_free_consistent(pDevice->pcid,
744 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
745 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
746 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
747 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
748 vir_pool, pDevice->pool_dma
753 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
754 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
756 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
757 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
759 // vir_pool: pvoid type
760 pDevice->apTD0Rings = vir_pool
761 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
762 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
764 pDevice->apTD1Rings = vir_pool
765 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
766 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
767 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
769 pDevice->tx1_bufs = pDevice->tx0_bufs +
770 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
772 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
773 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
775 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
778 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
779 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
781 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
782 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
787 static void device_free_rings(struct vnt_private *pDevice)
789 pci_free_consistent(pDevice->pcid,
790 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
791 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
792 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
793 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
795 pDevice->aRD0Ring, pDevice->pool_dma
798 if (pDevice->tx0_bufs)
799 pci_free_consistent(pDevice->pcid,
800 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
801 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
804 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
808 static void device_init_rd0_ring(struct vnt_private *pDevice)
811 dma_addr_t curr = pDevice->rd0_pool_dma;
814 /* Init the RD0 ring entries */
815 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
816 pDesc = &(pDevice->aRD0Ring[i]);
817 pDesc->pRDInfo = alloc_rd_info();
818 ASSERT(pDesc->pRDInfo);
819 if (!device_alloc_rx_buf(pDevice, pDesc))
820 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
822 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
823 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
824 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
828 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
829 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
832 static void device_init_rd1_ring(struct vnt_private *pDevice)
835 dma_addr_t curr = pDevice->rd1_pool_dma;
838 /* Init the RD1 ring entries */
839 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
840 pDesc = &(pDevice->aRD1Ring[i]);
841 pDesc->pRDInfo = alloc_rd_info();
842 ASSERT(pDesc->pRDInfo);
843 if (!device_alloc_rx_buf(pDevice, pDesc))
844 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
846 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
847 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
848 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
852 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
853 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
856 static void device_init_defrag_cb(struct vnt_private *pDevice)
859 PSDeFragControlBlock pDeF;
861 /* Init the fragment ctl entries */
862 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
863 pDeF = &(pDevice->sRxDFCB[i]);
864 if (!device_alloc_frag_buf(pDevice, pDeF))
865 dev_err(&pDevice->pcid->dev, "can not alloc frag bufs\n");
867 pDevice->cbDFCB = CB_MAX_RX_FRAG;
868 pDevice->cbFreeDFCB = pDevice->cbDFCB;
871 static void device_free_rd0_ring(struct vnt_private *pDevice)
875 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
876 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
877 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
879 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
880 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
882 dev_kfree_skb(pRDInfo->skb);
884 kfree(pDesc->pRDInfo);
888 static void device_free_rd1_ring(struct vnt_private *pDevice)
892 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
893 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
894 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
896 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
897 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
899 dev_kfree_skb(pRDInfo->skb);
901 kfree(pDesc->pRDInfo);
905 static void device_free_frag_buf(struct vnt_private *pDevice)
907 PSDeFragControlBlock pDeF;
910 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
911 pDeF = &(pDevice->sRxDFCB[i]);
914 dev_kfree_skb(pDeF->skb);
919 static void device_init_td0_ring(struct vnt_private *pDevice)
925 curr = pDevice->td0_pool_dma;
926 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
927 pDesc = &(pDevice->apTD0Rings[i]);
928 pDesc->pTDInfo = alloc_td_info();
929 ASSERT(pDesc->pTDInfo);
930 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
931 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
932 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
934 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
935 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
936 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
940 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
941 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
944 static void device_init_td1_ring(struct vnt_private *pDevice)
950 /* Init the TD ring entries */
951 curr = pDevice->td1_pool_dma;
952 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
953 pDesc = &(pDevice->apTD1Rings[i]);
954 pDesc->pTDInfo = alloc_td_info();
955 ASSERT(pDesc->pTDInfo);
956 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
957 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
958 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
960 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
961 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
962 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
966 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
967 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
970 static void device_free_td0_ring(struct vnt_private *pDevice)
974 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
975 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
976 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
978 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
979 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
980 pTDInfo->skb->len, PCI_DMA_TODEVICE);
983 dev_kfree_skb(pTDInfo->skb);
985 kfree(pDesc->pTDInfo);
989 static void device_free_td1_ring(struct vnt_private *pDevice)
993 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
994 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
995 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
997 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
998 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
999 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1002 dev_kfree_skb(pTDInfo->skb);
1004 kfree(pDesc->pTDInfo);
1008 /*-----------------------------------------------------------------*/
1010 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1015 for (pRD = pDevice->pCurrRD[uIdx];
1016 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1020 if (vnt_receive_frame(pDevice, pRD)) {
1021 if (!device_alloc_rx_buf(pDevice, pRD)) {
1022 dev_err(&pDevice->pcid->dev,
1023 "can not allocate rx buf\n");
1027 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1030 pDevice->pCurrRD[uIdx] = pRD;
1035 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
1037 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1039 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1040 if (pRDInfo->skb == NULL)
1042 ASSERT(pRDInfo->skb);
1045 pci_map_single(pDevice->pcid,
1046 skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)),
1047 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1049 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1051 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1052 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1053 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1054 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1059 bool device_alloc_frag_buf(struct vnt_private *pDevice,
1060 PSDeFragControlBlock pDeF)
1062 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1063 if (pDeF->skb == NULL)
1070 static const u8 fallback_rate0[5][5] = {
1071 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
1072 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
1073 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
1074 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
1075 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
1078 static const u8 fallback_rate1[5][5] = {
1079 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
1080 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
1081 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
1082 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
1083 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
1086 static int vnt_int_report_rate(struct vnt_private *priv,
1087 PDEVICE_TD_INFO context, u8 tsr0, u8 tsr1)
1089 struct vnt_tx_fifo_head *fifo_head;
1090 struct ieee80211_tx_info *info;
1091 struct ieee80211_rate *rate;
1093 u8 tx_retry = (tsr0 & TSR0_NCR);
1102 fifo_head = (struct vnt_tx_fifo_head *)context->buf;
1103 fb_option = (le16_to_cpu(fifo_head->fifo_ctl) &
1104 (FIFOCTL_AUTO_FB_0 | FIFOCTL_AUTO_FB_1));
1106 info = IEEE80211_SKB_CB(context->skb);
1107 idx = info->control.rates[0].idx;
1109 if (fb_option && !(tsr1 & TSR1_TERR)) {
1111 u8 retry = tx_retry;
1113 rate = ieee80211_get_tx_rate(priv->hw, info);
1114 tx_rate = rate->hw_value - RATE_18M;
1119 if (fb_option & FIFOCTL_AUTO_FB_0)
1120 tx_rate = fallback_rate0[tx_rate][retry];
1121 else if (fb_option & FIFOCTL_AUTO_FB_1)
1122 tx_rate = fallback_rate1[tx_rate][retry];
1124 if (info->band == IEEE80211_BAND_5GHZ)
1125 idx = tx_rate - RATE_6M;
1130 ieee80211_tx_info_clear_status(info);
1132 info->status.rates[0].count = tx_retry;
1134 if (!(tsr1 & TSR1_TERR)) {
1135 info->status.rates[0].idx = idx;
1136 info->flags |= IEEE80211_TX_STAT_ACK;
1142 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1146 unsigned char byTsr0;
1147 unsigned char byTsr1;
1149 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1150 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1155 byTsr0 = pTD->m_td0TD0.byTSR0;
1156 byTsr1 = pTD->m_td0TD0.byTSR1;
1158 //Only the status of first TD in the chain is correct
1159 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1160 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1162 vnt_int_report_rate(pDevice, pTD->pTDInfo, byTsr0, byTsr1);
1164 if (!(byTsr1 & TSR1_TERR)) {
1166 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
1171 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
1172 (int)uIdx, byTsr1, byTsr0);
1176 if (byTsr1 & TSR1_TERR) {
1177 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1178 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
1179 (int)uIdx, byTsr1, byTsr0);
1182 device_free_tx_buf(pDevice, pTD);
1183 pDevice->iTDUsed[uIdx]--;
1185 /* Make sure queue is available */
1186 if (AVAIL_TD(pDevice, uIdx))
1187 ieee80211_wake_queues(pDevice->hw);
1191 pDevice->apTailTD[uIdx] = pTD;
1196 static void device_error(struct vnt_private *pDevice, unsigned short status)
1198 if (status & ISR_FETALERR) {
1199 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
1201 MACbShutdown(pDevice->PortOffset);
1206 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
1208 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1209 struct sk_buff *skb = pTDInfo->skb;
1211 // pre-allocated buf_dma can't be unmapped.
1212 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1213 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1217 if (pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)
1218 ieee80211_tx_status_irqsafe(pDevice->hw, skb);
1220 dev_kfree_skb_irq(skb);
1222 pTDInfo->skb_dma = 0;
1223 pTDInfo->skb = NULL;
1224 pTDInfo->byFlags = 0;
1227 static irqreturn_t device_intr(int irq, void *dev_instance)
1229 struct vnt_private *pDevice = dev_instance;
1231 unsigned long dwMIBCounter = 0;
1232 unsigned char byOrgPageSel = 0;
1235 unsigned long flags;
1237 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
1239 if (pDevice->dwIsr == 0)
1240 return IRQ_RETVAL(handled);
1242 if (pDevice->dwIsr == 0xffffffff) {
1243 pr_debug("dwIsr = 0xffff\n");
1244 return IRQ_RETVAL(handled);
1248 MACvIntDisable(pDevice->PortOffset);
1250 spin_lock_irqsave(&pDevice->lock, flags);
1252 //Make sure current page is 0
1253 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
1254 if (byOrgPageSel == 1)
1255 MACvSelectPage0(pDevice->PortOffset);
1259 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
1261 // Must do this after doing rx/tx, cause ISR bit is slow
1262 // than RD/TD write back
1263 // update ISR counter
1264 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
1265 while (pDevice->dwIsr != 0) {
1266 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
1267 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
1269 if (pDevice->dwIsr & ISR_FETALERR) {
1270 pr_debug(" ISR_FETALERR\n");
1271 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
1272 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
1273 device_error(pDevice, pDevice->dwIsr);
1276 if (pDevice->dwIsr & ISR_TBTT) {
1278 pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
1279 if (pDevice->bUpdateBBVGA &&
1280 !(pDevice->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
1281 pDevice->vif->bss_conf.assoc &&
1282 pDevice->uCurrRSSI) {
1285 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
1286 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
1287 if (ldBm < pDevice->ldBmThreshold[ii]) {
1288 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1292 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1293 pDevice->uBBVGADiffCount++;
1294 if (pDevice->uBBVGADiffCount == 1) {
1295 // first VGA diff gain
1296 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
1297 pr_debug("First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1299 pDevice->byBBVGANew,
1300 pDevice->byBBVGACurrent,
1301 (int)pDevice->uBBVGADiffCount);
1303 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
1304 pr_debug("RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1306 pDevice->byBBVGANew,
1307 pDevice->byBBVGACurrent,
1308 (int)pDevice->uBBVGADiffCount);
1309 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
1312 pDevice->uBBVGADiffCount = 1;
1317 pDevice->bBeaconSent = false;
1318 if (pDevice->bEnablePSMode)
1319 PSbIsNextTBTTWakeUp((void *)pDevice);
1321 if ((pDevice->op_mode == NL80211_IFTYPE_AP ||
1322 pDevice->op_mode == NL80211_IFTYPE_ADHOC) &&
1323 pDevice->vif->bss_conf.enable_beacon) {
1324 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
1325 (pDevice->vif->bss_conf.beacon_int - MAKE_BEACON_RESERVED) << 10);
1328 /* TODO: adhoc PS mode */
1332 if (pDevice->dwIsr & ISR_BNTX) {
1333 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
1334 pDevice->bIsBeaconBufReadySet = false;
1335 pDevice->cbBeaconBufReadySetCnt = 0;
1338 pDevice->bBeaconSent = true;
1341 if (pDevice->dwIsr & ISR_RXDMA0)
1342 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
1344 if (pDevice->dwIsr & ISR_RXDMA1)
1345 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
1347 if (pDevice->dwIsr & ISR_TXDMA0)
1348 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
1350 if (pDevice->dwIsr & ISR_AC0DMA)
1351 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
1353 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
1355 if (pDevice->vif->bss_conf.enable_beacon)
1356 vnt_beacon_make(pDevice, pDevice->vif);
1360 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
1362 MACvReceive0(pDevice->PortOffset);
1363 MACvReceive1(pDevice->PortOffset);
1365 if (max_count > pDevice->sOpts.int_works)
1369 if (byOrgPageSel == 1)
1370 MACvSelectPage1(pDevice->PortOffset);
1372 spin_unlock_irqrestore(&pDevice->lock, flags);
1374 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1376 return IRQ_RETVAL(handled);
1379 static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1381 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1383 u32 dma_idx = TYPE_AC0DMA;
1384 unsigned long flags;
1386 spin_lock_irqsave(&priv->lock, flags);
1388 if (!ieee80211_is_data(hdr->frame_control))
1389 dma_idx = TYPE_TXDMA0;
1391 if (AVAIL_TD(priv, dma_idx) < 1) {
1392 spin_unlock_irqrestore(&priv->lock, flags);
1396 head_td = priv->apCurrTD[dma_idx];
1398 head_td->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1400 head_td->pTDInfo->skb = skb;
1402 priv->iTDUsed[dma_idx]++;
1404 /* Take ownership */
1406 head_td->m_td0TD0.f1Owner = OWNED_BY_NIC;
1410 priv->apCurrTD[dma_idx] = head_td->next;
1412 spin_unlock_irqrestore(&priv->lock, flags);
1414 vnt_generate_fifo_header(priv, dma_idx, head_td, skb);
1416 if (MACbIsRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
1417 MACbPSWakeup(priv->PortOffset);
1419 spin_lock_irqsave(&priv->lock, flags);
1421 priv->bPWBitOn = false;
1423 head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB;
1425 if (dma_idx == TYPE_AC0DMA)
1426 MACvTransmitAC0(priv->PortOffset);
1428 MACvTransmit0(priv->PortOffset);
1430 spin_unlock_irqrestore(&priv->lock, flags);
1435 static void vnt_tx_80211(struct ieee80211_hw *hw,
1436 struct ieee80211_tx_control *control,
1437 struct sk_buff *skb)
1439 struct vnt_private *priv = hw->priv;
1441 ieee80211_stop_queues(hw);
1443 if (vnt_tx_packet(priv, skb)) {
1444 ieee80211_free_txskb(hw, skb);
1446 ieee80211_wake_queues(hw);
1450 static int vnt_start(struct ieee80211_hw *hw)
1452 struct vnt_private *priv = hw->priv;
1455 priv->rx_buf_sz = PKT_BUF_SZ;
1456 if (!device_init_rings(priv))
1459 ret = request_irq(priv->pcid->irq, &device_intr,
1460 IRQF_SHARED, "vt6655", priv);
1462 dev_dbg(&priv->pcid->dev, "failed to start irq\n");
1466 dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
1467 device_init_rd0_ring(priv);
1468 device_init_rd1_ring(priv);
1469 device_init_defrag_cb(priv);
1470 device_init_td0_ring(priv);
1471 device_init_td1_ring(priv);
1473 device_init_registers(priv);
1475 dev_dbg(&priv->pcid->dev, "call MACvIntEnable\n");
1476 MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
1478 ieee80211_wake_queues(hw);
1483 static void vnt_stop(struct ieee80211_hw *hw)
1485 struct vnt_private *priv = hw->priv;
1487 ieee80211_stop_queues(hw);
1489 MACbShutdown(priv->PortOffset);
1490 MACbSoftwareReset(priv->PortOffset);
1491 CARDbRadioPowerOff(priv);
1493 device_free_td0_ring(priv);
1494 device_free_td1_ring(priv);
1495 device_free_rd0_ring(priv);
1496 device_free_rd1_ring(priv);
1497 device_free_frag_buf(priv);
1498 device_free_rings(priv);
1500 free_irq(priv->pcid->irq, priv);
1503 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1505 struct vnt_private *priv = hw->priv;
1509 switch (vif->type) {
1510 case NL80211_IFTYPE_STATION:
1511 if (priv->bDiversityRegCtlON)
1512 device_init_diversity_timer(priv);
1514 case NL80211_IFTYPE_ADHOC:
1515 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1517 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1520 case NL80211_IFTYPE_AP:
1521 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1523 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1530 priv->op_mode = vif->type;
1535 static void vnt_remove_interface(struct ieee80211_hw *hw,
1536 struct ieee80211_vif *vif)
1538 struct vnt_private *priv = hw->priv;
1540 switch (vif->type) {
1541 case NL80211_IFTYPE_STATION:
1542 if (priv->bDiversityRegCtlON) {
1543 del_timer(&priv->TimerSQ3Tmax1);
1544 del_timer(&priv->TimerSQ3Tmax2);
1545 del_timer(&priv->TimerSQ3Tmax3);
1548 case NL80211_IFTYPE_ADHOC:
1549 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1550 MACvRegBitsOff(priv->PortOffset,
1551 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1552 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1554 case NL80211_IFTYPE_AP:
1555 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1556 MACvRegBitsOff(priv->PortOffset,
1557 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1558 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1564 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
1568 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
1570 struct vnt_private *priv = hw->priv;
1571 struct ieee80211_conf *conf = &hw->conf;
1574 if (changed & IEEE80211_CONF_CHANGE_PS) {
1575 if (conf->flags & IEEE80211_CONF_PS)
1576 PSvEnablePowerSaving(priv, conf->listen_interval);
1578 PSvDisablePowerSaving(priv);
1581 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
1582 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
1583 set_channel(priv, conf->chandef.chan->hw_value);
1585 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
1586 bb_type = BB_TYPE_11A;
1588 bb_type = BB_TYPE_11G;
1590 if (priv->byBBType != bb_type) {
1591 priv->byBBType = bb_type;
1593 CARDbSetPhyParameter(priv,
1594 priv->byBBType, 0, 0, NULL, NULL);
1598 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1599 if (priv->byBBType == BB_TYPE_11B)
1600 priv->wCurrentRate = RATE_1M;
1602 priv->wCurrentRate = RATE_54M;
1604 RFbSetPower(priv, priv->wCurrentRate,
1605 conf->chandef.chan->hw_value);
1611 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
1612 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
1615 struct vnt_private *priv = hw->priv;
1617 priv->current_aid = conf->aid;
1619 if (changed & BSS_CHANGED_BSSID)
1620 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid);
1622 if (changed & BSS_CHANGED_BASIC_RATES) {
1623 priv->basic_rates = conf->basic_rates;
1625 CARDvUpdateBasicTopRate(priv);
1627 dev_dbg(&priv->pcid->dev,
1628 "basic rates %x\n", conf->basic_rates);
1631 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1632 if (conf->use_short_preamble) {
1633 MACvEnableBarkerPreambleMd(priv->PortOffset);
1634 priv->byPreambleType = true;
1636 MACvDisableBarkerPreambleMd(priv->PortOffset);
1637 priv->byPreambleType = false;
1641 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1642 if (conf->use_cts_prot)
1643 MACvEnableProtectMD(priv->PortOffset);
1645 MACvDisableProtectMD(priv->PortOffset);
1648 if (changed & BSS_CHANGED_ERP_SLOT) {
1649 if (conf->use_short_slot)
1650 priv->bShortSlotTime = true;
1652 priv->bShortSlotTime = false;
1655 CARDbSetPhyParameter(priv, priv->byBBType, 0, 0, NULL, NULL);
1656 BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
1659 if (changed & BSS_CHANGED_TXPOWER)
1660 RFbSetPower(priv, priv->wCurrentRate,
1661 conf->chandef.chan->hw_value);
1663 if (changed & BSS_CHANGED_BEACON_ENABLED) {
1664 dev_dbg(&priv->pcid->dev,
1665 "Beacon enable %d\n", conf->enable_beacon);
1667 if (conf->enable_beacon) {
1668 vnt_beacon_enable(priv, vif, conf);
1670 MACvRegBitsOn(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1672 MACvRegBitsOff(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1676 if (changed & BSS_CHANGED_ASSOC && priv->op_mode != NL80211_IFTYPE_AP) {
1678 CARDbUpdateTSF(priv, conf->beacon_rate->hw_value,
1679 conf->sync_device_ts, conf->sync_tsf);
1681 CARDbSetBeaconPeriod(priv, conf->beacon_int);
1683 CARDvSetFirstNextTBTT(priv->PortOffset,
1686 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1688 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1694 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
1695 struct netdev_hw_addr_list *mc_list)
1697 struct vnt_private *priv = hw->priv;
1698 struct netdev_hw_addr *ha;
1702 netdev_hw_addr_list_for_each(ha, mc_list) {
1703 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1705 mc_filter |= 1ULL << (bit_nr & 0x3f);
1708 priv->mc_list_count = mc_list->count;
1713 static void vnt_configure(struct ieee80211_hw *hw,
1714 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
1716 struct vnt_private *priv = hw->priv;
1719 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_PROMISC_IN_BSS |
1720 FIF_BCN_PRBRESP_PROMISC;
1722 VNSvInPortB(priv->PortOffset + MAC_REG_RCR, &rx_mode);
1724 dev_dbg(&priv->pcid->dev, "rx mode in = %x\n", rx_mode);
1726 if (changed_flags & FIF_PROMISC_IN_BSS) {
1727 /* unconditionally log net taps */
1728 if (*total_flags & FIF_PROMISC_IN_BSS)
1729 rx_mode |= RCR_UNICAST;
1731 rx_mode &= ~RCR_UNICAST;
1734 if (changed_flags & FIF_ALLMULTI) {
1735 if (*total_flags & FIF_ALLMULTI) {
1736 if (priv->mc_list_count > 2) {
1737 MACvSelectPage1(priv->PortOffset);
1739 VNSvOutPortD(priv->PortOffset +
1740 MAC_REG_MAR0, 0xffffffff);
1741 VNSvOutPortD(priv->PortOffset +
1742 MAC_REG_MAR0 + 4, 0xffffffff);
1744 MACvSelectPage0(priv->PortOffset);
1746 MACvSelectPage1(priv->PortOffset);
1748 VNSvOutPortD(priv->PortOffset +
1749 MAC_REG_MAR0, (u32)multicast);
1750 VNSvOutPortD(priv->PortOffset +
1752 (u32)(multicast >> 32));
1754 MACvSelectPage0(priv->PortOffset);
1757 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1759 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
1763 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
1764 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1766 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
1767 rx_mode &= ~RCR_BSSID;
1769 rx_mode |= RCR_BSSID;
1772 VNSvOutPortB(priv->PortOffset + MAC_REG_RCR, rx_mode);
1774 dev_dbg(&priv->pcid->dev, "rx mode out= %x\n", rx_mode);
1777 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1778 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1779 struct ieee80211_key_conf *key)
1781 struct vnt_private *priv = hw->priv;
1785 if (vnt_set_keys(hw, sta, vif, key))
1789 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
1790 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
1798 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1800 struct vnt_private *priv = hw->priv;
1803 CARDbGetCurrentTSF(priv->PortOffset, &tsf);
1808 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1811 struct vnt_private *priv = hw->priv;
1813 CARDvUpdateNextTBTT(priv->PortOffset, tsf, vif->bss_conf.beacon_int);
1816 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1818 struct vnt_private *priv = hw->priv;
1820 /* reset TSF counter */
1821 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1824 static const struct ieee80211_ops vnt_mac_ops = {
1828 .add_interface = vnt_add_interface,
1829 .remove_interface = vnt_remove_interface,
1830 .config = vnt_config,
1831 .bss_info_changed = vnt_bss_info_changed,
1832 .prepare_multicast = vnt_prepare_multicast,
1833 .configure_filter = vnt_configure,
1834 .set_key = vnt_set_key,
1835 .get_tsf = vnt_get_tsf,
1836 .set_tsf = vnt_set_tsf,
1837 .reset_tsf = vnt_reset_tsf,
1840 int vnt_init(struct vnt_private *priv)
1842 SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyCurrentNetAddr);
1844 vnt_init_bands(priv);
1846 if (ieee80211_register_hw(priv->hw))
1849 priv->mac_hw = true;
1851 CARDbRadioPowerOff(priv);
1857 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
1859 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
1860 struct vnt_private *priv;
1861 struct ieee80211_hw *hw;
1862 struct wiphy *wiphy;
1865 dev_notice(&pcid->dev,
1866 "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1868 dev_notice(&pcid->dev,
1869 "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
1871 hw = ieee80211_alloc_hw(sizeof(*priv), &vnt_mac_ops);
1873 dev_err(&pcid->dev, "could not register ieee80211_hw\n");
1879 vt6655_init_info(pcid, &priv, pChip_info);
1883 SET_IEEE80211_DEV(priv->hw, &pcid->dev);
1885 if (pci_enable_device(pcid)) {
1886 device_free_info(priv);
1891 "Before get pci_info memaddr is %x\n", priv->memaddr);
1893 if (!device_get_pci_info(priv, pcid)) {
1894 dev_err(&pcid->dev, ": Failed to find PCI device.\n");
1895 device_free_info(priv);
1901 "after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",
1902 priv->memaddr, priv->ioaddr, priv->io_size);
1914 for (i = 0; address[i]; i++) {
1915 pci_read_config_dword(pcid, address[i], &bar);
1917 dev_dbg(&pcid->dev, "bar %d is %x\n", i, bar);
1921 "bar %d not implemented\n", i);
1925 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
1928 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xffff);
1929 len = len & ~(len - 1);
1932 "IO space: len in IO %x, BAR %d\n",
1935 len = bar & 0xfffffff0;
1939 "len in MEM %x, BAR %d\n", len, i);
1945 priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK,
1947 if (!priv->PortOffset) {
1948 dev_err(&pcid->dev, ": Failed to IO remapping ..\n");
1949 device_free_info(priv);
1953 rc = pci_request_regions(pcid, DEVICE_NAME);
1955 dev_err(&pcid->dev, ": Failed to find PCI device\n");
1956 device_free_info(priv);
1961 if (!MACbSoftwareReset(priv->PortOffset)) {
1962 dev_err(&pcid->dev, ": Failed to access MAC hardware..\n");
1963 device_free_info(priv);
1966 /* initial to reload eeprom */
1967 MACvInitialize(priv->PortOffset);
1968 MACvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr);
1970 device_get_options(priv);
1971 device_set_options(priv);
1972 /* Mask out the options cannot be set to the chip */
1973 priv->sOpts.flags &= pChip_info->flags;
1975 /* Enable the chip specified capabilities */
1976 priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL);
1978 wiphy = priv->hw->wiphy;
1980 wiphy->frag_threshold = FRAG_THRESH_DEF;
1981 wiphy->rts_threshold = RTS_THRESH_DEF;
1982 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1983 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1985 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1986 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
1987 IEEE80211_HW_SIGNAL_DBM |
1988 IEEE80211_HW_TIMING_BEACON_ONLY;
1990 priv->hw->max_signal = 100;
1995 device_print_info(priv);
1996 pci_set_drvdata(pcid, priv);
2001 /*------------------------------------------------------------------*/
2004 static int vt6655_suspend(struct pci_dev *pcid, pm_message_t state)
2006 struct vnt_private *priv = pci_get_drvdata(pcid);
2007 unsigned long flags;
2009 spin_lock_irqsave(&priv->lock, flags);
2011 pci_save_state(pcid);
2013 MACbShutdown(priv->PortOffset);
2015 pci_disable_device(pcid);
2016 pci_set_power_state(pcid, pci_choose_state(pcid, state));
2018 spin_unlock_irqrestore(&priv->lock, flags);
2023 static int vt6655_resume(struct pci_dev *pcid)
2026 pci_set_power_state(pcid, PCI_D0);
2027 pci_enable_wake(pcid, PCI_D0, 0);
2028 pci_restore_state(pcid);
2034 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
2036 static struct pci_driver device_driver = {
2037 .name = DEVICE_NAME,
2038 .id_table = vt6655_pci_id_table,
2039 .probe = vt6655_probe,
2040 .remove = vt6655_remove,
2042 .suspend = vt6655_suspend,
2043 .resume = vt6655_resume,
2047 static int __init vt6655_init_module(void)
2051 ret = pci_register_driver(&device_driver);
2054 register_reboot_notifier(&device_notifier);
2060 static void __exit vt6655_cleanup_module(void)
2063 unregister_reboot_notifier(&device_notifier);
2065 pci_unregister_driver(&device_driver);
2068 module_init(vt6655_init_module);
2069 module_exit(vt6655_cleanup_module);
2073 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
2075 struct pci_dev *pdev = NULL;
2081 for_each_pci_dev(pdev) {
2082 if (pci_dev_driver(pdev) == &device_driver) {
2083 if (pci_get_drvdata(pdev))
2084 vt6655_suspend(pdev, PMSG_HIBERNATE);