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