Commit c6fdd8e5d0c65bb8821dc6da26ee1a2ddd58b3cc

Authored by Tilman Schmidt
Committed by David S. Miller
1 parent 910a578f7e

bas_gigaset: fix pre_reset handling

The delayed work function int_in_work() may call usb_reset_device()
and thus, indirectly, the driver's pre_reset method. Trying to
cancel the work synchronously in that situation would deadlock.
Fix by avoiding cancel_work_sync() in the pre_reset method.

If the reset was NOT initiated by int_in_work() this might cause
int_in_work() to run after the post_reset method, with urb_int_in
already resubmitted, so handle that case gracefully.

Signed-off-by: Tilman Schmidt <tilman@imap.cc>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 16 additions and 3 deletions Inline Diff

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