bas-gigaset.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313
  1. /*
  2. * USB driver for Gigaset 307x base via direct USB connection.
  3. *
  4. * Copyright (c) 2001 by Hansjoerg Lipp <hjlipp@web.de>,
  5. * Tilman Schmidt <tilman@imap.cc>,
  6. * Stefan Eilers.
  7. *
  8. * Based on usb-gigaset.c.
  9. *
  10. * =====================================================================
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. * =====================================================================
  16. */
  17. #include "gigaset.h"
  18. #include <linux/errno.h>
  19. #include <linux/init.h>
  20. #include <linux/slab.h>
  21. #include <linux/timer.h>
  22. #include <linux/usb.h>
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. /* Version Information */
  26. #define DRIVER_AUTHOR "Tilman Schmidt <tilman@imap.cc>, Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers"
  27. #define DRIVER_DESC "USB Driver for Gigaset 307x"
  28. /* Module parameters */
  29. static int startmode = SM_ISDN;
  30. static int cidmode = 1;
  31. module_param(startmode, int, S_IRUGO);
  32. module_param(cidmode, int, S_IRUGO);
  33. MODULE_PARM_DESC(startmode, "start in isdn4linux mode");
  34. MODULE_PARM_DESC(cidmode, "Call-ID mode");
  35. #define GIGASET_MINORS 1
  36. #define GIGASET_MINOR 16
  37. #define GIGASET_MODULENAME "bas_gigaset"
  38. #define GIGASET_DEVFSNAME "gig/bas/"
  39. #define GIGASET_DEVNAME "ttyGB"
  40. #define IF_WRITEBUF 256 //FIXME
  41. /* Values for the Gigaset 307x */
  42. #define USB_GIGA_VENDOR_ID 0x0681
  43. #define USB_GIGA_PRODUCT_ID 0x0001
  44. #define USB_4175_PRODUCT_ID 0x0002
  45. #define USB_SX303_PRODUCT_ID 0x0021
  46. #define USB_SX353_PRODUCT_ID 0x0022
  47. /* table of devices that work with this driver */
  48. static struct usb_device_id gigaset_table [] = {
  49. { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_GIGA_PRODUCT_ID) },
  50. { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_4175_PRODUCT_ID) },
  51. { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX303_PRODUCT_ID) },
  52. { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX353_PRODUCT_ID) },
  53. { } /* Terminating entry */
  54. };
  55. MODULE_DEVICE_TABLE(usb, gigaset_table);
  56. /*======================= local function prototypes =============================*/
  57. /* This function is called if a new device is connected to the USB port. It
  58. * checks whether this new device belongs to this driver.
  59. */
  60. static int gigaset_probe(struct usb_interface *interface,
  61. const struct usb_device_id *id);
  62. /* Function will be called if the device is unplugged */
  63. static void gigaset_disconnect(struct usb_interface *interface);
  64. /*==============================================================================*/
  65. struct bas_cardstate {
  66. struct usb_device *udev; /* USB device pointer */
  67. struct usb_interface *interface; /* interface for this device */
  68. unsigned char minor; /* starting minor number */
  69. struct urb *urb_ctrl; /* control pipe default URB */
  70. struct usb_ctrlrequest dr_ctrl;
  71. struct timer_list timer_ctrl; /* control request timeout */
  72. struct timer_list timer_atrdy; /* AT command ready timeout */
  73. struct urb *urb_cmd_out; /* for sending AT commands */
  74. struct usb_ctrlrequest dr_cmd_out;
  75. int retry_cmd_out;
  76. struct urb *urb_cmd_in; /* for receiving AT replies */
  77. struct usb_ctrlrequest dr_cmd_in;
  78. struct timer_list timer_cmd_in; /* receive request timeout */
  79. unsigned char *rcvbuf; /* AT reply receive buffer */
  80. struct urb *urb_int_in; /* URB for interrupt pipe */
  81. unsigned char int_in_buf[3];
  82. spinlock_t lock; /* locks all following */
  83. atomic_t basstate; /* bitmap (BS_*) */
  84. int pending; /* uncompleted base request */
  85. int rcvbuf_size; /* size of AT receive buffer */
  86. /* 0: no receive in progress */
  87. int retry_cmd_in; /* receive req retry count */
  88. };
  89. /* status of direct USB connection to 307x base (bits in basstate) */
  90. #define BS_ATOPEN 0x001
  91. #define BS_B1OPEN 0x002
  92. #define BS_B2OPEN 0x004
  93. #define BS_ATREADY 0x008
  94. #define BS_INIT 0x010
  95. #define BS_ATTIMER 0x020
  96. static struct gigaset_driver *driver = NULL;
  97. static struct cardstate *cardstate = NULL;
  98. /* usb specific object needed to register this driver with the usb subsystem */
  99. static struct usb_driver gigaset_usb_driver = {
  100. .name = GIGASET_MODULENAME,
  101. .probe = gigaset_probe,
  102. .disconnect = gigaset_disconnect,
  103. .id_table = gigaset_table,
  104. };
  105. /* get message text for USB status code
  106. */
  107. static char *get_usb_statmsg(int status)
  108. {
  109. static char unkmsg[28];
  110. switch (status) {
  111. case 0:
  112. return "success";
  113. case -ENOENT:
  114. return "canceled";
  115. case -ECONNRESET:
  116. return "canceled (async)";
  117. case -EINPROGRESS:
  118. return "pending";
  119. case -EPROTO:
  120. return "bit stuffing or unknown USB error";
  121. case -EILSEQ:
  122. return "Illegal byte sequence (CRC mismatch)";
  123. case -EPIPE:
  124. return "babble detect or endpoint stalled";
  125. case -ENOSR:
  126. return "buffer error";
  127. case -ETIMEDOUT:
  128. return "timed out";
  129. case -ENODEV:
  130. return "device not present";
  131. case -EREMOTEIO:
  132. return "short packet detected";
  133. case -EXDEV:
  134. return "partial isochronous transfer";
  135. case -EINVAL:
  136. return "invalid argument";
  137. case -ENXIO:
  138. return "URB already queued";
  139. case -EAGAIN:
  140. return "isochronous start frame too early or too much scheduled";
  141. case -EFBIG:
  142. return "too many isochronous frames requested";
  143. case -EMSGSIZE:
  144. return "endpoint message size zero";
  145. case -ESHUTDOWN:
  146. return "endpoint shutdown";
  147. case -EBUSY:
  148. return "another request pending";
  149. default:
  150. snprintf(unkmsg, sizeof(unkmsg), "unknown error %d", status);
  151. return unkmsg;
  152. }
  153. }
  154. /* usb_pipetype_str
  155. * retrieve string representation of USB pipe type
  156. */
  157. static inline char *usb_pipetype_str(int pipe)
  158. {
  159. if (usb_pipeisoc(pipe))
  160. return "Isoc";
  161. if (usb_pipeint(pipe))
  162. return "Int";
  163. if (usb_pipecontrol(pipe))
  164. return "Ctrl";
  165. if (usb_pipebulk(pipe))
  166. return "Bulk";
  167. return "?";
  168. }
  169. /* dump_urb
  170. * write content of URB to syslog for debugging
  171. */
  172. static inline void dump_urb(enum debuglevel level, const char *tag,
  173. struct urb *urb)
  174. {
  175. #ifdef CONFIG_GIGASET_DEBUG
  176. int i;
  177. gig_dbg(level, "%s urb(0x%08lx)->{", tag, (unsigned long) urb);
  178. if (urb) {
  179. gig_dbg(level,
  180. " dev=0x%08lx, pipe=%s:EP%d/DV%d:%s, "
  181. "status=%d, hcpriv=0x%08lx, transfer_flags=0x%x,",
  182. (unsigned long) urb->dev,
  183. usb_pipetype_str(urb->pipe),
  184. usb_pipeendpoint(urb->pipe), usb_pipedevice(urb->pipe),
  185. usb_pipein(urb->pipe) ? "in" : "out",
  186. urb->status, (unsigned long) urb->hcpriv,
  187. urb->transfer_flags);
  188. gig_dbg(level,
  189. " transfer_buffer=0x%08lx[%d], actual_length=%d, "
  190. "bandwidth=%d, setup_packet=0x%08lx,",
  191. (unsigned long) urb->transfer_buffer,
  192. urb->transfer_buffer_length, urb->actual_length,
  193. urb->bandwidth, (unsigned long) urb->setup_packet);
  194. gig_dbg(level,
  195. " start_frame=%d, number_of_packets=%d, interval=%d, "
  196. "error_count=%d,",
  197. urb->start_frame, urb->number_of_packets, urb->interval,
  198. urb->error_count);
  199. gig_dbg(level,
  200. " context=0x%08lx, complete=0x%08lx, "
  201. "iso_frame_desc[]={",
  202. (unsigned long) urb->context,
  203. (unsigned long) urb->complete);
  204. for (i = 0; i < urb->number_of_packets; i++) {
  205. struct usb_iso_packet_descriptor *pifd
  206. = &urb->iso_frame_desc[i];
  207. gig_dbg(level,
  208. " {offset=%u, length=%u, actual_length=%u, "
  209. "status=%u}",
  210. pifd->offset, pifd->length, pifd->actual_length,
  211. pifd->status);
  212. }
  213. }
  214. gig_dbg(level, "}}");
  215. #endif
  216. }
  217. /* read/set modem control bits etc. (m10x only) */
  218. static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
  219. unsigned new_state)
  220. {
  221. return -EINVAL;
  222. }
  223. static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
  224. {
  225. return -EINVAL;
  226. }
  227. static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
  228. {
  229. return -EINVAL;
  230. }
  231. /* error_hangup
  232. * hang up any existing connection because of an unrecoverable error
  233. * This function may be called from any context and takes care of scheduling
  234. * the necessary actions for execution outside of interrupt context.
  235. * argument:
  236. * B channel control structure
  237. */
  238. static inline void error_hangup(struct bc_state *bcs)
  239. {
  240. struct cardstate *cs = bcs->cs;
  241. gig_dbg(DEBUG_ANY, "%s: scheduling HUP for channel %d",
  242. __func__, bcs->channel);
  243. if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
  244. //FIXME what should we do?
  245. return;
  246. }
  247. gigaset_schedule_event(cs);
  248. }
  249. /* error_reset
  250. * reset Gigaset device because of an unrecoverable error
  251. * This function may be called from any context and takes care of scheduling
  252. * the necessary actions for execution outside of interrupt context.
  253. * argument:
  254. * controller state structure
  255. */
  256. static inline void error_reset(struct cardstate *cs)
  257. {
  258. //FIXME try to recover without bothering the user
  259. dev_err(cs->dev,
  260. "unrecoverable error - please disconnect Gigaset base to reset\n");
  261. }
  262. /* check_pending
  263. * check for completion of pending control request
  264. * parameter:
  265. * ucs hardware specific controller state structure
  266. */
  267. static void check_pending(struct bas_cardstate *ucs)
  268. {
  269. unsigned long flags;
  270. spin_lock_irqsave(&ucs->lock, flags);
  271. switch (ucs->pending) {
  272. case 0:
  273. break;
  274. case HD_OPEN_ATCHANNEL:
  275. if (atomic_read(&ucs->basstate) & BS_ATOPEN)
  276. ucs->pending = 0;
  277. break;
  278. case HD_OPEN_B1CHANNEL:
  279. if (atomic_read(&ucs->basstate) & BS_B1OPEN)
  280. ucs->pending = 0;
  281. break;
  282. case HD_OPEN_B2CHANNEL:
  283. if (atomic_read(&ucs->basstate) & BS_B2OPEN)
  284. ucs->pending = 0;
  285. break;
  286. case HD_CLOSE_ATCHANNEL:
  287. if (!(atomic_read(&ucs->basstate) & BS_ATOPEN))
  288. ucs->pending = 0;
  289. break;
  290. case HD_CLOSE_B1CHANNEL:
  291. if (!(atomic_read(&ucs->basstate) & BS_B1OPEN))
  292. ucs->pending = 0;
  293. break;
  294. case HD_CLOSE_B2CHANNEL:
  295. if (!(atomic_read(&ucs->basstate) & BS_B2OPEN))
  296. ucs->pending = 0;
  297. break;
  298. case HD_DEVICE_INIT_ACK: /* no reply expected */
  299. ucs->pending = 0;
  300. break;
  301. /* HD_READ_ATMESSAGE, HD_WRITE_ATMESSAGE, HD_RESET_INTERRUPTPIPE
  302. * are handled separately and should never end up here
  303. */
  304. default:
  305. dev_warn(&ucs->interface->dev,
  306. "unknown pending request 0x%02x cleared\n",
  307. ucs->pending);
  308. ucs->pending = 0;
  309. }
  310. if (!ucs->pending)
  311. del_timer(&ucs->timer_ctrl);
  312. spin_unlock_irqrestore(&ucs->lock, flags);
  313. }
  314. /* cmd_in_timeout
  315. * timeout routine for command input request
  316. * argument:
  317. * controller state structure
  318. */
  319. static void cmd_in_timeout(unsigned long data)
  320. {
  321. struct cardstate *cs = (struct cardstate *) data;
  322. struct bas_cardstate *ucs = cs->hw.bas;
  323. unsigned long flags;
  324. spin_lock_irqsave(&cs->lock, flags);
  325. if (unlikely(!cs->connected)) {
  326. gig_dbg(DEBUG_USBREQ, "%s: disconnected", __func__);
  327. spin_unlock_irqrestore(&cs->lock, flags);
  328. return;
  329. }
  330. if (!ucs->rcvbuf_size) {
  331. gig_dbg(DEBUG_USBREQ, "%s: no receive in progress", __func__);
  332. spin_unlock_irqrestore(&cs->lock, flags);
  333. return;
  334. }
  335. spin_unlock_irqrestore(&cs->lock, flags);
  336. dev_err(cs->dev, "timeout reading AT response\n");
  337. error_reset(cs); //FIXME retry?
  338. }
  339. static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs);
  340. /* atread_submit
  341. * submit an HD_READ_ATMESSAGE command URB
  342. * parameters:
  343. * cs controller state structure
  344. * timeout timeout in 1/10 sec., 0: none
  345. * return value:
  346. * 0 on success
  347. * -EINVAL if a NULL pointer is encountered somewhere
  348. * -EBUSY if another request is pending
  349. * any URB submission error code
  350. */
  351. static int atread_submit(struct cardstate *cs, int timeout)
  352. {
  353. struct bas_cardstate *ucs = cs->hw.bas;
  354. int ret;
  355. gig_dbg(DEBUG_USBREQ, "-------> HD_READ_ATMESSAGE (%d)",
  356. ucs->rcvbuf_size);
  357. if (ucs->urb_cmd_in->status == -EINPROGRESS) {
  358. dev_err(cs->dev,
  359. "could not submit HD_READ_ATMESSAGE: URB busy\n");
  360. return -EBUSY;
  361. }
  362. ucs->dr_cmd_in.bRequestType = IN_VENDOR_REQ;
  363. ucs->dr_cmd_in.bRequest = HD_READ_ATMESSAGE;
  364. ucs->dr_cmd_in.wValue = 0;
  365. ucs->dr_cmd_in.wIndex = 0;
  366. ucs->dr_cmd_in.wLength = cpu_to_le16(ucs->rcvbuf_size);
  367. usb_fill_control_urb(ucs->urb_cmd_in, ucs->udev,
  368. usb_rcvctrlpipe(ucs->udev, 0),
  369. (unsigned char*) & ucs->dr_cmd_in,
  370. ucs->rcvbuf, ucs->rcvbuf_size,
  371. read_ctrl_callback, cs->inbuf);
  372. if ((ret = usb_submit_urb(ucs->urb_cmd_in, SLAB_ATOMIC)) != 0) {
  373. dev_err(cs->dev, "could not submit HD_READ_ATMESSAGE: %s\n",
  374. get_usb_statmsg(ret));
  375. return ret;
  376. }
  377. if (timeout > 0) {
  378. gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
  379. ucs->timer_cmd_in.expires = jiffies + timeout * HZ / 10;
  380. ucs->timer_cmd_in.data = (unsigned long) cs;
  381. ucs->timer_cmd_in.function = cmd_in_timeout;
  382. add_timer(&ucs->timer_cmd_in);
  383. }
  384. return 0;
  385. }
  386. static void stopurbs(struct bas_bc_state *);
  387. static int start_cbsend(struct cardstate *);
  388. /* set/clear bits in base connection state
  389. */
  390. inline static void update_basstate(struct bas_cardstate *ucs,
  391. int set, int clear)
  392. {
  393. unsigned long flags;
  394. int state;
  395. spin_lock_irqsave(&ucs->lock, flags);
  396. state = atomic_read(&ucs->basstate);
  397. state &= ~clear;
  398. state |= set;
  399. atomic_set(&ucs->basstate, state);
  400. spin_unlock_irqrestore(&ucs->lock, flags);
  401. }
  402. /* read_int_callback
  403. * USB completion handler for interrupt pipe input
  404. * called by the USB subsystem in interrupt context
  405. * parameter:
  406. * urb USB request block
  407. * urb->context = controller state structure
  408. */
  409. static void read_int_callback(struct urb *urb, struct pt_regs *regs)
  410. {
  411. struct cardstate *cs = urb->context;
  412. struct bas_cardstate *ucs = cs->hw.bas;
  413. struct bc_state *bcs;
  414. unsigned long flags;
  415. int status;
  416. unsigned l;
  417. int channel;
  418. switch (urb->status) {
  419. case 0: /* success */
  420. break;
  421. case -ENOENT: /* canceled */
  422. case -ECONNRESET: /* canceled (async) */
  423. case -EINPROGRESS: /* pending */
  424. /* ignore silently */
  425. gig_dbg(DEBUG_USBREQ, "%s: %s",
  426. __func__, get_usb_statmsg(urb->status));
  427. return;
  428. default: /* severe trouble */
  429. dev_warn(cs->dev, "interrupt read: %s\n",
  430. get_usb_statmsg(urb->status));
  431. //FIXME corrective action? resubmission always ok?
  432. goto resubmit;
  433. }
  434. l = (unsigned) ucs->int_in_buf[1] +
  435. (((unsigned) ucs->int_in_buf[2]) << 8);
  436. gig_dbg(DEBUG_USBREQ, "<-------%d: 0x%02x (%u [0x%02x 0x%02x])",
  437. urb->actual_length, (int)ucs->int_in_buf[0], l,
  438. (int)ucs->int_in_buf[1], (int)ucs->int_in_buf[2]);
  439. channel = 0;
  440. switch (ucs->int_in_buf[0]) {
  441. case HD_DEVICE_INIT_OK:
  442. update_basstate(ucs, BS_INIT, 0);
  443. break;
  444. case HD_READY_SEND_ATDATA:
  445. del_timer(&ucs->timer_atrdy);
  446. update_basstate(ucs, BS_ATREADY, BS_ATTIMER);
  447. start_cbsend(cs);
  448. break;
  449. case HD_OPEN_B2CHANNEL_ACK:
  450. ++channel;
  451. case HD_OPEN_B1CHANNEL_ACK:
  452. bcs = cs->bcs + channel;
  453. update_basstate(ucs, BS_B1OPEN << channel, 0);
  454. gigaset_bchannel_up(bcs);
  455. break;
  456. case HD_OPEN_ATCHANNEL_ACK:
  457. update_basstate(ucs, BS_ATOPEN, 0);
  458. start_cbsend(cs);
  459. break;
  460. case HD_CLOSE_B2CHANNEL_ACK:
  461. ++channel;
  462. case HD_CLOSE_B1CHANNEL_ACK:
  463. bcs = cs->bcs + channel;
  464. update_basstate(ucs, 0, BS_B1OPEN << channel);
  465. stopurbs(bcs->hw.bas);
  466. gigaset_bchannel_down(bcs);
  467. break;
  468. case HD_CLOSE_ATCHANNEL_ACK:
  469. update_basstate(ucs, 0, BS_ATOPEN);
  470. break;
  471. case HD_B2_FLOW_CONTROL:
  472. ++channel;
  473. case HD_B1_FLOW_CONTROL:
  474. bcs = cs->bcs + channel;
  475. atomic_add((l - BAS_NORMFRAME) * BAS_CORRFRAMES,
  476. &bcs->hw.bas->corrbytes);
  477. gig_dbg(DEBUG_ISO,
  478. "Flow control (channel %d, sub %d): 0x%02x => %d",
  479. channel, bcs->hw.bas->numsub, l,
  480. atomic_read(&bcs->hw.bas->corrbytes));
  481. break;
  482. case HD_RECEIVEATDATA_ACK: /* AT response ready to be received */
  483. if (!l) {
  484. dev_warn(cs->dev,
  485. "HD_RECEIVEATDATA_ACK with length 0 ignored\n");
  486. break;
  487. }
  488. spin_lock_irqsave(&cs->lock, flags);
  489. if (ucs->rcvbuf_size) {
  490. spin_unlock_irqrestore(&cs->lock, flags);
  491. dev_err(cs->dev,
  492. "receive AT data overrun, %d bytes lost\n", l);
  493. error_reset(cs); //FIXME reschedule
  494. break;
  495. }
  496. if ((ucs->rcvbuf = kmalloc(l, GFP_ATOMIC)) == NULL) {
  497. spin_unlock_irqrestore(&cs->lock, flags);
  498. dev_err(cs->dev, "out of memory, %d bytes lost\n", l);
  499. error_reset(cs); //FIXME reschedule
  500. break;
  501. }
  502. ucs->rcvbuf_size = l;
  503. ucs->retry_cmd_in = 0;
  504. if ((status = atread_submit(cs, BAS_TIMEOUT)) < 0) {
  505. kfree(ucs->rcvbuf);
  506. ucs->rcvbuf = NULL;
  507. ucs->rcvbuf_size = 0;
  508. error_reset(cs); //FIXME reschedule
  509. }
  510. spin_unlock_irqrestore(&cs->lock, flags);
  511. break;
  512. case HD_RESET_INTERRUPT_PIPE_ACK:
  513. gig_dbg(DEBUG_USBREQ, "HD_RESET_INTERRUPT_PIPE_ACK");
  514. break;
  515. case HD_SUSPEND_END:
  516. gig_dbg(DEBUG_USBREQ, "HD_SUSPEND_END");
  517. break;
  518. default:
  519. dev_warn(cs->dev,
  520. "unknown Gigaset signal 0x%02x (%u) ignored\n",
  521. (int) ucs->int_in_buf[0], l);
  522. }
  523. check_pending(ucs);
  524. resubmit:
  525. spin_lock_irqsave(&cs->lock, flags);
  526. status = cs->connected ? usb_submit_urb(urb, SLAB_ATOMIC) : -ENODEV;
  527. spin_unlock_irqrestore(&cs->lock, flags);
  528. if (unlikely(status)) {
  529. dev_err(cs->dev, "could not resubmit interrupt URB: %s\n",
  530. get_usb_statmsg(status));
  531. error_reset(cs);
  532. }
  533. }
  534. /* read_ctrl_callback
  535. * USB completion handler for control pipe input
  536. * called by the USB subsystem in interrupt context
  537. * parameter:
  538. * urb USB request block
  539. * urb->context = inbuf structure for controller state
  540. */
  541. static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
  542. {
  543. struct inbuf_t *inbuf = urb->context;
  544. struct cardstate *cs = inbuf->cs;
  545. struct bas_cardstate *ucs = cs->hw.bas;
  546. int have_data = 0;
  547. unsigned numbytes;
  548. unsigned long flags;
  549. spin_lock_irqsave(&cs->lock, flags);
  550. if (unlikely(!cs->connected)) {
  551. warn("%s: disconnected", __func__);
  552. spin_unlock_irqrestore(&cs->lock, flags);
  553. return;
  554. }
  555. if (!ucs->rcvbuf_size) {
  556. dev_warn(cs->dev, "%s: no receive in progress\n", __func__);
  557. spin_unlock_irqrestore(&cs->lock, flags);
  558. return;
  559. }
  560. del_timer(&ucs->timer_cmd_in);
  561. switch (urb->status) {
  562. case 0: /* normal completion */
  563. numbytes = urb->actual_length;
  564. if (unlikely(numbytes == 0)) {
  565. dev_warn(cs->dev,
  566. "control read: empty block received\n");
  567. goto retry;
  568. }
  569. if (unlikely(numbytes != ucs->rcvbuf_size)) {
  570. dev_warn(cs->dev,
  571. "control read: received %d chars, expected %d\n",
  572. numbytes, ucs->rcvbuf_size);
  573. if (numbytes > ucs->rcvbuf_size)
  574. numbytes = ucs->rcvbuf_size;
  575. }
  576. /* copy received bytes to inbuf */
  577. have_data = gigaset_fill_inbuf(inbuf, ucs->rcvbuf, numbytes);
  578. if (unlikely(numbytes < ucs->rcvbuf_size)) {
  579. /* incomplete - resubmit for remaining bytes */
  580. ucs->rcvbuf_size -= numbytes;
  581. ucs->retry_cmd_in = 0;
  582. goto retry;
  583. }
  584. break;
  585. case -ENOENT: /* canceled */
  586. case -ECONNRESET: /* canceled (async) */
  587. case -EINPROGRESS: /* pending */
  588. /* no action necessary */
  589. gig_dbg(DEBUG_USBREQ, "%s: %s",
  590. __func__, get_usb_statmsg(urb->status));
  591. break;
  592. default: /* severe trouble */
  593. dev_warn(cs->dev, "control read: %s\n",
  594. get_usb_statmsg(urb->status));
  595. retry:
  596. if (ucs->retry_cmd_in++ < BAS_RETRY) {
  597. dev_notice(cs->dev, "control read: retry %d\n",
  598. ucs->retry_cmd_in);
  599. if (atread_submit(cs, BAS_TIMEOUT) >= 0) {
  600. /* resubmitted - bypass regular exit block */
  601. spin_unlock_irqrestore(&cs->lock, flags);
  602. return;
  603. }
  604. } else {
  605. dev_err(cs->dev,
  606. "control read: giving up after %d tries\n",
  607. ucs->retry_cmd_in);
  608. }
  609. error_reset(cs);
  610. }
  611. kfree(ucs->rcvbuf);
  612. ucs->rcvbuf = NULL;
  613. ucs->rcvbuf_size = 0;
  614. spin_unlock_irqrestore(&cs->lock, flags);
  615. if (have_data) {
  616. gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
  617. gigaset_schedule_event(cs);
  618. }
  619. }
  620. /* read_iso_callback
  621. * USB completion handler for B channel isochronous input
  622. * called by the USB subsystem in interrupt context
  623. * parameter:
  624. * urb USB request block of completed request
  625. * urb->context = bc_state structure
  626. */
  627. static void read_iso_callback(struct urb *urb, struct pt_regs *regs)
  628. {
  629. struct bc_state *bcs;
  630. struct bas_bc_state *ubc;
  631. unsigned long flags;
  632. int i, rc;
  633. /* status codes not worth bothering the tasklet with */
  634. if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET ||
  635. urb->status == -EINPROGRESS)) {
  636. gig_dbg(DEBUG_ISO, "%s: %s",
  637. __func__, get_usb_statmsg(urb->status));
  638. return;
  639. }
  640. bcs = urb->context;
  641. ubc = bcs->hw.bas;
  642. spin_lock_irqsave(&ubc->isoinlock, flags);
  643. if (likely(ubc->isoindone == NULL)) {
  644. /* pass URB to tasklet */
  645. ubc->isoindone = urb;
  646. tasklet_schedule(&ubc->rcvd_tasklet);
  647. } else {
  648. /* tasklet still busy, drop data and resubmit URB */
  649. ubc->loststatus = urb->status;
  650. for (i = 0; i < BAS_NUMFRAMES; i++) {
  651. ubc->isoinlost += urb->iso_frame_desc[i].actual_length;
  652. if (unlikely(urb->iso_frame_desc[i].status != 0 &&
  653. urb->iso_frame_desc[i].status != -EINPROGRESS)) {
  654. ubc->loststatus = urb->iso_frame_desc[i].status;
  655. }
  656. urb->iso_frame_desc[i].status = 0;
  657. urb->iso_frame_desc[i].actual_length = 0;
  658. }
  659. if (likely(atomic_read(&ubc->running))) {
  660. /* urb->dev is clobbered by USB subsystem */
  661. urb->dev = bcs->cs->hw.bas->udev;
  662. urb->transfer_flags = URB_ISO_ASAP;
  663. urb->number_of_packets = BAS_NUMFRAMES;
  664. gig_dbg(DEBUG_ISO, "%s: isoc read overrun/resubmit",
  665. __func__);
  666. rc = usb_submit_urb(urb, SLAB_ATOMIC);
  667. if (unlikely(rc != 0)) {
  668. dev_err(bcs->cs->dev,
  669. "could not resubmit isochronous read "
  670. "URB: %s\n", get_usb_statmsg(rc));
  671. dump_urb(DEBUG_ISO, "isoc read", urb);
  672. error_hangup(bcs);
  673. }
  674. }
  675. }
  676. spin_unlock_irqrestore(&ubc->isoinlock, flags);
  677. }
  678. /* write_iso_callback
  679. * USB completion handler for B channel isochronous output
  680. * called by the USB subsystem in interrupt context
  681. * parameter:
  682. * urb USB request block of completed request
  683. * urb->context = isow_urbctx_t structure
  684. */
  685. static void write_iso_callback(struct urb *urb, struct pt_regs *regs)
  686. {
  687. struct isow_urbctx_t *ucx;
  688. struct bas_bc_state *ubc;
  689. unsigned long flags;
  690. /* status codes not worth bothering the tasklet with */
  691. if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET ||
  692. urb->status == -EINPROGRESS)) {
  693. gig_dbg(DEBUG_ISO, "%s: %s",
  694. __func__, get_usb_statmsg(urb->status));
  695. return;
  696. }
  697. /* pass URB context to tasklet */
  698. ucx = urb->context;
  699. ubc = ucx->bcs->hw.bas;
  700. spin_lock_irqsave(&ubc->isooutlock, flags);
  701. ubc->isooutovfl = ubc->isooutdone;
  702. ubc->isooutdone = ucx;
  703. spin_unlock_irqrestore(&ubc->isooutlock, flags);
  704. tasklet_schedule(&ubc->sent_tasklet);
  705. }
  706. /* starturbs
  707. * prepare and submit USB request blocks for isochronous input and output
  708. * argument:
  709. * B channel control structure
  710. * return value:
  711. * 0 on success
  712. * < 0 on error (no URBs submitted)
  713. */
  714. static int starturbs(struct bc_state *bcs)
  715. {
  716. struct bas_bc_state *ubc = bcs->hw.bas;
  717. struct urb *urb;
  718. int j, k;
  719. int rc;
  720. /* initialize L2 reception */
  721. if (bcs->proto2 == ISDN_PROTO_L2_HDLC)
  722. bcs->inputstate |= INS_flag_hunt;
  723. /* submit all isochronous input URBs */
  724. atomic_set(&ubc->running, 1);
  725. for (k = 0; k < BAS_INURBS; k++) {
  726. urb = ubc->isoinurbs[k];
  727. if (!urb) {
  728. dev_err(bcs->cs->dev, "isoinurbs[%d]==NULL\n", k);
  729. rc = -EFAULT;
  730. goto error;
  731. }
  732. urb->dev = bcs->cs->hw.bas->udev;
  733. urb->pipe = usb_rcvisocpipe(urb->dev, 3 + 2 * bcs->channel);
  734. urb->transfer_flags = URB_ISO_ASAP;
  735. urb->transfer_buffer = ubc->isoinbuf + k * BAS_INBUFSIZE;
  736. urb->transfer_buffer_length = BAS_INBUFSIZE;
  737. urb->number_of_packets = BAS_NUMFRAMES;
  738. urb->interval = BAS_FRAMETIME;
  739. urb->complete = read_iso_callback;
  740. urb->context = bcs;
  741. for (j = 0; j < BAS_NUMFRAMES; j++) {
  742. urb->iso_frame_desc[j].offset = j * BAS_MAXFRAME;
  743. urb->iso_frame_desc[j].length = BAS_MAXFRAME;
  744. urb->iso_frame_desc[j].status = 0;
  745. urb->iso_frame_desc[j].actual_length = 0;
  746. }
  747. dump_urb(DEBUG_ISO, "Initial isoc read", urb);
  748. if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) {
  749. dev_err(bcs->cs->dev,
  750. "could not submit isochronous read URB %d: %s\n",
  751. k, get_usb_statmsg(rc));
  752. goto error;
  753. }
  754. }
  755. /* initialize L2 transmission */
  756. gigaset_isowbuf_init(ubc->isooutbuf, PPP_FLAG);
  757. /* set up isochronous output URBs for flag idling */
  758. for (k = 0; k < BAS_OUTURBS; ++k) {
  759. urb = ubc->isoouturbs[k].urb;
  760. if (!urb) {
  761. dev_err(bcs->cs->dev, "isoouturbs[%d].urb==NULL\n", k);
  762. rc = -EFAULT;
  763. goto error;
  764. }
  765. urb->dev = bcs->cs->hw.bas->udev;
  766. urb->pipe = usb_sndisocpipe(urb->dev, 4 + 2 * bcs->channel);
  767. urb->transfer_flags = URB_ISO_ASAP;
  768. urb->transfer_buffer = ubc->isooutbuf->data;
  769. urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data);
  770. urb->number_of_packets = BAS_NUMFRAMES;
  771. urb->interval = BAS_FRAMETIME;
  772. urb->complete = write_iso_callback;
  773. urb->context = &ubc->isoouturbs[k];
  774. for (j = 0; j < BAS_NUMFRAMES; ++j) {
  775. urb->iso_frame_desc[j].offset = BAS_OUTBUFSIZE;
  776. urb->iso_frame_desc[j].length = BAS_NORMFRAME;
  777. urb->iso_frame_desc[j].status = 0;
  778. urb->iso_frame_desc[j].actual_length = 0;
  779. }
  780. ubc->isoouturbs[k].limit = -1;
  781. }
  782. /* submit two URBs, keep third one */
  783. for (k = 0; k < 2; ++k) {
  784. dump_urb(DEBUG_ISO, "Initial isoc write", urb);
  785. rc = usb_submit_urb(ubc->isoouturbs[k].urb, SLAB_ATOMIC);
  786. if (rc != 0) {
  787. dev_err(bcs->cs->dev,
  788. "could not submit isochronous write URB %d: %s\n",
  789. k, get_usb_statmsg(rc));
  790. goto error;
  791. }
  792. }
  793. dump_urb(DEBUG_ISO, "Initial isoc write (free)", urb);
  794. ubc->isooutfree = &ubc->isoouturbs[2];
  795. ubc->isooutdone = ubc->isooutovfl = NULL;
  796. return 0;
  797. error:
  798. stopurbs(ubc);
  799. return rc;
  800. }
  801. /* stopurbs
  802. * cancel the USB request blocks for isochronous input and output
  803. * errors are silently ignored
  804. * argument:
  805. * B channel control structure
  806. */
  807. static void stopurbs(struct bas_bc_state *ubc)
  808. {
  809. int k, rc;
  810. atomic_set(&ubc->running, 0);
  811. for (k = 0; k < BAS_INURBS; ++k) {
  812. rc = usb_unlink_urb(ubc->isoinurbs[k]);
  813. gig_dbg(DEBUG_ISO,
  814. "%s: isoc input URB %d unlinked, result = %d",
  815. __func__, k, rc);
  816. }
  817. for (k = 0; k < BAS_OUTURBS; ++k) {
  818. rc = usb_unlink_urb(ubc->isoouturbs[k].urb);
  819. gig_dbg(DEBUG_ISO,
  820. "%s: isoc output URB %d unlinked, result = %d",
  821. __func__, k, rc);
  822. }
  823. }
  824. /* Isochronous Write - Bottom Half */
  825. /* =============================== */
  826. /* submit_iso_write_urb
  827. * fill and submit the next isochronous write URB
  828. * parameters:
  829. * bcs B channel state structure
  830. * return value:
  831. * number of frames submitted in URB
  832. * 0 if URB not submitted because no data available (isooutbuf busy)
  833. * error code < 0 on error
  834. */
  835. static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
  836. {
  837. struct urb *urb = ucx->urb;
  838. struct bas_bc_state *ubc = ucx->bcs->hw.bas;
  839. struct usb_iso_packet_descriptor *ifd;
  840. int corrbytes, nframe, rc;
  841. unsigned long flags;
  842. /* urb->dev is clobbered by USB subsystem */
  843. urb->dev = ucx->bcs->cs->hw.bas->udev;
  844. urb->transfer_flags = URB_ISO_ASAP;
  845. urb->transfer_buffer = ubc->isooutbuf->data;
  846. urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data);
  847. for (nframe = 0; nframe < BAS_NUMFRAMES; nframe++) {
  848. ifd = &urb->iso_frame_desc[nframe];
  849. /* compute frame length according to flow control */
  850. ifd->length = BAS_NORMFRAME;
  851. if ((corrbytes = atomic_read(&ubc->corrbytes)) != 0) {
  852. gig_dbg(DEBUG_ISO, "%s: corrbytes=%d",
  853. __func__, corrbytes);
  854. if (corrbytes > BAS_HIGHFRAME - BAS_NORMFRAME)
  855. corrbytes = BAS_HIGHFRAME - BAS_NORMFRAME;
  856. else if (corrbytes < BAS_LOWFRAME - BAS_NORMFRAME)
  857. corrbytes = BAS_LOWFRAME - BAS_NORMFRAME;
  858. ifd->length += corrbytes;
  859. atomic_add(-corrbytes, &ubc->corrbytes);
  860. }
  861. /* retrieve block of data to send */
  862. ifd->offset = gigaset_isowbuf_getbytes(ubc->isooutbuf,
  863. ifd->length);
  864. if (ifd->offset < 0) {
  865. if (ifd->offset == -EBUSY) {
  866. gig_dbg(DEBUG_ISO,
  867. "%s: buffer busy at frame %d",
  868. __func__, nframe);
  869. /* tasklet will be restarted from
  870. gigaset_send_skb() */
  871. } else {
  872. dev_err(ucx->bcs->cs->dev,
  873. "%s: buffer error %d at frame %d\n",
  874. __func__, ifd->offset, nframe);
  875. return ifd->offset;
  876. }
  877. break;
  878. }
  879. ucx->limit = atomic_read(&ubc->isooutbuf->nextread);
  880. ifd->status = 0;
  881. ifd->actual_length = 0;
  882. }
  883. if ((urb->number_of_packets = nframe) > 0) {
  884. spin_lock_irqsave(&ucx->bcs->cs->lock, flags);
  885. rc = ucx->bcs->cs->connected ? usb_submit_urb(urb, SLAB_ATOMIC) : -ENODEV;
  886. spin_unlock_irqrestore(&ucx->bcs->cs->lock, flags);
  887. if (rc) {
  888. dev_err(ucx->bcs->cs->dev,
  889. "could not submit isochronous write URB: %s\n",
  890. get_usb_statmsg(rc));
  891. dump_urb(DEBUG_ISO, "isoc write", urb);
  892. return rc;
  893. }
  894. ++ubc->numsub;
  895. }
  896. return nframe;
  897. }
  898. /* write_iso_tasklet
  899. * tasklet scheduled when an isochronous output URB from the Gigaset device
  900. * has completed
  901. * parameter:
  902. * data B channel state structure
  903. */
  904. static void write_iso_tasklet(unsigned long data)
  905. {
  906. struct bc_state *bcs = (struct bc_state *) data;
  907. struct bas_bc_state *ubc = bcs->hw.bas;
  908. struct cardstate *cs = bcs->cs;
  909. struct isow_urbctx_t *done, *next, *ovfl;
  910. struct urb *urb;
  911. struct usb_iso_packet_descriptor *ifd;
  912. int offset;
  913. unsigned long flags;
  914. int i;
  915. struct sk_buff *skb;
  916. int len;
  917. /* loop while completed URBs arrive in time */
  918. for (;;) {
  919. if (unlikely(!(atomic_read(&ubc->running)))) {
  920. gig_dbg(DEBUG_ISO, "%s: not running", __func__);
  921. return;
  922. }
  923. /* retrieve completed URBs */
  924. spin_lock_irqsave(&ubc->isooutlock, flags);
  925. done = ubc->isooutdone;
  926. ubc->isooutdone = NULL;
  927. ovfl = ubc->isooutovfl;
  928. ubc->isooutovfl = NULL;
  929. spin_unlock_irqrestore(&ubc->isooutlock, flags);
  930. if (ovfl) {
  931. dev_err(cs->dev, "isochronous write buffer underrun\n");
  932. error_hangup(bcs);
  933. break;
  934. }
  935. if (!done)
  936. break;
  937. /* submit free URB if available */
  938. spin_lock_irqsave(&ubc->isooutlock, flags);
  939. next = ubc->isooutfree;
  940. ubc->isooutfree = NULL;
  941. spin_unlock_irqrestore(&ubc->isooutlock, flags);
  942. if (next) {
  943. if (submit_iso_write_urb(next) <= 0) {
  944. /* could not submit URB, put it back */
  945. spin_lock_irqsave(&ubc->isooutlock, flags);
  946. if (ubc->isooutfree == NULL) {
  947. ubc->isooutfree = next;
  948. next = NULL;
  949. }
  950. spin_unlock_irqrestore(&ubc->isooutlock, flags);
  951. if (next) {
  952. /* couldn't put it back */
  953. dev_err(cs->dev,
  954. "losing isochronous write URB\n");
  955. error_hangup(bcs);
  956. }
  957. }
  958. }
  959. /* process completed URB */
  960. urb = done->urb;
  961. switch (urb->status) {
  962. case 0: /* normal completion */
  963. break;
  964. case -EXDEV: /* inspect individual frames */
  965. /* assumptions (for lack of documentation):
  966. * - actual_length bytes of the frame in error are
  967. * successfully sent
  968. * - all following frames are not sent at all
  969. */
  970. gig_dbg(DEBUG_ISO, "%s: URB partially completed",
  971. __func__);
  972. offset = done->limit; /* just in case */
  973. for (i = 0; i < BAS_NUMFRAMES; i++) {
  974. ifd = &urb->iso_frame_desc[i];
  975. if (ifd->status ||
  976. ifd->actual_length != ifd->length) {
  977. dev_warn(cs->dev,
  978. "isochronous write: frame %d: %s, "
  979. "only %d of %d bytes sent\n",
  980. i, get_usb_statmsg(ifd->status),
  981. ifd->actual_length, ifd->length);
  982. offset = (ifd->offset +
  983. ifd->actual_length)
  984. % BAS_OUTBUFSIZE;
  985. break;
  986. }
  987. }
  988. #ifdef CONFIG_GIGASET_DEBUG
  989. /* check assumption on remaining frames */
  990. for (; i < BAS_NUMFRAMES; i++) {
  991. ifd = &urb->iso_frame_desc[i];
  992. if (ifd->status != -EINPROGRESS
  993. || ifd->actual_length != 0) {
  994. dev_warn(cs->dev,
  995. "isochronous write: frame %d: %s, "
  996. "%d of %d bytes sent\n",
  997. i, get_usb_statmsg(ifd->status),
  998. ifd->actual_length, ifd->length);
  999. offset = (ifd->offset +
  1000. ifd->actual_length)
  1001. % BAS_OUTBUFSIZE;
  1002. break;
  1003. }
  1004. }
  1005. #endif
  1006. break;
  1007. case -EPIPE: //FIXME is this the code for "underrun"?
  1008. dev_err(cs->dev, "isochronous write stalled\n");
  1009. error_hangup(bcs);
  1010. break;
  1011. default: /* severe trouble */
  1012. dev_warn(cs->dev, "isochronous write: %s\n",
  1013. get_usb_statmsg(urb->status));
  1014. }
  1015. /* mark the write buffer area covered by this URB as free */
  1016. if (done->limit >= 0)
  1017. atomic_set(&ubc->isooutbuf->read, done->limit);
  1018. /* mark URB as free */
  1019. spin_lock_irqsave(&ubc->isooutlock, flags);
  1020. next = ubc->isooutfree;
  1021. ubc->isooutfree = done;
  1022. spin_unlock_irqrestore(&ubc->isooutlock, flags);
  1023. if (next) {
  1024. /* only one URB still active - resubmit one */
  1025. if (submit_iso_write_urb(next) <= 0) {
  1026. /* couldn't submit */
  1027. error_hangup(bcs);
  1028. }
  1029. }
  1030. }
  1031. /* process queued SKBs */
  1032. while ((skb = skb_dequeue(&bcs->squeue))) {
  1033. /* copy to output buffer, doing L2 encapsulation */
  1034. len = skb->len;
  1035. if (gigaset_isoc_buildframe(bcs, skb->data, len) == -EAGAIN) {
  1036. /* insufficient buffer space, push back onto queue */
  1037. skb_queue_head(&bcs->squeue, skb);
  1038. gig_dbg(DEBUG_ISO, "%s: skb requeued, qlen=%d",
  1039. __func__, skb_queue_len(&bcs->squeue));
  1040. break;
  1041. }
  1042. skb_pull(skb, len);
  1043. gigaset_skb_sent(bcs, skb);
  1044. dev_kfree_skb_any(skb);
  1045. }
  1046. }
  1047. /* Isochronous Read - Bottom Half */
  1048. /* ============================== */
  1049. /* read_iso_tasklet
  1050. * tasklet scheduled when an isochronous input URB from the Gigaset device
  1051. * has completed
  1052. * parameter:
  1053. * data B channel state structure
  1054. */
  1055. static void read_iso_tasklet(unsigned long data)
  1056. {
  1057. struct bc_state *bcs = (struct bc_state *) data;
  1058. struct bas_bc_state *ubc = bcs->hw.bas;
  1059. struct cardstate *cs = bcs->cs;
  1060. struct urb *urb;
  1061. char *rcvbuf;
  1062. unsigned long flags;
  1063. int totleft, numbytes, offset, frame, rc;
  1064. /* loop while more completed URBs arrive in the meantime */
  1065. for (;;) {
  1066. /* retrieve URB */
  1067. spin_lock_irqsave(&ubc->isoinlock, flags);
  1068. if (!(urb = ubc->isoindone)) {
  1069. spin_unlock_irqrestore(&ubc->isoinlock, flags);
  1070. return;
  1071. }
  1072. ubc->isoindone = NULL;
  1073. if (unlikely(ubc->loststatus != -EINPROGRESS)) {
  1074. dev_warn(cs->dev,
  1075. "isochronous read overrun, "
  1076. "dropped URB with status: %s, %d bytes lost\n",
  1077. get_usb_statmsg(ubc->loststatus),
  1078. ubc->isoinlost);
  1079. ubc->loststatus = -EINPROGRESS;
  1080. }
  1081. spin_unlock_irqrestore(&ubc->isoinlock, flags);
  1082. if (unlikely(!(atomic_read(&ubc->running)))) {
  1083. gig_dbg(DEBUG_ISO,
  1084. "%s: channel not running, "
  1085. "dropped URB with status: %s",
  1086. __func__, get_usb_statmsg(urb->status));
  1087. return;
  1088. }
  1089. switch (urb->status) {
  1090. case 0: /* normal completion */
  1091. break;
  1092. case -EXDEV: /* inspect individual frames
  1093. (we do that anyway) */
  1094. gig_dbg(DEBUG_ISO, "%s: URB partially completed",
  1095. __func__);
  1096. break;
  1097. case -ENOENT:
  1098. case -ECONNRESET:
  1099. gig_dbg(DEBUG_ISO, "%s: URB canceled", __func__);
  1100. continue; /* -> skip */
  1101. case -EINPROGRESS: /* huh? */
  1102. gig_dbg(DEBUG_ISO, "%s: URB still pending", __func__);
  1103. continue; /* -> skip */
  1104. case -EPIPE:
  1105. dev_err(cs->dev, "isochronous read stalled\n");
  1106. error_hangup(bcs);
  1107. continue; /* -> skip */
  1108. default: /* severe trouble */
  1109. dev_warn(cs->dev, "isochronous read: %s\n",
  1110. get_usb_statmsg(urb->status));
  1111. goto error;
  1112. }
  1113. rcvbuf = urb->transfer_buffer;
  1114. totleft = urb->actual_length;
  1115. for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) {
  1116. if (unlikely(urb->iso_frame_desc[frame].status)) {
  1117. dev_warn(cs->dev,
  1118. "isochronous read: frame %d: %s\n",
  1119. frame,
  1120. get_usb_statmsg(
  1121. urb->iso_frame_desc[frame].status));
  1122. break;
  1123. }
  1124. numbytes = urb->iso_frame_desc[frame].actual_length;
  1125. if (unlikely(numbytes > BAS_MAXFRAME)) {
  1126. dev_warn(cs->dev,
  1127. "isochronous read: frame %d: "
  1128. "numbytes (%d) > BAS_MAXFRAME\n",
  1129. frame, numbytes);
  1130. break;
  1131. }
  1132. if (unlikely(numbytes > totleft)) {
  1133. dev_warn(cs->dev,
  1134. "isochronous read: frame %d: "
  1135. "numbytes (%d) > totleft (%d)\n",
  1136. frame, numbytes, totleft);
  1137. break;
  1138. }
  1139. offset = urb->iso_frame_desc[frame].offset;
  1140. if (unlikely(offset + numbytes > BAS_INBUFSIZE)) {
  1141. dev_warn(cs->dev,
  1142. "isochronous read: frame %d: "
  1143. "offset (%d) + numbytes (%d) "
  1144. "> BAS_INBUFSIZE\n",
  1145. frame, offset, numbytes);
  1146. break;
  1147. }
  1148. gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs);
  1149. totleft -= numbytes;
  1150. }
  1151. if (unlikely(totleft > 0))
  1152. dev_warn(cs->dev,
  1153. "isochronous read: %d data bytes missing\n",
  1154. totleft);
  1155. error:
  1156. /* URB processed, resubmit */
  1157. for (frame = 0; frame < BAS_NUMFRAMES; frame++) {
  1158. urb->iso_frame_desc[frame].status = 0;
  1159. urb->iso_frame_desc[frame].actual_length = 0;
  1160. }
  1161. /* urb->dev is clobbered by USB subsystem */
  1162. urb->dev = bcs->cs->hw.bas->udev;
  1163. urb->transfer_flags = URB_ISO_ASAP;
  1164. urb->number_of_packets = BAS_NUMFRAMES;
  1165. spin_lock_irqsave(&cs->lock, flags);
  1166. rc = cs->connected ? usb_submit_urb(urb, SLAB_ATOMIC) : -ENODEV;
  1167. spin_unlock_irqrestore(&cs->lock, flags);
  1168. if (rc) {
  1169. dev_err(cs->dev,
  1170. "could not resubmit isochronous read URB: %s\n",
  1171. get_usb_statmsg(rc));
  1172. dump_urb(DEBUG_ISO, "resubmit iso read", urb);
  1173. error_hangup(bcs);
  1174. }
  1175. }
  1176. }
  1177. /* Channel Operations */
  1178. /* ================== */
  1179. /* req_timeout
  1180. * timeout routine for control output request
  1181. * argument:
  1182. * B channel control structure
  1183. */
  1184. static void req_timeout(unsigned long data)
  1185. {
  1186. struct bc_state *bcs = (struct bc_state *) data;
  1187. struct bas_cardstate *ucs = bcs->cs->hw.bas;
  1188. int pending;
  1189. unsigned long flags;
  1190. check_pending(ucs);
  1191. spin_lock_irqsave(&ucs->lock, flags);
  1192. pending = ucs->pending;
  1193. ucs->pending = 0;
  1194. spin_unlock_irqrestore(&ucs->lock, flags);
  1195. switch (pending) {
  1196. case 0: /* no pending request */
  1197. gig_dbg(DEBUG_USBREQ, "%s: no request pending", __func__);
  1198. break;
  1199. case HD_OPEN_ATCHANNEL:
  1200. dev_err(bcs->cs->dev, "timeout opening AT channel\n");
  1201. error_reset(bcs->cs);
  1202. break;
  1203. case HD_OPEN_B2CHANNEL:
  1204. case HD_OPEN_B1CHANNEL:
  1205. dev_err(bcs->cs->dev, "timeout opening channel %d\n",
  1206. bcs->channel + 1);
  1207. error_hangup(bcs);
  1208. break;
  1209. case HD_CLOSE_ATCHANNEL:
  1210. dev_err(bcs->cs->dev, "timeout closing AT channel\n");
  1211. break;
  1212. case HD_CLOSE_B2CHANNEL:
  1213. case HD_CLOSE_B1CHANNEL:
  1214. dev_err(bcs->cs->dev, "timeout closing channel %d\n",
  1215. bcs->channel + 1);
  1216. break;
  1217. default:
  1218. dev_warn(bcs->cs->dev, "request 0x%02x timed out, clearing\n",
  1219. pending);
  1220. }
  1221. }
  1222. /* write_ctrl_callback
  1223. * USB completion handler for control pipe output
  1224. * called by the USB subsystem in interrupt context
  1225. * parameter:
  1226. * urb USB request block of completed request
  1227. * urb->context = hardware specific controller state structure
  1228. */
  1229. static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs)
  1230. {
  1231. struct bas_cardstate *ucs = urb->context;
  1232. unsigned long flags;
  1233. spin_lock_irqsave(&ucs->lock, flags);
  1234. if (urb->status && ucs->pending) {
  1235. dev_err(&ucs->interface->dev,
  1236. "control request 0x%02x failed: %s\n",
  1237. ucs->pending, get_usb_statmsg(urb->status));
  1238. del_timer(&ucs->timer_ctrl);
  1239. ucs->pending = 0;
  1240. }
  1241. /* individual handling of specific request types */
  1242. switch (ucs->pending) {
  1243. case HD_DEVICE_INIT_ACK: /* no reply expected */
  1244. ucs->pending = 0;
  1245. break;
  1246. }
  1247. spin_unlock_irqrestore(&ucs->lock, flags);
  1248. }
  1249. /* req_submit
  1250. * submit a control output request without message buffer to the Gigaset base
  1251. * and optionally start a timeout
  1252. * parameters:
  1253. * bcs B channel control structure
  1254. * req control request code (HD_*)
  1255. * val control request parameter value (set to 0 if unused)
  1256. * timeout timeout in seconds (0: no timeout)
  1257. * return value:
  1258. * 0 on success
  1259. * -EINVAL if a NULL pointer is encountered somewhere
  1260. * -EBUSY if another request is pending
  1261. * any URB submission error code
  1262. */
  1263. static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
  1264. {
  1265. struct bas_cardstate *ucs = bcs->cs->hw.bas;
  1266. int ret;
  1267. unsigned long flags;
  1268. gig_dbg(DEBUG_USBREQ, "-------> 0x%02x (%d)", req, val);
  1269. spin_lock_irqsave(&ucs->lock, flags);
  1270. if (ucs->pending) {
  1271. spin_unlock_irqrestore(&ucs->lock, flags);
  1272. dev_err(bcs->cs->dev,
  1273. "submission of request 0x%02x failed: "
  1274. "request 0x%02x still pending\n",
  1275. req, ucs->pending);
  1276. return -EBUSY;
  1277. }
  1278. if (ucs->urb_ctrl->status == -EINPROGRESS) {
  1279. spin_unlock_irqrestore(&ucs->lock, flags);
  1280. dev_err(bcs->cs->dev,
  1281. "could not submit request 0x%02x: URB busy\n", req);
  1282. return -EBUSY;
  1283. }
  1284. ucs->dr_ctrl.bRequestType = OUT_VENDOR_REQ;
  1285. ucs->dr_ctrl.bRequest = req;
  1286. ucs->dr_ctrl.wValue = cpu_to_le16(val);
  1287. ucs->dr_ctrl.wIndex = 0;
  1288. ucs->dr_ctrl.wLength = 0;
  1289. usb_fill_control_urb(ucs->urb_ctrl, ucs->udev,
  1290. usb_sndctrlpipe(ucs->udev, 0),
  1291. (unsigned char*) &ucs->dr_ctrl, NULL, 0,
  1292. write_ctrl_callback, ucs);
  1293. if ((ret = usb_submit_urb(ucs->urb_ctrl, SLAB_ATOMIC)) != 0) {
  1294. dev_err(bcs->cs->dev, "could not submit request 0x%02x: %s\n",
  1295. req, get_usb_statmsg(ret));
  1296. spin_unlock_irqrestore(&ucs->lock, flags);
  1297. return ret;
  1298. }
  1299. ucs->pending = req;
  1300. if (timeout > 0) {
  1301. gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
  1302. ucs->timer_ctrl.expires = jiffies + timeout * HZ / 10;
  1303. ucs->timer_ctrl.data = (unsigned long) bcs;
  1304. ucs->timer_ctrl.function = req_timeout;
  1305. add_timer(&ucs->timer_ctrl);
  1306. }
  1307. spin_unlock_irqrestore(&ucs->lock, flags);
  1308. return 0;
  1309. }
  1310. /* gigaset_init_bchannel
  1311. * called by common.c to connect a B channel
  1312. * initialize isochronous I/O and tell the Gigaset base to open the channel
  1313. * argument:
  1314. * B channel control structure
  1315. * return value:
  1316. * 0 on success, error code < 0 on error
  1317. */
  1318. static int gigaset_init_bchannel(struct bc_state *bcs)
  1319. {
  1320. int req, ret;
  1321. if ((ret = starturbs(bcs)) < 0) {
  1322. dev_err(bcs->cs->dev,
  1323. "could not start isochronous I/O for channel %d\n",
  1324. bcs->channel + 1);
  1325. error_hangup(bcs);
  1326. return ret;
  1327. }
  1328. req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL;
  1329. if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) {
  1330. dev_err(bcs->cs->dev, "could not open channel %d: %s\n",
  1331. bcs->channel + 1, get_usb_statmsg(ret));
  1332. stopurbs(bcs->hw.bas);
  1333. error_hangup(bcs);
  1334. }
  1335. return ret;
  1336. }
  1337. /* gigaset_close_bchannel
  1338. * called by common.c to disconnect a B channel
  1339. * tell the Gigaset base to close the channel
  1340. * stopping isochronous I/O and LL notification will be done when the
  1341. * acknowledgement for the close arrives
  1342. * argument:
  1343. * B channel control structure
  1344. * return value:
  1345. * 0 on success, error code < 0 on error
  1346. */
  1347. static int gigaset_close_bchannel(struct bc_state *bcs)
  1348. {
  1349. int req, ret;
  1350. if (!(atomic_read(&bcs->cs->hw.bas->basstate) &
  1351. (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) {
  1352. /* channel not running: just signal common.c */
  1353. gigaset_bchannel_down(bcs);
  1354. return 0;
  1355. }
  1356. req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL;
  1357. if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0)
  1358. dev_err(bcs->cs->dev,
  1359. "could not submit HD_CLOSE_BxCHANNEL request: %s\n",
  1360. get_usb_statmsg(ret));
  1361. return ret;
  1362. }
  1363. /* Device Operations */
  1364. /* ================= */
  1365. /* complete_cb
  1366. * unqueue first command buffer from queue, waking any sleepers
  1367. * must be called with cs->cmdlock held
  1368. * parameter:
  1369. * cs controller state structure
  1370. */
  1371. static void complete_cb(struct cardstate *cs)
  1372. {
  1373. struct cmdbuf_t *cb = cs->cmdbuf;
  1374. /* unqueue completed buffer */
  1375. cs->cmdbytes -= cs->curlen;
  1376. gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD,
  1377. "write_command: sent %u bytes, %u left",
  1378. cs->curlen, cs->cmdbytes);
  1379. if ((cs->cmdbuf = cb->next) != NULL) {
  1380. cs->cmdbuf->prev = NULL;
  1381. cs->curlen = cs->cmdbuf->len;
  1382. } else {
  1383. cs->lastcmdbuf = NULL;
  1384. cs->curlen = 0;
  1385. }
  1386. if (cb->wake_tasklet)
  1387. tasklet_schedule(cb->wake_tasklet);
  1388. kfree(cb);
  1389. }
  1390. static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len);
  1391. /* write_command_callback
  1392. * USB completion handler for AT command transmission
  1393. * called by the USB subsystem in interrupt context
  1394. * parameter:
  1395. * urb USB request block of completed request
  1396. * urb->context = controller state structure
  1397. */
  1398. static void write_command_callback(struct urb *urb, struct pt_regs *regs)
  1399. {
  1400. struct cardstate *cs = urb->context;
  1401. struct bas_cardstate *ucs = cs->hw.bas;
  1402. unsigned long flags;
  1403. /* check status */
  1404. switch (urb->status) {
  1405. case 0: /* normal completion */
  1406. break;
  1407. case -ENOENT: /* canceled */
  1408. case -ECONNRESET: /* canceled (async) */
  1409. case -EINPROGRESS: /* pending */
  1410. /* ignore silently */
  1411. gig_dbg(DEBUG_USBREQ, "%s: %s",
  1412. __func__, get_usb_statmsg(urb->status));
  1413. return;
  1414. default: /* any failure */
  1415. if (++ucs->retry_cmd_out > BAS_RETRY) {
  1416. dev_warn(cs->dev,
  1417. "command write: %s, "
  1418. "giving up after %d retries\n",
  1419. get_usb_statmsg(urb->status),
  1420. ucs->retry_cmd_out);
  1421. break;
  1422. }
  1423. if (cs->cmdbuf == NULL) {
  1424. dev_warn(cs->dev,
  1425. "command write: %s, "
  1426. "cannot retry - cmdbuf gone\n",
  1427. get_usb_statmsg(urb->status));
  1428. break;
  1429. }
  1430. dev_notice(cs->dev, "command write: %s, retry %d\n",
  1431. get_usb_statmsg(urb->status), ucs->retry_cmd_out);
  1432. if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0)
  1433. /* resubmitted - bypass regular exit block */
  1434. return;
  1435. /* command send failed, assume base still waiting */
  1436. update_basstate(ucs, BS_ATREADY, 0);
  1437. }
  1438. spin_lock_irqsave(&cs->cmdlock, flags);
  1439. if (cs->cmdbuf != NULL)
  1440. complete_cb(cs);
  1441. spin_unlock_irqrestore(&cs->cmdlock, flags);
  1442. }
  1443. /* atrdy_timeout
  1444. * timeout routine for AT command transmission
  1445. * argument:
  1446. * controller state structure
  1447. */
  1448. static void atrdy_timeout(unsigned long data)
  1449. {
  1450. struct cardstate *cs = (struct cardstate *) data;
  1451. struct bas_cardstate *ucs = cs->hw.bas;
  1452. dev_warn(cs->dev, "timeout waiting for HD_READY_SEND_ATDATA\n");
  1453. /* fake the missing signal - what else can I do? */
  1454. update_basstate(ucs, BS_ATREADY, BS_ATTIMER);
  1455. start_cbsend(cs);
  1456. }
  1457. /* atwrite_submit
  1458. * submit an HD_WRITE_ATMESSAGE command URB
  1459. * parameters:
  1460. * cs controller state structure
  1461. * buf buffer containing command to send
  1462. * len length of command to send
  1463. * return value:
  1464. * 0 on success
  1465. * -EFAULT if a NULL pointer is encountered somewhere
  1466. * -EBUSY if another request is pending
  1467. * any URB submission error code
  1468. */
  1469. static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
  1470. {
  1471. struct bas_cardstate *ucs = cs->hw.bas;
  1472. unsigned long flags;
  1473. int ret;
  1474. gig_dbg(DEBUG_USBREQ, "-------> HD_WRITE_ATMESSAGE (%d)", len);
  1475. if (ucs->urb_cmd_out->status == -EINPROGRESS) {
  1476. dev_err(cs->dev,
  1477. "could not submit HD_WRITE_ATMESSAGE: URB busy\n");
  1478. return -EBUSY;
  1479. }
  1480. ucs->dr_cmd_out.bRequestType = OUT_VENDOR_REQ;
  1481. ucs->dr_cmd_out.bRequest = HD_WRITE_ATMESSAGE;
  1482. ucs->dr_cmd_out.wValue = 0;
  1483. ucs->dr_cmd_out.wIndex = 0;
  1484. ucs->dr_cmd_out.wLength = cpu_to_le16(len);
  1485. usb_fill_control_urb(ucs->urb_cmd_out, ucs->udev,
  1486. usb_sndctrlpipe(ucs->udev, 0),
  1487. (unsigned char*) &ucs->dr_cmd_out, buf, len,
  1488. write_command_callback, cs);
  1489. spin_lock_irqsave(&cs->lock, flags);
  1490. ret = cs->connected ? usb_submit_urb(ucs->urb_cmd_out, SLAB_ATOMIC) : -ENODEV;
  1491. spin_unlock_irqrestore(&cs->lock, flags);
  1492. if (ret) {
  1493. dev_err(cs->dev, "could not submit HD_WRITE_ATMESSAGE: %s\n",
  1494. get_usb_statmsg(ret));
  1495. return ret;
  1496. }
  1497. /* submitted successfully */
  1498. update_basstate(ucs, 0, BS_ATREADY);
  1499. /* start timeout if necessary */
  1500. if (!(atomic_read(&ucs->basstate) & BS_ATTIMER)) {
  1501. gig_dbg(DEBUG_OUTPUT, "setting ATREADY timeout of %d/10 secs",
  1502. ATRDY_TIMEOUT);
  1503. ucs->timer_atrdy.expires = jiffies + ATRDY_TIMEOUT * HZ / 10;
  1504. ucs->timer_atrdy.data = (unsigned long) cs;
  1505. ucs->timer_atrdy.function = atrdy_timeout;
  1506. add_timer(&ucs->timer_atrdy);
  1507. update_basstate(ucs, BS_ATTIMER, 0);
  1508. }
  1509. return 0;
  1510. }
  1511. /* start_cbsend
  1512. * start transmission of AT command queue if necessary
  1513. * parameter:
  1514. * cs controller state structure
  1515. * return value:
  1516. * 0 on success
  1517. * error code < 0 on error
  1518. */
  1519. static int start_cbsend(struct cardstate *cs)
  1520. {
  1521. struct cmdbuf_t *cb;
  1522. struct bas_cardstate *ucs = cs->hw.bas;
  1523. unsigned long flags;
  1524. int rc;
  1525. int retval = 0;
  1526. /* check if AT channel is open */
  1527. if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) {
  1528. gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD, "AT channel not open");
  1529. rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT);
  1530. if (rc < 0) {
  1531. dev_err(cs->dev, "could not open AT channel\n");
  1532. /* flush command queue */
  1533. spin_lock_irqsave(&cs->cmdlock, flags);
  1534. while (cs->cmdbuf != NULL)
  1535. complete_cb(cs);
  1536. spin_unlock_irqrestore(&cs->cmdlock, flags);
  1537. }
  1538. return rc;
  1539. }
  1540. /* try to send first command in queue */
  1541. spin_lock_irqsave(&cs->cmdlock, flags);
  1542. while ((cb = cs->cmdbuf) != NULL &&
  1543. atomic_read(&ucs->basstate) & BS_ATREADY) {
  1544. ucs->retry_cmd_out = 0;
  1545. rc = atwrite_submit(cs, cb->buf, cb->len);
  1546. if (unlikely(rc)) {
  1547. retval = rc;
  1548. complete_cb(cs);
  1549. }
  1550. }
  1551. spin_unlock_irqrestore(&cs->cmdlock, flags);
  1552. return retval;
  1553. }
  1554. /* gigaset_write_cmd
  1555. * This function is called by the device independent part of the driver
  1556. * to transmit an AT command string to the Gigaset device.
  1557. * It encapsulates the device specific method for transmission over the
  1558. * direct USB connection to the base.
  1559. * The command string is added to the queue of commands to send, and
  1560. * USB transmission is started if necessary.
  1561. * parameters:
  1562. * cs controller state structure
  1563. * buf command string to send
  1564. * len number of bytes to send (max. IF_WRITEBUF)
  1565. * wake_tasklet tasklet to run when transmission is completed
  1566. * (NULL if none)
  1567. * return value:
  1568. * number of bytes queued on success
  1569. * error code < 0 on error
  1570. */
  1571. static int gigaset_write_cmd(struct cardstate *cs,
  1572. const unsigned char *buf, int len,
  1573. struct tasklet_struct *wake_tasklet)
  1574. {
  1575. struct cmdbuf_t *cb;
  1576. unsigned long flags;
  1577. int status;
  1578. gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
  1579. DEBUG_TRANSCMD : DEBUG_LOCKCMD,
  1580. "CMD Transmit", len, buf);
  1581. if (len <= 0)
  1582. return 0; /* nothing to do */
  1583. if (len > IF_WRITEBUF)
  1584. len = IF_WRITEBUF;
  1585. if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
  1586. dev_err(cs->dev, "%s: out of memory\n", __func__);
  1587. return -ENOMEM;
  1588. }
  1589. memcpy(cb->buf, buf, len);
  1590. cb->len = len;
  1591. cb->offset = 0;
  1592. cb->next = NULL;
  1593. cb->wake_tasklet = wake_tasklet;
  1594. spin_lock_irqsave(&cs->cmdlock, flags);
  1595. cb->prev = cs->lastcmdbuf;
  1596. if (cs->lastcmdbuf)
  1597. cs->lastcmdbuf->next = cb;
  1598. else {
  1599. cs->cmdbuf = cb;
  1600. cs->curlen = len;
  1601. }
  1602. cs->cmdbytes += len;
  1603. cs->lastcmdbuf = cb;
  1604. spin_unlock_irqrestore(&cs->cmdlock, flags);
  1605. status = start_cbsend(cs);
  1606. return status < 0 ? status : len;
  1607. }
  1608. /* gigaset_write_room
  1609. * tty_driver.write_room interface routine
  1610. * return number of characters the driver will accept to be written via
  1611. * gigaset_write_cmd
  1612. * parameter:
  1613. * controller state structure
  1614. * return value:
  1615. * number of characters
  1616. */
  1617. static int gigaset_write_room(struct cardstate *cs)
  1618. {
  1619. return IF_WRITEBUF;
  1620. }
  1621. /* gigaset_chars_in_buffer
  1622. * tty_driver.chars_in_buffer interface routine
  1623. * return number of characters waiting to be sent
  1624. * parameter:
  1625. * controller state structure
  1626. * return value:
  1627. * number of characters
  1628. */
  1629. static int gigaset_chars_in_buffer(struct cardstate *cs)
  1630. {
  1631. unsigned long flags;
  1632. unsigned bytes;
  1633. spin_lock_irqsave(&cs->cmdlock, flags);
  1634. bytes = cs->cmdbytes;
  1635. spin_unlock_irqrestore(&cs->cmdlock, flags);
  1636. return bytes;
  1637. }
  1638. /* gigaset_brkchars
  1639. * implementation of ioctl(GIGASET_BRKCHARS)
  1640. * parameter:
  1641. * controller state structure
  1642. * return value:
  1643. * -EINVAL (unimplemented function)
  1644. */
  1645. static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
  1646. {
  1647. return -EINVAL;
  1648. }
  1649. /* Device Initialization/Shutdown */
  1650. /* ============================== */
  1651. /* Free hardware dependent part of the B channel structure
  1652. * parameter:
  1653. * bcs B channel structure
  1654. * return value:
  1655. * !=0 on success
  1656. */
  1657. static int gigaset_freebcshw(struct bc_state *bcs)
  1658. {
  1659. if (!bcs->hw.bas)
  1660. return 0;
  1661. if (bcs->hw.bas->isooutbuf)
  1662. kfree(bcs->hw.bas->isooutbuf);
  1663. kfree(bcs->hw.bas);
  1664. bcs->hw.bas = NULL;
  1665. return 1;
  1666. }
  1667. /* Initialize hardware dependent part of the B channel structure
  1668. * parameter:
  1669. * bcs B channel structure
  1670. * return value:
  1671. * !=0 on success
  1672. */
  1673. static int gigaset_initbcshw(struct bc_state *bcs)
  1674. {
  1675. int i;
  1676. struct bas_bc_state *ubc;
  1677. bcs->hw.bas = ubc = kmalloc(sizeof(struct bas_bc_state), GFP_KERNEL);
  1678. if (!ubc) {
  1679. err("could not allocate bas_bc_state");
  1680. return 0;
  1681. }
  1682. atomic_set(&ubc->running, 0);
  1683. atomic_set(&ubc->corrbytes, 0);
  1684. spin_lock_init(&ubc->isooutlock);
  1685. for (i = 0; i < BAS_OUTURBS; ++i) {
  1686. ubc->isoouturbs[i].urb = NULL;
  1687. ubc->isoouturbs[i].bcs = bcs;
  1688. }
  1689. ubc->isooutdone = ubc->isooutfree = ubc->isooutovfl = NULL;
  1690. ubc->numsub = 0;
  1691. if (!(ubc->isooutbuf = kmalloc(sizeof(struct isowbuf_t), GFP_KERNEL))) {
  1692. err("could not allocate isochronous output buffer");
  1693. kfree(ubc);
  1694. bcs->hw.bas = NULL;
  1695. return 0;
  1696. }
  1697. tasklet_init(&ubc->sent_tasklet,
  1698. &write_iso_tasklet, (unsigned long) bcs);
  1699. spin_lock_init(&ubc->isoinlock);
  1700. for (i = 0; i < BAS_INURBS; ++i)
  1701. ubc->isoinurbs[i] = NULL;
  1702. ubc->isoindone = NULL;
  1703. ubc->loststatus = -EINPROGRESS;
  1704. ubc->isoinlost = 0;
  1705. ubc->seqlen = 0;
  1706. ubc->inbyte = 0;
  1707. ubc->inbits = 0;
  1708. ubc->goodbytes = 0;
  1709. ubc->alignerrs = 0;
  1710. ubc->fcserrs = 0;
  1711. ubc->frameerrs = 0;
  1712. ubc->giants = 0;
  1713. ubc->runts = 0;
  1714. ubc->aborts = 0;
  1715. ubc->shared0s = 0;
  1716. ubc->stolen0s = 0;
  1717. tasklet_init(&ubc->rcvd_tasklet,
  1718. &read_iso_tasklet, (unsigned long) bcs);
  1719. return 1;
  1720. }
  1721. static void gigaset_reinitbcshw(struct bc_state *bcs)
  1722. {
  1723. struct bas_bc_state *ubc = bcs->hw.bas;
  1724. atomic_set(&bcs->hw.bas->running, 0);
  1725. atomic_set(&bcs->hw.bas->corrbytes, 0);
  1726. bcs->hw.bas->numsub = 0;
  1727. spin_lock_init(&ubc->isooutlock);
  1728. spin_lock_init(&ubc->isoinlock);
  1729. ubc->loststatus = -EINPROGRESS;
  1730. }
  1731. static void gigaset_freecshw(struct cardstate *cs)
  1732. {
  1733. struct bas_cardstate *ucs = cs->hw.bas;
  1734. del_timer(&ucs->timer_ctrl);
  1735. del_timer(&ucs->timer_atrdy);
  1736. del_timer(&ucs->timer_cmd_in);
  1737. kfree(cs->hw.bas);
  1738. }
  1739. static int gigaset_initcshw(struct cardstate *cs)
  1740. {
  1741. struct bas_cardstate *ucs;
  1742. cs->hw.bas = ucs = kmalloc(sizeof *ucs, GFP_KERNEL);
  1743. if (!ucs)
  1744. return 0;
  1745. ucs->urb_cmd_in = NULL;
  1746. ucs->urb_cmd_out = NULL;
  1747. ucs->rcvbuf = NULL;
  1748. ucs->rcvbuf_size = 0;
  1749. spin_lock_init(&ucs->lock);
  1750. ucs->pending = 0;
  1751. atomic_set(&ucs->basstate, 0);
  1752. init_timer(&ucs->timer_ctrl);
  1753. init_timer(&ucs->timer_atrdy);
  1754. init_timer(&ucs->timer_cmd_in);
  1755. return 1;
  1756. }
  1757. /* freeurbs
  1758. * unlink and deallocate all URBs unconditionally
  1759. * caller must make sure that no commands are still in progress
  1760. * parameter:
  1761. * cs controller state structure
  1762. */
  1763. static void freeurbs(struct cardstate *cs)
  1764. {
  1765. struct bas_cardstate *ucs = cs->hw.bas;
  1766. struct bas_bc_state *ubc;
  1767. int i, j;
  1768. for (j = 0; j < 2; ++j) {
  1769. ubc = cs->bcs[j].hw.bas;
  1770. for (i = 0; i < BAS_OUTURBS; ++i)
  1771. if (ubc->isoouturbs[i].urb) {
  1772. usb_kill_urb(ubc->isoouturbs[i].urb);
  1773. gig_dbg(DEBUG_INIT,
  1774. "%s: isoc output URB %d/%d unlinked",
  1775. __func__, j, i);
  1776. usb_free_urb(ubc->isoouturbs[i].urb);
  1777. ubc->isoouturbs[i].urb = NULL;
  1778. }
  1779. for (i = 0; i < BAS_INURBS; ++i)
  1780. if (ubc->isoinurbs[i]) {
  1781. usb_kill_urb(ubc->isoinurbs[i]);
  1782. gig_dbg(DEBUG_INIT,
  1783. "%s: isoc input URB %d/%d unlinked",
  1784. __func__, j, i);
  1785. usb_free_urb(ubc->isoinurbs[i]);
  1786. ubc->isoinurbs[i] = NULL;
  1787. }
  1788. }
  1789. if (ucs->urb_int_in) {
  1790. usb_kill_urb(ucs->urb_int_in);
  1791. gig_dbg(DEBUG_INIT, "%s: interrupt input URB unlinked",
  1792. __func__);
  1793. usb_free_urb(ucs->urb_int_in);
  1794. ucs->urb_int_in = NULL;
  1795. }
  1796. if (ucs->urb_cmd_out) {
  1797. usb_kill_urb(ucs->urb_cmd_out);
  1798. gig_dbg(DEBUG_INIT, "%s: command output URB unlinked",
  1799. __func__);
  1800. usb_free_urb(ucs->urb_cmd_out);
  1801. ucs->urb_cmd_out = NULL;
  1802. }
  1803. if (ucs->urb_cmd_in) {
  1804. usb_kill_urb(ucs->urb_cmd_in);
  1805. gig_dbg(DEBUG_INIT, "%s: command input URB unlinked",
  1806. __func__);
  1807. usb_free_urb(ucs->urb_cmd_in);
  1808. ucs->urb_cmd_in = NULL;
  1809. }
  1810. if (ucs->urb_ctrl) {
  1811. usb_kill_urb(ucs->urb_ctrl);
  1812. gig_dbg(DEBUG_INIT, "%s: control output URB unlinked",
  1813. __func__);
  1814. usb_free_urb(ucs->urb_ctrl);
  1815. ucs->urb_ctrl = NULL;
  1816. }
  1817. }
  1818. /* gigaset_probe
  1819. * This function is called when a new USB device is connected.
  1820. * It checks whether the new device is handled by this driver.
  1821. */
  1822. static int gigaset_probe(struct usb_interface *interface,
  1823. const struct usb_device_id *id)
  1824. {
  1825. struct usb_host_interface *hostif;
  1826. struct usb_device *udev = interface_to_usbdev(interface);
  1827. struct cardstate *cs = NULL;
  1828. struct bas_cardstate *ucs = NULL;
  1829. struct bas_bc_state *ubc;
  1830. struct usb_endpoint_descriptor *endpoint;
  1831. int i, j;
  1832. int ret;
  1833. gig_dbg(DEBUG_ANY,
  1834. "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
  1835. __func__, le16_to_cpu(udev->descriptor.idVendor),
  1836. le16_to_cpu(udev->descriptor.idProduct));
  1837. /* See if the device offered us matches what we can accept */
  1838. if ((le16_to_cpu(udev->descriptor.idVendor) != USB_GIGA_VENDOR_ID) ||
  1839. (le16_to_cpu(udev->descriptor.idProduct) != USB_GIGA_PRODUCT_ID &&
  1840. le16_to_cpu(udev->descriptor.idProduct) != USB_4175_PRODUCT_ID &&
  1841. le16_to_cpu(udev->descriptor.idProduct) != USB_SX303_PRODUCT_ID &&
  1842. le16_to_cpu(udev->descriptor.idProduct) != USB_SX353_PRODUCT_ID)) {
  1843. gig_dbg(DEBUG_ANY, "%s: unmatched ID - exiting", __func__);
  1844. return -ENODEV;
  1845. }
  1846. /* set required alternate setting */
  1847. hostif = interface->cur_altsetting;
  1848. if (hostif->desc.bAlternateSetting != 3) {
  1849. gig_dbg(DEBUG_ANY,
  1850. "%s: wrong alternate setting %d - trying to switch",
  1851. __func__, hostif->desc.bAlternateSetting);
  1852. if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) < 0) {
  1853. dev_warn(&udev->dev, "usb_set_interface failed, "
  1854. "device %d interface %d altsetting %d\n",
  1855. udev->devnum, hostif->desc.bInterfaceNumber,
  1856. hostif->desc.bAlternateSetting);
  1857. return -ENODEV;
  1858. }
  1859. hostif = interface->cur_altsetting;
  1860. }
  1861. /* Reject application specific interfaces
  1862. */
  1863. if (hostif->desc.bInterfaceClass != 255) {
  1864. dev_warn(&udev->dev, "%s: bInterfaceClass == %d\n",
  1865. __func__, hostif->desc.bInterfaceClass);
  1866. return -ENODEV;
  1867. }
  1868. dev_info(&udev->dev,
  1869. "%s: Device matched (Vendor: 0x%x, Product: 0x%x)\n",
  1870. __func__, le16_to_cpu(udev->descriptor.idVendor),
  1871. le16_to_cpu(udev->descriptor.idProduct));
  1872. cs = gigaset_getunassignedcs(driver);
  1873. if (!cs) {
  1874. dev_err(&udev->dev, "no free cardstate\n");
  1875. return -ENODEV;
  1876. }
  1877. ucs = cs->hw.bas;
  1878. /* save off device structure ptrs for later use */
  1879. usb_get_dev(udev);
  1880. ucs->udev = udev;
  1881. ucs->interface = interface;
  1882. cs->dev = &interface->dev;
  1883. /* allocate URBs:
  1884. * - one for the interrupt pipe
  1885. * - three for the different uses of the default control pipe
  1886. * - three for each isochronous pipe
  1887. */
  1888. ucs->urb_int_in = usb_alloc_urb(0, SLAB_KERNEL);
  1889. if (!ucs->urb_int_in) {
  1890. dev_err(cs->dev, "no free urbs available\n");
  1891. goto error;
  1892. }
  1893. ucs->urb_cmd_in = usb_alloc_urb(0, SLAB_KERNEL);
  1894. if (!ucs->urb_cmd_in) {
  1895. dev_err(cs->dev, "no free urbs available\n");
  1896. goto error;
  1897. }
  1898. ucs->urb_cmd_out = usb_alloc_urb(0, SLAB_KERNEL);
  1899. if (!ucs->urb_cmd_out) {
  1900. dev_err(cs->dev, "no free urbs available\n");
  1901. goto error;
  1902. }
  1903. ucs->urb_ctrl = usb_alloc_urb(0, SLAB_KERNEL);
  1904. if (!ucs->urb_ctrl) {
  1905. dev_err(cs->dev, "no free urbs available\n");
  1906. goto error;
  1907. }
  1908. for (j = 0; j < 2; ++j) {
  1909. ubc = cs->bcs[j].hw.bas;
  1910. for (i = 0; i < BAS_OUTURBS; ++i) {
  1911. ubc->isoouturbs[i].urb =
  1912. usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL);
  1913. if (!ubc->isoouturbs[i].urb) {
  1914. dev_err(cs->dev, "no free urbs available\n");
  1915. goto error;
  1916. }
  1917. }
  1918. for (i = 0; i < BAS_INURBS; ++i) {
  1919. ubc->isoinurbs[i] =
  1920. usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL);
  1921. if (!ubc->isoinurbs[i]) {
  1922. dev_err(cs->dev, "no free urbs available\n");
  1923. goto error;
  1924. }
  1925. }
  1926. }
  1927. ucs->rcvbuf = NULL;
  1928. ucs->rcvbuf_size = 0;
  1929. /* Fill the interrupt urb and send it to the core */
  1930. endpoint = &hostif->endpoint[0].desc;
  1931. usb_fill_int_urb(ucs->urb_int_in, udev,
  1932. usb_rcvintpipe(udev,
  1933. (endpoint->bEndpointAddress) & 0x0f),
  1934. ucs->int_in_buf, 3, read_int_callback, cs,
  1935. endpoint->bInterval);
  1936. ret = usb_submit_urb(ucs->urb_int_in, SLAB_KERNEL);
  1937. if (ret) {
  1938. dev_err(cs->dev, "could not submit interrupt URB: %s\n",
  1939. get_usb_statmsg(ret));
  1940. goto error;
  1941. }
  1942. /* tell the device that the driver is ready */
  1943. if ((ret = req_submit(cs->bcs, HD_DEVICE_INIT_ACK, 0, 0)) != 0)
  1944. goto error;
  1945. /* tell common part that the device is ready */
  1946. if (startmode == SM_LOCKED)
  1947. atomic_set(&cs->mstate, MS_LOCKED);
  1948. /* save address of controller structure */
  1949. usb_set_intfdata(interface, cs);
  1950. if (!gigaset_start(cs))
  1951. goto error;
  1952. return 0;
  1953. error:
  1954. freeurbs(cs);
  1955. usb_set_intfdata(interface, NULL);
  1956. gigaset_unassign(cs);
  1957. return -ENODEV;
  1958. }
  1959. /* gigaset_disconnect
  1960. * This function is called when the Gigaset base is unplugged.
  1961. */
  1962. static void gigaset_disconnect(struct usb_interface *interface)
  1963. {
  1964. struct cardstate *cs;
  1965. struct bas_cardstate *ucs;
  1966. cs = usb_get_intfdata(interface);
  1967. ucs = cs->hw.bas;
  1968. dev_info(cs->dev, "disconnecting Gigaset base\n");
  1969. gigaset_stop(cs);
  1970. freeurbs(cs);
  1971. usb_set_intfdata(interface, NULL);
  1972. kfree(ucs->rcvbuf);
  1973. ucs->rcvbuf = NULL;
  1974. ucs->rcvbuf_size = 0;
  1975. atomic_set(&ucs->basstate, 0);
  1976. usb_put_dev(ucs->udev);
  1977. ucs->interface = NULL;
  1978. ucs->udev = NULL;
  1979. cs->dev = NULL;
  1980. gigaset_unassign(cs);
  1981. }
  1982. static struct gigaset_ops gigops = {
  1983. gigaset_write_cmd,
  1984. gigaset_write_room,
  1985. gigaset_chars_in_buffer,
  1986. gigaset_brkchars,
  1987. gigaset_init_bchannel,
  1988. gigaset_close_bchannel,
  1989. gigaset_initbcshw,
  1990. gigaset_freebcshw,
  1991. gigaset_reinitbcshw,
  1992. gigaset_initcshw,
  1993. gigaset_freecshw,
  1994. gigaset_set_modem_ctrl,
  1995. gigaset_baud_rate,
  1996. gigaset_set_line_ctrl,
  1997. gigaset_isoc_send_skb,
  1998. gigaset_isoc_input,
  1999. };
  2000. /* bas_gigaset_init
  2001. * This function is called after the kernel module is loaded.
  2002. */
  2003. static int __init bas_gigaset_init(void)
  2004. {
  2005. int result;
  2006. /* allocate memory for our driver state and intialize it */
  2007. if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
  2008. GIGASET_MODULENAME, GIGASET_DEVNAME,
  2009. GIGASET_DEVFSNAME, &gigops,
  2010. THIS_MODULE)) == NULL)
  2011. goto error;
  2012. /* allocate memory for our device state and intialize it */
  2013. cardstate = gigaset_initcs(driver, 2, 0, 0, cidmode,
  2014. GIGASET_MODULENAME);
  2015. if (!cardstate)
  2016. goto error;
  2017. /* register this driver with the USB subsystem */
  2018. result = usb_register(&gigaset_usb_driver);
  2019. if (result < 0) {
  2020. err("usb_register failed (error %d)", -result);
  2021. goto error;
  2022. }
  2023. info(DRIVER_AUTHOR);
  2024. info(DRIVER_DESC);
  2025. return 0;
  2026. error: if (cardstate)
  2027. gigaset_freecs(cardstate);
  2028. cardstate = NULL;
  2029. if (driver)
  2030. gigaset_freedriver(driver);
  2031. driver = NULL;
  2032. return -1;
  2033. }
  2034. /* bas_gigaset_exit
  2035. * This function is called before the kernel module is unloaded.
  2036. */
  2037. static void __exit bas_gigaset_exit(void)
  2038. {
  2039. gigaset_blockdriver(driver); /* => probe will fail
  2040. * => no gigaset_start any more
  2041. */
  2042. gigaset_shutdown(cardstate);
  2043. /* from now on, no isdn callback should be possible */
  2044. if (atomic_read(&cardstate->hw.bas->basstate) & BS_ATOPEN) {
  2045. gig_dbg(DEBUG_ANY, "closing AT channel");
  2046. if (req_submit(cardstate->bcs,
  2047. HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT) >= 0) {
  2048. /* successfully submitted */
  2049. //FIXME wait for completion?
  2050. }
  2051. }
  2052. /* deregister this driver with the USB subsystem */
  2053. usb_deregister(&gigaset_usb_driver);
  2054. /* this will call the disconnect-callback */
  2055. /* from now on, no disconnect/probe callback should be running */
  2056. gigaset_freecs(cardstate);
  2057. cardstate = NULL;
  2058. gigaset_freedriver(driver);
  2059. driver = NULL;
  2060. }
  2061. module_init(bas_gigaset_init);
  2062. module_exit(bas_gigaset_exit);
  2063. MODULE_AUTHOR(DRIVER_AUTHOR);
  2064. MODULE_DESCRIPTION(DRIVER_DESC);
  2065. MODULE_LICENSE("GPL");