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 *************************************************************************/
27 #include "rt_config.h"
30 // Following information will be show when you run 'modinfo'
31 // *** If you have a solution for the bug in current version of driver, please mail to me.
32 // Otherwise post to forum in ralinktech's web site(www.ralinktech.com) and let all users help you. ***
33 MODULE_AUTHOR("Paul Lin <paul_lin@ralinktech.com>");
34 MODULE_DESCRIPTION("RT2870/RT3070 Wireless Lan Linux Driver");
35 MODULE_LICENSE("GPL");
37 MODULE_VERSION(STA_DRIVER_VERSION);
42 struct usb_device_id rtusb_usb_id[] = {
44 {USB_DEVICE(0x148F,0x2770)}, /* Ralink */
45 {USB_DEVICE(0x148F,0x2870)}, /* Ralink */
46 {USB_DEVICE(0x07B8,0x2870)}, /* AboCom */
47 {USB_DEVICE(0x07B8,0x2770)}, /* AboCom */
48 {USB_DEVICE(0x0DF6,0x0039)}, /* Sitecom 2770 */
49 {USB_DEVICE(0x083A,0x7512)}, /* Arcadyan 2770 */
50 {USB_DEVICE(0x0789,0x0162)}, /* Logitec 2870 */
51 {USB_DEVICE(0x0789,0x0163)}, /* Logitec 2870 */
52 {USB_DEVICE(0x0789,0x0164)}, /* Logitec 2870 */
53 {USB_DEVICE(0x177f,0x0302)}, /* lsusb */
54 {USB_DEVICE(0x0B05,0x1731)}, /* Asus */
55 {USB_DEVICE(0x0B05,0x1732)}, /* Asus */
56 {USB_DEVICE(0x0B05,0x1742)}, /* Asus */
57 {USB_DEVICE(0x0DF6,0x0017)}, /* Sitecom */
58 {USB_DEVICE(0x0DF6,0x002B)}, /* Sitecom */
59 {USB_DEVICE(0x0DF6,0x002C)}, /* Sitecom */
60 {USB_DEVICE(0x0DF6,0x002D)}, /* Sitecom */
61 {USB_DEVICE(0x14B2,0x3C06)}, /* Conceptronic */
62 {USB_DEVICE(0x14B2,0x3C28)}, /* Conceptronic */
63 {USB_DEVICE(0x2019,0xED06)}, /* Planex Communications, Inc. */
64 {USB_DEVICE(0x07D1,0x3C09)}, /* D-Link */
65 {USB_DEVICE(0x07D1,0x3C11)}, /* D-Link */
66 {USB_DEVICE(0x14B2,0x3C07)}, /* AL */
67 {USB_DEVICE(0x050D,0x8053)}, /* Belkin */
68 {USB_DEVICE(0x14B2,0x3C23)}, /* Airlink */
69 {USB_DEVICE(0x14B2,0x3C27)}, /* Airlink */
70 {USB_DEVICE(0x07AA,0x002F)}, /* Corega */
71 {USB_DEVICE(0x07AA,0x003C)}, /* Corega */
72 {USB_DEVICE(0x07AA,0x003F)}, /* Corega */
73 {USB_DEVICE(0x1044,0x800B)}, /* Gigabyte */
74 {USB_DEVICE(0x15A9,0x0006)}, /* Sparklan */
75 {USB_DEVICE(0x083A,0xB522)}, /* SMC */
76 {USB_DEVICE(0x083A,0xA618)}, /* SMC */
77 {USB_DEVICE(0x083A,0x8522)}, /* Arcadyan */
78 {USB_DEVICE(0x083A,0x7522)}, /* Arcadyan */
79 {USB_DEVICE(0x0CDE,0x0022)}, /* ZCOM */
80 {USB_DEVICE(0x0586,0x3416)}, /* Zyxel */
81 {USB_DEVICE(0x0CDE,0x0025)}, /* Zyxel */
82 {USB_DEVICE(0x1740,0x9701)}, /* EnGenius */
83 {USB_DEVICE(0x1740,0x9702)}, /* EnGenius */
84 {USB_DEVICE(0x0471,0x200f)}, /* Philips */
85 {USB_DEVICE(0x14B2,0x3C25)}, /* Draytek */
86 {USB_DEVICE(0x13D3,0x3247)}, /* AzureWave */
87 {USB_DEVICE(0x083A,0x6618)}, /* Accton */
88 {USB_DEVICE(0x15c5,0x0008)}, /* Amit */
89 {USB_DEVICE(0x0E66,0x0001)}, /* Hawking */
90 {USB_DEVICE(0x0E66,0x0003)}, /* Hawking */
91 {USB_DEVICE(0x129B,0x1828)}, /* Siemens */
92 {USB_DEVICE(0x157E,0x300E)}, /* U-Media */
93 {USB_DEVICE(0x050d,0x805c)},
94 {USB_DEVICE(0x050d,0x815c)},
95 {USB_DEVICE(0x1482,0x3C09)}, /* Abocom*/
96 {USB_DEVICE(0x14B2,0x3C09)}, /* Alpha */
97 {USB_DEVICE(0x04E8,0x2018)}, /* samsung */
98 {USB_DEVICE(0x5A57,0x0280)}, /* Zinwell */
99 {USB_DEVICE(0x5A57,0x0282)}, /* Zinwell */
100 {USB_DEVICE(0x7392,0x7718)},
101 {USB_DEVICE(0x7392,0x7717)},
102 {USB_DEVICE(0x1737,0x0070)}, /* Linksys WUSB100 */
103 {USB_DEVICE(0x1737,0x0071)}, /* Linksys WUSB600N */
104 {USB_DEVICE(0x0411,0x00e8)}, /* Buffalo WLI-UC-G300N*/
105 {USB_DEVICE(0x050d,0x815c)}, /* Belkin F5D8053 */
108 {USB_DEVICE(0x148F,0x3070)}, /* Ralink 3070 */
109 {USB_DEVICE(0x148F,0x3071)}, /* Ralink 3071 */
110 {USB_DEVICE(0x148F,0x3072)}, /* Ralink 3072 */
111 {USB_DEVICE(0x0DB0,0x3820)}, /* Ralink 3070 */
112 {USB_DEVICE(0x0DF6,0x003E)}, /* Sitecom 3070 */
113 {USB_DEVICE(0x0DF6,0x0042)}, /* Sitecom 3072 */
114 {USB_DEVICE(0x14B2,0x3C12)}, /* AL 3070 */
115 {USB_DEVICE(0x18C5,0x0012)}, /* Corega 3070 */
116 {USB_DEVICE(0x083A,0x7511)}, /* Arcadyan 3070 */
117 {USB_DEVICE(0x1740,0x9703)}, /* EnGenius 3070 */
118 {USB_DEVICE(0x1740,0x9705)}, /* EnGenius 3071 */
119 {USB_DEVICE(0x1740,0x9706)}, /* EnGenius 3072 */
120 {USB_DEVICE(0x13D3,0x3273)}, /* AzureWave 3070*/
121 {USB_DEVICE(0x1044,0x800D)}, /* Gigabyte GN-WB32L 3070 */
122 {USB_DEVICE(0x2019,0xAB25)}, /* Planex Communications, Inc. RT3070 */
123 {USB_DEVICE(0x07B8,0x3070)}, /* AboCom 3070 */
124 {USB_DEVICE(0x07B8,0x3071)}, /* AboCom 3071 */
125 {USB_DEVICE(0x07B8,0x3072)}, /* Abocom 3072 */
126 {USB_DEVICE(0x7392,0x7711)}, /* Edimax 3070 */
127 {USB_DEVICE(0x1A32,0x0304)}, /* Quanta 3070 */
128 {USB_DEVICE(0x1EDA,0x2310)}, /* AirTies 3070 */
129 {USB_DEVICE(0x07D1,0x3C0A)}, /* D-Link 3072 */
130 {USB_DEVICE(0x07D1,0x3C0D)}, /* D-Link 3070 */
131 {USB_DEVICE(0x07D1,0x3C0E)}, /* D-Link 3070 */
132 {USB_DEVICE(0x07D1,0x3C0F)}, /* D-Link 3070 */
133 {USB_DEVICE(0x1D4D,0x000C)}, /* Pegatron Corporation 3070 */
134 {USB_DEVICE(0x1D4D,0x000E)}, /* Pegatron Corporation 3070 */
135 {USB_DEVICE(0x5A57,0x5257)}, /* Zinwell 3070 */
136 {USB_DEVICE(0x5A57,0x0283)}, /* Zinwell 3072 */
137 {USB_DEVICE(0x04BB,0x0945)}, /* I-O DATA 3072 */
138 {USB_DEVICE(0x203D,0x1480)}, /* Encore 3070 */
140 { USB_DEVICE(0x0DF6, 0x003F) }, /* Sitecom WL-608 */
141 { USB_DEVICE(0x1737, 0x0077) }, /* Linksys WUSB54GC-EU v3 */
142 { USB_DEVICE(0x2001, 0x3C09) }, /* D-Link */
143 { USB_DEVICE(0x2001, 0x3C0A) }, /* D-Link 3072*/
144 { USB_DEVICE(0x2019, 0xED14) }, /* Planex Communications, Inc. */
145 { }/* Terminating entry */
148 INT const rtusb_usb_id_len = sizeof(rtusb_usb_id) / sizeof(struct usb_device_id);
150 MODULE_DEVICE_TABLE(usb, rtusb_usb_id);
152 static void rt2870_disconnect(
153 IN struct usb_device *dev,
154 IN PRTMP_ADAPTER pAd);
156 static int __devinit rt2870_probe(
157 IN struct usb_interface *intf,
158 IN struct usb_device *usb_dev,
159 IN const struct usb_device_id *dev_id,
160 IN RTMP_ADAPTER **ppAd);
163 #define PF_NOFREEZE 0
167 extern int rt28xx_close(IN struct net_device *net_dev);
168 extern int rt28xx_open(struct net_device *net_dev);
170 static BOOLEAN USBDevConfigInit(
171 IN struct usb_device *dev,
172 IN struct usb_interface *intf,
173 IN RTMP_ADAPTER *pAd);
177 ========================================================================
179 Check the chipset vendor/product ID.
182 _dev_p Point to the PCI or USB device
189 ========================================================================
191 BOOLEAN RT28XXChipsetCheck(
194 struct usb_interface *intf = (struct usb_interface *)_dev_p;
195 struct usb_device *dev_p = interface_to_usbdev(intf);
199 for(i=0; i<rtusb_usb_id_len; i++)
201 if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor &&
202 dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct)
204 printk("rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
205 dev_p->descriptor.idVendor, dev_p->descriptor.idProduct);
210 if (i == rtusb_usb_id_len)
212 printk("rt2870: Error! Device Descriptor not matching!\n");
219 /**************************************************************************/
220 /**************************************************************************/
221 //tested for kernel 2.6series
222 /**************************************************************************/
223 /**************************************************************************/
226 static int rt2870_suspend(struct usb_interface *intf, pm_message_t state);
227 static int rt2870_resume(struct usb_interface *intf);
228 #endif // CONFIG_PM //
230 static int rtusb_probe (struct usb_interface *intf,
231 const struct usb_device_id *id);
232 static void rtusb_disconnect(struct usb_interface *intf);
234 static BOOLEAN USBDevConfigInit(
235 IN struct usb_device *dev,
236 IN struct usb_interface *intf,
237 IN RTMP_ADAPTER *pAd)
239 struct usb_host_interface *iface_desc;
244 /* get the active interface descriptor */
245 iface_desc = intf->cur_altsetting;
247 /* get # of enpoints */
248 pAd->NumberOfPipes = iface_desc->desc.bNumEndpoints;
249 DBGPRINT(RT_DEBUG_TRACE, ("NumEndpoints=%d\n", iface_desc->desc.bNumEndpoints));
251 /* Configure Pipes */
254 for(i=0; i<pAd->NumberOfPipes; i++)
256 if ((iface_desc->endpoint[i].desc.bmAttributes ==
257 USB_ENDPOINT_XFER_BULK) &&
258 ((iface_desc->endpoint[i].desc.bEndpointAddress &
259 USB_ENDPOINT_DIR_MASK) == USB_DIR_IN))
261 pAd->BulkInEpAddr = iface_desc->endpoint[i].desc.bEndpointAddress;
262 pAd->BulkInMaxPacketSize = le2cpu16(iface_desc->endpoint[i].desc.wMaxPacketSize);
264 DBGPRINT_RAW(RT_DEBUG_TRACE, ("BULK IN MaxPacketSize = %d\n", pAd->BulkInMaxPacketSize));
265 DBGPRINT_RAW(RT_DEBUG_TRACE, ("EP address = 0x%2x\n", iface_desc->endpoint[i].desc.bEndpointAddress));
267 else if ((iface_desc->endpoint[i].desc.bmAttributes ==
268 USB_ENDPOINT_XFER_BULK) &&
269 ((iface_desc->endpoint[i].desc.bEndpointAddress &
270 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT))
272 // there are 6 bulk out EP. EP6 highest priority.
273 // EP1-4 is EDCA. EP5 is HCCA.
274 pAd->BulkOutEpAddr[BulkOutIdx++] = iface_desc->endpoint[i].desc.bEndpointAddress;
275 pAd->BulkOutMaxPacketSize = le2cpu16(iface_desc->endpoint[i].desc.wMaxPacketSize);
277 DBGPRINT_RAW(RT_DEBUG_TRACE, ("BULK OUT MaxPacketSize = %d\n", pAd->BulkOutMaxPacketSize));
278 DBGPRINT_RAW(RT_DEBUG_TRACE, ("EP address = 0x%2x \n", iface_desc->endpoint[i].desc.bEndpointAddress));
282 if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0]))
284 printk("%s: Could not find both bulk-in and bulk-out endpoints\n", __FUNCTION__);
288 pAd->config = &dev->config->desc;
289 usb_set_intfdata(intf, pAd);
297 static int rtusb_probe (struct usb_interface *intf,
298 const struct usb_device_id *id)
301 struct usb_device *dev;
304 dev = interface_to_usbdev(intf);
305 dev = usb_get_dev(dev);
307 rv = rt2870_probe(intf, dev, id, &pAd);
315 static void rtusb_disconnect(struct usb_interface *intf)
317 struct usb_device *dev = interface_to_usbdev(intf);
321 pAd = usb_get_intfdata(intf);
322 usb_set_intfdata(intf, NULL);
324 rt2870_disconnect(dev, pAd);
328 struct usb_driver rtusb_driver = {
331 .disconnect=rtusb_disconnect,
332 .id_table=rtusb_usb_id,
335 suspend: rt2870_suspend,
336 resume: rt2870_resume,
342 VOID RT2870RejectPendingPackets(
343 IN PRTMP_ADAPTER pAd)
346 // clear TxSw packets
349 static int rt2870_suspend(
350 struct usb_interface *intf,
353 struct net_device *net_dev;
354 PRTMP_ADAPTER pAd = usb_get_intfdata(intf);
357 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_suspend()\n"));
358 net_dev = pAd->net_dev;
359 netif_device_detach(net_dev);
361 pAd->PM_FlgSuspend = 1;
362 if (netif_running(net_dev)) {
363 RTUSBCancelPendingBulkInIRP(pAd);
364 RTUSBCancelPendingBulkOutIRP(pAd);
366 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_suspend()\n"));
370 static int rt2870_resume(
371 struct usb_interface *intf)
373 struct net_device *net_dev;
374 PRTMP_ADAPTER pAd = usb_get_intfdata(intf);
377 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_resume()\n"));
379 pAd->PM_FlgSuspend = 0;
380 net_dev = pAd->net_dev;
381 netif_device_attach(net_dev);
382 netif_start_queue(net_dev);
383 netif_carrier_on(net_dev);
384 netif_wake_queue(net_dev);
386 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_resume()\n"));
389 #endif // CONFIG_PM //
391 // Init driver module
392 INT __init rtusb_init(void)
394 printk("rtusb init --->\n");
395 return usb_register(&rtusb_driver);
398 // Deinit driver module
399 VOID __exit rtusb_exit(void)
401 usb_deregister(&rtusb_driver);
402 printk("<--- rtusb exit\n");
405 module_init(rtusb_init);
406 module_exit(rtusb_exit);
411 /*--------------------------------------------------------------------- */
412 /* function declarations */
413 /*--------------------------------------------------------------------- */
416 ========================================================================
421 *Context the pAd, driver control block pointer
427 ========================================================================
437 pTask = (RTMP_OS_TASK *)Context;
438 pAd = (PRTMP_ADAPTER)pTask->priv;
440 RtmpOSTaskCustomize(pTask);
442 while(!pTask->task_killed)
444 #ifdef KTHREAD_SUPPORT
445 RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask);
447 RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status);
449 /* unlock the device pointers */
452 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
457 /* lock the device pointers , need to check if required*/
458 //down(&(pAd->usbdev_semaphore));
460 if (!pAd->PM_FlgSuspend)
464 /* notify the exit routine that we're actually exiting now
466 * complete()/wait_for_completion() is similar to up()/down(),
467 * except that complete() is safe in the case where the structure
468 * is getting deleted in a parallel mode of execution (i.e. just
469 * after the down() -- that's necessary for the thread-shutdown
472 * complete_and_exit() goes even further than this -- it is safe in
473 * the case that the thread of the caller is going away (not just
474 * the structure) -- this is necessary for the module-remove case.
475 * This is important in preemption kernels, which transfer the flow
476 * of execution immediately upon a complete().
478 DBGPRINT(RT_DEBUG_TRACE,( "<---%s\n",__FUNCTION__));
479 #ifndef KTHREAD_SUPPORT
480 pTask->taskPID = THREAD_PID_INIT_VALUE;
481 complete_and_exit (&pTask->taskComplete, 0);
489 ========================================================================
491 USB command kernel thread.
494 *Context the pAd, driver control block pointer
500 ========================================================================
510 pTask = (RTMP_OS_TASK *)Context;
511 pAd = (PRTMP_ADAPTER)pTask->priv;
513 RtmpOSTaskCustomize(pTask);
515 NdisAcquireSpinLock(&pAd->CmdQLock);
516 pAd->CmdQ.CmdQState = RTMP_TASK_STAT_RUNNING;
517 NdisReleaseSpinLock(&pAd->CmdQLock);
519 while (pAd && pAd->CmdQ.CmdQState == RTMP_TASK_STAT_RUNNING)
521 #ifdef KTHREAD_SUPPORT
522 RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask);
524 /* lock the device pointers */
525 RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status);
529 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
534 if (pAd->CmdQ.CmdQState == RTMP_TASK_STAT_STOPED)
537 if (!pAd->PM_FlgSuspend)
541 if (pAd && !pAd->PM_FlgSuspend)
542 { // Clear the CmdQElements.
543 CmdQElmt *pCmdQElmt = NULL;
545 NdisAcquireSpinLock(&pAd->CmdQLock);
546 pAd->CmdQ.CmdQState = RTMP_TASK_STAT_STOPED;
547 while(pAd->CmdQ.size)
549 RTUSBDequeueCmd(&pAd->CmdQ, &pCmdQElmt);
552 if (pCmdQElmt->CmdFromNdis == TRUE)
554 if (pCmdQElmt->buffer != NULL)
555 os_free_mem(pAd, pCmdQElmt->buffer);
556 os_free_mem(pAd, (PUCHAR)pCmdQElmt);
560 if ((pCmdQElmt->buffer != NULL) && (pCmdQElmt->bufferlength != 0))
561 os_free_mem(pAd, pCmdQElmt->buffer);
562 os_free_mem(pAd, (PUCHAR)pCmdQElmt);
567 NdisReleaseSpinLock(&pAd->CmdQLock);
569 /* notify the exit routine that we're actually exiting now
571 * complete()/wait_for_completion() is similar to up()/down(),
572 * except that complete() is safe in the case where the structure
573 * is getting deleted in a parallel mode of execution (i.e. just
574 * after the down() -- that's necessary for the thread-shutdown
577 * complete_and_exit() goes even further than this -- it is safe in
578 * the case that the thread of the caller is going away (not just
579 * the structure) -- this is necessary for the module-remove case.
580 * This is important in preemption kernels, which transfer the flow
581 * of execution immediately upon a complete().
583 DBGPRINT(RT_DEBUG_TRACE,( "<---RTUSBCmdThread\n"));
585 #ifndef KTHREAD_SUPPORT
586 pTask->taskPID = THREAD_PID_INIT_VALUE;
587 complete_and_exit (&pTask->taskComplete, 0);
594 VOID RTUSBWatchDog(IN RTMP_ADAPTER *pAd)
596 PHT_TX_CONTEXT pHTTXContext;
600 BOOLEAN needDumpSeq = FALSE;
605 RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
606 if ((MACValue & 0xff) !=0 )
608 DBGPRINT(RT_DEBUG_TRACE, ("TX QUEUE 0 Not EMPTY(Value=0x%0x). !!!!!!!!!!!!!!!\n", MACValue));
609 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40012);
610 while((MACValue &0xff) != 0 && (idx++ < 10))
612 RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
615 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40006);
618 if (pAd->watchDogRxOverFlowCnt >= 2)
620 DBGPRINT(RT_DEBUG_TRACE, ("Maybe the Rx Bulk-In hanged! Cancel the pending Rx bulks request!\n"));
621 if ((!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS |
622 fRTMP_ADAPTER_BULKIN_RESET |
623 fRTMP_ADAPTER_HALT_IN_PROGRESS |
624 fRTMP_ADAPTER_NIC_NOT_EXIST))))
626 DBGPRINT(RT_DEBUG_TRACE, ("Call CMDTHREAD_RESET_BULK_IN to cancel the pending Rx Bulk!\n"));
627 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
628 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN, NULL, 0);
631 pAd->watchDogRxOverFlowCnt = 0;
634 RTUSBReadMACRegister(pAd, 0x438, &TxRxQ_Pcnt);
636 for (idx = 0; idx < NUM_OF_TX_RING; idx++)
640 RTMP_IRQ_LOCK(&pAd->BulkOutLock[idx], irqFlags);
641 if ((pAd->BulkOutPending[idx] == TRUE) && pAd->watchDogTxPendingCnt)
643 INT actual_length=0,transfer_buffer_length=0;
644 BOOLEAN isDataPacket=FALSE;
645 pAd->watchDogTxPendingCnt[idx]++;
647 if ((pAd->watchDogTxPendingCnt[idx] > 2) &&
648 (!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_BULKOUT_RESET)))
651 // FIXME: Following code just support single bulk out. If you wanna support multiple bulk out. Modify it!
652 pHTTXContext = (PHT_TX_CONTEXT)(&pAd->TxContext[idx]);
653 if (pHTTXContext->IRPPending)
654 { // Check TxContext.
655 pUrb = pHTTXContext->pUrb;
657 actual_length=pUrb->actual_length;
658 transfer_buffer_length=pUrb->transfer_buffer_length;
661 else if (idx == MGMTPIPEIDX)
663 PTX_CONTEXT pMLMEContext, pNULLContext, pPsPollContext;
666 pMLMEContext = (PTX_CONTEXT)(pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa);
667 pPsPollContext = (PTX_CONTEXT)(&pAd->PsPollContext);
668 pNULLContext = (PTX_CONTEXT)(&pAd->NullContext);
670 if (pMLMEContext->IRPPending)
672 ASSERT(pMLMEContext->IRPPending);
673 pUrb = pMLMEContext->pUrb;
675 else if (pNULLContext->IRPPending)
677 ASSERT(pNULLContext->IRPPending);
678 pUrb = pNULLContext->pUrb;
680 else if (pPsPollContext->IRPPending)
682 ASSERT(pPsPollContext->IRPPending);
683 pUrb = pPsPollContext->pUrb;
687 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
690 printk("%d:%d LTL=%d , TL=%d L:%d\n",idx,pAd->watchDogTxPendingCnt[idx],pAd->TransferedLength[idx]
691 ,actual_length,transfer_buffer_length);
696 && pAd->TransferedLength[idx]==actual_length
697 && pAd->TransferedLength[idx]<transfer_buffer_length
700 && pAd->watchDogTxPendingCnt[idx]>3)
701 || isDataPacket==FALSE || pAd->watchDogTxPendingCnt[idx]>6)
703 DBGPRINT(RT_DEBUG_TRACE, ("Maybe the Tx Bulk-Out hanged! Cancel the pending Tx bulks request of idx(%d)!\n", idx));
704 DBGPRINT(RT_DEBUG_TRACE, ("Unlink the pending URB!\n"));
706 RTUSB_UNLINK_URB(pUrb);
707 // Sleep 200 microseconds to give cancellation time to work
708 //RTMPusecDelay(200);
714 DBGPRINT(RT_DEBUG_ERROR, ("Unkonw bulkOut URB maybe hanged!!!!!!!!!!!!\n"));
719 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
722 if (isDataPacket==TRUE)
723 pAd->TransferedLength[idx]=actual_length;
727 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
731 // For Sigma debug, dump the ba_reordering sequence.
732 if((needDumpSeq == TRUE) && (pAd->CommonCfg.bDisableReordering == 0))
735 PBA_REC_ENTRY pBAEntry = NULL;
737 struct reordering_mpdu *mpdu_blk;
739 Idx = pAd->MacTab.Content[BSSID_WCID].BARecWcidArray[0];
741 pBAEntry = &pAd->BATable.BARecEntry[Idx];
742 if((pBAEntry->list.qlen > 0) && (pBAEntry->list.next != NULL))
744 DBGPRINT(RT_DEBUG_TRACE, ("NICUpdateRawCounters():The Queueing pkt in reordering buffer:\n"));
745 NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
746 mpdu_blk = pBAEntry->list.next;
749 DBGPRINT(RT_DEBUG_TRACE, ("\t%d:Seq-%d, bAMSDU-%d!\n", count, mpdu_blk->Sequence, mpdu_blk->bAMSDU));
750 mpdu_blk = mpdu_blk->next;
754 DBGPRINT(RT_DEBUG_TRACE, ("\npBAEntry->LastIndSeq=%d!\n", pBAEntry->LastIndSeq));
755 NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
761 ========================================================================
763 Release allocated resources.
766 *dev Point to the PCI or USB device
767 pAd driver control block pointer
773 ========================================================================
775 static void rt2870_disconnect(struct usb_device *dev, PRTMP_ADAPTER pAd)
777 DBGPRINT(RT_DEBUG_ERROR, ("rtusb_disconnect: unregister usbnet usb-%s-%s\n",
778 dev->bus->bus_name, dev->devpath));
782 printk("rtusb_disconnect: pAd == NULL!\n");
785 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);
787 // for debug, wait to show some messages to /proc system
791 RtmpPhyNetDevExit(pAd, pAd->net_dev);
793 // FIXME: Shall we need following delay and flush the schedule??
795 flush_scheduled_work();
798 // free the root net_device
799 RtmpOSNetDevFree(pAd->net_dev);
801 RtmpRaDevCtrlExit(pAd);
803 // release a use of the usb device structure
807 DBGPRINT(RT_DEBUG_ERROR, (" RTUSB disconnect successfully\n"));
811 static int __devinit rt2870_probe(
812 IN struct usb_interface *intf,
813 IN struct usb_device *usb_dev,
814 IN const struct usb_device_id *dev_id,
815 IN RTMP_ADAPTER **ppAd)
817 struct net_device *net_dev = NULL;
818 RTMP_ADAPTER *pAd = (RTMP_ADAPTER *) NULL;
821 RTMP_OS_NETDEV_OP_HOOK netDevHook;
824 DBGPRINT(RT_DEBUG_TRACE, ("===>rt2870_probe()!\n"));
826 // Check chipset vendor/product ID
827 //if (RT28XXChipsetCheck(_dev_p) == FALSE)
830 //RtmpDevInit=============================================
831 // Allocate RTMP_ADAPTER adapter structure
832 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
835 printk("rt2870_probe(): Allocate memory for os handle failed!\n");
838 ((POS_COOKIE)handle)->pUsb_Dev = usb_dev;
840 rv = RTMPAllocAdapterBlock(handle, &pAd);
841 if (rv != NDIS_STATUS_SUCCESS)
847 //USBDevInit==============================================
848 if (USBDevConfigInit(usb_dev, intf, pAd) == FALSE)
849 goto err_out_free_radev;
851 RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_USB);
853 //NetDevInit==============================================
854 net_dev = RtmpPhyNetDevInit(pAd, &netDevHook);
856 goto err_out_free_radev;
858 // Here are the net_device structure with usb specific parameters.
859 /* for supporting Network Manager.
860 * Set the sysfs physical device reference for the network logical device if set prior to registration will
861 * cause a symlink during initialization.
863 SET_NETDEV_DEV(net_dev, &(usb_dev->dev));
865 pAd->StaCfg.OriDevType = net_dev->type;
867 //All done, it's time to register the net device to linux kernel.
868 // Register this device
869 status = RtmpOSNetDevAttach(net_dev, &netDevHook);
871 goto err_out_free_netdev;
873 #ifdef KTHREAD_SUPPORT
874 init_waitqueue_head(&pAd->mlmeTask.kthread_q);
875 init_waitqueue_head(&pAd->timerTask.kthread_q);
876 init_waitqueue_head(&pAd->cmdQTask.kthread_q);
881 DBGPRINT(RT_DEBUG_TRACE, ("<===rt2870_probe()!\n"));
885 /* --------------------------- ERROR HANDLE --------------------------- */
887 RtmpOSNetDevFree(net_dev);
890 RTMPFreeAdapter(pAd);