2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
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. *
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. *
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. *
25 *************************************************************************
31 Create and register network interface.
35 -------- ---------- ----------------------------------------------
38 #include "rt_config.h"
40 extern INT __devinit rt28xx_probe(IN void *_dev_p, IN void *_dev_id_p,
41 IN UINT argc, OUT PRTMP_ADAPTER *ppAd);
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);
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
66 #define INT_RX RT2860_INT_RX_DONE
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
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);
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 //
93 // Ralink PCI device table, include all supported chipsets
95 static struct pci_device_id rt2860_pci_tbl[] __devinitdata =
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
105 MODULE_DEVICE_TABLE(pci, rt2860_pci_tbl);
106 #ifdef CONFIG_STA_SUPPORT
107 MODULE_LICENSE("GPL");
108 #ifdef MODULE_VERSION
109 MODULE_VERSION(STA_DRIVER_VERSION);
111 #endif // CONFIG_STA_SUPPORT //
115 // Our PCI driver structure
117 static struct pci_driver rt2860_driver =
120 id_table: rt2860_pci_tbl,
121 probe: rt2860_init_one,
122 remove: __devexit_p(rt2860_remove_one),
125 suspend: rt2860_suspend,
126 resume: rt2860_resume,
133 VOID RT2860RejectPendingPackets(
134 IN PRTMP_ADAPTER pAd)
137 // clear TxSw packets
140 static int rt2860_suspend(
141 struct pci_dev *pci_dev,
144 struct net_device *net_dev = pci_get_drvdata(pci_dev);
145 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL;
149 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_suspend()\n"));
153 DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n"));
157 pAd = net_dev->ml_priv;
159 /* we can not use IFF_UP because ra0 down but ra1 up */
160 /* and 1 suspend/resume function for 1 module, not for each interface */
161 /* so Linux will call suspend/resume function once */
162 if (VIRTUAL_IF_NUM(pAd) > 0)
164 // avoid users do suspend after interface is down
167 netif_carrier_off(net_dev);
168 netif_stop_queue(net_dev);
170 // mark device as removed from system and therefore no longer available
171 netif_device_detach(net_dev);
174 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
175 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
177 // take down the device
178 rt28xx_close((PNET_DEV)net_dev);
180 RT_MOD_DEC_USE_COUNT();
184 // reference to http://vovo2000.com/type-lab/linux/kernel-api/linux-kernel-api.html
185 // enable device to generate PME# when suspended
186 // pci_choose_state(): Choose the power state of a PCI device to be suspended
187 retval = pci_enable_wake(pci_dev, pci_choose_state(pci_dev, state), 1);
188 // save the PCI configuration space of a device before suspending
189 pci_save_state(pci_dev);
190 // disable PCI device after use
191 pci_disable_device(pci_dev);
193 retval = pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
195 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_suspend()\n"));
199 static int rt2860_resume(
200 struct pci_dev *pci_dev)
202 struct net_device *net_dev = pci_get_drvdata(pci_dev);
203 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL;
207 // set the power state of a PCI device
208 // PCI has 4 power states, DO (normal) ~ D3(less power)
209 // in include/linux/pci.h, you can find that
210 // #define PCI_D0 ((pci_power_t __force) 0)
211 // #define PCI_D1 ((pci_power_t __force) 1)
212 // #define PCI_D2 ((pci_power_t __force) 2)
213 // #define PCI_D3hot ((pci_power_t __force) 3)
214 // #define PCI_D3cold ((pci_power_t __force) 4)
215 // #define PCI_UNKNOWN ((pci_power_t __force) 5)
216 // #define PCI_POWER_ERROR ((pci_power_t __force) -1)
217 retval = pci_set_power_state(pci_dev, PCI_D0);
219 // restore the saved state of a PCI device
220 pci_restore_state(pci_dev);
222 // initialize device before it's used by a driver
223 if (pci_enable_device(pci_dev))
225 printk("pci enable fail!\n");
229 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_resume()\n"));
233 DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n"));
236 pAd = net_dev->ml_priv;
240 /* we can not use IFF_UP because ra0 down but ra1 up */
241 /* and 1 suspend/resume function for 1 module, not for each interface */
242 /* so Linux will call suspend/resume function once */
243 if (VIRTUAL_IF_NUM(pAd) > 0)
245 // mark device as attached from system and restart if needed
246 netif_device_attach(net_dev);
248 if (rt28xx_open((PNET_DEV)net_dev) != 0)
251 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_resume()\n"));
255 // increase MODULE use count
256 RT_MOD_INC_USE_COUNT();
258 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
259 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
261 netif_start_queue(net_dev);
262 netif_carrier_on(net_dev);
263 netif_wake_queue(net_dev);
267 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_resume()\n"));
270 #endif // CONFIG_PM //
273 static INT __init rt2860_init_module(VOID)
275 return pci_register_driver(&rt2860_driver);
280 // Driver module unload function
282 static VOID __exit rt2860_cleanup_module(VOID)
284 pci_unregister_driver(&rt2860_driver);
287 module_init(rt2860_init_module);
288 module_exit(rt2860_cleanup_module);
291 static INT __devinit rt2860_init_one (
292 IN struct pci_dev *pci_dev,
293 IN const struct pci_device_id *ent)
297 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_init_one\n"));
299 // wake up and enable device
300 if (pci_enable_device (pci_dev))
306 rc = rt2860_probe(pci_dev, ent);
309 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_init_one\n"));
314 static VOID __devexit rt2860_remove_one(
315 IN struct pci_dev *pci_dev)
317 struct net_device *net_dev = pci_get_drvdata(pci_dev);
318 RTMP_ADAPTER *pAd = net_dev->ml_priv;
320 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_remove_one\n"));
324 // Unregister network device
325 unregister_netdev(net_dev);
327 // Unmap CSR base address
328 iounmap((char *)(net_dev->base_addr));
330 RTMPFreeAdapter(pAd);
332 // release memory region
333 release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0));
337 // Unregister network device
338 unregister_netdev(net_dev);
340 // Unmap CSR base address
341 iounmap((char *)(net_dev->base_addr));
343 // release memory region
344 release_mem_region(pci_resource_start(pci_dev, 0), pci_resource_len(pci_dev, 0));
347 // Free pre-allocated net_device memory
348 free_netdev(net_dev);
352 // PCI device probe & initialization function
354 static INT __devinit rt2860_probe(
355 IN struct pci_dev *pci_dev,
356 IN const struct pci_device_id *ent)
361 rv = (INT)rt28xx_probe((void *)pci_dev, (void *)ent, 0, &pAd);
362 OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE);
367 void init_thread_task(IN PRTMP_ADAPTER pAd)
371 pObj = (POS_COOKIE) pAd->OS_Cookie;
373 tasklet_init(&pObj->rx_done_task, rx_done_tasklet, (unsigned long)pAd);
374 tasklet_init(&pObj->mgmt_dma_done_task, mgmt_dma_done_tasklet, (unsigned long)pAd);
375 tasklet_init(&pObj->ac0_dma_done_task, ac0_dma_done_tasklet, (unsigned long)pAd);
376 tasklet_init(&pObj->ac1_dma_done_task, ac1_dma_done_tasklet, (unsigned long)pAd);
377 tasklet_init(&pObj->ac2_dma_done_task, ac2_dma_done_tasklet, (unsigned long)pAd);
378 tasklet_init(&pObj->ac3_dma_done_task, ac3_dma_done_tasklet, (unsigned long)pAd);
379 tasklet_init(&pObj->hcca_dma_done_task, hcca_dma_done_tasklet, (unsigned long)pAd);
380 tasklet_init(&pObj->tbtt_task, tbtt_tasklet, (unsigned long)pAd);
381 tasklet_init(&pObj->fifo_statistic_full_task, fifo_statistic_full_tasklet, (unsigned long)pAd);
384 void kill_thread_task(IN PRTMP_ADAPTER pAd)
388 pObj = (POS_COOKIE) pAd->OS_Cookie;
390 tasklet_kill(&pObj->rx_done_task);
391 tasklet_kill(&pObj->mgmt_dma_done_task);
392 tasklet_kill(&pObj->ac0_dma_done_task);
393 tasklet_kill(&pObj->ac1_dma_done_task);
394 tasklet_kill(&pObj->ac2_dma_done_task);
395 tasklet_kill(&pObj->ac3_dma_done_task);
396 tasklet_kill(&pObj->hcca_dma_done_task);
397 tasklet_kill(&pObj->tbtt_task);
398 tasklet_kill(&pObj->fifo_statistic_full_task);
402 static void rt2860_int_enable(PRTMP_ADAPTER pAd, unsigned int mode)
406 pAd->int_disable_mask &= ~(mode);
407 regValue = pAd->int_enable_reg & ~(pAd->int_disable_mask);
408 RTMP_IO_WRITE32(pAd, INT_MASK_CSR, regValue); // 1:enable
411 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE);
415 static void rt2860_int_disable(PRTMP_ADAPTER pAd, unsigned int mode)
419 pAd->int_disable_mask |= mode;
420 regValue = pAd->int_enable_reg & ~(pAd->int_disable_mask);
421 RTMP_IO_WRITE32(pAd, INT_MASK_CSR, regValue); // 0: disable
425 RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE);
429 static void mgmt_dma_done_tasklet(unsigned long data)
432 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
433 INT_SOURCE_CSR_STRUC IntSource;
436 // Do nothing if the driver is starting halt state.
437 // This might happen when timer already been fired before cancel timer with mlmehalt
438 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
441 pObj = (POS_COOKIE) pAd->OS_Cookie;
444 IntSource.field.MgmtDmaDone = 1;
445 pAd->int_pending &= ~INT_MGMT_DLY;
447 RTMPHandleMgmtRingDmaDoneInterrupt(pAd);
449 // if you use RTMP_SEM_LOCK, sometimes kernel will hang up, no any
451 RTMP_INT_LOCK(&pAd->irq_lock, flags);
453 * double check to avoid lose of interrupts
455 if (pAd->int_pending & INT_MGMT_DLY)
457 tasklet_hi_schedule(&pObj->mgmt_dma_done_task);
458 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
462 /* enable TxDataInt again */
463 rt2860_int_enable(pAd, INT_MGMT_DLY);
464 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
467 static void rx_done_tasklet(unsigned long data)
470 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
471 BOOLEAN bReschedule = 0;
474 // Do nothing if the driver is starting halt state.
475 // This might happen when timer already been fired before cancel timer with mlmehalt
476 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
479 pObj = (POS_COOKIE) pAd->OS_Cookie;
481 pAd->int_pending &= ~(INT_RX);
482 #ifdef CONFIG_STA_SUPPORT
483 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
484 bReschedule = STARxDoneInterruptHandle(pAd, 0);
485 #endif // CONFIG_STA_SUPPORT //
487 RTMP_INT_LOCK(&pAd->irq_lock, flags);
489 * double check to avoid rotting packet
491 if (pAd->int_pending & INT_RX || bReschedule)
493 tasklet_hi_schedule(&pObj->rx_done_task);
494 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
498 /* enable RxINT again */
499 rt2860_int_enable(pAd, INT_RX);
500 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
504 void fifo_statistic_full_tasklet(unsigned long data)
507 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
510 // Do nothing if the driver is starting halt state.
511 // This might happen when timer already been fired before cancel timer with mlmehalt
512 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
515 pObj = (POS_COOKIE) pAd->OS_Cookie;
517 pAd->int_pending &= ~(FifoStaFullInt);
518 NICUpdateFifoStaCounters(pAd);
520 RTMP_INT_LOCK(&pAd->irq_lock, flags);
522 * double check to avoid rotting packet
524 if (pAd->int_pending & FifoStaFullInt)
526 tasklet_hi_schedule(&pObj->fifo_statistic_full_task);
527 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
531 /* enable RxINT again */
533 rt2860_int_enable(pAd, FifoStaFullInt);
534 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
538 static void hcca_dma_done_tasklet(unsigned long data)
541 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
542 INT_SOURCE_CSR_STRUC IntSource;
545 // Do nothing if the driver is starting halt state.
546 // This might happen when timer already been fired before cancel timer with mlmehalt
547 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
550 pObj = (POS_COOKIE) pAd->OS_Cookie;
554 IntSource.field.HccaDmaDone = 1;
555 pAd->int_pending &= ~INT_HCCA_DLY;
557 RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
559 RTMP_INT_LOCK(&pAd->irq_lock, flags);
561 * double check to avoid lose of interrupts
563 if (pAd->int_pending & INT_HCCA_DLY)
565 tasklet_hi_schedule(&pObj->hcca_dma_done_task);
566 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
570 /* enable TxDataInt again */
571 rt2860_int_enable(pAd, INT_HCCA_DLY);
572 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
575 static void ac3_dma_done_tasklet(unsigned long data)
578 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
579 INT_SOURCE_CSR_STRUC IntSource;
581 BOOLEAN bReschedule = 0;
583 // Do nothing if the driver is starting halt state.
584 // This might happen when timer already been fired before cancel timer with mlmehalt
585 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
588 pObj = (POS_COOKIE) pAd->OS_Cookie;
591 IntSource.field.Ac3DmaDone = 1;
592 pAd->int_pending &= ~INT_AC3_DLY;
594 bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
596 RTMP_INT_LOCK(&pAd->irq_lock, flags);
598 * double check to avoid lose of interrupts
600 if ((pAd->int_pending & INT_AC3_DLY) || bReschedule)
602 tasklet_hi_schedule(&pObj->ac3_dma_done_task);
603 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
607 /* enable TxDataInt again */
608 rt2860_int_enable(pAd, INT_AC3_DLY);
609 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
612 static void ac2_dma_done_tasklet(unsigned long data)
615 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
616 INT_SOURCE_CSR_STRUC IntSource;
618 BOOLEAN bReschedule = 0;
620 // Do nothing if the driver is starting halt state.
621 // This might happen when timer already been fired before cancel timer with mlmehalt
622 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
625 pObj = (POS_COOKIE) pAd->OS_Cookie;
628 IntSource.field.Ac2DmaDone = 1;
629 pAd->int_pending &= ~INT_AC2_DLY;
631 bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
633 RTMP_INT_LOCK(&pAd->irq_lock, flags);
636 * double check to avoid lose of interrupts
638 if ((pAd->int_pending & INT_AC2_DLY) || bReschedule)
640 tasklet_hi_schedule(&pObj->ac2_dma_done_task);
641 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
645 /* enable TxDataInt again */
646 rt2860_int_enable(pAd, INT_AC2_DLY);
647 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
650 static void ac1_dma_done_tasklet(unsigned long data)
653 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
654 INT_SOURCE_CSR_STRUC IntSource;
656 BOOLEAN bReschedule = 0;
658 // Do nothing if the driver is starting halt state.
659 // This might happen when timer already been fired before cancel timer with mlmehalt
660 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
663 pObj = (POS_COOKIE) pAd->OS_Cookie;
666 IntSource.field.Ac1DmaDone = 1;
667 pAd->int_pending &= ~INT_AC1_DLY;
669 bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
671 RTMP_INT_LOCK(&pAd->irq_lock, flags);
673 * double check to avoid lose of interrupts
675 if ((pAd->int_pending & INT_AC1_DLY) || bReschedule)
677 tasklet_hi_schedule(&pObj->ac1_dma_done_task);
678 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
682 /* enable TxDataInt again */
683 rt2860_int_enable(pAd, INT_AC1_DLY);
684 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
687 static void ac0_dma_done_tasklet(unsigned long data)
690 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER) data;
691 INT_SOURCE_CSR_STRUC IntSource;
693 BOOLEAN bReschedule = 0;
695 // Do nothing if the driver is starting halt state.
696 // This might happen when timer already been fired before cancel timer with mlmehalt
697 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST))
700 pObj = (POS_COOKIE) pAd->OS_Cookie;
703 IntSource.field.Ac0DmaDone = 1;
704 pAd->int_pending &= ~INT_AC0_DLY;
706 bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource);
708 RTMP_INT_LOCK(&pAd->irq_lock, flags);
710 * double check to avoid lose of interrupts
712 if ((pAd->int_pending & INT_AC0_DLY) || bReschedule)
714 tasklet_hi_schedule(&pObj->ac0_dma_done_task);
715 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
719 /* enable TxDataInt again */
720 rt2860_int_enable(pAd, INT_AC0_DLY);
721 RTMP_INT_UNLOCK(&pAd->irq_lock, flags);
728 rt2860_interrupt(int irq, void *dev_instance)
730 struct net_device *net_dev = (struct net_device *) dev_instance;
731 PRTMP_ADAPTER pAd = net_dev->ml_priv;
732 INT_SOURCE_CSR_STRUC IntSource;
736 pObj = (POS_COOKIE) pAd->OS_Cookie;
739 /* Note 03312008: we can not return here before
740 RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IntSource.word);
741 RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, IntSource.word);
742 Or kernel will panic after ifconfig ra0 down sometimes */
746 // Inital the Interrupt source.
748 IntSource.word = 0x00000000L;
749 // McuIntSource.word = 0x00000000L;
752 // Get the interrupt sources & saved to local variable
754 //RTMP_IO_READ32(pAd, where, &McuIntSource.word);
755 //RTMP_IO_WRITE32(pAd, , McuIntSource.word);
758 // Flag fOP_STATUS_DOZE On, means ASIC put to sleep, elase means ASICK WakeUp
759 // And at the same time, clock maybe turned off that say there is no DMA service.
760 // when ASIC get to sleep.
761 // To prevent system hang on power saving.
762 // We need to check it before handle the INT_SOURCE_CSR, ASIC must be wake up.
764 // RT2661 => when ASIC is sleeping, MAC register cannot be read and written.
765 // RT2860 => when ASIC is sleeping, MAC register can be read and written.
767 bOldValue = pAd->bPCIclkOff;
768 pAd->bPCIclkOff = FALSE;
770 RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IntSource.word);
771 RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, IntSource.word); // write 1 to clear
773 pAd->bPCIclkOff = bOldValue;
775 // Do nothing if Reset in progress
776 if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) ||
777 RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))
783 // Handle interrupt, walk through all bits
784 // Should start from highest priority interrupt
785 // The priority can be adjust by altering processing if statement
788 // If required spinlock, each interrupt service routine has to acquire
789 // and release itself.
792 // Do nothing if NIC doesn't exist
793 if (IntSource.word == 0xffffffff)
795 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS);
796 printk("snowpin - IntSource.word == 0xffffffff\n");
800 if (IntSource.word & TxCoherent)
802 DBGPRINT(RT_DEBUG_ERROR, (">>>TxCoherent<<<\n"));
803 RTMPHandleRxCoherentInterrupt(pAd);
806 if (IntSource.word & RxCoherent)
808 DBGPRINT(RT_DEBUG_ERROR, (">>>RxCoherent<<<\n"));
809 RTMPHandleRxCoherentInterrupt(pAd);
812 if (IntSource.word & FifoStaFullInt)
815 if ((pAd->int_disable_mask & FifoStaFullInt) == 0)
817 /* mask FifoStaFullInt */
818 rt2860_int_disable(pAd, FifoStaFullInt);
819 tasklet_hi_schedule(&pObj->fifo_statistic_full_task);
821 pAd->int_pending |= FifoStaFullInt;
823 NICUpdateFifoStaCounters(pAd);
827 if (IntSource.word & INT_MGMT_DLY)
829 if ((pAd->int_disable_mask & INT_MGMT_DLY) ==0 )
831 rt2860_int_disable(pAd, INT_MGMT_DLY);
832 tasklet_hi_schedule(&pObj->mgmt_dma_done_task);
834 pAd->int_pending |= INT_MGMT_DLY ;
837 if (IntSource.word & INT_RX)
839 if ((pAd->int_disable_mask & INT_RX) == 0)
842 rt2860_int_disable(pAd, INT_RX);
843 tasklet_hi_schedule(&pObj->rx_done_task);
845 pAd->int_pending |= INT_RX;
848 if (IntSource.word & INT_HCCA_DLY)
851 if ((pAd->int_disable_mask & INT_HCCA_DLY) == 0)
854 rt2860_int_disable(pAd, INT_HCCA_DLY);
855 tasklet_hi_schedule(&pObj->hcca_dma_done_task);
857 pAd->int_pending |= INT_HCCA_DLY;
860 if (IntSource.word & INT_AC3_DLY)
863 if ((pAd->int_disable_mask & INT_AC3_DLY) == 0)
866 rt2860_int_disable(pAd, INT_AC3_DLY);
867 tasklet_hi_schedule(&pObj->ac3_dma_done_task);
869 pAd->int_pending |= INT_AC3_DLY;
872 if (IntSource.word & INT_AC2_DLY)
875 if ((pAd->int_disable_mask & INT_AC2_DLY) == 0)
878 rt2860_int_disable(pAd, INT_AC2_DLY);
879 tasklet_hi_schedule(&pObj->ac2_dma_done_task);
881 pAd->int_pending |= INT_AC2_DLY;
884 if (IntSource.word & INT_AC1_DLY)
887 pAd->int_pending |= INT_AC1_DLY;
889 if ((pAd->int_disable_mask & INT_AC1_DLY) == 0)
892 rt2860_int_disable(pAd, INT_AC1_DLY);
893 tasklet_hi_schedule(&pObj->ac1_dma_done_task);
898 if (IntSource.word & INT_AC0_DLY)
900 pAd->int_pending |= INT_AC0_DLY;
902 if ((pAd->int_disable_mask & INT_AC0_DLY) == 0)
905 rt2860_int_disable(pAd, INT_AC0_DLY);
906 tasklet_hi_schedule(&pObj->ac0_dma_done_task);
911 if (IntSource.word & PreTBTTInt)
913 RTMPHandlePreTBTTInterrupt(pAd);
916 if (IntSource.word & TBTTInt)
918 RTMPHandleTBTTInterrupt(pAd);
923 #ifdef CONFIG_STA_SUPPORT
924 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
926 if (IntSource.word & AutoWakeupInt)
927 RTMPHandleTwakeupInterrupt(pAd);
929 #endif // CONFIG_STA_SUPPORT //
935 ========================================================================
937 Check the chipset vendor/product ID.
940 _dev_p Point to the PCI or USB device
947 ========================================================================
949 BOOLEAN RT28XXChipsetCheck(
958 ========================================================================
960 Init net device structure.
963 _dev_p Point to the PCI or USB device
964 *net_dev Point to the net device
965 *pAd the raxx interface data pointer
972 ========================================================================
974 BOOLEAN RT28XXNetDevInit(
976 IN struct net_device *net_dev,
977 IN RTMP_ADAPTER *pAd)
979 struct pci_dev *pci_dev = (struct pci_dev *)_dev_p;
980 const CHAR *print_name;
984 print_name = pci_dev ? pci_name(pci_dev) : "rt2860";
986 net_dev->base_addr = 0;
989 if (pci_request_regions(pci_dev, print_name))
990 goto err_out_free_netdev;
992 // interrupt IRQ number
993 net_dev->irq = pci_dev->irq;
995 // map physical address to virtual address for accessing register
996 csr_addr = (unsigned long) ioremap(pci_resource_start(pci_dev, 0),
997 pci_resource_len(pci_dev, 0));
1001 DBGPRINT(RT_DEBUG_ERROR,
1002 ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n",
1003 print_name, (ULONG)pci_resource_len(pci_dev, 0),
1004 (ULONG)pci_resource_start(pci_dev, 0)));
1005 goto err_out_free_res;
1008 // Save CSR virtual address and irq to device structure
1009 net_dev->base_addr = csr_addr;
1010 pAd->CSRBaseAddress = (PUCHAR)net_dev->base_addr;
1013 pci_set_master(pci_dev);
1015 net_dev->priv_flags = INT_MAIN;
1017 DBGPRINT(RT_DEBUG_TRACE, ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n",
1018 net_dev->name, (ULONG)pci_resource_start(pci_dev, 0),
1019 (ULONG)csr_addr, pci_dev->irq));
1023 /* --------------------------- ERROR HANDLE --------------------------- */
1025 pci_release_regions(pci_dev);
1026 err_out_free_netdev:
1027 /* free netdev in caller, not here */
1033 ========================================================================
1034 Routine Description:
1035 Init net device structure.
1038 _dev_p Point to the PCI or USB device
1039 *pAd the raxx interface data pointer
1046 ========================================================================
1048 BOOLEAN RT28XXProbePostConfig(
1050 IN RTMP_ADAPTER *pAd,
1059 ========================================================================
1060 Routine Description:
1064 *pAd the raxx interface data pointer
1070 ========================================================================
1072 VOID RT28XXDMADisable(
1073 IN RTMP_ADAPTER *pAd)
1075 WPDMA_GLO_CFG_STRUC GloCfg;
1078 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1079 GloCfg.word &= 0xff0;
1080 GloCfg.field.EnTXWriteBackDDONE =1;
1081 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1086 ========================================================================
1087 Routine Description:
1091 *pAd the raxx interface data pointer
1097 ========================================================================
1099 VOID RT28XXDMAEnable(
1100 IN RTMP_ADAPTER *pAd)
1102 WPDMA_GLO_CFG_STRUC GloCfg;
1105 RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4);
1108 RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word);
1109 if ((GloCfg.field.TxDMABusy == 0) && (GloCfg.field.RxDMABusy == 0))
1112 DBGPRINT(RT_DEBUG_TRACE, ("==> DMABusy\n"));
1113 RTMPusecDelay(1000);
1119 GloCfg.field.EnTXWriteBackDDONE = 1;
1120 GloCfg.field.WPDMABurstSIZE = 2;
1121 GloCfg.field.EnableRxDMA = 1;
1122 GloCfg.field.EnableTxDMA = 1;
1124 DBGPRINT(RT_DEBUG_TRACE, ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word));
1125 RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word);
1130 ========================================================================
1131 Routine Description:
1132 Write Beacon buffer to Asic.
1135 *pAd the raxx interface data pointer
1141 ========================================================================
1143 VOID RT28xx_UpdateBeaconToAsic(
1144 IN RTMP_ADAPTER *pAd,
1149 ULONG CapInfoPos = 0;
1150 UCHAR *ptr, *ptr_update, *ptr_capinfo;
1152 BOOLEAN bBcnReq = FALSE;
1156 DBGPRINT(RT_DEBUG_ERROR, ("%s() : No valid Interface be found.\n", __func__));
1160 if (bBcnReq == FALSE)
1162 /* when the ra interface is down, do not send its beacon frame */
1163 /* clear all zero */
1164 for(i=0; i<TXWI_SIZE; i+=4)
1165 RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, 0x00);
1169 ptr = (PUCHAR)&pAd->BeaconTxWI;
1170 #ifdef RT_BIG_ENDIAN
1171 RTMPWIEndianChange(ptr, TYPE_TXWI);
1173 for (i=0; i<TXWI_SIZE; i+=4) // 16-byte TXWI field
1175 UINT32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24);
1176 RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, longptr);
1180 // Update CapabilityInfo in Beacon
1181 for (i = CapInfoPos; i < (CapInfoPos+2); i++)
1183 RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, *ptr_capinfo);
1187 if (FrameLen > UpdatePos)
1189 for (i= UpdatePos; i< (FrameLen); i++)
1191 RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, *ptr_update);
1200 #ifdef CONFIG_STA_SUPPORT
1201 VOID RTMPInitPCIeLinkCtrlValue(
1202 IN PRTMP_ADAPTER pAd)
1206 VOID RTMPFindHostPCIDev(
1207 IN PRTMP_ADAPTER pAd)
1212 ========================================================================
1214 Routine Description:
1217 Level = RESTORE_HALT : Restore PCI host and Ralink PCIe Link Control field to its default value.
1218 Level = Other Value : Restore from dot11 power save or radio off status. And force PCI host Link Control fields to 0x1
1220 ========================================================================
1222 VOID RTMPPCIeLinkCtrlValueRestore(
1223 IN PRTMP_ADAPTER pAd,
1229 ========================================================================
1231 Routine Description:
1234 Max : limit Host PCI and Ralink PCIe device's LINK CONTROL field's value.
1235 Because now frequently set our device to mode 1 or mode 3 will cause problem.
1237 ========================================================================
1239 VOID RTMPPCIeLinkCtrlSetting(
1240 IN PRTMP_ADAPTER pAd,
1244 #endif // CONFIG_STA_SUPPORT //
1246 VOID rt2860_stop(struct net_device *net_dev)
1248 PRTMP_ADAPTER pAd = (PRTMP_ADAPTER)NULL;
1249 if (net_dev == NULL)
1251 DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n"));
1254 pAd = net_dev->ml_priv;
1259 netif_carrier_off(net_dev);
1260 netif_stop_queue(net_dev);
1262 // mark device as removed from system and therefore no longer available
1263 netif_device_detach(net_dev);
1266 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
1267 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF);
1269 // take down the device
1270 rt28xx_close((PNET_DEV)net_dev);
1271 RT_MOD_DEC_USE_COUNT();
1277 * invaild or writeback cache
1278 * and convert virtual address to physical address
1280 dma_addr_t linux_pci_map_single(void *handle, void *ptr, size_t size, int sd_idx, int direction)
1286 ------ Porting Information ------
1288 mgmt packets => sd_idx = 0
1289 SwIdx: pAd->MgmtRing.TxCpuIdx
1290 pTxD : pAd->MgmtRing.Cell[SwIdx].AllocVa;
1292 data packets => sd_idx = 1
1293 TxIdx : pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx
1294 QueIdx: pTxBlk->QueIdx
1295 pTxD : pAd->TxRing[pTxBlk->QueIdx].Cell[TxIdx].AllocVa;
1301 pAd = (PRTMP_ADAPTER)handle;
1302 pObj = (POS_COOKIE)pAd->OS_Cookie;
1307 pTxBlk = (PTX_BLK)ptr;
1308 return pci_map_single(pObj->pci_dev, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen, direction);
1312 return pci_map_single(pObj->pci_dev, ptr, size, direction);
1317 void linux_pci_unmap_single(void *handle, dma_addr_t dma_addr, size_t size, int direction)
1322 pAd=(PRTMP_ADAPTER)handle;
1323 pObj = (POS_COOKIE)pAd->OS_Cookie;
1325 pci_unmap_single(pObj->pci_dev, dma_addr, size, direction);