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.c400
1 files changed, 248 insertions, 152 deletions
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index 707d9c94cf9..178942a2ee6 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -109,6 +109,9 @@ struct bas_cardstate {
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() */
113 struct timer_list timer_int_in; /* int read retry delay */
114 int retry_int_in;
112 115
113 spinlock_t lock; /* locks all following */ 116 spinlock_t lock; /* locks all following */
114 int basstate; /* bitmap (BS_*) */ 117 int basstate; /* bitmap (BS_*) */
@@ -169,7 +172,7 @@ static char *get_usb_rcmsg(int rc)
169 case -EAGAIN: 172 case -EAGAIN:
170 return "start frame too early or too much scheduled"; 173 return "start frame too early or too much scheduled";
171 case -EFBIG: 174 case -EFBIG:
172 return "too many isochronous frames requested"; 175 return "too many isoc frames requested";
173 case -EPIPE: 176 case -EPIPE:
174 return "endpoint stalled"; 177 return "endpoint stalled";
175 case -EMSGSIZE: 178 case -EMSGSIZE:
@@ -200,13 +203,13 @@ static char *get_usb_statmsg(int status)
200 case -ENOENT: 203 case -ENOENT:
201 return "unlinked (sync)"; 204 return "unlinked (sync)";
202 case -EINPROGRESS: 205 case -EINPROGRESS:
203 return "pending"; 206 return "URB still pending";
204 case -EPROTO: 207 case -EPROTO:
205 return "bit stuffing error, timeout, or unknown USB error"; 208 return "bitstuff error, timeout, or unknown USB error";
206 case -EILSEQ: 209 case -EILSEQ:
207 return "CRC mismatch, timeout, or unknown USB error"; 210 return "CRC mismatch, timeout, or unknown USB error";
208 case -ETIME: 211 case -ETIME:
209 return "timed out"; 212 return "USB response timeout";
210 case -EPIPE: 213 case -EPIPE:
211 return "endpoint stalled"; 214 return "endpoint stalled";
212 case -ECOMM: 215 case -ECOMM:
@@ -214,15 +217,15 @@ static char *get_usb_statmsg(int status)
214 case -ENOSR: 217 case -ENOSR:
215 return "OUT buffer underrun"; 218 return "OUT buffer underrun";
216 case -EOVERFLOW: 219 case -EOVERFLOW:
217 return "too much data"; 220 return "endpoint babble";
218 case -EREMOTEIO: 221 case -EREMOTEIO:
219 return "short packet detected"; 222 return "short packet";
220 case -ENODEV: 223 case -ENODEV:
221 return "device removed"; 224 return "device removed";
222 case -EXDEV: 225 case -EXDEV:
223 return "partial isochronous transfer"; 226 return "partial isoc transfer";
224 case -EINVAL: 227 case -EINVAL:
225 return "invalid argument"; 228 return "ISO madness";
226 case -ECONNRESET: 229 case -ECONNRESET:
227 return "unlinked (async)"; 230 return "unlinked (async)";
228 case -ESHUTDOWN: 231 case -ESHUTDOWN:
@@ -350,7 +353,7 @@ static inline void error_hangup(struct bc_state *bcs)
350 * reset Gigaset device because of an unrecoverable error 353 * reset Gigaset device because of an unrecoverable error
351 * This function may be called from any context, and takes care of 354 * This function may be called from any context, and takes care of
352 * scheduling the necessary actions for execution outside of interrupt context. 355 * scheduling the necessary actions for execution outside of interrupt context.
353 * cs->lock must not be held. 356 * cs->hw.bas->lock must not be held.
354 * argument: 357 * argument:
355 * controller state structure 358 * controller state structure
356 */ 359 */
@@ -358,7 +361,9 @@ static inline void error_reset(struct cardstate *cs)
358{ 361{
359 /* reset interrupt pipe to recover (ignore errors) */ 362 /* reset interrupt pipe to recover (ignore errors) */
360 update_basstate(cs->hw.bas, BS_RESETTING, 0); 363 update_basstate(cs->hw.bas, BS_RESETTING, 0);
361 req_submit(cs->bcs, HD_RESET_INTERRUPT_PIPE, 0, BAS_TIMEOUT); 364 if (req_submit(cs->bcs, HD_RESET_INTERRUPT_PIPE, 0, BAS_TIMEOUT))
365 /* submission failed, escalate to USB port reset */
366 usb_queue_reset_device(cs->hw.bas->interface);
362} 367}
363 368
364/* check_pending 369/* check_pending
@@ -438,23 +443,27 @@ static void cmd_in_timeout(unsigned long data)
438 return; 443 return;
439 } 444 }
440 445
441 if (ucs->retry_cmd_in++ < BAS_RETRY) { 446 if (ucs->retry_cmd_in++ >= BAS_RETRY) {
442 dev_notice(cs->dev, "control read: timeout, retry %d\n",
443 ucs->retry_cmd_in);
444 rc = atread_submit(cs, BAS_TIMEOUT);
445 if (rc >= 0 || rc == -ENODEV)
446 /* resubmitted or disconnected */
447 /* - bypass regular exit block */
448 return;
449 } else {
450 dev_err(cs->dev, 447 dev_err(cs->dev,
451 "control read: timeout, giving up after %d tries\n", 448 "control read: timeout, giving up after %d tries\n",
452 ucs->retry_cmd_in); 449 ucs->retry_cmd_in);
450 kfree(ucs->rcvbuf);
451 ucs->rcvbuf = NULL;
452 ucs->rcvbuf_size = 0;
453 error_reset(cs);
454 return;
455 }
456
457 gig_dbg(DEBUG_USBREQ, "%s: timeout, retry %d",
458 __func__, ucs->retry_cmd_in);
459 rc = atread_submit(cs, BAS_TIMEOUT);
460 if (rc < 0) {
461 kfree(ucs->rcvbuf);
462 ucs->rcvbuf = NULL;
463 ucs->rcvbuf_size = 0;
464 if (rc != -ENODEV)
465 error_reset(cs);
453 } 466 }
454 kfree(ucs->rcvbuf);
455 ucs->rcvbuf = NULL;
456 ucs->rcvbuf_size = 0;
457 error_reset(cs);
458} 467}
459 468
460/* read_ctrl_callback 469/* read_ctrl_callback
@@ -470,18 +479,11 @@ static void read_ctrl_callback(struct urb *urb)
470 struct cardstate *cs = inbuf->cs; 479 struct cardstate *cs = inbuf->cs;
471 struct bas_cardstate *ucs = cs->hw.bas; 480 struct bas_cardstate *ucs = cs->hw.bas;
472 int status = urb->status; 481 int status = urb->status;
473 int have_data = 0;
474 unsigned numbytes; 482 unsigned numbytes;
475 int rc; 483 int rc;
476 484
477 update_basstate(ucs, 0, BS_ATRDPEND); 485 update_basstate(ucs, 0, BS_ATRDPEND);
478 wake_up(&ucs->waitqueue); 486 wake_up(&ucs->waitqueue);
479
480 if (!ucs->rcvbuf_size) {
481 dev_warn(cs->dev, "%s: no receive in progress\n", __func__);
482 return;
483 }
484
485 del_timer(&ucs->timer_cmd_in); 487 del_timer(&ucs->timer_cmd_in);
486 488
487 switch (status) { 489 switch (status) {
@@ -495,19 +497,10 @@ static void read_ctrl_callback(struct urb *urb)
495 numbytes = ucs->rcvbuf_size; 497 numbytes = ucs->rcvbuf_size;
496 } 498 }
497 499
498 /* copy received bytes to inbuf */ 500 /* copy received bytes to inbuf, notify event layer */
499 have_data = gigaset_fill_inbuf(inbuf, ucs->rcvbuf, numbytes); 501 if (gigaset_fill_inbuf(inbuf, ucs->rcvbuf, numbytes)) {
500 502 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
501 if (unlikely(numbytes < ucs->rcvbuf_size)) { 503 gigaset_schedule_event(cs);
502 /* incomplete - resubmit for remaining bytes */
503 ucs->rcvbuf_size -= numbytes;
504 ucs->retry_cmd_in = 0;
505 rc = atread_submit(cs, BAS_TIMEOUT);
506 if (rc >= 0 || rc == -ENODEV)
507 /* resubmitted or disconnected */
508 /* - bypass regular exit block */
509 return;
510 error_reset(cs);
511 } 504 }
512 break; 505 break;
513 506
@@ -516,37 +509,32 @@ static void read_ctrl_callback(struct urb *urb)
516 case -EINPROGRESS: /* pending */ 509 case -EINPROGRESS: /* pending */
517 case -ENODEV: /* device removed */ 510 case -ENODEV: /* device removed */
518 case -ESHUTDOWN: /* device shut down */ 511 case -ESHUTDOWN: /* device shut down */
519 /* no action necessary */ 512 /* no further action necessary */
520 gig_dbg(DEBUG_USBREQ, "%s: %s", 513 gig_dbg(DEBUG_USBREQ, "%s: %s",
521 __func__, get_usb_statmsg(status)); 514 __func__, get_usb_statmsg(status));
522 break; 515 break;
523 516
524 default: /* severe trouble */ 517 default: /* other errors: retry */
525 dev_warn(cs->dev, "control read: %s\n",
526 get_usb_statmsg(status));
527 if (ucs->retry_cmd_in++ < BAS_RETRY) { 518 if (ucs->retry_cmd_in++ < BAS_RETRY) {
528 dev_notice(cs->dev, "control read: retry %d\n", 519 gig_dbg(DEBUG_USBREQ, "%s: %s, retry %d", __func__,
529 ucs->retry_cmd_in); 520 get_usb_statmsg(status), ucs->retry_cmd_in);
530 rc = atread_submit(cs, BAS_TIMEOUT); 521 rc = atread_submit(cs, BAS_TIMEOUT);
531 if (rc >= 0 || rc == -ENODEV) 522 if (rc >= 0)
532 /* resubmitted or disconnected */ 523 /* successfully resubmitted, skip freeing */
533 /* - bypass regular exit block */
534 return; 524 return;
535 } else { 525 if (rc == -ENODEV)
536 dev_err(cs->dev, 526 /* disconnect, no further action necessary */
537 "control read: giving up after %d tries\n", 527 break;
538 ucs->retry_cmd_in);
539 } 528 }
529 dev_err(cs->dev, "control read: %s, giving up after %d tries\n",
530 get_usb_statmsg(status), ucs->retry_cmd_in);
540 error_reset(cs); 531 error_reset(cs);
541 } 532 }
542 533
534 /* read finished, free buffer */
543 kfree(ucs->rcvbuf); 535 kfree(ucs->rcvbuf);
544 ucs->rcvbuf = NULL; 536 ucs->rcvbuf = NULL;
545 ucs->rcvbuf_size = 0; 537 ucs->rcvbuf_size = 0;
546 if (have_data) {
547 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
548 gigaset_schedule_event(cs);
549 }
550} 538}
551 539
552/* atread_submit 540/* atread_submit
@@ -605,14 +593,67 @@ static int atread_submit(struct cardstate *cs, int timeout)
605 593
606 if (timeout > 0) { 594 if (timeout > 0) {
607 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout); 595 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
608 ucs->timer_cmd_in.expires = jiffies + timeout * HZ / 10; 596 mod_timer(&ucs->timer_cmd_in, jiffies + timeout * HZ / 10);
609 ucs->timer_cmd_in.data = (unsigned long) cs;
610 ucs->timer_cmd_in.function = cmd_in_timeout;
611 add_timer(&ucs->timer_cmd_in);
612 } 597 }
613 return 0; 598 return 0;
614} 599}
615 600
601/* int_in_work
602 * workqueue routine to clear halt on interrupt in endpoint
603 */
604
605static void int_in_work(struct work_struct *work)
606{
607 struct bas_cardstate *ucs =
608 container_of(work, struct bas_cardstate, int_in_wq);
609 struct urb *urb = ucs->urb_int_in;
610 struct cardstate *cs = urb->context;
611 int rc;
612
613 /* clear halt condition */
614 rc = usb_clear_halt(ucs->udev, urb->pipe);
615 gig_dbg(DEBUG_USBREQ, "clear_halt: %s", get_usb_rcmsg(rc));
616 if (rc == 0)
617 /* success, resubmit interrupt read URB */
618 rc = usb_submit_urb(urb, GFP_ATOMIC);
619 if (rc != 0 && rc != -ENODEV) {
620 dev_err(cs->dev, "clear halt failed: %s\n", get_usb_rcmsg(rc));
621 rc = usb_lock_device_for_reset(ucs->udev, ucs->interface);
622 if (rc == 0) {
623 rc = usb_reset_device(ucs->udev);
624 usb_unlock_device(ucs->udev);
625 }
626 }
627 ucs->retry_int_in = 0;
628}
629
630/* int_in_resubmit
631 * timer routine for interrupt read delayed resubmit
632 * argument:
633 * controller state structure
634 */
635static void int_in_resubmit(unsigned long data)
636{
637 struct cardstate *cs = (struct cardstate *) data;
638 struct bas_cardstate *ucs = cs->hw.bas;
639 int rc;
640
641 if (ucs->retry_int_in++ >= BAS_RETRY) {
642 dev_err(cs->dev, "interrupt read: giving up after %d tries\n",
643 ucs->retry_int_in);
644 usb_queue_reset_device(ucs->interface);
645 return;
646 }
647
648 gig_dbg(DEBUG_USBREQ, "%s: retry %d", __func__, ucs->retry_int_in);
649 rc = usb_submit_urb(ucs->urb_int_in, GFP_ATOMIC);
650 if (rc != 0 && rc != -ENODEV) {
651 dev_err(cs->dev, "could not resubmit interrupt URB: %s\n",
652 get_usb_rcmsg(rc));
653 usb_queue_reset_device(ucs->interface);
654 }
655}
656
616/* read_int_callback 657/* read_int_callback
617 * USB completion handler for interrupt pipe input 658 * USB completion handler for interrupt pipe input
618 * called by the USB subsystem in interrupt context 659 * called by the USB subsystem in interrupt context
@@ -633,19 +674,29 @@ static void read_int_callback(struct urb *urb)
633 674
634 switch (status) { 675 switch (status) {
635 case 0: /* success */ 676 case 0: /* success */
677 ucs->retry_int_in = 0;
636 break; 678 break;
679 case -EPIPE: /* endpoint stalled */
680 schedule_work(&ucs->int_in_wq);
681 /* fall through */
637 case -ENOENT: /* cancelled */ 682 case -ENOENT: /* cancelled */
638 case -ECONNRESET: /* cancelled (async) */ 683 case -ECONNRESET: /* cancelled (async) */
639 case -EINPROGRESS: /* pending */ 684 case -EINPROGRESS: /* pending */
640 /* ignore silently */ 685 case -ENODEV: /* device removed */
686 case -ESHUTDOWN: /* device shut down */
687 /* no further action necessary */
641 gig_dbg(DEBUG_USBREQ, "%s: %s", 688 gig_dbg(DEBUG_USBREQ, "%s: %s",
642 __func__, get_usb_statmsg(status)); 689 __func__, get_usb_statmsg(status));
643 return; 690 return;
644 case -ENODEV: /* device removed */ 691 case -EPROTO: /* protocol error or unplug */
645 case -ESHUTDOWN: /* device shut down */ 692 case -EILSEQ:
646 gig_dbg(DEBUG_USBREQ, "%s: device disconnected", __func__); 693 case -ETIME:
694 /* resubmit after delay */
695 gig_dbg(DEBUG_USBREQ, "%s: %s",
696 __func__, get_usb_statmsg(status));
697 mod_timer(&ucs->timer_int_in, jiffies + HZ / 10);
647 return; 698 return;
648 default: /* severe trouble */ 699 default: /* other errors: just resubmit */
649 dev_warn(cs->dev, "interrupt read: %s\n", 700 dev_warn(cs->dev, "interrupt read: %s\n",
650 get_usb_statmsg(status)); 701 get_usb_statmsg(status));
651 goto resubmit; 702 goto resubmit;
@@ -723,6 +774,13 @@ static void read_int_callback(struct urb *urb)
723 break; 774 break;
724 } 775 }
725 spin_lock_irqsave(&cs->lock, flags); 776 spin_lock_irqsave(&cs->lock, flags);
777 if (ucs->basstate & BS_ATRDPEND) {
778 spin_unlock_irqrestore(&cs->lock, flags);
779 dev_warn(cs->dev,
780 "HD_RECEIVEATDATA_ACK(%d) during HD_READ_ATMESSAGE(%d) ignored\n",
781 l, ucs->rcvbuf_size);
782 break;
783 }
726 if (ucs->rcvbuf_size) { 784 if (ucs->rcvbuf_size) {
727 /* throw away previous buffer - we have no queue */ 785 /* throw away previous buffer - we have no queue */
728 dev_err(cs->dev, 786 dev_err(cs->dev,
@@ -735,7 +793,6 @@ static void read_int_callback(struct urb *urb)
735 if (ucs->rcvbuf == NULL) { 793 if (ucs->rcvbuf == NULL) {
736 spin_unlock_irqrestore(&cs->lock, flags); 794 spin_unlock_irqrestore(&cs->lock, flags);
737 dev_err(cs->dev, "out of memory receiving AT data\n"); 795 dev_err(cs->dev, "out of memory receiving AT data\n");
738 error_reset(cs);
739 break; 796 break;
740 } 797 }
741 ucs->rcvbuf_size = l; 798 ucs->rcvbuf_size = l;
@@ -745,13 +802,10 @@ static void read_int_callback(struct urb *urb)
745 kfree(ucs->rcvbuf); 802 kfree(ucs->rcvbuf);
746 ucs->rcvbuf = NULL; 803 ucs->rcvbuf = NULL;
747 ucs->rcvbuf_size = 0; 804 ucs->rcvbuf_size = 0;
748 if (rc != -ENODEV) {
749 spin_unlock_irqrestore(&cs->lock, flags);
750 error_reset(cs);
751 break;
752 }
753 } 805 }
754 spin_unlock_irqrestore(&cs->lock, flags); 806 spin_unlock_irqrestore(&cs->lock, flags);
807 if (rc < 0 && rc != -ENODEV)
808 error_reset(cs);
755 break; 809 break;
756 810
757 case HD_RESET_INTERRUPT_PIPE_ACK: 811 case HD_RESET_INTERRUPT_PIPE_ACK:
@@ -818,6 +872,7 @@ static void read_iso_callback(struct urb *urb)
818 tasklet_hi_schedule(&ubc->rcvd_tasklet); 872 tasklet_hi_schedule(&ubc->rcvd_tasklet);
819 } else { 873 } else {
820 /* tasklet still busy, drop data and resubmit URB */ 874 /* tasklet still busy, drop data and resubmit URB */
875 gig_dbg(DEBUG_ISO, "%s: overrun", __func__);
821 ubc->loststatus = status; 876 ubc->loststatus = status;
822 for (i = 0; i < BAS_NUMFRAMES; i++) { 877 for (i = 0; i < BAS_NUMFRAMES; i++) {
823 ubc->isoinlost += urb->iso_frame_desc[i].actual_length; 878 ubc->isoinlost += urb->iso_frame_desc[i].actual_length;
@@ -833,13 +888,11 @@ static void read_iso_callback(struct urb *urb)
833 urb->dev = bcs->cs->hw.bas->udev; 888 urb->dev = bcs->cs->hw.bas->udev;
834 urb->transfer_flags = URB_ISO_ASAP; 889 urb->transfer_flags = URB_ISO_ASAP;
835 urb->number_of_packets = BAS_NUMFRAMES; 890 urb->number_of_packets = BAS_NUMFRAMES;
836 gig_dbg(DEBUG_ISO, "%s: isoc read overrun/resubmit",
837 __func__);
838 rc = usb_submit_urb(urb, GFP_ATOMIC); 891 rc = usb_submit_urb(urb, GFP_ATOMIC);
839 if (unlikely(rc != 0 && rc != -ENODEV)) { 892 if (unlikely(rc != 0 && rc != -ENODEV)) {
840 dev_err(bcs->cs->dev, 893 dev_err(bcs->cs->dev,
841 "could not resubmit isochronous read " 894 "could not resubmit isoc read URB: %s\n",
842 "URB: %s\n", get_usb_rcmsg(rc)); 895 get_usb_rcmsg(rc));
843 dump_urb(DEBUG_ISO, "isoc read", urb); 896 dump_urb(DEBUG_ISO, "isoc read", urb);
844 error_hangup(bcs); 897 error_hangup(bcs);
845 } 898 }
@@ -1081,7 +1134,7 @@ static int submit_iso_write_urb(struct isow_urbctx_t *ucx)
1081 gig_dbg(DEBUG_ISO, "%s: disconnected", __func__); 1134 gig_dbg(DEBUG_ISO, "%s: disconnected", __func__);
1082 else 1135 else
1083 dev_err(ucx->bcs->cs->dev, 1136 dev_err(ucx->bcs->cs->dev,
1084 "could not submit isochronous write URB: %s\n", 1137 "could not submit isoc write URB: %s\n",
1085 get_usb_rcmsg(rc)); 1138 get_usb_rcmsg(rc));
1086 return rc; 1139 return rc;
1087 } 1140 }
@@ -1126,7 +1179,7 @@ static void write_iso_tasklet(unsigned long data)
1126 ubc->isooutovfl = NULL; 1179 ubc->isooutovfl = NULL;
1127 spin_unlock_irqrestore(&ubc->isooutlock, flags); 1180 spin_unlock_irqrestore(&ubc->isooutlock, flags);
1128 if (ovfl) { 1181 if (ovfl) {
1129 dev_err(cs->dev, "isochronous write buffer underrun\n"); 1182 dev_err(cs->dev, "isoc write underrun\n");
1130 error_hangup(bcs); 1183 error_hangup(bcs);
1131 break; 1184 break;
1132 } 1185 }
@@ -1151,7 +1204,7 @@ static void write_iso_tasklet(unsigned long data)
1151 if (next) { 1204 if (next) {
1152 /* couldn't put it back */ 1205 /* couldn't put it back */
1153 dev_err(cs->dev, 1206 dev_err(cs->dev,
1154 "losing isochronous write URB\n"); 1207 "losing isoc write URB\n");
1155 error_hangup(bcs); 1208 error_hangup(bcs);
1156 } 1209 }
1157 } 1210 }
@@ -1178,10 +1231,10 @@ static void write_iso_tasklet(unsigned long data)
1178 if (ifd->status || 1231 if (ifd->status ||
1179 ifd->actual_length != ifd->length) { 1232 ifd->actual_length != ifd->length) {
1180 dev_warn(cs->dev, 1233 dev_warn(cs->dev,
1181 "isochronous write: frame %d: %s, " 1234 "isoc write: frame %d[%d/%d]: %s\n",
1182 "only %d of %d bytes sent\n", 1235 i, ifd->actual_length,
1183 i, get_usb_statmsg(ifd->status), 1236 ifd->length,
1184 ifd->actual_length, ifd->length); 1237 get_usb_statmsg(ifd->status));
1185 offset = (ifd->offset + 1238 offset = (ifd->offset +
1186 ifd->actual_length) 1239 ifd->actual_length)
1187 % BAS_OUTBUFSIZE; 1240 % BAS_OUTBUFSIZE;
@@ -1190,11 +1243,11 @@ static void write_iso_tasklet(unsigned long data)
1190 } 1243 }
1191 break; 1244 break;
1192 case -EPIPE: /* stall - probably underrun */ 1245 case -EPIPE: /* stall - probably underrun */
1193 dev_err(cs->dev, "isochronous write stalled\n"); 1246 dev_err(cs->dev, "isoc write: stalled\n");
1194 error_hangup(bcs); 1247 error_hangup(bcs);
1195 break; 1248 break;
1196 default: /* severe trouble */ 1249 default: /* other errors */
1197 dev_warn(cs->dev, "isochronous write: %s\n", 1250 dev_warn(cs->dev, "isoc write: %s\n",
1198 get_usb_statmsg(status)); 1251 get_usb_statmsg(status));
1199 } 1252 }
1200 1253
@@ -1250,6 +1303,7 @@ static void read_iso_tasklet(unsigned long data)
1250 struct cardstate *cs = bcs->cs; 1303 struct cardstate *cs = bcs->cs;
1251 struct urb *urb; 1304 struct urb *urb;
1252 int status; 1305 int status;
1306 struct usb_iso_packet_descriptor *ifd;
1253 char *rcvbuf; 1307 char *rcvbuf;
1254 unsigned long flags; 1308 unsigned long flags;
1255 int totleft, numbytes, offset, frame, rc; 1309 int totleft, numbytes, offset, frame, rc;
@@ -1267,8 +1321,7 @@ static void read_iso_tasklet(unsigned long data)
1267 ubc->isoindone = NULL; 1321 ubc->isoindone = NULL;
1268 if (unlikely(ubc->loststatus != -EINPROGRESS)) { 1322 if (unlikely(ubc->loststatus != -EINPROGRESS)) {
1269 dev_warn(cs->dev, 1323 dev_warn(cs->dev,
1270 "isochronous read overrun, " 1324 "isoc read overrun, URB dropped (status: %s, %d bytes)\n",
1271 "dropped URB with status: %s, %d bytes lost\n",
1272 get_usb_statmsg(ubc->loststatus), 1325 get_usb_statmsg(ubc->loststatus),
1273 ubc->isoinlost); 1326 ubc->isoinlost);
1274 ubc->loststatus = -EINPROGRESS; 1327 ubc->loststatus = -EINPROGRESS;
@@ -1298,11 +1351,11 @@ static void read_iso_tasklet(unsigned long data)
1298 __func__, get_usb_statmsg(status)); 1351 __func__, get_usb_statmsg(status));
1299 continue; /* -> skip */ 1352 continue; /* -> skip */
1300 case -EPIPE: 1353 case -EPIPE:
1301 dev_err(cs->dev, "isochronous read stalled\n"); 1354 dev_err(cs->dev, "isoc read: stalled\n");
1302 error_hangup(bcs); 1355 error_hangup(bcs);
1303 continue; /* -> skip */ 1356 continue; /* -> skip */
1304 default: /* severe trouble */ 1357 default: /* other error */
1305 dev_warn(cs->dev, "isochronous read: %s\n", 1358 dev_warn(cs->dev, "isoc read: %s\n",
1306 get_usb_statmsg(status)); 1359 get_usb_statmsg(status));
1307 goto error; 1360 goto error;
1308 } 1361 }
@@ -1310,40 +1363,52 @@ static void read_iso_tasklet(unsigned long data)
1310 rcvbuf = urb->transfer_buffer; 1363 rcvbuf = urb->transfer_buffer;
1311 totleft = urb->actual_length; 1364 totleft = urb->actual_length;
1312 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) { 1365 for (frame = 0; totleft > 0 && frame < BAS_NUMFRAMES; frame++) {
1313 numbytes = urb->iso_frame_desc[frame].actual_length; 1366 ifd = &urb->iso_frame_desc[frame];
1314 if (unlikely(urb->iso_frame_desc[frame].status)) 1367 numbytes = ifd->actual_length;
1368 switch (ifd->status) {
1369 case 0: /* success */
1370 break;
1371 case -EPROTO: /* protocol error or unplug */
1372 case -EILSEQ:
1373 case -ETIME:
1374 /* probably just disconnected, ignore */
1375 gig_dbg(DEBUG_ISO,
1376 "isoc read: frame %d[%d]: %s\n",
1377 frame, numbytes,
1378 get_usb_statmsg(ifd->status));
1379 break;
1380 default: /* other error */
1381 /* report, assume transferred bytes are ok */
1315 dev_warn(cs->dev, 1382 dev_warn(cs->dev,
1316 "isochronous read: frame %d[%d]: %s\n", 1383 "isoc read: frame %d[%d]: %s\n",
1317 frame, numbytes, 1384 frame, numbytes,
1318 get_usb_statmsg( 1385 get_usb_statmsg(ifd->status));
1319 urb->iso_frame_desc[frame].status)); 1386 }
1320 if (unlikely(numbytes > BAS_MAXFRAME)) 1387 if (unlikely(numbytes > BAS_MAXFRAME))
1321 dev_warn(cs->dev, 1388 dev_warn(cs->dev,
1322 "isochronous read: frame %d: " 1389 "isoc read: frame %d[%d]: %s\n",
1323 "numbytes (%d) > BAS_MAXFRAME\n", 1390 frame, numbytes,
1324 frame, numbytes); 1391 "exceeds max frame size");
1325 if (unlikely(numbytes > totleft)) { 1392 if (unlikely(numbytes > totleft)) {
1326 dev_warn(cs->dev, 1393 dev_warn(cs->dev,
1327 "isochronous read: frame %d: " 1394 "isoc read: frame %d[%d]: %s\n",
1328 "numbytes (%d) > totleft (%d)\n", 1395 frame, numbytes,
1329 frame, numbytes, totleft); 1396 "exceeds total transfer length");
1330 numbytes = totleft; 1397 numbytes = totleft;
1331 } 1398 }
1332 offset = urb->iso_frame_desc[frame].offset; 1399 offset = ifd->offset;
1333 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) { 1400 if (unlikely(offset + numbytes > BAS_INBUFSIZE)) {
1334 dev_warn(cs->dev, 1401 dev_warn(cs->dev,
1335 "isochronous read: frame %d: " 1402 "isoc read: frame %d[%d]: %s\n",
1336 "offset (%d) + numbytes (%d) " 1403 frame, numbytes,
1337 "> BAS_INBUFSIZE\n", 1404 "exceeds end of buffer");
1338 frame, offset, numbytes);
1339 numbytes = BAS_INBUFSIZE - offset; 1405 numbytes = BAS_INBUFSIZE - offset;
1340 } 1406 }
1341 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs); 1407 gigaset_isoc_receive(rcvbuf + offset, numbytes, bcs);
1342 totleft -= numbytes; 1408 totleft -= numbytes;
1343 } 1409 }
1344 if (unlikely(totleft > 0)) 1410 if (unlikely(totleft > 0))
1345 dev_warn(cs->dev, 1411 dev_warn(cs->dev, "isoc read: %d data bytes missing\n",
1346 "isochronous read: %d data bytes missing\n",
1347 totleft); 1412 totleft);
1348 1413
1349error: 1414error:
@@ -1359,9 +1424,9 @@ error:
1359 rc = usb_submit_urb(urb, GFP_ATOMIC); 1424 rc = usb_submit_urb(urb, GFP_ATOMIC);
1360 if (unlikely(rc != 0 && rc != -ENODEV)) { 1425 if (unlikely(rc != 0 && rc != -ENODEV)) {
1361 dev_err(cs->dev, 1426 dev_err(cs->dev,
1362 "could not resubmit isochronous read URB: %s\n", 1427 "could not resubmit isoc read URB: %s\n",
1363 get_usb_rcmsg(rc)); 1428 get_usb_rcmsg(rc));
1364 dump_urb(DEBUG_ISO, "resubmit iso read", urb); 1429 dump_urb(DEBUG_ISO, "resubmit isoc read", urb);
1365 error_hangup(bcs); 1430 error_hangup(bcs);
1366 } 1431 }
1367 } 1432 }
@@ -1373,12 +1438,12 @@ error:
1373/* req_timeout 1438/* req_timeout
1374 * timeout routine for control output request 1439 * timeout routine for control output request
1375 * argument: 1440 * argument:
1376 * B channel control structure 1441 * controller state structure
1377 */ 1442 */
1378static void req_timeout(unsigned long data) 1443static void req_timeout(unsigned long data)
1379{ 1444{
1380 struct bc_state *bcs = (struct bc_state *) data; 1445 struct cardstate *cs = (struct cardstate *) data;
1381 struct bas_cardstate *ucs = bcs->cs->hw.bas; 1446 struct bas_cardstate *ucs = cs->hw.bas;
1382 int pending; 1447 int pending;
1383 unsigned long flags; 1448 unsigned long flags;
1384 1449
@@ -1395,38 +1460,44 @@ static void req_timeout(unsigned long data)
1395 break; 1460 break;
1396 1461
1397 case HD_OPEN_ATCHANNEL: 1462 case HD_OPEN_ATCHANNEL:
1398 dev_err(bcs->cs->dev, "timeout opening AT channel\n"); 1463 dev_err(cs->dev, "timeout opening AT channel\n");
1399 error_reset(bcs->cs); 1464 error_reset(cs);
1400 break; 1465 break;
1401 1466
1402 case HD_OPEN_B2CHANNEL:
1403 case HD_OPEN_B1CHANNEL: 1467 case HD_OPEN_B1CHANNEL:
1404 dev_err(bcs->cs->dev, "timeout opening channel %d\n", 1468 dev_err(cs->dev, "timeout opening channel 1\n");
1405 bcs->channel + 1); 1469 error_hangup(&cs->bcs[0]);
1406 error_hangup(bcs); 1470 break;
1471
1472 case HD_OPEN_B2CHANNEL:
1473 dev_err(cs->dev, "timeout opening channel 2\n");
1474 error_hangup(&cs->bcs[1]);
1407 break; 1475 break;
1408 1476
1409 case HD_CLOSE_ATCHANNEL: 1477 case HD_CLOSE_ATCHANNEL:
1410 dev_err(bcs->cs->dev, "timeout closing AT channel\n"); 1478 dev_err(cs->dev, "timeout closing AT channel\n");
1411 error_reset(bcs->cs); 1479 error_reset(cs);
1412 break; 1480 break;
1413 1481
1414 case HD_CLOSE_B2CHANNEL:
1415 case HD_CLOSE_B1CHANNEL: 1482 case HD_CLOSE_B1CHANNEL:
1416 dev_err(bcs->cs->dev, "timeout closing channel %d\n", 1483 dev_err(cs->dev, "timeout closing channel 1\n");
1417 bcs->channel + 1); 1484 error_reset(cs);
1418 error_reset(bcs->cs); 1485 break;
1486
1487 case HD_CLOSE_B2CHANNEL:
1488 dev_err(cs->dev, "timeout closing channel 2\n");
1489 error_reset(cs);
1419 break; 1490 break;
1420 1491
1421 case HD_RESET_INTERRUPT_PIPE: 1492 case HD_RESET_INTERRUPT_PIPE:
1422 /* error recovery escalation */ 1493 /* error recovery escalation */
1423 dev_err(bcs->cs->dev, 1494 dev_err(cs->dev,
1424 "reset interrupt pipe timeout, attempting USB reset\n"); 1495 "reset interrupt pipe timeout, attempting USB reset\n");
1425 usb_queue_reset_device(bcs->cs->hw.bas->interface); 1496 usb_queue_reset_device(ucs->interface);
1426 break; 1497 break;
1427 1498
1428 default: 1499 default:
1429 dev_warn(bcs->cs->dev, "request 0x%02x timed out, clearing\n", 1500 dev_warn(cs->dev, "request 0x%02x timed out, clearing\n",
1430 pending); 1501 pending);
1431 } 1502 }
1432 1503
@@ -1557,10 +1628,7 @@ static int req_submit(struct bc_state *bcs, int req, int val, int timeout)
1557 1628
1558 if (timeout > 0) { 1629 if (timeout > 0) {
1559 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout); 1630 gig_dbg(DEBUG_USBREQ, "setting timeout of %d/10 secs", timeout);
1560 ucs->timer_ctrl.expires = jiffies + timeout * HZ / 10; 1631 mod_timer(&ucs->timer_ctrl, jiffies + timeout * HZ / 10);
1561 ucs->timer_ctrl.data = (unsigned long) bcs;
1562 ucs->timer_ctrl.function = req_timeout;
1563 add_timer(&ucs->timer_ctrl);
1564 } 1632 }
1565 1633
1566 spin_unlock_irqrestore(&ucs->lock, flags); 1634 spin_unlock_irqrestore(&ucs->lock, flags);
@@ -1590,21 +1658,20 @@ static int gigaset_init_bchannel(struct bc_state *bcs)
1590 1658
1591 if (cs->hw.bas->basstate & BS_SUSPEND) { 1659 if (cs->hw.bas->basstate & BS_SUSPEND) {
1592 dev_notice(cs->dev, 1660 dev_notice(cs->dev,
1593 "not starting isochronous I/O, " 1661 "not starting isoc I/O, suspend in progress\n");
1594 "suspend in progress\n");
1595 spin_unlock_irqrestore(&cs->lock, flags); 1662 spin_unlock_irqrestore(&cs->lock, flags);
1596 return -EHOSTUNREACH; 1663 return -EHOSTUNREACH;
1597 } 1664 }
1598 1665
1599 ret = starturbs(bcs); 1666 ret = starturbs(bcs);
1600 if (ret < 0) { 1667 if (ret < 0) {
1668 spin_unlock_irqrestore(&cs->lock, flags);
1601 dev_err(cs->dev, 1669 dev_err(cs->dev,
1602 "could not start isochronous I/O for channel B%d: %s\n", 1670 "could not start isoc I/O for channel B%d: %s\n",
1603 bcs->channel + 1, 1671 bcs->channel + 1,
1604 ret == -EFAULT ? "null URB" : get_usb_rcmsg(ret)); 1672 ret == -EFAULT ? "null URB" : get_usb_rcmsg(ret));
1605 if (ret != -ENODEV) 1673 if (ret != -ENODEV)
1606 error_hangup(bcs); 1674 error_hangup(bcs);
1607 spin_unlock_irqrestore(&cs->lock, flags);
1608 return ret; 1675 return ret;
1609 } 1676 }
1610 1677
@@ -1614,11 +1681,11 @@ static int gigaset_init_bchannel(struct bc_state *bcs)
1614 dev_err(cs->dev, "could not open channel B%d\n", 1681 dev_err(cs->dev, "could not open channel B%d\n",
1615 bcs->channel + 1); 1682 bcs->channel + 1);
1616 stopurbs(bcs->hw.bas); 1683 stopurbs(bcs->hw.bas);
1617 if (ret != -ENODEV)
1618 error_hangup(bcs);
1619 } 1684 }
1620 1685
1621 spin_unlock_irqrestore(&cs->lock, flags); 1686 spin_unlock_irqrestore(&cs->lock, flags);
1687 if (ret < 0 && ret != -ENODEV)
1688 error_hangup(bcs);
1622 return ret; 1689 return ret;
1623} 1690}
1624 1691
@@ -1826,10 +1893,7 @@ static int atwrite_submit(struct cardstate *cs, unsigned char *buf, int len)
1826 if (!(update_basstate(ucs, BS_ATTIMER, BS_ATREADY) & BS_ATTIMER)) { 1893 if (!(update_basstate(ucs, BS_ATTIMER, BS_ATREADY) & BS_ATTIMER)) {
1827 gig_dbg(DEBUG_OUTPUT, "setting ATREADY timeout of %d/10 secs", 1894 gig_dbg(DEBUG_OUTPUT, "setting ATREADY timeout of %d/10 secs",
1828 ATRDY_TIMEOUT); 1895 ATRDY_TIMEOUT);
1829 ucs->timer_atrdy.expires = jiffies + ATRDY_TIMEOUT * HZ / 10; 1896 mod_timer(&ucs->timer_atrdy, jiffies + ATRDY_TIMEOUT * HZ / 10);
1830 ucs->timer_atrdy.data = (unsigned long) cs;
1831 ucs->timer_atrdy.function = atrdy_timeout;
1832 add_timer(&ucs->timer_atrdy);
1833 } 1897 }
1834 return 0; 1898 return 0;
1835} 1899}
@@ -1914,6 +1978,28 @@ static int gigaset_write_cmd(struct cardstate *cs, struct cmdbuf_t *cb)
1914 * The next command will reopen the AT channel automatically. 1978 * The next command will reopen the AT channel automatically.
1915 */ 1979 */
1916 if (cb->len == 3 && !memcmp(cb->buf, "+++", 3)) { 1980 if (cb->len == 3 && !memcmp(cb->buf, "+++", 3)) {
1981 /* If an HD_RECEIVEATDATA_ACK message remains unhandled
1982 * because of an error, the base never sends another one.
1983 * The response channel is thus effectively blocked.
1984 * Closing and reopening the AT channel does *not* clear
1985 * this condition.
1986 * As a stopgap measure, submit a zero-length AT read
1987 * before closing the AT channel. This has the undocumented
1988 * effect of triggering a new HD_RECEIVEATDATA_ACK message
1989 * from the base if necessary.
1990 * The subsequent AT channel close then discards any pending
1991 * messages.
1992 */
1993 spin_lock_irqsave(&cs->lock, flags);
1994 if (!(cs->hw.bas->basstate & BS_ATRDPEND)) {
1995 kfree(cs->hw.bas->rcvbuf);
1996 cs->hw.bas->rcvbuf = NULL;
1997 cs->hw.bas->rcvbuf_size = 0;
1998 cs->hw.bas->retry_cmd_in = 0;
1999 atread_submit(cs, 0);
2000 }
2001 spin_unlock_irqrestore(&cs->lock, flags);
2002
1917 rc = req_submit(cs->bcs, HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT); 2003 rc = req_submit(cs->bcs, HD_CLOSE_ATCHANNEL, 0, BAS_TIMEOUT);
1918 if (cb->wake_tasklet) 2004 if (cb->wake_tasklet)
1919 tasklet_schedule(cb->wake_tasklet); 2005 tasklet_schedule(cb->wake_tasklet);
@@ -2010,7 +2096,7 @@ static int gigaset_freebcshw(struct bc_state *bcs)
2010 2096
2011 /* kill URBs and tasklets before freeing - better safe than sorry */ 2097 /* kill URBs and tasklets before freeing - better safe than sorry */
2012 ubc->running = 0; 2098 ubc->running = 0;
2013 gig_dbg(DEBUG_INIT, "%s: killing iso URBs", __func__); 2099 gig_dbg(DEBUG_INIT, "%s: killing isoc URBs", __func__);
2014 for (i = 0; i < BAS_OUTURBS; ++i) { 2100 for (i = 0; i < BAS_OUTURBS; ++i) {
2015 usb_kill_urb(ubc->isoouturbs[i].urb); 2101 usb_kill_urb(ubc->isoouturbs[i].urb);
2016 usb_free_urb(ubc->isoouturbs[i].urb); 2102 usb_free_urb(ubc->isoouturbs[i].urb);
@@ -2131,10 +2217,12 @@ static int gigaset_initcshw(struct cardstate *cs)
2131 ucs->pending = 0; 2217 ucs->pending = 0;
2132 2218
2133 ucs->basstate = 0; 2219 ucs->basstate = 0;
2134 init_timer(&ucs->timer_ctrl); 2220 setup_timer(&ucs->timer_ctrl, req_timeout, (unsigned long) cs);
2135 init_timer(&ucs->timer_atrdy); 2221 setup_timer(&ucs->timer_atrdy, atrdy_timeout, (unsigned long) cs);
2136 init_timer(&ucs->timer_cmd_in); 2222 setup_timer(&ucs->timer_cmd_in, cmd_in_timeout, (unsigned long) cs);
2223 setup_timer(&ucs->timer_int_in, int_in_resubmit, (unsigned long) cs);
2137 init_waitqueue_head(&ucs->waitqueue); 2224 init_waitqueue_head(&ucs->waitqueue);
2225 INIT_WORK(&ucs->int_in_wq, int_in_work);
2138 2226
2139 return 1; 2227 return 1;
2140} 2228}
@@ -2282,6 +2370,7 @@ static int gigaset_probe(struct usb_interface *interface,
2282 get_usb_rcmsg(rc)); 2370 get_usb_rcmsg(rc));
2283 goto error; 2371 goto error;
2284 } 2372 }
2373 ucs->retry_int_in = 0;
2285 2374
2286 /* tell the device that the driver is ready */ 2375 /* tell the device that the driver is ready */
2287 rc = req_submit(cs->bcs, HD_DEVICE_INIT_ACK, 0, 0); 2376 rc = req_submit(cs->bcs, HD_DEVICE_INIT_ACK, 0, 0);
@@ -2334,10 +2423,12 @@ static void gigaset_disconnect(struct usb_interface *interface)
2334 /* stop driver (common part) */ 2423 /* stop driver (common part) */
2335 gigaset_stop(cs); 2424 gigaset_stop(cs);
2336 2425
2337 /* stop timers and URBs, free ressources */ 2426 /* stop delayed work and URBs, free ressources */
2338 del_timer_sync(&ucs->timer_ctrl); 2427 del_timer_sync(&ucs->timer_ctrl);
2339 del_timer_sync(&ucs->timer_atrdy); 2428 del_timer_sync(&ucs->timer_atrdy);
2340 del_timer_sync(&ucs->timer_cmd_in); 2429 del_timer_sync(&ucs->timer_cmd_in);
2430 del_timer_sync(&ucs->timer_int_in);
2431 cancel_work_sync(&ucs->int_in_wq);
2341 freeurbs(cs); 2432 freeurbs(cs);
2342 usb_set_intfdata(interface, NULL); 2433 usb_set_intfdata(interface, NULL);
2343 kfree(ucs->rcvbuf); 2434 kfree(ucs->rcvbuf);
@@ -2400,10 +2491,14 @@ static int gigaset_suspend(struct usb_interface *intf, pm_message_t message)
2400 /* in case of timeout, proceed anyway */ 2491 /* in case of timeout, proceed anyway */
2401 } 2492 }
2402 2493
2403 /* kill all URBs and timers that might still be pending */ 2494 /* kill all URBs and delayed work that might still be pending */
2404 usb_kill_urb(ucs->urb_ctrl); 2495 usb_kill_urb(ucs->urb_ctrl);
2405 usb_kill_urb(ucs->urb_int_in); 2496 usb_kill_urb(ucs->urb_int_in);
2406 del_timer_sync(&ucs->timer_ctrl); 2497 del_timer_sync(&ucs->timer_ctrl);
2498 del_timer_sync(&ucs->timer_atrdy);
2499 del_timer_sync(&ucs->timer_cmd_in);
2500 del_timer_sync(&ucs->timer_int_in);
2501 cancel_work_sync(&ucs->int_in_wq);
2407 2502
2408 gig_dbg(DEBUG_SUSPEND, "suspend complete"); 2503 gig_dbg(DEBUG_SUSPEND, "suspend complete");
2409 return 0; 2504 return 0;
@@ -2425,6 +2520,7 @@ static int gigaset_resume(struct usb_interface *intf)
2425 get_usb_rcmsg(rc)); 2520 get_usb_rcmsg(rc));
2426 return rc; 2521 return rc;
2427 } 2522 }
2523 ucs->retry_int_in = 0;
2428 2524
2429 /* clear suspend flag to reallow activity */ 2525 /* clear suspend flag to reallow activity */
2430 update_basstate(ucs, 0, BS_SUSPEND); 2526 update_basstate(ucs, 0, BS_SUSPEND);