usb.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /*
  2. * Intel Wireless WiMAX Connection 2400m
  3. * Linux driver model glue for USB device, reset & fw upload
  4. *
  5. *
  6. * Copyright (C) 2007-2008 Intel Corporation <linux-wimax@intel.com>
  7. * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
  8. * Yanir Lubetkin <yanirx.lubetkin@intel.com>
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License version
  12. * 2 as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301, USA.
  23. *
  24. *
  25. * See i2400m-usb.h for a general description of this driver.
  26. *
  27. * This file implements driver model glue, and hook ups for the
  28. * generic driver to implement the bus-specific functions (device
  29. * communication setup/tear down, firmware upload and resetting).
  30. *
  31. * ROADMAP
  32. *
  33. * i2400mu_probe()
  34. * alloc_netdev()...
  35. * i2400mu_netdev_setup()
  36. * i2400mu_init()
  37. * i2400m_netdev_setup()
  38. * i2400m_setup()...
  39. *
  40. * i2400mu_disconnect
  41. * i2400m_release()
  42. * free_netdev()
  43. *
  44. * i2400mu_suspend()
  45. * i2400m_cmd_enter_powersave()
  46. * i2400mu_notification_release()
  47. *
  48. * i2400mu_resume()
  49. * i2400mu_notification_setup()
  50. *
  51. * i2400mu_bus_dev_start() Called by i2400m_dev_start() [who is
  52. * i2400mu_tx_setup() called by i2400m_setup()]
  53. * i2400mu_rx_setup()
  54. * i2400mu_notification_setup()
  55. *
  56. * i2400mu_bus_dev_stop() Called by i2400m_dev_stop() [who is
  57. * i2400mu_notification_release() called by i2400m_release()]
  58. * i2400mu_rx_release()
  59. * i2400mu_tx_release()
  60. *
  61. * i2400mu_bus_reset() Called by i2400m->bus_reset
  62. * __i2400mu_reset()
  63. * __i2400mu_send_barker()
  64. * usb_reset_device()
  65. */
  66. #include "i2400m-usb.h"
  67. #include <linux/wimax/i2400m.h>
  68. #include <linux/debugfs.h>
  69. #define D_SUBMODULE usb
  70. #include "usb-debug-levels.h"
  71. static char i2400mu_debug_params[128];
  72. module_param_string(debug, i2400mu_debug_params, sizeof(i2400mu_debug_params),
  73. 0644);
  74. MODULE_PARM_DESC(debug,
  75. "String of space-separated NAME:VALUE pairs, where NAMEs "
  76. "are the different debug submodules and VALUE are the "
  77. "initial debug value to set.");
  78. /* Our firmware file name */
  79. static const char *i2400mu_bus_fw_names[] = {
  80. #define I2400MU_FW_FILE_NAME_v1_4 "i2400m-fw-usb-1.4.sbcf"
  81. I2400MU_FW_FILE_NAME_v1_4,
  82. #define I2400MU_FW_FILE_NAME_v1_3 "i2400m-fw-usb-1.3.sbcf"
  83. I2400MU_FW_FILE_NAME_v1_3,
  84. NULL,
  85. };
  86. static
  87. int i2400mu_bus_dev_start(struct i2400m *i2400m)
  88. {
  89. int result;
  90. struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
  91. struct device *dev = &i2400mu->usb_iface->dev;
  92. d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
  93. result = i2400mu_tx_setup(i2400mu);
  94. if (result < 0)
  95. goto error_usb_tx_setup;
  96. result = i2400mu_rx_setup(i2400mu);
  97. if (result < 0)
  98. goto error_usb_rx_setup;
  99. result = i2400mu_notification_setup(i2400mu);
  100. if (result < 0)
  101. goto error_notif_setup;
  102. d_fnend(3, dev, "(i2400m %p) = %d\n", i2400m, result);
  103. return result;
  104. error_notif_setup:
  105. i2400mu_rx_release(i2400mu);
  106. error_usb_rx_setup:
  107. i2400mu_tx_release(i2400mu);
  108. error_usb_tx_setup:
  109. d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
  110. return result;
  111. }
  112. static
  113. void i2400mu_bus_dev_stop(struct i2400m *i2400m)
  114. {
  115. struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
  116. struct device *dev = &i2400mu->usb_iface->dev;
  117. d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
  118. i2400mu_notification_release(i2400mu);
  119. i2400mu_rx_release(i2400mu);
  120. i2400mu_tx_release(i2400mu);
  121. d_fnend(3, dev, "(i2400m %p) = void\n", i2400m);
  122. }
  123. /*
  124. * Sends a barker buffer to the device
  125. *
  126. * This helper will allocate a kmalloced buffer and use it to transmit
  127. * (then free it). Reason for this is that other arches cannot use
  128. * stack/vmalloc/text areas for DMA transfers.
  129. *
  130. * Error recovery here is simpler: anything is considered a hard error
  131. * and will move the reset code to use a last-resort bus-based reset.
  132. */
  133. static
  134. int __i2400mu_send_barker(struct i2400mu *i2400mu,
  135. const __le32 *barker,
  136. size_t barker_size,
  137. unsigned endpoint)
  138. {
  139. struct usb_endpoint_descriptor *epd = NULL;
  140. int pipe, actual_len, ret;
  141. struct device *dev = &i2400mu->usb_iface->dev;
  142. void *buffer;
  143. int do_autopm = 1;
  144. ret = usb_autopm_get_interface(i2400mu->usb_iface);
  145. if (ret < 0) {
  146. dev_err(dev, "RESET: can't get autopm: %d\n", ret);
  147. do_autopm = 0;
  148. }
  149. ret = -ENOMEM;
  150. buffer = kmalloc(barker_size, GFP_KERNEL);
  151. if (buffer == NULL)
  152. goto error_kzalloc;
  153. epd = usb_get_epd(i2400mu->usb_iface, endpoint);
  154. pipe = usb_sndbulkpipe(i2400mu->usb_dev, epd->bEndpointAddress);
  155. memcpy(buffer, barker, barker_size);
  156. ret = usb_bulk_msg(i2400mu->usb_dev, pipe, buffer, barker_size,
  157. &actual_len, HZ);
  158. if (ret < 0) {
  159. if (ret != -EINVAL)
  160. dev_err(dev, "E: barker error: %d\n", ret);
  161. } else if (actual_len != barker_size) {
  162. dev_err(dev, "E: only %d bytes transmitted\n", actual_len);
  163. ret = -EIO;
  164. }
  165. kfree(buffer);
  166. error_kzalloc:
  167. if (do_autopm)
  168. usb_autopm_put_interface(i2400mu->usb_iface);
  169. return ret;
  170. }
  171. /*
  172. * Reset a device at different levels (warm, cold or bus)
  173. *
  174. * @i2400m: device descriptor
  175. * @reset_type: soft, warm or bus reset (I2400M_RT_WARM/SOFT/BUS)
  176. *
  177. * Warm and cold resets get a USB reset if they fail.
  178. *
  179. * Warm reset:
  180. *
  181. * The device will be fully reset internally, but won't be
  182. * disconnected from the USB bus (so no reenumeration will
  183. * happen). Firmware upload will be neccessary.
  184. *
  185. * The device will send a reboot barker in the notification endpoint
  186. * that will trigger the driver to reinitialize the state
  187. * automatically from notif.c:i2400m_notification_grok() into
  188. * i2400m_dev_bootstrap_delayed().
  189. *
  190. * Cold and bus (USB) reset:
  191. *
  192. * The device will be fully reset internally, disconnected from the
  193. * USB bus an a reenumeration will happen. Firmware upload will be
  194. * neccessary. Thus, we don't do any locking or struct
  195. * reinitialization, as we are going to be fully disconnected and
  196. * reenumerated.
  197. *
  198. * Note we need to return -ENODEV if a warm reset was requested and we
  199. * had to resort to a bus reset. See i2400m_op_reset(), wimax_reset()
  200. * and wimax_dev->op_reset.
  201. *
  202. * WARNING: no driver state saved/fixed
  203. */
  204. static
  205. int i2400mu_bus_reset(struct i2400m *i2400m, enum i2400m_reset_type rt)
  206. {
  207. int result;
  208. struct i2400mu *i2400mu =
  209. container_of(i2400m, struct i2400mu, i2400m);
  210. struct device *dev = i2400m_dev(i2400m);
  211. static const __le32 i2400m_WARM_BOOT_BARKER[4] = {
  212. cpu_to_le32(I2400M_WARM_RESET_BARKER),
  213. cpu_to_le32(I2400M_WARM_RESET_BARKER),
  214. cpu_to_le32(I2400M_WARM_RESET_BARKER),
  215. cpu_to_le32(I2400M_WARM_RESET_BARKER),
  216. };
  217. static const __le32 i2400m_COLD_BOOT_BARKER[4] = {
  218. cpu_to_le32(I2400M_COLD_RESET_BARKER),
  219. cpu_to_le32(I2400M_COLD_RESET_BARKER),
  220. cpu_to_le32(I2400M_COLD_RESET_BARKER),
  221. cpu_to_le32(I2400M_COLD_RESET_BARKER),
  222. };
  223. d_fnstart(3, dev, "(i2400m %p rt %u)\n", i2400m, rt);
  224. if (rt == I2400M_RT_WARM)
  225. result = __i2400mu_send_barker(
  226. i2400mu, i2400m_WARM_BOOT_BARKER,
  227. sizeof(i2400m_WARM_BOOT_BARKER),
  228. i2400mu->endpoint_cfg.bulk_out);
  229. else if (rt == I2400M_RT_COLD)
  230. result = __i2400mu_send_barker(
  231. i2400mu, i2400m_COLD_BOOT_BARKER,
  232. sizeof(i2400m_COLD_BOOT_BARKER),
  233. i2400mu->endpoint_cfg.reset_cold);
  234. else if (rt == I2400M_RT_BUS) {
  235. do_bus_reset:
  236. result = usb_reset_device(i2400mu->usb_dev);
  237. switch (result) {
  238. case 0:
  239. case -EINVAL: /* device is gone */
  240. case -ENODEV:
  241. case -ENOENT:
  242. case -ESHUTDOWN:
  243. result = rt == I2400M_RT_WARM ? -ENODEV : 0;
  244. break; /* We assume the device is disconnected */
  245. default:
  246. dev_err(dev, "USB reset failed (%d), giving up!\n",
  247. result);
  248. }
  249. } else {
  250. result = -EINVAL; /* shut gcc up in certain arches */
  251. BUG();
  252. }
  253. if (result < 0
  254. && result != -EINVAL /* device is gone */
  255. && rt != I2400M_RT_BUS) {
  256. dev_err(dev, "%s reset failed (%d); trying USB reset\n",
  257. rt == I2400M_RT_WARM ? "warm" : "cold", result);
  258. rt = I2400M_RT_BUS;
  259. goto do_bus_reset;
  260. }
  261. d_fnend(3, dev, "(i2400m %p rt %u) = %d\n", i2400m, rt, result);
  262. return result;
  263. }
  264. static
  265. void i2400mu_netdev_setup(struct net_device *net_dev)
  266. {
  267. struct i2400m *i2400m = net_dev_to_i2400m(net_dev);
  268. struct i2400mu *i2400mu = container_of(i2400m, struct i2400mu, i2400m);
  269. i2400mu_init(i2400mu);
  270. i2400m_netdev_setup(net_dev);
  271. }
  272. /*
  273. * Debug levels control; see debug.h
  274. */
  275. struct d_level D_LEVEL[] = {
  276. D_SUBMODULE_DEFINE(usb),
  277. D_SUBMODULE_DEFINE(fw),
  278. D_SUBMODULE_DEFINE(notif),
  279. D_SUBMODULE_DEFINE(rx),
  280. D_SUBMODULE_DEFINE(tx),
  281. };
  282. size_t D_LEVEL_SIZE = ARRAY_SIZE(D_LEVEL);
  283. #define __debugfs_register(prefix, name, parent) \
  284. do { \
  285. result = d_level_register_debugfs(prefix, name, parent); \
  286. if (result < 0) \
  287. goto error; \
  288. } while (0)
  289. static
  290. int i2400mu_debugfs_add(struct i2400mu *i2400mu)
  291. {
  292. int result;
  293. struct device *dev = &i2400mu->usb_iface->dev;
  294. struct dentry *dentry = i2400mu->i2400m.wimax_dev.debugfs_dentry;
  295. struct dentry *fd;
  296. dentry = debugfs_create_dir("i2400m-usb", dentry);
  297. result = PTR_ERR(dentry);
  298. if (IS_ERR(dentry)) {
  299. if (result == -ENODEV)
  300. result = 0; /* No debugfs support */
  301. goto error;
  302. }
  303. i2400mu->debugfs_dentry = dentry;
  304. __debugfs_register("dl_", usb, dentry);
  305. __debugfs_register("dl_", fw, dentry);
  306. __debugfs_register("dl_", notif, dentry);
  307. __debugfs_register("dl_", rx, dentry);
  308. __debugfs_register("dl_", tx, dentry);
  309. /* Don't touch these if you don't know what you are doing */
  310. fd = debugfs_create_u8("rx_size_auto_shrink", 0600, dentry,
  311. &i2400mu->rx_size_auto_shrink);
  312. result = PTR_ERR(fd);
  313. if (IS_ERR(fd) && result != -ENODEV) {
  314. dev_err(dev, "Can't create debugfs entry "
  315. "rx_size_auto_shrink: %d\n", result);
  316. goto error;
  317. }
  318. fd = debugfs_create_size_t("rx_size", 0600, dentry,
  319. &i2400mu->rx_size);
  320. result = PTR_ERR(fd);
  321. if (IS_ERR(fd) && result != -ENODEV) {
  322. dev_err(dev, "Can't create debugfs entry "
  323. "rx_size: %d\n", result);
  324. goto error;
  325. }
  326. return 0;
  327. error:
  328. debugfs_remove_recursive(i2400mu->debugfs_dentry);
  329. return result;
  330. }
  331. static struct device_type i2400mu_type = {
  332. .name = "wimax",
  333. };
  334. /*
  335. * Probe a i2400m interface and register it
  336. *
  337. * @iface: USB interface to link to
  338. * @id: USB class/subclass/protocol id
  339. * @returns: 0 if ok, < 0 errno code on error.
  340. *
  341. * Alloc a net device, initialize the bus-specific details and then
  342. * calls the bus-generic initialization routine. That will register
  343. * the wimax and netdev devices, upload the firmware [using
  344. * _bus_bm_*()], call _bus_dev_start() to finalize the setup of the
  345. * communication with the device and then will start to talk to it to
  346. * finnish setting it up.
  347. */
  348. static
  349. int i2400mu_probe(struct usb_interface *iface,
  350. const struct usb_device_id *id)
  351. {
  352. int result;
  353. struct net_device *net_dev;
  354. struct device *dev = &iface->dev;
  355. struct i2400m *i2400m;
  356. struct i2400mu *i2400mu;
  357. struct usb_device *usb_dev = interface_to_usbdev(iface);
  358. if (usb_dev->speed != USB_SPEED_HIGH)
  359. dev_err(dev, "device not connected as high speed\n");
  360. /* Allocate instance [calls i2400m_netdev_setup() on it]. */
  361. result = -ENOMEM;
  362. net_dev = alloc_netdev(sizeof(*i2400mu), "wmx%d",
  363. i2400mu_netdev_setup);
  364. if (net_dev == NULL) {
  365. dev_err(dev, "no memory for network device instance\n");
  366. goto error_alloc_netdev;
  367. }
  368. SET_NETDEV_DEV(net_dev, dev);
  369. SET_NETDEV_DEVTYPE(net_dev, &i2400mu_type);
  370. i2400m = net_dev_to_i2400m(net_dev);
  371. i2400mu = container_of(i2400m, struct i2400mu, i2400m);
  372. i2400m->wimax_dev.net_dev = net_dev;
  373. i2400mu->usb_dev = usb_get_dev(usb_dev);
  374. i2400mu->usb_iface = iface;
  375. usb_set_intfdata(iface, i2400mu);
  376. i2400m->bus_tx_block_size = I2400MU_BLK_SIZE;
  377. i2400m->bus_pl_size_max = I2400MU_PL_SIZE_MAX;
  378. i2400m->bus_dev_start = i2400mu_bus_dev_start;
  379. i2400m->bus_dev_stop = i2400mu_bus_dev_stop;
  380. i2400m->bus_tx_kick = i2400mu_bus_tx_kick;
  381. i2400m->bus_reset = i2400mu_bus_reset;
  382. i2400m->bus_bm_retries = I2400M_USB_BOOT_RETRIES;
  383. i2400m->bus_bm_cmd_send = i2400mu_bus_bm_cmd_send;
  384. i2400m->bus_bm_wait_for_ack = i2400mu_bus_bm_wait_for_ack;
  385. i2400m->bus_fw_names = i2400mu_bus_fw_names;
  386. i2400m->bus_bm_mac_addr_impaired = 0;
  387. {
  388. i2400mu->endpoint_cfg.bulk_out = 0;
  389. i2400mu->endpoint_cfg.notification = 1;
  390. i2400mu->endpoint_cfg.reset_cold = 2;
  391. i2400mu->endpoint_cfg.bulk_in = 3;
  392. }
  393. #ifdef CONFIG_PM
  394. iface->needs_remote_wakeup = 1; /* autosuspend (15s delay) */
  395. device_init_wakeup(dev, 1);
  396. usb_dev->autosuspend_delay = 15 * HZ;
  397. usb_dev->autosuspend_disabled = 0;
  398. #endif
  399. result = i2400m_bm_buf_alloc(i2400m);
  400. if (result < 0) {
  401. dev_err(dev, "cannot allocate USB bootmode buffer\n");
  402. goto error_bm_buf_alloc;
  403. }
  404. result = i2400m_setup(i2400m, I2400M_BRI_MAC_REINIT);
  405. if (result < 0) {
  406. dev_err(dev, "cannot setup device: %d\n", result);
  407. goto error_setup;
  408. }
  409. result = i2400mu_debugfs_add(i2400mu);
  410. if (result < 0) {
  411. dev_err(dev, "Can't register i2400mu's debugfs: %d\n", result);
  412. goto error_debugfs_add;
  413. }
  414. return 0;
  415. error_debugfs_add:
  416. i2400m_release(i2400m);
  417. error_setup:
  418. i2400m_bm_buf_free(i2400m);
  419. error_bm_buf_alloc:
  420. usb_set_intfdata(iface, NULL);
  421. usb_put_dev(i2400mu->usb_dev);
  422. free_netdev(net_dev);
  423. error_alloc_netdev:
  424. return result;
  425. }
  426. /*
  427. * Disconect a i2400m from the system.
  428. *
  429. * i2400m_stop() has been called before, so al the rx and tx contexts
  430. * have been taken down already. Make sure the queue is stopped,
  431. * unregister netdev and i2400m, free and kill.
  432. */
  433. static
  434. void i2400mu_disconnect(struct usb_interface *iface)
  435. {
  436. struct i2400mu *i2400mu = usb_get_intfdata(iface);
  437. struct i2400m *i2400m = &i2400mu->i2400m;
  438. struct net_device *net_dev = i2400m->wimax_dev.net_dev;
  439. struct device *dev = &iface->dev;
  440. d_fnstart(3, dev, "(iface %p i2400m %p)\n", iface, i2400m);
  441. debugfs_remove_recursive(i2400mu->debugfs_dentry);
  442. i2400m_release(i2400m);
  443. usb_set_intfdata(iface, NULL);
  444. usb_put_dev(i2400mu->usb_dev);
  445. free_netdev(net_dev);
  446. d_fnend(3, dev, "(iface %p i2400m %p) = void\n", iface, i2400m);
  447. }
  448. /*
  449. * Get the device ready for USB port or system standby and hibernation
  450. *
  451. * USB port and system standby are handled the same.
  452. *
  453. * When the system hibernates, the USB device is powered down and then
  454. * up, so we don't really have to do much here, as it will be seen as
  455. * a reconnect. Still for simplicity we consider this case the same as
  456. * suspend, so that the device has a chance to do notify the base
  457. * station (if connected).
  458. *
  459. * So at the end, the three cases require common handling.
  460. *
  461. * If at the time of this call the device's firmware is not loaded,
  462. * nothing has to be done.
  463. *
  464. * If the firmware is loaded, we need to:
  465. *
  466. * - tell the device to go into host interface power save mode, wait
  467. * for it to ack
  468. *
  469. * This is quite more interesting than it is; we need to execute a
  470. * command, but this time, we don't want the code in usb-{tx,rx}.c
  471. * to call the usb_autopm_get/put_interface() barriers as it'd
  472. * deadlock, so we need to decrement i2400mu->do_autopm, that acts
  473. * as a poor man's semaphore. Ugly, but it works.
  474. *
  475. * As well, the device might refuse going to sleep for whichever
  476. * reason. In this case we just fail. For system suspend/hibernate,
  477. * we *can't* fail. We look at usb_dev->auto_pm to see if the
  478. * suspend call comes from the USB stack or from the system and act
  479. * in consequence.
  480. *
  481. * - stop the notification endpoint polling
  482. */
  483. static
  484. int i2400mu_suspend(struct usb_interface *iface, pm_message_t pm_msg)
  485. {
  486. int result = 0;
  487. struct device *dev = &iface->dev;
  488. struct i2400mu *i2400mu = usb_get_intfdata(iface);
  489. #ifdef CONFIG_PM
  490. struct usb_device *usb_dev = i2400mu->usb_dev;
  491. #endif
  492. unsigned is_autosuspend = 0;
  493. struct i2400m *i2400m = &i2400mu->i2400m;
  494. #ifdef CONFIG_PM
  495. if (usb_dev->auto_pm > 0)
  496. is_autosuspend = 1;
  497. #endif
  498. d_fnstart(3, dev, "(iface %p pm_msg %u)\n", iface, pm_msg.event);
  499. if (i2400m->updown == 0)
  500. goto no_firmware;
  501. if (i2400m->state == I2400M_SS_DATA_PATH_CONNECTED && is_autosuspend) {
  502. /* ugh -- the device is connected and this suspend
  503. * request is an autosuspend one (not a system standby
  504. * / hibernate).
  505. *
  506. * The only way the device can go to standby is if the
  507. * link with the base station is in IDLE mode; that
  508. * were the case, we'd be in status
  509. * I2400M_SS_CONNECTED_IDLE. But we are not.
  510. *
  511. * If we *tell* him to go power save now, it'll reset
  512. * as a precautionary measure, so if this is an
  513. * autosuspend thing, say no and it'll come back
  514. * later, when the link is IDLE
  515. */
  516. result = -EBADF;
  517. d_printf(1, dev, "fw up, link up, not-idle, autosuspend: "
  518. "not entering powersave\n");
  519. goto error_not_now;
  520. }
  521. d_printf(1, dev, "fw up: entering powersave\n");
  522. atomic_dec(&i2400mu->do_autopm);
  523. result = i2400m_cmd_enter_powersave(i2400m);
  524. atomic_inc(&i2400mu->do_autopm);
  525. if (result < 0 && !is_autosuspend) {
  526. /* System suspend, can't fail */
  527. dev_err(dev, "failed to suspend, will reset on resume\n");
  528. result = 0;
  529. }
  530. if (result < 0)
  531. goto error_enter_powersave;
  532. i2400mu_notification_release(i2400mu);
  533. d_printf(1, dev, "powersave requested\n");
  534. error_enter_powersave:
  535. error_not_now:
  536. no_firmware:
  537. d_fnend(3, dev, "(iface %p pm_msg %u) = %d\n",
  538. iface, pm_msg.event, result);
  539. return result;
  540. }
  541. static
  542. int i2400mu_resume(struct usb_interface *iface)
  543. {
  544. int ret = 0;
  545. struct device *dev = &iface->dev;
  546. struct i2400mu *i2400mu = usb_get_intfdata(iface);
  547. struct i2400m *i2400m = &i2400mu->i2400m;
  548. d_fnstart(3, dev, "(iface %p)\n", iface);
  549. if (i2400m->updown == 0) {
  550. d_printf(1, dev, "fw was down, no resume neeed\n");
  551. goto out;
  552. }
  553. d_printf(1, dev, "fw was up, resuming\n");
  554. i2400mu_notification_setup(i2400mu);
  555. /* USB has flow control, so we don't need to give it time to
  556. * come back; otherwise, we'd use something like a get-state
  557. * command... */
  558. out:
  559. d_fnend(3, dev, "(iface %p) = %d\n", iface, ret);
  560. return ret;
  561. }
  562. static
  563. struct usb_device_id i2400mu_id_table[] = {
  564. { USB_DEVICE(0x8086, 0x0181) },
  565. { USB_DEVICE(0x8086, 0x1403) },
  566. { USB_DEVICE(0x8086, 0x1405) },
  567. { USB_DEVICE(0x8086, 0x0180) },
  568. { USB_DEVICE(0x8086, 0x0182) },
  569. { USB_DEVICE(0x8086, 0x1406) },
  570. { USB_DEVICE(0x8086, 0x1403) },
  571. { },
  572. };
  573. MODULE_DEVICE_TABLE(usb, i2400mu_id_table);
  574. static
  575. struct usb_driver i2400mu_driver = {
  576. .name = KBUILD_MODNAME,
  577. .suspend = i2400mu_suspend,
  578. .resume = i2400mu_resume,
  579. .probe = i2400mu_probe,
  580. .disconnect = i2400mu_disconnect,
  581. .id_table = i2400mu_id_table,
  582. .supports_autosuspend = 1,
  583. };
  584. static
  585. int __init i2400mu_driver_init(void)
  586. {
  587. d_parse_params(D_LEVEL, D_LEVEL_SIZE, i2400mu_debug_params,
  588. "i2400m_usb.debug");
  589. return usb_register(&i2400mu_driver);
  590. }
  591. module_init(i2400mu_driver_init);
  592. static
  593. void __exit i2400mu_driver_exit(void)
  594. {
  595. flush_scheduled_work(); /* for the stuff we schedule from sysfs.c */
  596. usb_deregister(&i2400mu_driver);
  597. }
  598. module_exit(i2400mu_driver_exit);
  599. MODULE_AUTHOR("Intel Corporation <linux-wimax@intel.com>");
  600. MODULE_DESCRIPTION("Intel 2400M WiMAX networking for USB");
  601. MODULE_LICENSE("GPL");
  602. MODULE_FIRMWARE(I2400MU_FW_FILE_NAME_v1_4);
  603. MODULE_FIRMWARE(I2400MU_FW_FILE_NAME_v1_3);