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