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