usb_wwan.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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->minor;
  100. tmp.port = 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 device *dev;
  226. unsigned char *data = urb->transfer_buffer;
  227. int status = urb->status;
  228. endpoint = usb_pipeendpoint(urb->pipe);
  229. port = urb->context;
  230. dev = &port->dev;
  231. if (status) {
  232. dev_dbg(dev, "%s: nonzero status: %d on endpoint %02x.\n",
  233. __func__, status, endpoint);
  234. } else {
  235. if (urb->actual_length) {
  236. tty_insert_flip_string(&port->port, data,
  237. urb->actual_length);
  238. tty_flip_buffer_push(&port->port);
  239. } else
  240. dev_dbg(dev, "%s: empty read urb received\n", __func__);
  241. }
  242. /* Resubmit urb so we continue receiving */
  243. err = usb_submit_urb(urb, GFP_ATOMIC);
  244. if (err) {
  245. if (err != -EPERM) {
  246. dev_err(dev, "%s: resubmit read urb failed. (%d)\n",
  247. __func__, err);
  248. /* busy also in error unless we are killed */
  249. usb_mark_last_busy(port->serial->dev);
  250. }
  251. } else {
  252. usb_mark_last_busy(port->serial->dev);
  253. }
  254. }
  255. static void usb_wwan_outdat_callback(struct urb *urb)
  256. {
  257. struct usb_serial_port *port;
  258. struct usb_wwan_port_private *portdata;
  259. struct usb_wwan_intf_private *intfdata;
  260. int i;
  261. port = urb->context;
  262. intfdata = port->serial->private;
  263. usb_serial_port_softint(port);
  264. usb_autopm_put_interface_async(port->serial->interface);
  265. portdata = usb_get_serial_port_data(port);
  266. spin_lock(&intfdata->susp_lock);
  267. intfdata->in_flight--;
  268. spin_unlock(&intfdata->susp_lock);
  269. for (i = 0; i < N_OUT_URB; ++i) {
  270. if (portdata->out_urbs[i] == urb) {
  271. smp_mb__before_clear_bit();
  272. clear_bit(i, &portdata->out_busy);
  273. break;
  274. }
  275. }
  276. }
  277. int usb_wwan_write_room(struct tty_struct *tty)
  278. {
  279. struct usb_serial_port *port = tty->driver_data;
  280. struct usb_wwan_port_private *portdata;
  281. int i;
  282. int data_len = 0;
  283. struct urb *this_urb;
  284. portdata = usb_get_serial_port_data(port);
  285. for (i = 0; i < N_OUT_URB; i++) {
  286. this_urb = portdata->out_urbs[i];
  287. if (this_urb && !test_bit(i, &portdata->out_busy))
  288. data_len += OUT_BUFLEN;
  289. }
  290. dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
  291. return data_len;
  292. }
  293. EXPORT_SYMBOL(usb_wwan_write_room);
  294. int usb_wwan_chars_in_buffer(struct tty_struct *tty)
  295. {
  296. struct usb_serial_port *port = tty->driver_data;
  297. struct usb_wwan_port_private *portdata;
  298. int i;
  299. int data_len = 0;
  300. struct urb *this_urb;
  301. portdata = usb_get_serial_port_data(port);
  302. for (i = 0; i < N_OUT_URB; i++) {
  303. this_urb = portdata->out_urbs[i];
  304. /* FIXME: This locking is insufficient as this_urb may
  305. go unused during the test */
  306. if (this_urb && test_bit(i, &portdata->out_busy))
  307. data_len += this_urb->transfer_buffer_length;
  308. }
  309. dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
  310. return data_len;
  311. }
  312. EXPORT_SYMBOL(usb_wwan_chars_in_buffer);
  313. int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port)
  314. {
  315. struct usb_wwan_port_private *portdata;
  316. struct usb_wwan_intf_private *intfdata;
  317. struct usb_serial *serial = port->serial;
  318. int i, err;
  319. struct urb *urb;
  320. portdata = usb_get_serial_port_data(port);
  321. intfdata = serial->private;
  322. /* Start reading from the IN endpoint */
  323. for (i = 0; i < N_IN_URB; i++) {
  324. urb = portdata->in_urbs[i];
  325. if (!urb)
  326. continue;
  327. err = usb_submit_urb(urb, GFP_KERNEL);
  328. if (err) {
  329. dev_dbg(&port->dev, "%s: submit urb %d failed (%d) %d\n",
  330. __func__, i, err, urb->transfer_buffer_length);
  331. }
  332. }
  333. if (intfdata->send_setup)
  334. intfdata->send_setup(port);
  335. serial->interface->needs_remote_wakeup = 1;
  336. spin_lock_irq(&intfdata->susp_lock);
  337. portdata->opened = 1;
  338. spin_unlock_irq(&intfdata->susp_lock);
  339. /* this balances a get in the generic USB serial code */
  340. usb_autopm_put_interface(serial->interface);
  341. return 0;
  342. }
  343. EXPORT_SYMBOL(usb_wwan_open);
  344. void usb_wwan_close(struct usb_serial_port *port)
  345. {
  346. int i;
  347. struct usb_serial *serial = port->serial;
  348. struct usb_wwan_port_private *portdata;
  349. struct usb_wwan_intf_private *intfdata = port->serial->private;
  350. portdata = usb_get_serial_port_data(port);
  351. /* Stop reading/writing urbs */
  352. spin_lock_irq(&intfdata->susp_lock);
  353. portdata->opened = 0;
  354. spin_unlock_irq(&intfdata->susp_lock);
  355. for (i = 0; i < N_IN_URB; i++)
  356. usb_kill_urb(portdata->in_urbs[i]);
  357. for (i = 0; i < N_OUT_URB; i++)
  358. usb_kill_urb(portdata->out_urbs[i]);
  359. /* balancing - important as an error cannot be handled*/
  360. usb_autopm_get_interface_no_resume(serial->interface);
  361. serial->interface->needs_remote_wakeup = 0;
  362. }
  363. EXPORT_SYMBOL(usb_wwan_close);
  364. /* Helper functions used by usb_wwan_setup_urbs */
  365. static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port,
  366. int endpoint,
  367. int dir, void *ctx, char *buf, int len,
  368. void (*callback) (struct urb *))
  369. {
  370. struct usb_serial *serial = port->serial;
  371. struct urb *urb;
  372. urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
  373. if (!urb)
  374. return NULL;
  375. /* Fill URB using supplied data. */
  376. usb_fill_bulk_urb(urb, serial->dev,
  377. usb_sndbulkpipe(serial->dev, endpoint) | dir,
  378. buf, len, callback, ctx);
  379. return urb;
  380. }
  381. int usb_wwan_port_probe(struct usb_serial_port *port)
  382. {
  383. struct usb_wwan_port_private *portdata;
  384. struct urb *urb;
  385. u8 *buffer;
  386. int err;
  387. int i;
  388. portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
  389. if (!portdata)
  390. return -ENOMEM;
  391. init_usb_anchor(&portdata->delayed);
  392. for (i = 0; i < N_IN_URB; i++) {
  393. if (!port->bulk_in_size)
  394. break;
  395. buffer = (u8 *)__get_free_page(GFP_KERNEL);
  396. if (!buffer)
  397. goto bail_out_error;
  398. portdata->in_buffer[i] = buffer;
  399. urb = usb_wwan_setup_urb(port, port->bulk_in_endpointAddress,
  400. USB_DIR_IN, port,
  401. buffer, IN_BUFLEN,
  402. usb_wwan_indat_callback);
  403. portdata->in_urbs[i] = urb;
  404. }
  405. for (i = 0; i < N_OUT_URB; i++) {
  406. if (!port->bulk_out_size)
  407. break;
  408. buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL);
  409. if (!buffer)
  410. goto bail_out_error2;
  411. portdata->out_buffer[i] = buffer;
  412. urb = usb_wwan_setup_urb(port, port->bulk_out_endpointAddress,
  413. USB_DIR_OUT, port,
  414. buffer, OUT_BUFLEN,
  415. usb_wwan_outdat_callback);
  416. portdata->out_urbs[i] = urb;
  417. }
  418. usb_set_serial_port_data(port, portdata);
  419. if (port->interrupt_in_urb) {
  420. err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  421. if (err)
  422. dev_dbg(&port->dev, "%s: submit irq_in urb failed %d\n",
  423. __func__, err);
  424. }
  425. return 0;
  426. bail_out_error2:
  427. for (i = 0; i < N_OUT_URB; i++) {
  428. usb_free_urb(portdata->out_urbs[i]);
  429. kfree(portdata->out_buffer[i]);
  430. }
  431. bail_out_error:
  432. for (i = 0; i < N_IN_URB; i++) {
  433. usb_free_urb(portdata->in_urbs[i]);
  434. free_page((unsigned long)portdata->in_buffer[i]);
  435. }
  436. kfree(portdata);
  437. return -ENOMEM;
  438. }
  439. EXPORT_SYMBOL_GPL(usb_wwan_port_probe);
  440. int usb_wwan_port_remove(struct usb_serial_port *port)
  441. {
  442. int i;
  443. struct usb_wwan_port_private *portdata;
  444. portdata = usb_get_serial_port_data(port);
  445. usb_set_serial_port_data(port, NULL);
  446. /* Stop reading/writing urbs and free them */
  447. for (i = 0; i < N_IN_URB; i++) {
  448. usb_kill_urb(portdata->in_urbs[i]);
  449. usb_free_urb(portdata->in_urbs[i]);
  450. free_page((unsigned long)portdata->in_buffer[i]);
  451. }
  452. for (i = 0; i < N_OUT_URB; i++) {
  453. usb_kill_urb(portdata->out_urbs[i]);
  454. usb_free_urb(portdata->out_urbs[i]);
  455. kfree(portdata->out_buffer[i]);
  456. }
  457. /* Now free port private data */
  458. kfree(portdata);
  459. return 0;
  460. }
  461. EXPORT_SYMBOL(usb_wwan_port_remove);
  462. #ifdef CONFIG_PM
  463. static void stop_read_write_urbs(struct usb_serial *serial)
  464. {
  465. int i, j;
  466. struct usb_serial_port *port;
  467. struct usb_wwan_port_private *portdata;
  468. /* Stop reading/writing urbs */
  469. for (i = 0; i < serial->num_ports; ++i) {
  470. port = serial->port[i];
  471. portdata = usb_get_serial_port_data(port);
  472. if (!portdata)
  473. continue;
  474. for (j = 0; j < N_IN_URB; j++)
  475. usb_kill_urb(portdata->in_urbs[j]);
  476. for (j = 0; j < N_OUT_URB; j++)
  477. usb_kill_urb(portdata->out_urbs[j]);
  478. }
  479. }
  480. int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message)
  481. {
  482. struct usb_wwan_intf_private *intfdata = serial->private;
  483. int b;
  484. if (PMSG_IS_AUTO(message)) {
  485. spin_lock_irq(&intfdata->susp_lock);
  486. b = intfdata->in_flight;
  487. spin_unlock_irq(&intfdata->susp_lock);
  488. if (b)
  489. return -EBUSY;
  490. }
  491. spin_lock_irq(&intfdata->susp_lock);
  492. intfdata->suspended = 1;
  493. spin_unlock_irq(&intfdata->susp_lock);
  494. stop_read_write_urbs(serial);
  495. return 0;
  496. }
  497. EXPORT_SYMBOL(usb_wwan_suspend);
  498. static void unbusy_queued_urb(struct urb *urb, struct usb_wwan_port_private *portdata)
  499. {
  500. int i;
  501. for (i = 0; i < N_OUT_URB; i++) {
  502. if (urb == portdata->out_urbs[i]) {
  503. clear_bit(i, &portdata->out_busy);
  504. break;
  505. }
  506. }
  507. }
  508. static void play_delayed(struct usb_serial_port *port)
  509. {
  510. struct usb_wwan_intf_private *data;
  511. struct usb_wwan_port_private *portdata;
  512. struct urb *urb;
  513. int err;
  514. portdata = usb_get_serial_port_data(port);
  515. data = port->serial->private;
  516. while ((urb = usb_get_from_anchor(&portdata->delayed))) {
  517. err = usb_submit_urb(urb, GFP_ATOMIC);
  518. if (!err) {
  519. data->in_flight++;
  520. } else {
  521. /* we have to throw away the rest */
  522. do {
  523. unbusy_queued_urb(urb, portdata);
  524. usb_autopm_put_interface_no_suspend(port->serial->interface);
  525. } while ((urb = usb_get_from_anchor(&portdata->delayed)));
  526. break;
  527. }
  528. }
  529. }
  530. int usb_wwan_resume(struct usb_serial *serial)
  531. {
  532. int i, j;
  533. struct usb_serial_port *port;
  534. struct usb_wwan_intf_private *intfdata = serial->private;
  535. struct usb_wwan_port_private *portdata;
  536. struct urb *urb;
  537. int err = 0;
  538. /* get the interrupt URBs resubmitted unconditionally */
  539. for (i = 0; i < serial->num_ports; i++) {
  540. port = serial->port[i];
  541. if (!port->interrupt_in_urb) {
  542. dev_dbg(&port->dev, "%s: No interrupt URB for port\n", __func__);
  543. continue;
  544. }
  545. err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
  546. dev_dbg(&port->dev, "Submitted interrupt URB for port (result %d)\n", err);
  547. if (err < 0) {
  548. dev_err(&port->dev, "%s: Error %d for interrupt URB\n",
  549. __func__, err);
  550. goto err_out;
  551. }
  552. }
  553. for (i = 0; i < serial->num_ports; i++) {
  554. /* walk all ports */
  555. port = serial->port[i];
  556. portdata = usb_get_serial_port_data(port);
  557. /* skip closed ports */
  558. spin_lock_irq(&intfdata->susp_lock);
  559. if (!portdata || !portdata->opened) {
  560. spin_unlock_irq(&intfdata->susp_lock);
  561. continue;
  562. }
  563. for (j = 0; j < N_IN_URB; j++) {
  564. urb = portdata->in_urbs[j];
  565. err = usb_submit_urb(urb, GFP_ATOMIC);
  566. if (err < 0) {
  567. dev_err(&port->dev, "%s: Error %d for bulk URB %d\n",
  568. __func__, err, i);
  569. spin_unlock_irq(&intfdata->susp_lock);
  570. goto err_out;
  571. }
  572. }
  573. play_delayed(port);
  574. spin_unlock_irq(&intfdata->susp_lock);
  575. }
  576. spin_lock_irq(&intfdata->susp_lock);
  577. intfdata->suspended = 0;
  578. spin_unlock_irq(&intfdata->susp_lock);
  579. err_out:
  580. return err;
  581. }
  582. EXPORT_SYMBOL(usb_wwan_resume);
  583. #endif
  584. MODULE_AUTHOR(DRIVER_AUTHOR);
  585. MODULE_DESCRIPTION(DRIVER_DESC);
  586. MODULE_LICENSE("GPL");