Staging: rt2860: remove dead MULTIPLE_CARD_SUPPORT code
[linux-2.6] / drivers / staging / rt2860 / 2860_main_dev.c
1 /*
2  *************************************************************************
3  * Ralink Tech Inc.
4  * 5F., No.36, Taiyuan St., Jhubei City,
5  * Hsinchu County 302,
6  * Taiwan, R.O.C.
7  *
8  * (c) Copyright 2002-2007, Ralink Technology, Inc.
9  *
10  * This program is free software; you can redistribute it and/or modify  *
11  * it under the terms of the GNU General Public License as published by  *
12  * the Free Software Foundation; either version 2 of the License, or     *
13  * (at your option) any later version.                                   *
14  *                                                                       *
15  * This program is distributed in the hope that it will be useful,       *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  * GNU General Public License for more details.                          *
19  *                                                                       *
20  * You should have received a copy of the GNU General Public License     *
21  * along with this program; if not, write to the                         *
22  * Free Software Foundation, Inc.,                                       *
23  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
24  *                                                                       *
25  *************************************************************************
26
27     Module Name:
28     2870_main_dev.c
29
30     Abstract:
31     Create and register network interface.
32
33     Revision History:
34     Who         When            What
35     --------    ----------      ----------------------------------------------
36 */
37
38 #include "rt_config.h"
39
40 extern INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
41                                                                         IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
42
43 static void rx_done_tasklet(unsigned long data);
44 static void mgmt_dma_done_tasklet(unsigned long data);
45 static void ac0_dma_done_tasklet(unsigned long data);
46 static void ac1_dma_done_tasklet(unsigned long data);
47 static void ac2_dma_done_tasklet(unsigned long data);
48 static void ac3_dma_done_tasklet(unsigned long data);
49 static void hcca_dma_done_tasklet(unsigned long data);
50 static void fifo_statistic_full_tasklet(unsigned long data);
51
52
53 /*---------------------------------------------------------------------*/
54 /* Symbol & Macro Definitions                                          */
55 /*---------------------------------------------------------------------*/
56 #define RT2860_INT_RX_DLY                               (1<<0)          // bit 0
57 #define RT2860_INT_TX_DLY                               (1<<1)          // bit 1
58 #define RT2860_INT_RX_DONE                              (1<<2)          // bit 2
59 #define RT2860_INT_AC0_DMA_DONE                 (1<<3)          // bit 3
60 #define RT2860_INT_AC1_DMA_DONE                 (1<<4)          // bit 4
61 #define RT2860_INT_AC2_DMA_DONE                 (1<<5)          // bit 5
62 #define RT2860_INT_AC3_DMA_DONE                 (1<<6)          // bit 6
63 #define RT2860_INT_HCCA_DMA_DONE                (1<<7)          // bit 7
64 #define RT2860_INT_MGMT_DONE                    (1<<8)          // bit 8
65
66 #define INT_RX                  RT2860_INT_RX_DONE
67
68 #define INT_AC0_DLY             (RT2860_INT_AC0_DMA_DONE) //| RT2860_INT_TX_DLY)
69 #define INT_AC1_DLY             (RT2860_INT_AC1_DMA_DONE) //| RT2860_INT_TX_DLY)
70 #define INT_AC2_DLY             (RT2860_INT_AC2_DMA_DONE) //| RT2860_INT_TX_DLY)
71 #define INT_AC3_DLY             (RT2860_INT_AC3_DMA_DONE) //| RT2860_INT_TX_DLY)
72 #define INT_HCCA_DLY    (RT2860_INT_HCCA_DMA_DONE) //| RT2860_INT_TX_DLY)
73 #define INT_MGMT_DLY    RT2860_INT_MGMT_DONE
74
75 /*---------------------------------------------------------------------*/
76 /* Prototypes of Functions Used                                        */
77 /*---------------------------------------------------------------------*/
78 /* function declarations */
79 static INT __devinit rt2860_init_one (struct pci_dev *pci_dev, const struct pci_device_id  *ent);
80 static VOID __devexit rt2860_remove_one(struct pci_dev *pci_dev);
81 static INT __devinit rt2860_probe(struct pci_dev *pci_dev, const struct pci_device_id  *ent);
82 void init_thread_task(PRTMP_ADAPTER pAd);
83 static void __exit rt2860_cleanup_module(void);
84 static int __init rt2860_init_module(void);
85
86 #ifdef CONFIG_PM
87 static int rt2860_suspend(struct pci_dev *pci_dev, pm_message_t state);
88 static int rt2860_resume(struct pci_dev *pci_dev);
89 #endif // CONFIG_PM //
90
91
92 //
93 // Ralink PCI device table, include all supported chipsets
94 //
95 static struct pci_device_id rt2860_pci_tbl[] __devinitdata =
96 {
97         {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2860_PCI_DEVICE_ID)},         //RT28602.4G
98         {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2860_PCIe_DEVICE_ID)},
99         {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2760_PCI_DEVICE_ID)},
100         {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2790_PCIe_DEVICE_ID)},
101         {PCI_DEVICE(VEN_AWT_PCI_VENDOR_ID, VEN_AWT_PCIe_DEVICE_ID)},
102     {0,}                // terminate list
103 };
104
105 MODULE_DEVICE_TABLE(pci, rt2860_pci_tbl);
106 #ifdef CONFIG_STA_SUPPORT
107 MODULE_LICENSE("GPL");
108 #ifdef MODULE_VERSION
109 MODULE_VERSION(STA_DRIVER_VERSION);
110 #endif
111 #endif // CONFIG_STA_SUPPORT //
112
113
114 //
115 // Our PCI driver structure
116 //
117 static struct pci_driver rt2860_driver =
118 {
119     name:       "rt2860",
120     id_table:   rt2860_pci_tbl,
121     probe:      rt2860_init_one,
122     remove:     __devexit_p(rt2860_remove_one),
123
124 #ifdef CONFIG_PM
125         suspend:        rt2860_suspend,
126         resume:         rt2860_resume,
127 #endif
128 };
129
130
131 #ifdef CONFIG_PM
132
133 VOID RT2860RejectPendingPackets(
134         IN      PRTMP_ADAPTER   pAd)
135 {
136         // clear PS packets
137         // clear TxSw packets
138 }
139
140 static int rt2860_suspend(
141         struct pci_dev *pci_dev,
142         pm_message_t state)
143 {
144         struct net_device *net_dev = pci_get_drvdata(pci_dev);
145         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL;
146         INT32 retval;
147
148
149         DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_suspend()\n"));
150
151         if (net_dev == NULL)
152         {
153                 DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n"));
154         }
155         else
156         {
157                 pAd = net_dev->ml_priv;
158
159                 /* we can not use IFF_UP because ra0 down but ra1 up */
160                 /* and 1 suspend/resume function for 1 module, not for each interface */
161                 /* so Linux will call suspend/resume function once */
162                 if (VIRTUAL_IF_NUM(pAd) > 0)
163                 {
164                         // avoid users do suspend after interface is down
165
166                         // stop interface
167                         netif_carrier_off(net_dev);
168                         netif_stop_queue(net_dev);
169
170                         // mark device as removed from system and therefore no longer available
171                         netif_device_detach(net_dev);
172
173                         // mark halt flag
174                         RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
175                         RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
176
177                         // take down the device
178                         rt28xx_close((PNET_DEV)net_dev);
179
180                         RT_MOD_DEC_USE_COUNT();
181                 }
182         }
183
184         // reference to http://vovo2000.com/type-lab/linux/kernel-api/linux-kernel-api.html
185         // enable device to generate PME# when suspended
186         // pci_choose_state(): Choose the power state of a PCI device to be suspended
187         retval = pci_enable_wake(pci_dev, pci_choose_state(pci_dev, state), 1);
188         // save the PCI configuration space of a device before suspending
189         pci_save_state(pci_dev);
190         // disable PCI device after use
191         pci_disable_device(pci_dev);
192
193         retval = pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
194
195         DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_suspend()\n"));
196         return retval;
197 }
198
199 static int rt2860_resume(
200         struct pci_dev *pci_dev)
201 {
202         struct net_device *net_dev = pci_get_drvdata(pci_dev);
203         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL;
204         INT32 retval;
205
206
207         // set the power state of a PCI device
208         // PCI has 4 power states, DO (normal) ~ D3(less power)
209         // in include/linux/pci.h, you can find that
210         // #define PCI_D0          ((pci_power_t __force) 0)
211         // #define PCI_D1          ((pci_power_t __force) 1)
212         // #define PCI_D2          ((pci_power_t __force) 2)
213         // #define PCI_D3hot       ((pci_power_t __force) 3)
214         // #define PCI_D3cold      ((pci_power_t __force) 4)
215         // #define PCI_UNKNOWN     ((pci_power_t __force) 5)
216         // #define PCI_POWER_ERROR ((pci_power_t __force) -1)
217         retval = pci_set_power_state(pci_dev, PCI_D0);
218
219         // restore the saved state of a PCI device
220         pci_restore_state(pci_dev);
221
222         // initialize device before it's used by a driver
223         if (pci_enable_device(pci_dev))
224         {
225                 printk("pci enable fail!\n");
226                 return 0;
227         }
228
229         DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_resume()\n"));
230
231         if (net_dev == NULL)
232         {
233                 DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n"));
234         }
235         else
236                 pAd = net_dev->ml_priv;
237
238         if (pAd != NULL)
239         {
240                 /* we can not use IFF_UP because ra0 down but ra1 up */
241                 /* and 1 suspend/resume function for 1 module, not for each interface */
242                 /* so Linux will call suspend/resume function once */
243                 if (VIRTUAL_IF_NUM(pAd) > 0)
244                 {
245                         // mark device as attached from system and restart if needed
246                         netif_device_attach(net_dev);
247
248                         if (rt28xx_open((PNET_DEV)net_dev) != 0)
249                         {
250                                 // open fail
251                                 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_resume()\n"));
252                                 return 0;
253                         }
254
255                         // increase MODULE use count
256                         RT_MOD_INC_USE_COUNT();
257
258                         RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
259                         RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
260
261                         netif_start_queue(net_dev);
262                         netif_carrier_on(net_dev);
263                         netif_wake_queue(net_dev);
264                 }
265         }
266
267         DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_resume()\n"));
268         return 0;
269 }
270 #endif // CONFIG_PM //
271
272
273 static INT __init rt2860_init_module(VOID)
274 {
275         return pci_register_driver(&rt2860_driver);
276 }
277
278
279 //
280 // Driver module unload function
281 //
282 static VOID __exit rt2860_cleanup_module(VOID)
283 {
284     pci_unregister_driver(&rt2860_driver);
285 }
286
287 module_init(rt2860_init_module);
288 module_exit(rt2860_cleanup_module);
289
290
291 static INT __devinit rt2860_init_one (
292     IN  struct pci_dev              *pci_dev,
293     IN  const struct pci_device_id  *ent)
294 {
295     INT rc;
296
297     DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_init_one\n"));
298
299     // wake up and enable device
300     if (pci_enable_device (pci_dev))
301     {
302         rc = -EIO;
303     }
304     else
305     {
306         rc = rt2860_probe(pci_dev, ent);
307     }
308
309     DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_init_one\n"));
310     return rc;
311 }
312
313
314 static VOID __devexit rt2860_remove_one(
315     IN  struct pci_dev  *pci_dev)
316 {
317     struct net_device   *net_dev = pci_get_drvdata(pci_dev);
318     RTMP_ADAPTER        *pAd = net_dev->ml_priv;
319
320     DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_remove_one\n"));
321
322         if (pAd != NULL)
323         {
324                 // Unregister network device
325                 unregister_netdev(net_dev);
326
327                 // Unmap CSR base address
328                 iounmap((char *)(net_dev->base_addr));
329
330                 RTMPFreeAdapter(pAd);
331
332                 // release memory region
333                 release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0));
334         }
335         else
336         {
337                 // Unregister network device
338                 unregister_netdev(net_dev);
339
340                 // Unmap CSR base address
341                 iounmap((char *)(net_dev->base_addr));
342
343                 // release memory region
344                 release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0));
345         }
346
347         // Free pre-allocated net_device memory
348         free_netdev(net_dev);
349 }
350
351 //
352 // PCI device probe & initialization function
353 //
354 static INT __devinit   rt2860_probe(
355     IN  struct pci_dev              *pci_dev,
356     IN  const struct pci_device_id  *ent)
357 {
358         PRTMP_ADAPTER pAd;
359     INT rv = 0;
360
361     rv = (INT)rt28xx_probe((void *)pci_dev, (void *)ent, 0, &pAd);
362         OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE);
363         return rv;
364 }
365
366
367 void init_thread_task(IN PRTMP_ADAPTER pAd)
368 {
369         POS_COOKIE pObj;
370
371         pObj = (POS_COOKIE) pAd->OS_Cookie;
372
373         tasklet_init(&pObj->rx_done_task, rx_done_tasklet, (unsigned long)pAd);
374         tasklet_init(&pObj->mgmt_dma_done_task, mgmt_dma_done_tasklet, (unsigned long)pAd);
375         tasklet_init(&pObj->ac0_dma_done_task, ac0_dma_done_tasklet, (unsigned long)pAd);
376         tasklet_init(&pObj->ac1_dma_done_task, ac1_dma_done_tasklet, (unsigned long)pAd);
377         tasklet_init(&pObj->ac2_dma_done_task, ac2_dma_done_tasklet, (unsigned long)pAd);
378         tasklet_init(&pObj->ac3_dma_done_task, ac3_dma_done_tasklet, (unsigned long)pAd);
379         tasklet_init(&pObj->hcca_dma_done_task, hcca_dma_done_tasklet, (unsigned long)pAd);
380         tasklet_init(&pObj->tbtt_task, tbtt_tasklet, (unsigned long)pAd);
381         tasklet_init(&pObj->fifo_statistic_full_task, fifo_statistic_full_tasklet, (unsigned long)pAd);
382 }
383
384 void kill_thread_task(IN PRTMP_ADAPTER pAd)
385 {
386         POS_COOKIE pObj;
387
388         pObj = (POS_COOKIE) pAd->OS_Cookie;
389
390         tasklet_kill(&pObj->rx_done_task);
391         tasklet_kill(&pObj->mgmt_dma_done_task);
392         tasklet_kill(&pObj->ac0_dma_done_task);
393         tasklet_kill(&pObj->ac1_dma_done_task);
394         tasklet_kill(&pObj->ac2_dma_done_task);
395         tasklet_kill(&pObj->ac3_dma_done_task);
396         tasklet_kill(&pObj->hcca_dma_done_task);
397         tasklet_kill(&pObj->tbtt_task);
398         tasklet_kill(&pObj->fifo_statistic_full_task);
399 }
400
401
402 static void rt2860_int_enable(PRTMP_ADAPTER pAd, unsigned int mode)
403 {
404         u32 regValue;
405
406         pAd->int_disable_mask &= ~(mode);
407         regValue = pAd->int_enable_reg & ~(pAd->int_disable_mask);
408         RTMP_IO_WRITE32(pAd, INT_MASK_CSR, regValue);     // 1:enable
409
410         if (regValue != 0)
411                 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE);
412 }
413
414
415 static void rt2860_int_disable(PRTMP_ADAPTER pAd, unsigned int mode)
416 {
417         u32 regValue;
418
419         pAd->int_disable_mask |= mode;
420         regValue =      pAd->int_enable_reg & ~(pAd->int_disable_mask);
421         RTMP_IO_WRITE32(pAd, INT_MASK_CSR, regValue);     // 0: disable
422
423         if (regValue == 0)
424         {
425                 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE);
426         }
427 }
428
429 static void mgmt_dma_done_tasklet(unsigned long data)
430 {
431         unsigned long flags;
432         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
433     INT_SOURCE_CSR_STRUC        IntSource;
434         POS_COOKIE pObj;
435
436         // Do nothing if the driver is starting halt state.
437         // This might happen when timer already been fired before cancel timer with mlmehalt
438         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
439                 return;
440
441     pObj = (POS_COOKIE) pAd->OS_Cookie;
442
443         IntSource.word = 0;
444         IntSource.field.MgmtDmaDone = 1;
445         pAd->int_pending &= ~INT_MGMT_DLY;
446
447         RTMPHandleMgmtRingDmaDoneInterrupt(pAd);
448
449         // if you use RTMP_SEM_LOCK, sometimes kernel will hang up, no any
450         // bug report output
451         RTMP_INT_LOCK(&pAd->irq_lock, flags);
452         /*
453          * double check to avoid lose of interrupts
454          */
455         if (pAd->int_pending & INT_MGMT_DLY)
456         {
457                 tasklet_hi_schedule(&pObj->mgmt_dma_done_task);
458                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
459                 return;
460         }
461
462         /* enable TxDataInt again */
463         rt2860_int_enable(pAd, INT_MGMT_DLY);
464         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
465 }
466
467 static void rx_done_tasklet(unsigned long data)
468 {
469         unsigned long flags;
470         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
471         BOOLEAN bReschedule = 0;
472         POS_COOKIE pObj;
473
474         // Do nothing if the driver is starting halt state.
475         // This might happen when timer already been fired before cancel timer with mlmehalt
476         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
477                 return;
478
479     pObj = (POS_COOKIE) pAd->OS_Cookie;
480
481         pAd->int_pending &= ~(INT_RX);
482 #ifdef CONFIG_STA_SUPPORT
483         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
484                 bReschedule = STARxDoneInterruptHandle(pAd, 0);
485 #endif // CONFIG_STA_SUPPORT //
486
487         RTMP_INT_LOCK(&pAd->irq_lock, flags);
488         /*
489          * double check to avoid rotting packet
490          */
491         if (pAd->int_pending & INT_RX || bReschedule)
492         {
493                 tasklet_hi_schedule(&pObj->rx_done_task);
494                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
495                 return;
496         }
497
498         /* enable RxINT again */
499         rt2860_int_enable(pAd, INT_RX);
500         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
501
502 }
503
504 void fifo_statistic_full_tasklet(unsigned long data)
505 {
506         unsigned long flags;
507         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
508         POS_COOKIE pObj;
509
510         // Do nothing if the driver is starting halt state.
511         // This might happen when timer already been fired before cancel timer with mlmehalt
512         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
513                 return;
514
515     pObj = (POS_COOKIE) pAd->OS_Cookie;
516
517         pAd->int_pending &= ~(FifoStaFullInt);
518         NICUpdateFifoStaCounters(pAd);
519
520         RTMP_INT_LOCK(&pAd->irq_lock, flags);
521         /*
522          * double check to avoid rotting packet
523          */
524         if (pAd->int_pending & FifoStaFullInt)
525         {
526                 tasklet_hi_schedule(&pObj->fifo_statistic_full_task);
527                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
528                 return;
529         }
530
531         /* enable RxINT again */
532
533         rt2860_int_enable(pAd, FifoStaFullInt);
534         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
535
536 }
537
538 static void hcca_dma_done_tasklet(unsigned long data)
539 {
540         unsigned long flags;
541         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
542     INT_SOURCE_CSR_STRUC        IntSource;
543         POS_COOKIE pObj;
544
545         // Do nothing if the driver is starting halt state.
546         // This might happen when timer already been fired before cancel timer with mlmehalt
547         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
548                 return;
549
550     pObj = (POS_COOKIE) pAd->OS_Cookie;
551
552
553         IntSource.word = 0;
554         IntSource.field.HccaDmaDone = 1;
555         pAd->int_pending &= ~INT_HCCA_DLY;
556
557         RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
558
559         RTMP_INT_LOCK(&pAd->irq_lock, flags);
560         /*
561          * double check to avoid lose of interrupts
562          */
563         if (pAd->int_pending & INT_HCCA_DLY)
564         {
565                 tasklet_hi_schedule(&pObj->hcca_dma_done_task);
566                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
567                 return;
568         }
569
570         /* enable TxDataInt again */
571         rt2860_int_enable(pAd, INT_HCCA_DLY);
572         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
573 }
574
575 static void ac3_dma_done_tasklet(unsigned long data)
576 {
577         unsigned long flags;
578         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
579     INT_SOURCE_CSR_STRUC        IntSource;
580         POS_COOKIE pObj;
581         BOOLEAN bReschedule = 0;
582
583         // Do nothing if the driver is starting halt state.
584         // This might happen when timer already been fired before cancel timer with mlmehalt
585         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
586                 return;
587
588     pObj = (POS_COOKIE) pAd->OS_Cookie;
589
590         IntSource.word = 0;
591         IntSource.field.Ac3DmaDone = 1;
592         pAd->int_pending &= ~INT_AC3_DLY;
593
594         bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
595
596         RTMP_INT_LOCK(&pAd->irq_lock, flags);
597         /*
598          * double check to avoid lose of interrupts
599          */
600         if ((pAd->int_pending & INT_AC3_DLY) || bReschedule)
601         {
602                 tasklet_hi_schedule(&pObj->ac3_dma_done_task);
603                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
604                 return;
605         }
606
607         /* enable TxDataInt again */
608         rt2860_int_enable(pAd, INT_AC3_DLY);
609         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
610 }
611
612 static void ac2_dma_done_tasklet(unsigned long data)
613 {
614         unsigned long flags;
615         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
616     INT_SOURCE_CSR_STRUC        IntSource;
617         POS_COOKIE pObj;
618         BOOLEAN bReschedule = 0;
619
620         // Do nothing if the driver is starting halt state.
621         // This might happen when timer already been fired before cancel timer with mlmehalt
622         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
623                 return;
624
625     pObj = (POS_COOKIE) pAd->OS_Cookie;
626
627         IntSource.word = 0;
628         IntSource.field.Ac2DmaDone = 1;
629         pAd->int_pending &= ~INT_AC2_DLY;
630
631         bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
632
633         RTMP_INT_LOCK(&pAd->irq_lock, flags);
634
635         /*
636          * double check to avoid lose of interrupts
637          */
638         if ((pAd->int_pending & INT_AC2_DLY) || bReschedule)
639         {
640                 tasklet_hi_schedule(&pObj->ac2_dma_done_task);
641                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
642                 return;
643         }
644
645         /* enable TxDataInt again */
646         rt2860_int_enable(pAd, INT_AC2_DLY);
647         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
648 }
649
650 static void ac1_dma_done_tasklet(unsigned long data)
651 {
652         unsigned long flags;
653         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
654     INT_SOURCE_CSR_STRUC        IntSource;
655         POS_COOKIE pObj;
656         BOOLEAN bReschedule = 0;
657
658         // Do nothing if the driver is starting halt state.
659         // This might happen when timer already been fired before cancel timer with mlmehalt
660         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
661                 return;
662
663     pObj = (POS_COOKIE) pAd->OS_Cookie;
664
665         IntSource.word = 0;
666         IntSource.field.Ac1DmaDone = 1;
667         pAd->int_pending &= ~INT_AC1_DLY;
668
669         bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
670
671         RTMP_INT_LOCK(&pAd->irq_lock, flags);
672         /*
673          * double check to avoid lose of interrupts
674          */
675         if ((pAd->int_pending & INT_AC1_DLY) || bReschedule)
676         {
677                 tasklet_hi_schedule(&pObj->ac1_dma_done_task);
678                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
679                 return;
680         }
681
682         /* enable TxDataInt again */
683         rt2860_int_enable(pAd, INT_AC1_DLY);
684         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
685 }
686
687 static void ac0_dma_done_tasklet(unsigned long data)
688 {
689         unsigned long flags;
690         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
691     INT_SOURCE_CSR_STRUC        IntSource;
692         POS_COOKIE pObj;
693         BOOLEAN bReschedule = 0;
694
695         // Do nothing if the driver is starting halt state.
696         // This might happen when timer already been fired before cancel timer with mlmehalt
697         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
698                 return;
699
700     pObj = (POS_COOKIE) pAd->OS_Cookie;
701
702         IntSource.word = 0;
703         IntSource.field.Ac0DmaDone = 1;
704         pAd->int_pending &= ~INT_AC0_DLY;
705
706         bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
707
708         RTMP_INT_LOCK(&pAd->irq_lock, flags);
709         /*
710          * double check to avoid lose of interrupts
711          */
712         if ((pAd->int_pending & INT_AC0_DLY) || bReschedule)
713         {
714                 tasklet_hi_schedule(&pObj->ac0_dma_done_task);
715                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
716                 return;
717         }
718
719         /* enable TxDataInt again */
720         rt2860_int_enable(pAd, INT_AC0_DLY);
721         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
722 }
723
724
725 int print_int_count;
726
727 IRQ_HANDLE_TYPE
728 rt2860_interrupt(int irq, void *dev_instance)
729 {
730         struct net_device *net_dev = (struct net_device *) dev_instance;
731         PRTMP_ADAPTER pAd = net_dev->ml_priv;
732         INT_SOURCE_CSR_STRUC    IntSource;
733         POS_COOKIE pObj;
734         BOOLEAN bOldValue;
735
736         pObj = (POS_COOKIE) pAd->OS_Cookie;
737
738
739         /* Note 03312008: we can not return here before
740                 RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IntSource.word);
741                 RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, IntSource.word);
742                 Or kernel will panic after ifconfig ra0 down sometimes */
743
744
745         //
746         // Inital the Interrupt source.
747         //
748         IntSource.word = 0x00000000L;
749 //      McuIntSource.word = 0x00000000L;
750
751         //
752         // Get the interrupt sources & saved to local variable
753         //
754         //RTMP_IO_READ32(pAd, where, &McuIntSource.word);
755         //RTMP_IO_WRITE32(pAd, , McuIntSource.word);
756
757         //
758         // Flag fOP_STATUS_DOZE On, means ASIC put to sleep, elase means ASICK WakeUp
759         // And at the same time, clock maybe turned off that say there is no DMA service.
760         // when ASIC get to sleep.
761         // To prevent system hang on power saving.
762         // We need to check it before handle the INT_SOURCE_CSR, ASIC must be wake up.
763         //
764         // RT2661 => when ASIC is sleeping, MAC register cannot be read and written.
765         // RT2860 => when ASIC is sleeping, MAC register can be read and written.
766
767         bOldValue = pAd->bPCIclkOff;
768         pAd->bPCIclkOff = FALSE;
769         {
770                 RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IntSource.word);
771                 RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, IntSource.word); // write 1 to clear
772         }
773         pAd->bPCIclkOff = bOldValue;
774
775         // Do nothing if Reset in progress
776         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
777                 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
778         {
779                 return IRQ_HANDLED;
780         }
781
782         //
783         // Handle interrupt, walk through all bits
784         // Should start from highest priority interrupt
785         // The priority can be adjust by altering processing if statement
786         //
787
788         // If required spinlock, each interrupt service routine has to acquire
789         // and release itself.
790         //
791
792         // Do nothing if NIC doesn't exist
793         if (IntSource.word == 0xffffffff)
794         {
795                 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS);
796                 printk("snowpin - IntSource.word == 0xffffffff\n");
797                 return IRQ_HANDLED;
798         }
799
800         if (IntSource.word & TxCoherent)
801         {
802                 DBGPRINT(RT_DEBUG_ERROR, (">>>TxCoherent<<<\n"));
803                 RTMPHandleRxCoherentInterrupt(pAd);
804         }
805
806         if (IntSource.word & RxCoherent)
807         {
808                 DBGPRINT(RT_DEBUG_ERROR, (">>>RxCoherent<<<\n"));
809                 RTMPHandleRxCoherentInterrupt(pAd);
810         }
811
812         if (IntSource.word & FifoStaFullInt)
813         {
814 #if 1
815                 if ((pAd->int_disable_mask & FifoStaFullInt) == 0)
816                 {
817                         /* mask FifoStaFullInt */
818                         rt2860_int_disable(pAd, FifoStaFullInt);
819                         tasklet_hi_schedule(&pObj->fifo_statistic_full_task);
820                 }
821                 pAd->int_pending |= FifoStaFullInt;
822 #else
823                 NICUpdateFifoStaCounters(pAd);
824 #endif
825         }
826
827         if (IntSource.word & INT_MGMT_DLY)
828         {
829                 if ((pAd->int_disable_mask & INT_MGMT_DLY) ==0 )
830                 {
831                         rt2860_int_disable(pAd, INT_MGMT_DLY);
832                         tasklet_hi_schedule(&pObj->mgmt_dma_done_task);
833                 }
834                 pAd->int_pending |= INT_MGMT_DLY ;
835         }
836
837         if (IntSource.word & INT_RX)
838         {
839                 if ((pAd->int_disable_mask & INT_RX) == 0)
840                 {
841                         /* mask RxINT */
842                         rt2860_int_disable(pAd, INT_RX);
843                         tasklet_hi_schedule(&pObj->rx_done_task);
844                 }
845                 pAd->int_pending |= INT_RX;
846         }
847
848         if (IntSource.word & INT_HCCA_DLY)
849         {
850
851                 if ((pAd->int_disable_mask & INT_HCCA_DLY) == 0)
852                 {
853                         /* mask TxDataInt */
854                         rt2860_int_disable(pAd, INT_HCCA_DLY);
855                         tasklet_hi_schedule(&pObj->hcca_dma_done_task);
856                 }
857                 pAd->int_pending |= INT_HCCA_DLY;
858         }
859
860         if (IntSource.word & INT_AC3_DLY)
861         {
862
863                 if ((pAd->int_disable_mask & INT_AC3_DLY) == 0)
864                 {
865                         /* mask TxDataInt */
866                         rt2860_int_disable(pAd, INT_AC3_DLY);
867                         tasklet_hi_schedule(&pObj->ac3_dma_done_task);
868                 }
869                 pAd->int_pending |= INT_AC3_DLY;
870         }
871
872         if (IntSource.word & INT_AC2_DLY)
873         {
874
875                 if ((pAd->int_disable_mask & INT_AC2_DLY) == 0)
876                 {
877                         /* mask TxDataInt */
878                         rt2860_int_disable(pAd, INT_AC2_DLY);
879                         tasklet_hi_schedule(&pObj->ac2_dma_done_task);
880                 }
881                 pAd->int_pending |= INT_AC2_DLY;
882         }
883
884         if (IntSource.word & INT_AC1_DLY)
885         {
886
887                 pAd->int_pending |= INT_AC1_DLY;
888
889                 if ((pAd->int_disable_mask & INT_AC1_DLY) == 0)
890                 {
891                         /* mask TxDataInt */
892                         rt2860_int_disable(pAd, INT_AC1_DLY);
893                         tasklet_hi_schedule(&pObj->ac1_dma_done_task);
894                 }
895
896         }
897
898         if (IntSource.word & INT_AC0_DLY)
899         {
900                 pAd->int_pending |= INT_AC0_DLY;
901
902                 if ((pAd->int_disable_mask & INT_AC0_DLY) == 0)
903                 {
904                         /* mask TxDataInt */
905                         rt2860_int_disable(pAd, INT_AC0_DLY);
906                         tasklet_hi_schedule(&pObj->ac0_dma_done_task);
907                 }
908
909         }
910
911     if (IntSource.word & PreTBTTInt)
912         {
913                 RTMPHandlePreTBTTInterrupt(pAd);
914         }
915
916         if (IntSource.word & TBTTInt)
917         {
918                 RTMPHandleTBTTInterrupt(pAd);
919         }
920
921
922
923 #ifdef CONFIG_STA_SUPPORT
924         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
925         {
926                 if (IntSource.word & AutoWakeupInt)
927                         RTMPHandleTwakeupInterrupt(pAd);
928         }
929 #endif // CONFIG_STA_SUPPORT //
930
931     return  IRQ_HANDLED;
932 }
933
934 /*
935 ========================================================================
936 Routine Description:
937     Check the chipset vendor/product ID.
938
939 Arguments:
940     _dev_p                              Point to the PCI or USB device
941
942 Return Value:
943     TRUE                                Check ok
944         FALSE                           Check fail
945
946 Note:
947 ========================================================================
948 */
949 BOOLEAN RT28XXChipsetCheck(
950         IN void *_dev_p)
951 {
952         /* always TRUE */
953         return TRUE;
954 }
955
956
957 /*
958 ========================================================================
959 Routine Description:
960     Init net device structure.
961
962 Arguments:
963     _dev_p                              Point to the PCI or USB device
964     *net_dev                    Point to the net device
965         *pAd                            the raxx interface data pointer
966
967 Return Value:
968     TRUE                                Init ok
969         FALSE                           Init fail
970
971 Note:
972 ========================================================================
973 */
974 BOOLEAN RT28XXNetDevInit(
975         IN void                                 *_dev_p,
976         IN struct  net_device   *net_dev,
977         IN RTMP_ADAPTER                 *pAd)
978 {
979         struct pci_dev *pci_dev = (struct pci_dev *)_dev_p;
980     const CHAR  *print_name;
981     ULONG       csr_addr;
982
983
984         print_name = pci_dev ? pci_name(pci_dev) : "rt2860";
985
986         net_dev->base_addr = 0;
987         net_dev->irq = 0;
988
989     if (pci_request_regions(pci_dev, print_name))
990         goto err_out_free_netdev;
991
992     // interrupt IRQ number
993     net_dev->irq = pci_dev->irq;
994
995     // map physical address to virtual address for accessing register
996     csr_addr = (unsigned long) ioremap(pci_resource_start(pci_dev, 0),
997                                                                                 pci_resource_len(pci_dev, 0));
998
999     if (!csr_addr)
1000     {
1001         DBGPRINT(RT_DEBUG_ERROR,
1002                                 ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n",
1003                                 print_name, (ULONG)pci_resource_len(pci_dev, 0),
1004                                 (ULONG)pci_resource_start(pci_dev, 0)));
1005         goto err_out_free_res;
1006     }
1007
1008     // Save CSR virtual address and irq to device structure
1009     net_dev->base_addr = csr_addr;
1010     pAd->CSRBaseAddress = (PUCHAR)net_dev->base_addr;
1011
1012     // Set DMA master
1013     pci_set_master(pci_dev);
1014
1015     net_dev->priv_flags = INT_MAIN;
1016
1017     DBGPRINT(RT_DEBUG_TRACE, ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n",
1018                 net_dev->name, (ULONG)pci_resource_start(pci_dev, 0),
1019                         (ULONG)csr_addr, pci_dev->irq));
1020         return TRUE;
1021
1022
1023         /* --------------------------- ERROR HANDLE --------------------------- */
1024 err_out_free_res:
1025     pci_release_regions(pci_dev);
1026 err_out_free_netdev:
1027         /* free netdev in caller, not here */
1028         return FALSE;
1029 }
1030
1031
1032 /*
1033 ========================================================================
1034 Routine Description:
1035     Init net device structure.
1036
1037 Arguments:
1038     _dev_p                              Point to the PCI or USB device
1039         *pAd                            the raxx interface data pointer
1040
1041 Return Value:
1042     TRUE                                Config ok
1043         FALSE                           Config fail
1044
1045 Note:
1046 ========================================================================
1047 */
1048 BOOLEAN RT28XXProbePostConfig(
1049         IN void                                 *_dev_p,
1050         IN RTMP_ADAPTER                 *pAd,
1051         IN INT32                                argc)
1052 {
1053         /* no use */
1054         return TRUE;
1055 }
1056
1057
1058 /*
1059 ========================================================================
1060 Routine Description:
1061     Disable DMA.
1062
1063 Arguments:
1064         *pAd                            the raxx interface data pointer
1065
1066 Return Value:
1067         None
1068
1069 Note:
1070 ========================================================================
1071 */
1072 VOID RT28XXDMADisable(
1073         IN RTMP_ADAPTER                 *pAd)
1074 {
1075         WPDMA_GLO_CFG_STRUC     GloCfg;
1076
1077
1078         RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1079         GloCfg.word &= 0xff0;
1080         GloCfg.field.EnTXWriteBackDDONE =1;
1081         RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1082 }
1083
1084
1085 /*
1086 ========================================================================
1087 Routine Description:
1088     Enable DMA.
1089
1090 Arguments:
1091         *pAd                            the raxx interface data pointer
1092
1093 Return Value:
1094         None
1095
1096 Note:
1097 ========================================================================
1098 */
1099 VOID RT28XXDMAEnable(
1100         IN RTMP_ADAPTER                 *pAd)
1101 {
1102         WPDMA_GLO_CFG_STRUC     GloCfg;
1103         int i = 0;
1104
1105         RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4);
1106         do
1107         {
1108                 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1109                 if ((GloCfg.field.TxDMABusy == 0)  && (GloCfg.field.RxDMABusy == 0))
1110                         break;
1111
1112                 DBGPRINT(RT_DEBUG_TRACE, ("==>  DMABusy\n"));
1113                 RTMPusecDelay(1000);
1114                 i++;
1115         }while ( i <200);
1116
1117         RTMPusecDelay(50);
1118
1119         GloCfg.field.EnTXWriteBackDDONE = 1;
1120         GloCfg.field.WPDMABurstSIZE = 2;
1121         GloCfg.field.EnableRxDMA = 1;
1122         GloCfg.field.EnableTxDMA = 1;
1123
1124         DBGPRINT(RT_DEBUG_TRACE, ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word));
1125         RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1126
1127 }
1128
1129 /*
1130 ========================================================================
1131 Routine Description:
1132     Write Beacon buffer to Asic.
1133
1134 Arguments:
1135         *pAd                            the raxx interface data pointer
1136
1137 Return Value:
1138         None
1139
1140 Note:
1141 ========================================================================
1142 */
1143 VOID RT28xx_UpdateBeaconToAsic(
1144         IN RTMP_ADAPTER         *pAd,
1145         IN INT                          apidx,
1146         IN ULONG                        FrameLen,
1147         IN ULONG                        UpdatePos)
1148 {
1149         ULONG                           CapInfoPos = 0;
1150         UCHAR                   *ptr, *ptr_update, *ptr_capinfo;
1151         UINT                    i;
1152         BOOLEAN                 bBcnReq = FALSE;
1153         UCHAR                   bcn_idx = 0;
1154
1155         {
1156                 DBGPRINT(RT_DEBUG_ERROR, ("%s() : No valid Interface be found.\n", __func__));
1157                 return;
1158         }
1159
1160         if (bBcnReq == FALSE)
1161         {
1162                 /* when the ra interface is down, do not send its beacon frame */
1163                 /* clear all zero */
1164                 for(i=0; i<TXWI_SIZE; i+=4)
1165                         RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, 0x00);
1166         }
1167         else
1168         {
1169                 ptr = (PUCHAR)&pAd->BeaconTxWI;
1170 #ifdef RT_BIG_ENDIAN
1171                 RTMPWIEndianChange(ptr, TYPE_TXWI);
1172 #endif
1173                 for (i=0; i<TXWI_SIZE; i+=4)  // 16-byte TXWI field
1174                 {
1175                         UINT32 longptr =  *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24);
1176                         RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, longptr);
1177                         ptr += 4;
1178                 }
1179
1180                 // Update CapabilityInfo in Beacon
1181                 for (i = CapInfoPos; i < (CapInfoPos+2); i++)
1182                 {
1183                         RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, *ptr_capinfo);
1184                         ptr_capinfo ++;
1185                 }
1186
1187                 if (FrameLen > UpdatePos)
1188                 {
1189                         for (i= UpdatePos; i< (FrameLen); i++)
1190                         {
1191                                 RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, *ptr_update);
1192                                 ptr_update ++;
1193                         }
1194                 }
1195
1196         }
1197
1198 }
1199
1200 #ifdef CONFIG_STA_SUPPORT
1201 VOID RTMPInitPCIeLinkCtrlValue(
1202         IN      PRTMP_ADAPTER   pAd)
1203 {
1204 }
1205
1206 VOID RTMPFindHostPCIDev(
1207     IN  PRTMP_ADAPTER   pAd)
1208 {
1209 }
1210
1211 /*
1212         ========================================================================
1213
1214         Routine Description:
1215
1216         Arguments:
1217                 Level = RESTORE_HALT : Restore PCI host and Ralink PCIe Link Control field to its default value.
1218                 Level = Other Value : Restore from dot11 power save or radio off status. And force PCI host Link Control fields to 0x1
1219
1220         ========================================================================
1221 */
1222 VOID RTMPPCIeLinkCtrlValueRestore(
1223         IN      PRTMP_ADAPTER   pAd,
1224         IN   UCHAR              Level)
1225 {
1226 }
1227
1228 /*
1229         ========================================================================
1230
1231         Routine Description:
1232
1233         Arguments:
1234                 Max : limit Host PCI and Ralink PCIe device's LINK CONTROL field's value.
1235                 Because now frequently set our device to mode 1 or mode 3 will cause problem.
1236
1237         ========================================================================
1238 */
1239 VOID RTMPPCIeLinkCtrlSetting(
1240         IN      PRTMP_ADAPTER   pAd,
1241         IN      USHORT          Max)
1242 {
1243 }
1244 #endif // CONFIG_STA_SUPPORT //
1245
1246 VOID rt2860_stop(struct net_device *net_dev)
1247 {
1248     PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL;
1249     if (net_dev == NULL)
1250         {
1251                 DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n"));
1252         }
1253         else
1254                 pAd = net_dev->ml_priv;
1255
1256         if (pAd != NULL)
1257         {
1258             // stop interface
1259                 netif_carrier_off(net_dev);
1260                 netif_stop_queue(net_dev);
1261
1262                 // mark device as removed from system and therefore no longer available
1263                 netif_device_detach(net_dev);
1264
1265                 // mark halt flag
1266                 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
1267                 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1268
1269                 // take down the device
1270                 rt28xx_close((PNET_DEV)net_dev);
1271                 RT_MOD_DEC_USE_COUNT();
1272         }
1273     return;
1274 }
1275
1276 /*
1277  * invaild or writeback cache
1278  * and convert virtual address to physical address
1279  */
1280 dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction)
1281 {
1282         PRTMP_ADAPTER pAd;
1283         POS_COOKIE pObj;
1284
1285         /*
1286                 ------ Porting Information ------
1287                 > For Tx Alloc:
1288                         mgmt packets => sd_idx = 0
1289                         SwIdx: pAd->MgmtRing.TxCpuIdx
1290                         pTxD : pAd->MgmtRing.Cell[SwIdx].AllocVa;
1291
1292                         data packets => sd_idx = 1
1293                         TxIdx : pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx
1294                         QueIdx: pTxBlk->QueIdx
1295                         pTxD  : pAd->TxRing[pTxBlk->QueIdx].Cell[TxIdx].AllocVa;
1296
1297                 > For Rx Alloc:
1298                         sd_idx = -1
1299         */
1300
1301         pAd = (PRTMP_ADAPTER)handle;
1302         pObj = (POS_COOKIE)pAd->OS_Cookie;
1303
1304         if (sd_idx == 1)
1305         {
1306                 PTX_BLK         pTxBlk;
1307                 pTxBlk = (PTX_BLK)ptr;
1308                 return pci_map_single(pObj->pci_dev, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen, direction);
1309         }
1310         else
1311         {
1312                 return pci_map_single(pObj->pci_dev, ptr, size, direction);
1313         }
1314
1315 }
1316
1317 void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction)
1318 {
1319         PRTMP_ADAPTER pAd;
1320         POS_COOKIE pObj;
1321
1322         pAd=(PRTMP_ADAPTER)handle;
1323         pObj = (POS_COOKIE)pAd->OS_Cookie;
1324
1325         pci_unmap_single(pObj->pci_dev, dma_addr, size, direction);
1326
1327 }
1328