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