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>
75 #include <linux/delay.h>
76 #include <linux/kthread.h>
77 #include <linux/slab.h>
79 /*--------------------- Static Definitions -------------------------*/
81 // Define module options
83 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
84 MODULE_LICENSE("GPL");
85 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
87 #define DEVICE_PARAM(N, D)
89 #define RX_DESC_MIN0 16
90 #define RX_DESC_MAX0 128
91 #define RX_DESC_DEF0 32
92 DEVICE_PARAM(RxDescriptors0, "Number of receive descriptors0");
94 #define RX_DESC_MIN1 16
95 #define RX_DESC_MAX1 128
96 #define RX_DESC_DEF1 32
97 DEVICE_PARAM(RxDescriptors1, "Number of receive descriptors1");
99 #define TX_DESC_MIN0 16
100 #define TX_DESC_MAX0 128
101 #define TX_DESC_DEF0 32
102 DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
104 #define TX_DESC_MIN1 16
105 #define TX_DESC_MAX1 128
106 #define TX_DESC_DEF1 64
107 DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
109 #define IP_ALIG_DEF 0
110 /* IP_byte_align[] is used for IP header unsigned long byte aligned
111 0: indicate the IP header won't be unsigned long byte aligned.(Default) .
112 1: indicate the IP header will be unsigned long byte aligned.
113 In some environment, the IP header should be unsigned long byte aligned,
114 or the packet will be droped when we receive it. (eg: IPVS)
116 DEVICE_PARAM(IP_byte_align, "Enable IP header dword aligned");
118 #define INT_WORKS_DEF 20
119 #define INT_WORKS_MIN 10
120 #define INT_WORKS_MAX 64
122 DEVICE_PARAM(int_works, "Number of packets per interrupt services");
124 #define CHANNEL_MIN 1
125 #define CHANNEL_MAX 14
126 #define CHANNEL_DEF 6
128 DEVICE_PARAM(Channel, "Channel number");
130 /* PreambleType[] is the preamble length used for transmit.
131 0: indicate allows long preamble type
132 1: indicate allows short preamble type
135 #define PREAMBLE_TYPE_DEF 1
137 DEVICE_PARAM(PreambleType, "Preamble Type");
139 #define RTS_THRESH_MIN 512
140 #define RTS_THRESH_MAX 2347
141 #define RTS_THRESH_DEF 2347
143 DEVICE_PARAM(RTSThreshold, "RTS threshold");
145 #define FRAG_THRESH_MIN 256
146 #define FRAG_THRESH_MAX 2346
147 #define FRAG_THRESH_DEF 2346
149 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
151 #define DATA_RATE_MIN 0
152 #define DATA_RATE_MAX 13
153 #define DATA_RATE_DEF 13
155 0: indicate 1 Mbps 0x02
156 1: indicate 2 Mbps 0x04
157 2: indicate 5.5 Mbps 0x0B
158 3: indicate 11 Mbps 0x16
159 4: indicate 6 Mbps 0x0c
160 5: indicate 9 Mbps 0x12
161 6: indicate 12 Mbps 0x18
162 7: indicate 18 Mbps 0x24
163 8: indicate 24 Mbps 0x30
164 9: indicate 36 Mbps 0x48
165 10: indicate 48 Mbps 0x60
166 11: indicate 54 Mbps 0x6c
167 12: indicate 72 Mbps 0x90
168 13: indicate auto rate
171 DEVICE_PARAM(ConnectionRate, "Connection data rate");
173 #define OP_MODE_DEF 0
175 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
177 /* OpMode[] is used for transmit.
178 0: indicate infrastruct mode used
179 1: indicate adhoc mode used
180 2: indicate AP mode used
184 0: indicate disable power saving mode
185 1: indicate enable power saving mode
188 #define PS_MODE_DEF 0
190 DEVICE_PARAM(PSMode, "Power saving mode");
192 #define SHORT_RETRY_MIN 0
193 #define SHORT_RETRY_MAX 31
194 #define SHORT_RETRY_DEF 8
196 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
198 #define LONG_RETRY_MIN 0
199 #define LONG_RETRY_MAX 15
200 #define LONG_RETRY_DEF 4
202 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
204 /* BasebandType[] baseband type selected
205 0: indicate 802.11a type
206 1: indicate 802.11b type
207 2: indicate 802.11g type
209 #define BBP_TYPE_MIN 0
210 #define BBP_TYPE_MAX 2
211 #define BBP_TYPE_DEF 2
213 DEVICE_PARAM(BasebandType, "baseband type");
216 0: indicate disable 802.11h
217 1: indicate enable 802.11h
220 #define X80211h_MODE_DEF 0
222 DEVICE_PARAM(b80211hEnable, "802.11h mode");
225 0: indicate disable 802.11h
226 1: indicate enable 802.11h
229 #define DIVERSITY_ANT_DEF 0
231 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
234 // Static vars definitions
236 static CHIP_INFO chip_info_table[] = {
237 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
238 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
242 static const struct pci_device_id vt6655_pci_id_table[] = {
243 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
247 /*--------------------- Static Functions --------------------------*/
249 static int vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent);
250 static void vt6655_init_info(struct pci_dev *pcid,
251 struct vnt_private **ppDevice, PCHIP_INFO);
252 static void device_free_info(struct vnt_private *pDevice);
253 static bool device_get_pci_info(struct vnt_private *, struct pci_dev *pcid);
254 static void device_print_info(struct vnt_private *pDevice);
255 static void device_init_diversity_timer(struct vnt_private *pDevice);
256 static irqreturn_t device_intr(int irq, void *dev_instance);
259 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
260 static struct notifier_block device_notifier = {
261 .notifier_call = device_notify_reboot,
267 static void device_init_rd0_ring(struct vnt_private *pDevice);
268 static void device_init_rd1_ring(struct vnt_private *pDevice);
269 static void device_init_defrag_cb(struct vnt_private *pDevice);
270 static void device_init_td0_ring(struct vnt_private *pDevice);
271 static void device_init_td1_ring(struct vnt_private *pDevice);
273 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx);
274 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx);
275 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc);
276 static void device_init_registers(struct vnt_private *pDevice);
277 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc);
278 static void device_free_td0_ring(struct vnt_private *pDevice);
279 static void device_free_td1_ring(struct vnt_private *pDevice);
280 static void device_free_rd0_ring(struct vnt_private *pDevice);
281 static void device_free_rd1_ring(struct vnt_private *pDevice);
282 static void device_free_rings(struct vnt_private *pDevice);
283 static void device_free_frag_buf(struct vnt_private *pDevice);
285 /*--------------------- Export Variables --------------------------*/
287 /*--------------------- Export Functions --------------------------*/
289 static char *get_chip_name(int chip_id)
293 for (i = 0; chip_info_table[i].name != NULL; i++)
294 if (chip_info_table[i].chip_id == chip_id)
296 return chip_info_table[i].name;
299 static void vt6655_remove(struct pci_dev *pcid)
301 struct vnt_private *pDevice = pci_get_drvdata(pcid);
305 device_free_info(pDevice);
308 static void device_get_options(struct vnt_private *pDevice)
310 POPTIONS pOpts = &(pDevice->sOpts);
312 pOpts->nRxDescs0 = RX_DESC_DEF0;
313 pOpts->nRxDescs1 = RX_DESC_DEF1;
314 pOpts->nTxDescs[0] = TX_DESC_DEF0;
315 pOpts->nTxDescs[1] = TX_DESC_DEF1;
316 pOpts->flags |= DEVICE_FLAGS_IP_ALIGN;
317 pOpts->int_works = INT_WORKS_DEF;
318 pOpts->rts_thresh = RTS_THRESH_DEF;
319 pOpts->frag_thresh = FRAG_THRESH_DEF;
320 pOpts->data_rate = DATA_RATE_DEF;
321 pOpts->channel_num = CHANNEL_DEF;
323 pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE;
324 pOpts->flags |= DEVICE_FLAGS_OP_MODE;
325 pOpts->short_retry = SHORT_RETRY_DEF;
326 pOpts->long_retry = LONG_RETRY_DEF;
327 pOpts->bbp_type = BBP_TYPE_DEF;
328 pOpts->flags |= DEVICE_FLAGS_80211h_MODE;
329 pOpts->flags |= DEVICE_FLAGS_DiversityANT;
333 device_set_options(struct vnt_private *pDevice)
335 unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
336 unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
337 unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
339 ether_addr_copy(pDevice->abyBroadcastAddr, abyBroadcastAddr);
340 ether_addr_copy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042);
341 ether_addr_copy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel);
343 pDevice->uChannel = pDevice->sOpts.channel_num;
344 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
345 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
346 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
347 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
348 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
349 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
350 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
351 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
352 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
353 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
354 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
355 if (pDevice->uConnectionRate < RATE_AUTO)
356 pDevice->bFixRate = true;
357 pDevice->byBBType = pDevice->sOpts.bbp_type;
358 pDevice->byPacketType = (VIA_PKT_TYPE)pDevice->byBBType;
359 pDevice->byAutoFBCtrl = AUTO_FB_0;
360 pDevice->bUpdateBBVGA = true;
361 pDevice->byFOETuning = 0;
362 pDevice->byPreambleType = 0;
364 pr_debug(" uChannel= %d\n", (int)pDevice->uChannel);
365 pr_debug(" byOpMode= %d\n", (int)pDevice->byOpMode);
366 pr_debug(" ePSMode= %d\n", (int)pDevice->ePSMode);
367 pr_debug(" wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
368 pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
369 pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
370 pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType);
371 pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
372 pr_debug(" uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
373 pr_debug(" byBBType= %d\n", (int)pDevice->byBBType);
374 pr_debug(" pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
375 pr_debug(" pDevice->bDiversityRegCtlON= %d\n",
376 (int)pDevice->bDiversityRegCtlON);
380 // Initialisation of MAC & BBP registers
383 static void device_init_registers(struct vnt_private *pDevice)
387 unsigned char byValue;
388 unsigned char byValue1;
389 unsigned char byCCKPwrdBm = 0;
390 unsigned char byOFDMPwrdBm = 0;
392 MACbShutdown(pDevice->PortOffset);
393 BBvSoftwareReset(pDevice->PortOffset);
395 /* Do MACbSoftwareReset in MACvInitialize */
396 MACbSoftwareReset(pDevice->PortOffset);
398 pDevice->bAES = false;
400 /* Only used in 11g type, sync with ERP IE */
401 pDevice->bProtectMode = false;
403 pDevice->bNonERPPresent = false;
404 pDevice->bBarkerPreambleMd = false;
405 pDevice->wCurrentRate = RATE_1M;
406 pDevice->byTopOFDMBasicRate = RATE_24M;
407 pDevice->byTopCCKBasicRate = RATE_1M;
409 /* Target to IF pin while programming to RF chip. */
410 pDevice->byRevId = 0;
413 MACvInitialize(pDevice->PortOffset);
416 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
418 spin_lock_irqsave(&pDevice->lock, flags);
420 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
422 spin_unlock_irqrestore(&pDevice->lock, flags);
424 /* Get Channel range */
425 pDevice->byMinChannel = 1;
426 pDevice->byMaxChannel = CB_MAX_CHANNEL;
429 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
430 if (byValue & EEP_ANTINV)
431 pDevice->bTxRxAntInv = true;
433 pDevice->bTxRxAntInv = false;
435 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
436 /* if not set default is All */
438 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
440 pDevice->ulDiversityNValue = 100*260;
441 pDevice->ulDiversityMValue = 100*16;
443 pDevice->byTMax2 = 4;
444 pDevice->ulSQ3TH = 0;
445 pDevice->byTMax3 = 64;
447 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
448 pDevice->byAntennaCount = 2;
449 pDevice->byTxAntennaMode = ANT_B;
450 pDevice->dwTxAntennaSel = 1;
451 pDevice->dwRxAntennaSel = 1;
453 if (pDevice->bTxRxAntInv)
454 pDevice->byRxAntennaMode = ANT_A;
456 pDevice->byRxAntennaMode = ANT_B;
458 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset,
461 if ((byValue1 & 0x08) == 0)
462 pDevice->bDiversityEnable = false;
464 pDevice->bDiversityEnable = true;
466 pDevice->bDiversityEnable = false;
467 pDevice->byAntennaCount = 1;
468 pDevice->dwTxAntennaSel = 0;
469 pDevice->dwRxAntennaSel = 0;
471 if (byValue & EEP_ANTENNA_AUX) {
472 pDevice->byTxAntennaMode = ANT_A;
474 if (pDevice->bTxRxAntInv)
475 pDevice->byRxAntennaMode = ANT_B;
477 pDevice->byRxAntennaMode = ANT_A;
479 pDevice->byTxAntennaMode = ANT_B;
481 if (pDevice->bTxRxAntInv)
482 pDevice->byRxAntennaMode = ANT_A;
484 pDevice->byRxAntennaMode = ANT_B;
488 pr_debug("bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
489 pDevice->bDiversityEnable, (int)pDevice->ulDiversityNValue,
490 (int)pDevice->ulDiversityMValue, pDevice->byTMax,
493 /* zonetype initial */
494 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
497 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
499 /* force change RevID for VT3253 emu */
500 if ((pDevice->byRFType & RF_EMU) != 0)
501 pDevice->byRevId = 0x80;
503 pDevice->byRFType &= RF_MASK;
504 pr_debug("pDevice->byRFType = %x\n", pDevice->byRFType);
506 if (!pDevice->bZoneRegExist)
507 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
509 pr_debug("pDevice->byZoneType = %x\n", pDevice->byZoneType);
514 /* Get Desire Power Value */
515 pDevice->byCurPwr = 0xFF;
516 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
517 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
519 /* Load power Table */
520 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
521 pDevice->abyCCKPwrTbl[ii + 1] =
522 SROMbyReadEmbedded(pDevice->PortOffset,
523 (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
524 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
525 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
527 pDevice->abyOFDMPwrTbl[ii + 1] =
528 SROMbyReadEmbedded(pDevice->PortOffset,
529 (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
530 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
531 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
533 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
534 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
537 /* recover 12,13 ,14channel for EUROPE by 11 channel */
538 for (ii = 11; ii < 14; ii++) {
539 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
540 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
543 /* Load OFDM A Power Table */
544 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
545 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
546 SROMbyReadEmbedded(pDevice->PortOffset,
547 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
549 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
550 SROMbyReadEmbedded(pDevice->PortOffset,
551 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
554 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
555 MACvSelectPage1(pDevice->PortOffset);
557 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
558 (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
560 MACvSelectPage0(pDevice->PortOffset);
563 /* use relative tx timeout and 802.11i D4 */
564 MACvWordRegBitsOn(pDevice->PortOffset,
565 MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
567 /* set performance parameter by registry */
568 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
569 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
571 /* reset TSF counter */
572 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
573 /* enable TSF counter */
574 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
576 /* initialize BBP registers */
577 BBbVT3253Init(pDevice);
579 if (pDevice->bUpdateBBVGA) {
580 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
581 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
582 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
585 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
586 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
588 /* Set BB and packet type at the same time. */
589 /* Set Short Slot Time, xIFS, and RSPINF. */
590 if (pDevice->uConnectionRate == RATE_AUTO)
591 pDevice->wCurrentRate = RATE_54M;
593 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
595 pDevice->bRadioOff = false;
597 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
599 pDevice->bHWRadioOff = false;
601 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
603 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
605 if (((pDevice->byGPIO & GPIO0_DATA) &&
606 !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
607 (!(pDevice->byGPIO & GPIO0_DATA) &&
608 (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
609 pDevice->bHWRadioOff = true;
612 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
613 CARDbRadioPowerOff(pDevice);
615 /* get Permanent network address */
616 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
617 pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
619 /* reset Tx pointer */
620 CARDvSafeResetRx(pDevice);
621 /* reset Rx pointer */
622 CARDvSafeResetTx(pDevice);
624 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
625 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
628 MACvReceive0(pDevice->PortOffset);
629 MACvReceive1(pDevice->PortOffset);
631 /* start the adapter */
632 MACvStart(pDevice->PortOffset);
635 static void device_init_diversity_timer(struct vnt_private *pDevice)
637 init_timer(&pDevice->TimerSQ3Tmax1);
638 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
639 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
640 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
642 init_timer(&pDevice->TimerSQ3Tmax2);
643 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
644 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
645 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
647 init_timer(&pDevice->TimerSQ3Tmax3);
648 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
649 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
650 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
653 static void device_print_info(struct vnt_private *pDevice)
655 dev_info(&pDevice->pcid->dev, "%s\n", get_chip_name(pDevice->chip_id));
657 dev_info(&pDevice->pcid->dev, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
658 pDevice->abyCurrentNetAddr, (unsigned long)pDevice->ioaddr,
659 (unsigned long)pDevice->PortOffset, pDevice->pcid->irq);
662 static void vt6655_init_info(struct pci_dev *pcid,
663 struct vnt_private **ppDevice,
664 PCHIP_INFO pChip_info)
666 memset(*ppDevice, 0, sizeof(**ppDevice));
668 (*ppDevice)->pcid = pcid;
669 (*ppDevice)->chip_id = pChip_info->chip_id;
670 (*ppDevice)->io_size = pChip_info->io_size;
671 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
672 (*ppDevice)->multicast_limit = 32;
674 spin_lock_init(&((*ppDevice)->lock));
677 static bool device_get_pci_info(struct vnt_private *pDevice,
678 struct pci_dev *pcid)
682 unsigned int cis_addr;
684 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
685 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
686 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
687 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
689 pci_set_master(pcid);
691 pDevice->memaddr = pci_resource_start(pcid, 0);
692 pDevice->ioaddr = pci_resource_start(pcid, 1);
694 cis_addr = pci_resource_start(pcid, 2);
696 pDevice->pcid = pcid;
698 pci_read_config_byte(pcid, PCI_COMMAND, &b);
699 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
704 static void device_free_info(struct vnt_private *pDevice)
710 ieee80211_unregister_hw(pDevice->hw);
712 if (pDevice->PortOffset)
713 iounmap(pDevice->PortOffset);
716 pci_release_regions(pDevice->pcid);
719 ieee80211_free_hw(pDevice->hw);
722 static bool device_init_rings(struct vnt_private *pDevice)
726 /*allocate all RD/TD rings a single pool*/
727 vir_pool = pci_zalloc_consistent(pDevice->pcid,
728 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
729 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
730 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
731 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
733 if (vir_pool == NULL) {
734 dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n");
738 pDevice->aRD0Ring = vir_pool;
739 pDevice->aRD1Ring = vir_pool +
740 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
742 pDevice->rd0_pool_dma = pDevice->pool_dma;
743 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
744 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
746 pDevice->tx0_bufs = pci_zalloc_consistent(pDevice->pcid,
747 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
748 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
751 &pDevice->tx_bufs_dma0);
752 if (pDevice->tx0_bufs == NULL) {
753 dev_err(&pDevice->pcid->dev, "allocate buf dma memory failed\n");
755 pci_free_consistent(pDevice->pcid,
756 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
757 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
758 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
759 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
760 vir_pool, pDevice->pool_dma
765 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
766 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
768 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
769 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
771 // vir_pool: pvoid type
772 pDevice->apTD0Rings = vir_pool
773 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
774 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
776 pDevice->apTD1Rings = vir_pool
777 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
778 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
779 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
781 pDevice->tx1_bufs = pDevice->tx0_bufs +
782 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
784 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
785 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
787 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
790 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
791 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
793 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
794 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
799 static void device_free_rings(struct vnt_private *pDevice)
801 pci_free_consistent(pDevice->pcid,
802 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
803 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
804 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
805 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
807 pDevice->aRD0Ring, pDevice->pool_dma
810 if (pDevice->tx0_bufs)
811 pci_free_consistent(pDevice->pcid,
812 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
813 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
816 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
820 static void device_init_rd0_ring(struct vnt_private *pDevice)
823 dma_addr_t curr = pDevice->rd0_pool_dma;
826 /* Init the RD0 ring entries */
827 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
828 pDesc = &(pDevice->aRD0Ring[i]);
829 pDesc->pRDInfo = alloc_rd_info();
830 ASSERT(pDesc->pRDInfo);
831 if (!device_alloc_rx_buf(pDevice, pDesc))
832 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
834 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
835 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
836 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
840 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
841 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
844 static void device_init_rd1_ring(struct vnt_private *pDevice)
847 dma_addr_t curr = pDevice->rd1_pool_dma;
850 /* Init the RD1 ring entries */
851 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
852 pDesc = &(pDevice->aRD1Ring[i]);
853 pDesc->pRDInfo = alloc_rd_info();
854 ASSERT(pDesc->pRDInfo);
855 if (!device_alloc_rx_buf(pDevice, pDesc))
856 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
858 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
859 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
860 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
864 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
865 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
868 static void device_init_defrag_cb(struct vnt_private *pDevice)
871 PSDeFragControlBlock pDeF;
873 /* Init the fragment ctl entries */
874 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
875 pDeF = &(pDevice->sRxDFCB[i]);
876 if (!device_alloc_frag_buf(pDevice, pDeF))
877 dev_err(&pDevice->pcid->dev, "can not alloc frag bufs\n");
879 pDevice->cbDFCB = CB_MAX_RX_FRAG;
880 pDevice->cbFreeDFCB = pDevice->cbDFCB;
883 static void device_free_rd0_ring(struct vnt_private *pDevice)
887 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
888 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
889 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
891 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
892 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
894 dev_kfree_skb(pRDInfo->skb);
896 kfree(pDesc->pRDInfo);
900 static void device_free_rd1_ring(struct vnt_private *pDevice)
904 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
905 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
906 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
908 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
909 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
911 dev_kfree_skb(pRDInfo->skb);
913 kfree(pDesc->pRDInfo);
917 static void device_free_frag_buf(struct vnt_private *pDevice)
919 PSDeFragControlBlock pDeF;
922 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
923 pDeF = &(pDevice->sRxDFCB[i]);
926 dev_kfree_skb(pDeF->skb);
931 static void device_init_td0_ring(struct vnt_private *pDevice)
937 curr = pDevice->td0_pool_dma;
938 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
939 pDesc = &(pDevice->apTD0Rings[i]);
940 pDesc->pTDInfo = alloc_td_info();
941 ASSERT(pDesc->pTDInfo);
942 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
943 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
944 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
946 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
947 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
948 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
952 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
953 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
956 static void device_init_td1_ring(struct vnt_private *pDevice)
962 /* Init the TD ring entries */
963 curr = pDevice->td1_pool_dma;
964 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
965 pDesc = &(pDevice->apTD1Rings[i]);
966 pDesc->pTDInfo = alloc_td_info();
967 ASSERT(pDesc->pTDInfo);
968 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
969 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
970 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
972 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
973 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
974 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
978 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
979 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
982 static void device_free_td0_ring(struct vnt_private *pDevice)
986 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
987 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
988 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
990 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
991 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
992 pTDInfo->skb->len, PCI_DMA_TODEVICE);
995 dev_kfree_skb(pTDInfo->skb);
997 kfree(pDesc->pTDInfo);
1001 static void device_free_td1_ring(struct vnt_private *pDevice)
1005 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1006 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
1007 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1009 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1010 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1011 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1014 dev_kfree_skb(pTDInfo->skb);
1016 kfree(pDesc->pTDInfo);
1020 /*-----------------------------------------------------------------*/
1022 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1027 for (pRD = pDevice->pCurrRD[uIdx];
1028 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1032 if (vnt_receive_frame(pDevice, pRD)) {
1033 if (!device_alloc_rx_buf(pDevice, pRD)) {
1034 dev_err(&pDevice->pcid->dev,
1035 "can not allocate rx buf\n");
1039 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1042 pDevice->pCurrRD[uIdx] = pRD;
1047 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
1049 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1051 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1052 if (pRDInfo->skb == NULL)
1054 ASSERT(pRDInfo->skb);
1057 pci_map_single(pDevice->pcid,
1058 skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)),
1059 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1061 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1063 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1064 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1065 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1066 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1071 bool device_alloc_frag_buf(struct vnt_private *pDevice,
1072 PSDeFragControlBlock pDeF)
1074 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1075 if (pDeF->skb == NULL)
1082 static const u8 fallback_rate0[5][5] = {
1083 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
1084 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
1085 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
1086 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
1087 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
1090 static const u8 fallback_rate1[5][5] = {
1091 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
1092 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
1093 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
1094 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
1095 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
1098 static int vnt_int_report_rate(struct vnt_private *priv,
1099 PDEVICE_TD_INFO context, u8 tsr0, u8 tsr1)
1101 struct vnt_tx_fifo_head *fifo_head;
1102 struct ieee80211_tx_info *info;
1103 struct ieee80211_rate *rate;
1105 u8 tx_retry = (tsr0 & TSR0_NCR);
1114 fifo_head = (struct vnt_tx_fifo_head *)context->buf;
1115 fb_option = (le16_to_cpu(fifo_head->fifo_ctl) &
1116 (FIFOCTL_AUTO_FB_0 | FIFOCTL_AUTO_FB_1));
1118 info = IEEE80211_SKB_CB(context->skb);
1119 idx = info->control.rates[0].idx;
1121 if (fb_option && !(tsr1 & TSR1_TERR)) {
1123 u8 retry = tx_retry;
1125 rate = ieee80211_get_tx_rate(priv->hw, info);
1126 tx_rate = rate->hw_value - RATE_18M;
1131 if (fb_option & FIFOCTL_AUTO_FB_0)
1132 tx_rate = fallback_rate0[tx_rate][retry];
1133 else if (fb_option & FIFOCTL_AUTO_FB_1)
1134 tx_rate = fallback_rate1[tx_rate][retry];
1136 if (info->band == IEEE80211_BAND_5GHZ)
1137 idx = tx_rate - RATE_6M;
1142 ieee80211_tx_info_clear_status(info);
1144 info->status.rates[0].count = tx_retry;
1146 if (!(tsr1 & TSR1_TERR)) {
1147 info->status.rates[0].idx = idx;
1148 info->flags |= IEEE80211_TX_STAT_ACK;
1154 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1158 unsigned char byTsr0;
1159 unsigned char byTsr1;
1161 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1162 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1167 byTsr0 = pTD->m_td0TD0.byTSR0;
1168 byTsr1 = pTD->m_td0TD0.byTSR1;
1170 //Only the status of first TD in the chain is correct
1171 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1172 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1174 vnt_int_report_rate(pDevice, pTD->pTDInfo, byTsr0, byTsr1);
1176 if (!(byTsr1 & TSR1_TERR)) {
1178 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
1183 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
1184 (int)uIdx, byTsr1, byTsr0);
1188 if (byTsr1 & TSR1_TERR) {
1189 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1190 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
1191 (int)uIdx, byTsr1, byTsr0);
1194 device_free_tx_buf(pDevice, pTD);
1195 pDevice->iTDUsed[uIdx]--;
1197 /* Make sure queue is available */
1198 if (AVAIL_TD(pDevice, uIdx))
1199 ieee80211_wake_queues(pDevice->hw);
1203 pDevice->apTailTD[uIdx] = pTD;
1208 static void device_error(struct vnt_private *pDevice, unsigned short status)
1210 if (status & ISR_FETALERR) {
1211 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
1213 MACbShutdown(pDevice->PortOffset);
1218 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
1220 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1221 struct sk_buff *skb = pTDInfo->skb;
1223 // pre-allocated buf_dma can't be unmapped.
1224 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1225 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1229 if (pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)
1230 ieee80211_tx_status_irqsafe(pDevice->hw, skb);
1232 dev_kfree_skb_irq(skb);
1234 pTDInfo->skb_dma = 0;
1235 pTDInfo->skb = NULL;
1236 pTDInfo->byFlags = 0;
1239 static irqreturn_t device_intr(int irq, void *dev_instance)
1241 struct vnt_private *pDevice = dev_instance;
1243 unsigned long dwMIBCounter = 0;
1244 unsigned char byOrgPageSel = 0;
1247 unsigned long flags;
1249 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
1251 if (pDevice->dwIsr == 0)
1252 return IRQ_RETVAL(handled);
1254 if (pDevice->dwIsr == 0xffffffff) {
1255 pr_debug("dwIsr = 0xffff\n");
1256 return IRQ_RETVAL(handled);
1260 MACvIntDisable(pDevice->PortOffset);
1262 spin_lock_irqsave(&pDevice->lock, flags);
1264 //Make sure current page is 0
1265 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
1266 if (byOrgPageSel == 1)
1267 MACvSelectPage0(pDevice->PortOffset);
1271 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
1273 // Must do this after doing rx/tx, cause ISR bit is slow
1274 // than RD/TD write back
1275 // update ISR counter
1276 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
1277 while (pDevice->dwIsr != 0) {
1278 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
1279 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
1281 if (pDevice->dwIsr & ISR_FETALERR) {
1282 pr_debug(" ISR_FETALERR\n");
1283 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
1284 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
1285 device_error(pDevice, pDevice->dwIsr);
1288 if (pDevice->dwIsr & ISR_TBTT) {
1290 pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
1291 if (pDevice->bUpdateBBVGA &&
1292 !(pDevice->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
1293 pDevice->vif->bss_conf.assoc &&
1294 pDevice->uCurrRSSI) {
1297 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
1298 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
1299 if (ldBm < pDevice->ldBmThreshold[ii]) {
1300 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1304 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1305 pDevice->uBBVGADiffCount++;
1306 if (pDevice->uBBVGADiffCount == 1) {
1307 // first VGA diff gain
1308 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
1309 pr_debug("First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1311 pDevice->byBBVGANew,
1312 pDevice->byBBVGACurrent,
1313 (int)pDevice->uBBVGADiffCount);
1315 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
1316 pr_debug("RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1318 pDevice->byBBVGANew,
1319 pDevice->byBBVGACurrent,
1320 (int)pDevice->uBBVGADiffCount);
1321 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
1324 pDevice->uBBVGADiffCount = 1;
1329 pDevice->bBeaconSent = false;
1330 if (pDevice->bEnablePSMode)
1331 PSbIsNextTBTTWakeUp((void *)pDevice);
1333 if ((pDevice->op_mode == NL80211_IFTYPE_AP ||
1334 pDevice->op_mode == NL80211_IFTYPE_ADHOC) &&
1335 pDevice->vif->bss_conf.enable_beacon) {
1336 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
1337 (pDevice->vif->bss_conf.beacon_int - MAKE_BEACON_RESERVED) << 10);
1340 /* TODO: adhoc PS mode */
1344 if (pDevice->dwIsr & ISR_BNTX) {
1345 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
1346 pDevice->bIsBeaconBufReadySet = false;
1347 pDevice->cbBeaconBufReadySetCnt = 0;
1350 pDevice->bBeaconSent = true;
1353 if (pDevice->dwIsr & ISR_RXDMA0)
1354 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
1356 if (pDevice->dwIsr & ISR_RXDMA1)
1357 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
1359 if (pDevice->dwIsr & ISR_TXDMA0)
1360 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
1362 if (pDevice->dwIsr & ISR_AC0DMA)
1363 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
1365 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
1367 if (pDevice->vif->bss_conf.enable_beacon)
1368 vnt_beacon_make(pDevice, pDevice->vif);
1372 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
1374 MACvReceive0(pDevice->PortOffset);
1375 MACvReceive1(pDevice->PortOffset);
1377 if (max_count > pDevice->sOpts.int_works)
1381 if (byOrgPageSel == 1)
1382 MACvSelectPage1(pDevice->PortOffset);
1384 spin_unlock_irqrestore(&pDevice->lock, flags);
1386 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1388 return IRQ_RETVAL(handled);
1391 static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1393 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1395 u32 dma_idx = TYPE_AC0DMA;
1396 unsigned long flags;
1398 spin_lock_irqsave(&priv->lock, flags);
1400 if (!ieee80211_is_data(hdr->frame_control))
1401 dma_idx = TYPE_TXDMA0;
1403 if (AVAIL_TD(priv, dma_idx) < 1) {
1404 spin_unlock_irqrestore(&priv->lock, flags);
1408 head_td = priv->apCurrTD[dma_idx];
1410 head_td->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1412 head_td->pTDInfo->skb = skb;
1414 priv->iTDUsed[dma_idx]++;
1416 /* Take ownership */
1418 head_td->m_td0TD0.f1Owner = OWNED_BY_NIC;
1422 priv->apCurrTD[dma_idx] = head_td->next;
1424 spin_unlock_irqrestore(&priv->lock, flags);
1426 vnt_generate_fifo_header(priv, dma_idx, head_td, skb);
1428 if (MACbIsRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
1429 MACbPSWakeup(priv->PortOffset);
1431 spin_lock_irqsave(&priv->lock, flags);
1433 priv->bPWBitOn = false;
1435 head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB;
1437 if (dma_idx == TYPE_AC0DMA)
1438 MACvTransmitAC0(priv->PortOffset);
1440 MACvTransmit0(priv->PortOffset);
1442 spin_unlock_irqrestore(&priv->lock, flags);
1447 static void vnt_tx_80211(struct ieee80211_hw *hw,
1448 struct ieee80211_tx_control *control,
1449 struct sk_buff *skb)
1451 struct vnt_private *priv = hw->priv;
1453 ieee80211_stop_queues(hw);
1455 if (vnt_tx_packet(priv, skb)) {
1456 ieee80211_free_txskb(hw, skb);
1458 ieee80211_wake_queues(hw);
1462 static int vnt_start(struct ieee80211_hw *hw)
1464 struct vnt_private *priv = hw->priv;
1467 priv->rx_buf_sz = PKT_BUF_SZ;
1468 if (!device_init_rings(priv))
1471 ret = request_irq(priv->pcid->irq, &device_intr,
1472 IRQF_SHARED, "vt6655", priv);
1474 dev_dbg(&priv->pcid->dev, "failed to start irq\n");
1478 dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
1479 device_init_rd0_ring(priv);
1480 device_init_rd1_ring(priv);
1481 device_init_defrag_cb(priv);
1482 device_init_td0_ring(priv);
1483 device_init_td1_ring(priv);
1485 device_init_registers(priv);
1487 dev_dbg(&priv->pcid->dev, "call MACvIntEnable\n");
1488 MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
1490 ieee80211_wake_queues(hw);
1495 static void vnt_stop(struct ieee80211_hw *hw)
1497 struct vnt_private *priv = hw->priv;
1499 ieee80211_stop_queues(hw);
1501 MACbShutdown(priv->PortOffset);
1502 MACbSoftwareReset(priv->PortOffset);
1503 CARDbRadioPowerOff(priv);
1505 device_free_td0_ring(priv);
1506 device_free_td1_ring(priv);
1507 device_free_rd0_ring(priv);
1508 device_free_rd1_ring(priv);
1509 device_free_frag_buf(priv);
1510 device_free_rings(priv);
1512 free_irq(priv->pcid->irq, priv);
1515 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1517 struct vnt_private *priv = hw->priv;
1521 switch (vif->type) {
1522 case NL80211_IFTYPE_STATION:
1523 if (priv->bDiversityRegCtlON)
1524 device_init_diversity_timer(priv);
1526 case NL80211_IFTYPE_ADHOC:
1527 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1529 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1532 case NL80211_IFTYPE_AP:
1533 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1535 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1542 priv->op_mode = vif->type;
1547 static void vnt_remove_interface(struct ieee80211_hw *hw,
1548 struct ieee80211_vif *vif)
1550 struct vnt_private *priv = hw->priv;
1552 switch (vif->type) {
1553 case NL80211_IFTYPE_STATION:
1554 if (priv->bDiversityRegCtlON) {
1555 del_timer(&priv->TimerSQ3Tmax1);
1556 del_timer(&priv->TimerSQ3Tmax2);
1557 del_timer(&priv->TimerSQ3Tmax3);
1560 case NL80211_IFTYPE_ADHOC:
1561 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1562 MACvRegBitsOff(priv->PortOffset,
1563 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1564 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1566 case NL80211_IFTYPE_AP:
1567 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1568 MACvRegBitsOff(priv->PortOffset,
1569 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1570 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1576 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
1580 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
1582 struct vnt_private *priv = hw->priv;
1583 struct ieee80211_conf *conf = &hw->conf;
1586 if (changed & IEEE80211_CONF_CHANGE_PS) {
1587 if (conf->flags & IEEE80211_CONF_PS)
1588 PSvEnablePowerSaving(priv, conf->listen_interval);
1590 PSvDisablePowerSaving(priv);
1593 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
1594 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
1595 set_channel(priv, conf->chandef.chan->hw_value);
1597 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
1598 bb_type = BB_TYPE_11A;
1600 bb_type = BB_TYPE_11G;
1602 if (priv->byBBType != bb_type) {
1603 priv->byBBType = bb_type;
1605 CARDbSetPhyParameter(priv,
1606 priv->byBBType, 0, 0, NULL, NULL);
1610 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1611 if (priv->byBBType == BB_TYPE_11B)
1612 priv->wCurrentRate = RATE_1M;
1614 priv->wCurrentRate = RATE_54M;
1616 RFbSetPower(priv, priv->wCurrentRate,
1617 conf->chandef.chan->hw_value);
1623 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
1624 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
1627 struct vnt_private *priv = hw->priv;
1629 priv->current_aid = conf->aid;
1631 if (changed & BSS_CHANGED_BSSID)
1632 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid);
1634 if (changed & BSS_CHANGED_BASIC_RATES) {
1635 priv->basic_rates = conf->basic_rates;
1637 CARDvUpdateBasicTopRate(priv);
1639 dev_dbg(&priv->pcid->dev,
1640 "basic rates %x\n", conf->basic_rates);
1643 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1644 if (conf->use_short_preamble) {
1645 MACvEnableBarkerPreambleMd(priv->PortOffset);
1646 priv->byPreambleType = true;
1648 MACvDisableBarkerPreambleMd(priv->PortOffset);
1649 priv->byPreambleType = false;
1653 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1654 if (conf->use_cts_prot)
1655 MACvEnableProtectMD(priv->PortOffset);
1657 MACvDisableProtectMD(priv->PortOffset);
1660 if (changed & BSS_CHANGED_ERP_SLOT) {
1661 if (conf->use_short_slot)
1662 priv->bShortSlotTime = true;
1664 priv->bShortSlotTime = false;
1667 CARDbSetPhyParameter(priv, priv->byBBType, 0, 0, NULL, NULL);
1668 BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
1671 if (changed & BSS_CHANGED_TXPOWER)
1672 RFbSetPower(priv, priv->wCurrentRate,
1673 conf->chandef.chan->hw_value);
1675 if (changed & BSS_CHANGED_BEACON_ENABLED) {
1676 dev_dbg(&priv->pcid->dev,
1677 "Beacon enable %d\n", conf->enable_beacon);
1679 if (conf->enable_beacon) {
1680 vnt_beacon_enable(priv, vif, conf);
1682 MACvRegBitsOn(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1684 MACvRegBitsOff(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1688 if (changed & BSS_CHANGED_ASSOC && priv->op_mode != NL80211_IFTYPE_AP) {
1690 CARDbUpdateTSF(priv, conf->beacon_rate->hw_value,
1691 conf->sync_device_ts, conf->sync_tsf);
1693 CARDbSetBeaconPeriod(priv, conf->beacon_int);
1695 CARDvSetFirstNextTBTT(priv->PortOffset,
1698 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1700 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1706 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
1707 struct netdev_hw_addr_list *mc_list)
1709 struct vnt_private *priv = hw->priv;
1710 struct netdev_hw_addr *ha;
1714 netdev_hw_addr_list_for_each(ha, mc_list) {
1715 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1717 mc_filter |= 1ULL << (bit_nr & 0x3f);
1720 priv->mc_list_count = mc_list->count;
1725 static void vnt_configure(struct ieee80211_hw *hw,
1726 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
1728 struct vnt_private *priv = hw->priv;
1731 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_PROMISC_IN_BSS |
1732 FIF_BCN_PRBRESP_PROMISC;
1734 VNSvInPortB(priv->PortOffset + MAC_REG_RCR, &rx_mode);
1736 dev_dbg(&priv->pcid->dev, "rx mode in = %x\n", rx_mode);
1738 if (changed_flags & FIF_PROMISC_IN_BSS) {
1739 /* unconditionally log net taps */
1740 if (*total_flags & FIF_PROMISC_IN_BSS)
1741 rx_mode |= RCR_UNICAST;
1743 rx_mode &= ~RCR_UNICAST;
1746 if (changed_flags & FIF_ALLMULTI) {
1747 if (*total_flags & FIF_ALLMULTI) {
1748 if (priv->mc_list_count > 2) {
1749 MACvSelectPage1(priv->PortOffset);
1751 VNSvOutPortD(priv->PortOffset +
1752 MAC_REG_MAR0, 0xffffffff);
1753 VNSvOutPortD(priv->PortOffset +
1754 MAC_REG_MAR0 + 4, 0xffffffff);
1756 MACvSelectPage0(priv->PortOffset);
1758 MACvSelectPage1(priv->PortOffset);
1760 VNSvOutPortD(priv->PortOffset +
1761 MAC_REG_MAR0, (u32)multicast);
1762 VNSvOutPortD(priv->PortOffset +
1764 (u32)(multicast >> 32));
1766 MACvSelectPage0(priv->PortOffset);
1769 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1771 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
1775 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
1776 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1778 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
1779 rx_mode &= ~RCR_BSSID;
1781 rx_mode |= RCR_BSSID;
1784 VNSvOutPortB(priv->PortOffset + MAC_REG_RCR, rx_mode);
1786 dev_dbg(&priv->pcid->dev, "rx mode out= %x\n", rx_mode);
1789 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1790 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1791 struct ieee80211_key_conf *key)
1793 struct vnt_private *priv = hw->priv;
1797 if (vnt_set_keys(hw, sta, vif, key))
1801 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
1802 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
1810 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1812 struct vnt_private *priv = hw->priv;
1815 CARDbGetCurrentTSF(priv->PortOffset, &tsf);
1820 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1823 struct vnt_private *priv = hw->priv;
1825 CARDvUpdateNextTBTT(priv->PortOffset, tsf, vif->bss_conf.beacon_int);
1828 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1830 struct vnt_private *priv = hw->priv;
1832 /* reset TSF counter */
1833 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1836 static const struct ieee80211_ops vnt_mac_ops = {
1840 .add_interface = vnt_add_interface,
1841 .remove_interface = vnt_remove_interface,
1842 .config = vnt_config,
1843 .bss_info_changed = vnt_bss_info_changed,
1844 .prepare_multicast = vnt_prepare_multicast,
1845 .configure_filter = vnt_configure,
1846 .set_key = vnt_set_key,
1847 .get_tsf = vnt_get_tsf,
1848 .set_tsf = vnt_set_tsf,
1849 .reset_tsf = vnt_reset_tsf,
1852 int vnt_init(struct vnt_private *priv)
1854 SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyCurrentNetAddr);
1856 vnt_init_bands(priv);
1858 if (ieee80211_register_hw(priv->hw))
1861 priv->mac_hw = true;
1863 CARDbRadioPowerOff(priv);
1869 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
1871 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
1872 struct vnt_private *priv;
1873 struct ieee80211_hw *hw;
1874 struct wiphy *wiphy;
1877 dev_notice(&pcid->dev,
1878 "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1880 dev_notice(&pcid->dev,
1881 "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
1883 hw = ieee80211_alloc_hw(sizeof(*priv), &vnt_mac_ops);
1885 dev_err(&pcid->dev, "could not register ieee80211_hw\n");
1891 vt6655_init_info(pcid, &priv, pChip_info);
1895 SET_IEEE80211_DEV(priv->hw, &pcid->dev);
1897 if (pci_enable_device(pcid)) {
1898 device_free_info(priv);
1903 "Before get pci_info memaddr is %x\n", priv->memaddr);
1905 if (!device_get_pci_info(priv, pcid)) {
1906 dev_err(&pcid->dev, ": Failed to find PCI device.\n");
1907 device_free_info(priv);
1913 "after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",
1914 priv->memaddr, priv->ioaddr, priv->io_size);
1926 for (i = 0; address[i]; i++) {
1927 pci_read_config_dword(pcid, address[i], &bar);
1929 dev_dbg(&pcid->dev, "bar %d is %x\n", i, bar);
1933 "bar %d not implemented\n", i);
1937 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
1940 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xffff);
1941 len = len & ~(len - 1);
1944 "IO space: len in IO %x, BAR %d\n",
1947 len = bar & 0xfffffff0;
1951 "len in MEM %x, BAR %d\n", len, i);
1957 priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK,
1959 if (!priv->PortOffset) {
1960 dev_err(&pcid->dev, ": Failed to IO remapping ..\n");
1961 device_free_info(priv);
1965 rc = pci_request_regions(pcid, DEVICE_NAME);
1967 dev_err(&pcid->dev, ": Failed to find PCI device\n");
1968 device_free_info(priv);
1973 if (!MACbSoftwareReset(priv->PortOffset)) {
1974 dev_err(&pcid->dev, ": Failed to access MAC hardware..\n");
1975 device_free_info(priv);
1978 /* initial to reload eeprom */
1979 MACvInitialize(priv->PortOffset);
1980 MACvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr);
1982 device_get_options(priv);
1983 device_set_options(priv);
1984 /* Mask out the options cannot be set to the chip */
1985 priv->sOpts.flags &= pChip_info->flags;
1987 /* Enable the chip specified capabilities */
1988 priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL);
1990 wiphy = priv->hw->wiphy;
1992 wiphy->frag_threshold = FRAG_THRESH_DEF;
1993 wiphy->rts_threshold = RTS_THRESH_DEF;
1994 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1995 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1997 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1998 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
1999 IEEE80211_HW_SIGNAL_DBM |
2000 IEEE80211_HW_TIMING_BEACON_ONLY;
2002 priv->hw->max_signal = 100;
2007 device_print_info(priv);
2008 pci_set_drvdata(pcid, priv);
2013 /*------------------------------------------------------------------*/
2016 static int vt6655_suspend(struct pci_dev *pcid, pm_message_t state)
2018 struct vnt_private *priv = pci_get_drvdata(pcid);
2019 unsigned long flags;
2021 spin_lock_irqsave(&priv->lock, flags);
2023 pci_save_state(pcid);
2025 MACbShutdown(priv->PortOffset);
2027 pci_disable_device(pcid);
2028 pci_set_power_state(pcid, pci_choose_state(pcid, state));
2030 spin_unlock_irqrestore(&priv->lock, flags);
2035 static int vt6655_resume(struct pci_dev *pcid)
2038 pci_set_power_state(pcid, PCI_D0);
2039 pci_enable_wake(pcid, PCI_D0, 0);
2040 pci_restore_state(pcid);
2046 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
2048 static struct pci_driver device_driver = {
2049 .name = DEVICE_NAME,
2050 .id_table = vt6655_pci_id_table,
2051 .probe = vt6655_probe,
2052 .remove = vt6655_remove,
2054 .suspend = vt6655_suspend,
2055 .resume = vt6655_resume,
2059 static int __init vt6655_init_module(void)
2063 ret = pci_register_driver(&device_driver);
2066 register_reboot_notifier(&device_notifier);
2072 static void __exit vt6655_cleanup_module(void)
2075 unregister_reboot_notifier(&device_notifier);
2077 pci_unregister_driver(&device_driver);
2080 module_init(vt6655_init_module);
2081 module_exit(vt6655_cleanup_module);
2085 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
2087 struct pci_dev *pdev = NULL;
2093 for_each_pci_dev(pdev) {
2094 if (pci_dev_driver(pdev) == &device_driver) {
2095 if (pci_get_drvdata(pdev))
2096 vt6655_suspend(pdev, PMSG_HIBERNATE);