Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 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>, |
Tilman Schmidt | 70440cf | 2006-04-10 22:55:14 -0700 | [diff] [blame] | 6 | * Stefan Eilers. |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 7 | * |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 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 | * ===================================================================== |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include "gigaset.h" |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 17 | #include <linux/usb.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/moduleparam.h> |
| 20 | |
| 21 | /* Version Information */ |
Tilman Schmidt | 70440cf | 2006-04-10 22:55:14 -0700 | [diff] [blame] | 22 | #define DRIVER_AUTHOR "Tilman Schmidt <tilman@imap.cc>, Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers" |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 23 | #define DRIVER_DESC "USB Driver for Gigaset 307x" |
| 24 | |
| 25 | |
| 26 | /* Module parameters */ |
| 27 | |
| 28 | static int startmode = SM_ISDN; |
| 29 | static int cidmode = 1; |
| 30 | |
| 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 | |
| 36 | #define GIGASET_MINORS 1 |
| 37 | #define GIGASET_MINOR 16 |
| 38 | #define GIGASET_MODULENAME "bas_gigaset" |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 39 | #define GIGASET_DEVNAME "ttyGB" |
| 40 | |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 41 | /* length limit according to Siemens 3070usb-protokoll.doc ch. 2.1 */ |
| 42 | #define IF_WRITEBUF 264 |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 43 | |
Tilman Schmidt | 170ebf8 | 2009-03-18 23:44:23 -0700 | [diff] [blame] | 44 | /* interrupt pipe message size according to ibid. ch. 2.2 */ |
| 45 | #define IP_MSGSIZE 3 |
| 46 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 47 | /* Values for the Gigaset 307x */ |
| 48 | #define USB_GIGA_VENDOR_ID 0x0681 |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 49 | #define USB_3070_PRODUCT_ID 0x0001 |
| 50 | #define USB_3075_PRODUCT_ID 0x0002 |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 51 | #define USB_SX303_PRODUCT_ID 0x0021 |
| 52 | #define USB_SX353_PRODUCT_ID 0x0022 |
| 53 | |
| 54 | /* table of devices that work with this driver */ |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 55 | static const struct usb_device_id gigaset_table[] = { |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 56 | { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_3070_PRODUCT_ID) }, |
| 57 | { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_3075_PRODUCT_ID) }, |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 58 | { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX303_PRODUCT_ID) }, |
| 59 | { USB_DEVICE(USB_GIGA_VENDOR_ID, USB_SX353_PRODUCT_ID) }, |
| 60 | { } /* Terminating entry */ |
| 61 | }; |
| 62 | |
| 63 | MODULE_DEVICE_TABLE(usb, gigaset_table); |
| 64 | |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 65 | /*======================= local function prototypes ==========================*/ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 66 | |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 67 | /* function called if a new device belonging to this driver is connected */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 68 | static int gigaset_probe(struct usb_interface *interface, |
| 69 | const struct usb_device_id *id); |
| 70 | |
| 71 | /* Function will be called if the device is unplugged */ |
| 72 | static void gigaset_disconnect(struct usb_interface *interface); |
| 73 | |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 74 | /* functions called before/after suspend */ |
| 75 | static int gigaset_suspend(struct usb_interface *intf, pm_message_t message); |
| 76 | static int gigaset_resume(struct usb_interface *intf); |
| 77 | |
| 78 | /* functions called before/after device reset */ |
| 79 | static int gigaset_pre_reset(struct usb_interface *intf); |
| 80 | static int gigaset_post_reset(struct usb_interface *intf); |
| 81 | |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 82 | static int atread_submit(struct cardstate *, int); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 83 | static void stopurbs(struct bas_bc_state *); |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 84 | static int req_submit(struct bc_state *, int, int, int); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 85 | static int atwrite_submit(struct cardstate *, unsigned char *, int); |
| 86 | static int start_cbsend(struct cardstate *); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 87 | |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 88 | /*============================================================================*/ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 89 | |
| 90 | struct bas_cardstate { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 91 | struct usb_device *udev; /* USB device pointer */ |
| 92 | struct usb_interface *interface; /* interface for this device */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 93 | unsigned char minor; /* starting minor number */ |
| 94 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 95 | struct urb *urb_ctrl; /* control pipe default URB */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 96 | struct usb_ctrlrequest dr_ctrl; |
| 97 | struct timer_list timer_ctrl; /* control request timeout */ |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 98 | int retry_ctrl; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 99 | |
| 100 | struct timer_list timer_atrdy; /* AT command ready timeout */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 101 | struct urb *urb_cmd_out; /* for sending AT commands */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 102 | struct usb_ctrlrequest dr_cmd_out; |
| 103 | int retry_cmd_out; |
| 104 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 105 | struct urb *urb_cmd_in; /* for receiving AT replies */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 106 | struct usb_ctrlrequest dr_cmd_in; |
| 107 | struct timer_list timer_cmd_in; /* receive request timeout */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 108 | unsigned char *rcvbuf; /* AT reply receive buffer */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 109 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 110 | struct urb *urb_int_in; /* URB for interrupt pipe */ |
Tilman Schmidt | 170ebf8 | 2009-03-18 23:44:23 -0700 | [diff] [blame] | 111 | unsigned char *int_in_buf; |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 112 | struct work_struct int_in_wq; /* for usb_clear_halt() */ |
| 113 | struct timer_list timer_int_in; /* int read retry delay */ |
| 114 | int retry_int_in; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 115 | |
| 116 | spinlock_t lock; /* locks all following */ |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 117 | int basstate; /* bitmap (BS_*) */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 118 | int pending; /* uncompleted base request */ |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 119 | wait_queue_head_t waitqueue; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 120 | int rcvbuf_size; /* size of AT receive buffer */ |
| 121 | /* 0: no receive in progress */ |
| 122 | int retry_cmd_in; /* receive req retry count */ |
| 123 | }; |
| 124 | |
| 125 | /* status of direct USB connection to 307x base (bits in basstate) */ |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 126 | #define BS_ATOPEN 0x001 /* AT channel open */ |
| 127 | #define BS_B1OPEN 0x002 /* B channel 1 open */ |
| 128 | #define BS_B2OPEN 0x004 /* B channel 2 open */ |
| 129 | #define BS_ATREADY 0x008 /* base ready for AT command */ |
| 130 | #define BS_INIT 0x010 /* base has signalled INIT_OK */ |
| 131 | #define BS_ATTIMER 0x020 /* waiting for HD_READY_SEND_ATDATA */ |
| 132 | #define BS_ATRDPEND 0x040 /* urb_cmd_in in use */ |
| 133 | #define BS_ATWRPEND 0x080 /* urb_cmd_out in use */ |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 134 | #define BS_SUSPEND 0x100 /* USB port suspended */ |
Tilman Schmidt | b5f581d | 2009-10-06 12:18:51 +0000 | [diff] [blame] | 135 | #define BS_RESETTING 0x200 /* waiting for HD_RESET_INTERRUPT_PIPE_ACK */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 136 | |
| 137 | |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 138 | static struct gigaset_driver *driver; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 139 | |
| 140 | /* usb specific object needed to register this driver with the usb subsystem */ |
| 141 | static struct usb_driver gigaset_usb_driver = { |
| 142 | .name = GIGASET_MODULENAME, |
| 143 | .probe = gigaset_probe, |
| 144 | .disconnect = gigaset_disconnect, |
| 145 | .id_table = gigaset_table, |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 146 | .suspend = gigaset_suspend, |
| 147 | .resume = gigaset_resume, |
| 148 | .reset_resume = gigaset_post_reset, |
| 149 | .pre_reset = gigaset_pre_reset, |
| 150 | .post_reset = gigaset_post_reset, |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 151 | }; |
| 152 | |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 153 | /* get message text for usb_submit_urb return code |
| 154 | */ |
| 155 | static char *get_usb_rcmsg(int rc) |
| 156 | { |
| 157 | static char unkmsg[28]; |
| 158 | |
| 159 | switch (rc) { |
| 160 | case 0: |
| 161 | return "success"; |
| 162 | case -ENOMEM: |
| 163 | return "out of memory"; |
| 164 | case -ENODEV: |
| 165 | return "device not present"; |
| 166 | case -ENOENT: |
| 167 | return "endpoint not present"; |
| 168 | case -ENXIO: |
| 169 | return "URB type not supported"; |
| 170 | case -EINVAL: |
| 171 | return "invalid argument"; |
| 172 | case -EAGAIN: |
| 173 | return "start frame too early or too much scheduled"; |
| 174 | case -EFBIG: |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 175 | return "too many isoc frames requested"; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 176 | case -EPIPE: |
| 177 | return "endpoint stalled"; |
| 178 | case -EMSGSIZE: |
| 179 | return "invalid packet size"; |
| 180 | case -ENOSPC: |
| 181 | return "would overcommit USB bandwidth"; |
| 182 | case -ESHUTDOWN: |
| 183 | return "device shut down"; |
| 184 | case -EPERM: |
| 185 | return "reject flag set"; |
| 186 | case -EHOSTUNREACH: |
| 187 | return "device suspended"; |
| 188 | default: |
| 189 | snprintf(unkmsg, sizeof(unkmsg), "unknown error %d", rc); |
| 190 | return unkmsg; |
| 191 | } |
| 192 | } |
| 193 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 194 | /* get message text for USB status code |
| 195 | */ |
| 196 | static char *get_usb_statmsg(int status) |
| 197 | { |
| 198 | static char unkmsg[28]; |
| 199 | |
| 200 | switch (status) { |
| 201 | case 0: |
| 202 | return "success"; |
| 203 | case -ENOENT: |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 204 | return "unlinked (sync)"; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 205 | case -EINPROGRESS: |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 206 | return "URB still pending"; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 207 | case -EPROTO: |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 208 | return "bitstuff error, timeout, or unknown USB error"; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 209 | case -EILSEQ: |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 210 | return "CRC mismatch, timeout, or unknown USB error"; |
Pete Zaitcev | 38e2bfc | 2006-09-18 22:49:02 -0700 | [diff] [blame] | 211 | case -ETIME: |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 212 | return "USB response timeout"; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 213 | case -EPIPE: |
| 214 | return "endpoint stalled"; |
| 215 | case -ECOMM: |
| 216 | return "IN buffer overrun"; |
| 217 | case -ENOSR: |
| 218 | return "OUT buffer underrun"; |
| 219 | case -EOVERFLOW: |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 220 | return "endpoint babble"; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 221 | case -EREMOTEIO: |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 222 | return "short packet"; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 223 | case -ENODEV: |
| 224 | return "device removed"; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 225 | case -EXDEV: |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 226 | return "partial isoc transfer"; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 227 | case -EINVAL: |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 228 | return "ISO madness"; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 229 | case -ECONNRESET: |
| 230 | return "unlinked (async)"; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 231 | case -ESHUTDOWN: |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 232 | return "device shut down"; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 233 | default: |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 234 | snprintf(unkmsg, sizeof(unkmsg), "unknown status %d", status); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 235 | return unkmsg; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /* usb_pipetype_str |
| 240 | * retrieve string representation of USB pipe type |
| 241 | */ |
| 242 | static inline char *usb_pipetype_str(int pipe) |
| 243 | { |
| 244 | if (usb_pipeisoc(pipe)) |
| 245 | return "Isoc"; |
| 246 | if (usb_pipeint(pipe)) |
| 247 | return "Int"; |
| 248 | if (usb_pipecontrol(pipe)) |
| 249 | return "Ctrl"; |
| 250 | if (usb_pipebulk(pipe)) |
| 251 | return "Bulk"; |
| 252 | return "?"; |
| 253 | } |
| 254 | |
| 255 | /* dump_urb |
| 256 | * write content of URB to syslog for debugging |
| 257 | */ |
| 258 | static inline void dump_urb(enum debuglevel level, const char *tag, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 259 | struct urb *urb) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 260 | { |
| 261 | #ifdef CONFIG_GIGASET_DEBUG |
| 262 | int i; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 263 | gig_dbg(level, "%s urb(0x%08lx)->{", tag, (unsigned long) urb); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 264 | if (urb) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 265 | gig_dbg(level, |
| 266 | " dev=0x%08lx, pipe=%s:EP%d/DV%d:%s, " |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 267 | "hcpriv=0x%08lx, transfer_flags=0x%x,", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 268 | (unsigned long) urb->dev, |
| 269 | usb_pipetype_str(urb->pipe), |
| 270 | usb_pipeendpoint(urb->pipe), usb_pipedevice(urb->pipe), |
| 271 | usb_pipein(urb->pipe) ? "in" : "out", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 272 | (unsigned long) urb->hcpriv, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 273 | urb->transfer_flags); |
| 274 | gig_dbg(level, |
| 275 | " transfer_buffer=0x%08lx[%d], actual_length=%d, " |
Andrew Morton | 249b061 | 2007-02-10 01:46:49 -0800 | [diff] [blame] | 276 | "setup_packet=0x%08lx,", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 277 | (unsigned long) urb->transfer_buffer, |
| 278 | urb->transfer_buffer_length, urb->actual_length, |
Andrew Morton | 249b061 | 2007-02-10 01:46:49 -0800 | [diff] [blame] | 279 | (unsigned long) urb->setup_packet); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 280 | gig_dbg(level, |
| 281 | " start_frame=%d, number_of_packets=%d, interval=%d, " |
| 282 | "error_count=%d,", |
| 283 | urb->start_frame, urb->number_of_packets, urb->interval, |
| 284 | urb->error_count); |
| 285 | gig_dbg(level, |
| 286 | " context=0x%08lx, complete=0x%08lx, " |
| 287 | "iso_frame_desc[]={", |
| 288 | (unsigned long) urb->context, |
| 289 | (unsigned long) urb->complete); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 290 | for (i = 0; i < urb->number_of_packets; i++) { |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 291 | struct usb_iso_packet_descriptor *pifd |
| 292 | = &urb->iso_frame_desc[i]; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 293 | gig_dbg(level, |
| 294 | " {offset=%u, length=%u, actual_length=%u, " |
| 295 | "status=%u}", |
| 296 | pifd->offset, pifd->length, pifd->actual_length, |
| 297 | pifd->status); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 298 | } |
| 299 | } |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 300 | gig_dbg(level, "}}"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 301 | #endif |
| 302 | } |
| 303 | |
| 304 | /* read/set modem control bits etc. (m10x only) */ |
| 305 | static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 306 | unsigned new_state) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 307 | { |
| 308 | return -EINVAL; |
| 309 | } |
| 310 | |
| 311 | static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag) |
| 312 | { |
| 313 | return -EINVAL; |
| 314 | } |
| 315 | |
| 316 | static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag) |
| 317 | { |
| 318 | return -EINVAL; |
| 319 | } |
| 320 | |
Tilman Schmidt | b5f581d | 2009-10-06 12:18:51 +0000 | [diff] [blame] | 321 | /* set/clear bits in base connection state, return previous state |
| 322 | */ |
| 323 | static inline int update_basstate(struct bas_cardstate *ucs, |
| 324 | int set, int clear) |
| 325 | { |
| 326 | unsigned long flags; |
| 327 | int state; |
| 328 | |
| 329 | spin_lock_irqsave(&ucs->lock, flags); |
| 330 | state = ucs->basstate; |
| 331 | ucs->basstate = (state & ~clear) | set; |
| 332 | spin_unlock_irqrestore(&ucs->lock, flags); |
| 333 | return state; |
| 334 | } |
| 335 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 336 | /* error_hangup |
| 337 | * hang up any existing connection because of an unrecoverable error |
| 338 | * This function may be called from any context and takes care of scheduling |
| 339 | * the necessary actions for execution outside of interrupt context. |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 340 | * cs->lock must not be held. |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 341 | * argument: |
| 342 | * B channel control structure |
| 343 | */ |
| 344 | static inline void error_hangup(struct bc_state *bcs) |
| 345 | { |
| 346 | struct cardstate *cs = bcs->cs; |
| 347 | |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 348 | gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 349 | gigaset_schedule_event(cs); |
| 350 | } |
| 351 | |
| 352 | /* error_reset |
| 353 | * reset Gigaset device because of an unrecoverable error |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 354 | * This function may be called from any context, and takes care of |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 355 | * scheduling the necessary actions for execution outside of interrupt context. |
Tilman Schmidt | 60798c68 | 2010-09-30 13:35:21 +0000 | [diff] [blame] | 356 | * cs->hw.bas->lock must not be held. |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 357 | * argument: |
| 358 | * controller state structure |
| 359 | */ |
| 360 | static inline void error_reset(struct cardstate *cs) |
| 361 | { |
Tilman Schmidt | b5f581d | 2009-10-06 12:18:51 +0000 | [diff] [blame] | 362 | /* reset interrupt pipe to recover (ignore errors) */ |
| 363 | update_basstate(cs->hw.bas, BS_RESETTING, 0); |
Tilman Schmidt | 60798c68 | 2010-09-30 13:35:21 +0000 | [diff] [blame] | 364 | if (req_submit(cs->bcs, HD_RESET_INTERRUPT_PIPE, 0, BAS_TIMEOUT)) |
| 365 | /* submission failed, escalate to USB port reset */ |
| 366 | usb_queue_reset_device(cs->hw.bas->interface); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /* check_pending |
| 370 | * check for completion of pending control request |
| 371 | * parameter: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 372 | * ucs hardware specific controller state structure |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 373 | */ |
| 374 | static void check_pending(struct bas_cardstate *ucs) |
| 375 | { |
| 376 | unsigned long flags; |
| 377 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 378 | spin_lock_irqsave(&ucs->lock, flags); |
| 379 | switch (ucs->pending) { |
| 380 | case 0: |
| 381 | break; |
| 382 | case HD_OPEN_ATCHANNEL: |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 383 | if (ucs->basstate & BS_ATOPEN) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 384 | ucs->pending = 0; |
| 385 | break; |
| 386 | case HD_OPEN_B1CHANNEL: |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 387 | if (ucs->basstate & BS_B1OPEN) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 388 | ucs->pending = 0; |
| 389 | break; |
| 390 | case HD_OPEN_B2CHANNEL: |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 391 | if (ucs->basstate & BS_B2OPEN) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 392 | ucs->pending = 0; |
| 393 | break; |
| 394 | case HD_CLOSE_ATCHANNEL: |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 395 | if (!(ucs->basstate & BS_ATOPEN)) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 396 | ucs->pending = 0; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 397 | break; |
| 398 | case HD_CLOSE_B1CHANNEL: |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 399 | if (!(ucs->basstate & BS_B1OPEN)) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 400 | ucs->pending = 0; |
| 401 | break; |
| 402 | case HD_CLOSE_B2CHANNEL: |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 403 | if (!(ucs->basstate & BS_B2OPEN)) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 404 | ucs->pending = 0; |
| 405 | break; |
| 406 | case HD_DEVICE_INIT_ACK: /* no reply expected */ |
| 407 | ucs->pending = 0; |
| 408 | break; |
Tilman Schmidt | b5f581d | 2009-10-06 12:18:51 +0000 | [diff] [blame] | 409 | case HD_RESET_INTERRUPT_PIPE: |
| 410 | if (!(ucs->basstate & BS_RESETTING)) |
| 411 | ucs->pending = 0; |
| 412 | break; |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [diff] [blame^] | 413 | /* |
| 414 | * HD_READ_ATMESSAGE and HD_WRITE_ATMESSAGE are handled separately |
| 415 | * and should never end up here |
| 416 | */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 417 | default: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 418 | dev_warn(&ucs->interface->dev, |
| 419 | "unknown pending request 0x%02x cleared\n", |
| 420 | ucs->pending); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 421 | ucs->pending = 0; |
| 422 | } |
| 423 | |
| 424 | if (!ucs->pending) |
| 425 | del_timer(&ucs->timer_ctrl); |
| 426 | |
| 427 | spin_unlock_irqrestore(&ucs->lock, flags); |
| 428 | } |
| 429 | |
| 430 | /* cmd_in_timeout |
| 431 | * timeout routine for command input request |
| 432 | * argument: |
| 433 | * controller state structure |
| 434 | */ |
| 435 | static void cmd_in_timeout(unsigned long data) |
| 436 | { |
| 437 | struct cardstate *cs = (struct cardstate *) data; |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 438 | struct bas_cardstate *ucs = cs->hw.bas; |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 439 | int rc; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 440 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 441 | if (!ucs->rcvbuf_size) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 442 | gig_dbg(DEBUG_USBREQ, "%s: no receive in progress", __func__); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 443 | return; |
| 444 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 445 | |
Tilman Schmidt | c8701a0 | 2010-09-30 13:34:40 +0000 | [diff] [blame] | 446 | if (ucs->retry_cmd_in++ >= BAS_RETRY) { |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 447 | dev_err(cs->dev, |
| 448 | "control read: timeout, giving up after %d tries\n", |
| 449 | ucs->retry_cmd_in); |
Tilman Schmidt | c8701a0 | 2010-09-30 13:34:40 +0000 | [diff] [blame] | 450 | kfree(ucs->rcvbuf); |
| 451 | ucs->rcvbuf = NULL; |
| 452 | ucs->rcvbuf_size = 0; |
| 453 | error_reset(cs); |
| 454 | return; |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 455 | } |
Tilman Schmidt | c8701a0 | 2010-09-30 13:34:40 +0000 | [diff] [blame] | 456 | |
| 457 | gig_dbg(DEBUG_USBREQ, "%s: timeout, retry %d", |
| 458 | __func__, ucs->retry_cmd_in); |
| 459 | rc = atread_submit(cs, BAS_TIMEOUT); |
| 460 | if (rc < 0) { |
| 461 | kfree(ucs->rcvbuf); |
| 462 | ucs->rcvbuf = NULL; |
| 463 | ucs->rcvbuf_size = 0; |
| 464 | if (rc != -ENODEV) |
| 465 | error_reset(cs); |
| 466 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 467 | } |
| 468 | |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 469 | /* read_ctrl_callback |
| 470 | * USB completion handler for control pipe input |
| 471 | * called by the USB subsystem in interrupt context |
| 472 | * parameter: |
| 473 | * urb USB request block |
| 474 | * urb->context = inbuf structure for controller state |
| 475 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 476 | static void read_ctrl_callback(struct urb *urb) |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 477 | { |
| 478 | struct inbuf_t *inbuf = urb->context; |
| 479 | struct cardstate *cs = inbuf->cs; |
| 480 | struct bas_cardstate *ucs = cs->hw.bas; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 481 | int status = urb->status; |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 482 | unsigned numbytes; |
| 483 | int rc; |
| 484 | |
| 485 | update_basstate(ucs, 0, BS_ATRDPEND); |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 486 | wake_up(&ucs->waitqueue); |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 487 | del_timer(&ucs->timer_cmd_in); |
| 488 | |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 489 | switch (status) { |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 490 | case 0: /* normal completion */ |
| 491 | numbytes = urb->actual_length; |
| 492 | if (unlikely(numbytes != ucs->rcvbuf_size)) { |
| 493 | dev_warn(cs->dev, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 494 | "control read: received %d chars, expected %d\n", |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 495 | numbytes, ucs->rcvbuf_size); |
| 496 | if (numbytes > ucs->rcvbuf_size) |
| 497 | numbytes = ucs->rcvbuf_size; |
| 498 | } |
| 499 | |
Tilman Schmidt | c8701a0 | 2010-09-30 13:34:40 +0000 | [diff] [blame] | 500 | /* copy received bytes to inbuf, notify event layer */ |
| 501 | if (gigaset_fill_inbuf(inbuf, ucs->rcvbuf, numbytes)) { |
| 502 | gig_dbg(DEBUG_INTR, "%s-->BH", __func__); |
| 503 | gigaset_schedule_event(cs); |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 504 | } |
| 505 | break; |
| 506 | |
| 507 | case -ENOENT: /* cancelled */ |
| 508 | case -ECONNRESET: /* cancelled (async) */ |
| 509 | case -EINPROGRESS: /* pending */ |
| 510 | case -ENODEV: /* device removed */ |
| 511 | case -ESHUTDOWN: /* device shut down */ |
Tilman Schmidt | c8701a0 | 2010-09-30 13:34:40 +0000 | [diff] [blame] | 512 | /* no further action necessary */ |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 513 | gig_dbg(DEBUG_USBREQ, "%s: %s", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 514 | __func__, get_usb_statmsg(status)); |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 515 | break; |
| 516 | |
Tilman Schmidt | c8701a0 | 2010-09-30 13:34:40 +0000 | [diff] [blame] | 517 | default: /* other errors: retry */ |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 518 | if (ucs->retry_cmd_in++ < BAS_RETRY) { |
Tilman Schmidt | c8701a0 | 2010-09-30 13:34:40 +0000 | [diff] [blame] | 519 | gig_dbg(DEBUG_USBREQ, "%s: %s, retry %d", __func__, |
| 520 | get_usb_statmsg(status), ucs->retry_cmd_in); |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 521 | rc = atread_submit(cs, BAS_TIMEOUT); |
Tilman Schmidt | c8701a0 | 2010-09-30 13:34:40 +0000 | [diff] [blame] | 522 | if (rc >= 0) |
| 523 | /* successfully resubmitted, skip freeing */ |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 524 | return; |
Tilman Schmidt | c8701a0 | 2010-09-30 13:34:40 +0000 | [diff] [blame] | 525 | if (rc == -ENODEV) |
| 526 | /* disconnect, no further action necessary */ |
| 527 | break; |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 528 | } |
Tilman Schmidt | c8701a0 | 2010-09-30 13:34:40 +0000 | [diff] [blame] | 529 | dev_err(cs->dev, "control read: %s, giving up after %d tries\n", |
| 530 | get_usb_statmsg(status), ucs->retry_cmd_in); |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 531 | error_reset(cs); |
| 532 | } |
| 533 | |
Tilman Schmidt | c8701a0 | 2010-09-30 13:34:40 +0000 | [diff] [blame] | 534 | /* read finished, free buffer */ |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 535 | kfree(ucs->rcvbuf); |
| 536 | ucs->rcvbuf = NULL; |
| 537 | ucs->rcvbuf_size = 0; |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 540 | /* atread_submit |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 541 | * submit an HD_READ_ATMESSAGE command URB and optionally start a timeout |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 542 | * parameters: |
| 543 | * cs controller state structure |
| 544 | * timeout timeout in 1/10 sec., 0: none |
| 545 | * return value: |
| 546 | * 0 on success |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 547 | * -EBUSY if another request is pending |
| 548 | * any URB submission error code |
| 549 | */ |
| 550 | static int atread_submit(struct cardstate *cs, int timeout) |
| 551 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 552 | struct bas_cardstate *ucs = cs->hw.bas; |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 553 | int basstate; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 554 | int ret; |
| 555 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 556 | gig_dbg(DEBUG_USBREQ, "-------> HD_READ_ATMESSAGE (%d)", |
| 557 | ucs->rcvbuf_size); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 558 | |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 559 | basstate = update_basstate(ucs, BS_ATRDPEND, 0); |
| 560 | if (basstate & BS_ATRDPEND) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 561 | dev_err(cs->dev, |
| 562 | "could not submit HD_READ_ATMESSAGE: URB busy\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 563 | return -EBUSY; |
| 564 | } |
| 565 | |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 566 | if (basstate & BS_SUSPEND) { |
| 567 | dev_notice(cs->dev, |
| 568 | "HD_READ_ATMESSAGE not submitted, " |
| 569 | "suspend in progress\n"); |
| 570 | update_basstate(ucs, 0, BS_ATRDPEND); |
| 571 | /* treat like disconnect */ |
| 572 | return -ENODEV; |
| 573 | } |
| 574 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 575 | ucs->dr_cmd_in.bRequestType = IN_VENDOR_REQ; |
| 576 | ucs->dr_cmd_in.bRequest = HD_READ_ATMESSAGE; |
| 577 | ucs->dr_cmd_in.wValue = 0; |
| 578 | ucs->dr_cmd_in.wIndex = 0; |
| 579 | ucs->dr_cmd_in.wLength = cpu_to_le16(ucs->rcvbuf_size); |
| 580 | usb_fill_control_urb(ucs->urb_cmd_in, ucs->udev, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 581 | usb_rcvctrlpipe(ucs->udev, 0), |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 582 | (unsigned char *) &ucs->dr_cmd_in, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 583 | ucs->rcvbuf, ucs->rcvbuf_size, |
| 584 | read_ctrl_callback, cs->inbuf); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 585 | |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 586 | ret = usb_submit_urb(ucs->urb_cmd_in, GFP_ATOMIC); |
| 587 | if (ret != 0) { |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 588 | update_basstate(ucs, 0, BS_ATRDPEND); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 589 | dev_err(cs->dev, "could not submit HD_READ_ATMESSAGE: %s\n", |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 590 | get_usb_rcmsg(ret)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 591 | return ret; |
| 592 | } |
| 593 | |
| 594 | if (timeout > 0) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 595 | gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout); |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 596 | mod_timer(&ucs->timer_cmd_in, jiffies + timeout * HZ / 10); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 597 | } |
| 598 | return 0; |
| 599 | } |
| 600 | |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 601 | /* int_in_work |
| 602 | * workqueue routine to clear halt on interrupt in endpoint |
| 603 | */ |
| 604 | |
| 605 | static void int_in_work(struct work_struct *work) |
| 606 | { |
| 607 | struct bas_cardstate *ucs = |
| 608 | container_of(work, struct bas_cardstate, int_in_wq); |
| 609 | struct urb *urb = ucs->urb_int_in; |
| 610 | struct cardstate *cs = urb->context; |
| 611 | int rc; |
| 612 | |
| 613 | /* clear halt condition */ |
| 614 | rc = usb_clear_halt(ucs->udev, urb->pipe); |
| 615 | gig_dbg(DEBUG_USBREQ, "clear_halt: %s", get_usb_rcmsg(rc)); |
| 616 | if (rc == 0) |
| 617 | /* success, resubmit interrupt read URB */ |
| 618 | rc = usb_submit_urb(urb, GFP_ATOMIC); |
| 619 | if (rc != 0 && rc != -ENODEV) { |
| 620 | dev_err(cs->dev, "clear halt failed: %s\n", get_usb_rcmsg(rc)); |
| 621 | rc = usb_lock_device_for_reset(ucs->udev, ucs->interface); |
| 622 | if (rc == 0) { |
| 623 | rc = usb_reset_device(ucs->udev); |
| 624 | usb_unlock_device(ucs->udev); |
| 625 | } |
| 626 | } |
| 627 | ucs->retry_int_in = 0; |
| 628 | } |
| 629 | |
| 630 | /* int_in_resubmit |
| 631 | * timer routine for interrupt read delayed resubmit |
| 632 | * argument: |
| 633 | * controller state structure |
| 634 | */ |
| 635 | static void int_in_resubmit(unsigned long data) |
| 636 | { |
| 637 | struct cardstate *cs = (struct cardstate *) data; |
| 638 | struct bas_cardstate *ucs = cs->hw.bas; |
| 639 | int rc; |
| 640 | |
| 641 | if (ucs->retry_int_in++ >= BAS_RETRY) { |
| 642 | dev_err(cs->dev, "interrupt read: giving up after %d tries\n", |
| 643 | ucs->retry_int_in); |
| 644 | usb_queue_reset_device(ucs->interface); |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | gig_dbg(DEBUG_USBREQ, "%s: retry %d", __func__, ucs->retry_int_in); |
| 649 | rc = usb_submit_urb(ucs->urb_int_in, GFP_ATOMIC); |
| 650 | if (rc != 0 && rc != -ENODEV) { |
| 651 | dev_err(cs->dev, "could not resubmit interrupt URB: %s\n", |
| 652 | get_usb_rcmsg(rc)); |
| 653 | usb_queue_reset_device(ucs->interface); |
| 654 | } |
| 655 | } |
| 656 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 657 | /* read_int_callback |
| 658 | * USB completion handler for interrupt pipe input |
| 659 | * called by the USB subsystem in interrupt context |
| 660 | * parameter: |
| 661 | * urb USB request block |
| 662 | * urb->context = controller state structure |
| 663 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 664 | static void read_int_callback(struct urb *urb) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 665 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 666 | struct cardstate *cs = urb->context; |
| 667 | struct bas_cardstate *ucs = cs->hw.bas; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 668 | struct bc_state *bcs; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 669 | int status = urb->status; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 670 | unsigned long flags; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 671 | int rc; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 672 | unsigned l; |
| 673 | int channel; |
| 674 | |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 675 | switch (status) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 676 | case 0: /* success */ |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 677 | ucs->retry_int_in = 0; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 678 | break; |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 679 | case -EPIPE: /* endpoint stalled */ |
| 680 | schedule_work(&ucs->int_in_wq); |
| 681 | /* fall through */ |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 682 | case -ENOENT: /* cancelled */ |
| 683 | case -ECONNRESET: /* cancelled (async) */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 684 | case -EINPROGRESS: /* pending */ |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 685 | case -ENODEV: /* device removed */ |
| 686 | case -ESHUTDOWN: /* device shut down */ |
| 687 | /* no further action necessary */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 688 | gig_dbg(DEBUG_USBREQ, "%s: %s", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 689 | __func__, get_usb_statmsg(status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 690 | return; |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 691 | case -EPROTO: /* protocol error or unplug */ |
| 692 | case -EILSEQ: |
| 693 | case -ETIME: |
| 694 | /* resubmit after delay */ |
| 695 | gig_dbg(DEBUG_USBREQ, "%s: %s", |
| 696 | __func__, get_usb_statmsg(status)); |
| 697 | mod_timer(&ucs->timer_int_in, jiffies + HZ / 10); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 698 | return; |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 699 | default: /* other errors: just resubmit */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 700 | dev_warn(cs->dev, "interrupt read: %s\n", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 701 | get_usb_statmsg(status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 702 | goto resubmit; |
| 703 | } |
| 704 | |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 705 | /* drop incomplete packets even if the missing bytes wouldn't matter */ |
Tilman Schmidt | 170ebf8 | 2009-03-18 23:44:23 -0700 | [diff] [blame] | 706 | if (unlikely(urb->actual_length < IP_MSGSIZE)) { |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 707 | dev_warn(cs->dev, "incomplete interrupt packet (%d bytes)\n", |
| 708 | urb->actual_length); |
| 709 | goto resubmit; |
| 710 | } |
| 711 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 712 | l = (unsigned) ucs->int_in_buf[1] + |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 713 | (((unsigned) ucs->int_in_buf[2]) << 8); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 714 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 715 | gig_dbg(DEBUG_USBREQ, "<-------%d: 0x%02x (%u [0x%02x 0x%02x])", |
| 716 | urb->actual_length, (int)ucs->int_in_buf[0], l, |
| 717 | (int)ucs->int_in_buf[1], (int)ucs->int_in_buf[2]); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 718 | |
| 719 | channel = 0; |
| 720 | |
| 721 | switch (ucs->int_in_buf[0]) { |
| 722 | case HD_DEVICE_INIT_OK: |
| 723 | update_basstate(ucs, BS_INIT, 0); |
| 724 | break; |
| 725 | |
| 726 | case HD_READY_SEND_ATDATA: |
| 727 | del_timer(&ucs->timer_atrdy); |
| 728 | update_basstate(ucs, BS_ATREADY, BS_ATTIMER); |
| 729 | start_cbsend(cs); |
| 730 | break; |
| 731 | |
| 732 | case HD_OPEN_B2CHANNEL_ACK: |
| 733 | ++channel; |
| 734 | case HD_OPEN_B1CHANNEL_ACK: |
| 735 | bcs = cs->bcs + channel; |
| 736 | update_basstate(ucs, BS_B1OPEN << channel, 0); |
| 737 | gigaset_bchannel_up(bcs); |
| 738 | break; |
| 739 | |
| 740 | case HD_OPEN_ATCHANNEL_ACK: |
| 741 | update_basstate(ucs, BS_ATOPEN, 0); |
| 742 | start_cbsend(cs); |
| 743 | break; |
| 744 | |
| 745 | case HD_CLOSE_B2CHANNEL_ACK: |
| 746 | ++channel; |
| 747 | case HD_CLOSE_B1CHANNEL_ACK: |
| 748 | bcs = cs->bcs + channel; |
| 749 | update_basstate(ucs, 0, BS_B1OPEN << channel); |
| 750 | stopurbs(bcs->hw.bas); |
| 751 | gigaset_bchannel_down(bcs); |
| 752 | break; |
| 753 | |
| 754 | case HD_CLOSE_ATCHANNEL_ACK: |
| 755 | update_basstate(ucs, 0, BS_ATOPEN); |
| 756 | break; |
| 757 | |
| 758 | case HD_B2_FLOW_CONTROL: |
| 759 | ++channel; |
| 760 | case HD_B1_FLOW_CONTROL: |
| 761 | bcs = cs->bcs + channel; |
| 762 | atomic_add((l - BAS_NORMFRAME) * BAS_CORRFRAMES, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 763 | &bcs->hw.bas->corrbytes); |
| 764 | gig_dbg(DEBUG_ISO, |
| 765 | "Flow control (channel %d, sub %d): 0x%02x => %d", |
| 766 | channel, bcs->hw.bas->numsub, l, |
| 767 | atomic_read(&bcs->hw.bas->corrbytes)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case HD_RECEIVEATDATA_ACK: /* AT response ready to be received */ |
| 771 | if (!l) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 772 | dev_warn(cs->dev, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 773 | "HD_RECEIVEATDATA_ACK with length 0 ignored\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 774 | break; |
| 775 | } |
| 776 | spin_lock_irqsave(&cs->lock, flags); |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 777 | if (ucs->basstate & BS_ATRDPEND) { |
| 778 | spin_unlock_irqrestore(&cs->lock, flags); |
| 779 | dev_warn(cs->dev, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 780 | "HD_RECEIVEATDATA_ACK(%d) during HD_READ_ATMESSAGE(%d) ignored\n", |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 781 | l, ucs->rcvbuf_size); |
| 782 | break; |
| 783 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 784 | if (ucs->rcvbuf_size) { |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 785 | /* throw away previous buffer - we have no queue */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 786 | dev_err(cs->dev, |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 787 | "receive AT data overrun, %d bytes lost\n", |
| 788 | ucs->rcvbuf_size); |
| 789 | kfree(ucs->rcvbuf); |
| 790 | ucs->rcvbuf_size = 0; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 791 | } |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 792 | ucs->rcvbuf = kmalloc(l, GFP_ATOMIC); |
| 793 | if (ucs->rcvbuf == NULL) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 794 | spin_unlock_irqrestore(&cs->lock, flags); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 795 | dev_err(cs->dev, "out of memory receiving AT data\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 796 | break; |
| 797 | } |
| 798 | ucs->rcvbuf_size = l; |
| 799 | ucs->retry_cmd_in = 0; |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 800 | rc = atread_submit(cs, BAS_TIMEOUT); |
| 801 | if (rc < 0) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 802 | kfree(ucs->rcvbuf); |
| 803 | ucs->rcvbuf = NULL; |
| 804 | ucs->rcvbuf_size = 0; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 805 | } |
| 806 | spin_unlock_irqrestore(&cs->lock, flags); |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 807 | if (rc < 0 && rc != -ENODEV) |
| 808 | error_reset(cs); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 809 | break; |
| 810 | |
| 811 | case HD_RESET_INTERRUPT_PIPE_ACK: |
Tilman Schmidt | b5f581d | 2009-10-06 12:18:51 +0000 | [diff] [blame] | 812 | update_basstate(ucs, 0, BS_RESETTING); |
| 813 | dev_notice(cs->dev, "interrupt pipe reset\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 814 | break; |
| 815 | |
| 816 | case HD_SUSPEND_END: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 817 | gig_dbg(DEBUG_USBREQ, "HD_SUSPEND_END"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 818 | break; |
| 819 | |
| 820 | default: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 821 | dev_warn(cs->dev, |
| 822 | "unknown Gigaset signal 0x%02x (%u) ignored\n", |
| 823 | (int) ucs->int_in_buf[0], l); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | check_pending(ucs); |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 827 | wake_up(&ucs->waitqueue); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 828 | |
| 829 | resubmit: |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 830 | rc = usb_submit_urb(urb, GFP_ATOMIC); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 831 | if (unlikely(rc != 0 && rc != -ENODEV)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 832 | dev_err(cs->dev, "could not resubmit interrupt URB: %s\n", |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 833 | get_usb_rcmsg(rc)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 834 | error_reset(cs); |
| 835 | } |
| 836 | } |
| 837 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 838 | /* read_iso_callback |
| 839 | * USB completion handler for B channel isochronous input |
| 840 | * called by the USB subsystem in interrupt context |
| 841 | * parameter: |
| 842 | * urb USB request block of completed request |
| 843 | * urb->context = bc_state structure |
| 844 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 845 | static void read_iso_callback(struct urb *urb) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 846 | { |
| 847 | struct bc_state *bcs; |
| 848 | struct bas_bc_state *ubc; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 849 | int status = urb->status; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 850 | unsigned long flags; |
| 851 | int i, rc; |
| 852 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 853 | /* status codes not worth bothering the tasklet with */ |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 854 | if (unlikely(status == -ENOENT || |
| 855 | status == -ECONNRESET || |
| 856 | status == -EINPROGRESS || |
| 857 | status == -ENODEV || |
| 858 | status == -ESHUTDOWN)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 859 | gig_dbg(DEBUG_ISO, "%s: %s", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 860 | __func__, get_usb_statmsg(status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 861 | return; |
| 862 | } |
| 863 | |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 864 | bcs = urb->context; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 865 | ubc = bcs->hw.bas; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 866 | |
| 867 | spin_lock_irqsave(&ubc->isoinlock, flags); |
| 868 | if (likely(ubc->isoindone == NULL)) { |
| 869 | /* pass URB to tasklet */ |
| 870 | ubc->isoindone = urb; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 871 | ubc->isoinstatus = status; |
Tilman Schmidt | 368fd81 | 2009-04-05 06:39:33 +0000 | [diff] [blame] | 872 | tasklet_hi_schedule(&ubc->rcvd_tasklet); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 873 | } else { |
| 874 | /* tasklet still busy, drop data and resubmit URB */ |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 875 | gig_dbg(DEBUG_ISO, "%s: overrun", __func__); |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 876 | ubc->loststatus = status; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 877 | for (i = 0; i < BAS_NUMFRAMES; i++) { |
| 878 | ubc->isoinlost += urb->iso_frame_desc[i].actual_length; |
| 879 | if (unlikely(urb->iso_frame_desc[i].status != 0 && |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [diff] [blame^] | 880 | urb->iso_frame_desc[i].status != -EINPROGRESS)) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 881 | ubc->loststatus = urb->iso_frame_desc[i].status; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 882 | urb->iso_frame_desc[i].status = 0; |
| 883 | urb->iso_frame_desc[i].actual_length = 0; |
| 884 | } |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 885 | if (likely(ubc->running)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 886 | /* urb->dev is clobbered by USB subsystem */ |
| 887 | urb->dev = bcs->cs->hw.bas->udev; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 888 | urb->transfer_flags = URB_ISO_ASAP; |
| 889 | urb->number_of_packets = BAS_NUMFRAMES; |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 890 | rc = usb_submit_urb(urb, GFP_ATOMIC); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 891 | if (unlikely(rc != 0 && rc != -ENODEV)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 892 | dev_err(bcs->cs->dev, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 893 | "could not resubmit isoc read URB: %s\n", |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 894 | get_usb_rcmsg(rc)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 895 | dump_urb(DEBUG_ISO, "isoc read", urb); |
| 896 | error_hangup(bcs); |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | spin_unlock_irqrestore(&ubc->isoinlock, flags); |
| 901 | } |
| 902 | |
| 903 | /* write_iso_callback |
| 904 | * USB completion handler for B channel isochronous output |
| 905 | * called by the USB subsystem in interrupt context |
| 906 | * parameter: |
| 907 | * urb USB request block of completed request |
| 908 | * urb->context = isow_urbctx_t structure |
| 909 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 910 | static void write_iso_callback(struct urb *urb) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 911 | { |
| 912 | struct isow_urbctx_t *ucx; |
| 913 | struct bas_bc_state *ubc; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 914 | int status = urb->status; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 915 | unsigned long flags; |
| 916 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 917 | /* status codes not worth bothering the tasklet with */ |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 918 | if (unlikely(status == -ENOENT || |
| 919 | status == -ECONNRESET || |
| 920 | status == -EINPROGRESS || |
| 921 | status == -ENODEV || |
| 922 | status == -ESHUTDOWN)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 923 | gig_dbg(DEBUG_ISO, "%s: %s", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 924 | __func__, get_usb_statmsg(status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 925 | return; |
| 926 | } |
| 927 | |
| 928 | /* pass URB context to tasklet */ |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 929 | ucx = urb->context; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 930 | ubc = ucx->bcs->hw.bas; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 931 | ucx->status = status; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 932 | |
| 933 | spin_lock_irqsave(&ubc->isooutlock, flags); |
| 934 | ubc->isooutovfl = ubc->isooutdone; |
| 935 | ubc->isooutdone = ucx; |
| 936 | spin_unlock_irqrestore(&ubc->isooutlock, flags); |
Tilman Schmidt | 368fd81 | 2009-04-05 06:39:33 +0000 | [diff] [blame] | 937 | tasklet_hi_schedule(&ubc->sent_tasklet); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | /* starturbs |
| 941 | * prepare and submit USB request blocks for isochronous input and output |
| 942 | * argument: |
| 943 | * B channel control structure |
| 944 | * return value: |
| 945 | * 0 on success |
| 946 | * < 0 on error (no URBs submitted) |
| 947 | */ |
| 948 | static int starturbs(struct bc_state *bcs) |
| 949 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 950 | struct bas_bc_state *ubc = bcs->hw.bas; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 951 | struct urb *urb; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 952 | int j, k; |
| 953 | int rc; |
| 954 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 955 | /* initialize L2 reception */ |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 956 | if (bcs->proto2 == L2_HDLC) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 957 | bcs->inputstate |= INS_flag_hunt; |
| 958 | |
| 959 | /* submit all isochronous input URBs */ |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 960 | ubc->running = 1; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 961 | for (k = 0; k < BAS_INURBS; k++) { |
| 962 | urb = ubc->isoinurbs[k]; |
| 963 | if (!urb) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 964 | rc = -EFAULT; |
| 965 | goto error; |
| 966 | } |
| 967 | |
| 968 | urb->dev = bcs->cs->hw.bas->udev; |
| 969 | urb->pipe = usb_rcvisocpipe(urb->dev, 3 + 2 * bcs->channel); |
| 970 | urb->transfer_flags = URB_ISO_ASAP; |
| 971 | urb->transfer_buffer = ubc->isoinbuf + k * BAS_INBUFSIZE; |
| 972 | urb->transfer_buffer_length = BAS_INBUFSIZE; |
| 973 | urb->number_of_packets = BAS_NUMFRAMES; |
| 974 | urb->interval = BAS_FRAMETIME; |
| 975 | urb->complete = read_iso_callback; |
| 976 | urb->context = bcs; |
| 977 | for (j = 0; j < BAS_NUMFRAMES; j++) { |
| 978 | urb->iso_frame_desc[j].offset = j * BAS_MAXFRAME; |
| 979 | urb->iso_frame_desc[j].length = BAS_MAXFRAME; |
| 980 | urb->iso_frame_desc[j].status = 0; |
| 981 | urb->iso_frame_desc[j].actual_length = 0; |
| 982 | } |
| 983 | |
| 984 | dump_urb(DEBUG_ISO, "Initial isoc read", urb); |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 985 | rc = usb_submit_urb(urb, GFP_ATOMIC); |
| 986 | if (rc != 0) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 987 | goto error; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | /* initialize L2 transmission */ |
| 991 | gigaset_isowbuf_init(ubc->isooutbuf, PPP_FLAG); |
| 992 | |
| 993 | /* set up isochronous output URBs for flag idling */ |
| 994 | for (k = 0; k < BAS_OUTURBS; ++k) { |
| 995 | urb = ubc->isoouturbs[k].urb; |
| 996 | if (!urb) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 997 | rc = -EFAULT; |
| 998 | goto error; |
| 999 | } |
| 1000 | urb->dev = bcs->cs->hw.bas->udev; |
| 1001 | urb->pipe = usb_sndisocpipe(urb->dev, 4 + 2 * bcs->channel); |
| 1002 | urb->transfer_flags = URB_ISO_ASAP; |
| 1003 | urb->transfer_buffer = ubc->isooutbuf->data; |
| 1004 | urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data); |
| 1005 | urb->number_of_packets = BAS_NUMFRAMES; |
| 1006 | urb->interval = BAS_FRAMETIME; |
| 1007 | urb->complete = write_iso_callback; |
| 1008 | urb->context = &ubc->isoouturbs[k]; |
| 1009 | for (j = 0; j < BAS_NUMFRAMES; ++j) { |
| 1010 | urb->iso_frame_desc[j].offset = BAS_OUTBUFSIZE; |
| 1011 | urb->iso_frame_desc[j].length = BAS_NORMFRAME; |
| 1012 | urb->iso_frame_desc[j].status = 0; |
| 1013 | urb->iso_frame_desc[j].actual_length = 0; |
| 1014 | } |
| 1015 | ubc->isoouturbs[k].limit = -1; |
| 1016 | } |
| 1017 | |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1018 | /* keep one URB free, submit the others */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1019 | for (k = 0; k < BAS_OUTURBS - 1; ++k) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1020 | dump_urb(DEBUG_ISO, "Initial isoc write", urb); |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 1021 | rc = usb_submit_urb(ubc->isoouturbs[k].urb, GFP_ATOMIC); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1022 | if (rc != 0) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1023 | goto error; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1024 | } |
| 1025 | dump_urb(DEBUG_ISO, "Initial isoc write (free)", urb); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1026 | ubc->isooutfree = &ubc->isoouturbs[BAS_OUTURBS - 1]; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1027 | ubc->isooutdone = ubc->isooutovfl = NULL; |
| 1028 | return 0; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1029 | error: |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1030 | stopurbs(ubc); |
| 1031 | return rc; |
| 1032 | } |
| 1033 | |
| 1034 | /* stopurbs |
| 1035 | * cancel the USB request blocks for isochronous input and output |
| 1036 | * errors are silently ignored |
| 1037 | * argument: |
| 1038 | * B channel control structure |
| 1039 | */ |
| 1040 | static void stopurbs(struct bas_bc_state *ubc) |
| 1041 | { |
| 1042 | int k, rc; |
| 1043 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1044 | ubc->running = 0; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1045 | |
| 1046 | for (k = 0; k < BAS_INURBS; ++k) { |
| 1047 | rc = usb_unlink_urb(ubc->isoinurbs[k]); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1048 | gig_dbg(DEBUG_ISO, |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1049 | "%s: isoc input URB %d unlinked, result = %s", |
| 1050 | __func__, k, get_usb_rcmsg(rc)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | for (k = 0; k < BAS_OUTURBS; ++k) { |
| 1054 | rc = usb_unlink_urb(ubc->isoouturbs[k].urb); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1055 | gig_dbg(DEBUG_ISO, |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1056 | "%s: isoc output URB %d unlinked, result = %s", |
| 1057 | __func__, k, get_usb_rcmsg(rc)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | /* Isochronous Write - Bottom Half */ |
| 1062 | /* =============================== */ |
| 1063 | |
| 1064 | /* submit_iso_write_urb |
| 1065 | * fill and submit the next isochronous write URB |
| 1066 | * parameters: |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1067 | * ucx context structure containing URB |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1068 | * return value: |
| 1069 | * number of frames submitted in URB |
| 1070 | * 0 if URB not submitted because no data available (isooutbuf busy) |
| 1071 | * error code < 0 on error |
| 1072 | */ |
| 1073 | static int submit_iso_write_urb(struct isow_urbctx_t *ucx) |
| 1074 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 1075 | struct urb *urb = ucx->urb; |
| 1076 | struct bas_bc_state *ubc = ucx->bcs->hw.bas; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1077 | struct usb_iso_packet_descriptor *ifd; |
| 1078 | int corrbytes, nframe, rc; |
| 1079 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1080 | /* urb->dev is clobbered by USB subsystem */ |
| 1081 | urb->dev = ucx->bcs->cs->hw.bas->udev; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1082 | urb->transfer_flags = URB_ISO_ASAP; |
| 1083 | urb->transfer_buffer = ubc->isooutbuf->data; |
| 1084 | urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data); |
| 1085 | |
| 1086 | for (nframe = 0; nframe < BAS_NUMFRAMES; nframe++) { |
| 1087 | ifd = &urb->iso_frame_desc[nframe]; |
| 1088 | |
| 1089 | /* compute frame length according to flow control */ |
| 1090 | ifd->length = BAS_NORMFRAME; |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 1091 | corrbytes = atomic_read(&ubc->corrbytes); |
| 1092 | if (corrbytes != 0) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1093 | gig_dbg(DEBUG_ISO, "%s: corrbytes=%d", |
| 1094 | __func__, corrbytes); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1095 | if (corrbytes > BAS_HIGHFRAME - BAS_NORMFRAME) |
| 1096 | corrbytes = BAS_HIGHFRAME - BAS_NORMFRAME; |
| 1097 | else if (corrbytes < BAS_LOWFRAME - BAS_NORMFRAME) |
| 1098 | corrbytes = BAS_LOWFRAME - BAS_NORMFRAME; |
| 1099 | ifd->length += corrbytes; |
| 1100 | atomic_add(-corrbytes, &ubc->corrbytes); |
| 1101 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1102 | |
| 1103 | /* retrieve block of data to send */ |
Tilman Schmidt | 5f09c4c | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 1104 | rc = gigaset_isowbuf_getbytes(ubc->isooutbuf, ifd->length); |
| 1105 | if (rc < 0) { |
| 1106 | if (rc == -EBUSY) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1107 | gig_dbg(DEBUG_ISO, |
| 1108 | "%s: buffer busy at frame %d", |
| 1109 | __func__, nframe); |
| 1110 | /* tasklet will be restarted from |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 1111 | gigaset_isoc_send_skb() */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1112 | } else { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1113 | dev_err(ucx->bcs->cs->dev, |
| 1114 | "%s: buffer error %d at frame %d\n", |
Tilman Schmidt | 5f09c4c | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 1115 | __func__, rc, nframe); |
| 1116 | return rc; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1117 | } |
| 1118 | break; |
| 1119 | } |
Tilman Schmidt | 5f09c4c | 2008-07-23 21:28:27 -0700 | [diff] [blame] | 1120 | ifd->offset = rc; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1121 | ucx->limit = ubc->isooutbuf->nextread; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1122 | ifd->status = 0; |
| 1123 | ifd->actual_length = 0; |
| 1124 | } |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1125 | if (unlikely(nframe == 0)) |
| 1126 | return 0; /* no data to send */ |
| 1127 | urb->number_of_packets = nframe; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1128 | |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 1129 | rc = usb_submit_urb(urb, GFP_ATOMIC); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1130 | if (unlikely(rc)) { |
| 1131 | if (rc == -ENODEV) |
| 1132 | /* device removed - give up silently */ |
| 1133 | gig_dbg(DEBUG_ISO, "%s: disconnected", __func__); |
| 1134 | else |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1135 | dev_err(ucx->bcs->cs->dev, |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1136 | "could not submit isoc write URB: %s\n", |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1137 | get_usb_rcmsg(rc)); |
| 1138 | return rc; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1139 | } |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1140 | ++ubc->numsub; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1141 | return nframe; |
| 1142 | } |
| 1143 | |
| 1144 | /* write_iso_tasklet |
| 1145 | * tasklet scheduled when an isochronous output URB from the Gigaset device |
| 1146 | * has completed |
| 1147 | * parameter: |
| 1148 | * data B channel state structure |
| 1149 | */ |
| 1150 | static void write_iso_tasklet(unsigned long data) |
| 1151 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 1152 | struct bc_state *bcs = (struct bc_state *) data; |
| 1153 | struct bas_bc_state *ubc = bcs->hw.bas; |
| 1154 | struct cardstate *cs = bcs->cs; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1155 | struct isow_urbctx_t *done, *next, *ovfl; |
| 1156 | struct urb *urb; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1157 | int status; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1158 | struct usb_iso_packet_descriptor *ifd; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1159 | unsigned long flags; |
| 1160 | int i; |
| 1161 | struct sk_buff *skb; |
| 1162 | int len; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1163 | int rc; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1164 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1165 | /* loop while completed URBs arrive in time */ |
| 1166 | for (;;) { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1167 | if (unlikely(!(ubc->running))) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1168 | gig_dbg(DEBUG_ISO, "%s: not running", __func__); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1169 | return; |
| 1170 | } |
| 1171 | |
| 1172 | /* retrieve completed URBs */ |
| 1173 | spin_lock_irqsave(&ubc->isooutlock, flags); |
| 1174 | done = ubc->isooutdone; |
| 1175 | ubc->isooutdone = NULL; |
| 1176 | ovfl = ubc->isooutovfl; |
| 1177 | ubc->isooutovfl = NULL; |
| 1178 | spin_unlock_irqrestore(&ubc->isooutlock, flags); |
| 1179 | if (ovfl) { |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1180 | dev_err(cs->dev, "isoc write underrun\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1181 | error_hangup(bcs); |
| 1182 | break; |
| 1183 | } |
| 1184 | if (!done) |
| 1185 | break; |
| 1186 | |
| 1187 | /* submit free URB if available */ |
| 1188 | spin_lock_irqsave(&ubc->isooutlock, flags); |
| 1189 | next = ubc->isooutfree; |
| 1190 | ubc->isooutfree = NULL; |
| 1191 | spin_unlock_irqrestore(&ubc->isooutlock, flags); |
| 1192 | if (next) { |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1193 | rc = submit_iso_write_urb(next); |
| 1194 | if (unlikely(rc <= 0 && rc != -ENODEV)) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1195 | /* could not submit URB, put it back */ |
| 1196 | spin_lock_irqsave(&ubc->isooutlock, flags); |
| 1197 | if (ubc->isooutfree == NULL) { |
| 1198 | ubc->isooutfree = next; |
| 1199 | next = NULL; |
| 1200 | } |
| 1201 | spin_unlock_irqrestore(&ubc->isooutlock, flags); |
| 1202 | if (next) { |
| 1203 | /* couldn't put it back */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1204 | dev_err(cs->dev, |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1205 | "losing isoc write URB\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1206 | error_hangup(bcs); |
| 1207 | } |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | /* process completed URB */ |
| 1212 | urb = done->urb; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1213 | status = done->status; |
| 1214 | switch (status) { |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1215 | case -EXDEV: /* partial completion */ |
| 1216 | gig_dbg(DEBUG_ISO, "%s: URB partially completed", |
| 1217 | __func__); |
| 1218 | /* fall through - what's the difference anyway? */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1219 | case 0: /* normal completion */ |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1220 | /* inspect individual frames |
| 1221 | * assumptions (for lack of documentation): |
| 1222 | * - actual_length bytes of first frame in error are |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 1223 | * successfully sent |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1224 | * - all following frames are not sent at all |
| 1225 | */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1226 | for (i = 0; i < BAS_NUMFRAMES; i++) { |
| 1227 | ifd = &urb->iso_frame_desc[i]; |
| 1228 | if (ifd->status || |
| 1229 | ifd->actual_length != ifd->length) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1230 | dev_warn(cs->dev, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1231 | "isoc write: frame %d[%d/%d]: %s\n", |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1232 | i, ifd->actual_length, |
| 1233 | ifd->length, |
| 1234 | get_usb_statmsg(ifd->status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1235 | break; |
| 1236 | } |
| 1237 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1238 | break; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1239 | case -EPIPE: /* stall - probably underrun */ |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1240 | dev_err(cs->dev, "isoc write: stalled\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1241 | error_hangup(bcs); |
| 1242 | break; |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1243 | default: /* other errors */ |
| 1244 | dev_warn(cs->dev, "isoc write: %s\n", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1245 | get_usb_statmsg(status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | /* mark the write buffer area covered by this URB as free */ |
| 1249 | if (done->limit >= 0) |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1250 | ubc->isooutbuf->read = done->limit; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1251 | |
| 1252 | /* mark URB as free */ |
| 1253 | spin_lock_irqsave(&ubc->isooutlock, flags); |
| 1254 | next = ubc->isooutfree; |
| 1255 | ubc->isooutfree = done; |
| 1256 | spin_unlock_irqrestore(&ubc->isooutlock, flags); |
| 1257 | if (next) { |
| 1258 | /* only one URB still active - resubmit one */ |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1259 | rc = submit_iso_write_urb(next); |
| 1260 | if (unlikely(rc <= 0 && rc != -ENODEV)) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1261 | /* couldn't submit */ |
| 1262 | error_hangup(bcs); |
| 1263 | } |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | /* process queued SKBs */ |
| 1268 | while ((skb = skb_dequeue(&bcs->squeue))) { |
| 1269 | /* copy to output buffer, doing L2 encapsulation */ |
| 1270 | len = skb->len; |
| 1271 | if (gigaset_isoc_buildframe(bcs, skb->data, len) == -EAGAIN) { |
| 1272 | /* insufficient buffer space, push back onto queue */ |
| 1273 | skb_queue_head(&bcs->squeue, skb); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1274 | gig_dbg(DEBUG_ISO, "%s: skb requeued, qlen=%d", |
| 1275 | __func__, skb_queue_len(&bcs->squeue)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1276 | break; |
| 1277 | } |
| 1278 | skb_pull(skb, len); |
| 1279 | gigaset_skb_sent(bcs, skb); |
| 1280 | dev_kfree_skb_any(skb); |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | /* Isochronous Read - Bottom Half */ |
| 1285 | /* ============================== */ |
| 1286 | |
| 1287 | /* read_iso_tasklet |
| 1288 | * tasklet scheduled when an isochronous input URB from the Gigaset device |
| 1289 | * has completed |
| 1290 | * parameter: |
| 1291 | * data B channel state structure |
| 1292 | */ |
| 1293 | static void read_iso_tasklet(unsigned long data) |
| 1294 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 1295 | struct bc_state *bcs = (struct bc_state *) data; |
| 1296 | struct bas_bc_state *ubc = bcs->hw.bas; |
| 1297 | struct cardstate *cs = bcs->cs; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1298 | struct urb *urb; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1299 | int status; |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1300 | struct usb_iso_packet_descriptor *ifd; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1301 | char *rcvbuf; |
| 1302 | unsigned long flags; |
| 1303 | int totleft, numbytes, offset, frame, rc; |
| 1304 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1305 | /* loop while more completed URBs arrive in the meantime */ |
| 1306 | for (;;) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1307 | /* retrieve URB */ |
| 1308 | spin_lock_irqsave(&ubc->isoinlock, flags); |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 1309 | urb = ubc->isoindone; |
| 1310 | if (!urb) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1311 | spin_unlock_irqrestore(&ubc->isoinlock, flags); |
| 1312 | return; |
| 1313 | } |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1314 | status = ubc->isoinstatus; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1315 | ubc->isoindone = NULL; |
| 1316 | if (unlikely(ubc->loststatus != -EINPROGRESS)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1317 | dev_warn(cs->dev, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1318 | "isoc read overrun, URB dropped (status: %s, %d bytes)\n", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1319 | get_usb_statmsg(ubc->loststatus), |
| 1320 | ubc->isoinlost); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1321 | ubc->loststatus = -EINPROGRESS; |
| 1322 | } |
| 1323 | spin_unlock_irqrestore(&ubc->isoinlock, flags); |
| 1324 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1325 | if (unlikely(!(ubc->running))) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1326 | gig_dbg(DEBUG_ISO, |
| 1327 | "%s: channel not running, " |
| 1328 | "dropped URB with status: %s", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1329 | __func__, get_usb_statmsg(status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1330 | return; |
| 1331 | } |
| 1332 | |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1333 | switch (status) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1334 | case 0: /* normal completion */ |
| 1335 | break; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 1336 | case -EXDEV: /* inspect individual frames |
| 1337 | (we do that anyway) */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1338 | gig_dbg(DEBUG_ISO, "%s: URB partially completed", |
| 1339 | __func__); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1340 | break; |
| 1341 | case -ENOENT: |
| 1342 | case -ECONNRESET: |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1343 | case -EINPROGRESS: |
| 1344 | gig_dbg(DEBUG_ISO, "%s: %s", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1345 | __func__, get_usb_statmsg(status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1346 | continue; /* -> skip */ |
| 1347 | case -EPIPE: |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1348 | dev_err(cs->dev, "isoc read: stalled\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1349 | error_hangup(bcs); |
| 1350 | continue; /* -> skip */ |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1351 | default: /* other error */ |
| 1352 | dev_warn(cs->dev, "isoc read: %s\n", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1353 | get_usb_statmsg(status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1354 | goto error; |
| 1355 | } |
| 1356 | |
| 1357 | rcvbuf = urb->transfer_buffer; |
| 1358 | totleft = urb->actual_length; |
| 1359 | for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) { |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1360 | ifd = &urb->iso_frame_desc[frame]; |
| 1361 | numbytes = ifd->actual_length; |
| 1362 | switch (ifd->status) { |
| 1363 | case 0: /* success */ |
| 1364 | break; |
| 1365 | case -EPROTO: /* protocol error or unplug */ |
| 1366 | case -EILSEQ: |
| 1367 | case -ETIME: |
| 1368 | /* probably just disconnected, ignore */ |
| 1369 | gig_dbg(DEBUG_ISO, |
| 1370 | "isoc read: frame %d[%d]: %s\n", |
| 1371 | frame, numbytes, |
| 1372 | get_usb_statmsg(ifd->status)); |
| 1373 | break; |
| 1374 | default: /* other error */ |
| 1375 | /* report, assume transferred bytes are ok */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1376 | dev_warn(cs->dev, |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1377 | "isoc read: frame %d[%d]: %s\n", |
Tilman Schmidt | eb4459f | 2009-10-06 12:18:36 +0000 | [diff] [blame] | 1378 | frame, numbytes, |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1379 | get_usb_statmsg(ifd->status)); |
| 1380 | } |
Tilman Schmidt | eb4459f | 2009-10-06 12:18:36 +0000 | [diff] [blame] | 1381 | if (unlikely(numbytes > BAS_MAXFRAME)) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1382 | dev_warn(cs->dev, |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1383 | "isoc read: frame %d[%d]: %s\n", |
| 1384 | frame, numbytes, |
| 1385 | "exceeds max frame size"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1386 | if (unlikely(numbytes > totleft)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1387 | dev_warn(cs->dev, |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1388 | "isoc read: frame %d[%d]: %s\n", |
| 1389 | frame, numbytes, |
| 1390 | "exceeds total transfer length"); |
Tilman Schmidt | eb4459f | 2009-10-06 12:18:36 +0000 | [diff] [blame] | 1391 | numbytes = totleft; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1392 | } |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1393 | offset = ifd->offset; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1394 | if (unlikely(offset + numbytes > BAS_INBUFSIZE)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1395 | dev_warn(cs->dev, |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1396 | "isoc read: frame %d[%d]: %s\n", |
| 1397 | frame, numbytes, |
| 1398 | "exceeds end of buffer"); |
Tilman Schmidt | eb4459f | 2009-10-06 12:18:36 +0000 | [diff] [blame] | 1399 | numbytes = BAS_INBUFSIZE - offset; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1400 | } |
| 1401 | gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs); |
| 1402 | totleft -= numbytes; |
| 1403 | } |
| 1404 | if (unlikely(totleft > 0)) |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1405 | dev_warn(cs->dev, "isoc read: %d data bytes missing\n", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1406 | totleft); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1407 | |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 1408 | error: |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1409 | /* URB processed, resubmit */ |
| 1410 | for (frame = 0; frame < BAS_NUMFRAMES; frame++) { |
| 1411 | urb->iso_frame_desc[frame].status = 0; |
| 1412 | urb->iso_frame_desc[frame].actual_length = 0; |
| 1413 | } |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1414 | /* urb->dev is clobbered by USB subsystem */ |
| 1415 | urb->dev = bcs->cs->hw.bas->udev; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1416 | urb->transfer_flags = URB_ISO_ASAP; |
| 1417 | urb->number_of_packets = BAS_NUMFRAMES; |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 1418 | rc = usb_submit_urb(urb, GFP_ATOMIC); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1419 | if (unlikely(rc != 0 && rc != -ENODEV)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1420 | dev_err(cs->dev, |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1421 | "could not resubmit isoc read URB: %s\n", |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1422 | get_usb_rcmsg(rc)); |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1423 | dump_urb(DEBUG_ISO, "resubmit isoc read", urb); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1424 | error_hangup(bcs); |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | /* Channel Operations */ |
| 1430 | /* ================== */ |
| 1431 | |
| 1432 | /* req_timeout |
| 1433 | * timeout routine for control output request |
| 1434 | * argument: |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 1435 | * controller state structure |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1436 | */ |
| 1437 | static void req_timeout(unsigned long data) |
| 1438 | { |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 1439 | struct cardstate *cs = (struct cardstate *) data; |
| 1440 | struct bas_cardstate *ucs = cs->hw.bas; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1441 | int pending; |
| 1442 | unsigned long flags; |
| 1443 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1444 | check_pending(ucs); |
| 1445 | |
| 1446 | spin_lock_irqsave(&ucs->lock, flags); |
| 1447 | pending = ucs->pending; |
| 1448 | ucs->pending = 0; |
| 1449 | spin_unlock_irqrestore(&ucs->lock, flags); |
| 1450 | |
| 1451 | switch (pending) { |
| 1452 | case 0: /* no pending request */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1453 | gig_dbg(DEBUG_USBREQ, "%s: no request pending", __func__); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1454 | break; |
| 1455 | |
| 1456 | case HD_OPEN_ATCHANNEL: |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 1457 | dev_err(cs->dev, "timeout opening AT channel\n"); |
| 1458 | error_reset(cs); |
| 1459 | break; |
| 1460 | |
| 1461 | case HD_OPEN_B1CHANNEL: |
| 1462 | dev_err(cs->dev, "timeout opening channel 1\n"); |
| 1463 | error_hangup(&cs->bcs[0]); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1464 | break; |
| 1465 | |
| 1466 | case HD_OPEN_B2CHANNEL: |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 1467 | dev_err(cs->dev, "timeout opening channel 2\n"); |
| 1468 | error_hangup(&cs->bcs[1]); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1469 | break; |
| 1470 | |
| 1471 | case HD_CLOSE_ATCHANNEL: |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 1472 | dev_err(cs->dev, "timeout closing AT channel\n"); |
| 1473 | error_reset(cs); |
| 1474 | break; |
| 1475 | |
| 1476 | case HD_CLOSE_B1CHANNEL: |
| 1477 | dev_err(cs->dev, "timeout closing channel 1\n"); |
| 1478 | error_reset(cs); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1479 | break; |
| 1480 | |
| 1481 | case HD_CLOSE_B2CHANNEL: |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 1482 | dev_err(cs->dev, "timeout closing channel 2\n"); |
| 1483 | error_reset(cs); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1484 | break; |
| 1485 | |
Tilman Schmidt | b5f581d | 2009-10-06 12:18:51 +0000 | [diff] [blame] | 1486 | case HD_RESET_INTERRUPT_PIPE: |
| 1487 | /* error recovery escalation */ |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 1488 | dev_err(cs->dev, |
Tilman Schmidt | b5f581d | 2009-10-06 12:18:51 +0000 | [diff] [blame] | 1489 | "reset interrupt pipe timeout, attempting USB reset\n"); |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 1490 | usb_queue_reset_device(ucs->interface); |
Tilman Schmidt | b5f581d | 2009-10-06 12:18:51 +0000 | [diff] [blame] | 1491 | break; |
| 1492 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1493 | default: |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 1494 | dev_warn(cs->dev, "request 0x%02x timed out, clearing\n", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1495 | pending); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1496 | } |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 1497 | |
| 1498 | wake_up(&ucs->waitqueue); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | /* write_ctrl_callback |
| 1502 | * USB completion handler for control pipe output |
| 1503 | * called by the USB subsystem in interrupt context |
| 1504 | * parameter: |
| 1505 | * urb USB request block of completed request |
| 1506 | * urb->context = hardware specific controller state structure |
| 1507 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1508 | static void write_ctrl_callback(struct urb *urb) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1509 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 1510 | struct bas_cardstate *ucs = urb->context; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1511 | int status = urb->status; |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1512 | int rc; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1513 | unsigned long flags; |
| 1514 | |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1515 | /* check status */ |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1516 | switch (status) { |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1517 | case 0: /* normal completion */ |
| 1518 | spin_lock_irqsave(&ucs->lock, flags); |
| 1519 | switch (ucs->pending) { |
| 1520 | case HD_DEVICE_INIT_ACK: /* no reply expected */ |
| 1521 | del_timer(&ucs->timer_ctrl); |
| 1522 | ucs->pending = 0; |
| 1523 | break; |
| 1524 | } |
| 1525 | spin_unlock_irqrestore(&ucs->lock, flags); |
| 1526 | return; |
| 1527 | |
| 1528 | case -ENOENT: /* cancelled */ |
| 1529 | case -ECONNRESET: /* cancelled (async) */ |
| 1530 | case -EINPROGRESS: /* pending */ |
| 1531 | case -ENODEV: /* device removed */ |
| 1532 | case -ESHUTDOWN: /* device shut down */ |
| 1533 | /* ignore silently */ |
| 1534 | gig_dbg(DEBUG_USBREQ, "%s: %s", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1535 | __func__, get_usb_statmsg(status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1536 | break; |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1537 | |
| 1538 | default: /* any failure */ |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 1539 | /* don't retry if suspend requested */ |
| 1540 | if (++ucs->retry_ctrl > BAS_RETRY || |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1541 | (ucs->basstate & BS_SUSPEND)) { |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1542 | dev_err(&ucs->interface->dev, |
| 1543 | "control request 0x%02x failed: %s\n", |
| 1544 | ucs->dr_ctrl.bRequest, |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1545 | get_usb_statmsg(status)); |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1546 | break; /* give up */ |
| 1547 | } |
| 1548 | dev_notice(&ucs->interface->dev, |
| 1549 | "control request 0x%02x: %s, retry %d\n", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1550 | ucs->dr_ctrl.bRequest, get_usb_statmsg(status), |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1551 | ucs->retry_ctrl); |
| 1552 | /* urb->dev is clobbered by USB subsystem */ |
| 1553 | urb->dev = ucs->udev; |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 1554 | rc = usb_submit_urb(urb, GFP_ATOMIC); |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1555 | if (unlikely(rc)) { |
| 1556 | dev_err(&ucs->interface->dev, |
| 1557 | "could not resubmit request 0x%02x: %s\n", |
| 1558 | ucs->dr_ctrl.bRequest, get_usb_rcmsg(rc)); |
| 1559 | break; |
| 1560 | } |
| 1561 | /* resubmitted */ |
| 1562 | return; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1563 | } |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1564 | |
| 1565 | /* failed, clear pending request */ |
| 1566 | spin_lock_irqsave(&ucs->lock, flags); |
| 1567 | del_timer(&ucs->timer_ctrl); |
| 1568 | ucs->pending = 0; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1569 | spin_unlock_irqrestore(&ucs->lock, flags); |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 1570 | wake_up(&ucs->waitqueue); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | /* req_submit |
| 1574 | * submit a control output request without message buffer to the Gigaset base |
| 1575 | * and optionally start a timeout |
| 1576 | * parameters: |
| 1577 | * bcs B channel control structure |
| 1578 | * req control request code (HD_*) |
| 1579 | * val control request parameter value (set to 0 if unused) |
| 1580 | * timeout timeout in seconds (0: no timeout) |
| 1581 | * return value: |
| 1582 | * 0 on success |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1583 | * -EBUSY if another request is pending |
| 1584 | * any URB submission error code |
| 1585 | */ |
| 1586 | static int req_submit(struct bc_state *bcs, int req, int val, int timeout) |
| 1587 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 1588 | struct bas_cardstate *ucs = bcs->cs->hw.bas; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1589 | int ret; |
| 1590 | unsigned long flags; |
| 1591 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1592 | gig_dbg(DEBUG_USBREQ, "-------> 0x%02x (%d)", req, val); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1593 | |
| 1594 | spin_lock_irqsave(&ucs->lock, flags); |
| 1595 | if (ucs->pending) { |
| 1596 | spin_unlock_irqrestore(&ucs->lock, flags); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1597 | dev_err(bcs->cs->dev, |
| 1598 | "submission of request 0x%02x failed: " |
| 1599 | "request 0x%02x still pending\n", |
| 1600 | req, ucs->pending); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1601 | return -EBUSY; |
| 1602 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1603 | |
| 1604 | ucs->dr_ctrl.bRequestType = OUT_VENDOR_REQ; |
| 1605 | ucs->dr_ctrl.bRequest = req; |
| 1606 | ucs->dr_ctrl.wValue = cpu_to_le16(val); |
| 1607 | ucs->dr_ctrl.wIndex = 0; |
| 1608 | ucs->dr_ctrl.wLength = 0; |
| 1609 | usb_fill_control_urb(ucs->urb_ctrl, ucs->udev, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1610 | usb_sndctrlpipe(ucs->udev, 0), |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 1611 | (unsigned char *) &ucs->dr_ctrl, NULL, 0, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1612 | write_ctrl_callback, ucs); |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1613 | ucs->retry_ctrl = 0; |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 1614 | ret = usb_submit_urb(ucs->urb_ctrl, GFP_ATOMIC); |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1615 | if (unlikely(ret)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1616 | dev_err(bcs->cs->dev, "could not submit request 0x%02x: %s\n", |
Tilman Schmidt | 06163f8 | 2006-06-26 00:25:33 -0700 | [diff] [blame] | 1617 | req, get_usb_rcmsg(ret)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1618 | spin_unlock_irqrestore(&ucs->lock, flags); |
| 1619 | return ret; |
| 1620 | } |
| 1621 | ucs->pending = req; |
| 1622 | |
| 1623 | if (timeout > 0) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1624 | gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout); |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 1625 | mod_timer(&ucs->timer_ctrl, jiffies + timeout * HZ / 10); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | spin_unlock_irqrestore(&ucs->lock, flags); |
| 1629 | return 0; |
| 1630 | } |
| 1631 | |
| 1632 | /* gigaset_init_bchannel |
| 1633 | * called by common.c to connect a B channel |
| 1634 | * initialize isochronous I/O and tell the Gigaset base to open the channel |
| 1635 | * argument: |
| 1636 | * B channel control structure |
| 1637 | * return value: |
| 1638 | * 0 on success, error code < 0 on error |
| 1639 | */ |
| 1640 | static int gigaset_init_bchannel(struct bc_state *bcs) |
| 1641 | { |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1642 | struct cardstate *cs = bcs->cs; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1643 | int req, ret; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1644 | unsigned long flags; |
| 1645 | |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1646 | spin_lock_irqsave(&cs->lock, flags); |
| 1647 | if (unlikely(!cs->connected)) { |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1648 | gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__); |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1649 | spin_unlock_irqrestore(&cs->lock, flags); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1650 | return -ENODEV; |
| 1651 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1652 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1653 | if (cs->hw.bas->basstate & BS_SUSPEND) { |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 1654 | dev_notice(cs->dev, |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1655 | "not starting isoc I/O, suspend in progress\n"); |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 1656 | spin_unlock_irqrestore(&cs->lock, flags); |
| 1657 | return -EHOSTUNREACH; |
| 1658 | } |
| 1659 | |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 1660 | ret = starturbs(bcs); |
| 1661 | if (ret < 0) { |
Tilman Schmidt | b33ffa5 | 2010-09-30 13:34:30 +0000 | [diff] [blame] | 1662 | spin_unlock_irqrestore(&cs->lock, flags); |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1663 | dev_err(cs->dev, |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 1664 | "could not start isoc I/O for channel B%d: %s\n", |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1665 | bcs->channel + 1, |
| 1666 | ret == -EFAULT ? "null URB" : get_usb_rcmsg(ret)); |
| 1667 | if (ret != -ENODEV) |
| 1668 | error_hangup(bcs); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1669 | return ret; |
| 1670 | } |
| 1671 | |
| 1672 | req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL; |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 1673 | ret = req_submit(bcs, req, 0, BAS_TIMEOUT); |
| 1674 | if (ret < 0) { |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1675 | dev_err(cs->dev, "could not open channel B%d\n", |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1676 | bcs->channel + 1); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1677 | stopurbs(bcs->hw.bas); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1678 | } |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1679 | |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1680 | spin_unlock_irqrestore(&cs->lock, flags); |
Tilman Schmidt | b33ffa5 | 2010-09-30 13:34:30 +0000 | [diff] [blame] | 1681 | if (ret < 0 && ret != -ENODEV) |
| 1682 | error_hangup(bcs); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1683 | return ret; |
| 1684 | } |
| 1685 | |
| 1686 | /* gigaset_close_bchannel |
| 1687 | * called by common.c to disconnect a B channel |
| 1688 | * tell the Gigaset base to close the channel |
| 1689 | * stopping isochronous I/O and LL notification will be done when the |
| 1690 | * acknowledgement for the close arrives |
| 1691 | * argument: |
| 1692 | * B channel control structure |
| 1693 | * return value: |
| 1694 | * 0 on success, error code < 0 on error |
| 1695 | */ |
| 1696 | static int gigaset_close_bchannel(struct bc_state *bcs) |
| 1697 | { |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1698 | struct cardstate *cs = bcs->cs; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1699 | int req, ret; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1700 | unsigned long flags; |
| 1701 | |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1702 | spin_lock_irqsave(&cs->lock, flags); |
| 1703 | if (unlikely(!cs->connected)) { |
| 1704 | spin_unlock_irqrestore(&cs->lock, flags); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1705 | gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__); |
| 1706 | return -ENODEV; |
| 1707 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1708 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1709 | if (!(cs->hw.bas->basstate & (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1710 | /* channel not running: just signal common.c */ |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1711 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1712 | gigaset_bchannel_down(bcs); |
| 1713 | return 0; |
| 1714 | } |
| 1715 | |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1716 | /* channel running: tell device to close it */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1717 | req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL; |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 1718 | ret = req_submit(bcs, req, 0, BAS_TIMEOUT); |
| 1719 | if (ret < 0) |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1720 | dev_err(cs->dev, "closing channel B%d failed\n", |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1721 | bcs->channel + 1); |
| 1722 | |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 1723 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1724 | return ret; |
| 1725 | } |
| 1726 | |
| 1727 | /* Device Operations */ |
| 1728 | /* ================= */ |
| 1729 | |
| 1730 | /* complete_cb |
| 1731 | * unqueue first command buffer from queue, waking any sleepers |
| 1732 | * must be called with cs->cmdlock held |
| 1733 | * parameter: |
| 1734 | * cs controller state structure |
| 1735 | */ |
| 1736 | static void complete_cb(struct cardstate *cs) |
| 1737 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 1738 | struct cmdbuf_t *cb = cs->cmdbuf; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1739 | |
| 1740 | /* unqueue completed buffer */ |
| 1741 | cs->cmdbytes -= cs->curlen; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1742 | gig_dbg(DEBUG_OUTPUT, "write_command: sent %u bytes, %u left", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1743 | cs->curlen, cs->cmdbytes); |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 1744 | if (cb->next != NULL) { |
| 1745 | cs->cmdbuf = cb->next; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1746 | cs->cmdbuf->prev = NULL; |
| 1747 | cs->curlen = cs->cmdbuf->len; |
| 1748 | } else { |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 1749 | cs->cmdbuf = NULL; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1750 | cs->lastcmdbuf = NULL; |
| 1751 | cs->curlen = 0; |
| 1752 | } |
| 1753 | |
| 1754 | if (cb->wake_tasklet) |
| 1755 | tasklet_schedule(cb->wake_tasklet); |
| 1756 | |
| 1757 | kfree(cb); |
| 1758 | } |
| 1759 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1760 | /* write_command_callback |
| 1761 | * USB completion handler for AT command transmission |
| 1762 | * called by the USB subsystem in interrupt context |
| 1763 | * parameter: |
| 1764 | * urb USB request block of completed request |
| 1765 | * urb->context = controller state structure |
| 1766 | */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1767 | static void write_command_callback(struct urb *urb) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1768 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 1769 | struct cardstate *cs = urb->context; |
| 1770 | struct bas_cardstate *ucs = cs->hw.bas; |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1771 | int status = urb->status; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1772 | unsigned long flags; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1773 | |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1774 | update_basstate(ucs, 0, BS_ATWRPEND); |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 1775 | wake_up(&ucs->waitqueue); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1776 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1777 | /* check status */ |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1778 | switch (status) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1779 | case 0: /* normal completion */ |
| 1780 | break; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1781 | case -ENOENT: /* cancelled */ |
| 1782 | case -ECONNRESET: /* cancelled (async) */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1783 | case -EINPROGRESS: /* pending */ |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1784 | case -ENODEV: /* device removed */ |
| 1785 | case -ESHUTDOWN: /* device shut down */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1786 | /* ignore silently */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1787 | gig_dbg(DEBUG_USBREQ, "%s: %s", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1788 | __func__, get_usb_statmsg(status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1789 | return; |
| 1790 | default: /* any failure */ |
| 1791 | if (++ucs->retry_cmd_out > BAS_RETRY) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1792 | dev_warn(cs->dev, |
| 1793 | "command write: %s, " |
| 1794 | "giving up after %d retries\n", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1795 | get_usb_statmsg(status), |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1796 | ucs->retry_cmd_out); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1797 | break; |
| 1798 | } |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1799 | if (ucs->basstate & BS_SUSPEND) { |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 1800 | dev_warn(cs->dev, |
| 1801 | "command write: %s, " |
| 1802 | "won't retry - suspend requested\n", |
| 1803 | get_usb_statmsg(status)); |
| 1804 | break; |
| 1805 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1806 | if (cs->cmdbuf == NULL) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1807 | dev_warn(cs->dev, |
| 1808 | "command write: %s, " |
| 1809 | "cannot retry - cmdbuf gone\n", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1810 | get_usb_statmsg(status)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1811 | break; |
| 1812 | } |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1813 | dev_notice(cs->dev, "command write: %s, retry %d\n", |
Tilman Schmidt | dbd9823 | 2008-02-06 01:38:23 -0800 | [diff] [blame] | 1814 | get_usb_statmsg(status), ucs->retry_cmd_out); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1815 | if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0) |
| 1816 | /* resubmitted - bypass regular exit block */ |
| 1817 | return; |
| 1818 | /* command send failed, assume base still waiting */ |
| 1819 | update_basstate(ucs, BS_ATREADY, 0); |
| 1820 | } |
| 1821 | |
| 1822 | spin_lock_irqsave(&cs->cmdlock, flags); |
| 1823 | if (cs->cmdbuf != NULL) |
| 1824 | complete_cb(cs); |
| 1825 | spin_unlock_irqrestore(&cs->cmdlock, flags); |
| 1826 | } |
| 1827 | |
| 1828 | /* atrdy_timeout |
| 1829 | * timeout routine for AT command transmission |
| 1830 | * argument: |
| 1831 | * controller state structure |
| 1832 | */ |
| 1833 | static void atrdy_timeout(unsigned long data) |
| 1834 | { |
| 1835 | struct cardstate *cs = (struct cardstate *) data; |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 1836 | struct bas_cardstate *ucs = cs->hw.bas; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1837 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1838 | dev_warn(cs->dev, "timeout waiting for HD_READY_SEND_ATDATA\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1839 | |
| 1840 | /* fake the missing signal - what else can I do? */ |
| 1841 | update_basstate(ucs, BS_ATREADY, BS_ATTIMER); |
| 1842 | start_cbsend(cs); |
| 1843 | } |
| 1844 | |
| 1845 | /* atwrite_submit |
| 1846 | * submit an HD_WRITE_ATMESSAGE command URB |
| 1847 | * parameters: |
| 1848 | * cs controller state structure |
| 1849 | * buf buffer containing command to send |
| 1850 | * len length of command to send |
| 1851 | * return value: |
| 1852 | * 0 on success |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1853 | * -EBUSY if another request is pending |
| 1854 | * any URB submission error code |
| 1855 | */ |
| 1856 | static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len) |
| 1857 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 1858 | struct bas_cardstate *ucs = cs->hw.bas; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1859 | int rc; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1860 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1861 | gig_dbg(DEBUG_USBREQ, "-------> HD_WRITE_ATMESSAGE (%d)", len); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1862 | |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1863 | if (update_basstate(ucs, BS_ATWRPEND, 0) & BS_ATWRPEND) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1864 | dev_err(cs->dev, |
| 1865 | "could not submit HD_WRITE_ATMESSAGE: URB busy\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1866 | return -EBUSY; |
| 1867 | } |
| 1868 | |
| 1869 | ucs->dr_cmd_out.bRequestType = OUT_VENDOR_REQ; |
| 1870 | ucs->dr_cmd_out.bRequest = HD_WRITE_ATMESSAGE; |
| 1871 | ucs->dr_cmd_out.wValue = 0; |
| 1872 | ucs->dr_cmd_out.wIndex = 0; |
| 1873 | ucs->dr_cmd_out.wLength = cpu_to_le16(len); |
| 1874 | usb_fill_control_urb(ucs->urb_cmd_out, ucs->udev, |
| 1875 | usb_sndctrlpipe(ucs->udev, 0), |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 1876 | (unsigned char *) &ucs->dr_cmd_out, buf, len, |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1877 | write_command_callback, cs); |
Christoph Lameter | 54e6ecb | 2006-12-06 20:33:16 -0800 | [diff] [blame] | 1878 | rc = usb_submit_urb(ucs->urb_cmd_out, GFP_ATOMIC); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1879 | if (unlikely(rc)) { |
| 1880 | update_basstate(ucs, 0, BS_ATWRPEND); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1881 | dev_err(cs->dev, "could not submit HD_WRITE_ATMESSAGE: %s\n", |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1882 | get_usb_rcmsg(rc)); |
| 1883 | return rc; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1884 | } |
| 1885 | |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 1886 | /* submitted successfully, start timeout if necessary */ |
| 1887 | if (!(update_basstate(ucs, BS_ATTIMER, BS_ATREADY) & BS_ATTIMER)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1888 | gig_dbg(DEBUG_OUTPUT, "setting ATREADY timeout of %d/10 secs", |
| 1889 | ATRDY_TIMEOUT); |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 1890 | mod_timer(&ucs->timer_atrdy, jiffies + ATRDY_TIMEOUT * HZ / 10); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1891 | } |
| 1892 | return 0; |
| 1893 | } |
| 1894 | |
| 1895 | /* start_cbsend |
| 1896 | * start transmission of AT command queue if necessary |
| 1897 | * parameter: |
| 1898 | * cs controller state structure |
| 1899 | * return value: |
| 1900 | * 0 on success |
| 1901 | * error code < 0 on error |
| 1902 | */ |
| 1903 | static int start_cbsend(struct cardstate *cs) |
| 1904 | { |
| 1905 | struct cmdbuf_t *cb; |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 1906 | struct bas_cardstate *ucs = cs->hw.bas; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1907 | unsigned long flags; |
| 1908 | int rc; |
| 1909 | int retval = 0; |
| 1910 | |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 1911 | /* check if suspend requested */ |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1912 | if (ucs->basstate & BS_SUSPEND) { |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1913 | gig_dbg(DEBUG_OUTPUT, "suspending"); |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 1914 | return -EHOSTUNREACH; |
| 1915 | } |
| 1916 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1917 | /* check if AT channel is open */ |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1918 | if (!(ucs->basstate & BS_ATOPEN)) { |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1919 | gig_dbg(DEBUG_OUTPUT, "AT channel not open"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1920 | rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT); |
| 1921 | if (rc < 0) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1922 | /* flush command queue */ |
| 1923 | spin_lock_irqsave(&cs->cmdlock, flags); |
| 1924 | while (cs->cmdbuf != NULL) |
| 1925 | complete_cb(cs); |
| 1926 | spin_unlock_irqrestore(&cs->cmdlock, flags); |
| 1927 | } |
| 1928 | return rc; |
| 1929 | } |
| 1930 | |
| 1931 | /* try to send first command in queue */ |
| 1932 | spin_lock_irqsave(&cs->cmdlock, flags); |
| 1933 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1934 | while ((cb = cs->cmdbuf) != NULL && (ucs->basstate & BS_ATREADY)) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1935 | ucs->retry_cmd_out = 0; |
| 1936 | rc = atwrite_submit(cs, cb->buf, cb->len); |
| 1937 | if (unlikely(rc)) { |
| 1938 | retval = rc; |
| 1939 | complete_cb(cs); |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | spin_unlock_irqrestore(&cs->cmdlock, flags); |
| 1944 | return retval; |
| 1945 | } |
| 1946 | |
| 1947 | /* gigaset_write_cmd |
| 1948 | * This function is called by the device independent part of the driver |
| 1949 | * to transmit an AT command string to the Gigaset device. |
| 1950 | * It encapsulates the device specific method for transmission over the |
| 1951 | * direct USB connection to the base. |
| 1952 | * The command string is added to the queue of commands to send, and |
| 1953 | * USB transmission is started if necessary. |
| 1954 | * parameters: |
| 1955 | * cs controller state structure |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 1956 | * cb command buffer structure |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1957 | * return value: |
| 1958 | * number of bytes queued on success |
| 1959 | * error code < 0 on error |
| 1960 | */ |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 1961 | static int gigaset_write_cmd(struct cardstate *cs, struct cmdbuf_t *cb) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1962 | { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1963 | unsigned long flags; |
Tilman Schmidt | 39f0722 | 2006-12-13 00:33:52 -0800 | [diff] [blame] | 1964 | int rc; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1965 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1966 | gigaset_dbg_buffer(cs->mstate != MS_LOCKED ? |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1967 | DEBUG_TRANSCMD : DEBUG_LOCKCMD, |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 1968 | "CMD Transmit", cb->len, cb->buf); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 1969 | |
Tilman Schmidt | b5f581d | 2009-10-06 12:18:51 +0000 | [diff] [blame] | 1970 | /* translate "+++" escape sequence sent as a single separate command |
| 1971 | * into "close AT channel" command for error recovery |
| 1972 | * The next command will reopen the AT channel automatically. |
| 1973 | */ |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 1974 | if (cb->len == 3 && !memcmp(cb->buf, "+++", 3)) { |
Tilman Schmidt | 4cb5e42 | 2010-09-30 13:35:31 +0000 | [diff] [blame] | 1975 | /* If an HD_RECEIVEATDATA_ACK message remains unhandled |
| 1976 | * because of an error, the base never sends another one. |
| 1977 | * The response channel is thus effectively blocked. |
| 1978 | * Closing and reopening the AT channel does *not* clear |
| 1979 | * this condition. |
| 1980 | * As a stopgap measure, submit a zero-length AT read |
| 1981 | * before closing the AT channel. This has the undocumented |
| 1982 | * effect of triggering a new HD_RECEIVEATDATA_ACK message |
| 1983 | * from the base if necessary. |
| 1984 | * The subsequent AT channel close then discards any pending |
| 1985 | * messages. |
| 1986 | */ |
| 1987 | spin_lock_irqsave(&cs->lock, flags); |
| 1988 | if (!(cs->hw.bas->basstate & BS_ATRDPEND)) { |
| 1989 | kfree(cs->hw.bas->rcvbuf); |
| 1990 | cs->hw.bas->rcvbuf = NULL; |
| 1991 | cs->hw.bas->rcvbuf_size = 0; |
| 1992 | cs->hw.bas->retry_cmd_in = 0; |
| 1993 | atread_submit(cs, 0); |
| 1994 | } |
| 1995 | spin_unlock_irqrestore(&cs->lock, flags); |
| 1996 | |
Tilman Schmidt | b5f581d | 2009-10-06 12:18:51 +0000 | [diff] [blame] | 1997 | rc = req_submit(cs->bcs, HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT); |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 1998 | if (cb->wake_tasklet) |
| 1999 | tasklet_schedule(cb->wake_tasklet); |
Dan Carpenter | 8bcfbd0 | 2010-08-05 22:21:26 +0000 | [diff] [blame] | 2000 | if (!rc) |
| 2001 | rc = cb->len; |
| 2002 | kfree(cb); |
| 2003 | return rc; |
Tilman Schmidt | b5f581d | 2009-10-06 12:18:51 +0000 | [diff] [blame] | 2004 | } |
| 2005 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2006 | spin_lock_irqsave(&cs->cmdlock, flags); |
| 2007 | cb->prev = cs->lastcmdbuf; |
| 2008 | if (cs->lastcmdbuf) |
| 2009 | cs->lastcmdbuf->next = cb; |
| 2010 | else { |
| 2011 | cs->cmdbuf = cb; |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 2012 | cs->curlen = cb->len; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2013 | } |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 2014 | cs->cmdbytes += cb->len; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2015 | cs->lastcmdbuf = cb; |
| 2016 | spin_unlock_irqrestore(&cs->cmdlock, flags); |
| 2017 | |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2018 | spin_lock_irqsave(&cs->lock, flags); |
| 2019 | if (unlikely(!cs->connected)) { |
| 2020 | spin_unlock_irqrestore(&cs->lock, flags); |
| 2021 | gig_dbg(DEBUG_USBREQ, "%s: not connected", __func__); |
Tilman Schmidt | 39f0722 | 2006-12-13 00:33:52 -0800 | [diff] [blame] | 2022 | /* flush command queue */ |
| 2023 | spin_lock_irqsave(&cs->cmdlock, flags); |
| 2024 | while (cs->cmdbuf != NULL) |
| 2025 | complete_cb(cs); |
| 2026 | spin_unlock_irqrestore(&cs->cmdlock, flags); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2027 | return -ENODEV; |
| 2028 | } |
Tilman Schmidt | 39f0722 | 2006-12-13 00:33:52 -0800 | [diff] [blame] | 2029 | rc = start_cbsend(cs); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2030 | spin_unlock_irqrestore(&cs->lock, flags); |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 2031 | return rc < 0 ? rc : cb->len; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | /* gigaset_write_room |
| 2035 | * tty_driver.write_room interface routine |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 2036 | * return number of characters the driver will accept to be written via |
| 2037 | * gigaset_write_cmd |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2038 | * parameter: |
| 2039 | * controller state structure |
| 2040 | * return value: |
| 2041 | * number of characters |
| 2042 | */ |
| 2043 | static int gigaset_write_room(struct cardstate *cs) |
| 2044 | { |
| 2045 | return IF_WRITEBUF; |
| 2046 | } |
| 2047 | |
| 2048 | /* gigaset_chars_in_buffer |
| 2049 | * tty_driver.chars_in_buffer interface routine |
| 2050 | * return number of characters waiting to be sent |
| 2051 | * parameter: |
| 2052 | * controller state structure |
| 2053 | * return value: |
| 2054 | * number of characters |
| 2055 | */ |
| 2056 | static int gigaset_chars_in_buffer(struct cardstate *cs) |
| 2057 | { |
Tilman Schmidt | 4d1ff58 | 2007-10-16 01:27:50 -0700 | [diff] [blame] | 2058 | return cs->cmdbytes; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | /* gigaset_brkchars |
| 2062 | * implementation of ioctl(GIGASET_BRKCHARS) |
| 2063 | * parameter: |
| 2064 | * controller state structure |
| 2065 | * return value: |
| 2066 | * -EINVAL (unimplemented function) |
| 2067 | */ |
| 2068 | static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6]) |
| 2069 | { |
| 2070 | return -EINVAL; |
| 2071 | } |
| 2072 | |
| 2073 | |
| 2074 | /* Device Initialization/Shutdown */ |
| 2075 | /* ============================== */ |
| 2076 | |
| 2077 | /* Free hardware dependent part of the B channel structure |
| 2078 | * parameter: |
| 2079 | * bcs B channel structure |
| 2080 | * return value: |
| 2081 | * !=0 on success |
| 2082 | */ |
| 2083 | static int gigaset_freebcshw(struct bc_state *bcs) |
| 2084 | { |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2085 | struct bas_bc_state *ubc = bcs->hw.bas; |
| 2086 | int i; |
| 2087 | |
| 2088 | if (!ubc) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2089 | return 0; |
| 2090 | |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2091 | /* kill URBs and tasklets before freeing - better safe than sorry */ |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 2092 | ubc->running = 0; |
Tilman Schmidt | bb7196d | 2010-09-30 13:35:52 +0000 | [diff] [blame] | 2093 | gig_dbg(DEBUG_INIT, "%s: killing isoc URBs", __func__); |
Tilman Schmidt | 39f0722 | 2006-12-13 00:33:52 -0800 | [diff] [blame] | 2094 | for (i = 0; i < BAS_OUTURBS; ++i) { |
| 2095 | usb_kill_urb(ubc->isoouturbs[i].urb); |
| 2096 | usb_free_urb(ubc->isoouturbs[i].urb); |
| 2097 | } |
| 2098 | for (i = 0; i < BAS_INURBS; ++i) { |
| 2099 | usb_kill_urb(ubc->isoinurbs[i]); |
| 2100 | usb_free_urb(ubc->isoinurbs[i]); |
| 2101 | } |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2102 | tasklet_kill(&ubc->sent_tasklet); |
| 2103 | tasklet_kill(&ubc->rcvd_tasklet); |
| 2104 | kfree(ubc->isooutbuf); |
| 2105 | kfree(ubc); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2106 | bcs->hw.bas = NULL; |
| 2107 | return 1; |
| 2108 | } |
| 2109 | |
| 2110 | /* Initialize hardware dependent part of the B channel structure |
| 2111 | * parameter: |
| 2112 | * bcs B channel structure |
| 2113 | * return value: |
| 2114 | * !=0 on success |
| 2115 | */ |
| 2116 | static int gigaset_initbcshw(struct bc_state *bcs) |
| 2117 | { |
| 2118 | int i; |
| 2119 | struct bas_bc_state *ubc; |
| 2120 | |
| 2121 | bcs->hw.bas = ubc = kmalloc(sizeof(struct bas_bc_state), GFP_KERNEL); |
| 2122 | if (!ubc) { |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 2123 | pr_err("out of memory\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2124 | return 0; |
| 2125 | } |
| 2126 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 2127 | ubc->running = 0; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2128 | atomic_set(&ubc->corrbytes, 0); |
| 2129 | spin_lock_init(&ubc->isooutlock); |
| 2130 | for (i = 0; i < BAS_OUTURBS; ++i) { |
| 2131 | ubc->isoouturbs[i].urb = NULL; |
| 2132 | ubc->isoouturbs[i].bcs = bcs; |
| 2133 | } |
| 2134 | ubc->isooutdone = ubc->isooutfree = ubc->isooutovfl = NULL; |
| 2135 | ubc->numsub = 0; |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 2136 | ubc->isooutbuf = kmalloc(sizeof(struct isowbuf_t), GFP_KERNEL); |
| 2137 | if (!ubc->isooutbuf) { |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 2138 | pr_err("out of memory\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2139 | kfree(ubc); |
| 2140 | bcs->hw.bas = NULL; |
| 2141 | return 0; |
| 2142 | } |
| 2143 | tasklet_init(&ubc->sent_tasklet, |
Joe Perches | 5452fee | 2009-11-19 09:55:53 +0000 | [diff] [blame] | 2144 | write_iso_tasklet, (unsigned long) bcs); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2145 | |
| 2146 | spin_lock_init(&ubc->isoinlock); |
| 2147 | for (i = 0; i < BAS_INURBS; ++i) |
| 2148 | ubc->isoinurbs[i] = NULL; |
| 2149 | ubc->isoindone = NULL; |
| 2150 | ubc->loststatus = -EINPROGRESS; |
| 2151 | ubc->isoinlost = 0; |
| 2152 | ubc->seqlen = 0; |
| 2153 | ubc->inbyte = 0; |
| 2154 | ubc->inbits = 0; |
| 2155 | ubc->goodbytes = 0; |
| 2156 | ubc->alignerrs = 0; |
| 2157 | ubc->fcserrs = 0; |
| 2158 | ubc->frameerrs = 0; |
| 2159 | ubc->giants = 0; |
| 2160 | ubc->runts = 0; |
| 2161 | ubc->aborts = 0; |
| 2162 | ubc->shared0s = 0; |
| 2163 | ubc->stolen0s = 0; |
| 2164 | tasklet_init(&ubc->rcvd_tasklet, |
Joe Perches | 5452fee | 2009-11-19 09:55:53 +0000 | [diff] [blame] | 2165 | read_iso_tasklet, (unsigned long) bcs); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2166 | return 1; |
| 2167 | } |
| 2168 | |
| 2169 | static void gigaset_reinitbcshw(struct bc_state *bcs) |
| 2170 | { |
| 2171 | struct bas_bc_state *ubc = bcs->hw.bas; |
| 2172 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 2173 | bcs->hw.bas->running = 0; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2174 | atomic_set(&bcs->hw.bas->corrbytes, 0); |
| 2175 | bcs->hw.bas->numsub = 0; |
| 2176 | spin_lock_init(&ubc->isooutlock); |
| 2177 | spin_lock_init(&ubc->isoinlock); |
| 2178 | ubc->loststatus = -EINPROGRESS; |
| 2179 | } |
| 2180 | |
| 2181 | static void gigaset_freecshw(struct cardstate *cs) |
| 2182 | { |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2183 | /* timers, URBs and rcvbuf are disposed of in disconnect */ |
Tilman Schmidt | 170ebf8 | 2009-03-18 23:44:23 -0700 | [diff] [blame] | 2184 | kfree(cs->hw.bas->int_in_buf); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2185 | kfree(cs->hw.bas); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2186 | cs->hw.bas = NULL; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | static int gigaset_initcshw(struct cardstate *cs) |
| 2190 | { |
| 2191 | struct bas_cardstate *ucs; |
| 2192 | |
| 2193 | cs->hw.bas = ucs = kmalloc(sizeof *ucs, GFP_KERNEL); |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 2194 | if (!ucs) { |
| 2195 | pr_err("out of memory\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2196 | return 0; |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 2197 | } |
Tilman Schmidt | 170ebf8 | 2009-03-18 23:44:23 -0700 | [diff] [blame] | 2198 | ucs->int_in_buf = kmalloc(IP_MSGSIZE, GFP_KERNEL); |
| 2199 | if (!ucs->int_in_buf) { |
| 2200 | kfree(ucs); |
| 2201 | pr_err("out of memory\n"); |
| 2202 | return 0; |
| 2203 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2204 | |
| 2205 | ucs->urb_cmd_in = NULL; |
| 2206 | ucs->urb_cmd_out = NULL; |
| 2207 | ucs->rcvbuf = NULL; |
| 2208 | ucs->rcvbuf_size = 0; |
| 2209 | |
| 2210 | spin_lock_init(&ucs->lock); |
| 2211 | ucs->pending = 0; |
| 2212 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 2213 | ucs->basstate = 0; |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 2214 | setup_timer(&ucs->timer_ctrl, req_timeout, (unsigned long) cs); |
| 2215 | setup_timer(&ucs->timer_atrdy, atrdy_timeout, (unsigned long) cs); |
| 2216 | setup_timer(&ucs->timer_cmd_in, cmd_in_timeout, (unsigned long) cs); |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 2217 | setup_timer(&ucs->timer_int_in, int_in_resubmit, (unsigned long) cs); |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2218 | init_waitqueue_head(&ucs->waitqueue); |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 2219 | INIT_WORK(&ucs->int_in_wq, int_in_work); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2220 | |
| 2221 | return 1; |
| 2222 | } |
| 2223 | |
| 2224 | /* freeurbs |
| 2225 | * unlink and deallocate all URBs unconditionally |
| 2226 | * caller must make sure that no commands are still in progress |
| 2227 | * parameter: |
| 2228 | * cs controller state structure |
| 2229 | */ |
| 2230 | static void freeurbs(struct cardstate *cs) |
| 2231 | { |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 2232 | struct bas_cardstate *ucs = cs->hw.bas; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2233 | struct bas_bc_state *ubc; |
| 2234 | int i, j; |
| 2235 | |
Tilman Schmidt | 39f0722 | 2006-12-13 00:33:52 -0800 | [diff] [blame] | 2236 | gig_dbg(DEBUG_INIT, "%s: killing URBs", __func__); |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 2237 | for (j = 0; j < BAS_CHANNELS; ++j) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2238 | ubc = cs->bcs[j].hw.bas; |
Tilman Schmidt | 39f0722 | 2006-12-13 00:33:52 -0800 | [diff] [blame] | 2239 | for (i = 0; i < BAS_OUTURBS; ++i) { |
| 2240 | usb_kill_urb(ubc->isoouturbs[i].urb); |
| 2241 | usb_free_urb(ubc->isoouturbs[i].urb); |
| 2242 | ubc->isoouturbs[i].urb = NULL; |
| 2243 | } |
| 2244 | for (i = 0; i < BAS_INURBS; ++i) { |
| 2245 | usb_kill_urb(ubc->isoinurbs[i]); |
| 2246 | usb_free_urb(ubc->isoinurbs[i]); |
| 2247 | ubc->isoinurbs[i] = NULL; |
| 2248 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2249 | } |
Tilman Schmidt | 39f0722 | 2006-12-13 00:33:52 -0800 | [diff] [blame] | 2250 | usb_kill_urb(ucs->urb_int_in); |
| 2251 | usb_free_urb(ucs->urb_int_in); |
| 2252 | ucs->urb_int_in = NULL; |
| 2253 | usb_kill_urb(ucs->urb_cmd_out); |
| 2254 | usb_free_urb(ucs->urb_cmd_out); |
| 2255 | ucs->urb_cmd_out = NULL; |
| 2256 | usb_kill_urb(ucs->urb_cmd_in); |
| 2257 | usb_free_urb(ucs->urb_cmd_in); |
| 2258 | ucs->urb_cmd_in = NULL; |
| 2259 | usb_kill_urb(ucs->urb_ctrl); |
| 2260 | usb_free_urb(ucs->urb_ctrl); |
| 2261 | ucs->urb_ctrl = NULL; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | /* gigaset_probe |
| 2265 | * This function is called when a new USB device is connected. |
| 2266 | * It checks whether the new device is handled by this driver. |
| 2267 | */ |
| 2268 | static int gigaset_probe(struct usb_interface *interface, |
| 2269 | const struct usb_device_id *id) |
| 2270 | { |
| 2271 | struct usb_host_interface *hostif; |
| 2272 | struct usb_device *udev = interface_to_usbdev(interface); |
| 2273 | struct cardstate *cs = NULL; |
| 2274 | struct bas_cardstate *ucs = NULL; |
| 2275 | struct bas_bc_state *ubc; |
| 2276 | struct usb_endpoint_descriptor *endpoint; |
| 2277 | int i, j; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2278 | int rc; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2279 | |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 2280 | gig_dbg(DEBUG_INIT, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 2281 | "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)", |
| 2282 | __func__, le16_to_cpu(udev->descriptor.idVendor), |
| 2283 | le16_to_cpu(udev->descriptor.idProduct)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2284 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2285 | /* set required alternate setting */ |
| 2286 | hostif = interface->cur_altsetting; |
| 2287 | if (hostif->desc.bAlternateSetting != 3) { |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 2288 | gig_dbg(DEBUG_INIT, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 2289 | "%s: wrong alternate setting %d - trying to switch", |
| 2290 | __func__, hostif->desc.bAlternateSetting); |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 2291 | if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) |
| 2292 | < 0) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 2293 | dev_warn(&udev->dev, "usb_set_interface failed, " |
| 2294 | "device %d interface %d altsetting %d\n", |
| 2295 | udev->devnum, hostif->desc.bInterfaceNumber, |
| 2296 | hostif->desc.bAlternateSetting); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2297 | return -ENODEV; |
| 2298 | } |
| 2299 | hostif = interface->cur_altsetting; |
| 2300 | } |
| 2301 | |
| 2302 | /* Reject application specific interfaces |
| 2303 | */ |
| 2304 | if (hostif->desc.bInterfaceClass != 255) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 2305 | dev_warn(&udev->dev, "%s: bInterfaceClass == %d\n", |
| 2306 | __func__, hostif->desc.bInterfaceClass); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2307 | return -ENODEV; |
| 2308 | } |
| 2309 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 2310 | dev_info(&udev->dev, |
| 2311 | "%s: Device matched (Vendor: 0x%x, Product: 0x%x)\n", |
| 2312 | __func__, le16_to_cpu(udev->descriptor.idVendor), |
| 2313 | le16_to_cpu(udev->descriptor.idProduct)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2314 | |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 2315 | /* allocate memory for our device state and initialize it */ |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 2316 | cs = gigaset_initcs(driver, BAS_CHANNELS, 0, 0, cidmode, |
| 2317 | GIGASET_MODULENAME); |
| 2318 | if (!cs) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2319 | return -ENODEV; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2320 | ucs = cs->hw.bas; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 2321 | |
| 2322 | /* save off device structure ptrs for later use */ |
| 2323 | usb_get_dev(udev); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2324 | ucs->udev = udev; |
| 2325 | ucs->interface = interface; |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 2326 | cs->dev = &interface->dev; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2327 | |
| 2328 | /* allocate URBs: |
| 2329 | * - one for the interrupt pipe |
| 2330 | * - three for the different uses of the default control pipe |
| 2331 | * - three for each isochronous pipe |
| 2332 | */ |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 2333 | if (!(ucs->urb_int_in = usb_alloc_urb(0, GFP_KERNEL)) || |
| 2334 | !(ucs->urb_cmd_in = usb_alloc_urb(0, GFP_KERNEL)) || |
| 2335 | !(ucs->urb_cmd_out = usb_alloc_urb(0, GFP_KERNEL)) || |
| 2336 | !(ucs->urb_ctrl = usb_alloc_urb(0, GFP_KERNEL))) |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2337 | goto allocerr; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2338 | |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 2339 | for (j = 0; j < BAS_CHANNELS; ++j) { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2340 | ubc = cs->bcs[j].hw.bas; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2341 | for (i = 0; i < BAS_OUTURBS; ++i) |
| 2342 | if (!(ubc->isoouturbs[i].urb = |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 2343 | usb_alloc_urb(BAS_NUMFRAMES, GFP_KERNEL))) |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2344 | goto allocerr; |
| 2345 | for (i = 0; i < BAS_INURBS; ++i) |
| 2346 | if (!(ubc->isoinurbs[i] = |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 2347 | usb_alloc_urb(BAS_NUMFRAMES, GFP_KERNEL))) |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2348 | goto allocerr; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | ucs->rcvbuf = NULL; |
| 2352 | ucs->rcvbuf_size = 0; |
| 2353 | |
| 2354 | /* Fill the interrupt urb and send it to the core */ |
| 2355 | endpoint = &hostif->endpoint[0].desc; |
| 2356 | usb_fill_int_urb(ucs->urb_int_in, udev, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 2357 | usb_rcvintpipe(udev, |
| 2358 | (endpoint->bEndpointAddress) & 0x0f), |
Tilman Schmidt | 170ebf8 | 2009-03-18 23:44:23 -0700 | [diff] [blame] | 2359 | ucs->int_in_buf, IP_MSGSIZE, read_int_callback, cs, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 2360 | endpoint->bInterval); |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 2361 | rc = usb_submit_urb(ucs->urb_int_in, GFP_KERNEL); |
| 2362 | if (rc != 0) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 2363 | dev_err(cs->dev, "could not submit interrupt URB: %s\n", |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2364 | get_usb_rcmsg(rc)); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2365 | goto error; |
| 2366 | } |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 2367 | ucs->retry_int_in = 0; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2368 | |
| 2369 | /* tell the device that the driver is ready */ |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 2370 | rc = req_submit(cs->bcs, HD_DEVICE_INIT_ACK, 0, 0); |
| 2371 | if (rc != 0) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2372 | goto error; |
| 2373 | |
| 2374 | /* tell common part that the device is ready */ |
| 2375 | if (startmode == SM_LOCKED) |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 2376 | cs->mstate = MS_LOCKED; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2377 | |
| 2378 | /* save address of controller structure */ |
| 2379 | usb_set_intfdata(interface, cs); |
| 2380 | |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 2381 | if (!gigaset_start(cs)) |
| 2382 | goto error; |
| 2383 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2384 | return 0; |
| 2385 | |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2386 | allocerr: |
| 2387 | dev_err(cs->dev, "could not allocate URBs\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2388 | error: |
| 2389 | freeurbs(cs); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 2390 | usb_set_intfdata(interface, NULL); |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 2391 | gigaset_freecs(cs); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2392 | return -ENODEV; |
| 2393 | } |
| 2394 | |
| 2395 | /* gigaset_disconnect |
| 2396 | * This function is called when the Gigaset base is unplugged. |
| 2397 | */ |
| 2398 | static void gigaset_disconnect(struct usb_interface *interface) |
| 2399 | { |
| 2400 | struct cardstate *cs; |
| 2401 | struct bas_cardstate *ucs; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2402 | int j; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2403 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2404 | cs = usb_get_intfdata(interface); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2405 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2406 | ucs = cs->hw.bas; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2407 | |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 2408 | dev_info(cs->dev, "disconnecting Gigaset base\n"); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2409 | |
| 2410 | /* mark base as not ready, all channels disconnected */ |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 2411 | ucs->basstate = 0; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2412 | |
| 2413 | /* tell LL all channels are down */ |
Tilman Schmidt | c652cbd | 2008-02-06 01:38:24 -0800 | [diff] [blame] | 2414 | for (j = 0; j < BAS_CHANNELS; ++j) |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2415 | gigaset_bchannel_down(cs->bcs + j); |
| 2416 | |
| 2417 | /* stop driver (common part) */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2418 | gigaset_stop(cs); |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2419 | |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 2420 | /* stop delayed work and URBs, free ressources */ |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2421 | del_timer_sync(&ucs->timer_ctrl); |
| 2422 | del_timer_sync(&ucs->timer_atrdy); |
| 2423 | del_timer_sync(&ucs->timer_cmd_in); |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 2424 | del_timer_sync(&ucs->timer_int_in); |
| 2425 | cancel_work_sync(&ucs->int_in_wq); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2426 | freeurbs(cs); |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 2427 | usb_set_intfdata(interface, NULL); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2428 | kfree(ucs->rcvbuf); |
| 2429 | ucs->rcvbuf = NULL; |
| 2430 | ucs->rcvbuf_size = 0; |
Tilman Schmidt | b1d4746 | 2006-04-10 22:55:07 -0700 | [diff] [blame] | 2431 | usb_put_dev(ucs->udev); |
| 2432 | ucs->interface = NULL; |
| 2433 | ucs->udev = NULL; |
| 2434 | cs->dev = NULL; |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 2435 | gigaset_freecs(cs); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2436 | } |
| 2437 | |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2438 | /* gigaset_suspend |
| 2439 | * This function is called before the USB connection is suspended. |
| 2440 | */ |
| 2441 | static int gigaset_suspend(struct usb_interface *intf, pm_message_t message) |
| 2442 | { |
| 2443 | struct cardstate *cs = usb_get_intfdata(intf); |
| 2444 | struct bas_cardstate *ucs = cs->hw.bas; |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2445 | int rc; |
| 2446 | |
| 2447 | /* set suspend flag; this stops AT command/response traffic */ |
| 2448 | if (update_basstate(ucs, BS_SUSPEND, 0) & BS_SUSPEND) { |
| 2449 | gig_dbg(DEBUG_SUSPEND, "already suspended"); |
| 2450 | return 0; |
| 2451 | } |
| 2452 | |
| 2453 | /* wait a bit for blocking conditions to go away */ |
| 2454 | rc = wait_event_timeout(ucs->waitqueue, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2455 | !(ucs->basstate & |
| 2456 | (BS_B1OPEN | BS_B2OPEN | BS_ATRDPEND | BS_ATWRPEND)), |
| 2457 | BAS_TIMEOUT * HZ / 10); |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2458 | gig_dbg(DEBUG_SUSPEND, "wait_event_timeout() -> %d", rc); |
| 2459 | |
| 2460 | /* check for conditions preventing suspend */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2461 | if (ucs->basstate & (BS_B1OPEN | BS_B2OPEN | BS_ATRDPEND | BS_ATWRPEND)) { |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2462 | dev_warn(cs->dev, "cannot suspend:\n"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 2463 | if (ucs->basstate & BS_B1OPEN) |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2464 | dev_warn(cs->dev, " B channel 1 open\n"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 2465 | if (ucs->basstate & BS_B2OPEN) |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2466 | dev_warn(cs->dev, " B channel 2 open\n"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 2467 | if (ucs->basstate & BS_ATRDPEND) |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2468 | dev_warn(cs->dev, " receiving AT reply\n"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 2469 | if (ucs->basstate & BS_ATWRPEND) |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2470 | dev_warn(cs->dev, " sending AT command\n"); |
| 2471 | update_basstate(ucs, 0, BS_SUSPEND); |
| 2472 | return -EBUSY; |
| 2473 | } |
| 2474 | |
| 2475 | /* close AT channel if open */ |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 2476 | if (ucs->basstate & BS_ATOPEN) { |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2477 | gig_dbg(DEBUG_SUSPEND, "closing AT channel"); |
| 2478 | rc = req_submit(cs->bcs, HD_CLOSE_ATCHANNEL, 0, 0); |
| 2479 | if (rc) { |
| 2480 | update_basstate(ucs, 0, BS_SUSPEND); |
| 2481 | return rc; |
| 2482 | } |
| 2483 | wait_event_timeout(ucs->waitqueue, !ucs->pending, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 2484 | BAS_TIMEOUT * HZ / 10); |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2485 | /* in case of timeout, proceed anyway */ |
| 2486 | } |
| 2487 | |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 2488 | /* kill all URBs and delayed work that might still be pending */ |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2489 | usb_kill_urb(ucs->urb_ctrl); |
| 2490 | usb_kill_urb(ucs->urb_int_in); |
| 2491 | del_timer_sync(&ucs->timer_ctrl); |
Tilman Schmidt | 1d5a9ed | 2010-09-30 13:35:11 +0000 | [diff] [blame] | 2492 | del_timer_sync(&ucs->timer_atrdy); |
| 2493 | del_timer_sync(&ucs->timer_cmd_in); |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 2494 | del_timer_sync(&ucs->timer_int_in); |
| 2495 | cancel_work_sync(&ucs->int_in_wq); |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2496 | |
| 2497 | gig_dbg(DEBUG_SUSPEND, "suspend complete"); |
| 2498 | return 0; |
| 2499 | } |
| 2500 | |
| 2501 | /* gigaset_resume |
| 2502 | * This function is called after the USB connection has been resumed. |
| 2503 | */ |
| 2504 | static int gigaset_resume(struct usb_interface *intf) |
| 2505 | { |
| 2506 | struct cardstate *cs = usb_get_intfdata(intf); |
| 2507 | struct bas_cardstate *ucs = cs->hw.bas; |
| 2508 | int rc; |
| 2509 | |
| 2510 | /* resubmit interrupt URB for spontaneous messages from base */ |
| 2511 | rc = usb_submit_urb(ucs->urb_int_in, GFP_KERNEL); |
| 2512 | if (rc) { |
| 2513 | dev_err(cs->dev, "could not resubmit interrupt URB: %s\n", |
| 2514 | get_usb_rcmsg(rc)); |
| 2515 | return rc; |
| 2516 | } |
Tilman Schmidt | c9c0c30 | 2010-09-30 13:35:42 +0000 | [diff] [blame] | 2517 | ucs->retry_int_in = 0; |
Tilman Schmidt | 024fd29 | 2008-02-06 01:38:26 -0800 | [diff] [blame] | 2518 | |
| 2519 | /* clear suspend flag to reallow activity */ |
| 2520 | update_basstate(ucs, 0, BS_SUSPEND); |
| 2521 | |
| 2522 | gig_dbg(DEBUG_SUSPEND, "resume complete"); |
| 2523 | return 0; |
| 2524 | } |
| 2525 | |
| 2526 | /* gigaset_pre_reset |
| 2527 | * This function is called before the USB connection is reset. |
| 2528 | */ |
| 2529 | static int gigaset_pre_reset(struct usb_interface *intf) |
| 2530 | { |
| 2531 | /* handle just like suspend */ |
| 2532 | return gigaset_suspend(intf, PMSG_ON); |
| 2533 | } |
| 2534 | |
| 2535 | /* gigaset_post_reset |
| 2536 | * This function is called after the USB connection has been reset. |
| 2537 | */ |
| 2538 | static int gigaset_post_reset(struct usb_interface *intf) |
| 2539 | { |
| 2540 | /* FIXME: send HD_DEVICE_INIT_ACK? */ |
| 2541 | |
| 2542 | /* resume operations */ |
| 2543 | return gigaset_resume(intf); |
| 2544 | } |
| 2545 | |
| 2546 | |
Tilman Schmidt | 35dc845 | 2007-03-29 01:20:34 -0700 | [diff] [blame] | 2547 | static const struct gigaset_ops gigops = { |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2548 | gigaset_write_cmd, |
| 2549 | gigaset_write_room, |
| 2550 | gigaset_chars_in_buffer, |
| 2551 | gigaset_brkchars, |
| 2552 | gigaset_init_bchannel, |
| 2553 | gigaset_close_bchannel, |
| 2554 | gigaset_initbcshw, |
| 2555 | gigaset_freebcshw, |
| 2556 | gigaset_reinitbcshw, |
| 2557 | gigaset_initcshw, |
| 2558 | gigaset_freecshw, |
| 2559 | gigaset_set_modem_ctrl, |
| 2560 | gigaset_baud_rate, |
| 2561 | gigaset_set_line_ctrl, |
| 2562 | gigaset_isoc_send_skb, |
| 2563 | gigaset_isoc_input, |
| 2564 | }; |
| 2565 | |
| 2566 | /* bas_gigaset_init |
| 2567 | * This function is called after the kernel module is loaded. |
| 2568 | */ |
| 2569 | static int __init bas_gigaset_init(void) |
| 2570 | { |
| 2571 | int result; |
| 2572 | |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 2573 | /* allocate memory for our driver state and initialize it */ |
Tilman Schmidt | 7891adf | 2009-10-25 09:30:37 +0000 | [diff] [blame] | 2574 | driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, |
| 2575 | GIGASET_MODULENAME, GIGASET_DEVNAME, |
| 2576 | &gigops, THIS_MODULE); |
| 2577 | if (driver == NULL) |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2578 | goto error; |
| 2579 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2580 | /* register this driver with the USB subsystem */ |
| 2581 | result = usb_register(&gigaset_usb_driver); |
| 2582 | if (result < 0) { |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 2583 | pr_err("error %d registering USB driver\n", -result); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2584 | goto error; |
| 2585 | } |
| 2586 | |
Tilman Schmidt | c8770dc | 2008-12-26 01:21:29 -0800 | [diff] [blame] | 2587 | pr_info(DRIVER_DESC "\n"); |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2588 | return 0; |
| 2589 | |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 2590 | error: |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2591 | if (driver) |
| 2592 | gigaset_freedriver(driver); |
| 2593 | driver = NULL; |
| 2594 | return -1; |
| 2595 | } |
| 2596 | |
| 2597 | /* bas_gigaset_exit |
| 2598 | * This function is called before the kernel module is unloaded. |
| 2599 | */ |
| 2600 | static void __exit bas_gigaset_exit(void) |
| 2601 | { |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 2602 | struct bas_cardstate *ucs; |
| 2603 | int i; |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 2604 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2605 | gigaset_blockdriver(driver); /* => probe will fail |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 2606 | * => no gigaset_start any more |
| 2607 | */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2608 | |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 2609 | /* stop all connected devices */ |
| 2610 | for (i = 0; i < driver->minors; i++) { |
| 2611 | if (gigaset_shutdown(driver->cs + i) < 0) |
| 2612 | continue; /* no device */ |
| 2613 | /* from now on, no isdn callback should be possible */ |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2614 | |
Tilman Schmidt | e468c04 | 2008-02-06 01:38:29 -0800 | [diff] [blame] | 2615 | /* close all still open channels */ |
| 2616 | ucs = driver->cs[i].hw.bas; |
| 2617 | if (ucs->basstate & BS_B1OPEN) { |
| 2618 | gig_dbg(DEBUG_INIT, "closing B1 channel"); |
| 2619 | usb_control_msg(ucs->udev, |
| 2620 | usb_sndctrlpipe(ucs->udev, 0), |
| 2621 | HD_CLOSE_B1CHANNEL, OUT_VENDOR_REQ, |
| 2622 | 0, 0, NULL, 0, BAS_TIMEOUT); |
| 2623 | } |
| 2624 | if (ucs->basstate & BS_B2OPEN) { |
| 2625 | gig_dbg(DEBUG_INIT, "closing B2 channel"); |
| 2626 | usb_control_msg(ucs->udev, |
| 2627 | usb_sndctrlpipe(ucs->udev, 0), |
| 2628 | HD_CLOSE_B2CHANNEL, OUT_VENDOR_REQ, |
| 2629 | 0, 0, NULL, 0, BAS_TIMEOUT); |
| 2630 | } |
| 2631 | if (ucs->basstate & BS_ATOPEN) { |
| 2632 | gig_dbg(DEBUG_INIT, "closing AT channel"); |
| 2633 | usb_control_msg(ucs->udev, |
| 2634 | usb_sndctrlpipe(ucs->udev, 0), |
| 2635 | HD_CLOSE_ATCHANNEL, OUT_VENDOR_REQ, |
| 2636 | 0, 0, NULL, 0, BAS_TIMEOUT); |
| 2637 | } |
| 2638 | ucs->basstate = 0; |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2639 | } |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2640 | |
| 2641 | /* deregister this driver with the USB subsystem */ |
| 2642 | usb_deregister(&gigaset_usb_driver); |
| 2643 | /* this will call the disconnect-callback */ |
| 2644 | /* from now on, no disconnect/probe callback should be running */ |
| 2645 | |
Hansjoerg Lipp | cf7776d | 2006-03-26 01:38:34 -0800 | [diff] [blame] | 2646 | gigaset_freedriver(driver); |
| 2647 | driver = NULL; |
| 2648 | } |
| 2649 | |
| 2650 | |
| 2651 | module_init(bas_gigaset_init); |
| 2652 | module_exit(bas_gigaset_exit); |
| 2653 | |
| 2654 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 2655 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 2656 | MODULE_LICENSE("GPL"); |