usb_wwan.c 17 KB

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