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>
77 #include <linux/delay.h>
78 #include <linux/kthread.h>
79 #include <linux/slab.h>
81 /*--------------------- Static Definitions -------------------------*/
83 // Define module options
85 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
86 MODULE_LICENSE("GPL");
87 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
89 #define DEVICE_PARAM(N, D)
91 #define RX_DESC_MIN0 16
92 #define RX_DESC_MAX0 128
93 #define RX_DESC_DEF0 32
94 DEVICE_PARAM(RxDescriptors0, "Number of receive descriptors0");
96 #define RX_DESC_MIN1 16
97 #define RX_DESC_MAX1 128
98 #define RX_DESC_DEF1 32
99 DEVICE_PARAM(RxDescriptors1, "Number of receive descriptors1");
101 #define TX_DESC_MIN0 16
102 #define TX_DESC_MAX0 128
103 #define TX_DESC_DEF0 32
104 DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
106 #define TX_DESC_MIN1 16
107 #define TX_DESC_MAX1 128
108 #define TX_DESC_DEF1 64
109 DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
111 #define IP_ALIG_DEF 0
112 /* IP_byte_align[] is used for IP header unsigned long byte aligned
113 0: indicate the IP header won't be unsigned long byte aligned.(Default) .
114 1: indicate the IP header will be unsigned long byte aligned.
115 In some environment, the IP header should be unsigned long byte aligned,
116 or the packet will be droped when we receive it. (eg: IPVS)
118 DEVICE_PARAM(IP_byte_align, "Enable IP header dword aligned");
120 #define INT_WORKS_DEF 20
121 #define INT_WORKS_MIN 10
122 #define INT_WORKS_MAX 64
124 DEVICE_PARAM(int_works, "Number of packets per interrupt services");
126 #define CHANNEL_MIN 1
127 #define CHANNEL_MAX 14
128 #define CHANNEL_DEF 6
130 DEVICE_PARAM(Channel, "Channel number");
132 /* PreambleType[] is the preamble length used for transmit.
133 0: indicate allows long preamble type
134 1: indicate allows short preamble type
137 #define PREAMBLE_TYPE_DEF 1
139 DEVICE_PARAM(PreambleType, "Preamble Type");
141 #define RTS_THRESH_MIN 512
142 #define RTS_THRESH_MAX 2347
143 #define RTS_THRESH_DEF 2347
145 DEVICE_PARAM(RTSThreshold, "RTS threshold");
147 #define FRAG_THRESH_MIN 256
148 #define FRAG_THRESH_MAX 2346
149 #define FRAG_THRESH_DEF 2346
151 DEVICE_PARAM(FragThreshold, "Fragmentation threshold");
153 #define DATA_RATE_MIN 0
154 #define DATA_RATE_MAX 13
155 #define DATA_RATE_DEF 13
157 0: indicate 1 Mbps 0x02
158 1: indicate 2 Mbps 0x04
159 2: indicate 5.5 Mbps 0x0B
160 3: indicate 11 Mbps 0x16
161 4: indicate 6 Mbps 0x0c
162 5: indicate 9 Mbps 0x12
163 6: indicate 12 Mbps 0x18
164 7: indicate 18 Mbps 0x24
165 8: indicate 24 Mbps 0x30
166 9: indicate 36 Mbps 0x48
167 10: indicate 48 Mbps 0x60
168 11: indicate 54 Mbps 0x6c
169 12: indicate 72 Mbps 0x90
170 13: indicate auto rate
173 DEVICE_PARAM(ConnectionRate, "Connection data rate");
175 #define OP_MODE_DEF 0
177 DEVICE_PARAM(OPMode, "Infrastruct, adhoc, AP mode ");
179 /* OpMode[] is used for transmit.
180 0: indicate infrastruct mode used
181 1: indicate adhoc mode used
182 2: indicate AP mode used
186 0: indicate disable power saving mode
187 1: indicate enable power saving mode
190 #define PS_MODE_DEF 0
192 DEVICE_PARAM(PSMode, "Power saving mode");
194 #define SHORT_RETRY_MIN 0
195 #define SHORT_RETRY_MAX 31
196 #define SHORT_RETRY_DEF 8
198 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
200 #define LONG_RETRY_MIN 0
201 #define LONG_RETRY_MAX 15
202 #define LONG_RETRY_DEF 4
204 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
206 /* BasebandType[] baseband type selected
207 0: indicate 802.11a type
208 1: indicate 802.11b type
209 2: indicate 802.11g type
211 #define BBP_TYPE_MIN 0
212 #define BBP_TYPE_MAX 2
213 #define BBP_TYPE_DEF 2
215 DEVICE_PARAM(BasebandType, "baseband type");
218 0: indicate disable 802.11h
219 1: indicate enable 802.11h
222 #define X80211h_MODE_DEF 0
224 DEVICE_PARAM(b80211hEnable, "802.11h mode");
227 0: indicate disable 802.11h
228 1: indicate enable 802.11h
231 #define DIVERSITY_ANT_DEF 0
233 DEVICE_PARAM(bDiversityANTEnable, "ANT diversity mode");
236 // Static vars definitions
238 static CHIP_INFO chip_info_table[] = {
239 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
240 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
244 static const struct pci_device_id vt6655_pci_id_table[] = {
245 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
249 /*--------------------- Static Functions --------------------------*/
251 static int vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent);
252 static void vt6655_init_info(struct pci_dev *pcid,
253 struct vnt_private **ppDevice, PCHIP_INFO);
254 static void device_free_info(struct vnt_private *pDevice);
255 static bool device_get_pci_info(struct vnt_private *, struct pci_dev *pcid);
256 static void device_print_info(struct vnt_private *pDevice);
257 static void device_init_diversity_timer(struct vnt_private *pDevice);
258 static irqreturn_t device_intr(int irq, void *dev_instance);
261 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
262 static struct notifier_block device_notifier = {
263 .notifier_call = device_notify_reboot,
269 static void device_init_rd0_ring(struct vnt_private *pDevice);
270 static void device_init_rd1_ring(struct vnt_private *pDevice);
271 static void device_init_defrag_cb(struct vnt_private *pDevice);
272 static void device_init_td0_ring(struct vnt_private *pDevice);
273 static void device_init_td1_ring(struct vnt_private *pDevice);
275 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx);
276 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx);
277 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc);
278 static void device_init_registers(struct vnt_private *pDevice);
279 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc);
280 static void device_free_td0_ring(struct vnt_private *pDevice);
281 static void device_free_td1_ring(struct vnt_private *pDevice);
282 static void device_free_rd0_ring(struct vnt_private *pDevice);
283 static void device_free_rd1_ring(struct vnt_private *pDevice);
284 static void device_free_rings(struct vnt_private *pDevice);
285 static void device_free_frag_buf(struct vnt_private *pDevice);
287 /*--------------------- Export Variables --------------------------*/
289 /*--------------------- Export Functions --------------------------*/
291 static char *get_chip_name(int chip_id)
295 for (i = 0; chip_info_table[i].name != NULL; i++)
296 if (chip_info_table[i].chip_id == chip_id)
298 return chip_info_table[i].name;
301 static void vt6655_remove(struct pci_dev *pcid)
303 struct vnt_private *pDevice = pci_get_drvdata(pcid);
307 device_free_info(pDevice);
310 static void device_get_options(struct vnt_private *pDevice)
312 POPTIONS pOpts = &(pDevice->sOpts);
314 pOpts->nRxDescs0 = RX_DESC_DEF0;
315 pOpts->nRxDescs1 = RX_DESC_DEF1;
316 pOpts->nTxDescs[0] = TX_DESC_DEF0;
317 pOpts->nTxDescs[1] = TX_DESC_DEF1;
318 pOpts->flags |= DEVICE_FLAGS_IP_ALIGN;
319 pOpts->int_works = INT_WORKS_DEF;
320 pOpts->rts_thresh = RTS_THRESH_DEF;
321 pOpts->frag_thresh = FRAG_THRESH_DEF;
322 pOpts->data_rate = DATA_RATE_DEF;
323 pOpts->channel_num = CHANNEL_DEF;
325 pOpts->flags |= DEVICE_FLAGS_PREAMBLE_TYPE;
326 pOpts->flags |= DEVICE_FLAGS_OP_MODE;
327 pOpts->short_retry = SHORT_RETRY_DEF;
328 pOpts->long_retry = LONG_RETRY_DEF;
329 pOpts->bbp_type = BBP_TYPE_DEF;
330 pOpts->flags |= DEVICE_FLAGS_80211h_MODE;
331 pOpts->flags |= DEVICE_FLAGS_DiversityANT;
335 device_set_options(struct vnt_private *pDevice)
337 unsigned char abyBroadcastAddr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
338 unsigned char abySNAP_RFC1042[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0x00};
339 unsigned char abySNAP_Bridgetunnel[ETH_ALEN] = {0xAA, 0xAA, 0x03, 0x00, 0x00, 0xF8};
341 ether_addr_copy(pDevice->abyBroadcastAddr, abyBroadcastAddr);
342 ether_addr_copy(pDevice->abySNAP_RFC1042, abySNAP_RFC1042);
343 ether_addr_copy(pDevice->abySNAP_Bridgetunnel, abySNAP_Bridgetunnel);
345 pDevice->uChannel = pDevice->sOpts.channel_num;
346 pDevice->wRTSThreshold = pDevice->sOpts.rts_thresh;
347 pDevice->wFragmentationThreshold = pDevice->sOpts.frag_thresh;
348 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
349 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
350 pDevice->wMaxTransmitMSDULifetime = DEFAULT_MSDU_LIFETIME;
351 pDevice->byShortPreamble = (pDevice->sOpts.flags & DEVICE_FLAGS_PREAMBLE_TYPE) ? 1 : 0;
352 pDevice->byOpMode = (pDevice->sOpts.flags & DEVICE_FLAGS_OP_MODE) ? 1 : 0;
353 pDevice->ePSMode = (pDevice->sOpts.flags & DEVICE_FLAGS_PS_MODE) ? 1 : 0;
354 pDevice->b11hEnable = (pDevice->sOpts.flags & DEVICE_FLAGS_80211h_MODE) ? 1 : 0;
355 pDevice->bDiversityRegCtlON = (pDevice->sOpts.flags & DEVICE_FLAGS_DiversityANT) ? 1 : 0;
356 pDevice->uConnectionRate = pDevice->sOpts.data_rate;
357 if (pDevice->uConnectionRate < RATE_AUTO)
358 pDevice->bFixRate = true;
359 pDevice->byBBType = pDevice->sOpts.bbp_type;
360 pDevice->byPacketType = (VIA_PKT_TYPE)pDevice->byBBType;
361 pDevice->byAutoFBCtrl = AUTO_FB_0;
362 pDevice->bUpdateBBVGA = true;
363 pDevice->byFOETuning = 0;
364 pDevice->byPreambleType = 0;
366 pr_debug(" uChannel= %d\n", (int)pDevice->uChannel);
367 pr_debug(" byOpMode= %d\n", (int)pDevice->byOpMode);
368 pr_debug(" ePSMode= %d\n", (int)pDevice->ePSMode);
369 pr_debug(" wRTSThreshold= %d\n", (int)pDevice->wRTSThreshold);
370 pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
371 pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
372 pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType);
373 pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
374 pr_debug(" uConnectionRate= %d\n", (int)pDevice->uConnectionRate);
375 pr_debug(" byBBType= %d\n", (int)pDevice->byBBType);
376 pr_debug(" pDevice->b11hEnable= %d\n", (int)pDevice->b11hEnable);
377 pr_debug(" pDevice->bDiversityRegCtlON= %d\n",
378 (int)pDevice->bDiversityRegCtlON);
382 // Initialisation of MAC & BBP registers
385 static void device_init_registers(struct vnt_private *pDevice)
389 unsigned char byValue;
390 unsigned char byValue1;
391 unsigned char byCCKPwrdBm = 0;
392 unsigned char byOFDMPwrdBm = 0;
394 MACbShutdown(pDevice->PortOffset);
395 BBvSoftwareReset(pDevice->PortOffset);
397 /* Do MACbSoftwareReset in MACvInitialize */
398 MACbSoftwareReset(pDevice->PortOffset);
400 pDevice->bAES = false;
402 /* Only used in 11g type, sync with ERP IE */
403 pDevice->bProtectMode = false;
405 pDevice->bNonERPPresent = false;
406 pDevice->bBarkerPreambleMd = false;
407 pDevice->wCurrentRate = RATE_1M;
408 pDevice->byTopOFDMBasicRate = RATE_24M;
409 pDevice->byTopCCKBasicRate = RATE_1M;
411 /* Target to IF pin while programming to RF chip. */
412 pDevice->byRevId = 0;
415 MACvInitialize(pDevice->PortOffset);
418 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
420 spin_lock_irqsave(&pDevice->lock, flags);
422 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
424 spin_unlock_irqrestore(&pDevice->lock, flags);
426 /* Get Channel range */
427 pDevice->byMinChannel = 1;
428 pDevice->byMaxChannel = CB_MAX_CHANNEL;
431 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
432 if (byValue & EEP_ANTINV)
433 pDevice->bTxRxAntInv = true;
435 pDevice->bTxRxAntInv = false;
437 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
438 /* if not set default is All */
440 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
442 pDevice->ulDiversityNValue = 100*260;
443 pDevice->ulDiversityMValue = 100*16;
445 pDevice->byTMax2 = 4;
446 pDevice->ulSQ3TH = 0;
447 pDevice->byTMax3 = 64;
449 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
450 pDevice->byAntennaCount = 2;
451 pDevice->byTxAntennaMode = ANT_B;
452 pDevice->dwTxAntennaSel = 1;
453 pDevice->dwRxAntennaSel = 1;
455 if (pDevice->bTxRxAntInv)
456 pDevice->byRxAntennaMode = ANT_A;
458 pDevice->byRxAntennaMode = ANT_B;
460 byValue1 = SROMbyReadEmbedded(pDevice->PortOffset,
463 if ((byValue1 & 0x08) == 0)
464 pDevice->bDiversityEnable = false;
466 pDevice->bDiversityEnable = true;
468 pDevice->bDiversityEnable = false;
469 pDevice->byAntennaCount = 1;
470 pDevice->dwTxAntennaSel = 0;
471 pDevice->dwRxAntennaSel = 0;
473 if (byValue & EEP_ANTENNA_AUX) {
474 pDevice->byTxAntennaMode = ANT_A;
476 if (pDevice->bTxRxAntInv)
477 pDevice->byRxAntennaMode = ANT_B;
479 pDevice->byRxAntennaMode = ANT_A;
481 pDevice->byTxAntennaMode = ANT_B;
483 if (pDevice->bTxRxAntInv)
484 pDevice->byRxAntennaMode = ANT_A;
486 pDevice->byRxAntennaMode = ANT_B;
490 pr_debug("bDiversityEnable=[%d],NValue=[%d],MValue=[%d],TMax=[%d],TMax2=[%d]\n",
491 pDevice->bDiversityEnable, (int)pDevice->ulDiversityNValue,
492 (int)pDevice->ulDiversityMValue, pDevice->byTMax,
495 /* zonetype initial */
496 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
499 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
501 /* force change RevID for VT3253 emu */
502 if ((pDevice->byRFType & RF_EMU) != 0)
503 pDevice->byRevId = 0x80;
505 pDevice->byRFType &= RF_MASK;
506 pr_debug("pDevice->byRFType = %x\n", pDevice->byRFType);
508 if (!pDevice->bZoneRegExist)
509 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
511 pr_debug("pDevice->byZoneType = %x\n", pDevice->byZoneType);
516 /* Get Desire Power Value */
517 pDevice->byCurPwr = 0xFF;
518 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
519 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
521 /* Load power Table */
522 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
523 pDevice->abyCCKPwrTbl[ii + 1] =
524 SROMbyReadEmbedded(pDevice->PortOffset,
525 (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
526 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
527 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
529 pDevice->abyOFDMPwrTbl[ii + 1] =
530 SROMbyReadEmbedded(pDevice->PortOffset,
531 (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
532 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
533 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
535 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
536 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
539 /* recover 12,13 ,14channel for EUROPE by 11 channel */
540 for (ii = 11; ii < 14; ii++) {
541 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
542 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
545 /* Load OFDM A Power Table */
546 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
547 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
548 SROMbyReadEmbedded(pDevice->PortOffset,
549 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
551 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
552 SROMbyReadEmbedded(pDevice->PortOffset,
553 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
556 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
557 MACvSelectPage1(pDevice->PortOffset);
559 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
560 (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
562 MACvSelectPage0(pDevice->PortOffset);
565 /* use relative tx timeout and 802.11i D4 */
566 MACvWordRegBitsOn(pDevice->PortOffset,
567 MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
569 /* set performance parameter by registry */
570 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
571 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
573 /* reset TSF counter */
574 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
575 /* enable TSF counter */
576 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
578 /* initialize BBP registers */
579 BBbVT3253Init(pDevice);
581 if (pDevice->bUpdateBBVGA) {
582 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
583 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
584 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
587 BBvSetRxAntennaMode(pDevice->PortOffset, pDevice->byRxAntennaMode);
588 BBvSetTxAntennaMode(pDevice->PortOffset, pDevice->byTxAntennaMode);
590 /* Set BB and packet type at the same time. */
591 /* Set Short Slot Time, xIFS, and RSPINF. */
592 if (pDevice->uConnectionRate == RATE_AUTO)
593 pDevice->wCurrentRate = RATE_54M;
595 pDevice->wCurrentRate = (unsigned short)pDevice->uConnectionRate;
597 pDevice->bRadioOff = false;
599 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
601 pDevice->bHWRadioOff = false;
603 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
605 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
607 if (((pDevice->byGPIO & GPIO0_DATA) &&
608 !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
609 (!(pDevice->byGPIO & GPIO0_DATA) &&
610 (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
611 pDevice->bHWRadioOff = true;
614 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
615 CARDbRadioPowerOff(pDevice);
617 /* get Permanent network address */
618 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
619 pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
621 /* reset Tx pointer */
622 CARDvSafeResetRx(pDevice);
623 /* reset Rx pointer */
624 CARDvSafeResetTx(pDevice);
626 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
627 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
630 MACvReceive0(pDevice->PortOffset);
631 MACvReceive1(pDevice->PortOffset);
633 /* start the adapter */
634 MACvStart(pDevice->PortOffset);
637 static void device_init_diversity_timer(struct vnt_private *pDevice)
639 init_timer(&pDevice->TimerSQ3Tmax1);
640 pDevice->TimerSQ3Tmax1.data = (unsigned long) pDevice;
641 pDevice->TimerSQ3Tmax1.function = (TimerFunction)TimerSQ3CallBack;
642 pDevice->TimerSQ3Tmax1.expires = RUN_AT(HZ);
644 init_timer(&pDevice->TimerSQ3Tmax2);
645 pDevice->TimerSQ3Tmax2.data = (unsigned long) pDevice;
646 pDevice->TimerSQ3Tmax2.function = (TimerFunction)TimerSQ3CallBack;
647 pDevice->TimerSQ3Tmax2.expires = RUN_AT(HZ);
649 init_timer(&pDevice->TimerSQ3Tmax3);
650 pDevice->TimerSQ3Tmax3.data = (unsigned long) pDevice;
651 pDevice->TimerSQ3Tmax3.function = (TimerFunction)TimerState1CallBack;
652 pDevice->TimerSQ3Tmax3.expires = RUN_AT(HZ);
655 static void device_print_info(struct vnt_private *pDevice)
657 dev_info(&pDevice->pcid->dev, "%s\n", get_chip_name(pDevice->chip_id));
659 dev_info(&pDevice->pcid->dev, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
660 pDevice->abyCurrentNetAddr, (unsigned long)pDevice->ioaddr,
661 (unsigned long)pDevice->PortOffset, pDevice->pcid->irq);
664 static void vt6655_init_info(struct pci_dev *pcid,
665 struct vnt_private **ppDevice,
666 PCHIP_INFO pChip_info)
668 memset(*ppDevice, 0, sizeof(**ppDevice));
670 (*ppDevice)->pcid = pcid;
671 (*ppDevice)->chip_id = pChip_info->chip_id;
672 (*ppDevice)->io_size = pChip_info->io_size;
673 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
674 (*ppDevice)->multicast_limit = 32;
676 spin_lock_init(&((*ppDevice)->lock));
679 static bool device_get_pci_info(struct vnt_private *pDevice,
680 struct pci_dev *pcid)
684 unsigned int cis_addr;
686 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
687 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
688 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
689 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
691 pci_set_master(pcid);
693 pDevice->memaddr = pci_resource_start(pcid, 0);
694 pDevice->ioaddr = pci_resource_start(pcid, 1);
696 cis_addr = pci_resource_start(pcid, 2);
698 pDevice->pcid = pcid;
700 pci_read_config_byte(pcid, PCI_COMMAND, &b);
701 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
706 static void device_free_info(struct vnt_private *pDevice)
712 ieee80211_unregister_hw(pDevice->hw);
714 if (pDevice->PortOffset)
715 iounmap(pDevice->PortOffset);
718 pci_release_regions(pDevice->pcid);
721 ieee80211_free_hw(pDevice->hw);
724 static bool device_init_rings(struct vnt_private *pDevice)
728 /*allocate all RD/TD rings a single pool*/
729 vir_pool = pci_zalloc_consistent(pDevice->pcid,
730 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
731 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
732 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
733 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
735 if (vir_pool == NULL) {
736 dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n");
740 pDevice->aRD0Ring = vir_pool;
741 pDevice->aRD1Ring = vir_pool +
742 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
744 pDevice->rd0_pool_dma = pDevice->pool_dma;
745 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
746 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
748 pDevice->tx0_bufs = pci_zalloc_consistent(pDevice->pcid,
749 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
750 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
753 &pDevice->tx_bufs_dma0);
754 if (pDevice->tx0_bufs == NULL) {
755 dev_err(&pDevice->pcid->dev, "allocate buf dma memory failed\n");
757 pci_free_consistent(pDevice->pcid,
758 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
759 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
760 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
761 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
762 vir_pool, pDevice->pool_dma
767 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
768 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
770 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
771 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
773 // vir_pool: pvoid type
774 pDevice->apTD0Rings = vir_pool
775 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
776 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
778 pDevice->apTD1Rings = vir_pool
779 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
780 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
781 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
783 pDevice->tx1_bufs = pDevice->tx0_bufs +
784 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
786 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
787 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
789 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
792 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
793 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
795 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
796 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
801 static void device_free_rings(struct vnt_private *pDevice)
803 pci_free_consistent(pDevice->pcid,
804 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
805 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
806 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
807 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
809 pDevice->aRD0Ring, pDevice->pool_dma
812 if (pDevice->tx0_bufs)
813 pci_free_consistent(pDevice->pcid,
814 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
815 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
818 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
822 static void device_init_rd0_ring(struct vnt_private *pDevice)
825 dma_addr_t curr = pDevice->rd0_pool_dma;
828 /* Init the RD0 ring entries */
829 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
830 pDesc = &(pDevice->aRD0Ring[i]);
831 pDesc->pRDInfo = alloc_rd_info();
832 ASSERT(pDesc->pRDInfo);
833 if (!device_alloc_rx_buf(pDevice, pDesc))
834 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
836 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
837 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
838 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
842 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
843 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
846 static void device_init_rd1_ring(struct vnt_private *pDevice)
849 dma_addr_t curr = pDevice->rd1_pool_dma;
852 /* Init the RD1 ring entries */
853 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
854 pDesc = &(pDevice->aRD1Ring[i]);
855 pDesc->pRDInfo = alloc_rd_info();
856 ASSERT(pDesc->pRDInfo);
857 if (!device_alloc_rx_buf(pDevice, pDesc))
858 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
860 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
861 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
862 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
866 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
867 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
870 static void device_init_defrag_cb(struct vnt_private *pDevice)
873 PSDeFragControlBlock pDeF;
875 /* Init the fragment ctl entries */
876 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
877 pDeF = &(pDevice->sRxDFCB[i]);
878 if (!device_alloc_frag_buf(pDevice, pDeF))
879 dev_err(&pDevice->pcid->dev, "can not alloc frag bufs\n");
881 pDevice->cbDFCB = CB_MAX_RX_FRAG;
882 pDevice->cbFreeDFCB = pDevice->cbDFCB;
885 static void device_free_rd0_ring(struct vnt_private *pDevice)
889 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
890 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
891 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
893 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
894 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
896 dev_kfree_skb(pRDInfo->skb);
898 kfree(pDesc->pRDInfo);
902 static void device_free_rd1_ring(struct vnt_private *pDevice)
906 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
907 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
908 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
910 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
911 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
913 dev_kfree_skb(pRDInfo->skb);
915 kfree(pDesc->pRDInfo);
919 static void device_free_frag_buf(struct vnt_private *pDevice)
921 PSDeFragControlBlock pDeF;
924 for (i = 0; i < CB_MAX_RX_FRAG; i++) {
925 pDeF = &(pDevice->sRxDFCB[i]);
928 dev_kfree_skb(pDeF->skb);
933 static void device_init_td0_ring(struct vnt_private *pDevice)
939 curr = pDevice->td0_pool_dma;
940 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
941 pDesc = &(pDevice->apTD0Rings[i]);
942 pDesc->pTDInfo = alloc_td_info();
943 ASSERT(pDesc->pTDInfo);
944 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
945 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
946 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
948 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
949 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
950 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
954 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
955 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
958 static void device_init_td1_ring(struct vnt_private *pDevice)
964 /* Init the TD ring entries */
965 curr = pDevice->td1_pool_dma;
966 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
967 pDesc = &(pDevice->apTD1Rings[i]);
968 pDesc->pTDInfo = alloc_td_info();
969 ASSERT(pDesc->pTDInfo);
970 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
971 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
972 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
974 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
975 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
976 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
980 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
981 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
984 static void device_free_td0_ring(struct vnt_private *pDevice)
988 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
989 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
990 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
992 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
993 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
994 pTDInfo->skb->len, PCI_DMA_TODEVICE);
997 dev_kfree_skb(pTDInfo->skb);
999 kfree(pDesc->pTDInfo);
1003 static void device_free_td1_ring(struct vnt_private *pDevice)
1007 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
1008 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
1009 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1011 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
1012 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
1013 pTDInfo->skb->len, PCI_DMA_TODEVICE);
1016 dev_kfree_skb(pTDInfo->skb);
1018 kfree(pDesc->pTDInfo);
1022 /*-----------------------------------------------------------------*/
1024 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1029 for (pRD = pDevice->pCurrRD[uIdx];
1030 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
1034 if (vnt_receive_frame(pDevice, pRD)) {
1035 if (!device_alloc_rx_buf(pDevice, pRD)) {
1036 dev_err(&pDevice->pcid->dev,
1037 "can not allocate rx buf\n");
1041 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1044 pDevice->pCurrRD[uIdx] = pRD;
1049 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
1051 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
1053 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1054 if (pRDInfo->skb == NULL)
1056 ASSERT(pRDInfo->skb);
1059 pci_map_single(pDevice->pcid,
1060 skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)),
1061 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
1063 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
1065 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
1066 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
1067 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
1068 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
1073 bool device_alloc_frag_buf(struct vnt_private *pDevice,
1074 PSDeFragControlBlock pDeF)
1076 pDeF->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1077 if (pDeF->skb == NULL)
1084 static const u8 fallback_rate0[5][5] = {
1085 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
1086 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
1087 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
1088 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
1089 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
1092 static const u8 fallback_rate1[5][5] = {
1093 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
1094 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
1095 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
1096 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
1097 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
1100 static int vnt_int_report_rate(struct vnt_private *priv,
1101 PDEVICE_TD_INFO context, u8 tsr0, u8 tsr1)
1103 struct vnt_tx_fifo_head *fifo_head;
1104 struct ieee80211_tx_info *info;
1105 struct ieee80211_rate *rate;
1107 u8 tx_retry = (tsr0 & TSR0_NCR);
1116 fifo_head = (struct vnt_tx_fifo_head *)context->buf;
1117 fb_option = (le16_to_cpu(fifo_head->fifo_ctl) &
1118 (FIFOCTL_AUTO_FB_0 | FIFOCTL_AUTO_FB_1));
1120 info = IEEE80211_SKB_CB(context->skb);
1121 idx = info->control.rates[0].idx;
1123 if (fb_option && !(tsr1 & TSR1_TERR)) {
1125 u8 retry = tx_retry;
1127 rate = ieee80211_get_tx_rate(priv->hw, info);
1128 tx_rate = rate->hw_value - RATE_18M;
1133 if (fb_option & FIFOCTL_AUTO_FB_0)
1134 tx_rate = fallback_rate0[tx_rate][retry];
1135 else if (fb_option & FIFOCTL_AUTO_FB_1)
1136 tx_rate = fallback_rate1[tx_rate][retry];
1138 if (info->band == IEEE80211_BAND_5GHZ)
1139 idx = tx_rate - RATE_6M;
1144 ieee80211_tx_info_clear_status(info);
1146 info->status.rates[0].count = tx_retry;
1148 if (!(tsr1 & TSR1_TERR)) {
1149 info->status.rates[0].idx = idx;
1150 info->flags |= IEEE80211_TX_STAT_ACK;
1156 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
1160 unsigned char byTsr0;
1161 unsigned char byTsr1;
1163 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
1164 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
1169 byTsr0 = pTD->m_td0TD0.byTSR0;
1170 byTsr1 = pTD->m_td0TD0.byTSR1;
1172 //Only the status of first TD in the chain is correct
1173 if (pTD->m_td1TD1.byTCR & TCR_STP) {
1174 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
1176 vnt_int_report_rate(pDevice, pTD->pTDInfo, byTsr0, byTsr1);
1178 if (!(byTsr1 & TSR1_TERR)) {
1180 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
1185 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
1186 (int)uIdx, byTsr1, byTsr0);
1190 if (byTsr1 & TSR1_TERR) {
1191 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
1192 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
1193 (int)uIdx, byTsr1, byTsr0);
1196 device_free_tx_buf(pDevice, pTD);
1197 pDevice->iTDUsed[uIdx]--;
1199 /* Make sure queue is available */
1200 if (AVAIL_TD(pDevice, uIdx))
1201 ieee80211_wake_queues(pDevice->hw);
1205 pDevice->apTailTD[uIdx] = pTD;
1210 static void device_error(struct vnt_private *pDevice, unsigned short status)
1212 if (status & ISR_FETALERR) {
1213 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
1215 MACbShutdown(pDevice->PortOffset);
1220 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
1222 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
1223 struct sk_buff *skb = pTDInfo->skb;
1225 // pre-allocated buf_dma can't be unmapped.
1226 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
1227 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1231 if (pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)
1232 ieee80211_tx_status_irqsafe(pDevice->hw, skb);
1234 dev_kfree_skb_irq(skb);
1236 pTDInfo->skb_dma = 0;
1237 pTDInfo->skb = NULL;
1238 pTDInfo->byFlags = 0;
1241 static irqreturn_t device_intr(int irq, void *dev_instance)
1243 struct vnt_private *pDevice = dev_instance;
1245 unsigned long dwMIBCounter = 0;
1246 unsigned char byOrgPageSel = 0;
1249 unsigned long flags;
1251 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
1253 if (pDevice->dwIsr == 0)
1254 return IRQ_RETVAL(handled);
1256 if (pDevice->dwIsr == 0xffffffff) {
1257 pr_debug("dwIsr = 0xffff\n");
1258 return IRQ_RETVAL(handled);
1262 MACvIntDisable(pDevice->PortOffset);
1264 spin_lock_irqsave(&pDevice->lock, flags);
1266 //Make sure current page is 0
1267 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
1268 if (byOrgPageSel == 1)
1269 MACvSelectPage0(pDevice->PortOffset);
1273 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
1275 // Must do this after doing rx/tx, cause ISR bit is slow
1276 // than RD/TD write back
1277 // update ISR counter
1278 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic , dwMIBCounter);
1279 while (pDevice->dwIsr != 0) {
1280 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
1281 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
1283 if (pDevice->dwIsr & ISR_FETALERR) {
1284 pr_debug(" ISR_FETALERR\n");
1285 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
1286 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
1287 device_error(pDevice, pDevice->dwIsr);
1290 if (pDevice->dwIsr & ISR_TBTT) {
1292 pDevice->op_mode != NL80211_IFTYPE_ADHOC) {
1293 if (pDevice->bUpdateBBVGA &&
1294 !(pDevice->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) &&
1295 pDevice->vif->bss_conf.assoc &&
1296 pDevice->uCurrRSSI) {
1299 RFvRSSITodBm(pDevice, (unsigned char) pDevice->uCurrRSSI, &ldBm);
1300 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
1301 if (ldBm < pDevice->ldBmThreshold[ii]) {
1302 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1306 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1307 pDevice->uBBVGADiffCount++;
1308 if (pDevice->uBBVGADiffCount == 1) {
1309 // first VGA diff gain
1310 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
1311 pr_debug("First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1313 pDevice->byBBVGANew,
1314 pDevice->byBBVGACurrent,
1315 (int)pDevice->uBBVGADiffCount);
1317 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
1318 pr_debug("RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1320 pDevice->byBBVGANew,
1321 pDevice->byBBVGACurrent,
1322 (int)pDevice->uBBVGADiffCount);
1323 BBvSetVGAGainOffset(pDevice, pDevice->byBBVGANew);
1326 pDevice->uBBVGADiffCount = 1;
1331 pDevice->bBeaconSent = false;
1332 if (pDevice->bEnablePSMode)
1333 PSbIsNextTBTTWakeUp((void *)pDevice);
1335 if ((pDevice->op_mode == NL80211_IFTYPE_AP ||
1336 pDevice->op_mode == NL80211_IFTYPE_ADHOC) &&
1337 pDevice->vif->bss_conf.enable_beacon) {
1338 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
1339 (pDevice->vif->bss_conf.beacon_int - MAKE_BEACON_RESERVED) << 10);
1342 /* TODO: adhoc PS mode */
1346 if (pDevice->dwIsr & ISR_BNTX) {
1347 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
1348 pDevice->bIsBeaconBufReadySet = false;
1349 pDevice->cbBeaconBufReadySetCnt = 0;
1352 pDevice->bBeaconSent = true;
1355 if (pDevice->dwIsr & ISR_RXDMA0)
1356 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
1358 if (pDevice->dwIsr & ISR_RXDMA1)
1359 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
1361 if (pDevice->dwIsr & ISR_TXDMA0)
1362 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
1364 if (pDevice->dwIsr & ISR_AC0DMA)
1365 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
1367 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
1369 if (pDevice->vif->bss_conf.enable_beacon)
1370 vnt_beacon_make(pDevice, pDevice->vif);
1374 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
1376 MACvReceive0(pDevice->PortOffset);
1377 MACvReceive1(pDevice->PortOffset);
1379 if (max_count > pDevice->sOpts.int_works)
1383 if (byOrgPageSel == 1)
1384 MACvSelectPage1(pDevice->PortOffset);
1386 spin_unlock_irqrestore(&pDevice->lock, flags);
1388 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1390 return IRQ_RETVAL(handled);
1393 static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1395 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1397 u32 dma_idx = TYPE_AC0DMA;
1398 unsigned long flags;
1400 spin_lock_irqsave(&priv->lock, flags);
1402 if (!ieee80211_is_data(hdr->frame_control))
1403 dma_idx = TYPE_TXDMA0;
1405 if (AVAIL_TD(priv, dma_idx) < 1) {
1406 spin_unlock_irqrestore(&priv->lock, flags);
1410 head_td = priv->apCurrTD[dma_idx];
1412 head_td->m_td1TD1.byTCR = (TCR_EDP|TCR_STP);
1414 head_td->pTDInfo->skb = skb;
1416 priv->iTDUsed[dma_idx]++;
1418 /* Take ownership */
1420 head_td->m_td0TD0.f1Owner = OWNED_BY_NIC;
1424 priv->apCurrTD[dma_idx] = head_td->next;
1426 spin_unlock_irqrestore(&priv->lock, flags);
1428 vnt_generate_fifo_header(priv, dma_idx, head_td, skb);
1430 if (MACbIsRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
1431 MACbPSWakeup(priv->PortOffset);
1433 spin_lock_irqsave(&priv->lock, flags);
1435 priv->bPWBitOn = false;
1437 head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB;
1439 if (dma_idx == TYPE_AC0DMA)
1440 MACvTransmitAC0(priv->PortOffset);
1442 MACvTransmit0(priv->PortOffset);
1444 spin_unlock_irqrestore(&priv->lock, flags);
1449 static void vnt_tx_80211(struct ieee80211_hw *hw,
1450 struct ieee80211_tx_control *control,
1451 struct sk_buff *skb)
1453 struct vnt_private *priv = hw->priv;
1455 ieee80211_stop_queues(hw);
1457 if (vnt_tx_packet(priv, skb)) {
1458 ieee80211_free_txskb(hw, skb);
1460 ieee80211_wake_queues(hw);
1464 static int vnt_start(struct ieee80211_hw *hw)
1466 struct vnt_private *priv = hw->priv;
1469 priv->rx_buf_sz = PKT_BUF_SZ;
1470 if (!device_init_rings(priv))
1473 ret = request_irq(priv->pcid->irq, &device_intr,
1474 IRQF_SHARED, "vt6655", priv);
1476 dev_dbg(&priv->pcid->dev, "failed to start irq\n");
1480 dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
1481 device_init_rd0_ring(priv);
1482 device_init_rd1_ring(priv);
1483 device_init_defrag_cb(priv);
1484 device_init_td0_ring(priv);
1485 device_init_td1_ring(priv);
1487 device_init_registers(priv);
1489 dev_dbg(&priv->pcid->dev, "call MACvIntEnable\n");
1490 MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
1492 ieee80211_wake_queues(hw);
1497 static void vnt_stop(struct ieee80211_hw *hw)
1499 struct vnt_private *priv = hw->priv;
1501 ieee80211_stop_queues(hw);
1503 MACbShutdown(priv->PortOffset);
1504 MACbSoftwareReset(priv->PortOffset);
1505 CARDbRadioPowerOff(priv);
1507 device_free_td0_ring(priv);
1508 device_free_td1_ring(priv);
1509 device_free_rd0_ring(priv);
1510 device_free_rd1_ring(priv);
1511 device_free_frag_buf(priv);
1512 device_free_rings(priv);
1514 free_irq(priv->pcid->irq, priv);
1517 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1519 struct vnt_private *priv = hw->priv;
1523 switch (vif->type) {
1524 case NL80211_IFTYPE_STATION:
1525 if (priv->bDiversityRegCtlON)
1526 device_init_diversity_timer(priv);
1528 case NL80211_IFTYPE_ADHOC:
1529 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1531 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1534 case NL80211_IFTYPE_AP:
1535 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1537 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1544 priv->op_mode = vif->type;
1549 static void vnt_remove_interface(struct ieee80211_hw *hw,
1550 struct ieee80211_vif *vif)
1552 struct vnt_private *priv = hw->priv;
1554 switch (vif->type) {
1555 case NL80211_IFTYPE_STATION:
1556 if (priv->bDiversityRegCtlON) {
1557 del_timer(&priv->TimerSQ3Tmax1);
1558 del_timer(&priv->TimerSQ3Tmax2);
1559 del_timer(&priv->TimerSQ3Tmax3);
1562 case NL80211_IFTYPE_ADHOC:
1563 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1564 MACvRegBitsOff(priv->PortOffset,
1565 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1566 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1568 case NL80211_IFTYPE_AP:
1569 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1570 MACvRegBitsOff(priv->PortOffset,
1571 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1572 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1578 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
1582 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
1584 struct vnt_private *priv = hw->priv;
1585 struct ieee80211_conf *conf = &hw->conf;
1588 if (changed & IEEE80211_CONF_CHANGE_PS) {
1589 if (conf->flags & IEEE80211_CONF_PS)
1590 PSvEnablePowerSaving(priv, conf->listen_interval);
1592 PSvDisablePowerSaving(priv);
1595 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
1596 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
1597 set_channel(priv, conf->chandef.chan->hw_value);
1599 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
1600 bb_type = BB_TYPE_11A;
1602 bb_type = BB_TYPE_11G;
1604 if (priv->byBBType != bb_type) {
1605 priv->byBBType = bb_type;
1607 CARDbSetPhyParameter(priv,
1608 priv->byBBType, 0, 0, NULL, NULL);
1612 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1613 if (priv->byBBType == BB_TYPE_11B)
1614 priv->wCurrentRate = RATE_1M;
1616 priv->wCurrentRate = RATE_54M;
1618 RFbSetPower(priv, priv->wCurrentRate,
1619 conf->chandef.chan->hw_value);
1625 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
1626 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
1629 struct vnt_private *priv = hw->priv;
1631 priv->current_aid = conf->aid;
1633 if (changed & BSS_CHANGED_BSSID)
1634 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid);
1636 if (changed & BSS_CHANGED_BASIC_RATES) {
1637 priv->basic_rates = conf->basic_rates;
1639 CARDvUpdateBasicTopRate(priv);
1641 dev_dbg(&priv->pcid->dev,
1642 "basic rates %x\n", conf->basic_rates);
1645 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1646 if (conf->use_short_preamble) {
1647 MACvEnableBarkerPreambleMd(priv->PortOffset);
1648 priv->byPreambleType = true;
1650 MACvDisableBarkerPreambleMd(priv->PortOffset);
1651 priv->byPreambleType = false;
1655 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1656 if (conf->use_cts_prot)
1657 MACvEnableProtectMD(priv->PortOffset);
1659 MACvDisableProtectMD(priv->PortOffset);
1662 if (changed & BSS_CHANGED_ERP_SLOT) {
1663 if (conf->use_short_slot)
1664 priv->bShortSlotTime = true;
1666 priv->bShortSlotTime = false;
1669 CARDbSetPhyParameter(priv, priv->byBBType, 0, 0, NULL, NULL);
1670 BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
1673 if (changed & BSS_CHANGED_TXPOWER)
1674 RFbSetPower(priv, priv->wCurrentRate,
1675 conf->chandef.chan->hw_value);
1677 if (changed & BSS_CHANGED_BEACON_ENABLED) {
1678 dev_dbg(&priv->pcid->dev,
1679 "Beacon enable %d\n", conf->enable_beacon);
1681 if (conf->enable_beacon) {
1682 vnt_beacon_enable(priv, vif, conf);
1684 MACvRegBitsOn(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1686 MACvRegBitsOff(priv, MAC_REG_TCR, TCR_AUTOBCNTX);
1690 if (changed & BSS_CHANGED_ASSOC && priv->op_mode != NL80211_IFTYPE_AP) {
1692 CARDbUpdateTSF(priv, conf->beacon_rate->hw_value,
1693 conf->sync_device_ts, conf->sync_tsf);
1695 CARDbSetBeaconPeriod(priv, conf->beacon_int);
1697 CARDvSetFirstNextTBTT(priv->PortOffset,
1700 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1702 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1708 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
1709 struct netdev_hw_addr_list *mc_list)
1711 struct vnt_private *priv = hw->priv;
1712 struct netdev_hw_addr *ha;
1716 netdev_hw_addr_list_for_each(ha, mc_list) {
1717 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1719 mc_filter |= 1ULL << (bit_nr & 0x3f);
1722 priv->mc_list_count = mc_list->count;
1727 static void vnt_configure(struct ieee80211_hw *hw,
1728 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
1730 struct vnt_private *priv = hw->priv;
1733 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_PROMISC_IN_BSS |
1734 FIF_BCN_PRBRESP_PROMISC;
1736 VNSvInPortB(priv->PortOffset + MAC_REG_RCR, &rx_mode);
1738 dev_dbg(&priv->pcid->dev, "rx mode in = %x\n", rx_mode);
1740 if (changed_flags & FIF_PROMISC_IN_BSS) {
1741 /* unconditionally log net taps */
1742 if (*total_flags & FIF_PROMISC_IN_BSS)
1743 rx_mode |= RCR_UNICAST;
1745 rx_mode &= ~RCR_UNICAST;
1748 if (changed_flags & FIF_ALLMULTI) {
1749 if (*total_flags & FIF_ALLMULTI) {
1750 if (priv->mc_list_count > 2) {
1751 MACvSelectPage1(priv->PortOffset);
1753 VNSvOutPortD(priv->PortOffset +
1754 MAC_REG_MAR0, 0xffffffff);
1755 VNSvOutPortD(priv->PortOffset +
1756 MAC_REG_MAR0 + 4, 0xffffffff);
1758 MACvSelectPage0(priv->PortOffset);
1760 MACvSelectPage1(priv->PortOffset);
1762 VNSvOutPortD(priv->PortOffset +
1763 MAC_REG_MAR0, (u32)multicast);
1764 VNSvOutPortD(priv->PortOffset +
1766 (u32)(multicast >> 32));
1768 MACvSelectPage0(priv->PortOffset);
1771 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1773 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
1777 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
1778 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1780 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
1781 rx_mode &= ~RCR_BSSID;
1783 rx_mode |= RCR_BSSID;
1786 VNSvOutPortB(priv->PortOffset + MAC_REG_RCR, rx_mode);
1788 dev_dbg(&priv->pcid->dev, "rx mode out= %x\n", rx_mode);
1791 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1792 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1793 struct ieee80211_key_conf *key)
1795 struct vnt_private *priv = hw->priv;
1799 if (vnt_set_keys(hw, sta, vif, key))
1803 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
1804 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
1812 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1814 struct vnt_private *priv = hw->priv;
1817 CARDbGetCurrentTSF(priv->PortOffset, &tsf);
1822 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1825 struct vnt_private *priv = hw->priv;
1827 CARDvUpdateNextTBTT(priv->PortOffset, tsf, vif->bss_conf.beacon_int);
1830 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1832 struct vnt_private *priv = hw->priv;
1834 /* reset TSF counter */
1835 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1838 static const struct ieee80211_ops vnt_mac_ops = {
1842 .add_interface = vnt_add_interface,
1843 .remove_interface = vnt_remove_interface,
1844 .config = vnt_config,
1845 .bss_info_changed = vnt_bss_info_changed,
1846 .prepare_multicast = vnt_prepare_multicast,
1847 .configure_filter = vnt_configure,
1848 .set_key = vnt_set_key,
1849 .get_tsf = vnt_get_tsf,
1850 .set_tsf = vnt_set_tsf,
1851 .reset_tsf = vnt_reset_tsf,
1854 int vnt_init(struct vnt_private *priv)
1856 SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyCurrentNetAddr);
1858 vnt_init_bands(priv);
1860 if (ieee80211_register_hw(priv->hw))
1863 priv->mac_hw = true;
1865 CARDbRadioPowerOff(priv);
1871 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
1873 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
1874 struct vnt_private *priv;
1875 struct ieee80211_hw *hw;
1876 struct wiphy *wiphy;
1879 dev_notice(&pcid->dev,
1880 "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1882 dev_notice(&pcid->dev,
1883 "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
1885 hw = ieee80211_alloc_hw(sizeof(*priv), &vnt_mac_ops);
1887 dev_err(&pcid->dev, "could not register ieee80211_hw\n");
1893 vt6655_init_info(pcid, &priv, pChip_info);
1897 SET_IEEE80211_DEV(priv->hw, &pcid->dev);
1899 if (pci_enable_device(pcid)) {
1900 device_free_info(priv);
1905 "Before get pci_info memaddr is %x\n", priv->memaddr);
1907 if (!device_get_pci_info(priv, pcid)) {
1908 dev_err(&pcid->dev, ": Failed to find PCI device.\n");
1909 device_free_info(priv);
1915 "after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",
1916 priv->memaddr, priv->ioaddr, priv->io_size);
1928 for (i = 0; address[i]; i++) {
1929 pci_read_config_dword(pcid, address[i], &bar);
1931 dev_dbg(&pcid->dev, "bar %d is %x\n", i, bar);
1935 "bar %d not implemented\n", i);
1939 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
1942 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xffff);
1943 len = len & ~(len - 1);
1946 "IO space: len in IO %x, BAR %d\n",
1949 len = bar & 0xfffffff0;
1953 "len in MEM %x, BAR %d\n", len, i);
1959 priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK,
1961 if (!priv->PortOffset) {
1962 dev_err(&pcid->dev, ": Failed to IO remapping ..\n");
1963 device_free_info(priv);
1967 rc = pci_request_regions(pcid, DEVICE_NAME);
1969 dev_err(&pcid->dev, ": Failed to find PCI device\n");
1970 device_free_info(priv);
1975 if (!MACbSoftwareReset(priv->PortOffset)) {
1976 dev_err(&pcid->dev, ": Failed to access MAC hardware..\n");
1977 device_free_info(priv);
1980 /* initial to reload eeprom */
1981 MACvInitialize(priv->PortOffset);
1982 MACvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr);
1984 device_get_options(priv);
1985 device_set_options(priv);
1986 /* Mask out the options cannot be set to the chip */
1987 priv->sOpts.flags &= pChip_info->flags;
1989 /* Enable the chip specified capabilities */
1990 priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL);
1992 wiphy = priv->hw->wiphy;
1994 wiphy->frag_threshold = FRAG_THRESH_DEF;
1995 wiphy->rts_threshold = RTS_THRESH_DEF;
1996 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1997 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1999 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
2000 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
2001 IEEE80211_HW_SIGNAL_DBM |
2002 IEEE80211_HW_TIMING_BEACON_ONLY;
2004 priv->hw->max_signal = 100;
2009 device_print_info(priv);
2010 pci_set_drvdata(pcid, priv);
2015 /*------------------------------------------------------------------*/
2018 static int vt6655_suspend(struct pci_dev *pcid, pm_message_t state)
2020 struct vnt_private *priv = pci_get_drvdata(pcid);
2021 unsigned long flags;
2023 spin_lock_irqsave(&priv->lock, flags);
2025 pci_save_state(pcid);
2027 MACbShutdown(priv->PortOffset);
2029 pci_disable_device(pcid);
2030 pci_set_power_state(pcid, pci_choose_state(pcid, state));
2032 spin_unlock_irqrestore(&priv->lock, flags);
2037 static int vt6655_resume(struct pci_dev *pcid)
2040 pci_set_power_state(pcid, PCI_D0);
2041 pci_enable_wake(pcid, PCI_D0, 0);
2042 pci_restore_state(pcid);
2048 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
2050 static struct pci_driver device_driver = {
2051 .name = DEVICE_NAME,
2052 .id_table = vt6655_pci_id_table,
2053 .probe = vt6655_probe,
2054 .remove = vt6655_remove,
2056 .suspend = vt6655_suspend,
2057 .resume = vt6655_resume,
2061 static int __init vt6655_init_module(void)
2065 ret = pci_register_driver(&device_driver);
2068 register_reboot_notifier(&device_notifier);
2074 static void __exit vt6655_cleanup_module(void)
2077 unregister_reboot_notifier(&device_notifier);
2079 pci_unregister_driver(&device_driver);
2082 module_init(vt6655_init_module);
2083 module_exit(vt6655_cleanup_module);
2087 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
2089 struct pci_dev *pdev = NULL;
2095 for_each_pci_dev(pdev) {
2096 if (pci_dev_driver(pdev) == &device_driver) {
2097 if (pci_get_drvdata(pdev))
2098 vt6655_suspend(pdev, PMSG_HIBERNATE);