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