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_free_tx_buf - free tx buffer function
39 * device_init_rd0_ring- initial rd dma0 ring
40 * device_init_rd1_ring- initial rd dma1 ring
41 * device_init_td0_ring- initial tx dma0 ring buffer
42 * device_init_td1_ring- initial tx dma1 ring buffer
43 * device_init_registers- initial MAC & BBP & RF internal registers.
44 * device_init_rings- initial tx/rx ring buffer
45 * device_free_rings- free all allocated ring buffer
46 * device_tx_srv- tx interrupt service function
52 #include <linux/file.h>
62 #include <linux/delay.h>
63 #include <linux/kthread.h>
64 #include <linux/slab.h>
66 /*--------------------- Static Definitions -------------------------*/
68 // Define module options
70 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
71 MODULE_LICENSE("GPL");
72 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
74 #define DEVICE_PARAM(N, D)
76 #define RX_DESC_MIN0 16
77 #define RX_DESC_MAX0 128
78 #define RX_DESC_DEF0 32
79 DEVICE_PARAM(RxDescriptors0, "Number of receive descriptors0");
81 #define RX_DESC_MIN1 16
82 #define RX_DESC_MAX1 128
83 #define RX_DESC_DEF1 32
84 DEVICE_PARAM(RxDescriptors1, "Number of receive descriptors1");
86 #define TX_DESC_MIN0 16
87 #define TX_DESC_MAX0 128
88 #define TX_DESC_DEF0 32
89 DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
91 #define TX_DESC_MIN1 16
92 #define TX_DESC_MAX1 128
93 #define TX_DESC_DEF1 64
94 DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
96 #define INT_WORKS_DEF 20
97 #define INT_WORKS_MIN 10
98 #define INT_WORKS_MAX 64
100 DEVICE_PARAM(int_works, "Number of packets per interrupt services");
102 #define RTS_THRESH_DEF 2347
104 #define FRAG_THRESH_DEF 2346
106 #define SHORT_RETRY_MIN 0
107 #define SHORT_RETRY_MAX 31
108 #define SHORT_RETRY_DEF 8
110 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
112 #define LONG_RETRY_MIN 0
113 #define LONG_RETRY_MAX 15
114 #define LONG_RETRY_DEF 4
116 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
118 /* BasebandType[] baseband type selected
119 0: indicate 802.11a type
120 1: indicate 802.11b type
121 2: indicate 802.11g type
123 #define BBP_TYPE_MIN 0
124 #define BBP_TYPE_MAX 2
125 #define BBP_TYPE_DEF 2
127 DEVICE_PARAM(BasebandType, "baseband type");
130 // Static vars definitions
132 static CHIP_INFO chip_info_table[] = {
133 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
134 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
138 static const struct pci_device_id vt6655_pci_id_table[] = {
139 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
143 /*--------------------- Static Functions --------------------------*/
145 static int vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent);
146 static void vt6655_init_info(struct pci_dev *pcid,
147 struct vnt_private **ppDevice, PCHIP_INFO);
148 static void device_free_info(struct vnt_private *pDevice);
149 static bool device_get_pci_info(struct vnt_private *, struct pci_dev *pcid);
150 static void device_print_info(struct vnt_private *pDevice);
151 static irqreturn_t device_intr(int irq, void *dev_instance);
154 static int device_notify_reboot(struct notifier_block *, unsigned long event, void *ptr);
155 static struct notifier_block device_notifier = {
156 .notifier_call = device_notify_reboot,
162 static void device_init_rd0_ring(struct vnt_private *pDevice);
163 static void device_init_rd1_ring(struct vnt_private *pDevice);
164 static void device_init_td0_ring(struct vnt_private *pDevice);
165 static void device_init_td1_ring(struct vnt_private *pDevice);
167 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx);
168 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx);
169 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pDesc);
170 static void device_init_registers(struct vnt_private *pDevice);
171 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc);
172 static void device_free_td0_ring(struct vnt_private *pDevice);
173 static void device_free_td1_ring(struct vnt_private *pDevice);
174 static void device_free_rd0_ring(struct vnt_private *pDevice);
175 static void device_free_rd1_ring(struct vnt_private *pDevice);
176 static void device_free_rings(struct vnt_private *pDevice);
178 /*--------------------- Export Variables --------------------------*/
180 /*--------------------- Export Functions --------------------------*/
182 static char *get_chip_name(int chip_id)
186 for (i = 0; chip_info_table[i].name != NULL; i++)
187 if (chip_info_table[i].chip_id == chip_id)
189 return chip_info_table[i].name;
192 static void vt6655_remove(struct pci_dev *pcid)
194 struct vnt_private *pDevice = pci_get_drvdata(pcid);
198 device_free_info(pDevice);
201 static void device_get_options(struct vnt_private *pDevice)
203 POPTIONS pOpts = &(pDevice->sOpts);
205 pOpts->nRxDescs0 = RX_DESC_DEF0;
206 pOpts->nRxDescs1 = RX_DESC_DEF1;
207 pOpts->nTxDescs[0] = TX_DESC_DEF0;
208 pOpts->nTxDescs[1] = TX_DESC_DEF1;
209 pOpts->int_works = INT_WORKS_DEF;
211 pOpts->short_retry = SHORT_RETRY_DEF;
212 pOpts->long_retry = LONG_RETRY_DEF;
213 pOpts->bbp_type = BBP_TYPE_DEF;
217 device_set_options(struct vnt_private *pDevice)
219 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
220 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
221 pDevice->byBBType = pDevice->sOpts.bbp_type;
222 pDevice->byPacketType = pDevice->byBBType;
223 pDevice->byAutoFBCtrl = AUTO_FB_0;
224 pDevice->bUpdateBBVGA = true;
225 pDevice->byPreambleType = 0;
227 pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
228 pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
229 pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType);
230 pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
231 pr_debug(" byBBType= %d\n", (int)pDevice->byBBType);
235 // Initialisation of MAC & BBP registers
238 static void device_init_registers(struct vnt_private *pDevice)
242 unsigned char byValue;
243 unsigned char byCCKPwrdBm = 0;
244 unsigned char byOFDMPwrdBm = 0;
246 MACbShutdown(pDevice->PortOffset);
247 BBvSoftwareReset(pDevice);
249 /* Do MACbSoftwareReset in MACvInitialize */
250 MACbSoftwareReset(pDevice->PortOffset);
252 pDevice->bAES = false;
254 /* Only used in 11g type, sync with ERP IE */
255 pDevice->bProtectMode = false;
257 pDevice->bNonERPPresent = false;
258 pDevice->bBarkerPreambleMd = false;
259 pDevice->wCurrentRate = RATE_1M;
260 pDevice->byTopOFDMBasicRate = RATE_24M;
261 pDevice->byTopCCKBasicRate = RATE_1M;
263 /* Target to IF pin while programming to RF chip. */
264 pDevice->byRevId = 0;
267 MACvInitialize(pDevice->PortOffset);
270 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
272 spin_lock_irqsave(&pDevice->lock, flags);
274 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
276 spin_unlock_irqrestore(&pDevice->lock, flags);
278 /* Get Channel range */
279 pDevice->byMinChannel = 1;
280 pDevice->byMaxChannel = CB_MAX_CHANNEL;
283 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
284 if (byValue & EEP_ANTINV)
285 pDevice->bTxRxAntInv = true;
287 pDevice->bTxRxAntInv = false;
289 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
290 /* if not set default is All */
292 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
294 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
295 pDevice->byAntennaCount = 2;
296 pDevice->byTxAntennaMode = ANT_B;
297 pDevice->dwTxAntennaSel = 1;
298 pDevice->dwRxAntennaSel = 1;
300 if (pDevice->bTxRxAntInv)
301 pDevice->byRxAntennaMode = ANT_A;
303 pDevice->byRxAntennaMode = ANT_B;
305 pDevice->byAntennaCount = 1;
306 pDevice->dwTxAntennaSel = 0;
307 pDevice->dwRxAntennaSel = 0;
309 if (byValue & EEP_ANTENNA_AUX) {
310 pDevice->byTxAntennaMode = ANT_A;
312 if (pDevice->bTxRxAntInv)
313 pDevice->byRxAntennaMode = ANT_B;
315 pDevice->byRxAntennaMode = ANT_A;
317 pDevice->byTxAntennaMode = ANT_B;
319 if (pDevice->bTxRxAntInv)
320 pDevice->byRxAntennaMode = ANT_A;
322 pDevice->byRxAntennaMode = ANT_B;
326 /* Set initial antenna mode */
327 BBvSetTxAntennaMode(pDevice, pDevice->byTxAntennaMode);
328 BBvSetRxAntennaMode(pDevice, pDevice->byRxAntennaMode);
330 /* zonetype initial */
331 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
334 pDevice->byRFType = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_RFTYPE);
336 /* force change RevID for VT3253 emu */
337 if ((pDevice->byRFType & RF_EMU) != 0)
338 pDevice->byRevId = 0x80;
340 pDevice->byRFType &= RF_MASK;
341 pr_debug("pDevice->byRFType = %x\n", pDevice->byRFType);
343 if (!pDevice->bZoneRegExist)
344 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
346 pr_debug("pDevice->byZoneType = %x\n", pDevice->byZoneType);
351 /* Get Desire Power Value */
352 pDevice->byCurPwr = 0xFF;
353 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
354 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
356 /* Load power Table */
357 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
358 pDevice->abyCCKPwrTbl[ii + 1] =
359 SROMbyReadEmbedded(pDevice->PortOffset,
360 (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
361 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
362 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
364 pDevice->abyOFDMPwrTbl[ii + 1] =
365 SROMbyReadEmbedded(pDevice->PortOffset,
366 (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
367 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
368 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
370 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
371 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
374 /* recover 12,13 ,14channel for EUROPE by 11 channel */
375 for (ii = 11; ii < 14; ii++) {
376 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
377 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
380 /* Load OFDM A Power Table */
381 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
382 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
383 SROMbyReadEmbedded(pDevice->PortOffset,
384 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
386 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
387 SROMbyReadEmbedded(pDevice->PortOffset,
388 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
391 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
392 MACvSelectPage1(pDevice->PortOffset);
394 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
395 (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
397 MACvSelectPage0(pDevice->PortOffset);
400 /* use relative tx timeout and 802.11i D4 */
401 MACvWordRegBitsOn(pDevice->PortOffset,
402 MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
404 /* set performance parameter by registry */
405 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
406 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
408 /* reset TSF counter */
409 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
410 /* enable TSF counter */
411 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
413 /* initialize BBP registers */
414 BBbVT3253Init(pDevice);
416 if (pDevice->bUpdateBBVGA) {
417 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
418 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
419 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
422 BBvSetRxAntennaMode(pDevice, pDevice->byRxAntennaMode);
423 BBvSetTxAntennaMode(pDevice, pDevice->byTxAntennaMode);
425 /* Set BB and packet type at the same time. */
426 /* Set Short Slot Time, xIFS, and RSPINF. */
427 pDevice->wCurrentRate = RATE_54M;
429 pDevice->bRadioOff = false;
431 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
433 pDevice->bHWRadioOff = false;
435 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
437 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
439 if (((pDevice->byGPIO & GPIO0_DATA) &&
440 !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
441 (!(pDevice->byGPIO & GPIO0_DATA) &&
442 (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
443 pDevice->bHWRadioOff = true;
446 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
447 CARDbRadioPowerOff(pDevice);
449 /* get Permanent network address */
450 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
451 pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
453 /* reset Tx pointer */
454 CARDvSafeResetRx(pDevice);
455 /* reset Rx pointer */
456 CARDvSafeResetTx(pDevice);
458 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
459 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
462 MACvReceive0(pDevice->PortOffset);
463 MACvReceive1(pDevice->PortOffset);
465 /* start the adapter */
466 MACvStart(pDevice->PortOffset);
469 static void device_print_info(struct vnt_private *pDevice)
471 dev_info(&pDevice->pcid->dev, "%s\n", get_chip_name(pDevice->chip_id));
473 dev_info(&pDevice->pcid->dev, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
474 pDevice->abyCurrentNetAddr, (unsigned long)pDevice->ioaddr,
475 (unsigned long)pDevice->PortOffset, pDevice->pcid->irq);
478 static void vt6655_init_info(struct pci_dev *pcid,
479 struct vnt_private **ppDevice,
480 PCHIP_INFO pChip_info)
482 memset(*ppDevice, 0, sizeof(**ppDevice));
484 (*ppDevice)->pcid = pcid;
485 (*ppDevice)->chip_id = pChip_info->chip_id;
486 (*ppDevice)->io_size = pChip_info->io_size;
487 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
488 (*ppDevice)->multicast_limit = 32;
490 spin_lock_init(&((*ppDevice)->lock));
493 static bool device_get_pci_info(struct vnt_private *pDevice,
494 struct pci_dev *pcid)
498 unsigned int cis_addr;
500 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
501 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
502 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
503 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
505 pci_set_master(pcid);
507 pDevice->memaddr = pci_resource_start(pcid, 0);
508 pDevice->ioaddr = pci_resource_start(pcid, 1);
510 cis_addr = pci_resource_start(pcid, 2);
512 pDevice->pcid = pcid;
514 pci_read_config_byte(pcid, PCI_COMMAND, &b);
515 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
520 static void device_free_info(struct vnt_private *pDevice)
526 ieee80211_unregister_hw(pDevice->hw);
528 if (pDevice->PortOffset)
529 iounmap(pDevice->PortOffset);
532 pci_release_regions(pDevice->pcid);
535 ieee80211_free_hw(pDevice->hw);
538 static bool device_init_rings(struct vnt_private *pDevice)
542 /*allocate all RD/TD rings a single pool*/
543 vir_pool = pci_zalloc_consistent(pDevice->pcid,
544 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
545 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
546 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
547 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
549 if (vir_pool == NULL) {
550 dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n");
554 pDevice->aRD0Ring = vir_pool;
555 pDevice->aRD1Ring = vir_pool +
556 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
558 pDevice->rd0_pool_dma = pDevice->pool_dma;
559 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
560 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc);
562 pDevice->tx0_bufs = pci_zalloc_consistent(pDevice->pcid,
563 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
564 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
567 &pDevice->tx_bufs_dma0);
568 if (pDevice->tx0_bufs == NULL) {
569 dev_err(&pDevice->pcid->dev, "allocate buf dma memory failed\n");
571 pci_free_consistent(pDevice->pcid,
572 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
573 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
574 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
575 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc),
576 vir_pool, pDevice->pool_dma
581 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
582 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
584 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
585 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
587 // vir_pool: pvoid type
588 pDevice->apTD0Rings = vir_pool
589 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
590 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc);
592 pDevice->apTD1Rings = vir_pool
593 + pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc)
594 + pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc)
595 + pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc);
597 pDevice->tx1_bufs = pDevice->tx0_bufs +
598 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
600 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
601 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
603 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
606 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
607 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
609 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
610 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
615 static void device_free_rings(struct vnt_private *pDevice)
617 pci_free_consistent(pDevice->pcid,
618 pDevice->sOpts.nRxDescs0 * sizeof(SRxDesc) +
619 pDevice->sOpts.nRxDescs1 * sizeof(SRxDesc) +
620 pDevice->sOpts.nTxDescs[0] * sizeof(STxDesc) +
621 pDevice->sOpts.nTxDescs[1] * sizeof(STxDesc)
623 pDevice->aRD0Ring, pDevice->pool_dma
626 if (pDevice->tx0_bufs)
627 pci_free_consistent(pDevice->pcid,
628 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
629 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
632 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
636 static void device_init_rd0_ring(struct vnt_private *pDevice)
639 dma_addr_t curr = pDevice->rd0_pool_dma;
642 /* Init the RD0 ring entries */
643 for (i = 0; i < pDevice->sOpts.nRxDescs0; i ++, curr += sizeof(SRxDesc)) {
644 pDesc = &(pDevice->aRD0Ring[i]);
645 pDesc->pRDInfo = alloc_rd_info();
646 ASSERT(pDesc->pRDInfo);
647 if (!device_alloc_rx_buf(pDevice, pDesc))
648 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
650 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
651 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
652 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
656 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
657 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
660 static void device_init_rd1_ring(struct vnt_private *pDevice)
663 dma_addr_t curr = pDevice->rd1_pool_dma;
666 /* Init the RD1 ring entries */
667 for (i = 0; i < pDevice->sOpts.nRxDescs1; i ++, curr += sizeof(SRxDesc)) {
668 pDesc = &(pDevice->aRD1Ring[i]);
669 pDesc->pRDInfo = alloc_rd_info();
670 ASSERT(pDesc->pRDInfo);
671 if (!device_alloc_rx_buf(pDevice, pDesc))
672 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
674 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
675 pDesc->pRDInfo->curr_desc = cpu_to_le32(curr);
676 pDesc->next_desc = cpu_to_le32(curr + sizeof(SRxDesc));
680 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
681 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
684 static void device_free_rd0_ring(struct vnt_private *pDevice)
688 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
689 PSRxDesc pDesc = &(pDevice->aRD0Ring[i]);
690 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
692 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
693 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
695 dev_kfree_skb(pRDInfo->skb);
697 kfree(pDesc->pRDInfo);
701 static void device_free_rd1_ring(struct vnt_private *pDevice)
705 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
706 PSRxDesc pDesc = &(pDevice->aRD1Ring[i]);
707 PDEVICE_RD_INFO pRDInfo = pDesc->pRDInfo;
709 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
710 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
712 dev_kfree_skb(pRDInfo->skb);
714 kfree(pDesc->pRDInfo);
718 static void device_init_td0_ring(struct vnt_private *pDevice)
724 curr = pDevice->td0_pool_dma;
725 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++, curr += sizeof(STxDesc)) {
726 pDesc = &(pDevice->apTD0Rings[i]);
727 pDesc->pTDInfo = alloc_td_info();
728 ASSERT(pDesc->pTDInfo);
729 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
730 pDesc->pTDInfo->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
731 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
733 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
734 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
735 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
739 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
740 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
743 static void device_init_td1_ring(struct vnt_private *pDevice)
749 /* Init the TD ring entries */
750 curr = pDevice->td1_pool_dma;
751 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++, curr += sizeof(STxDesc)) {
752 pDesc = &(pDevice->apTD1Rings[i]);
753 pDesc->pTDInfo = alloc_td_info();
754 ASSERT(pDesc->pTDInfo);
755 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
756 pDesc->pTDInfo->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
757 pDesc->pTDInfo->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
759 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
760 pDesc->pTDInfo->curr_desc = cpu_to_le32(curr);
761 pDesc->next_desc = cpu_to_le32(curr+sizeof(STxDesc));
765 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
766 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
769 static void device_free_td0_ring(struct vnt_private *pDevice)
773 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
774 PSTxDesc pDesc = &(pDevice->apTD0Rings[i]);
775 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
777 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
778 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
779 pTDInfo->skb->len, PCI_DMA_TODEVICE);
782 dev_kfree_skb(pTDInfo->skb);
784 kfree(pDesc->pTDInfo);
788 static void device_free_td1_ring(struct vnt_private *pDevice)
792 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
793 PSTxDesc pDesc = &(pDevice->apTD1Rings[i]);
794 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
796 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma))
797 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma,
798 pTDInfo->skb->len, PCI_DMA_TODEVICE);
801 dev_kfree_skb(pTDInfo->skb);
803 kfree(pDesc->pTDInfo);
807 /*-----------------------------------------------------------------*/
809 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
814 for (pRD = pDevice->pCurrRD[uIdx];
815 pRD->m_rd0RD0.f1Owner == OWNED_BY_HOST;
819 if (vnt_receive_frame(pDevice, pRD)) {
820 if (!device_alloc_rx_buf(pDevice, pRD)) {
821 dev_err(&pDevice->pcid->dev,
822 "can not allocate rx buf\n");
826 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
829 pDevice->pCurrRD[uIdx] = pRD;
834 static bool device_alloc_rx_buf(struct vnt_private *pDevice, PSRxDesc pRD)
836 PDEVICE_RD_INFO pRDInfo = pRD->pRDInfo;
838 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
839 if (pRDInfo->skb == NULL)
841 ASSERT(pRDInfo->skb);
844 pci_map_single(pDevice->pcid,
845 skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)),
846 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
848 *((unsigned int *)&(pRD->m_rd0RD0)) = 0; /* FIX cast */
850 pRD->m_rd0RD0.wResCount = cpu_to_le16(pDevice->rx_buf_sz);
851 pRD->m_rd0RD0.f1Owner = OWNED_BY_NIC;
852 pRD->m_rd1RD1.wReqCount = cpu_to_le16(pDevice->rx_buf_sz);
853 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
858 static const u8 fallback_rate0[5][5] = {
859 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
860 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
861 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
862 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
863 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
866 static const u8 fallback_rate1[5][5] = {
867 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
868 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
869 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
870 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
871 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
874 static int vnt_int_report_rate(struct vnt_private *priv,
875 PDEVICE_TD_INFO context, u8 tsr0, u8 tsr1)
877 struct vnt_tx_fifo_head *fifo_head;
878 struct ieee80211_tx_info *info;
879 struct ieee80211_rate *rate;
881 u8 tx_retry = (tsr0 & TSR0_NCR);
890 fifo_head = (struct vnt_tx_fifo_head *)context->buf;
891 fb_option = (le16_to_cpu(fifo_head->fifo_ctl) &
892 (FIFOCTL_AUTO_FB_0 | FIFOCTL_AUTO_FB_1));
894 info = IEEE80211_SKB_CB(context->skb);
895 idx = info->control.rates[0].idx;
897 if (fb_option && !(tsr1 & TSR1_TERR)) {
901 rate = ieee80211_get_tx_rate(priv->hw, info);
902 tx_rate = rate->hw_value - RATE_18M;
907 if (fb_option & FIFOCTL_AUTO_FB_0)
908 tx_rate = fallback_rate0[tx_rate][retry];
909 else if (fb_option & FIFOCTL_AUTO_FB_1)
910 tx_rate = fallback_rate1[tx_rate][retry];
912 if (info->band == IEEE80211_BAND_5GHZ)
913 idx = tx_rate - RATE_6M;
918 ieee80211_tx_info_clear_status(info);
920 info->status.rates[0].count = tx_retry;
922 if (!(tsr1 & TSR1_TERR)) {
923 info->status.rates[0].idx = idx;
924 info->flags |= IEEE80211_TX_STAT_ACK;
930 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
934 unsigned char byTsr0;
935 unsigned char byTsr1;
937 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
938 if (pTD->m_td0TD0.f1Owner == OWNED_BY_NIC)
943 byTsr0 = pTD->m_td0TD0.byTSR0;
944 byTsr1 = pTD->m_td0TD0.byTSR1;
946 //Only the status of first TD in the chain is correct
947 if (pTD->m_td1TD1.byTCR & TCR_STP) {
948 if ((pTD->pTDInfo->byFlags & TD_FLAGS_NETIF_SKB) != 0) {
950 vnt_int_report_rate(pDevice, pTD->pTDInfo, byTsr0, byTsr1);
952 if (!(byTsr1 & TSR1_TERR)) {
954 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
959 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
960 (int)uIdx, byTsr1, byTsr0);
964 if (byTsr1 & TSR1_TERR) {
965 if ((pTD->pTDInfo->byFlags & TD_FLAGS_PRIV_SKB) != 0) {
966 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
967 (int)uIdx, byTsr1, byTsr0);
970 device_free_tx_buf(pDevice, pTD);
971 pDevice->iTDUsed[uIdx]--;
975 pDevice->apTailTD[uIdx] = pTD;
980 static void device_error(struct vnt_private *pDevice, unsigned short status)
982 if (status & ISR_FETALERR) {
983 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
985 MACbShutdown(pDevice->PortOffset);
990 static void device_free_tx_buf(struct vnt_private *pDevice, PSTxDesc pDesc)
992 PDEVICE_TD_INFO pTDInfo = pDesc->pTDInfo;
993 struct sk_buff *skb = pTDInfo->skb;
995 // pre-allocated buf_dma can't be unmapped.
996 if (pTDInfo->skb_dma && (pTDInfo->skb_dma != pTDInfo->buf_dma)) {
997 pci_unmap_single(pDevice->pcid, pTDInfo->skb_dma, skb->len,
1001 if (pTDInfo->byFlags & TD_FLAGS_NETIF_SKB)
1002 ieee80211_tx_status_irqsafe(pDevice->hw, skb);
1004 dev_kfree_skb_irq(skb);
1006 pTDInfo->skb_dma = 0;
1007 pTDInfo->skb = NULL;
1008 pTDInfo->byFlags = 0;
1011 static void vnt_check_bb_vga(struct vnt_private *priv)
1016 if (!priv->bUpdateBBVGA)
1019 if (priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
1022 if (!(priv->vif->bss_conf.assoc && priv->uCurrRSSI))
1025 RFvRSSITodBm(priv, (u8)priv->uCurrRSSI, &dbm);
1027 for (i = 0; i < BB_VGA_LEVEL; i++) {
1028 if (dbm < priv->ldBmThreshold[i]) {
1029 priv->byBBVGANew = priv->abyBBVGA[i];
1034 if (priv->byBBVGANew == priv->byBBVGACurrent) {
1035 priv->uBBVGADiffCount = 1;
1039 priv->uBBVGADiffCount++;
1041 if (priv->uBBVGADiffCount == 1) {
1042 /* first VGA diff gain */
1043 BBvSetVGAGainOffset(priv, priv->byBBVGANew);
1045 dev_dbg(&priv->pcid->dev,
1046 "First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1047 (int)dbm, priv->byBBVGANew,
1048 priv->byBBVGACurrent,
1049 (int)priv->uBBVGADiffCount);
1052 if (priv->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
1053 dev_dbg(&priv->pcid->dev,
1054 "RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1055 (int)dbm, priv->byBBVGANew,
1056 priv->byBBVGACurrent,
1057 (int)priv->uBBVGADiffCount);
1059 BBvSetVGAGainOffset(priv, priv->byBBVGANew);
1063 static irqreturn_t device_intr(int irq, void *dev_instance)
1065 struct vnt_private *pDevice = dev_instance;
1067 unsigned long dwMIBCounter = 0;
1068 unsigned char byOrgPageSel = 0;
1070 unsigned long flags;
1072 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
1074 if (pDevice->dwIsr == 0)
1075 return IRQ_RETVAL(handled);
1077 if (pDevice->dwIsr == 0xffffffff) {
1078 pr_debug("dwIsr = 0xffff\n");
1079 return IRQ_RETVAL(handled);
1083 MACvIntDisable(pDevice->PortOffset);
1085 spin_lock_irqsave(&pDevice->lock, flags);
1087 //Make sure current page is 0
1088 VNSvInPortB(pDevice->PortOffset + MAC_REG_PAGE1SEL, &byOrgPageSel);
1089 if (byOrgPageSel == 1)
1090 MACvSelectPage0(pDevice->PortOffset);
1094 MACvReadMIBCounter(pDevice->PortOffset, &dwMIBCounter);
1096 // Must do this after doing rx/tx, cause ISR bit is slow
1097 // than RD/TD write back
1098 // update ISR counter
1099 STAvUpdate802_11Counter(&pDevice->s802_11Counter, &pDevice->scStatistic, dwMIBCounter);
1100 while (pDevice->dwIsr != 0) {
1101 STAvUpdateIsrStatCounter(&pDevice->scStatistic, pDevice->dwIsr);
1102 MACvWriteISR(pDevice->PortOffset, pDevice->dwIsr);
1104 if (pDevice->dwIsr & ISR_FETALERR) {
1105 pr_debug(" ISR_FETALERR\n");
1106 VNSvOutPortB(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, 0);
1107 VNSvOutPortW(pDevice->PortOffset + MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
1108 device_error(pDevice, pDevice->dwIsr);
1111 if (pDevice->dwIsr & ISR_TBTT) {
1113 pDevice->op_mode != NL80211_IFTYPE_ADHOC)
1114 vnt_check_bb_vga(pDevice);
1116 pDevice->bBeaconSent = false;
1117 if (pDevice->bEnablePSMode)
1118 PSbIsNextTBTTWakeUp((void *)pDevice);
1120 if ((pDevice->op_mode == NL80211_IFTYPE_AP ||
1121 pDevice->op_mode == NL80211_IFTYPE_ADHOC) &&
1122 pDevice->vif->bss_conf.enable_beacon) {
1123 MACvOneShotTimer1MicroSec(pDevice->PortOffset,
1124 (pDevice->vif->bss_conf.beacon_int - MAKE_BEACON_RESERVED) << 10);
1127 /* TODO: adhoc PS mode */
1131 if (pDevice->dwIsr & ISR_BNTX) {
1132 if (pDevice->op_mode == NL80211_IFTYPE_ADHOC) {
1133 pDevice->bIsBeaconBufReadySet = false;
1134 pDevice->cbBeaconBufReadySetCnt = 0;
1137 pDevice->bBeaconSent = true;
1140 if (pDevice->dwIsr & ISR_RXDMA0)
1141 max_count += device_rx_srv(pDevice, TYPE_RXDMA0);
1143 if (pDevice->dwIsr & ISR_RXDMA1)
1144 max_count += device_rx_srv(pDevice, TYPE_RXDMA1);
1146 if (pDevice->dwIsr & ISR_TXDMA0)
1147 max_count += device_tx_srv(pDevice, TYPE_TXDMA0);
1149 if (pDevice->dwIsr & ISR_AC0DMA)
1150 max_count += device_tx_srv(pDevice, TYPE_AC0DMA);
1152 if (pDevice->dwIsr & ISR_SOFTTIMER1) {
1154 if (pDevice->vif->bss_conf.enable_beacon)
1155 vnt_beacon_make(pDevice, pDevice->vif);
1159 /* If both buffers available wake the queue */
1161 if (AVAIL_TD(pDevice, TYPE_TXDMA0) &&
1162 AVAIL_TD(pDevice, TYPE_AC0DMA) &&
1163 ieee80211_queue_stopped(pDevice->hw, 0))
1164 ieee80211_wake_queues(pDevice->hw);
1167 MACvReadISR(pDevice->PortOffset, &pDevice->dwIsr);
1169 MACvReceive0(pDevice->PortOffset);
1170 MACvReceive1(pDevice->PortOffset);
1172 if (max_count > pDevice->sOpts.int_works)
1176 if (byOrgPageSel == 1)
1177 MACvSelectPage1(pDevice->PortOffset);
1179 spin_unlock_irqrestore(&pDevice->lock, flags);
1181 MACvIntEnable(pDevice->PortOffset, IMR_MASK_VALUE);
1183 return IRQ_RETVAL(handled);
1186 static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1188 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1190 u32 dma_idx = TYPE_AC0DMA;
1191 unsigned long flags;
1193 spin_lock_irqsave(&priv->lock, flags);
1195 if (!ieee80211_is_data(hdr->frame_control))
1196 dma_idx = TYPE_TXDMA0;
1198 if (AVAIL_TD(priv, dma_idx) < 1) {
1199 spin_unlock_irqrestore(&priv->lock, flags);
1203 head_td = priv->apCurrTD[dma_idx];
1205 head_td->m_td1TD1.byTCR = 0;
1207 head_td->pTDInfo->skb = skb;
1209 priv->iTDUsed[dma_idx]++;
1211 /* Take ownership */
1213 head_td->m_td0TD0.f1Owner = OWNED_BY_NIC;
1217 priv->apCurrTD[dma_idx] = head_td->next;
1219 spin_unlock_irqrestore(&priv->lock, flags);
1221 vnt_generate_fifo_header(priv, dma_idx, head_td, skb);
1223 if (MACbIsRegBitsOn(priv->PortOffset, MAC_REG_PSCTL, PSCTL_PS))
1224 MACbPSWakeup(priv->PortOffset);
1226 spin_lock_irqsave(&priv->lock, flags);
1228 priv->bPWBitOn = false;
1230 /* Set TSR1 & ReqCount in TxDescHead */
1231 head_td->m_td1TD1.byTCR |= (TCR_STP | TCR_EDP | EDMSDU);
1232 head_td->m_td1TD1.wReqCount =
1233 cpu_to_le16((u16)head_td->pTDInfo->dwReqCount);
1235 head_td->buff_addr = cpu_to_le32(head_td->pTDInfo->skb_dma);
1237 if (dma_idx == TYPE_AC0DMA) {
1238 head_td->pTDInfo->byFlags = TD_FLAGS_NETIF_SKB;
1240 MACvTransmitAC0(priv->PortOffset);
1242 MACvTransmit0(priv->PortOffset);
1245 spin_unlock_irqrestore(&priv->lock, flags);
1250 static void vnt_tx_80211(struct ieee80211_hw *hw,
1251 struct ieee80211_tx_control *control,
1252 struct sk_buff *skb)
1254 struct vnt_private *priv = hw->priv;
1256 ieee80211_stop_queues(hw);
1258 if (vnt_tx_packet(priv, skb)) {
1259 ieee80211_free_txskb(hw, skb);
1261 ieee80211_wake_queues(hw);
1265 static int vnt_start(struct ieee80211_hw *hw)
1267 struct vnt_private *priv = hw->priv;
1270 priv->rx_buf_sz = PKT_BUF_SZ;
1271 if (!device_init_rings(priv))
1274 ret = request_irq(priv->pcid->irq, &device_intr,
1275 IRQF_SHARED, "vt6655", priv);
1277 dev_dbg(&priv->pcid->dev, "failed to start irq\n");
1281 dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
1282 device_init_rd0_ring(priv);
1283 device_init_rd1_ring(priv);
1284 device_init_td0_ring(priv);
1285 device_init_td1_ring(priv);
1287 device_init_registers(priv);
1289 dev_dbg(&priv->pcid->dev, "call MACvIntEnable\n");
1290 MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
1292 ieee80211_wake_queues(hw);
1297 static void vnt_stop(struct ieee80211_hw *hw)
1299 struct vnt_private *priv = hw->priv;
1301 ieee80211_stop_queues(hw);
1303 MACbShutdown(priv->PortOffset);
1304 MACbSoftwareReset(priv->PortOffset);
1305 CARDbRadioPowerOff(priv);
1307 device_free_td0_ring(priv);
1308 device_free_td1_ring(priv);
1309 device_free_rd0_ring(priv);
1310 device_free_rd1_ring(priv);
1311 device_free_rings(priv);
1313 free_irq(priv->pcid->irq, priv);
1316 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1318 struct vnt_private *priv = hw->priv;
1322 switch (vif->type) {
1323 case NL80211_IFTYPE_STATION:
1325 case NL80211_IFTYPE_ADHOC:
1326 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1328 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1331 case NL80211_IFTYPE_AP:
1332 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1334 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1341 priv->op_mode = vif->type;
1346 static void vnt_remove_interface(struct ieee80211_hw *hw,
1347 struct ieee80211_vif *vif)
1349 struct vnt_private *priv = hw->priv;
1351 switch (vif->type) {
1352 case NL80211_IFTYPE_STATION:
1354 case NL80211_IFTYPE_ADHOC:
1355 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1356 MACvRegBitsOff(priv->PortOffset,
1357 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1358 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1360 case NL80211_IFTYPE_AP:
1361 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1362 MACvRegBitsOff(priv->PortOffset,
1363 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1364 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1370 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
1374 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
1376 struct vnt_private *priv = hw->priv;
1377 struct ieee80211_conf *conf = &hw->conf;
1380 if (changed & IEEE80211_CONF_CHANGE_PS) {
1381 if (conf->flags & IEEE80211_CONF_PS)
1382 PSvEnablePowerSaving(priv, conf->listen_interval);
1384 PSvDisablePowerSaving(priv);
1387 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
1388 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
1389 set_channel(priv, conf->chandef.chan);
1391 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
1392 bb_type = BB_TYPE_11A;
1394 bb_type = BB_TYPE_11G;
1396 if (priv->byBBType != bb_type) {
1397 priv->byBBType = bb_type;
1399 CARDbSetPhyParameter(priv, priv->byBBType);
1403 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1404 if (priv->byBBType == BB_TYPE_11B)
1405 priv->wCurrentRate = RATE_1M;
1407 priv->wCurrentRate = RATE_54M;
1409 RFbSetPower(priv, priv->wCurrentRate,
1410 conf->chandef.chan->hw_value);
1416 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
1417 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
1420 struct vnt_private *priv = hw->priv;
1422 priv->current_aid = conf->aid;
1424 if (changed & BSS_CHANGED_BSSID)
1425 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid);
1427 if (changed & BSS_CHANGED_BASIC_RATES) {
1428 priv->basic_rates = conf->basic_rates;
1430 CARDvUpdateBasicTopRate(priv);
1432 dev_dbg(&priv->pcid->dev,
1433 "basic rates %x\n", conf->basic_rates);
1436 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1437 if (conf->use_short_preamble) {
1438 MACvEnableBarkerPreambleMd(priv->PortOffset);
1439 priv->byPreambleType = true;
1441 MACvDisableBarkerPreambleMd(priv->PortOffset);
1442 priv->byPreambleType = false;
1446 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1447 if (conf->use_cts_prot)
1448 MACvEnableProtectMD(priv->PortOffset);
1450 MACvDisableProtectMD(priv->PortOffset);
1453 if (changed & BSS_CHANGED_ERP_SLOT) {
1454 if (conf->use_short_slot)
1455 priv->bShortSlotTime = true;
1457 priv->bShortSlotTime = false;
1459 CARDbSetPhyParameter(priv, priv->byBBType);
1460 BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
1463 if (changed & BSS_CHANGED_TXPOWER)
1464 RFbSetPower(priv, priv->wCurrentRate,
1465 conf->chandef.chan->hw_value);
1467 if (changed & BSS_CHANGED_BEACON_ENABLED) {
1468 dev_dbg(&priv->pcid->dev,
1469 "Beacon enable %d\n", conf->enable_beacon);
1471 if (conf->enable_beacon) {
1472 vnt_beacon_enable(priv, vif, conf);
1474 MACvRegBitsOn(priv->PortOffset, MAC_REG_TCR,
1477 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR,
1482 if (changed & BSS_CHANGED_ASSOC && priv->op_mode != NL80211_IFTYPE_AP) {
1484 CARDbUpdateTSF(priv, conf->beacon_rate->hw_value,
1485 conf->sync_device_ts, conf->sync_tsf);
1487 CARDbSetBeaconPeriod(priv, conf->beacon_int);
1489 CARDvSetFirstNextTBTT(priv, conf->beacon_int);
1491 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1493 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1499 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
1500 struct netdev_hw_addr_list *mc_list)
1502 struct vnt_private *priv = hw->priv;
1503 struct netdev_hw_addr *ha;
1507 netdev_hw_addr_list_for_each(ha, mc_list) {
1508 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1510 mc_filter |= 1ULL << (bit_nr & 0x3f);
1513 priv->mc_list_count = mc_list->count;
1518 static void vnt_configure(struct ieee80211_hw *hw,
1519 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
1521 struct vnt_private *priv = hw->priv;
1524 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_PROMISC_IN_BSS |
1525 FIF_BCN_PRBRESP_PROMISC;
1527 VNSvInPortB(priv->PortOffset + MAC_REG_RCR, &rx_mode);
1529 dev_dbg(&priv->pcid->dev, "rx mode in = %x\n", rx_mode);
1531 if (changed_flags & FIF_PROMISC_IN_BSS) {
1532 /* unconditionally log net taps */
1533 if (*total_flags & FIF_PROMISC_IN_BSS)
1534 rx_mode |= RCR_UNICAST;
1536 rx_mode &= ~RCR_UNICAST;
1539 if (changed_flags & FIF_ALLMULTI) {
1540 if (*total_flags & FIF_ALLMULTI) {
1541 unsigned long flags;
1543 spin_lock_irqsave(&priv->lock, flags);
1545 if (priv->mc_list_count > 2) {
1546 MACvSelectPage1(priv->PortOffset);
1548 VNSvOutPortD(priv->PortOffset +
1549 MAC_REG_MAR0, 0xffffffff);
1550 VNSvOutPortD(priv->PortOffset +
1551 MAC_REG_MAR0 + 4, 0xffffffff);
1553 MACvSelectPage0(priv->PortOffset);
1555 MACvSelectPage1(priv->PortOffset);
1557 VNSvOutPortD(priv->PortOffset +
1558 MAC_REG_MAR0, (u32)multicast);
1559 VNSvOutPortD(priv->PortOffset +
1561 (u32)(multicast >> 32));
1563 MACvSelectPage0(priv->PortOffset);
1566 spin_unlock_irqrestore(&priv->lock, flags);
1568 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1570 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
1574 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
1575 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1577 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
1578 rx_mode &= ~RCR_BSSID;
1580 rx_mode |= RCR_BSSID;
1583 VNSvOutPortB(priv->PortOffset + MAC_REG_RCR, rx_mode);
1585 dev_dbg(&priv->pcid->dev, "rx mode out= %x\n", rx_mode);
1588 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1589 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1590 struct ieee80211_key_conf *key)
1592 struct vnt_private *priv = hw->priv;
1596 if (vnt_set_keys(hw, sta, vif, key))
1600 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
1601 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
1609 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1611 struct vnt_private *priv = hw->priv;
1614 CARDbGetCurrentTSF(priv, &tsf);
1619 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1622 struct vnt_private *priv = hw->priv;
1624 CARDvUpdateNextTBTT(priv, tsf, vif->bss_conf.beacon_int);
1627 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1629 struct vnt_private *priv = hw->priv;
1631 /* reset TSF counter */
1632 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1635 static const struct ieee80211_ops vnt_mac_ops = {
1639 .add_interface = vnt_add_interface,
1640 .remove_interface = vnt_remove_interface,
1641 .config = vnt_config,
1642 .bss_info_changed = vnt_bss_info_changed,
1643 .prepare_multicast = vnt_prepare_multicast,
1644 .configure_filter = vnt_configure,
1645 .set_key = vnt_set_key,
1646 .get_tsf = vnt_get_tsf,
1647 .set_tsf = vnt_set_tsf,
1648 .reset_tsf = vnt_reset_tsf,
1651 static int vnt_init(struct vnt_private *priv)
1653 SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyCurrentNetAddr);
1655 vnt_init_bands(priv);
1657 if (ieee80211_register_hw(priv->hw))
1660 priv->mac_hw = true;
1662 CARDbRadioPowerOff(priv);
1668 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
1670 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
1671 struct vnt_private *priv;
1672 struct ieee80211_hw *hw;
1673 struct wiphy *wiphy;
1676 dev_notice(&pcid->dev,
1677 "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1679 dev_notice(&pcid->dev,
1680 "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
1682 hw = ieee80211_alloc_hw(sizeof(*priv), &vnt_mac_ops);
1684 dev_err(&pcid->dev, "could not register ieee80211_hw\n");
1690 vt6655_init_info(pcid, &priv, pChip_info);
1694 SET_IEEE80211_DEV(priv->hw, &pcid->dev);
1696 if (pci_enable_device(pcid)) {
1697 device_free_info(priv);
1702 "Before get pci_info memaddr is %x\n", priv->memaddr);
1704 if (!device_get_pci_info(priv, pcid)) {
1705 dev_err(&pcid->dev, ": Failed to find PCI device.\n");
1706 device_free_info(priv);
1712 "after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",
1713 priv->memaddr, priv->ioaddr, priv->io_size);
1725 for (i = 0; address[i]; i++) {
1726 pci_read_config_dword(pcid, address[i], &bar);
1728 dev_dbg(&pcid->dev, "bar %d is %x\n", i, bar);
1732 "bar %d not implemented\n", i);
1736 if (bar & PCI_BASE_ADDRESS_SPACE_IO) {
1739 len = bar & (PCI_BASE_ADDRESS_IO_MASK & 0xffff);
1740 len = len & ~(len - 1);
1743 "IO space: len in IO %x, BAR %d\n",
1746 len = bar & 0xfffffff0;
1750 "len in MEM %x, BAR %d\n", len, i);
1756 priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK,
1758 if (!priv->PortOffset) {
1759 dev_err(&pcid->dev, ": Failed to IO remapping ..\n");
1760 device_free_info(priv);
1764 rc = pci_request_regions(pcid, DEVICE_NAME);
1766 dev_err(&pcid->dev, ": Failed to find PCI device\n");
1767 device_free_info(priv);
1772 if (!MACbSoftwareReset(priv->PortOffset)) {
1773 dev_err(&pcid->dev, ": Failed to access MAC hardware..\n");
1774 device_free_info(priv);
1777 /* initial to reload eeprom */
1778 MACvInitialize(priv->PortOffset);
1779 MACvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr);
1781 device_get_options(priv);
1782 device_set_options(priv);
1783 /* Mask out the options cannot be set to the chip */
1784 priv->sOpts.flags &= pChip_info->flags;
1786 /* Enable the chip specified capabilities */
1787 priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL);
1789 wiphy = priv->hw->wiphy;
1791 wiphy->frag_threshold = FRAG_THRESH_DEF;
1792 wiphy->rts_threshold = RTS_THRESH_DEF;
1793 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1794 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1796 priv->hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
1797 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
1798 IEEE80211_HW_SIGNAL_DBM |
1799 IEEE80211_HW_TIMING_BEACON_ONLY;
1801 priv->hw->max_signal = 100;
1806 device_print_info(priv);
1807 pci_set_drvdata(pcid, priv);
1812 /*------------------------------------------------------------------*/
1815 static int vt6655_suspend(struct pci_dev *pcid, pm_message_t state)
1817 struct vnt_private *priv = pci_get_drvdata(pcid);
1818 unsigned long flags;
1820 spin_lock_irqsave(&priv->lock, flags);
1822 pci_save_state(pcid);
1824 MACbShutdown(priv->PortOffset);
1826 pci_disable_device(pcid);
1827 pci_set_power_state(pcid, pci_choose_state(pcid, state));
1829 spin_unlock_irqrestore(&priv->lock, flags);
1834 static int vt6655_resume(struct pci_dev *pcid)
1837 pci_set_power_state(pcid, PCI_D0);
1838 pci_enable_wake(pcid, PCI_D0, 0);
1839 pci_restore_state(pcid);
1845 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
1847 static struct pci_driver device_driver = {
1848 .name = DEVICE_NAME,
1849 .id_table = vt6655_pci_id_table,
1850 .probe = vt6655_probe,
1851 .remove = vt6655_remove,
1853 .suspend = vt6655_suspend,
1854 .resume = vt6655_resume,
1858 static int __init vt6655_init_module(void)
1862 ret = pci_register_driver(&device_driver);
1865 register_reboot_notifier(&device_notifier);
1871 static void __exit vt6655_cleanup_module(void)
1874 unregister_reboot_notifier(&device_notifier);
1876 pci_unregister_driver(&device_driver);
1879 module_init(vt6655_init_module);
1880 module_exit(vt6655_cleanup_module);
1884 device_notify_reboot(struct notifier_block *nb, unsigned long event, void *p)
1886 struct pci_dev *pdev = NULL;
1892 for_each_pci_dev(pdev) {
1893 if (pci_dev_driver(pdev) == &device_driver) {
1894 if (pci_get_drvdata(pdev))
1895 vt6655_suspend(pdev, PMSG_HIBERNATE);