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