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