diff options
Diffstat (limited to 'drivers/usb/class/cdc-acm.c')
-rw-r--r-- | drivers/usb/class/cdc-acm.c | 445 |
1 files changed, 257 insertions, 188 deletions
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c index 0a69c0977e3f..ddeb69192537 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 | ||
88 | static DEFINE_MUTEX(open_mutex); | 89 | static 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 | |||
93 | static 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 | ||
102 | static int acm_ctrl_msg(struct acm *acm, int request, int value, void *buf, int len) | 106 | static 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 | } |
321 | exit: | 333 | exit: |
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 | |||
396 | next_buffer: | 408 | next_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 | ||
430 | urbs: | 444 | urbs: |
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) | |||
499 | static void acm_softint(struct work_struct *work) | 516 | static 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 | ||
509 | static void acm_waker(struct work_struct *waker) | 529 | static 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); | |
586 | done: | 606 | done: |
587 | mutex_unlock(&acm->mutex); | 607 | mutex_unlock(&acm->mutex); |
588 | err_out: | 608 | err_out: |
@@ -593,16 +613,17 @@ full_bailout: | |||
593 | usb_kill_urb(acm->ctrlurb); | 613 | usb_kill_urb(acm->ctrlurb); |
594 | bail_out: | 614 | bail_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); |
598 | early_bail: | 618 | early_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 | ||
603 | static void acm_tty_unregister(struct acm *acm) | 624 | static 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 | ||
620 | static int acm_tty_chars_in_buffer(struct tty_struct *tty); | 641 | static int acm_tty_chars_in_buffer(struct tty_struct *tty); |
621 | 642 | ||
643 | static 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 | |||
667 | static 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 | |||
622 | static void acm_tty_close(struct tty_struct *tty, struct file *filp) | 674 | static 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 | ||
656 | static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) | 691 | static 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 | ||
780 | static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) | 820 | static 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 | ||
802 | static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old) | 843 | static 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 | ||
854 | static void acm_read_buffers_free(struct acm *acm) | 899 | static 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 | ||
885 | static int acm_probe (struct usb_interface *intf, | 931 | static 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; |
@@ -897,7 +943,7 @@ static int acm_probe (struct usb_interface *intf, | |||
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; |
@@ -917,7 +963,7 @@ static int acm_probe (struct usb_interface *intf, | |||
917 | control_interface = usb_ifnum_to_if(usb_dev, 0); | 963 | control_interface = usb_ifnum_to_if(usb_dev, 0); |
918 | goto skip_normal_probe; | 964 | goto skip_normal_probe; |
919 | } | 965 | } |
920 | 966 | ||
921 | /* normal probing*/ | 967 | /* normal probing*/ |
922 | if (!buffer) { | 968 | if (!buffer) { |
923 | dev_err(&intf->dev, "Weird descriptor references\n"); | 969 | dev_err(&intf->dev, "Weird descriptor references\n"); |
@@ -925,8 +971,10 @@ static int acm_probe (struct usb_interface *intf, | |||
925 | } | 971 | } |
926 | 972 | ||
927 | if (!buflen) { | 973 | if (!buflen) { |
928 | if (intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) { | 974 | if (intf->cur_altsetting->endpoint->extralen && |
929 | dev_dbg(&intf->dev,"Seeking extra descriptors on endpoint\n"); | 975 | intf->cur_altsetting->endpoint->extra) { |
976 | dev_dbg(&intf->dev, | ||
977 | "Seeking extra descriptors on endpoint\n"); | ||
930 | buflen = intf->cur_altsetting->endpoint->extralen; | 978 | buflen = intf->cur_altsetting->endpoint->extralen; |
931 | buffer = intf->cur_altsetting->endpoint->extra; | 979 | buffer = intf->cur_altsetting->endpoint->extra; |
932 | } else { | 980 | } else { |
@@ -937,47 +985,43 @@ static int acm_probe (struct usb_interface *intf, | |||
937 | } | 985 | } |
938 | 986 | ||
939 | while (buflen > 0) { | 987 | while (buflen > 0) { |
940 | if (buffer [1] != USB_DT_CS_INTERFACE) { | 988 | if (buffer[1] != USB_DT_CS_INTERFACE) { |
941 | dev_err(&intf->dev, "skipping garbage\n"); | 989 | dev_err(&intf->dev, "skipping garbage\n"); |
942 | goto next_desc; | 990 | goto next_desc; |
943 | } | 991 | } |
944 | 992 | ||
945 | switch (buffer [2]) { | 993 | switch (buffer[2]) { |
946 | case USB_CDC_UNION_TYPE: /* we've found it */ | 994 | case USB_CDC_UNION_TYPE: /* we've found it */ |
947 | if (union_header) { | 995 | if (union_header) { |
948 | dev_err(&intf->dev, "More than one " | 996 | dev_err(&intf->dev, "More than one " |
949 | "union descriptor, " | 997 | "union descriptor, skipping ...\n"); |
950 | "skipping ...\n"); | 998 | 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 | } | 999 | } |
1000 | union_header = (struct usb_cdc_union_desc *)buffer; | ||
1001 | break; | ||
1002 | case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/ | ||
1003 | cfd = (struct usb_cdc_country_functional_desc *)buffer; | ||
1004 | break; | ||
1005 | case USB_CDC_HEADER_TYPE: /* maybe check version */ | ||
1006 | break; /* for now we ignore it */ | ||
1007 | case USB_CDC_ACM_TYPE: | ||
1008 | ac_management_function = buffer[3]; | ||
1009 | break; | ||
1010 | case USB_CDC_CALL_MANAGEMENT_TYPE: | ||
1011 | call_management_function = buffer[3]; | ||
1012 | call_interface_num = buffer[4]; | ||
1013 | if ((call_management_function & 3) != 3) | ||
1014 | dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n"); | ||
1015 | break; | ||
1016 | default: | ||
1017 | /* there are LOTS more CDC descriptors that | ||
1018 | * could legitimately be found here. | ||
1019 | */ | ||
1020 | dev_dbg(&intf->dev, "Ignoring descriptor: " | ||
1021 | "type %02x, length %d\n", | ||
1022 | buffer[2], buffer[0]); | ||
1023 | break; | ||
1024 | } | ||
981 | next_desc: | 1025 | next_desc: |
982 | buflen -= buffer[0]; | 1026 | buflen -= buffer[0]; |
983 | buffer += buffer[0]; | 1027 | buffer += buffer[0]; |
@@ -985,33 +1029,36 @@ next_desc: | |||
985 | 1029 | ||
986 | if (!union_header) { | 1030 | if (!union_header) { |
987 | if (call_interface_num > 0) { | 1031 | if (call_interface_num > 0) { |
988 | dev_dbg(&intf->dev,"No union descriptor, using call management descriptor\n"); | 1032 | 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)); | 1033 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); |
990 | control_interface = intf; | 1034 | control_interface = intf; |
991 | } else { | 1035 | } else { |
992 | dev_dbg(&intf->dev,"No union descriptor, giving up\n"); | 1036 | dev_dbg(&intf->dev, |
1037 | "No union descriptor, giving up\n"); | ||
993 | return -ENODEV; | 1038 | return -ENODEV; |
994 | } | 1039 | } |
995 | } else { | 1040 | } else { |
996 | control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); | 1041 | 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)); | 1042 | data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); |
998 | if (!control_interface || !data_interface) { | 1043 | if (!control_interface || !data_interface) { |
999 | dev_dbg(&intf->dev,"no interfaces\n"); | 1044 | dev_dbg(&intf->dev, "no interfaces\n"); |
1000 | return -ENODEV; | 1045 | return -ENODEV; |
1001 | } | 1046 | } |
1002 | } | 1047 | } |
1003 | 1048 | ||
1004 | if (data_interface_num != call_interface_num) | 1049 | if (data_interface_num != call_interface_num) |
1005 | dev_dbg(&intf->dev,"Separate call control interface. That is not fully supported.\n"); | 1050 | dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); |
1006 | 1051 | ||
1007 | skip_normal_probe: | 1052 | skip_normal_probe: |
1008 | 1053 | ||
1009 | /*workaround for switched interfaces */ | 1054 | /*workaround for switched interfaces */ |
1010 | if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) { | 1055 | if (data_interface->cur_altsetting->desc.bInterfaceClass |
1011 | if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) { | 1056 | != CDC_DATA_INTERFACE_TYPE) { |
1057 | if (control_interface->cur_altsetting->desc.bInterfaceClass | ||
1058 | == CDC_DATA_INTERFACE_TYPE) { | ||
1012 | struct usb_interface *t; | 1059 | struct usb_interface *t; |
1013 | dev_dbg(&intf->dev,"Your device has switched interfaces.\n"); | 1060 | dev_dbg(&intf->dev, |
1014 | 1061 | "Your device has switched interfaces.\n"); | |
1015 | t = control_interface; | 1062 | t = control_interface; |
1016 | control_interface = data_interface; | 1063 | control_interface = data_interface; |
1017 | data_interface = t; | 1064 | data_interface = t; |
@@ -1023,9 +1070,9 @@ skip_normal_probe: | |||
1023 | /* Accept probe requests only for the control interface */ | 1070 | /* Accept probe requests only for the control interface */ |
1024 | if (intf != control_interface) | 1071 | if (intf != control_interface) |
1025 | return -ENODEV; | 1072 | return -ENODEV; |
1026 | 1073 | ||
1027 | if (usb_interface_claimed(data_interface)) { /* valid in this context */ | 1074 | if (usb_interface_claimed(data_interface)) { /* valid in this context */ |
1028 | dev_dbg(&intf->dev,"The data interface isn't available\n"); | 1075 | dev_dbg(&intf->dev, "The data interface isn't available\n"); |
1029 | return -EBUSY; | 1076 | return -EBUSY; |
1030 | } | 1077 | } |
1031 | 1078 | ||
@@ -1042,8 +1089,8 @@ skip_normal_probe: | |||
1042 | if (!usb_endpoint_dir_in(epread)) { | 1089 | if (!usb_endpoint_dir_in(epread)) { |
1043 | /* descriptors are swapped */ | 1090 | /* descriptors are swapped */ |
1044 | struct usb_endpoint_descriptor *t; | 1091 | struct usb_endpoint_descriptor *t; |
1045 | dev_dbg(&intf->dev,"The data interface has switched endpoints\n"); | 1092 | dev_dbg(&intf->dev, |
1046 | 1093 | "The data interface has switched endpoints\n"); | |
1047 | t = epread; | 1094 | t = epread; |
1048 | epread = epwrite; | 1095 | epread = epwrite; |
1049 | epwrite = t; | 1096 | epwrite = t; |
@@ -1056,13 +1103,15 @@ skip_normal_probe: | |||
1056 | return -ENODEV; | 1103 | return -ENODEV; |
1057 | } | 1104 | } |
1058 | 1105 | ||
1059 | if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) { | 1106 | acm = kzalloc(sizeof(struct acm), GFP_KERNEL); |
1107 | if (acm == NULL) { | ||
1060 | dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); | 1108 | dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); |
1061 | goto alloc_fail; | 1109 | goto alloc_fail; |
1062 | } | 1110 | } |
1063 | 1111 | ||
1064 | ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); | 1112 | ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); |
1065 | readsize = le16_to_cpu(epread->wMaxPacketSize)* ( quirks == SINGLE_RX_URB ? 1 : 2); | 1113 | readsize = le16_to_cpu(epread->wMaxPacketSize) * |
1114 | (quirks == SINGLE_RX_URB ? 1 : 2); | ||
1066 | acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; | 1115 | acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; |
1067 | acm->control = control_interface; | 1116 | acm->control = control_interface; |
1068 | acm->data = data_interface; | 1117 | acm->data = data_interface; |
@@ -1082,6 +1131,8 @@ skip_normal_probe: | |||
1082 | spin_lock_init(&acm->read_lock); | 1131 | spin_lock_init(&acm->read_lock); |
1083 | mutex_init(&acm->mutex); | 1132 | mutex_init(&acm->mutex); |
1084 | acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); | 1133 | acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); |
1134 | tty_port_init(&acm->port); | ||
1135 | acm->port.ops = &acm_port_ops; | ||
1085 | 1136 | ||
1086 | buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); | 1137 | buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); |
1087 | if (!buf) { | 1138 | if (!buf) { |
@@ -1103,8 +1154,10 @@ skip_normal_probe: | |||
1103 | for (i = 0; i < num_rx_buf; i++) { | 1154 | for (i = 0; i < num_rx_buf; i++) { |
1104 | struct acm_ru *rcv = &(acm->ru[i]); | 1155 | struct acm_ru *rcv = &(acm->ru[i]); |
1105 | 1156 | ||
1106 | if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) { | 1157 | rcv->urb = usb_alloc_urb(0, GFP_KERNEL); |
1107 | dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)\n"); | 1158 | if (rcv->urb == NULL) { |
1159 | dev_dbg(&intf->dev, | ||
1160 | "out of memory (read urbs usb_alloc_urb)\n"); | ||
1108 | goto alloc_fail7; | 1161 | goto alloc_fail7; |
1109 | } | 1162 | } |
1110 | 1163 | ||
@@ -1117,26 +1170,29 @@ skip_normal_probe: | |||
1117 | rb->base = usb_buffer_alloc(acm->dev, readsize, | 1170 | rb->base = usb_buffer_alloc(acm->dev, readsize, |
1118 | GFP_KERNEL, &rb->dma); | 1171 | GFP_KERNEL, &rb->dma); |
1119 | if (!rb->base) { | 1172 | if (!rb->base) { |
1120 | dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)\n"); | 1173 | dev_dbg(&intf->dev, |
1174 | "out of memory (read bufs usb_buffer_alloc)\n"); | ||
1121 | goto alloc_fail7; | 1175 | goto alloc_fail7; |
1122 | } | 1176 | } |
1123 | } | 1177 | } |
1124 | for(i = 0; i < ACM_NW; i++) | 1178 | for (i = 0; i < ACM_NW; i++) { |
1125 | { | ||
1126 | struct acm_wb *snd = &(acm->wb[i]); | 1179 | struct acm_wb *snd = &(acm->wb[i]); |
1127 | 1180 | ||
1128 | if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) { | 1181 | snd->urb = usb_alloc_urb(0, GFP_KERNEL); |
1129 | dev_dbg(&intf->dev, "out of memory (write urbs usb_alloc_urb)"); | 1182 | if (snd->urb == NULL) { |
1183 | dev_dbg(&intf->dev, | ||
1184 | "out of memory (write urbs usb_alloc_urb)"); | ||
1130 | goto alloc_fail7; | 1185 | goto alloc_fail7; |
1131 | } | 1186 | } |
1132 | 1187 | ||
1133 | usb_fill_bulk_urb(snd->urb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), | 1188 | usb_fill_bulk_urb(snd->urb, usb_dev, |
1134 | NULL, acm->writesize, acm_write_bulk, snd); | 1189 | usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), |
1190 | NULL, acm->writesize, acm_write_bulk, snd); | ||
1135 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 1191 | snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1136 | snd->instance = acm; | 1192 | snd->instance = acm; |
1137 | } | 1193 | } |
1138 | 1194 | ||
1139 | usb_set_intfdata (intf, acm); | 1195 | usb_set_intfdata(intf, acm); |
1140 | 1196 | ||
1141 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); | 1197 | i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); |
1142 | if (i < 0) | 1198 | if (i < 0) |
@@ -1147,7 +1203,8 @@ skip_normal_probe: | |||
1147 | if (!acm->country_codes) | 1203 | if (!acm->country_codes) |
1148 | goto skip_countries; | 1204 | goto skip_countries; |
1149 | acm->country_code_size = cfd->bLength - 4; | 1205 | acm->country_code_size = cfd->bLength - 4; |
1150 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4); | 1206 | memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, |
1207 | cfd->bLength - 4); | ||
1151 | acm->country_rel_date = cfd->iCountryCodeRelDate; | 1208 | acm->country_rel_date = cfd->iCountryCodeRelDate; |
1152 | 1209 | ||
1153 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); | 1210 | i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); |
@@ -1156,7 +1213,8 @@ skip_normal_probe: | |||
1156 | goto skip_countries; | 1213 | goto skip_countries; |
1157 | } | 1214 | } |
1158 | 1215 | ||
1159 | i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate); | 1216 | i = device_create_file(&intf->dev, |
1217 | &dev_attr_iCountryCodeRelDate); | ||
1160 | if (i < 0) { | 1218 | if (i < 0) { |
1161 | kfree(acm->country_codes); | 1219 | kfree(acm->country_codes); |
1162 | goto skip_countries; | 1220 | goto skip_countries; |
@@ -1164,8 +1222,10 @@ skip_normal_probe: | |||
1164 | } | 1222 | } |
1165 | 1223 | ||
1166 | skip_countries: | 1224 | skip_countries: |
1167 | usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), | 1225 | usb_fill_int_urb(acm->ctrlurb, usb_dev, |
1168 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval); | 1226 | usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), |
1227 | acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, | ||
1228 | epctrl->bInterval); | ||
1169 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 1229 | acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
1170 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; | 1230 | acm->ctrlurb->transfer_dma = acm->ctrl_dma; |
1171 | 1231 | ||
@@ -1212,7 +1272,7 @@ static void stop_data_traffic(struct acm *acm) | |||
1212 | tasklet_disable(&acm->urb_task); | 1272 | tasklet_disable(&acm->urb_task); |
1213 | 1273 | ||
1214 | usb_kill_urb(acm->ctrlurb); | 1274 | usb_kill_urb(acm->ctrlurb); |
1215 | for(i = 0; i < ACM_NW; i++) | 1275 | for (i = 0; i < ACM_NW; i++) |
1216 | usb_kill_urb(acm->wb[i].urb); | 1276 | usb_kill_urb(acm->wb[i].urb); |
1217 | for (i = 0; i < acm->rx_buflimit; i++) | 1277 | for (i = 0; i < acm->rx_buflimit; i++) |
1218 | usb_kill_urb(acm->ru[i].urb); | 1278 | usb_kill_urb(acm->ru[i].urb); |
@@ -1227,13 +1287,14 @@ static void acm_disconnect(struct usb_interface *intf) | |||
1227 | { | 1287 | { |
1228 | struct acm *acm = usb_get_intfdata(intf); | 1288 | struct acm *acm = usb_get_intfdata(intf); |
1229 | struct usb_device *usb_dev = interface_to_usbdev(intf); | 1289 | struct usb_device *usb_dev = interface_to_usbdev(intf); |
1290 | struct tty_struct *tty; | ||
1230 | 1291 | ||
1231 | /* sibling interface is already cleaning up */ | 1292 | /* sibling interface is already cleaning up */ |
1232 | if (!acm) | 1293 | if (!acm) |
1233 | return; | 1294 | return; |
1234 | 1295 | ||
1235 | mutex_lock(&open_mutex); | 1296 | mutex_lock(&open_mutex); |
1236 | if (acm->country_codes){ | 1297 | if (acm->country_codes) { |
1237 | device_remove_file(&acm->control->dev, | 1298 | device_remove_file(&acm->control->dev, |
1238 | &dev_attr_wCountryCodes); | 1299 | &dev_attr_wCountryCodes); |
1239 | device_remove_file(&acm->control->dev, | 1300 | device_remove_file(&acm->control->dev, |
@@ -1247,22 +1308,25 @@ static void acm_disconnect(struct usb_interface *intf) | |||
1247 | stop_data_traffic(acm); | 1308 | stop_data_traffic(acm); |
1248 | 1309 | ||
1249 | acm_write_buffers_free(acm); | 1310 | acm_write_buffers_free(acm); |
1250 | usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); | 1311 | usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, |
1312 | acm->ctrl_dma); | ||
1251 | acm_read_buffers_free(acm); | 1313 | acm_read_buffers_free(acm); |
1252 | 1314 | ||
1253 | usb_driver_release_interface(&acm_driver, intf == acm->control ? | 1315 | usb_driver_release_interface(&acm_driver, intf == acm->control ? |
1254 | acm->data : acm->control); | 1316 | acm->data : acm->control); |
1255 | 1317 | ||
1256 | if (!acm->used) { | 1318 | if (acm->port.count == 0) { |
1257 | acm_tty_unregister(acm); | 1319 | acm_tty_unregister(acm); |
1258 | mutex_unlock(&open_mutex); | 1320 | mutex_unlock(&open_mutex); |
1259 | return; | 1321 | return; |
1260 | } | 1322 | } |
1261 | 1323 | ||
1262 | mutex_unlock(&open_mutex); | 1324 | mutex_unlock(&open_mutex); |
1263 | 1325 | tty = tty_port_tty_get(&acm->port); | |
1264 | if (acm->tty) | 1326 | if (tty) { |
1265 | tty_hangup(acm->tty); | 1327 | tty_hangup(tty); |
1328 | tty_kref_put(tty); | ||
1329 | } | ||
1266 | } | 1330 | } |
1267 | 1331 | ||
1268 | #ifdef CONFIG_PM | 1332 | #ifdef CONFIG_PM |
@@ -1297,7 +1361,7 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message) | |||
1297 | */ | 1361 | */ |
1298 | mutex_lock(&acm->mutex); | 1362 | mutex_lock(&acm->mutex); |
1299 | 1363 | ||
1300 | if (acm->used) | 1364 | if (acm->port.count) |
1301 | stop_data_traffic(acm); | 1365 | stop_data_traffic(acm); |
1302 | 1366 | ||
1303 | mutex_unlock(&acm->mutex); | 1367 | mutex_unlock(&acm->mutex); |
@@ -1319,7 +1383,7 @@ static int acm_resume(struct usb_interface *intf) | |||
1319 | return 0; | 1383 | return 0; |
1320 | 1384 | ||
1321 | mutex_lock(&acm->mutex); | 1385 | mutex_lock(&acm->mutex); |
1322 | if (acm->used) { | 1386 | if (acm->port.count) { |
1323 | rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); | 1387 | rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); |
1324 | if (rv < 0) | 1388 | if (rv < 0) |
1325 | goto err_out; | 1389 | goto err_out; |
@@ -1375,6 +1439,9 @@ static struct usb_device_id acm_ids[] = { | |||
1375 | { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */ | 1439 | { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */ |
1376 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | 1440 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ |
1377 | }, | 1441 | }, |
1442 | { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */ | ||
1443 | .driver_info = NO_UNION_NORMAL, /* has no union descriptor */ | ||
1444 | }, | ||
1378 | { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */ | 1445 | { USB_DEVICE(0x22b8, 0x6425), /* Motorola MOTOMAGX phones */ |
1379 | }, | 1446 | }, |
1380 | { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */ | 1447 | { USB_DEVICE(0x0572, 0x1329), /* Hummingbird huc56s (Conexant) */ |
@@ -1395,7 +1462,7 @@ static struct usb_device_id acm_ids[] = { | |||
1395 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1462 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1396 | USB_CDC_ACM_PROTO_AT_GSM) }, | 1463 | USB_CDC_ACM_PROTO_AT_GSM) }, |
1397 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1464 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1398 | USB_CDC_ACM_PROTO_AT_3G ) }, | 1465 | USB_CDC_ACM_PROTO_AT_3G) }, |
1399 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, | 1466 | { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, |
1400 | USB_CDC_ACM_PROTO_AT_CDMA) }, | 1467 | USB_CDC_ACM_PROTO_AT_CDMA) }, |
1401 | 1468 | ||
@@ -1403,7 +1470,7 @@ static struct usb_device_id acm_ids[] = { | |||
1403 | { } | 1470 | { } |
1404 | }; | 1471 | }; |
1405 | 1472 | ||
1406 | MODULE_DEVICE_TABLE (usb, acm_ids); | 1473 | MODULE_DEVICE_TABLE(usb, acm_ids); |
1407 | 1474 | ||
1408 | static struct usb_driver acm_driver = { | 1475 | static struct usb_driver acm_driver = { |
1409 | .name = "cdc_acm", | 1476 | .name = "cdc_acm", |
@@ -1426,6 +1493,7 @@ static struct usb_driver acm_driver = { | |||
1426 | static const struct tty_operations acm_ops = { | 1493 | static const struct tty_operations acm_ops = { |
1427 | .open = acm_tty_open, | 1494 | .open = acm_tty_open, |
1428 | .close = acm_tty_close, | 1495 | .close = acm_tty_close, |
1496 | .hangup = acm_tty_hangup, | ||
1429 | .write = acm_tty_write, | 1497 | .write = acm_tty_write, |
1430 | .write_room = acm_tty_write_room, | 1498 | .write_room = acm_tty_write_room, |
1431 | .ioctl = acm_tty_ioctl, | 1499 | .ioctl = acm_tty_ioctl, |
@@ -1457,7 +1525,8 @@ static int __init acm_init(void) | |||
1457 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, | 1525 | acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, |
1458 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; | 1526 | acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; |
1459 | acm_tty_driver->init_termios = tty_std_termios; | 1527 | acm_tty_driver->init_termios = tty_std_termios; |
1460 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; | 1528 | acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | |
1529 | HUPCL | CLOCAL; | ||
1461 | tty_set_operations(acm_tty_driver, &acm_ops); | 1530 | tty_set_operations(acm_tty_driver, &acm_ops); |
1462 | 1531 | ||
1463 | retval = tty_register_driver(acm_tty_driver); | 1532 | retval = tty_register_driver(acm_tty_driver); |
@@ -1489,7 +1558,7 @@ static void __exit acm_exit(void) | |||
1489 | module_init(acm_init); | 1558 | module_init(acm_init); |
1490 | module_exit(acm_exit); | 1559 | module_exit(acm_exit); |
1491 | 1560 | ||
1492 | MODULE_AUTHOR( DRIVER_AUTHOR ); | 1561 | MODULE_AUTHOR(DRIVER_AUTHOR); |
1493 | MODULE_DESCRIPTION( DRIVER_DESC ); | 1562 | MODULE_DESCRIPTION(DRIVER_DESC); |
1494 | MODULE_LICENSE("GPL"); | 1563 | MODULE_LICENSE("GPL"); |
1495 | MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); | 1564 | MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); |