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_rx_srv - rx service function
36 * device_alloc_rx_buf - rx buffer pre-allocated function
37 * device_free_tx_buf - free tx buffer function
38 * device_init_rd0_ring- initial rd dma0 ring
39 * device_init_rd1_ring- initial rd dma1 ring
40 * device_init_td0_ring- initial tx dma0 ring buffer
41 * device_init_td1_ring- initial tx dma1 ring buffer
42 * device_init_registers- initial MAC & BBP & RF internal registers.
43 * device_init_rings- initial tx/rx ring buffer
44 * device_free_rings- free all allocated ring buffer
45 * device_tx_srv- tx interrupt service function
51 #include <linux/file.h>
61 #include <linux/delay.h>
62 #include <linux/kthread.h>
63 #include <linux/slab.h>
65 /*--------------------- Static Definitions -------------------------*/
67 * Define module options
69 MODULE_AUTHOR("VIA Networking Technologies, Inc., <lyndonchen@vntek.com.tw>");
70 MODULE_LICENSE("GPL");
71 MODULE_DESCRIPTION("VIA Networking Solomon-A/B/G Wireless LAN Adapter Driver");
73 #define DEVICE_PARAM(N, D)
75 #define RX_DESC_MIN0 16
76 #define RX_DESC_MAX0 128
77 #define RX_DESC_DEF0 32
78 DEVICE_PARAM(RxDescriptors0, "Number of receive descriptors0");
80 #define RX_DESC_MIN1 16
81 #define RX_DESC_MAX1 128
82 #define RX_DESC_DEF1 32
83 DEVICE_PARAM(RxDescriptors1, "Number of receive descriptors1");
85 #define TX_DESC_MIN0 16
86 #define TX_DESC_MAX0 128
87 #define TX_DESC_DEF0 32
88 DEVICE_PARAM(TxDescriptors0, "Number of transmit descriptors0");
90 #define TX_DESC_MIN1 16
91 #define TX_DESC_MAX1 128
92 #define TX_DESC_DEF1 64
93 DEVICE_PARAM(TxDescriptors1, "Number of transmit descriptors1");
95 #define INT_WORKS_DEF 20
96 #define INT_WORKS_MIN 10
97 #define INT_WORKS_MAX 64
99 DEVICE_PARAM(int_works, "Number of packets per interrupt services");
101 #define RTS_THRESH_DEF 2347
103 #define FRAG_THRESH_DEF 2346
105 #define SHORT_RETRY_MIN 0
106 #define SHORT_RETRY_MAX 31
107 #define SHORT_RETRY_DEF 8
109 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
111 #define LONG_RETRY_MIN 0
112 #define LONG_RETRY_MAX 15
113 #define LONG_RETRY_DEF 4
115 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
117 /* BasebandType[] baseband type selected
118 0: indicate 802.11a type
119 1: indicate 802.11b type
120 2: indicate 802.11g type
122 #define BBP_TYPE_MIN 0
123 #define BBP_TYPE_MAX 2
124 #define BBP_TYPE_DEF 2
126 DEVICE_PARAM(BasebandType, "baseband type");
129 * Static vars definitions
131 static CHIP_INFO chip_info_table[] = {
132 { VT3253, "VIA Networking Solomon-A/B/G Wireless LAN Adapter ",
133 256, 1, DEVICE_FLAGS_IP_ALIGN|DEVICE_FLAGS_TX_ALIGN },
137 static const struct pci_device_id vt6655_pci_id_table[] = {
138 { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
142 /*--------------------- Static Functions --------------------------*/
144 static int vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent);
145 static void vt6655_init_info(struct pci_dev *pcid,
146 struct vnt_private **ppDevice, PCHIP_INFO);
147 static void device_free_info(struct vnt_private *pDevice);
148 static bool device_get_pci_info(struct vnt_private *, struct pci_dev *pcid);
149 static void device_print_info(struct vnt_private *pDevice);
151 static void device_init_rd0_ring(struct vnt_private *pDevice);
152 static void device_init_rd1_ring(struct vnt_private *pDevice);
153 static void device_init_td0_ring(struct vnt_private *pDevice);
154 static void device_init_td1_ring(struct vnt_private *pDevice);
156 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx);
157 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx);
158 static bool device_alloc_rx_buf(struct vnt_private *, struct vnt_rx_desc *);
159 static void device_init_registers(struct vnt_private *pDevice);
160 static void device_free_tx_buf(struct vnt_private *, struct vnt_tx_desc *);
161 static void device_free_td0_ring(struct vnt_private *pDevice);
162 static void device_free_td1_ring(struct vnt_private *pDevice);
163 static void device_free_rd0_ring(struct vnt_private *pDevice);
164 static void device_free_rd1_ring(struct vnt_private *pDevice);
165 static void device_free_rings(struct vnt_private *pDevice);
167 /*--------------------- Export Variables --------------------------*/
169 /*--------------------- Export Functions --------------------------*/
171 static void vt6655_remove(struct pci_dev *pcid)
173 struct vnt_private *pDevice = pci_get_drvdata(pcid);
177 device_free_info(pDevice);
180 static void device_get_options(struct vnt_private *pDevice)
182 POPTIONS pOpts = &(pDevice->sOpts);
184 pOpts->nRxDescs0 = RX_DESC_DEF0;
185 pOpts->nRxDescs1 = RX_DESC_DEF1;
186 pOpts->nTxDescs[0] = TX_DESC_DEF0;
187 pOpts->nTxDescs[1] = TX_DESC_DEF1;
188 pOpts->int_works = INT_WORKS_DEF;
190 pOpts->short_retry = SHORT_RETRY_DEF;
191 pOpts->long_retry = LONG_RETRY_DEF;
192 pOpts->bbp_type = BBP_TYPE_DEF;
196 device_set_options(struct vnt_private *pDevice)
198 pDevice->byShortRetryLimit = pDevice->sOpts.short_retry;
199 pDevice->byLongRetryLimit = pDevice->sOpts.long_retry;
200 pDevice->byBBType = pDevice->sOpts.bbp_type;
201 pDevice->byPacketType = pDevice->byBBType;
202 pDevice->byAutoFBCtrl = AUTO_FB_0;
203 pDevice->bUpdateBBVGA = true;
204 pDevice->byPreambleType = 0;
206 pr_debug(" byShortRetryLimit= %d\n", (int)pDevice->byShortRetryLimit);
207 pr_debug(" byLongRetryLimit= %d\n", (int)pDevice->byLongRetryLimit);
208 pr_debug(" byPreambleType= %d\n", (int)pDevice->byPreambleType);
209 pr_debug(" byShortPreamble= %d\n", (int)pDevice->byShortPreamble);
210 pr_debug(" byBBType= %d\n", (int)pDevice->byBBType);
214 * Initialisation of MAC & BBP registers
217 static void device_init_registers(struct vnt_private *pDevice)
221 unsigned char byValue;
222 unsigned char byCCKPwrdBm = 0;
223 unsigned char byOFDMPwrdBm = 0;
225 MACbShutdown(pDevice->PortOffset);
226 BBvSoftwareReset(pDevice);
228 /* Do MACbSoftwareReset in MACvInitialize */
229 MACbSoftwareReset(pDevice->PortOffset);
231 pDevice->bAES = false;
233 /* Only used in 11g type, sync with ERP IE */
234 pDevice->bProtectMode = false;
236 pDevice->bNonERPPresent = false;
237 pDevice->bBarkerPreambleMd = false;
238 pDevice->wCurrentRate = RATE_1M;
239 pDevice->byTopOFDMBasicRate = RATE_24M;
240 pDevice->byTopCCKBasicRate = RATE_1M;
242 /* Target to IF pin while programming to RF chip. */
243 pDevice->byRevId = 0;
246 MACvInitialize(pDevice->PortOffset);
249 VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
251 spin_lock_irqsave(&pDevice->lock, flags);
253 SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
255 spin_unlock_irqrestore(&pDevice->lock, flags);
257 /* Get Channel range */
258 pDevice->byMinChannel = 1;
259 pDevice->byMaxChannel = CB_MAX_CHANNEL;
262 byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
263 if (byValue & EEP_ANTINV)
264 pDevice->bTxRxAntInv = true;
266 pDevice->bTxRxAntInv = false;
268 byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
269 /* if not set default is All */
271 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
273 if (byValue == (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN)) {
274 pDevice->byAntennaCount = 2;
275 pDevice->byTxAntennaMode = ANT_B;
276 pDevice->dwTxAntennaSel = 1;
277 pDevice->dwRxAntennaSel = 1;
279 if (pDevice->bTxRxAntInv)
280 pDevice->byRxAntennaMode = ANT_A;
282 pDevice->byRxAntennaMode = ANT_B;
284 pDevice->byAntennaCount = 1;
285 pDevice->dwTxAntennaSel = 0;
286 pDevice->dwRxAntennaSel = 0;
288 if (byValue & EEP_ANTENNA_AUX) {
289 pDevice->byTxAntennaMode = ANT_A;
291 if (pDevice->bTxRxAntInv)
292 pDevice->byRxAntennaMode = ANT_B;
294 pDevice->byRxAntennaMode = ANT_A;
296 pDevice->byTxAntennaMode = ANT_B;
298 if (pDevice->bTxRxAntInv)
299 pDevice->byRxAntennaMode = ANT_A;
301 pDevice->byRxAntennaMode = ANT_B;
305 /* Set initial antenna mode */
306 BBvSetTxAntennaMode(pDevice, pDevice->byTxAntennaMode);
307 BBvSetRxAntennaMode(pDevice, pDevice->byRxAntennaMode);
309 /* zonetype initial */
310 pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
312 if (!pDevice->bZoneRegExist)
313 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
315 pr_debug("pDevice->byZoneType = %x\n", pDevice->byZoneType);
320 /* Get Desire Power Value */
321 pDevice->byCurPwr = 0xFF;
322 pDevice->byCCKPwr = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_CCK);
323 pDevice->byOFDMPwrG = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_PWR_OFDMG);
325 /* Load power Table */
326 for (ii = 0; ii < CB_MAX_CHANNEL_24G; ii++) {
327 pDevice->abyCCKPwrTbl[ii + 1] =
328 SROMbyReadEmbedded(pDevice->PortOffset,
329 (unsigned char)(ii + EEP_OFS_CCK_PWR_TBL));
330 if (pDevice->abyCCKPwrTbl[ii + 1] == 0)
331 pDevice->abyCCKPwrTbl[ii+1] = pDevice->byCCKPwr;
333 pDevice->abyOFDMPwrTbl[ii + 1] =
334 SROMbyReadEmbedded(pDevice->PortOffset,
335 (unsigned char)(ii + EEP_OFS_OFDM_PWR_TBL));
336 if (pDevice->abyOFDMPwrTbl[ii + 1] == 0)
337 pDevice->abyOFDMPwrTbl[ii + 1] = pDevice->byOFDMPwrG;
339 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
340 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
343 /* recover 12,13 ,14channel for EUROPE by 11 channel */
344 for (ii = 11; ii < 14; ii++) {
345 pDevice->abyCCKPwrTbl[ii] = pDevice->abyCCKPwrTbl[10];
346 pDevice->abyOFDMPwrTbl[ii] = pDevice->abyOFDMPwrTbl[10];
349 /* Load OFDM A Power Table */
350 for (ii = 0; ii < CB_MAX_CHANNEL_5G; ii++) {
351 pDevice->abyOFDMPwrTbl[ii + CB_MAX_CHANNEL_24G + 1] =
352 SROMbyReadEmbedded(pDevice->PortOffset,
353 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_TBL));
355 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
356 SROMbyReadEmbedded(pDevice->PortOffset,
357 (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
360 if (pDevice->byLocalID > REV_ID_VT3253_B1) {
361 MACvSelectPage1(pDevice->PortOffset);
363 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
364 (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
366 MACvSelectPage0(pDevice->PortOffset);
369 /* use relative tx timeout and 802.11i D4 */
370 MACvWordRegBitsOn(pDevice->PortOffset,
371 MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
373 /* set performance parameter by registry */
374 MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
375 MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
377 /* reset TSF counter */
378 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
379 /* enable TSF counter */
380 VNSvOutPortB(pDevice->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
382 /* initialize BBP registers */
383 BBbVT3253Init(pDevice);
385 if (pDevice->bUpdateBBVGA) {
386 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
387 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
388 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
391 BBvSetRxAntennaMode(pDevice, pDevice->byRxAntennaMode);
392 BBvSetTxAntennaMode(pDevice, pDevice->byTxAntennaMode);
394 /* Set BB and packet type at the same time. */
395 /* Set Short Slot Time, xIFS, and RSPINF. */
396 pDevice->wCurrentRate = RATE_54M;
398 pDevice->bRadioOff = false;
400 pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
402 pDevice->bHWRadioOff = false;
404 if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
406 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
408 if (((pDevice->byGPIO & GPIO0_DATA) &&
409 !(pDevice->byRadioCtl & EEP_RADIOCTL_INV)) ||
410 (!(pDevice->byGPIO & GPIO0_DATA) &&
411 (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
412 pDevice->bHWRadioOff = true;
415 if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
416 CARDbRadioPowerOff(pDevice);
418 /* get Permanent network address */
419 SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
420 pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
422 /* reset Tx pointer */
423 CARDvSafeResetRx(pDevice);
424 /* reset Rx pointer */
425 CARDvSafeResetTx(pDevice);
427 if (pDevice->byLocalID <= REV_ID_VT3253_A1)
428 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
431 MACvReceive0(pDevice->PortOffset);
432 MACvReceive1(pDevice->PortOffset);
434 /* start the adapter */
435 MACvStart(pDevice->PortOffset);
438 static void device_print_info(struct vnt_private *pDevice)
440 dev_info(&pDevice->pcid->dev, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
441 pDevice->abyCurrentNetAddr, (unsigned long)pDevice->ioaddr,
442 (unsigned long)pDevice->PortOffset, pDevice->pcid->irq);
445 static void vt6655_init_info(struct pci_dev *pcid,
446 struct vnt_private **ppDevice,
447 PCHIP_INFO pChip_info)
449 memset(*ppDevice, 0, sizeof(**ppDevice));
451 (*ppDevice)->pcid = pcid;
452 (*ppDevice)->chip_id = pChip_info->chip_id;
453 (*ppDevice)->io_size = pChip_info->io_size;
454 (*ppDevice)->nTxQueues = pChip_info->nTxQueue;
455 (*ppDevice)->multicast_limit = 32;
457 spin_lock_init(&((*ppDevice)->lock));
460 static bool device_get_pci_info(struct vnt_private *pDevice,
461 struct pci_dev *pcid)
465 unsigned int cis_addr;
467 pci_read_config_byte(pcid, PCI_REVISION_ID, &pDevice->byRevId);
468 pci_read_config_word(pcid, PCI_SUBSYSTEM_ID, &pDevice->SubSystemID);
469 pci_read_config_word(pcid, PCI_SUBSYSTEM_VENDOR_ID, &pDevice->SubVendorID);
470 pci_read_config_word(pcid, PCI_COMMAND, (u16 *)&(pci_cmd));
472 pci_set_master(pcid);
474 pDevice->memaddr = pci_resource_start(pcid, 0);
475 pDevice->ioaddr = pci_resource_start(pcid, 1);
477 cis_addr = pci_resource_start(pcid, 2);
479 pDevice->pcid = pcid;
481 pci_read_config_byte(pcid, PCI_COMMAND, &b);
482 pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
487 static void device_free_info(struct vnt_private *pDevice)
493 ieee80211_unregister_hw(pDevice->hw);
495 if (pDevice->PortOffset)
496 iounmap(pDevice->PortOffset);
499 pci_release_regions(pDevice->pcid);
502 ieee80211_free_hw(pDevice->hw);
505 static bool device_init_rings(struct vnt_private *pDevice)
509 /*allocate all RD/TD rings a single pool*/
510 vir_pool = dma_zalloc_coherent(&pDevice->pcid->dev,
511 pDevice->sOpts.nRxDescs0 * sizeof(struct vnt_rx_desc) +
512 pDevice->sOpts.nRxDescs1 * sizeof(struct vnt_rx_desc) +
513 pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc) +
514 pDevice->sOpts.nTxDescs[1] * sizeof(struct vnt_tx_desc),
515 &pDevice->pool_dma, GFP_ATOMIC);
516 if (vir_pool == NULL) {
517 dev_err(&pDevice->pcid->dev, "allocate desc dma memory failed\n");
521 pDevice->aRD0Ring = vir_pool;
522 pDevice->aRD1Ring = vir_pool +
523 pDevice->sOpts.nRxDescs0 * sizeof(struct vnt_rx_desc);
525 pDevice->rd0_pool_dma = pDevice->pool_dma;
526 pDevice->rd1_pool_dma = pDevice->rd0_pool_dma +
527 pDevice->sOpts.nRxDescs0 * sizeof(struct vnt_rx_desc);
529 pDevice->tx0_bufs = dma_zalloc_coherent(&pDevice->pcid->dev,
530 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
531 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
534 &pDevice->tx_bufs_dma0,
536 if (pDevice->tx0_bufs == NULL) {
537 dev_err(&pDevice->pcid->dev, "allocate buf dma memory failed\n");
539 dma_free_coherent(&pDevice->pcid->dev,
540 pDevice->sOpts.nRxDescs0 * sizeof(struct vnt_rx_desc) +
541 pDevice->sOpts.nRxDescs1 * sizeof(struct vnt_rx_desc) +
542 pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc) +
543 pDevice->sOpts.nTxDescs[1] * sizeof(struct vnt_tx_desc),
544 vir_pool, pDevice->pool_dma
549 pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
550 pDevice->sOpts.nRxDescs1 * sizeof(struct vnt_rx_desc);
552 pDevice->td1_pool_dma = pDevice->td0_pool_dma +
553 pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc);
555 /* vir_pool: pvoid type */
556 pDevice->apTD0Rings = vir_pool
557 + pDevice->sOpts.nRxDescs0 * sizeof(struct vnt_rx_desc)
558 + pDevice->sOpts.nRxDescs1 * sizeof(struct vnt_rx_desc);
560 pDevice->apTD1Rings = vir_pool
561 + pDevice->sOpts.nRxDescs0 * sizeof(struct vnt_rx_desc)
562 + pDevice->sOpts.nRxDescs1 * sizeof(struct vnt_rx_desc)
563 + pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc);
565 pDevice->tx1_bufs = pDevice->tx0_bufs +
566 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
568 pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
569 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
571 pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
574 pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
575 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
577 pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
578 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
583 static void device_free_rings(struct vnt_private *pDevice)
585 dma_free_coherent(&pDevice->pcid->dev,
586 pDevice->sOpts.nRxDescs0 * sizeof(struct vnt_rx_desc) +
587 pDevice->sOpts.nRxDescs1 * sizeof(struct vnt_rx_desc) +
588 pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc) +
589 pDevice->sOpts.nTxDescs[1] * sizeof(struct vnt_tx_desc)
591 pDevice->aRD0Ring, pDevice->pool_dma
594 if (pDevice->tx0_bufs)
595 dma_free_coherent(&pDevice->pcid->dev,
596 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ +
597 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ +
600 pDevice->tx0_bufs, pDevice->tx_bufs_dma0
604 static void device_init_rd0_ring(struct vnt_private *pDevice)
607 dma_addr_t curr = pDevice->rd0_pool_dma;
608 struct vnt_rx_desc *pDesc;
610 /* Init the RD0 ring entries */
611 for (i = 0; i < pDevice->sOpts.nRxDescs0;
612 i ++, curr += sizeof(struct vnt_rx_desc)) {
613 pDesc = &(pDevice->aRD0Ring[i]);
614 pDesc->rd_info = alloc_rd_info();
616 if (!device_alloc_rx_buf(pDevice, pDesc))
617 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
619 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
620 pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_rx_desc));
624 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
625 pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
628 static void device_init_rd1_ring(struct vnt_private *pDevice)
631 dma_addr_t curr = pDevice->rd1_pool_dma;
632 struct vnt_rx_desc *pDesc;
634 /* Init the RD1 ring entries */
635 for (i = 0; i < pDevice->sOpts.nRxDescs1;
636 i ++, curr += sizeof(struct vnt_rx_desc)) {
637 pDesc = &(pDevice->aRD1Ring[i]);
638 pDesc->rd_info = alloc_rd_info();
640 if (!device_alloc_rx_buf(pDevice, pDesc))
641 dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
643 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
644 pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_rx_desc));
648 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
649 pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
652 static void device_free_rd0_ring(struct vnt_private *pDevice)
656 for (i = 0; i < pDevice->sOpts.nRxDescs0; i++) {
657 struct vnt_rx_desc *pDesc = &(pDevice->aRD0Ring[i]);
658 struct vnt_rd_info *rd_info = pDesc->rd_info;
660 dma_unmap_single(&pDevice->pcid->dev, rd_info->skb_dma,
661 pDevice->rx_buf_sz, DMA_FROM_DEVICE);
663 dev_kfree_skb(rd_info->skb);
665 kfree(pDesc->rd_info);
669 static void device_free_rd1_ring(struct vnt_private *pDevice)
673 for (i = 0; i < pDevice->sOpts.nRxDescs1; i++) {
674 struct vnt_rx_desc *pDesc = &(pDevice->aRD1Ring[i]);
675 struct vnt_rd_info *rd_info = pDesc->rd_info;
677 dma_unmap_single(&pDevice->pcid->dev, rd_info->skb_dma,
678 pDevice->rx_buf_sz, DMA_FROM_DEVICE);
680 dev_kfree_skb(rd_info->skb);
682 kfree(pDesc->rd_info);
686 static void device_init_td0_ring(struct vnt_private *pDevice)
690 struct vnt_tx_desc *pDesc;
692 curr = pDevice->td0_pool_dma;
693 for (i = 0; i < pDevice->sOpts.nTxDescs[0];
694 i++, curr += sizeof(struct vnt_tx_desc)) {
695 pDesc = &(pDevice->apTD0Rings[i]);
696 pDesc->td_info = alloc_td_info();
698 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
699 pDesc->td_info->buf = pDevice->tx0_bufs + (i)*PKT_BUF_SZ;
700 pDesc->td_info->buf_dma = pDevice->tx_bufs_dma0 + (i)*PKT_BUF_SZ;
702 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
703 pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_tx_desc));
707 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
708 pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
711 static void device_init_td1_ring(struct vnt_private *pDevice)
715 struct vnt_tx_desc *pDesc;
717 /* Init the TD ring entries */
718 curr = pDevice->td1_pool_dma;
719 for (i = 0; i < pDevice->sOpts.nTxDescs[1];
720 i++, curr += sizeof(struct vnt_tx_desc)) {
721 pDesc = &(pDevice->apTD1Rings[i]);
722 pDesc->td_info = alloc_td_info();
724 if (pDevice->flags & DEVICE_FLAGS_TX_ALIGN) {
725 pDesc->td_info->buf = pDevice->tx1_bufs + (i) * PKT_BUF_SZ;
726 pDesc->td_info->buf_dma = pDevice->tx_bufs_dma1 + (i) * PKT_BUF_SZ;
728 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
729 pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_tx_desc));
733 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
734 pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
737 static void device_free_td0_ring(struct vnt_private *pDevice)
741 for (i = 0; i < pDevice->sOpts.nTxDescs[0]; i++) {
742 struct vnt_tx_desc *pDesc = &pDevice->apTD0Rings[i];
743 struct vnt_td_info *pTDInfo = pDesc->td_info;
745 dev_kfree_skb(pTDInfo->skb);
746 kfree(pDesc->td_info);
750 static void device_free_td1_ring(struct vnt_private *pDevice)
754 for (i = 0; i < pDevice->sOpts.nTxDescs[1]; i++) {
755 struct vnt_tx_desc *pDesc = &pDevice->apTD1Rings[i];
756 struct vnt_td_info *pTDInfo = pDesc->td_info;
758 dev_kfree_skb(pTDInfo->skb);
759 kfree(pDesc->td_info);
763 /*-----------------------------------------------------------------*/
765 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
767 struct vnt_rx_desc *pRD;
770 for (pRD = pDevice->pCurrRD[uIdx];
771 pRD->rd0.owner == OWNED_BY_HOST;
776 if (!pRD->rd_info->skb)
779 if (vnt_receive_frame(pDevice, pRD)) {
780 if (!device_alloc_rx_buf(pDevice, pRD)) {
781 dev_err(&pDevice->pcid->dev,
782 "can not allocate rx buf\n");
786 pRD->rd0.owner = OWNED_BY_NIC;
789 pDevice->pCurrRD[uIdx] = pRD;
794 static bool device_alloc_rx_buf(struct vnt_private *pDevice,
795 struct vnt_rx_desc *pRD)
797 struct vnt_rd_info *pRDInfo = pRD->rd_info;
799 pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
800 if (pRDInfo->skb == NULL)
804 dma_map_single(&pDevice->pcid->dev,
805 skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)),
806 pDevice->rx_buf_sz, DMA_FROM_DEVICE);
808 *((unsigned int *)&pRD->rd0) = 0; /* FIX cast */
810 pRD->rd0.res_count = cpu_to_le16(pDevice->rx_buf_sz);
811 pRD->rd0.owner = OWNED_BY_NIC;
812 pRD->rd1.req_count = cpu_to_le16(pDevice->rx_buf_sz);
813 pRD->buff_addr = cpu_to_le32(pRDInfo->skb_dma);
818 static const u8 fallback_rate0[5][5] = {
819 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
820 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
821 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
822 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
823 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
826 static const u8 fallback_rate1[5][5] = {
827 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
828 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
829 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
830 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
831 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
834 static int vnt_int_report_rate(struct vnt_private *priv,
835 struct vnt_td_info *context, u8 tsr0, u8 tsr1)
837 struct vnt_tx_fifo_head *fifo_head;
838 struct ieee80211_tx_info *info;
839 struct ieee80211_rate *rate;
841 u8 tx_retry = (tsr0 & TSR0_NCR);
850 fifo_head = (struct vnt_tx_fifo_head *)context->buf;
851 fb_option = (le16_to_cpu(fifo_head->fifo_ctl) &
852 (FIFOCTL_AUTO_FB_0 | FIFOCTL_AUTO_FB_1));
854 info = IEEE80211_SKB_CB(context->skb);
855 idx = info->control.rates[0].idx;
857 if (fb_option && !(tsr1 & TSR1_TERR)) {
861 rate = ieee80211_get_tx_rate(priv->hw, info);
862 tx_rate = rate->hw_value - RATE_18M;
867 if (fb_option & FIFOCTL_AUTO_FB_0)
868 tx_rate = fallback_rate0[tx_rate][retry];
869 else if (fb_option & FIFOCTL_AUTO_FB_1)
870 tx_rate = fallback_rate1[tx_rate][retry];
872 if (info->band == IEEE80211_BAND_5GHZ)
873 idx = tx_rate - RATE_6M;
878 ieee80211_tx_info_clear_status(info);
880 info->status.rates[0].count = tx_retry;
882 if (!(tsr1 & TSR1_TERR)) {
883 info->status.rates[0].idx = idx;
885 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
886 info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
888 info->flags |= IEEE80211_TX_STAT_ACK;
894 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
896 struct vnt_tx_desc *pTD;
898 unsigned char byTsr0;
899 unsigned char byTsr1;
901 for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
902 if (pTD->td0.owner == OWNED_BY_NIC)
907 byTsr0 = pTD->td0.tsr0;
908 byTsr1 = pTD->td0.tsr1;
910 /* Only the status of first TD in the chain is correct */
911 if (pTD->td1.tcr & TCR_STP) {
912 if ((pTD->td_info->flags & TD_FLAGS_NETIF_SKB) != 0) {
913 if (!(byTsr1 & TSR1_TERR)) {
915 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
920 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
921 (int)uIdx, byTsr1, byTsr0);
925 if (byTsr1 & TSR1_TERR) {
926 if ((pTD->td_info->flags & TD_FLAGS_PRIV_SKB) != 0) {
927 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
928 (int)uIdx, byTsr1, byTsr0);
932 vnt_int_report_rate(pDevice, pTD->td_info, byTsr0, byTsr1);
934 device_free_tx_buf(pDevice, pTD);
935 pDevice->iTDUsed[uIdx]--;
939 pDevice->apTailTD[uIdx] = pTD;
944 static void device_error(struct vnt_private *pDevice, unsigned short status)
946 if (status & ISR_FETALERR) {
947 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
949 MACbShutdown(pDevice->PortOffset);
954 static void device_free_tx_buf(struct vnt_private *pDevice,
955 struct vnt_tx_desc *pDesc)
957 struct vnt_td_info *pTDInfo = pDesc->td_info;
958 struct sk_buff *skb = pTDInfo->skb;
961 ieee80211_tx_status_irqsafe(pDevice->hw, skb);
967 static void vnt_check_bb_vga(struct vnt_private *priv)
972 if (!priv->bUpdateBBVGA)
975 if (priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
978 if (!(priv->vif->bss_conf.assoc && priv->uCurrRSSI))
981 RFvRSSITodBm(priv, (u8)priv->uCurrRSSI, &dbm);
983 for (i = 0; i < BB_VGA_LEVEL; i++) {
984 if (dbm < priv->ldBmThreshold[i]) {
985 priv->byBBVGANew = priv->abyBBVGA[i];
990 if (priv->byBBVGANew == priv->byBBVGACurrent) {
991 priv->uBBVGADiffCount = 1;
995 priv->uBBVGADiffCount++;
997 if (priv->uBBVGADiffCount == 1) {
998 /* first VGA diff gain */
999 BBvSetVGAGainOffset(priv, priv->byBBVGANew);
1001 dev_dbg(&priv->pcid->dev,
1002 "First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1003 (int)dbm, priv->byBBVGANew,
1004 priv->byBBVGACurrent,
1005 (int)priv->uBBVGADiffCount);
1008 if (priv->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD) {
1009 dev_dbg(&priv->pcid->dev,
1010 "RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1011 (int)dbm, priv->byBBVGANew,
1012 priv->byBBVGACurrent,
1013 (int)priv->uBBVGADiffCount);
1015 BBvSetVGAGainOffset(priv, priv->byBBVGANew);
1019 static void vnt_interrupt_process(struct vnt_private *priv)
1021 struct ieee80211_low_level_stats *low_stats = &priv->low_stats;
1025 unsigned long flags;
1027 MACvReadISR(priv->PortOffset, &isr);
1032 if (isr == 0xffffffff) {
1033 pr_debug("isr = 0xffff\n");
1037 MACvIntDisable(priv->PortOffset);
1039 spin_lock_irqsave(&priv->lock, flags);
1041 /* Read low level stats */
1042 MACvReadMIBCounter(priv->PortOffset, &mib_counter);
1044 low_stats->dot11RTSSuccessCount += mib_counter & 0xff;
1045 low_stats->dot11RTSFailureCount += (mib_counter >> 8) & 0xff;
1046 low_stats->dot11ACKFailureCount += (mib_counter >> 16) & 0xff;
1047 low_stats->dot11FCSErrorCount += (mib_counter >> 24) & 0xff;
1051 * Must do this after doing rx/tx, cause ISR bit is slow
1052 * than RD/TD write back
1053 * update ISR counter
1055 while (isr && priv->vif) {
1056 MACvWriteISR(priv->PortOffset, isr);
1058 if (isr & ISR_FETALERR) {
1059 pr_debug(" ISR_FETALERR\n");
1060 VNSvOutPortB(priv->PortOffset + MAC_REG_SOFTPWRCTL, 0);
1061 VNSvOutPortW(priv->PortOffset +
1062 MAC_REG_SOFTPWRCTL, SOFTPWRCTL_SWPECTI);
1063 device_error(priv, isr);
1066 if (isr & ISR_TBTT) {
1067 if (priv->op_mode != NL80211_IFTYPE_ADHOC)
1068 vnt_check_bb_vga(priv);
1070 priv->bBeaconSent = false;
1071 if (priv->bEnablePSMode)
1072 PSbIsNextTBTTWakeUp((void *)priv);
1074 if ((priv->op_mode == NL80211_IFTYPE_AP ||
1075 priv->op_mode == NL80211_IFTYPE_ADHOC) &&
1076 priv->vif->bss_conf.enable_beacon) {
1077 MACvOneShotTimer1MicroSec(priv->PortOffset,
1078 (priv->vif->bss_conf.beacon_int - MAKE_BEACON_RESERVED) << 10);
1081 /* TODO: adhoc PS mode */
1085 if (isr & ISR_BNTX) {
1086 if (priv->op_mode == NL80211_IFTYPE_ADHOC) {
1087 priv->bIsBeaconBufReadySet = false;
1088 priv->cbBeaconBufReadySetCnt = 0;
1091 priv->bBeaconSent = true;
1094 if (isr & ISR_RXDMA0)
1095 max_count += device_rx_srv(priv, TYPE_RXDMA0);
1097 if (isr & ISR_RXDMA1)
1098 max_count += device_rx_srv(priv, TYPE_RXDMA1);
1100 if (isr & ISR_TXDMA0)
1101 max_count += device_tx_srv(priv, TYPE_TXDMA0);
1103 if (isr & ISR_AC0DMA)
1104 max_count += device_tx_srv(priv, TYPE_AC0DMA);
1106 if (isr & ISR_SOFTTIMER1) {
1107 if (priv->vif->bss_conf.enable_beacon)
1108 vnt_beacon_make(priv, priv->vif);
1111 /* If both buffers available wake the queue */
1112 if (AVAIL_TD(priv, TYPE_TXDMA0) &&
1113 AVAIL_TD(priv, TYPE_AC0DMA) &&
1114 ieee80211_queue_stopped(priv->hw, 0))
1115 ieee80211_wake_queues(priv->hw);
1117 MACvReadISR(priv->PortOffset, &isr);
1119 MACvReceive0(priv->PortOffset);
1120 MACvReceive1(priv->PortOffset);
1122 if (max_count > priv->sOpts.int_works)
1126 spin_unlock_irqrestore(&priv->lock, flags);
1128 MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
1131 static void vnt_interrupt_work(struct work_struct *work)
1133 struct vnt_private *priv =
1134 container_of(work, struct vnt_private, interrupt_work);
1137 vnt_interrupt_process(priv);
1140 static irqreturn_t vnt_interrupt(int irq, void *arg)
1142 struct vnt_private *priv = arg;
1145 schedule_work(&priv->interrupt_work);
1150 static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1152 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1153 struct vnt_tx_desc *head_td;
1155 unsigned long flags;
1157 spin_lock_irqsave(&priv->lock, flags);
1159 if (ieee80211_is_data(hdr->frame_control))
1160 dma_idx = TYPE_AC0DMA;
1162 dma_idx = TYPE_TXDMA0;
1164 if (AVAIL_TD(priv, dma_idx) < 1) {
1165 spin_unlock_irqrestore(&priv->lock, flags);
1169 head_td = priv->apCurrTD[dma_idx];
1171 head_td->td1.tcr = 0;
1173 head_td->td_info->skb = skb;
1175 if (dma_idx == TYPE_AC0DMA)
1176 head_td->td_info->flags = TD_FLAGS_NETIF_SKB;
1178 priv->apCurrTD[dma_idx] = head_td->next;
1180 spin_unlock_irqrestore(&priv->lock, flags);
1182 vnt_generate_fifo_header(priv, dma_idx, head_td, skb);
1184 spin_lock_irqsave(&priv->lock, flags);
1186 priv->bPWBitOn = false;
1188 /* Set TSR1 & ReqCount in TxDescHead */
1189 head_td->td1.tcr |= (TCR_STP | TCR_EDP | EDMSDU);
1190 head_td->td1.req_count = cpu_to_le16(head_td->td_info->req_count);
1192 head_td->buff_addr = cpu_to_le32(head_td->td_info->buf_dma);
1194 /* Poll Transmit the adapter */
1196 head_td->td0.owner = OWNED_BY_NIC;
1197 wmb(); /* second memory barrier */
1199 if (head_td->td_info->flags & TD_FLAGS_NETIF_SKB)
1200 MACvTransmitAC0(priv->PortOffset);
1202 MACvTransmit0(priv->PortOffset);
1204 priv->iTDUsed[dma_idx]++;
1206 spin_unlock_irqrestore(&priv->lock, flags);
1211 static void vnt_tx_80211(struct ieee80211_hw *hw,
1212 struct ieee80211_tx_control *control,
1213 struct sk_buff *skb)
1215 struct vnt_private *priv = hw->priv;
1217 ieee80211_stop_queues(hw);
1219 if (vnt_tx_packet(priv, skb)) {
1220 ieee80211_free_txskb(hw, skb);
1222 ieee80211_wake_queues(hw);
1226 static int vnt_start(struct ieee80211_hw *hw)
1228 struct vnt_private *priv = hw->priv;
1231 priv->rx_buf_sz = PKT_BUF_SZ;
1232 if (!device_init_rings(priv))
1235 ret = request_irq(priv->pcid->irq, &vnt_interrupt,
1236 IRQF_SHARED, "vt6655", priv);
1238 dev_dbg(&priv->pcid->dev, "failed to start irq\n");
1242 dev_dbg(&priv->pcid->dev, "call device init rd0 ring\n");
1243 device_init_rd0_ring(priv);
1244 device_init_rd1_ring(priv);
1245 device_init_td0_ring(priv);
1246 device_init_td1_ring(priv);
1248 device_init_registers(priv);
1250 dev_dbg(&priv->pcid->dev, "call MACvIntEnable\n");
1251 MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
1253 ieee80211_wake_queues(hw);
1258 static void vnt_stop(struct ieee80211_hw *hw)
1260 struct vnt_private *priv = hw->priv;
1262 ieee80211_stop_queues(hw);
1264 cancel_work_sync(&priv->interrupt_work);
1266 MACbShutdown(priv->PortOffset);
1267 MACbSoftwareReset(priv->PortOffset);
1268 CARDbRadioPowerOff(priv);
1270 device_free_td0_ring(priv);
1271 device_free_td1_ring(priv);
1272 device_free_rd0_ring(priv);
1273 device_free_rd1_ring(priv);
1274 device_free_rings(priv);
1276 free_irq(priv->pcid->irq, priv);
1279 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1281 struct vnt_private *priv = hw->priv;
1285 switch (vif->type) {
1286 case NL80211_IFTYPE_STATION:
1288 case NL80211_IFTYPE_ADHOC:
1289 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1291 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1294 case NL80211_IFTYPE_AP:
1295 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1297 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1304 priv->op_mode = vif->type;
1309 static void vnt_remove_interface(struct ieee80211_hw *hw,
1310 struct ieee80211_vif *vif)
1312 struct vnt_private *priv = hw->priv;
1314 switch (vif->type) {
1315 case NL80211_IFTYPE_STATION:
1317 case NL80211_IFTYPE_ADHOC:
1318 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1319 MACvRegBitsOff(priv->PortOffset,
1320 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1321 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1323 case NL80211_IFTYPE_AP:
1324 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR, TCR_AUTOBCNTX);
1325 MACvRegBitsOff(priv->PortOffset,
1326 MAC_REG_TFTCTL, TFTCTL_TSFCNTREN);
1327 MACvRegBitsOff(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1333 priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
1337 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
1339 struct vnt_private *priv = hw->priv;
1340 struct ieee80211_conf *conf = &hw->conf;
1343 if (changed & IEEE80211_CONF_CHANGE_PS) {
1344 if (conf->flags & IEEE80211_CONF_PS)
1345 PSvEnablePowerSaving(priv, conf->listen_interval);
1347 PSvDisablePowerSaving(priv);
1350 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
1351 (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
1352 set_channel(priv, conf->chandef.chan);
1354 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
1355 bb_type = BB_TYPE_11A;
1357 bb_type = BB_TYPE_11G;
1359 if (priv->byBBType != bb_type) {
1360 priv->byBBType = bb_type;
1362 CARDbSetPhyParameter(priv, priv->byBBType);
1366 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1367 if (priv->byBBType == BB_TYPE_11B)
1368 priv->wCurrentRate = RATE_1M;
1370 priv->wCurrentRate = RATE_54M;
1372 RFbSetPower(priv, priv->wCurrentRate,
1373 conf->chandef.chan->hw_value);
1379 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
1380 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
1383 struct vnt_private *priv = hw->priv;
1385 priv->current_aid = conf->aid;
1387 if (changed & BSS_CHANGED_BSSID && conf->bssid) {
1388 unsigned long flags;
1390 spin_lock_irqsave(&priv->lock, flags);
1392 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid);
1394 spin_unlock_irqrestore(&priv->lock, flags);
1397 if (changed & BSS_CHANGED_BASIC_RATES) {
1398 priv->basic_rates = conf->basic_rates;
1400 CARDvUpdateBasicTopRate(priv);
1402 dev_dbg(&priv->pcid->dev,
1403 "basic rates %x\n", conf->basic_rates);
1406 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1407 if (conf->use_short_preamble) {
1408 MACvEnableBarkerPreambleMd(priv->PortOffset);
1409 priv->byPreambleType = true;
1411 MACvDisableBarkerPreambleMd(priv->PortOffset);
1412 priv->byPreambleType = false;
1416 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1417 if (conf->use_cts_prot)
1418 MACvEnableProtectMD(priv->PortOffset);
1420 MACvDisableProtectMD(priv->PortOffset);
1423 if (changed & BSS_CHANGED_ERP_SLOT) {
1424 if (conf->use_short_slot)
1425 priv->bShortSlotTime = true;
1427 priv->bShortSlotTime = false;
1429 CARDbSetPhyParameter(priv, priv->byBBType);
1430 BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
1433 if (changed & BSS_CHANGED_TXPOWER)
1434 RFbSetPower(priv, priv->wCurrentRate,
1435 conf->chandef.chan->hw_value);
1437 if (changed & BSS_CHANGED_BEACON_ENABLED) {
1438 dev_dbg(&priv->pcid->dev,
1439 "Beacon enable %d\n", conf->enable_beacon);
1441 if (conf->enable_beacon) {
1442 vnt_beacon_enable(priv, vif, conf);
1444 MACvRegBitsOn(priv->PortOffset, MAC_REG_TCR,
1447 MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR,
1452 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INFO) &&
1453 priv->op_mode != NL80211_IFTYPE_AP) {
1454 if (conf->assoc && conf->beacon_rate) {
1455 CARDbUpdateTSF(priv, conf->beacon_rate->hw_value,
1458 CARDbSetBeaconPeriod(priv, conf->beacon_int);
1460 CARDvSetFirstNextTBTT(priv, conf->beacon_int);
1462 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1464 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1470 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
1471 struct netdev_hw_addr_list *mc_list)
1473 struct vnt_private *priv = hw->priv;
1474 struct netdev_hw_addr *ha;
1478 netdev_hw_addr_list_for_each(ha, mc_list) {
1479 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1481 mc_filter |= 1ULL << (bit_nr & 0x3f);
1484 priv->mc_list_count = mc_list->count;
1489 static void vnt_configure(struct ieee80211_hw *hw,
1490 unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
1492 struct vnt_private *priv = hw->priv;
1495 *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC;
1497 VNSvInPortB(priv->PortOffset + MAC_REG_RCR, &rx_mode);
1499 dev_dbg(&priv->pcid->dev, "rx mode in = %x\n", rx_mode);
1501 if (changed_flags & FIF_ALLMULTI) {
1502 if (*total_flags & FIF_ALLMULTI) {
1503 unsigned long flags;
1505 spin_lock_irqsave(&priv->lock, flags);
1507 if (priv->mc_list_count > 2) {
1508 MACvSelectPage1(priv->PortOffset);
1510 VNSvOutPortD(priv->PortOffset +
1511 MAC_REG_MAR0, 0xffffffff);
1512 VNSvOutPortD(priv->PortOffset +
1513 MAC_REG_MAR0 + 4, 0xffffffff);
1515 MACvSelectPage0(priv->PortOffset);
1517 MACvSelectPage1(priv->PortOffset);
1519 VNSvOutPortD(priv->PortOffset +
1520 MAC_REG_MAR0, (u32)multicast);
1521 VNSvOutPortD(priv->PortOffset +
1523 (u32)(multicast >> 32));
1525 MACvSelectPage0(priv->PortOffset);
1528 spin_unlock_irqrestore(&priv->lock, flags);
1530 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1532 rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
1536 if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
1537 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1539 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
1540 rx_mode &= ~RCR_BSSID;
1542 rx_mode |= RCR_BSSID;
1545 VNSvOutPortB(priv->PortOffset + MAC_REG_RCR, rx_mode);
1547 dev_dbg(&priv->pcid->dev, "rx mode out= %x\n", rx_mode);
1550 static int vnt_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
1551 struct ieee80211_vif *vif, struct ieee80211_sta *sta,
1552 struct ieee80211_key_conf *key)
1554 struct vnt_private *priv = hw->priv;
1558 if (vnt_set_keys(hw, sta, vif, key))
1562 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
1563 clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
1571 static int vnt_get_stats(struct ieee80211_hw *hw,
1572 struct ieee80211_low_level_stats *stats)
1574 struct vnt_private *priv = hw->priv;
1576 memcpy(stats, &priv->low_stats, sizeof(*stats));
1581 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1583 struct vnt_private *priv = hw->priv;
1586 CARDbGetCurrentTSF(priv, &tsf);
1591 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1594 struct vnt_private *priv = hw->priv;
1596 CARDvUpdateNextTBTT(priv, tsf, vif->bss_conf.beacon_int);
1599 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1601 struct vnt_private *priv = hw->priv;
1603 /* reset TSF counter */
1604 VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1607 static const struct ieee80211_ops vnt_mac_ops = {
1611 .add_interface = vnt_add_interface,
1612 .remove_interface = vnt_remove_interface,
1613 .config = vnt_config,
1614 .bss_info_changed = vnt_bss_info_changed,
1615 .prepare_multicast = vnt_prepare_multicast,
1616 .configure_filter = vnt_configure,
1617 .set_key = vnt_set_key,
1618 .get_stats = vnt_get_stats,
1619 .get_tsf = vnt_get_tsf,
1620 .set_tsf = vnt_set_tsf,
1621 .reset_tsf = vnt_reset_tsf,
1624 static int vnt_init(struct vnt_private *priv)
1626 SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyCurrentNetAddr);
1628 vnt_init_bands(priv);
1630 if (ieee80211_register_hw(priv->hw))
1633 priv->mac_hw = true;
1635 CARDbRadioPowerOff(priv);
1641 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
1643 PCHIP_INFO pChip_info = (PCHIP_INFO)ent->driver_data;
1644 struct vnt_private *priv;
1645 struct ieee80211_hw *hw;
1646 struct wiphy *wiphy;
1649 dev_notice(&pcid->dev,
1650 "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1652 dev_notice(&pcid->dev,
1653 "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
1655 hw = ieee80211_alloc_hw(sizeof(*priv), &vnt_mac_ops);
1657 dev_err(&pcid->dev, "could not register ieee80211_hw\n");
1663 vt6655_init_info(pcid, &priv, pChip_info);
1667 SET_IEEE80211_DEV(priv->hw, &pcid->dev);
1669 if (pci_enable_device(pcid)) {
1670 device_free_info(priv);
1675 "Before get pci_info memaddr is %x\n", priv->memaddr);
1677 if (!device_get_pci_info(priv, pcid)) {
1678 dev_err(&pcid->dev, ": Failed to find PCI device.\n");
1679 device_free_info(priv);
1683 priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK,
1685 if (!priv->PortOffset) {
1686 dev_err(&pcid->dev, ": Failed to IO remapping ..\n");
1687 device_free_info(priv);
1691 rc = pci_request_regions(pcid, DEVICE_NAME);
1693 dev_err(&pcid->dev, ": Failed to find PCI device\n");
1694 device_free_info(priv);
1698 if (dma_set_mask(&pcid->dev, DMA_BIT_MASK(32))) {
1699 dev_err(&pcid->dev, ": Failed to set dma 32 bit mask\n");
1700 device_free_info(priv);
1704 INIT_WORK(&priv->interrupt_work, vnt_interrupt_work);
1707 if (!MACbSoftwareReset(priv->PortOffset)) {
1708 dev_err(&pcid->dev, ": Failed to access MAC hardware..\n");
1709 device_free_info(priv);
1712 /* initial to reload eeprom */
1713 MACvInitialize(priv->PortOffset);
1714 MACvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr);
1717 priv->byRFType = SROMbyReadEmbedded(priv->PortOffset, EEP_OFS_RFTYPE);
1718 priv->byRFType &= RF_MASK;
1720 dev_dbg(&pcid->dev, "RF Type = %x\n", priv->byRFType);
1722 device_get_options(priv);
1723 device_set_options(priv);
1724 /* Mask out the options cannot be set to the chip */
1725 priv->sOpts.flags &= pChip_info->flags;
1727 /* Enable the chip specified capabilities */
1728 priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL);
1730 wiphy = priv->hw->wiphy;
1732 wiphy->frag_threshold = FRAG_THRESH_DEF;
1733 wiphy->rts_threshold = RTS_THRESH_DEF;
1734 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
1735 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
1737 ieee80211_hw_set(priv->hw, TIMING_BEACON_ONLY);
1738 ieee80211_hw_set(priv->hw, SIGNAL_DBM);
1739 ieee80211_hw_set(priv->hw, RX_INCLUDES_FCS);
1740 ieee80211_hw_set(priv->hw, REPORTS_TX_ACK_STATUS);
1741 ieee80211_hw_set(priv->hw, SUPPORTS_PS);
1743 priv->hw->max_signal = 100;
1748 device_print_info(priv);
1749 pci_set_drvdata(pcid, priv);
1754 /*------------------------------------------------------------------*/
1757 static int vt6655_suspend(struct pci_dev *pcid, pm_message_t state)
1759 struct vnt_private *priv = pci_get_drvdata(pcid);
1760 unsigned long flags;
1762 spin_lock_irqsave(&priv->lock, flags);
1764 pci_save_state(pcid);
1766 MACbShutdown(priv->PortOffset);
1768 pci_disable_device(pcid);
1769 pci_set_power_state(pcid, pci_choose_state(pcid, state));
1771 spin_unlock_irqrestore(&priv->lock, flags);
1776 static int vt6655_resume(struct pci_dev *pcid)
1779 pci_set_power_state(pcid, PCI_D0);
1780 pci_enable_wake(pcid, PCI_D0, 0);
1781 pci_restore_state(pcid);
1787 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
1789 static struct pci_driver device_driver = {
1790 .name = DEVICE_NAME,
1791 .id_table = vt6655_pci_id_table,
1792 .probe = vt6655_probe,
1793 .remove = vt6655_remove,
1795 .suspend = vt6655_suspend,
1796 .resume = vt6655_resume,
1800 module_pci_driver(device_driver);