]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/vt6655/device_main.c
staging: vt6655: remove get_chip_name and info message.
[karo-tx-linux.git] / drivers / staging / vt6655 / device_main.c
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
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.
9  *
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.
14  *
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.
18  *
19  * File: device_main.c
20  *
21  * Purpose: driver entry for initial, open, close, tx and rx.
22  *
23  * Author: Lyndon Chen
24  *
25  * Date: Jan 8, 2003
26  *
27  * Functions:
28  *
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
46  *
47  * Revision History:
48  */
49 #undef __NO_VERSION__
50
51 #include <linux/file.h>
52 #include "device.h"
53 #include "card.h"
54 #include "channel.h"
55 #include "baseband.h"
56 #include "mac.h"
57 #include "power.h"
58 #include "rxtx.h"
59 #include "dpc.h"
60 #include "rf.h"
61 #include <linux/delay.h>
62 #include <linux/kthread.h>
63 #include <linux/slab.h>
64
65 /*---------------------  Static Definitions -------------------------*/
66 /*
67  * Define module options
68  */
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");
72
73 #define DEVICE_PARAM(N, D)
74
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");
79
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");
84
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");
89
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");
94
95 #define INT_WORKS_DEF   20
96 #define INT_WORKS_MIN   10
97 #define INT_WORKS_MAX   64
98
99 DEVICE_PARAM(int_works, "Number of packets per interrupt services");
100
101 #define RTS_THRESH_DEF     2347
102
103 #define FRAG_THRESH_DEF     2346
104
105 #define SHORT_RETRY_MIN     0
106 #define SHORT_RETRY_MAX     31
107 #define SHORT_RETRY_DEF     8
108
109 DEVICE_PARAM(ShortRetryLimit, "Short frame retry limits");
110
111 #define LONG_RETRY_MIN     0
112 #define LONG_RETRY_MAX     15
113 #define LONG_RETRY_DEF     4
114
115 DEVICE_PARAM(LongRetryLimit, "long frame retry limits");
116
117 /* BasebandType[] baseband type selected
118    0: indicate 802.11a type
119    1: indicate 802.11b type
120    2: indicate 802.11g type
121 */
122 #define BBP_TYPE_MIN     0
123 #define BBP_TYPE_MAX     2
124 #define BBP_TYPE_DEF     2
125
126 DEVICE_PARAM(BasebandType, "baseband type");
127
128 /*
129  * Static vars definitions
130  */
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 },
134         {0, NULL}
135 };
136
137 static const struct pci_device_id vt6655_pci_id_table[] = {
138         { PCI_VDEVICE(VIA, 0x3253), (kernel_ulong_t)chip_info_table},
139         { 0, }
140 };
141
142 /*---------------------  Static Functions  --------------------------*/
143
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);
150
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);
155
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);
166
167 /*---------------------  Export Variables  --------------------------*/
168
169 /*---------------------  Export Functions  --------------------------*/
170
171 static void vt6655_remove(struct pci_dev *pcid)
172 {
173         struct vnt_private *pDevice = pci_get_drvdata(pcid);
174
175         if (pDevice == NULL)
176                 return;
177         device_free_info(pDevice);
178 }
179
180 static void device_get_options(struct vnt_private *pDevice)
181 {
182         POPTIONS pOpts = &(pDevice->sOpts);
183
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;
189
190         pOpts->short_retry = SHORT_RETRY_DEF;
191         pOpts->long_retry = LONG_RETRY_DEF;
192         pOpts->bbp_type = BBP_TYPE_DEF;
193 }
194
195 static void
196 device_set_options(struct vnt_private *pDevice)
197 {
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;
205
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);
211 }
212
213 /*
214  * Initialisation of MAC & BBP registers
215  */
216
217 static void device_init_registers(struct vnt_private *pDevice)
218 {
219         unsigned long flags;
220         unsigned int ii;
221         unsigned char byValue;
222         unsigned char byCCKPwrdBm = 0;
223         unsigned char byOFDMPwrdBm = 0;
224
225         MACbShutdown(pDevice->PortOffset);
226         BBvSoftwareReset(pDevice);
227
228         /* Do MACbSoftwareReset in MACvInitialize */
229         MACbSoftwareReset(pDevice->PortOffset);
230
231         pDevice->bAES = false;
232
233         /* Only used in 11g type, sync with ERP IE */
234         pDevice->bProtectMode = false;
235
236         pDevice->bNonERPPresent = false;
237         pDevice->bBarkerPreambleMd = false;
238         pDevice->wCurrentRate = RATE_1M;
239         pDevice->byTopOFDMBasicRate = RATE_24M;
240         pDevice->byTopCCKBasicRate = RATE_1M;
241
242         /* Target to IF pin while programming to RF chip. */
243         pDevice->byRevId = 0;
244
245         /* init MAC */
246         MACvInitialize(pDevice->PortOffset);
247
248         /* Get Local ID */
249         VNSvInPortB(pDevice->PortOffset + MAC_REG_LOCALID, &pDevice->byLocalID);
250
251         spin_lock_irqsave(&pDevice->lock, flags);
252
253         SROMvReadAllContents(pDevice->PortOffset, pDevice->abyEEPROM);
254
255         spin_unlock_irqrestore(&pDevice->lock, flags);
256
257         /* Get Channel range */
258         pDevice->byMinChannel = 1;
259         pDevice->byMaxChannel = CB_MAX_CHANNEL;
260
261         /* Get Antena */
262         byValue = SROMbyReadEmbedded(pDevice->PortOffset, EEP_OFS_ANTENNA);
263         if (byValue & EEP_ANTINV)
264                 pDevice->bTxRxAntInv = true;
265         else
266                 pDevice->bTxRxAntInv = false;
267
268         byValue &= (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
269         /* if not set default is All */
270         if (byValue == 0)
271                 byValue = (EEP_ANTENNA_AUX | EEP_ANTENNA_MAIN);
272
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;
278
279                 if (pDevice->bTxRxAntInv)
280                         pDevice->byRxAntennaMode = ANT_A;
281                 else
282                         pDevice->byRxAntennaMode = ANT_B;
283         } else  {
284                 pDevice->byAntennaCount = 1;
285                 pDevice->dwTxAntennaSel = 0;
286                 pDevice->dwRxAntennaSel = 0;
287
288                 if (byValue & EEP_ANTENNA_AUX) {
289                         pDevice->byTxAntennaMode = ANT_A;
290
291                         if (pDevice->bTxRxAntInv)
292                                 pDevice->byRxAntennaMode = ANT_B;
293                         else
294                                 pDevice->byRxAntennaMode = ANT_A;
295                 } else {
296                         pDevice->byTxAntennaMode = ANT_B;
297
298                         if (pDevice->bTxRxAntInv)
299                                 pDevice->byRxAntennaMode = ANT_A;
300                         else
301                                 pDevice->byRxAntennaMode = ANT_B;
302                 }
303         }
304
305         /* Set initial antenna mode */
306         BBvSetTxAntennaMode(pDevice, pDevice->byTxAntennaMode);
307         BBvSetRxAntennaMode(pDevice, pDevice->byRxAntennaMode);
308
309         /* zonetype initial */
310         pDevice->byOriginalZonetype = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
311
312         if (!pDevice->bZoneRegExist)
313                 pDevice->byZoneType = pDevice->abyEEPROM[EEP_OFS_ZONETYPE];
314
315         pr_debug("pDevice->byZoneType = %x\n", pDevice->byZoneType);
316
317         /* Init RF module */
318         RFbInit(pDevice);
319
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);
324
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;
332
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;
338
339                 pDevice->abyCCKDefaultPwr[ii + 1] = byCCKPwrdBm;
340                 pDevice->abyOFDMDefaultPwr[ii + 1] = byOFDMPwrdBm;
341         }
342
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];
347         }
348
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));
354
355                 pDevice->abyOFDMDefaultPwr[ii + CB_MAX_CHANNEL_24G + 1] =
356                         SROMbyReadEmbedded(pDevice->PortOffset,
357                                            (unsigned char)(ii + EEP_OFS_OFDMA_PWR_dBm));
358         }
359
360         if (pDevice->byLocalID > REV_ID_VT3253_B1) {
361                 MACvSelectPage1(pDevice->PortOffset);
362
363                 VNSvOutPortB(pDevice->PortOffset + MAC_REG_MSRCTL + 1,
364                              (MSRCTL1_TXPWR | MSRCTL1_CSAPAREN));
365
366                 MACvSelectPage0(pDevice->PortOffset);
367         }
368
369         /* use relative tx timeout and 802.11i D4 */
370         MACvWordRegBitsOn(pDevice->PortOffset,
371                           MAC_REG_CFG, (CFG_TKIPOPT | CFG_NOTXTIMEOUT));
372
373         /* set performance parameter by registry */
374         MACvSetShortRetryLimit(pDevice->PortOffset, pDevice->byShortRetryLimit);
375         MACvSetLongRetryLimit(pDevice->PortOffset, pDevice->byLongRetryLimit);
376
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);
381
382         /* initialize BBP registers */
383         BBbVT3253Init(pDevice);
384
385         if (pDevice->bUpdateBBVGA) {
386                 pDevice->byBBVGACurrent = pDevice->abyBBVGA[0];
387                 pDevice->byBBVGANew = pDevice->byBBVGACurrent;
388                 BBvSetVGAGainOffset(pDevice, pDevice->abyBBVGA[0]);
389         }
390
391         BBvSetRxAntennaMode(pDevice, pDevice->byRxAntennaMode);
392         BBvSetTxAntennaMode(pDevice, pDevice->byTxAntennaMode);
393
394         /* Set BB and packet type at the same time. */
395         /* Set Short Slot Time, xIFS, and RSPINF. */
396         pDevice->wCurrentRate = RATE_54M;
397
398         pDevice->bRadioOff = false;
399
400         pDevice->byRadioCtl = SROMbyReadEmbedded(pDevice->PortOffset,
401                                                  EEP_OFS_RADIOCTL);
402         pDevice->bHWRadioOff = false;
403
404         if (pDevice->byRadioCtl & EEP_RADIOCTL_ENABLE) {
405                 /* Get GPIO */
406                 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
407
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;
413         }
414
415         if (pDevice->bHWRadioOff || pDevice->bRadioControlOff)
416                 CARDbRadioPowerOff(pDevice);
417
418         /* get Permanent network address */
419         SROMvReadEtherAddress(pDevice->PortOffset, pDevice->abyCurrentNetAddr);
420         pr_debug("Network address = %pM\n", pDevice->abyCurrentNetAddr);
421
422         /* reset Tx pointer */
423         CARDvSafeResetRx(pDevice);
424         /* reset Rx pointer */
425         CARDvSafeResetTx(pDevice);
426
427         if (pDevice->byLocalID <= REV_ID_VT3253_A1)
428                 MACvRegBitsOn(pDevice->PortOffset, MAC_REG_RCR, RCR_WPAERR);
429
430         /* Turn On Rx DMA */
431         MACvReceive0(pDevice->PortOffset);
432         MACvReceive1(pDevice->PortOffset);
433
434         /* start the adapter */
435         MACvStart(pDevice->PortOffset);
436 }
437
438 static void device_print_info(struct vnt_private *pDevice)
439 {
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);
443 }
444
445 static void vt6655_init_info(struct pci_dev *pcid,
446                              struct vnt_private **ppDevice,
447                              PCHIP_INFO pChip_info)
448 {
449         memset(*ppDevice, 0, sizeof(**ppDevice));
450
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;
456
457         spin_lock_init(&((*ppDevice)->lock));
458 }
459
460 static bool device_get_pci_info(struct vnt_private *pDevice,
461                                 struct pci_dev *pcid)
462 {
463         u16 pci_cmd;
464         u8  b;
465         unsigned int cis_addr;
466
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));
471
472         pci_set_master(pcid);
473
474         pDevice->memaddr = pci_resource_start(pcid, 0);
475         pDevice->ioaddr = pci_resource_start(pcid, 1);
476
477         cis_addr = pci_resource_start(pcid, 2);
478
479         pDevice->pcid = pcid;
480
481         pci_read_config_byte(pcid, PCI_COMMAND, &b);
482         pci_write_config_byte(pcid, PCI_COMMAND, (b|PCI_COMMAND_MASTER));
483
484         return true;
485 }
486
487 static void device_free_info(struct vnt_private *pDevice)
488 {
489         if (!pDevice)
490                 return;
491
492         if (pDevice->mac_hw)
493                 ieee80211_unregister_hw(pDevice->hw);
494
495         if (pDevice->PortOffset)
496                 iounmap(pDevice->PortOffset);
497
498         if (pDevice->pcid)
499                 pci_release_regions(pDevice->pcid);
500
501         if (pDevice->hw)
502                 ieee80211_free_hw(pDevice->hw);
503 }
504
505 static bool device_init_rings(struct vnt_private *pDevice)
506 {
507         void *vir_pool;
508
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");
518                 return false;
519         }
520
521         pDevice->aRD0Ring = vir_pool;
522         pDevice->aRD1Ring = vir_pool +
523                 pDevice->sOpts.nRxDescs0 * sizeof(struct vnt_rx_desc);
524
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);
528
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 +
532                                                   CB_BEACON_BUF_SIZE +
533                                                   CB_MAX_BUF_SIZE,
534                                                   &pDevice->tx_bufs_dma0,
535                                                   GFP_ATOMIC);
536         if (pDevice->tx0_bufs == NULL) {
537                 dev_err(&pDevice->pcid->dev, "allocate buf dma memory failed\n");
538
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
545                         );
546                 return false;
547         }
548
549         pDevice->td0_pool_dma = pDevice->rd1_pool_dma +
550                 pDevice->sOpts.nRxDescs1 * sizeof(struct vnt_rx_desc);
551
552         pDevice->td1_pool_dma = pDevice->td0_pool_dma +
553                 pDevice->sOpts.nTxDescs[0] * sizeof(struct vnt_tx_desc);
554
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);
559
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);
564
565         pDevice->tx1_bufs = pDevice->tx0_bufs +
566                 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
567
568         pDevice->tx_beacon_bufs = pDevice->tx1_bufs +
569                 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
570
571         pDevice->pbyTmpBuff = pDevice->tx_beacon_bufs +
572                 CB_BEACON_BUF_SIZE;
573
574         pDevice->tx_bufs_dma1 = pDevice->tx_bufs_dma0 +
575                 pDevice->sOpts.nTxDescs[0] * PKT_BUF_SZ;
576
577         pDevice->tx_beacon_dma = pDevice->tx_bufs_dma1 +
578                 pDevice->sOpts.nTxDescs[1] * PKT_BUF_SZ;
579
580         return true;
581 }
582
583 static void device_free_rings(struct vnt_private *pDevice)
584 {
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)
590                             ,
591                             pDevice->aRD0Ring, pDevice->pool_dma
592                 );
593
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 +
598                                     CB_BEACON_BUF_SIZE +
599                                     CB_MAX_BUF_SIZE,
600                                     pDevice->tx0_bufs, pDevice->tx_bufs_dma0
601                         );
602 }
603
604 static void device_init_rd0_ring(struct vnt_private *pDevice)
605 {
606         int i;
607         dma_addr_t      curr = pDevice->rd0_pool_dma;
608         struct vnt_rx_desc *pDesc;
609
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();
615
616                 if (!device_alloc_rx_buf(pDevice, pDesc))
617                         dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
618
619                 pDesc->next = &(pDevice->aRD0Ring[(i+1) % pDevice->sOpts.nRxDescs0]);
620                 pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_rx_desc));
621         }
622
623         if (i > 0)
624                 pDevice->aRD0Ring[i-1].next_desc = cpu_to_le32(pDevice->rd0_pool_dma);
625         pDevice->pCurrRD[0] = &(pDevice->aRD0Ring[0]);
626 }
627
628 static void device_init_rd1_ring(struct vnt_private *pDevice)
629 {
630         int i;
631         dma_addr_t      curr = pDevice->rd1_pool_dma;
632         struct vnt_rx_desc *pDesc;
633
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();
639
640                 if (!device_alloc_rx_buf(pDevice, pDesc))
641                         dev_err(&pDevice->pcid->dev, "can not alloc rx bufs\n");
642
643                 pDesc->next = &(pDevice->aRD1Ring[(i+1) % pDevice->sOpts.nRxDescs1]);
644                 pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_rx_desc));
645         }
646
647         if (i > 0)
648                 pDevice->aRD1Ring[i-1].next_desc = cpu_to_le32(pDevice->rd1_pool_dma);
649         pDevice->pCurrRD[1] = &(pDevice->aRD1Ring[0]);
650 }
651
652 static void device_free_rd0_ring(struct vnt_private *pDevice)
653 {
654         int i;
655
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;
659
660                 dma_unmap_single(&pDevice->pcid->dev, rd_info->skb_dma,
661                                  pDevice->rx_buf_sz, DMA_FROM_DEVICE);
662
663                 dev_kfree_skb(rd_info->skb);
664
665                 kfree(pDesc->rd_info);
666         }
667 }
668
669 static void device_free_rd1_ring(struct vnt_private *pDevice)
670 {
671         int i;
672
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;
676
677                 dma_unmap_single(&pDevice->pcid->dev, rd_info->skb_dma,
678                                  pDevice->rx_buf_sz, DMA_FROM_DEVICE);
679
680                 dev_kfree_skb(rd_info->skb);
681
682                 kfree(pDesc->rd_info);
683         }
684 }
685
686 static void device_init_td0_ring(struct vnt_private *pDevice)
687 {
688         int i;
689         dma_addr_t  curr;
690         struct vnt_tx_desc *pDesc;
691
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();
697
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;
701                 }
702                 pDesc->next = &(pDevice->apTD0Rings[(i+1) % pDevice->sOpts.nTxDescs[0]]);
703                 pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_tx_desc));
704         }
705
706         if (i > 0)
707                 pDevice->apTD0Rings[i-1].next_desc = cpu_to_le32(pDevice->td0_pool_dma);
708         pDevice->apTailTD[0] = pDevice->apCurrTD[0] = &(pDevice->apTD0Rings[0]);
709 }
710
711 static void device_init_td1_ring(struct vnt_private *pDevice)
712 {
713         int i;
714         dma_addr_t  curr;
715         struct vnt_tx_desc *pDesc;
716
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();
723
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;
727                 }
728                 pDesc->next = &(pDevice->apTD1Rings[(i + 1) % pDevice->sOpts.nTxDescs[1]]);
729                 pDesc->next_desc = cpu_to_le32(curr + sizeof(struct vnt_tx_desc));
730         }
731
732         if (i > 0)
733                 pDevice->apTD1Rings[i-1].next_desc = cpu_to_le32(pDevice->td1_pool_dma);
734         pDevice->apTailTD[1] = pDevice->apCurrTD[1] = &(pDevice->apTD1Rings[0]);
735 }
736
737 static void device_free_td0_ring(struct vnt_private *pDevice)
738 {
739         int i;
740
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;
744
745                 dev_kfree_skb(pTDInfo->skb);
746                 kfree(pDesc->td_info);
747         }
748 }
749
750 static void device_free_td1_ring(struct vnt_private *pDevice)
751 {
752         int i;
753
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;
757
758                 dev_kfree_skb(pTDInfo->skb);
759                 kfree(pDesc->td_info);
760         }
761 }
762
763 /*-----------------------------------------------------------------*/
764
765 static int device_rx_srv(struct vnt_private *pDevice, unsigned int uIdx)
766 {
767         struct vnt_rx_desc *pRD;
768         int works = 0;
769
770         for (pRD = pDevice->pCurrRD[uIdx];
771              pRD->rd0.owner == OWNED_BY_HOST;
772              pRD = pRD->next) {
773                 if (works++ > 15)
774                         break;
775
776                 if (!pRD->rd_info->skb)
777                         break;
778
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");
783                                 break;
784                         }
785                 }
786                 pRD->rd0.owner = OWNED_BY_NIC;
787         }
788
789         pDevice->pCurrRD[uIdx] = pRD;
790
791         return works;
792 }
793
794 static bool device_alloc_rx_buf(struct vnt_private *pDevice,
795                                 struct vnt_rx_desc *pRD)
796 {
797         struct vnt_rd_info *pRDInfo = pRD->rd_info;
798
799         pRDInfo->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
800         if (pRDInfo->skb == NULL)
801                 return false;
802
803         pRDInfo->skb_dma =
804                 dma_map_single(&pDevice->pcid->dev,
805                                skb_put(pRDInfo->skb, skb_tailroom(pRDInfo->skb)),
806                                pDevice->rx_buf_sz, DMA_FROM_DEVICE);
807
808         *((unsigned int *)&pRD->rd0) = 0; /* FIX cast */
809
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);
814
815         return true;
816 }
817
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}
824 };
825
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}
832 };
833
834 static int vnt_int_report_rate(struct vnt_private *priv,
835                                struct vnt_td_info *context, u8 tsr0, u8 tsr1)
836 {
837         struct vnt_tx_fifo_head *fifo_head;
838         struct ieee80211_tx_info *info;
839         struct ieee80211_rate *rate;
840         u16 fb_option;
841         u8 tx_retry = (tsr0 & TSR0_NCR);
842         s8 idx;
843
844         if (!context)
845                 return -ENOMEM;
846
847         if (!context->skb)
848                 return -EINVAL;
849
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));
853
854         info = IEEE80211_SKB_CB(context->skb);
855         idx = info->control.rates[0].idx;
856
857         if (fb_option && !(tsr1 & TSR1_TERR)) {
858                 u8 tx_rate;
859                 u8 retry = tx_retry;
860
861                 rate = ieee80211_get_tx_rate(priv->hw, info);
862                 tx_rate = rate->hw_value - RATE_18M;
863
864                 if (retry > 4)
865                         retry = 4;
866
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];
871
872                 if (info->band == IEEE80211_BAND_5GHZ)
873                         idx = tx_rate - RATE_6M;
874                 else
875                         idx = tx_rate;
876         }
877
878         ieee80211_tx_info_clear_status(info);
879
880         info->status.rates[0].count = tx_retry;
881
882         if (!(tsr1 & TSR1_TERR)) {
883                 info->status.rates[0].idx = idx;
884
885                 if (info->flags & IEEE80211_TX_CTL_NO_ACK)
886                         info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED;
887                 else
888                         info->flags |= IEEE80211_TX_STAT_ACK;
889         }
890
891         return 0;
892 }
893
894 static int device_tx_srv(struct vnt_private *pDevice, unsigned int uIdx)
895 {
896         struct vnt_tx_desc *pTD;
897         int                      works = 0;
898         unsigned char byTsr0;
899         unsigned char byTsr1;
900
901         for (pTD = pDevice->apTailTD[uIdx]; pDevice->iTDUsed[uIdx] > 0; pTD = pTD->next) {
902                 if (pTD->td0.owner == OWNED_BY_NIC)
903                         break;
904                 if (works++ > 15)
905                         break;
906
907                 byTsr0 = pTD->td0.tsr0;
908                 byTsr1 = pTD->td0.tsr1;
909
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)) {
914                                         if (byTsr0 != 0) {
915                                                 pr_debug(" Tx[%d] OK but has error. tsr1[%02X] tsr0[%02X]\n",
916                                                          (int)uIdx, byTsr1,
917                                                          byTsr0);
918                                         }
919                                 } else {
920                                         pr_debug(" Tx[%d] dropped & tsr1[%02X] tsr0[%02X]\n",
921                                                  (int)uIdx, byTsr1, byTsr0);
922                                 }
923                         }
924
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);
929                                 }
930                         }
931
932                         vnt_int_report_rate(pDevice, pTD->td_info, byTsr0, byTsr1);
933
934                         device_free_tx_buf(pDevice, pTD);
935                         pDevice->iTDUsed[uIdx]--;
936                 }
937         }
938
939         pDevice->apTailTD[uIdx] = pTD;
940
941         return works;
942 }
943
944 static void device_error(struct vnt_private *pDevice, unsigned short status)
945 {
946         if (status & ISR_FETALERR) {
947                 dev_err(&pDevice->pcid->dev, "Hardware fatal error\n");
948
949                 MACbShutdown(pDevice->PortOffset);
950                 return;
951         }
952 }
953
954 static void device_free_tx_buf(struct vnt_private *pDevice,
955                                struct vnt_tx_desc *pDesc)
956 {
957         struct vnt_td_info *pTDInfo = pDesc->td_info;
958         struct sk_buff *skb = pTDInfo->skb;
959
960         if (skb)
961                 ieee80211_tx_status_irqsafe(pDevice->hw, skb);
962
963         pTDInfo->skb = NULL;
964         pTDInfo->flags = 0;
965 }
966
967 static void vnt_check_bb_vga(struct vnt_private *priv)
968 {
969         long dbm;
970         int i;
971
972         if (!priv->bUpdateBBVGA)
973                 return;
974
975         if (priv->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL)
976                 return;
977
978         if (!(priv->vif->bss_conf.assoc && priv->uCurrRSSI))
979                 return;
980
981         RFvRSSITodBm(priv, (u8)priv->uCurrRSSI, &dbm);
982
983         for (i = 0; i < BB_VGA_LEVEL; i++) {
984                 if (dbm < priv->ldBmThreshold[i]) {
985                         priv->byBBVGANew = priv->abyBBVGA[i];
986                         break;
987                 }
988         }
989
990         if (priv->byBBVGANew == priv->byBBVGACurrent) {
991                 priv->uBBVGADiffCount = 1;
992                 return;
993         }
994
995         priv->uBBVGADiffCount++;
996
997         if (priv->uBBVGADiffCount == 1) {
998                 /* first VGA diff gain */
999                 BBvSetVGAGainOffset(priv, priv->byBBVGANew);
1000
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);
1006         }
1007
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);
1014
1015                 BBvSetVGAGainOffset(priv, priv->byBBVGANew);
1016         }
1017 }
1018
1019 static void vnt_interrupt_process(struct vnt_private *priv)
1020 {
1021         struct ieee80211_low_level_stats *low_stats = &priv->low_stats;
1022         int             max_count = 0;
1023         u32 mib_counter;
1024         u32 isr;
1025         unsigned long flags;
1026
1027         MACvReadISR(priv->PortOffset, &isr);
1028
1029         if (isr == 0)
1030                 return;
1031
1032         if (isr == 0xffffffff) {
1033                 pr_debug("isr = 0xffff\n");
1034                 return;
1035         }
1036
1037         MACvIntDisable(priv->PortOffset);
1038
1039         spin_lock_irqsave(&priv->lock, flags);
1040
1041         /* Read low level stats */
1042         MACvReadMIBCounter(priv->PortOffset, &mib_counter);
1043
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;
1048
1049         /*
1050          * TBD....
1051          * Must do this after doing rx/tx, cause ISR bit is slow
1052          * than RD/TD write back
1053          * update ISR counter
1054          */
1055         while (isr && priv->vif) {
1056                 MACvWriteISR(priv->PortOffset, isr);
1057
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);
1064                 }
1065
1066                 if (isr & ISR_TBTT) {
1067                         if (priv->op_mode != NL80211_IFTYPE_ADHOC)
1068                                 vnt_check_bb_vga(priv);
1069
1070                         priv->bBeaconSent = false;
1071                         if (priv->bEnablePSMode)
1072                                 PSbIsNextTBTTWakeUp((void *)priv);
1073
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);
1079                         }
1080
1081                         /* TODO: adhoc PS mode */
1082
1083                 }
1084
1085                 if (isr & ISR_BNTX) {
1086                         if (priv->op_mode == NL80211_IFTYPE_ADHOC) {
1087                                 priv->bIsBeaconBufReadySet = false;
1088                                 priv->cbBeaconBufReadySetCnt = 0;
1089                         }
1090
1091                         priv->bBeaconSent = true;
1092                 }
1093
1094                 if (isr & ISR_RXDMA0)
1095                         max_count += device_rx_srv(priv, TYPE_RXDMA0);
1096
1097                 if (isr & ISR_RXDMA1)
1098                         max_count += device_rx_srv(priv, TYPE_RXDMA1);
1099
1100                 if (isr & ISR_TXDMA0)
1101                         max_count += device_tx_srv(priv, TYPE_TXDMA0);
1102
1103                 if (isr & ISR_AC0DMA)
1104                         max_count += device_tx_srv(priv, TYPE_AC0DMA);
1105
1106                 if (isr & ISR_SOFTTIMER1) {
1107                         if (priv->vif->bss_conf.enable_beacon)
1108                                 vnt_beacon_make(priv, priv->vif);
1109                 }
1110
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);
1116
1117                 MACvReadISR(priv->PortOffset, &isr);
1118
1119                 MACvReceive0(priv->PortOffset);
1120                 MACvReceive1(priv->PortOffset);
1121
1122                 if (max_count > priv->sOpts.int_works)
1123                         break;
1124         }
1125
1126         spin_unlock_irqrestore(&priv->lock, flags);
1127
1128         MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
1129 }
1130
1131 static void vnt_interrupt_work(struct work_struct *work)
1132 {
1133         struct vnt_private *priv =
1134                 container_of(work, struct vnt_private, interrupt_work);
1135
1136         if (priv->vif)
1137                 vnt_interrupt_process(priv);
1138 }
1139
1140 static irqreturn_t vnt_interrupt(int irq,  void *arg)
1141 {
1142         struct vnt_private *priv = arg;
1143
1144         if (priv->vif)
1145                 schedule_work(&priv->interrupt_work);
1146
1147         return IRQ_HANDLED;
1148 }
1149
1150 static int vnt_tx_packet(struct vnt_private *priv, struct sk_buff *skb)
1151 {
1152         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
1153         struct vnt_tx_desc *head_td;
1154         u32 dma_idx;
1155         unsigned long flags;
1156
1157         spin_lock_irqsave(&priv->lock, flags);
1158
1159         if (ieee80211_is_data(hdr->frame_control))
1160                 dma_idx = TYPE_AC0DMA;
1161         else
1162                 dma_idx = TYPE_TXDMA0;
1163
1164         if (AVAIL_TD(priv, dma_idx) < 1) {
1165                 spin_unlock_irqrestore(&priv->lock, flags);
1166                 return -ENOMEM;
1167         }
1168
1169         head_td = priv->apCurrTD[dma_idx];
1170
1171         head_td->td1.tcr = 0;
1172
1173         head_td->td_info->skb = skb;
1174
1175         if (dma_idx == TYPE_AC0DMA)
1176                 head_td->td_info->flags = TD_FLAGS_NETIF_SKB;
1177
1178         priv->apCurrTD[dma_idx] = head_td->next;
1179
1180         spin_unlock_irqrestore(&priv->lock, flags);
1181
1182         vnt_generate_fifo_header(priv, dma_idx, head_td, skb);
1183
1184         spin_lock_irqsave(&priv->lock, flags);
1185
1186         priv->bPWBitOn = false;
1187
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);
1191
1192         head_td->buff_addr = cpu_to_le32(head_td->td_info->buf_dma);
1193
1194         /* Poll Transmit the adapter */
1195         wmb();
1196         head_td->td0.owner = OWNED_BY_NIC;
1197         wmb(); /* second memory barrier */
1198
1199         if (head_td->td_info->flags & TD_FLAGS_NETIF_SKB)
1200                 MACvTransmitAC0(priv->PortOffset);
1201         else
1202                 MACvTransmit0(priv->PortOffset);
1203
1204         priv->iTDUsed[dma_idx]++;
1205
1206         spin_unlock_irqrestore(&priv->lock, flags);
1207
1208         return 0;
1209 }
1210
1211 static void vnt_tx_80211(struct ieee80211_hw *hw,
1212                          struct ieee80211_tx_control *control,
1213                          struct sk_buff *skb)
1214 {
1215         struct vnt_private *priv = hw->priv;
1216
1217         ieee80211_stop_queues(hw);
1218
1219         if (vnt_tx_packet(priv, skb)) {
1220                 ieee80211_free_txskb(hw, skb);
1221
1222                 ieee80211_wake_queues(hw);
1223         }
1224 }
1225
1226 static int vnt_start(struct ieee80211_hw *hw)
1227 {
1228         struct vnt_private *priv = hw->priv;
1229         int ret;
1230
1231         priv->rx_buf_sz = PKT_BUF_SZ;
1232         if (!device_init_rings(priv))
1233                 return -ENOMEM;
1234
1235         ret = request_irq(priv->pcid->irq, &vnt_interrupt,
1236                           IRQF_SHARED, "vt6655", priv);
1237         if (ret) {
1238                 dev_dbg(&priv->pcid->dev, "failed to start irq\n");
1239                 return ret;
1240         }
1241
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);
1247
1248         device_init_registers(priv);
1249
1250         dev_dbg(&priv->pcid->dev, "call MACvIntEnable\n");
1251         MACvIntEnable(priv->PortOffset, IMR_MASK_VALUE);
1252
1253         ieee80211_wake_queues(hw);
1254
1255         return 0;
1256 }
1257
1258 static void vnt_stop(struct ieee80211_hw *hw)
1259 {
1260         struct vnt_private *priv = hw->priv;
1261
1262         ieee80211_stop_queues(hw);
1263
1264         cancel_work_sync(&priv->interrupt_work);
1265
1266         MACbShutdown(priv->PortOffset);
1267         MACbSoftwareReset(priv->PortOffset);
1268         CARDbRadioPowerOff(priv);
1269
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);
1275
1276         free_irq(priv->pcid->irq, priv);
1277 }
1278
1279 static int vnt_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1280 {
1281         struct vnt_private *priv = hw->priv;
1282
1283         priv->vif = vif;
1284
1285         switch (vif->type) {
1286         case NL80211_IFTYPE_STATION:
1287                 break;
1288         case NL80211_IFTYPE_ADHOC:
1289                 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1290
1291                 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_ADHOC);
1292
1293                 break;
1294         case NL80211_IFTYPE_AP:
1295                 MACvRegBitsOff(priv->PortOffset, MAC_REG_RCR, RCR_UNICAST);
1296
1297                 MACvRegBitsOn(priv->PortOffset, MAC_REG_HOSTCR, HOSTCR_AP);
1298
1299                 break;
1300         default:
1301                 return -EOPNOTSUPP;
1302         }
1303
1304         priv->op_mode = vif->type;
1305
1306         return 0;
1307 }
1308
1309 static void vnt_remove_interface(struct ieee80211_hw *hw,
1310                                  struct ieee80211_vif *vif)
1311 {
1312         struct vnt_private *priv = hw->priv;
1313
1314         switch (vif->type) {
1315         case NL80211_IFTYPE_STATION:
1316                 break;
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);
1322                 break;
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);
1328                 break;
1329         default:
1330                 break;
1331         }
1332
1333         priv->op_mode = NL80211_IFTYPE_UNSPECIFIED;
1334 }
1335
1336
1337 static int vnt_config(struct ieee80211_hw *hw, u32 changed)
1338 {
1339         struct vnt_private *priv = hw->priv;
1340         struct ieee80211_conf *conf = &hw->conf;
1341         u8 bb_type;
1342
1343         if (changed & IEEE80211_CONF_CHANGE_PS) {
1344                 if (conf->flags & IEEE80211_CONF_PS)
1345                         PSvEnablePowerSaving(priv, conf->listen_interval);
1346                 else
1347                         PSvDisablePowerSaving(priv);
1348         }
1349
1350         if ((changed & IEEE80211_CONF_CHANGE_CHANNEL) ||
1351             (conf->flags & IEEE80211_CONF_OFFCHANNEL)) {
1352                 set_channel(priv, conf->chandef.chan);
1353
1354                 if (conf->chandef.chan->band == IEEE80211_BAND_5GHZ)
1355                         bb_type = BB_TYPE_11A;
1356                 else
1357                         bb_type = BB_TYPE_11G;
1358
1359                 if (priv->byBBType != bb_type) {
1360                         priv->byBBType = bb_type;
1361
1362                         CARDbSetPhyParameter(priv, priv->byBBType);
1363                 }
1364         }
1365
1366         if (changed & IEEE80211_CONF_CHANGE_POWER) {
1367                 if (priv->byBBType == BB_TYPE_11B)
1368                         priv->wCurrentRate = RATE_1M;
1369                 else
1370                         priv->wCurrentRate = RATE_54M;
1371
1372                 RFbSetPower(priv, priv->wCurrentRate,
1373                             conf->chandef.chan->hw_value);
1374         }
1375
1376         return 0;
1377 }
1378
1379 static void vnt_bss_info_changed(struct ieee80211_hw *hw,
1380                 struct ieee80211_vif *vif, struct ieee80211_bss_conf *conf,
1381                 u32 changed)
1382 {
1383         struct vnt_private *priv = hw->priv;
1384
1385         priv->current_aid = conf->aid;
1386
1387         if (changed & BSS_CHANGED_BSSID && conf->bssid) {
1388                 unsigned long flags;
1389
1390                 spin_lock_irqsave(&priv->lock, flags);
1391
1392                 MACvWriteBSSIDAddress(priv->PortOffset, (u8 *)conf->bssid);
1393
1394                 spin_unlock_irqrestore(&priv->lock, flags);
1395         }
1396
1397         if (changed & BSS_CHANGED_BASIC_RATES) {
1398                 priv->basic_rates = conf->basic_rates;
1399
1400                 CARDvUpdateBasicTopRate(priv);
1401
1402                 dev_dbg(&priv->pcid->dev,
1403                         "basic rates %x\n", conf->basic_rates);
1404         }
1405
1406         if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1407                 if (conf->use_short_preamble) {
1408                         MACvEnableBarkerPreambleMd(priv->PortOffset);
1409                         priv->byPreambleType = true;
1410                 } else {
1411                         MACvDisableBarkerPreambleMd(priv->PortOffset);
1412                         priv->byPreambleType = false;
1413                 }
1414         }
1415
1416         if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1417                 if (conf->use_cts_prot)
1418                         MACvEnableProtectMD(priv->PortOffset);
1419                 else
1420                         MACvDisableProtectMD(priv->PortOffset);
1421         }
1422
1423         if (changed & BSS_CHANGED_ERP_SLOT) {
1424                 if (conf->use_short_slot)
1425                         priv->bShortSlotTime = true;
1426                 else
1427                         priv->bShortSlotTime = false;
1428
1429                 CARDbSetPhyParameter(priv, priv->byBBType);
1430                 BBvSetVGAGainOffset(priv, priv->abyBBVGA[0]);
1431         }
1432
1433         if (changed & BSS_CHANGED_TXPOWER)
1434                 RFbSetPower(priv, priv->wCurrentRate,
1435                             conf->chandef.chan->hw_value);
1436
1437         if (changed & BSS_CHANGED_BEACON_ENABLED) {
1438                 dev_dbg(&priv->pcid->dev,
1439                         "Beacon enable %d\n", conf->enable_beacon);
1440
1441                 if (conf->enable_beacon) {
1442                         vnt_beacon_enable(priv, vif, conf);
1443
1444                         MACvRegBitsOn(priv->PortOffset, MAC_REG_TCR,
1445                                       TCR_AUTOBCNTX);
1446                 } else {
1447                         MACvRegBitsOff(priv->PortOffset, MAC_REG_TCR,
1448                                        TCR_AUTOBCNTX);
1449                 }
1450         }
1451
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,
1456                                        conf->sync_tsf);
1457
1458                         CARDbSetBeaconPeriod(priv, conf->beacon_int);
1459
1460                         CARDvSetFirstNextTBTT(priv, conf->beacon_int);
1461                 } else {
1462                         VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1463                                      TFTCTL_TSFCNTRST);
1464                         VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL,
1465                                      TFTCTL_TSFCNTREN);
1466                 }
1467         }
1468 }
1469
1470 static u64 vnt_prepare_multicast(struct ieee80211_hw *hw,
1471         struct netdev_hw_addr_list *mc_list)
1472 {
1473         struct vnt_private *priv = hw->priv;
1474         struct netdev_hw_addr *ha;
1475         u64 mc_filter = 0;
1476         u32 bit_nr = 0;
1477
1478         netdev_hw_addr_list_for_each(ha, mc_list) {
1479                 bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
1480
1481                 mc_filter |= 1ULL << (bit_nr & 0x3f);
1482         }
1483
1484         priv->mc_list_count = mc_list->count;
1485
1486         return mc_filter;
1487 }
1488
1489 static void vnt_configure(struct ieee80211_hw *hw,
1490         unsigned int changed_flags, unsigned int *total_flags, u64 multicast)
1491 {
1492         struct vnt_private *priv = hw->priv;
1493         u8 rx_mode = 0;
1494
1495         *total_flags &= FIF_ALLMULTI | FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC;
1496
1497         VNSvInPortB(priv->PortOffset + MAC_REG_RCR, &rx_mode);
1498
1499         dev_dbg(&priv->pcid->dev, "rx mode in = %x\n", rx_mode);
1500
1501         if (changed_flags & FIF_ALLMULTI) {
1502                 if (*total_flags & FIF_ALLMULTI) {
1503                         unsigned long flags;
1504
1505                         spin_lock_irqsave(&priv->lock, flags);
1506
1507                         if (priv->mc_list_count > 2) {
1508                                 MACvSelectPage1(priv->PortOffset);
1509
1510                                 VNSvOutPortD(priv->PortOffset +
1511                                              MAC_REG_MAR0, 0xffffffff);
1512                                 VNSvOutPortD(priv->PortOffset +
1513                                             MAC_REG_MAR0 + 4, 0xffffffff);
1514
1515                                 MACvSelectPage0(priv->PortOffset);
1516                         } else {
1517                                 MACvSelectPage1(priv->PortOffset);
1518
1519                                 VNSvOutPortD(priv->PortOffset +
1520                                              MAC_REG_MAR0, (u32)multicast);
1521                                 VNSvOutPortD(priv->PortOffset +
1522                                              MAC_REG_MAR0 + 4,
1523                                              (u32)(multicast >> 32));
1524
1525                                 MACvSelectPage0(priv->PortOffset);
1526                         }
1527
1528                         spin_unlock_irqrestore(&priv->lock, flags);
1529
1530                         rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1531                 } else {
1532                         rx_mode &= ~(RCR_MULTICAST | RCR_BROADCAST);
1533                 }
1534         }
1535
1536         if (changed_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC)) {
1537                 rx_mode |= RCR_MULTICAST | RCR_BROADCAST;
1538
1539                 if (*total_flags & (FIF_OTHER_BSS | FIF_BCN_PRBRESP_PROMISC))
1540                         rx_mode &= ~RCR_BSSID;
1541                 else
1542                         rx_mode |= RCR_BSSID;
1543         }
1544
1545         VNSvOutPortB(priv->PortOffset + MAC_REG_RCR, rx_mode);
1546
1547         dev_dbg(&priv->pcid->dev, "rx mode out= %x\n", rx_mode);
1548 }
1549
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)
1553 {
1554         struct vnt_private *priv = hw->priv;
1555
1556         switch (cmd) {
1557         case SET_KEY:
1558                 if (vnt_set_keys(hw, sta, vif, key))
1559                         return -EOPNOTSUPP;
1560                 break;
1561         case DISABLE_KEY:
1562                 if (test_bit(key->hw_key_idx, &priv->key_entry_inuse))
1563                         clear_bit(key->hw_key_idx, &priv->key_entry_inuse);
1564         default:
1565                 break;
1566         }
1567
1568         return 0;
1569 }
1570
1571 static int vnt_get_stats(struct ieee80211_hw *hw,
1572                          struct ieee80211_low_level_stats *stats)
1573 {
1574         struct vnt_private *priv = hw->priv;
1575
1576         memcpy(stats, &priv->low_stats, sizeof(*stats));
1577
1578         return 0;
1579 }
1580
1581 static u64 vnt_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1582 {
1583         struct vnt_private *priv = hw->priv;
1584         u64 tsf;
1585
1586         CARDbGetCurrentTSF(priv, &tsf);
1587
1588         return tsf;
1589 }
1590
1591 static void vnt_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1592                         u64 tsf)
1593 {
1594         struct vnt_private *priv = hw->priv;
1595
1596         CARDvUpdateNextTBTT(priv, tsf, vif->bss_conf.beacon_int);
1597 }
1598
1599 static void vnt_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1600 {
1601         struct vnt_private *priv = hw->priv;
1602
1603         /* reset TSF counter */
1604         VNSvOutPortB(priv->PortOffset + MAC_REG_TFTCTL, TFTCTL_TSFCNTRST);
1605 }
1606
1607 static const struct ieee80211_ops vnt_mac_ops = {
1608         .tx                     = vnt_tx_80211,
1609         .start                  = vnt_start,
1610         .stop                   = vnt_stop,
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,
1622 };
1623
1624 static int vnt_init(struct vnt_private *priv)
1625 {
1626         SET_IEEE80211_PERM_ADDR(priv->hw, priv->abyCurrentNetAddr);
1627
1628         vnt_init_bands(priv);
1629
1630         if (ieee80211_register_hw(priv->hw))
1631                 return -ENODEV;
1632
1633         priv->mac_hw = true;
1634
1635         CARDbRadioPowerOff(priv);
1636
1637         return 0;
1638 }
1639
1640 static int
1641 vt6655_probe(struct pci_dev *pcid, const struct pci_device_id *ent)
1642 {
1643         PCHIP_INFO  pChip_info = (PCHIP_INFO)ent->driver_data;
1644         struct vnt_private *priv;
1645         struct ieee80211_hw *hw;
1646         struct wiphy *wiphy;
1647         int         rc;
1648
1649         dev_notice(&pcid->dev,
1650                    "%s Ver. %s\n", DEVICE_FULL_DRV_NAM, DEVICE_VERSION);
1651
1652         dev_notice(&pcid->dev,
1653                    "Copyright (c) 2003 VIA Networking Technologies, Inc.\n");
1654
1655         hw = ieee80211_alloc_hw(sizeof(*priv), &vnt_mac_ops);
1656         if (!hw) {
1657                 dev_err(&pcid->dev, "could not register ieee80211_hw\n");
1658                 return -ENOMEM;
1659         }
1660
1661         priv = hw->priv;
1662
1663         vt6655_init_info(pcid, &priv, pChip_info);
1664
1665         priv->hw = hw;
1666
1667         SET_IEEE80211_DEV(priv->hw, &pcid->dev);
1668
1669         if (pci_enable_device(pcid)) {
1670                 device_free_info(priv);
1671                 return -ENODEV;
1672         }
1673
1674         dev_dbg(&pcid->dev,
1675                 "Before get pci_info memaddr is %x\n", priv->memaddr);
1676
1677         if (!device_get_pci_info(priv, pcid)) {
1678                 dev_err(&pcid->dev, ": Failed to find PCI device.\n");
1679                 device_free_info(priv);
1680                 return -ENODEV;
1681         }
1682
1683         priv->PortOffset = ioremap(priv->memaddr & PCI_BASE_ADDRESS_MEM_MASK,
1684                                    priv->io_size);
1685         if (!priv->PortOffset) {
1686                 dev_err(&pcid->dev, ": Failed to IO remapping ..\n");
1687                 device_free_info(priv);
1688                 return -ENODEV;
1689         }
1690
1691         rc = pci_request_regions(pcid, DEVICE_NAME);
1692         if (rc) {
1693                 dev_err(&pcid->dev, ": Failed to find PCI device\n");
1694                 device_free_info(priv);
1695                 return -ENODEV;
1696         }
1697
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);
1701                 return -ENODEV;
1702         }
1703
1704         INIT_WORK(&priv->interrupt_work, vnt_interrupt_work);
1705
1706         /* do reset */
1707         if (!MACbSoftwareReset(priv->PortOffset)) {
1708                 dev_err(&pcid->dev, ": Failed to access MAC hardware..\n");
1709                 device_free_info(priv);
1710                 return -ENODEV;
1711         }
1712         /* initial to reload eeprom */
1713         MACvInitialize(priv->PortOffset);
1714         MACvReadEtherAddress(priv->PortOffset, priv->abyCurrentNetAddr);
1715
1716         /* Get RFType */
1717         priv->byRFType = SROMbyReadEmbedded(priv->PortOffset, EEP_OFS_RFTYPE);
1718         priv->byRFType &= RF_MASK;
1719
1720         dev_dbg(&pcid->dev, "RF Type = %x\n", priv->byRFType);
1721
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;
1726
1727         /* Enable the chip specified capabilities */
1728         priv->flags = priv->sOpts.flags | (pChip_info->flags & 0xff000000UL);
1729
1730         wiphy = priv->hw->wiphy;
1731
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);
1736
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);
1742
1743         priv->hw->max_signal = 100;
1744
1745         if (vnt_init(priv))
1746                 return -ENODEV;
1747
1748         device_print_info(priv);
1749         pci_set_drvdata(pcid, priv);
1750
1751         return 0;
1752 }
1753
1754 /*------------------------------------------------------------------*/
1755
1756 #ifdef CONFIG_PM
1757 static int vt6655_suspend(struct pci_dev *pcid, pm_message_t state)
1758 {
1759         struct vnt_private *priv = pci_get_drvdata(pcid);
1760         unsigned long flags;
1761
1762         spin_lock_irqsave(&priv->lock, flags);
1763
1764         pci_save_state(pcid);
1765
1766         MACbShutdown(priv->PortOffset);
1767
1768         pci_disable_device(pcid);
1769         pci_set_power_state(pcid, pci_choose_state(pcid, state));
1770
1771         spin_unlock_irqrestore(&priv->lock, flags);
1772
1773         return 0;
1774 }
1775
1776 static int vt6655_resume(struct pci_dev *pcid)
1777 {
1778
1779         pci_set_power_state(pcid, PCI_D0);
1780         pci_enable_wake(pcid, PCI_D0, 0);
1781         pci_restore_state(pcid);
1782
1783         return 0;
1784 }
1785 #endif
1786
1787 MODULE_DEVICE_TABLE(pci, vt6655_pci_id_table);
1788
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,
1794 #ifdef CONFIG_PM
1795         .suspend = vt6655_suspend,
1796         .resume = vt6655_resume,
1797 #endif
1798 };
1799
1800 module_pci_driver(device_driver);