usb_wwan.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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. static int get_serial_info(struct usb_serial_port *port,
  106. struct serial_struct __user *retinfo)
  107. {
  108. struct serial_struct tmp;
  109. memset(&tmp, 0, sizeof(tmp));
  110. tmp.line = port->minor;
  111. tmp.port = port->port_number;
  112. tmp.baud_base = tty_get_baud_rate(port->port.tty);
  113. tmp.close_delay = port->port.close_delay / 10;
  114. tmp.closing_wait = port->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
  115. ASYNC_CLOSING_WAIT_NONE :
  116. port->port.closing_wait / 10;
  117. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  118. return -EFAULT;
  119. return 0;
  120. }
  121. static int set_serial_info(struct usb_serial_port *port,
  122. struct serial_struct __user *newinfo)
  123. {
  124. struct serial_struct new_serial;
  125. unsigned int closing_wait, close_delay;
  126. int retval = 0;
  127. if (copy_from_user(&new_serial, newinfo, sizeof(new_serial)))
  128. return -EFAULT;
  129. close_delay = new_serial.close_delay * 10;
  130. closing_wait = new_serial.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
  131. ASYNC_CLOSING_WAIT_NONE : new_serial.closing_wait * 10;
  132. mutex_lock(&port->port.mutex);
  133. if (!capable(CAP_SYS_ADMIN)) {
  134. if ((close_delay != port->port.close_delay) ||
  135. (closing_wait != port->port.closing_wait))
  136. retval = -EPERM;
  137. else
  138. retval = -EOPNOTSUPP;
  139. } else {
  140. port->port.close_delay = close_delay;
  141. port->port.closing_wait = closing_wait;
  142. }
  143. mutex_unlock(&port->port.mutex);
  144. return retval;
  145. }
  146. int usb_wwan_ioctl(struct tty_struct *tty,
  147. unsigned int cmd, unsigned long arg)
  148. {
  149. struct usb_serial_port *port = tty->driver_data;
  150. dev_dbg(&port->dev, "%s cmd 0x%04x\n", __func__, cmd);
  151. switch (cmd) {
  152. case TIOCGSERIAL:
  153. return get_serial_info(port,
  154. (struct serial_struct __user *) arg);
  155. case TIOCSSERIAL:
  156. return set_serial_info(port,
  157. (struct serial_struct __user *) arg);
  158. default:
  159. break;
  160. }
  161. dev_dbg(&port->dev, "%s arg not supported\n", __func__);
  162. return -ENOIOCTLCMD;
  163. }
  164. EXPORT_SYMBOL(usb_wwan_ioctl);
  165. int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port,
  166. const unsigned char *buf, int count)
  167. {
  168. struct usb_wwan_port_private *portdata;
  169. struct usb_wwan_intf_private *intfdata;
  170. int i;
  171. int left, todo;
  172. struct urb *this_urb = NULL; /* spurious */
  173. int err;
  174. unsigned long flags;
  175. portdata = usb_get_serial_port_data(port);
  176. intfdata = usb_get_serial_data(port->serial);
  177. dev_dbg(&port->dev, "%s: write (%d chars)\n", __func__, count);
  178. i = 0;
  179. left = count;
  180. for (i = 0; left > 0 && i < N_OUT_URB; i++) {
  181. todo = left;
  182. if (todo > OUT_BUFLEN)
  183. todo = OUT_BUFLEN;
  184. this_urb = portdata->out_urbs[i];
  185. if (test_and_set_bit(i, &portdata->out_busy)) {
  186. if (time_before(jiffies,
  187. portdata->tx_start_time[i] + 10 * HZ))
  188. continue;
  189. usb_unlink_urb(this_urb);
  190. continue;
  191. }
  192. dev_dbg(&port->dev, "%s: endpoint %d buf %d\n", __func__,
  193. usb_pipeendpoint(this_urb->pipe), i);
  194. err = usb_autopm_get_interface_async(port->serial->interface);
  195. if (err < 0) {
  196. clear_bit(i, &portdata->out_busy);
  197. break;
  198. }
  199. /* send the data */
  200. memcpy(this_urb->transfer_buffer, buf, todo);
  201. this_urb->transfer_buffer_length = todo;
  202. spin_lock_irqsave(&intfdata->susp_lock, flags);
  203. if (intfdata->suspended) {
  204. usb_anchor_urb(this_urb, &portdata->delayed);
  205. spin_unlock_irqrestore(&intfdata->susp_lock, flags);
  206. } else {
  207. intfdata->in_flight++;
  208. spin_unlock_irqrestore(&intfdata->susp_lock, flags);
  209. err = usb_submit_urb(this_urb, GFP_ATOMIC);
  210. if (err) {
  211. dev_err(&port->dev,
  212. "%s: submit urb %d failed: %d\n",
  213. __func__, i, err);
  214. clear_bit(i, &portdata->out_busy);
  215. spin_lock_irqsave(&intfdata->susp_lock, flags);
  216. intfdata->in_flight--;
  217. spin_unlock_irqrestore(&intfdata->susp_lock,
  218. flags);
  219. usb_autopm_put_interface_async(port->serial->interface);
  220. break;
  221. }
  222. }
  223. portdata->tx_start_time[i] = jiffies;
  224. buf += todo;
  225. left -= todo;
  226. }
  227. count -= left;
  228. dev_dbg(&port->dev, "%s: wrote (did %d)\n", __func__, count);
  229. return count;
  230. }
  231. EXPORT_SYMBOL(usb_wwan_write);
  232. static void usb_wwan_indat_callback(struct urb *urb)
  233. {
  234. int err;
  235. int endpoint;
  236. struct usb_serial_port *port;
  237. struct device *dev;
  238. unsigned char *data = urb->transfer_buffer;
  239. int status = urb->status;
  240. endpoint = usb_pipeendpoint(urb->pipe);
  241. port = urb->context;
  242. dev = &port->dev;
  243. if (status) {
  244. dev_dbg(dev, "%s: nonzero status: %d on endpoint %02x.\n",
  245. __func__, status, endpoint);
  246. } else {
  247. if (urb->actual_length) {
  248. tty_insert_flip_string(&port->port, data,
  249. urb->actual_length);
  250. tty_flip_buffer_push(&port->port);
  251. } else
  252. dev_dbg(dev, "%s: empty read urb received\n", __func__);
  253. }
  254. /* Resubmit urb so we continue receiving */
  255. err = usb_submit_urb(urb, GFP_ATOMIC);
  256. if (err) {
  257. if (err != -EPERM && err != -ENODEV) {
  258. dev_err(dev, "%s: resubmit read urb failed. (%d)\n",
  259. __func__, err);
  260. /* busy also in error unless we are killed */
  261. usb_mark_last_busy(port->serial->dev);
  262. }
  263. } else {
  264. usb_mark_last_busy(port->serial->dev);
  265. }
  266. }
  267. static void usb_wwan_outdat_callback(struct urb *urb)
  268. {
  269. struct usb_serial_port *port;
  270. struct usb_wwan_port_private *portdata;
  271. struct usb_wwan_intf_private *intfdata;
  272. int i;
  273. port = urb->context;
  274. intfdata = usb_get_serial_data(port->serial);
  275. usb_serial_port_softint(port);
  276. usb_autopm_put_interface_async(port->serial->interface);
  277. portdata = usb_get_serial_port_data(port);
  278. spin_lock(&intfdata->susp_lock);
  279. intfdata->in_flight--;
  280. spin_unlock(&intfdata->susp_lock);
  281. for (i = 0; i < N_OUT_URB; ++i) {
  282. if (portdata->out_urbs[i] == urb) {
  283. smp_mb__before_atomic();
  284. clear_bit(i, &portdata->out_busy);
  285. break;
  286. }
  287. }
  288. }
  289. int usb_wwan_write_room(struct tty_struct *tty)
  290. {
  291. struct usb_serial_port *port = tty->driver_data;
  292. struct usb_wwan_port_private *portdata;
  293. int i;
  294. int data_len = 0;
  295. struct urb *this_urb;
  296. portdata = usb_get_serial_port_data(port);
  297. for (i = 0; i < N_OUT_URB; i++) {
  298. this_urb = portdata->out_urbs[i];
  299. if (this_urb && !test_bit(i, &portdata->out_busy))
  300. data_len += OUT_BUFLEN;
  301. }
  302. dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
  303. return data_len;
  304. }
  305. EXPORT_SYMBOL(usb_wwan_write_room);
  306. int usb_wwan_chars_in_buffer(struct tty_struct *tty)
  307. {
  308. struct usb_serial_port *port = tty->driver_data;
  309. struct usb_wwan_port_private *portdata;
  310. int i;
  311. int data_len = 0;
  312. struct urb *this_urb;
  313. portdata = usb_get_serial_port_data(port);
  314. for (i = 0; i < N_OUT_URB; i++) {
  315. this_urb = portdata->out_urbs[i];
  316. /* FIXME: This locking is insufficient as this_urb may
  317. go unused during the test */
  318. if (this_urb && test_bit(i, &portdata->out_busy))
  319. data_len += this_urb->transfer_buffer_length;
  320. }
  321. dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
  322. return data_len;
  323. }
  324. EXPORT_SYMBOL(usb_wwan_chars_in_buffer);
  325. int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port)
  326. {
  327. struct usb_wwan_port_private *portdata;
  328. struct usb_wwan_intf_private *intfdata;
  329. struct usb_serial *serial = port->serial;
  330. int i, err;
  331. struct urb *urb;
  332. portdata = usb_get_serial_port_data(port);
  333. intfdata = usb_get_serial_data(serial);
  334. if (port->interrupt_in_urb) {
  335. err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  336. if (err) {
  337. dev_err(&port->dev, "%s: submit int urb failed: %d\n",
  338. __func__, err);
  339. }
  340. }
  341. /* Start reading from the IN endpoint */
  342. for (i = 0; i < N_IN_URB; i++) {
  343. urb = portdata->in_urbs[i];
  344. if (!urb)
  345. continue;
  346. err = usb_submit_urb(urb, GFP_KERNEL);
  347. if (err) {
  348. dev_err(&port->dev,
  349. "%s: submit read urb %d failed: %d\n",
  350. __func__, i, err);
  351. }
  352. }
  353. spin_lock_irq(&intfdata->susp_lock);
  354. if (++intfdata->open_ports == 1)
  355. serial->interface->needs_remote_wakeup = 1;
  356. spin_unlock_irq(&intfdata->susp_lock);
  357. /* this balances a get in the generic USB serial code */
  358. usb_autopm_put_interface(serial->interface);
  359. return 0;
  360. }
  361. EXPORT_SYMBOL(usb_wwan_open);
  362. static void unbusy_queued_urb(struct urb *urb,
  363. struct usb_wwan_port_private *portdata)
  364. {
  365. int i;
  366. for (i = 0; i < N_OUT_URB; i++) {
  367. if (urb == portdata->out_urbs[i]) {
  368. clear_bit(i, &portdata->out_busy);
  369. break;
  370. }
  371. }
  372. }
  373. void usb_wwan_close(struct usb_serial_port *port)
  374. {
  375. int i;
  376. struct usb_serial *serial = port->serial;
  377. struct usb_wwan_port_private *portdata;
  378. struct usb_wwan_intf_private *intfdata = usb_get_serial_data(serial);
  379. struct urb *urb;
  380. portdata = usb_get_serial_port_data(port);
  381. /*
  382. * Need to take susp_lock to make sure port is not already being
  383. * resumed, but no need to hold it due to initialized
  384. */
  385. spin_lock_irq(&intfdata->susp_lock);
  386. if (--intfdata->open_ports == 0)
  387. serial->interface->needs_remote_wakeup = 0;
  388. spin_unlock_irq(&intfdata->susp_lock);
  389. for (;;) {
  390. urb = usb_get_from_anchor(&portdata->delayed);
  391. if (!urb)
  392. break;
  393. unbusy_queued_urb(urb, portdata);
  394. usb_autopm_put_interface_async(serial->interface);
  395. }
  396. for (i = 0; i < N_IN_URB; i++)
  397. usb_kill_urb(portdata->in_urbs[i]);
  398. for (i = 0; i < N_OUT_URB; i++)
  399. usb_kill_urb(portdata->out_urbs[i]);
  400. usb_kill_urb(port->interrupt_in_urb);
  401. usb_autopm_get_interface_no_resume(serial->interface);
  402. }
  403. EXPORT_SYMBOL(usb_wwan_close);
  404. static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port,
  405. int endpoint,
  406. int dir, void *ctx, char *buf, int len,
  407. void (*callback) (struct urb *))
  408. {
  409. struct usb_serial *serial = port->serial;
  410. struct urb *urb;
  411. urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
  412. if (!urb)
  413. return NULL;
  414. usb_fill_bulk_urb(urb, serial->dev,
  415. usb_sndbulkpipe(serial->dev, endpoint) | dir,
  416. buf, len, callback, ctx);
  417. return urb;
  418. }
  419. int usb_wwan_port_probe(struct usb_serial_port *port)
  420. {
  421. struct usb_wwan_port_private *portdata;
  422. struct urb *urb;
  423. u8 *buffer;
  424. int i;
  425. if (!port->bulk_in_size || !port->bulk_out_size)
  426. return -ENODEV;
  427. portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
  428. if (!portdata)
  429. return -ENOMEM;
  430. init_usb_anchor(&portdata->delayed);
  431. for (i = 0; i < N_IN_URB; i++) {
  432. buffer = (u8 *)__get_free_page(GFP_KERNEL);
  433. if (!buffer)
  434. goto bail_out_error;
  435. portdata->in_buffer[i] = buffer;
  436. urb = usb_wwan_setup_urb(port, port->bulk_in_endpointAddress,
  437. USB_DIR_IN, port,
  438. buffer, IN_BUFLEN,
  439. usb_wwan_indat_callback);
  440. portdata->in_urbs[i] = urb;
  441. }
  442. for (i = 0; i < N_OUT_URB; i++) {
  443. buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL);
  444. if (!buffer)
  445. goto bail_out_error2;
  446. portdata->out_buffer[i] = buffer;
  447. urb = usb_wwan_setup_urb(port, port->bulk_out_endpointAddress,
  448. USB_DIR_OUT, port,
  449. buffer, OUT_BUFLEN,
  450. usb_wwan_outdat_callback);
  451. portdata->out_urbs[i] = urb;
  452. }
  453. usb_set_serial_port_data(port, portdata);
  454. return 0;
  455. bail_out_error2:
  456. for (i = 0; i < N_OUT_URB; i++) {
  457. usb_free_urb(portdata->out_urbs[i]);
  458. kfree(portdata->out_buffer[i]);
  459. }
  460. bail_out_error:
  461. for (i = 0; i < N_IN_URB; i++) {
  462. usb_free_urb(portdata->in_urbs[i]);
  463. free_page((unsigned long)portdata->in_buffer[i]);
  464. }
  465. kfree(portdata);
  466. return -ENOMEM;
  467. }
  468. EXPORT_SYMBOL_GPL(usb_wwan_port_probe);
  469. int usb_wwan_port_remove(struct usb_serial_port *port)
  470. {
  471. int i;
  472. struct usb_wwan_port_private *portdata;
  473. portdata = usb_get_serial_port_data(port);
  474. usb_set_serial_port_data(port, NULL);
  475. for (i = 0; i < N_IN_URB; i++) {
  476. usb_free_urb(portdata->in_urbs[i]);
  477. free_page((unsigned long)portdata->in_buffer[i]);
  478. }
  479. for (i = 0; i < N_OUT_URB; i++) {
  480. usb_free_urb(portdata->out_urbs[i]);
  481. kfree(portdata->out_buffer[i]);
  482. }
  483. kfree(portdata);
  484. return 0;
  485. }
  486. EXPORT_SYMBOL(usb_wwan_port_remove);
  487. #ifdef CONFIG_PM
  488. static void stop_urbs(struct usb_serial *serial)
  489. {
  490. int i, j;
  491. struct usb_serial_port *port;
  492. struct usb_wwan_port_private *portdata;
  493. for (i = 0; i < serial->num_ports; ++i) {
  494. port = serial->port[i];
  495. portdata = usb_get_serial_port_data(port);
  496. if (!portdata)
  497. continue;
  498. for (j = 0; j < N_IN_URB; j++)
  499. usb_kill_urb(portdata->in_urbs[j]);
  500. for (j = 0; j < N_OUT_URB; j++)
  501. usb_kill_urb(portdata->out_urbs[j]);
  502. usb_kill_urb(port->interrupt_in_urb);
  503. }
  504. }
  505. int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message)
  506. {
  507. struct usb_wwan_intf_private *intfdata = usb_get_serial_data(serial);
  508. spin_lock_irq(&intfdata->susp_lock);
  509. if (PMSG_IS_AUTO(message)) {
  510. if (intfdata->in_flight) {
  511. spin_unlock_irq(&intfdata->susp_lock);
  512. return -EBUSY;
  513. }
  514. }
  515. intfdata->suspended = 1;
  516. spin_unlock_irq(&intfdata->susp_lock);
  517. stop_urbs(serial);
  518. return 0;
  519. }
  520. EXPORT_SYMBOL(usb_wwan_suspend);
  521. /* Caller must hold susp_lock. */
  522. static int usb_wwan_submit_delayed_urbs(struct usb_serial_port *port)
  523. {
  524. struct usb_serial *serial = port->serial;
  525. struct usb_wwan_intf_private *data = usb_get_serial_data(serial);
  526. struct usb_wwan_port_private *portdata;
  527. struct urb *urb;
  528. int err_count = 0;
  529. int err;
  530. portdata = usb_get_serial_port_data(port);
  531. for (;;) {
  532. urb = usb_get_from_anchor(&portdata->delayed);
  533. if (!urb)
  534. break;
  535. err = usb_submit_urb(urb, GFP_ATOMIC);
  536. if (err) {
  537. dev_err(&port->dev, "%s: submit urb failed: %d\n",
  538. __func__, err);
  539. err_count++;
  540. unbusy_queued_urb(urb, portdata);
  541. usb_autopm_put_interface_async(serial->interface);
  542. continue;
  543. }
  544. data->in_flight++;
  545. }
  546. if (err_count)
  547. return -EIO;
  548. return 0;
  549. }
  550. int usb_wwan_resume(struct usb_serial *serial)
  551. {
  552. int i, j;
  553. struct usb_serial_port *port;
  554. struct usb_wwan_intf_private *intfdata = usb_get_serial_data(serial);
  555. struct usb_wwan_port_private *portdata;
  556. struct urb *urb;
  557. int err;
  558. int err_count = 0;
  559. spin_lock_irq(&intfdata->susp_lock);
  560. for (i = 0; i < serial->num_ports; i++) {
  561. port = serial->port[i];
  562. if (!tty_port_initialized(&port->port))
  563. continue;
  564. portdata = usb_get_serial_port_data(port);
  565. if (port->interrupt_in_urb) {
  566. err = usb_submit_urb(port->interrupt_in_urb,
  567. GFP_ATOMIC);
  568. if (err) {
  569. dev_err(&port->dev,
  570. "%s: submit int urb failed: %d\n",
  571. __func__, err);
  572. err_count++;
  573. }
  574. }
  575. err = usb_wwan_submit_delayed_urbs(port);
  576. if (err)
  577. err_count++;
  578. for (j = 0; j < N_IN_URB; j++) {
  579. urb = portdata->in_urbs[j];
  580. err = usb_submit_urb(urb, GFP_ATOMIC);
  581. if (err < 0) {
  582. dev_err(&port->dev,
  583. "%s: submit read urb %d failed: %d\n",
  584. __func__, i, err);
  585. err_count++;
  586. }
  587. }
  588. }
  589. intfdata->suspended = 0;
  590. spin_unlock_irq(&intfdata->susp_lock);
  591. if (err_count)
  592. return -EIO;
  593. return 0;
  594. }
  595. EXPORT_SYMBOL(usb_wwan_resume);
  596. #endif
  597. MODULE_AUTHOR(DRIVER_AUTHOR);
  598. MODULE_DESCRIPTION(DRIVER_DESC);
  599. MODULE_LICENSE("GPL v2");