blob: 322bf49ee90670ff1b5fb175998f782db94905d9 [file] [log] [blame]
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +02001/*
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
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -080029/* Following information will be show when you run 'modinfo' */
Justin P. Mattock6ccb5d72010-11-08 13:41:46 -080030/* If you have a solution for the bug in current version of driver, please e-mail me. */
31/* Otherwise post to the forum at ralinktech's web site(www.ralinktech.com) and let all users help you. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020032MODULE_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
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +020039/* module table */
40struct usb_device_id rtusb_usb_id[] = {
41#ifdef RT2870
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -080042 {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 */
Ben Hutchings9e693e42010-08-29 02:13:11 +010047 {USB_DEVICE(0x0DF6, 0x003F)}, /* Sitecom 2770 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -080048 {USB_DEVICE(0x083A, 0x7512)}, /* Arcadyan 2770 */
49 {USB_DEVICE(0x0789, 0x0162)}, /* Logitec 2870 */
50 {USB_DEVICE(0x0789, 0x0163)}, /* Logitec 2870 */
51 {USB_DEVICE(0x0789, 0x0164)}, /* Logitec 2870 */
52 {USB_DEVICE(0x177f, 0x0302)}, /* lsusb */
53 {USB_DEVICE(0x0B05, 0x1731)}, /* Asus */
54 {USB_DEVICE(0x0B05, 0x1732)}, /* Asus */
55 {USB_DEVICE(0x0B05, 0x1742)}, /* Asus */
56 {USB_DEVICE(0x0DF6, 0x0017)}, /* Sitecom */
57 {USB_DEVICE(0x0DF6, 0x002B)}, /* Sitecom */
58 {USB_DEVICE(0x0DF6, 0x002C)}, /* Sitecom */
59 {USB_DEVICE(0x0DF6, 0x002D)}, /* Sitecom */
60 {USB_DEVICE(0x14B2, 0x3C06)}, /* Conceptronic */
61 {USB_DEVICE(0x14B2, 0x3C28)}, /* Conceptronic */
62 {USB_DEVICE(0x2019, 0xED06)}, /* Planex Communications, Inc. */
63 {USB_DEVICE(0x07D1, 0x3C09)}, /* D-Link */
64 {USB_DEVICE(0x07D1, 0x3C11)}, /* D-Link */
65 {USB_DEVICE(0x14B2, 0x3C07)}, /* AL */
66 {USB_DEVICE(0x050D, 0x8053)}, /* Belkin */
Chris Largret12840c62010-03-03 05:24:26 -060067 {USB_DEVICE(0x050D, 0x825B)}, /* Belkin */
Larry Finger705059a2010-10-28 08:47:13 -050068 {USB_DEVICE(0x050D, 0x935A)}, /* Belkin F6D4050 v1 */
Larry Finger5d92fe32010-07-25 16:14:53 -050069 {USB_DEVICE(0x050D, 0x935B)}, /* Belkin F6D4050 v2 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -080070 {USB_DEVICE(0x14B2, 0x3C23)}, /* Airlink */
71 {USB_DEVICE(0x14B2, 0x3C27)}, /* Airlink */
72 {USB_DEVICE(0x07AA, 0x002F)}, /* Corega */
73 {USB_DEVICE(0x07AA, 0x003C)}, /* Corega */
74 {USB_DEVICE(0x07AA, 0x003F)}, /* Corega */
75 {USB_DEVICE(0x1044, 0x800B)}, /* Gigabyte */
76 {USB_DEVICE(0x15A9, 0x0006)}, /* Sparklan */
77 {USB_DEVICE(0x083A, 0xB522)}, /* SMC */
78 {USB_DEVICE(0x083A, 0xA618)}, /* SMC */
79 {USB_DEVICE(0x083A, 0x8522)}, /* Arcadyan */
80 {USB_DEVICE(0x083A, 0x7522)}, /* Arcadyan */
81 {USB_DEVICE(0x0CDE, 0x0022)}, /* ZCOM */
82 {USB_DEVICE(0x0586, 0x3416)}, /* Zyxel */
Ozan Çağlayan9674e572010-06-21 14:00:56 +030083 {USB_DEVICE(0x0586, 0x341a)}, /* Zyxel NWD-270N */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -080084 {USB_DEVICE(0x0CDE, 0x0025)}, /* Zyxel */
85 {USB_DEVICE(0x1740, 0x9701)}, /* EnGenius */
86 {USB_DEVICE(0x1740, 0x9702)}, /* EnGenius */
87 {USB_DEVICE(0x0471, 0x200f)}, /* Philips */
88 {USB_DEVICE(0x14B2, 0x3C25)}, /* Draytek */
89 {USB_DEVICE(0x13D3, 0x3247)}, /* AzureWave */
90 {USB_DEVICE(0x083A, 0x6618)}, /* Accton */
91 {USB_DEVICE(0x15c5, 0x0008)}, /* Amit */
92 {USB_DEVICE(0x0E66, 0x0001)}, /* Hawking */
93 {USB_DEVICE(0x0E66, 0x0003)}, /* Hawking */
94 {USB_DEVICE(0x129B, 0x1828)}, /* Siemens */
95 {USB_DEVICE(0x157E, 0x300E)}, /* U-Media */
96 {USB_DEVICE(0x050d, 0x805c)},
97 {USB_DEVICE(0x050d, 0x815c)},
98 {USB_DEVICE(0x1482, 0x3C09)}, /* Abocom */
99 {USB_DEVICE(0x14B2, 0x3C09)}, /* Alpha */
Ben Hutchings9e693e42010-08-29 02:13:11 +0100100 {USB_DEVICE(0x04E8, 0x2018)}, /* samsung linkstick2 */
101 {USB_DEVICE(0x1690, 0x0740)}, /* Askey */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800102 {USB_DEVICE(0x5A57, 0x0280)}, /* Zinwell */
103 {USB_DEVICE(0x5A57, 0x0282)}, /* Zinwell */
104 {USB_DEVICE(0x7392, 0x7718)},
105 {USB_DEVICE(0x7392, 0x7717)},
Nobuhiro KUSUNOde37cd42010-05-06 05:23:28 +0900106 {USB_DEVICE(0x0411, 0x016f)}, /* MelCo.,Inc. WLI-UC-G301N */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800107 {USB_DEVICE(0x1737, 0x0070)}, /* Linksys WUSB100 */
108 {USB_DEVICE(0x1737, 0x0071)}, /* Linksys WUSB600N */
Larry Finger27c82812011-01-12 22:24:28 -0600109 {USB_DEVICE(0x1737, 0x0078)}, /* Linksys WUSB100v2 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800110 {USB_DEVICE(0x0411, 0x00e8)}, /* Buffalo WLI-UC-G300N */
111 {USB_DEVICE(0x050d, 0x815c)}, /* Belkin F5D8053 */
Ben Hutchings9e693e42010-08-29 02:13:11 +0100112 {USB_DEVICE(0x100D, 0x9031)}, /* Motorola 2770 */
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800113#endif /* RT2870 // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200114#ifdef RT3070
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800115 {USB_DEVICE(0x148F, 0x3070)}, /* Ralink 3070 */
116 {USB_DEVICE(0x148F, 0x3071)}, /* Ralink 3071 */
117 {USB_DEVICE(0x148F, 0x3072)}, /* Ralink 3072 */
118 {USB_DEVICE(0x0DB0, 0x3820)}, /* Ralink 3070 */
Ben Hutchings9e693e42010-08-29 02:13:11 +0100119 {USB_DEVICE(0x0DB0, 0x871C)}, /* Ralink 3070 */
120 {USB_DEVICE(0x0DB0, 0x822C)}, /* Ralink 3070 */
121 {USB_DEVICE(0x0DB0, 0x871B)}, /* Ralink 3070 */
122 {USB_DEVICE(0x0DB0, 0x822B)}, /* Ralink 3070 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800123 {USB_DEVICE(0x0DF6, 0x003E)}, /* Sitecom 3070 */
124 {USB_DEVICE(0x0DF6, 0x0042)}, /* Sitecom 3072 */
Ben Hutchings9e693e42010-08-29 02:13:11 +0100125 {USB_DEVICE(0x0DF6, 0x0048)}, /* Sitecom 3070 */
126 {USB_DEVICE(0x0DF6, 0x0047)}, /* Sitecom 3071 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800127 {USB_DEVICE(0x14B2, 0x3C12)}, /* AL 3070 */
128 {USB_DEVICE(0x18C5, 0x0012)}, /* Corega 3070 */
129 {USB_DEVICE(0x083A, 0x7511)}, /* Arcadyan 3070 */
Ben Hutchings9e693e42010-08-29 02:13:11 +0100130 {USB_DEVICE(0x083A, 0xA701)}, /* SMC 3070 */
131 {USB_DEVICE(0x083A, 0xA702)}, /* SMC 3072 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800132 {USB_DEVICE(0x1740, 0x9703)}, /* EnGenius 3070 */
133 {USB_DEVICE(0x1740, 0x9705)}, /* EnGenius 3071 */
134 {USB_DEVICE(0x1740, 0x9706)}, /* EnGenius 3072 */
Ben Hutchings9e693e42010-08-29 02:13:11 +0100135 {USB_DEVICE(0x1740, 0x9707)}, /* EnGenius 3070 */
136 {USB_DEVICE(0x1740, 0x9708)}, /* EnGenius 3071 */
137 {USB_DEVICE(0x1740, 0x9709)}, /* EnGenius 3072 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800138 {USB_DEVICE(0x13D3, 0x3273)}, /* AzureWave 3070 */
Ben Hutchings9e693e42010-08-29 02:13:11 +0100139 {USB_DEVICE(0x13D3, 0x3305)}, /* AzureWave 3070*/
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800140 {USB_DEVICE(0x1044, 0x800D)}, /* Gigabyte GN-WB32L 3070 */
141 {USB_DEVICE(0x2019, 0xAB25)}, /* Planex Communications, Inc. RT3070 */
142 {USB_DEVICE(0x07B8, 0x3070)}, /* AboCom 3070 */
143 {USB_DEVICE(0x07B8, 0x3071)}, /* AboCom 3071 */
144 {USB_DEVICE(0x07B8, 0x3072)}, /* Abocom 3072 */
145 {USB_DEVICE(0x7392, 0x7711)}, /* Edimax 3070 */
146 {USB_DEVICE(0x1A32, 0x0304)}, /* Quanta 3070 */
147 {USB_DEVICE(0x1EDA, 0x2310)}, /* AirTies 3070 */
148 {USB_DEVICE(0x07D1, 0x3C0A)}, /* D-Link 3072 */
149 {USB_DEVICE(0x07D1, 0x3C0D)}, /* D-Link 3070 */
150 {USB_DEVICE(0x07D1, 0x3C0E)}, /* D-Link 3070 */
151 {USB_DEVICE(0x07D1, 0x3C0F)}, /* D-Link 3070 */
Ben Hutchings9e693e42010-08-29 02:13:11 +0100152 {USB_DEVICE(0x07D1, 0x3C16)}, /* D-Link 3070 */
153 {USB_DEVICE(0x07D1, 0x3C17)}, /* D-Link 8070 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800154 {USB_DEVICE(0x1D4D, 0x000C)}, /* Pegatron Corporation 3070 */
155 {USB_DEVICE(0x1D4D, 0x000E)}, /* Pegatron Corporation 3070 */
156 {USB_DEVICE(0x5A57, 0x5257)}, /* Zinwell 3070 */
157 {USB_DEVICE(0x5A57, 0x0283)}, /* Zinwell 3072 */
158 {USB_DEVICE(0x04BB, 0x0945)}, /* I-O DATA 3072 */
Ben Hutchings9e693e42010-08-29 02:13:11 +0100159 {USB_DEVICE(0x04BB, 0x0947)}, /* I-O DATA 3070 */
160 {USB_DEVICE(0x04BB, 0x0948)}, /* I-O DATA 3072 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800161 {USB_DEVICE(0x203D, 0x1480)}, /* Encore 3070 */
Ben Hutchings9e693e42010-08-29 02:13:11 +0100162 {USB_DEVICE(0x20B8, 0x8888)}, /* PARA INDUSTRIAL 3070 */
163 {USB_DEVICE(0x0B05, 0x1784)}, /* Asus 3072 */
164 {USB_DEVICE(0x203D, 0x14A9)}, /* Encore 3070*/
165 {USB_DEVICE(0x0DB0, 0x899A)}, /* MSI 3070*/
166 {USB_DEVICE(0x0DB0, 0x3870)}, /* MSI 3070*/
167 {USB_DEVICE(0x0DB0, 0x870A)}, /* MSI 3070*/
168 {USB_DEVICE(0x0DB0, 0x6899)}, /* MSI 3070 */
169 {USB_DEVICE(0x0DB0, 0x3822)}, /* MSI 3070 */
170 {USB_DEVICE(0x0DB0, 0x3871)}, /* MSI 3070 */
171 {USB_DEVICE(0x0DB0, 0x871A)}, /* MSI 3070 */
172 {USB_DEVICE(0x0DB0, 0x822A)}, /* MSI 3070 */
173 {USB_DEVICE(0x0DB0, 0x3821)}, /* Ralink 3070 */
174 {USB_DEVICE(0x0DB0, 0x821A)}, /* Ralink 3070 */
175 {USB_DEVICE(0x083A, 0xA703)}, /* IO-MAGIC */
176 {USB_DEVICE(0x13D3, 0x3307)}, /* Azurewave */
177 {USB_DEVICE(0x13D3, 0x3321)}, /* Azurewave */
178 {USB_DEVICE(0x07FA, 0x7712)}, /* Edimax */
179 {USB_DEVICE(0x0789, 0x0166)}, /* Edimax */
180 {USB_DEVICE(0x148F, 0x2070)}, /* Edimax */
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800181#endif /* RT3070 // */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800182 {USB_DEVICE(0x1737, 0x0077)}, /* Linksys WUSB54GC-EU v3 */
183 {USB_DEVICE(0x2001, 0x3C09)}, /* D-Link */
184 {USB_DEVICE(0x2001, 0x3C0A)}, /* D-Link 3072 */
185 {USB_DEVICE(0x2019, 0xED14)}, /* Planex Communications, Inc. */
John Tapsell251d3802010-03-25 13:30:45 +0000186 {USB_DEVICE(0x0411, 0x015D)}, /* Buffalo Airstation WLI-UC-GN */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800187 {} /* Terminating entry */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200188};
189
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800190int const rtusb_usb_id_len =
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800191 sizeof(rtusb_usb_id) / sizeof(struct usb_device_id);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200192
193MODULE_DEVICE_TABLE(usb, rtusb_usb_id);
194
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800195static void rt2870_disconnect(struct usb_device *dev, struct rt_rtmp_adapter *pAd);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200196
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800197static int __devinit rt2870_probe(IN struct usb_interface *intf,
198 IN struct usb_device *usb_dev,
199 IN const struct usb_device_id *dev_id,
Trey Evansa3327f02010-04-19 16:15:37 -0400200 struct rt_rtmp_adapter **ppAd);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200201
202#ifndef PF_NOFREEZE
203#define PF_NOFREEZE 0
204#endif
205
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200206extern int rt28xx_close(IN struct net_device *net_dev);
207extern int rt28xx_open(struct net_device *net_dev);
208
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800209static BOOLEAN USBDevConfigInit(IN struct usb_device *dev,
210 IN struct usb_interface *intf,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800211 struct rt_rtmp_adapter *pAd);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200212
213/*
214========================================================================
215Routine Description:
216 Check the chipset vendor/product ID.
217
218Arguments:
219 _dev_p Point to the PCI or USB device
220
221Return Value:
222 TRUE Check ok
223 FALSE Check fail
224
225Note:
226========================================================================
227*/
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800228BOOLEAN RT28XXChipsetCheck(IN void *_dev_p)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200229{
230 struct usb_interface *intf = (struct usb_interface *)_dev_p;
231 struct usb_device *dev_p = interface_to_usbdev(intf);
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800232 u32 i;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200233
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800234 for (i = 0; i < rtusb_usb_id_len; i++) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200235 if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor &&
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800236 dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct) {
L. Alberto Giménez3be305f2010-12-14 02:01:54 +0100237 printk(KERN_INFO "rt2870: idVendor = 0x%x, idProduct = 0x%x\n",
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800238 dev_p->descriptor.idVendor,
239 dev_p->descriptor.idProduct);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200240 break;
241 }
242 }
243
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800244 if (i == rtusb_usb_id_len) {
L. Alberto Giménez3be305f2010-12-14 02:01:54 +0100245 printk(KERN_ERR "rt2870: Error! Device Descriptor not matching!\n");
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200246 return FALSE;
247 }
248
249 return TRUE;
250}
251
252/**************************************************************************/
253/**************************************************************************/
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800254/*tested for kernel 2.6series */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200255/**************************************************************************/
256/**************************************************************************/
257
258#ifdef CONFIG_PM
259static int rt2870_suspend(struct usb_interface *intf, pm_message_t state);
260static int rt2870_resume(struct usb_interface *intf);
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800261#endif /* CONFIG_PM // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200262
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800263static BOOLEAN USBDevConfigInit(IN struct usb_device *dev,
264 IN struct usb_interface *intf,
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800265 struct rt_rtmp_adapter *pAd)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200266{
267 struct usb_host_interface *iface_desc;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800268 unsigned long BulkOutIdx;
269 u32 i;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200270
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200271 /* get the active interface descriptor */
272 iface_desc = intf->cur_altsetting;
273
274 /* get # of enpoints */
275 pAd->NumberOfPipes = iface_desc->desc.bNumEndpoints;
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800276 DBGPRINT(RT_DEBUG_TRACE,
277 ("NumEndpoints=%d\n", iface_desc->desc.bNumEndpoints));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200278
279 /* Configure Pipes */
280 BulkOutIdx = 0;
281
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800282 for (i = 0; i < pAd->NumberOfPipes; i++) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200283 if ((iface_desc->endpoint[i].desc.bmAttributes ==
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800284 USB_ENDPOINT_XFER_BULK) &&
285 ((iface_desc->endpoint[i].desc.bEndpointAddress &
286 USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)) {
287 pAd->BulkInEpAddr =
288 iface_desc->endpoint[i].desc.bEndpointAddress;
289 pAd->BulkInMaxPacketSize =
290 le2cpu16(iface_desc->endpoint[i].desc.
291 wMaxPacketSize);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200292
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800293 DBGPRINT_RAW(RT_DEBUG_TRACE,
294 ("BULK IN MaxPacketSize = %d\n",
295 pAd->BulkInMaxPacketSize));
296 DBGPRINT_RAW(RT_DEBUG_TRACE,
297 ("EP address = 0x%2x\n",
298 iface_desc->endpoint[i].desc.
299 bEndpointAddress));
300 } else
301 if ((iface_desc->endpoint[i].desc.bmAttributes ==
302 USB_ENDPOINT_XFER_BULK)
303 &&
304 ((iface_desc->endpoint[i].desc.
305 bEndpointAddress & USB_ENDPOINT_DIR_MASK) ==
306 USB_DIR_OUT)) {
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800307 /* there are 6 bulk out EP. EP6 highest priority. */
308 /* EP1-4 is EDCA. EP5 is HCCA. */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800309 pAd->BulkOutEpAddr[BulkOutIdx++] =
310 iface_desc->endpoint[i].desc.bEndpointAddress;
311 pAd->BulkOutMaxPacketSize =
312 le2cpu16(iface_desc->endpoint[i].desc.
313 wMaxPacketSize);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200314
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800315 DBGPRINT_RAW(RT_DEBUG_TRACE,
316 ("BULK OUT MaxPacketSize = %d\n",
317 pAd->BulkOutMaxPacketSize));
318 DBGPRINT_RAW(RT_DEBUG_TRACE,
319 ("EP address = 0x%2x \n",
320 iface_desc->endpoint[i].desc.
321 bEndpointAddress));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200322 }
323 }
324
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800325 if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0])) {
326 printk
L. Alberto Giménez3be305f2010-12-14 02:01:54 +0100327 (KERN_ERR "%s: Could not find both bulk-in and bulk-out endpoints\n",
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800328 __FUNCTION__);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200329 return FALSE;
330 }
331
332 pAd->config = &dev->config->desc;
333 usb_set_intfdata(intf, pAd);
334
335 return TRUE;
336
337}
338
Simon Hormanc33c2062009-12-23 19:54:50 +1100339static int __devinit rtusb_probe(struct usb_interface *intf,
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800340 const struct usb_device_id *id)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200341{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800342 struct rt_rtmp_adapter *pAd;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200343 struct usb_device *dev;
344 int rv;
345
346 dev = interface_to_usbdev(intf);
347 dev = usb_get_dev(dev);
348
349 rv = rt2870_probe(intf, dev, id, &pAd);
350 if (rv != 0)
351 usb_put_dev(dev);
352
353 return rv;
354}
355
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200356static void rtusb_disconnect(struct usb_interface *intf)
357{
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800358 struct usb_device *dev = interface_to_usbdev(intf);
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800359 struct rt_rtmp_adapter *pAd;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200360
361 pAd = usb_get_intfdata(intf);
362 usb_set_intfdata(intf, NULL);
363
364 rt2870_disconnect(dev, pAd);
365}
366
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200367struct usb_driver rtusb_driver = {
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800368 .name = "rt2870",
369 .probe = rtusb_probe,
370 .disconnect = rtusb_disconnect,
371 .id_table = rtusb_usb_id,
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200372
373#ifdef CONFIG_PM
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800374suspend:rt2870_suspend,
375resume:rt2870_resume,
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200376#endif
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800377};
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200378
379#ifdef CONFIG_PM
380
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800381void RT2870RejectPendingPackets(struct rt_rtmp_adapter *pAd)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200382{
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800383 /* clear PS packets */
384 /* clear TxSw packets */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200385}
386
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800387static int rt2870_suspend(struct usb_interface *intf, pm_message_t state)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200388{
389 struct net_device *net_dev;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800390 struct rt_rtmp_adapter *pAd = usb_get_intfdata(intf);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200391
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200392 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_suspend()\n"));
393 net_dev = pAd->net_dev;
394 netif_device_detach(net_dev);
395
396 pAd->PM_FlgSuspend = 1;
397 if (netif_running(net_dev)) {
398 RTUSBCancelPendingBulkInIRP(pAd);
399 RTUSBCancelPendingBulkOutIRP(pAd);
400 }
401 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_suspend()\n"));
402 return 0;
403}
404
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800405static int rt2870_resume(struct usb_interface *intf)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200406{
407 struct net_device *net_dev;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800408 struct rt_rtmp_adapter *pAd = usb_get_intfdata(intf);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200409
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200410 DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_resume()\n"));
411
412 pAd->PM_FlgSuspend = 0;
413 net_dev = pAd->net_dev;
414 netif_device_attach(net_dev);
415 netif_start_queue(net_dev);
416 netif_carrier_on(net_dev);
417 netif_wake_queue(net_dev);
418
419 DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_resume()\n"));
420 return 0;
421}
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800422#endif /* CONFIG_PM // */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200423
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800424/* Init driver module */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800425int __init rtusb_init(void)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200426{
L. Alberto Giménez3be305f2010-12-14 02:01:54 +0100427 printk(KERN_DEBUG "rtusb init --->\n");
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200428 return usb_register(&rtusb_driver);
429}
430
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800431/* Deinit driver module */
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800432void __exit rtusb_exit(void)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200433{
434 usb_deregister(&rtusb_driver);
L. Alberto Giménez3be305f2010-12-14 02:01:54 +0100435 printk(KERN_DEBUG "<--- rtusb exit\n");
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200436}
437
438module_init(rtusb_init);
439module_exit(rtusb_exit);
440
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200441/*--------------------------------------------------------------------- */
442/* function declarations */
443/*--------------------------------------------------------------------- */
444
445/*
446========================================================================
447Routine Description:
448 MLME kernel thread.
449
450Arguments:
451 *Context the pAd, driver control block pointer
452
453Return Value:
454 0 close the thread
455
456Note:
457========================================================================
458*/
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800459int MlmeThread(IN void *Context)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200460{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800461 struct rt_rtmp_adapter *pAd;
462 struct rt_rtmp_os_task *pTask;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200463 int status;
464 status = 0;
465
Kulikov Vasiliyef7d8ba2010-06-29 14:16:12 +0400466 pTask = Context;
467 pAd = pTask->priv;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200468
469 RtmpOSTaskCustomize(pTask);
470
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800471 while (!pTask->task_killed) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200472#ifdef KTHREAD_SUPPORT
473 RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask);
474#else
475 RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status);
476
477 /* unlock the device pointers */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800478 if (status != 0) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200479 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
480 break;
481 }
482#endif
483
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800484 /* lock the device pointers , need to check if required */
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800485 /*down(&(pAd->usbdev_semaphore)); */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200486
487 if (!pAd->PM_FlgSuspend)
488 MlmeHandler(pAd);
489 }
490
491 /* notify the exit routine that we're actually exiting now
492 *
493 * complete()/wait_for_completion() is similar to up()/down(),
494 * except that complete() is safe in the case where the structure
495 * is getting deleted in a parallel mode of execution (i.e. just
496 * after the down() -- that's necessary for the thread-shutdown
497 * case.
498 *
499 * complete_and_exit() goes even further than this -- it is safe in
500 * the case that the thread of the caller is going away (not just
501 * the structure) -- this is necessary for the module-remove case.
502 * This is important in preemption kernels, which transfer the flow
503 * of execution immediately upon a complete().
504 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800505 DBGPRINT(RT_DEBUG_TRACE, ("<---%s\n", __FUNCTION__));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200506#ifndef KTHREAD_SUPPORT
507 pTask->taskPID = THREAD_PID_INIT_VALUE;
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800508 complete_and_exit(&pTask->taskComplete, 0);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200509#endif
510 return 0;
511
512}
513
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200514/*
515========================================================================
516Routine Description:
517 USB command kernel thread.
518
519Arguments:
520 *Context the pAd, driver control block pointer
521
522Return Value:
523 0 close the thread
524
525Note:
526========================================================================
527*/
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800528int RTUSBCmdThread(IN void *Context)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200529{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800530 struct rt_rtmp_adapter *pAd;
531 struct rt_rtmp_os_task *pTask;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200532 int status;
533 status = 0;
534
Kulikov Vasiliyef7d8ba2010-06-29 14:16:12 +0400535 pTask = Context;
536 pAd = pTask->priv;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200537
538 RtmpOSTaskCustomize(pTask);
539
540 NdisAcquireSpinLock(&pAd->CmdQLock);
541 pAd->CmdQ.CmdQState = RTMP_TASK_STAT_RUNNING;
542 NdisReleaseSpinLock(&pAd->CmdQLock);
543
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800544 while (pAd && pAd->CmdQ.CmdQState == RTMP_TASK_STAT_RUNNING) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200545#ifdef KTHREAD_SUPPORT
546 RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask);
547#else
548 /* lock the device pointers */
549 RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status);
550
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800551 if (status != 0) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200552 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS);
553 break;
554 }
555#endif
556
557 if (pAd->CmdQ.CmdQState == RTMP_TASK_STAT_STOPED)
558 break;
559
560 if (!pAd->PM_FlgSuspend)
561 CMDHandler(pAd);
562 }
563
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800564 if (pAd && !pAd->PM_FlgSuspend) { /* Clear the CmdQElements. */
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800565 struct rt_cmdqelmt *pCmdQElmt = NULL;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200566
567 NdisAcquireSpinLock(&pAd->CmdQLock);
568 pAd->CmdQ.CmdQState = RTMP_TASK_STAT_STOPED;
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800569 while (pAd->CmdQ.size) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200570 RTUSBDequeueCmd(&pAd->CmdQ, &pCmdQElmt);
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800571 if (pCmdQElmt) {
572 if (pCmdQElmt->CmdFromNdis == TRUE) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200573 if (pCmdQElmt->buffer != NULL)
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800574 os_free_mem(pAd,
575 pCmdQElmt->buffer);
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800576 os_free_mem(pAd, (u8 *)pCmdQElmt);
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800577 } else {
578 if ((pCmdQElmt->buffer != NULL)
579 && (pCmdQElmt->bufferlength != 0))
580 os_free_mem(pAd,
581 pCmdQElmt->buffer);
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800582 os_free_mem(pAd, (u8 *)pCmdQElmt);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200583 }
584 }
585 }
586
587 NdisReleaseSpinLock(&pAd->CmdQLock);
588 }
589 /* notify the exit routine that we're actually exiting now
590 *
591 * complete()/wait_for_completion() is similar to up()/down(),
592 * except that complete() is safe in the case where the structure
593 * is getting deleted in a parallel mode of execution (i.e. just
594 * after the down() -- that's necessary for the thread-shutdown
595 * case.
596 *
597 * complete_and_exit() goes even further than this -- it is safe in
598 * the case that the thread of the caller is going away (not just
599 * the structure) -- this is necessary for the module-remove case.
600 * This is important in preemption kernels, which transfer the flow
601 * of execution immediately upon a complete().
602 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800603 DBGPRINT(RT_DEBUG_TRACE, ("<---RTUSBCmdThread\n"));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200604
605#ifndef KTHREAD_SUPPORT
606 pTask->taskPID = THREAD_PID_INIT_VALUE;
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800607 complete_and_exit(&pTask->taskComplete, 0);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200608#endif
609 return 0;
610
611}
612
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800613void RTUSBWatchDog(struct rt_rtmp_adapter *pAd)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200614{
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800615 struct rt_ht_tx_context *pHTTXContext;
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800616 int idx;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800617 unsigned long irqFlags;
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800618 PURB pUrb;
619 BOOLEAN needDumpSeq = FALSE;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800620 u32 MACValue;
621 u32 TxRxQ_Pcnt;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200622
623 idx = 0;
624 RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800625 if ((MACValue & 0xff) != 0) {
626 DBGPRINT(RT_DEBUG_TRACE,
Sebastian Dalfuß06aea992009-11-07 17:31:12 +0100627 ("TX QUEUE 0 Not EMPTY(Value=0x%0x)!\n",
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800628 MACValue));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200629 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40012);
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800630 while ((MACValue & 0xff) != 0 && (idx++ < 10)) {
631 RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue);
632 RTMPusecDelay(1);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200633 }
634 RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40006);
635 }
636
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800637 if (pAd->watchDogRxOverFlowCnt >= 2) {
638 DBGPRINT(RT_DEBUG_TRACE,
639 ("Maybe the Rx Bulk-In hanged! Cancel the pending Rx bulks request!\n"));
640 if ((!RTMP_TEST_FLAG
641 (pAd,
642 (fRTMP_ADAPTER_RESET_IN_PROGRESS |
643 fRTMP_ADAPTER_BULKIN_RESET |
644 fRTMP_ADAPTER_HALT_IN_PROGRESS |
645 fRTMP_ADAPTER_NIC_NOT_EXIST)))) {
646 DBGPRINT(RT_DEBUG_TRACE,
647 ("Call CMDTHREAD_RESET_BULK_IN to cancel the pending Rx Bulk!\n"));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200648 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET);
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800649 RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN,
650 NULL, 0);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200651 needDumpSeq = TRUE;
652 }
653 pAd->watchDogRxOverFlowCnt = 0;
654 }
655
656 RTUSBReadMACRegister(pAd, 0x438, &TxRxQ_Pcnt);
657
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800658 for (idx = 0; idx < NUM_OF_TX_RING; idx++) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200659 pUrb = NULL;
660
661 RTMP_IRQ_LOCK(&pAd->BulkOutLock[idx], irqFlags);
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800662 if ((pAd->BulkOutPending[idx] == TRUE)
663 && pAd->watchDogTxPendingCnt) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800664 int actual_length = 0, transfer_buffer_length = 0;
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800665 BOOLEAN isDataPacket = FALSE;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200666 pAd->watchDogTxPendingCnt[idx]++;
667
668 if ((pAd->watchDogTxPendingCnt[idx] > 2) &&
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800669 (!RTMP_TEST_FLAG
670 (pAd,
671 (fRTMP_ADAPTER_RESET_IN_PROGRESS |
672 fRTMP_ADAPTER_HALT_IN_PROGRESS |
673 fRTMP_ADAPTER_NIC_NOT_EXIST |
674 fRTMP_ADAPTER_BULKOUT_RESET)))
675 ) {
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800676 /* FIXME: Following code just support single bulk out. If you wanna support multiple bulk out. Modify it! */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800677 pHTTXContext =
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800678 (struct rt_ht_tx_context *)(&pAd->TxContext[idx]);
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800679 if (pHTTXContext->IRPPending) { /* Check TxContext. */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200680 pUrb = pHTTXContext->pUrb;
681
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800682 actual_length = pUrb->actual_length;
683 transfer_buffer_length =
684 pUrb->transfer_buffer_length;
685 isDataPacket = TRUE;
686 } else if (idx == MGMTPIPEIDX) {
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800687 struct rt_tx_context *pMLMEContext, *pNULLContext,
688 *pPsPollContext;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200689
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800690 /*Check MgmtContext. */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800691 pMLMEContext =
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800692 (struct rt_tx_context *)(pAd->MgmtRing.
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800693 Cell[pAd->MgmtRing.
694 TxDmaIdx].
695 AllocVa);
696 pPsPollContext =
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800697 (struct rt_tx_context *)(&pAd->PsPollContext);
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800698 pNULLContext =
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800699 (struct rt_tx_context *)(&pAd->NullContext);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200700
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800701 if (pMLMEContext->IRPPending) {
702 ASSERT(pMLMEContext->
703 IRPPending);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200704 pUrb = pMLMEContext->pUrb;
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800705 } else if (pNULLContext->IRPPending) {
706 ASSERT(pNULLContext->
707 IRPPending);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200708 pUrb = pNULLContext->pUrb;
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800709 } else if (pPsPollContext->IRPPending) {
710 ASSERT(pPsPollContext->
711 IRPPending);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200712 pUrb = pPsPollContext->pUrb;
713 }
714 }
715
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800716 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx],
717 irqFlags);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200718
Bartlomiej Zolnierkiewiczca58fb32009-10-21 22:44:42 +0200719 printk(KERN_INFO "%d:%lu LTL=%d , TL=%d L:%d\n",
720 idx, pAd->watchDogTxPendingCnt[idx],
721 pAd->TransferedLength[idx],
722 actual_length, transfer_buffer_length);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200723
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800724 if (pUrb) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200725 if ((isDataPacket
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800726 && pAd->TransferedLength[idx] ==
727 actual_length
728 && pAd->TransferedLength[idx] <
729 transfer_buffer_length
730 && actual_length != 0
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800731/* && TxRxQ_Pcnt==0 */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800732 && pAd->watchDogTxPendingCnt[idx] >
733 3)
734 || isDataPacket == FALSE
735 || pAd->watchDogTxPendingCnt[idx] >
736 6) {
737 DBGPRINT(RT_DEBUG_TRACE,
738 ("Maybe the Tx Bulk-Out hanged! Cancel the pending Tx bulks request of idx(%d)!\n",
739 idx));
740 DBGPRINT(RT_DEBUG_TRACE,
741 ("Unlink the pending URB!\n"));
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800742 /* unlink it now */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800743 RTUSB_UNLINK_URB(pUrb);
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800744 /* Sleep 200 microseconds to give cancellation time to work */
745 /*RTMPusecDelay(200); */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800746 needDumpSeq = TRUE;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200747 }
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800748 } else {
749 DBGPRINT(RT_DEBUG_ERROR,
Sebastian Dalfuß06aea992009-11-07 17:31:12 +0100750 ("Unknown bulkOut URB maybe hanged!\n"));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200751 }
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800752 } else {
753 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx],
754 irqFlags);
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200755 }
756
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800757 if (isDataPacket == TRUE)
758 pAd->TransferedLength[idx] = actual_length;
759 } else {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200760 RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags);
761 }
762 }
763
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800764 /* For Sigma debug, dump the ba_reordering sequence. */
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800765 if ((needDumpSeq == TRUE) && (pAd->CommonCfg.bDisableReordering == 0)) {
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800766 u16 Idx;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800767 struct rt_ba_rec_entry *pBAEntry = NULL;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800768 u8 count = 0;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200769 struct reordering_mpdu *mpdu_blk;
770
771 Idx = pAd->MacTab.Content[BSSID_WCID].BARecWcidArray[0];
772
773 pBAEntry = &pAd->BATable.BARecEntry[Idx];
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800774 if ((pBAEntry->list.qlen > 0) && (pBAEntry->list.next != NULL)) {
775 DBGPRINT(RT_DEBUG_TRACE,
776 ("NICUpdateRawCounters():The Queueing pkt in reordering buffer:\n"));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200777 NdisAcquireSpinLock(&pBAEntry->RxReRingLock);
778 mpdu_blk = pBAEntry->list.next;
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800779 while (mpdu_blk) {
780 DBGPRINT(RT_DEBUG_TRACE,
781 ("\t%d:Seq-%d, bAMSDU-%d!\n", count,
782 mpdu_blk->Sequence,
783 mpdu_blk->bAMSDU));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200784 mpdu_blk = mpdu_blk->next;
785 count++;
786 }
787
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800788 DBGPRINT(RT_DEBUG_TRACE,
789 ("\npBAEntry->LastIndSeq=%d!\n",
790 pBAEntry->LastIndSeq));
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200791 NdisReleaseSpinLock(&pBAEntry->RxReRingLock);
792 }
793 }
794}
795
796/*
797========================================================================
798Routine Description:
799 Release allocated resources.
800
801Arguments:
802 *dev Point to the PCI or USB device
803 pAd driver control block pointer
804
805Return Value:
806 None
807
808Note:
809========================================================================
810*/
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800811static void rt2870_disconnect(struct usb_device *dev, struct rt_rtmp_adapter *pAd)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200812{
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800813 DBGPRINT(RT_DEBUG_ERROR,
814 ("rtusb_disconnect: unregister usbnet usb-%s-%s\n",
815 dev->bus->bus_name, dev->devpath));
816 if (!pAd) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200817 usb_put_dev(dev);
L. Alberto Giménez3be305f2010-12-14 02:01:54 +0100818 printk(KERN_ERR "rtusb_disconnect: pAd == NULL!\n");
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200819 return;
820 }
821 RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST);
822
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800823 /* for debug, wait to show some messages to /proc system */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200824 udelay(1);
825
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200826 RtmpPhyNetDevExit(pAd, pAd->net_dev);
827
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800828 /* FIXME: Shall we need following delay and flush the schedule?? */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200829 udelay(1);
830 flush_scheduled_work();
831 udelay(1);
832
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800833 /* free the root net_device */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200834 RtmpOSNetDevFree(pAd->net_dev);
835
836 RtmpRaDevCtrlExit(pAd);
837
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800838 /* release a use of the usb device structure */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200839 usb_put_dev(dev);
840 udelay(1);
841
842 DBGPRINT(RT_DEBUG_ERROR, (" RTUSB disconnect successfully\n"));
843}
844
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800845static int __devinit rt2870_probe(IN struct usb_interface *intf,
846 IN struct usb_device *usb_dev,
847 IN const struct usb_device_id *dev_id,
Trey Evansa3327f02010-04-19 16:15:37 -0400848 struct rt_rtmp_adapter **ppAd)
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200849{
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800850 struct net_device *net_dev = NULL;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800851 struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL;
Bartlomiej Zolnierkiewicz51126de2009-12-11 12:23:15 -0800852 int status, rv;
853 void *handle;
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800854 struct rt_rtmp_os_netdev_op_hook netDevHook;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200855
856 DBGPRINT(RT_DEBUG_TRACE, ("===>rt2870_probe()!\n"));
857
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800858 /* Check chipset vendor/product ID */
859 /*if (RT28XXChipsetCheck(_dev_p) == FALSE) */
860 /* goto err_out; */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200861
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800862/*RtmpDevInit============================================= */
Bartlomiej Zolnierkiewicz62eb7342009-12-11 12:23:16 -0800863 /* Allocate struct rt_rtmp_adapter adapter structure */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200864 handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL);
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800865 if (handle == NULL) {
866 printk
867 ("rt2870_probe(): Allocate memory for os handle failed!\n");
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200868 return -ENOMEM;
869 }
Bartlomiej Zolnierkiewicz8a10a542009-12-11 12:23:15 -0800870 ((struct os_cookie *)handle)->pUsb_Dev = usb_dev;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200871
872 rv = RTMPAllocAdapterBlock(handle, &pAd);
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800873 if (rv != NDIS_STATUS_SUCCESS) {
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200874 kfree(handle);
875 goto err_out;
876 }
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800877/*USBDevInit============================================== */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200878 if (USBDevConfigInit(usb_dev, intf, pAd) == FALSE)
879 goto err_out_free_radev;
880
881 RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_USB);
882
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800883/*NetDevInit============================================== */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200884 net_dev = RtmpPhyNetDevInit(pAd, &netDevHook);
885 if (net_dev == NULL)
886 goto err_out_free_radev;
887
Justin P. Mattock6ccb5d72010-11-08 13:41:46 -0800888 /* Here are the net_device structure with usb specific parameters.
889 * for supporting Network Manager.
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800890 * Set the sysfs physical device reference for the network logical device if set prior to registration will
891 * cause a symlink during initialization.
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200892 */
893 SET_NETDEV_DEV(net_dev, &(usb_dev->dev));
894
Bartlomiej Zolnierkiewicz66cd8d62009-12-11 12:23:13 -0800895 pAd->StaCfg.OriDevType = net_dev->type;
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200896
Bartlomiej Zolnierkiewicz9f548a22009-12-11 12:23:14 -0800897/*All done, it's time to register the net device to linux kernel. */
898 /* Register this device */
Bartlomiej Zolnierkiewiczca97b832009-09-22 20:44:07 +0200899 status = RtmpOSNetDevAttach(net_dev, &netDevHook);
900 if (status != 0)
901 goto err_out_free_netdev;
902
903#ifdef KTHREAD_SUPPORT
904 init_waitqueue_head(&pAd->mlmeTask.kthread_q);
905 init_waitqueue_head(&pAd->timerTask.kthread_q);
906 init_waitqueue_head(&pAd->cmdQTask.kthread_q);
907#endif
908
909 *ppAd = pAd;
910
911 DBGPRINT(RT_DEBUG_TRACE, ("<===rt2870_probe()!\n"));
912
913 return 0;
914
915 /* --------------------------- ERROR HANDLE --------------------------- */
916err_out_free_netdev:
917 RtmpOSNetDevFree(net_dev);
918
919err_out_free_radev:
920 RTMPFreeAdapter(pAd);
921
922err_out:
923 *ppAd = NULL;
924
925 return -1;
926
927}