Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/nico/orion...
[deliverable/linux.git] / drivers / staging / rt2860 / usb_main_dev.c
CommitLineData
ca97b838
BZ
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#include "rt_config.h"
28
9f548a2a
BZ
29/* Following information will be show when you run 'modinfo' */
30/* *** If you have a solution for the bug in current version of driver, please mail to me. */
31/* Otherwise post to forum in ralinktech's web site(www.ralinktech.com) and let all users help you. *** */
ca97b838
BZ
32MODULE_AUTHOR("Paul Lin <paul_lin@ralinktech.com>");
33MODULE_DESCRIPTION("RT2870/RT3070 Wireless Lan Linux Driver");
34MODULE_LICENSE("GPL");
35#ifdef MODULE_VERSION
36MODULE_VERSION(STA_DRIVER_VERSION);
37#endif
38
ca97b838
BZ
39/* module table */
40struct usb_device_id rtusb_usb_id[] = {
41#ifdef RT2870
66cd8d6e
BZ
42 {USB_DEVICE(0x148F, 0x2770)}, /* Ralink */
43 {USB_DEVICE(0x148F, 0x2870)}, /* Ralink */
44 {USB_DEVICE(0x07B8, 0x2870)}, /* AboCom */
45 {USB_DEVICE(0x07B8, 0x2770)}, /* AboCom */
46 {USB_DEVICE(0x0DF6, 0x0039)}, /* Sitecom 2770 */
47 {USB_DEVICE(0x083A, 0x7512)}, /* Arcadyan 2770 */
48 {USB_DEVICE(0x0789, 0x0162)}, /* Logitec 2870 */
49 {USB_DEVICE(0x0789, 0x0163)}, /* Logitec 2870 */
50 {USB_DEVICE(0x0789, 0x0164)}, /* Logitec 2870 */
51 {USB_DEVICE(0x177f, 0x0302)}, /* lsusb */
52 {USB_DEVICE(0x0B05, 0x1731)}, /* Asus */
53 {USB_DEVICE(0x0B05, 0x1732)}, /* Asus */
54 {USB_DEVICE(0x0B05, 0x1742)}, /* Asus */
55 {USB_DEVICE(0x0DF6, 0x0017)}, /* Sitecom */
56 {USB_DEVICE(0x0DF6, 0x002B)}, /* Sitecom */
57 {USB_DEVICE(0x0DF6, 0x002C)}, /* Sitecom */
58 {USB_DEVICE(0x0DF6, 0x002D)}, /* Sitecom */
59 {USB_DEVICE(0x14B2, 0x3C06)}, /* Conceptronic */
60 {USB_DEVICE(0x14B2, 0x3C28)}, /* Conceptronic */
61 {USB_DEVICE(0x2019, 0xED06)}, /* Planex Communications, Inc. */
62 {USB_DEVICE(0x07D1, 0x3C09)}, /* D-Link */
63 {USB_DEVICE(0x07D1, 0x3C11)}, /* D-Link */
64 {USB_DEVICE(0x14B2, 0x3C07)}, /* AL */
65 {USB_DEVICE(0x050D, 0x8053)}, /* Belkin */
12840c63 66 {USB_DEVICE(0x050D, 0x825B)}, /* Belkin */
66cd8d6e
BZ
67 {USB_DEVICE(0x14B2, 0x3C23)}, /* Airlink */
68 {USB_DEVICE(0x14B2, 0x3C27)}, /* Airlink */
69 {USB_DEVICE(0x07AA, 0x002F)}, /* Corega */
70 {USB_DEVICE(0x07AA, 0x003C)}, /* Corega */
71 {USB_DEVICE(0x07AA, 0x003F)}, /* Corega */
72 {USB_DEVICE(0x1044, 0x800B)}, /* Gigabyte */
73 {USB_DEVICE(0x15A9, 0x0006)}, /* Sparklan */
74 {USB_DEVICE(0x083A, 0xB522)}, /* SMC */
75 {USB_DEVICE(0x083A, 0xA618)}, /* SMC */
76 {USB_DEVICE(0x083A, 0x8522)}, /* Arcadyan */
77 {USB_DEVICE(0x083A, 0x7522)}, /* Arcadyan */
78 {USB_DEVICE(0x0CDE, 0x0022)}, /* ZCOM */
79 {USB_DEVICE(0x0586, 0x3416)}, /* Zyxel */
80 {USB_DEVICE(0x0CDE, 0x0025)}, /* Zyxel */
81 {USB_DEVICE(0x1740, 0x9701)}, /* EnGenius */
82 {USB_DEVICE(0x1740, 0x9702)}, /* EnGenius */
83 {USB_DEVICE(0x0471, 0x200f)}, /* Philips */
84 {USB_DEVICE(0x14B2, 0x3C25)}, /* Draytek */
85 {USB_DEVICE(0x13D3, 0x3247)}, /* AzureWave */
86 {USB_DEVICE(0x083A, 0x6618)}, /* Accton */
87 {USB_DEVICE(0x15c5, 0x0008)}, /* Amit */
88 {USB_DEVICE(0x0E66, 0x0001)}, /* Hawking */
89 {USB_DEVICE(0x0E66, 0x0003)}, /* Hawking */
90 {USB_DEVICE(0x129B, 0x1828)}, /* Siemens */
91 {USB_DEVICE(0x157E, 0x300E)}, /* U-Media */
92 {USB_DEVICE(0x050d, 0x805c)},
93 {USB_DEVICE(0x050d, 0x815c)},
94 {USB_DEVICE(0x1482, 0x3C09)}, /* Abocom */
95 {USB_DEVICE(0x14B2, 0x3C09)}, /* Alpha */
96 {USB_DEVICE(0x04E8, 0x2018)}, /* samsung */
97 {USB_DEVICE(0x5A57, 0x0280)}, /* Zinwell */
98 {USB_DEVICE(0x5A57, 0x0282)}, /* Zinwell */
99 {USB_DEVICE(0x7392, 0x7718)},
100 {USB_DEVICE(0x7392, 0x7717)},
101 {USB_DEVICE(0x1737, 0x0070)}, /* Linksys WUSB100 */
102 {USB_DEVICE(0x1737, 0x0071)}, /* Linksys WUSB600N */
103 {USB_DEVICE(0x0411, 0x00e8)}, /* Buffalo WLI-UC-G300N */
104 {USB_DEVICE(0x050d, 0x815c)}, /* Belkin F5D8053 */
9f548a2a 105#endif /* RT2870 // */
ca97b838 106#ifdef RT3070
66cd8d6e
BZ
107 {USB_DEVICE(0x148F, 0x3070)}, /* Ralink 3070 */
108 {USB_DEVICE(0x148F, 0x3071)}, /* Ralink 3071 */
109 {USB_DEVICE(0x148F, 0x3072)}, /* Ralink 3072 */
110 {USB_DEVICE(0x0DB0, 0x3820)}, /* Ralink 3070 */
111 {USB_DEVICE(0x0DF6, 0x003E)}, /* Sitecom 3070 */
112 {USB_DEVICE(0x0DF6, 0x0042)}, /* Sitecom 3072 */
113 {USB_DEVICE(0x14B2, 0x3C12)}, /* AL 3070 */
114 {USB_DEVICE(0x18C5, 0x0012)}, /* Corega 3070 */
115 {USB_DEVICE(0x083A, 0x7511)}, /* Arcadyan 3070 */
116 {USB_DEVICE(0x1740, 0x9703)}, /* EnGenius 3070 */
117 {USB_DEVICE(0x1740, 0x9705)}, /* EnGenius 3071 */
118 {USB_DEVICE(0x1740, 0x9706)}, /* EnGenius 3072 */
119 {USB_DEVICE(0x13D3, 0x3273)}, /* AzureWave 3070 */
120 {USB_DEVICE(0x1044, 0x800D)}, /* Gigabyte GN-WB32L 3070 */
121 {USB_DEVICE(0x2019, 0xAB25)}, /* Planex Communications, Inc. RT3070 */
122 {USB_DEVICE(0x07B8, 0x3070)}, /* AboCom 3070 */
123 {USB_DEVICE(0x07B8, 0x3071)}, /* AboCom 3071 */
124 {USB_DEVICE(0x07B8, 0x3072)}, /* Abocom 3072 */
125 {USB_DEVICE(0x7392, 0x7711)}, /* Edimax 3070 */
126 {USB_DEVICE(0x1A32, 0x0304)}, /* Quanta 3070 */
127 {USB_DEVICE(0x1EDA, 0x2310)}, /* AirTies 3070 */
128 {USB_DEVICE(0x07D1, 0x3C0A)}, /* D-Link 3072 */
129 {USB_DEVICE(0x07D1, 0x3C0D)}, /* D-Link 3070 */
130 {USB_DEVICE(0x07D1, 0x3C0E)}, /* D-Link 3070 */
131 {USB_DEVICE(0x07D1, 0x3C0F)}, /* D-Link 3070 */
132 {USB_DEVICE(0x1D4D, 0x000C)}, /* Pegatron Corporation 3070 */
133 {USB_DEVICE(0x1D4D, 0x000E)}, /* Pegatron Corporation 3070 */
134 {USB_DEVICE(0x5A57, 0x5257)}, /* Zinwell 3070 */
135 {USB_DEVICE(0x5A57, 0x0283)}, /* Zinwell 3072 */
136 {USB_DEVICE(0x04BB, 0x0945)}, /* I-O DATA 3072 */
137 {USB_DEVICE(0x203D, 0x1480)}, /* Encore 3070 */
9f548a2a 138#endif /* RT3070 // */
66cd8d6e
BZ
139 {USB_DEVICE(0x0DF6, 0x003F)}, /* Sitecom WL-608 */
140 {USB_DEVICE(0x1737, 0x0077)}, /* Linksys WUSB54GC-EU v3 */
141 {USB_DEVICE(0x2001, 0x3C09)}, /* D-Link */
142 {USB_DEVICE(0x2001, 0x3C0A)}, /* D-Link 3072 */
143 {USB_DEVICE(0x2019, 0xED14)}, /* Planex Communications, Inc. */
144 {} /* Terminating entry */
ca97b838
BZ
145};
146
51126deb 147int const rtusb_usb_id_len =
66cd8d6e 148 sizeof(rtusb_usb_id) / sizeof(struct usb_device_id);
ca97b838
BZ
149
150MODULE_DEVICE_TABLE(usb, rtusb_usb_id);
151
62eb734b 152static void rt2870_disconnect(struct usb_device *dev, struct rt_rtmp_adapter *pAd);
ca97b838 153
66cd8d6e
BZ
154static int __devinit rt2870_probe(IN struct usb_interface *intf,
155 IN struct usb_device *usb_dev,
156 IN const struct usb_device_id *dev_id,
62eb734b 157 struct rt_rtmp_adapter ** ppAd);
ca97b838
BZ
158
159#ifndef PF_NOFREEZE
160#define PF_NOFREEZE 0
161#endif
162
ca97b838
BZ
163extern int rt28xx_close(IN struct net_device *net_dev);
164extern int rt28xx_open(struct net_device *net_dev);
165
66cd8d6e
BZ
166static BOOLEAN USBDevConfigInit(IN struct usb_device *dev,
167 IN struct usb_interface *intf,
62eb734b 168 struct rt_rtmp_adapter *pAd);
ca97b838
BZ
169
170/*
171========================================================================
172Routine Description:
173 Check the chipset vendor/product ID.
174
175Arguments:
176 _dev_p Point to the PCI or USB device
177
178Return Value:
179 TRUE Check ok
180 FALSE Check fail
181
182Note:
183========================================================================
184*/
66cd8d6e 185BOOLEAN RT28XXChipsetCheck(IN void *_dev_p)
ca97b838
BZ
186{
187 struct usb_interface *intf = (struct usb_interface *)_dev_p;
188 struct usb_device *dev_p = interface_to_usbdev(intf);
51126deb 189 u32 i;
ca97b838 190
66cd8d6e 191 for (i = 0; i < rtusb_usb_id_len; i++) {
ca97b838 192 if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor &&
66cd8d6e 193 dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct) {
ca97b838 194 printk("rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
66cd8d6e
BZ
195 dev_p->descriptor.idVendor,
196 dev_p->descriptor.idProduct);
ca97b838
BZ
197 break;
198 }
199 }
200
66cd8d6e 201 if (i == rtusb_usb_id_len) {
ca97b838
BZ
202 printk("rt2870: Error! Device Descriptor not matching!\n");
203 return FALSE;
204 }
205
206 return TRUE;
207}
208
209/**************************************************************************/
210/**************************************************************************/
9f548a2a 211/*tested for kernel 2.6series */
ca97b838
BZ
212/**************************************************************************/
213/**************************************************************************/
214
215#ifdef CONFIG_PM
216static int rt2870_suspend(struct usb_interface *intf, pm_message_t state);
217static int rt2870_resume(struct usb_interface *intf);
9f548a2a 218#endif /* CONFIG_PM // */
ca97b838 219
66cd8d6e
BZ
220static BOOLEAN USBDevConfigInit(IN struct usb_device *dev,
221 IN struct usb_interface *intf,
62eb734b 222 struct rt_rtmp_adapter *pAd)
ca97b838
BZ
223{
224 struct usb_host_interface *iface_desc;
51126deb
BZ
225 unsigned long BulkOutIdx;
226 u32 i;
ca97b838 227
ca97b838
BZ
228 /* get the active interface descriptor */
229 iface_desc = intf->cur_altsetting;
230
231 /* get # of enpoints */
232 pAd->NumberOfPipes = iface_desc->desc.bNumEndpoints;
66cd8d6e
BZ
233 DBGPRINT(RT_DEBUG_TRACE,
234 ("NumEndpoints=%d\n", iface_desc->desc.bNumEndpoints));
ca97b838
BZ
235
236 /* Configure Pipes */
237 BulkOutIdx = 0;
238
66cd8d6e 239 for (i = 0; i < pAd->NumberOfPipes; i++) {
ca97b838 240 if ((iface_desc->endpoint[i].desc.bmAttributes ==
66cd8d6e
BZ
241 USB_ENDPOINT_XFER_BULK) &&
242 ((iface_desc->endpoint[i].desc.bEndpointAddress &
243 USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)) {
244 pAd->BulkInEpAddr =
245 iface_desc->endpoint[i].desc.bEndpointAddress;
246 pAd->BulkInMaxPacketSize =
247 le2cpu16(iface_desc->endpoint[i].desc.
248 wMaxPacketSize);
249
250 DBGPRINT_RAW(RT_DEBUG_TRACE,
251 ("BULK IN MaxPacketSize = %d\n",
252 pAd->BulkInMaxPacketSize));
253 DBGPRINT_RAW(RT_DEBUG_TRACE,
254 ("EP address = 0x%2x\n",
255 iface_desc->endpoint[i].desc.
256 bEndpointAddress));
257 } else
258 if ((iface_desc->endpoint[i].desc.bmAttributes ==
259 USB_ENDPOINT_XFER_BULK)
260 &&
261 ((iface_desc->endpoint[i].desc.
262 bEndpointAddress & USB_ENDPOINT_DIR_MASK) ==
263 USB_DIR_OUT)) {
9f548a2a
BZ
264 /* there are 6 bulk out EP. EP6 highest priority. */
265 /* EP1-4 is EDCA. EP5 is HCCA. */
66cd8d6e
BZ
266 pAd->BulkOutEpAddr[BulkOutIdx++] =
267 iface_desc->endpoint[i].desc.bEndpointAddress;
268 pAd->BulkOutMaxPacketSize =
269 le2cpu16(iface_desc->endpoint[i].desc.
270 wMaxPacketSize);
271
272 DBGPRINT_RAW(RT_DEBUG_TRACE,
273 ("BULK OUT MaxPacketSize = %d\n",
274 pAd->BulkOutMaxPacketSize));
275 DBGPRINT_RAW(RT_DEBUG_TRACE,
276 ("EP address = 0x%2x \n",
277 iface_desc->endpoint[i].desc.
278 bEndpointAddress));
ca97b838
BZ
279 }
280 }
281
66cd8d6e
BZ
282 if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0])) {
283 printk
284 ("%s: Could not find both bulk-in and bulk-out endpoints\n",
285 __FUNCTION__);
ca97b838
BZ
286 return FALSE;
287 }
288
289 pAd->config = &dev->config->desc;
290 usb_set_intfdata(intf, pAd);
291
292 return TRUE;
293
294}
295
c33c2065 296static int __devinit rtusb_probe(struct usb_interface *intf,
66cd8d6e 297 const struct usb_device_id *id)
ca97b838 298{
62eb734b 299 struct rt_rtmp_adapter *pAd;
ca97b838
BZ
300 struct usb_device *dev;
301 int rv;
302
303 dev = interface_to_usbdev(intf);
304 dev = usb_get_dev(dev);
305
306 rv = rt2870_probe(intf, dev, id, &pAd);
307 if (rv != 0)
308 usb_put_dev(dev);
309
310 return rv;
311}
312
ca97b838
BZ
313static void rtusb_disconnect(struct usb_interface *intf)
314{
66cd8d6e 315 struct usb_device *dev = interface_to_usbdev(intf);
62eb734b 316 struct rt_rtmp_adapter *pAd;
ca97b838
BZ
317
318 pAd = usb_get_intfdata(intf);
319 usb_set_intfdata(intf, NULL);
320
321 rt2870_disconnect(dev, pAd);
322}
323
ca97b838 324struct usb_driver rtusb_driver = {
66cd8d6e
BZ
325 .name = "rt2870",
326 .probe = rtusb_probe,
327 .disconnect = rtusb_disconnect,
328 .id_table = rtusb_usb_id,
ca97b838
BZ
329
330#ifdef CONFIG_PM
66cd8d6e
BZ
331suspend:rt2870_suspend,
332resume:rt2870_resume,
ca97b838 333#endif
66cd8d6e 334};
ca97b838
BZ
335
336#ifdef CONFIG_PM
337
62eb734b 338void RT2870RejectPendingPackets(struct rt_rtmp_adapter *pAd)
ca97b838 339{
9f548a2a
BZ
340 /* clear PS packets */
341 /* clear TxSw packets */
ca97b838
BZ
342}
343
66cd8d6e 344static int rt2870_suspend(struct usb_interface *intf, pm_message_t state)
ca97b838
BZ
345{
346 struct net_device *net_dev;
62eb734b 347 struct rt_rtmp_adapter *pAd = usb_get_intfdata(intf);
ca97b838 348
ca97b838
BZ
349 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_suspend()\n"));
350 net_dev = pAd->net_dev;
351 netif_device_detach(net_dev);
352
353 pAd->PM_FlgSuspend = 1;
354 if (netif_running(net_dev)) {
355 RTUSBCancelPendingBulkInIRP(pAd);
356 RTUSBCancelPendingBulkOutIRP(pAd);
357 }
358 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_suspend()\n"));
359 return 0;
360}
361
66cd8d6e 362static int rt2870_resume(struct usb_interface *intf)
ca97b838
BZ
363{
364 struct net_device *net_dev;
62eb734b 365 struct rt_rtmp_adapter *pAd = usb_get_intfdata(intf);
ca97b838 366
ca97b838
BZ
367 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_resume()\n"));
368
369 pAd->PM_FlgSuspend = 0;
370 net_dev = pAd->net_dev;
371 netif_device_attach(net_dev);
372 netif_start_queue(net_dev);
373 netif_carrier_on(net_dev);
374 netif_wake_queue(net_dev);
375
376 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_resume()\n"));
377 return 0;
378}
9f548a2a 379#endif /* CONFIG_PM // */
ca97b838 380
9f548a2a 381/* Init driver module */
51126deb 382int __init rtusb_init(void)
ca97b838
BZ
383{
384 printk("rtusb init --->\n");
385 return usb_register(&rtusb_driver);
386}
387
9f548a2a 388/* Deinit driver module */
51126deb 389void __exit rtusb_exit(void)
ca97b838
BZ
390{
391 usb_deregister(&rtusb_driver);
392 printk("<--- rtusb exit\n");
393}
394
395module_init(rtusb_init);
396module_exit(rtusb_exit);
397
ca97b838
BZ
398/*--------------------------------------------------------------------- */
399/* function declarations */
400/*--------------------------------------------------------------------- */
401
402/*
403========================================================================
404Routine Description:
405 MLME kernel thread.
406
407Arguments:
408 *Context the pAd, driver control block pointer
409
410Return Value:
411 0 close the thread
412
413Note:
414========================================================================
415*/
51126deb 416int MlmeThread(IN void *Context)
ca97b838 417{
62eb734b
BZ
418 struct rt_rtmp_adapter *pAd;
419 struct rt_rtmp_os_task *pTask;
ca97b838
BZ
420 int status;
421 status = 0;
422
62eb734b
BZ
423 pTask = (struct rt_rtmp_os_task *)Context;
424 pAd = (struct rt_rtmp_adapter *)pTask->priv;
ca97b838
BZ
425
426 RtmpOSTaskCustomize(pTask);
427
66cd8d6e 428 while (!pTask->task_killed) {
ca97b838
BZ
429#ifdef KTHREAD_SUPPORT
430 RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask);
431#else
432 RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status);
433
434 /* unlock the device pointers */
66cd8d6e 435 if (status != 0) {
ca97b838
BZ
436 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
437 break;
438 }
439#endif
440
66cd8d6e 441 /* lock the device pointers , need to check if required */
9f548a2a 442 /*down(&(pAd->usbdev_semaphore)); */
ca97b838
BZ
443
444 if (!pAd->PM_FlgSuspend)
445 MlmeHandler(pAd);
446 }
447
448 /* notify the exit routine that we're actually exiting now
449 *
450 * complete()/wait_for_completion() is similar to up()/down(),
451 * except that complete() is safe in the case where the structure
452 * is getting deleted in a parallel mode of execution (i.e. just
453 * after the down() -- that's necessary for the thread-shutdown
454 * case.
455 *
456 * complete_and_exit() goes even further than this -- it is safe in
457 * the case that the thread of the caller is going away (not just
458 * the structure) -- this is necessary for the module-remove case.
459 * This is important in preemption kernels, which transfer the flow
460 * of execution immediately upon a complete().
461 */
66cd8d6e 462 DBGPRINT(RT_DEBUG_TRACE, ("<---%s\n", __FUNCTION__));
ca97b838
BZ
463#ifndef KTHREAD_SUPPORT
464 pTask->taskPID = THREAD_PID_INIT_VALUE;
66cd8d6e 465 complete_and_exit(&pTask->taskComplete, 0);
ca97b838
BZ
466#endif
467 return 0;
468
469}
470
ca97b838
BZ
471/*
472========================================================================
473Routine Description:
474 USB command kernel thread.
475
476Arguments:
477 *Context the pAd, driver control block pointer
478
479Return Value:
480 0 close the thread
481
482Note:
483========================================================================
484*/
51126deb 485int RTUSBCmdThread(IN void *Context)
ca97b838 486{
62eb734b
BZ
487 struct rt_rtmp_adapter *pAd;
488 struct rt_rtmp_os_task *pTask;
ca97b838
BZ
489 int status;
490 status = 0;
491
62eb734b
BZ
492 pTask = (struct rt_rtmp_os_task *)Context;
493 pAd = (struct rt_rtmp_adapter *)pTask->priv;
ca97b838
BZ
494
495 RtmpOSTaskCustomize(pTask);
496
497 NdisAcquireSpinLock(&pAd->CmdQLock);
498 pAd->CmdQ.CmdQState = RTMP_TASK_STAT_RUNNING;
499 NdisReleaseSpinLock(&pAd->CmdQLock);
500
66cd8d6e 501 while (pAd && pAd->CmdQ.CmdQState == RTMP_TASK_STAT_RUNNING) {
ca97b838
BZ
502#ifdef KTHREAD_SUPPORT
503 RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask);
504#else
505 /* lock the device pointers */
506 RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status);
507
66cd8d6e 508 if (status != 0) {
ca97b838
BZ
509 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
510 break;
511 }
512#endif
513
514 if (pAd->CmdQ.CmdQState == RTMP_TASK_STAT_STOPED)
515 break;
516
517 if (!pAd->PM_FlgSuspend)
518 CMDHandler(pAd);
519 }
520
9f548a2a 521 if (pAd && !pAd->PM_FlgSuspend) { /* Clear the CmdQElements. */
62eb734b 522 struct rt_cmdqelmt *pCmdQElmt = NULL;
ca97b838
BZ
523
524 NdisAcquireSpinLock(&pAd->CmdQLock);
525 pAd->CmdQ.CmdQState = RTMP_TASK_STAT_STOPED;
66cd8d6e 526 while (pAd->CmdQ.size) {
ca97b838 527 RTUSBDequeueCmd(&pAd->CmdQ, &pCmdQElmt);
66cd8d6e
BZ
528 if (pCmdQElmt) {
529 if (pCmdQElmt->CmdFromNdis == TRUE) {
ca97b838 530 if (pCmdQElmt->buffer != NULL)
66cd8d6e
BZ
531 os_free_mem(pAd,
532 pCmdQElmt->buffer);
51126deb 533 os_free_mem(pAd, (u8 *)pCmdQElmt);
66cd8d6e
BZ
534 } else {
535 if ((pCmdQElmt->buffer != NULL)
536 && (pCmdQElmt->bufferlength != 0))
537 os_free_mem(pAd,
538 pCmdQElmt->buffer);
51126deb 539 os_free_mem(pAd, (u8 *)pCmdQElmt);
ca97b838
BZ
540 }
541 }
542 }
543
544 NdisReleaseSpinLock(&pAd->CmdQLock);
545 }
546 /* notify the exit routine that we're actually exiting now
547 *
548 * complete()/wait_for_completion() is similar to up()/down(),
549 * except that complete() is safe in the case where the structure
550 * is getting deleted in a parallel mode of execution (i.e. just
551 * after the down() -- that's necessary for the thread-shutdown
552 * case.
553 *
554 * complete_and_exit() goes even further than this -- it is safe in
555 * the case that the thread of the caller is going away (not just
556 * the structure) -- this is necessary for the module-remove case.
557 * This is important in preemption kernels, which transfer the flow
558 * of execution immediately upon a complete().
559 */
66cd8d6e 560 DBGPRINT(RT_DEBUG_TRACE, ("<---RTUSBCmdThread\n"));
ca97b838
BZ
561
562#ifndef KTHREAD_SUPPORT
563 pTask->taskPID = THREAD_PID_INIT_VALUE;
66cd8d6e 564 complete_and_exit(&pTask->taskComplete, 0);
ca97b838
BZ
565#endif
566 return 0;
567
568}
569
62eb734b 570void RTUSBWatchDog(struct rt_rtmp_adapter *pAd)
ca97b838 571{
62eb734b 572 struct rt_ht_tx_context *pHTTXContext;
66cd8d6e 573 int idx;
51126deb 574 unsigned long irqFlags;
66cd8d6e
BZ
575 PURB pUrb;
576 BOOLEAN needDumpSeq = FALSE;
51126deb
BZ
577 u32 MACValue;
578 u32 TxRxQ_Pcnt;
ca97b838
BZ
579
580 idx = 0;
581 RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
66cd8d6e
BZ
582 if ((MACValue & 0xff) != 0) {
583 DBGPRINT(RT_DEBUG_TRACE,
06aea994 584 ("TX QUEUE 0 Not EMPTY(Value=0x%0x)!\n",
66cd8d6e 585 MACValue));
ca97b838 586 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40012);
66cd8d6e
BZ
587 while ((MACValue & 0xff) != 0 && (idx++ < 10)) {
588 RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
589 RTMPusecDelay(1);
ca97b838
BZ
590 }
591 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40006);
592 }
593
66cd8d6e
BZ
594 if (pAd->watchDogRxOverFlowCnt >= 2) {
595 DBGPRINT(RT_DEBUG_TRACE,
596 ("Maybe the Rx Bulk-In hanged! Cancel the pending Rx bulks request!\n"));
597 if ((!RTMP_TEST_FLAG
598 (pAd,
599 (fRTMP_ADAPTER_RESET_IN_PROGRESS |
600 fRTMP_ADAPTER_BULKIN_RESET |
601 fRTMP_ADAPTER_HALT_IN_PROGRESS |
602 fRTMP_ADAPTER_NIC_NOT_EXIST)))) {
603 DBGPRINT(RT_DEBUG_TRACE,
604 ("Call CMDTHREAD_RESET_BULK_IN to cancel the pending Rx Bulk!\n"));
ca97b838 605 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
66cd8d6e
BZ
606 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN,
607 NULL, 0);
ca97b838
BZ
608 needDumpSeq = TRUE;
609 }
610 pAd->watchDogRxOverFlowCnt = 0;
611 }
612
613 RTUSBReadMACRegister(pAd, 0x438, &TxRxQ_Pcnt);
614
66cd8d6e 615 for (idx = 0; idx < NUM_OF_TX_RING; idx++) {
ca97b838
BZ
616 pUrb = NULL;
617
618 RTMP_IRQ_LOCK(&pAd->BulkOutLock[idx], irqFlags);
66cd8d6e
BZ
619 if ((pAd->BulkOutPending[idx] == TRUE)
620 && pAd->watchDogTxPendingCnt) {
51126deb 621 int actual_length = 0, transfer_buffer_length = 0;
66cd8d6e 622 BOOLEAN isDataPacket = FALSE;
ca97b838
BZ
623 pAd->watchDogTxPendingCnt[idx]++;
624
625 if ((pAd->watchDogTxPendingCnt[idx] > 2) &&
66cd8d6e
BZ
626 (!RTMP_TEST_FLAG
627 (pAd,
628 (fRTMP_ADAPTER_RESET_IN_PROGRESS |
629 fRTMP_ADAPTER_HALT_IN_PROGRESS |
630 fRTMP_ADAPTER_NIC_NOT_EXIST |
631 fRTMP_ADAPTER_BULKOUT_RESET)))
632 ) {
9f548a2a 633 /* FIXME: Following code just support single bulk out. If you wanna support multiple bulk out. Modify it! */
66cd8d6e 634 pHTTXContext =
62eb734b 635 (struct rt_ht_tx_context *)(&pAd->TxContext[idx]);
9f548a2a 636 if (pHTTXContext->IRPPending) { /* Check TxContext. */
ca97b838
BZ
637 pUrb = pHTTXContext->pUrb;
638
66cd8d6e
BZ
639 actual_length = pUrb->actual_length;
640 transfer_buffer_length =
641 pUrb->transfer_buffer_length;
642 isDataPacket = TRUE;
643 } else if (idx == MGMTPIPEIDX) {
62eb734b
BZ
644 struct rt_tx_context *pMLMEContext, *pNULLContext,
645 *pPsPollContext;
ca97b838 646
9f548a2a 647 /*Check MgmtContext. */
66cd8d6e 648 pMLMEContext =
62eb734b 649 (struct rt_tx_context *)(pAd->MgmtRing.
66cd8d6e
BZ
650 Cell[pAd->MgmtRing.
651 TxDmaIdx].
652 AllocVa);
653 pPsPollContext =
62eb734b 654 (struct rt_tx_context *)(&pAd->PsPollContext);
66cd8d6e 655 pNULLContext =
62eb734b 656 (struct rt_tx_context *)(&pAd->NullContext);
66cd8d6e
BZ
657
658 if (pMLMEContext->IRPPending) {
659 ASSERT(pMLMEContext->
660 IRPPending);
ca97b838 661 pUrb = pMLMEContext->pUrb;
66cd8d6e
BZ
662 } else if (pNULLContext->IRPPending) {
663 ASSERT(pNULLContext->
664 IRPPending);
ca97b838 665 pUrb = pNULLContext->pUrb;
66cd8d6e
BZ
666 } else if (pPsPollContext->IRPPending) {
667 ASSERT(pPsPollContext->
668 IRPPending);
ca97b838
BZ
669 pUrb = pPsPollContext->pUrb;
670 }
671 }
672
66cd8d6e
BZ
673 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx],
674 irqFlags);
ca97b838 675
ca58fb30
BZ
676 printk(KERN_INFO "%d:%lu LTL=%d , TL=%d L:%d\n",
677 idx, pAd->watchDogTxPendingCnt[idx],
678 pAd->TransferedLength[idx],
679 actual_length, transfer_buffer_length);
ca97b838 680
66cd8d6e 681 if (pUrb) {
ca97b838 682 if ((isDataPacket
66cd8d6e
BZ
683 && pAd->TransferedLength[idx] ==
684 actual_length
685 && pAd->TransferedLength[idx] <
686 transfer_buffer_length
687 && actual_length != 0
9f548a2a 688/* && TxRxQ_Pcnt==0 */
66cd8d6e
BZ
689 && pAd->watchDogTxPendingCnt[idx] >
690 3)
691 || isDataPacket == FALSE
692 || pAd->watchDogTxPendingCnt[idx] >
693 6) {
694 DBGPRINT(RT_DEBUG_TRACE,
695 ("Maybe the Tx Bulk-Out hanged! Cancel the pending Tx bulks request of idx(%d)!\n",
696 idx));
697 DBGPRINT(RT_DEBUG_TRACE,
698 ("Unlink the pending URB!\n"));
9f548a2a 699 /* unlink it now */
66cd8d6e 700 RTUSB_UNLINK_URB(pUrb);
9f548a2a
BZ
701 /* Sleep 200 microseconds to give cancellation time to work */
702 /*RTMPusecDelay(200); */
66cd8d6e 703 needDumpSeq = TRUE;
ca97b838 704 }
66cd8d6e
BZ
705 } else {
706 DBGPRINT(RT_DEBUG_ERROR,
06aea994 707 ("Unknown bulkOut URB maybe hanged!\n"));
ca97b838 708 }
66cd8d6e
BZ
709 } else {
710 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx],
711 irqFlags);
ca97b838
BZ
712 }
713
66cd8d6e
BZ
714 if (isDataPacket == TRUE)
715 pAd->TransferedLength[idx] = actual_length;
716 } else {
ca97b838
BZ
717 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
718 }
719 }
720
9f548a2a 721 /* For Sigma debug, dump the ba_reordering sequence. */
66cd8d6e 722 if ((needDumpSeq == TRUE) && (pAd->CommonCfg.bDisableReordering == 0)) {
51126deb 723 u16 Idx;
62eb734b 724 struct rt_ba_rec_entry *pBAEntry = NULL;
51126deb 725 u8 count = 0;
ca97b838
BZ
726 struct reordering_mpdu *mpdu_blk;
727
728 Idx = pAd->MacTab.Content[BSSID_WCID].BARecWcidArray[0];
729
730 pBAEntry = &pAd->BATable.BARecEntry[Idx];
66cd8d6e
BZ
731 if ((pBAEntry->list.qlen > 0) && (pBAEntry->list.next != NULL)) {
732 DBGPRINT(RT_DEBUG_TRACE,
733 ("NICUpdateRawCounters():The Queueing pkt in reordering buffer:\n"));
ca97b838
BZ
734 NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
735 mpdu_blk = pBAEntry->list.next;
66cd8d6e
BZ
736 while (mpdu_blk) {
737 DBGPRINT(RT_DEBUG_TRACE,
738 ("\t%d:Seq-%d, bAMSDU-%d!\n", count,
739 mpdu_blk->Sequence,
740 mpdu_blk->bAMSDU));
ca97b838
BZ
741 mpdu_blk = mpdu_blk->next;
742 count++;
743 }
744
66cd8d6e
BZ
745 DBGPRINT(RT_DEBUG_TRACE,
746 ("\npBAEntry->LastIndSeq=%d!\n",
747 pBAEntry->LastIndSeq));
ca97b838
BZ
748 NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
749 }
750 }
751}
752
753/*
754========================================================================
755Routine Description:
756 Release allocated resources.
757
758Arguments:
759 *dev Point to the PCI or USB device
760 pAd driver control block pointer
761
762Return Value:
763 None
764
765Note:
766========================================================================
767*/
62eb734b 768static void rt2870_disconnect(struct usb_device *dev, struct rt_rtmp_adapter *pAd)
ca97b838 769{
66cd8d6e
BZ
770 DBGPRINT(RT_DEBUG_ERROR,
771 ("rtusb_disconnect: unregister usbnet usb-%s-%s\n",
772 dev->bus->bus_name, dev->devpath));
773 if (!pAd) {
ca97b838
BZ
774 usb_put_dev(dev);
775 printk("rtusb_disconnect: pAd == NULL!\n");
776 return;
777 }
778 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);
779
9f548a2a 780 /* for debug, wait to show some messages to /proc system */
ca97b838
BZ
781 udelay(1);
782
ca97b838
BZ
783 RtmpPhyNetDevExit(pAd, pAd->net_dev);
784
9f548a2a 785 /* FIXME: Shall we need following delay and flush the schedule?? */
ca97b838
BZ
786 udelay(1);
787 flush_scheduled_work();
788 udelay(1);
789
9f548a2a 790 /* free the root net_device */
ca97b838
BZ
791 RtmpOSNetDevFree(pAd->net_dev);
792
793 RtmpRaDevCtrlExit(pAd);
794
9f548a2a 795 /* release a use of the usb device structure */
ca97b838
BZ
796 usb_put_dev(dev);
797 udelay(1);
798
799 DBGPRINT(RT_DEBUG_ERROR, (" RTUSB disconnect successfully\n"));
800}
801
66cd8d6e
BZ
802static int __devinit rt2870_probe(IN struct usb_interface *intf,
803 IN struct usb_device *usb_dev,
804 IN const struct usb_device_id *dev_id,
62eb734b 805 struct rt_rtmp_adapter ** ppAd)
ca97b838 806{
66cd8d6e 807 struct net_device *net_dev = NULL;
62eb734b 808 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL;
51126deb
BZ
809 int status, rv;
810 void *handle;
62eb734b 811 struct rt_rtmp_os_netdev_op_hook netDevHook;
ca97b838
BZ
812
813 DBGPRINT(RT_DEBUG_TRACE, ("===>rt2870_probe()!\n"));
814
9f548a2a
BZ
815 /* Check chipset vendor/product ID */
816 /*if (RT28XXChipsetCheck(_dev_p) == FALSE) */
817 /* goto err_out; */
ca97b838 818
9f548a2a 819/*RtmpDevInit============================================= */
62eb734b 820 /* Allocate struct rt_rtmp_adapter adapter structure */
ca97b838 821 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
66cd8d6e
BZ
822 if (handle == NULL) {
823 printk
824 ("rt2870_probe(): Allocate memory for os handle failed!\n");
ca97b838
BZ
825 return -ENOMEM;
826 }
8a10a546 827 ((struct os_cookie *)handle)->pUsb_Dev = usb_dev;
ca97b838
BZ
828
829 rv = RTMPAllocAdapterBlock(handle, &pAd);
66cd8d6e 830 if (rv != NDIS_STATUS_SUCCESS) {
ca97b838
BZ
831 kfree(handle);
832 goto err_out;
833 }
9f548a2a 834/*USBDevInit============================================== */
ca97b838
BZ
835 if (USBDevConfigInit(usb_dev, intf, pAd) == FALSE)
836 goto err_out_free_radev;
837
838 RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_USB);
839
9f548a2a 840/*NetDevInit============================================== */
ca97b838
BZ
841 net_dev = RtmpPhyNetDevInit(pAd, &netDevHook);
842 if (net_dev == NULL)
843 goto err_out_free_radev;
844
9f548a2a 845 /* Here are the net_device structure with usb specific parameters. */
ca97b838 846 /* for supporting Network Manager.
66cd8d6e
BZ
847 * Set the sysfs physical device reference for the network logical device if set prior to registration will
848 * cause a symlink during initialization.
ca97b838
BZ
849 */
850 SET_NETDEV_DEV(net_dev, &(usb_dev->dev));
851
66cd8d6e 852 pAd->StaCfg.OriDevType = net_dev->type;
ca97b838 853
9f548a2a
BZ
854/*All done, it's time to register the net device to linux kernel. */
855 /* Register this device */
ca97b838
BZ
856 status = RtmpOSNetDevAttach(net_dev, &netDevHook);
857 if (status != 0)
858 goto err_out_free_netdev;
859
860#ifdef KTHREAD_SUPPORT
861 init_waitqueue_head(&pAd->mlmeTask.kthread_q);
862 init_waitqueue_head(&pAd->timerTask.kthread_q);
863 init_waitqueue_head(&pAd->cmdQTask.kthread_q);
864#endif
865
866 *ppAd = pAd;
867
868 DBGPRINT(RT_DEBUG_TRACE, ("<===rt2870_probe()!\n"));
869
870 return 0;
871
872 /* --------------------------- ERROR HANDLE --------------------------- */
873err_out_free_netdev:
874 RtmpOSNetDevFree(net_dev);
875
876err_out_free_radev:
877 RTMPFreeAdapter(pAd);
878
879err_out:
880 *ppAd = NULL;
881
882 return -1;
883
884}
This page took 0.104081 seconds and 5 git commands to generate.