bas-gigaset.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317
  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 <Eilers.Stefan@epost.de>.
  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 <Eilers.Stefan@epost.de>"
  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(!atomic_read(&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. if (unlikely(!atomic_read(&cs->connected))) {
  419. warn("%s: disconnected", __func__);
  420. return;
  421. }
  422. switch (urb->status) {
  423. case 0: /* success */
  424. break;
  425. case -ENOENT: /* canceled */
  426. case -ECONNRESET: /* canceled (async) */
  427. case -EINPROGRESS: /* pending */
  428. /* ignore silently */
  429. gig_dbg(DEBUG_USBREQ, "%s: %s",
  430. __func__, get_usb_statmsg(urb->status));
  431. return;
  432. default: /* severe trouble */
  433. dev_warn(cs->dev, "interrupt read: %s\n",
  434. get_usb_statmsg(urb->status));
  435. //FIXME corrective action? resubmission always ok?
  436. goto resubmit;
  437. }
  438. l = (unsigned) ucs->int_in_buf[1] +
  439. (((unsigned) ucs->int_in_buf[2]) << 8);
  440. gig_dbg(DEBUG_USBREQ, "<-------%d: 0x%02x (%u [0x%02x 0x%02x])",
  441. urb->actual_length, (int)ucs->int_in_buf[0], l,
  442. (int)ucs->int_in_buf[1], (int)ucs->int_in_buf[2]);
  443. channel = 0;
  444. switch (ucs->int_in_buf[0]) {
  445. case HD_DEVICE_INIT_OK:
  446. update_basstate(ucs, BS_INIT, 0);
  447. break;
  448. case HD_READY_SEND_ATDATA:
  449. del_timer(&ucs->timer_atrdy);
  450. update_basstate(ucs, BS_ATREADY, BS_ATTIMER);
  451. start_cbsend(cs);
  452. break;
  453. case HD_OPEN_B2CHANNEL_ACK:
  454. ++channel;
  455. case HD_OPEN_B1CHANNEL_ACK:
  456. bcs = cs->bcs + channel;
  457. update_basstate(ucs, BS_B1OPEN << channel, 0);
  458. gigaset_bchannel_up(bcs);
  459. break;
  460. case HD_OPEN_ATCHANNEL_ACK:
  461. update_basstate(ucs, BS_ATOPEN, 0);
  462. start_cbsend(cs);
  463. break;
  464. case HD_CLOSE_B2CHANNEL_ACK:
  465. ++channel;
  466. case HD_CLOSE_B1CHANNEL_ACK:
  467. bcs = cs->bcs + channel;
  468. update_basstate(ucs, 0, BS_B1OPEN << channel);
  469. stopurbs(bcs->hw.bas);
  470. gigaset_bchannel_down(bcs);
  471. break;
  472. case HD_CLOSE_ATCHANNEL_ACK:
  473. update_basstate(ucs, 0, BS_ATOPEN);
  474. break;
  475. case HD_B2_FLOW_CONTROL:
  476. ++channel;
  477. case HD_B1_FLOW_CONTROL:
  478. bcs = cs->bcs + channel;
  479. atomic_add((l - BAS_NORMFRAME) * BAS_CORRFRAMES,
  480. &bcs->hw.bas->corrbytes);
  481. gig_dbg(DEBUG_ISO,
  482. "Flow control (channel %d, sub %d): 0x%02x => %d",
  483. channel, bcs->hw.bas->numsub, l,
  484. atomic_read(&bcs->hw.bas->corrbytes));
  485. break;
  486. case HD_RECEIVEATDATA_ACK: /* AT response ready to be received */
  487. if (!l) {
  488. dev_warn(cs->dev,
  489. "HD_RECEIVEATDATA_ACK with length 0 ignored\n");
  490. break;
  491. }
  492. spin_lock_irqsave(&cs->lock, flags);
  493. if (ucs->rcvbuf_size) {
  494. spin_unlock_irqrestore(&cs->lock, flags);
  495. dev_err(cs->dev,
  496. "receive AT data overrun, %d bytes lost\n", l);
  497. error_reset(cs); //FIXME reschedule
  498. break;
  499. }
  500. if ((ucs->rcvbuf = kmalloc(l, GFP_ATOMIC)) == NULL) {
  501. spin_unlock_irqrestore(&cs->lock, flags);
  502. dev_err(cs->dev, "out of memory, %d bytes lost\n", l);
  503. error_reset(cs); //FIXME reschedule
  504. break;
  505. }
  506. ucs->rcvbuf_size = l;
  507. ucs->retry_cmd_in = 0;
  508. if ((status = atread_submit(cs, BAS_TIMEOUT)) < 0) {
  509. kfree(ucs->rcvbuf);
  510. ucs->rcvbuf = NULL;
  511. ucs->rcvbuf_size = 0;
  512. error_reset(cs); //FIXME reschedule
  513. }
  514. spin_unlock_irqrestore(&cs->lock, flags);
  515. break;
  516. case HD_RESET_INTERRUPT_PIPE_ACK:
  517. gig_dbg(DEBUG_USBREQ, "HD_RESET_INTERRUPT_PIPE_ACK");
  518. break;
  519. case HD_SUSPEND_END:
  520. gig_dbg(DEBUG_USBREQ, "HD_SUSPEND_END");
  521. break;
  522. default:
  523. dev_warn(cs->dev,
  524. "unknown Gigaset signal 0x%02x (%u) ignored\n",
  525. (int) ucs->int_in_buf[0], l);
  526. }
  527. check_pending(ucs);
  528. resubmit:
  529. status = usb_submit_urb(urb, SLAB_ATOMIC);
  530. if (unlikely(status)) {
  531. dev_err(cs->dev, "could not resubmit interrupt URB: %s\n",
  532. get_usb_statmsg(status));
  533. error_reset(cs);
  534. }
  535. }
  536. /* read_ctrl_callback
  537. * USB completion handler for control pipe input
  538. * called by the USB subsystem in interrupt context
  539. * parameter:
  540. * urb USB request block
  541. * urb->context = inbuf structure for controller state
  542. */
  543. static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
  544. {
  545. struct inbuf_t *inbuf = urb->context;
  546. struct cardstate *cs = inbuf->cs;
  547. struct bas_cardstate *ucs = cs->hw.bas;
  548. int have_data = 0;
  549. unsigned numbytes;
  550. unsigned long flags;
  551. spin_lock_irqsave(&cs->lock, flags);
  552. if (unlikely(!atomic_read(&cs->connected))) {
  553. warn("%s: disconnected", __func__);
  554. spin_unlock_irqrestore(&cs->lock, flags);
  555. return;
  556. }
  557. if (!ucs->rcvbuf_size) {
  558. dev_warn(cs->dev, "%s: no receive in progress\n", __func__);
  559. spin_unlock_irqrestore(&cs->lock, flags);
  560. return;
  561. }
  562. del_timer(&ucs->timer_cmd_in);
  563. switch (urb->status) {
  564. case 0: /* normal completion */
  565. numbytes = urb->actual_length;
  566. if (unlikely(numbytes == 0)) {
  567. dev_warn(cs->dev,
  568. "control read: empty block received\n");
  569. goto retry;
  570. }
  571. if (unlikely(numbytes != ucs->rcvbuf_size)) {
  572. dev_warn(cs->dev,
  573. "control read: received %d chars, expected %d\n",
  574. numbytes, ucs->rcvbuf_size);
  575. if (numbytes > ucs->rcvbuf_size)
  576. numbytes = ucs->rcvbuf_size;
  577. }
  578. /* copy received bytes to inbuf */
  579. have_data = gigaset_fill_inbuf(inbuf, ucs->rcvbuf, numbytes);
  580. if (unlikely(numbytes < ucs->rcvbuf_size)) {
  581. /* incomplete - resubmit for remaining bytes */
  582. ucs->rcvbuf_size -= numbytes;
  583. ucs->retry_cmd_in = 0;
  584. goto retry;
  585. }
  586. break;
  587. case -ENOENT: /* canceled */
  588. case -ECONNRESET: /* canceled (async) */
  589. case -EINPROGRESS: /* pending */
  590. /* no action necessary */
  591. gig_dbg(DEBUG_USBREQ, "%s: %s",
  592. __func__, get_usb_statmsg(urb->status));
  593. break;
  594. default: /* severe trouble */
  595. dev_warn(cs->dev, "control read: %s\n",
  596. get_usb_statmsg(urb->status));
  597. retry:
  598. if (ucs->retry_cmd_in++ < BAS_RETRY) {
  599. dev_notice(cs->dev, "control read: retry %d\n",
  600. ucs->retry_cmd_in);
  601. if (atread_submit(cs, BAS_TIMEOUT) >= 0) {
  602. /* resubmitted - bypass regular exit block */
  603. spin_unlock_irqrestore(&cs->lock, flags);
  604. return;
  605. }
  606. } else {
  607. dev_err(cs->dev,
  608. "control read: giving up after %d tries\n",
  609. ucs->retry_cmd_in);
  610. }
  611. error_reset(cs);
  612. }
  613. kfree(ucs->rcvbuf);
  614. ucs->rcvbuf = NULL;
  615. ucs->rcvbuf_size = 0;
  616. spin_unlock_irqrestore(&cs->lock, flags);
  617. if (have_data) {
  618. gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
  619. gigaset_schedule_event(cs);
  620. }
  621. }
  622. /* read_iso_callback
  623. * USB completion handler for B channel isochronous input
  624. * called by the USB subsystem in interrupt context
  625. * parameter:
  626. * urb USB request block of completed request
  627. * urb->context = bc_state structure
  628. */
  629. static void read_iso_callback(struct urb *urb, struct pt_regs *regs)
  630. {
  631. struct bc_state *bcs;
  632. struct bas_bc_state *ubc;
  633. unsigned long flags;
  634. int i, rc;
  635. /* status codes not worth bothering the tasklet with */
  636. if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET ||
  637. urb->status == -EINPROGRESS)) {
  638. gig_dbg(DEBUG_ISO, "%s: %s",
  639. __func__, get_usb_statmsg(urb->status));
  640. return;
  641. }
  642. bcs = urb->context;
  643. ubc = bcs->hw.bas;
  644. spin_lock_irqsave(&ubc->isoinlock, flags);
  645. if (likely(ubc->isoindone == NULL)) {
  646. /* pass URB to tasklet */
  647. ubc->isoindone = urb;
  648. tasklet_schedule(&ubc->rcvd_tasklet);
  649. } else {
  650. /* tasklet still busy, drop data and resubmit URB */
  651. ubc->loststatus = urb->status;
  652. for (i = 0; i < BAS_NUMFRAMES; i++) {
  653. ubc->isoinlost += urb->iso_frame_desc[i].actual_length;
  654. if (unlikely(urb->iso_frame_desc[i].status != 0 &&
  655. urb->iso_frame_desc[i].status != -EINPROGRESS)) {
  656. ubc->loststatus = urb->iso_frame_desc[i].status;
  657. }
  658. urb->iso_frame_desc[i].status = 0;
  659. urb->iso_frame_desc[i].actual_length = 0;
  660. }
  661. if (likely(atomic_read(&ubc->running))) {
  662. /* urb->dev is clobbered by USB subsystem */
  663. urb->dev = bcs->cs->hw.bas->udev;
  664. urb->transfer_flags = URB_ISO_ASAP;
  665. urb->number_of_packets = BAS_NUMFRAMES;
  666. gig_dbg(DEBUG_ISO, "%s: isoc read overrun/resubmit",
  667. __func__);
  668. rc = usb_submit_urb(urb, SLAB_ATOMIC);
  669. if (unlikely(rc != 0)) {
  670. dev_err(bcs->cs->dev,
  671. "could not resubmit isochronous read "
  672. "URB: %s\n", get_usb_statmsg(rc));
  673. dump_urb(DEBUG_ISO, "isoc read", urb);
  674. error_hangup(bcs);
  675. }
  676. }
  677. }
  678. spin_unlock_irqrestore(&ubc->isoinlock, flags);
  679. }
  680. /* write_iso_callback
  681. * USB completion handler for B channel isochronous output
  682. * called by the USB subsystem in interrupt context
  683. * parameter:
  684. * urb USB request block of completed request
  685. * urb->context = isow_urbctx_t structure
  686. */
  687. static void write_iso_callback(struct urb *urb, struct pt_regs *regs)
  688. {
  689. struct isow_urbctx_t *ucx;
  690. struct bas_bc_state *ubc;
  691. unsigned long flags;
  692. /* status codes not worth bothering the tasklet with */
  693. if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET ||
  694. urb->status == -EINPROGRESS)) {
  695. gig_dbg(DEBUG_ISO, "%s: %s",
  696. __func__, get_usb_statmsg(urb->status));
  697. return;
  698. }
  699. /* pass URB context to tasklet */
  700. ucx = urb->context;
  701. ubc = ucx->bcs->hw.bas;
  702. spin_lock_irqsave(&ubc->isooutlock, flags);
  703. ubc->isooutovfl = ubc->isooutdone;
  704. ubc->isooutdone = ucx;
  705. spin_unlock_irqrestore(&ubc->isooutlock, flags);
  706. tasklet_schedule(&ubc->sent_tasklet);
  707. }
  708. /* starturbs
  709. * prepare and submit USB request blocks for isochronous input and output
  710. * argument:
  711. * B channel control structure
  712. * return value:
  713. * 0 on success
  714. * < 0 on error (no URBs submitted)
  715. */
  716. static int starturbs(struct bc_state *bcs)
  717. {
  718. struct bas_bc_state *ubc = bcs->hw.bas;
  719. struct urb *urb;
  720. int j, k;
  721. int rc;
  722. /* initialize L2 reception */
  723. if (bcs->proto2 == ISDN_PROTO_L2_HDLC)
  724. bcs->inputstate |= INS_flag_hunt;
  725. /* submit all isochronous input URBs */
  726. atomic_set(&ubc->running, 1);
  727. for (k = 0; k < BAS_INURBS; k++) {
  728. urb = ubc->isoinurbs[k];
  729. if (!urb) {
  730. dev_err(bcs->cs->dev, "isoinurbs[%d]==NULL\n", k);
  731. rc = -EFAULT;
  732. goto error;
  733. }
  734. urb->dev = bcs->cs->hw.bas->udev;
  735. urb->pipe = usb_rcvisocpipe(urb->dev, 3 + 2 * bcs->channel);
  736. urb->transfer_flags = URB_ISO_ASAP;
  737. urb->transfer_buffer = ubc->isoinbuf + k * BAS_INBUFSIZE;
  738. urb->transfer_buffer_length = BAS_INBUFSIZE;
  739. urb->number_of_packets = BAS_NUMFRAMES;
  740. urb->interval = BAS_FRAMETIME;
  741. urb->complete = read_iso_callback;
  742. urb->context = bcs;
  743. for (j = 0; j < BAS_NUMFRAMES; j++) {
  744. urb->iso_frame_desc[j].offset = j * BAS_MAXFRAME;
  745. urb->iso_frame_desc[j].length = BAS_MAXFRAME;
  746. urb->iso_frame_desc[j].status = 0;
  747. urb->iso_frame_desc[j].actual_length = 0;
  748. }
  749. dump_urb(DEBUG_ISO, "Initial isoc read", urb);
  750. if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) {
  751. dev_err(bcs->cs->dev,
  752. "could not submit isochronous read URB %d: %s\n",
  753. k, get_usb_statmsg(rc));
  754. goto error;
  755. }
  756. }
  757. /* initialize L2 transmission */
  758. gigaset_isowbuf_init(ubc->isooutbuf, PPP_FLAG);
  759. /* set up isochronous output URBs for flag idling */
  760. for (k = 0; k < BAS_OUTURBS; ++k) {
  761. urb = ubc->isoouturbs[k].urb;
  762. if (!urb) {
  763. dev_err(bcs->cs->dev, "isoouturbs[%d].urb==NULL\n", k);
  764. rc = -EFAULT;
  765. goto error;
  766. }
  767. urb->dev = bcs->cs->hw.bas->udev;
  768. urb->pipe = usb_sndisocpipe(urb->dev, 4 + 2 * bcs->channel);
  769. urb->transfer_flags = URB_ISO_ASAP;
  770. urb->transfer_buffer = ubc->isooutbuf->data;
  771. urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data);
  772. urb->number_of_packets = BAS_NUMFRAMES;
  773. urb->interval = BAS_FRAMETIME;
  774. urb->complete = write_iso_callback;
  775. urb->context = &ubc->isoouturbs[k];
  776. for (j = 0; j < BAS_NUMFRAMES; ++j) {
  777. urb->iso_frame_desc[j].offset = BAS_OUTBUFSIZE;
  778. urb->iso_frame_desc[j].length = BAS_NORMFRAME;
  779. urb->iso_frame_desc[j].status = 0;
  780. urb->iso_frame_desc[j].actual_length = 0;
  781. }
  782. ubc->isoouturbs[k].limit = -1;
  783. }
  784. /* submit two URBs, keep third one */
  785. for (k = 0; k < 2; ++k) {
  786. dump_urb(DEBUG_ISO, "Initial isoc write", urb);
  787. rc = usb_submit_urb(ubc->isoouturbs[k].urb, SLAB_ATOMIC);
  788. if (rc != 0) {
  789. dev_err(bcs->cs->dev,
  790. "could not submit isochronous write URB %d: %s\n",
  791. k, get_usb_statmsg(rc));
  792. goto error;
  793. }
  794. }
  795. dump_urb(DEBUG_ISO, "Initial isoc write (free)", urb);
  796. ubc->isooutfree = &ubc->isoouturbs[2];
  797. ubc->isooutdone = ubc->isooutovfl = NULL;
  798. return 0;
  799. error:
  800. stopurbs(ubc);
  801. return rc;
  802. }
  803. /* stopurbs
  804. * cancel the USB request blocks for isochronous input and output
  805. * errors are silently ignored
  806. * argument:
  807. * B channel control structure
  808. */
  809. static void stopurbs(struct bas_bc_state *ubc)
  810. {
  811. int k, rc;
  812. atomic_set(&ubc->running, 0);
  813. for (k = 0; k < BAS_INURBS; ++k) {
  814. rc = usb_unlink_urb(ubc->isoinurbs[k]);
  815. gig_dbg(DEBUG_ISO,
  816. "%s: isoc input URB %d unlinked, result = %d",
  817. __func__, k, rc);
  818. }
  819. for (k = 0; k < BAS_OUTURBS; ++k) {
  820. rc = usb_unlink_urb(ubc->isoouturbs[k].urb);
  821. gig_dbg(DEBUG_ISO,
  822. "%s: isoc output URB %d unlinked, result = %d",
  823. __func__, k, rc);
  824. }
  825. }
  826. /* Isochronous Write - Bottom Half */
  827. /* =============================== */
  828. /* submit_iso_write_urb
  829. * fill and submit the next isochronous write URB
  830. * parameters:
  831. * bcs B channel state structure
  832. * return value:
  833. * number of frames submitted in URB
  834. * 0 if URB not submitted because no data available (isooutbuf busy)
  835. * error code < 0 on error
  836. */
  837. static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
  838. {
  839. struct urb *urb = ucx->urb;
  840. struct bas_bc_state *ubc = ucx->bcs->hw.bas;
  841. struct usb_iso_packet_descriptor *ifd;
  842. int corrbytes, nframe, rc;
  843. /* urb->dev is clobbered by USB subsystem */
  844. urb->dev = ucx->bcs->cs->hw.bas->udev;
  845. urb->transfer_flags = URB_ISO_ASAP;
  846. urb->transfer_buffer = ubc->isooutbuf->data;
  847. urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data);
  848. for (nframe = 0; nframe < BAS_NUMFRAMES; nframe++) {
  849. ifd = &urb->iso_frame_desc[nframe];
  850. /* compute frame length according to flow control */
  851. ifd->length = BAS_NORMFRAME;
  852. if ((corrbytes = atomic_read(&ubc->corrbytes)) != 0) {
  853. gig_dbg(DEBUG_ISO, "%s: corrbytes=%d",
  854. __func__, corrbytes);
  855. if (corrbytes > BAS_HIGHFRAME - BAS_NORMFRAME)
  856. corrbytes = BAS_HIGHFRAME - BAS_NORMFRAME;
  857. else if (corrbytes < BAS_LOWFRAME - BAS_NORMFRAME)
  858. corrbytes = BAS_LOWFRAME - BAS_NORMFRAME;
  859. ifd->length += corrbytes;
  860. atomic_add(-corrbytes, &ubc->corrbytes);
  861. }
  862. /* retrieve block of data to send */
  863. ifd->offset = gigaset_isowbuf_getbytes(ubc->isooutbuf,
  864. ifd->length);
  865. if (ifd->offset < 0) {
  866. if (ifd->offset == -EBUSY) {
  867. gig_dbg(DEBUG_ISO,
  868. "%s: buffer busy at frame %d",
  869. __func__, nframe);
  870. /* tasklet will be restarted from
  871. gigaset_send_skb() */
  872. } else {
  873. dev_err(ucx->bcs->cs->dev,
  874. "%s: buffer error %d at frame %d\n",
  875. __func__, ifd->offset, nframe);
  876. return ifd->offset;
  877. }
  878. break;
  879. }
  880. ucx->limit = atomic_read(&ubc->isooutbuf->nextread);
  881. ifd->status = 0;
  882. ifd->actual_length = 0;
  883. }
  884. if ((urb->number_of_packets = nframe) > 0) {
  885. if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) {
  886. dev_err(ucx->bcs->cs->dev,
  887. "could not submit isochronous write URB: %s\n",
  888. get_usb_statmsg(rc));
  889. dump_urb(DEBUG_ISO, "isoc write", urb);
  890. return rc;
  891. }
  892. ++ubc->numsub;
  893. }
  894. return nframe;
  895. }
  896. /* write_iso_tasklet
  897. * tasklet scheduled when an isochronous output URB from the Gigaset device
  898. * has completed
  899. * parameter:
  900. * data B channel state structure
  901. */
  902. static void write_iso_tasklet(unsigned long data)
  903. {
  904. struct bc_state *bcs = (struct bc_state *) data;
  905. struct bas_bc_state *ubc = bcs->hw.bas;
  906. struct cardstate *cs = bcs->cs;
  907. struct isow_urbctx_t *done, *next, *ovfl;
  908. struct urb *urb;
  909. struct usb_iso_packet_descriptor *ifd;
  910. int offset;
  911. unsigned long flags;
  912. int i;
  913. struct sk_buff *skb;
  914. int len;
  915. /* loop while completed URBs arrive in time */
  916. for (;;) {
  917. if (unlikely(!atomic_read(&cs->connected))) {
  918. warn("%s: disconnected", __func__);
  919. return;
  920. }
  921. if (unlikely(!(atomic_read(&ubc->running)))) {
  922. gig_dbg(DEBUG_ISO, "%s: not running", __func__);
  923. return;
  924. }
  925. /* retrieve completed URBs */
  926. spin_lock_irqsave(&ubc->isooutlock, flags);
  927. done = ubc->isooutdone;
  928. ubc->isooutdone = NULL;
  929. ovfl = ubc->isooutovfl;
  930. ubc->isooutovfl = NULL;
  931. spin_unlock_irqrestore(&ubc->isooutlock, flags);
  932. if (ovfl) {
  933. dev_err(cs->dev, "isochronous write buffer underrun\n");
  934. error_hangup(bcs);
  935. break;
  936. }
  937. if (!done)
  938. break;
  939. /* submit free URB if available */
  940. spin_lock_irqsave(&ubc->isooutlock, flags);
  941. next = ubc->isooutfree;
  942. ubc->isooutfree = NULL;
  943. spin_unlock_irqrestore(&ubc->isooutlock, flags);
  944. if (next) {
  945. if (submit_iso_write_urb(next) <= 0) {
  946. /* could not submit URB, put it back */
  947. spin_lock_irqsave(&ubc->isooutlock, flags);
  948. if (ubc->isooutfree == NULL) {
  949. ubc->isooutfree = next;
  950. next = NULL;
  951. }
  952. spin_unlock_irqrestore(&ubc->isooutlock, flags);
  953. if (next) {
  954. /* couldn't put it back */
  955. dev_err(cs->dev,
  956. "losing isochronous write URB\n");
  957. error_hangup(bcs);
  958. }
  959. }
  960. }
  961. /* process completed URB */
  962. urb = done->urb;
  963. switch (urb->status) {
  964. case 0: /* normal completion */
  965. break;
  966. case -EXDEV: /* inspect individual frames */
  967. /* assumptions (for lack of documentation):
  968. * - actual_length bytes of the frame in error are
  969. * successfully sent
  970. * - all following frames are not sent at all
  971. */
  972. gig_dbg(DEBUG_ISO, "%s: URB partially completed",
  973. __func__);
  974. offset = done->limit; /* just in case */
  975. for (i = 0; i < BAS_NUMFRAMES; i++) {
  976. ifd = &urb->iso_frame_desc[i];
  977. if (ifd->status ||
  978. ifd->actual_length != ifd->length) {
  979. dev_warn(cs->dev,
  980. "isochronous write: frame %d: %s, "
  981. "only %d of %d bytes sent\n",
  982. i, get_usb_statmsg(ifd->status),
  983. ifd->actual_length, ifd->length);
  984. offset = (ifd->offset +
  985. ifd->actual_length)
  986. % BAS_OUTBUFSIZE;
  987. break;
  988. }
  989. }
  990. #ifdef CONFIG_GIGASET_DEBUG
  991. /* check assumption on remaining frames */
  992. for (; i < BAS_NUMFRAMES; i++) {
  993. ifd = &urb->iso_frame_desc[i];
  994. if (ifd->status != -EINPROGRESS
  995. || ifd->actual_length != 0) {
  996. dev_warn(cs->dev,
  997. "isochronous write: frame %d: %s, "
  998. "%d of %d bytes sent\n",
  999. i, get_usb_statmsg(ifd->status),
  1000. ifd->actual_length, ifd->length);
  1001. offset = (ifd->offset +
  1002. ifd->actual_length)
  1003. % BAS_OUTBUFSIZE;
  1004. break;
  1005. }
  1006. }
  1007. #endif
  1008. break;
  1009. case -EPIPE: //FIXME is this the code for "underrun"?
  1010. dev_err(cs->dev, "isochronous write stalled\n");
  1011. error_hangup(bcs);
  1012. break;
  1013. default: /* severe trouble */
  1014. dev_warn(cs->dev, "isochronous write: %s\n",
  1015. get_usb_statmsg(urb->status));
  1016. }
  1017. /* mark the write buffer area covered by this URB as free */
  1018. if (done->limit >= 0)
  1019. atomic_set(&ubc->isooutbuf->read, done->limit);
  1020. /* mark URB as free */
  1021. spin_lock_irqsave(&ubc->isooutlock, flags);
  1022. next = ubc->isooutfree;
  1023. ubc->isooutfree = done;
  1024. spin_unlock_irqrestore(&ubc->isooutlock, flags);
  1025. if (next) {
  1026. /* only one URB still active - resubmit one */
  1027. if (submit_iso_write_urb(next) <= 0) {
  1028. /* couldn't submit */
  1029. error_hangup(bcs);
  1030. }
  1031. }
  1032. }
  1033. /* process queued SKBs */
  1034. while ((skb = skb_dequeue(&bcs->squeue))) {
  1035. /* copy to output buffer, doing L2 encapsulation */
  1036. len = skb->len;
  1037. if (gigaset_isoc_buildframe(bcs, skb->data, len) == -EAGAIN) {
  1038. /* insufficient buffer space, push back onto queue */
  1039. skb_queue_head(&bcs->squeue, skb);
  1040. gig_dbg(DEBUG_ISO, "%s: skb requeued, qlen=%d",
  1041. __func__, skb_queue_len(&bcs->squeue));
  1042. break;
  1043. }
  1044. skb_pull(skb, len);
  1045. gigaset_skb_sent(bcs, skb);
  1046. dev_kfree_skb_any(skb);
  1047. }
  1048. }
  1049. /* Isochronous Read - Bottom Half */
  1050. /* ============================== */
  1051. /* read_iso_tasklet
  1052. * tasklet scheduled when an isochronous input URB from the Gigaset device
  1053. * has completed
  1054. * parameter:
  1055. * data B channel state structure
  1056. */
  1057. static void read_iso_tasklet(unsigned long data)
  1058. {
  1059. struct bc_state *bcs = (struct bc_state *) data;
  1060. struct bas_bc_state *ubc = bcs->hw.bas;
  1061. struct cardstate *cs = bcs->cs;
  1062. struct urb *urb;
  1063. char *rcvbuf;
  1064. unsigned long flags;
  1065. int totleft, numbytes, offset, frame, rc;
  1066. /* loop while more completed URBs arrive in the meantime */
  1067. for (;;) {
  1068. if (unlikely(!atomic_read(&cs->connected))) {
  1069. warn("%s: disconnected", __func__);
  1070. return;
  1071. }
  1072. /* retrieve URB */
  1073. spin_lock_irqsave(&ubc->isoinlock, flags);
  1074. if (!(urb = ubc->isoindone)) {
  1075. spin_unlock_irqrestore(&ubc->isoinlock, flags);
  1076. return;
  1077. }
  1078. ubc->isoindone = NULL;
  1079. if (unlikely(ubc->loststatus != -EINPROGRESS)) {
  1080. dev_warn(cs->dev,
  1081. "isochronous read overrun, "
  1082. "dropped URB with status: %s, %d bytes lost\n",
  1083. get_usb_statmsg(ubc->loststatus),
  1084. ubc->isoinlost);
  1085. ubc->loststatus = -EINPROGRESS;
  1086. }
  1087. spin_unlock_irqrestore(&ubc->isoinlock, flags);
  1088. if (unlikely(!(atomic_read(&ubc->running)))) {
  1089. gig_dbg(DEBUG_ISO,
  1090. "%s: channel not running, "
  1091. "dropped URB with status: %s",
  1092. __func__, get_usb_statmsg(urb->status));
  1093. return;
  1094. }
  1095. switch (urb->status) {
  1096. case 0: /* normal completion */
  1097. break;
  1098. case -EXDEV: /* inspect individual frames
  1099. (we do that anyway) */
  1100. gig_dbg(DEBUG_ISO, "%s: URB partially completed",
  1101. __func__);
  1102. break;
  1103. case -ENOENT:
  1104. case -ECONNRESET:
  1105. gig_dbg(DEBUG_ISO, "%s: URB canceled", __func__);
  1106. continue; /* -> skip */
  1107. case -EINPROGRESS: /* huh? */
  1108. gig_dbg(DEBUG_ISO, "%s: URB still pending", __func__);
  1109. continue; /* -> skip */
  1110. case -EPIPE:
  1111. dev_err(cs->dev, "isochronous read stalled\n");
  1112. error_hangup(bcs);
  1113. continue; /* -> skip */
  1114. default: /* severe trouble */
  1115. dev_warn(cs->dev, "isochronous read: %s\n",
  1116. get_usb_statmsg(urb->status));
  1117. goto error;
  1118. }
  1119. rcvbuf = urb->transfer_buffer;
  1120. totleft = urb->actual_length;
  1121. for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) {
  1122. if (unlikely(urb->iso_frame_desc[frame].status)) {
  1123. dev_warn(cs->dev,
  1124. "isochronous read: frame %d: %s\n",
  1125. frame,
  1126. get_usb_statmsg(
  1127. urb->iso_frame_desc[frame].status));
  1128. break;
  1129. }
  1130. numbytes = urb->iso_frame_desc[frame].actual_length;
  1131. if (unlikely(numbytes > BAS_MAXFRAME)) {
  1132. dev_warn(cs->dev,
  1133. "isochronous read: frame %d: "
  1134. "numbytes (%d) > BAS_MAXFRAME\n",
  1135. frame, numbytes);
  1136. break;
  1137. }
  1138. if (unlikely(numbytes > totleft)) {
  1139. dev_warn(cs->dev,
  1140. "isochronous read: frame %d: "
  1141. "numbytes (%d) > totleft (%d)\n",
  1142. frame, numbytes, totleft);
  1143. break;
  1144. }
  1145. offset = urb->iso_frame_desc[frame].offset;
  1146. if (unlikely(offset + numbytes > BAS_INBUFSIZE)) {
  1147. dev_warn(cs->dev,
  1148. "isochronous read: frame %d: "
  1149. "offset (%d) + numbytes (%d) "
  1150. "> BAS_INBUFSIZE\n",
  1151. frame, offset, numbytes);
  1152. break;
  1153. }
  1154. gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs);
  1155. totleft -= numbytes;
  1156. }
  1157. if (unlikely(totleft > 0))
  1158. dev_warn(cs->dev,
  1159. "isochronous read: %d data bytes missing\n",
  1160. totleft);
  1161. error:
  1162. /* URB processed, resubmit */
  1163. for (frame = 0; frame < BAS_NUMFRAMES; frame++) {
  1164. urb->iso_frame_desc[frame].status = 0;
  1165. urb->iso_frame_desc[frame].actual_length = 0;
  1166. }
  1167. /* urb->dev is clobbered by USB subsystem */
  1168. urb->dev = bcs->cs->hw.bas->udev;
  1169. urb->transfer_flags = URB_ISO_ASAP;
  1170. urb->number_of_packets = BAS_NUMFRAMES;
  1171. if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) {
  1172. dev_err(cs->dev,
  1173. "could not resubmit isochronous read URB: %s\n",
  1174. get_usb_statmsg(rc));
  1175. dump_urb(DEBUG_ISO, "resubmit iso read", urb);
  1176. error_hangup(bcs);
  1177. }
  1178. }
  1179. }
  1180. /* Channel Operations */
  1181. /* ================== */
  1182. /* req_timeout
  1183. * timeout routine for control output request
  1184. * argument:
  1185. * B channel control structure
  1186. */
  1187. static void req_timeout(unsigned long data)
  1188. {
  1189. struct bc_state *bcs = (struct bc_state *) data;
  1190. struct bas_cardstate *ucs = bcs->cs->hw.bas;
  1191. int pending;
  1192. unsigned long flags;
  1193. check_pending(ucs);
  1194. spin_lock_irqsave(&ucs->lock, flags);
  1195. pending = ucs->pending;
  1196. ucs->pending = 0;
  1197. spin_unlock_irqrestore(&ucs->lock, flags);
  1198. switch (pending) {
  1199. case 0: /* no pending request */
  1200. gig_dbg(DEBUG_USBREQ, "%s: no request pending", __func__);
  1201. break;
  1202. case HD_OPEN_ATCHANNEL:
  1203. dev_err(bcs->cs->dev, "timeout opening AT channel\n");
  1204. error_reset(bcs->cs);
  1205. break;
  1206. case HD_OPEN_B2CHANNEL:
  1207. case HD_OPEN_B1CHANNEL:
  1208. dev_err(bcs->cs->dev, "timeout opening channel %d\n",
  1209. bcs->channel + 1);
  1210. error_hangup(bcs);
  1211. break;
  1212. case HD_CLOSE_ATCHANNEL:
  1213. dev_err(bcs->cs->dev, "timeout closing AT channel\n");
  1214. break;
  1215. case HD_CLOSE_B2CHANNEL:
  1216. case HD_CLOSE_B1CHANNEL:
  1217. dev_err(bcs->cs->dev, "timeout closing channel %d\n",
  1218. bcs->channel + 1);
  1219. break;
  1220. default:
  1221. dev_warn(bcs->cs->dev, "request 0x%02x timed out, clearing\n",
  1222. pending);
  1223. }
  1224. }
  1225. /* write_ctrl_callback
  1226. * USB completion handler for control pipe output
  1227. * called by the USB subsystem in interrupt context
  1228. * parameter:
  1229. * urb USB request block of completed request
  1230. * urb->context = hardware specific controller state structure
  1231. */
  1232. static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs)
  1233. {
  1234. struct bas_cardstate *ucs = urb->context;
  1235. unsigned long flags;
  1236. spin_lock_irqsave(&ucs->lock, flags);
  1237. if (urb->status && ucs->pending) {
  1238. dev_err(&ucs->interface->dev,
  1239. "control request 0x%02x failed: %s\n",
  1240. ucs->pending, get_usb_statmsg(urb->status));
  1241. del_timer(&ucs->timer_ctrl);
  1242. ucs->pending = 0;
  1243. }
  1244. /* individual handling of specific request types */
  1245. switch (ucs->pending) {
  1246. case HD_DEVICE_INIT_ACK: /* no reply expected */
  1247. ucs->pending = 0;
  1248. break;
  1249. }
  1250. spin_unlock_irqrestore(&ucs->lock, flags);
  1251. }
  1252. /* req_submit
  1253. * submit a control output request without message buffer to the Gigaset base
  1254. * and optionally start a timeout
  1255. * parameters:
  1256. * bcs B channel control structure
  1257. * req control request code (HD_*)
  1258. * val control request parameter value (set to 0 if unused)
  1259. * timeout timeout in seconds (0: no timeout)
  1260. * return value:
  1261. * 0 on success
  1262. * -EINVAL if a NULL pointer is encountered somewhere
  1263. * -EBUSY if another request is pending
  1264. * any URB submission error code
  1265. */
  1266. static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
  1267. {
  1268. struct bas_cardstate *ucs = bcs->cs->hw.bas;
  1269. int ret;
  1270. unsigned long flags;
  1271. gig_dbg(DEBUG_USBREQ, "-------> 0x%02x (%d)", req, val);
  1272. spin_lock_irqsave(&ucs->lock, flags);
  1273. if (ucs->pending) {
  1274. spin_unlock_irqrestore(&ucs->lock, flags);
  1275. dev_err(bcs->cs->dev,
  1276. "submission of request 0x%02x failed: "
  1277. "request 0x%02x still pending\n",
  1278. req, ucs->pending);
  1279. return -EBUSY;
  1280. }
  1281. if (ucs->urb_ctrl->status == -EINPROGRESS) {
  1282. spin_unlock_irqrestore(&ucs->lock, flags);
  1283. dev_err(bcs->cs->dev,
  1284. "could not submit request 0x%02x: URB busy\n", req);
  1285. return -EBUSY;
  1286. }
  1287. ucs->dr_ctrl.bRequestType = OUT_VENDOR_REQ;
  1288. ucs->dr_ctrl.bRequest = req;
  1289. ucs->dr_ctrl.wValue = cpu_to_le16(val);
  1290. ucs->dr_ctrl.wIndex = 0;
  1291. ucs->dr_ctrl.wLength = 0;
  1292. usb_fill_control_urb(ucs->urb_ctrl, ucs->udev,
  1293. usb_sndctrlpipe(ucs->udev, 0),
  1294. (unsigned char*) &ucs->dr_ctrl, NULL, 0,
  1295. write_ctrl_callback, ucs);
  1296. if ((ret = usb_submit_urb(ucs->urb_ctrl, SLAB_ATOMIC)) != 0) {
  1297. dev_err(bcs->cs->dev, "could not submit request 0x%02x: %s\n",
  1298. req, get_usb_statmsg(ret));
  1299. spin_unlock_irqrestore(&ucs->lock, flags);
  1300. return ret;
  1301. }
  1302. ucs->pending = req;
  1303. if (timeout > 0) {
  1304. gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
  1305. ucs->timer_ctrl.expires = jiffies + timeout * HZ / 10;
  1306. ucs->timer_ctrl.data = (unsigned long) bcs;
  1307. ucs->timer_ctrl.function = req_timeout;
  1308. add_timer(&ucs->timer_ctrl);
  1309. }
  1310. spin_unlock_irqrestore(&ucs->lock, flags);
  1311. return 0;
  1312. }
  1313. /* gigaset_init_bchannel
  1314. * called by common.c to connect a B channel
  1315. * initialize isochronous I/O and tell the Gigaset base to open the channel
  1316. * argument:
  1317. * B channel control structure
  1318. * return value:
  1319. * 0 on success, error code < 0 on error
  1320. */
  1321. static int gigaset_init_bchannel(struct bc_state *bcs)
  1322. {
  1323. int req, ret;
  1324. if ((ret = starturbs(bcs)) < 0) {
  1325. dev_err(bcs->cs->dev,
  1326. "could not start isochronous I/O for channel %d\n",
  1327. bcs->channel + 1);
  1328. error_hangup(bcs);
  1329. return ret;
  1330. }
  1331. req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL;
  1332. if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) {
  1333. dev_err(bcs->cs->dev, "could not open channel %d: %s\n",
  1334. bcs->channel + 1, get_usb_statmsg(ret));
  1335. stopurbs(bcs->hw.bas);
  1336. error_hangup(bcs);
  1337. }
  1338. return ret;
  1339. }
  1340. /* gigaset_close_bchannel
  1341. * called by common.c to disconnect a B channel
  1342. * tell the Gigaset base to close the channel
  1343. * stopping isochronous I/O and LL notification will be done when the
  1344. * acknowledgement for the close arrives
  1345. * argument:
  1346. * B channel control structure
  1347. * return value:
  1348. * 0 on success, error code < 0 on error
  1349. */
  1350. static int gigaset_close_bchannel(struct bc_state *bcs)
  1351. {
  1352. int req, ret;
  1353. if (!(atomic_read(&bcs->cs->hw.bas->basstate) &
  1354. (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) {
  1355. /* channel not running: just signal common.c */
  1356. gigaset_bchannel_down(bcs);
  1357. return 0;
  1358. }
  1359. req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL;
  1360. if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0)
  1361. dev_err(bcs->cs->dev,
  1362. "could not submit HD_CLOSE_BxCHANNEL request: %s\n",
  1363. get_usb_statmsg(ret));
  1364. return ret;
  1365. }
  1366. /* Device Operations */
  1367. /* ================= */
  1368. /* complete_cb
  1369. * unqueue first command buffer from queue, waking any sleepers
  1370. * must be called with cs->cmdlock held
  1371. * parameter:
  1372. * cs controller state structure
  1373. */
  1374. static void complete_cb(struct cardstate *cs)
  1375. {
  1376. struct cmdbuf_t *cb = cs->cmdbuf;
  1377. /* unqueue completed buffer */
  1378. cs->cmdbytes -= cs->curlen;
  1379. gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD,
  1380. "write_command: sent %u bytes, %u left",
  1381. cs->curlen, cs->cmdbytes);
  1382. if ((cs->cmdbuf = cb->next) != NULL) {
  1383. cs->cmdbuf->prev = NULL;
  1384. cs->curlen = cs->cmdbuf->len;
  1385. } else {
  1386. cs->lastcmdbuf = NULL;
  1387. cs->curlen = 0;
  1388. }
  1389. if (cb->wake_tasklet)
  1390. tasklet_schedule(cb->wake_tasklet);
  1391. kfree(cb);
  1392. }
  1393. static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len);
  1394. /* write_command_callback
  1395. * USB completion handler for AT command transmission
  1396. * called by the USB subsystem in interrupt context
  1397. * parameter:
  1398. * urb USB request block of completed request
  1399. * urb->context = controller state structure
  1400. */
  1401. static void write_command_callback(struct urb *urb, struct pt_regs *regs)
  1402. {
  1403. struct cardstate *cs = urb->context;
  1404. struct bas_cardstate *ucs = cs->hw.bas;
  1405. unsigned long flags;
  1406. /* check status */
  1407. switch (urb->status) {
  1408. case 0: /* normal completion */
  1409. break;
  1410. case -ENOENT: /* canceled */
  1411. case -ECONNRESET: /* canceled (async) */
  1412. case -EINPROGRESS: /* pending */
  1413. /* ignore silently */
  1414. gig_dbg(DEBUG_USBREQ, "%s: %s",
  1415. __func__, get_usb_statmsg(urb->status));
  1416. return;
  1417. default: /* any failure */
  1418. if (++ucs->retry_cmd_out > BAS_RETRY) {
  1419. dev_warn(cs->dev,
  1420. "command write: %s, "
  1421. "giving up after %d retries\n",
  1422. get_usb_statmsg(urb->status),
  1423. ucs->retry_cmd_out);
  1424. break;
  1425. }
  1426. if (cs->cmdbuf == NULL) {
  1427. dev_warn(cs->dev,
  1428. "command write: %s, "
  1429. "cannot retry - cmdbuf gone\n",
  1430. get_usb_statmsg(urb->status));
  1431. break;
  1432. }
  1433. dev_notice(cs->dev, "command write: %s, retry %d\n",
  1434. get_usb_statmsg(urb->status), ucs->retry_cmd_out);
  1435. if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0)
  1436. /* resubmitted - bypass regular exit block */
  1437. return;
  1438. /* command send failed, assume base still waiting */
  1439. update_basstate(ucs, BS_ATREADY, 0);
  1440. }
  1441. spin_lock_irqsave(&cs->cmdlock, flags);
  1442. if (cs->cmdbuf != NULL)
  1443. complete_cb(cs);
  1444. spin_unlock_irqrestore(&cs->cmdlock, flags);
  1445. }
  1446. /* atrdy_timeout
  1447. * timeout routine for AT command transmission
  1448. * argument:
  1449. * controller state structure
  1450. */
  1451. static void atrdy_timeout(unsigned long data)
  1452. {
  1453. struct cardstate *cs = (struct cardstate *) data;
  1454. struct bas_cardstate *ucs = cs->hw.bas;
  1455. dev_warn(cs->dev, "timeout waiting for HD_READY_SEND_ATDATA\n");
  1456. /* fake the missing signal - what else can I do? */
  1457. update_basstate(ucs, BS_ATREADY, BS_ATTIMER);
  1458. start_cbsend(cs);
  1459. }
  1460. /* atwrite_submit
  1461. * submit an HD_WRITE_ATMESSAGE command URB
  1462. * parameters:
  1463. * cs controller state structure
  1464. * buf buffer containing command to send
  1465. * len length of command to send
  1466. * return value:
  1467. * 0 on success
  1468. * -EFAULT if a NULL pointer is encountered somewhere
  1469. * -EBUSY if another request is pending
  1470. * any URB submission error code
  1471. */
  1472. static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
  1473. {
  1474. struct bas_cardstate *ucs = cs->hw.bas;
  1475. int ret;
  1476. gig_dbg(DEBUG_USBREQ, "-------> HD_WRITE_ATMESSAGE (%d)", len);
  1477. if (ucs->urb_cmd_out->status == -EINPROGRESS) {
  1478. dev_err(cs->dev,
  1479. "could not submit HD_WRITE_ATMESSAGE: URB busy\n");
  1480. return -EBUSY;
  1481. }
  1482. ucs->dr_cmd_out.bRequestType = OUT_VENDOR_REQ;
  1483. ucs->dr_cmd_out.bRequest = HD_WRITE_ATMESSAGE;
  1484. ucs->dr_cmd_out.wValue = 0;
  1485. ucs->dr_cmd_out.wIndex = 0;
  1486. ucs->dr_cmd_out.wLength = cpu_to_le16(len);
  1487. usb_fill_control_urb(ucs->urb_cmd_out, ucs->udev,
  1488. usb_sndctrlpipe(ucs->udev, 0),
  1489. (unsigned char*) &ucs->dr_cmd_out, buf, len,
  1490. write_command_callback, cs);
  1491. if ((ret = usb_submit_urb(ucs->urb_cmd_out, SLAB_ATOMIC)) != 0) {
  1492. dev_err(cs->dev, "could not submit HD_WRITE_ATMESSAGE: %s\n",
  1493. get_usb_statmsg(ret));
  1494. return ret;
  1495. }
  1496. /* submitted successfully */
  1497. update_basstate(ucs, 0, BS_ATREADY);
  1498. /* start timeout if necessary */
  1499. if (!(atomic_read(&ucs->basstate) & BS_ATTIMER)) {
  1500. gig_dbg(DEBUG_OUTPUT, "setting ATREADY timeout of %d/10 secs",
  1501. ATRDY_TIMEOUT);
  1502. ucs->timer_atrdy.expires = jiffies + ATRDY_TIMEOUT * HZ / 10;
  1503. ucs->timer_atrdy.data = (unsigned long) cs;
  1504. ucs->timer_atrdy.function = atrdy_timeout;
  1505. add_timer(&ucs->timer_atrdy);
  1506. update_basstate(ucs, BS_ATTIMER, 0);
  1507. }
  1508. return 0;
  1509. }
  1510. /* start_cbsend
  1511. * start transmission of AT command queue if necessary
  1512. * parameter:
  1513. * cs controller state structure
  1514. * return value:
  1515. * 0 on success
  1516. * error code < 0 on error
  1517. */
  1518. static int start_cbsend(struct cardstate *cs)
  1519. {
  1520. struct cmdbuf_t *cb;
  1521. struct bas_cardstate *ucs = cs->hw.bas;
  1522. unsigned long flags;
  1523. int rc;
  1524. int retval = 0;
  1525. /* check if AT channel is open */
  1526. if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) {
  1527. gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD, "AT channel not open");
  1528. rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT);
  1529. if (rc < 0) {
  1530. dev_err(cs->dev, "could not open AT channel\n");
  1531. /* flush command queue */
  1532. spin_lock_irqsave(&cs->cmdlock, flags);
  1533. while (cs->cmdbuf != NULL)
  1534. complete_cb(cs);
  1535. spin_unlock_irqrestore(&cs->cmdlock, flags);
  1536. }
  1537. return rc;
  1538. }
  1539. /* try to send first command in queue */
  1540. spin_lock_irqsave(&cs->cmdlock, flags);
  1541. while ((cb = cs->cmdbuf) != NULL &&
  1542. atomic_read(&ucs->basstate) & BS_ATREADY) {
  1543. ucs->retry_cmd_out = 0;
  1544. rc = atwrite_submit(cs, cb->buf, cb->len);
  1545. if (unlikely(rc)) {
  1546. retval = rc;
  1547. complete_cb(cs);
  1548. }
  1549. }
  1550. spin_unlock_irqrestore(&cs->cmdlock, flags);
  1551. return retval;
  1552. }
  1553. /* gigaset_write_cmd
  1554. * This function is called by the device independent part of the driver
  1555. * to transmit an AT command string to the Gigaset device.
  1556. * It encapsulates the device specific method for transmission over the
  1557. * direct USB connection to the base.
  1558. * The command string is added to the queue of commands to send, and
  1559. * USB transmission is started if necessary.
  1560. * parameters:
  1561. * cs controller state structure
  1562. * buf command string to send
  1563. * len number of bytes to send (max. IF_WRITEBUF)
  1564. * wake_tasklet tasklet to run when transmission is completed
  1565. * (NULL if none)
  1566. * return value:
  1567. * number of bytes queued on success
  1568. * error code < 0 on error
  1569. */
  1570. static int gigaset_write_cmd(struct cardstate *cs,
  1571. const unsigned char *buf, int len,
  1572. struct tasklet_struct *wake_tasklet)
  1573. {
  1574. struct cmdbuf_t *cb;
  1575. unsigned long flags;
  1576. int status;
  1577. gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
  1578. DEBUG_TRANSCMD : DEBUG_LOCKCMD,
  1579. "CMD Transmit", len, buf, 0);
  1580. if (unlikely(!atomic_read(&cs->connected))) {
  1581. err("%s: disconnected", __func__);
  1582. return -ENODEV;
  1583. }
  1584. if (len <= 0)
  1585. return 0; /* nothing to do */
  1586. if (len > IF_WRITEBUF)
  1587. len = IF_WRITEBUF;
  1588. if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
  1589. dev_err(cs->dev, "%s: out of memory\n", __func__);
  1590. return -ENOMEM;
  1591. }
  1592. memcpy(cb->buf, buf, len);
  1593. cb->len = len;
  1594. cb->offset = 0;
  1595. cb->next = NULL;
  1596. cb->wake_tasklet = wake_tasklet;
  1597. spin_lock_irqsave(&cs->cmdlock, flags);
  1598. cb->prev = cs->lastcmdbuf;
  1599. if (cs->lastcmdbuf)
  1600. cs->lastcmdbuf->next = cb;
  1601. else {
  1602. cs->cmdbuf = cb;
  1603. cs->curlen = len;
  1604. }
  1605. cs->cmdbytes += len;
  1606. cs->lastcmdbuf = cb;
  1607. spin_unlock_irqrestore(&cs->cmdlock, flags);
  1608. status = start_cbsend(cs);
  1609. return status < 0 ? status : len;
  1610. }
  1611. /* gigaset_write_room
  1612. * tty_driver.write_room interface routine
  1613. * return number of characters the driver will accept to be written via
  1614. * gigaset_write_cmd
  1615. * parameter:
  1616. * controller state structure
  1617. * return value:
  1618. * number of characters
  1619. */
  1620. static int gigaset_write_room(struct cardstate *cs)
  1621. {
  1622. return IF_WRITEBUF;
  1623. }
  1624. /* gigaset_chars_in_buffer
  1625. * tty_driver.chars_in_buffer interface routine
  1626. * return number of characters waiting to be sent
  1627. * parameter:
  1628. * controller state structure
  1629. * return value:
  1630. * number of characters
  1631. */
  1632. static int gigaset_chars_in_buffer(struct cardstate *cs)
  1633. {
  1634. unsigned long flags;
  1635. unsigned bytes;
  1636. spin_lock_irqsave(&cs->cmdlock, flags);
  1637. bytes = cs->cmdbytes;
  1638. spin_unlock_irqrestore(&cs->cmdlock, flags);
  1639. return bytes;
  1640. }
  1641. /* gigaset_brkchars
  1642. * implementation of ioctl(GIGASET_BRKCHARS)
  1643. * parameter:
  1644. * controller state structure
  1645. * return value:
  1646. * -EINVAL (unimplemented function)
  1647. */
  1648. static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
  1649. {
  1650. return -EINVAL;
  1651. }
  1652. /* Device Initialization/Shutdown */
  1653. /* ============================== */
  1654. /* Free hardware dependent part of the B channel structure
  1655. * parameter:
  1656. * bcs B channel structure
  1657. * return value:
  1658. * !=0 on success
  1659. */
  1660. static int gigaset_freebcshw(struct bc_state *bcs)
  1661. {
  1662. if (!bcs->hw.bas)
  1663. return 0;
  1664. if (bcs->hw.bas->isooutbuf)
  1665. kfree(bcs->hw.bas->isooutbuf);
  1666. kfree(bcs->hw.bas);
  1667. bcs->hw.bas = NULL;
  1668. return 1;
  1669. }
  1670. /* Initialize hardware dependent part of the B channel structure
  1671. * parameter:
  1672. * bcs B channel structure
  1673. * return value:
  1674. * !=0 on success
  1675. */
  1676. static int gigaset_initbcshw(struct bc_state *bcs)
  1677. {
  1678. int i;
  1679. struct bas_bc_state *ubc;
  1680. bcs->hw.bas = ubc = kmalloc(sizeof(struct bas_bc_state), GFP_KERNEL);
  1681. if (!ubc) {
  1682. err("could not allocate bas_bc_state");
  1683. return 0;
  1684. }
  1685. atomic_set(&ubc->running, 0);
  1686. atomic_set(&ubc->corrbytes, 0);
  1687. spin_lock_init(&ubc->isooutlock);
  1688. for (i = 0; i < BAS_OUTURBS; ++i) {
  1689. ubc->isoouturbs[i].urb = NULL;
  1690. ubc->isoouturbs[i].bcs = bcs;
  1691. }
  1692. ubc->isooutdone = ubc->isooutfree = ubc->isooutovfl = NULL;
  1693. ubc->numsub = 0;
  1694. if (!(ubc->isooutbuf = kmalloc(sizeof(struct isowbuf_t), GFP_KERNEL))) {
  1695. err("could not allocate isochronous output buffer");
  1696. kfree(ubc);
  1697. bcs->hw.bas = NULL;
  1698. return 0;
  1699. }
  1700. tasklet_init(&ubc->sent_tasklet,
  1701. &write_iso_tasklet, (unsigned long) bcs);
  1702. spin_lock_init(&ubc->isoinlock);
  1703. for (i = 0; i < BAS_INURBS; ++i)
  1704. ubc->isoinurbs[i] = NULL;
  1705. ubc->isoindone = NULL;
  1706. ubc->loststatus = -EINPROGRESS;
  1707. ubc->isoinlost = 0;
  1708. ubc->seqlen = 0;
  1709. ubc->inbyte = 0;
  1710. ubc->inbits = 0;
  1711. ubc->goodbytes = 0;
  1712. ubc->alignerrs = 0;
  1713. ubc->fcserrs = 0;
  1714. ubc->frameerrs = 0;
  1715. ubc->giants = 0;
  1716. ubc->runts = 0;
  1717. ubc->aborts = 0;
  1718. ubc->shared0s = 0;
  1719. ubc->stolen0s = 0;
  1720. tasklet_init(&ubc->rcvd_tasklet,
  1721. &read_iso_tasklet, (unsigned long) bcs);
  1722. return 1;
  1723. }
  1724. static void gigaset_reinitbcshw(struct bc_state *bcs)
  1725. {
  1726. struct bas_bc_state *ubc = bcs->hw.bas;
  1727. atomic_set(&bcs->hw.bas->running, 0);
  1728. atomic_set(&bcs->hw.bas->corrbytes, 0);
  1729. bcs->hw.bas->numsub = 0;
  1730. spin_lock_init(&ubc->isooutlock);
  1731. spin_lock_init(&ubc->isoinlock);
  1732. ubc->loststatus = -EINPROGRESS;
  1733. }
  1734. static void gigaset_freecshw(struct cardstate *cs)
  1735. {
  1736. struct bas_cardstate *ucs = cs->hw.bas;
  1737. del_timer(&ucs->timer_ctrl);
  1738. del_timer(&ucs->timer_atrdy);
  1739. del_timer(&ucs->timer_cmd_in);
  1740. kfree(cs->hw.bas);
  1741. }
  1742. static int gigaset_initcshw(struct cardstate *cs)
  1743. {
  1744. struct bas_cardstate *ucs;
  1745. cs->hw.bas = ucs = kmalloc(sizeof *ucs, GFP_KERNEL);
  1746. if (!ucs)
  1747. return 0;
  1748. ucs->urb_cmd_in = NULL;
  1749. ucs->urb_cmd_out = NULL;
  1750. ucs->rcvbuf = NULL;
  1751. ucs->rcvbuf_size = 0;
  1752. spin_lock_init(&ucs->lock);
  1753. ucs->pending = 0;
  1754. atomic_set(&ucs->basstate, 0);
  1755. init_timer(&ucs->timer_ctrl);
  1756. init_timer(&ucs->timer_atrdy);
  1757. init_timer(&ucs->timer_cmd_in);
  1758. return 1;
  1759. }
  1760. /* freeurbs
  1761. * unlink and deallocate all URBs unconditionally
  1762. * caller must make sure that no commands are still in progress
  1763. * parameter:
  1764. * cs controller state structure
  1765. */
  1766. static void freeurbs(struct cardstate *cs)
  1767. {
  1768. struct bas_cardstate *ucs = cs->hw.bas;
  1769. struct bas_bc_state *ubc;
  1770. int i, j;
  1771. for (j = 0; j < 2; ++j) {
  1772. ubc = cs->bcs[j].hw.bas;
  1773. for (i = 0; i < BAS_OUTURBS; ++i)
  1774. if (ubc->isoouturbs[i].urb) {
  1775. usb_kill_urb(ubc->isoouturbs[i].urb);
  1776. gig_dbg(DEBUG_INIT,
  1777. "%s: isoc output URB %d/%d unlinked",
  1778. __func__, j, i);
  1779. usb_free_urb(ubc->isoouturbs[i].urb);
  1780. ubc->isoouturbs[i].urb = NULL;
  1781. }
  1782. for (i = 0; i < BAS_INURBS; ++i)
  1783. if (ubc->isoinurbs[i]) {
  1784. usb_kill_urb(ubc->isoinurbs[i]);
  1785. gig_dbg(DEBUG_INIT,
  1786. "%s: isoc input URB %d/%d unlinked",
  1787. __func__, j, i);
  1788. usb_free_urb(ubc->isoinurbs[i]);
  1789. ubc->isoinurbs[i] = NULL;
  1790. }
  1791. }
  1792. if (ucs->urb_int_in) {
  1793. usb_kill_urb(ucs->urb_int_in);
  1794. gig_dbg(DEBUG_INIT, "%s: interrupt input URB unlinked",
  1795. __func__);
  1796. usb_free_urb(ucs->urb_int_in);
  1797. ucs->urb_int_in = NULL;
  1798. }
  1799. if (ucs->urb_cmd_out) {
  1800. usb_kill_urb(ucs->urb_cmd_out);
  1801. gig_dbg(DEBUG_INIT, "%s: command output URB unlinked",
  1802. __func__);
  1803. usb_free_urb(ucs->urb_cmd_out);
  1804. ucs->urb_cmd_out = NULL;
  1805. }
  1806. if (ucs->urb_cmd_in) {
  1807. usb_kill_urb(ucs->urb_cmd_in);
  1808. gig_dbg(DEBUG_INIT, "%s: command input URB unlinked",
  1809. __func__);
  1810. usb_free_urb(ucs->urb_cmd_in);
  1811. ucs->urb_cmd_in = NULL;
  1812. }
  1813. if (ucs->urb_ctrl) {
  1814. usb_kill_urb(ucs->urb_ctrl);
  1815. gig_dbg(DEBUG_INIT, "%s: control output URB unlinked",
  1816. __func__);
  1817. usb_free_urb(ucs->urb_ctrl);
  1818. ucs->urb_ctrl = NULL;
  1819. }
  1820. }
  1821. /* gigaset_probe
  1822. * This function is called when a new USB device is connected.
  1823. * It checks whether the new device is handled by this driver.
  1824. */
  1825. static int gigaset_probe(struct usb_interface *interface,
  1826. const struct usb_device_id *id)
  1827. {
  1828. struct usb_host_interface *hostif;
  1829. struct usb_device *udev = interface_to_usbdev(interface);
  1830. struct cardstate *cs = NULL;
  1831. struct bas_cardstate *ucs = NULL;
  1832. struct bas_bc_state *ubc;
  1833. struct usb_endpoint_descriptor *endpoint;
  1834. int i, j;
  1835. int ret;
  1836. gig_dbg(DEBUG_ANY,
  1837. "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
  1838. __func__, le16_to_cpu(udev->descriptor.idVendor),
  1839. le16_to_cpu(udev->descriptor.idProduct));
  1840. /* See if the device offered us matches what we can accept */
  1841. if ((le16_to_cpu(udev->descriptor.idVendor) != USB_GIGA_VENDOR_ID) ||
  1842. (le16_to_cpu(udev->descriptor.idProduct) != USB_GIGA_PRODUCT_ID &&
  1843. le16_to_cpu(udev->descriptor.idProduct) != USB_4175_PRODUCT_ID &&
  1844. le16_to_cpu(udev->descriptor.idProduct) != USB_SX303_PRODUCT_ID &&
  1845. le16_to_cpu(udev->descriptor.idProduct) != USB_SX353_PRODUCT_ID)) {
  1846. gig_dbg(DEBUG_ANY, "%s: unmatched ID - exiting", __func__);
  1847. return -ENODEV;
  1848. }
  1849. /* set required alternate setting */
  1850. hostif = interface->cur_altsetting;
  1851. if (hostif->desc.bAlternateSetting != 3) {
  1852. gig_dbg(DEBUG_ANY,
  1853. "%s: wrong alternate setting %d - trying to switch",
  1854. __func__, hostif->desc.bAlternateSetting);
  1855. if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) < 0) {
  1856. dev_warn(&udev->dev, "usb_set_interface failed, "
  1857. "device %d interface %d altsetting %d\n",
  1858. udev->devnum, hostif->desc.bInterfaceNumber,
  1859. hostif->desc.bAlternateSetting);
  1860. return -ENODEV;
  1861. }
  1862. hostif = interface->cur_altsetting;
  1863. }
  1864. /* Reject application specific interfaces
  1865. */
  1866. if (hostif->desc.bInterfaceClass != 255) {
  1867. dev_warn(&udev->dev, "%s: bInterfaceClass == %d\n",
  1868. __func__, hostif->desc.bInterfaceClass);
  1869. return -ENODEV;
  1870. }
  1871. dev_info(&udev->dev,
  1872. "%s: Device matched (Vendor: 0x%x, Product: 0x%x)\n",
  1873. __func__, le16_to_cpu(udev->descriptor.idVendor),
  1874. le16_to_cpu(udev->descriptor.idProduct));
  1875. cs = gigaset_getunassignedcs(driver);
  1876. if (!cs) {
  1877. dev_err(&udev->dev, "no free cardstate\n");
  1878. return -ENODEV;
  1879. }
  1880. ucs = cs->hw.bas;
  1881. /* save off device structure ptrs for later use */
  1882. usb_get_dev(udev);
  1883. ucs->udev = udev;
  1884. ucs->interface = interface;
  1885. cs->dev = &interface->dev;
  1886. /* allocate URBs:
  1887. * - one for the interrupt pipe
  1888. * - three for the different uses of the default control pipe
  1889. * - three for each isochronous pipe
  1890. */
  1891. ucs->urb_int_in = usb_alloc_urb(0, SLAB_KERNEL);
  1892. if (!ucs->urb_int_in) {
  1893. dev_err(cs->dev, "no free urbs available\n");
  1894. goto error;
  1895. }
  1896. ucs->urb_cmd_in = usb_alloc_urb(0, SLAB_KERNEL);
  1897. if (!ucs->urb_cmd_in) {
  1898. dev_err(cs->dev, "no free urbs available\n");
  1899. goto error;
  1900. }
  1901. ucs->urb_cmd_out = usb_alloc_urb(0, SLAB_KERNEL);
  1902. if (!ucs->urb_cmd_out) {
  1903. dev_err(cs->dev, "no free urbs available\n");
  1904. goto error;
  1905. }
  1906. ucs->urb_ctrl = usb_alloc_urb(0, SLAB_KERNEL);
  1907. if (!ucs->urb_ctrl) {
  1908. dev_err(cs->dev, "no free urbs available\n");
  1909. goto error;
  1910. }
  1911. for (j = 0; j < 2; ++j) {
  1912. ubc = cs->bcs[j].hw.bas;
  1913. for (i = 0; i < BAS_OUTURBS; ++i) {
  1914. ubc->isoouturbs[i].urb =
  1915. usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL);
  1916. if (!ubc->isoouturbs[i].urb) {
  1917. dev_err(cs->dev, "no free urbs available\n");
  1918. goto error;
  1919. }
  1920. }
  1921. for (i = 0; i < BAS_INURBS; ++i) {
  1922. ubc->isoinurbs[i] =
  1923. usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL);
  1924. if (!ubc->isoinurbs[i]) {
  1925. dev_err(cs->dev, "no free urbs available\n");
  1926. goto error;
  1927. }
  1928. }
  1929. }
  1930. ucs->rcvbuf = NULL;
  1931. ucs->rcvbuf_size = 0;
  1932. /* Fill the interrupt urb and send it to the core */
  1933. endpoint = &hostif->endpoint[0].desc;
  1934. usb_fill_int_urb(ucs->urb_int_in, udev,
  1935. usb_rcvintpipe(udev,
  1936. (endpoint->bEndpointAddress) & 0x0f),
  1937. ucs->int_in_buf, 3, read_int_callback, cs,
  1938. endpoint->bInterval);
  1939. ret = usb_submit_urb(ucs->urb_int_in, SLAB_KERNEL);
  1940. if (ret) {
  1941. dev_err(cs->dev, "could not submit interrupt URB: %s\n",
  1942. get_usb_statmsg(ret));
  1943. goto error;
  1944. }
  1945. /* tell the device that the driver is ready */
  1946. if ((ret = req_submit(cs->bcs, HD_DEVICE_INIT_ACK, 0, 0)) != 0)
  1947. goto error;
  1948. /* tell common part that the device is ready */
  1949. if (startmode == SM_LOCKED)
  1950. atomic_set(&cs->mstate, MS_LOCKED);
  1951. /* save address of controller structure */
  1952. usb_set_intfdata(interface, cs);
  1953. if (!gigaset_start(cs))
  1954. goto error;
  1955. return 0;
  1956. error:
  1957. freeurbs(cs);
  1958. gigaset_unassign(cs);
  1959. return -ENODEV;
  1960. }
  1961. /* gigaset_disconnect
  1962. * This function is called when the Gigaset base is unplugged.
  1963. */
  1964. static void gigaset_disconnect(struct usb_interface *interface)
  1965. {
  1966. struct cardstate *cs;
  1967. struct bas_cardstate *ucs;
  1968. cs = usb_get_intfdata(interface);
  1969. ucs = cs->hw.bas;
  1970. dev_info(cs->dev, "disconnecting Gigaset base\n");
  1971. gigaset_stop(cs);
  1972. freeurbs(cs);
  1973. usb_set_intfdata(interface, NULL);
  1974. kfree(ucs->rcvbuf);
  1975. ucs->rcvbuf = NULL;
  1976. ucs->rcvbuf_size = 0;
  1977. atomic_set(&ucs->basstate, 0);
  1978. usb_put_dev(ucs->udev);
  1979. ucs->interface = NULL;
  1980. ucs->udev = NULL;
  1981. cs->dev = NULL;
  1982. gigaset_unassign(cs);
  1983. }
  1984. static struct gigaset_ops gigops = {
  1985. gigaset_write_cmd,
  1986. gigaset_write_room,
  1987. gigaset_chars_in_buffer,
  1988. gigaset_brkchars,
  1989. gigaset_init_bchannel,
  1990. gigaset_close_bchannel,
  1991. gigaset_initbcshw,
  1992. gigaset_freebcshw,
  1993. gigaset_reinitbcshw,
  1994. gigaset_initcshw,
  1995. gigaset_freecshw,
  1996. gigaset_set_modem_ctrl,
  1997. gigaset_baud_rate,
  1998. gigaset_set_line_ctrl,
  1999. gigaset_isoc_send_skb,
  2000. gigaset_isoc_input,
  2001. };
  2002. /* bas_gigaset_init
  2003. * This function is called after the kernel module is loaded.
  2004. */
  2005. static int __init bas_gigaset_init(void)
  2006. {
  2007. int result;
  2008. /* allocate memory for our driver state and intialize it */
  2009. if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
  2010. GIGASET_MODULENAME, GIGASET_DEVNAME,
  2011. GIGASET_DEVFSNAME, &gigops,
  2012. THIS_MODULE)) == NULL)
  2013. goto error;
  2014. /* allocate memory for our device state and intialize it */
  2015. cardstate = gigaset_initcs(driver, 2, 0, 0, cidmode,
  2016. GIGASET_MODULENAME);
  2017. if (!cardstate)
  2018. goto error;
  2019. /* register this driver with the USB subsystem */
  2020. result = usb_register(&gigaset_usb_driver);
  2021. if (result < 0) {
  2022. err("usb_register failed (error %d)", -result);
  2023. goto error;
  2024. }
  2025. info(DRIVER_AUTHOR);
  2026. info(DRIVER_DESC);
  2027. return 0;
  2028. error: if (cardstate)
  2029. gigaset_freecs(cardstate);
  2030. cardstate = NULL;
  2031. if (driver)
  2032. gigaset_freedriver(driver);
  2033. driver = NULL;
  2034. return -1;
  2035. }
  2036. /* bas_gigaset_exit
  2037. * This function is called before the kernel module is unloaded.
  2038. */
  2039. static void __exit bas_gigaset_exit(void)
  2040. {
  2041. gigaset_blockdriver(driver); /* => probe will fail
  2042. * => no gigaset_start any more
  2043. */
  2044. gigaset_shutdown(cardstate);
  2045. /* from now on, no isdn callback should be possible */
  2046. if (atomic_read(&cardstate->hw.bas->basstate) & BS_ATOPEN) {
  2047. gig_dbg(DEBUG_ANY, "closing AT channel");
  2048. if (req_submit(cardstate->bcs,
  2049. HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT) >= 0) {
  2050. /* successfully submitted */
  2051. //FIXME wait for completion?
  2052. }
  2053. }
  2054. /* deregister this driver with the USB subsystem */
  2055. usb_deregister(&gigaset_usb_driver);
  2056. /* this will call the disconnect-callback */
  2057. /* from now on, no disconnect/probe callback should be running */
  2058. gigaset_freecs(cardstate);
  2059. cardstate = NULL;
  2060. gigaset_freedriver(driver);
  2061. driver = NULL;
  2062. }
  2063. module_init(bas_gigaset_init);
  2064. module_exit(bas_gigaset_exit);
  2065. MODULE_AUTHOR(DRIVER_AUTHOR);
  2066. MODULE_DESCRIPTION(DRIVER_DESC);
  2067. MODULE_LICENSE("GPL");