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