prism2usb.c 8.3 KB

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