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