usb_wwan.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. } else {
  249. if (urb->actual_length) {
  250. tty_insert_flip_string(&port->port, data,
  251. urb->actual_length);
  252. tty_flip_buffer_push(&port->port);
  253. } else
  254. dev_dbg(dev, "%s: empty read urb received\n", __func__);
  255. }
  256. /* Resubmit urb so we continue receiving */
  257. err = usb_submit_urb(urb, GFP_ATOMIC);
  258. if (err) {
  259. if (err != -EPERM && err != -ENODEV) {
  260. dev_err(dev, "%s: resubmit read urb failed. (%d)\n",
  261. __func__, err);
  262. /* busy also in error unless we are killed */
  263. usb_mark_last_busy(port->serial->dev);
  264. }
  265. } else {
  266. usb_mark_last_busy(port->serial->dev);
  267. }
  268. }
  269. static void usb_wwan_outdat_callback(struct urb *urb)
  270. {
  271. struct usb_serial_port *port;
  272. struct usb_wwan_port_private *portdata;
  273. struct usb_wwan_intf_private *intfdata;
  274. int i;
  275. port = urb->context;
  276. intfdata = usb_get_serial_data(port->serial);
  277. usb_serial_port_softint(port);
  278. usb_autopm_put_interface_async(port->serial->interface);
  279. portdata = usb_get_serial_port_data(port);
  280. spin_lock(&intfdata->susp_lock);
  281. intfdata->in_flight--;
  282. spin_unlock(&intfdata->susp_lock);
  283. for (i = 0; i < N_OUT_URB; ++i) {
  284. if (portdata->out_urbs[i] == urb) {
  285. smp_mb__before_atomic();
  286. clear_bit(i, &portdata->out_busy);
  287. break;
  288. }
  289. }
  290. }
  291. int usb_wwan_write_room(struct tty_struct *tty)
  292. {
  293. struct usb_serial_port *port = tty->driver_data;
  294. struct usb_wwan_port_private *portdata;
  295. int i;
  296. int data_len = 0;
  297. struct urb *this_urb;
  298. portdata = usb_get_serial_port_data(port);
  299. for (i = 0; i < N_OUT_URB; i++) {
  300. this_urb = portdata->out_urbs[i];
  301. if (this_urb && !test_bit(i, &portdata->out_busy))
  302. data_len += OUT_BUFLEN;
  303. }
  304. dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
  305. return data_len;
  306. }
  307. EXPORT_SYMBOL(usb_wwan_write_room);
  308. int usb_wwan_chars_in_buffer(struct tty_struct *tty)
  309. {
  310. struct usb_serial_port *port = tty->driver_data;
  311. struct usb_wwan_port_private *portdata;
  312. int i;
  313. int data_len = 0;
  314. struct urb *this_urb;
  315. portdata = usb_get_serial_port_data(port);
  316. for (i = 0; i < N_OUT_URB; i++) {
  317. this_urb = portdata->out_urbs[i];
  318. /* FIXME: This locking is insufficient as this_urb may
  319. go unused during the test */
  320. if (this_urb && test_bit(i, &portdata->out_busy))
  321. data_len += this_urb->transfer_buffer_length;
  322. }
  323. dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
  324. return data_len;
  325. }
  326. EXPORT_SYMBOL(usb_wwan_chars_in_buffer);
  327. int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port)
  328. {
  329. struct usb_wwan_port_private *portdata;
  330. struct usb_wwan_intf_private *intfdata;
  331. struct usb_serial *serial = port->serial;
  332. int i, err;
  333. struct urb *urb;
  334. portdata = usb_get_serial_port_data(port);
  335. intfdata = usb_get_serial_data(serial);
  336. if (port->interrupt_in_urb) {
  337. err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  338. if (err) {
  339. dev_err(&port->dev, "%s: submit int urb failed: %d\n",
  340. __func__, err);
  341. }
  342. }
  343. /* Start reading from the IN endpoint */
  344. for (i = 0; i < N_IN_URB; i++) {
  345. urb = portdata->in_urbs[i];
  346. if (!urb)
  347. continue;
  348. err = usb_submit_urb(urb, GFP_KERNEL);
  349. if (err) {
  350. dev_err(&port->dev,
  351. "%s: submit read urb %d failed: %d\n",
  352. __func__, i, err);
  353. }
  354. }
  355. spin_lock_irq(&intfdata->susp_lock);
  356. if (++intfdata->open_ports == 1)
  357. serial->interface->needs_remote_wakeup = 1;
  358. spin_unlock_irq(&intfdata->susp_lock);
  359. /* this balances a get in the generic USB serial code */
  360. usb_autopm_put_interface(serial->interface);
  361. return 0;
  362. }
  363. EXPORT_SYMBOL(usb_wwan_open);
  364. static void unbusy_queued_urb(struct urb *urb,
  365. struct usb_wwan_port_private *portdata)
  366. {
  367. int i;
  368. for (i = 0; i < N_OUT_URB; i++) {
  369. if (urb == portdata->out_urbs[i]) {
  370. clear_bit(i, &portdata->out_busy);
  371. break;
  372. }
  373. }
  374. }
  375. void usb_wwan_close(struct usb_serial_port *port)
  376. {
  377. int i;
  378. struct usb_serial *serial = port->serial;
  379. struct usb_wwan_port_private *portdata;
  380. struct usb_wwan_intf_private *intfdata = usb_get_serial_data(serial);
  381. struct urb *urb;
  382. portdata = usb_get_serial_port_data(port);
  383. /*
  384. * Need to take susp_lock to make sure port is not already being
  385. * resumed, but no need to hold it due to initialized
  386. */
  387. spin_lock_irq(&intfdata->susp_lock);
  388. if (--intfdata->open_ports == 0)
  389. serial->interface->needs_remote_wakeup = 0;
  390. spin_unlock_irq(&intfdata->susp_lock);
  391. for (;;) {
  392. urb = usb_get_from_anchor(&portdata->delayed);
  393. if (!urb)
  394. break;
  395. unbusy_queued_urb(urb, portdata);
  396. usb_autopm_put_interface_async(serial->interface);
  397. }
  398. for (i = 0; i < N_IN_URB; i++)
  399. usb_kill_urb(portdata->in_urbs[i]);
  400. for (i = 0; i < N_OUT_URB; i++)
  401. usb_kill_urb(portdata->out_urbs[i]);
  402. usb_kill_urb(port->interrupt_in_urb);
  403. usb_autopm_get_interface_no_resume(serial->interface);
  404. }
  405. EXPORT_SYMBOL(usb_wwan_close);
  406. static struct urb *usb_wwan_setup_urb(struct usb_serial_port *port,
  407. int endpoint,
  408. int dir, void *ctx, char *buf, int len,
  409. void (*callback) (struct urb *))
  410. {
  411. struct usb_serial *serial = port->serial;
  412. struct urb *urb;
  413. urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
  414. if (!urb)
  415. return NULL;
  416. usb_fill_bulk_urb(urb, serial->dev,
  417. usb_sndbulkpipe(serial->dev, endpoint) | dir,
  418. buf, len, callback, ctx);
  419. #if 1 //Added by Quectel for zero packet
  420. if (dir == USB_DIR_OUT) {
  421. struct usb_device_descriptor *desc = &serial->dev->descriptor;
  422. if (desc->idVendor == cpu_to_le16(0x2C7C))
  423. {
  424. urb->transfer_flags |= URB_ZERO_PACKET;
  425. }
  426. }
  427. #endif
  428. return urb;
  429. }
  430. int usb_wwan_port_probe(struct usb_serial_port *port)
  431. {
  432. struct usb_wwan_port_private *portdata;
  433. struct urb *urb;
  434. u8 *buffer;
  435. int i;
  436. if (!port->bulk_in_size || !port->bulk_out_size)
  437. return -ENODEV;
  438. portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
  439. if (!portdata)
  440. return -ENOMEM;
  441. init_usb_anchor(&portdata->delayed);
  442. for (i = 0; i < N_IN_URB; i++) {
  443. buffer = (u8 *)__get_free_page(GFP_KERNEL);
  444. if (!buffer)
  445. goto bail_out_error;
  446. portdata->in_buffer[i] = buffer;
  447. urb = usb_wwan_setup_urb(port, port->bulk_in_endpointAddress,
  448. USB_DIR_IN, port,
  449. buffer, IN_BUFLEN,
  450. usb_wwan_indat_callback);
  451. portdata->in_urbs[i] = urb;
  452. }
  453. for (i = 0; i < N_OUT_URB; i++) {
  454. buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL);
  455. if (!buffer)
  456. goto bail_out_error2;
  457. portdata->out_buffer[i] = buffer;
  458. urb = usb_wwan_setup_urb(port, port->bulk_out_endpointAddress,
  459. USB_DIR_OUT, port,
  460. buffer, OUT_BUFLEN,
  461. usb_wwan_outdat_callback);
  462. portdata->out_urbs[i] = urb;
  463. }
  464. usb_set_serial_port_data(port, portdata);
  465. return 0;
  466. bail_out_error2:
  467. for (i = 0; i < N_OUT_URB; i++) {
  468. usb_free_urb(portdata->out_urbs[i]);
  469. kfree(portdata->out_buffer[i]);
  470. }
  471. bail_out_error:
  472. for (i = 0; i < N_IN_URB; i++) {
  473. usb_free_urb(portdata->in_urbs[i]);
  474. free_page((unsigned long)portdata->in_buffer[i]);
  475. }
  476. kfree(portdata);
  477. return -ENOMEM;
  478. }
  479. EXPORT_SYMBOL_GPL(usb_wwan_port_probe);
  480. int usb_wwan_port_remove(struct usb_serial_port *port)
  481. {
  482. int i;
  483. struct usb_wwan_port_private *portdata;
  484. portdata = usb_get_serial_port_data(port);
  485. usb_set_serial_port_data(port, NULL);
  486. for (i = 0; i < N_IN_URB; i++) {
  487. usb_free_urb(portdata->in_urbs[i]);
  488. free_page((unsigned long)portdata->in_buffer[i]);
  489. }
  490. for (i = 0; i < N_OUT_URB; i++) {
  491. usb_free_urb(portdata->out_urbs[i]);
  492. kfree(portdata->out_buffer[i]);
  493. }
  494. kfree(portdata);
  495. return 0;
  496. }
  497. EXPORT_SYMBOL(usb_wwan_port_remove);
  498. #ifdef CONFIG_PM
  499. static void stop_urbs(struct usb_serial *serial)
  500. {
  501. int i, j;
  502. struct usb_serial_port *port;
  503. struct usb_wwan_port_private *portdata;
  504. for (i = 0; i < serial->num_ports; ++i) {
  505. port = serial->port[i];
  506. portdata = usb_get_serial_port_data(port);
  507. if (!portdata)
  508. continue;
  509. for (j = 0; j < N_IN_URB; j++)
  510. usb_kill_urb(portdata->in_urbs[j]);
  511. for (j = 0; j < N_OUT_URB; j++)
  512. usb_kill_urb(portdata->out_urbs[j]);
  513. usb_kill_urb(port->interrupt_in_urb);
  514. }
  515. }
  516. int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message)
  517. {
  518. struct usb_wwan_intf_private *intfdata = usb_get_serial_data(serial);
  519. spin_lock_irq(&intfdata->susp_lock);
  520. if (PMSG_IS_AUTO(message)) {
  521. if (intfdata->in_flight) {
  522. spin_unlock_irq(&intfdata->susp_lock);
  523. return -EBUSY;
  524. }
  525. }
  526. intfdata->suspended = 1;
  527. spin_unlock_irq(&intfdata->susp_lock);
  528. stop_urbs(serial);
  529. return 0;
  530. }
  531. EXPORT_SYMBOL(usb_wwan_suspend);
  532. /* Caller must hold susp_lock. */
  533. static int usb_wwan_submit_delayed_urbs(struct usb_serial_port *port)
  534. {
  535. struct usb_serial *serial = port->serial;
  536. struct usb_wwan_intf_private *data = usb_get_serial_data(serial);
  537. struct usb_wwan_port_private *portdata;
  538. struct urb *urb;
  539. int err_count = 0;
  540. int err;
  541. portdata = usb_get_serial_port_data(port);
  542. for (;;) {
  543. urb = usb_get_from_anchor(&portdata->delayed);
  544. if (!urb)
  545. break;
  546. err = usb_submit_urb(urb, GFP_ATOMIC);
  547. if (err) {
  548. dev_err(&port->dev, "%s: submit urb failed: %d\n",
  549. __func__, err);
  550. err_count++;
  551. unbusy_queued_urb(urb, portdata);
  552. usb_autopm_put_interface_async(serial->interface);
  553. continue;
  554. }
  555. data->in_flight++;
  556. }
  557. if (err_count)
  558. return -EIO;
  559. return 0;
  560. }
  561. int usb_wwan_resume(struct usb_serial *serial)
  562. {
  563. int i, j;
  564. struct usb_serial_port *port;
  565. struct usb_wwan_intf_private *intfdata = usb_get_serial_data(serial);
  566. struct usb_wwan_port_private *portdata;
  567. struct urb *urb;
  568. int err;
  569. int err_count = 0;
  570. spin_lock_irq(&intfdata->susp_lock);
  571. for (i = 0; i < serial->num_ports; i++) {
  572. port = serial->port[i];
  573. if (!tty_port_initialized(&port->port))
  574. continue;
  575. portdata = usb_get_serial_port_data(port);
  576. if (port->interrupt_in_urb) {
  577. err = usb_submit_urb(port->interrupt_in_urb,
  578. GFP_ATOMIC);
  579. if (err) {
  580. dev_err(&port->dev,
  581. "%s: submit int urb failed: %d\n",
  582. __func__, err);
  583. err_count++;
  584. }
  585. }
  586. err = usb_wwan_submit_delayed_urbs(port);
  587. if (err)
  588. err_count++;
  589. for (j = 0; j < N_IN_URB; j++) {
  590. urb = portdata->in_urbs[j];
  591. err = usb_submit_urb(urb, GFP_ATOMIC);
  592. if (err < 0) {
  593. dev_err(&port->dev,
  594. "%s: submit read urb %d failed: %d\n",
  595. __func__, i, err);
  596. err_count++;
  597. }
  598. }
  599. }
  600. intfdata->suspended = 0;
  601. spin_unlock_irq(&intfdata->susp_lock);
  602. if (err_count)
  603. return -EIO;
  604. return 0;
  605. }
  606. EXPORT_SYMBOL(usb_wwan_resume);
  607. #endif
  608. MODULE_AUTHOR(DRIVER_AUTHOR);
  609. MODULE_DESCRIPTION(DRIVER_DESC);
  610. MODULE_LICENSE("GPL");