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