/drivers/staging/wlan-ng/prism2usb.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2 · C · 373 lines · 252 code · 54 blank · 67 comment · 19 complexity · a2e87533f139470af1b51ea98c3d1d00 MD5 · raw file

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