usb_wwan.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. USB Driver layer for GSM modems
  3. Copyright (C) 2005 Matthias Urlichs <smurf@smurf.noris.de>
  4. This driver is free software; you can redistribute it and/or modify
  5. it under the terms of Version 2 of the GNU General Public License as
  6. published by the Free Software Foundation.
  7. Portions copied from the Keyspan driver by Hugh Blemings <hugh@blemings.org>
  8. History: see the git log.
  9. Work sponsored by: Sigos GmbH, Germany <info@sigos.de>
  10. This driver exists because the "normal" serial driver doesn't work too well
  11. with GSM modems. Issues:
  12. - data loss -- one single Receive URB is not nearly enough
  13. - controlling the baud rate doesn't make sense
  14. */
  15. #define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>"
  16. #define DRIVER_DESC "USB Driver for GSM modems"
  17. #include <linux/kernel.h>
  18. #include <linux/jiffies.h>
  19. #include <linux/errno.h>
  20. #include <linux/slab.h>
  21. #include <linux/tty.h>
  22. #include <linux/tty_flip.h>
  23. #include <linux/module.h>
  24. #include <linux/bitops.h>
  25. #include <linux/uaccess.h>
  26. #include <linux/usb.h>
  27. #include <linux/usb/serial.h>
  28. #include <linux/serial.h>
  29. #include "usb-wwan.h"
  30. void usb_wwan_dtr_rts(struct usb_serial_port *port, int on)
  31. {
  32. struct usb_wwan_port_private *portdata;
  33. struct usb_wwan_intf_private *intfdata;
  34. intfdata = port->serial->private;
  35. if (!intfdata->send_setup)
  36. return;
  37. portdata = usb_get_serial_port_data(port);
  38. /* FIXME: locking */
  39. portdata->rts_state = on;
  40. portdata->dtr_state = on;
  41. intfdata->send_setup(port);
  42. }
  43. EXPORT_SYMBOL(usb_wwan_dtr_rts);
  44. void usb_wwan_set_termios(struct tty_struct *tty,
  45. struct usb_serial_port *port,
  46. struct ktermios *old_termios)
  47. {
  48. struct usb_wwan_intf_private *intfdata = port->serial->private;
  49. /* Doesn't support option setting */
  50. tty_termios_copy_hw(&tty->termios, old_termios);
  51. if (intfdata->send_setup)
  52. intfdata->send_setup(port);
  53. }
  54. EXPORT_SYMBOL(usb_wwan_set_termios);
  55. int usb_wwan_tiocmget(struct tty_struct *tty)
  56. {
  57. struct usb_serial_port *port = tty->driver_data;
  58. unsigned int value;
  59. struct usb_wwan_port_private *portdata;
  60. portdata = usb_get_serial_port_data(port);
  61. value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
  62. ((portdata->dtr_state) ? TIOCM_DTR : 0) |
  63. ((portdata->cts_state) ? TIOCM_CTS : 0) |
  64. ((portdata->dsr_state) ? TIOCM_DSR : 0) |
  65. ((portdata->dcd_state) ? TIOCM_CAR : 0) |
  66. ((portdata->ri_state) ? TIOCM_RNG : 0);
  67. return value;
  68. }
  69. EXPORT_SYMBOL(usb_wwan_tiocmget);
  70. int usb_wwan_tiocmset(struct tty_struct *tty,
  71. unsigned int set, unsigned int clear)
  72. {
  73. struct usb_serial_port *port = tty->driver_data;
  74. struct usb_wwan_port_private *portdata;
  75. struct usb_wwan_intf_private *intfdata;
  76. portdata = usb_get_serial_port_data(port);
  77. intfdata = port->serial->private;
  78. if (!intfdata->send_setup)
  79. return -EINVAL;
  80. /* FIXME: what locks portdata fields ? */
  81. if (set & TIOCM_RTS)
  82. portdata->rts_state = 1;
  83. if (set & TIOCM_DTR)
  84. portdata->dtr_state = 1;
  85. if (clear & TIOCM_RTS)
  86. portdata->rts_state = 0;
  87. if (clear & TIOCM_DTR)
  88. portdata->dtr_state = 0;
  89. return intfdata->send_setup(port);
  90. }
  91. EXPORT_SYMBOL(usb_wwan_tiocmset);
  92. static int get_serial_info(struct usb_serial_port *port,
  93. struct serial_struct __user *retinfo)
  94. {
  95. struct serial_struct tmp;
  96. if (!retinfo)
  97. return -EFAULT;
  98. memset(&tmp, 0, sizeof(tmp));
  99. tmp.line = port->serial->minor;
  100. tmp.port = port->number;
  101. tmp.baud_base = tty_get_baud_rate(port->port.tty);
  102. tmp.close_delay = port->port.close_delay / 10;
  103. tmp.closing_wait = port->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
  104. ASYNC_CLOSING_WAIT_NONE :
  105. port->port.closing_wait / 10;
  106. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  107. return -EFAULT;
  108. return 0;
  109. }
  110. static int set_serial_info(struct usb_serial_port *port,
  111. struct serial_struct __user *newinfo)
  112. {
  113. struct serial_struct new_serial;
  114. unsigned int closing_wait, close_delay;
  115. int retval = 0;
  116. if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
  117. return -EFAULT;
  118. close_delay = new_serial.close_delay * 10;
  119. closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
  120. ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10;
  121. mutex_lock(&port->port.mutex);
  122. if (!capable(CAP_SYS_ADMIN)) {
  123. if ((close_delay != port->port.close_delay) ||
  124. (closing_wait != port->port.closing_wait))
  125. retval = -EPERM;
  126. else
  127. retval = -EOPNOTSUPP;
  128. } else {
  129. port->port.close_delay = close_delay;
  130. port->port.closing_wait = closing_wait;
  131. }
  132. mutex_unlock(&port->port.mutex);
  133. return retval;
  134. }
  135. int usb_wwan_ioctl(struct tty_struct *tty,
  136. unsigned int cmd, unsigned long arg)
  137. {
  138. struct usb_serial_port *port = tty->driver_data;
  139. dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd);
  140. switch (cmd) {
  141. case TIOCGSERIAL:
  142. return get_serial_info(port,
  143. (struct serial_struct __user *) arg);
  144. case TIOCSSERIAL:
  145. return set_serial_info(port,
  146. (struct serial_struct __user *) arg);
  147. default:
  148. break;
  149. }
  150. dev_dbg(&port->dev, "%s arg not supported\n", __func__);
  151. return -ENOIOCTLCMD;
  152. }
  153. EXPORT_SYMBOL(usb_wwan_ioctl);
  154. /* Write */
  155. int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port,
  156. const unsigned char *buf, int count)
  157. {
  158. struct usb_wwan_port_private *portdata;
  159. struct usb_wwan_intf_private *intfdata;
  160. int i;
  161. int left, todo;
  162. struct urb *this_urb = NULL; /* spurious */
  163. int err;
  164. unsigned long flags;
  165. portdata = usb_get_serial_port_data(port);
  166. intfdata = port->serial->private;
  167. dev_dbg(&port->dev, "%s: write (%d chars)\n", __func__, count);
  168. i = 0;
  169. left = count;
  170. for (i = 0; left > 0 && i < N_OUT_URB; i++) {
  171. todo = left;
  172. if (todo > OUT_BUFLEN)
  173. todo = OUT_BUFLEN;
  174. this_urb = portdata->out_urbs[i];
  175. if (test_and_set_bit(i, &portdata->out_busy)) {
  176. if (time_before(jiffies,
  177. portdata->tx_start_time[i] + 10 * HZ))
  178. continue;
  179. usb_unlink_urb(this_urb);
  180. continue;
  181. }
  182. dev_dbg(&port->dev, "%s: endpoint %d buf %d\n", __func__,
  183. usb_pipeendpoint(this_urb->pipe), i);
  184. err = usb_autopm_get_interface_async(port->serial->interface);
  185. if (err < 0)
  186. break;
  187. /* send the data */
  188. memcpy(this_urb->transfer_buffer, buf, todo);
  189. this_urb->transfer_buffer_length = todo;
  190. spin_lock_irqsave(&intfdata->susp_lock, flags);
  191. if (intfdata->suspended) {
  192. usb_anchor_urb(this_urb, &portdata->delayed);
  193. spin_unlock_irqrestore(&intfdata->susp_lock, flags);
  194. } else {
  195. intfdata->in_flight++;
  196. spin_unlock_irqrestore(&intfdata->susp_lock, flags);
  197. err = usb_submit_urb(this_urb, GFP_ATOMIC);
  198. if (err) {
  199. dev_dbg(&port->dev,
  200. "usb_submit_urb %p (write bulk) failed (%d)\n",
  201. this_urb, err);
  202. clear_bit(i, &portdata->out_busy);
  203. spin_lock_irqsave(&intfdata->susp_lock, flags);
  204. intfdata->in_flight--;
  205. spin_unlock_irqrestore(&intfdata->susp_lock,
  206. flags);
  207. usb_autopm_put_interface_async(port->serial->interface);
  208. break;
  209. }
  210. }
  211. portdata->tx_start_time[i] = jiffies;
  212. buf += todo;
  213. left -= todo;
  214. }
  215. count -= left;
  216. dev_dbg(&port->dev, "%s: wrote (did %d)\n", __func__, count);
  217. return count;
  218. }
  219. EXPORT_SYMBOL(usb_wwan_write);
  220. static void usb_wwan_indat_callback(struct urb *urb)
  221. {
  222. int err;
  223. int endpoint;
  224. struct usb_serial_port *port;
  225. struct tty_struct *tty;
  226. struct device *dev;
  227. unsigned char *data = urb->transfer_buffer;
  228. int status = urb->status;
  229. endpoint = usb_pipeendpoint(urb->pipe);
  230. port = urb->context;
  231. dev = &port->dev;
  232. if (status) {
  233. dev_dbg(dev, "%s: nonzero status: %d on endpoint %02x.\n",
  234. __func__, status, endpoint);
  235. } else {
  236. tty = tty_port_tty_get(&port->port);
  237. if (tty) {
  238. if (urb->actual_length) {
  239. tty_insert_flip_string(tty, data,
  240. urb->actual_length);
  241. tty_flip_buffer_push(tty);
  242. } else
  243. dev_dbg(dev, "%s: empty read urb received\n", __func__);
  244. tty_kref_put(tty);
  245. }
  246. /* Resubmit urb so we continue receiving */
  247. err = usb_submit_urb(urb, GFP_ATOMIC);
  248. if (err) {
  249. if (err != -EPERM) {
  250. dev_err(dev, "%s: resubmit read urb failed. (%d)\n", __func__, err);
  251. /* busy also in error unless we are killed */
  252. usb_mark_last_busy(port->serial->dev);
  253. }
  254. } else {
  255. usb_mark_last_busy(port->serial->dev);
  256. }
  257. }
  258. }
  259. static void usb_wwan_outdat_callback(struct urb *urb)
  260. {
  261. struct usb_serial_port *port;
  262. struct usb_wwan_port_private *portdata;
  263. struct usb_wwan_intf_private *intfdata;
  264. int i;
  265. port = urb->context;
  266. intfdata = port->serial->private;
  267. usb_serial_port_softint(port);
  268. usb_autopm_put_interface_async(port->serial->interface);
  269. portdata = usb_get_serial_port_data(port);
  270. spin_lock(&intfdata->susp_lock);
  271. intfdata->in_flight--;
  272. spin_unlock(&intfdata->susp_lock);
  273. for (i = 0; i < N_OUT_URB; ++i) {
  274. if (portdata->out_urbs[i] == urb) {
  275. smp_mb__before_clear_bit();
  276. clear_bit(i, &portdata->out_busy);
  277. break;
  278. }
  279. }
  280. }
  281. int usb_wwan_write_room(struct tty_struct *tty)
  282. {
  283. struct usb_serial_port *port = tty->driver_data;
  284. struct usb_wwan_port_private *portdata;
  285. int i;
  286. int data_len = 0;
  287. struct urb *this_urb;
  288. portdata = usb_get_serial_port_data(port);
  289. for (i = 0; i < N_OUT_URB; i++) {
  290. this_urb = portdata->out_urbs[i];
  291. if (this_urb && !test_bit(i, &portdata->out_busy))
  292. data_len += OUT_BUFLEN;
  293. }
  294. dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
  295. return data_len;
  296. }
  297. EXPORT_SYMBOL(usb_wwan_write_room);
  298. int usb_wwan_chars_in_buffer(struct tty_struct *tty)
  299. {
  300. struct usb_serial_port *port = tty->driver_data;
  301. struct usb_wwan_port_private *portdata;
  302. int i;
  303. int data_len = 0;
  304. struct urb *this_urb;
  305. portdata = usb_get_serial_port_data(port);
  306. for (i = 0; i < N_OUT_URB; i++) {
  307. this_urb = portdata->out_urbs[i];
  308. /* FIXME: This locking is insufficient as this_urb may
  309. go unused during the test */
  310. if (this_urb && test_bit(i, &portdata->out_busy))
  311. data_len += this_urb->transfer_buffer_length;
  312. }
  313. dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
  314. return data_len;
  315. }
  316. EXPORT_SYMBOL(usb_wwan_chars_in_buffer);
  317. int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port)
  318. {
  319. struct usb_wwan_port_private *portdata;
  320. struct usb_wwan_intf_private *intfdata;
  321. struct usb_serial *serial = port->serial;
  322. int i, err;
  323. struct urb *urb;
  324. portdata = usb_get_serial_port_data(port);
  325. intfdata = serial->private;
  326. /* Start reading from the IN endpoint */
  327. for (i = 0; i < N_IN_URB; i++) {
  328. urb = portdata->in_urbs[i];
  329. if (!urb)
  330. continue;
  331. err = usb_submit_urb(urb, GFP_KERNEL);
  332. if (err) {
  333. dev_dbg(&port->dev, "%s: submit urb %d failed (%d) %d\n",
  334. __func__, i, err, urb->transfer_buffer_length);
  335. }
  336. }
  337. if (intfdata->send_setup)
  338. intfdata->send_setup(port);
  339. serial->interface->needs_remote_wakeup = 1;
  340. spin_lock_irq(&intfdata->susp_lock);
  341. portdata->opened = 1;
  342. spin_unlock_irq(&intfdata->susp_lock);
  343. /* this balances a get in the generic USB serial code */
  344. usb_autopm_put_interface(serial->interface);
  345. return 0;
  346. }
  347. EXPORT_SYMBOL(usb_wwan_open);
  348. void usb_wwan_close(struct usb_serial_port *port)
  349. {
  350. int i;
  351. struct usb_serial *serial = port->serial;
  352. struct usb_wwan_port_private *portdata;
  353. struct usb_wwan_intf_private *intfdata = port->serial->private;
  354. portdata = usb_get_serial_port_data(port);
  355. if (serial->dev) {
  356. /* Stop reading/writing urbs */
  357. spin_lock_irq(&intfdata->susp_lock);
  358. portdata->opened = 0;
  359. spin_unlock_irq(&intfdata->susp_lock);
  360. for (i = 0; i < N_IN_URB; i++)
  361. usb_kill_urb(portdata->in_urbs[i]);
  362. for (i = 0; i < N_OUT_URB; i++)
  363. usb_kill_urb(portdata->out_urbs[i]);
  364. /* balancing - important as an error cannot be handled*/
  365. usb_autopm_get_interface_no_resume(serial->interface);
  366. serial->interface->needs_remote_wakeup = 0;
  367. }
  368. }
  369. EXPORT_SYMBOL(usb_wwan_close);
  370. /* Helper functions used by usb_wwan_setup_urbs */
  371. static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port,
  372. int endpoint,
  373. int dir, void *ctx, char *buf, int len,
  374. void (*callback) (struct urb *))
  375. {
  376. struct usb_serial *serial = port->serial;
  377. struct urb *urb;
  378. urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
  379. if (urb == NULL) {
  380. dev_dbg(&serial->interface->dev,
  381. "%s: alloc for endpoint %d failed.\n", __func__,
  382. endpoint);
  383. return NULL;
  384. }
  385. /* Fill URB using supplied data. */
  386. usb_fill_bulk_urb(urb, serial->dev,
  387. usb_sndbulkpipe(serial->dev, endpoint) | dir,
  388. buf, len, callback, ctx);
  389. return urb;
  390. }
  391. int usb_wwan_port_probe(struct usb_serial_port *port)
  392. {
  393. struct usb_wwan_port_private *portdata;
  394. struct urb *urb;
  395. u8 *buffer;
  396. int err;
  397. int i;
  398. portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
  399. if (!portdata)
  400. return -ENOMEM;
  401. init_usb_anchor(&portdata->delayed);
  402. for (i = 0; i < N_IN_URB; i++) {
  403. if (!port->bulk_in_size)
  404. break;
  405. buffer = (u8 *)__get_free_page(GFP_KERNEL);
  406. if (!buffer)
  407. goto bail_out_error;
  408. portdata->in_buffer[i] = buffer;
  409. urb = usb_wwan_setup_urb(port, port->bulk_in_endpointAddress,
  410. USB_DIR_IN, port,
  411. buffer, IN_BUFLEN,
  412. usb_wwan_indat_callback);
  413. portdata->in_urbs[i] = urb;
  414. }
  415. for (i = 0; i < N_OUT_URB; i++) {
  416. if (!port->bulk_out_size)
  417. break;
  418. buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL);
  419. if (!buffer)
  420. goto bail_out_error2;
  421. portdata->out_buffer[i] = buffer;
  422. urb = usb_wwan_setup_urb(port, port->bulk_out_endpointAddress,
  423. USB_DIR_OUT, port,
  424. buffer, OUT_BUFLEN,
  425. usb_wwan_outdat_callback);
  426. portdata->out_urbs[i] = urb;
  427. }
  428. usb_set_serial_port_data(port, portdata);
  429. if (port->interrupt_in_urb) {
  430. err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  431. if (err)
  432. dev_dbg(&port->dev, "%s: submit irq_in urb failed %d\n",
  433. __func__, err);
  434. }
  435. return 0;
  436. bail_out_error2:
  437. for (i = 0; i < N_OUT_URB; i++) {
  438. usb_free_urb(portdata->out_urbs[i]);
  439. kfree(portdata->out_buffer[i]);
  440. }
  441. bail_out_error:
  442. for (i = 0; i < N_IN_URB; i++) {
  443. usb_free_urb(portdata->in_urbs[i]);
  444. free_page((unsigned long)portdata->in_buffer[i]);
  445. }
  446. kfree(portdata);
  447. return -ENOMEM;
  448. }
  449. EXPORT_SYMBOL_GPL(usb_wwan_port_probe);
  450. int usb_wwan_port_remove(struct usb_serial_port *port)
  451. {
  452. int i;
  453. struct usb_wwan_port_private *portdata;
  454. portdata = usb_get_serial_port_data(port);
  455. usb_set_serial_port_data(port, NULL);
  456. /* Stop reading/writing urbs and free them */
  457. for (i = 0; i < N_IN_URB; i++) {
  458. usb_kill_urb(portdata->in_urbs[i]);
  459. usb_free_urb(portdata->in_urbs[i]);
  460. free_page((unsigned long)portdata->in_buffer[i]);
  461. }
  462. for (i = 0; i < N_OUT_URB; i++) {
  463. usb_kill_urb(portdata->out_urbs[i]);
  464. usb_free_urb(portdata->out_urbs[i]);
  465. kfree(portdata->out_buffer[i]);
  466. }
  467. /* Now free port private data */
  468. kfree(portdata);
  469. return 0;
  470. }
  471. EXPORT_SYMBOL(usb_wwan_port_remove);
  472. #ifdef CONFIG_PM
  473. static void stop_read_write_urbs(struct usb_serial *serial)
  474. {
  475. int i, j;
  476. struct usb_serial_port *port;
  477. struct usb_wwan_port_private *portdata;
  478. /* Stop reading/writing urbs */
  479. for (i = 0; i < serial->num_ports; ++i) {
  480. port = serial->port[i];
  481. portdata = usb_get_serial_port_data(port);
  482. if (!portdata)
  483. continue;
  484. for (j = 0; j < N_IN_URB; j++)
  485. usb_kill_urb(portdata->in_urbs[j]);
  486. for (j = 0; j < N_OUT_URB; j++)
  487. usb_kill_urb(portdata->out_urbs[j]);
  488. }
  489. }
  490. int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message)
  491. {
  492. struct usb_wwan_intf_private *intfdata = serial->private;
  493. int b;
  494. if (PMSG_IS_AUTO(message)) {
  495. spin_lock_irq(&intfdata->susp_lock);
  496. b = intfdata->in_flight;
  497. spin_unlock_irq(&intfdata->susp_lock);
  498. if (b)
  499. return -EBUSY;
  500. }
  501. spin_lock_irq(&intfdata->susp_lock);
  502. intfdata->suspended = 1;
  503. spin_unlock_irq(&intfdata->susp_lock);
  504. stop_read_write_urbs(serial);
  505. return 0;
  506. }
  507. EXPORT_SYMBOL(usb_wwan_suspend);
  508. static void unbusy_queued_urb(struct urb *urb, struct usb_wwan_port_private *portdata)
  509. {
  510. int i;
  511. for (i = 0; i < N_OUT_URB; i++) {
  512. if (urb == portdata->out_urbs[i]) {
  513. clear_bit(i, &portdata->out_busy);
  514. break;
  515. }
  516. }
  517. }
  518. static void play_delayed(struct usb_serial_port *port)
  519. {
  520. struct usb_wwan_intf_private *data;
  521. struct usb_wwan_port_private *portdata;
  522. struct urb *urb;
  523. int err;
  524. portdata = usb_get_serial_port_data(port);
  525. data = port->serial->private;
  526. while ((urb = usb_get_from_anchor(&portdata->delayed))) {
  527. err = usb_submit_urb(urb, GFP_ATOMIC);
  528. if (!err) {
  529. data->in_flight++;
  530. } else {
  531. /* we have to throw away the rest */
  532. do {
  533. unbusy_queued_urb(urb, portdata);
  534. usb_autopm_put_interface_no_suspend(port->serial->interface);
  535. } while ((urb = usb_get_from_anchor(&portdata->delayed)));
  536. break;
  537. }
  538. }
  539. }
  540. int usb_wwan_resume(struct usb_serial *serial)
  541. {
  542. int i, j;
  543. struct usb_serial_port *port;
  544. struct usb_wwan_intf_private *intfdata = serial->private;
  545. struct usb_wwan_port_private *portdata;
  546. struct urb *urb;
  547. int err = 0;
  548. /* get the interrupt URBs resubmitted unconditionally */
  549. for (i = 0; i < serial->num_ports; i++) {
  550. port = serial->port[i];
  551. if (!port->interrupt_in_urb) {
  552. dev_dbg(&port->dev, "%s: No interrupt URB for port\n", __func__);
  553. continue;
  554. }
  555. err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
  556. dev_dbg(&port->dev, "Submitted interrupt URB for port (result %d)\n", err);
  557. if (err < 0) {
  558. dev_err(&port->dev, "%s: Error %d for interrupt URB\n",
  559. __func__, err);
  560. goto err_out;
  561. }
  562. }
  563. for (i = 0; i < serial->num_ports; i++) {
  564. /* walk all ports */
  565. port = serial->port[i];
  566. portdata = usb_get_serial_port_data(port);
  567. /* skip closed ports */
  568. spin_lock_irq(&intfdata->susp_lock);
  569. if (!portdata || !portdata->opened) {
  570. spin_unlock_irq(&intfdata->susp_lock);
  571. continue;
  572. }
  573. for (j = 0; j < N_IN_URB; j++) {
  574. urb = portdata->in_urbs[j];
  575. err = usb_submit_urb(urb, GFP_ATOMIC);
  576. if (err < 0) {
  577. dev_err(&port->dev, "%s: Error %d for bulk URB %d\n",
  578. __func__, err, i);
  579. spin_unlock_irq(&intfdata->susp_lock);
  580. goto err_out;
  581. }
  582. }
  583. play_delayed(port);
  584. spin_unlock_irq(&intfdata->susp_lock);
  585. }
  586. spin_lock_irq(&intfdata->susp_lock);
  587. intfdata->suspended = 0;
  588. spin_unlock_irq(&intfdata->susp_lock);
  589. err_out:
  590. return err;
  591. }
  592. EXPORT_SYMBOL(usb_wwan_resume);
  593. #endif
  594. MODULE_AUTHOR(DRIVER_AUTHOR);
  595. MODULE_DESCRIPTION(DRIVER_DESC);
  596. MODULE_LICENSE("GPL");