Merge branch 'for-2.6.31' of git://git.linux-nfs.org/projects/trondmy/nfs-2.6
[pandora-kernel.git] / 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         bReschedule = STARxDoneInterruptHandle(pAd, 0);
481
482         RTMP_INT_LOCK(&pAd->irq_lock, flags);
483         /*
484          * double check to avoid rotting packet
485          */
486         if (pAd->int_pending & INT_RX || bReschedule)
487         {
488                 tasklet_hi_schedule(&pObj->rx_done_task);
489                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
490                 return;
491         }
492
493         /* enable RxINT again */
494         rt2860_int_enable(pAd, INT_RX);
495         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
496
497 }
498
499 void fifo_statistic_full_tasklet(unsigned long data)
500 {
501         unsigned long flags;
502         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
503         POS_COOKIE pObj;
504
505         // Do nothing if the driver is starting halt state.
506         // This might happen when timer already been fired before cancel timer with mlmehalt
507         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
508                 return;
509
510     pObj = (POS_COOKIE) pAd->OS_Cookie;
511
512         pAd->int_pending &= ~(FifoStaFullInt);
513         NICUpdateFifoStaCounters(pAd);
514
515         RTMP_INT_LOCK(&pAd->irq_lock, flags);
516         /*
517          * double check to avoid rotting packet
518          */
519         if (pAd->int_pending & FifoStaFullInt)
520         {
521                 tasklet_hi_schedule(&pObj->fifo_statistic_full_task);
522                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
523                 return;
524         }
525
526         /* enable RxINT again */
527
528         rt2860_int_enable(pAd, FifoStaFullInt);
529         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
530
531 }
532
533 static void hcca_dma_done_tasklet(unsigned long data)
534 {
535         unsigned long flags;
536         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
537     INT_SOURCE_CSR_STRUC        IntSource;
538         POS_COOKIE pObj;
539
540         // Do nothing if the driver is starting halt state.
541         // This might happen when timer already been fired before cancel timer with mlmehalt
542         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
543                 return;
544
545     pObj = (POS_COOKIE) pAd->OS_Cookie;
546
547
548         IntSource.word = 0;
549         IntSource.field.HccaDmaDone = 1;
550         pAd->int_pending &= ~INT_HCCA_DLY;
551
552         RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
553
554         RTMP_INT_LOCK(&pAd->irq_lock, flags);
555         /*
556          * double check to avoid lose of interrupts
557          */
558         if (pAd->int_pending & INT_HCCA_DLY)
559         {
560                 tasklet_hi_schedule(&pObj->hcca_dma_done_task);
561                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
562                 return;
563         }
564
565         /* enable TxDataInt again */
566         rt2860_int_enable(pAd, INT_HCCA_DLY);
567         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
568 }
569
570 static void ac3_dma_done_tasklet(unsigned long data)
571 {
572         unsigned long flags;
573         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
574     INT_SOURCE_CSR_STRUC        IntSource;
575         POS_COOKIE pObj;
576         BOOLEAN bReschedule = 0;
577
578         // Do nothing if the driver is starting halt state.
579         // This might happen when timer already been fired before cancel timer with mlmehalt
580         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
581                 return;
582
583     pObj = (POS_COOKIE) pAd->OS_Cookie;
584
585         IntSource.word = 0;
586         IntSource.field.Ac3DmaDone = 1;
587         pAd->int_pending &= ~INT_AC3_DLY;
588
589         bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
590
591         RTMP_INT_LOCK(&pAd->irq_lock, flags);
592         /*
593          * double check to avoid lose of interrupts
594          */
595         if ((pAd->int_pending & INT_AC3_DLY) || bReschedule)
596         {
597                 tasklet_hi_schedule(&pObj->ac3_dma_done_task);
598                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
599                 return;
600         }
601
602         /* enable TxDataInt again */
603         rt2860_int_enable(pAd, INT_AC3_DLY);
604         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
605 }
606
607 static void ac2_dma_done_tasklet(unsigned long data)
608 {
609         unsigned long flags;
610         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
611     INT_SOURCE_CSR_STRUC        IntSource;
612         POS_COOKIE pObj;
613         BOOLEAN bReschedule = 0;
614
615         // Do nothing if the driver is starting halt state.
616         // This might happen when timer already been fired before cancel timer with mlmehalt
617         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
618                 return;
619
620     pObj = (POS_COOKIE) pAd->OS_Cookie;
621
622         IntSource.word = 0;
623         IntSource.field.Ac2DmaDone = 1;
624         pAd->int_pending &= ~INT_AC2_DLY;
625
626         bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
627
628         RTMP_INT_LOCK(&pAd->irq_lock, flags);
629
630         /*
631          * double check to avoid lose of interrupts
632          */
633         if ((pAd->int_pending & INT_AC2_DLY) || bReschedule)
634         {
635                 tasklet_hi_schedule(&pObj->ac2_dma_done_task);
636                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
637                 return;
638         }
639
640         /* enable TxDataInt again */
641         rt2860_int_enable(pAd, INT_AC2_DLY);
642         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
643 }
644
645 static void ac1_dma_done_tasklet(unsigned long data)
646 {
647         unsigned long flags;
648         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
649     INT_SOURCE_CSR_STRUC        IntSource;
650         POS_COOKIE pObj;
651         BOOLEAN bReschedule = 0;
652
653         // Do nothing if the driver is starting halt state.
654         // This might happen when timer already been fired before cancel timer with mlmehalt
655         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
656                 return;
657
658     pObj = (POS_COOKIE) pAd->OS_Cookie;
659
660         IntSource.word = 0;
661         IntSource.field.Ac1DmaDone = 1;
662         pAd->int_pending &= ~INT_AC1_DLY;
663
664         bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
665
666         RTMP_INT_LOCK(&pAd->irq_lock, flags);
667         /*
668          * double check to avoid lose of interrupts
669          */
670         if ((pAd->int_pending & INT_AC1_DLY) || bReschedule)
671         {
672                 tasklet_hi_schedule(&pObj->ac1_dma_done_task);
673                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
674                 return;
675         }
676
677         /* enable TxDataInt again */
678         rt2860_int_enable(pAd, INT_AC1_DLY);
679         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
680 }
681
682 static void ac0_dma_done_tasklet(unsigned long data)
683 {
684         unsigned long flags;
685         PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
686     INT_SOURCE_CSR_STRUC        IntSource;
687         POS_COOKIE pObj;
688         BOOLEAN bReschedule = 0;
689
690         // Do nothing if the driver is starting halt state.
691         // This might happen when timer already been fired before cancel timer with mlmehalt
692         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
693                 return;
694
695     pObj = (POS_COOKIE) pAd->OS_Cookie;
696
697         IntSource.word = 0;
698         IntSource.field.Ac0DmaDone = 1;
699         pAd->int_pending &= ~INT_AC0_DLY;
700
701         bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
702
703         RTMP_INT_LOCK(&pAd->irq_lock, flags);
704         /*
705          * double check to avoid lose of interrupts
706          */
707         if ((pAd->int_pending & INT_AC0_DLY) || bReschedule)
708         {
709                 tasklet_hi_schedule(&pObj->ac0_dma_done_task);
710                 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
711                 return;
712         }
713
714         /* enable TxDataInt again */
715         rt2860_int_enable(pAd, INT_AC0_DLY);
716         RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
717 }
718
719
720 int print_int_count;
721
722 IRQ_HANDLE_TYPE
723 rt2860_interrupt(int irq, void *dev_instance)
724 {
725         struct net_device *net_dev = (struct net_device *) dev_instance;
726         PRTMP_ADAPTER pAd = net_dev->ml_priv;
727         INT_SOURCE_CSR_STRUC    IntSource;
728         POS_COOKIE pObj;
729         BOOLEAN bOldValue;
730
731         pObj = (POS_COOKIE) pAd->OS_Cookie;
732
733
734         /* Note 03312008: we can not return here before
735                 RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IntSource.word);
736                 RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, IntSource.word);
737                 Or kernel will panic after ifconfig ra0 down sometimes */
738
739
740         //
741         // Inital the Interrupt source.
742         //
743         IntSource.word = 0x00000000L;
744 //      McuIntSource.word = 0x00000000L;
745
746         //
747         // Get the interrupt sources & saved to local variable
748         //
749         //RTMP_IO_READ32(pAd, where, &McuIntSource.word);
750         //RTMP_IO_WRITE32(pAd, , McuIntSource.word);
751
752         //
753         // Flag fOP_STATUS_DOZE On, means ASIC put to sleep, elase means ASICK WakeUp
754         // And at the same time, clock maybe turned off that say there is no DMA service.
755         // when ASIC get to sleep.
756         // To prevent system hang on power saving.
757         // We need to check it before handle the INT_SOURCE_CSR, ASIC must be wake up.
758         //
759         // RT2661 => when ASIC is sleeping, MAC register cannot be read and written.
760         // RT2860 => when ASIC is sleeping, MAC register can be read and written.
761
762         bOldValue = pAd->bPCIclkOff;
763         pAd->bPCIclkOff = FALSE;
764         {
765                 RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IntSource.word);
766                 RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, IntSource.word); // write 1 to clear
767         }
768         pAd->bPCIclkOff = bOldValue;
769
770         // Do nothing if Reset in progress
771         if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
772                 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
773         {
774                 return IRQ_HANDLED;
775         }
776
777         //
778         // Handle interrupt, walk through all bits
779         // Should start from highest priority interrupt
780         // The priority can be adjust by altering processing if statement
781         //
782
783         // If required spinlock, each interrupt service routine has to acquire
784         // and release itself.
785         //
786
787         // Do nothing if NIC doesn't exist
788         if (IntSource.word == 0xffffffff)
789         {
790                 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS);
791                 printk("snowpin - IntSource.word == 0xffffffff\n");
792                 return IRQ_HANDLED;
793         }
794
795         if (IntSource.word & TxCoherent)
796         {
797                 DBGPRINT(RT_DEBUG_ERROR, (">>>TxCoherent<<<\n"));
798                 RTMPHandleRxCoherentInterrupt(pAd);
799         }
800
801         if (IntSource.word & RxCoherent)
802         {
803                 DBGPRINT(RT_DEBUG_ERROR, (">>>RxCoherent<<<\n"));
804                 RTMPHandleRxCoherentInterrupt(pAd);
805         }
806
807         if (IntSource.word & FifoStaFullInt)
808         {
809 #if 1
810                 if ((pAd->int_disable_mask & FifoStaFullInt) == 0)
811                 {
812                         /* mask FifoStaFullInt */
813                         rt2860_int_disable(pAd, FifoStaFullInt);
814                         tasklet_hi_schedule(&pObj->fifo_statistic_full_task);
815                 }
816                 pAd->int_pending |= FifoStaFullInt;
817 #else
818                 NICUpdateFifoStaCounters(pAd);
819 #endif
820         }
821
822         if (IntSource.word & INT_MGMT_DLY)
823         {
824                 if ((pAd->int_disable_mask & INT_MGMT_DLY) ==0 )
825                 {
826                         rt2860_int_disable(pAd, INT_MGMT_DLY);
827                         tasklet_hi_schedule(&pObj->mgmt_dma_done_task);
828                 }
829                 pAd->int_pending |= INT_MGMT_DLY ;
830         }
831
832         if (IntSource.word & INT_RX)
833         {
834                 if ((pAd->int_disable_mask & INT_RX) == 0)
835                 {
836                         /* mask RxINT */
837                         rt2860_int_disable(pAd, INT_RX);
838                         tasklet_hi_schedule(&pObj->rx_done_task);
839                 }
840                 pAd->int_pending |= INT_RX;
841         }
842
843         if (IntSource.word & INT_HCCA_DLY)
844         {
845
846                 if ((pAd->int_disable_mask & INT_HCCA_DLY) == 0)
847                 {
848                         /* mask TxDataInt */
849                         rt2860_int_disable(pAd, INT_HCCA_DLY);
850                         tasklet_hi_schedule(&pObj->hcca_dma_done_task);
851                 }
852                 pAd->int_pending |= INT_HCCA_DLY;
853         }
854
855         if (IntSource.word & INT_AC3_DLY)
856         {
857
858                 if ((pAd->int_disable_mask & INT_AC3_DLY) == 0)
859                 {
860                         /* mask TxDataInt */
861                         rt2860_int_disable(pAd, INT_AC3_DLY);
862                         tasklet_hi_schedule(&pObj->ac3_dma_done_task);
863                 }
864                 pAd->int_pending |= INT_AC3_DLY;
865         }
866
867         if (IntSource.word & INT_AC2_DLY)
868         {
869
870                 if ((pAd->int_disable_mask & INT_AC2_DLY) == 0)
871                 {
872                         /* mask TxDataInt */
873                         rt2860_int_disable(pAd, INT_AC2_DLY);
874                         tasklet_hi_schedule(&pObj->ac2_dma_done_task);
875                 }
876                 pAd->int_pending |= INT_AC2_DLY;
877         }
878
879         if (IntSource.word & INT_AC1_DLY)
880         {
881
882                 pAd->int_pending |= INT_AC1_DLY;
883
884                 if ((pAd->int_disable_mask & INT_AC1_DLY) == 0)
885                 {
886                         /* mask TxDataInt */
887                         rt2860_int_disable(pAd, INT_AC1_DLY);
888                         tasklet_hi_schedule(&pObj->ac1_dma_done_task);
889                 }
890
891         }
892
893         if (IntSource.word & INT_AC0_DLY)
894         {
895                 pAd->int_pending |= INT_AC0_DLY;
896
897                 if ((pAd->int_disable_mask & INT_AC0_DLY) == 0)
898                 {
899                         /* mask TxDataInt */
900                         rt2860_int_disable(pAd, INT_AC0_DLY);
901                         tasklet_hi_schedule(&pObj->ac0_dma_done_task);
902                 }
903
904         }
905
906     if (IntSource.word & PreTBTTInt)
907         {
908                 RTMPHandlePreTBTTInterrupt(pAd);
909         }
910
911         if (IntSource.word & TBTTInt)
912         {
913                 RTMPHandleTBTTInterrupt(pAd);
914         }
915
916         if (IntSource.word & AutoWakeupInt)
917                 RTMPHandleTwakeupInterrupt(pAd);
918
919     return  IRQ_HANDLED;
920 }
921
922 /*
923 ========================================================================
924 Routine Description:
925     Check the chipset vendor/product ID.
926
927 Arguments:
928     _dev_p                              Point to the PCI or USB device
929
930 Return Value:
931     TRUE                                Check ok
932         FALSE                           Check fail
933
934 Note:
935 ========================================================================
936 */
937 BOOLEAN RT28XXChipsetCheck(
938         IN void *_dev_p)
939 {
940         /* always TRUE */
941         return TRUE;
942 }
943
944
945 /*
946 ========================================================================
947 Routine Description:
948     Init net device structure.
949
950 Arguments:
951     _dev_p                              Point to the PCI or USB device
952     *net_dev                    Point to the net device
953         *pAd                            the raxx interface data pointer
954
955 Return Value:
956     TRUE                                Init ok
957         FALSE                           Init fail
958
959 Note:
960 ========================================================================
961 */
962 BOOLEAN RT28XXNetDevInit(
963         IN void                                 *_dev_p,
964         IN struct  net_device   *net_dev,
965         IN RTMP_ADAPTER                 *pAd)
966 {
967         struct pci_dev *pci_dev = (struct pci_dev *)_dev_p;
968     const CHAR  *print_name;
969     ULONG       csr_addr;
970
971
972         print_name = pci_dev ? pci_name(pci_dev) : "rt2860";
973
974         net_dev->base_addr = 0;
975         net_dev->irq = 0;
976
977     if (pci_request_regions(pci_dev, print_name))
978         goto err_out_free_netdev;
979
980     // interrupt IRQ number
981     net_dev->irq = pci_dev->irq;
982
983     // map physical address to virtual address for accessing register
984     csr_addr = (unsigned long) ioremap(pci_resource_start(pci_dev, 0),
985                                                                                 pci_resource_len(pci_dev, 0));
986
987     if (!csr_addr)
988     {
989         DBGPRINT(RT_DEBUG_ERROR,
990                                 ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n",
991                                 print_name, (ULONG)pci_resource_len(pci_dev, 0),
992                                 (ULONG)pci_resource_start(pci_dev, 0)));
993         goto err_out_free_res;
994     }
995
996     // Save CSR virtual address and irq to device structure
997     net_dev->base_addr = csr_addr;
998     pAd->CSRBaseAddress = (PUCHAR)net_dev->base_addr;
999
1000     // Set DMA master
1001     pci_set_master(pci_dev);
1002
1003     net_dev->priv_flags = INT_MAIN;
1004
1005     DBGPRINT(RT_DEBUG_TRACE, ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n",
1006                 net_dev->name, (ULONG)pci_resource_start(pci_dev, 0),
1007                         (ULONG)csr_addr, pci_dev->irq));
1008         return TRUE;
1009
1010
1011         /* --------------------------- ERROR HANDLE --------------------------- */
1012 err_out_free_res:
1013     pci_release_regions(pci_dev);
1014 err_out_free_netdev:
1015         /* free netdev in caller, not here */
1016         return FALSE;
1017 }
1018
1019
1020 /*
1021 ========================================================================
1022 Routine Description:
1023     Init net device structure.
1024
1025 Arguments:
1026     _dev_p                              Point to the PCI or USB device
1027         *pAd                            the raxx interface data pointer
1028
1029 Return Value:
1030     TRUE                                Config ok
1031         FALSE                           Config fail
1032
1033 Note:
1034 ========================================================================
1035 */
1036 BOOLEAN RT28XXProbePostConfig(
1037         IN void                                 *_dev_p,
1038         IN RTMP_ADAPTER                 *pAd,
1039         IN INT32                                argc)
1040 {
1041         /* no use */
1042         return TRUE;
1043 }
1044
1045
1046 /*
1047 ========================================================================
1048 Routine Description:
1049     Disable DMA.
1050
1051 Arguments:
1052         *pAd                            the raxx interface data pointer
1053
1054 Return Value:
1055         None
1056
1057 Note:
1058 ========================================================================
1059 */
1060 VOID RT28XXDMADisable(
1061         IN RTMP_ADAPTER                 *pAd)
1062 {
1063         WPDMA_GLO_CFG_STRUC     GloCfg;
1064
1065
1066         RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1067         GloCfg.word &= 0xff0;
1068         GloCfg.field.EnTXWriteBackDDONE =1;
1069         RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1070 }
1071
1072
1073 /*
1074 ========================================================================
1075 Routine Description:
1076     Enable DMA.
1077
1078 Arguments:
1079         *pAd                            the raxx interface data pointer
1080
1081 Return Value:
1082         None
1083
1084 Note:
1085 ========================================================================
1086 */
1087 VOID RT28XXDMAEnable(
1088         IN RTMP_ADAPTER                 *pAd)
1089 {
1090         WPDMA_GLO_CFG_STRUC     GloCfg;
1091         int i = 0;
1092
1093         RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4);
1094         do
1095         {
1096                 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1097                 if ((GloCfg.field.TxDMABusy == 0)  && (GloCfg.field.RxDMABusy == 0))
1098                         break;
1099
1100                 DBGPRINT(RT_DEBUG_TRACE, ("==>  DMABusy\n"));
1101                 RTMPusecDelay(1000);
1102                 i++;
1103         }while ( i <200);
1104
1105         RTMPusecDelay(50);
1106
1107         GloCfg.field.EnTXWriteBackDDONE = 1;
1108         GloCfg.field.WPDMABurstSIZE = 2;
1109         GloCfg.field.EnableRxDMA = 1;
1110         GloCfg.field.EnableTxDMA = 1;
1111
1112         DBGPRINT(RT_DEBUG_TRACE, ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word));
1113         RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1114
1115 }
1116
1117 /*
1118 ========================================================================
1119 Routine Description:
1120     Write Beacon buffer to Asic.
1121
1122 Arguments:
1123         *pAd                            the raxx interface data pointer
1124
1125 Return Value:
1126         None
1127
1128 Note:
1129 ========================================================================
1130 */
1131 VOID RT28xx_UpdateBeaconToAsic(
1132         IN RTMP_ADAPTER         *pAd,
1133         IN INT                          apidx,
1134         IN ULONG                        FrameLen,
1135         IN ULONG                        UpdatePos)
1136 {
1137         ULONG                           CapInfoPos = 0;
1138         UCHAR                   *ptr, *ptr_update, *ptr_capinfo;
1139         UINT                    i;
1140         BOOLEAN                 bBcnReq = FALSE;
1141         UCHAR                   bcn_idx = 0;
1142
1143         {
1144                 DBGPRINT(RT_DEBUG_ERROR, ("%s() : No valid Interface be found.\n", __func__));
1145                 return;
1146         }
1147
1148         if (bBcnReq == FALSE)
1149         {
1150                 /* when the ra interface is down, do not send its beacon frame */
1151                 /* clear all zero */
1152                 for(i=0; i<TXWI_SIZE; i+=4)
1153                         RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, 0x00);
1154         }
1155         else
1156         {
1157                 ptr = (PUCHAR)&pAd->BeaconTxWI;
1158
1159                 for (i=0; i<TXWI_SIZE; i+=4)  // 16-byte TXWI field
1160                 {
1161                         UINT32 longptr =  *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24);
1162                         RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, longptr);
1163                         ptr += 4;
1164                 }
1165
1166                 // Update CapabilityInfo in Beacon
1167                 for (i = CapInfoPos; i < (CapInfoPos+2); i++)
1168                 {
1169                         RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, *ptr_capinfo);
1170                         ptr_capinfo ++;
1171                 }
1172
1173                 if (FrameLen > UpdatePos)
1174                 {
1175                         for (i= UpdatePos; i< (FrameLen); i++)
1176                         {
1177                                 RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, *ptr_update);
1178                                 ptr_update ++;
1179                         }
1180                 }
1181
1182         }
1183
1184 }
1185
1186 VOID RTMPInitPCIeLinkCtrlValue(
1187         IN      PRTMP_ADAPTER   pAd)
1188 {
1189 }
1190
1191 VOID RTMPFindHostPCIDev(
1192     IN  PRTMP_ADAPTER   pAd)
1193 {
1194 }
1195
1196 /*
1197         ========================================================================
1198
1199         Routine Description:
1200
1201         Arguments:
1202                 Level = RESTORE_HALT : Restore PCI host and Ralink PCIe Link Control field to its default value.
1203                 Level = Other Value : Restore from dot11 power save or radio off status. And force PCI host Link Control fields to 0x1
1204
1205         ========================================================================
1206 */
1207 VOID RTMPPCIeLinkCtrlValueRestore(
1208         IN      PRTMP_ADAPTER   pAd,
1209         IN   UCHAR              Level)
1210 {
1211 }
1212
1213 /*
1214         ========================================================================
1215
1216         Routine Description:
1217
1218         Arguments:
1219                 Max : limit Host PCI and Ralink PCIe device's LINK CONTROL field's value.
1220                 Because now frequently set our device to mode 1 or mode 3 will cause problem.
1221
1222         ========================================================================
1223 */
1224 VOID RTMPPCIeLinkCtrlSetting(
1225         IN      PRTMP_ADAPTER   pAd,
1226         IN      USHORT          Max)
1227 {
1228 }
1229
1230 VOID rt2860_stop(struct net_device *net_dev)
1231 {
1232     PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL;
1233     if (net_dev == NULL)
1234         {
1235                 DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n"));
1236         }
1237         else
1238                 pAd = net_dev->ml_priv;
1239
1240         if (pAd != NULL)
1241         {
1242             // stop interface
1243                 netif_carrier_off(net_dev);
1244                 netif_stop_queue(net_dev);
1245
1246                 // mark device as removed from system and therefore no longer available
1247                 netif_device_detach(net_dev);
1248
1249                 // mark halt flag
1250                 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
1251                 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1252
1253                 // take down the device
1254                 rt28xx_close((PNET_DEV)net_dev);
1255                 RT_MOD_DEC_USE_COUNT();
1256         }
1257     return;
1258 }
1259
1260 /*
1261  * invaild or writeback cache
1262  * and convert virtual address to physical address
1263  */
1264 dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction)
1265 {
1266         PRTMP_ADAPTER pAd;
1267         POS_COOKIE pObj;
1268
1269         /*
1270                 ------ Porting Information ------
1271                 > For Tx Alloc:
1272                         mgmt packets => sd_idx = 0
1273                         SwIdx: pAd->MgmtRing.TxCpuIdx
1274                         pTxD : pAd->MgmtRing.Cell[SwIdx].AllocVa;
1275
1276                         data packets => sd_idx = 1
1277                         TxIdx : pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx
1278                         QueIdx: pTxBlk->QueIdx
1279                         pTxD  : pAd->TxRing[pTxBlk->QueIdx].Cell[TxIdx].AllocVa;
1280
1281                 > For Rx Alloc:
1282                         sd_idx = -1
1283         */
1284
1285         pAd = (PRTMP_ADAPTER)handle;
1286         pObj = (POS_COOKIE)pAd->OS_Cookie;
1287
1288         if (sd_idx == 1)
1289         {
1290                 PTX_BLK         pTxBlk;
1291                 pTxBlk = (PTX_BLK)ptr;
1292                 return pci_map_single(pObj->pci_dev, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen, direction);
1293         }
1294         else
1295         {
1296                 return pci_map_single(pObj->pci_dev, ptr, size, direction);
1297         }
1298
1299 }
1300
1301 void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction)
1302 {
1303         PRTMP_ADAPTER pAd;
1304         POS_COOKIE pObj;
1305
1306         pAd=(PRTMP_ADAPTER)handle;
1307         pObj = (POS_COOKIE)pAd->OS_Cookie;
1308
1309         pci_unmap_single(pObj->pci_dev, dma_addr, size, direction);
1310
1311 }
1312