aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/class
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/class')
-rw-r--r--drivers/usb/class/cdc-acm.c503
-rw-r--r--drivers/usb/class/cdc-acm.h7
-rw-r--r--drivers/usb/class/usblp.c6
-rw-r--r--drivers/usb/class/usbtmc.c6
4 files changed, 324 insertions, 198 deletions
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 7a1164dd1d37..38bfdb0f6660 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -16,7 +16,8 @@
16 * v0.9 - thorough cleaning, URBification, almost a rewrite 16 * v0.9 - thorough cleaning, URBification, almost a rewrite
17 * v0.10 - some more cleanups 17 * v0.10 - some more cleanups
18 * v0.11 - fixed flow control, read error doesn't stop reads 18 * v0.11 - fixed flow control, read error doesn't stop reads
19 * v0.12 - added TIOCM ioctls, added break handling, made struct acm kmalloced 19 * v0.12 - added TIOCM ioctls, added break handling, made struct acm
20 * kmalloced
20 * v0.13 - added termios, added hangup 21 * v0.13 - added termios, added hangup
21 * v0.14 - sized down struct acm 22 * v0.14 - sized down struct acm
22 * v0.15 - fixed flow control again - characters could be lost 23 * v0.15 - fixed flow control again - characters could be lost
@@ -62,7 +63,7 @@
62#include <linux/tty_flip.h> 63#include <linux/tty_flip.h>
63#include <linux/module.h> 64#include <linux/module.h>
64#include <linux/mutex.h> 65#include <linux/mutex.h>
65#include <asm/uaccess.h> 66#include <linux/uaccess.h>
66#include <linux/usb.h> 67#include <linux/usb.h>
67#include <linux/usb/cdc.h> 68#include <linux/usb/cdc.h>
68#include <asm/byteorder.h> 69#include <asm/byteorder.h>
@@ -87,7 +88,10 @@ static struct acm *acm_table[ACM_TTY_MINORS];
87 88
88static DEFINE_MUTEX(open_mutex); 89static DEFINE_MUTEX(open_mutex);
89 90
90#define ACM_READY(acm) (acm && acm->dev && acm->used) 91#define ACM_READY(acm) (acm && acm->dev && acm->port.count)
92
93static const struct tty_port_operations acm_port_ops = {
94};
91 95
92#ifdef VERBOSE_DEBUG 96#ifdef VERBOSE_DEBUG
93#define verbose 1 97#define verbose 1
@@ -99,13 +103,15 @@ static DEFINE_MUTEX(open_mutex);
99 * Functions for ACM control messages. 103 * Functions for ACM control messages.
100 */ 104 */
101 105
102static int acm_ctrl_msg(struct acm *acm, int request, int value, void *buf, int len) 106static int acm_ctrl_msg(struct acm *acm, int request, int value,
107 void *buf, int len)
103{ 108{
104 int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), 109 int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0),
105 request, USB_RT_ACM, value, 110 request, USB_RT_ACM, value,
106 acm->control->altsetting[0].desc.bInterfaceNumber, 111 acm->control->altsetting[0].desc.bInterfaceNumber,
107 buf, len, 5000); 112 buf, len, 5000);
108 dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", request, value, len, retval); 113 dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d",
114 request, value, len, retval);
109 return retval < 0 ? retval : 0; 115 return retval < 0 ? retval : 0;
110} 116}
111 117
@@ -150,9 +156,8 @@ static int acm_wb_is_avail(struct acm *acm)
150 156
151 n = ACM_NW; 157 n = ACM_NW;
152 spin_lock_irqsave(&acm->write_lock, flags); 158 spin_lock_irqsave(&acm->write_lock, flags);
153 for (i = 0; i < ACM_NW; i++) { 159 for (i = 0; i < ACM_NW; i++)
154 n -= acm->wb[i].use; 160 n -= acm->wb[i].use;
155 }
156 spin_unlock_irqrestore(&acm->write_lock, flags); 161 spin_unlock_irqrestore(&acm->write_lock, flags);
157 return n; 162 return n;
158} 163}
@@ -183,7 +188,8 @@ static int acm_start_wb(struct acm *acm, struct acm_wb *wb)
183 wb->urb->transfer_buffer_length = wb->len; 188 wb->urb->transfer_buffer_length = wb->len;
184 wb->urb->dev = acm->dev; 189 wb->urb->dev = acm->dev;
185 190
186 if ((rc = usb_submit_urb(wb->urb, GFP_ATOMIC)) < 0) { 191 rc = usb_submit_urb(wb->urb, GFP_ATOMIC);
192 if (rc < 0) {
187 dbg("usb_submit_urb(write bulk) failed: %d", rc); 193 dbg("usb_submit_urb(write bulk) failed: %d", rc);
188 acm_write_done(acm, wb); 194 acm_write_done(acm, wb);
189 } 195 }
@@ -262,6 +268,7 @@ static void acm_ctrl_irq(struct urb *urb)
262{ 268{
263 struct acm *acm = urb->context; 269 struct acm *acm = urb->context;
264 struct usb_cdc_notification *dr = urb->transfer_buffer; 270 struct usb_cdc_notification *dr = urb->transfer_buffer;
271 struct tty_struct *tty;
265 unsigned char *data; 272 unsigned char *data;
266 int newctrl; 273 int newctrl;
267 int retval; 274 int retval;
@@ -287,40 +294,45 @@ static void acm_ctrl_irq(struct urb *urb)
287 294
288 data = (unsigned char *)(dr + 1); 295 data = (unsigned char *)(dr + 1);
289 switch (dr->bNotificationType) { 296 switch (dr->bNotificationType) {
297 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
298 dbg("%s network", dr->wValue ?
299 "connected to" : "disconnected from");
300 break;
290 301
291 case USB_CDC_NOTIFY_NETWORK_CONNECTION: 302 case USB_CDC_NOTIFY_SERIAL_STATE:
292 303 tty = tty_port_tty_get(&acm->port);
293 dbg("%s network", dr->wValue ? "connected to" : "disconnected from"); 304 newctrl = get_unaligned_le16(data);
294 break;
295
296 case USB_CDC_NOTIFY_SERIAL_STATE:
297
298 newctrl = get_unaligned_le16(data);
299 305
300 if (acm->tty && !acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { 306 if (tty) {
307 if (!acm->clocal &&
308 (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) {
301 dbg("calling hangup"); 309 dbg("calling hangup");
302 tty_hangup(acm->tty); 310 tty_hangup(tty);
303 } 311 }
312 tty_kref_put(tty);
313 }
304 314
305 acm->ctrlin = newctrl; 315 acm->ctrlin = newctrl;
306
307 dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c",
308 acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', acm->ctrlin & ACM_CTRL_DSR ? '+' : '-',
309 acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', acm->ctrlin & ACM_CTRL_RI ? '+' : '-',
310 acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-',
311 acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-');
312 316
317 dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c",
318 acm->ctrlin & ACM_CTRL_DCD ? '+' : '-',
319 acm->ctrlin & ACM_CTRL_DSR ? '+' : '-',
320 acm->ctrlin & ACM_CTRL_BRK ? '+' : '-',
321 acm->ctrlin & ACM_CTRL_RI ? '+' : '-',
322 acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-',
323 acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-',
324 acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-');
313 break; 325 break;
314 326
315 default: 327 default:
316 dbg("unknown notification %d received: index %d len %d data0 %d data1 %d", 328 dbg("unknown notification %d received: index %d len %d data0 %d data1 %d",
317 dr->bNotificationType, dr->wIndex, 329 dr->bNotificationType, dr->wIndex,
318 dr->wLength, data[0], data[1]); 330 dr->wLength, data[0], data[1]);
319 break; 331 break;
320 } 332 }
321exit: 333exit:
322 usb_mark_last_busy(acm->dev); 334 usb_mark_last_busy(acm->dev);
323 retval = usb_submit_urb (urb, GFP_ATOMIC); 335 retval = usb_submit_urb(urb, GFP_ATOMIC);
324 if (retval) 336 if (retval)
325 dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with " 337 dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with "
326 "result %d", __func__, retval); 338 "result %d", __func__, retval);
@@ -371,15 +383,14 @@ static void acm_rx_tasklet(unsigned long _acm)
371{ 383{
372 struct acm *acm = (void *)_acm; 384 struct acm *acm = (void *)_acm;
373 struct acm_rb *buf; 385 struct acm_rb *buf;
374 struct tty_struct *tty = acm->tty; 386 struct tty_struct *tty;
375 struct acm_ru *rcv; 387 struct acm_ru *rcv;
376 unsigned long flags; 388 unsigned long flags;
377 unsigned char throttled; 389 unsigned char throttled;
378 390
379 dbg("Entering acm_rx_tasklet"); 391 dbg("Entering acm_rx_tasklet");
380 392
381 if (!ACM_READY(acm)) 393 if (!ACM_READY(acm)) {
382 {
383 dbg("acm_rx_tasklet: ACM not ready"); 394 dbg("acm_rx_tasklet: ACM not ready");
384 return; 395 return;
385 } 396 }
@@ -387,12 +398,13 @@ static void acm_rx_tasklet(unsigned long _acm)
387 spin_lock_irqsave(&acm->throttle_lock, flags); 398 spin_lock_irqsave(&acm->throttle_lock, flags);
388 throttled = acm->throttle; 399 throttled = acm->throttle;
389 spin_unlock_irqrestore(&acm->throttle_lock, flags); 400 spin_unlock_irqrestore(&acm->throttle_lock, flags);
390 if (throttled) 401 if (throttled) {
391 {
392 dbg("acm_rx_tasklet: throttled"); 402 dbg("acm_rx_tasklet: throttled");
393 return; 403 return;
394 } 404 }
395 405
406 tty = tty_port_tty_get(&acm->port);
407
396next_buffer: 408next_buffer:
397 spin_lock_irqsave(&acm->read_lock, flags); 409 spin_lock_irqsave(&acm->read_lock, flags);
398 if (list_empty(&acm->filled_read_bufs)) { 410 if (list_empty(&acm->filled_read_bufs)) {
@@ -406,20 +418,22 @@ next_buffer:
406 418
407 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); 419 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size);
408 420
409 tty_buffer_request_room(tty, buf->size); 421 if (tty) {
410 spin_lock_irqsave(&acm->throttle_lock, flags); 422 spin_lock_irqsave(&acm->throttle_lock, flags);
411 throttled = acm->throttle; 423 throttled = acm->throttle;
412 spin_unlock_irqrestore(&acm->throttle_lock, flags); 424 spin_unlock_irqrestore(&acm->throttle_lock, flags);
413 if (!throttled) 425 if (!throttled) {
414 tty_insert_flip_string(tty, buf->base, buf->size); 426 tty_buffer_request_room(tty, buf->size);
415 tty_flip_buffer_push(tty); 427 tty_insert_flip_string(tty, buf->base, buf->size);
416 428 tty_flip_buffer_push(tty);
417 if (throttled) { 429 } else {
418 dbg("Throttling noticed"); 430 tty_kref_put(tty);
419 spin_lock_irqsave(&acm->read_lock, flags); 431 dbg("Throttling noticed");
420 list_add(&buf->list, &acm->filled_read_bufs); 432 spin_lock_irqsave(&acm->read_lock, flags);
421 spin_unlock_irqrestore(&acm->read_lock, flags); 433 list_add(&buf->list, &acm->filled_read_bufs);
422 return; 434 spin_unlock_irqrestore(&acm->read_lock, flags);
435 return;
436 }
423 } 437 }
424 438
425 spin_lock_irqsave(&acm->read_lock, flags); 439 spin_lock_irqsave(&acm->read_lock, flags);
@@ -428,6 +442,8 @@ next_buffer:
428 goto next_buffer; 442 goto next_buffer;
429 443
430urbs: 444urbs:
445 tty_kref_put(tty);
446
431 while (!list_empty(&acm->spare_read_bufs)) { 447 while (!list_empty(&acm->spare_read_bufs)) {
432 spin_lock_irqsave(&acm->read_lock, flags); 448 spin_lock_irqsave(&acm->read_lock, flags);
433 if (list_empty(&acm->spare_read_urbs)) { 449 if (list_empty(&acm->spare_read_urbs)) {
@@ -454,10 +470,11 @@ urbs:
454 rcv->urb->transfer_dma = buf->dma; 470 rcv->urb->transfer_dma = buf->dma;
455 rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 471 rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
456 472
457 /* This shouldn't kill the driver as unsuccessful URBs are returned to the 473 /* This shouldn't kill the driver as unsuccessful URBs are
458 free-urbs-pool and resubmited ASAP */ 474 returned to the free-urbs-pool and resubmited ASAP */
459 spin_lock_irqsave(&acm->read_lock, flags); 475 spin_lock_irqsave(&acm->read_lock, flags);
460 if (acm->susp_count || usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) { 476 if (acm->susp_count ||
477 usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) {
461 list_add(&buf->list, &acm->spare_read_bufs); 478 list_add(&buf->list, &acm->spare_read_bufs);
462 list_add(&rcv->list, &acm->spare_read_urbs); 479 list_add(&rcv->list, &acm->spare_read_urbs);
463 acm->processing = 0; 480 acm->processing = 0;
@@ -499,11 +516,14 @@ static void acm_write_bulk(struct urb *urb)
499static void acm_softint(struct work_struct *work) 516static void acm_softint(struct work_struct *work)
500{ 517{
501 struct acm *acm = container_of(work, struct acm, work); 518 struct acm *acm = container_of(work, struct acm, work);
519 struct tty_struct *tty;
502 520
503 dev_vdbg(&acm->data->dev, "tx work\n"); 521 dev_vdbg(&acm->data->dev, "tx work\n");
504 if (!ACM_READY(acm)) 522 if (!ACM_READY(acm))
505 return; 523 return;
506 tty_wakeup(acm->tty); 524 tty = tty_port_tty_get(&acm->port);
525 tty_wakeup(tty);
526 tty_kref_put(tty);
507} 527}
508 528
509static void acm_waker(struct work_struct *waker) 529static void acm_waker(struct work_struct *waker)
@@ -543,8 +563,9 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
543 rv = 0; 563 rv = 0;
544 564
545 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); 565 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
566
546 tty->driver_data = acm; 567 tty->driver_data = acm;
547 acm->tty = tty; 568 tty_port_tty_set(&acm->port, tty);
548 569
549 if (usb_autopm_get_interface(acm->control) < 0) 570 if (usb_autopm_get_interface(acm->control) < 0)
550 goto early_bail; 571 goto early_bail;
@@ -552,11 +573,10 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
552 acm->control->needs_remote_wakeup = 1; 573 acm->control->needs_remote_wakeup = 1;
553 574
554 mutex_lock(&acm->mutex); 575 mutex_lock(&acm->mutex);
555 if (acm->used++) { 576 if (acm->port.count++) {
556 usb_autopm_put_interface(acm->control); 577 usb_autopm_put_interface(acm->control);
557 goto done; 578 goto done;
558 } 579 }
559
560 580
561 acm->ctrlurb->dev = acm->dev; 581 acm->ctrlurb->dev = acm->dev;
562 if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { 582 if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) {
@@ -567,22 +587,22 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
567 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && 587 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) &&
568 (acm->ctrl_caps & USB_CDC_CAP_LINE)) 588 (acm->ctrl_caps & USB_CDC_CAP_LINE))
569 goto full_bailout; 589 goto full_bailout;
590
570 usb_autopm_put_interface(acm->control); 591 usb_autopm_put_interface(acm->control);
571 592
572 INIT_LIST_HEAD(&acm->spare_read_urbs); 593 INIT_LIST_HEAD(&acm->spare_read_urbs);
573 INIT_LIST_HEAD(&acm->spare_read_bufs); 594 INIT_LIST_HEAD(&acm->spare_read_bufs);
574 INIT_LIST_HEAD(&acm->filled_read_bufs); 595 INIT_LIST_HEAD(&acm->filled_read_bufs);
575 for (i = 0; i < acm->rx_buflimit; i++) { 596
597 for (i = 0; i < acm->rx_buflimit; i++)
576 list_add(&(acm->ru[i].list), &acm->spare_read_urbs); 598 list_add(&(acm->ru[i].list), &acm->spare_read_urbs);
577 } 599 for (i = 0; i < acm->rx_buflimit; i++)
578 for (i = 0; i < acm->rx_buflimit; i++) {
579 list_add(&(acm->rb[i].list), &acm->spare_read_bufs); 600 list_add(&(acm->rb[i].list), &acm->spare_read_bufs);
580 }
581 601
582 acm->throttle = 0; 602 acm->throttle = 0;
583 603
584 tasklet_schedule(&acm->urb_task); 604 tasklet_schedule(&acm->urb_task);
585 605 rv = tty_port_block_til_ready(&acm->port, tty, filp);
586done: 606done:
587 mutex_unlock(&acm->mutex); 607 mutex_unlock(&acm->mutex);
588err_out: 608err_out:
@@ -593,16 +613,17 @@ full_bailout:
593 usb_kill_urb(acm->ctrlurb); 613 usb_kill_urb(acm->ctrlurb);
594bail_out: 614bail_out:
595 usb_autopm_put_interface(acm->control); 615 usb_autopm_put_interface(acm->control);
596 acm->used--; 616 acm->port.count--;
597 mutex_unlock(&acm->mutex); 617 mutex_unlock(&acm->mutex);
598early_bail: 618early_bail:
599 mutex_unlock(&open_mutex); 619 mutex_unlock(&open_mutex);
620 tty_port_tty_set(&acm->port, NULL);
600 return -EIO; 621 return -EIO;
601} 622}
602 623
603static void acm_tty_unregister(struct acm *acm) 624static void acm_tty_unregister(struct acm *acm)
604{ 625{
605 int i,nr; 626 int i, nr;
606 627
607 nr = acm->rx_buflimit; 628 nr = acm->rx_buflimit;
608 tty_unregister_device(acm_tty_driver, acm->minor); 629 tty_unregister_device(acm_tty_driver, acm->minor);
@@ -619,41 +640,56 @@ static void acm_tty_unregister(struct acm *acm)
619 640
620static int acm_tty_chars_in_buffer(struct tty_struct *tty); 641static int acm_tty_chars_in_buffer(struct tty_struct *tty);
621 642
643static void acm_port_down(struct acm *acm, int drain)
644{
645 int i, nr = acm->rx_buflimit;
646 mutex_lock(&open_mutex);
647 if (acm->dev) {
648 usb_autopm_get_interface(acm->control);
649 acm_set_control(acm, acm->ctrlout = 0);
650 /* try letting the last writes drain naturally */
651 if (drain) {
652 wait_event_interruptible_timeout(acm->drain_wait,
653 (ACM_NW == acm_wb_is_avail(acm)) || !acm->dev,
654 ACM_CLOSE_TIMEOUT * HZ);
655 }
656 usb_kill_urb(acm->ctrlurb);
657 for (i = 0; i < ACM_NW; i++)
658 usb_kill_urb(acm->wb[i].urb);
659 for (i = 0; i < nr; i++)
660 usb_kill_urb(acm->ru[i].urb);
661 acm->control->needs_remote_wakeup = 0;
662 usb_autopm_put_interface(acm->control);
663 }
664 mutex_unlock(&open_mutex);
665}
666
667static void acm_tty_hangup(struct tty_struct *tty)
668{
669 struct acm *acm = tty->driver_data;
670 tty_port_hangup(&acm->port);
671 acm_port_down(acm, 0);
672}
673
622static void acm_tty_close(struct tty_struct *tty, struct file *filp) 674static void acm_tty_close(struct tty_struct *tty, struct file *filp)
623{ 675{
624 struct acm *acm = tty->driver_data; 676 struct acm *acm = tty->driver_data;
625 int i,nr;
626 677
627 if (!acm || !acm->used) 678 /* Perform the closing process and see if we need to do the hardware
679 shutdown */
680 if (tty_port_close_start(&acm->port, tty, filp) == 0)
628 return; 681 return;
629 682 acm_port_down(acm, 0);
630 nr = acm->rx_buflimit; 683 tty_port_close_end(&acm->port, tty);
631 mutex_lock(&open_mutex); 684 mutex_lock(&open_mutex);
632 if (!--acm->used) { 685 tty_port_tty_set(&acm->port, NULL);
633 if (acm->dev) { 686 if (!acm->dev)
634 usb_autopm_get_interface(acm->control); 687 acm_tty_unregister(acm);
635 acm_set_control(acm, acm->ctrlout = 0);
636
637 /* try letting the last writes drain naturally */
638 wait_event_interruptible_timeout(acm->drain_wait,
639 (ACM_NW == acm_wb_is_avail(acm))
640 || !acm->dev,
641 ACM_CLOSE_TIMEOUT * HZ);
642
643 usb_kill_urb(acm->ctrlurb);
644 for (i = 0; i < ACM_NW; i++)
645 usb_kill_urb(acm->wb[i].urb);
646 for (i = 0; i < nr; i++)
647 usb_kill_urb(acm->ru[i].urb);
648 acm->control->needs_remote_wakeup = 0;
649 usb_autopm_put_interface(acm->control);
650 } else
651 acm_tty_unregister(acm);
652 }
653 mutex_unlock(&open_mutex); 688 mutex_unlock(&open_mutex);
654} 689}
655 690
656static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) 691static int acm_tty_write(struct tty_struct *tty,
692 const unsigned char *buf, int count)
657{ 693{
658 struct acm *acm = tty->driver_data; 694 struct acm *acm = tty->driver_data;
659 int stat; 695 int stat;
@@ -669,7 +705,8 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c
669 return 0; 705 return 0;
670 706
671 spin_lock_irqsave(&acm->write_lock, flags); 707 spin_lock_irqsave(&acm->write_lock, flags);
672 if ((wbn = acm_wb_alloc(acm)) < 0) { 708 wbn = acm_wb_alloc(acm);
709 if (wbn < 0) {
673 spin_unlock_irqrestore(&acm->write_lock, flags); 710 spin_unlock_irqrestore(&acm->write_lock, flags);
674 return 0; 711 return 0;
675 } 712 }
@@ -681,7 +718,8 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c
681 wb->len = count; 718 wb->len = count;
682 spin_unlock_irqrestore(&acm->write_lock, flags); 719 spin_unlock_irqrestore(&acm->write_lock, flags);
683 720
684 if ((stat = acm_write_start(acm, wbn)) < 0) 721 stat = acm_write_start(acm, wbn);
722 if (stat < 0)
685 return stat; 723 return stat;
686 return count; 724 return count;
687} 725}
@@ -767,8 +805,10 @@ static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file,
767 return -EINVAL; 805 return -EINVAL;
768 806
769 newctrl = acm->ctrlout; 807 newctrl = acm->ctrlout;
770 set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); 808 set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
771 clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); 809 (set & TIOCM_RTS ? ACM_CTRL_RTS : 0);
810 clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
811 (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0);
772 812
773 newctrl = (newctrl & ~clear) | set; 813 newctrl = (newctrl & ~clear) | set;
774 814
@@ -777,7 +817,8 @@ static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file,
777 return acm_set_control(acm, acm->ctrlout = newctrl); 817 return acm_set_control(acm, acm->ctrlout = newctrl);
778} 818}
779 819
780static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) 820static int acm_tty_ioctl(struct tty_struct *tty, struct file *file,
821 unsigned int cmd, unsigned long arg)
781{ 822{
782 struct acm *acm = tty->driver_data; 823 struct acm *acm = tty->driver_data;
783 824
@@ -799,7 +840,8 @@ static const __u8 acm_tty_size[] = {
799 5, 6, 7, 8 840 5, 6, 7, 8
800}; 841};
801 842
802static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old) 843static void acm_tty_set_termios(struct tty_struct *tty,
844 struct ktermios *termios_old)
803{ 845{
804 struct acm *acm = tty->driver_data; 846 struct acm *acm = tty->driver_data;
805 struct ktermios *termios = tty->termios; 847 struct ktermios *termios = tty->termios;
@@ -809,19 +851,23 @@ static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios
809 if (!ACM_READY(acm)) 851 if (!ACM_READY(acm))
810 return; 852 return;
811 853
854 /* FIXME: Needs to support the tty_baud interface */
855 /* FIXME: Broken on sparc */
812 newline.dwDTERate = cpu_to_le32p(acm_tty_speed + 856 newline.dwDTERate = cpu_to_le32p(acm_tty_speed +
813 (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0)); 857 (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0));
814 newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; 858 newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0;
815 newline.bParityType = termios->c_cflag & PARENB ? 859 newline.bParityType = termios->c_cflag & PARENB ?
816 (termios->c_cflag & PARODD ? 1 : 2) + (termios->c_cflag & CMSPAR ? 2 : 0) : 0; 860 (termios->c_cflag & PARODD ? 1 : 2) +
861 (termios->c_cflag & CMSPAR ? 2 : 0) : 0;
817 newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4]; 862 newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4];
818 863 /* FIXME: Needs to clear unsupported bits in the termios */
819 acm->clocal = ((termios->c_cflag & CLOCAL) != 0); 864 acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
820 865
821 if (!newline.dwDTERate) { 866 if (!newline.dwDTERate) {
822 newline.dwDTERate = acm->line.dwDTERate; 867 newline.dwDTERate = acm->line.dwDTERate;
823 newctrl &= ~ACM_CTRL_DTR; 868 newctrl &= ~ACM_CTRL_DTR;
824 } else newctrl |= ACM_CTRL_DTR; 869 } else
870 newctrl |= ACM_CTRL_DTR;
825 871
826 if (newctrl != acm->ctrlout) 872 if (newctrl != acm->ctrlout)
827 acm_set_control(acm, acm->ctrlout = newctrl); 873 acm_set_control(acm, acm->ctrlout = newctrl);
@@ -846,9 +892,8 @@ static void acm_write_buffers_free(struct acm *acm)
846 struct acm_wb *wb; 892 struct acm_wb *wb;
847 struct usb_device *usb_dev = interface_to_usbdev(acm->control); 893 struct usb_device *usb_dev = interface_to_usbdev(acm->control);
848 894
849 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { 895 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++)
850 usb_buffer_free(usb_dev, acm->writesize, wb->buf, wb->dmah); 896 usb_buffer_free(usb_dev, acm->writesize, wb->buf, wb->dmah);
851 }
852} 897}
853 898
854static void acm_read_buffers_free(struct acm *acm) 899static void acm_read_buffers_free(struct acm *acm)
@@ -857,7 +902,8 @@ static void acm_read_buffers_free(struct acm *acm)
857 int i, n = acm->rx_buflimit; 902 int i, n = acm->rx_buflimit;
858 903
859 for (i = 0; i < n; i++) 904 for (i = 0; i < n; i++)
860 usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma); 905 usb_buffer_free(usb_dev, acm->readsize,
906 acm->rb[i].base, acm->rb[i].dma);
861} 907}
862 908
863/* Little helper: write buffers allocate */ 909/* Little helper: write buffers allocate */
@@ -882,8 +928,8 @@ static int acm_write_buffers_alloc(struct acm *acm)
882 return 0; 928 return 0;
883} 929}
884 930
885static int acm_probe (struct usb_interface *intf, 931static int acm_probe(struct usb_interface *intf,
886 const struct usb_device_id *id) 932 const struct usb_device_id *id)
887{ 933{
888 struct usb_cdc_union_desc *union_header = NULL; 934 struct usb_cdc_union_desc *union_header = NULL;
889 struct usb_cdc_country_functional_desc *cfd = NULL; 935 struct usb_cdc_country_functional_desc *cfd = NULL;
@@ -891,13 +937,13 @@ static int acm_probe (struct usb_interface *intf,
891 int buflen = intf->altsetting->extralen; 937 int buflen = intf->altsetting->extralen;
892 struct usb_interface *control_interface; 938 struct usb_interface *control_interface;
893 struct usb_interface *data_interface; 939 struct usb_interface *data_interface;
894 struct usb_endpoint_descriptor *epctrl; 940 struct usb_endpoint_descriptor *epctrl = NULL;
895 struct usb_endpoint_descriptor *epread; 941 struct usb_endpoint_descriptor *epread = NULL;
896 struct usb_endpoint_descriptor *epwrite; 942 struct usb_endpoint_descriptor *epwrite = NULL;
897 struct usb_device *usb_dev = interface_to_usbdev(intf); 943 struct usb_device *usb_dev = interface_to_usbdev(intf);
898 struct acm *acm; 944 struct acm *acm;
899 int minor; 945 int minor;
900 int ctrlsize,readsize; 946 int ctrlsize, readsize;
901 u8 *buf; 947 u8 *buf;
902 u8 ac_management_function = 0; 948 u8 ac_management_function = 0;
903 u8 call_management_function = 0; 949 u8 call_management_function = 0;
@@ -906,6 +952,7 @@ static int acm_probe (struct usb_interface *intf,
906 unsigned long quirks; 952 unsigned long quirks;
907 int num_rx_buf; 953 int num_rx_buf;
908 int i; 954 int i;
955 int combined_interfaces = 0;
909 956
910 /* normal quirks */ 957 /* normal quirks */
911 quirks = (unsigned long)id->driver_info; 958 quirks = (unsigned long)id->driver_info;
@@ -917,7 +964,7 @@ static int acm_probe (struct usb_interface *intf,
917 control_interface = usb_ifnum_to_if(usb_dev, 0); 964 control_interface = usb_ifnum_to_if(usb_dev, 0);
918 goto skip_normal_probe; 965 goto skip_normal_probe;
919 } 966 }
920 967
921 /* normal probing*/ 968 /* normal probing*/
922 if (!buffer) { 969 if (!buffer) {
923 dev_err(&intf->dev, "Weird descriptor references\n"); 970 dev_err(&intf->dev, "Weird descriptor references\n");
@@ -925,8 +972,10 @@ static int acm_probe (struct usb_interface *intf,
925 } 972 }
926 973
927 if (!buflen) { 974 if (!buflen) {
928 if (intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) { 975 if (intf->cur_altsetting->endpoint->extralen &&
929 dev_dbg(&intf->dev,"Seeking extra descriptors on endpoint\n"); 976 intf->cur_altsetting->endpoint->extra) {
977 dev_dbg(&intf->dev,
978 "Seeking extra descriptors on endpoint\n");
930 buflen = intf->cur_altsetting->endpoint->extralen; 979 buflen = intf->cur_altsetting->endpoint->extralen;
931 buffer = intf->cur_altsetting->endpoint->extra; 980 buffer = intf->cur_altsetting->endpoint->extra;
932 } else { 981 } else {
@@ -937,47 +986,43 @@ static int acm_probe (struct usb_interface *intf,
937 } 986 }
938 987
939 while (buflen > 0) { 988 while (buflen > 0) {
940 if (buffer [1] != USB_DT_CS_INTERFACE) { 989 if (buffer[1] != USB_DT_CS_INTERFACE) {
941 dev_err(&intf->dev, "skipping garbage\n"); 990 dev_err(&intf->dev, "skipping garbage\n");
942 goto next_desc; 991 goto next_desc;
943 } 992 }
944 993
945 switch (buffer [2]) { 994 switch (buffer[2]) {
946 case USB_CDC_UNION_TYPE: /* we've found it */ 995 case USB_CDC_UNION_TYPE: /* we've found it */
947 if (union_header) { 996 if (union_header) {
948 dev_err(&intf->dev, "More than one " 997 dev_err(&intf->dev, "More than one "
949 "union descriptor, " 998 "union descriptor, skipping ...\n");
950 "skipping ...\n"); 999 goto next_desc;
951 goto next_desc;
952 }
953 union_header = (struct usb_cdc_union_desc *)
954 buffer;
955 break;
956 case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/
957 cfd = (struct usb_cdc_country_functional_desc *)buffer;
958 break;
959 case USB_CDC_HEADER_TYPE: /* maybe check version */
960 break; /* for now we ignore it */
961 case USB_CDC_ACM_TYPE:
962 ac_management_function = buffer[3];
963 break;
964 case USB_CDC_CALL_MANAGEMENT_TYPE:
965 call_management_function = buffer[3];
966 call_interface_num = buffer[4];
967 if ((call_management_function & 3) != 3)
968 dev_err(&intf->dev, "This device "
969 "cannot do calls on its own. "
970 "It is no modem.\n");
971 break;
972 default:
973 /* there are LOTS more CDC descriptors that
974 * could legitimately be found here.
975 */
976 dev_dbg(&intf->dev, "Ignoring descriptor: "
977 "type %02x, length %d\n",
978 buffer[2], buffer[0]);
979 break;
980 } 1000 }
1001 union_header = (struct usb_cdc_union_desc *)buffer;
1002 break;
1003 case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/
1004 cfd = (struct usb_cdc_country_functional_desc *)buffer;
1005 break;
1006 case USB_CDC_HEADER_TYPE: /* maybe check version */
1007 break; /* for now we ignore it */
1008 case USB_CDC_ACM_TYPE:
1009 ac_management_function = buffer[3];
1010 break;
1011 case USB_CDC_CALL_MANAGEMENT_TYPE:
1012 call_management_function = buffer[3];
1013 call_interface_num = buffer[4];
1014 if ((call_management_function & 3) != 3)
1015 dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n");
1016 break;
1017 default:
1018 /* there are LOTS more CDC descriptors that
1019 * could legitimately be found here.
1020 */
1021 dev_dbg(&intf->dev, "Ignoring descriptor: "
1022 "type %02x, length %d\n",
1023 buffer[2], buffer[0]);
1024 break;
1025 }
981next_desc: 1026next_desc:
982 buflen -= buffer[0]; 1027 buflen -= buffer[0];
983 buffer += buffer[0]; 1028 buffer += buffer[0];
@@ -985,33 +1030,72 @@ next_desc:
985 1030
986 if (!union_header) { 1031 if (!union_header) {
987 if (call_interface_num > 0) { 1032 if (call_interface_num > 0) {
988 dev_dbg(&intf->dev,"No union descriptor, using call management descriptor\n"); 1033 dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n");
989 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); 1034 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num));
990 control_interface = intf; 1035 control_interface = intf;
991 } else { 1036 } else {
992 dev_dbg(&intf->dev,"No union descriptor, giving up\n"); 1037 if (intf->cur_altsetting->desc.bNumEndpoints != 3) {
993 return -ENODEV; 1038 dev_dbg(&intf->dev,"No union descriptor, giving up\n");
1039 return -ENODEV;
1040 } else {
1041 dev_warn(&intf->dev,"No union descriptor, testing for castrated device\n");
1042 combined_interfaces = 1;
1043 control_interface = data_interface = intf;
1044 goto look_for_collapsed_interface;
1045 }
994 } 1046 }
995 } else { 1047 } else {
996 control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); 1048 control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0);
997 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); 1049 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0));
998 if (!control_interface || !data_interface) { 1050 if (!control_interface || !data_interface) {
999 dev_dbg(&intf->dev,"no interfaces\n"); 1051 dev_dbg(&intf->dev, "no interfaces\n");
1000 return -ENODEV; 1052 return -ENODEV;
1001 } 1053 }
1002 } 1054 }
1003 1055
1004 if (data_interface_num != call_interface_num) 1056 if (data_interface_num != call_interface_num)
1005 dev_dbg(&intf->dev,"Separate call control interface. That is not fully supported.\n"); 1057 dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n");
1058
1059 if (control_interface == data_interface) {
1060 /* some broken devices designed for windows work this way */
1061 dev_warn(&intf->dev,"Control and data interfaces are not separated!\n");
1062 combined_interfaces = 1;
1063 /* a popular other OS doesn't use it */
1064 quirks |= NO_CAP_LINE;
1065 if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) {
1066 dev_err(&intf->dev, "This needs exactly 3 endpoints\n");
1067 return -EINVAL;
1068 }
1069look_for_collapsed_interface:
1070 for (i = 0; i < 3; i++) {
1071 struct usb_endpoint_descriptor *ep;
1072 ep = &data_interface->cur_altsetting->endpoint[i].desc;
1073
1074 if (usb_endpoint_is_int_in(ep))
1075 epctrl = ep;
1076 else if (usb_endpoint_is_bulk_out(ep))
1077 epwrite = ep;
1078 else if (usb_endpoint_is_bulk_in(ep))
1079 epread = ep;
1080 else
1081 return -EINVAL;
1082 }
1083 if (!epctrl || !epread || !epwrite)
1084 return -ENODEV;
1085 else
1086 goto made_compressed_probe;
1087 }
1006 1088
1007skip_normal_probe: 1089skip_normal_probe:
1008 1090
1009 /*workaround for switched interfaces */ 1091 /*workaround for switched interfaces */
1010 if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) { 1092 if (data_interface->cur_altsetting->desc.bInterfaceClass
1011 if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) { 1093 != CDC_DATA_INTERFACE_TYPE) {
1094 if (control_interface->cur_altsetting->desc.bInterfaceClass
1095 == CDC_DATA_INTERFACE_TYPE) {
1012 struct usb_interface *t; 1096 struct usb_interface *t;
1013 dev_dbg(&intf->dev,"Your device has switched interfaces.\n"); 1097 dev_dbg(&intf->dev,
1014 1098 "Your device has switched interfaces.\n");
1015 t = control_interface; 1099 t = control_interface;
1016 control_interface = data_interface; 1100 control_interface = data_interface;
1017 data_interface = t; 1101 data_interface = t;
@@ -1021,11 +1105,12 @@ skip_normal_probe:
1021 } 1105 }
1022 1106
1023 /* Accept probe requests only for the control interface */ 1107 /* Accept probe requests only for the control interface */
1024 if (intf != control_interface) 1108 if (!combined_interfaces && intf != control_interface)
1025 return -ENODEV; 1109 return -ENODEV;
1026 1110
1027 if (usb_interface_claimed(data_interface)) { /* valid in this context */ 1111 if (!combined_interfaces && usb_interface_claimed(data_interface)) {
1028 dev_dbg(&intf->dev,"The data interface isn't available\n"); 1112 /* valid in this context */
1113 dev_dbg(&intf->dev, "The data interface isn't available\n");
1029 return -EBUSY; 1114 return -EBUSY;
1030 } 1115 }
1031 1116
@@ -1042,12 +1127,13 @@ skip_normal_probe:
1042 if (!usb_endpoint_dir_in(epread)) { 1127 if (!usb_endpoint_dir_in(epread)) {
1043 /* descriptors are swapped */ 1128 /* descriptors are swapped */
1044 struct usb_endpoint_descriptor *t; 1129 struct usb_endpoint_descriptor *t;
1045 dev_dbg(&intf->dev,"The data interface has switched endpoints\n"); 1130 dev_dbg(&intf->dev,
1046 1131 "The data interface has switched endpoints\n");
1047 t = epread; 1132 t = epread;
1048 epread = epwrite; 1133 epread = epwrite;
1049 epwrite = t; 1134 epwrite = t;
1050 } 1135 }
1136made_compressed_probe:
1051 dbg("interfaces are valid"); 1137 dbg("interfaces are valid");
1052 for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++); 1138 for (minor = 0; minor < ACM_TTY_MINORS && acm_table[minor]; minor++);
1053 1139
@@ -1056,19 +1142,24 @@ skip_normal_probe:
1056 return -ENODEV; 1142 return -ENODEV;
1057 } 1143 }
1058 1144
1059 if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) { 1145 acm = kzalloc(sizeof(struct acm), GFP_KERNEL);
1146 if (acm == NULL) {
1060 dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); 1147 dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n");
1061 goto alloc_fail; 1148 goto alloc_fail;
1062 } 1149 }
1063 1150
1064 ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); 1151 ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize);
1065 readsize = le16_to_cpu(epread->wMaxPacketSize)* ( quirks == SINGLE_RX_URB ? 1 : 2); 1152 readsize = le16_to_cpu(epread->wMaxPacketSize) *
1153 (quirks == SINGLE_RX_URB ? 1 : 2);
1154 acm->combined_interfaces = combined_interfaces;
1066 acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; 1155 acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20;
1067 acm->control = control_interface; 1156 acm->control = control_interface;
1068 acm->data = data_interface; 1157 acm->data = data_interface;
1069 acm->minor = minor; 1158 acm->minor = minor;
1070 acm->dev = usb_dev; 1159 acm->dev = usb_dev;
1071 acm->ctrl_caps = ac_management_function; 1160 acm->ctrl_caps = ac_management_function;
1161 if (quirks & NO_CAP_LINE)
1162 acm->ctrl_caps &= ~USB_CDC_CAP_LINE;
1072 acm->ctrlsize = ctrlsize; 1163 acm->ctrlsize = ctrlsize;
1073 acm->readsize = readsize; 1164 acm->readsize = readsize;
1074 acm->rx_buflimit = num_rx_buf; 1165 acm->rx_buflimit = num_rx_buf;
@@ -1082,6 +1173,8 @@ skip_normal_probe:
1082 spin_lock_init(&acm->read_lock); 1173 spin_lock_init(&acm->read_lock);
1083 mutex_init(&acm->mutex); 1174 mutex_init(&acm->mutex);
1084 acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); 1175 acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress);
1176 tty_port_init(&acm->port);
1177 acm->port.ops = &acm_port_ops;
1085 1178
1086 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); 1179 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
1087 if (!buf) { 1180 if (!buf) {
@@ -1103,8 +1196,10 @@ skip_normal_probe:
1103 for (i = 0; i < num_rx_buf; i++) { 1196 for (i = 0; i < num_rx_buf; i++) {
1104 struct acm_ru *rcv = &(acm->ru[i]); 1197 struct acm_ru *rcv = &(acm->ru[i]);
1105 1198
1106 if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) { 1199 rcv->urb = usb_alloc_urb(0, GFP_KERNEL);
1107 dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)\n"); 1200 if (rcv->urb == NULL) {
1201 dev_dbg(&intf->dev,
1202 "out of memory (read urbs usb_alloc_urb)\n");
1108 goto alloc_fail7; 1203 goto alloc_fail7;
1109 } 1204 }
1110 1205
@@ -1117,26 +1212,29 @@ skip_normal_probe:
1117 rb->base = usb_buffer_alloc(acm->dev, readsize, 1212 rb->base = usb_buffer_alloc(acm->dev, readsize,
1118 GFP_KERNEL, &rb->dma); 1213 GFP_KERNEL, &rb->dma);
1119 if (!rb->base) { 1214 if (!rb->base) {
1120 dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)\n"); 1215 dev_dbg(&intf->dev,
1216 "out of memory (read bufs usb_buffer_alloc)\n");
1121 goto alloc_fail7; 1217 goto alloc_fail7;
1122 } 1218 }
1123 } 1219 }
1124 for(i = 0; i < ACM_NW; i++) 1220 for (i = 0; i < ACM_NW; i++) {
1125 {
1126 struct acm_wb *snd = &(acm->wb[i]); 1221 struct acm_wb *snd = &(acm->wb[i]);
1127 1222
1128 if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) { 1223 snd->urb = usb_alloc_urb(0, GFP_KERNEL);
1129 dev_dbg(&intf->dev, "out of memory (write urbs usb_alloc_urb)"); 1224 if (snd->urb == NULL) {
1225 dev_dbg(&intf->dev,
1226 "out of memory (write urbs usb_alloc_urb)");
1130 goto alloc_fail7; 1227 goto alloc_fail7;
1131 } 1228 }
1132 1229
1133 usb_fill_bulk_urb(snd->urb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), 1230 usb_fill_bulk_urb(snd->urb, usb_dev,
1134 NULL, acm->writesize, acm_write_bulk, snd); 1231 usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
1232 NULL, acm->writesize, acm_write_bulk, snd);
1135 snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1233 snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1136 snd->instance = acm; 1234 snd->instance = acm;
1137 } 1235 }
1138 1236
1139 usb_set_intfdata (intf, acm); 1237 usb_set_intfdata(intf, acm);
1140 1238
1141 i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); 1239 i = device_create_file(&intf->dev, &dev_attr_bmCapabilities);
1142 if (i < 0) 1240 if (i < 0)
@@ -1147,7 +1245,8 @@ skip_normal_probe:
1147 if (!acm->country_codes) 1245 if (!acm->country_codes)
1148 goto skip_countries; 1246 goto skip_countries;
1149 acm->country_code_size = cfd->bLength - 4; 1247 acm->country_code_size = cfd->bLength - 4;
1150 memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4); 1248 memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0,
1249 cfd->bLength - 4);
1151 acm->country_rel_date = cfd->iCountryCodeRelDate; 1250 acm->country_rel_date = cfd->iCountryCodeRelDate;
1152 1251
1153 i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); 1252 i = device_create_file(&intf->dev, &dev_attr_wCountryCodes);
@@ -1156,7 +1255,8 @@ skip_normal_probe:
1156 goto skip_countries; 1255 goto skip_countries;
1157 } 1256 }
1158 1257
1159 i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate); 1258 i = device_create_file(&intf->dev,
1259 &dev_attr_iCountryCodeRelDate);
1160 if (i < 0) { 1260 if (i < 0) {
1161 kfree(acm->country_codes); 1261 kfree(acm->country_codes);
1162 goto skip_countries; 1262 goto skip_countries;
@@ -1164,8 +1264,11 @@ skip_normal_probe:
1164 } 1264 }
1165 1265
1166skip_countries: 1266skip_countries:
1167 usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), 1267 usb_fill_int_urb(acm->ctrlurb, usb_dev,
1168 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval); 1268 usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress),
1269 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm,
1270 /* works around buggy devices */
1271 epctrl->bInterval ? epctrl->bInterval : 0xff);
1169 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1272 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1170 acm->ctrlurb->transfer_dma = acm->ctrl_dma; 1273 acm->ctrlurb->transfer_dma = acm->ctrl_dma;
1171 1274
@@ -1212,7 +1315,7 @@ static void stop_data_traffic(struct acm *acm)
1212 tasklet_disable(&acm->urb_task); 1315 tasklet_disable(&acm->urb_task);
1213 1316
1214 usb_kill_urb(acm->ctrlurb); 1317 usb_kill_urb(acm->ctrlurb);
1215 for(i = 0; i < ACM_NW; i++) 1318 for (i = 0; i < ACM_NW; i++)
1216 usb_kill_urb(acm->wb[i].urb); 1319 usb_kill_urb(acm->wb[i].urb);
1217 for (i = 0; i < acm->rx_buflimit; i++) 1320 for (i = 0; i < acm->rx_buflimit; i++)
1218 usb_kill_urb(acm->ru[i].urb); 1321 usb_kill_urb(acm->ru[i].urb);
@@ -1227,13 +1330,14 @@ static void acm_disconnect(struct usb_interface *intf)
1227{ 1330{
1228 struct acm *acm = usb_get_intfdata(intf); 1331 struct acm *acm = usb_get_intfdata(intf);
1229 struct usb_device *usb_dev = interface_to_usbdev(intf); 1332 struct usb_device *usb_dev = interface_to_usbdev(intf);
1333 struct tty_struct *tty;
1230 1334
1231 /* sibling interface is already cleaning up */ 1335 /* sibling interface is already cleaning up */
1232 if (!acm) 1336 if (!acm)
1233 return; 1337 return;
1234 1338
1235 mutex_lock(&open_mutex); 1339 mutex_lock(&open_mutex);
1236 if (acm->country_codes){ 1340 if (acm->country_codes) {
1237 device_remove_file(&acm->control->dev, 1341 device_remove_file(&acm->control->dev,
1238 &dev_attr_wCountryCodes); 1342 &dev_attr_wCountryCodes);
1239 device_remove_file(&acm->control->dev, 1343 device_remove_file(&acm->control->dev,
@@ -1247,22 +1351,26 @@ static void acm_disconnect(struct usb_interface *intf)
1247 stop_data_traffic(acm); 1351 stop_data_traffic(acm);
1248 1352
1249 acm_write_buffers_free(acm); 1353 acm_write_buffers_free(acm);
1250 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); 1354 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer,
1355 acm->ctrl_dma);
1251 acm_read_buffers_free(acm); 1356 acm_read_buffers_free(acm);
1252 1357
1253 usb_driver_release_interface(&acm_driver, intf == acm->control ? 1358 if (!acm->combined_interfaces)
1359 usb_driver_release_interface(&acm_driver, intf == acm->control ?
1254 acm->data : acm->control); 1360 acm->data : acm->control);
1255 1361
1256 if (!acm->used) { 1362 if (acm->port.count == 0) {
1257 acm_tty_unregister(acm); 1363 acm_tty_unregister(acm);
1258 mutex_unlock(&open_mutex); 1364 mutex_unlock(&open_mutex);
1259 return; 1365 return;
1260 } 1366 }
1261 1367
1262 mutex_unlock(&open_mutex); 1368 mutex_unlock(&open_mutex);
1263 1369 tty = tty_port_tty_get(&acm->port);
1264 if (acm->tty) 1370 if (tty) {
1265 tty_hangup(acm->tty); 1371 tty_hangup(tty);
1372 tty_kref_put(tty);
1373 }
1266} 1374}
1267 1375
1268#ifdef CONFIG_PM 1376#ifdef CONFIG_PM
@@ -1297,7 +1405,7 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message)
1297 */ 1405 */
1298 mutex_lock(&acm->mutex); 1406 mutex_lock(&acm->mutex);
1299 1407
1300 if (acm->used) 1408 if (acm->port.count)
1301 stop_data_traffic(acm); 1409 stop_data_traffic(acm);
1302 1410
1303 mutex_unlock(&acm->mutex); 1411 mutex_unlock(&acm->mutex);
@@ -1319,7 +1427,7 @@ static int acm_resume(struct usb_interface *intf)
1319 return 0; 1427 return 0;
1320 1428
1321 mutex_lock(&acm->mutex); 1429 mutex_lock(&acm->mutex);
1322 if (acm->used) { 1430 if (acm->port.count) {
1323 rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); 1431 rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO);
1324 if (rv < 0) 1432 if (rv < 0)
1325 goto err_out; 1433 goto err_out;
@@ -1387,6 +1495,9 @@ static struct usb_device_id acm_ids[] = {
1387 Maybe we should define a new 1495 Maybe we should define a new
1388 quirk for this. */ 1496 quirk for this. */
1389 }, 1497 },
1498 { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */
1499 .driver_info = NO_UNION_NORMAL, /* reports zero length descriptor */
1500 },
1390 1501
1391 /* control interfaces with various AT-command sets */ 1502 /* control interfaces with various AT-command sets */
1392 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1503 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
@@ -1398,7 +1509,7 @@ static struct usb_device_id acm_ids[] = {
1398 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1509 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1399 USB_CDC_ACM_PROTO_AT_GSM) }, 1510 USB_CDC_ACM_PROTO_AT_GSM) },
1400 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1511 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1401 USB_CDC_ACM_PROTO_AT_3G ) }, 1512 USB_CDC_ACM_PROTO_AT_3G) },
1402 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1513 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1403 USB_CDC_ACM_PROTO_AT_CDMA) }, 1514 USB_CDC_ACM_PROTO_AT_CDMA) },
1404 1515
@@ -1406,7 +1517,7 @@ static struct usb_device_id acm_ids[] = {
1406 { } 1517 { }
1407}; 1518};
1408 1519
1409MODULE_DEVICE_TABLE (usb, acm_ids); 1520MODULE_DEVICE_TABLE(usb, acm_ids);
1410 1521
1411static struct usb_driver acm_driver = { 1522static struct usb_driver acm_driver = {
1412 .name = "cdc_acm", 1523 .name = "cdc_acm",
@@ -1429,6 +1540,7 @@ static struct usb_driver acm_driver = {
1429static const struct tty_operations acm_ops = { 1540static const struct tty_operations acm_ops = {
1430 .open = acm_tty_open, 1541 .open = acm_tty_open,
1431 .close = acm_tty_close, 1542 .close = acm_tty_close,
1543 .hangup = acm_tty_hangup,
1432 .write = acm_tty_write, 1544 .write = acm_tty_write,
1433 .write_room = acm_tty_write_room, 1545 .write_room = acm_tty_write_room,
1434 .ioctl = acm_tty_ioctl, 1546 .ioctl = acm_tty_ioctl,
@@ -1460,7 +1572,8 @@ static int __init acm_init(void)
1460 acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, 1572 acm_tty_driver->subtype = SERIAL_TYPE_NORMAL,
1461 acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 1573 acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1462 acm_tty_driver->init_termios = tty_std_termios; 1574 acm_tty_driver->init_termios = tty_std_termios;
1463 acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1575 acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD |
1576 HUPCL | CLOCAL;
1464 tty_set_operations(acm_tty_driver, &acm_ops); 1577 tty_set_operations(acm_tty_driver, &acm_ops);
1465 1578
1466 retval = tty_register_driver(acm_tty_driver); 1579 retval = tty_register_driver(acm_tty_driver);
@@ -1492,7 +1605,7 @@ static void __exit acm_exit(void)
1492module_init(acm_init); 1605module_init(acm_init);
1493module_exit(acm_exit); 1606module_exit(acm_exit);
1494 1607
1495MODULE_AUTHOR( DRIVER_AUTHOR ); 1608MODULE_AUTHOR(DRIVER_AUTHOR);
1496MODULE_DESCRIPTION( DRIVER_DESC ); 1609MODULE_DESCRIPTION(DRIVER_DESC);
1497MODULE_LICENSE("GPL"); 1610MODULE_LICENSE("GPL");
1498MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); 1611MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR);
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index 1f95e7aa1b66..1602324808ba 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -89,8 +89,8 @@ struct acm {
89 struct usb_device *dev; /* the corresponding usb device */ 89 struct usb_device *dev; /* the corresponding usb device */
90 struct usb_interface *control; /* control interface */ 90 struct usb_interface *control; /* control interface */
91 struct usb_interface *data; /* data interface */ 91 struct usb_interface *data; /* data interface */
92 struct tty_struct *tty; /* the corresponding tty */ 92 struct tty_port port; /* our tty port data */
93 struct urb *ctrlurb; /* urbs */ 93 struct urb *ctrlurb; /* urbs */
94 u8 *ctrl_buffer; /* buffers of urbs */ 94 u8 *ctrl_buffer; /* buffers of urbs */
95 dma_addr_t ctrl_dma; /* dma handles of buffers */ 95 dma_addr_t ctrl_dma; /* dma handles of buffers */
96 u8 *country_codes; /* country codes from device */ 96 u8 *country_codes; /* country codes from device */
@@ -120,12 +120,12 @@ struct acm {
120 unsigned int ctrlout; /* output control lines (DTR, RTS) */ 120 unsigned int ctrlout; /* output control lines (DTR, RTS) */
121 unsigned int writesize; /* max packet size for the output bulk endpoint */ 121 unsigned int writesize; /* max packet size for the output bulk endpoint */
122 unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ 122 unsigned int readsize,ctrlsize; /* buffer sizes for freeing */
123 unsigned int used; /* someone has this acm's device open */
124 unsigned int minor; /* acm minor number */ 123 unsigned int minor; /* acm minor number */
125 unsigned char throttle; /* throttled by tty layer */ 124 unsigned char throttle; /* throttled by tty layer */
126 unsigned char clocal; /* termios CLOCAL */ 125 unsigned char clocal; /* termios CLOCAL */
127 unsigned int ctrl_caps; /* control capabilities from the class specific header */ 126 unsigned int ctrl_caps; /* control capabilities from the class specific header */
128 unsigned int susp_count; /* number of suspended interfaces */ 127 unsigned int susp_count; /* number of suspended interfaces */
128 int combined_interfaces:1; /* control and data collapsed */
129 struct acm_wb *delayed_wb; /* write queued for a device about to be woken */ 129 struct acm_wb *delayed_wb; /* write queued for a device about to be woken */
130}; 130};
131 131
@@ -134,3 +134,4 @@ struct acm {
134/* constants describing various quirks and errors */ 134/* constants describing various quirks and errors */
135#define NO_UNION_NORMAL 1 135#define NO_UNION_NORMAL 1
136#define SINGLE_RX_URB 2 136#define SINGLE_RX_URB 2
137#define NO_CAP_LINE 4
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index d2747a49b974..26c09f0257db 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -1057,8 +1057,14 @@ static const struct file_operations usblp_fops = {
1057 .release = usblp_release, 1057 .release = usblp_release,
1058}; 1058};
1059 1059
1060static char *usblp_nodename(struct device *dev)
1061{
1062 return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
1063}
1064
1060static struct usb_class_driver usblp_class = { 1065static struct usb_class_driver usblp_class = {
1061 .name = "lp%d", 1066 .name = "lp%d",
1067 .nodename = usblp_nodename,
1062 .fops = &usblp_fops, 1068 .fops = &usblp_fops,
1063 .minor_base = USBLP_MINOR_BASE, 1069 .minor_base = USBLP_MINOR_BASE,
1064}; 1070};
diff --git a/drivers/usb/class/usbtmc.c b/drivers/usb/class/usbtmc.c
index c40a9b284cc9..3703789d0d2a 100644
--- a/drivers/usb/class/usbtmc.c
+++ b/drivers/usb/class/usbtmc.c
@@ -927,21 +927,27 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
927 switch (cmd) { 927 switch (cmd) {
928 case USBTMC_IOCTL_CLEAR_OUT_HALT: 928 case USBTMC_IOCTL_CLEAR_OUT_HALT:
929 retval = usbtmc_ioctl_clear_out_halt(data); 929 retval = usbtmc_ioctl_clear_out_halt(data);
930 break;
930 931
931 case USBTMC_IOCTL_CLEAR_IN_HALT: 932 case USBTMC_IOCTL_CLEAR_IN_HALT:
932 retval = usbtmc_ioctl_clear_in_halt(data); 933 retval = usbtmc_ioctl_clear_in_halt(data);
934 break;
933 935
934 case USBTMC_IOCTL_INDICATOR_PULSE: 936 case USBTMC_IOCTL_INDICATOR_PULSE:
935 retval = usbtmc_ioctl_indicator_pulse(data); 937 retval = usbtmc_ioctl_indicator_pulse(data);
938 break;
936 939
937 case USBTMC_IOCTL_CLEAR: 940 case USBTMC_IOCTL_CLEAR:
938 retval = usbtmc_ioctl_clear(data); 941 retval = usbtmc_ioctl_clear(data);
942 break;
939 943
940 case USBTMC_IOCTL_ABORT_BULK_OUT: 944 case USBTMC_IOCTL_ABORT_BULK_OUT:
941 retval = usbtmc_ioctl_abort_bulk_out(data); 945 retval = usbtmc_ioctl_abort_bulk_out(data);
946 break;
942 947
943 case USBTMC_IOCTL_ABORT_BULK_IN: 948 case USBTMC_IOCTL_ABORT_BULK_IN:
944 retval = usbtmc_ioctl_abort_bulk_in(data); 949 retval = usbtmc_ioctl_abort_bulk_in(data);
950 break;
945 } 951 }
946 952
947 mutex_unlock(&data->io_mutex); 953 mutex_unlock(&data->io_mutex);