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