2 * USB driver for Gigaset 307x base via direct USB connection.
4 * Copyright (c) 2001 by Hansjoerg Lipp <hjlipp@web.de>,
5 * Tilman Schmidt <tilman@imap.cc>,
8 * =====================================================================
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 * =====================================================================
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>
26 /* Version Information */
27 #define DRIVER_AUTHOR "Tilman Schmidt <tilman@imap.cc>, Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers"
28 #define DRIVER_DESC "USB Driver for Gigaset 307x"
31 /* Module parameters */
33 static int startmode = SM_ISDN;
34 static int cidmode = 1;
36 module_param(startmode, int, S_IRUGO);
37 module_param(cidmode, int, S_IRUGO);
38 MODULE_PARM_DESC(startmode, "start in isdn4linux mode");
39 MODULE_PARM_DESC(cidmode, "Call-ID mode");
41 #define GIGASET_MINORS 1
42 #define GIGASET_MINOR 16
43 #define GIGASET_MODULENAME "bas_gigaset"
44 #define GIGASET_DEVNAME "ttyGB"
46 /* length limit according to Siemens 3070usb-protokoll.doc ch. 2.1 */
47 #define IF_WRITEBUF 264
49 /* Values for the Gigaset 307x */
50 #define USB_GIGA_VENDOR_ID 0x0681
51 #define USB_3070_PRODUCT_ID 0x0001
52 #define USB_3075_PRODUCT_ID 0x0002
53 #define USB_SX303_PRODUCT_ID 0x0021
54 #define USB_SX353_PRODUCT_ID 0x0022
56 /* table of devices that work with this driver */
57 static const struct usb_device_id gigaset_table [] = {
58 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_3070_PRODUCT_ID) },
59 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_3075_PRODUCT_ID) },
60 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX303_PRODUCT_ID) },
61 { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX353_PRODUCT_ID) },
62 { } /* Terminating entry */
65 MODULE_DEVICE_TABLE(usb, gigaset_table);
67 /*======================= local function prototypes ==========================*/
69 /* function called if a new device belonging to this driver is connected */
70 static int gigaset_probe(struct usb_interface *interface,
71 const struct usb_device_id *id);
73 /* Function will be called if the device is unplugged */
74 static void gigaset_disconnect(struct usb_interface *interface);
76 static int atread_submit(struct cardstate *, int);
77 static void stopurbs(struct bas_bc_state *);
78 static int req_submit(struct bc_state *, int, int, int);
79 static int atwrite_submit(struct cardstate *, unsigned char *, int);
80 static int start_cbsend(struct cardstate *);
82 /*============================================================================*/
84 struct bas_cardstate {
85 struct usb_device *udev; /* USB device pointer */
86 struct usb_interface *interface; /* interface for this device */
87 unsigned char minor; /* starting minor number */
89 struct urb *urb_ctrl; /* control pipe default URB */
90 struct usb_ctrlrequest dr_ctrl;
91 struct timer_list timer_ctrl; /* control request timeout */
94 struct timer_list timer_atrdy; /* AT command ready timeout */
95 struct urb *urb_cmd_out; /* for sending AT commands */
96 struct usb_ctrlrequest dr_cmd_out;
99 struct urb *urb_cmd_in; /* for receiving AT replies */
100 struct usb_ctrlrequest dr_cmd_in;
101 struct timer_list timer_cmd_in; /* receive request timeout */
102 unsigned char *rcvbuf; /* AT reply receive buffer */
104 struct urb *urb_int_in; /* URB for interrupt pipe */
105 unsigned char int_in_buf[3];
107 spinlock_t lock; /* locks all following */
108 atomic_t basstate; /* bitmap (BS_*) */
109 int pending; /* uncompleted base request */
110 int rcvbuf_size; /* size of AT receive buffer */
111 /* 0: no receive in progress */
112 int retry_cmd_in; /* receive req retry count */
115 /* status of direct USB connection to 307x base (bits in basstate) */
116 #define BS_ATOPEN 0x001 /* AT channel open */
117 #define BS_B1OPEN 0x002 /* B channel 1 open */
118 #define BS_B2OPEN 0x004 /* B channel 2 open */
119 #define BS_ATREADY 0x008 /* base ready for AT command */
120 #define BS_INIT 0x010 /* base has signalled INIT_OK */
121 #define BS_ATTIMER 0x020 /* waiting for HD_READY_SEND_ATDATA */
122 #define BS_ATRDPEND 0x040 /* urb_cmd_in in use */
123 #define BS_ATWRPEND 0x080 /* urb_cmd_out in use */
126 static struct gigaset_driver *driver = NULL;
127 static struct cardstate *cardstate = NULL;
129 /* usb specific object needed to register this driver with the usb subsystem */
130 static struct usb_driver gigaset_usb_driver = {
131 .name = GIGASET_MODULENAME,
132 .probe = gigaset_probe,
133 .disconnect = gigaset_disconnect,
134 .id_table = gigaset_table,
137 /* get message text for usb_submit_urb return code
139 static char *get_usb_rcmsg(int rc)
141 static char unkmsg[28];
147 return "out of memory";
149 return "device not present";
151 return "endpoint not present";
153 return "URB type not supported";
155 return "invalid argument";
157 return "start frame too early or too much scheduled";
159 return "too many isochronous frames requested";
161 return "endpoint stalled";
163 return "invalid packet size";
165 return "would overcommit USB bandwidth";
167 return "device shut down";
169 return "reject flag set";
171 return "device suspended";
173 snprintf(unkmsg, sizeof(unkmsg), "unknown error %d", rc);
178 /* get message text for USB status code
180 static char *get_usb_statmsg(int status)
182 static char unkmsg[28];
188 return "unlinked (sync)";
192 return "bit stuffing error, timeout, or unknown USB error";
194 return "CRC mismatch, timeout, or unknown USB error";
198 return "endpoint stalled";
200 return "IN buffer overrun";
202 return "OUT buffer underrun";
204 return "too much data";
206 return "short packet detected";
208 return "device removed";
210 return "partial isochronous transfer";
212 return "invalid argument";
214 return "unlinked (async)";
216 return "device shut down";
218 snprintf(unkmsg, sizeof(unkmsg), "unknown status %d", status);
224 * retrieve string representation of USB pipe type
226 static inline char *usb_pipetype_str(int pipe)
228 if (usb_pipeisoc(pipe))
230 if (usb_pipeint(pipe))
232 if (usb_pipecontrol(pipe))
234 if (usb_pipebulk(pipe))
240 * write content of URB to syslog for debugging
242 static inline void dump_urb(enum debuglevel level, const char *tag,
245 #ifdef CONFIG_GIGASET_DEBUG
247 gig_dbg(level, "%s urb(0x%08lx)->{", tag, (unsigned long) urb);
250 " dev=0x%08lx, pipe=%s:EP%d/DV%d:%s, "
251 "hcpriv=0x%08lx, transfer_flags=0x%x,",
252 (unsigned long) urb->dev,
253 usb_pipetype_str(urb->pipe),
254 usb_pipeendpoint(urb->pipe), usb_pipedevice(urb->pipe),
255 usb_pipein(urb->pipe) ? "in" : "out",
256 (unsigned long) urb->hcpriv,
257 urb->transfer_flags);
259 " transfer_buffer=0x%08lx[%d], actual_length=%d, "
260 "setup_packet=0x%08lx,",
261 (unsigned long) urb->transfer_buffer,
262 urb->transfer_buffer_length, urb->actual_length,
263 (unsigned long) urb->setup_packet);
265 " start_frame=%d, number_of_packets=%d, interval=%d, "
267 urb->start_frame, urb->number_of_packets, urb->interval,
270 " context=0x%08lx, complete=0x%08lx, "
271 "iso_frame_desc[]={",
272 (unsigned long) urb->context,
273 (unsigned long) urb->complete);
274 for (i = 0; i < urb->number_of_packets; i++) {
275 struct usb_iso_packet_descriptor *pifd
276 = &urb->iso_frame_desc[i];
278 " {offset=%u, length=%u, actual_length=%u, "
280 pifd->offset, pifd->length, pifd->actual_length,
284 gig_dbg(level, "}}");
288 /* read/set modem control bits etc. (m10x only) */
289 static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
295 static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
300 static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
306 * hang up any existing connection because of an unrecoverable error
307 * This function may be called from any context and takes care of scheduling
308 * the necessary actions for execution outside of interrupt context.
309 * cs->lock must not be held.
311 * B channel control structure
313 static inline void error_hangup(struct bc_state *bcs)
315 struct cardstate *cs = bcs->cs;
317 gig_dbg(DEBUG_ANY, "%s: scheduling HUP for channel %d",
318 __func__, bcs->channel);
320 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL))
321 dev_err(cs->dev, "event queue full\n");
323 gigaset_schedule_event(cs);
327 * reset Gigaset device because of an unrecoverable error
328 * This function may be called from any context, and takes care of
329 * scheduling the necessary actions for execution outside of interrupt context.
330 * cs->lock must not be held.
332 * controller state structure
334 static inline void error_reset(struct cardstate *cs)
336 /* close AT command channel to recover (ignore errors) */
337 req_submit(cs->bcs, HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT);
339 //FIXME try to recover without bothering the user
341 "unrecoverable error - please disconnect Gigaset base to reset\n");
345 * check for completion of pending control request
347 * ucs hardware specific controller state structure
349 static void check_pending(struct bas_cardstate *ucs)
353 spin_lock_irqsave(&ucs->lock, flags);
354 switch (ucs->pending) {
357 case HD_OPEN_ATCHANNEL:
358 if (atomic_read(&ucs->basstate) & BS_ATOPEN)
361 case HD_OPEN_B1CHANNEL:
362 if (atomic_read(&ucs->basstate) & BS_B1OPEN)
365 case HD_OPEN_B2CHANNEL:
366 if (atomic_read(&ucs->basstate) & BS_B2OPEN)
369 case HD_CLOSE_ATCHANNEL:
370 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN))
373 case HD_CLOSE_B1CHANNEL:
374 if (!(atomic_read(&ucs->basstate) & BS_B1OPEN))
377 case HD_CLOSE_B2CHANNEL:
378 if (!(atomic_read(&ucs->basstate) & BS_B2OPEN))
381 case HD_DEVICE_INIT_ACK: /* no reply expected */
384 /* HD_READ_ATMESSAGE, HD_WRITE_ATMESSAGE, HD_RESET_INTERRUPTPIPE
385 * are handled separately and should never end up here
388 dev_warn(&ucs->interface->dev,
389 "unknown pending request 0x%02x cleared\n",
395 del_timer(&ucs->timer_ctrl);
397 spin_unlock_irqrestore(&ucs->lock, flags);
401 * timeout routine for command input request
403 * controller state structure
405 static void cmd_in_timeout(unsigned long data)
407 struct cardstate *cs = (struct cardstate *) data;
408 struct bas_cardstate *ucs = cs->hw.bas;
411 if (!ucs->rcvbuf_size) {
412 gig_dbg(DEBUG_USBREQ, "%s: no receive in progress", __func__);
416 if (ucs->retry_cmd_in++ < BAS_RETRY) {
417 dev_notice(cs->dev, "control read: timeout, retry %d\n",
419 rc = atread_submit(cs, BAS_TIMEOUT);
420 if (rc >= 0 || rc == -ENODEV)
421 /* resubmitted or disconnected */
422 /* - bypass regular exit block */
426 "control read: timeout, giving up after %d tries\n",
431 ucs->rcvbuf_size = 0;
435 /* set/clear bits in base connection state, return previous state
437 inline static int update_basstate(struct bas_cardstate *ucs,
443 spin_lock_irqsave(&ucs->lock, flags);
444 state = atomic_read(&ucs->basstate);
445 atomic_set(&ucs->basstate, (state & ~clear) | set);
446 spin_unlock_irqrestore(&ucs->lock, flags);
450 /* read_ctrl_callback
451 * USB completion handler for control pipe input
452 * called by the USB subsystem in interrupt context
454 * urb USB request block
455 * urb->context = inbuf structure for controller state
457 static void read_ctrl_callback(struct urb *urb)
459 struct inbuf_t *inbuf = urb->context;
460 struct cardstate *cs = inbuf->cs;
461 struct bas_cardstate *ucs = cs->hw.bas;
462 int status = urb->status;
467 update_basstate(ucs, 0, BS_ATRDPEND);
469 if (!ucs->rcvbuf_size) {
470 dev_warn(cs->dev, "%s: no receive in progress\n", __func__);
474 del_timer(&ucs->timer_cmd_in);
477 case 0: /* normal completion */
478 numbytes = urb->actual_length;
479 if (unlikely(numbytes != ucs->rcvbuf_size)) {
481 "control read: received %d chars, expected %d\n",
482 numbytes, ucs->rcvbuf_size);
483 if (numbytes > ucs->rcvbuf_size)
484 numbytes = ucs->rcvbuf_size;
487 /* copy received bytes to inbuf */
488 have_data = gigaset_fill_inbuf(inbuf, ucs->rcvbuf, numbytes);
490 if (unlikely(numbytes < ucs->rcvbuf_size)) {
491 /* incomplete - resubmit for remaining bytes */
492 ucs->rcvbuf_size -= numbytes;
493 ucs->retry_cmd_in = 0;
494 rc = atread_submit(cs, BAS_TIMEOUT);
495 if (rc >= 0 || rc == -ENODEV)
496 /* resubmitted or disconnected */
497 /* - bypass regular exit block */
503 case -ENOENT: /* cancelled */
504 case -ECONNRESET: /* cancelled (async) */
505 case -EINPROGRESS: /* pending */
506 case -ENODEV: /* device removed */
507 case -ESHUTDOWN: /* device shut down */
508 /* no action necessary */
509 gig_dbg(DEBUG_USBREQ, "%s: %s",
510 __func__, get_usb_statmsg(status));
513 default: /* severe trouble */
514 dev_warn(cs->dev, "control read: %s\n",
515 get_usb_statmsg(status));
516 if (ucs->retry_cmd_in++ < BAS_RETRY) {
517 dev_notice(cs->dev, "control read: retry %d\n",
519 rc = atread_submit(cs, BAS_TIMEOUT);
520 if (rc >= 0 || rc == -ENODEV)
521 /* resubmitted or disconnected */
522 /* - bypass regular exit block */
526 "control read: giving up after %d tries\n",
534 ucs->rcvbuf_size = 0;
536 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
537 gigaset_schedule_event(cs);
542 * submit an HD_READ_ATMESSAGE command URB and optionally start a timeout
544 * cs controller state structure
545 * timeout timeout in 1/10 sec., 0: none
548 * -EBUSY if another request is pending
549 * any URB submission error code
551 static int atread_submit(struct cardstate *cs, int timeout)
553 struct bas_cardstate *ucs = cs->hw.bas;
556 gig_dbg(DEBUG_USBREQ, "-------> HD_READ_ATMESSAGE (%d)",
559 if (update_basstate(ucs, BS_ATRDPEND, 0) & BS_ATRDPEND) {
561 "could not submit HD_READ_ATMESSAGE: URB busy\n");
565 ucs->dr_cmd_in.bRequestType = IN_VENDOR_REQ;
566 ucs->dr_cmd_in.bRequest = HD_READ_ATMESSAGE;
567 ucs->dr_cmd_in.wValue = 0;
568 ucs->dr_cmd_in.wIndex = 0;
569 ucs->dr_cmd_in.wLength = cpu_to_le16(ucs->rcvbuf_size);
570 usb_fill_control_urb(ucs->urb_cmd_in, ucs->udev,
571 usb_rcvctrlpipe(ucs->udev, 0),
572 (unsigned char*) & ucs->dr_cmd_in,
573 ucs->rcvbuf, ucs->rcvbuf_size,
574 read_ctrl_callback, cs->inbuf);
576 if ((ret = usb_submit_urb(ucs->urb_cmd_in, GFP_ATOMIC)) != 0) {
577 update_basstate(ucs, 0, BS_ATRDPEND);
578 dev_err(cs->dev, "could not submit HD_READ_ATMESSAGE: %s\n",
584 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
585 ucs->timer_cmd_in.expires = jiffies + timeout * HZ / 10;
586 ucs->timer_cmd_in.data = (unsigned long) cs;
587 ucs->timer_cmd_in.function = cmd_in_timeout;
588 add_timer(&ucs->timer_cmd_in);
594 * USB completion handler for interrupt pipe input
595 * called by the USB subsystem in interrupt context
597 * urb USB request block
598 * urb->context = controller state structure
600 static void read_int_callback(struct urb *urb)
602 struct cardstate *cs = urb->context;
603 struct bas_cardstate *ucs = cs->hw.bas;
604 struct bc_state *bcs;
605 int status = urb->status;
612 case 0: /* success */
614 case -ENOENT: /* cancelled */
615 case -ECONNRESET: /* cancelled (async) */
616 case -EINPROGRESS: /* pending */
617 /* ignore silently */
618 gig_dbg(DEBUG_USBREQ, "%s: %s",
619 __func__, get_usb_statmsg(status));
621 case -ENODEV: /* device removed */
622 case -ESHUTDOWN: /* device shut down */
623 //FIXME use this as disconnect indicator?
624 gig_dbg(DEBUG_USBREQ, "%s: device disconnected", __func__);
626 default: /* severe trouble */
627 dev_warn(cs->dev, "interrupt read: %s\n",
628 get_usb_statmsg(status));
629 //FIXME corrective action? resubmission always ok?
633 /* drop incomplete packets even if the missing bytes wouldn't matter */
634 if (unlikely(urb->actual_length < 3)) {
635 dev_warn(cs->dev, "incomplete interrupt packet (%d bytes)\n",
640 l = (unsigned) ucs->int_in_buf[1] +
641 (((unsigned) ucs->int_in_buf[2]) << 8);
643 gig_dbg(DEBUG_USBREQ, "<-------%d: 0x%02x (%u [0x%02x 0x%02x])",
644 urb->actual_length, (int)ucs->int_in_buf[0], l,
645 (int)ucs->int_in_buf[1], (int)ucs->int_in_buf[2]);
649 switch (ucs->int_in_buf[0]) {
650 case HD_DEVICE_INIT_OK:
651 update_basstate(ucs, BS_INIT, 0);
654 case HD_READY_SEND_ATDATA:
655 del_timer(&ucs->timer_atrdy);
656 update_basstate(ucs, BS_ATREADY, BS_ATTIMER);
660 case HD_OPEN_B2CHANNEL_ACK:
662 case HD_OPEN_B1CHANNEL_ACK:
663 bcs = cs->bcs + channel;
664 update_basstate(ucs, BS_B1OPEN << channel, 0);
665 gigaset_bchannel_up(bcs);
668 case HD_OPEN_ATCHANNEL_ACK:
669 update_basstate(ucs, BS_ATOPEN, 0);
673 case HD_CLOSE_B2CHANNEL_ACK:
675 case HD_CLOSE_B1CHANNEL_ACK:
676 bcs = cs->bcs + channel;
677 update_basstate(ucs, 0, BS_B1OPEN << channel);
678 stopurbs(bcs->hw.bas);
679 gigaset_bchannel_down(bcs);
682 case HD_CLOSE_ATCHANNEL_ACK:
683 update_basstate(ucs, 0, BS_ATOPEN);
686 case HD_B2_FLOW_CONTROL:
688 case HD_B1_FLOW_CONTROL:
689 bcs = cs->bcs + channel;
690 atomic_add((l - BAS_NORMFRAME) * BAS_CORRFRAMES,
691 &bcs->hw.bas->corrbytes);
693 "Flow control (channel %d, sub %d): 0x%02x => %d",
694 channel, bcs->hw.bas->numsub, l,
695 atomic_read(&bcs->hw.bas->corrbytes));
698 case HD_RECEIVEATDATA_ACK: /* AT response ready to be received */
701 "HD_RECEIVEATDATA_ACK with length 0 ignored\n");
704 spin_lock_irqsave(&cs->lock, flags);
705 if (ucs->rcvbuf_size) {
706 /* throw away previous buffer - we have no queue */
708 "receive AT data overrun, %d bytes lost\n",
711 ucs->rcvbuf_size = 0;
713 if ((ucs->rcvbuf = kmalloc(l, GFP_ATOMIC)) == NULL) {
714 spin_unlock_irqrestore(&cs->lock, flags);
715 dev_err(cs->dev, "out of memory receiving AT data\n");
719 ucs->rcvbuf_size = l;
720 ucs->retry_cmd_in = 0;
721 if ((rc = atread_submit(cs, BAS_TIMEOUT)) < 0) {
724 ucs->rcvbuf_size = 0;
726 //FIXME corrective action?
727 spin_unlock_irqrestore(&cs->lock, flags);
732 spin_unlock_irqrestore(&cs->lock, flags);
735 case HD_RESET_INTERRUPT_PIPE_ACK:
736 gig_dbg(DEBUG_USBREQ, "HD_RESET_INTERRUPT_PIPE_ACK");
740 gig_dbg(DEBUG_USBREQ, "HD_SUSPEND_END");
745 "unknown Gigaset signal 0x%02x (%u) ignored\n",
746 (int) ucs->int_in_buf[0], l);
752 rc = usb_submit_urb(urb, GFP_ATOMIC);
753 if (unlikely(rc != 0 && rc != -ENODEV)) {
754 dev_err(cs->dev, "could not resubmit interrupt URB: %s\n",
761 * USB completion handler for B channel isochronous input
762 * called by the USB subsystem in interrupt context
764 * urb USB request block of completed request
765 * urb->context = bc_state structure
767 static void read_iso_callback(struct urb *urb)
769 struct bc_state *bcs;
770 struct bas_bc_state *ubc;
771 int status = urb->status;
775 /* status codes not worth bothering the tasklet with */
776 if (unlikely(status == -ENOENT ||
777 status == -ECONNRESET ||
778 status == -EINPROGRESS ||
780 status == -ESHUTDOWN)) {
781 gig_dbg(DEBUG_ISO, "%s: %s",
782 __func__, get_usb_statmsg(status));
789 spin_lock_irqsave(&ubc->isoinlock, flags);
790 if (likely(ubc->isoindone == NULL)) {
791 /* pass URB to tasklet */
792 ubc->isoindone = urb;
793 ubc->isoinstatus = status;
794 tasklet_schedule(&ubc->rcvd_tasklet);
796 /* tasklet still busy, drop data and resubmit URB */
797 ubc->loststatus = status;
798 for (i = 0; i < BAS_NUMFRAMES; i++) {
799 ubc->isoinlost += urb->iso_frame_desc[i].actual_length;
800 if (unlikely(urb->iso_frame_desc[i].status != 0 &&
801 urb->iso_frame_desc[i].status !=
803 ubc->loststatus = urb->iso_frame_desc[i].status;
804 urb->iso_frame_desc[i].status = 0;
805 urb->iso_frame_desc[i].actual_length = 0;
807 if (likely(atomic_read(&ubc->running))) {
808 /* urb->dev is clobbered by USB subsystem */
809 urb->dev = bcs->cs->hw.bas->udev;
810 urb->transfer_flags = URB_ISO_ASAP;
811 urb->number_of_packets = BAS_NUMFRAMES;
812 gig_dbg(DEBUG_ISO, "%s: isoc read overrun/resubmit",
814 rc = usb_submit_urb(urb, GFP_ATOMIC);
815 if (unlikely(rc != 0 && rc != -ENODEV)) {
816 dev_err(bcs->cs->dev,
817 "could not resubmit isochronous read "
818 "URB: %s\n", get_usb_rcmsg(rc));
819 dump_urb(DEBUG_ISO, "isoc read", urb);
824 spin_unlock_irqrestore(&ubc->isoinlock, flags);
827 /* write_iso_callback
828 * USB completion handler for B channel isochronous output
829 * called by the USB subsystem in interrupt context
831 * urb USB request block of completed request
832 * urb->context = isow_urbctx_t structure
834 static void write_iso_callback(struct urb *urb)
836 struct isow_urbctx_t *ucx;
837 struct bas_bc_state *ubc;
838 int status = urb->status;
841 /* status codes not worth bothering the tasklet with */
842 if (unlikely(status == -ENOENT ||
843 status == -ECONNRESET ||
844 status == -EINPROGRESS ||
846 status == -ESHUTDOWN)) {
847 gig_dbg(DEBUG_ISO, "%s: %s",
848 __func__, get_usb_statmsg(status));
852 /* pass URB context to tasklet */
854 ubc = ucx->bcs->hw.bas;
855 ucx->status = status;
857 spin_lock_irqsave(&ubc->isooutlock, flags);
858 ubc->isooutovfl = ubc->isooutdone;
859 ubc->isooutdone = ucx;
860 spin_unlock_irqrestore(&ubc->isooutlock, flags);
861 tasklet_schedule(&ubc->sent_tasklet);
865 * prepare and submit USB request blocks for isochronous input and output
867 * B channel control structure
870 * < 0 on error (no URBs submitted)
872 static int starturbs(struct bc_state *bcs)
874 struct bas_bc_state *ubc = bcs->hw.bas;
879 /* initialize L2 reception */
880 if (bcs->proto2 == ISDN_PROTO_L2_HDLC)
881 bcs->inputstate |= INS_flag_hunt;
883 /* submit all isochronous input URBs */
884 atomic_set(&ubc->running, 1);
885 for (k = 0; k < BAS_INURBS; k++) {
886 urb = ubc->isoinurbs[k];
892 urb->dev = bcs->cs->hw.bas->udev;
893 urb->pipe = usb_rcvisocpipe(urb->dev, 3 + 2 * bcs->channel);
894 urb->transfer_flags = URB_ISO_ASAP;
895 urb->transfer_buffer = ubc->isoinbuf + k * BAS_INBUFSIZE;
896 urb->transfer_buffer_length = BAS_INBUFSIZE;
897 urb->number_of_packets = BAS_NUMFRAMES;
898 urb->interval = BAS_FRAMETIME;
899 urb->complete = read_iso_callback;
901 for (j = 0; j < BAS_NUMFRAMES; j++) {
902 urb->iso_frame_desc[j].offset = j * BAS_MAXFRAME;
903 urb->iso_frame_desc[j].length = BAS_MAXFRAME;
904 urb->iso_frame_desc[j].status = 0;
905 urb->iso_frame_desc[j].actual_length = 0;
908 dump_urb(DEBUG_ISO, "Initial isoc read", urb);
909 if ((rc = usb_submit_urb(urb, GFP_ATOMIC)) != 0)
913 /* initialize L2 transmission */
914 gigaset_isowbuf_init(ubc->isooutbuf, PPP_FLAG);
916 /* set up isochronous output URBs for flag idling */
917 for (k = 0; k < BAS_OUTURBS; ++k) {
918 urb = ubc->isoouturbs[k].urb;
923 urb->dev = bcs->cs->hw.bas->udev;
924 urb->pipe = usb_sndisocpipe(urb->dev, 4 + 2 * bcs->channel);
925 urb->transfer_flags = URB_ISO_ASAP;
926 urb->transfer_buffer = ubc->isooutbuf->data;
927 urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data);
928 urb->number_of_packets = BAS_NUMFRAMES;
929 urb->interval = BAS_FRAMETIME;
930 urb->complete = write_iso_callback;
931 urb->context = &ubc->isoouturbs[k];
932 for (j = 0; j < BAS_NUMFRAMES; ++j) {
933 urb->iso_frame_desc[j].offset = BAS_OUTBUFSIZE;
934 urb->iso_frame_desc[j].length = BAS_NORMFRAME;
935 urb->iso_frame_desc[j].status = 0;
936 urb->iso_frame_desc[j].actual_length = 0;
938 ubc->isoouturbs[k].limit = -1;
941 /* keep one URB free, submit the others */
942 for (k = 0; k < BAS_OUTURBS-1; ++k) {
943 dump_urb(DEBUG_ISO, "Initial isoc write", urb);
944 rc = usb_submit_urb(ubc->isoouturbs[k].urb, GFP_ATOMIC);
948 dump_urb(DEBUG_ISO, "Initial isoc write (free)", urb);
949 ubc->isooutfree = &ubc->isoouturbs[BAS_OUTURBS-1];
950 ubc->isooutdone = ubc->isooutovfl = NULL;
958 * cancel the USB request blocks for isochronous input and output
959 * errors are silently ignored
961 * B channel control structure
963 static void stopurbs(struct bas_bc_state *ubc)
967 atomic_set(&ubc->running, 0);
969 for (k = 0; k < BAS_INURBS; ++k) {
970 rc = usb_unlink_urb(ubc->isoinurbs[k]);
972 "%s: isoc input URB %d unlinked, result = %s",
973 __func__, k, get_usb_rcmsg(rc));
976 for (k = 0; k < BAS_OUTURBS; ++k) {
977 rc = usb_unlink_urb(ubc->isoouturbs[k].urb);
979 "%s: isoc output URB %d unlinked, result = %s",
980 __func__, k, get_usb_rcmsg(rc));
984 /* Isochronous Write - Bottom Half */
985 /* =============================== */
987 /* submit_iso_write_urb
988 * fill and submit the next isochronous write URB
990 * ucx context structure containing URB
992 * number of frames submitted in URB
993 * 0 if URB not submitted because no data available (isooutbuf busy)
994 * error code < 0 on error
996 static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
998 struct urb *urb = ucx->urb;
999 struct bas_bc_state *ubc = ucx->bcs->hw.bas;
1000 struct usb_iso_packet_descriptor *ifd;
1001 int corrbytes, nframe, rc;
1003 /* urb->dev is clobbered by USB subsystem */
1004 urb->dev = ucx->bcs->cs->hw.bas->udev;
1005 urb->transfer_flags = URB_ISO_ASAP;
1006 urb->transfer_buffer = ubc->isooutbuf->data;
1007 urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data);
1009 for (nframe = 0; nframe < BAS_NUMFRAMES; nframe++) {
1010 ifd = &urb->iso_frame_desc[nframe];
1012 /* compute frame length according to flow control */
1013 ifd->length = BAS_NORMFRAME;
1014 if ((corrbytes = atomic_read(&ubc->corrbytes)) != 0) {
1015 gig_dbg(DEBUG_ISO, "%s: corrbytes=%d",
1016 __func__, corrbytes);
1017 if (corrbytes > BAS_HIGHFRAME - BAS_NORMFRAME)
1018 corrbytes = BAS_HIGHFRAME - BAS_NORMFRAME;
1019 else if (corrbytes < BAS_LOWFRAME - BAS_NORMFRAME)
1020 corrbytes = BAS_LOWFRAME - BAS_NORMFRAME;
1021 ifd->length += corrbytes;
1022 atomic_add(-corrbytes, &ubc->corrbytes);
1025 /* retrieve block of data to send */
1026 ifd->offset = gigaset_isowbuf_getbytes(ubc->isooutbuf,
1028 if (ifd->offset < 0) {
1029 if (ifd->offset == -EBUSY) {
1031 "%s: buffer busy at frame %d",
1033 /* tasklet will be restarted from
1034 gigaset_send_skb() */
1036 dev_err(ucx->bcs->cs->dev,
1037 "%s: buffer error %d at frame %d\n",
1038 __func__, ifd->offset, nframe);
1043 ucx->limit = atomic_read(&ubc->isooutbuf->nextread);
1045 ifd->actual_length = 0;
1047 if (unlikely(nframe == 0))
1048 return 0; /* no data to send */
1049 urb->number_of_packets = nframe;
1051 rc = usb_submit_urb(urb, GFP_ATOMIC);
1054 /* device removed - give up silently */
1055 gig_dbg(DEBUG_ISO, "%s: disconnected", __func__);
1057 dev_err(ucx->bcs->cs->dev,
1058 "could not submit isochronous write URB: %s\n",
1066 /* write_iso_tasklet
1067 * tasklet scheduled when an isochronous output URB from the Gigaset device
1070 * data B channel state structure
1072 static void write_iso_tasklet(unsigned long data)
1074 struct bc_state *bcs = (struct bc_state *) data;
1075 struct bas_bc_state *ubc = bcs->hw.bas;
1076 struct cardstate *cs = bcs->cs;
1077 struct isow_urbctx_t *done, *next, *ovfl;
1080 struct usb_iso_packet_descriptor *ifd;
1082 unsigned long flags;
1084 struct sk_buff *skb;
1088 /* loop while completed URBs arrive in time */
1090 if (unlikely(!(atomic_read(&ubc->running)))) {
1091 gig_dbg(DEBUG_ISO, "%s: not running", __func__);
1095 /* retrieve completed URBs */
1096 spin_lock_irqsave(&ubc->isooutlock, flags);
1097 done = ubc->isooutdone;
1098 ubc->isooutdone = NULL;
1099 ovfl = ubc->isooutovfl;
1100 ubc->isooutovfl = NULL;
1101 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1103 dev_err(cs->dev, "isochronous write buffer underrun\n");
1110 /* submit free URB if available */
1111 spin_lock_irqsave(&ubc->isooutlock, flags);
1112 next = ubc->isooutfree;
1113 ubc->isooutfree = NULL;
1114 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1116 rc = submit_iso_write_urb(next);
1117 if (unlikely(rc <= 0 && rc != -ENODEV)) {
1118 /* could not submit URB, put it back */
1119 spin_lock_irqsave(&ubc->isooutlock, flags);
1120 if (ubc->isooutfree == NULL) {
1121 ubc->isooutfree = next;
1124 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1126 /* couldn't put it back */
1128 "losing isochronous write URB\n");
1134 /* process completed URB */
1136 status = done->status;
1138 case -EXDEV: /* partial completion */
1139 gig_dbg(DEBUG_ISO, "%s: URB partially completed",
1141 /* fall through - what's the difference anyway? */
1142 case 0: /* normal completion */
1143 /* inspect individual frames
1144 * assumptions (for lack of documentation):
1145 * - actual_length bytes of first frame in error are
1147 * - all following frames are not sent at all
1149 offset = done->limit; /* default (no error) */
1150 for (i = 0; i < BAS_NUMFRAMES; i++) {
1151 ifd = &urb->iso_frame_desc[i];
1153 ifd->actual_length != ifd->length) {
1155 "isochronous write: frame %d: %s, "
1156 "only %d of %d bytes sent\n",
1157 i, get_usb_statmsg(ifd->status),
1158 ifd->actual_length, ifd->length);
1159 offset = (ifd->offset +
1165 #ifdef CONFIG_GIGASET_DEBUG
1166 /* check assumption on remaining frames */
1167 for (; i < BAS_NUMFRAMES; i++) {
1168 ifd = &urb->iso_frame_desc[i];
1169 if (ifd->status != -EINPROGRESS
1170 || ifd->actual_length != 0) {
1172 "isochronous write: frame %d: %s, "
1173 "%d of %d bytes sent\n",
1174 i, get_usb_statmsg(ifd->status),
1175 ifd->actual_length, ifd->length);
1176 offset = (ifd->offset +
1184 case -EPIPE: /* stall - probably underrun */
1185 dev_err(cs->dev, "isochronous write stalled\n");
1188 default: /* severe trouble */
1189 dev_warn(cs->dev, "isochronous write: %s\n",
1190 get_usb_statmsg(status));
1193 /* mark the write buffer area covered by this URB as free */
1194 if (done->limit >= 0)
1195 atomic_set(&ubc->isooutbuf->read, done->limit);
1197 /* mark URB as free */
1198 spin_lock_irqsave(&ubc->isooutlock, flags);
1199 next = ubc->isooutfree;
1200 ubc->isooutfree = done;
1201 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1203 /* only one URB still active - resubmit one */
1204 rc = submit_iso_write_urb(next);
1205 if (unlikely(rc <= 0 && rc != -ENODEV)) {
1206 /* couldn't submit */
1212 /* process queued SKBs */
1213 while ((skb = skb_dequeue(&bcs->squeue))) {
1214 /* copy to output buffer, doing L2 encapsulation */
1216 if (gigaset_isoc_buildframe(bcs, skb->data, len) == -EAGAIN) {
1217 /* insufficient buffer space, push back onto queue */
1218 skb_queue_head(&bcs->squeue, skb);
1219 gig_dbg(DEBUG_ISO, "%s: skb requeued, qlen=%d",
1220 __func__, skb_queue_len(&bcs->squeue));
1224 gigaset_skb_sent(bcs, skb);
1225 dev_kfree_skb_any(skb);
1229 /* Isochronous Read - Bottom Half */
1230 /* ============================== */
1233 * tasklet scheduled when an isochronous input URB from the Gigaset device
1236 * data B channel state structure
1238 static void read_iso_tasklet(unsigned long data)
1240 struct bc_state *bcs = (struct bc_state *) data;
1241 struct bas_bc_state *ubc = bcs->hw.bas;
1242 struct cardstate *cs = bcs->cs;
1246 unsigned long flags;
1247 int totleft, numbytes, offset, frame, rc;
1249 /* loop while more completed URBs arrive in the meantime */
1252 spin_lock_irqsave(&ubc->isoinlock, flags);
1253 if (!(urb = ubc->isoindone)) {
1254 spin_unlock_irqrestore(&ubc->isoinlock, flags);
1257 status = ubc->isoinstatus;
1258 ubc->isoindone = NULL;
1259 if (unlikely(ubc->loststatus != -EINPROGRESS)) {
1261 "isochronous read overrun, "
1262 "dropped URB with status: %s, %d bytes lost\n",
1263 get_usb_statmsg(ubc->loststatus),
1265 ubc->loststatus = -EINPROGRESS;
1267 spin_unlock_irqrestore(&ubc->isoinlock, flags);
1269 if (unlikely(!(atomic_read(&ubc->running)))) {
1271 "%s: channel not running, "
1272 "dropped URB with status: %s",
1273 __func__, get_usb_statmsg(status));
1278 case 0: /* normal completion */
1280 case -EXDEV: /* inspect individual frames
1281 (we do that anyway) */
1282 gig_dbg(DEBUG_ISO, "%s: URB partially completed",
1288 gig_dbg(DEBUG_ISO, "%s: %s",
1289 __func__, get_usb_statmsg(status));
1290 continue; /* -> skip */
1292 dev_err(cs->dev, "isochronous read stalled\n");
1294 continue; /* -> skip */
1295 default: /* severe trouble */
1296 dev_warn(cs->dev, "isochronous read: %s\n",
1297 get_usb_statmsg(status));
1301 rcvbuf = urb->transfer_buffer;
1302 totleft = urb->actual_length;
1303 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) {
1304 if (unlikely(urb->iso_frame_desc[frame].status)) {
1306 "isochronous read: frame %d: %s\n",
1309 urb->iso_frame_desc[frame].status));
1312 numbytes = urb->iso_frame_desc[frame].actual_length;
1313 if (unlikely(numbytes > BAS_MAXFRAME)) {
1315 "isochronous read: frame %d: "
1316 "numbytes (%d) > BAS_MAXFRAME\n",
1320 if (unlikely(numbytes > totleft)) {
1322 "isochronous read: frame %d: "
1323 "numbytes (%d) > totleft (%d)\n",
1324 frame, numbytes, totleft);
1327 offset = urb->iso_frame_desc[frame].offset;
1328 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) {
1330 "isochronous read: frame %d: "
1331 "offset (%d) + numbytes (%d) "
1332 "> BAS_INBUFSIZE\n",
1333 frame, offset, numbytes);
1336 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs);
1337 totleft -= numbytes;
1339 if (unlikely(totleft > 0))
1341 "isochronous read: %d data bytes missing\n",
1345 /* URB processed, resubmit */
1346 for (frame = 0; frame < BAS_NUMFRAMES; frame++) {
1347 urb->iso_frame_desc[frame].status = 0;
1348 urb->iso_frame_desc[frame].actual_length = 0;
1350 /* urb->dev is clobbered by USB subsystem */
1351 urb->dev = bcs->cs->hw.bas->udev;
1352 urb->transfer_flags = URB_ISO_ASAP;
1353 urb->number_of_packets = BAS_NUMFRAMES;
1354 rc = usb_submit_urb(urb, GFP_ATOMIC);
1355 if (unlikely(rc != 0 && rc != -ENODEV)) {
1357 "could not resubmit isochronous read URB: %s\n",
1359 dump_urb(DEBUG_ISO, "resubmit iso read", urb);
1365 /* Channel Operations */
1366 /* ================== */
1369 * timeout routine for control output request
1371 * B channel control structure
1373 static void req_timeout(unsigned long data)
1375 struct bc_state *bcs = (struct bc_state *) data;
1376 struct bas_cardstate *ucs = bcs->cs->hw.bas;
1378 unsigned long flags;
1382 spin_lock_irqsave(&ucs->lock, flags);
1383 pending = ucs->pending;
1385 spin_unlock_irqrestore(&ucs->lock, flags);
1388 case 0: /* no pending request */
1389 gig_dbg(DEBUG_USBREQ, "%s: no request pending", __func__);
1392 case HD_OPEN_ATCHANNEL:
1393 dev_err(bcs->cs->dev, "timeout opening AT channel\n");
1394 error_reset(bcs->cs);
1397 case HD_OPEN_B2CHANNEL:
1398 case HD_OPEN_B1CHANNEL:
1399 dev_err(bcs->cs->dev, "timeout opening channel %d\n",
1404 case HD_CLOSE_ATCHANNEL:
1405 dev_err(bcs->cs->dev, "timeout closing AT channel\n");
1408 case HD_CLOSE_B2CHANNEL:
1409 case HD_CLOSE_B1CHANNEL:
1410 dev_err(bcs->cs->dev, "timeout closing channel %d\n",
1412 error_reset(bcs->cs);
1416 dev_warn(bcs->cs->dev, "request 0x%02x timed out, clearing\n",
1421 /* write_ctrl_callback
1422 * USB completion handler for control pipe output
1423 * called by the USB subsystem in interrupt context
1425 * urb USB request block of completed request
1426 * urb->context = hardware specific controller state structure
1428 static void write_ctrl_callback(struct urb *urb)
1430 struct bas_cardstate *ucs = urb->context;
1431 int status = urb->status;
1433 unsigned long flags;
1437 case 0: /* normal completion */
1438 spin_lock_irqsave(&ucs->lock, flags);
1439 switch (ucs->pending) {
1440 case HD_DEVICE_INIT_ACK: /* no reply expected */
1441 del_timer(&ucs->timer_ctrl);
1445 spin_unlock_irqrestore(&ucs->lock, flags);
1448 case -ENOENT: /* cancelled */
1449 case -ECONNRESET: /* cancelled (async) */
1450 case -EINPROGRESS: /* pending */
1451 case -ENODEV: /* device removed */
1452 case -ESHUTDOWN: /* device shut down */
1453 /* ignore silently */
1454 gig_dbg(DEBUG_USBREQ, "%s: %s",
1455 __func__, get_usb_statmsg(status));
1458 default: /* any failure */
1459 if (++ucs->retry_ctrl > BAS_RETRY) {
1460 dev_err(&ucs->interface->dev,
1461 "control request 0x%02x failed: %s\n",
1462 ucs->dr_ctrl.bRequest,
1463 get_usb_statmsg(status));
1464 break; /* give up */
1466 dev_notice(&ucs->interface->dev,
1467 "control request 0x%02x: %s, retry %d\n",
1468 ucs->dr_ctrl.bRequest, get_usb_statmsg(status),
1470 /* urb->dev is clobbered by USB subsystem */
1471 urb->dev = ucs->udev;
1472 rc = usb_submit_urb(urb, GFP_ATOMIC);
1474 dev_err(&ucs->interface->dev,
1475 "could not resubmit request 0x%02x: %s\n",
1476 ucs->dr_ctrl.bRequest, get_usb_rcmsg(rc));
1483 /* failed, clear pending request */
1484 spin_lock_irqsave(&ucs->lock, flags);
1485 del_timer(&ucs->timer_ctrl);
1487 spin_unlock_irqrestore(&ucs->lock, flags);
1491 * submit a control output request without message buffer to the Gigaset base
1492 * and optionally start a timeout
1494 * bcs B channel control structure
1495 * req control request code (HD_*)
1496 * val control request parameter value (set to 0 if unused)
1497 * timeout timeout in seconds (0: no timeout)
1500 * -EBUSY if another request is pending
1501 * any URB submission error code
1503 static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
1505 struct bas_cardstate *ucs = bcs->cs->hw.bas;
1507 unsigned long flags;
1509 gig_dbg(DEBUG_USBREQ, "-------> 0x%02x (%d)", req, val);
1511 spin_lock_irqsave(&ucs->lock, flags);
1513 spin_unlock_irqrestore(&ucs->lock, flags);
1514 dev_err(bcs->cs->dev,
1515 "submission of request 0x%02x failed: "
1516 "request 0x%02x still pending\n",
1521 ucs->dr_ctrl.bRequestType = OUT_VENDOR_REQ;
1522 ucs->dr_ctrl.bRequest = req;
1523 ucs->dr_ctrl.wValue = cpu_to_le16(val);
1524 ucs->dr_ctrl.wIndex = 0;
1525 ucs->dr_ctrl.wLength = 0;
1526 usb_fill_control_urb(ucs->urb_ctrl, ucs->udev,
1527 usb_sndctrlpipe(ucs->udev, 0),
1528 (unsigned char*) &ucs->dr_ctrl, NULL, 0,
1529 write_ctrl_callback, ucs);
1530 ucs->retry_ctrl = 0;
1531 ret = usb_submit_urb(ucs->urb_ctrl, GFP_ATOMIC);
1532 if (unlikely(ret)) {
1533 dev_err(bcs->cs->dev, "could not submit request 0x%02x: %s\n",
1534 req, get_usb_rcmsg(ret));
1535 spin_unlock_irqrestore(&ucs->lock, flags);
1541 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
1542 ucs->timer_ctrl.expires = jiffies + timeout * HZ / 10;
1543 ucs->timer_ctrl.data = (unsigned long) bcs;
1544 ucs->timer_ctrl.function = req_timeout;
1545 add_timer(&ucs->timer_ctrl);
1548 spin_unlock_irqrestore(&ucs->lock, flags);
1552 /* gigaset_init_bchannel
1553 * called by common.c to connect a B channel
1554 * initialize isochronous I/O and tell the Gigaset base to open the channel
1556 * B channel control structure
1558 * 0 on success, error code < 0 on error
1560 static int gigaset_init_bchannel(struct bc_state *bcs)
1562 struct cardstate *cs = bcs->cs;
1564 unsigned long flags;
1566 spin_lock_irqsave(&cs->lock, flags);
1567 if (unlikely(!cs->connected)) {
1568 gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__);
1569 spin_unlock_irqrestore(&cs->lock, flags);
1573 if ((ret = starturbs(bcs)) < 0) {
1575 "could not start isochronous I/O for channel B%d: %s\n",
1577 ret == -EFAULT ? "null URB" : get_usb_rcmsg(ret));
1580 spin_unlock_irqrestore(&cs->lock, flags);
1584 req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL;
1585 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) {
1586 dev_err(cs->dev, "could not open channel B%d\n",
1588 stopurbs(bcs->hw.bas);
1593 spin_unlock_irqrestore(&cs->lock, flags);
1597 /* gigaset_close_bchannel
1598 * called by common.c to disconnect a B channel
1599 * tell the Gigaset base to close the channel
1600 * stopping isochronous I/O and LL notification will be done when the
1601 * acknowledgement for the close arrives
1603 * B channel control structure
1605 * 0 on success, error code < 0 on error
1607 static int gigaset_close_bchannel(struct bc_state *bcs)
1609 struct cardstate *cs = bcs->cs;
1611 unsigned long flags;
1613 spin_lock_irqsave(&cs->lock, flags);
1614 if (unlikely(!cs->connected)) {
1615 spin_unlock_irqrestore(&cs->lock, flags);
1616 gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__);
1620 if (!(atomic_read(&cs->hw.bas->basstate) &
1621 (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) {
1622 /* channel not running: just signal common.c */
1623 spin_unlock_irqrestore(&cs->lock, flags);
1624 gigaset_bchannel_down(bcs);
1628 /* channel running: tell device to close it */
1629 req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL;
1630 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0)
1631 dev_err(cs->dev, "closing channel B%d failed\n",
1634 spin_unlock_irqrestore(&cs->lock, flags);
1638 /* Device Operations */
1639 /* ================= */
1642 * unqueue first command buffer from queue, waking any sleepers
1643 * must be called with cs->cmdlock held
1645 * cs controller state structure
1647 static void complete_cb(struct cardstate *cs)
1649 struct cmdbuf_t *cb = cs->cmdbuf;
1651 /* unqueue completed buffer */
1652 cs->cmdbytes -= cs->curlen;
1653 gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD,
1654 "write_command: sent %u bytes, %u left",
1655 cs->curlen, cs->cmdbytes);
1656 if ((cs->cmdbuf = cb->next) != NULL) {
1657 cs->cmdbuf->prev = NULL;
1658 cs->curlen = cs->cmdbuf->len;
1660 cs->lastcmdbuf = NULL;
1664 if (cb->wake_tasklet)
1665 tasklet_schedule(cb->wake_tasklet);
1670 /* write_command_callback
1671 * USB completion handler for AT command transmission
1672 * called by the USB subsystem in interrupt context
1674 * urb USB request block of completed request
1675 * urb->context = controller state structure
1677 static void write_command_callback(struct urb *urb)
1679 struct cardstate *cs = urb->context;
1680 struct bas_cardstate *ucs = cs->hw.bas;
1681 int status = urb->status;
1682 unsigned long flags;
1684 update_basstate(ucs, 0, BS_ATWRPEND);
1688 case 0: /* normal completion */
1690 case -ENOENT: /* cancelled */
1691 case -ECONNRESET: /* cancelled (async) */
1692 case -EINPROGRESS: /* pending */
1693 case -ENODEV: /* device removed */
1694 case -ESHUTDOWN: /* device shut down */
1695 /* ignore silently */
1696 gig_dbg(DEBUG_USBREQ, "%s: %s",
1697 __func__, get_usb_statmsg(status));
1699 default: /* any failure */
1700 if (++ucs->retry_cmd_out > BAS_RETRY) {
1702 "command write: %s, "
1703 "giving up after %d retries\n",
1704 get_usb_statmsg(status),
1705 ucs->retry_cmd_out);
1708 if (cs->cmdbuf == NULL) {
1710 "command write: %s, "
1711 "cannot retry - cmdbuf gone\n",
1712 get_usb_statmsg(status));
1715 dev_notice(cs->dev, "command write: %s, retry %d\n",
1716 get_usb_statmsg(status), ucs->retry_cmd_out);
1717 if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0)
1718 /* resubmitted - bypass regular exit block */
1720 /* command send failed, assume base still waiting */
1721 update_basstate(ucs, BS_ATREADY, 0);
1724 spin_lock_irqsave(&cs->cmdlock, flags);
1725 if (cs->cmdbuf != NULL)
1727 spin_unlock_irqrestore(&cs->cmdlock, flags);
1731 * timeout routine for AT command transmission
1733 * controller state structure
1735 static void atrdy_timeout(unsigned long data)
1737 struct cardstate *cs = (struct cardstate *) data;
1738 struct bas_cardstate *ucs = cs->hw.bas;
1740 dev_warn(cs->dev, "timeout waiting for HD_READY_SEND_ATDATA\n");
1742 /* fake the missing signal - what else can I do? */
1743 update_basstate(ucs, BS_ATREADY, BS_ATTIMER);
1748 * submit an HD_WRITE_ATMESSAGE command URB
1750 * cs controller state structure
1751 * buf buffer containing command to send
1752 * len length of command to send
1755 * -EBUSY if another request is pending
1756 * any URB submission error code
1758 static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1760 struct bas_cardstate *ucs = cs->hw.bas;
1763 gig_dbg(DEBUG_USBREQ, "-------> HD_WRITE_ATMESSAGE (%d)", len);
1765 if (update_basstate(ucs, BS_ATWRPEND, 0) & BS_ATWRPEND) {
1767 "could not submit HD_WRITE_ATMESSAGE: URB busy\n");
1771 ucs->dr_cmd_out.bRequestType = OUT_VENDOR_REQ;
1772 ucs->dr_cmd_out.bRequest = HD_WRITE_ATMESSAGE;
1773 ucs->dr_cmd_out.wValue = 0;
1774 ucs->dr_cmd_out.wIndex = 0;
1775 ucs->dr_cmd_out.wLength = cpu_to_le16(len);
1776 usb_fill_control_urb(ucs->urb_cmd_out, ucs->udev,
1777 usb_sndctrlpipe(ucs->udev, 0),
1778 (unsigned char*) &ucs->dr_cmd_out, buf, len,
1779 write_command_callback, cs);
1780 rc = usb_submit_urb(ucs->urb_cmd_out, GFP_ATOMIC);
1782 update_basstate(ucs, 0, BS_ATWRPEND);
1783 dev_err(cs->dev, "could not submit HD_WRITE_ATMESSAGE: %s\n",
1788 /* submitted successfully, start timeout if necessary */
1789 if (!(update_basstate(ucs, BS_ATTIMER, BS_ATREADY) & BS_ATTIMER)) {
1790 gig_dbg(DEBUG_OUTPUT, "setting ATREADY timeout of %d/10 secs",
1792 ucs->timer_atrdy.expires = jiffies + ATRDY_TIMEOUT * HZ / 10;
1793 ucs->timer_atrdy.data = (unsigned long) cs;
1794 ucs->timer_atrdy.function = atrdy_timeout;
1795 add_timer(&ucs->timer_atrdy);
1801 * start transmission of AT command queue if necessary
1803 * cs controller state structure
1806 * error code < 0 on error
1808 static int start_cbsend(struct cardstate *cs)
1810 struct cmdbuf_t *cb;
1811 struct bas_cardstate *ucs = cs->hw.bas;
1812 unsigned long flags;
1816 /* check if AT channel is open */
1817 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) {
1818 gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD, "AT channel not open");
1819 rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT);
1821 /* flush command queue */
1822 spin_lock_irqsave(&cs->cmdlock, flags);
1823 while (cs->cmdbuf != NULL)
1825 spin_unlock_irqrestore(&cs->cmdlock, flags);
1830 /* try to send first command in queue */
1831 spin_lock_irqsave(&cs->cmdlock, flags);
1833 while ((cb = cs->cmdbuf) != NULL &&
1834 atomic_read(&ucs->basstate) & BS_ATREADY) {
1835 ucs->retry_cmd_out = 0;
1836 rc = atwrite_submit(cs, cb->buf, cb->len);
1843 spin_unlock_irqrestore(&cs->cmdlock, flags);
1847 /* gigaset_write_cmd
1848 * This function is called by the device independent part of the driver
1849 * to transmit an AT command string to the Gigaset device.
1850 * It encapsulates the device specific method for transmission over the
1851 * direct USB connection to the base.
1852 * The command string is added to the queue of commands to send, and
1853 * USB transmission is started if necessary.
1855 * cs controller state structure
1856 * buf command string to send
1857 * len number of bytes to send (max. IF_WRITEBUF)
1858 * wake_tasklet tasklet to run when transmission is completed
1861 * number of bytes queued on success
1862 * error code < 0 on error
1864 static int gigaset_write_cmd(struct cardstate *cs,
1865 const unsigned char *buf, int len,
1866 struct tasklet_struct *wake_tasklet)
1868 struct cmdbuf_t *cb;
1869 unsigned long flags;
1872 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
1873 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
1874 "CMD Transmit", len, buf);
1882 if (len > IF_WRITEBUF)
1884 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
1885 dev_err(cs->dev, "%s: out of memory\n", __func__);
1890 memcpy(cb->buf, buf, len);
1894 cb->wake_tasklet = wake_tasklet;
1896 spin_lock_irqsave(&cs->cmdlock, flags);
1897 cb->prev = cs->lastcmdbuf;
1899 cs->lastcmdbuf->next = cb;
1904 cs->cmdbytes += len;
1905 cs->lastcmdbuf = cb;
1906 spin_unlock_irqrestore(&cs->cmdlock, flags);
1908 spin_lock_irqsave(&cs->lock, flags);
1909 if (unlikely(!cs->connected)) {
1910 spin_unlock_irqrestore(&cs->lock, flags);
1911 gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__);
1912 /* flush command queue */
1913 spin_lock_irqsave(&cs->cmdlock, flags);
1914 while (cs->cmdbuf != NULL)
1916 spin_unlock_irqrestore(&cs->cmdlock, flags);
1919 rc = start_cbsend(cs);
1920 spin_unlock_irqrestore(&cs->lock, flags);
1921 return rc < 0 ? rc : len;
1923 notqueued: /* request handled without queuing */
1925 tasklet_schedule(wake_tasklet);
1929 /* gigaset_write_room
1930 * tty_driver.write_room interface routine
1931 * return number of characters the driver will accept to be written via
1934 * controller state structure
1936 * number of characters
1938 static int gigaset_write_room(struct cardstate *cs)
1943 /* gigaset_chars_in_buffer
1944 * tty_driver.chars_in_buffer interface routine
1945 * return number of characters waiting to be sent
1947 * controller state structure
1949 * number of characters
1951 static int gigaset_chars_in_buffer(struct cardstate *cs)
1953 return cs->cmdbytes;
1957 * implementation of ioctl(GIGASET_BRKCHARS)
1959 * controller state structure
1961 * -EINVAL (unimplemented function)
1963 static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
1969 /* Device Initialization/Shutdown */
1970 /* ============================== */
1972 /* Free hardware dependent part of the B channel structure
1974 * bcs B channel structure
1978 static int gigaset_freebcshw(struct bc_state *bcs)
1980 struct bas_bc_state *ubc = bcs->hw.bas;
1986 /* kill URBs and tasklets before freeing - better safe than sorry */
1987 atomic_set(&ubc->running, 0);
1988 gig_dbg(DEBUG_INIT, "%s: killing iso URBs", __func__);
1989 for (i = 0; i < BAS_OUTURBS; ++i) {
1990 usb_kill_urb(ubc->isoouturbs[i].urb);
1991 usb_free_urb(ubc->isoouturbs[i].urb);
1993 for (i = 0; i < BAS_INURBS; ++i) {
1994 usb_kill_urb(ubc->isoinurbs[i]);
1995 usb_free_urb(ubc->isoinurbs[i]);
1997 tasklet_kill(&ubc->sent_tasklet);
1998 tasklet_kill(&ubc->rcvd_tasklet);
1999 kfree(ubc->isooutbuf);
2005 /* Initialize hardware dependent part of the B channel structure
2007 * bcs B channel structure
2011 static int gigaset_initbcshw(struct bc_state *bcs)
2014 struct bas_bc_state *ubc;
2016 bcs->hw.bas = ubc = kmalloc(sizeof(struct bas_bc_state), GFP_KERNEL);
2018 err("could not allocate bas_bc_state");
2022 atomic_set(&ubc->running, 0);
2023 atomic_set(&ubc->corrbytes, 0);
2024 spin_lock_init(&ubc->isooutlock);
2025 for (i = 0; i < BAS_OUTURBS; ++i) {
2026 ubc->isoouturbs[i].urb = NULL;
2027 ubc->isoouturbs[i].bcs = bcs;
2029 ubc->isooutdone = ubc->isooutfree = ubc->isooutovfl = NULL;
2031 if (!(ubc->isooutbuf = kmalloc(sizeof(struct isowbuf_t), GFP_KERNEL))) {
2032 err("could not allocate isochronous output buffer");
2037 tasklet_init(&ubc->sent_tasklet,
2038 &write_iso_tasklet, (unsigned long) bcs);
2040 spin_lock_init(&ubc->isoinlock);
2041 for (i = 0; i < BAS_INURBS; ++i)
2042 ubc->isoinurbs[i] = NULL;
2043 ubc->isoindone = NULL;
2044 ubc->loststatus = -EINPROGRESS;
2058 tasklet_init(&ubc->rcvd_tasklet,
2059 &read_iso_tasklet, (unsigned long) bcs);
2063 static void gigaset_reinitbcshw(struct bc_state *bcs)
2065 struct bas_bc_state *ubc = bcs->hw.bas;
2067 atomic_set(&bcs->hw.bas->running, 0);
2068 atomic_set(&bcs->hw.bas->corrbytes, 0);
2069 bcs->hw.bas->numsub = 0;
2070 spin_lock_init(&ubc->isooutlock);
2071 spin_lock_init(&ubc->isoinlock);
2072 ubc->loststatus = -EINPROGRESS;
2075 static void gigaset_freecshw(struct cardstate *cs)
2077 /* timers, URBs and rcvbuf are disposed of in disconnect */
2082 static int gigaset_initcshw(struct cardstate *cs)
2084 struct bas_cardstate *ucs;
2086 cs->hw.bas = ucs = kmalloc(sizeof *ucs, GFP_KERNEL);
2090 ucs->urb_cmd_in = NULL;
2091 ucs->urb_cmd_out = NULL;
2093 ucs->rcvbuf_size = 0;
2095 spin_lock_init(&ucs->lock);
2098 atomic_set(&ucs->basstate, 0);
2099 init_timer(&ucs->timer_ctrl);
2100 init_timer(&ucs->timer_atrdy);
2101 init_timer(&ucs->timer_cmd_in);
2107 * unlink and deallocate all URBs unconditionally
2108 * caller must make sure that no commands are still in progress
2110 * cs controller state structure
2112 static void freeurbs(struct cardstate *cs)
2114 struct bas_cardstate *ucs = cs->hw.bas;
2115 struct bas_bc_state *ubc;
2118 gig_dbg(DEBUG_INIT, "%s: killing URBs", __func__);
2119 for (j = 0; j < BAS_CHANNELS; ++j) {
2120 ubc = cs->bcs[j].hw.bas;
2121 for (i = 0; i < BAS_OUTURBS; ++i) {
2122 usb_kill_urb(ubc->isoouturbs[i].urb);
2123 usb_free_urb(ubc->isoouturbs[i].urb);
2124 ubc->isoouturbs[i].urb = NULL;
2126 for (i = 0; i < BAS_INURBS; ++i) {
2127 usb_kill_urb(ubc->isoinurbs[i]);
2128 usb_free_urb(ubc->isoinurbs[i]);
2129 ubc->isoinurbs[i] = NULL;
2132 usb_kill_urb(ucs->urb_int_in);
2133 usb_free_urb(ucs->urb_int_in);
2134 ucs->urb_int_in = NULL;
2135 usb_kill_urb(ucs->urb_cmd_out);
2136 usb_free_urb(ucs->urb_cmd_out);
2137 ucs->urb_cmd_out = NULL;
2138 usb_kill_urb(ucs->urb_cmd_in);
2139 usb_free_urb(ucs->urb_cmd_in);
2140 ucs->urb_cmd_in = NULL;
2141 usb_kill_urb(ucs->urb_ctrl);
2142 usb_free_urb(ucs->urb_ctrl);
2143 ucs->urb_ctrl = NULL;
2147 * This function is called when a new USB device is connected.
2148 * It checks whether the new device is handled by this driver.
2150 static int gigaset_probe(struct usb_interface *interface,
2151 const struct usb_device_id *id)
2153 struct usb_host_interface *hostif;
2154 struct usb_device *udev = interface_to_usbdev(interface);
2155 struct cardstate *cs = NULL;
2156 struct bas_cardstate *ucs = NULL;
2157 struct bas_bc_state *ubc;
2158 struct usb_endpoint_descriptor *endpoint;
2163 "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
2164 __func__, le16_to_cpu(udev->descriptor.idVendor),
2165 le16_to_cpu(udev->descriptor.idProduct));
2167 /* set required alternate setting */
2168 hostif = interface->cur_altsetting;
2169 if (hostif->desc.bAlternateSetting != 3) {
2171 "%s: wrong alternate setting %d - trying to switch",
2172 __func__, hostif->desc.bAlternateSetting);
2173 if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) < 0) {
2174 dev_warn(&udev->dev, "usb_set_interface failed, "
2175 "device %d interface %d altsetting %d\n",
2176 udev->devnum, hostif->desc.bInterfaceNumber,
2177 hostif->desc.bAlternateSetting);
2180 hostif = interface->cur_altsetting;
2183 /* Reject application specific interfaces
2185 if (hostif->desc.bInterfaceClass != 255) {
2186 dev_warn(&udev->dev, "%s: bInterfaceClass == %d\n",
2187 __func__, hostif->desc.bInterfaceClass);
2191 dev_info(&udev->dev,
2192 "%s: Device matched (Vendor: 0x%x, Product: 0x%x)\n",
2193 __func__, le16_to_cpu(udev->descriptor.idVendor),
2194 le16_to_cpu(udev->descriptor.idProduct));
2196 cs = gigaset_getunassignedcs(driver);
2198 dev_err(&udev->dev, "no free cardstate\n");
2203 /* save off device structure ptrs for later use */
2206 ucs->interface = interface;
2207 cs->dev = &interface->dev;
2210 * - one for the interrupt pipe
2211 * - three for the different uses of the default control pipe
2212 * - three for each isochronous pipe
2214 if (!(ucs->urb_int_in = usb_alloc_urb(0, GFP_KERNEL)) ||
2215 !(ucs->urb_cmd_in = usb_alloc_urb(0, GFP_KERNEL)) ||
2216 !(ucs->urb_cmd_out = usb_alloc_urb(0, GFP_KERNEL)) ||
2217 !(ucs->urb_ctrl = usb_alloc_urb(0, GFP_KERNEL)))
2220 for (j = 0; j < BAS_CHANNELS; ++j) {
2221 ubc = cs->bcs[j].hw.bas;
2222 for (i = 0; i < BAS_OUTURBS; ++i)
2223 if (!(ubc->isoouturbs[i].urb =
2224 usb_alloc_urb(BAS_NUMFRAMES, GFP_KERNEL)))
2226 for (i = 0; i < BAS_INURBS; ++i)
2227 if (!(ubc->isoinurbs[i] =
2228 usb_alloc_urb(BAS_NUMFRAMES, GFP_KERNEL)))
2233 ucs->rcvbuf_size = 0;
2235 /* Fill the interrupt urb and send it to the core */
2236 endpoint = &hostif->endpoint[0].desc;
2237 usb_fill_int_urb(ucs->urb_int_in, udev,
2238 usb_rcvintpipe(udev,
2239 (endpoint->bEndpointAddress) & 0x0f),
2240 ucs->int_in_buf, 3, read_int_callback, cs,
2241 endpoint->bInterval);
2242 if ((rc = usb_submit_urb(ucs->urb_int_in, GFP_KERNEL)) != 0) {
2243 dev_err(cs->dev, "could not submit interrupt URB: %s\n",
2248 /* tell the device that the driver is ready */
2249 if ((rc = req_submit(cs->bcs, HD_DEVICE_INIT_ACK, 0, 0)) != 0)
2252 /* tell common part that the device is ready */
2253 if (startmode == SM_LOCKED)
2254 atomic_set(&cs->mstate, MS_LOCKED);
2256 /* save address of controller structure */
2257 usb_set_intfdata(interface, cs);
2259 if (!gigaset_start(cs))
2265 dev_err(cs->dev, "could not allocate URBs\n");
2268 usb_set_intfdata(interface, NULL);
2269 gigaset_unassign(cs);
2273 /* gigaset_disconnect
2274 * This function is called when the Gigaset base is unplugged.
2276 static void gigaset_disconnect(struct usb_interface *interface)
2278 struct cardstate *cs;
2279 struct bas_cardstate *ucs;
2282 cs = usb_get_intfdata(interface);
2286 dev_info(cs->dev, "disconnecting Gigaset base\n");
2288 /* mark base as not ready, all channels disconnected */
2289 atomic_set(&ucs->basstate, 0);
2291 /* tell LL all channels are down */
2292 for (j = 0; j < BAS_CHANNELS; ++j)
2293 gigaset_bchannel_down(cs->bcs + j);
2295 /* stop driver (common part) */
2298 /* stop timers and URBs, free ressources */
2299 del_timer_sync(&ucs->timer_ctrl);
2300 del_timer_sync(&ucs->timer_atrdy);
2301 del_timer_sync(&ucs->timer_cmd_in);
2303 usb_set_intfdata(interface, NULL);
2306 ucs->rcvbuf_size = 0;
2307 usb_put_dev(ucs->udev);
2308 ucs->interface = NULL;
2311 gigaset_unassign(cs);
2314 static const struct gigaset_ops gigops = {
2317 gigaset_chars_in_buffer,
2319 gigaset_init_bchannel,
2320 gigaset_close_bchannel,
2323 gigaset_reinitbcshw,
2326 gigaset_set_modem_ctrl,
2328 gigaset_set_line_ctrl,
2329 gigaset_isoc_send_skb,
2334 * This function is called after the kernel module is loaded.
2336 static int __init bas_gigaset_init(void)
2340 /* allocate memory for our driver state and intialize it */
2341 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
2342 GIGASET_MODULENAME, GIGASET_DEVNAME,
2343 &gigops, THIS_MODULE)) == NULL)
2346 /* allocate memory for our device state and intialize it */
2347 cardstate = gigaset_initcs(driver, BAS_CHANNELS, 0, 0, cidmode,
2348 GIGASET_MODULENAME);
2352 /* register this driver with the USB subsystem */
2353 result = usb_register(&gigaset_usb_driver);
2355 err("usb_register failed (error %d)", -result);
2359 info(DRIVER_AUTHOR);
2363 error: if (cardstate)
2364 gigaset_freecs(cardstate);
2367 gigaset_freedriver(driver);
2373 * This function is called before the kernel module is unloaded.
2375 static void __exit bas_gigaset_exit(void)
2377 struct bas_cardstate *ucs = cardstate->hw.bas;
2379 gigaset_blockdriver(driver); /* => probe will fail
2380 * => no gigaset_start any more
2383 gigaset_shutdown(cardstate);
2384 /* from now on, no isdn callback should be possible */
2386 /* close all still open channels */
2387 if (atomic_read(&ucs->basstate) & BS_B1OPEN) {
2388 gig_dbg(DEBUG_INIT, "closing B1 channel");
2389 usb_control_msg(ucs->udev, usb_sndctrlpipe(ucs->udev, 0),
2390 HD_CLOSE_B1CHANNEL, OUT_VENDOR_REQ, 0, 0,
2391 NULL, 0, BAS_TIMEOUT);
2393 if (atomic_read(&ucs->basstate) & BS_B2OPEN) {
2394 gig_dbg(DEBUG_INIT, "closing B2 channel");
2395 usb_control_msg(ucs->udev, usb_sndctrlpipe(ucs->udev, 0),
2396 HD_CLOSE_B2CHANNEL, OUT_VENDOR_REQ, 0, 0,
2397 NULL, 0, BAS_TIMEOUT);
2399 if (atomic_read(&ucs->basstate) & BS_ATOPEN) {
2400 gig_dbg(DEBUG_INIT, "closing AT channel");
2401 usb_control_msg(ucs->udev, usb_sndctrlpipe(ucs->udev, 0),
2402 HD_CLOSE_ATCHANNEL, OUT_VENDOR_REQ, 0, 0,
2403 NULL, 0, BAS_TIMEOUT);
2405 atomic_set(&ucs->basstate, 0);
2407 /* deregister this driver with the USB subsystem */
2408 usb_deregister(&gigaset_usb_driver);
2409 /* this will call the disconnect-callback */
2410 /* from now on, no disconnect/probe callback should be running */
2412 gigaset_freecs(cardstate);
2414 gigaset_freedriver(driver);
2419 module_init(bas_gigaset_init);
2420 module_exit(bas_gigaset_exit);
2422 MODULE_AUTHOR(DRIVER_AUTHOR);
2423 MODULE_DESCRIPTION(DRIVER_DESC);
2424 MODULE_LICENSE("GPL");