aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/gigaset/bas-gigaset.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/isdn/gigaset/bas-gigaset.c')
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c870
1 files changed, 409 insertions, 461 deletions
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index 31f0f07832bc..f86ed6af3aa2 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -3,7 +3,7 @@
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 <Eilers.Stefan@epost.de>. 6 * Stefan Eilers.
7 * 7 *
8 * Based on usb-gigaset.c. 8 * Based on usb-gigaset.c.
9 * 9 *
@@ -13,10 +13,6 @@
13 * published by the Free Software Foundation; either version 2 of 13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version. 14 * the License, or (at your option) any later version.
15 * ===================================================================== 15 * =====================================================================
16 * ToDo: ...
17 * =====================================================================
18 * Version: $Id: bas-gigaset.c,v 1.52.4.19 2006/02/04 18:28:16 hjlipp Exp $
19 * =====================================================================
20 */ 16 */
21 17
22#include "gigaset.h" 18#include "gigaset.h"
@@ -30,7 +26,7 @@
30#include <linux/moduleparam.h> 26#include <linux/moduleparam.h>
31 27
32/* Version Information */ 28/* Version Information */
33#define DRIVER_AUTHOR "Tilman Schmidt <tilman@imap.cc>, Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers <Eilers.Stefan@epost.de>" 29#define DRIVER_AUTHOR "Tilman Schmidt <tilman@imap.cc>, Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers"
34#define DRIVER_DESC "USB Driver for Gigaset 307x" 30#define DRIVER_DESC "USB Driver for Gigaset 307x"
35 31
36 32
@@ -70,9 +66,6 @@ static struct usb_device_id gigaset_table [] = {
70 66
71MODULE_DEVICE_TABLE(usb, gigaset_table); 67MODULE_DEVICE_TABLE(usb, gigaset_table);
72 68
73/* Get a minor range for your devices from the usb maintainer */
74#define USB_SKEL_MINOR_BASE 200
75
76/*======================= local function prototypes =============================*/ 69/*======================= local function prototypes =============================*/
77 70
78/* This function is called if a new device is connected to the USB port. It 71/* This function is called if a new device is connected to the USB port. It
@@ -88,25 +81,25 @@ static void gigaset_disconnect(struct usb_interface *interface);
88/*==============================================================================*/ 81/*==============================================================================*/
89 82
90struct bas_cardstate { 83struct bas_cardstate {
91 struct usb_device *udev; /* USB device pointer */ 84 struct usb_device *udev; /* USB device pointer */
92 struct usb_interface *interface; /* interface for this device */ 85 struct usb_interface *interface; /* interface for this device */
93 unsigned char minor; /* starting minor number */ 86 unsigned char minor; /* starting minor number */
94 87
95 struct urb *urb_ctrl; /* control pipe default URB */ 88 struct urb *urb_ctrl; /* control pipe default URB */
96 struct usb_ctrlrequest dr_ctrl; 89 struct usb_ctrlrequest dr_ctrl;
97 struct timer_list timer_ctrl; /* control request timeout */ 90 struct timer_list timer_ctrl; /* control request timeout */
98 91
99 struct timer_list timer_atrdy; /* AT command ready timeout */ 92 struct timer_list timer_atrdy; /* AT command ready timeout */
100 struct urb *urb_cmd_out; /* for sending AT commands */ 93 struct urb *urb_cmd_out; /* for sending AT commands */
101 struct usb_ctrlrequest dr_cmd_out; 94 struct usb_ctrlrequest dr_cmd_out;
102 int retry_cmd_out; 95 int retry_cmd_out;
103 96
104 struct urb *urb_cmd_in; /* for receiving AT replies */ 97 struct urb *urb_cmd_in; /* for receiving AT replies */
105 struct usb_ctrlrequest dr_cmd_in; 98 struct usb_ctrlrequest dr_cmd_in;
106 struct timer_list timer_cmd_in; /* receive request timeout */ 99 struct timer_list timer_cmd_in; /* receive request timeout */
107 unsigned char *rcvbuf; /* AT reply receive buffer */ 100 unsigned char *rcvbuf; /* AT reply receive buffer */
108 101
109 struct urb *urb_int_in; /* URB for interrupt pipe */ 102 struct urb *urb_int_in; /* URB for interrupt pipe */
110 unsigned char int_in_buf[3]; 103 unsigned char int_in_buf[3];
111 104
112 spinlock_t lock; /* locks all following */ 105 spinlock_t lock; /* locks all following */
@@ -208,53 +201,54 @@ static inline char *usb_pipetype_str(int pipe)
208 * write content of URB to syslog for debugging 201 * write content of URB to syslog for debugging
209 */ 202 */
210static inline void dump_urb(enum debuglevel level, const char *tag, 203static inline void dump_urb(enum debuglevel level, const char *tag,
211 struct urb *urb) 204 struct urb *urb)
212{ 205{
213#ifdef CONFIG_GIGASET_DEBUG 206#ifdef CONFIG_GIGASET_DEBUG
214 int i; 207 int i;
215 IFNULLRET(tag); 208 gig_dbg(level, "%s urb(0x%08lx)->{", tag, (unsigned long) urb);
216 dbg(level, "%s urb(0x%08lx)->{", tag, (unsigned long) urb);
217 if (urb) { 209 if (urb) {
218 dbg(level, 210 gig_dbg(level,
219 " dev=0x%08lx, pipe=%s:EP%d/DV%d:%s, " 211 " dev=0x%08lx, pipe=%s:EP%d/DV%d:%s, "
220 "status=%d, hcpriv=0x%08lx, transfer_flags=0x%x,", 212 "status=%d, hcpriv=0x%08lx, transfer_flags=0x%x,",
221 (unsigned long) urb->dev, 213 (unsigned long) urb->dev,
222 usb_pipetype_str(urb->pipe), 214 usb_pipetype_str(urb->pipe),
223 usb_pipeendpoint(urb->pipe), usb_pipedevice(urb->pipe), 215 usb_pipeendpoint(urb->pipe), usb_pipedevice(urb->pipe),
224 usb_pipein(urb->pipe) ? "in" : "out", 216 usb_pipein(urb->pipe) ? "in" : "out",
225 urb->status, (unsigned long) urb->hcpriv, 217 urb->status, (unsigned long) urb->hcpriv,
226 urb->transfer_flags); 218 urb->transfer_flags);
227 dbg(level, 219 gig_dbg(level,
228 " transfer_buffer=0x%08lx[%d], actual_length=%d, " 220 " transfer_buffer=0x%08lx[%d], actual_length=%d, "
229 "bandwidth=%d, setup_packet=0x%08lx,", 221 "bandwidth=%d, setup_packet=0x%08lx,",
230 (unsigned long) urb->transfer_buffer, 222 (unsigned long) urb->transfer_buffer,
231 urb->transfer_buffer_length, urb->actual_length, 223 urb->transfer_buffer_length, urb->actual_length,
232 urb->bandwidth, (unsigned long) urb->setup_packet); 224 urb->bandwidth, (unsigned long) urb->setup_packet);
233 dbg(level, 225 gig_dbg(level,
234 " start_frame=%d, number_of_packets=%d, interval=%d, " 226 " start_frame=%d, number_of_packets=%d, interval=%d, "
235 "error_count=%d,", 227 "error_count=%d,",
236 urb->start_frame, urb->number_of_packets, urb->interval, 228 urb->start_frame, urb->number_of_packets, urb->interval,
237 urb->error_count); 229 urb->error_count);
238 dbg(level, 230 gig_dbg(level,
239 " context=0x%08lx, complete=0x%08lx, iso_frame_desc[]={", 231 " context=0x%08lx, complete=0x%08lx, "
240 (unsigned long) urb->context, 232 "iso_frame_desc[]={",
241 (unsigned long) urb->complete); 233 (unsigned long) urb->context,
234 (unsigned long) urb->complete);
242 for (i = 0; i < urb->number_of_packets; i++) { 235 for (i = 0; i < urb->number_of_packets; i++) {
243 struct usb_iso_packet_descriptor *pifd = &urb->iso_frame_desc[i]; 236 struct usb_iso_packet_descriptor *pifd
244 dbg(level, 237 = &urb->iso_frame_desc[i];
245 " {offset=%u, length=%u, actual_length=%u, " 238 gig_dbg(level,
246 "status=%u}", 239 " {offset=%u, length=%u, actual_length=%u, "
247 pifd->offset, pifd->length, pifd->actual_length, 240 "status=%u}",
248 pifd->status); 241 pifd->offset, pifd->length, pifd->actual_length,
242 pifd->status);
249 } 243 }
250 } 244 }
251 dbg(level, "}}"); 245 gig_dbg(level, "}}");
252#endif 246#endif
253} 247}
254 248
255/* read/set modem control bits etc. (m10x only) */ 249/* read/set modem control bits etc. (m10x only) */
256static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state, 250static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
257 unsigned new_state) 251 unsigned new_state)
258{ 252{
259 return -EINVAL; 253 return -EINVAL;
260} 254}
@@ -280,8 +274,8 @@ static inline void error_hangup(struct bc_state *bcs)
280{ 274{
281 struct cardstate *cs = bcs->cs; 275 struct cardstate *cs = bcs->cs;
282 276
283 dbg(DEBUG_ANY, 277 gig_dbg(DEBUG_ANY, "%s: scheduling HUP for channel %d",
284 "%s: scheduling HUP for channel %d", __func__, bcs->channel); 278 __func__, bcs->channel);
285 279
286 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) { 280 if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
287 //FIXME what should we do? 281 //FIXME what should we do?
@@ -301,22 +295,19 @@ static inline void error_hangup(struct bc_state *bcs)
301static inline void error_reset(struct cardstate *cs) 295static inline void error_reset(struct cardstate *cs)
302{ 296{
303 //FIXME try to recover without bothering the user 297 //FIXME try to recover without bothering the user
304 err("unrecoverable error - please disconnect the Gigaset base to reset"); 298 dev_err(cs->dev,
299 "unrecoverable error - please disconnect Gigaset base to reset\n");
305} 300}
306 301
307/* check_pending 302/* check_pending
308 * check for completion of pending control request 303 * check for completion of pending control request
309 * parameter: 304 * parameter:
310 * urb USB request block of completed request 305 * ucs hardware specific controller state structure
311 * urb->context = hardware specific controller state structure
312 */ 306 */
313static void check_pending(struct bas_cardstate *ucs) 307static void check_pending(struct bas_cardstate *ucs)
314{ 308{
315 unsigned long flags; 309 unsigned long flags;
316 310
317 IFNULLRET(ucs);
318 IFNULLRET(cardstate);
319
320 spin_lock_irqsave(&ucs->lock, flags); 311 spin_lock_irqsave(&ucs->lock, flags);
321 switch (ucs->pending) { 312 switch (ucs->pending) {
322 case 0: 313 case 0:
@@ -336,8 +327,6 @@ static void check_pending(struct bas_cardstate *ucs)
336 case HD_CLOSE_ATCHANNEL: 327 case HD_CLOSE_ATCHANNEL:
337 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) 328 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN))
338 ucs->pending = 0; 329 ucs->pending = 0;
339 //wake_up_interruptible(cs->initwait);
340 //FIXME need own wait queue?
341 break; 330 break;
342 case HD_CLOSE_B1CHANNEL: 331 case HD_CLOSE_B1CHANNEL:
343 if (!(atomic_read(&ucs->basstate) & BS_B1OPEN)) 332 if (!(atomic_read(&ucs->basstate) & BS_B1OPEN))
@@ -354,7 +343,9 @@ static void check_pending(struct bas_cardstate *ucs)
354 * are handled separately and should never end up here 343 * are handled separately and should never end up here
355 */ 344 */
356 default: 345 default:
357 warn("unknown pending request 0x%02x cleared", ucs->pending); 346 dev_warn(&ucs->interface->dev,
347 "unknown pending request 0x%02x cleared\n",
348 ucs->pending);
358 ucs->pending = 0; 349 ucs->pending = 0;
359 } 350 }
360 351
@@ -372,27 +363,23 @@ static void check_pending(struct bas_cardstate *ucs)
372static void cmd_in_timeout(unsigned long data) 363static void cmd_in_timeout(unsigned long data)
373{ 364{
374 struct cardstate *cs = (struct cardstate *) data; 365 struct cardstate *cs = (struct cardstate *) data;
375 struct bas_cardstate *ucs; 366 struct bas_cardstate *ucs = cs->hw.bas;
376 unsigned long flags; 367 unsigned long flags;
377 368
378 IFNULLRET(cs);
379 ucs = cs->hw.bas;
380 IFNULLRET(ucs);
381
382 spin_lock_irqsave(&cs->lock, flags); 369 spin_lock_irqsave(&cs->lock, flags);
383 if (!atomic_read(&cs->connected)) { 370 if (unlikely(!cs->connected)) {
384 dbg(DEBUG_USBREQ, "%s: disconnected", __func__); 371 gig_dbg(DEBUG_USBREQ, "%s: disconnected", __func__);
385 spin_unlock_irqrestore(&cs->lock, flags); 372 spin_unlock_irqrestore(&cs->lock, flags);
386 return; 373 return;
387 } 374 }
388 if (!ucs->rcvbuf_size) { 375 if (!ucs->rcvbuf_size) {
389 dbg(DEBUG_USBREQ, "%s: no receive in progress", __func__); 376 gig_dbg(DEBUG_USBREQ, "%s: no receive in progress", __func__);
390 spin_unlock_irqrestore(&cs->lock, flags); 377 spin_unlock_irqrestore(&cs->lock, flags);
391 return; 378 return;
392 } 379 }
393 spin_unlock_irqrestore(&cs->lock, flags); 380 spin_unlock_irqrestore(&cs->lock, flags);
394 381
395 err("timeout reading AT response"); 382 dev_err(cs->dev, "timeout reading AT response\n");
396 error_reset(cs); //FIXME retry? 383 error_reset(cs); //FIXME retry?
397} 384}
398 385
@@ -412,18 +399,15 @@ static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs);
412 */ 399 */
413static int atread_submit(struct cardstate *cs, int timeout) 400static int atread_submit(struct cardstate *cs, int timeout)
414{ 401{
415 struct bas_cardstate *ucs; 402 struct bas_cardstate *ucs = cs->hw.bas;
416 int ret; 403 int ret;
417 404
418 IFNULLRETVAL(cs, -EINVAL); 405 gig_dbg(DEBUG_USBREQ, "-------> HD_READ_ATMESSAGE (%d)",
419 ucs = cs->hw.bas; 406 ucs->rcvbuf_size);
420 IFNULLRETVAL(ucs, -EINVAL);
421 IFNULLRETVAL(ucs->urb_cmd_in, -EINVAL);
422
423 dbg(DEBUG_USBREQ, "-------> HD_READ_ATMESSAGE (%d)", ucs->rcvbuf_size);
424 407
425 if (ucs->urb_cmd_in->status == -EINPROGRESS) { 408 if (ucs->urb_cmd_in->status == -EINPROGRESS) {
426 err("could not submit HD_READ_ATMESSAGE: URB busy"); 409 dev_err(cs->dev,
410 "could not submit HD_READ_ATMESSAGE: URB busy\n");
427 return -EBUSY; 411 return -EBUSY;
428 } 412 }
429 413
@@ -433,19 +417,19 @@ static int atread_submit(struct cardstate *cs, int timeout)
433 ucs->dr_cmd_in.wIndex = 0; 417 ucs->dr_cmd_in.wIndex = 0;
434 ucs->dr_cmd_in.wLength = cpu_to_le16(ucs->rcvbuf_size); 418 ucs->dr_cmd_in.wLength = cpu_to_le16(ucs->rcvbuf_size);
435 usb_fill_control_urb(ucs->urb_cmd_in, ucs->udev, 419 usb_fill_control_urb(ucs->urb_cmd_in, ucs->udev,
436 usb_rcvctrlpipe(ucs->udev, 0), 420 usb_rcvctrlpipe(ucs->udev, 0),
437 (unsigned char*) & ucs->dr_cmd_in, 421 (unsigned char*) & ucs->dr_cmd_in,
438 ucs->rcvbuf, ucs->rcvbuf_size, 422 ucs->rcvbuf, ucs->rcvbuf_size,
439 read_ctrl_callback, cs->inbuf); 423 read_ctrl_callback, cs->inbuf);
440 424
441 if ((ret = usb_submit_urb(ucs->urb_cmd_in, SLAB_ATOMIC)) != 0) { 425 if ((ret = usb_submit_urb(ucs->urb_cmd_in, SLAB_ATOMIC)) != 0) {
442 err("could not submit HD_READ_ATMESSAGE: %s", 426 dev_err(cs->dev, "could not submit HD_READ_ATMESSAGE: %s\n",
443 get_usb_statmsg(ret)); 427 get_usb_statmsg(ret));
444 return ret; 428 return ret;
445 } 429 }
446 430
447 if (timeout > 0) { 431 if (timeout > 0) {
448 dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout); 432 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
449 ucs->timer_cmd_in.expires = jiffies + timeout * HZ / 10; 433 ucs->timer_cmd_in.expires = jiffies + timeout * HZ / 10;
450 ucs->timer_cmd_in.data = (unsigned long) cs; 434 ucs->timer_cmd_in.data = (unsigned long) cs;
451 ucs->timer_cmd_in.function = cmd_in_timeout; 435 ucs->timer_cmd_in.function = cmd_in_timeout;
@@ -483,25 +467,14 @@ inline static void update_basstate(struct bas_cardstate *ucs,
483 */ 467 */
484static void read_int_callback(struct urb *urb, struct pt_regs *regs) 468static void read_int_callback(struct urb *urb, struct pt_regs *regs)
485{ 469{
486 struct cardstate *cs; 470 struct cardstate *cs = urb->context;
487 struct bas_cardstate *ucs; 471 struct bas_cardstate *ucs = cs->hw.bas;
488 struct bc_state *bcs; 472 struct bc_state *bcs;
489 unsigned long flags; 473 unsigned long flags;
490 int status; 474 int status;
491 unsigned l; 475 unsigned l;
492 int channel; 476 int channel;
493 477
494 IFNULLRET(urb);
495 cs = (struct cardstate *) urb->context;
496 IFNULLRET(cs);
497 ucs = cs->hw.bas;
498 IFNULLRET(ucs);
499
500 if (unlikely(!atomic_read(&cs->connected))) {
501 warn("%s: disconnected", __func__);
502 return;
503 }
504
505 switch (urb->status) { 478 switch (urb->status) {
506 case 0: /* success */ 479 case 0: /* success */
507 break; 480 break;
@@ -509,11 +482,12 @@ static void read_int_callback(struct urb *urb, struct pt_regs *regs)
509 case -ECONNRESET: /* canceled (async) */ 482 case -ECONNRESET: /* canceled (async) */
510 case -EINPROGRESS: /* pending */ 483 case -EINPROGRESS: /* pending */
511 /* ignore silently */ 484 /* ignore silently */
512 dbg(DEBUG_USBREQ, 485 gig_dbg(DEBUG_USBREQ, "%s: %s",
513 "%s: %s", __func__, get_usb_statmsg(urb->status)); 486 __func__, get_usb_statmsg(urb->status));
514 return; 487 return;
515 default: /* severe trouble */ 488 default: /* severe trouble */
516 warn("interrupt read: %s", get_usb_statmsg(urb->status)); 489 dev_warn(cs->dev, "interrupt read: %s\n",
490 get_usb_statmsg(urb->status));
517 //FIXME corrective action? resubmission always ok? 491 //FIXME corrective action? resubmission always ok?
518 goto resubmit; 492 goto resubmit;
519 } 493 }
@@ -521,10 +495,9 @@ static void read_int_callback(struct urb *urb, struct pt_regs *regs)
521 l = (unsigned) ucs->int_in_buf[1] + 495 l = (unsigned) ucs->int_in_buf[1] +
522 (((unsigned) ucs->int_in_buf[2]) << 8); 496 (((unsigned) ucs->int_in_buf[2]) << 8);
523 497
524 dbg(DEBUG_USBREQ, 498 gig_dbg(DEBUG_USBREQ, "<-------%d: 0x%02x (%u [0x%02x 0x%02x])",
525 "<-------%d: 0x%02x (%u [0x%02x 0x%02x])", urb->actual_length, 499 urb->actual_length, (int)ucs->int_in_buf[0], l,
526 (int)ucs->int_in_buf[0], l, 500 (int)ucs->int_in_buf[1], (int)ucs->int_in_buf[2]);
527 (int)ucs->int_in_buf[1], (int)ucs->int_in_buf[2]);
528 501
529 channel = 0; 502 channel = 0;
530 503
@@ -570,28 +543,30 @@ static void read_int_callback(struct urb *urb, struct pt_regs *regs)
570 case HD_B1_FLOW_CONTROL: 543 case HD_B1_FLOW_CONTROL:
571 bcs = cs->bcs + channel; 544 bcs = cs->bcs + channel;
572 atomic_add((l - BAS_NORMFRAME) * BAS_CORRFRAMES, 545 atomic_add((l - BAS_NORMFRAME) * BAS_CORRFRAMES,
573 &bcs->hw.bas->corrbytes); 546 &bcs->hw.bas->corrbytes);
574 dbg(DEBUG_ISO, 547 gig_dbg(DEBUG_ISO,
575 "Flow control (channel %d, sub %d): 0x%02x => %d", 548 "Flow control (channel %d, sub %d): 0x%02x => %d",
576 channel, bcs->hw.bas->numsub, l, 549 channel, bcs->hw.bas->numsub, l,
577 atomic_read(&bcs->hw.bas->corrbytes)); 550 atomic_read(&bcs->hw.bas->corrbytes));
578 break; 551 break;
579 552
580 case HD_RECEIVEATDATA_ACK: /* AT response ready to be received */ 553 case HD_RECEIVEATDATA_ACK: /* AT response ready to be received */
581 if (!l) { 554 if (!l) {
582 warn("HD_RECEIVEATDATA_ACK with length 0 ignored"); 555 dev_warn(cs->dev,
556 "HD_RECEIVEATDATA_ACK with length 0 ignored\n");
583 break; 557 break;
584 } 558 }
585 spin_lock_irqsave(&cs->lock, flags); 559 spin_lock_irqsave(&cs->lock, flags);
586 if (ucs->rcvbuf_size) { 560 if (ucs->rcvbuf_size) {
587 spin_unlock_irqrestore(&cs->lock, flags); 561 spin_unlock_irqrestore(&cs->lock, flags);
588 err("receive AT data overrun, %d bytes lost", l); 562 dev_err(cs->dev,
563 "receive AT data overrun, %d bytes lost\n", l);
589 error_reset(cs); //FIXME reschedule 564 error_reset(cs); //FIXME reschedule
590 break; 565 break;
591 } 566 }
592 if ((ucs->rcvbuf = kmalloc(l, GFP_ATOMIC)) == NULL) { 567 if ((ucs->rcvbuf = kmalloc(l, GFP_ATOMIC)) == NULL) {
593 spin_unlock_irqrestore(&cs->lock, flags); 568 spin_unlock_irqrestore(&cs->lock, flags);
594 err("%s: out of memory, %d bytes lost", __func__, l); 569 dev_err(cs->dev, "out of memory, %d bytes lost\n", l);
595 error_reset(cs); //FIXME reschedule 570 error_reset(cs); //FIXME reschedule
596 break; 571 break;
597 } 572 }
@@ -607,25 +582,28 @@ static void read_int_callback(struct urb *urb, struct pt_regs *regs)
607 break; 582 break;
608 583
609 case HD_RESET_INTERRUPT_PIPE_ACK: 584 case HD_RESET_INTERRUPT_PIPE_ACK:
610 dbg(DEBUG_USBREQ, "HD_RESET_INTERRUPT_PIPE_ACK"); 585 gig_dbg(DEBUG_USBREQ, "HD_RESET_INTERRUPT_PIPE_ACK");
611 break; 586 break;
612 587
613 case HD_SUSPEND_END: 588 case HD_SUSPEND_END:
614 dbg(DEBUG_USBREQ, "HD_SUSPEND_END"); 589 gig_dbg(DEBUG_USBREQ, "HD_SUSPEND_END");
615 break; 590 break;
616 591
617 default: 592 default:
618 warn("unknown Gigaset signal 0x%02x (%u) ignored", 593 dev_warn(cs->dev,
619 (int) ucs->int_in_buf[0], l); 594 "unknown Gigaset signal 0x%02x (%u) ignored\n",
595 (int) ucs->int_in_buf[0], l);
620 } 596 }
621 597
622 check_pending(ucs); 598 check_pending(ucs);
623 599
624resubmit: 600resubmit:
625 status = usb_submit_urb(urb, SLAB_ATOMIC); 601 spin_lock_irqsave(&cs->lock, flags);
602 status = cs->connected ? usb_submit_urb(urb, SLAB_ATOMIC) : -ENODEV;
603 spin_unlock_irqrestore(&cs->lock, flags);
626 if (unlikely(status)) { 604 if (unlikely(status)) {
627 err("could not resubmit interrupt URB: %s", 605 dev_err(cs->dev, "could not resubmit interrupt URB: %s\n",
628 get_usb_statmsg(status)); 606 get_usb_statmsg(status));
629 error_reset(cs); 607 error_reset(cs);
630 } 608 }
631} 609}
@@ -639,30 +617,22 @@ resubmit:
639 */ 617 */
640static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs) 618static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
641{ 619{
642 struct cardstate *cs; 620 struct inbuf_t *inbuf = urb->context;
643 struct bas_cardstate *ucs; 621 struct cardstate *cs = inbuf->cs;
622 struct bas_cardstate *ucs = cs->hw.bas;
623 int have_data = 0;
644 unsigned numbytes; 624 unsigned numbytes;
645 unsigned long flags; 625 unsigned long flags;
646 struct inbuf_t *inbuf;
647 int have_data = 0;
648
649 IFNULLRET(urb);
650 inbuf = (struct inbuf_t *) urb->context;
651 IFNULLRET(inbuf);
652 cs = inbuf->cs;
653 IFNULLRET(cs);
654 ucs = cs->hw.bas;
655 IFNULLRET(ucs);
656 626
657 spin_lock_irqsave(&cs->lock, flags); 627 spin_lock_irqsave(&cs->lock, flags);
658 if (!atomic_read(&cs->connected)) { 628 if (unlikely(!cs->connected)) {
659 warn("%s: disconnected", __func__); 629 warn("%s: disconnected", __func__);
660 spin_unlock_irqrestore(&cs->lock, flags); 630 spin_unlock_irqrestore(&cs->lock, flags);
661 return; 631 return;
662 } 632 }
663 633
664 if (!ucs->rcvbuf_size) { 634 if (!ucs->rcvbuf_size) {
665 warn("%s: no receive in progress", __func__); 635 dev_warn(cs->dev, "%s: no receive in progress\n", __func__);
666 spin_unlock_irqrestore(&cs->lock, flags); 636 spin_unlock_irqrestore(&cs->lock, flags);
667 return; 637 return;
668 } 638 }
@@ -673,12 +643,14 @@ static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
673 case 0: /* normal completion */ 643 case 0: /* normal completion */
674 numbytes = urb->actual_length; 644 numbytes = urb->actual_length;
675 if (unlikely(numbytes == 0)) { 645 if (unlikely(numbytes == 0)) {
676 warn("control read: empty block received"); 646 dev_warn(cs->dev,
647 "control read: empty block received\n");
677 goto retry; 648 goto retry;
678 } 649 }
679 if (unlikely(numbytes != ucs->rcvbuf_size)) { 650 if (unlikely(numbytes != ucs->rcvbuf_size)) {
680 warn("control read: received %d chars, expected %d", 651 dev_warn(cs->dev,
681 numbytes, ucs->rcvbuf_size); 652 "control read: received %d chars, expected %d\n",
653 numbytes, ucs->rcvbuf_size);
682 if (numbytes > ucs->rcvbuf_size) 654 if (numbytes > ucs->rcvbuf_size)
683 numbytes = ucs->rcvbuf_size; 655 numbytes = ucs->rcvbuf_size;
684 } 656 }
@@ -698,23 +670,26 @@ static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
698 case -ECONNRESET: /* canceled (async) */ 670 case -ECONNRESET: /* canceled (async) */
699 case -EINPROGRESS: /* pending */ 671 case -EINPROGRESS: /* pending */
700 /* no action necessary */ 672 /* no action necessary */
701 dbg(DEBUG_USBREQ, 673 gig_dbg(DEBUG_USBREQ, "%s: %s",
702 "%s: %s", __func__, get_usb_statmsg(urb->status)); 674 __func__, get_usb_statmsg(urb->status));
703 break; 675 break;
704 676
705 default: /* severe trouble */ 677 default: /* severe trouble */
706 warn("control read: %s", get_usb_statmsg(urb->status)); 678 dev_warn(cs->dev, "control read: %s\n",
679 get_usb_statmsg(urb->status));
707 retry: 680 retry:
708 if (ucs->retry_cmd_in++ < BAS_RETRY) { 681 if (ucs->retry_cmd_in++ < BAS_RETRY) {
709 notice("control read: retry %d", ucs->retry_cmd_in); 682 dev_notice(cs->dev, "control read: retry %d\n",
683 ucs->retry_cmd_in);
710 if (atread_submit(cs, BAS_TIMEOUT) >= 0) { 684 if (atread_submit(cs, BAS_TIMEOUT) >= 0) {
711 /* resubmitted - bypass regular exit block */ 685 /* resubmitted - bypass regular exit block */
712 spin_unlock_irqrestore(&cs->lock, flags); 686 spin_unlock_irqrestore(&cs->lock, flags);
713 return; 687 return;
714 } 688 }
715 } else { 689 } else {
716 err("control read: giving up after %d tries", 690 dev_err(cs->dev,
717 ucs->retry_cmd_in); 691 "control read: giving up after %d tries\n",
692 ucs->retry_cmd_in);
718 } 693 }
719 error_reset(cs); 694 error_reset(cs);
720 } 695 }
@@ -724,7 +699,7 @@ static void read_ctrl_callback(struct urb *urb, struct pt_regs *regs)
724 ucs->rcvbuf_size = 0; 699 ucs->rcvbuf_size = 0;
725 spin_unlock_irqrestore(&cs->lock, flags); 700 spin_unlock_irqrestore(&cs->lock, flags);
726 if (have_data) { 701 if (have_data) {
727 dbg(DEBUG_INTR, "%s-->BH", __func__); 702 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
728 gigaset_schedule_event(cs); 703 gigaset_schedule_event(cs);
729 } 704 }
730} 705}
@@ -743,21 +718,16 @@ static void read_iso_callback(struct urb *urb, struct pt_regs *regs)
743 unsigned long flags; 718 unsigned long flags;
744 int i, rc; 719 int i, rc;
745 720
746 IFNULLRET(urb);
747 IFNULLRET(urb->context);
748 IFNULLRET(cardstate);
749
750 /* status codes not worth bothering the tasklet with */ 721 /* status codes not worth bothering the tasklet with */
751 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET || 722 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET ||
752 urb->status == -EINPROGRESS)) { 723 urb->status == -EINPROGRESS)) {
753 dbg(DEBUG_ISO, 724 gig_dbg(DEBUG_ISO, "%s: %s",
754 "%s: %s", __func__, get_usb_statmsg(urb->status)); 725 __func__, get_usb_statmsg(urb->status));
755 return; 726 return;
756 } 727 }
757 728
758 bcs = (struct bc_state *) urb->context; 729 bcs = urb->context;
759 ubc = bcs->hw.bas; 730 ubc = bcs->hw.bas;
760 IFNULLRET(ubc);
761 731
762 spin_lock_irqsave(&ubc->isoinlock, flags); 732 spin_lock_irqsave(&ubc->isoinlock, flags);
763 if (likely(ubc->isoindone == NULL)) { 733 if (likely(ubc->isoindone == NULL)) {
@@ -777,14 +747,17 @@ static void read_iso_callback(struct urb *urb, struct pt_regs *regs)
777 urb->iso_frame_desc[i].actual_length = 0; 747 urb->iso_frame_desc[i].actual_length = 0;
778 } 748 }
779 if (likely(atomic_read(&ubc->running))) { 749 if (likely(atomic_read(&ubc->running))) {
780 urb->dev = bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */ 750 /* urb->dev is clobbered by USB subsystem */
751 urb->dev = bcs->cs->hw.bas->udev;
781 urb->transfer_flags = URB_ISO_ASAP; 752 urb->transfer_flags = URB_ISO_ASAP;
782 urb->number_of_packets = BAS_NUMFRAMES; 753 urb->number_of_packets = BAS_NUMFRAMES;
783 dbg(DEBUG_ISO, "%s: isoc read overrun/resubmit", __func__); 754 gig_dbg(DEBUG_ISO, "%s: isoc read overrun/resubmit",
755 __func__);
784 rc = usb_submit_urb(urb, SLAB_ATOMIC); 756 rc = usb_submit_urb(urb, SLAB_ATOMIC);
785 if (unlikely(rc != 0)) { 757 if (unlikely(rc != 0)) {
786 err("could not resubmit isochronous read URB: %s", 758 dev_err(bcs->cs->dev,
787 get_usb_statmsg(rc)); 759 "could not resubmit isochronous read "
760 "URB: %s\n", get_usb_statmsg(rc));
788 dump_urb(DEBUG_ISO, "isoc read", urb); 761 dump_urb(DEBUG_ISO, "isoc read", urb);
789 error_hangup(bcs); 762 error_hangup(bcs);
790 } 763 }
@@ -806,23 +779,17 @@ static void write_iso_callback(struct urb *urb, struct pt_regs *regs)
806 struct bas_bc_state *ubc; 779 struct bas_bc_state *ubc;
807 unsigned long flags; 780 unsigned long flags;
808 781
809 IFNULLRET(urb);
810 IFNULLRET(urb->context);
811 IFNULLRET(cardstate);
812
813 /* status codes not worth bothering the tasklet with */ 782 /* status codes not worth bothering the tasklet with */
814 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET || 783 if (unlikely(urb->status == -ENOENT || urb->status == -ECONNRESET ||
815 urb->status == -EINPROGRESS)) { 784 urb->status == -EINPROGRESS)) {
816 dbg(DEBUG_ISO, 785 gig_dbg(DEBUG_ISO, "%s: %s",
817 "%s: %s", __func__, get_usb_statmsg(urb->status)); 786 __func__, get_usb_statmsg(urb->status));
818 return; 787 return;
819 } 788 }
820 789
821 /* pass URB context to tasklet */ 790 /* pass URB context to tasklet */
822 ucx = (struct isow_urbctx_t *) urb->context; 791 ucx = urb->context;
823 IFNULLRET(ucx->bcs);
824 ubc = ucx->bcs->hw.bas; 792 ubc = ucx->bcs->hw.bas;
825 IFNULLRET(ubc);
826 793
827 spin_lock_irqsave(&ubc->isooutlock, flags); 794 spin_lock_irqsave(&ubc->isooutlock, flags);
828 ubc->isooutovfl = ubc->isooutdone; 795 ubc->isooutovfl = ubc->isooutdone;
@@ -841,15 +808,11 @@ static void write_iso_callback(struct urb *urb, struct pt_regs *regs)
841 */ 808 */
842static int starturbs(struct bc_state *bcs) 809static int starturbs(struct bc_state *bcs)
843{ 810{
811 struct bas_bc_state *ubc = bcs->hw.bas;
844 struct urb *urb; 812 struct urb *urb;
845 struct bas_bc_state *ubc;
846 int j, k; 813 int j, k;
847 int rc; 814 int rc;
848 815
849 IFNULLRETVAL(bcs, -EFAULT);
850 ubc = bcs->hw.bas;
851 IFNULLRETVAL(ubc, -EFAULT);
852
853 /* initialize L2 reception */ 816 /* initialize L2 reception */
854 if (bcs->proto2 == ISDN_PROTO_L2_HDLC) 817 if (bcs->proto2 == ISDN_PROTO_L2_HDLC)
855 bcs->inputstate |= INS_flag_hunt; 818 bcs->inputstate |= INS_flag_hunt;
@@ -859,7 +822,7 @@ static int starturbs(struct bc_state *bcs)
859 for (k = 0; k < BAS_INURBS; k++) { 822 for (k = 0; k < BAS_INURBS; k++) {
860 urb = ubc->isoinurbs[k]; 823 urb = ubc->isoinurbs[k];
861 if (!urb) { 824 if (!urb) {
862 err("isoinurbs[%d]==NULL", k); 825 dev_err(bcs->cs->dev, "isoinurbs[%d]==NULL\n", k);
863 rc = -EFAULT; 826 rc = -EFAULT;
864 goto error; 827 goto error;
865 } 828 }
@@ -882,8 +845,9 @@ static int starturbs(struct bc_state *bcs)
882 845
883 dump_urb(DEBUG_ISO, "Initial isoc read", urb); 846 dump_urb(DEBUG_ISO, "Initial isoc read", urb);
884 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) { 847 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) {
885 err("could not submit isochronous read URB %d: %s", 848 dev_err(bcs->cs->dev,
886 k, get_usb_statmsg(rc)); 849 "could not submit isochronous read URB %d: %s\n",
850 k, get_usb_statmsg(rc));
887 goto error; 851 goto error;
888 } 852 }
889 } 853 }
@@ -895,7 +859,7 @@ static int starturbs(struct bc_state *bcs)
895 for (k = 0; k < BAS_OUTURBS; ++k) { 859 for (k = 0; k < BAS_OUTURBS; ++k) {
896 urb = ubc->isoouturbs[k].urb; 860 urb = ubc->isoouturbs[k].urb;
897 if (!urb) { 861 if (!urb) {
898 err("isoouturbs[%d].urb==NULL", k); 862 dev_err(bcs->cs->dev, "isoouturbs[%d].urb==NULL\n", k);
899 rc = -EFAULT; 863 rc = -EFAULT;
900 goto error; 864 goto error;
901 } 865 }
@@ -922,8 +886,9 @@ static int starturbs(struct bc_state *bcs)
922 dump_urb(DEBUG_ISO, "Initial isoc write", urb); 886 dump_urb(DEBUG_ISO, "Initial isoc write", urb);
923 rc = usb_submit_urb(ubc->isoouturbs[k].urb, SLAB_ATOMIC); 887 rc = usb_submit_urb(ubc->isoouturbs[k].urb, SLAB_ATOMIC);
924 if (rc != 0) { 888 if (rc != 0) {
925 err("could not submit isochronous write URB %d: %s", 889 dev_err(bcs->cs->dev,
926 k, get_usb_statmsg(rc)); 890 "could not submit isochronous write URB %d: %s\n",
891 k, get_usb_statmsg(rc));
927 goto error; 892 goto error;
928 } 893 }
929 } 894 }
@@ -946,20 +911,20 @@ static void stopurbs(struct bas_bc_state *ubc)
946{ 911{
947 int k, rc; 912 int k, rc;
948 913
949 IFNULLRET(ubc);
950
951 atomic_set(&ubc->running, 0); 914 atomic_set(&ubc->running, 0);
952 915
953 for (k = 0; k < BAS_INURBS; ++k) { 916 for (k = 0; k < BAS_INURBS; ++k) {
954 rc = usb_unlink_urb(ubc->isoinurbs[k]); 917 rc = usb_unlink_urb(ubc->isoinurbs[k]);
955 dbg(DEBUG_ISO, "%s: isoc input URB %d unlinked, result = %d", 918 gig_dbg(DEBUG_ISO,
956 __func__, k, rc); 919 "%s: isoc input URB %d unlinked, result = %d",
920 __func__, k, rc);
957 } 921 }
958 922
959 for (k = 0; k < BAS_OUTURBS; ++k) { 923 for (k = 0; k < BAS_OUTURBS; ++k) {
960 rc = usb_unlink_urb(ubc->isoouturbs[k].urb); 924 rc = usb_unlink_urb(ubc->isoouturbs[k].urb);
961 dbg(DEBUG_ISO, "%s: isoc output URB %d unlinked, result = %d", 925 gig_dbg(DEBUG_ISO,
962 __func__, k, rc); 926 "%s: isoc output URB %d unlinked, result = %d",
927 __func__, k, rc);
963 } 928 }
964} 929}
965 930
@@ -977,19 +942,14 @@ static void stopurbs(struct bas_bc_state *ubc)
977 */ 942 */
978static int submit_iso_write_urb(struct isow_urbctx_t *ucx) 943static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
979{ 944{
980 struct urb *urb; 945 struct urb *urb = ucx->urb;
981 struct bas_bc_state *ubc; 946 struct bas_bc_state *ubc = ucx->bcs->hw.bas;
982 struct usb_iso_packet_descriptor *ifd; 947 struct usb_iso_packet_descriptor *ifd;
983 int corrbytes, nframe, rc; 948 int corrbytes, nframe, rc;
949 unsigned long flags;
984 950
985 IFNULLRETVAL(ucx, -EFAULT); 951 /* urb->dev is clobbered by USB subsystem */
986 urb = ucx->urb; 952 urb->dev = ucx->bcs->cs->hw.bas->udev;
987 IFNULLRETVAL(urb, -EFAULT);
988 IFNULLRETVAL(ucx->bcs, -EFAULT);
989 ubc = ucx->bcs->hw.bas;
990 IFNULLRETVAL(ubc, -EFAULT);
991
992 urb->dev = ucx->bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */
993 urb->transfer_flags = URB_ISO_ASAP; 953 urb->transfer_flags = URB_ISO_ASAP;
994 urb->transfer_buffer = ubc->isooutbuf->data; 954 urb->transfer_buffer = ubc->isooutbuf->data;
995 urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data); 955 urb->transfer_buffer_length = sizeof(ubc->isooutbuf->data);
@@ -1000,7 +960,8 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1000 /* compute frame length according to flow control */ 960 /* compute frame length according to flow control */
1001 ifd->length = BAS_NORMFRAME; 961 ifd->length = BAS_NORMFRAME;
1002 if ((corrbytes = atomic_read(&ubc->corrbytes)) != 0) { 962 if ((corrbytes = atomic_read(&ubc->corrbytes)) != 0) {
1003 dbg(DEBUG_ISO, "%s: corrbytes=%d", __func__, corrbytes); 963 gig_dbg(DEBUG_ISO, "%s: corrbytes=%d",
964 __func__, corrbytes);
1004 if (corrbytes > BAS_HIGHFRAME - BAS_NORMFRAME) 965 if (corrbytes > BAS_HIGHFRAME - BAS_NORMFRAME)
1005 corrbytes = BAS_HIGHFRAME - BAS_NORMFRAME; 966 corrbytes = BAS_HIGHFRAME - BAS_NORMFRAME;
1006 else if (corrbytes < BAS_LOWFRAME - BAS_NORMFRAME) 967 else if (corrbytes < BAS_LOWFRAME - BAS_NORMFRAME)
@@ -1008,18 +969,21 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1008 ifd->length += corrbytes; 969 ifd->length += corrbytes;
1009 atomic_add(-corrbytes, &ubc->corrbytes); 970 atomic_add(-corrbytes, &ubc->corrbytes);
1010 } 971 }
1011 //dbg(DEBUG_ISO, "%s: frame %d length=%d", __func__, nframe, ifd->length);
1012 972
1013 /* retrieve block of data to send */ 973 /* retrieve block of data to send */
1014 ifd->offset = gigaset_isowbuf_getbytes(ubc->isooutbuf, ifd->length); 974 ifd->offset = gigaset_isowbuf_getbytes(ubc->isooutbuf,
975 ifd->length);
1015 if (ifd->offset < 0) { 976 if (ifd->offset < 0) {
1016 if (ifd->offset == -EBUSY) { 977 if (ifd->offset == -EBUSY) {
1017 dbg(DEBUG_ISO, "%s: buffer busy at frame %d", 978 gig_dbg(DEBUG_ISO,
1018 __func__, nframe); 979 "%s: buffer busy at frame %d",
1019 /* tasklet will be restarted from gigaset_send_skb() */ 980 __func__, nframe);
981 /* tasklet will be restarted from
982 gigaset_send_skb() */
1020 } else { 983 } else {
1021 err("%s: buffer error %d at frame %d", 984 dev_err(ucx->bcs->cs->dev,
1022 __func__, ifd->offset, nframe); 985 "%s: buffer error %d at frame %d\n",
986 __func__, ifd->offset, nframe);
1023 return ifd->offset; 987 return ifd->offset;
1024 } 988 }
1025 break; 989 break;
@@ -1029,9 +993,14 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1029 ifd->actual_length = 0; 993 ifd->actual_length = 0;
1030 } 994 }
1031 if ((urb->number_of_packets = nframe) > 0) { 995 if ((urb->number_of_packets = nframe) > 0) {
1032 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) { 996 spin_lock_irqsave(&ucx->bcs->cs->lock, flags);
1033 err("could not submit isochronous write URB: %s", 997 rc = ucx->bcs->cs->connected ? usb_submit_urb(urb, SLAB_ATOMIC) : -ENODEV;
1034 get_usb_statmsg(rc)); 998 spin_unlock_irqrestore(&ucx->bcs->cs->lock, flags);
999
1000 if (rc) {
1001 dev_err(ucx->bcs->cs->dev,
1002 "could not submit isochronous write URB: %s\n",
1003 get_usb_statmsg(rc));
1035 dump_urb(DEBUG_ISO, "isoc write", urb); 1004 dump_urb(DEBUG_ISO, "isoc write", urb);
1036 return rc; 1005 return rc;
1037 } 1006 }
@@ -1048,9 +1017,9 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1048 */ 1017 */
1049static void write_iso_tasklet(unsigned long data) 1018static void write_iso_tasklet(unsigned long data)
1050{ 1019{
1051 struct bc_state *bcs; 1020 struct bc_state *bcs = (struct bc_state *) data;
1052 struct bas_bc_state *ubc; 1021 struct bas_bc_state *ubc = bcs->hw.bas;
1053 struct cardstate *cs; 1022 struct cardstate *cs = bcs->cs;
1054 struct isow_urbctx_t *done, *next, *ovfl; 1023 struct isow_urbctx_t *done, *next, *ovfl;
1055 struct urb *urb; 1024 struct urb *urb;
1056 struct usb_iso_packet_descriptor *ifd; 1025 struct usb_iso_packet_descriptor *ifd;
@@ -1060,22 +1029,10 @@ static void write_iso_tasklet(unsigned long data)
1060 struct sk_buff *skb; 1029 struct sk_buff *skb;
1061 int len; 1030 int len;
1062 1031
1063 bcs = (struct bc_state *) data;
1064 IFNULLRET(bcs);
1065 ubc = bcs->hw.bas;
1066 IFNULLRET(ubc);
1067 cs = bcs->cs;
1068 IFNULLRET(cs);
1069
1070 /* loop while completed URBs arrive in time */ 1032 /* loop while completed URBs arrive in time */
1071 for (;;) { 1033 for (;;) {
1072 if (unlikely(!atomic_read(&cs->connected))) {
1073 warn("%s: disconnected", __func__);
1074 return;
1075 }
1076
1077 if (unlikely(!(atomic_read(&ubc->running)))) { 1034 if (unlikely(!(atomic_read(&ubc->running)))) {
1078 dbg(DEBUG_ISO, "%s: not running", __func__); 1035 gig_dbg(DEBUG_ISO, "%s: not running", __func__);
1079 return; 1036 return;
1080 } 1037 }
1081 1038
@@ -1087,7 +1044,7 @@ static void write_iso_tasklet(unsigned long data)
1087 ubc->isooutovfl = NULL; 1044 ubc->isooutovfl = NULL;
1088 spin_unlock_irqrestore(&ubc->isooutlock, flags); 1045 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1089 if (ovfl) { 1046 if (ovfl) {
1090 err("isochronous write buffer underrun - buy a faster machine :-)"); 1047 dev_err(cs->dev, "isochronous write buffer underrun\n");
1091 error_hangup(bcs); 1048 error_hangup(bcs);
1092 break; 1049 break;
1093 } 1050 }
@@ -1110,7 +1067,8 @@ static void write_iso_tasklet(unsigned long data)
1110 spin_unlock_irqrestore(&ubc->isooutlock, flags); 1067 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1111 if (next) { 1068 if (next) {
1112 /* couldn't put it back */ 1069 /* couldn't put it back */
1113 err("losing isochronous write URB"); 1070 dev_err(cs->dev,
1071 "losing isochronous write URB\n");
1114 error_hangup(bcs); 1072 error_hangup(bcs);
1115 } 1073 }
1116 } 1074 }
@@ -1123,22 +1081,25 @@ static void write_iso_tasklet(unsigned long data)
1123 break; 1081 break;
1124 case -EXDEV: /* inspect individual frames */ 1082 case -EXDEV: /* inspect individual frames */
1125 /* assumptions (for lack of documentation): 1083 /* assumptions (for lack of documentation):
1126 * - actual_length bytes of the frame in error are successfully sent 1084 * - actual_length bytes of the frame in error are
1085 * successfully sent
1127 * - all following frames are not sent at all 1086 * - all following frames are not sent at all
1128 */ 1087 */
1129 dbg(DEBUG_ISO, "%s: URB partially completed", __func__); 1088 gig_dbg(DEBUG_ISO, "%s: URB partially completed",
1089 __func__);
1130 offset = done->limit; /* just in case */ 1090 offset = done->limit; /* just in case */
1131 for (i = 0; i < BAS_NUMFRAMES; i++) { 1091 for (i = 0; i < BAS_NUMFRAMES; i++) {
1132 ifd = &urb->iso_frame_desc[i]; 1092 ifd = &urb->iso_frame_desc[i];
1133 if (ifd->status || 1093 if (ifd->status ||
1134 ifd->actual_length != ifd->length) { 1094 ifd->actual_length != ifd->length) {
1135 warn("isochronous write: frame %d: %s, " 1095 dev_warn(cs->dev,
1136 "only %d of %d bytes sent", 1096 "isochronous write: frame %d: %s, "
1097 "only %d of %d bytes sent\n",
1137 i, get_usb_statmsg(ifd->status), 1098 i, get_usb_statmsg(ifd->status),
1138 ifd->actual_length, ifd->length); 1099 ifd->actual_length, ifd->length);
1139 offset = (ifd->offset + 1100 offset = (ifd->offset +
1140 ifd->actual_length) 1101 ifd->actual_length)
1141 % BAS_OUTBUFSIZE; 1102 % BAS_OUTBUFSIZE;
1142 break; 1103 break;
1143 } 1104 }
1144 } 1105 }
@@ -1148,25 +1109,26 @@ static void write_iso_tasklet(unsigned long data)
1148 ifd = &urb->iso_frame_desc[i]; 1109 ifd = &urb->iso_frame_desc[i];
1149 if (ifd->status != -EINPROGRESS 1110 if (ifd->status != -EINPROGRESS
1150 || ifd->actual_length != 0) { 1111 || ifd->actual_length != 0) {
1151 warn("isochronous write: frame %d: %s, " 1112 dev_warn(cs->dev,
1152 "%d of %d bytes sent", 1113 "isochronous write: frame %d: %s, "
1114 "%d of %d bytes sent\n",
1153 i, get_usb_statmsg(ifd->status), 1115 i, get_usb_statmsg(ifd->status),
1154 ifd->actual_length, ifd->length); 1116 ifd->actual_length, ifd->length);
1155 offset = (ifd->offset + 1117 offset = (ifd->offset +
1156 ifd->actual_length) 1118 ifd->actual_length)
1157 % BAS_OUTBUFSIZE; 1119 % BAS_OUTBUFSIZE;
1158 break; 1120 break;
1159 } 1121 }
1160 } 1122 }
1161#endif 1123#endif
1162 break; 1124 break;
1163 case -EPIPE: //FIXME is this the code for "underrun"? 1125 case -EPIPE: //FIXME is this the code for "underrun"?
1164 err("isochronous write stalled"); 1126 dev_err(cs->dev, "isochronous write stalled\n");
1165 error_hangup(bcs); 1127 error_hangup(bcs);
1166 break; 1128 break;
1167 default: /* severe trouble */ 1129 default: /* severe trouble */
1168 warn("isochronous write: %s", 1130 dev_warn(cs->dev, "isochronous write: %s\n",
1169 get_usb_statmsg(urb->status)); 1131 get_usb_statmsg(urb->status));
1170 } 1132 }
1171 1133
1172 /* mark the write buffer area covered by this URB as free */ 1134 /* mark the write buffer area covered by this URB as free */
@@ -1194,8 +1156,8 @@ static void write_iso_tasklet(unsigned long data)
1194 if (gigaset_isoc_buildframe(bcs, skb->data, len) == -EAGAIN) { 1156 if (gigaset_isoc_buildframe(bcs, skb->data, len) == -EAGAIN) {
1195 /* insufficient buffer space, push back onto queue */ 1157 /* insufficient buffer space, push back onto queue */
1196 skb_queue_head(&bcs->squeue, skb); 1158 skb_queue_head(&bcs->squeue, skb);
1197 dbg(DEBUG_ISO, "%s: skb requeued, qlen=%d", 1159 gig_dbg(DEBUG_ISO, "%s: skb requeued, qlen=%d",
1198 __func__, skb_queue_len(&bcs->squeue)); 1160 __func__, skb_queue_len(&bcs->squeue));
1199 break; 1161 break;
1200 } 1162 }
1201 skb_pull(skb, len); 1163 skb_pull(skb, len);
@@ -1215,28 +1177,16 @@ static void write_iso_tasklet(unsigned long data)
1215 */ 1177 */
1216static void read_iso_tasklet(unsigned long data) 1178static void read_iso_tasklet(unsigned long data)
1217{ 1179{
1218 struct bc_state *bcs; 1180 struct bc_state *bcs = (struct bc_state *) data;
1219 struct bas_bc_state *ubc; 1181 struct bas_bc_state *ubc = bcs->hw.bas;
1220 struct cardstate *cs; 1182 struct cardstate *cs = bcs->cs;
1221 struct urb *urb; 1183 struct urb *urb;
1222 char *rcvbuf; 1184 char *rcvbuf;
1223 unsigned long flags; 1185 unsigned long flags;
1224 int totleft, numbytes, offset, frame, rc; 1186 int totleft, numbytes, offset, frame, rc;
1225 1187
1226 bcs = (struct bc_state *) data;
1227 IFNULLRET(bcs);
1228 ubc = bcs->hw.bas;
1229 IFNULLRET(ubc);
1230 cs = bcs->cs;
1231 IFNULLRET(cs);
1232
1233 /* loop while more completed URBs arrive in the meantime */ 1188 /* loop while more completed URBs arrive in the meantime */
1234 for (;;) { 1189 for (;;) {
1235 if (!atomic_read(&cs->connected)) {
1236 warn("%s: disconnected", __func__);
1237 return;
1238 }
1239
1240 /* retrieve URB */ 1190 /* retrieve URB */
1241 spin_lock_irqsave(&ubc->isoinlock, flags); 1191 spin_lock_irqsave(&ubc->isoinlock, flags);
1242 if (!(urb = ubc->isoindone)) { 1192 if (!(urb = ubc->isoindone)) {
@@ -1245,38 +1195,45 @@ static void read_iso_tasklet(unsigned long data)
1245 } 1195 }
1246 ubc->isoindone = NULL; 1196 ubc->isoindone = NULL;
1247 if (unlikely(ubc->loststatus != -EINPROGRESS)) { 1197 if (unlikely(ubc->loststatus != -EINPROGRESS)) {
1248 warn("isochronous read overrun, dropped URB with status: %s, %d bytes lost", 1198 dev_warn(cs->dev,
1249 get_usb_statmsg(ubc->loststatus), ubc->isoinlost); 1199 "isochronous read overrun, "
1200 "dropped URB with status: %s, %d bytes lost\n",
1201 get_usb_statmsg(ubc->loststatus),
1202 ubc->isoinlost);
1250 ubc->loststatus = -EINPROGRESS; 1203 ubc->loststatus = -EINPROGRESS;
1251 } 1204 }
1252 spin_unlock_irqrestore(&ubc->isoinlock, flags); 1205 spin_unlock_irqrestore(&ubc->isoinlock, flags);
1253 1206
1254 if (unlikely(!(atomic_read(&ubc->running)))) { 1207 if (unlikely(!(atomic_read(&ubc->running)))) {
1255 dbg(DEBUG_ISO, "%s: channel not running, dropped URB with status: %s", 1208 gig_dbg(DEBUG_ISO,
1256 __func__, get_usb_statmsg(urb->status)); 1209 "%s: channel not running, "
1210 "dropped URB with status: %s",
1211 __func__, get_usb_statmsg(urb->status));
1257 return; 1212 return;
1258 } 1213 }
1259 1214
1260 switch (urb->status) { 1215 switch (urb->status) {
1261 case 0: /* normal completion */ 1216 case 0: /* normal completion */
1262 break; 1217 break;
1263 case -EXDEV: /* inspect individual frames (we do that anyway) */ 1218 case -EXDEV: /* inspect individual frames
1264 dbg(DEBUG_ISO, "%s: URB partially completed", __func__); 1219 (we do that anyway) */
1220 gig_dbg(DEBUG_ISO, "%s: URB partially completed",
1221 __func__);
1265 break; 1222 break;
1266 case -ENOENT: 1223 case -ENOENT:
1267 case -ECONNRESET: 1224 case -ECONNRESET:
1268 dbg(DEBUG_ISO, "%s: URB canceled", __func__); 1225 gig_dbg(DEBUG_ISO, "%s: URB canceled", __func__);
1269 continue; /* -> skip */ 1226 continue; /* -> skip */
1270 case -EINPROGRESS: /* huh? */ 1227 case -EINPROGRESS: /* huh? */
1271 dbg(DEBUG_ISO, "%s: URB still pending", __func__); 1228 gig_dbg(DEBUG_ISO, "%s: URB still pending", __func__);
1272 continue; /* -> skip */ 1229 continue; /* -> skip */
1273 case -EPIPE: 1230 case -EPIPE:
1274 err("isochronous read stalled"); 1231 dev_err(cs->dev, "isochronous read stalled\n");
1275 error_hangup(bcs); 1232 error_hangup(bcs);
1276 continue; /* -> skip */ 1233 continue; /* -> skip */
1277 default: /* severe trouble */ 1234 default: /* severe trouble */
1278 warn("isochronous read: %s", 1235 dev_warn(cs->dev, "isochronous read: %s\n",
1279 get_usb_statmsg(urb->status)); 1236 get_usb_statmsg(urb->status));
1280 goto error; 1237 goto error;
1281 } 1238 }
1282 1239
@@ -1284,33 +1241,44 @@ static void read_iso_tasklet(unsigned long data)
1284 totleft = urb->actual_length; 1241 totleft = urb->actual_length;
1285 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) { 1242 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) {
1286 if (unlikely(urb->iso_frame_desc[frame].status)) { 1243 if (unlikely(urb->iso_frame_desc[frame].status)) {
1287 warn("isochronous read: frame %d: %s", 1244 dev_warn(cs->dev,
1288 frame, get_usb_statmsg(urb->iso_frame_desc[frame].status)); 1245 "isochronous read: frame %d: %s\n",
1246 frame,
1247 get_usb_statmsg(
1248 urb->iso_frame_desc[frame].status));
1289 break; 1249 break;
1290 } 1250 }
1291 numbytes = urb->iso_frame_desc[frame].actual_length; 1251 numbytes = urb->iso_frame_desc[frame].actual_length;
1292 if (unlikely(numbytes > BAS_MAXFRAME)) { 1252 if (unlikely(numbytes > BAS_MAXFRAME)) {
1293 warn("isochronous read: frame %d: numbytes (%d) > BAS_MAXFRAME", 1253 dev_warn(cs->dev,
1294 frame, numbytes); 1254 "isochronous read: frame %d: "
1255 "numbytes (%d) > BAS_MAXFRAME\n",
1256 frame, numbytes);
1295 break; 1257 break;
1296 } 1258 }
1297 if (unlikely(numbytes > totleft)) { 1259 if (unlikely(numbytes > totleft)) {
1298 warn("isochronous read: frame %d: numbytes (%d) > totleft (%d)", 1260 dev_warn(cs->dev,
1299 frame, numbytes, totleft); 1261 "isochronous read: frame %d: "
1262 "numbytes (%d) > totleft (%d)\n",
1263 frame, numbytes, totleft);
1300 break; 1264 break;
1301 } 1265 }
1302 offset = urb->iso_frame_desc[frame].offset; 1266 offset = urb->iso_frame_desc[frame].offset;
1303 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) { 1267 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) {
1304 warn("isochronous read: frame %d: offset (%d) + numbytes (%d) > BAS_INBUFSIZE", 1268 dev_warn(cs->dev,
1305 frame, offset, numbytes); 1269 "isochronous read: frame %d: "
1270 "offset (%d) + numbytes (%d) "
1271 "> BAS_INBUFSIZE\n",
1272 frame, offset, numbytes);
1306 break; 1273 break;
1307 } 1274 }
1308 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs); 1275 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs);
1309 totleft -= numbytes; 1276 totleft -= numbytes;
1310 } 1277 }
1311 if (unlikely(totleft > 0)) 1278 if (unlikely(totleft > 0))
1312 warn("isochronous read: %d data bytes missing", 1279 dev_warn(cs->dev,
1313 totleft); 1280 "isochronous read: %d data bytes missing\n",
1281 totleft);
1314 1282
1315 error: 1283 error:
1316 /* URB processed, resubmit */ 1284 /* URB processed, resubmit */
@@ -1318,12 +1286,17 @@ static void read_iso_tasklet(unsigned long data)
1318 urb->iso_frame_desc[frame].status = 0; 1286 urb->iso_frame_desc[frame].status = 0;
1319 urb->iso_frame_desc[frame].actual_length = 0; 1287 urb->iso_frame_desc[frame].actual_length = 0;
1320 } 1288 }
1321 urb->dev = bcs->cs->hw.bas->udev; /* clobbered by USB subsystem */ 1289 /* urb->dev is clobbered by USB subsystem */
1290 urb->dev = bcs->cs->hw.bas->udev;
1322 urb->transfer_flags = URB_ISO_ASAP; 1291 urb->transfer_flags = URB_ISO_ASAP;
1323 urb->number_of_packets = BAS_NUMFRAMES; 1292 urb->number_of_packets = BAS_NUMFRAMES;
1324 if ((rc = usb_submit_urb(urb, SLAB_ATOMIC)) != 0) { 1293 spin_lock_irqsave(&cs->lock, flags);
1325 err("could not resubmit isochronous read URB: %s", 1294 rc = cs->connected ? usb_submit_urb(urb, SLAB_ATOMIC) : -ENODEV;
1326 get_usb_statmsg(rc)); 1295 spin_unlock_irqrestore(&cs->lock, flags);
1296 if (rc) {
1297 dev_err(cs->dev,
1298 "could not resubmit isochronous read URB: %s\n",
1299 get_usb_statmsg(rc));
1327 dump_urb(DEBUG_ISO, "resubmit iso read", urb); 1300 dump_urb(DEBUG_ISO, "resubmit iso read", urb);
1328 error_hangup(bcs); 1301 error_hangup(bcs);
1329 } 1302 }
@@ -1341,15 +1314,10 @@ static void read_iso_tasklet(unsigned long data)
1341static void req_timeout(unsigned long data) 1314static void req_timeout(unsigned long data)
1342{ 1315{
1343 struct bc_state *bcs = (struct bc_state *) data; 1316 struct bc_state *bcs = (struct bc_state *) data;
1344 struct bas_cardstate *ucs; 1317 struct bas_cardstate *ucs = bcs->cs->hw.bas;
1345 int pending; 1318 int pending;
1346 unsigned long flags; 1319 unsigned long flags;
1347 1320
1348 IFNULLRET(bcs);
1349 IFNULLRET(bcs->cs);
1350 ucs = bcs->cs->hw.bas;
1351 IFNULLRET(ucs);
1352
1353 check_pending(ucs); 1321 check_pending(ucs);
1354 1322
1355 spin_lock_irqsave(&ucs->lock, flags); 1323 spin_lock_irqsave(&ucs->lock, flags);
@@ -1359,33 +1327,34 @@ static void req_timeout(unsigned long data)
1359 1327
1360 switch (pending) { 1328 switch (pending) {
1361 case 0: /* no pending request */ 1329 case 0: /* no pending request */
1362 dbg(DEBUG_USBREQ, "%s: no request pending", __func__); 1330 gig_dbg(DEBUG_USBREQ, "%s: no request pending", __func__);
1363 break; 1331 break;
1364 1332
1365 case HD_OPEN_ATCHANNEL: 1333 case HD_OPEN_ATCHANNEL:
1366 err("timeout opening AT channel"); 1334 dev_err(bcs->cs->dev, "timeout opening AT channel\n");
1367 error_reset(bcs->cs); 1335 error_reset(bcs->cs);
1368 break; 1336 break;
1369 1337
1370 case HD_OPEN_B2CHANNEL: 1338 case HD_OPEN_B2CHANNEL:
1371 case HD_OPEN_B1CHANNEL: 1339 case HD_OPEN_B1CHANNEL:
1372 err("timeout opening channel %d", bcs->channel + 1); 1340 dev_err(bcs->cs->dev, "timeout opening channel %d\n",
1341 bcs->channel + 1);
1373 error_hangup(bcs); 1342 error_hangup(bcs);
1374 break; 1343 break;
1375 1344
1376 case HD_CLOSE_ATCHANNEL: 1345 case HD_CLOSE_ATCHANNEL:
1377 err("timeout closing AT channel"); 1346 dev_err(bcs->cs->dev, "timeout closing AT channel\n");
1378 //wake_up_interruptible(cs->initwait);
1379 //FIXME need own wait queue?
1380 break; 1347 break;
1381 1348
1382 case HD_CLOSE_B2CHANNEL: 1349 case HD_CLOSE_B2CHANNEL:
1383 case HD_CLOSE_B1CHANNEL: 1350 case HD_CLOSE_B1CHANNEL:
1384 err("timeout closing channel %d", bcs->channel + 1); 1351 dev_err(bcs->cs->dev, "timeout closing channel %d\n",
1352 bcs->channel + 1);
1385 break; 1353 break;
1386 1354
1387 default: 1355 default:
1388 warn("request 0x%02x timed out, clearing", pending); 1356 dev_warn(bcs->cs->dev, "request 0x%02x timed out, clearing\n",
1357 pending);
1389 } 1358 }
1390} 1359}
1391 1360
@@ -1398,18 +1367,14 @@ static void req_timeout(unsigned long data)
1398 */ 1367 */
1399static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs) 1368static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs)
1400{ 1369{
1401 struct bas_cardstate *ucs; 1370 struct bas_cardstate *ucs = urb->context;
1402 unsigned long flags; 1371 unsigned long flags;
1403 1372
1404 IFNULLRET(urb);
1405 IFNULLRET(urb->context);
1406 IFNULLRET(cardstate);
1407
1408 ucs = (struct bas_cardstate *) urb->context;
1409 spin_lock_irqsave(&ucs->lock, flags); 1373 spin_lock_irqsave(&ucs->lock, flags);
1410 if (urb->status && ucs->pending) { 1374 if (urb->status && ucs->pending) {
1411 err("control request 0x%02x failed: %s", 1375 dev_err(&ucs->interface->dev,
1412 ucs->pending, get_usb_statmsg(urb->status)); 1376 "control request 0x%02x failed: %s\n",
1377 ucs->pending, get_usb_statmsg(urb->status));
1413 del_timer(&ucs->timer_ctrl); 1378 del_timer(&ucs->timer_ctrl);
1414 ucs->pending = 0; 1379 ucs->pending = 0;
1415 } 1380 }
@@ -1438,28 +1403,25 @@ static void write_ctrl_callback(struct urb *urb, struct pt_regs *regs)
1438 */ 1403 */
1439static int req_submit(struct bc_state *bcs, int req, int val, int timeout) 1404static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
1440{ 1405{
1441 struct bas_cardstate *ucs; 1406 struct bas_cardstate *ucs = bcs->cs->hw.bas;
1442 int ret; 1407 int ret;
1443 unsigned long flags; 1408 unsigned long flags;
1444 1409
1445 IFNULLRETVAL(bcs, -EINVAL); 1410 gig_dbg(DEBUG_USBREQ, "-------> 0x%02x (%d)", req, val);
1446 IFNULLRETVAL(bcs->cs, -EINVAL);
1447 ucs = bcs->cs->hw.bas;
1448 IFNULLRETVAL(ucs, -EINVAL);
1449 IFNULLRETVAL(ucs->urb_ctrl, -EINVAL);
1450
1451 dbg(DEBUG_USBREQ, "-------> 0x%02x (%d)", req, val);
1452 1411
1453 spin_lock_irqsave(&ucs->lock, flags); 1412 spin_lock_irqsave(&ucs->lock, flags);
1454 if (ucs->pending) { 1413 if (ucs->pending) {
1455 spin_unlock_irqrestore(&ucs->lock, flags); 1414 spin_unlock_irqrestore(&ucs->lock, flags);
1456 err("submission of request 0x%02x failed: request 0x%02x still pending", 1415 dev_err(bcs->cs->dev,
1457 req, ucs->pending); 1416 "submission of request 0x%02x failed: "
1417 "request 0x%02x still pending\n",
1418 req, ucs->pending);
1458 return -EBUSY; 1419 return -EBUSY;
1459 } 1420 }
1460 if (ucs->urb_ctrl->status == -EINPROGRESS) { 1421 if (ucs->urb_ctrl->status == -EINPROGRESS) {
1461 spin_unlock_irqrestore(&ucs->lock, flags); 1422 spin_unlock_irqrestore(&ucs->lock, flags);
1462 err("could not submit request 0x%02x: URB busy", req); 1423 dev_err(bcs->cs->dev,
1424 "could not submit request 0x%02x: URB busy\n", req);
1463 return -EBUSY; 1425 return -EBUSY;
1464 } 1426 }
1465 1427
@@ -1469,19 +1431,19 @@ static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
1469 ucs->dr_ctrl.wIndex = 0; 1431 ucs->dr_ctrl.wIndex = 0;
1470 ucs->dr_ctrl.wLength = 0; 1432 ucs->dr_ctrl.wLength = 0;
1471 usb_fill_control_urb(ucs->urb_ctrl, ucs->udev, 1433 usb_fill_control_urb(ucs->urb_ctrl, ucs->udev,
1472 usb_sndctrlpipe(ucs->udev, 0), 1434 usb_sndctrlpipe(ucs->udev, 0),
1473 (unsigned char*) &ucs->dr_ctrl, NULL, 0, 1435 (unsigned char*) &ucs->dr_ctrl, NULL, 0,
1474 write_ctrl_callback, ucs); 1436 write_ctrl_callback, ucs);
1475 if ((ret = usb_submit_urb(ucs->urb_ctrl, SLAB_ATOMIC)) != 0) { 1437 if ((ret = usb_submit_urb(ucs->urb_ctrl, SLAB_ATOMIC)) != 0) {
1476 err("could not submit request 0x%02x: %s", 1438 dev_err(bcs->cs->dev, "could not submit request 0x%02x: %s\n",
1477 req, get_usb_statmsg(ret)); 1439 req, get_usb_statmsg(ret));
1478 spin_unlock_irqrestore(&ucs->lock, flags); 1440 spin_unlock_irqrestore(&ucs->lock, flags);
1479 return ret; 1441 return ret;
1480 } 1442 }
1481 ucs->pending = req; 1443 ucs->pending = req;
1482 1444
1483 if (timeout > 0) { 1445 if (timeout > 0) {
1484 dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout); 1446 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
1485 ucs->timer_ctrl.expires = jiffies + timeout * HZ / 10; 1447 ucs->timer_ctrl.expires = jiffies + timeout * HZ / 10;
1486 ucs->timer_ctrl.data = (unsigned long) bcs; 1448 ucs->timer_ctrl.data = (unsigned long) bcs;
1487 ucs->timer_ctrl.function = req_timeout; 1449 ucs->timer_ctrl.function = req_timeout;
@@ -1504,19 +1466,18 @@ static int gigaset_init_bchannel(struct bc_state *bcs)
1504{ 1466{
1505 int req, ret; 1467 int req, ret;
1506 1468
1507 IFNULLRETVAL(bcs, -EINVAL);
1508
1509 if ((ret = starturbs(bcs)) < 0) { 1469 if ((ret = starturbs(bcs)) < 0) {
1510 err("could not start isochronous I/O for channel %d", 1470 dev_err(bcs->cs->dev,
1511 bcs->channel + 1); 1471 "could not start isochronous I/O for channel %d\n",
1472 bcs->channel + 1);
1512 error_hangup(bcs); 1473 error_hangup(bcs);
1513 return ret; 1474 return ret;
1514 } 1475 }
1515 1476
1516 req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL; 1477 req = bcs->channel ? HD_OPEN_B2CHANNEL : HD_OPEN_B1CHANNEL;
1517 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) { 1478 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) {
1518 err("could not open channel %d: %s", 1479 dev_err(bcs->cs->dev, "could not open channel %d: %s\n",
1519 bcs->channel + 1, get_usb_statmsg(ret)); 1480 bcs->channel + 1, get_usb_statmsg(ret));
1520 stopurbs(bcs->hw.bas); 1481 stopurbs(bcs->hw.bas);
1521 error_hangup(bcs); 1482 error_hangup(bcs);
1522 } 1483 }
@@ -1537,8 +1498,6 @@ static int gigaset_close_bchannel(struct bc_state *bcs)
1537{ 1498{
1538 int req, ret; 1499 int req, ret;
1539 1500
1540 IFNULLRETVAL(bcs, -EINVAL);
1541
1542 if (!(atomic_read(&bcs->cs->hw.bas->basstate) & 1501 if (!(atomic_read(&bcs->cs->hw.bas->basstate) &
1543 (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) { 1502 (bcs->channel ? BS_B2OPEN : BS_B1OPEN))) {
1544 /* channel not running: just signal common.c */ 1503 /* channel not running: just signal common.c */
@@ -1548,8 +1507,9 @@ static int gigaset_close_bchannel(struct bc_state *bcs)
1548 1507
1549 req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL; 1508 req = bcs->channel ? HD_CLOSE_B2CHANNEL : HD_CLOSE_B1CHANNEL;
1550 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0) 1509 if ((ret = req_submit(bcs, req, 0, BAS_TIMEOUT)) < 0)
1551 err("could not submit HD_CLOSE_BxCHANNEL request: %s", 1510 dev_err(bcs->cs->dev,
1552 get_usb_statmsg(ret)); 1511 "could not submit HD_CLOSE_BxCHANNEL request: %s\n",
1512 get_usb_statmsg(ret));
1553 return ret; 1513 return ret;
1554} 1514}
1555 1515
@@ -1564,17 +1524,13 @@ static int gigaset_close_bchannel(struct bc_state *bcs)
1564 */ 1524 */
1565static void complete_cb(struct cardstate *cs) 1525static void complete_cb(struct cardstate *cs)
1566{ 1526{
1567 struct cmdbuf_t *cb; 1527 struct cmdbuf_t *cb = cs->cmdbuf;
1568
1569 IFNULLRET(cs);
1570 cb = cs->cmdbuf;
1571 IFNULLRET(cb);
1572 1528
1573 /* unqueue completed buffer */ 1529 /* unqueue completed buffer */
1574 cs->cmdbytes -= cs->curlen; 1530 cs->cmdbytes -= cs->curlen;
1575 dbg(DEBUG_TRANSCMD | DEBUG_LOCKCMD, 1531 gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD,
1576 "write_command: sent %u bytes, %u left", 1532 "write_command: sent %u bytes, %u left",
1577 cs->curlen, cs->cmdbytes); 1533 cs->curlen, cs->cmdbytes);
1578 if ((cs->cmdbuf = cb->next) != NULL) { 1534 if ((cs->cmdbuf = cb->next) != NULL) {
1579 cs->cmdbuf->prev = NULL; 1535 cs->cmdbuf->prev = NULL;
1580 cs->curlen = cs->cmdbuf->len; 1536 cs->curlen = cs->cmdbuf->len;
@@ -1600,15 +1556,9 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len);
1600 */ 1556 */
1601static void write_command_callback(struct urb *urb, struct pt_regs *regs) 1557static void write_command_callback(struct urb *urb, struct pt_regs *regs)
1602{ 1558{
1603 struct cardstate *cs; 1559 struct cardstate *cs = urb->context;
1560 struct bas_cardstate *ucs = cs->hw.bas;
1604 unsigned long flags; 1561 unsigned long flags;
1605 struct bas_cardstate *ucs;
1606
1607 IFNULLRET(urb);
1608 cs = (struct cardstate *) urb->context;
1609 IFNULLRET(cs);
1610 ucs = cs->hw.bas;
1611 IFNULLRET(ucs);
1612 1562
1613 /* check status */ 1563 /* check status */
1614 switch (urb->status) { 1564 switch (urb->status) {
@@ -1618,22 +1568,27 @@ static void write_command_callback(struct urb *urb, struct pt_regs *regs)
1618 case -ECONNRESET: /* canceled (async) */ 1568 case -ECONNRESET: /* canceled (async) */
1619 case -EINPROGRESS: /* pending */ 1569 case -EINPROGRESS: /* pending */
1620 /* ignore silently */ 1570 /* ignore silently */
1621 dbg(DEBUG_USBREQ, 1571 gig_dbg(DEBUG_USBREQ, "%s: %s",
1622 "%s: %s", __func__, get_usb_statmsg(urb->status)); 1572 __func__, get_usb_statmsg(urb->status));
1623 return; 1573 return;
1624 default: /* any failure */ 1574 default: /* any failure */
1625 if (++ucs->retry_cmd_out > BAS_RETRY) { 1575 if (++ucs->retry_cmd_out > BAS_RETRY) {
1626 warn("command write: %s, giving up after %d retries", 1576 dev_warn(cs->dev,
1627 get_usb_statmsg(urb->status), ucs->retry_cmd_out); 1577 "command write: %s, "
1578 "giving up after %d retries\n",
1579 get_usb_statmsg(urb->status),
1580 ucs->retry_cmd_out);
1628 break; 1581 break;
1629 } 1582 }
1630 if (cs->cmdbuf == NULL) { 1583 if (cs->cmdbuf == NULL) {
1631 warn("command write: %s, cannot retry - cmdbuf gone", 1584 dev_warn(cs->dev,
1632 get_usb_statmsg(urb->status)); 1585 "command write: %s, "
1586 "cannot retry - cmdbuf gone\n",
1587 get_usb_statmsg(urb->status));
1633 break; 1588 break;
1634 } 1589 }
1635 notice("command write: %s, retry %d", 1590 dev_notice(cs->dev, "command write: %s, retry %d\n",
1636 get_usb_statmsg(urb->status), ucs->retry_cmd_out); 1591 get_usb_statmsg(urb->status), ucs->retry_cmd_out);
1637 if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0) 1592 if (atwrite_submit(cs, cs->cmdbuf->buf, cs->cmdbuf->len) >= 0)
1638 /* resubmitted - bypass regular exit block */ 1593 /* resubmitted - bypass regular exit block */
1639 return; 1594 return;
@@ -1655,13 +1610,9 @@ static void write_command_callback(struct urb *urb, struct pt_regs *regs)
1655static void atrdy_timeout(unsigned long data) 1610static void atrdy_timeout(unsigned long data)
1656{ 1611{
1657 struct cardstate *cs = (struct cardstate *) data; 1612 struct cardstate *cs = (struct cardstate *) data;
1658 struct bas_cardstate *ucs; 1613 struct bas_cardstate *ucs = cs->hw.bas;
1659
1660 IFNULLRET(cs);
1661 ucs = cs->hw.bas;
1662 IFNULLRET(ucs);
1663 1614
1664 warn("timeout waiting for HD_READY_SEND_ATDATA"); 1615 dev_warn(cs->dev, "timeout waiting for HD_READY_SEND_ATDATA\n");
1665 1616
1666 /* fake the missing signal - what else can I do? */ 1617 /* fake the missing signal - what else can I do? */
1667 update_basstate(ucs, BS_ATREADY, BS_ATTIMER); 1618 update_basstate(ucs, BS_ATREADY, BS_ATTIMER);
@@ -1682,18 +1633,15 @@ static void atrdy_timeout(unsigned long data)
1682 */ 1633 */
1683static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len) 1634static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1684{ 1635{
1685 struct bas_cardstate *ucs; 1636 struct bas_cardstate *ucs = cs->hw.bas;
1637 unsigned long flags;
1686 int ret; 1638 int ret;
1687 1639
1688 IFNULLRETVAL(cs, -EFAULT); 1640 gig_dbg(DEBUG_USBREQ, "-------> HD_WRITE_ATMESSAGE (%d)", len);
1689 ucs = cs->hw.bas;
1690 IFNULLRETVAL(ucs, -EFAULT);
1691 IFNULLRETVAL(ucs->urb_cmd_out, -EFAULT);
1692
1693 dbg(DEBUG_USBREQ, "-------> HD_WRITE_ATMESSAGE (%d)", len);
1694 1641
1695 if (ucs->urb_cmd_out->status == -EINPROGRESS) { 1642 if (ucs->urb_cmd_out->status == -EINPROGRESS) {
1696 err("could not submit HD_WRITE_ATMESSAGE: URB busy"); 1643 dev_err(cs->dev,
1644 "could not submit HD_WRITE_ATMESSAGE: URB busy\n");
1697 return -EBUSY; 1645 return -EBUSY;
1698 } 1646 }
1699 1647
@@ -1707,9 +1655,13 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1707 (unsigned char*) &ucs->dr_cmd_out, buf, len, 1655 (unsigned char*) &ucs->dr_cmd_out, buf, len,
1708 write_command_callback, cs); 1656 write_command_callback, cs);
1709 1657
1710 if ((ret = usb_submit_urb(ucs->urb_cmd_out, SLAB_ATOMIC)) != 0) { 1658 spin_lock_irqsave(&cs->lock, flags);
1711 err("could not submit HD_WRITE_ATMESSAGE: %s", 1659 ret = cs->connected ? usb_submit_urb(ucs->urb_cmd_out, SLAB_ATOMIC) : -ENODEV;
1712 get_usb_statmsg(ret)); 1660 spin_unlock_irqrestore(&cs->lock, flags);
1661
1662 if (ret) {
1663 dev_err(cs->dev, "could not submit HD_WRITE_ATMESSAGE: %s\n",
1664 get_usb_statmsg(ret));
1713 return ret; 1665 return ret;
1714 } 1666 }
1715 1667
@@ -1718,8 +1670,8 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1718 1670
1719 /* start timeout if necessary */ 1671 /* start timeout if necessary */
1720 if (!(atomic_read(&ucs->basstate) & BS_ATTIMER)) { 1672 if (!(atomic_read(&ucs->basstate) & BS_ATTIMER)) {
1721 dbg(DEBUG_OUTPUT, 1673 gig_dbg(DEBUG_OUTPUT, "setting ATREADY timeout of %d/10 secs",
1722 "setting ATREADY timeout of %d/10 secs", ATRDY_TIMEOUT); 1674 ATRDY_TIMEOUT);
1723 ucs->timer_atrdy.expires = jiffies + ATRDY_TIMEOUT * HZ / 10; 1675 ucs->timer_atrdy.expires = jiffies + ATRDY_TIMEOUT * HZ / 10;
1724 ucs->timer_atrdy.data = (unsigned long) cs; 1676 ucs->timer_atrdy.data = (unsigned long) cs;
1725 ucs->timer_atrdy.function = atrdy_timeout; 1677 ucs->timer_atrdy.function = atrdy_timeout;
@@ -1740,21 +1692,17 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1740static int start_cbsend(struct cardstate *cs) 1692static int start_cbsend(struct cardstate *cs)
1741{ 1693{
1742 struct cmdbuf_t *cb; 1694 struct cmdbuf_t *cb;
1743 struct bas_cardstate *ucs; 1695 struct bas_cardstate *ucs = cs->hw.bas;
1744 unsigned long flags; 1696 unsigned long flags;
1745 int rc; 1697 int rc;
1746 int retval = 0; 1698 int retval = 0;
1747 1699
1748 IFNULLRETVAL(cs, -EFAULT);
1749 ucs = cs->hw.bas;
1750 IFNULLRETVAL(ucs, -EFAULT);
1751
1752 /* check if AT channel is open */ 1700 /* check if AT channel is open */
1753 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) { 1701 if (!(atomic_read(&ucs->basstate) & BS_ATOPEN)) {
1754 dbg(DEBUG_TRANSCMD | DEBUG_LOCKCMD, "AT channel not open"); 1702 gig_dbg(DEBUG_TRANSCMD|DEBUG_LOCKCMD, "AT channel not open");
1755 rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT); 1703 rc = req_submit(cs->bcs, HD_OPEN_ATCHANNEL, 0, BAS_TIMEOUT);
1756 if (rc < 0) { 1704 if (rc < 0) {
1757 err("could not open AT channel"); 1705 dev_err(cs->dev, "could not open AT channel\n");
1758 /* flush command queue */ 1706 /* flush command queue */
1759 spin_lock_irqsave(&cs->cmdlock, flags); 1707 spin_lock_irqsave(&cs->cmdlock, flags);
1760 while (cs->cmdbuf != NULL) 1708 while (cs->cmdbuf != NULL)
@@ -1792,27 +1740,23 @@ static int start_cbsend(struct cardstate *cs)
1792 * cs controller state structure 1740 * cs controller state structure
1793 * buf command string to send 1741 * buf command string to send
1794 * len number of bytes to send (max. IF_WRITEBUF) 1742 * len number of bytes to send (max. IF_WRITEBUF)
1795 * wake_tasklet tasklet to run when transmission is completed (NULL if none) 1743 * wake_tasklet tasklet to run when transmission is completed
1744 * (NULL if none)
1796 * return value: 1745 * return value:
1797 * number of bytes queued on success 1746 * number of bytes queued on success
1798 * error code < 0 on error 1747 * error code < 0 on error
1799 */ 1748 */
1800static int gigaset_write_cmd(struct cardstate *cs, 1749static int gigaset_write_cmd(struct cardstate *cs,
1801 const unsigned char *buf, int len, 1750 const unsigned char *buf, int len,
1802 struct tasklet_struct *wake_tasklet) 1751 struct tasklet_struct *wake_tasklet)
1803{ 1752{
1804 struct cmdbuf_t *cb; 1753 struct cmdbuf_t *cb;
1805 unsigned long flags; 1754 unsigned long flags;
1806 int status; 1755 int status;
1807 1756
1808 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ? 1757 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
1809 DEBUG_TRANSCMD : DEBUG_LOCKCMD, 1758 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
1810 "CMD Transmit", len, buf, 0); 1759 "CMD Transmit", len, buf);
1811
1812 if (!atomic_read(&cs->connected)) {
1813 err("%s: not connected", __func__);
1814 return -ENODEV;
1815 }
1816 1760
1817 if (len <= 0) 1761 if (len <= 0)
1818 return 0; /* nothing to do */ 1762 return 0; /* nothing to do */
@@ -1820,7 +1764,7 @@ static int gigaset_write_cmd(struct cardstate *cs,
1820 if (len > IF_WRITEBUF) 1764 if (len > IF_WRITEBUF)
1821 len = IF_WRITEBUF; 1765 len = IF_WRITEBUF;
1822 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) { 1766 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
1823 err("%s: out of memory", __func__); 1767 dev_err(cs->dev, "%s: out of memory\n", __func__);
1824 return -ENOMEM; 1768 return -ENOMEM;
1825 } 1769 }
1826 1770
@@ -1849,7 +1793,8 @@ static int gigaset_write_cmd(struct cardstate *cs,
1849 1793
1850/* gigaset_write_room 1794/* gigaset_write_room
1851 * tty_driver.write_room interface routine 1795 * tty_driver.write_room interface routine
1852 * return number of characters the driver will accept to be written via gigaset_write_cmd 1796 * return number of characters the driver will accept to be written via
1797 * gigaset_write_cmd
1853 * parameter: 1798 * parameter:
1854 * controller state structure 1799 * controller state structure
1855 * return value: 1800 * return value:
@@ -1947,7 +1892,7 @@ static int gigaset_initbcshw(struct bc_state *bcs)
1947 return 0; 1892 return 0;
1948 } 1893 }
1949 tasklet_init(&ubc->sent_tasklet, 1894 tasklet_init(&ubc->sent_tasklet,
1950 &write_iso_tasklet, (unsigned long) bcs); 1895 &write_iso_tasklet, (unsigned long) bcs);
1951 1896
1952 spin_lock_init(&ubc->isoinlock); 1897 spin_lock_init(&ubc->isoinlock);
1953 for (i = 0; i < BAS_INURBS; ++i) 1898 for (i = 0; i < BAS_INURBS; ++i)
@@ -1968,7 +1913,7 @@ static int gigaset_initbcshw(struct bc_state *bcs)
1968 ubc->shared0s = 0; 1913 ubc->shared0s = 0;
1969 ubc->stolen0s = 0; 1914 ubc->stolen0s = 0;
1970 tasklet_init(&ubc->rcvd_tasklet, 1915 tasklet_init(&ubc->rcvd_tasklet,
1971 &read_iso_tasklet, (unsigned long) bcs); 1916 &read_iso_tasklet, (unsigned long) bcs);
1972 return 1; 1917 return 1;
1973} 1918}
1974 1919
@@ -2027,57 +1972,56 @@ static int gigaset_initcshw(struct cardstate *cs)
2027 */ 1972 */
2028static void freeurbs(struct cardstate *cs) 1973static void freeurbs(struct cardstate *cs)
2029{ 1974{
2030 struct bas_cardstate *ucs; 1975 struct bas_cardstate *ucs = cs->hw.bas;
2031 struct bas_bc_state *ubc; 1976 struct bas_bc_state *ubc;
2032 int i, j; 1977 int i, j;
2033 1978
2034 IFNULLRET(cs);
2035 ucs = cs->hw.bas;
2036 IFNULLRET(ucs);
2037
2038 for (j = 0; j < 2; ++j) { 1979 for (j = 0; j < 2; ++j) {
2039 ubc = cs->bcs[j].hw.bas; 1980 ubc = cs->bcs[j].hw.bas;
2040 IFNULLCONT(ubc);
2041 for (i = 0; i < BAS_OUTURBS; ++i) 1981 for (i = 0; i < BAS_OUTURBS; ++i)
2042 if (ubc->isoouturbs[i].urb) { 1982 if (ubc->isoouturbs[i].urb) {
2043 usb_kill_urb(ubc->isoouturbs[i].urb); 1983 usb_kill_urb(ubc->isoouturbs[i].urb);
2044 dbg(DEBUG_INIT, 1984 gig_dbg(DEBUG_INIT,
2045 "%s: isoc output URB %d/%d unlinked", 1985 "%s: isoc output URB %d/%d unlinked",
2046 __func__, j, i); 1986 __func__, j, i);
2047 usb_free_urb(ubc->isoouturbs[i].urb); 1987 usb_free_urb(ubc->isoouturbs[i].urb);
2048 ubc->isoouturbs[i].urb = NULL; 1988 ubc->isoouturbs[i].urb = NULL;
2049 } 1989 }
2050 for (i = 0; i < BAS_INURBS; ++i) 1990 for (i = 0; i < BAS_INURBS; ++i)
2051 if (ubc->isoinurbs[i]) { 1991 if (ubc->isoinurbs[i]) {
2052 usb_kill_urb(ubc->isoinurbs[i]); 1992 usb_kill_urb(ubc->isoinurbs[i]);
2053 dbg(DEBUG_INIT, 1993 gig_dbg(DEBUG_INIT,
2054 "%s: isoc input URB %d/%d unlinked", 1994 "%s: isoc input URB %d/%d unlinked",
2055 __func__, j, i); 1995 __func__, j, i);
2056 usb_free_urb(ubc->isoinurbs[i]); 1996 usb_free_urb(ubc->isoinurbs[i]);
2057 ubc->isoinurbs[i] = NULL; 1997 ubc->isoinurbs[i] = NULL;
2058 } 1998 }
2059 } 1999 }
2060 if (ucs->urb_int_in) { 2000 if (ucs->urb_int_in) {
2061 usb_kill_urb(ucs->urb_int_in); 2001 usb_kill_urb(ucs->urb_int_in);
2062 dbg(DEBUG_INIT, "%s: interrupt input URB unlinked", __func__); 2002 gig_dbg(DEBUG_INIT, "%s: interrupt input URB unlinked",
2003 __func__);
2063 usb_free_urb(ucs->urb_int_in); 2004 usb_free_urb(ucs->urb_int_in);
2064 ucs->urb_int_in = NULL; 2005 ucs->urb_int_in = NULL;
2065 } 2006 }
2066 if (ucs->urb_cmd_out) { 2007 if (ucs->urb_cmd_out) {
2067 usb_kill_urb(ucs->urb_cmd_out); 2008 usb_kill_urb(ucs->urb_cmd_out);
2068 dbg(DEBUG_INIT, "%s: command output URB unlinked", __func__); 2009 gig_dbg(DEBUG_INIT, "%s: command output URB unlinked",
2010 __func__);
2069 usb_free_urb(ucs->urb_cmd_out); 2011 usb_free_urb(ucs->urb_cmd_out);
2070 ucs->urb_cmd_out = NULL; 2012 ucs->urb_cmd_out = NULL;
2071 } 2013 }
2072 if (ucs->urb_cmd_in) { 2014 if (ucs->urb_cmd_in) {
2073 usb_kill_urb(ucs->urb_cmd_in); 2015 usb_kill_urb(ucs->urb_cmd_in);
2074 dbg(DEBUG_INIT, "%s: command input URB unlinked", __func__); 2016 gig_dbg(DEBUG_INIT, "%s: command input URB unlinked",
2017 __func__);
2075 usb_free_urb(ucs->urb_cmd_in); 2018 usb_free_urb(ucs->urb_cmd_in);
2076 ucs->urb_cmd_in = NULL; 2019 ucs->urb_cmd_in = NULL;
2077 } 2020 }
2078 if (ucs->urb_ctrl) { 2021 if (ucs->urb_ctrl) {
2079 usb_kill_urb(ucs->urb_ctrl); 2022 usb_kill_urb(ucs->urb_ctrl);
2080 dbg(DEBUG_INIT, "%s: control output URB unlinked", __func__); 2023 gig_dbg(DEBUG_INIT, "%s: control output URB unlinked",
2024 __func__);
2081 usb_free_urb(ucs->urb_ctrl); 2025 usb_free_urb(ucs->urb_ctrl);
2082 ucs->urb_ctrl = NULL; 2026 ucs->urb_ctrl = NULL;
2083 } 2027 }
@@ -2099,12 +2043,10 @@ static int gigaset_probe(struct usb_interface *interface,
2099 int i, j; 2043 int i, j;
2100 int ret; 2044 int ret;
2101 2045
2102 IFNULLRETVAL(udev, -ENODEV); 2046 gig_dbg(DEBUG_ANY,
2103 2047 "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
2104 dbg(DEBUG_ANY, 2048 __func__, le16_to_cpu(udev->descriptor.idVendor),
2105 "%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)", 2049 le16_to_cpu(udev->descriptor.idProduct));
2106 __func__, le16_to_cpu(udev->descriptor.idVendor),
2107 le16_to_cpu(udev->descriptor.idProduct));
2108 2050
2109 /* See if the device offered us matches what we can accept */ 2051 /* See if the device offered us matches what we can accept */
2110 if ((le16_to_cpu(udev->descriptor.idVendor) != USB_GIGA_VENDOR_ID) || 2052 if ((le16_to_cpu(udev->descriptor.idVendor) != USB_GIGA_VENDOR_ID) ||
@@ -2112,20 +2054,21 @@ static int gigaset_probe(struct usb_interface *interface,
2112 le16_to_cpu(udev->descriptor.idProduct) != USB_4175_PRODUCT_ID && 2054 le16_to_cpu(udev->descriptor.idProduct) != USB_4175_PRODUCT_ID &&
2113 le16_to_cpu(udev->descriptor.idProduct) != USB_SX303_PRODUCT_ID && 2055 le16_to_cpu(udev->descriptor.idProduct) != USB_SX303_PRODUCT_ID &&
2114 le16_to_cpu(udev->descriptor.idProduct) != USB_SX353_PRODUCT_ID)) { 2056 le16_to_cpu(udev->descriptor.idProduct) != USB_SX353_PRODUCT_ID)) {
2115 dbg(DEBUG_ANY, "%s: unmatched ID - exiting", __func__); 2057 gig_dbg(DEBUG_ANY, "%s: unmatched ID - exiting", __func__);
2116 return -ENODEV; 2058 return -ENODEV;
2117 } 2059 }
2118 2060
2119 /* set required alternate setting */ 2061 /* set required alternate setting */
2120 hostif = interface->cur_altsetting; 2062 hostif = interface->cur_altsetting;
2121 if (hostif->desc.bAlternateSetting != 3) { 2063 if (hostif->desc.bAlternateSetting != 3) {
2122 dbg(DEBUG_ANY, 2064 gig_dbg(DEBUG_ANY,
2123 "%s: wrong alternate setting %d - trying to switch", 2065 "%s: wrong alternate setting %d - trying to switch",
2124 __func__, hostif->desc.bAlternateSetting); 2066 __func__, hostif->desc.bAlternateSetting);
2125 if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) < 0) { 2067 if (usb_set_interface(udev, hostif->desc.bInterfaceNumber, 3) < 0) {
2126 warn("usb_set_interface failed, device %d interface %d altsetting %d", 2068 dev_warn(&udev->dev, "usb_set_interface failed, "
2127 udev->devnum, hostif->desc.bInterfaceNumber, 2069 "device %d interface %d altsetting %d\n",
2128 hostif->desc.bAlternateSetting); 2070 udev->devnum, hostif->desc.bInterfaceNumber,
2071 hostif->desc.bAlternateSetting);
2129 return -ENODEV; 2072 return -ENODEV;
2130 } 2073 }
2131 hostif = interface->cur_altsetting; 2074 hostif = interface->cur_altsetting;
@@ -2134,23 +2077,28 @@ static int gigaset_probe(struct usb_interface *interface,
2134 /* Reject application specific interfaces 2077 /* Reject application specific interfaces
2135 */ 2078 */
2136 if (hostif->desc.bInterfaceClass != 255) { 2079 if (hostif->desc.bInterfaceClass != 255) {
2137 warn("%s: bInterfaceClass == %d", 2080 dev_warn(&udev->dev, "%s: bInterfaceClass == %d\n",
2138 __func__, hostif->desc.bInterfaceClass); 2081 __func__, hostif->desc.bInterfaceClass);
2139 return -ENODEV; 2082 return -ENODEV;
2140 } 2083 }
2141 2084
2142 info("%s: Device matched (Vendor: 0x%x, Product: 0x%x)", 2085 dev_info(&udev->dev,
2143 __func__, le16_to_cpu(udev->descriptor.idVendor), 2086 "%s: Device matched (Vendor: 0x%x, Product: 0x%x)\n",
2144 le16_to_cpu(udev->descriptor.idProduct)); 2087 __func__, le16_to_cpu(udev->descriptor.idVendor),
2088 le16_to_cpu(udev->descriptor.idProduct));
2145 2089
2146 cs = gigaset_getunassignedcs(driver); 2090 cs = gigaset_getunassignedcs(driver);
2147 if (!cs) { 2091 if (!cs) {
2148 err("%s: no free cardstate", __func__); 2092 dev_err(&udev->dev, "no free cardstate\n");
2149 return -ENODEV; 2093 return -ENODEV;
2150 } 2094 }
2151 ucs = cs->hw.bas; 2095 ucs = cs->hw.bas;
2096
2097 /* save off device structure ptrs for later use */
2098 usb_get_dev(udev);
2152 ucs->udev = udev; 2099 ucs->udev = udev;
2153 ucs->interface = interface; 2100 ucs->interface = interface;
2101 cs->dev = &interface->dev;
2154 2102
2155 /* allocate URBs: 2103 /* allocate URBs:
2156 * - one for the interrupt pipe 2104 * - one for the interrupt pipe
@@ -2159,22 +2107,22 @@ static int gigaset_probe(struct usb_interface *interface,
2159 */ 2107 */
2160 ucs->urb_int_in = usb_alloc_urb(0, SLAB_KERNEL); 2108 ucs->urb_int_in = usb_alloc_urb(0, SLAB_KERNEL);
2161 if (!ucs->urb_int_in) { 2109 if (!ucs->urb_int_in) {
2162 err("No free urbs available"); 2110 dev_err(cs->dev, "no free urbs available\n");
2163 goto error; 2111 goto error;
2164 } 2112 }
2165 ucs->urb_cmd_in = usb_alloc_urb(0, SLAB_KERNEL); 2113 ucs->urb_cmd_in = usb_alloc_urb(0, SLAB_KERNEL);
2166 if (!ucs->urb_cmd_in) { 2114 if (!ucs->urb_cmd_in) {
2167 err("No free urbs available"); 2115 dev_err(cs->dev, "no free urbs available\n");
2168 goto error; 2116 goto error;
2169 } 2117 }
2170 ucs->urb_cmd_out = usb_alloc_urb(0, SLAB_KERNEL); 2118 ucs->urb_cmd_out = usb_alloc_urb(0, SLAB_KERNEL);
2171 if (!ucs->urb_cmd_out) { 2119 if (!ucs->urb_cmd_out) {
2172 err("No free urbs available"); 2120 dev_err(cs->dev, "no free urbs available\n");
2173 goto error; 2121 goto error;
2174 } 2122 }
2175 ucs->urb_ctrl = usb_alloc_urb(0, SLAB_KERNEL); 2123 ucs->urb_ctrl = usb_alloc_urb(0, SLAB_KERNEL);
2176 if (!ucs->urb_ctrl) { 2124 if (!ucs->urb_ctrl) {
2177 err("No free urbs available"); 2125 dev_err(cs->dev, "no free urbs available\n");
2178 goto error; 2126 goto error;
2179 } 2127 }
2180 2128
@@ -2184,7 +2132,7 @@ static int gigaset_probe(struct usb_interface *interface,
2184 ubc->isoouturbs[i].urb = 2132 ubc->isoouturbs[i].urb =
2185 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL); 2133 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL);
2186 if (!ubc->isoouturbs[i].urb) { 2134 if (!ubc->isoouturbs[i].urb) {
2187 err("No free urbs available"); 2135 dev_err(cs->dev, "no free urbs available\n");
2188 goto error; 2136 goto error;
2189 } 2137 }
2190 } 2138 }
@@ -2192,7 +2140,7 @@ static int gigaset_probe(struct usb_interface *interface,
2192 ubc->isoinurbs[i] = 2140 ubc->isoinurbs[i] =
2193 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL); 2141 usb_alloc_urb(BAS_NUMFRAMES, SLAB_KERNEL);
2194 if (!ubc->isoinurbs[i]) { 2142 if (!ubc->isoinurbs[i]) {
2195 err("No free urbs available"); 2143 dev_err(cs->dev, "no free urbs available\n");
2196 goto error; 2144 goto error;
2197 } 2145 }
2198 } 2146 }
@@ -2204,13 +2152,14 @@ static int gigaset_probe(struct usb_interface *interface,
2204 /* Fill the interrupt urb and send it to the core */ 2152 /* Fill the interrupt urb and send it to the core */
2205 endpoint = &hostif->endpoint[0].desc; 2153 endpoint = &hostif->endpoint[0].desc;
2206 usb_fill_int_urb(ucs->urb_int_in, udev, 2154 usb_fill_int_urb(ucs->urb_int_in, udev,
2207 usb_rcvintpipe(udev, 2155 usb_rcvintpipe(udev,
2208 (endpoint->bEndpointAddress) & 0x0f), 2156 (endpoint->bEndpointAddress) & 0x0f),
2209 ucs->int_in_buf, 3, read_int_callback, cs, 2157 ucs->int_in_buf, 3, read_int_callback, cs,
2210 endpoint->bInterval); 2158 endpoint->bInterval);
2211 ret = usb_submit_urb(ucs->urb_int_in, SLAB_KERNEL); 2159 ret = usb_submit_urb(ucs->urb_int_in, SLAB_KERNEL);
2212 if (ret) { 2160 if (ret) {
2213 err("could not submit interrupt URB: %s", get_usb_statmsg(ret)); 2161 dev_err(cs->dev, "could not submit interrupt URB: %s\n",
2162 get_usb_statmsg(ret));
2214 goto error; 2163 goto error;
2215 } 2164 }
2216 2165
@@ -2221,18 +2170,18 @@ static int gigaset_probe(struct usb_interface *interface,
2221 /* tell common part that the device is ready */ 2170 /* tell common part that the device is ready */
2222 if (startmode == SM_LOCKED) 2171 if (startmode == SM_LOCKED)
2223 atomic_set(&cs->mstate, MS_LOCKED); 2172 atomic_set(&cs->mstate, MS_LOCKED);
2224 if (!gigaset_start(cs))
2225 goto error;
2226 2173
2227 /* save address of controller structure */ 2174 /* save address of controller structure */
2228 usb_set_intfdata(interface, cs); 2175 usb_set_intfdata(interface, cs);
2229 2176
2230 /* set up device sysfs */ 2177 if (!gigaset_start(cs))
2231 gigaset_init_dev_sysfs(interface); 2178 goto error;
2179
2232 return 0; 2180 return 0;
2233 2181
2234error: 2182error:
2235 freeurbs(cs); 2183 freeurbs(cs);
2184 usb_set_intfdata(interface, NULL);
2236 gigaset_unassign(cs); 2185 gigaset_unassign(cs);
2237 return -ENODEV; 2186 return -ENODEV;
2238} 2187}
@@ -2245,23 +2194,22 @@ static void gigaset_disconnect(struct usb_interface *interface)
2245 struct cardstate *cs; 2194 struct cardstate *cs;
2246 struct bas_cardstate *ucs; 2195 struct bas_cardstate *ucs;
2247 2196
2248 /* clear device sysfs */
2249 gigaset_free_dev_sysfs(interface);
2250
2251 cs = usb_get_intfdata(interface); 2197 cs = usb_get_intfdata(interface);
2252 usb_set_intfdata(interface, NULL);
2253 2198
2254 IFNULLRET(cs);
2255 ucs = cs->hw.bas; 2199 ucs = cs->hw.bas;
2256 IFNULLRET(ucs);
2257 2200
2258 info("disconnecting GigaSet base"); 2201 dev_info(cs->dev, "disconnecting Gigaset base\n");
2259 gigaset_stop(cs); 2202 gigaset_stop(cs);
2260 freeurbs(cs); 2203 freeurbs(cs);
2204 usb_set_intfdata(interface, NULL);
2261 kfree(ucs->rcvbuf); 2205 kfree(ucs->rcvbuf);
2262 ucs->rcvbuf = NULL; 2206 ucs->rcvbuf = NULL;
2263 ucs->rcvbuf_size = 0; 2207 ucs->rcvbuf_size = 0;
2264 atomic_set(&ucs->basstate, 0); 2208 atomic_set(&ucs->basstate, 0);
2209 usb_put_dev(ucs->udev);
2210 ucs->interface = NULL;
2211 ucs->udev = NULL;
2212 cs->dev = NULL;
2265 gigaset_unassign(cs); 2213 gigaset_unassign(cs);
2266} 2214}
2267 2215
@@ -2293,13 +2241,14 @@ static int __init bas_gigaset_init(void)
2293 2241
2294 /* allocate memory for our driver state and intialize it */ 2242 /* allocate memory for our driver state and intialize it */
2295 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS, 2243 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
2296 GIGASET_MODULENAME, GIGASET_DEVNAME, 2244 GIGASET_MODULENAME, GIGASET_DEVNAME,
2297 GIGASET_DEVFSNAME, &gigops, 2245 GIGASET_DEVFSNAME, &gigops,
2298 THIS_MODULE)) == NULL) 2246 THIS_MODULE)) == NULL)
2299 goto error; 2247 goto error;
2300 2248
2301 /* allocate memory for our device state and intialize it */ 2249 /* allocate memory for our device state and intialize it */
2302 cardstate = gigaset_initcs(driver, 2, 0, 0, cidmode, GIGASET_MODULENAME); 2250 cardstate = gigaset_initcs(driver, 2, 0, 0, cidmode,
2251 GIGASET_MODULENAME);
2303 if (!cardstate) 2252 if (!cardstate)
2304 goto error; 2253 goto error;
2305 2254
@@ -2329,19 +2278,18 @@ error: if (cardstate)
2329static void __exit bas_gigaset_exit(void) 2278static void __exit bas_gigaset_exit(void)
2330{ 2279{
2331 gigaset_blockdriver(driver); /* => probe will fail 2280 gigaset_blockdriver(driver); /* => probe will fail
2332 * => no gigaset_start any more 2281 * => no gigaset_start any more
2333 */ 2282 */
2334 2283
2335 gigaset_shutdown(cardstate); 2284 gigaset_shutdown(cardstate);
2336 /* from now on, no isdn callback should be possible */ 2285 /* from now on, no isdn callback should be possible */
2337 2286
2338 if (atomic_read(&cardstate->hw.bas->basstate) & BS_ATOPEN) { 2287 if (atomic_read(&cardstate->hw.bas->basstate) & BS_ATOPEN) {
2339 dbg(DEBUG_ANY, "closing AT channel"); 2288 gig_dbg(DEBUG_ANY, "closing AT channel");
2340 if (req_submit(cardstate->bcs, 2289 if (req_submit(cardstate->bcs,
2341 HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT) >= 0) { 2290 HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT) >= 0) {
2342 /* successfully submitted - wait for completion */ 2291 /* successfully submitted */
2343 //wait_event_interruptible(cs->initwait, !cs->hw.bas->pending); 2292 //FIXME wait for completion?
2344 //FIXME need own wait queue? wakeup?
2345 } 2293 }
2346 } 2294 }
2347 2295