usb_wwan.c 18 KB

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