Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6] / drivers / staging / wlan-ng / prism2_usb.c
1 #define WLAN_HOSTIF WLAN_USB
2 #include "hfa384x_usb.c"
3 #include "prism2mgmt.c"
4 #include "prism2mib.c"
5 #include "prism2sta.c"
6
7 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0))
8 #error "prism2_usb requires at least a 2.4.x kernel!"
9 #endif
10
11 #define PRISM_USB_DEVICE(vid, pid, name) \
12            USB_DEVICE(vid, pid),  \
13            .driver_info = (unsigned long) name
14
15 static struct usb_device_id usb_prism_tbl[] = {
16         {PRISM_USB_DEVICE(0x04bb, 0x0922, "IOData AirPort WN-B11/USBS")},
17         {PRISM_USB_DEVICE(0x07aa, 0x0012, "Corega Wireless LAN USB Stick-11")},
18         {PRISM_USB_DEVICE(0x09aa, 0x3642, "Prism2.x 11Mbps WLAN USB Adapter")},
19         {PRISM_USB_DEVICE(0x1668, 0x0408, "Actiontec Prism2.5 11Mbps WLAN USB Adapter")},
20         {PRISM_USB_DEVICE(0x1668, 0x0421, "Actiontec Prism2.5 11Mbps WLAN USB Adapter")},
21         {PRISM_USB_DEVICE(0x1915, 0x2236, "Linksys WUSB11v3.0 11Mbps WLAN USB Adapter")},
22         {PRISM_USB_DEVICE(0x066b, 0x2212, "Linksys WUSB11v2.5 11Mbps WLAN USB Adapter")},
23         {PRISM_USB_DEVICE(0x066b, 0x2213, "Linksys WUSB12v1.1 11Mbps WLAN USB Adapter")},
24         {PRISM_USB_DEVICE(0x067c, 0x1022, "Siemens SpeedStream 1022 11Mbps WLAN USB Adapter")},
25         {PRISM_USB_DEVICE(0x049f, 0x0033, "Compaq/Intel W100 PRO/Wireless 11Mbps multiport WLAN Adapter")},
26         {PRISM_USB_DEVICE(0x0411, 0x0016, "Melco WLI-USB-S11 11Mbps WLAN Adapter")},
27         {PRISM_USB_DEVICE(0x08de, 0x7a01, "PRISM25 IEEE 802.11 Mini USB Adapter")},
28         {PRISM_USB_DEVICE(0x8086, 0x1111, "Intel PRO/Wireless 2011B LAN USB Adapter")},
29         {PRISM_USB_DEVICE(0x0d8e, 0x7a01, "PRISM25 IEEE 802.11 Mini USB Adapter")},
30         {PRISM_USB_DEVICE(0x045e, 0x006e, "Microsoft MN510 Wireless USB Adapter")},
31         {PRISM_USB_DEVICE(0x0967, 0x0204, "Acer Warplink USB Adapter")},
32         {PRISM_USB_DEVICE(0x0cde, 0x0002, "Z-Com 725/726 Prism2.5 USB/USB Integrated")},
33         {PRISM_USB_DEVICE(0x0cde, 0x0005, "Z-Com Xl735 Wireless 802.11b USB Adapter")},
34         {PRISM_USB_DEVICE(0x413c, 0x8100, "Dell TrueMobile 1180 Wireless USB Adapter")},
35         {PRISM_USB_DEVICE(0x0b3b, 0x1601, "ALLNET 0193 11Mbps WLAN USB Adapter")},
36         {PRISM_USB_DEVICE(0x0b3b, 0x1602, "ZyXEL ZyAIR B200 Wireless USB Adapter")},
37         {PRISM_USB_DEVICE(0x0baf, 0x00eb, "USRobotics USR1120 Wireless USB Adapter")},
38         {PRISM_USB_DEVICE(0x0411, 0x0027, "Melco WLI-USB-KS11G 11Mbps WLAN Adapter")},
39         {PRISM_USB_DEVICE(0x04f1, 0x3009, "JVC MP-XP7250 Builtin USB WLAN Adapter")},
40         {PRISM_USB_DEVICE(0x0846, 0x4110, "NetGear MA111")},
41         {PRISM_USB_DEVICE(0x03f3, 0x0020, "Adaptec AWN-8020 USB WLAN Adapter")},
42 //      {PRISM_USB_DEVICE(0x0ace, 0x1201, "ZyDAS ZD1201 Wireless USB Adapter")},
43         {PRISM_USB_DEVICE(0x2821, 0x3300, "ASUS-WL140 Wireless USB Adapter")},
44         {PRISM_USB_DEVICE(0x2001, 0x3700, "DWL-122 Wireless USB Adapter")},
45         {PRISM_USB_DEVICE(0x2001, 0x3702, "DWL-120 Rev F Wireless USB Adapter")},
46         {PRISM_USB_DEVICE(0x50c2, 0x4013, "Averatec USB WLAN Adapter")},
47         {PRISM_USB_DEVICE(0x2c02, 0x14ea, "Planex GW-US11H WLAN USB Adapter")},
48         {PRISM_USB_DEVICE(0x124a, 0x168b, "Airvast PRISM3 WLAN USB Adapter")},
49         {PRISM_USB_DEVICE(0x083a, 0x3503, "T-Sinus 111 USB WLAN Adapter")},
50         {PRISM_USB_DEVICE(0x2821, 0x3300, "Hawking HighDB USB Adapter")},
51         {PRISM_USB_DEVICE(0x0411, 0x0044, "Melco WLI-USB-KB11 11Mbps WLAN Adapter")},
52         {PRISM_USB_DEVICE(0x1668, 0x6106, "ROPEX FreeLan 802.11b USB Adapter")},
53         {PRISM_USB_DEVICE(0x124a, 0x4017, "Pheenet WL-503IA 802.11b USB Adapter")},
54         {PRISM_USB_DEVICE(0x0bb2, 0x0302, "Ambit Microsystems Corp.")},
55         {PRISM_USB_DEVICE(0x9016, 0x182d, "Sitecom WL-022 802.11b USB Adapter")},
56         {PRISM_USB_DEVICE(0x0543, 0x0f01, "ViewSonic Airsync USB Adapter 11Mbps (Prism2.5)")},
57         { /* terminator */ }
58 };
59
60 MODULE_DEVICE_TABLE(usb, usb_prism_tbl);
61
62 /*----------------------------------------------------------------
63 * prism2sta_probe_usb
64 *
65 * Probe routine called by the USB subsystem.
66 *
67 * Arguments:
68 *       dev             ptr to the usb_device struct
69 *       ifnum           interface number being offered
70 *
71 * Returns:
72 *       NULL            - we're not claiming the device+interface
73 *       non-NULL        - we are claiming the device+interface and
74 *                         this is a ptr to the data we want back
75 *                         when disconnect is called.
76 *
77 * Side effects:
78 *
79 * Call context:
80 *       I'm not sure, assume it's interrupt.
81 *
82 ----------------------------------------------------------------*/
83 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
84 static void __devinit *prism2sta_probe_usb(
85         struct usb_device *dev,
86         unsigned int ifnum,
87         const struct usb_device_id *id)
88 #else
89 static int prism2sta_probe_usb(
90         struct usb_interface *interface,
91         const struct usb_device_id *id)
92 #endif
93 {
94
95 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
96         struct usb_interface *interface;
97 #else
98         struct usb_device *dev;
99 #endif
100
101         wlandevice_t    *wlandev = NULL;
102         hfa384x_t       *hw = NULL;
103         int              result = 0;
104
105         DBFENTER;
106
107 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
108         interface = &dev->actconfig->interface[ifnum];
109 #else
110         dev = interface_to_usbdev(interface);
111 #endif
112
113
114         if ((wlandev = create_wlan()) == NULL) {
115                 WLAN_LOG_ERROR("%s: Memory allocation failure.\n", dev_info);
116                 result = -EIO;
117                 goto failed;
118         }
119         hw = wlandev->priv;
120
121         if ( wlan_setup(wlandev) != 0 ) {
122                 WLAN_LOG_ERROR("%s: wlan_setup() failed.\n", dev_info);
123                 result = -EIO;
124                 goto failed;
125         }
126
127         /* Initialize the hw data */
128         hfa384x_create(hw, dev);
129         hw->wlandev = wlandev;
130
131         /* Register the wlandev, this gets us a name and registers the
132          * linux netdevice.
133          */
134 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
135         SET_NETDEV_DEV(wlandev->netdev, &(interface->dev));
136 #endif
137         if ( register_wlandev(wlandev) != 0 ) {
138                 WLAN_LOG_ERROR("%s: register_wlandev() failed.\n", dev_info);
139                 result = -EIO;
140                 goto failed;
141         }
142
143         /* Do a chip-level reset on the MAC */
144         if (prism2_doreset) {
145                 result = hfa384x_corereset(hw,
146                                 prism2_reset_holdtime,
147                                 prism2_reset_settletime, 0);
148                 if (result != 0) {
149                         unregister_wlandev(wlandev);
150                         hfa384x_destroy(hw);
151                         result = -EIO;
152                         WLAN_LOG_ERROR(
153                                 "%s: hfa384x_corereset() failed.\n",
154                                 dev_info);
155                         goto failed;
156                 }
157         }
158
159 #ifndef NEW_MODULE_CODE
160         usb_inc_dev_use(dev);
161 #endif
162 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
163         usb_get_dev(dev);
164 #endif
165
166         wlandev->msdstate = WLAN_MSD_HWPRESENT;
167
168         goto done;
169
170  failed:
171         if (wlandev)    kfree(wlandev);
172         if (hw)         kfree(hw);
173         wlandev = NULL;
174
175  done:
176         DBFEXIT;
177
178 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
179         return wlandev;
180 #else
181         usb_set_intfdata(interface, wlandev);
182         return result;
183 #endif
184 }
185
186
187 /*----------------------------------------------------------------
188 * prism2sta_disconnect_usb
189 *
190 * Called when a device previously claimed by probe is removed
191 * from the USB.
192 *
193 * Arguments:
194 *       dev             ptr to the usb_device struct
195 *       ptr             ptr returned by probe() when the device
196 *                       was claimed.
197 *
198 * Returns:
199 *       Nothing
200 *
201 * Side effects:
202 *
203 * Call context:
204 *       process
205 ----------------------------------------------------------------*/
206 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
207 static void __devexit
208 prism2sta_disconnect_usb(struct usb_device *dev, void *ptr)
209 #else
210 static void
211 prism2sta_disconnect_usb(struct usb_interface *interface)
212 #endif
213 {
214 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
215         wlandevice_t            *wlandev;
216 #else
217         wlandevice_t            *wlandev = (wlandevice_t*)ptr;
218 #endif
219
220         DBFENTER;
221
222 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
223         wlandev = (wlandevice_t *) usb_get_intfdata(interface);
224 #endif
225
226         if ( wlandev != NULL ) {
227                 LIST_HEAD(cleanlist);
228                 struct list_head        *entry;
229                 struct list_head        *temp;
230                 unsigned long           flags;
231
232                 hfa384x_t               *hw = wlandev->priv;
233
234                 if (!hw)
235                         goto exit;
236
237                 spin_lock_irqsave(&hw->ctlxq.lock, flags);
238
239                 p80211netdev_hwremoved(wlandev);
240                 list_splice_init(&hw->ctlxq.reapable, &cleanlist);
241                 list_splice_init(&hw->ctlxq.completing, &cleanlist);
242                 list_splice_init(&hw->ctlxq.pending, &cleanlist);
243                 list_splice_init(&hw->ctlxq.active, &cleanlist);
244
245                 spin_unlock_irqrestore(&hw->ctlxq.lock, flags);
246
247                 /* There's no hardware to shutdown, but the driver
248                  * might have some tasks or tasklets that must be
249                  * stopped before we can tear everything down.
250                  */
251                 prism2sta_ifstate(wlandev, P80211ENUM_ifstate_disable);
252
253                 del_singleshot_timer_sync(&hw->throttle);
254                 del_singleshot_timer_sync(&hw->reqtimer);
255                 del_singleshot_timer_sync(&hw->resptimer);
256
257                 /* Unlink all the URBs. This "removes the wheels"
258                  * from the entire CTLX handling mechanism.
259                  */
260                 usb_kill_urb(&hw->rx_urb);
261                 usb_kill_urb(&hw->tx_urb);
262                 usb_kill_urb(&hw->ctlx_urb);
263
264                 tasklet_kill(&hw->completion_bh);
265                 tasklet_kill(&hw->reaper_bh);
266
267                 flush_scheduled_work();
268
269                 /* Now we complete any outstanding commands
270                  * and tell everyone who is waiting for their
271                  * responses that we have shut down.
272                  */
273                 list_for_each(entry, &cleanlist) {
274                         hfa384x_usbctlx_t       *ctlx;
275
276                         ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
277                         complete(&ctlx->done);
278                 }
279
280                 /* Give any outstanding synchronous commands
281                  * a chance to complete. All they need to do
282                  * is "wake up", so that's easy.
283                  * (I'd like a better way to do this, really.)
284                  */
285                 msleep(100);
286
287                 /* Now delete the CTLXs, because no-one else can now. */
288                 list_for_each_safe(entry, temp, &cleanlist) {
289                         hfa384x_usbctlx_t *ctlx;
290
291                         ctlx = list_entry(entry, hfa384x_usbctlx_t, list);
292                         kfree(ctlx);
293                 }
294
295                 /* Unhook the wlandev */
296                 unregister_wlandev(wlandev);
297                 wlan_unsetup(wlandev);
298
299 #ifndef NEW_MODULE_CODE
300                 usb_dec_dev_use(hw->usb);
301 #endif
302 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
303                 usb_put_dev(hw->usb);
304 #endif
305
306                 hfa384x_destroy(hw);
307                 kfree(hw);
308
309                 kfree(wlandev);
310         }
311
312  exit:
313
314 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
315         usb_set_intfdata(interface, NULL);
316 #endif
317         DBFEXIT;
318 }
319
320
321 static struct usb_driver prism2_usb_driver = {
322 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,4,19)) && (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16))
323         .owner = THIS_MODULE,
324 #endif
325         .name = "prism2_usb",
326         .probe = prism2sta_probe_usb,
327         .disconnect = prism2sta_disconnect_usb,
328         .id_table = usb_prism_tbl,
329         /* fops, minor? */
330 };
331
332 #ifdef MODULE
333
334 static int __init prism2usb_init(void)
335 {
336         DBFENTER;
337
338         WLAN_LOG_NOTICE("%s Loaded\n", version);
339         WLAN_LOG_NOTICE("dev_info is: %s\n", dev_info);
340
341         /* This call will result in calls to prism2sta_probe_usb. */
342         return usb_register(&prism2_usb_driver);
343
344         DBFEXIT;
345 };
346
347 static void __exit prism2usb_cleanup(void)
348 {
349         DBFENTER;
350
351         usb_deregister(&prism2_usb_driver);
352
353         printk(KERN_NOTICE "%s Unloaded\n", version);
354
355         DBFEXIT;
356 };
357
358 module_init(prism2usb_init);
359 module_exit(prism2usb_cleanup);
360
361 #endif // module