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
];
333 if (!pDevice
->bZoneRegExist
)
334 pDevice
->byZoneType
= pDevice
->abyEEPROM
[EEP_OFS_ZONETYPE
];
336 pr_debug("pDevice->byZoneType = %x\n", pDevice
->byZoneType
);
341 /* Get Desire Power Value */
342 pDevice
->byCurPwr
= 0xFF;
343 pDevice
->byCCKPwr
= SROMbyReadEmbedded(pDevice
->PortOffset
, EEP_OFS_PWR_CCK
);
344 pDevice
->byOFDMPwrG
= SROMbyReadEmbedded(pDevice
->PortOffset
, EEP_OFS_PWR_OFDMG
);
346 /* Load power Table */
347 for (ii
= 0; ii
< CB_MAX_CHANNEL_24G
; ii
++) {
348 pDevice
->abyCCKPwrTbl
[ii
+ 1] =
349 SROMbyReadEmbedded(pDevice
->PortOffset
,
350 (unsigned char)(ii
+ EEP_OFS_CCK_PWR_TBL
));
351 if (pDevice
->abyCCKPwrTbl
[ii
+ 1] == 0)
352 pDevice
->abyCCKPwrTbl
[ii
+1] = pDevice
->byCCKPwr
;
354 pDevice
->abyOFDMPwrTbl
[ii
+ 1] =
355 SROMbyReadEmbedded(pDevice
->PortOffset
,
356 (unsigned char)(ii
+ EEP_OFS_OFDM_PWR_TBL
));
357 if (pDevice
->abyOFDMPwrTbl
[ii
+ 1] == 0)
358 pDevice
->abyOFDMPwrTbl
[ii
+ 1] = pDevice
->byOFDMPwrG
;
360 pDevice
->abyCCKDefaultPwr
[ii
+ 1] = byCCKPwrdBm
;
361 pDevice
->abyOFDMDefaultPwr
[ii
+ 1] = byOFDMPwrdBm
;
364 /* recover 12,13 ,14channel for EUROPE by 11 channel */
365 for (ii
= 11; ii
< 14; ii
++) {
366 pDevice
->abyCCKPwrTbl
[ii
] = pDevice
->abyCCKPwrTbl
[10];
367 pDevice
->abyOFDMPwrTbl
[ii
] = pDevice
->abyOFDMPwrTbl
[10];
370 /* Load OFDM A Power Table */
371 for (ii
= 0; ii
< CB_MAX_CHANNEL_5G
; ii
++) {
372 pDevice
->abyOFDMPwrTbl
[ii
+ CB_MAX_CHANNEL_24G
+ 1] =
373 SROMbyReadEmbedded(pDevice
->PortOffset
,
374 (unsigned char)(ii
+ EEP_OFS_OFDMA_PWR_TBL
));
376 pDevice
->abyOFDMDefaultPwr
[ii
+ CB_MAX_CHANNEL_24G
+ 1] =
377 SROMbyReadEmbedded(pDevice
->PortOffset
,
378 (unsigned char)(ii
+ EEP_OFS_OFDMA_PWR_dBm
));
381 if (pDevice
->byLocalID
> REV_ID_VT3253_B1
) {
382 MACvSelectPage1(pDevice
->PortOffset
);
384 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_MSRCTL
+ 1,
385 (MSRCTL1_TXPWR
| MSRCTL1_CSAPAREN
));
387 MACvSelectPage0(pDevice
->PortOffset
);
390 /* use relative tx timeout and 802.11i D4 */
391 MACvWordRegBitsOn(pDevice
->PortOffset
,
392 MAC_REG_CFG
, (CFG_TKIPOPT
| CFG_NOTXTIMEOUT
));
394 /* set performance parameter by registry */
395 MACvSetShortRetryLimit(pDevice
->PortOffset
, pDevice
->byShortRetryLimit
);
396 MACvSetLongRetryLimit(pDevice
->PortOffset
, pDevice
->byLongRetryLimit
);
398 /* reset TSF counter */
399 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_TFTCTL
, TFTCTL_TSFCNTRST
);
400 /* enable TSF counter */
401 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_TFTCTL
, TFTCTL_TSFCNTREN
);
403 /* initialize BBP registers */
404 BBbVT3253Init(pDevice
);
406 if (pDevice
->bUpdateBBVGA
) {
407 pDevice
->byBBVGACurrent
= pDevice
->abyBBVGA
[0];
408 pDevice
->byBBVGANew
= pDevice
->byBBVGACurrent
;
409 BBvSetVGAGainOffset(pDevice
, pDevice
->abyBBVGA
[0]);
412 BBvSetRxAntennaMode(pDevice
, pDevice
->byRxAntennaMode
);
413 BBvSetTxAntennaMode(pDevice
, pDevice
->byTxAntennaMode
);
415 /* Set BB and packet type at the same time. */
416 /* Set Short Slot Time, xIFS, and RSPINF. */
417 pDevice
->wCurrentRate
= RATE_54M
;
419 pDevice
->bRadioOff
= false;
421 pDevice
->byRadioCtl
= SROMbyReadEmbedded(pDevice
->PortOffset
,
423 pDevice
->bHWRadioOff
= false;
425 if (pDevice
->byRadioCtl
& EEP_RADIOCTL_ENABLE
) {
427 MACvGPIOIn(pDevice
->PortOffset
, &pDevice
->byGPIO
);
429 if (((pDevice
->byGPIO
& GPIO0_DATA
) &&
430 !(pDevice
->byRadioCtl
& EEP_RADIOCTL_INV
)) ||
431 (!(pDevice
->byGPIO
& GPIO0_DATA
) &&
432 (pDevice
->byRadioCtl
& EEP_RADIOCTL_INV
)))
433 pDevice
->bHWRadioOff
= true;
436 if (pDevice
->bHWRadioOff
|| pDevice
->bRadioControlOff
)
437 CARDbRadioPowerOff(pDevice
);
439 /* get Permanent network address */
440 SROMvReadEtherAddress(pDevice
->PortOffset
, pDevice
->abyCurrentNetAddr
);
441 pr_debug("Network address = %pM\n", pDevice
->abyCurrentNetAddr
);
443 /* reset Tx pointer */
444 CARDvSafeResetRx(pDevice
);
445 /* reset Rx pointer */
446 CARDvSafeResetTx(pDevice
);
448 if (pDevice
->byLocalID
<= REV_ID_VT3253_A1
)
449 MACvRegBitsOn(pDevice
->PortOffset
, MAC_REG_RCR
, RCR_WPAERR
);
452 MACvReceive0(pDevice
->PortOffset
);
453 MACvReceive1(pDevice
->PortOffset
);
455 /* start the adapter */
456 MACvStart(pDevice
->PortOffset
);
459 static void device_print_info(struct vnt_private
*pDevice
)
461 dev_info(&pDevice
->pcid
->dev
, "%s\n", get_chip_name(pDevice
->chip_id
));
463 dev_info(&pDevice
->pcid
->dev
, "MAC=%pM IO=0x%lx Mem=0x%lx IRQ=%d\n",
464 pDevice
->abyCurrentNetAddr
, (unsigned long)pDevice
->ioaddr
,
465 (unsigned long)pDevice
->PortOffset
, pDevice
->pcid
->irq
);
468 static void vt6655_init_info(struct pci_dev
*pcid
,
469 struct vnt_private
**ppDevice
,
470 PCHIP_INFO pChip_info
)
472 memset(*ppDevice
, 0, sizeof(**ppDevice
));
474 (*ppDevice
)->pcid
= pcid
;
475 (*ppDevice
)->chip_id
= pChip_info
->chip_id
;
476 (*ppDevice
)->io_size
= pChip_info
->io_size
;
477 (*ppDevice
)->nTxQueues
= pChip_info
->nTxQueue
;
478 (*ppDevice
)->multicast_limit
= 32;
480 spin_lock_init(&((*ppDevice
)->lock
));
483 static bool device_get_pci_info(struct vnt_private
*pDevice
,
484 struct pci_dev
*pcid
)
488 unsigned int cis_addr
;
490 pci_read_config_byte(pcid
, PCI_REVISION_ID
, &pDevice
->byRevId
);
491 pci_read_config_word(pcid
, PCI_SUBSYSTEM_ID
, &pDevice
->SubSystemID
);
492 pci_read_config_word(pcid
, PCI_SUBSYSTEM_VENDOR_ID
, &pDevice
->SubVendorID
);
493 pci_read_config_word(pcid
, PCI_COMMAND
, (u16
*)&(pci_cmd
));
495 pci_set_master(pcid
);
497 pDevice
->memaddr
= pci_resource_start(pcid
, 0);
498 pDevice
->ioaddr
= pci_resource_start(pcid
, 1);
500 cis_addr
= pci_resource_start(pcid
, 2);
502 pDevice
->pcid
= pcid
;
504 pci_read_config_byte(pcid
, PCI_COMMAND
, &b
);
505 pci_write_config_byte(pcid
, PCI_COMMAND
, (b
|PCI_COMMAND_MASTER
));
510 static void device_free_info(struct vnt_private
*pDevice
)
516 ieee80211_unregister_hw(pDevice
->hw
);
518 if (pDevice
->PortOffset
)
519 iounmap(pDevice
->PortOffset
);
522 pci_release_regions(pDevice
->pcid
);
525 ieee80211_free_hw(pDevice
->hw
);
528 static bool device_init_rings(struct vnt_private
*pDevice
)
532 /*allocate all RD/TD rings a single pool*/
533 vir_pool
= pci_zalloc_consistent(pDevice
->pcid
,
534 pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
) +
535 pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
) +
536 pDevice
->sOpts
.nTxDescs
[0] * sizeof(STxDesc
) +
537 pDevice
->sOpts
.nTxDescs
[1] * sizeof(STxDesc
),
539 if (vir_pool
== NULL
) {
540 dev_err(&pDevice
->pcid
->dev
, "allocate desc dma memory failed\n");
544 pDevice
->aRD0Ring
= vir_pool
;
545 pDevice
->aRD1Ring
= vir_pool
+
546 pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
);
548 pDevice
->rd0_pool_dma
= pDevice
->pool_dma
;
549 pDevice
->rd1_pool_dma
= pDevice
->rd0_pool_dma
+
550 pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
);
552 pDevice
->tx0_bufs
= pci_zalloc_consistent(pDevice
->pcid
,
553 pDevice
->sOpts
.nTxDescs
[0] * PKT_BUF_SZ
+
554 pDevice
->sOpts
.nTxDescs
[1] * PKT_BUF_SZ
+
557 &pDevice
->tx_bufs_dma0
);
558 if (pDevice
->tx0_bufs
== NULL
) {
559 dev_err(&pDevice
->pcid
->dev
, "allocate buf dma memory failed\n");
561 pci_free_consistent(pDevice
->pcid
,
562 pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
) +
563 pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
) +
564 pDevice
->sOpts
.nTxDescs
[0] * sizeof(STxDesc
) +
565 pDevice
->sOpts
.nTxDescs
[1] * sizeof(STxDesc
),
566 vir_pool
, pDevice
->pool_dma
571 pDevice
->td0_pool_dma
= pDevice
->rd1_pool_dma
+
572 pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
);
574 pDevice
->td1_pool_dma
= pDevice
->td0_pool_dma
+
575 pDevice
->sOpts
.nTxDescs
[0] * sizeof(STxDesc
);
577 // vir_pool: pvoid type
578 pDevice
->apTD0Rings
= vir_pool
579 + pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
)
580 + pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
);
582 pDevice
->apTD1Rings
= vir_pool
583 + pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
)
584 + pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
)
585 + pDevice
->sOpts
.nTxDescs
[0] * sizeof(STxDesc
);
587 pDevice
->tx1_bufs
= pDevice
->tx0_bufs
+
588 pDevice
->sOpts
.nTxDescs
[0] * PKT_BUF_SZ
;
590 pDevice
->tx_beacon_bufs
= pDevice
->tx1_bufs
+
591 pDevice
->sOpts
.nTxDescs
[1] * PKT_BUF_SZ
;
593 pDevice
->pbyTmpBuff
= pDevice
->tx_beacon_bufs
+
596 pDevice
->tx_bufs_dma1
= pDevice
->tx_bufs_dma0
+
597 pDevice
->sOpts
.nTxDescs
[0] * PKT_BUF_SZ
;
599 pDevice
->tx_beacon_dma
= pDevice
->tx_bufs_dma1
+
600 pDevice
->sOpts
.nTxDescs
[1] * PKT_BUF_SZ
;
605 static void device_free_rings(struct vnt_private
*pDevice
)
607 pci_free_consistent(pDevice
->pcid
,
608 pDevice
->sOpts
.nRxDescs0
* sizeof(SRxDesc
) +
609 pDevice
->sOpts
.nRxDescs1
* sizeof(SRxDesc
) +
610 pDevice
->sOpts
.nTxDescs
[0] * sizeof(STxDesc
) +
611 pDevice
->sOpts
.nTxDescs
[1] * sizeof(STxDesc
)
613 pDevice
->aRD0Ring
, pDevice
->pool_dma
616 if (pDevice
->tx0_bufs
)
617 pci_free_consistent(pDevice
->pcid
,
618 pDevice
->sOpts
.nTxDescs
[0] * PKT_BUF_SZ
+
619 pDevice
->sOpts
.nTxDescs
[1] * PKT_BUF_SZ
+
622 pDevice
->tx0_bufs
, pDevice
->tx_bufs_dma0
626 static void device_init_rd0_ring(struct vnt_private
*pDevice
)
629 dma_addr_t curr
= pDevice
->rd0_pool_dma
;
632 /* Init the RD0 ring entries */
633 for (i
= 0; i
< pDevice
->sOpts
.nRxDescs0
; i
++, curr
+= sizeof(SRxDesc
)) {
634 pDesc
= &(pDevice
->aRD0Ring
[i
]);
635 pDesc
->pRDInfo
= alloc_rd_info();
636 ASSERT(pDesc
->pRDInfo
);
637 if (!device_alloc_rx_buf(pDevice
, pDesc
))
638 dev_err(&pDevice
->pcid
->dev
, "can not alloc rx bufs\n");
640 pDesc
->next
= &(pDevice
->aRD0Ring
[(i
+1) % pDevice
->sOpts
.nRxDescs0
]);
641 pDesc
->pRDInfo
->curr_desc
= cpu_to_le32(curr
);
642 pDesc
->next_desc
= cpu_to_le32(curr
+ sizeof(SRxDesc
));
646 pDevice
->aRD0Ring
[i
-1].next_desc
= cpu_to_le32(pDevice
->rd0_pool_dma
);
647 pDevice
->pCurrRD
[0] = &(pDevice
->aRD0Ring
[0]);
650 static void device_init_rd1_ring(struct vnt_private
*pDevice
)
653 dma_addr_t curr
= pDevice
->rd1_pool_dma
;
656 /* Init the RD1 ring entries */
657 for (i
= 0; i
< pDevice
->sOpts
.nRxDescs1
; i
++, curr
+= sizeof(SRxDesc
)) {
658 pDesc
= &(pDevice
->aRD1Ring
[i
]);
659 pDesc
->pRDInfo
= alloc_rd_info();
660 ASSERT(pDesc
->pRDInfo
);
661 if (!device_alloc_rx_buf(pDevice
, pDesc
))
662 dev_err(&pDevice
->pcid
->dev
, "can not alloc rx bufs\n");
664 pDesc
->next
= &(pDevice
->aRD1Ring
[(i
+1) % pDevice
->sOpts
.nRxDescs1
]);
665 pDesc
->pRDInfo
->curr_desc
= cpu_to_le32(curr
);
666 pDesc
->next_desc
= cpu_to_le32(curr
+ sizeof(SRxDesc
));
670 pDevice
->aRD1Ring
[i
-1].next_desc
= cpu_to_le32(pDevice
->rd1_pool_dma
);
671 pDevice
->pCurrRD
[1] = &(pDevice
->aRD1Ring
[0]);
674 static void device_free_rd0_ring(struct vnt_private
*pDevice
)
678 for (i
= 0; i
< pDevice
->sOpts
.nRxDescs0
; i
++) {
679 PSRxDesc pDesc
= &(pDevice
->aRD0Ring
[i
]);
680 PDEVICE_RD_INFO pRDInfo
= pDesc
->pRDInfo
;
682 pci_unmap_single(pDevice
->pcid
, pRDInfo
->skb_dma
,
683 pDevice
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
685 dev_kfree_skb(pRDInfo
->skb
);
687 kfree(pDesc
->pRDInfo
);
691 static void device_free_rd1_ring(struct vnt_private
*pDevice
)
695 for (i
= 0; i
< pDevice
->sOpts
.nRxDescs1
; i
++) {
696 PSRxDesc pDesc
= &(pDevice
->aRD1Ring
[i
]);
697 PDEVICE_RD_INFO pRDInfo
= pDesc
->pRDInfo
;
699 pci_unmap_single(pDevice
->pcid
, pRDInfo
->skb_dma
,
700 pDevice
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
702 dev_kfree_skb(pRDInfo
->skb
);
704 kfree(pDesc
->pRDInfo
);
708 static void device_init_td0_ring(struct vnt_private
*pDevice
)
714 curr
= pDevice
->td0_pool_dma
;
715 for (i
= 0; i
< pDevice
->sOpts
.nTxDescs
[0]; i
++, curr
+= sizeof(STxDesc
)) {
716 pDesc
= &(pDevice
->apTD0Rings
[i
]);
717 pDesc
->pTDInfo
= alloc_td_info();
718 ASSERT(pDesc
->pTDInfo
);
719 if (pDevice
->flags
& DEVICE_FLAGS_TX_ALIGN
) {
720 pDesc
->pTDInfo
->buf
= pDevice
->tx0_bufs
+ (i
)*PKT_BUF_SZ
;
721 pDesc
->pTDInfo
->buf_dma
= pDevice
->tx_bufs_dma0
+ (i
)*PKT_BUF_SZ
;
723 pDesc
->next
= &(pDevice
->apTD0Rings
[(i
+1) % pDevice
->sOpts
.nTxDescs
[0]]);
724 pDesc
->pTDInfo
->curr_desc
= cpu_to_le32(curr
);
725 pDesc
->next_desc
= cpu_to_le32(curr
+sizeof(STxDesc
));
729 pDevice
->apTD0Rings
[i
-1].next_desc
= cpu_to_le32(pDevice
->td0_pool_dma
);
730 pDevice
->apTailTD
[0] = pDevice
->apCurrTD
[0] = &(pDevice
->apTD0Rings
[0]);
733 static void device_init_td1_ring(struct vnt_private
*pDevice
)
739 /* Init the TD ring entries */
740 curr
= pDevice
->td1_pool_dma
;
741 for (i
= 0; i
< pDevice
->sOpts
.nTxDescs
[1]; i
++, curr
+= sizeof(STxDesc
)) {
742 pDesc
= &(pDevice
->apTD1Rings
[i
]);
743 pDesc
->pTDInfo
= alloc_td_info();
744 ASSERT(pDesc
->pTDInfo
);
745 if (pDevice
->flags
& DEVICE_FLAGS_TX_ALIGN
) {
746 pDesc
->pTDInfo
->buf
= pDevice
->tx1_bufs
+ (i
) * PKT_BUF_SZ
;
747 pDesc
->pTDInfo
->buf_dma
= pDevice
->tx_bufs_dma1
+ (i
) * PKT_BUF_SZ
;
749 pDesc
->next
= &(pDevice
->apTD1Rings
[(i
+ 1) % pDevice
->sOpts
.nTxDescs
[1]]);
750 pDesc
->pTDInfo
->curr_desc
= cpu_to_le32(curr
);
751 pDesc
->next_desc
= cpu_to_le32(curr
+sizeof(STxDesc
));
755 pDevice
->apTD1Rings
[i
-1].next_desc
= cpu_to_le32(pDevice
->td1_pool_dma
);
756 pDevice
->apTailTD
[1] = pDevice
->apCurrTD
[1] = &(pDevice
->apTD1Rings
[0]);
759 static void device_free_td0_ring(struct vnt_private
*pDevice
)
763 for (i
= 0; i
< pDevice
->sOpts
.nTxDescs
[0]; i
++) {
764 PSTxDesc pDesc
= &(pDevice
->apTD0Rings
[i
]);
765 PDEVICE_TD_INFO pTDInfo
= pDesc
->pTDInfo
;
767 if (pTDInfo
->skb_dma
&& (pTDInfo
->skb_dma
!= pTDInfo
->buf_dma
))
768 pci_unmap_single(pDevice
->pcid
, pTDInfo
->skb_dma
,
769 pTDInfo
->skb
->len
, PCI_DMA_TODEVICE
);
772 dev_kfree_skb(pTDInfo
->skb
);
774 kfree(pDesc
->pTDInfo
);
778 static void device_free_td1_ring(struct vnt_private
*pDevice
)
782 for (i
= 0; i
< pDevice
->sOpts
.nTxDescs
[1]; i
++) {
783 PSTxDesc pDesc
= &(pDevice
->apTD1Rings
[i
]);
784 PDEVICE_TD_INFO pTDInfo
= pDesc
->pTDInfo
;
786 if (pTDInfo
->skb_dma
&& (pTDInfo
->skb_dma
!= pTDInfo
->buf_dma
))
787 pci_unmap_single(pDevice
->pcid
, pTDInfo
->skb_dma
,
788 pTDInfo
->skb
->len
, PCI_DMA_TODEVICE
);
791 dev_kfree_skb(pTDInfo
->skb
);
793 kfree(pDesc
->pTDInfo
);
797 /*-----------------------------------------------------------------*/
799 static int device_rx_srv(struct vnt_private
*pDevice
, unsigned int uIdx
)
804 for (pRD
= pDevice
->pCurrRD
[uIdx
];
805 pRD
->m_rd0RD0
.f1Owner
== OWNED_BY_HOST
;
809 if (vnt_receive_frame(pDevice
, pRD
)) {
810 if (!device_alloc_rx_buf(pDevice
, pRD
)) {
811 dev_err(&pDevice
->pcid
->dev
,
812 "can not allocate rx buf\n");
816 pRD
->m_rd0RD0
.f1Owner
= OWNED_BY_NIC
;
819 pDevice
->pCurrRD
[uIdx
] = pRD
;
824 static bool device_alloc_rx_buf(struct vnt_private
*pDevice
, PSRxDesc pRD
)
826 PDEVICE_RD_INFO pRDInfo
= pRD
->pRDInfo
;
828 pRDInfo
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
829 if (pRDInfo
->skb
== NULL
)
831 ASSERT(pRDInfo
->skb
);
834 pci_map_single(pDevice
->pcid
,
835 skb_put(pRDInfo
->skb
, skb_tailroom(pRDInfo
->skb
)),
836 pDevice
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
838 *((unsigned int *)&(pRD
->m_rd0RD0
)) = 0; /* FIX cast */
840 pRD
->m_rd0RD0
.wResCount
= cpu_to_le16(pDevice
->rx_buf_sz
);
841 pRD
->m_rd0RD0
.f1Owner
= OWNED_BY_NIC
;
842 pRD
->m_rd1RD1
.wReqCount
= cpu_to_le16(pDevice
->rx_buf_sz
);
843 pRD
->buff_addr
= cpu_to_le32(pRDInfo
->skb_dma
);
848 static const u8 fallback_rate0
[5][5] = {
849 {RATE_18M
, RATE_18M
, RATE_12M
, RATE_12M
, RATE_12M
},
850 {RATE_24M
, RATE_24M
, RATE_18M
, RATE_12M
, RATE_12M
},
851 {RATE_36M
, RATE_36M
, RATE_24M
, RATE_18M
, RATE_18M
},
852 {RATE_48M
, RATE_48M
, RATE_36M
, RATE_24M
, RATE_24M
},
853 {RATE_54M
, RATE_54M
, RATE_48M
, RATE_36M
, RATE_36M
}
856 static const u8 fallback_rate1
[5][5] = {
857 {RATE_18M
, RATE_18M
, RATE_12M
, RATE_6M
, RATE_6M
},
858 {RATE_24M
, RATE_24M
, RATE_18M
, RATE_6M
, RATE_6M
},
859 {RATE_36M
, RATE_36M
, RATE_24M
, RATE_12M
, RATE_12M
},
860 {RATE_48M
, RATE_48M
, RATE_24M
, RATE_12M
, RATE_12M
},
861 {RATE_54M
, RATE_54M
, RATE_36M
, RATE_18M
, RATE_18M
}
864 static int vnt_int_report_rate(struct vnt_private
*priv
,
865 PDEVICE_TD_INFO context
, u8 tsr0
, u8 tsr1
)
867 struct vnt_tx_fifo_head
*fifo_head
;
868 struct ieee80211_tx_info
*info
;
869 struct ieee80211_rate
*rate
;
871 u8 tx_retry
= (tsr0
& TSR0_NCR
);
880 fifo_head
= (struct vnt_tx_fifo_head
*)context
->buf
;
881 fb_option
= (le16_to_cpu(fifo_head
->fifo_ctl
) &
882 (FIFOCTL_AUTO_FB_0
| FIFOCTL_AUTO_FB_1
));
884 info
= IEEE80211_SKB_CB(context
->skb
);
885 idx
= info
->control
.rates
[0].idx
;
887 if (fb_option
&& !(tsr1
& TSR1_TERR
)) {
891 rate
= ieee80211_get_tx_rate(priv
->hw
, info
);
892 tx_rate
= rate
->hw_value
- RATE_18M
;
897 if (fb_option
& FIFOCTL_AUTO_FB_0
)
898 tx_rate
= fallback_rate0
[tx_rate
][retry
];
899 else if (fb_option
& FIFOCTL_AUTO_FB_1
)
900 tx_rate
= fallback_rate1
[tx_rate
][retry
];
902 if (info
->band
== IEEE80211_BAND_5GHZ
)
903 idx
= tx_rate
- RATE_6M
;
908 ieee80211_tx_info_clear_status(info
);
910 info
->status
.rates
[0].count
= tx_retry
;
912 if (!(tsr1
& TSR1_TERR
)) {
913 info
->status
.rates
[0].idx
= idx
;
914 info
->flags
|= IEEE80211_TX_STAT_ACK
;
920 static int device_tx_srv(struct vnt_private
*pDevice
, unsigned int uIdx
)
924 unsigned char byTsr0
;
925 unsigned char byTsr1
;
927 for (pTD
= pDevice
->apTailTD
[uIdx
]; pDevice
->iTDUsed
[uIdx
] > 0; pTD
= pTD
->next
) {
928 if (pTD
->m_td0TD0
.f1Owner
== OWNED_BY_NIC
)
933 byTsr0
= pTD
->m_td0TD0
.byTSR0
;
934 byTsr1
= pTD
->m_td0TD0
.byTSR1
;
936 //Only the status of first TD in the chain is correct
937 if (pTD
->m_td1TD1
.byTCR
& TCR_STP
) {
938 if ((pTD
->pTDInfo
->byFlags
& TD_FLAGS_NETIF_SKB
) != 0) {
940 vnt_int_report_rate(pDevice
, pTD
->pTDInfo
, byTsr0
, byTsr1
);
942 if (!(byTsr1
& TSR1_TERR
)) {
944 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
949 pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
950 (int)uIdx
, byTsr1
, byTsr0
);
954 if (byTsr1
& TSR1_TERR
) {
955 if ((pTD
->pTDInfo
->byFlags
& TD_FLAGS_PRIV_SKB
) != 0) {
956 pr_debug(" Tx[%d] fail has error. tsr1[%02X] tsr0[%02X]\n",
957 (int)uIdx
, byTsr1
, byTsr0
);
960 device_free_tx_buf(pDevice
, pTD
);
961 pDevice
->iTDUsed
[uIdx
]--;
965 pDevice
->apTailTD
[uIdx
] = pTD
;
970 static void device_error(struct vnt_private
*pDevice
, unsigned short status
)
972 if (status
& ISR_FETALERR
) {
973 dev_err(&pDevice
->pcid
->dev
, "Hardware fatal error\n");
975 MACbShutdown(pDevice
->PortOffset
);
980 static void device_free_tx_buf(struct vnt_private
*pDevice
, PSTxDesc pDesc
)
982 PDEVICE_TD_INFO pTDInfo
= pDesc
->pTDInfo
;
983 struct sk_buff
*skb
= pTDInfo
->skb
;
985 // pre-allocated buf_dma can't be unmapped.
986 if (pTDInfo
->skb_dma
&& (pTDInfo
->skb_dma
!= pTDInfo
->buf_dma
)) {
987 pci_unmap_single(pDevice
->pcid
, pTDInfo
->skb_dma
, skb
->len
,
991 if (pTDInfo
->byFlags
& TD_FLAGS_NETIF_SKB
)
992 ieee80211_tx_status_irqsafe(pDevice
->hw
, skb
);
994 dev_kfree_skb_irq(skb
);
996 pTDInfo
->skb_dma
= 0;
998 pTDInfo
->byFlags
= 0;
1001 static void vnt_check_bb_vga(struct vnt_private
*priv
)
1006 if (!priv
->bUpdateBBVGA
)
1009 if (priv
->hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
)
1012 if (!(priv
->vif
->bss_conf
.assoc
&& priv
->uCurrRSSI
))
1015 RFvRSSITodBm(priv
, (u8
)priv
->uCurrRSSI
, &dbm
);
1017 for (i
= 0; i
< BB_VGA_LEVEL
; i
++) {
1018 if (dbm
< priv
->ldBmThreshold
[i
]) {
1019 priv
->byBBVGANew
= priv
->abyBBVGA
[i
];
1024 if (priv
->byBBVGANew
== priv
->byBBVGACurrent
) {
1025 priv
->uBBVGADiffCount
= 1;
1029 priv
->uBBVGADiffCount
++;
1031 if (priv
->uBBVGADiffCount
== 1) {
1032 /* first VGA diff gain */
1033 BBvSetVGAGainOffset(priv
, priv
->byBBVGANew
);
1035 dev_dbg(&priv
->pcid
->dev
,
1036 "First RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1037 (int)dbm
, priv
->byBBVGANew
,
1038 priv
->byBBVGACurrent
,
1039 (int)priv
->uBBVGADiffCount
);
1042 if (priv
->uBBVGADiffCount
>= BB_VGA_CHANGE_THRESHOLD
) {
1043 dev_dbg(&priv
->pcid
->dev
,
1044 "RSSI[%d] NewGain[%d] OldGain[%d] Count[%d]\n",
1045 (int)dbm
, priv
->byBBVGANew
,
1046 priv
->byBBVGACurrent
,
1047 (int)priv
->uBBVGADiffCount
);
1049 BBvSetVGAGainOffset(priv
, priv
->byBBVGANew
);
1053 static irqreturn_t
device_intr(int irq
, void *dev_instance
)
1055 struct vnt_private
*pDevice
= dev_instance
;
1057 unsigned long dwMIBCounter
= 0;
1058 unsigned char byOrgPageSel
= 0;
1060 unsigned long flags
;
1062 MACvReadISR(pDevice
->PortOffset
, &pDevice
->dwIsr
);
1064 if (pDevice
->dwIsr
== 0)
1065 return IRQ_RETVAL(handled
);
1067 if (pDevice
->dwIsr
== 0xffffffff) {
1068 pr_debug("dwIsr = 0xffff\n");
1069 return IRQ_RETVAL(handled
);
1073 MACvIntDisable(pDevice
->PortOffset
);
1075 spin_lock_irqsave(&pDevice
->lock
, flags
);
1077 //Make sure current page is 0
1078 VNSvInPortB(pDevice
->PortOffset
+ MAC_REG_PAGE1SEL
, &byOrgPageSel
);
1079 if (byOrgPageSel
== 1)
1080 MACvSelectPage0(pDevice
->PortOffset
);
1084 MACvReadMIBCounter(pDevice
->PortOffset
, &dwMIBCounter
);
1086 // Must do this after doing rx/tx, cause ISR bit is slow
1087 // than RD/TD write back
1088 // update ISR counter
1089 STAvUpdate802_11Counter(&pDevice
->s802_11Counter
, &pDevice
->scStatistic
, dwMIBCounter
);
1090 while (pDevice
->dwIsr
!= 0) {
1091 STAvUpdateIsrStatCounter(&pDevice
->scStatistic
, pDevice
->dwIsr
);
1092 MACvWriteISR(pDevice
->PortOffset
, pDevice
->dwIsr
);
1094 if (pDevice
->dwIsr
& ISR_FETALERR
) {
1095 pr_debug(" ISR_FETALERR\n");
1096 VNSvOutPortB(pDevice
->PortOffset
+ MAC_REG_SOFTPWRCTL
, 0);
1097 VNSvOutPortW(pDevice
->PortOffset
+ MAC_REG_SOFTPWRCTL
, SOFTPWRCTL_SWPECTI
);
1098 device_error(pDevice
, pDevice
->dwIsr
);
1101 if (pDevice
->dwIsr
& ISR_TBTT
) {
1103 pDevice
->op_mode
!= NL80211_IFTYPE_ADHOC
)
1104 vnt_check_bb_vga(pDevice
);
1106 pDevice
->bBeaconSent
= false;
1107 if (pDevice
->bEnablePSMode
)
1108 PSbIsNextTBTTWakeUp((void *)pDevice
);
1110 if ((pDevice
->op_mode
== NL80211_IFTYPE_AP
||
1111 pDevice
->op_mode
== NL80211_IFTYPE_ADHOC
) &&
1112 pDevice
->vif
->bss_conf
.enable_beacon
) {
1113 MACvOneShotTimer1MicroSec(pDevice
->PortOffset
,
1114 (pDevice
->vif
->bss_conf
.beacon_int
- MAKE_BEACON_RESERVED
) << 10);
1117 /* TODO: adhoc PS mode */
1121 if (pDevice
->dwIsr
& ISR_BNTX
) {
1122 if (pDevice
->op_mode
== NL80211_IFTYPE_ADHOC
) {
1123 pDevice
->bIsBeaconBufReadySet
= false;
1124 pDevice
->cbBeaconBufReadySetCnt
= 0;
1127 pDevice
->bBeaconSent
= true;
1130 if (pDevice
->dwIsr
& ISR_RXDMA0
)
1131 max_count
+= device_rx_srv(pDevice
, TYPE_RXDMA0
);
1133 if (pDevice
->dwIsr
& ISR_RXDMA1
)
1134 max_count
+= device_rx_srv(pDevice
, TYPE_RXDMA1
);
1136 if (pDevice
->dwIsr
& ISR_TXDMA0
)
1137 max_count
+= device_tx_srv(pDevice
, TYPE_TXDMA0
);
1139 if (pDevice
->dwIsr
& ISR_AC0DMA
)
1140 max_count
+= device_tx_srv(pDevice
, TYPE_AC0DMA
);
1142 if (pDevice
->dwIsr
& ISR_SOFTTIMER1
) {
1144 if (pDevice
->vif
->bss_conf
.enable_beacon
)
1145 vnt_beacon_make(pDevice
, pDevice
->vif
);
1149 /* If both buffers available wake the queue */
1151 if (AVAIL_TD(pDevice
, TYPE_TXDMA0
) &&
1152 AVAIL_TD(pDevice
, TYPE_AC0DMA
) &&
1153 ieee80211_queue_stopped(pDevice
->hw
, 0))
1154 ieee80211_wake_queues(pDevice
->hw
);
1157 MACvReadISR(pDevice
->PortOffset
, &pDevice
->dwIsr
);
1159 MACvReceive0(pDevice
->PortOffset
);
1160 MACvReceive1(pDevice
->PortOffset
);
1162 if (max_count
> pDevice
->sOpts
.int_works
)
1166 if (byOrgPageSel
== 1)
1167 MACvSelectPage1(pDevice
->PortOffset
);
1169 spin_unlock_irqrestore(&pDevice
->lock
, flags
);
1171 MACvIntEnable(pDevice
->PortOffset
, IMR_MASK_VALUE
);
1173 return IRQ_RETVAL(handled
);
1176 static int vnt_tx_packet(struct vnt_private
*priv
, struct sk_buff
*skb
)
1178 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
1181 unsigned long flags
;
1183 spin_lock_irqsave(&priv
->lock
, flags
);
1185 if (ieee80211_is_data(hdr
->frame_control
))
1186 dma_idx
= TYPE_AC0DMA
;
1188 dma_idx
= TYPE_TXDMA0
;
1190 if (AVAIL_TD(priv
, dma_idx
) < 1) {
1191 spin_unlock_irqrestore(&priv
->lock
, flags
);
1195 head_td
= priv
->apCurrTD
[dma_idx
];
1197 head_td
->m_td1TD1
.byTCR
= 0;
1199 head_td
->pTDInfo
->skb
= skb
;
1201 if (dma_idx
== TYPE_AC0DMA
)
1202 head_td
->pTDInfo
->byFlags
= TD_FLAGS_NETIF_SKB
;
1204 priv
->iTDUsed
[dma_idx
]++;
1206 /* Take ownership */
1208 head_td
->m_td0TD0
.f1Owner
= OWNED_BY_NIC
;
1212 priv
->apCurrTD
[dma_idx
] = head_td
->next
;
1214 spin_unlock_irqrestore(&priv
->lock
, flags
);
1216 vnt_generate_fifo_header(priv
, dma_idx
, head_td
, skb
);
1218 if (MACbIsRegBitsOn(priv
->PortOffset
, MAC_REG_PSCTL
, PSCTL_PS
))
1219 MACbPSWakeup(priv
->PortOffset
);
1221 spin_lock_irqsave(&priv
->lock
, flags
);
1223 priv
->bPWBitOn
= false;
1225 /* Set TSR1 & ReqCount in TxDescHead */
1226 head_td
->m_td1TD1
.byTCR
|= (TCR_STP
| TCR_EDP
| EDMSDU
);
1227 head_td
->m_td1TD1
.wReqCount
=
1228 cpu_to_le16((u16
)head_td
->pTDInfo
->dwReqCount
);
1230 head_td
->buff_addr
= cpu_to_le32(head_td
->pTDInfo
->skb_dma
);
1232 if (head_td
->pTDInfo
->byFlags
& TD_FLAGS_NETIF_SKB
)
1233 MACvTransmitAC0(priv
->PortOffset
);
1235 MACvTransmit0(priv
->PortOffset
);
1237 spin_unlock_irqrestore(&priv
->lock
, flags
);
1242 static void vnt_tx_80211(struct ieee80211_hw
*hw
,
1243 struct ieee80211_tx_control
*control
,
1244 struct sk_buff
*skb
)
1246 struct vnt_private
*priv
= hw
->priv
;
1248 ieee80211_stop_queues(hw
);
1250 if (vnt_tx_packet(priv
, skb
)) {
1251 ieee80211_free_txskb(hw
, skb
);
1253 ieee80211_wake_queues(hw
);
1257 static int vnt_start(struct ieee80211_hw
*hw
)
1259 struct vnt_private
*priv
= hw
->priv
;
1262 priv
->rx_buf_sz
= PKT_BUF_SZ
;
1263 if (!device_init_rings(priv
))
1266 ret
= request_irq(priv
->pcid
->irq
, &device_intr
,
1267 IRQF_SHARED
, "vt6655", priv
);
1269 dev_dbg(&priv
->pcid
->dev
, "failed to start irq\n");
1273 dev_dbg(&priv
->pcid
->dev
, "call device init rd0 ring\n");
1274 device_init_rd0_ring(priv
);
1275 device_init_rd1_ring(priv
);
1276 device_init_td0_ring(priv
);
1277 device_init_td1_ring(priv
);
1279 device_init_registers(priv
);
1281 dev_dbg(&priv
->pcid
->dev
, "call MACvIntEnable\n");
1282 MACvIntEnable(priv
->PortOffset
, IMR_MASK_VALUE
);
1284 ieee80211_wake_queues(hw
);
1289 static void vnt_stop(struct ieee80211_hw
*hw
)
1291 struct vnt_private
*priv
= hw
->priv
;
1293 ieee80211_stop_queues(hw
);
1295 MACbShutdown(priv
->PortOffset
);
1296 MACbSoftwareReset(priv
->PortOffset
);
1297 CARDbRadioPowerOff(priv
);
1299 device_free_td0_ring(priv
);
1300 device_free_td1_ring(priv
);
1301 device_free_rd0_ring(priv
);
1302 device_free_rd1_ring(priv
);
1303 device_free_rings(priv
);
1305 free_irq(priv
->pcid
->irq
, priv
);
1308 static int vnt_add_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1310 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_RCR
, RCR_UNICAST
);
1320 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_ADHOC
);
1323 case NL80211_IFTYPE_AP
:
1324 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_RCR
, RCR_UNICAST
);
1326 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_AP
);
1333 priv
->op_mode
= vif
->type
;
1338 static void vnt_remove_interface(struct ieee80211_hw
*hw
,
1339 struct ieee80211_vif
*vif
)
1341 struct vnt_private
*priv
= hw
->priv
;
1343 switch (vif
->type
) {
1344 case NL80211_IFTYPE_STATION
:
1346 case NL80211_IFTYPE_ADHOC
:
1347 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_TCR
, TCR_AUTOBCNTX
);
1348 MACvRegBitsOff(priv
->PortOffset
,
1349 MAC_REG_TFTCTL
, TFTCTL_TSFCNTREN
);
1350 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_ADHOC
);
1352 case NL80211_IFTYPE_AP
:
1353 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_TCR
, TCR_AUTOBCNTX
);
1354 MACvRegBitsOff(priv
->PortOffset
,
1355 MAC_REG_TFTCTL
, TFTCTL_TSFCNTREN
);
1356 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_HOSTCR
, HOSTCR_AP
);
1362 priv
->op_mode
= NL80211_IFTYPE_UNSPECIFIED
;
1366 static int vnt_config(struct ieee80211_hw
*hw
, u32 changed
)
1368 struct vnt_private
*priv
= hw
->priv
;
1369 struct ieee80211_conf
*conf
= &hw
->conf
;
1372 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1373 if (conf
->flags
& IEEE80211_CONF_PS
)
1374 PSvEnablePowerSaving(priv
, conf
->listen_interval
);
1376 PSvDisablePowerSaving(priv
);
1379 if ((changed
& IEEE80211_CONF_CHANGE_CHANNEL
) ||
1380 (conf
->flags
& IEEE80211_CONF_OFFCHANNEL
)) {
1381 set_channel(priv
, conf
->chandef
.chan
);
1383 if (conf
->chandef
.chan
->band
== IEEE80211_BAND_5GHZ
)
1384 bb_type
= BB_TYPE_11A
;
1386 bb_type
= BB_TYPE_11G
;
1388 if (priv
->byBBType
!= bb_type
) {
1389 priv
->byBBType
= bb_type
;
1391 CARDbSetPhyParameter(priv
, priv
->byBBType
);
1395 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1396 if (priv
->byBBType
== BB_TYPE_11B
)
1397 priv
->wCurrentRate
= RATE_1M
;
1399 priv
->wCurrentRate
= RATE_54M
;
1401 RFbSetPower(priv
, priv
->wCurrentRate
,
1402 conf
->chandef
.chan
->hw_value
);
1408 static void vnt_bss_info_changed(struct ieee80211_hw
*hw
,
1409 struct ieee80211_vif
*vif
, struct ieee80211_bss_conf
*conf
,
1412 struct vnt_private
*priv
= hw
->priv
;
1414 priv
->current_aid
= conf
->aid
;
1416 if (changed
& BSS_CHANGED_BSSID
)
1417 MACvWriteBSSIDAddress(priv
->PortOffset
, (u8
*)conf
->bssid
);
1419 if (changed
& BSS_CHANGED_BASIC_RATES
) {
1420 priv
->basic_rates
= conf
->basic_rates
;
1422 CARDvUpdateBasicTopRate(priv
);
1424 dev_dbg(&priv
->pcid
->dev
,
1425 "basic rates %x\n", conf
->basic_rates
);
1428 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1429 if (conf
->use_short_preamble
) {
1430 MACvEnableBarkerPreambleMd(priv
->PortOffset
);
1431 priv
->byPreambleType
= true;
1433 MACvDisableBarkerPreambleMd(priv
->PortOffset
);
1434 priv
->byPreambleType
= false;
1438 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1439 if (conf
->use_cts_prot
)
1440 MACvEnableProtectMD(priv
->PortOffset
);
1442 MACvDisableProtectMD(priv
->PortOffset
);
1445 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1446 if (conf
->use_short_slot
)
1447 priv
->bShortSlotTime
= true;
1449 priv
->bShortSlotTime
= false;
1451 CARDbSetPhyParameter(priv
, priv
->byBBType
);
1452 BBvSetVGAGainOffset(priv
, priv
->abyBBVGA
[0]);
1455 if (changed
& BSS_CHANGED_TXPOWER
)
1456 RFbSetPower(priv
, priv
->wCurrentRate
,
1457 conf
->chandef
.chan
->hw_value
);
1459 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
1460 dev_dbg(&priv
->pcid
->dev
,
1461 "Beacon enable %d\n", conf
->enable_beacon
);
1463 if (conf
->enable_beacon
) {
1464 vnt_beacon_enable(priv
, vif
, conf
);
1466 MACvRegBitsOn(priv
->PortOffset
, MAC_REG_TCR
,
1469 MACvRegBitsOff(priv
->PortOffset
, MAC_REG_TCR
,
1474 if (changed
& BSS_CHANGED_ASSOC
&& priv
->op_mode
!= NL80211_IFTYPE_AP
) {
1476 CARDbUpdateTSF(priv
, conf
->beacon_rate
->hw_value
,
1477 conf
->sync_device_ts
, conf
->sync_tsf
);
1479 CARDbSetBeaconPeriod(priv
, conf
->beacon_int
);
1481 CARDvSetFirstNextTBTT(priv
, conf
->beacon_int
);
1483 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_TFTCTL
,
1485 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_TFTCTL
,
1491 static u64
vnt_prepare_multicast(struct ieee80211_hw
*hw
,
1492 struct netdev_hw_addr_list
*mc_list
)
1494 struct vnt_private
*priv
= hw
->priv
;
1495 struct netdev_hw_addr
*ha
;
1499 netdev_hw_addr_list_for_each(ha
, mc_list
) {
1500 bit_nr
= ether_crc(ETH_ALEN
, ha
->addr
) >> 26;
1502 mc_filter
|= 1ULL << (bit_nr
& 0x3f);
1505 priv
->mc_list_count
= mc_list
->count
;
1510 static void vnt_configure(struct ieee80211_hw
*hw
,
1511 unsigned int changed_flags
, unsigned int *total_flags
, u64 multicast
)
1513 struct vnt_private
*priv
= hw
->priv
;
1516 *total_flags
&= FIF_ALLMULTI
| FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
|
1517 FIF_BCN_PRBRESP_PROMISC
;
1519 VNSvInPortB(priv
->PortOffset
+ MAC_REG_RCR
, &rx_mode
);
1521 dev_dbg(&priv
->pcid
->dev
, "rx mode in = %x\n", rx_mode
);
1523 if (changed_flags
& FIF_PROMISC_IN_BSS
) {
1524 /* unconditionally log net taps */
1525 if (*total_flags
& FIF_PROMISC_IN_BSS
)
1526 rx_mode
|= RCR_UNICAST
;
1528 rx_mode
&= ~RCR_UNICAST
;
1531 if (changed_flags
& FIF_ALLMULTI
) {
1532 if (*total_flags
& FIF_ALLMULTI
) {
1533 unsigned long flags
;
1535 spin_lock_irqsave(&priv
->lock
, flags
);
1537 if (priv
->mc_list_count
> 2) {
1538 MACvSelectPage1(priv
->PortOffset
);
1540 VNSvOutPortD(priv
->PortOffset
+
1541 MAC_REG_MAR0
, 0xffffffff);
1542 VNSvOutPortD(priv
->PortOffset
+
1543 MAC_REG_MAR0
+ 4, 0xffffffff);
1545 MACvSelectPage0(priv
->PortOffset
);
1547 MACvSelectPage1(priv
->PortOffset
);
1549 VNSvOutPortD(priv
->PortOffset
+
1550 MAC_REG_MAR0
, (u32
)multicast
);
1551 VNSvOutPortD(priv
->PortOffset
+
1553 (u32
)(multicast
>> 32));
1555 MACvSelectPage0(priv
->PortOffset
);
1558 spin_unlock_irqrestore(&priv
->lock
, flags
);
1560 rx_mode
|= RCR_MULTICAST
| RCR_BROADCAST
;
1562 rx_mode
&= ~(RCR_MULTICAST
| RCR_BROADCAST
);
1566 if (changed_flags
& (FIF_OTHER_BSS
| FIF_BCN_PRBRESP_PROMISC
)) {
1567 rx_mode
|= RCR_MULTICAST
| RCR_BROADCAST
;
1569 if (*total_flags
& (FIF_OTHER_BSS
| FIF_BCN_PRBRESP_PROMISC
))
1570 rx_mode
&= ~RCR_BSSID
;
1572 rx_mode
|= RCR_BSSID
;
1575 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_RCR
, rx_mode
);
1577 dev_dbg(&priv
->pcid
->dev
, "rx mode out= %x\n", rx_mode
);
1580 static int vnt_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
1581 struct ieee80211_vif
*vif
, struct ieee80211_sta
*sta
,
1582 struct ieee80211_key_conf
*key
)
1584 struct vnt_private
*priv
= hw
->priv
;
1588 if (vnt_set_keys(hw
, sta
, vif
, key
))
1592 if (test_bit(key
->hw_key_idx
, &priv
->key_entry_inuse
))
1593 clear_bit(key
->hw_key_idx
, &priv
->key_entry_inuse
);
1601 static u64
vnt_get_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1603 struct vnt_private
*priv
= hw
->priv
;
1606 CARDbGetCurrentTSF(priv
, &tsf
);
1611 static void vnt_set_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1614 struct vnt_private
*priv
= hw
->priv
;
1616 CARDvUpdateNextTBTT(priv
, tsf
, vif
->bss_conf
.beacon_int
);
1619 static void vnt_reset_tsf(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1621 struct vnt_private
*priv
= hw
->priv
;
1623 /* reset TSF counter */
1624 VNSvOutPortB(priv
->PortOffset
+ MAC_REG_TFTCTL
, TFTCTL_TSFCNTRST
);
1627 static const struct ieee80211_ops vnt_mac_ops
= {
1631 .add_interface
= vnt_add_interface
,
1632 .remove_interface
= vnt_remove_interface
,
1633 .config
= vnt_config
,
1634 .bss_info_changed
= vnt_bss_info_changed
,
1635 .prepare_multicast
= vnt_prepare_multicast
,
1636 .configure_filter
= vnt_configure
,
1637 .set_key
= vnt_set_key
,
1638 .get_tsf
= vnt_get_tsf
,
1639 .set_tsf
= vnt_set_tsf
,
1640 .reset_tsf
= vnt_reset_tsf
,
1643 static int vnt_init(struct vnt_private
*priv
)
1645 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->abyCurrentNetAddr
);
1647 vnt_init_bands(priv
);
1649 if (ieee80211_register_hw(priv
->hw
))
1652 priv
->mac_hw
= true;
1654 CARDbRadioPowerOff(priv
);
1660 vt6655_probe(struct pci_dev
*pcid
, const struct pci_device_id
*ent
)
1662 PCHIP_INFO pChip_info
= (PCHIP_INFO
)ent
->driver_data
;
1663 struct vnt_private
*priv
;
1664 struct ieee80211_hw
*hw
;
1665 struct wiphy
*wiphy
;
1668 dev_notice(&pcid
->dev
,
1669 "%s Ver. %s\n", DEVICE_FULL_DRV_NAM
, DEVICE_VERSION
);
1671 dev_notice(&pcid
->dev
,
1672 "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
1674 hw
= ieee80211_alloc_hw(sizeof(*priv
), &vnt_mac_ops
);
1676 dev_err(&pcid
->dev
, "could not register ieee80211_hw\n");
1682 vt6655_init_info(pcid
, &priv
, pChip_info
);
1686 SET_IEEE80211_DEV(priv
->hw
, &pcid
->dev
);
1688 if (pci_enable_device(pcid
)) {
1689 device_free_info(priv
);
1694 "Before get pci_info memaddr is %x\n", priv
->memaddr
);
1696 if (!device_get_pci_info(priv
, pcid
)) {
1697 dev_err(&pcid
->dev
, ": Failed to find PCI device.\n");
1698 device_free_info(priv
);
1704 "after get pci_info memaddr is %x, io addr is %x,io_size is %d\n",
1705 priv
->memaddr
, priv
->ioaddr
, priv
->io_size
);
1717 for (i
= 0; address
[i
]; i
++) {
1718 pci_read_config_dword(pcid
, address
[i
], &bar
);
1720 dev_dbg(&pcid
->dev
, "bar %d is %x\n", i
, bar
);
1724 "bar %d not implemented\n", i
);
1728 if (bar
& PCI_BASE_ADDRESS_SPACE_IO
) {
1731 len
= bar
& (PCI_BASE_ADDRESS_IO_MASK
& 0xffff);
1732 len
= len
& ~(len
- 1);
1735 "IO space: len in IO %x, BAR %d\n",
1738 len
= bar
& 0xfffffff0;
1742 "len in MEM %x, BAR %d\n", len
, i
);
1748 priv
->PortOffset
= ioremap(priv
->memaddr
& PCI_BASE_ADDRESS_MEM_MASK
,
1750 if (!priv
->PortOffset
) {
1751 dev_err(&pcid
->dev
, ": Failed to IO remapping ..\n");
1752 device_free_info(priv
);
1756 rc
= pci_request_regions(pcid
, DEVICE_NAME
);
1758 dev_err(&pcid
->dev
, ": Failed to find PCI device\n");
1759 device_free_info(priv
);
1764 if (!MACbSoftwareReset(priv
->PortOffset
)) {
1765 dev_err(&pcid
->dev
, ": Failed to access MAC hardware..\n");
1766 device_free_info(priv
);
1769 /* initial to reload eeprom */
1770 MACvInitialize(priv
->PortOffset
);
1771 MACvReadEtherAddress(priv
->PortOffset
, priv
->abyCurrentNetAddr
);
1774 priv
->byRFType
= SROMbyReadEmbedded(priv
->PortOffset
, EEP_OFS_RFTYPE
);
1775 priv
->byRFType
&= RF_MASK
;
1777 dev_dbg(&pcid
->dev
, "RF Type = %x\n", priv
->byRFType
);
1779 device_get_options(priv
);
1780 device_set_options(priv
);
1781 /* Mask out the options cannot be set to the chip */
1782 priv
->sOpts
.flags
&= pChip_info
->flags
;
1784 /* Enable the chip specified capabilities */
1785 priv
->flags
= priv
->sOpts
.flags
| (pChip_info
->flags
& 0xff000000UL
);
1787 wiphy
= priv
->hw
->wiphy
;
1789 wiphy
->frag_threshold
= FRAG_THRESH_DEF
;
1790 wiphy
->rts_threshold
= RTS_THRESH_DEF
;
1791 wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
1792 BIT(NL80211_IFTYPE_ADHOC
) | BIT(NL80211_IFTYPE_AP
);
1794 priv
->hw
->flags
= IEEE80211_HW_RX_INCLUDES_FCS
|
1795 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
1796 IEEE80211_HW_SIGNAL_DBM
|
1797 IEEE80211_HW_TIMING_BEACON_ONLY
;
1799 priv
->hw
->max_signal
= 100;
1804 device_print_info(priv
);
1805 pci_set_drvdata(pcid
, priv
);
1810 /*------------------------------------------------------------------*/
1813 static int vt6655_suspend(struct pci_dev
*pcid
, pm_message_t state
)
1815 struct vnt_private
*priv
= pci_get_drvdata(pcid
);
1816 unsigned long flags
;
1818 spin_lock_irqsave(&priv
->lock
, flags
);
1820 pci_save_state(pcid
);
1822 MACbShutdown(priv
->PortOffset
);
1824 pci_disable_device(pcid
);
1825 pci_set_power_state(pcid
, pci_choose_state(pcid
, state
));
1827 spin_unlock_irqrestore(&priv
->lock
, flags
);
1832 static int vt6655_resume(struct pci_dev
*pcid
)
1835 pci_set_power_state(pcid
, PCI_D0
);
1836 pci_enable_wake(pcid
, PCI_D0
, 0);
1837 pci_restore_state(pcid
);
1843 MODULE_DEVICE_TABLE(pci
, vt6655_pci_id_table
);
1845 static struct pci_driver device_driver
= {
1846 .name
= DEVICE_NAME
,
1847 .id_table
= vt6655_pci_id_table
,
1848 .probe
= vt6655_probe
,
1849 .remove
= vt6655_remove
,
1851 .suspend
= vt6655_suspend
,
1852 .resume
= vt6655_resume
,
1856 static int __init
vt6655_init_module(void)
1860 ret
= pci_register_driver(&device_driver
);
1863 register_reboot_notifier(&device_notifier
);
1869 static void __exit
vt6655_cleanup_module(void)
1872 unregister_reboot_notifier(&device_notifier
);
1874 pci_unregister_driver(&device_driver
);
1877 module_init(vt6655_init_module
);
1878 module_exit(vt6655_cleanup_module
);
1882 device_notify_reboot(struct notifier_block
*nb
, unsigned long event
, void *p
)
1884 struct pci_dev
*pdev
= NULL
;
1890 for_each_pci_dev(pdev
) {
1891 if (pci_dev_driver(pdev
) == &device_driver
) {
1892 if (pci_get_drvdata(pdev
))
1893 vt6655_suspend(pdev
, PMSG_HIBERNATE
);