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>
74 #include <linux/delay.h>
75 #include <linux/kthread.h>
76 #include <linux/slab.h>
78 /*--------------------- Static Definitions -------------------------*/
80 // Define module options
82 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
83 MODULE_LICENSE("GPL");
84 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
86 #define DEVICE_PARAM(N, D)
88 #define RX_DESC_MIN0 16
89 #define RX_DESC_MAX0 128
90 #define RX_DESC_DEF0 32
91 DEVICE_PARAM(RxDescriptors0, "Number of receive descriptors0");
93 #define RX_DESC_MIN1 16
94 #define RX_DESC_MAX1 128
95 #define RX_DESC_DEF1 32
96 DEVICE_PARAM(RxDescriptors1, "Number of receive descriptors1");
98 #define TX_DESC_MIN0 16
99 #define TX_DESC_MAX0 128
100 #define TX_DESC_DEF0 32
101 DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
103 #define TX_DESC_MIN1 16
104 #define TX_DESC_MAX1 128
105 #define TX_DESC_DEF1 64
106 DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
108 #define IP_ALIG_DEF 0
109 /* IP_byte_align[] is used for IP header unsigned long byte aligned
110 0: indicate the IP header won't be unsigned long byte aligned.(Default) .
111 1: indicate the IP header will be unsigned long byte aligned.
112 In some environment, the IP header should be unsigned long byte aligned,
113 or the packet will be droped when we receive it. (eg: IPVS)
115 DEVICE_PARAM(IP_byte_align, "Enable IP header dword aligned");
117 #define INT_WORKS_DEF 20
118 #define INT_WORKS_MIN 10
119 #define INT_WORKS_MAX 64
121 DEVICE_PARAM(int_works, "Number of packets per interrupt services");
123 #define CHANNEL_MIN 1
124 #define CHANNEL_MAX 14
125 #define CHANNEL_DEF 6
127 DEVICE_PARAM(Channel, "Channel number");
129 /* PreambleType[] is the preamble length used for transmit.
130 0: indicate allows long preamble type
131 1: indicate allows short preamble type
134 #define PREAMBLE_TYPE_DEF 1
136 DEVICE_PARAM(PreambleType, "Preamble Type");
138 #define RTS_THRESH_MIN 512
139 #define RTS_THRESH_MAX 2347
140 #define RTS_THRESH_DEF 2347
142 DEVICE_PARAM(RTSThreshold, "RTS threshold");
144 #define FRAG_THRESH_MIN 256
145 #define FRAG_THRESH_MAX 2346
146 #define FRAG_THRESH_DEF 2346
148 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
150 #define DATA_RATE_MIN 0
151 #define DATA_RATE_MAX 13
152 #define DATA_RATE_DEF 13
154 0: indicate 1 Mbps 0x02
155 1: indicate 2 Mbps 0x04
156 2: indicate 5.5 Mbps 0x0B
157 3: indicate 11 Mbps 0x16
158 4: indicate 6 Mbps 0x0c
159 5: indicate 9 Mbps 0x12
160 6: indicate 12 Mbps 0x18
161 7: indicate 18 Mbps 0x24
162 8: indicate 24 Mbps 0x30
163 9: indicate 36 Mbps 0x48
164 10: indicate 48 Mbps 0x60
165 11: indicate 54 Mbps 0x6c
166 12: indicate 72 Mbps 0x90
167 13: indicate auto rate
170 DEVICE_PARAM(ConnectionRate, "Connection data rate");
172 #define OP_MODE_DEF 0
174 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
176 /* OpMode[] is used for transmit.
177 0: indicate infrastruct mode used
178 1: indicate adhoc mode used
179 2: indicate AP mode used
183 0: indicate disable power saving mode
184 1: indicate enable power saving mode
187 #define PS_MODE_DEF 0
189 DEVICE_PARAM(PSMode, "Power saving mode");
191 #define SHORT_RETRY_MIN 0
192 #define SHORT_RETRY_MAX 31
193 #define SHORT_RETRY_DEF 8
195 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
197 #define LONG_RETRY_MIN 0
198 #define LONG_RETRY_MAX 15
199 #define LONG_RETRY_DEF 4
201 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
203 /* BasebandType[] baseband type selected
204 0: indicate 802.11a type
205 1: indicate 802.11b type
206 2: indicate 802.11g type
208 #define BBP_TYPE_MIN 0
209 #define BBP_TYPE_MAX 2
210 #define BBP_TYPE_DEF 2
212 DEVICE_PARAM(BasebandType, "baseband type");
215 0: indicate disable 802.11h
216 1: indicate enable 802.11h
219 #define X80211h_MODE_DEF 0
221 DEVICE_PARAM(b80211hEnable, "802.11h mode");
224 0: indicate disable 802.11h
225 1: indicate enable 802.11h
228 #define DIVERSITY_ANT_DEF 0
230 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
233 // Static vars definitions
235 static CHIP_INFO chip_info_table[] = {
236 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
237 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
241 static const struct pci_device_id vt6655_pci_id_table[] = {
242 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
246 /*--------------------- Static Functions --------------------------*/
248 static int vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent);
249 static void vt6655_init_info(struct pci_dev *pcid,
250 struct vnt_private **ppDevice, PCHIP_INFO);
251 static void device_free_info(struct vnt_private *pDevice);
252 static bool device_get_pci_info(struct vnt_private *, struct pci_dev *pcid);
253 static void device_print_info(struct vnt_private *pDevice);
254 static void device_init_diversity_timer(struct vnt_private *pDevice);
255 static irqreturn_t device_intr(int irq, void *dev_instance);
258 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
259 static struct notifier_block device_notifier = {
260 .notifier_call = device_notify_reboot,
266 static void device_init_rd0_ring(struct vnt_private *pDevice);
267 static void device_init_rd1_ring(struct vnt_private *pDevice);
268 static void device_init_defrag_cb(struct vnt_private *pDevice);
269 static void device_init_td0_ring(struct vnt_private *pDevice);
270 static void device_init_td1_ring(struct vnt_private *pDevice);
272 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx);
273 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx);
274 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc);
275 static void device_init_registers(struct vnt_private *pDevice);
276 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc);
277 static void device_free_td0_ring(struct vnt_private *pDevice);
278 static void device_free_td1_ring(struct vnt_private *pDevice);
279 static void device_free_rd0_ring(struct vnt_private *pDevice);
280 static void device_free_rd1_ring(struct vnt_private *pDevice);
281 static void device_free_rings(struct vnt_private *pDevice);
282 static void device_free_frag_buf(struct vnt_private *pDevice);
284 /*--------------------- Export Variables --------------------------*/
286 /*--------------------- Export Functions --------------------------*/
288 static char *get_chip_name(int chip_id)
292 for (i = 0; chip_info_table[i].name != NULL; i++)
293 if (chip_info_table[i].chip_id == chip_id)
295 return chip_info_table[i].name;
298 static void vt6655_remove(struct pci_dev *pcid)
300 struct vnt_private *pDevice = pci_get_drvdata(pcid);
304 device_free_info(pDevice);
307 static void device_get_options(struct vnt_private *pDevice)
309 POPTIONS pOpts = &(pDevice->sOpts);
311 pOpts->nRxDescs0 = RX_DESC_DEF0;
312 pOpts->nRxDescs1 = RX_DESC_DEF1;
313 pOpts->nTxDescs[0] = TX_DESC_DEF0;
314 pOpts->nTxDescs[1] = TX_DESC_DEF1;
315 pOpts->flags |= DEVICE_FLAGS_IP_ALIGN;
316 pOpts->int_works = INT_WORKS_DEF;
317 pOpts->rts_thresh = RTS_THRESH_DEF;
318 pOpts->frag_thresh = FRAG_THRESH_DEF;
319 pOpts->data_rate = DATA_RATE_DEF;
320 pOpts->channel_num = CHANNEL_DEF;
322 pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE;
323 pOpts->flags |= DEVICE_FLAGS_OP_MODE;
324 pOpts->short_retry = SHORT_RETRY_DEF;
325 pOpts->long_retry = LONG_RETRY_DEF;
326 pOpts->bbp_type = BBP_TYPE_DEF;
327 pOpts->flags |= DEVICE_FLAGS_80211h_MODE;
328 pOpts->flags |= DEVICE_FLAGS_DiversityANT;
332 device_set_options(struct vnt_private *pDevice)
334 unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
335 unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
336 unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
338 ether_addr_copy(pDevice->abyBroadcastAddr, abyBroadcastAddr);
339 ether_addr_copy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042);
340 ether_addr_copy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel);
342 pDevice->uChannel = pDevice->sOpts.channel_num;
343 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
344 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
345 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
346 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
347 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
348 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
349 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
350 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
351 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
352 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
353 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
354 if (pDevice->uConnectionRate < RATE_AUTO)
355 pDevice->bFixRate = true;
356 pDevice->byBBType = pDevice->sOpts.bbp_type;
357 pDevice->byPacketType = (VIA_PKT_TYPE)pDevice->byBBType;
358 pDevice->byAutoFBCtrl = AUTO_FB_0;
359 pDevice->bUpdateBBVGA = true;
360 pDevice->byFOETuning = 0;
361 pDevice->byPreambleType = 0;
363 pr_debug(" uChannel= %d\n", (int)pDevice->uChannel);
364 pr_debug(" byOpMode= %d\n", (int)pDevice->byOpMode);
365 pr_debug(" ePSMode= %d\n", (int)pDevice->ePSMode);
366 pr_debug(" wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
367 pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
368 pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
369 pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType);
370 pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
371 pr_debug(" uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
372 pr_debug(" byBBType= %d\n", (int)pDevice->byBBType);
373 pr_debug(" pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
374 pr_debug(" pDevice->bDiversityRegCtlON= %d\n",
375 (int)pDevice->bDiversityRegCtlON);
379 // Initialisation of MAC & BBP registers
382 static void device_init_registers(struct vnt_private *pDevice)
386 unsigned char byValue;
387 unsigned char byValue1;
388 unsigned char byCCKPwrdBm = 0;
389 unsigned char byOFDMPwrdBm = 0;
391 MACbShutdown(pDevice->PortOffset);
392 BBvSoftwareReset(pDevice->PortOffset);
394 /* Do MACbSoftwareReset in MACvInitialize */
395 MACbSoftwareReset(pDevice->PortOffset);
397 pDevice->bAES = false;
399 /* Only used in 11g type, sync with ERP IE */
400 pDevice->bProtectMode = false;
402 pDevice->bNonERPPresent = false;
403 pDevice->bBarkerPreambleMd = false;
404 pDevice->wCurrentRate = RATE_1M;
405 pDevice->byTopOFDMBasicRate = RATE_24M;
406 pDevice->byTopCCKBasicRate = RATE_1M;
408 /* Target to IF pin while programming to RF chip. */
409 pDevice->byRevId = 0;
412 MACvInitialize(pDevice->PortOffset);
415 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
417 spin_lock_irqsave(&pDevice->lock, flags);
419 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
421 spin_unlock_irqrestore(&pDevice->lock, flags);
423 /* Get Channel range */
424 pDevice->byMinChannel = 1;
425 pDevice->byMaxChannel = CB_MAX_CHANNEL;
428 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
429 if (byValue & EEP_ANTINV)
430 pDevice->bTxRxAntInv = true;
432 pDevice->bTxRxAntInv = false;
434 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
435 /* if not set default is All */
437 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
439 pDevice->ulDiversityNValue = 100*260;
440 pDevice->ulDiversityMValue = 100*16;
442 pDevice->byTMax2 = 4;
443 pDevice->ulSQ3TH = 0;
444 pDevice->byTMax3 = 64;
446 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
447 pDevice->byAntennaCount = 2;
448 pDevice->byTxAntennaMode = ANT_B;
449 pDevice->dwTxAntennaSel = 1;
450 pDevice->dwRxAntennaSel = 1;
452 if (pDevice->bTxRxAntInv)
453 pDevice->byRxAntennaMode = ANT_A;
455 pDevice->byRxAntennaMode = ANT_B;
457 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset,
460 if ((byValue1 & 0x08) == 0)
461 pDevice->bDiversityEnable = false;
463 pDevice->bDiversityEnable = true;
465 pDevice->bDiversityEnable = false;
466 pDevice->byAntennaCount = 1;
467 pDevice->dwTxAntennaSel = 0;
468 pDevice->dwRxAntennaSel = 0;
470 if (byValue & EEP_ANTENNA_AUX) {
471 pDevice->byTxAntennaMode = ANT_A;
473 if (pDevice->bTxRxAntInv)
474 pDevice->byRxAntennaMode = ANT_B;
476 pDevice->byRxAntennaMode = ANT_A;
478 pDevice->byTxAntennaMode = ANT_B;
480 if (pDevice->bTxRxAntInv)
481 pDevice->byRxAntennaMode = ANT_A;
483 pDevice->byRxAntennaMode = ANT_B;
487 pr_debug("bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
488 pDevice->bDiversityEnable, (int)pDevice->ulDiversityNValue,
489 (int)pDevice->ulDiversityMValue, pDevice->byTMax,
492 /* zonetype initial */
493 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
496 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
498 /* force change RevID for VT3253 emu */
499 if ((pDevice->byRFType & RF_EMU) != 0)
500 pDevice->byRevId = 0x80;
502 pDevice->byRFType &= RF_MASK;
503 pr_debug("pDevice->byRFType = %x\n", pDevice->byRFType);
505 if (!pDevice->bZoneRegExist)
506 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
508 pr_debug("pDevice->byZoneType = %x\n", pDevice->byZoneType);
513 /* Get Desire Power Value */
514 pDevice->byCurPwr = 0xFF;
515 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
516 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
518 /* Load power Table */
519 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
520 pDevice->abyCCKPwrTbl[ii + 1] =
521 SROMbyReadEmbedded(pDevice->PortOffset,
522 (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
523 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
524 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
526 pDevice->abyOFDMPwrTbl[ii + 1] =
527 SROMbyReadEmbedded(pDevice->PortOffset,
528 (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
529 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
530 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
532 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
533 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
536 /* recover 12,13 ,14channel for EUROPE by 11 channel */
537 for (ii = 11; ii < 14; ii++) {
538 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
539 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
542 /* Load OFDM A Power Table */
543 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
544 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
545 SROMbyReadEmbedded(pDevice->PortOffset,
546 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
548 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
549 SROMbyReadEmbedded(pDevice->PortOffset,
550 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
553 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
554 MACvSelectPage1(pDevice->PortOffset);
556 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
557 (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
559 MACvSelectPage0(pDevice->PortOffset);
562 /* use relative tx timeout and 802.11i D4 */
563 MACvWordRegBitsOn(pDevice->PortOffset,
564 MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
566 /* set performance parameter by registry */
567 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
568 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
570 /* reset TSF counter */
571 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
572 /* enable TSF counter */
573 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
575 /* initialize BBP registers */
576 BBbVT3253Init(pDevice);
578 if (pDevice->bUpdateBBVGA) {
579 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
580 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
581 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
584 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
585 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
587 /* Set BB and packet type at the same time. */
588 /* Set Short Slot Time, xIFS, and RSPINF. */
589 if (pDevice->uConnectionRate == RATE_AUTO)
590 pDevice->wCurrentRate = RATE_54M;
592 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
594 pDevice->bRadioOff = false;
596 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
598 pDevice->bHWRadioOff = false;
600 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
602 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
604 if (((pDevice->byGPIO & GPIO0_DATA) &&
605 !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
606 (!(pDevice->byGPIO & GPIO0_DATA) &&
607 (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
608 pDevice->bHWRadioOff = true;
611 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
612 CARDbRadioPowerOff(pDevice);
614 /* get Permanent network address */
615 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
616 pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
618 /* reset Tx pointer */
619 CARDvSafeResetRx(pDevice);
620 /* reset Rx pointer */
621 CARDvSafeResetTx(pDevice);
623 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
624 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
627 MACvReceive0(pDevice->PortOffset);
628 MACvReceive1(pDevice->PortOffset);
630 /* start the adapter */
631 MACvStart(pDevice->PortOffset);
634 static void device_init_diversity_timer(struct vnt_private *pDevice)
636 init_timer(&pDevice->TimerSQ3Tmax1);
637 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
638 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
639 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
641 init_timer(&pDevice->TimerSQ3Tmax2);
642 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
643 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
644 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
646 init_timer(&pDevice->TimerSQ3Tmax3);
647 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
648 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
649 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
652 static void device_print_info(struct vnt_private *pDevice)
654 dev_info(&pDevice->pcid->dev, "%s\n", get_chip_name(pDevice->chip_id));
656 dev_info(&pDevice->pcid->dev, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
657 pDevice->abyCurrentNetAddr, (unsigned long)pDevice->ioaddr,
658 (unsigned long)pDevice->PortOffset, pDevice->pcid->irq);
661 static void vt6655_init_info(struct pci_dev *pcid,
662 struct vnt_private **ppDevice,
663 PCHIP_INFO pChip_info)
665 memset(*ppDevice, 0, sizeof(**ppDevice));
667 (*ppDevice)->pcid = pcid;
668 (*ppDevice)->chip_id = pChip_info->chip_id;
669 (*ppDevice)->io_size = pChip_info->io_size;
670 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
671 (*ppDevice)->multicast_limit = 32;
673 spin_lock_init(&((*ppDevice)->lock));
676 static bool device_get_pci_info(struct vnt_private *pDevice,
677 struct pci_dev *pcid)
681 unsigned int cis_addr;
683 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
684 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
685 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
686 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
688 pci_set_master(pcid);
690 pDevice->memaddr = pci_resource_start(pcid, 0);
691 pDevice->ioaddr = pci_resource_start(pcid, 1);
693 cis_addr = pci_resource_start(pcid, 2);
695 pDevice->pcid = pcid;
697 pci_read_config_byte(pcid, PCI_COMMAND, &b);
698 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
703 static void device_free_info(struct vnt_private *pDevice)
709 ieee80211_unregister_hw(pDevice->hw);
711 if (pDevice->PortOffset)
712 iounmap(pDevice->PortOffset);
715 pci_release_regions(pDevice->pcid);
718 ieee80211_free_hw(pDevice->hw);
721 static bool device_init_rings(struct vnt_private *pDevice)
725 /*allocate all RD/TD rings a single pool*/
726 vir_pool = pci_zalloc_consistent(pDevice->pcid,
727 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
728 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
729 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
730 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
732 if (vir_pool == NULL) {
733 dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n");
737 pDevice->aRD0Ring = vir_pool;
738 pDevice->aRD1Ring = vir_pool +
739 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
741 pDevice->rd0_pool_dma = pDevice->pool_dma;
742 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
743 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
745 pDevice->tx0_bufs = pci_zalloc_consistent(pDevice->pcid,
746 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
747 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
750 &pDevice->tx_bufs_dma0);
751 if (pDevice->tx0_bufs == NULL) {
752 dev_err(&pDevice->pcid->dev, "allocate buf dma memory failed\n");
754 pci_free_consistent(pDevice->pcid,
755 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
756 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
757 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
758 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
759 vir_pool, pDevice->pool_dma
764 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
765 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
767 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
768 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
770 // vir_pool: pvoid type
771 pDevice->apTD0Rings = vir_pool
772 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
773 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
775 pDevice->apTD1Rings = vir_pool
776 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
777 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
778 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
780 pDevice->tx1_bufs = pDevice->tx0_bufs +
781 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
783 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
784 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
786 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
789 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
790 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
792 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
793 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
798 static void device_free_rings(struct vnt_private *pDevice)
800 pci_free_consistent(pDevice->pcid,
801 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
802 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
803 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
804 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
806 pDevice->aRD0Ring, pDevice->pool_dma
809 if (pDevice->tx0_bufs)
810 pci_free_consistent(pDevice->pcid,
811 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
812 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
815 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
819 static void device_init_rd0_ring(struct vnt_private *pDevice)
822 dma_addr_t curr = pDevice->rd0_pool_dma;
825 /* Init the RD0 ring entries */
826 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
827 pDesc = &(pDevice->aRD0Ring[i]);
828 pDesc->pRDInfo = alloc_rd_info();
829 ASSERT(pDesc->pRDInfo);
830 if (!device_alloc_rx_buf(pDevice, pDesc))
831 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
833 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
834 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
835 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
839 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
840 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
843 static void device_init_rd1_ring(struct vnt_private *pDevice)
846 dma_addr_t curr = pDevice->rd1_pool_dma;
849 /* Init the RD1 ring entries */
850 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
851 pDesc = &(pDevice->aRD1Ring[i]);
852 pDesc->pRDInfo = alloc_rd_info();
853 ASSERT(pDesc->pRDInfo);
854 if (!device_alloc_rx_buf(pDevice, pDesc))
855 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
857 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
858 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
859 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
863 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
864 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
867 static void device_init_defrag_cb(struct vnt_private *pDevice)
870 PSDeFragControlBlock pDeF;
872 /* Init the fragment ctl entries */
873 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
874 pDeF = &(pDevice->sRxDFCB[i]);
875 if (!device_alloc_frag_buf(pDevice, pDeF))
876 dev_err(&pDevice->pcid->dev, "can not alloc frag bufs\n");
878 pDevice->cbDFCB = CB_MAX_RX_FRAG;
879 pDevice->cbFreeDFCB = pDevice->cbDFCB;
882 static void device_free_rd0_ring(struct vnt_private *pDevice)
886 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
887 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
888 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
890 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
891 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
893 dev_kfree_skb(pRDInfo->skb);
895 kfree(pDesc->pRDInfo);
899 static void device_free_rd1_ring(struct vnt_private *pDevice)
903 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
904 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
905 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
907 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
908 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
910 dev_kfree_skb(pRDInfo->skb);
912 kfree(pDesc->pRDInfo);
916 static void device_free_frag_buf(struct vnt_private *pDevice)
918 PSDeFragControlBlock pDeF;
921 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
922 pDeF = &(pDevice->sRxDFCB[i]);
925 dev_kfree_skb(pDeF->skb);
930 static void device_init_td0_ring(struct vnt_private *pDevice)
936 curr = pDevice->td0_pool_dma;
937 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
938 pDesc = &(pDevice->apTD0Rings[i]);
939 pDesc->pTDInfo = alloc_td_info();
940 ASSERT(pDesc->pTDInfo);
941 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
942 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
943 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
945 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
946 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
947 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
951 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
952 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
955 static void device_init_td1_ring(struct vnt_private *pDevice)
961 /* Init the TD ring entries */
962 curr = pDevice->td1_pool_dma;
963 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
964 pDesc = &(pDevice->apTD1Rings[i]);
965 pDesc->pTDInfo = alloc_td_info();
966 ASSERT(pDesc->pTDInfo);
967 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
968 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
969 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
971 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
972 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
973 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
977 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
978 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
981 static void device_free_td0_ring(struct vnt_private *pDevice)
985 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
986 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
987 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
989 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
990 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
991 pTDInfo->skb->len, PCI_DMA_TODEVICE);
994 dev_kfree_skb(pTDInfo->skb);
996 kfree(pDesc->pTDInfo);
1000 static void device_free_td1_ring(struct vnt_private *pDevice)
1004 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1005 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
1006 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1008 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1009 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1010 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1013 dev_kfree_skb(pTDInfo->skb);
1015 kfree(pDesc->pTDInfo);
1019 /*-----------------------------------------------------------------*/
1021 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1026 for (pRD = pDevice->pCurrRD[uIdx];
1027 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1031 if (vnt_receive_frame(pDevice, pRD)) {
1032 if (!device_alloc_rx_buf(pDevice, pRD)) {
1033 dev_err(&pDevice->pcid->dev,
1034 "can not allocate rx buf\n");
1038 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1041 pDevice->pCurrRD[uIdx] = pRD;
1046 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
1048 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1050 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1051 if (pRDInfo->skb == NULL)
1053 ASSERT(pRDInfo->skb);
1056 pci_map_single(pDevice->pcid,
1057 skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)),
1058 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1060 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1062 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1063 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1064 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1065 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1070 bool device_alloc_frag_buf(struct vnt_private *pDevice,
1071 PSDeFragControlBlock pDeF)
1073 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1074 if (pDeF->skb == NULL)
1081 static const u8 fallback_rate0[5][5] = {
1082 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
1083 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
1084 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
1085 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
1086 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
1089 static const u8 fallback_rate1[5][5] = {
1090 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
1091 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
1092 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
1093 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
1094 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
1097 static int vnt_int_report_rate(struct vnt_private *priv,
1098 PDEVICE_TD_INFO context, u8 tsr0, u8 tsr1)
1100 struct vnt_tx_fifo_head *fifo_head;
1101 struct ieee80211_tx_info *info;
1102 struct ieee80211_rate *rate;
1104 u8 tx_retry = (tsr0 & TSR0_NCR);
1113 fifo_head = (struct vnt_tx_fifo_head *)context->buf;
1114 fb_option = (le16_to_cpu(fifo_head->fifo_ctl) &
1115 (FIFOCTL_AUTO_FB_0 | FIFOCTL_AUTO_FB_1));
1117 info = IEEE80211_SKB_CB(context->skb);
1118 idx = info->control.rates[0].idx;
1120 if (fb_option && !(tsr1 & TSR1_TERR)) {
1122 u8 retry = tx_retry;
1124 rate = ieee80211_get_tx_rate(priv->hw, info);
1125 tx_rate = rate->hw_value - RATE_18M;
1130 if (fb_option & FIFOCTL_AUTO_FB_0)
1131 tx_rate = fallback_rate0[tx_rate][retry];
1132 else if (fb_option & FIFOCTL_AUTO_FB_1)
1133 tx_rate = fallback_rate1[tx_rate][retry];
1135 if (info->band == IEEE80211_BAND_5GHZ)
1136 idx = tx_rate - RATE_6M;
1141 ieee80211_tx_info_clear_status(info);
1143 info->status.rates[0].count = tx_retry;
1145 if (!(tsr1 & TSR1_TERR)) {
1146 info->status.rates[0].idx = idx;
1147 info->flags |= IEEE80211_TX_STAT_ACK;
1153 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1157 unsigned char byTsr0;
1158 unsigned char byTsr1;
1160 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1161 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1166 byTsr0 = pTD->m_td0TD0.byTSR0;
1167 byTsr1 = pTD->m_td0TD0.byTSR1;
1169 //Only the status of first TD in the chain is correct
1170 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1171 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1173 vnt_int_report_rate(pDevice, pTD->pTDInfo, byTsr0, byTsr1);
1175 if (!(byTsr1 & TSR1_TERR)) {
1177 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
1182 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
1183 (int)uIdx, byTsr1, byTsr0);
1187 if (byTsr1 & TSR1_TERR) {
1188 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1189 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
1190 (int)uIdx, byTsr1, byTsr0);
1193 device_free_tx_buf(pDevice, pTD);
1194 pDevice->iTDUsed[uIdx]--;
1196 /* Make sure queue is available */
1197 if (AVAIL_TD(pDevice, uIdx))
1198 ieee80211_wake_queues(pDevice->hw);
1202 pDevice->apTailTD[uIdx] = pTD;
1207 static void device_error(struct vnt_private *pDevice, unsigned short status)
1209 if (status & ISR_FETALERR) {
1210 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
1212 MACbShutdown(pDevice->PortOffset);
1217 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
1219 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1220 struct sk_buff *skb = pTDInfo->skb;
1222 // pre-allocated buf_dma can't be unmapped.
1223 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1224 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1228 if (pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)
1229 ieee80211_tx_status_irqsafe(pDevice->hw, skb);
1231 dev_kfree_skb_irq(skb);
1233 pTDInfo->skb_dma = 0;
1234 pTDInfo->skb = NULL;
1235 pTDInfo->byFlags = 0;
1238 static irqreturn_t device_intr(int irq, void *dev_instance)
1240 struct vnt_private *pDevice = dev_instance;
1242 unsigned long dwMIBCounter = 0;
1243 unsigned char byOrgPageSel = 0;
1246 unsigned long flags;
1248 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
1250 if (pDevice->dwIsr == 0)
1251 return IRQ_RETVAL(handled);
1253 if (pDevice->dwIsr == 0xffffffff) {
1254 pr_debug("dwIsr = 0xffff\n");
1255 return IRQ_RETVAL(handled);
1259 MACvIntDisable(pDevice->PortOffset);
1261 spin_lock_irqsave(&pDevice->lock, flags);
1263 //Make sure current page is 0
1264 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
1265 if (byOrgPageSel == 1)
1266 MACvSelectPage0(pDevice->PortOffset);
1270 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
1272 // Must do this after doing rx/tx, cause ISR bit is slow
1273 // than RD/TD write back
1274 // update ISR counter
1275 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
1276 while (pDevice->dwIsr != 0) {
1277 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
1278 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
1280 if (pDevice->dwIsr & ISR_FETALERR) {
1281 pr_debug(" ISR_FETALERR\n");
1282 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
1283 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
1284 device_error(pDevice, pDevice->dwIsr);
1287 if (pDevice->dwIsr & ISR_TBTT) {
1289 pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
1290 if (pDevice->bUpdateBBVGA &&
1291 !(pDevice->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
1292 pDevice->vif->bss_conf.assoc &&
1293 pDevice->uCurrRSSI) {
1296 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
1297 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
1298 if (ldBm < pDevice->ldBmThreshold[ii]) {
1299 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1303 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1304 pDevice->uBBVGADiffCount++;
1305 if (pDevice->uBBVGADiffCount == 1) {
1306 // first VGA diff gain
1307 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
1308 pr_debug("First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1310 pDevice->byBBVGANew,
1311 pDevice->byBBVGACurrent,
1312 (int)pDevice->uBBVGADiffCount);
1314 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
1315 pr_debug("RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1317 pDevice->byBBVGANew,
1318 pDevice->byBBVGACurrent,
1319 (int)pDevice->uBBVGADiffCount);
1320 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
1323 pDevice->uBBVGADiffCount = 1;
1328 pDevice->bBeaconSent = false;
1329 if (pDevice->bEnablePSMode)
1330 PSbIsNextTBTTWakeUp((void *)pDevice);
1332 if ((pDevice->op_mode == NL80211_IFTYPE_AP ||
1333 pDevice->op_mode == NL80211_IFTYPE_ADHOC) &&
1334 pDevice->vif->bss_conf.enable_beacon) {
1335 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
1336 (pDevice->vif->bss_conf.beacon_int - MAKE_BEACON_RESERVED) << 10);
1339 /* TODO: adhoc PS mode */
1343 if (pDevice->dwIsr & ISR_BNTX) {
1344 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
1345 pDevice->bIsBeaconBufReadySet = false;
1346 pDevice->cbBeaconBufReadySetCnt = 0;
1349 pDevice->bBeaconSent = true;
1352 if (pDevice->dwIsr & ISR_RXDMA0)
1353 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
1355 if (pDevice->dwIsr & ISR_RXDMA1)
1356 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
1358 if (pDevice->dwIsr & ISR_TXDMA0)
1359 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
1361 if (pDevice->dwIsr & ISR_AC0DMA)
1362 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
1364 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
1366 if (pDevice->vif->bss_conf.enable_beacon)
1367 vnt_beacon_make(pDevice, pDevice->vif);
1371 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
1373 MACvReceive0(pDevice->PortOffset);
1374 MACvReceive1(pDevice->PortOffset);
1376 if (max_count > pDevice->sOpts.int_works)
1380 if (byOrgPageSel == 1)
1381 MACvSelectPage1(pDevice->PortOffset);
1383 spin_unlock_irqrestore(&pDevice->lock, flags);
1385 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1387 return IRQ_RETVAL(handled);
1390 static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1392 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1394 u32 dma_idx = TYPE_AC0DMA;
1395 unsigned long flags;
1397 spin_lock_irqsave(&priv->lock, flags);
1399 if (!ieee80211_is_data(hdr->frame_control))
1400 dma_idx = TYPE_TXDMA0;
1402 if (AVAIL_TD(priv, dma_idx) < 1) {
1403 spin_unlock_irqrestore(&priv->lock, flags);
1407 head_td = priv->apCurrTD[dma_idx];
1409 head_td->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1411 head_td->pTDInfo->skb = skb;
1413 priv->iTDUsed[dma_idx]++;
1415 /* Take ownership */
1417 head_td->m_td0TD0.f1Owner = OWNED_BY_NIC;
1421 priv->apCurrTD[dma_idx] = head_td->next;
1423 spin_unlock_irqrestore(&priv->lock, flags);
1425 vnt_generate_fifo_header(priv, dma_idx, head_td, skb);
1427 if (MACbIsRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
1428 MACbPSWakeup(priv->PortOffset);
1430 spin_lock_irqsave(&priv->lock, flags);
1432 priv->bPWBitOn = false;
1434 head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB;
1436 if (dma_idx == TYPE_AC0DMA)
1437 MACvTransmitAC0(priv->PortOffset);
1439 MACvTransmit0(priv->PortOffset);
1441 spin_unlock_irqrestore(&priv->lock, flags);
1446 static void vnt_tx_80211(struct ieee80211_hw *hw,
1447 struct ieee80211_tx_control *control,
1448 struct sk_buff *skb)
1450 struct vnt_private *priv = hw->priv;
1452 ieee80211_stop_queues(hw);
1454 if (vnt_tx_packet(priv, skb)) {
1455 ieee80211_free_txskb(hw, skb);
1457 ieee80211_wake_queues(hw);
1461 static int vnt_start(struct ieee80211_hw *hw)
1463 struct vnt_private *priv = hw->priv;
1466 priv->rx_buf_sz = PKT_BUF_SZ;
1467 if (!device_init_rings(priv))
1470 ret = request_irq(priv->pcid->irq, &device_intr,
1471 IRQF_SHARED, "vt6655", priv);
1473 dev_dbg(&priv->pcid->dev, "failed to start irq\n");
1477 dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
1478 device_init_rd0_ring(priv);
1479 device_init_rd1_ring(priv);
1480 device_init_defrag_cb(priv);
1481 device_init_td0_ring(priv);
1482 device_init_td1_ring(priv);
1484 device_init_registers(priv);
1486 dev_dbg(&priv->pcid->dev, "call MACvIntEnable\n");
1487 MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
1489 ieee80211_wake_queues(hw);
1494 static void vnt_stop(struct ieee80211_hw *hw)
1496 struct vnt_private *priv = hw->priv;
1498 ieee80211_stop_queues(hw);
1500 MACbShutdown(priv->PortOffset);
1501 MACbSoftwareReset(priv->PortOffset);
1502 CARDbRadioPowerOff(priv);
1504 device_free_td0_ring(priv);
1505 device_free_td1_ring(priv);
1506 device_free_rd0_ring(priv);
1507 device_free_rd1_ring(priv);
1508 device_free_frag_buf(priv);
1509 device_free_rings(priv);
1511 free_irq(priv->pcid->irq, priv);
1514 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1516 struct vnt_private *priv = hw->priv;
1520 switch (vif->type) {
1521 case NL80211_IFTYPE_STATION:
1522 if (priv->bDiversityRegCtlON)
1523 device_init_diversity_timer(priv);
1525 case NL80211_IFTYPE_ADHOC:
1526 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1528 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1531 case NL80211_IFTYPE_AP:
1532 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1534 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1541 priv->op_mode = vif->type;
1546 static void vnt_remove_interface(struct ieee80211_hw *hw,
1547 struct ieee80211_vif *vif)
1549 struct vnt_private *priv = hw->priv;
1551 switch (vif->type) {
1552 case NL80211_IFTYPE_STATION:
1553 if (priv->bDiversityRegCtlON) {
1554 del_timer(&priv->TimerSQ3Tmax1);
1555 del_timer(&priv->TimerSQ3Tmax2);
1556 del_timer(&priv->TimerSQ3Tmax3);
1559 case NL80211_IFTYPE_ADHOC:
1560 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1561 MACvRegBitsOff(priv->PortOffset,
1562 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1563 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1565 case NL80211_IFTYPE_AP:
1566 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1567 MACvRegBitsOff(priv->PortOffset,
1568 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1569 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1575 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
1579 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
1581 struct vnt_private *priv = hw->priv;
1582 struct ieee80211_conf *conf = &hw->conf;
1585 if (changed & IEEE80211_CONF_CHANGE_PS) {
1586 if (conf->flags & IEEE80211_CONF_PS)
1587 PSvEnablePowerSaving(priv, conf->listen_interval);
1589 PSvDisablePowerSaving(priv);
1592 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
1593 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
1594 set_channel(priv, conf->chandef.chan->hw_value);
1596 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
1597 bb_type = BB_TYPE_11A;
1599 bb_type = BB_TYPE_11G;
1601 if (priv->byBBType != bb_type) {
1602 priv->byBBType = bb_type;
1604 CARDbSetPhyParameter(priv,
1605 priv->byBBType, 0, 0, NULL, NULL);
1609 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1610 if (priv->byBBType == BB_TYPE_11B)
1611 priv->wCurrentRate = RATE_1M;
1613 priv->wCurrentRate = RATE_54M;
1615 RFbSetPower(priv, priv->wCurrentRate,
1616 conf->chandef.chan->hw_value);
1622 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
1623 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
1626 struct vnt_private *priv = hw->priv;
1628 priv->current_aid = conf->aid;
1630 if (changed & BSS_CHANGED_BSSID)
1631 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid);
1633 if (changed & BSS_CHANGED_BASIC_RATES) {
1634 priv->basic_rates = conf->basic_rates;
1636 CARDvUpdateBasicTopRate(priv);
1638 dev_dbg(&priv->pcid->dev,
1639 "basic rates %x\n", conf->basic_rates);
1642 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1643 if (conf->use_short_preamble) {
1644 MACvEnableBarkerPreambleMd(priv->PortOffset);
1645 priv->byPreambleType = true;
1647 MACvDisableBarkerPreambleMd(priv->PortOffset);
1648 priv->byPreambleType = false;
1652 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1653 if (conf->use_cts_prot)
1654 MACvEnableProtectMD(priv->PortOffset);
1656 MACvDisableProtectMD(priv->PortOffset);
1659 if (changed & BSS_CHANGED_ERP_SLOT) {
1660 if (conf->use_short_slot)
1661 priv->bShortSlotTime = true;
1663 priv->bShortSlotTime = false;
1666 CARDbSetPhyParameter(priv, priv->byBBType, 0, 0, NULL, NULL);
1667 BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
1670 if (changed & BSS_CHANGED_TXPOWER)
1671 RFbSetPower(priv, priv->wCurrentRate,
1672 conf->chandef.chan->hw_value);
1674 if (changed & BSS_CHANGED_BEACON_ENABLED) {
1675 dev_dbg(&priv->pcid->dev,
1676 "Beacon enable %d\n", conf->enable_beacon);
1678 if (conf->enable_beacon) {
1679 vnt_beacon_enable(priv, vif, conf);
1681 MACvRegBitsOn(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1683 MACvRegBitsOff(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1687 if (changed & BSS_CHANGED_ASSOC && priv->op_mode != NL80211_IFTYPE_AP) {
1689 CARDbUpdateTSF(priv, conf->beacon_rate->hw_value,
1690 conf->sync_device_ts, conf->sync_tsf);
1692 CARDbSetBeaconPeriod(priv, conf->beacon_int);
1694 CARDvSetFirstNextTBTT(priv->PortOffset,
1697 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1699 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1705 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
1706 struct netdev_hw_addr_list *mc_list)
1708 struct vnt_private *priv = hw->priv;
1709 struct netdev_hw_addr *ha;
1713 netdev_hw_addr_list_for_each(ha, mc_list) {
1714 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1716 mc_filter |= 1ULL << (bit_nr & 0x3f);
1719 priv->mc_list_count = mc_list->count;
1724 static void vnt_configure(struct ieee80211_hw *hw,
1725 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
1727 struct vnt_private *priv = hw->priv;
1730 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_PROMISC_IN_BSS |
1731 FIF_BCN_PRBRESP_PROMISC;
1733 VNSvInPortB(priv->PortOffset + MAC_REG_RCR, &rx_mode);
1735 dev_dbg(&priv->pcid->dev, "rx mode in = %x\n", rx_mode);
1737 if (changed_flags & FIF_PROMISC_IN_BSS) {
1738 /* unconditionally log net taps */
1739 if (*total_flags & FIF_PROMISC_IN_BSS)
1740 rx_mode |= RCR_UNICAST;
1742 rx_mode &= ~RCR_UNICAST;
1745 if (changed_flags & FIF_ALLMULTI) {
1746 if (*total_flags & FIF_ALLMULTI) {
1747 if (priv->mc_list_count > 2) {
1748 MACvSelectPage1(priv->PortOffset);
1750 VNSvOutPortD(priv->PortOffset +
1751 MAC_REG_MAR0, 0xffffffff);
1752 VNSvOutPortD(priv->PortOffset +
1753 MAC_REG_MAR0 + 4, 0xffffffff);
1755 MACvSelectPage0(priv->PortOffset);
1757 MACvSelectPage1(priv->PortOffset);
1759 VNSvOutPortD(priv->PortOffset +
1760 MAC_REG_MAR0, (u32)multicast);
1761 VNSvOutPortD(priv->PortOffset +
1763 (u32)(multicast >> 32));
1765 MACvSelectPage0(priv->PortOffset);
1768 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1770 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
1774 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
1775 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1777 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
1778 rx_mode &= ~RCR_BSSID;
1780 rx_mode |= RCR_BSSID;
1783 VNSvOutPortB(priv->PortOffset + MAC_REG_RCR, rx_mode);
1785 dev_dbg(&priv->pcid->dev, "rx mode out= %x\n", rx_mode);
1788 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1789 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1790 struct ieee80211_key_conf *key)
1792 struct vnt_private *priv = hw->priv;
1796 if (vnt_set_keys(hw, sta, vif, key))
1800 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
1801 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
1809 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1811 struct vnt_private *priv = hw->priv;
1814 CARDbGetCurrentTSF(priv->PortOffset, &tsf);
1819 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1822 struct vnt_private *priv = hw->priv;
1824 CARDvUpdateNextTBTT(priv->PortOffset, tsf, vif->bss_conf.beacon_int);
1827 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1829 struct vnt_private *priv = hw->priv;
1831 /* reset TSF counter */
1832 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1835 static const struct ieee80211_ops vnt_mac_ops = {
1839 .add_interface = vnt_add_interface,
1840 .remove_interface = vnt_remove_interface,
1841 .config = vnt_config,
1842 .bss_info_changed = vnt_bss_info_changed,
1843 .prepare_multicast = vnt_prepare_multicast,
1844 .configure_filter = vnt_configure,
1845 .set_key = vnt_set_key,
1846 .get_tsf = vnt_get_tsf,
1847 .set_tsf = vnt_set_tsf,
1848 .reset_tsf = vnt_reset_tsf,
1851 int vnt_init(struct vnt_private *priv)
1853 SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyCurrentNetAddr);
1855 vnt_init_bands(priv);
1857 if (ieee80211_register_hw(priv->hw))
1860 priv->mac_hw = true;
1862 CARDbRadioPowerOff(priv);
1868 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
1870 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
1871 struct vnt_private *priv;
1872 struct ieee80211_hw *hw;
1873 struct wiphy *wiphy;
1876 dev_notice(&pcid->dev,
1877 "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1879 dev_notice(&pcid->dev,
1880 "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
1882 hw = ieee80211_alloc_hw(sizeof(*priv), &vnt_mac_ops);
1884 dev_err(&pcid->dev, "could not register ieee80211_hw\n");
1890 vt6655_init_info(pcid, &priv, pChip_info);
1894 SET_IEEE80211_DEV(priv->hw, &pcid->dev);
1896 if (pci_enable_device(pcid)) {
1897 device_free_info(priv);
1902 "Before get pci_info memaddr is %x\n", priv->memaddr);
1904 if (!device_get_pci_info(priv, pcid)) {
1905 dev_err(&pcid->dev, ": Failed to find PCI device.\n");
1906 device_free_info(priv);
1912 "after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",
1913 priv->memaddr, priv->ioaddr, priv->io_size);
1925 for (i = 0; address[i]; i++) {
1926 pci_read_config_dword(pcid, address[i], &bar);
1928 dev_dbg(&pcid->dev, "bar %d is %x\n", i, bar);
1932 "bar %d not implemented\n", i);
1936 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
1939 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xffff);
1940 len = len & ~(len - 1);
1943 "IO space: len in IO %x, BAR %d\n",
1946 len = bar & 0xfffffff0;
1950 "len in MEM %x, BAR %d\n", len, i);
1956 priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK,
1958 if (!priv->PortOffset) {
1959 dev_err(&pcid->dev, ": Failed to IO remapping ..\n");
1960 device_free_info(priv);
1964 rc = pci_request_regions(pcid, DEVICE_NAME);
1966 dev_err(&pcid->dev, ": Failed to find PCI device\n");
1967 device_free_info(priv);
1972 if (!MACbSoftwareReset(priv->PortOffset)) {
1973 dev_err(&pcid->dev, ": Failed to access MAC hardware..\n");
1974 device_free_info(priv);
1977 /* initial to reload eeprom */
1978 MACvInitialize(priv->PortOffset);
1979 MACvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr);
1981 device_get_options(priv);
1982 device_set_options(priv);
1983 /* Mask out the options cannot be set to the chip */
1984 priv->sOpts.flags &= pChip_info->flags;
1986 /* Enable the chip specified capabilities */
1987 priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL);
1989 wiphy = priv->hw->wiphy;
1991 wiphy->frag_threshold = FRAG_THRESH_DEF;
1992 wiphy->rts_threshold = RTS_THRESH_DEF;
1993 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1994 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1996 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1997 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
1998 IEEE80211_HW_SIGNAL_DBM |
1999 IEEE80211_HW_TIMING_BEACON_ONLY;
2001 priv->hw->max_signal = 100;
2006 device_print_info(priv);
2007 pci_set_drvdata(pcid, priv);
2012 /*------------------------------------------------------------------*/
2015 static int vt6655_suspend(struct pci_dev *pcid, pm_message_t state)
2017 struct vnt_private *priv = pci_get_drvdata(pcid);
2018 unsigned long flags;
2020 spin_lock_irqsave(&priv->lock, flags);
2022 pci_save_state(pcid);
2024 MACbShutdown(priv->PortOffset);
2026 pci_disable_device(pcid);
2027 pci_set_power_state(pcid, pci_choose_state(pcid, state));
2029 spin_unlock_irqrestore(&priv->lock, flags);
2034 static int vt6655_resume(struct pci_dev *pcid)
2037 pci_set_power_state(pcid, PCI_D0);
2038 pci_enable_wake(pcid, PCI_D0, 0);
2039 pci_restore_state(pcid);
2045 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
2047 static struct pci_driver device_driver = {
2048 .name = DEVICE_NAME,
2049 .id_table = vt6655_pci_id_table,
2050 .probe = vt6655_probe,
2051 .remove = vt6655_remove,
2053 .suspend = vt6655_suspend,
2054 .resume = vt6655_resume,
2058 static int __init vt6655_init_module(void)
2062 ret = pci_register_driver(&device_driver);
2065 register_reboot_notifier(&device_notifier);
2071 static void __exit vt6655_cleanup_module(void)
2074 unregister_reboot_notifier(&device_notifier);
2076 pci_unregister_driver(&device_driver);
2079 module_init(vt6655_init_module);
2080 module_exit(vt6655_cleanup_module);
2084 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
2086 struct pci_dev *pdev = NULL;
2092 for_each_pci_dev(pdev) {
2093 if (pci_dev_driver(pdev) == &device_driver) {
2094 if (pci_get_drvdata(pdev))
2095 vt6655_suspend(pdev, PMSG_HIBERNATE);