option.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /*
  2. Option Card (PCMCIA to) USB to Serial Driver
  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:
  9. 2005-05-19 v0.1 Initial version, based on incomplete docs
  10. and analysis of misbehavior with the standard driver
  11. 2005-05-20 v0.2 Extended the input buffer to avoid losing
  12. random 64-byte chunks of data
  13. 2005-05-21 v0.3 implemented chars_in_buffer()
  14. turned on low_latency
  15. simplified the code somewhat
  16. 2005-05-24 v0.4 option_write() sometimes deadlocked under heavy load
  17. removed some dead code
  18. added sponsor notice
  19. coding style clean-up
  20. 2005-06-20 v0.4.1 add missing braces :-/
  21. killed end-of-line whitespace
  22. 2005-07-15 v0.4.2 rename WLAN product to FUSION, add FUSION2
  23. 2005-09-10 v0.4.3 added HUAWEI E600 card and Audiovox AirCard
  24. 2005-09-20 v0.4.4 increased recv buffer size: the card sometimes
  25. wants to send >2000 bytes.
  26. 2006-04-10 v0.4.2 fixed two array overrun errors :-/
  27. Work sponsored by: Sigos GmbH, Germany <info@sigos.de>
  28. */
  29. #define DRIVER_VERSION "v0.4"
  30. #define DRIVER_AUTHOR "Matthias Urlichs <smurf@smurf.noris.de>"
  31. #define DRIVER_DESC "Option Card (PC-Card to) USB to Serial Driver"
  32. #include <linux/config.h>
  33. #include <linux/kernel.h>
  34. #include <linux/jiffies.h>
  35. #include <linux/errno.h>
  36. #include <linux/tty.h>
  37. #include <linux/tty_flip.h>
  38. #include <linux/module.h>
  39. #include <linux/usb.h>
  40. #include "usb-serial.h"
  41. /* Function prototypes */
  42. static int option_open(struct usb_serial_port *port, struct file *filp);
  43. static void option_close(struct usb_serial_port *port, struct file *filp);
  44. static int option_startup(struct usb_serial *serial);
  45. static void option_shutdown(struct usb_serial *serial);
  46. static void option_rx_throttle(struct usb_serial_port *port);
  47. static void option_rx_unthrottle(struct usb_serial_port *port);
  48. static int option_write_room(struct usb_serial_port *port);
  49. static void option_instat_callback(struct urb *urb, struct pt_regs *regs);
  50. static int option_write(struct usb_serial_port *port,
  51. const unsigned char *buf, int count);
  52. static int option_chars_in_buffer(struct usb_serial_port *port);
  53. static int option_ioctl(struct usb_serial_port *port, struct file *file,
  54. unsigned int cmd, unsigned long arg);
  55. static void option_set_termios(struct usb_serial_port *port,
  56. struct termios *old);
  57. static void option_break_ctl(struct usb_serial_port *port, int break_state);
  58. static int option_tiocmget(struct usb_serial_port *port, struct file *file);
  59. static int option_tiocmset(struct usb_serial_port *port, struct file *file,
  60. unsigned int set, unsigned int clear);
  61. static int option_send_setup(struct usb_serial_port *port);
  62. /* Vendor and product IDs */
  63. #define OPTION_VENDOR_ID 0x0AF0
  64. #define HUAWEI_VENDOR_ID 0x12D1
  65. #define AUDIOVOX_VENDOR_ID 0x0F3D
  66. #define OPTION_PRODUCT_OLD 0x5000
  67. #define OPTION_PRODUCT_FUSION 0x6000
  68. #define OPTION_PRODUCT_FUSION2 0x6300
  69. #define HUAWEI_PRODUCT_E600 0x1001
  70. #define AUDIOVOX_PRODUCT_AIRCARD 0x0112
  71. static struct usb_device_id option_ids[] = {
  72. { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
  73. { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
  74. { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION2) },
  75. { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E600) },
  76. { USB_DEVICE(AUDIOVOX_VENDOR_ID, AUDIOVOX_PRODUCT_AIRCARD) },
  77. { } /* Terminating entry */
  78. };
  79. MODULE_DEVICE_TABLE(usb, option_ids);
  80. static struct usb_driver option_driver = {
  81. .name = "option",
  82. .probe = usb_serial_probe,
  83. .disconnect = usb_serial_disconnect,
  84. .id_table = option_ids,
  85. .no_dynamic_id = 1,
  86. };
  87. /* The card has three separate interfaces, which the serial driver
  88. * recognizes separately, thus num_port=1.
  89. */
  90. static struct usb_serial_driver option_3port_device = {
  91. .driver = {
  92. .owner = THIS_MODULE,
  93. .name = "option",
  94. },
  95. .description = "Option 3G data card",
  96. .id_table = option_ids,
  97. .num_interrupt_in = NUM_DONT_CARE,
  98. .num_bulk_in = NUM_DONT_CARE,
  99. .num_bulk_out = NUM_DONT_CARE,
  100. .num_ports = 1, /* 3, but the card reports its ports separately */
  101. .open = option_open,
  102. .close = option_close,
  103. .write = option_write,
  104. .write_room = option_write_room,
  105. .chars_in_buffer = option_chars_in_buffer,
  106. .throttle = option_rx_throttle,
  107. .unthrottle = option_rx_unthrottle,
  108. .ioctl = option_ioctl,
  109. .set_termios = option_set_termios,
  110. .break_ctl = option_break_ctl,
  111. .tiocmget = option_tiocmget,
  112. .tiocmset = option_tiocmset,
  113. .attach = option_startup,
  114. .shutdown = option_shutdown,
  115. .read_int_callback = option_instat_callback,
  116. };
  117. #ifdef CONFIG_USB_DEBUG
  118. static int debug;
  119. #else
  120. #define debug 0
  121. #endif
  122. /* per port private data */
  123. #define N_IN_URB 4
  124. #define N_OUT_URB 1
  125. #define IN_BUFLEN 4096
  126. #define OUT_BUFLEN 128
  127. struct option_port_private {
  128. /* Input endpoints and buffer for this port */
  129. struct urb *in_urbs[N_IN_URB];
  130. char in_buffer[N_IN_URB][IN_BUFLEN];
  131. /* Output endpoints and buffer for this port */
  132. struct urb *out_urbs[N_OUT_URB];
  133. char out_buffer[N_OUT_URB][OUT_BUFLEN];
  134. /* Settings for the port */
  135. int rts_state; /* Handshaking pins (outputs) */
  136. int dtr_state;
  137. int cts_state; /* Handshaking pins (inputs) */
  138. int dsr_state;
  139. int dcd_state;
  140. int ri_state;
  141. unsigned long tx_start_time[N_OUT_URB];
  142. };
  143. /* Functions used by new usb-serial code. */
  144. static int __init option_init(void)
  145. {
  146. int retval;
  147. retval = usb_serial_register(&option_3port_device);
  148. if (retval)
  149. goto failed_3port_device_register;
  150. retval = usb_register(&option_driver);
  151. if (retval)
  152. goto failed_driver_register;
  153. info(DRIVER_DESC ": " DRIVER_VERSION);
  154. return 0;
  155. failed_driver_register:
  156. usb_serial_deregister (&option_3port_device);
  157. failed_3port_device_register:
  158. return retval;
  159. }
  160. static void __exit option_exit(void)
  161. {
  162. usb_deregister (&option_driver);
  163. usb_serial_deregister (&option_3port_device);
  164. }
  165. module_init(option_init);
  166. module_exit(option_exit);
  167. static void option_rx_throttle(struct usb_serial_port *port)
  168. {
  169. dbg("%s", __FUNCTION__);
  170. }
  171. static void option_rx_unthrottle(struct usb_serial_port *port)
  172. {
  173. dbg("%s", __FUNCTION__);
  174. }
  175. static void option_break_ctl(struct usb_serial_port *port, int break_state)
  176. {
  177. /* Unfortunately, I don't know how to send a break */
  178. dbg("%s", __FUNCTION__);
  179. }
  180. static void option_set_termios(struct usb_serial_port *port,
  181. struct termios *old_termios)
  182. {
  183. dbg("%s", __FUNCTION__);
  184. option_send_setup(port);
  185. }
  186. static int option_tiocmget(struct usb_serial_port *port, struct file *file)
  187. {
  188. unsigned int value;
  189. struct option_port_private *portdata;
  190. portdata = usb_get_serial_port_data(port);
  191. value = ((portdata->rts_state) ? TIOCM_RTS : 0) |
  192. ((portdata->dtr_state) ? TIOCM_DTR : 0) |
  193. ((portdata->cts_state) ? TIOCM_CTS : 0) |
  194. ((portdata->dsr_state) ? TIOCM_DSR : 0) |
  195. ((portdata->dcd_state) ? TIOCM_CAR : 0) |
  196. ((portdata->ri_state) ? TIOCM_RNG : 0);
  197. return value;
  198. }
  199. static int option_tiocmset(struct usb_serial_port *port, struct file *file,
  200. unsigned int set, unsigned int clear)
  201. {
  202. struct option_port_private *portdata;
  203. portdata = usb_get_serial_port_data(port);
  204. if (set & TIOCM_RTS)
  205. portdata->rts_state = 1;
  206. if (set & TIOCM_DTR)
  207. portdata->dtr_state = 1;
  208. if (clear & TIOCM_RTS)
  209. portdata->rts_state = 0;
  210. if (clear & TIOCM_DTR)
  211. portdata->dtr_state = 0;
  212. return option_send_setup(port);
  213. }
  214. static int option_ioctl(struct usb_serial_port *port, struct file *file,
  215. unsigned int cmd, unsigned long arg)
  216. {
  217. return -ENOIOCTLCMD;
  218. }
  219. /* Write */
  220. static int option_write(struct usb_serial_port *port,
  221. const unsigned char *buf, int count)
  222. {
  223. struct option_port_private *portdata;
  224. int i;
  225. int left, todo;
  226. struct urb *this_urb = NULL; /* spurious */
  227. int err;
  228. portdata = usb_get_serial_port_data(port);
  229. dbg("%s: write (%d chars)", __FUNCTION__, count);
  230. i = 0;
  231. left = count;
  232. for (i=0; left > 0 && i < N_OUT_URB; i++) {
  233. todo = left;
  234. if (todo > OUT_BUFLEN)
  235. todo = OUT_BUFLEN;
  236. this_urb = portdata->out_urbs[i];
  237. if (this_urb->status == -EINPROGRESS) {
  238. if (time_before(jiffies,
  239. portdata->tx_start_time[i] + 10 * HZ))
  240. continue;
  241. usb_unlink_urb(this_urb);
  242. continue;
  243. }
  244. if (this_urb->status != 0)
  245. dbg("usb_write %p failed (err=%d)",
  246. this_urb, this_urb->status);
  247. dbg("%s: endpoint %d buf %d", __FUNCTION__,
  248. usb_pipeendpoint(this_urb->pipe), i);
  249. /* send the data */
  250. memcpy (this_urb->transfer_buffer, buf, todo);
  251. this_urb->transfer_buffer_length = todo;
  252. this_urb->dev = port->serial->dev;
  253. err = usb_submit_urb(this_urb, GFP_ATOMIC);
  254. if (err) {
  255. dbg("usb_submit_urb %p (write bulk) failed "
  256. "(%d, has %d)", this_urb,
  257. err, this_urb->status);
  258. continue;
  259. }
  260. portdata->tx_start_time[i] = jiffies;
  261. buf += todo;
  262. left -= todo;
  263. }
  264. count -= left;
  265. dbg("%s: wrote (did %d)", __FUNCTION__, count);
  266. return count;
  267. }
  268. static void option_indat_callback(struct urb *urb, struct pt_regs *regs)
  269. {
  270. int err;
  271. int endpoint;
  272. struct usb_serial_port *port;
  273. struct tty_struct *tty;
  274. unsigned char *data = urb->transfer_buffer;
  275. dbg("%s: %p", __FUNCTION__, urb);
  276. endpoint = usb_pipeendpoint(urb->pipe);
  277. port = (struct usb_serial_port *) urb->context;
  278. if (urb->status) {
  279. dbg("%s: nonzero status: %d on endpoint %02x.",
  280. __FUNCTION__, urb->status, endpoint);
  281. } else {
  282. tty = port->tty;
  283. if (urb->actual_length) {
  284. tty_buffer_request_room(tty, urb->actual_length);
  285. tty_insert_flip_string(tty, data, urb->actual_length);
  286. tty_flip_buffer_push(tty);
  287. } else {
  288. dbg("%s: empty read urb received", __FUNCTION__);
  289. }
  290. /* Resubmit urb so we continue receiving */
  291. if (port->open_count && urb->status != -ESHUTDOWN) {
  292. err = usb_submit_urb(urb, GFP_ATOMIC);
  293. if (err)
  294. printk(KERN_ERR "%s: resubmit read urb failed. "
  295. "(%d)", __FUNCTION__, err);
  296. }
  297. }
  298. return;
  299. }
  300. static void option_outdat_callback(struct urb *urb, struct pt_regs *regs)
  301. {
  302. struct usb_serial_port *port;
  303. dbg("%s", __FUNCTION__);
  304. port = (struct usb_serial_port *) urb->context;
  305. if (port->open_count)
  306. schedule_work(&port->work);
  307. }
  308. static void option_instat_callback(struct urb *urb, struct pt_regs *regs)
  309. {
  310. int err;
  311. struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
  312. struct option_port_private *portdata = usb_get_serial_port_data(port);
  313. struct usb_serial *serial = port->serial;
  314. dbg("%s", __FUNCTION__);
  315. dbg("%s: urb %p port %p has data %p", __FUNCTION__,urb,port,portdata);
  316. if (urb->status == 0) {
  317. struct usb_ctrlrequest *req_pkt =
  318. (struct usb_ctrlrequest *)urb->transfer_buffer;
  319. if (!req_pkt) {
  320. dbg("%s: NULL req_pkt\n", __FUNCTION__);
  321. return;
  322. }
  323. if ((req_pkt->bRequestType == 0xA1) &&
  324. (req_pkt->bRequest == 0x20)) {
  325. int old_dcd_state;
  326. unsigned char signals = *((unsigned char *)
  327. urb->transfer_buffer +
  328. sizeof(struct usb_ctrlrequest));
  329. dbg("%s: signal x%x", __FUNCTION__, signals);
  330. old_dcd_state = portdata->dcd_state;
  331. portdata->cts_state = 1;
  332. portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
  333. portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
  334. portdata->ri_state = ((signals & 0x08) ? 1 : 0);
  335. if (port->tty && !C_CLOCAL(port->tty) &&
  336. old_dcd_state && !portdata->dcd_state)
  337. tty_hangup(port->tty);
  338. } else {
  339. dbg("%s: type %x req %x", __FUNCTION__,
  340. req_pkt->bRequestType,req_pkt->bRequest);
  341. }
  342. } else
  343. dbg("%s: error %d", __FUNCTION__, urb->status);
  344. /* Resubmit urb so we continue receiving IRQ data */
  345. if (urb->status != -ESHUTDOWN) {
  346. urb->dev = serial->dev;
  347. err = usb_submit_urb(urb, GFP_ATOMIC);
  348. if (err)
  349. dbg("%s: resubmit intr urb failed. (%d)",
  350. __FUNCTION__, err);
  351. }
  352. }
  353. static int option_write_room(struct usb_serial_port *port)
  354. {
  355. struct option_port_private *portdata;
  356. int i;
  357. int data_len = 0;
  358. struct urb *this_urb;
  359. portdata = usb_get_serial_port_data(port);
  360. for (i=0; i < N_OUT_URB; i++) {
  361. this_urb = portdata->out_urbs[i];
  362. if (this_urb && this_urb->status != -EINPROGRESS)
  363. data_len += OUT_BUFLEN;
  364. }
  365. dbg("%s: %d", __FUNCTION__, data_len);
  366. return data_len;
  367. }
  368. static int option_chars_in_buffer(struct usb_serial_port *port)
  369. {
  370. struct option_port_private *portdata;
  371. int i;
  372. int data_len = 0;
  373. struct urb *this_urb;
  374. portdata = usb_get_serial_port_data(port);
  375. for (i=0; i < N_OUT_URB; i++) {
  376. this_urb = portdata->out_urbs[i];
  377. if (this_urb && this_urb->status == -EINPROGRESS)
  378. data_len += this_urb->transfer_buffer_length;
  379. }
  380. dbg("%s: %d", __FUNCTION__, data_len);
  381. return data_len;
  382. }
  383. static int option_open(struct usb_serial_port *port, struct file *filp)
  384. {
  385. struct option_port_private *portdata;
  386. struct usb_serial *serial = port->serial;
  387. int i, err;
  388. struct urb *urb;
  389. portdata = usb_get_serial_port_data(port);
  390. dbg("%s", __FUNCTION__);
  391. /* Set some sane defaults */
  392. portdata->rts_state = 1;
  393. portdata->dtr_state = 1;
  394. /* Reset low level data toggle and start reading from endpoints */
  395. for (i = 0; i < N_IN_URB; i++) {
  396. urb = portdata->in_urbs[i];
  397. if (! urb)
  398. continue;
  399. if (urb->dev != serial->dev) {
  400. dbg("%s: dev %p != %p", __FUNCTION__,
  401. urb->dev, serial->dev);
  402. continue;
  403. }
  404. /*
  405. * make sure endpoint data toggle is synchronized with the
  406. * device
  407. */
  408. usb_clear_halt(urb->dev, urb->pipe);
  409. err = usb_submit_urb(urb, GFP_KERNEL);
  410. if (err) {
  411. dbg("%s: submit urb %d failed (%d) %d",
  412. __FUNCTION__, i, err,
  413. urb->transfer_buffer_length);
  414. }
  415. }
  416. /* Reset low level data toggle on out endpoints */
  417. for (i = 0; i < N_OUT_URB; i++) {
  418. urb = portdata->out_urbs[i];
  419. if (! urb)
  420. continue;
  421. urb->dev = serial->dev;
  422. /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
  423. usb_pipeout(urb->pipe), 0); */
  424. }
  425. port->tty->low_latency = 1;
  426. option_send_setup(port);
  427. return (0);
  428. }
  429. static inline void stop_urb(struct urb *urb)
  430. {
  431. if (urb && urb->status == -EINPROGRESS)
  432. usb_kill_urb(urb);
  433. }
  434. static void option_close(struct usb_serial_port *port, struct file *filp)
  435. {
  436. int i;
  437. struct usb_serial *serial = port->serial;
  438. struct option_port_private *portdata;
  439. dbg("%s", __FUNCTION__);
  440. portdata = usb_get_serial_port_data(port);
  441. portdata->rts_state = 0;
  442. portdata->dtr_state = 0;
  443. if (serial->dev) {
  444. option_send_setup(port);
  445. /* Stop reading/writing urbs */
  446. for (i = 0; i < N_IN_URB; i++)
  447. stop_urb(portdata->in_urbs[i]);
  448. for (i = 0; i < N_OUT_URB; i++)
  449. stop_urb(portdata->out_urbs[i]);
  450. }
  451. port->tty = NULL;
  452. }
  453. /* Helper functions used by option_setup_urbs */
  454. static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
  455. int dir, void *ctx, char *buf, int len,
  456. void (*callback)(struct urb *, struct pt_regs *regs))
  457. {
  458. struct urb *urb;
  459. if (endpoint == -1)
  460. return NULL; /* endpoint not needed */
  461. urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
  462. if (urb == NULL) {
  463. dbg("%s: alloc for endpoint %d failed.", __FUNCTION__, endpoint);
  464. return NULL;
  465. }
  466. /* Fill URB using supplied data. */
  467. usb_fill_bulk_urb(urb, serial->dev,
  468. usb_sndbulkpipe(serial->dev, endpoint) | dir,
  469. buf, len, callback, ctx);
  470. return urb;
  471. }
  472. /* Setup urbs */
  473. static void option_setup_urbs(struct usb_serial *serial)
  474. {
  475. int j;
  476. struct usb_serial_port *port;
  477. struct option_port_private *portdata;
  478. dbg("%s", __FUNCTION__);
  479. port = serial->port[0];
  480. portdata = usb_get_serial_port_data(port);
  481. /* Do indat endpoints first */
  482. for (j = 0; j < N_IN_URB; ++j) {
  483. portdata->in_urbs[j] = option_setup_urb (serial,
  484. port->bulk_in_endpointAddress, USB_DIR_IN, port,
  485. portdata->in_buffer[j], IN_BUFLEN, option_indat_callback);
  486. }
  487. /* outdat endpoints */
  488. for (j = 0; j < N_OUT_URB; ++j) {
  489. portdata->out_urbs[j] = option_setup_urb (serial,
  490. port->bulk_out_endpointAddress, USB_DIR_OUT, port,
  491. portdata->out_buffer[j], OUT_BUFLEN, option_outdat_callback);
  492. }
  493. }
  494. static int option_send_setup(struct usb_serial_port *port)
  495. {
  496. struct usb_serial *serial = port->serial;
  497. struct option_port_private *portdata;
  498. dbg("%s", __FUNCTION__);
  499. portdata = usb_get_serial_port_data(port);
  500. if (port->tty) {
  501. int val = 0;
  502. if (portdata->dtr_state)
  503. val |= 0x01;
  504. if (portdata->rts_state)
  505. val |= 0x02;
  506. return usb_control_msg(serial->dev,
  507. usb_rcvctrlpipe(serial->dev, 0),
  508. 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
  509. }
  510. return 0;
  511. }
  512. static int option_startup(struct usb_serial *serial)
  513. {
  514. int i, err;
  515. struct usb_serial_port *port;
  516. struct option_port_private *portdata;
  517. dbg("%s", __FUNCTION__);
  518. /* Now setup per port private data */
  519. for (i = 0; i < serial->num_ports; i++) {
  520. port = serial->port[i];
  521. portdata = kzalloc(sizeof(*portdata), GFP_KERNEL);
  522. if (!portdata) {
  523. dbg("%s: kmalloc for option_port_private (%d) failed!.",
  524. __FUNCTION__, i);
  525. return (1);
  526. }
  527. usb_set_serial_port_data(port, portdata);
  528. if (! port->interrupt_in_urb)
  529. continue;
  530. err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  531. if (err)
  532. dbg("%s: submit irq_in urb failed %d",
  533. __FUNCTION__, err);
  534. }
  535. option_setup_urbs(serial);
  536. return (0);
  537. }
  538. static void option_shutdown(struct usb_serial *serial)
  539. {
  540. int i, j;
  541. struct usb_serial_port *port;
  542. struct option_port_private *portdata;
  543. dbg("%s", __FUNCTION__);
  544. /* Stop reading/writing urbs */
  545. for (i = 0; i < serial->num_ports; ++i) {
  546. port = serial->port[i];
  547. portdata = usb_get_serial_port_data(port);
  548. for (j = 0; j < N_IN_URB; j++)
  549. stop_urb(portdata->in_urbs[j]);
  550. for (j = 0; j < N_OUT_URB; j++)
  551. stop_urb(portdata->out_urbs[j]);
  552. }
  553. /* Now free them */
  554. for (i = 0; i < serial->num_ports; ++i) {
  555. port = serial->port[i];
  556. portdata = usb_get_serial_port_data(port);
  557. for (j = 0; j < N_IN_URB; j++) {
  558. if (portdata->in_urbs[j]) {
  559. usb_free_urb(portdata->in_urbs[j]);
  560. portdata->in_urbs[j] = NULL;
  561. }
  562. }
  563. for (j = 0; j < N_OUT_URB; j++) {
  564. if (portdata->out_urbs[j]) {
  565. usb_free_urb(portdata->out_urbs[j]);
  566. portdata->out_urbs[j] = NULL;
  567. }
  568. }
  569. }
  570. /* Now free per port private data */
  571. for (i = 0; i < serial->num_ports; i++) {
  572. port = serial->port[i];
  573. kfree(usb_get_serial_port_data(port));
  574. }
  575. }
  576. MODULE_AUTHOR(DRIVER_AUTHOR);
  577. MODULE_DESCRIPTION(DRIVER_DESC);
  578. MODULE_VERSION(DRIVER_VERSION);
  579. MODULE_LICENSE("GPL");
  580. #ifdef CONFIG_USB_DEBUG
  581. module_param(debug, bool, S_IRUGO | S_IWUSR);
  582. MODULE_PARM_DESC(debug, "Debug messages");
  583. #endif