cdc-acm.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737
  1. /*
  2. * cdc-acm.c
  3. *
  4. * Copyright (c) 1999 Armin Fuerst <fuerst@in.tum.de>
  5. * Copyright (c) 1999 Pavel Machek <pavel@ucw.cz>
  6. * Copyright (c) 1999 Johannes Erdfelt <johannes@erdfelt.com>
  7. * Copyright (c) 2000 Vojtech Pavlik <vojtech@suse.cz>
  8. * Copyright (c) 2004 Oliver Neukum <oliver@neukum.name>
  9. * Copyright (c) 2005 David Kubicek <dave@awk.cz>
  10. *
  11. * USB Abstract Control Model driver for USB modems and ISDN adapters
  12. *
  13. * Sponsored by SuSE
  14. *
  15. * ChangeLog:
  16. * v0.9 - thorough cleaning, URBification, almost a rewrite
  17. * v0.10 - some more cleanups
  18. * v0.11 - fixed flow control, read error doesn't stop reads
  19. * v0.12 - added TIOCM ioctls, added break handling, made struct acm
  20. * kmalloced
  21. * v0.13 - added termios, added hangup
  22. * v0.14 - sized down struct acm
  23. * v0.15 - fixed flow control again - characters could be lost
  24. * v0.16 - added code for modems with swapped data and control interfaces
  25. * v0.17 - added new style probing
  26. * v0.18 - fixed new style probing for devices with more configurations
  27. * v0.19 - fixed CLOCAL handling (thanks to Richard Shih-Ping Chan)
  28. * v0.20 - switched to probing on interface (rather than device) class
  29. * v0.21 - revert to probing on device for devices with multiple configs
  30. * v0.22 - probe only the control interface. if usbcore doesn't choose the
  31. * config we want, sysadmin changes bConfigurationValue in sysfs.
  32. * v0.23 - use softirq for rx processing, as needed by tty layer
  33. * v0.24 - change probe method to evaluate CDC union descriptor
  34. * v0.25 - downstream tasks paralelized to maximize throughput
  35. * v0.26 - multiple write urbs, writesize increased
  36. */
  37. /*
  38. * This program is free software; you can redistribute it and/or modify
  39. * it under the terms of the GNU General Public License as published by
  40. * the Free Software Foundation; either version 2 of the License, or
  41. * (at your option) any later version.
  42. *
  43. * This program is distributed in the hope that it will be useful,
  44. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  45. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  46. * GNU General Public License for more details.
  47. *
  48. * You should have received a copy of the GNU General Public License
  49. * along with this program; if not, write to the Free Software
  50. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  51. */
  52. #undef DEBUG
  53. #undef VERBOSE_DEBUG
  54. #include <linux/kernel.h>
  55. #include <linux/errno.h>
  56. #include <linux/init.h>
  57. #include <linux/slab.h>
  58. #include <linux/tty.h>
  59. #include <linux/serial.h>
  60. #include <linux/tty_driver.h>
  61. #include <linux/tty_flip.h>
  62. #include <linux/module.h>
  63. #include <linux/mutex.h>
  64. #include <linux/uaccess.h>
  65. #include <linux/usb.h>
  66. #include <linux/usb/cdc.h>
  67. #include <asm/byteorder.h>
  68. #include <asm/unaligned.h>
  69. #include <linux/list.h>
  70. #include "cdc-acm.h"
  71. #define ACM_CLOSE_TIMEOUT 15 /* seconds to let writes drain */
  72. /*
  73. * Version Information
  74. */
  75. #define DRIVER_VERSION "v0.26"
  76. #define DRIVER_AUTHOR "Armin Fuerst, Pavel Machek, Johannes Erdfelt, Vojtech Pavlik, David Kubicek"
  77. #define DRIVER_DESC "USB Abstract Control Model driver for USB modems and ISDN adapters"
  78. static struct usb_driver acm_driver;
  79. static struct tty_driver *acm_tty_driver;
  80. static struct acm *acm_table[ACM_TTY_MINORS];
  81. static DEFINE_MUTEX(open_mutex);
  82. #define ACM_READY(acm) (acm && acm->dev && acm->port.count)
  83. static const struct tty_port_operations acm_port_ops = {
  84. };
  85. #ifdef VERBOSE_DEBUG
  86. #define verbose 1
  87. #else
  88. #define verbose 0
  89. #endif
  90. /*
  91. * Functions for ACM control messages.
  92. */
  93. static int acm_ctrl_msg(struct acm *acm, int request, int value,
  94. void *buf, int len)
  95. {
  96. int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0),
  97. request, USB_RT_ACM, value,
  98. acm->control->altsetting[0].desc.bInterfaceNumber,
  99. buf, len, 5000);
  100. dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d",
  101. request, value, len, retval);
  102. return retval < 0 ? retval : 0;
  103. }
  104. /* devices aren't required to support these requests.
  105. * the cdc acm descriptor tells whether they do...
  106. */
  107. #define acm_set_control(acm, control) \
  108. acm_ctrl_msg(acm, USB_CDC_REQ_SET_CONTROL_LINE_STATE, control, NULL, 0)
  109. #define acm_set_line(acm, line) \
  110. acm_ctrl_msg(acm, USB_CDC_REQ_SET_LINE_CODING, 0, line, sizeof *(line))
  111. #define acm_send_break(acm, ms) \
  112. acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0)
  113. /*
  114. * Write buffer management.
  115. * All of these assume proper locks taken by the caller.
  116. */
  117. static int acm_wb_alloc(struct acm *acm)
  118. {
  119. int i, wbn;
  120. struct acm_wb *wb;
  121. wbn = 0;
  122. i = 0;
  123. for (;;) {
  124. wb = &acm->wb[wbn];
  125. if (!wb->use) {
  126. wb->use = 1;
  127. return wbn;
  128. }
  129. wbn = (wbn + 1) % ACM_NW;
  130. if (++i >= ACM_NW)
  131. return -1;
  132. }
  133. }
  134. static int acm_wb_is_avail(struct acm *acm)
  135. {
  136. int i, n;
  137. unsigned long flags;
  138. n = ACM_NW;
  139. spin_lock_irqsave(&acm->write_lock, flags);
  140. for (i = 0; i < ACM_NW; i++)
  141. n -= acm->wb[i].use;
  142. spin_unlock_irqrestore(&acm->write_lock, flags);
  143. return n;
  144. }
  145. /*
  146. * Finish write. Caller must hold acm->write_lock
  147. */
  148. static void acm_write_done(struct acm *acm, struct acm_wb *wb)
  149. {
  150. wb->use = 0;
  151. acm->transmitting--;
  152. usb_autopm_put_interface_async(acm->control);
  153. }
  154. /*
  155. * Poke write.
  156. *
  157. * the caller is responsible for locking
  158. */
  159. static int acm_start_wb(struct acm *acm, struct acm_wb *wb)
  160. {
  161. int rc;
  162. acm->transmitting++;
  163. wb->urb->transfer_buffer = wb->buf;
  164. wb->urb->transfer_dma = wb->dmah;
  165. wb->urb->transfer_buffer_length = wb->len;
  166. wb->urb->dev = acm->dev;
  167. rc = usb_submit_urb(wb->urb, GFP_ATOMIC);
  168. if (rc < 0) {
  169. dbg("usb_submit_urb(write bulk) failed: %d", rc);
  170. acm_write_done(acm, wb);
  171. }
  172. return rc;
  173. }
  174. static int acm_write_start(struct acm *acm, int wbn)
  175. {
  176. unsigned long flags;
  177. struct acm_wb *wb = &acm->wb[wbn];
  178. int rc;
  179. spin_lock_irqsave(&acm->write_lock, flags);
  180. if (!acm->dev) {
  181. wb->use = 0;
  182. spin_unlock_irqrestore(&acm->write_lock, flags);
  183. return -ENODEV;
  184. }
  185. dbg("%s susp_count: %d", __func__, acm->susp_count);
  186. usb_autopm_get_interface_async(acm->control);
  187. if (acm->susp_count) {
  188. if (!acm->delayed_wb)
  189. acm->delayed_wb = wb;
  190. else
  191. usb_autopm_put_interface_async(acm->control);
  192. spin_unlock_irqrestore(&acm->write_lock, flags);
  193. return 0; /* A white lie */
  194. }
  195. usb_mark_last_busy(acm->dev);
  196. rc = acm_start_wb(acm, wb);
  197. spin_unlock_irqrestore(&acm->write_lock, flags);
  198. return rc;
  199. }
  200. /*
  201. * attributes exported through sysfs
  202. */
  203. static ssize_t show_caps
  204. (struct device *dev, struct device_attribute *attr, char *buf)
  205. {
  206. struct usb_interface *intf = to_usb_interface(dev);
  207. struct acm *acm = usb_get_intfdata(intf);
  208. return sprintf(buf, "%d", acm->ctrl_caps);
  209. }
  210. static DEVICE_ATTR(bmCapabilities, S_IRUGO, show_caps, NULL);
  211. static ssize_t show_country_codes
  212. (struct device *dev, struct device_attribute *attr, char *buf)
  213. {
  214. struct usb_interface *intf = to_usb_interface(dev);
  215. struct acm *acm = usb_get_intfdata(intf);
  216. memcpy(buf, acm->country_codes, acm->country_code_size);
  217. return acm->country_code_size;
  218. }
  219. static DEVICE_ATTR(wCountryCodes, S_IRUGO, show_country_codes, NULL);
  220. static ssize_t show_country_rel_date
  221. (struct device *dev, struct device_attribute *attr, char *buf)
  222. {
  223. struct usb_interface *intf = to_usb_interface(dev);
  224. struct acm *acm = usb_get_intfdata(intf);
  225. return sprintf(buf, "%d", acm->country_rel_date);
  226. }
  227. static DEVICE_ATTR(iCountryCodeRelDate, S_IRUGO, show_country_rel_date, NULL);
  228. /*
  229. * Interrupt handlers for various ACM device responses
  230. */
  231. /* control interface reports status changes with "interrupt" transfers */
  232. static void acm_ctrl_irq(struct urb *urb)
  233. {
  234. struct acm *acm = urb->context;
  235. struct usb_cdc_notification *dr = urb->transfer_buffer;
  236. struct tty_struct *tty;
  237. unsigned char *data;
  238. int newctrl;
  239. int retval;
  240. int status = urb->status;
  241. switch (status) {
  242. case 0:
  243. /* success */
  244. break;
  245. case -ECONNRESET:
  246. case -ENOENT:
  247. case -ESHUTDOWN:
  248. /* this urb is terminated, clean up */
  249. dbg("%s - urb shutting down with status: %d", __func__, status);
  250. return;
  251. default:
  252. dbg("%s - nonzero urb status received: %d", __func__, status);
  253. goto exit;
  254. }
  255. if (!ACM_READY(acm))
  256. goto exit;
  257. data = (unsigned char *)(dr + 1);
  258. switch (dr->bNotificationType) {
  259. case USB_CDC_NOTIFY_NETWORK_CONNECTION:
  260. dbg("%s network", dr->wValue ?
  261. "connected to" : "disconnected from");
  262. break;
  263. case USB_CDC_NOTIFY_SERIAL_STATE:
  264. tty = tty_port_tty_get(&acm->port);
  265. newctrl = get_unaligned_le16(data);
  266. if (tty) {
  267. if (!acm->clocal &&
  268. (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) {
  269. dbg("calling hangup");
  270. tty_hangup(tty);
  271. }
  272. tty_kref_put(tty);
  273. }
  274. acm->ctrlin = newctrl;
  275. dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c",
  276. acm->ctrlin & ACM_CTRL_DCD ? '+' : '-',
  277. acm->ctrlin & ACM_CTRL_DSR ? '+' : '-',
  278. acm->ctrlin & ACM_CTRL_BRK ? '+' : '-',
  279. acm->ctrlin & ACM_CTRL_RI ? '+' : '-',
  280. acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-',
  281. acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-',
  282. acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-');
  283. break;
  284. default:
  285. dbg("unknown notification %d received: index %d len %d data0 %d data1 %d",
  286. dr->bNotificationType, dr->wIndex,
  287. dr->wLength, data[0], data[1]);
  288. break;
  289. }
  290. exit:
  291. usb_mark_last_busy(acm->dev);
  292. retval = usb_submit_urb(urb, GFP_ATOMIC);
  293. if (retval)
  294. dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with "
  295. "result %d", __func__, retval);
  296. }
  297. /* data interface returns incoming bytes, or we got unthrottled */
  298. static void acm_read_bulk(struct urb *urb)
  299. {
  300. struct acm_rb *buf;
  301. struct acm_ru *rcv = urb->context;
  302. struct acm *acm = rcv->instance;
  303. int status = urb->status;
  304. dbg("Entering acm_read_bulk with status %d", status);
  305. if (!ACM_READY(acm)) {
  306. dev_dbg(&acm->data->dev, "Aborting, acm not ready");
  307. return;
  308. }
  309. usb_mark_last_busy(acm->dev);
  310. if (status)
  311. dev_dbg(&acm->data->dev, "bulk rx status %d\n", status);
  312. buf = rcv->buffer;
  313. buf->size = urb->actual_length;
  314. if (likely(status == 0)) {
  315. spin_lock(&acm->read_lock);
  316. acm->processing++;
  317. list_add_tail(&rcv->list, &acm->spare_read_urbs);
  318. list_add_tail(&buf->list, &acm->filled_read_bufs);
  319. spin_unlock(&acm->read_lock);
  320. } else {
  321. /* we drop the buffer due to an error */
  322. spin_lock(&acm->read_lock);
  323. list_add_tail(&rcv->list, &acm->spare_read_urbs);
  324. list_add(&buf->list, &acm->spare_read_bufs);
  325. spin_unlock(&acm->read_lock);
  326. /* nevertheless the tasklet must be kicked unconditionally
  327. so the queue cannot dry up */
  328. }
  329. if (likely(!acm->susp_count))
  330. tasklet_schedule(&acm->urb_task);
  331. }
  332. static void acm_rx_tasklet(unsigned long _acm)
  333. {
  334. struct acm *acm = (void *)_acm;
  335. struct acm_rb *buf;
  336. struct tty_struct *tty;
  337. struct acm_ru *rcv;
  338. unsigned long flags;
  339. unsigned char throttled;
  340. dbg("Entering acm_rx_tasklet");
  341. if (!ACM_READY(acm)) {
  342. dbg("acm_rx_tasklet: ACM not ready");
  343. return;
  344. }
  345. spin_lock_irqsave(&acm->throttle_lock, flags);
  346. throttled = acm->throttle;
  347. spin_unlock_irqrestore(&acm->throttle_lock, flags);
  348. if (throttled) {
  349. dbg("acm_rx_tasklet: throttled");
  350. return;
  351. }
  352. tty = tty_port_tty_get(&acm->port);
  353. next_buffer:
  354. spin_lock_irqsave(&acm->read_lock, flags);
  355. if (list_empty(&acm->filled_read_bufs)) {
  356. spin_unlock_irqrestore(&acm->read_lock, flags);
  357. goto urbs;
  358. }
  359. buf = list_entry(acm->filled_read_bufs.next,
  360. struct acm_rb, list);
  361. list_del(&buf->list);
  362. spin_unlock_irqrestore(&acm->read_lock, flags);
  363. dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size);
  364. if (tty) {
  365. spin_lock_irqsave(&acm->throttle_lock, flags);
  366. throttled = acm->throttle;
  367. spin_unlock_irqrestore(&acm->throttle_lock, flags);
  368. if (!throttled) {
  369. tty_insert_flip_string(tty, buf->base, buf->size);
  370. tty_flip_buffer_push(tty);
  371. } else {
  372. tty_kref_put(tty);
  373. dbg("Throttling noticed");
  374. spin_lock_irqsave(&acm->read_lock, flags);
  375. list_add(&buf->list, &acm->filled_read_bufs);
  376. spin_unlock_irqrestore(&acm->read_lock, flags);
  377. return;
  378. }
  379. }
  380. spin_lock_irqsave(&acm->read_lock, flags);
  381. list_add(&buf->list, &acm->spare_read_bufs);
  382. spin_unlock_irqrestore(&acm->read_lock, flags);
  383. goto next_buffer;
  384. urbs:
  385. tty_kref_put(tty);
  386. while (!list_empty(&acm->spare_read_bufs)) {
  387. spin_lock_irqsave(&acm->read_lock, flags);
  388. if (list_empty(&acm->spare_read_urbs)) {
  389. acm->processing = 0;
  390. spin_unlock_irqrestore(&acm->read_lock, flags);
  391. return;
  392. }
  393. rcv = list_entry(acm->spare_read_urbs.next,
  394. struct acm_ru, list);
  395. list_del(&rcv->list);
  396. spin_unlock_irqrestore(&acm->read_lock, flags);
  397. buf = list_entry(acm->spare_read_bufs.next,
  398. struct acm_rb, list);
  399. list_del(&buf->list);
  400. rcv->buffer = buf;
  401. if (acm->is_int_ep)
  402. usb_fill_int_urb(rcv->urb, acm->dev,
  403. acm->rx_endpoint,
  404. buf->base,
  405. acm->readsize,
  406. acm_read_bulk, rcv, acm->bInterval);
  407. else
  408. usb_fill_bulk_urb(rcv->urb, acm->dev,
  409. acm->rx_endpoint,
  410. buf->base,
  411. acm->readsize,
  412. acm_read_bulk, rcv);
  413. rcv->urb->transfer_dma = buf->dma;
  414. rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  415. /* This shouldn't kill the driver as unsuccessful URBs are
  416. returned to the free-urbs-pool and resubmited ASAP */
  417. spin_lock_irqsave(&acm->read_lock, flags);
  418. if (acm->susp_count ||
  419. usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) {
  420. list_add(&buf->list, &acm->spare_read_bufs);
  421. list_add(&rcv->list, &acm->spare_read_urbs);
  422. acm->processing = 0;
  423. spin_unlock_irqrestore(&acm->read_lock, flags);
  424. return;
  425. } else {
  426. spin_unlock_irqrestore(&acm->read_lock, flags);
  427. dbg("acm_rx_tasklet: sending urb 0x%p, rcv 0x%p, buf 0x%p", rcv->urb, rcv, buf);
  428. }
  429. }
  430. spin_lock_irqsave(&acm->read_lock, flags);
  431. acm->processing = 0;
  432. spin_unlock_irqrestore(&acm->read_lock, flags);
  433. }
  434. /* data interface wrote those outgoing bytes */
  435. static void acm_write_bulk(struct urb *urb)
  436. {
  437. struct acm_wb *wb = urb->context;
  438. struct acm *acm = wb->instance;
  439. unsigned long flags;
  440. if (verbose || urb->status
  441. || (urb->actual_length != urb->transfer_buffer_length))
  442. dev_dbg(&acm->data->dev, "tx %d/%d bytes -- > %d\n",
  443. urb->actual_length,
  444. urb->transfer_buffer_length,
  445. urb->status);
  446. spin_lock_irqsave(&acm->write_lock, flags);
  447. acm_write_done(acm, wb);
  448. spin_unlock_irqrestore(&acm->write_lock, flags);
  449. if (ACM_READY(acm))
  450. schedule_work(&acm->work);
  451. else
  452. wake_up_interruptible(&acm->drain_wait);
  453. }
  454. static void acm_softint(struct work_struct *work)
  455. {
  456. struct acm *acm = container_of(work, struct acm, work);
  457. struct tty_struct *tty;
  458. dev_vdbg(&acm->data->dev, "tx work\n");
  459. if (!ACM_READY(acm))
  460. return;
  461. tty = tty_port_tty_get(&acm->port);
  462. if (!tty)
  463. return;
  464. tty_wakeup(tty);
  465. tty_kref_put(tty);
  466. }
  467. /*
  468. * TTY handlers
  469. */
  470. static int acm_tty_open(struct tty_struct *tty, struct file *filp)
  471. {
  472. struct acm *acm;
  473. int rv = -ENODEV;
  474. int i;
  475. dbg("Entering acm_tty_open.");
  476. mutex_lock(&open_mutex);
  477. acm = acm_table[tty->index];
  478. if (!acm || !acm->dev)
  479. goto out;
  480. else
  481. rv = 0;
  482. set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
  483. tty->driver_data = acm;
  484. tty_port_tty_set(&acm->port, tty);
  485. if (usb_autopm_get_interface(acm->control) < 0)
  486. goto early_bail;
  487. else
  488. acm->control->needs_remote_wakeup = 1;
  489. mutex_lock(&acm->mutex);
  490. if (acm->port.count++) {
  491. mutex_unlock(&acm->mutex);
  492. usb_autopm_put_interface(acm->control);
  493. goto out;
  494. }
  495. acm->ctrlurb->dev = acm->dev;
  496. if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) {
  497. dbg("usb_submit_urb(ctrl irq) failed");
  498. goto bail_out;
  499. }
  500. if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) &&
  501. (acm->ctrl_caps & USB_CDC_CAP_LINE))
  502. goto full_bailout;
  503. usb_autopm_put_interface(acm->control);
  504. INIT_LIST_HEAD(&acm->spare_read_urbs);
  505. INIT_LIST_HEAD(&acm->spare_read_bufs);
  506. INIT_LIST_HEAD(&acm->filled_read_bufs);
  507. for (i = 0; i < acm->rx_buflimit; i++)
  508. list_add(&(acm->ru[i].list), &acm->spare_read_urbs);
  509. for (i = 0; i < acm->rx_buflimit; i++)
  510. list_add(&(acm->rb[i].list), &acm->spare_read_bufs);
  511. acm->throttle = 0;
  512. set_bit(ASYNCB_INITIALIZED, &acm->port.flags);
  513. rv = tty_port_block_til_ready(&acm->port, tty, filp);
  514. tasklet_schedule(&acm->urb_task);
  515. mutex_unlock(&acm->mutex);
  516. out:
  517. mutex_unlock(&open_mutex);
  518. return rv;
  519. full_bailout:
  520. usb_kill_urb(acm->ctrlurb);
  521. bail_out:
  522. acm->port.count--;
  523. mutex_unlock(&acm->mutex);
  524. usb_autopm_put_interface(acm->control);
  525. early_bail:
  526. mutex_unlock(&open_mutex);
  527. tty_port_tty_set(&acm->port, NULL);
  528. return -EIO;
  529. }
  530. static void acm_tty_unregister(struct acm *acm)
  531. {
  532. int i, nr;
  533. nr = acm->rx_buflimit;
  534. tty_unregister_device(acm_tty_driver, acm->minor);
  535. usb_put_intf(acm->control);
  536. acm_table[acm->minor] = NULL;
  537. usb_free_urb(acm->ctrlurb);
  538. for (i = 0; i < ACM_NW; i++)
  539. usb_free_urb(acm->wb[i].urb);
  540. for (i = 0; i < nr; i++)
  541. usb_free_urb(acm->ru[i].urb);
  542. kfree(acm->country_codes);
  543. kfree(acm);
  544. }
  545. static int acm_tty_chars_in_buffer(struct tty_struct *tty);
  546. static void acm_port_down(struct acm *acm)
  547. {
  548. int i, nr = acm->rx_buflimit;
  549. mutex_lock(&open_mutex);
  550. if (acm->dev) {
  551. usb_autopm_get_interface(acm->control);
  552. acm_set_control(acm, acm->ctrlout = 0);
  553. usb_kill_urb(acm->ctrlurb);
  554. for (i = 0; i < ACM_NW; i++)
  555. usb_kill_urb(acm->wb[i].urb);
  556. tasklet_disable(&acm->urb_task);
  557. for (i = 0; i < nr; i++)
  558. usb_kill_urb(acm->ru[i].urb);
  559. tasklet_enable(&acm->urb_task);
  560. acm->control->needs_remote_wakeup = 0;
  561. usb_autopm_put_interface(acm->control);
  562. }
  563. mutex_unlock(&open_mutex);
  564. }
  565. static void acm_tty_hangup(struct tty_struct *tty)
  566. {
  567. struct acm *acm = tty->driver_data;
  568. tty_port_hangup(&acm->port);
  569. acm_port_down(acm);
  570. }
  571. static void acm_tty_close(struct tty_struct *tty, struct file *filp)
  572. {
  573. struct acm *acm = tty->driver_data;
  574. /* Perform the closing process and see if we need to do the hardware
  575. shutdown */
  576. if (!acm)
  577. return;
  578. if (tty_port_close_start(&acm->port, tty, filp) == 0) {
  579. mutex_lock(&open_mutex);
  580. if (!acm->dev) {
  581. tty_port_tty_set(&acm->port, NULL);
  582. acm_tty_unregister(acm);
  583. tty->driver_data = NULL;
  584. }
  585. mutex_unlock(&open_mutex);
  586. return;
  587. }
  588. acm_port_down(acm);
  589. tty_port_close_end(&acm->port, tty);
  590. tty_port_tty_set(&acm->port, NULL);
  591. }
  592. static int acm_tty_write(struct tty_struct *tty,
  593. const unsigned char *buf, int count)
  594. {
  595. struct acm *acm = tty->driver_data;
  596. int stat;
  597. unsigned long flags;
  598. int wbn;
  599. struct acm_wb *wb;
  600. dbg("Entering acm_tty_write to write %d bytes,", count);
  601. if (!ACM_READY(acm))
  602. return -EINVAL;
  603. if (!count)
  604. return 0;
  605. spin_lock_irqsave(&acm->write_lock, flags);
  606. wbn = acm_wb_alloc(acm);
  607. if (wbn < 0) {
  608. spin_unlock_irqrestore(&acm->write_lock, flags);
  609. return 0;
  610. }
  611. wb = &acm->wb[wbn];
  612. count = (count > acm->writesize) ? acm->writesize : count;
  613. dbg("Get %d bytes...", count);
  614. memcpy(wb->buf, buf, count);
  615. wb->len = count;
  616. spin_unlock_irqrestore(&acm->write_lock, flags);
  617. stat = acm_write_start(acm, wbn);
  618. if (stat < 0)
  619. return stat;
  620. return count;
  621. }
  622. static int acm_tty_write_room(struct tty_struct *tty)
  623. {
  624. struct acm *acm = tty->driver_data;
  625. if (!ACM_READY(acm))
  626. return -EINVAL;
  627. /*
  628. * Do not let the line discipline to know that we have a reserve,
  629. * or it might get too enthusiastic.
  630. */
  631. return acm_wb_is_avail(acm) ? acm->writesize : 0;
  632. }
  633. static int acm_tty_chars_in_buffer(struct tty_struct *tty)
  634. {
  635. struct acm *acm = tty->driver_data;
  636. if (!ACM_READY(acm))
  637. return 0;
  638. /*
  639. * This is inaccurate (overcounts), but it works.
  640. */
  641. return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize;
  642. }
  643. static void acm_tty_throttle(struct tty_struct *tty)
  644. {
  645. struct acm *acm = tty->driver_data;
  646. if (!ACM_READY(acm))
  647. return;
  648. spin_lock_bh(&acm->throttle_lock);
  649. acm->throttle = 1;
  650. spin_unlock_bh(&acm->throttle_lock);
  651. }
  652. static void acm_tty_unthrottle(struct tty_struct *tty)
  653. {
  654. struct acm *acm = tty->driver_data;
  655. if (!ACM_READY(acm))
  656. return;
  657. spin_lock_bh(&acm->throttle_lock);
  658. acm->throttle = 0;
  659. spin_unlock_bh(&acm->throttle_lock);
  660. tasklet_schedule(&acm->urb_task);
  661. }
  662. static int acm_tty_break_ctl(struct tty_struct *tty, int state)
  663. {
  664. struct acm *acm = tty->driver_data;
  665. int retval;
  666. if (!ACM_READY(acm))
  667. return -EINVAL;
  668. retval = acm_send_break(acm, state ? 0xffff : 0);
  669. if (retval < 0)
  670. dbg("send break failed");
  671. return retval;
  672. }
  673. static int acm_tty_tiocmget(struct tty_struct *tty)
  674. {
  675. struct acm *acm = tty->driver_data;
  676. if (!ACM_READY(acm))
  677. return -EINVAL;
  678. return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) |
  679. (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) |
  680. (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) |
  681. (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) |
  682. (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) |
  683. TIOCM_CTS;
  684. }
  685. static int acm_tty_tiocmset(struct tty_struct *tty,
  686. unsigned int set, unsigned int clear)
  687. {
  688. struct acm *acm = tty->driver_data;
  689. unsigned int newctrl;
  690. if (!ACM_READY(acm))
  691. return -EINVAL;
  692. newctrl = acm->ctrlout;
  693. set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
  694. (set & TIOCM_RTS ? ACM_CTRL_RTS : 0);
  695. clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
  696. (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0);
  697. newctrl = (newctrl & ~clear) | set;
  698. if (acm->ctrlout == newctrl)
  699. return 0;
  700. return acm_set_control(acm, acm->ctrlout = newctrl);
  701. }
  702. static int acm_tty_ioctl(struct tty_struct *tty,
  703. unsigned int cmd, unsigned long arg)
  704. {
  705. struct acm *acm = tty->driver_data;
  706. if (!ACM_READY(acm))
  707. return -EINVAL;
  708. return -ENOIOCTLCMD;
  709. }
  710. static const __u32 acm_tty_speed[] = {
  711. 0, 50, 75, 110, 134, 150, 200, 300, 600,
  712. 1200, 1800, 2400, 4800, 9600, 19200, 38400,
  713. 57600, 115200, 230400, 460800, 500000, 576000,
  714. 921600, 1000000, 1152000, 1500000, 2000000,
  715. 2500000, 3000000, 3500000, 4000000
  716. };
  717. static const __u8 acm_tty_size[] = {
  718. 5, 6, 7, 8
  719. };
  720. static void acm_tty_set_termios(struct tty_struct *tty,
  721. struct ktermios *termios_old)
  722. {
  723. struct acm *acm = tty->driver_data;
  724. struct ktermios *termios = tty->termios;
  725. struct usb_cdc_line_coding newline;
  726. int newctrl = acm->ctrlout;
  727. if (!ACM_READY(acm))
  728. return;
  729. newline.dwDTERate = cpu_to_le32(tty_get_baud_rate(tty));
  730. newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0;
  731. newline.bParityType = termios->c_cflag & PARENB ?
  732. (termios->c_cflag & PARODD ? 1 : 2) +
  733. (termios->c_cflag & CMSPAR ? 2 : 0) : 0;
  734. newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4];
  735. /* FIXME: Needs to clear unsupported bits in the termios */
  736. acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
  737. if (!newline.dwDTERate) {
  738. newline.dwDTERate = acm->line.dwDTERate;
  739. newctrl &= ~ACM_CTRL_DTR;
  740. } else
  741. newctrl |= ACM_CTRL_DTR;
  742. if (newctrl != acm->ctrlout)
  743. acm_set_control(acm, acm->ctrlout = newctrl);
  744. if (memcmp(&acm->line, &newline, sizeof newline)) {
  745. memcpy(&acm->line, &newline, sizeof newline);
  746. dbg("set line: %d %d %d %d", le32_to_cpu(newline.dwDTERate),
  747. newline.bCharFormat, newline.bParityType,
  748. newline.bDataBits);
  749. acm_set_line(acm, &acm->line);
  750. }
  751. }
  752. /*
  753. * USB probe and disconnect routines.
  754. */
  755. /* Little helpers: write/read buffers free */
  756. static void acm_write_buffers_free(struct acm *acm)
  757. {
  758. int i;
  759. struct acm_wb *wb;
  760. struct usb_device *usb_dev = interface_to_usbdev(acm->control);
  761. for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++)
  762. usb_free_coherent(usb_dev, acm->writesize, wb->buf, wb->dmah);
  763. }
  764. static void acm_read_buffers_free(struct acm *acm)
  765. {
  766. struct usb_device *usb_dev = interface_to_usbdev(acm->control);
  767. int i, n = acm->rx_buflimit;
  768. for (i = 0; i < n; i++)
  769. usb_free_coherent(usb_dev, acm->readsize,
  770. acm->rb[i].base, acm->rb[i].dma);
  771. }
  772. /* Little helper: write buffers allocate */
  773. static int acm_write_buffers_alloc(struct acm *acm)
  774. {
  775. int i;
  776. struct acm_wb *wb;
  777. for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) {
  778. wb->buf = usb_alloc_coherent(acm->dev, acm->writesize, GFP_KERNEL,
  779. &wb->dmah);
  780. if (!wb->buf) {
  781. while (i != 0) {
  782. --i;
  783. --wb;
  784. usb_free_coherent(acm->dev, acm->writesize,
  785. wb->buf, wb->dmah);
  786. }
  787. return -ENOMEM;
  788. }
  789. }
  790. return 0;
  791. }
  792. static int acm_probe(struct usb_interface *intf,
  793. const struct usb_device_id *id)
  794. {
  795. struct usb_cdc_union_desc *union_header = NULL;
  796. struct usb_cdc_country_functional_desc *cfd = NULL;
  797. unsigned char *buffer = intf->altsetting->extra;
  798. int buflen = intf->altsetting->extralen;
  799. struct usb_interface *control_interface;
  800. struct usb_interface *data_interface;
  801. struct usb_endpoint_descriptor *epctrl = NULL;
  802. struct usb_endpoint_descriptor *epread = NULL;
  803. struct usb_endpoint_descriptor *epwrite = NULL;
  804. struct usb_device *usb_dev = interface_to_usbdev(intf);
  805. struct acm *acm;
  806. int minor;
  807. int ctrlsize, readsize;
  808. u8 *buf;
  809. u8 ac_management_function = 0;
  810. u8 call_management_function = 0;
  811. int call_interface_num = -1;
  812. int data_interface_num;
  813. unsigned long quirks;
  814. int num_rx_buf;
  815. int i;
  816. int combined_interfaces = 0;
  817. /* normal quirks */
  818. quirks = (unsigned long)id->driver_info;
  819. num_rx_buf = (quirks == SINGLE_RX_URB) ? 1 : ACM_NR;
  820. /* handle quirks deadly to normal probing*/
  821. if (quirks == NO_UNION_NORMAL) {
  822. data_interface = usb_ifnum_to_if(usb_dev, 1);
  823. control_interface = usb_ifnum_to_if(usb_dev, 0);
  824. goto skip_normal_probe;
  825. }
  826. /* normal probing*/
  827. if (!buffer) {
  828. dev_err(&intf->dev, "Weird descriptor references\n");
  829. return -EINVAL;
  830. }
  831. if (!buflen) {
  832. if (intf->cur_altsetting->endpoint &&
  833. intf->cur_altsetting->endpoint->extralen &&
  834. intf->cur_altsetting->endpoint->extra) {
  835. dev_dbg(&intf->dev,
  836. "Seeking extra descriptors on endpoint\n");
  837. buflen = intf->cur_altsetting->endpoint->extralen;
  838. buffer = intf->cur_altsetting->endpoint->extra;
  839. } else {
  840. dev_err(&intf->dev,
  841. "Zero length descriptor references\n");
  842. return -EINVAL;
  843. }
  844. }
  845. while (buflen > 0) {
  846. if (buffer[1] != USB_DT_CS_INTERFACE) {
  847. dev_err(&intf->dev, "skipping garbage\n");
  848. goto next_desc;
  849. }
  850. switch (buffer[2]) {
  851. case USB_CDC_UNION_TYPE: /* we've found it */
  852. if (union_header) {
  853. dev_err(&intf->dev, "More than one "
  854. "union descriptor, skipping ...\n");
  855. goto next_desc;
  856. }
  857. union_header = (struct usb_cdc_union_desc *)buffer;
  858. break;
  859. case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/
  860. cfd = (struct usb_cdc_country_functional_desc *)buffer;
  861. break;
  862. case USB_CDC_HEADER_TYPE: /* maybe check version */
  863. break; /* for now we ignore it */
  864. case USB_CDC_ACM_TYPE:
  865. ac_management_function = buffer[3];
  866. break;
  867. case USB_CDC_CALL_MANAGEMENT_TYPE:
  868. call_management_function = buffer[3];
  869. call_interface_num = buffer[4];
  870. if ( (quirks & NOT_A_MODEM) == 0 && (call_management_function & 3) != 3)
  871. dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n");
  872. break;
  873. default:
  874. /* there are LOTS more CDC descriptors that
  875. * could legitimately be found here.
  876. */
  877. dev_dbg(&intf->dev, "Ignoring descriptor: "
  878. "type %02x, length %d\n",
  879. buffer[2], buffer[0]);
  880. break;
  881. }
  882. next_desc:
  883. buflen -= buffer[0];
  884. buffer += buffer[0];
  885. }
  886. if (!union_header) {
  887. if (call_interface_num > 0) {
  888. dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n");
  889. data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num));
  890. control_interface = intf;
  891. } else {
  892. if (intf->cur_altsetting->desc.bNumEndpoints != 3) {
  893. dev_dbg(&intf->dev,"No union descriptor, giving up\n");
  894. return -ENODEV;
  895. } else {
  896. dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n");
  897. combined_interfaces = 1;
  898. control_interface = data_interface = intf;
  899. goto look_for_collapsed_interface;
  900. }
  901. }
  902. } else {
  903. control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0);
  904. data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0));
  905. if (!control_interface || !data_interface) {
  906. dev_dbg(&intf->dev, "no interfaces\n");
  907. return -ENODEV;
  908. }
  909. }
  910. if (data_interface_num != call_interface_num)
  911. dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n");
  912. if (control_interface == data_interface) {
  913. /* some broken devices designed for windows work this way */
  914. dev_warn(&intf->dev,"Control and data interfaces are not separated!\n");
  915. combined_interfaces = 1;
  916. /* a popular other OS doesn't use it */
  917. quirks |= NO_CAP_LINE;
  918. if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) {
  919. dev_err(&intf->dev, "This needs exactly 3 endpoints\n");
  920. return -EINVAL;
  921. }
  922. look_for_collapsed_interface:
  923. for (i = 0; i < 3; i++) {
  924. struct usb_endpoint_descriptor *ep;
  925. ep = &data_interface->cur_altsetting->endpoint[i].desc;
  926. if (usb_endpoint_is_int_in(ep))
  927. epctrl = ep;
  928. else if (usb_endpoint_is_bulk_out(ep))
  929. epwrite = ep;
  930. else if (usb_endpoint_is_bulk_in(ep))
  931. epread = ep;
  932. else
  933. return -EINVAL;
  934. }
  935. if (!epctrl || !epread || !epwrite)
  936. return -ENODEV;
  937. else
  938. goto made_compressed_probe;
  939. }
  940. skip_normal_probe:
  941. /*workaround for switched interfaces */
  942. if (data_interface->cur_altsetting->desc.bInterfaceClass
  943. != CDC_DATA_INTERFACE_TYPE) {
  944. if (control_interface->cur_altsetting->desc.bInterfaceClass
  945. == CDC_DATA_INTERFACE_TYPE) {
  946. struct usb_interface *t;
  947. dev_dbg(&intf->dev,
  948. "Your device has switched interfaces.\n");
  949. t = control_interface;
  950. control_interface = data_interface;
  951. data_interface = t;
  952. } else {
  953. return -EINVAL;
  954. }
  955. }
  956. /* Accept probe requests only for the control interface */
  957. if (!combined_interfaces && intf != control_interface)
  958. return -ENODEV;
  959. if (!combined_interfaces && usb_interface_claimed(data_interface)) {
  960. /* valid in this context */
  961. dev_dbg(&intf->dev, "The data interface isn't available\n");
  962. return -EBUSY;
  963. }
  964. if (data_interface->cur_altsetting->desc.bNumEndpoints < 2)
  965. return -EINVAL;
  966. epctrl = &control_interface->cur_altsetting->endpoint[0].desc;
  967. epread = &data_interface->cur_altsetting->endpoint[0].desc;
  968. epwrite = &data_interface->cur_altsetting->endpoint[1].desc;
  969. /* workaround for switched endpoints */
  970. if (!usb_endpoint_dir_in(epread)) {
  971. /* descriptors are swapped */
  972. struct usb_endpoint_descriptor *t;
  973. dev_dbg(&intf->dev,
  974. "The data interface has switched endpoints\n");
  975. t = epread;
  976. epread = epwrite;
  977. epwrite = t;
  978. }
  979. made_compressed_probe:
  980. dbg("interfaces are valid");
  981. for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++);
  982. if (minor == ACM_TTY_MINORS) {
  983. dev_err(&intf->dev, "no more free acm devices\n");
  984. return -ENODEV;
  985. }
  986. acm = kzalloc(sizeof(struct acm), GFP_KERNEL);
  987. if (acm == NULL) {
  988. dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n");
  989. goto alloc_fail;
  990. }
  991. ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize);
  992. readsize = le16_to_cpu(epread->wMaxPacketSize) *
  993. (quirks == SINGLE_RX_URB ? 1 : 2);
  994. acm->combined_interfaces = combined_interfaces;
  995. acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20;
  996. acm->control = control_interface;
  997. acm->data = data_interface;
  998. acm->minor = minor;
  999. acm->dev = usb_dev;
  1000. acm->ctrl_caps = ac_management_function;
  1001. if (quirks & NO_CAP_LINE)
  1002. acm->ctrl_caps &= ~USB_CDC_CAP_LINE;
  1003. acm->ctrlsize = ctrlsize;
  1004. acm->readsize = readsize;
  1005. acm->rx_buflimit = num_rx_buf;
  1006. acm->urb_task.func = acm_rx_tasklet;
  1007. acm->urb_task.data = (unsigned long) acm;
  1008. INIT_WORK(&acm->work, acm_softint);
  1009. init_waitqueue_head(&acm->drain_wait);
  1010. spin_lock_init(&acm->throttle_lock);
  1011. spin_lock_init(&acm->write_lock);
  1012. spin_lock_init(&acm->read_lock);
  1013. mutex_init(&acm->mutex);
  1014. acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress);
  1015. acm->is_int_ep = usb_endpoint_xfer_int(epread);
  1016. if (acm->is_int_ep)
  1017. acm->bInterval = epread->bInterval;
  1018. tty_port_init(&acm->port);
  1019. acm->port.ops = &acm_port_ops;
  1020. buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
  1021. if (!buf) {
  1022. dev_dbg(&intf->dev, "out of memory (ctrl buffer alloc)\n");
  1023. goto alloc_fail2;
  1024. }
  1025. acm->ctrl_buffer = buf;
  1026. if (acm_write_buffers_alloc(acm) < 0) {
  1027. dev_dbg(&intf->dev, "out of memory (write buffer alloc)\n");
  1028. goto alloc_fail4;
  1029. }
  1030. acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL);
  1031. if (!acm->ctrlurb) {
  1032. dev_dbg(&intf->dev, "out of memory (ctrlurb kmalloc)\n");
  1033. goto alloc_fail5;
  1034. }
  1035. for (i = 0; i < num_rx_buf; i++) {
  1036. struct acm_ru *rcv = &(acm->ru[i]);
  1037. rcv->urb = usb_alloc_urb(0, GFP_KERNEL);
  1038. if (rcv->urb == NULL) {
  1039. dev_dbg(&intf->dev,
  1040. "out of memory (read urbs usb_alloc_urb)\n");
  1041. goto alloc_fail6;
  1042. }
  1043. rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1044. rcv->instance = acm;
  1045. }
  1046. for (i = 0; i < num_rx_buf; i++) {
  1047. struct acm_rb *rb = &(acm->rb[i]);
  1048. rb->base = usb_alloc_coherent(acm->dev, readsize,
  1049. GFP_KERNEL, &rb->dma);
  1050. if (!rb->base) {
  1051. dev_dbg(&intf->dev,
  1052. "out of memory (read bufs usb_alloc_coherent)\n");
  1053. goto alloc_fail7;
  1054. }
  1055. }
  1056. for (i = 0; i < ACM_NW; i++) {
  1057. struct acm_wb *snd = &(acm->wb[i]);
  1058. snd->urb = usb_alloc_urb(0, GFP_KERNEL);
  1059. if (snd->urb == NULL) {
  1060. dev_dbg(&intf->dev,
  1061. "out of memory (write urbs usb_alloc_urb)");
  1062. goto alloc_fail8;
  1063. }
  1064. if (usb_endpoint_xfer_int(epwrite))
  1065. usb_fill_int_urb(snd->urb, usb_dev,
  1066. usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
  1067. NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval);
  1068. else
  1069. usb_fill_bulk_urb(snd->urb, usb_dev,
  1070. usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
  1071. NULL, acm->writesize, acm_write_bulk, snd);
  1072. snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1073. snd->instance = acm;
  1074. }
  1075. usb_set_intfdata(intf, acm);
  1076. i = device_create_file(&intf->dev, &dev_attr_bmCapabilities);
  1077. if (i < 0)
  1078. goto alloc_fail8;
  1079. if (cfd) { /* export the country data */
  1080. acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL);
  1081. if (!acm->country_codes)
  1082. goto skip_countries;
  1083. acm->country_code_size = cfd->bLength - 4;
  1084. memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0,
  1085. cfd->bLength - 4);
  1086. acm->country_rel_date = cfd->iCountryCodeRelDate;
  1087. i = device_create_file(&intf->dev, &dev_attr_wCountryCodes);
  1088. if (i < 0) {
  1089. kfree(acm->country_codes);
  1090. goto skip_countries;
  1091. }
  1092. i = device_create_file(&intf->dev,
  1093. &dev_attr_iCountryCodeRelDate);
  1094. if (i < 0) {
  1095. device_remove_file(&intf->dev, &dev_attr_wCountryCodes);
  1096. kfree(acm->country_codes);
  1097. goto skip_countries;
  1098. }
  1099. }
  1100. skip_countries:
  1101. usb_fill_int_urb(acm->ctrlurb, usb_dev,
  1102. usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress),
  1103. acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm,
  1104. /* works around buggy devices */
  1105. epctrl->bInterval ? epctrl->bInterval : 0xff);
  1106. acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  1107. acm->ctrlurb->transfer_dma = acm->ctrl_dma;
  1108. dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor);
  1109. acm_set_control(acm, acm->ctrlout);
  1110. acm->line.dwDTERate = cpu_to_le32(9600);
  1111. acm->line.bDataBits = 8;
  1112. acm_set_line(acm, &acm->line);
  1113. usb_driver_claim_interface(&acm_driver, data_interface, acm);
  1114. usb_set_intfdata(data_interface, acm);
  1115. usb_get_intf(control_interface);
  1116. tty_register_device(acm_tty_driver, minor, &control_interface->dev);
  1117. acm_table[minor] = acm;
  1118. return 0;
  1119. alloc_fail8:
  1120. for (i = 0; i < ACM_NW; i++)
  1121. usb_free_urb(acm->wb[i].urb);
  1122. alloc_fail7:
  1123. acm_read_buffers_free(acm);
  1124. alloc_fail6:
  1125. for (i = 0; i < num_rx_buf; i++)
  1126. usb_free_urb(acm->ru[i].urb);
  1127. usb_free_urb(acm->ctrlurb);
  1128. alloc_fail5:
  1129. acm_write_buffers_free(acm);
  1130. alloc_fail4:
  1131. usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma);
  1132. alloc_fail2:
  1133. kfree(acm);
  1134. alloc_fail:
  1135. return -ENOMEM;
  1136. }
  1137. static void stop_data_traffic(struct acm *acm)
  1138. {
  1139. int i;
  1140. dbg("Entering stop_data_traffic");
  1141. tasklet_disable(&acm->urb_task);
  1142. usb_kill_urb(acm->ctrlurb);
  1143. for (i = 0; i < ACM_NW; i++)
  1144. usb_kill_urb(acm->wb[i].urb);
  1145. for (i = 0; i < acm->rx_buflimit; i++)
  1146. usb_kill_urb(acm->ru[i].urb);
  1147. tasklet_enable(&acm->urb_task);
  1148. cancel_work_sync(&acm->work);
  1149. }
  1150. static void acm_disconnect(struct usb_interface *intf)
  1151. {
  1152. struct acm *acm = usb_get_intfdata(intf);
  1153. struct usb_device *usb_dev = interface_to_usbdev(intf);
  1154. struct tty_struct *tty;
  1155. /* sibling interface is already cleaning up */
  1156. if (!acm)
  1157. return;
  1158. mutex_lock(&open_mutex);
  1159. if (acm->country_codes) {
  1160. device_remove_file(&acm->control->dev,
  1161. &dev_attr_wCountryCodes);
  1162. device_remove_file(&acm->control->dev,
  1163. &dev_attr_iCountryCodeRelDate);
  1164. }
  1165. device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities);
  1166. acm->dev = NULL;
  1167. usb_set_intfdata(acm->control, NULL);
  1168. usb_set_intfdata(acm->data, NULL);
  1169. stop_data_traffic(acm);
  1170. acm_write_buffers_free(acm);
  1171. usb_free_coherent(usb_dev, acm->ctrlsize, acm->ctrl_buffer,
  1172. acm->ctrl_dma);
  1173. acm_read_buffers_free(acm);
  1174. if (!acm->combined_interfaces)
  1175. usb_driver_release_interface(&acm_driver, intf == acm->control ?
  1176. acm->data : acm->control);
  1177. if (acm->port.count == 0) {
  1178. acm_tty_unregister(acm);
  1179. mutex_unlock(&open_mutex);
  1180. return;
  1181. }
  1182. mutex_unlock(&open_mutex);
  1183. tty = tty_port_tty_get(&acm->port);
  1184. if (tty) {
  1185. tty_hangup(tty);
  1186. tty_kref_put(tty);
  1187. }
  1188. }
  1189. #ifdef CONFIG_PM
  1190. static int acm_suspend(struct usb_interface *intf, pm_message_t message)
  1191. {
  1192. struct acm *acm = usb_get_intfdata(intf);
  1193. int cnt;
  1194. if (message.event & PM_EVENT_AUTO) {
  1195. int b;
  1196. spin_lock_irq(&acm->read_lock);
  1197. spin_lock(&acm->write_lock);
  1198. b = acm->processing + acm->transmitting;
  1199. spin_unlock(&acm->write_lock);
  1200. spin_unlock_irq(&acm->read_lock);
  1201. if (b)
  1202. return -EBUSY;
  1203. }
  1204. spin_lock_irq(&acm->read_lock);
  1205. spin_lock(&acm->write_lock);
  1206. cnt = acm->susp_count++;
  1207. spin_unlock(&acm->write_lock);
  1208. spin_unlock_irq(&acm->read_lock);
  1209. if (cnt)
  1210. return 0;
  1211. /*
  1212. we treat opened interfaces differently,
  1213. we must guard against open
  1214. */
  1215. mutex_lock(&acm->mutex);
  1216. if (acm->port.count)
  1217. stop_data_traffic(acm);
  1218. mutex_unlock(&acm->mutex);
  1219. return 0;
  1220. }
  1221. static int acm_resume(struct usb_interface *intf)
  1222. {
  1223. struct acm *acm = usb_get_intfdata(intf);
  1224. struct acm_wb *wb;
  1225. int rv = 0;
  1226. int cnt;
  1227. spin_lock_irq(&acm->read_lock);
  1228. acm->susp_count -= 1;
  1229. cnt = acm->susp_count;
  1230. spin_unlock_irq(&acm->read_lock);
  1231. if (cnt)
  1232. return 0;
  1233. mutex_lock(&acm->mutex);
  1234. if (acm->port.count) {
  1235. rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO);
  1236. spin_lock_irq(&acm->write_lock);
  1237. if (acm->delayed_wb) {
  1238. wb = acm->delayed_wb;
  1239. acm->delayed_wb = NULL;
  1240. spin_unlock_irq(&acm->write_lock);
  1241. acm_start_wb(acm, wb);
  1242. } else {
  1243. spin_unlock_irq(&acm->write_lock);
  1244. }
  1245. /*
  1246. * delayed error checking because we must
  1247. * do the write path at all cost
  1248. */
  1249. if (rv < 0)
  1250. goto err_out;
  1251. tasklet_schedule(&acm->urb_task);
  1252. }
  1253. err_out:
  1254. mutex_unlock(&acm->mutex);
  1255. return rv;
  1256. }
  1257. static int acm_reset_resume(struct usb_interface *intf)
  1258. {
  1259. struct acm *acm = usb_get_intfdata(intf);
  1260. struct tty_struct *tty;
  1261. mutex_lock(&acm->mutex);
  1262. if (acm->port.count) {
  1263. tty = tty_port_tty_get(&acm->port);
  1264. if (tty) {
  1265. tty_hangup(tty);
  1266. tty_kref_put(tty);
  1267. }
  1268. }
  1269. mutex_unlock(&acm->mutex);
  1270. return acm_resume(intf);
  1271. }
  1272. #endif /* CONFIG_PM */
  1273. #define NOKIA_PCSUITE_ACM_INFO(x) \
  1274. USB_DEVICE_AND_INTERFACE_INFO(0x0421, x, \
  1275. USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \
  1276. USB_CDC_ACM_PROTO_VENDOR)
  1277. #define SAMSUNG_PCSUITE_ACM_INFO(x) \
  1278. USB_DEVICE_AND_INTERFACE_INFO(0x04e7, x, \
  1279. USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, \
  1280. USB_CDC_ACM_PROTO_VENDOR)
  1281. /*
  1282. * USB driver structure.
  1283. */
  1284. static const struct usb_device_id acm_ids[] = {
  1285. /* quirky and broken devices */
  1286. { USB_DEVICE(0x0870, 0x0001), /* Metricom GS Modem */
  1287. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1288. },
  1289. { USB_DEVICE(0x0e8d, 0x0003), /* FIREFLY, MediaTek Inc; andrey.arapov@gmail.com */
  1290. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1291. },
  1292. { USB_DEVICE(0x0e8d, 0x3329), /* MediaTek Inc GPS */
  1293. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1294. },
  1295. { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
  1296. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1297. },
  1298. { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */
  1299. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1300. },
  1301. { USB_DEVICE(0x0ace, 0x1602), /* ZyDAS 56K USB MODEM */
  1302. .driver_info = SINGLE_RX_URB,
  1303. },
  1304. { USB_DEVICE(0x0ace, 0x1608), /* ZyDAS 56K USB MODEM */
  1305. .driver_info = SINGLE_RX_URB, /* firmware bug */
  1306. },
  1307. { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
  1308. .driver_info = SINGLE_RX_URB, /* firmware bug */
  1309. },
  1310. { USB_DEVICE(0x22b8, 0x7000), /* Motorola Q Phone */
  1311. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1312. },
  1313. { USB_DEVICE(0x0803, 0x3095), /* Zoom Telephonics Model 3095F USB MODEM */
  1314. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1315. },
  1316. { USB_DEVICE(0x0572, 0x1321), /* Conexant USB MODEM CX93010 */
  1317. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1318. },
  1319. { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */
  1320. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1321. },
  1322. { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */
  1323. .driver_info = NO_UNION_NORMAL, /* has no union descriptor */
  1324. },
  1325. { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */
  1326. },
  1327. { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */
  1328. .driver_info = NO_UNION_NORMAL, /* union descriptor misplaced on
  1329. data interface instead of
  1330. communications interface.
  1331. Maybe we should define a new
  1332. quirk for this. */
  1333. },
  1334. { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */
  1335. .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
  1336. },
  1337. { USB_DEVICE(0x1576, 0x03b1), /* Maretron USB100 */
  1338. .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
  1339. },
  1340. /* Nokia S60 phones expose two ACM channels. The first is
  1341. * a modem and is picked up by the standard AT-command
  1342. * information below. The second is 'vendor-specific' but
  1343. * is treated as a serial device at the S60 end, so we want
  1344. * to expose it on Linux too. */
  1345. { NOKIA_PCSUITE_ACM_INFO(0x042D), }, /* Nokia 3250 */
  1346. { NOKIA_PCSUITE_ACM_INFO(0x04D8), }, /* Nokia 5500 Sport */
  1347. { NOKIA_PCSUITE_ACM_INFO(0x04C9), }, /* Nokia E50 */
  1348. { NOKIA_PCSUITE_ACM_INFO(0x0419), }, /* Nokia E60 */
  1349. { NOKIA_PCSUITE_ACM_INFO(0x044D), }, /* Nokia E61 */
  1350. { NOKIA_PCSUITE_ACM_INFO(0x0001), }, /* Nokia E61i */
  1351. { NOKIA_PCSUITE_ACM_INFO(0x0475), }, /* Nokia E62 */
  1352. { NOKIA_PCSUITE_ACM_INFO(0x0508), }, /* Nokia E65 */
  1353. { NOKIA_PCSUITE_ACM_INFO(0x0418), }, /* Nokia E70 */
  1354. { NOKIA_PCSUITE_ACM_INFO(0x0425), }, /* Nokia N71 */
  1355. { NOKIA_PCSUITE_ACM_INFO(0x0486), }, /* Nokia N73 */
  1356. { NOKIA_PCSUITE_ACM_INFO(0x04DF), }, /* Nokia N75 */
  1357. { NOKIA_PCSUITE_ACM_INFO(0x000e), }, /* Nokia N77 */
  1358. { NOKIA_PCSUITE_ACM_INFO(0x0445), }, /* Nokia N80 */
  1359. { NOKIA_PCSUITE_ACM_INFO(0x042F), }, /* Nokia N91 & N91 8GB */
  1360. { NOKIA_PCSUITE_ACM_INFO(0x048E), }, /* Nokia N92 */
  1361. { NOKIA_PCSUITE_ACM_INFO(0x0420), }, /* Nokia N93 */
  1362. { NOKIA_PCSUITE_ACM_INFO(0x04E6), }, /* Nokia N93i */
  1363. { NOKIA_PCSUITE_ACM_INFO(0x04B2), }, /* Nokia 5700 XpressMusic */
  1364. { NOKIA_PCSUITE_ACM_INFO(0x0134), }, /* Nokia 6110 Navigator (China) */
  1365. { NOKIA_PCSUITE_ACM_INFO(0x046E), }, /* Nokia 6110 Navigator */
  1366. { NOKIA_PCSUITE_ACM_INFO(0x002f), }, /* Nokia 6120 classic & */
  1367. { NOKIA_PCSUITE_ACM_INFO(0x0088), }, /* Nokia 6121 classic */
  1368. { NOKIA_PCSUITE_ACM_INFO(0x00fc), }, /* Nokia 6124 classic */
  1369. { NOKIA_PCSUITE_ACM_INFO(0x0042), }, /* Nokia E51 */
  1370. { NOKIA_PCSUITE_ACM_INFO(0x00b0), }, /* Nokia E66 */
  1371. { NOKIA_PCSUITE_ACM_INFO(0x00ab), }, /* Nokia E71 */
  1372. { NOKIA_PCSUITE_ACM_INFO(0x0481), }, /* Nokia N76 */
  1373. { NOKIA_PCSUITE_ACM_INFO(0x0007), }, /* Nokia N81 & N81 8GB */
  1374. { NOKIA_PCSUITE_ACM_INFO(0x0071), }, /* Nokia N82 */
  1375. { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */
  1376. { NOKIA_PCSUITE_ACM_INFO(0x0070), }, /* Nokia N95 8GB */
  1377. { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
  1378. { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */
  1379. { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */
  1380. { NOKIA_PCSUITE_ACM_INFO(0x008f), }, /* Nokia 6220 Classic */
  1381. { NOKIA_PCSUITE_ACM_INFO(0x00a0), }, /* Nokia 6650 */
  1382. { NOKIA_PCSUITE_ACM_INFO(0x007b), }, /* Nokia N78 */
  1383. { NOKIA_PCSUITE_ACM_INFO(0x0094), }, /* Nokia N85 */
  1384. { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */
  1385. { NOKIA_PCSUITE_ACM_INFO(0x00e9), }, /* Nokia 5320 XpressMusic */
  1386. { NOKIA_PCSUITE_ACM_INFO(0x0108), }, /* Nokia 5320 XpressMusic 2G */
  1387. { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */
  1388. { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */
  1389. { NOKIA_PCSUITE_ACM_INFO(0x0178), }, /* Nokia E63 */
  1390. { NOKIA_PCSUITE_ACM_INFO(0x010e), }, /* Nokia E75 */
  1391. { NOKIA_PCSUITE_ACM_INFO(0x02d9), }, /* Nokia 6760 Slide */
  1392. { NOKIA_PCSUITE_ACM_INFO(0x01d0), }, /* Nokia E52 */
  1393. { NOKIA_PCSUITE_ACM_INFO(0x0223), }, /* Nokia E72 */
  1394. { NOKIA_PCSUITE_ACM_INFO(0x0275), }, /* Nokia X6 */
  1395. { NOKIA_PCSUITE_ACM_INFO(0x026c), }, /* Nokia N97 Mini */
  1396. { NOKIA_PCSUITE_ACM_INFO(0x0154), }, /* Nokia 5800 XpressMusic */
  1397. { NOKIA_PCSUITE_ACM_INFO(0x04ce), }, /* Nokia E90 */
  1398. { NOKIA_PCSUITE_ACM_INFO(0x01d4), }, /* Nokia E55 */
  1399. { NOKIA_PCSUITE_ACM_INFO(0x0302), }, /* Nokia N8 */
  1400. { SAMSUNG_PCSUITE_ACM_INFO(0x6651), }, /* Samsung GTi8510 (INNOV8) */
  1401. /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
  1402. /* Support Lego NXT using pbLua firmware */
  1403. { USB_DEVICE(0x0694, 0xff00),
  1404. .driver_info = NOT_A_MODEM,
  1405. },
  1406. /* control interfaces without any protocol set */
  1407. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1408. USB_CDC_PROTO_NONE) },
  1409. /* control interfaces with various AT-command sets */
  1410. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1411. USB_CDC_ACM_PROTO_AT_V25TER) },
  1412. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1413. USB_CDC_ACM_PROTO_AT_PCCA101) },
  1414. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1415. USB_CDC_ACM_PROTO_AT_PCCA101_WAKE) },
  1416. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1417. USB_CDC_ACM_PROTO_AT_GSM) },
  1418. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1419. USB_CDC_ACM_PROTO_AT_3G) },
  1420. { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
  1421. USB_CDC_ACM_PROTO_AT_CDMA) },
  1422. { }
  1423. };
  1424. MODULE_DEVICE_TABLE(usb, acm_ids);
  1425. static struct usb_driver acm_driver = {
  1426. .name = "cdc_acm",
  1427. .probe = acm_probe,
  1428. .disconnect = acm_disconnect,
  1429. #ifdef CONFIG_PM
  1430. .suspend = acm_suspend,
  1431. .resume = acm_resume,
  1432. .reset_resume = acm_reset_resume,
  1433. #endif
  1434. .id_table = acm_ids,
  1435. #ifdef CONFIG_PM
  1436. .supports_autosuspend = 1,
  1437. #endif
  1438. };
  1439. /*
  1440. * TTY driver structures.
  1441. */
  1442. static const struct tty_operations acm_ops = {
  1443. .open = acm_tty_open,
  1444. .close = acm_tty_close,
  1445. .hangup = acm_tty_hangup,
  1446. .write = acm_tty_write,
  1447. .write_room = acm_tty_write_room,
  1448. .ioctl = acm_tty_ioctl,
  1449. .throttle = acm_tty_throttle,
  1450. .unthrottle = acm_tty_unthrottle,
  1451. .chars_in_buffer = acm_tty_chars_in_buffer,
  1452. .break_ctl = acm_tty_break_ctl,
  1453. .set_termios = acm_tty_set_termios,
  1454. .tiocmget = acm_tty_tiocmget,
  1455. .tiocmset = acm_tty_tiocmset,
  1456. };
  1457. /*
  1458. * Init / exit.
  1459. */
  1460. static int __init acm_init(void)
  1461. {
  1462. int retval;
  1463. acm_tty_driver = alloc_tty_driver(ACM_TTY_MINORS);
  1464. if (!acm_tty_driver)
  1465. return -ENOMEM;
  1466. acm_tty_driver->owner = THIS_MODULE,
  1467. acm_tty_driver->driver_name = "acm",
  1468. acm_tty_driver->name = "ttyACM",
  1469. acm_tty_driver->major = ACM_TTY_MAJOR,
  1470. acm_tty_driver->minor_start = 0,
  1471. acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL,
  1472. acm_tty_driver->subtype = SERIAL_TYPE_NORMAL,
  1473. acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  1474. acm_tty_driver->init_termios = tty_std_termios;
  1475. acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD |
  1476. HUPCL | CLOCAL;
  1477. tty_set_operations(acm_tty_driver, &acm_ops);
  1478. retval = tty_register_driver(acm_tty_driver);
  1479. if (retval) {
  1480. put_tty_driver(acm_tty_driver);
  1481. return retval;
  1482. }
  1483. retval = usb_register(&acm_driver);
  1484. if (retval) {
  1485. tty_unregister_driver(acm_tty_driver);
  1486. put_tty_driver(acm_tty_driver);
  1487. return retval;
  1488. }
  1489. printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
  1490. DRIVER_DESC "\n");
  1491. return 0;
  1492. }
  1493. static void __exit acm_exit(void)
  1494. {
  1495. usb_deregister(&acm_driver);
  1496. tty_unregister_driver(acm_tty_driver);
  1497. put_tty_driver(acm_tty_driver);
  1498. }
  1499. module_init(acm_init);
  1500. module_exit(acm_exit);
  1501. MODULE_AUTHOR(DRIVER_AUTHOR);
  1502. MODULE_DESCRIPTION(DRIVER_DESC);
  1503. MODULE_LICENSE("GPL");
  1504. MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR);