generic.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * USB Serial Converter Generic functions
  4. *
  5. * Copyright (C) 2010 - 2013 Johan Hovold (jhovold@gmail.com)
  6. * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/sched/signal.h>
  10. #include <linux/errno.h>
  11. #include <linux/slab.h>
  12. #include <linux/sysrq.h>
  13. #include <linux/tty.h>
  14. #include <linux/tty_flip.h>
  15. #include <linux/module.h>
  16. #include <linux/moduleparam.h>
  17. #include <linux/usb.h>
  18. #include <linux/usb/serial.h>
  19. #include <linux/uaccess.h>
  20. #include <linux/kfifo.h>
  21. #include <linux/serial.h>
  22. #ifdef CONFIG_USB_SERIAL_GENERIC
  23. static __u16 vendor = 0x05f9;
  24. static __u16 product = 0xffff;
  25. module_param(vendor, ushort, 0);
  26. MODULE_PARM_DESC(vendor, "User specified USB idVendor");
  27. module_param(product, ushort, 0);
  28. MODULE_PARM_DESC(product, "User specified USB idProduct");
  29. static struct usb_device_id generic_device_ids[2]; /* Initially all zeroes. */
  30. static int usb_serial_generic_probe(struct usb_serial *serial,
  31. const struct usb_device_id *id)
  32. {
  33. struct device *dev = &serial->interface->dev;
  34. dev_info(dev, "The \"generic\" usb-serial driver is only for testing and one-off prototypes.\n");
  35. dev_info(dev, "Tell linux-usb@vger.kernel.org to add your device to a proper driver.\n");
  36. return 0;
  37. }
  38. static int usb_serial_generic_calc_num_ports(struct usb_serial *serial,
  39. struct usb_serial_endpoints *epds)
  40. {
  41. struct device *dev = &serial->interface->dev;
  42. int num_ports;
  43. num_ports = max(epds->num_bulk_in, epds->num_bulk_out);
  44. if (num_ports == 0) {
  45. dev_err(dev, "device has no bulk endpoints\n");
  46. return -ENODEV;
  47. }
  48. return num_ports;
  49. }
  50. static struct usb_serial_driver usb_serial_generic_device = {
  51. .driver = {
  52. .name = "generic",
  53. },
  54. .id_table = generic_device_ids,
  55. .probe = usb_serial_generic_probe,
  56. .calc_num_ports = usb_serial_generic_calc_num_ports,
  57. .throttle = usb_serial_generic_throttle,
  58. .unthrottle = usb_serial_generic_unthrottle,
  59. .resume = usb_serial_generic_resume,
  60. };
  61. static struct usb_serial_driver * const serial_drivers[] = {
  62. &usb_serial_generic_device, NULL
  63. };
  64. #endif
  65. int usb_serial_generic_register(void)
  66. {
  67. int retval = 0;
  68. #ifdef CONFIG_USB_SERIAL_GENERIC
  69. generic_device_ids[0].idVendor = vendor;
  70. generic_device_ids[0].idProduct = product;
  71. generic_device_ids[0].match_flags =
  72. USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT;
  73. retval = usb_serial_register_drivers(serial_drivers,
  74. "usbserial_generic", generic_device_ids);
  75. #endif
  76. return retval;
  77. }
  78. void usb_serial_generic_deregister(void)
  79. {
  80. #ifdef CONFIG_USB_SERIAL_GENERIC
  81. usb_serial_deregister_drivers(serial_drivers);
  82. #endif
  83. }
  84. int usb_serial_generic_open(struct tty_struct *tty, struct usb_serial_port *port)
  85. {
  86. int result = 0;
  87. clear_bit(USB_SERIAL_THROTTLED, &port->flags);
  88. if (port->bulk_in_size)
  89. result = usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
  90. return result;
  91. }
  92. EXPORT_SYMBOL_GPL(usb_serial_generic_open);
  93. void usb_serial_generic_close(struct usb_serial_port *port)
  94. {
  95. unsigned long flags;
  96. int i;
  97. if (port->bulk_out_size) {
  98. for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i)
  99. usb_kill_urb(port->write_urbs[i]);
  100. spin_lock_irqsave(&port->lock, flags);
  101. kfifo_reset_out(&port->write_fifo);
  102. spin_unlock_irqrestore(&port->lock, flags);
  103. }
  104. if (port->bulk_in_size) {
  105. for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
  106. usb_kill_urb(port->read_urbs[i]);
  107. }
  108. }
  109. EXPORT_SYMBOL_GPL(usb_serial_generic_close);
  110. int usb_serial_generic_prepare_write_buffer(struct usb_serial_port *port,
  111. void *dest, size_t size)
  112. {
  113. return kfifo_out_locked(&port->write_fifo, dest, size, &port->lock);
  114. }
  115. /**
  116. * usb_serial_generic_write_start - start writing buffered data
  117. * @port: usb-serial port
  118. * @mem_flags: flags to use for memory allocations
  119. *
  120. * Serialised using USB_SERIAL_WRITE_BUSY flag.
  121. *
  122. * Return: Zero on success or if busy, otherwise a negative errno value.
  123. */
  124. int usb_serial_generic_write_start(struct usb_serial_port *port,
  125. gfp_t mem_flags)
  126. {
  127. struct urb *urb;
  128. int count, result;
  129. unsigned long flags;
  130. int i;
  131. if (test_and_set_bit_lock(USB_SERIAL_WRITE_BUSY, &port->flags))
  132. return 0;
  133. retry:
  134. spin_lock_irqsave(&port->lock, flags);
  135. if (!port->write_urbs_free || !kfifo_len(&port->write_fifo)) {
  136. clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
  137. spin_unlock_irqrestore(&port->lock, flags);
  138. return 0;
  139. }
  140. i = (int)find_first_bit(&port->write_urbs_free,
  141. ARRAY_SIZE(port->write_urbs));
  142. spin_unlock_irqrestore(&port->lock, flags);
  143. urb = port->write_urbs[i];
  144. count = port->serial->type->prepare_write_buffer(port,
  145. urb->transfer_buffer,
  146. port->bulk_out_size);
  147. urb->transfer_buffer_length = count;
  148. usb_serial_debug_data(&port->dev, __func__, count, urb->transfer_buffer);
  149. spin_lock_irqsave(&port->lock, flags);
  150. port->tx_bytes += count;
  151. spin_unlock_irqrestore(&port->lock, flags);
  152. clear_bit(i, &port->write_urbs_free);
  153. result = usb_submit_urb(urb, mem_flags);
  154. if (result) {
  155. dev_err_console(port, "%s - error submitting urb: %d\n",
  156. __func__, result);
  157. set_bit(i, &port->write_urbs_free);
  158. spin_lock_irqsave(&port->lock, flags);
  159. port->tx_bytes -= count;
  160. spin_unlock_irqrestore(&port->lock, flags);
  161. clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags);
  162. return result;
  163. }
  164. goto retry; /* try sending off another urb */
  165. }
  166. EXPORT_SYMBOL_GPL(usb_serial_generic_write_start);
  167. /**
  168. * usb_serial_generic_write - generic write function
  169. * @tty: tty for the port
  170. * @port: usb-serial port
  171. * @buf: data to write
  172. * @count: number of bytes to write
  173. *
  174. * Return: The number of characters buffered, which may be anything from
  175. * zero to @count, or a negative errno value.
  176. */
  177. int usb_serial_generic_write(struct tty_struct *tty,
  178. struct usb_serial_port *port, const unsigned char *buf, int count)
  179. {
  180. int result;
  181. if (!port->bulk_out_size)
  182. return -ENODEV;
  183. if (!count)
  184. return 0;
  185. count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock);
  186. result = usb_serial_generic_write_start(port, GFP_ATOMIC);
  187. if (result)
  188. return result;
  189. return count;
  190. }
  191. EXPORT_SYMBOL_GPL(usb_serial_generic_write);
  192. unsigned int usb_serial_generic_write_room(struct tty_struct *tty)
  193. {
  194. struct usb_serial_port *port = tty->driver_data;
  195. unsigned long flags;
  196. unsigned int room;
  197. if (!port->bulk_out_size)
  198. return 0;
  199. spin_lock_irqsave(&port->lock, flags);
  200. room = kfifo_avail(&port->write_fifo);
  201. spin_unlock_irqrestore(&port->lock, flags);
  202. dev_dbg(&port->dev, "%s - returns %u\n", __func__, room);
  203. return room;
  204. }
  205. unsigned int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
  206. {
  207. struct usb_serial_port *port = tty->driver_data;
  208. unsigned long flags;
  209. unsigned int chars;
  210. if (!port->bulk_out_size)
  211. return 0;
  212. spin_lock_irqsave(&port->lock, flags);
  213. chars = kfifo_len(&port->write_fifo) + port->tx_bytes;
  214. spin_unlock_irqrestore(&port->lock, flags);
  215. dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars);
  216. return chars;
  217. }
  218. EXPORT_SYMBOL_GPL(usb_serial_generic_chars_in_buffer);
  219. void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout)
  220. {
  221. struct usb_serial_port *port = tty->driver_data;
  222. unsigned int bps;
  223. unsigned long period;
  224. unsigned long expire;
  225. bps = tty_get_baud_rate(tty);
  226. if (!bps)
  227. bps = 9600; /* B0 */
  228. /*
  229. * Use a poll-period of roughly the time it takes to send one
  230. * character or at least one jiffy.
  231. */
  232. period = max_t(unsigned long, (10 * HZ / bps), 1);
  233. if (timeout)
  234. period = min_t(unsigned long, period, timeout);
  235. dev_dbg(&port->dev, "%s - timeout = %u ms, period = %u ms\n",
  236. __func__, jiffies_to_msecs(timeout),
  237. jiffies_to_msecs(period));
  238. expire = jiffies + timeout;
  239. while (!port->serial->type->tx_empty(port)) {
  240. schedule_timeout_interruptible(period);
  241. if (signal_pending(current))
  242. break;
  243. if (timeout && time_after(jiffies, expire))
  244. break;
  245. }
  246. }
  247. EXPORT_SYMBOL_GPL(usb_serial_generic_wait_until_sent);
  248. static int usb_serial_generic_submit_read_urb(struct usb_serial_port *port,
  249. int index, gfp_t mem_flags)
  250. {
  251. int res;
  252. if (!test_and_clear_bit(index, &port->read_urbs_free))
  253. return 0;
  254. dev_dbg(&port->dev, "%s - urb %d\n", __func__, index);
  255. res = usb_submit_urb(port->read_urbs[index], mem_flags);
  256. if (res) {
  257. if (res != -EPERM && res != -ENODEV) {
  258. dev_err(&port->dev,
  259. "%s - usb_submit_urb failed: %d\n",
  260. __func__, res);
  261. }
  262. set_bit(index, &port->read_urbs_free);
  263. return res;
  264. }
  265. return 0;
  266. }
  267. int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port,
  268. gfp_t mem_flags)
  269. {
  270. int res;
  271. int i;
  272. for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
  273. res = usb_serial_generic_submit_read_urb(port, i, mem_flags);
  274. if (res)
  275. goto err;
  276. }
  277. return 0;
  278. err:
  279. for (; i >= 0; --i)
  280. usb_kill_urb(port->read_urbs[i]);
  281. return res;
  282. }
  283. EXPORT_SYMBOL_GPL(usb_serial_generic_submit_read_urbs);
  284. void usb_serial_generic_process_read_urb(struct urb *urb)
  285. {
  286. struct usb_serial_port *port = urb->context;
  287. char *ch = urb->transfer_buffer;
  288. int i;
  289. if (!urb->actual_length)
  290. return;
  291. /*
  292. * The per character mucking around with sysrq path it too slow for
  293. * stuff like 3G modems, so shortcircuit it in the 99.9999999% of
  294. * cases where the USB serial is not a console anyway.
  295. */
  296. if (port->sysrq) {
  297. for (i = 0; i < urb->actual_length; i++, ch++) {
  298. if (!usb_serial_handle_sysrq_char(port, *ch))
  299. tty_insert_flip_char(&port->port, *ch, TTY_NORMAL);
  300. }
  301. } else {
  302. tty_insert_flip_string(&port->port, ch, urb->actual_length);
  303. }
  304. tty_flip_buffer_push(&port->port);
  305. }
  306. EXPORT_SYMBOL_GPL(usb_serial_generic_process_read_urb);
  307. void usb_serial_generic_read_bulk_callback(struct urb *urb)
  308. {
  309. struct usb_serial_port *port = urb->context;
  310. unsigned char *data = urb->transfer_buffer;
  311. bool stopped = false;
  312. int status = urb->status;
  313. int i;
  314. for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) {
  315. if (urb == port->read_urbs[i])
  316. break;
  317. }
  318. dev_dbg(&port->dev, "%s - urb %d, len %d\n", __func__, i,
  319. urb->actual_length);
  320. switch (status) {
  321. case 0:
  322. usb_serial_debug_data(&port->dev, __func__, urb->actual_length,
  323. data);
  324. port->serial->type->process_read_urb(urb);
  325. break;
  326. case -ENOENT:
  327. case -ECONNRESET:
  328. case -ESHUTDOWN:
  329. dev_dbg(&port->dev, "%s - urb stopped: %d\n",
  330. __func__, status);
  331. stopped = true;
  332. break;
  333. case -EPIPE:
  334. dev_err(&port->dev, "%s - urb stopped: %d\n",
  335. __func__, status);
  336. stopped = true;
  337. break;
  338. default:
  339. dev_dbg(&port->dev, "%s - nonzero urb status: %d\n",
  340. __func__, status);
  341. break;
  342. }
  343. /*
  344. * Make sure URB processing is done before marking as free to avoid
  345. * racing with unthrottle() on another CPU. Matches the barriers
  346. * implied by the test_and_clear_bit() in
  347. * usb_serial_generic_submit_read_urb().
  348. */
  349. smp_mb__before_atomic();
  350. set_bit(i, &port->read_urbs_free);
  351. /*
  352. * Make sure URB is marked as free before checking the throttled flag
  353. * to avoid racing with unthrottle() on another CPU. Matches the
  354. * smp_mb__after_atomic() in unthrottle().
  355. */
  356. smp_mb__after_atomic();
  357. if (stopped)
  358. return;
  359. if (test_bit(USB_SERIAL_THROTTLED, &port->flags))
  360. return;
  361. usb_serial_generic_submit_read_urb(port, i, GFP_ATOMIC);
  362. }
  363. EXPORT_SYMBOL_GPL(usb_serial_generic_read_bulk_callback);
  364. void usb_serial_generic_write_bulk_callback(struct urb *urb)
  365. {
  366. unsigned long flags;
  367. struct usb_serial_port *port = urb->context;
  368. int status = urb->status;
  369. int i;
  370. for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) {
  371. if (port->write_urbs[i] == urb)
  372. break;
  373. }
  374. spin_lock_irqsave(&port->lock, flags);
  375. port->tx_bytes -= urb->transfer_buffer_length;
  376. set_bit(i, &port->write_urbs_free);
  377. spin_unlock_irqrestore(&port->lock, flags);
  378. switch (status) {
  379. case 0:
  380. break;
  381. case -ENOENT:
  382. case -ECONNRESET:
  383. case -ESHUTDOWN:
  384. dev_dbg(&port->dev, "%s - urb stopped: %d\n",
  385. __func__, status);
  386. return;
  387. case -EPIPE:
  388. dev_err_console(port, "%s - urb stopped: %d\n",
  389. __func__, status);
  390. return;
  391. default:
  392. dev_err_console(port, "%s - nonzero urb status: %d\n",
  393. __func__, status);
  394. break;
  395. }
  396. usb_serial_generic_write_start(port, GFP_ATOMIC);
  397. usb_serial_port_softint(port);
  398. }
  399. EXPORT_SYMBOL_GPL(usb_serial_generic_write_bulk_callback);
  400. void usb_serial_generic_throttle(struct tty_struct *tty)
  401. {
  402. struct usb_serial_port *port = tty->driver_data;
  403. set_bit(USB_SERIAL_THROTTLED, &port->flags);
  404. }
  405. EXPORT_SYMBOL_GPL(usb_serial_generic_throttle);
  406. void usb_serial_generic_unthrottle(struct tty_struct *tty)
  407. {
  408. struct usb_serial_port *port = tty->driver_data;
  409. clear_bit(USB_SERIAL_THROTTLED, &port->flags);
  410. /*
  411. * Matches the smp_mb__after_atomic() in
  412. * usb_serial_generic_read_bulk_callback().
  413. */
  414. smp_mb__after_atomic();
  415. usb_serial_generic_submit_read_urbs(port, GFP_KERNEL);
  416. }
  417. EXPORT_SYMBOL_GPL(usb_serial_generic_unthrottle);
  418. static bool usb_serial_generic_msr_changed(struct tty_struct *tty,
  419. unsigned long arg, struct async_icount *cprev)
  420. {
  421. struct usb_serial_port *port = tty->driver_data;
  422. struct async_icount cnow;
  423. unsigned long flags;
  424. bool ret;
  425. /*
  426. * Use tty-port initialised flag to detect all hangups including the
  427. * one generated at USB-device disconnect.
  428. */
  429. if (!tty_port_initialized(&port->port))
  430. return true;
  431. spin_lock_irqsave(&port->lock, flags);
  432. cnow = port->icount; /* atomic copy*/
  433. spin_unlock_irqrestore(&port->lock, flags);
  434. ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
  435. ((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
  436. ((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
  437. ((arg & TIOCM_CTS) && (cnow.cts != cprev->cts));
  438. *cprev = cnow;
  439. return ret;
  440. }
  441. int usb_serial_generic_tiocmiwait(struct tty_struct *tty, unsigned long arg)
  442. {
  443. struct usb_serial_port *port = tty->driver_data;
  444. struct async_icount cnow;
  445. unsigned long flags;
  446. int ret;
  447. spin_lock_irqsave(&port->lock, flags);
  448. cnow = port->icount; /* atomic copy */
  449. spin_unlock_irqrestore(&port->lock, flags);
  450. ret = wait_event_interruptible(port->port.delta_msr_wait,
  451. usb_serial_generic_msr_changed(tty, arg, &cnow));
  452. if (!ret && !tty_port_initialized(&port->port))
  453. ret = -EIO;
  454. return ret;
  455. }
  456. EXPORT_SYMBOL_GPL(usb_serial_generic_tiocmiwait);
  457. int usb_serial_generic_get_icount(struct tty_struct *tty,
  458. struct serial_icounter_struct *icount)
  459. {
  460. struct usb_serial_port *port = tty->driver_data;
  461. struct async_icount cnow;
  462. unsigned long flags;
  463. spin_lock_irqsave(&port->lock, flags);
  464. cnow = port->icount; /* atomic copy */
  465. spin_unlock_irqrestore(&port->lock, flags);
  466. icount->cts = cnow.cts;
  467. icount->dsr = cnow.dsr;
  468. icount->rng = cnow.rng;
  469. icount->dcd = cnow.dcd;
  470. icount->tx = cnow.tx;
  471. icount->rx = cnow.rx;
  472. icount->frame = cnow.frame;
  473. icount->parity = cnow.parity;
  474. icount->overrun = cnow.overrun;
  475. icount->brk = cnow.brk;
  476. icount->buf_overrun = cnow.buf_overrun;
  477. return 0;
  478. }
  479. EXPORT_SYMBOL_GPL(usb_serial_generic_get_icount);
  480. #if defined(CONFIG_USB_SERIAL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  481. int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
  482. {
  483. if (port->sysrq) {
  484. if (ch && time_before(jiffies, port->sysrq)) {
  485. handle_sysrq(ch);
  486. port->sysrq = 0;
  487. return 1;
  488. }
  489. port->sysrq = 0;
  490. }
  491. return 0;
  492. }
  493. EXPORT_SYMBOL_GPL(usb_serial_handle_sysrq_char);
  494. int usb_serial_handle_break(struct usb_serial_port *port)
  495. {
  496. if (!port->port.console)
  497. return 0;
  498. if (!port->sysrq) {
  499. port->sysrq = jiffies + HZ*5;
  500. return 1;
  501. }
  502. port->sysrq = 0;
  503. return 0;
  504. }
  505. EXPORT_SYMBOL_GPL(usb_serial_handle_break);
  506. #endif
  507. /**
  508. * usb_serial_handle_dcd_change - handle a change of carrier detect state
  509. * @port: usb-serial port
  510. * @tty: tty for the port
  511. * @status: new carrier detect status, nonzero if active
  512. */
  513. void usb_serial_handle_dcd_change(struct usb_serial_port *port,
  514. struct tty_struct *tty, unsigned int status)
  515. {
  516. dev_dbg(&port->dev, "%s - status %d\n", __func__, status);
  517. if (tty) {
  518. struct tty_ldisc *ld = tty_ldisc_ref(tty);
  519. if (ld) {
  520. if (ld->ops->dcd_change)
  521. ld->ops->dcd_change(tty, status);
  522. tty_ldisc_deref(ld);
  523. }
  524. }
  525. if (status)
  526. wake_up_interruptible(&port->port.open_wait);
  527. else if (tty && !C_CLOCAL(tty))
  528. tty_hangup(tty);
  529. }
  530. EXPORT_SYMBOL_GPL(usb_serial_handle_dcd_change);
  531. int usb_serial_generic_resume(struct usb_serial *serial)
  532. {
  533. struct usb_serial_port *port;
  534. int i, c = 0, r;
  535. for (i = 0; i < serial->num_ports; i++) {
  536. port = serial->port[i];
  537. if (!tty_port_initialized(&port->port))
  538. continue;
  539. if (port->bulk_in_size) {
  540. r = usb_serial_generic_submit_read_urbs(port,
  541. GFP_NOIO);
  542. if (r < 0)
  543. c++;
  544. }
  545. if (port->bulk_out_size) {
  546. r = usb_serial_generic_write_start(port, GFP_NOIO);
  547. if (r < 0)
  548. c++;
  549. }
  550. }
  551. return c ? -EIO : 0;
  552. }
  553. EXPORT_SYMBOL_GPL(usb_serial_generic_resume);