Lines Matching +full:overrun +full:- +full:throttle +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0+
3 * cdc-acm.c
42 #include "cdc-acm.h"
72 mutex_lock(&acm->mutex); in acm_get_by_minor()
73 if (acm->disconnected) { in acm_get_by_minor()
74 mutex_unlock(&acm->mutex); in acm_get_by_minor()
77 tty_port_get(&acm->port); in acm_get_by_minor()
78 mutex_unlock(&acm->mutex); in acm_get_by_minor()
103 idr_remove(&acm_minors, acm->minor); in acm_release_minor()
116 retval = usb_autopm_get_interface(acm->control); in acm_ctrl_msg()
120 retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), in acm_ctrl_msg()
122 acm->control->altsetting[0].desc.bInterfaceNumber, in acm_ctrl_msg()
125 dev_dbg(&acm->control->dev, in acm_ctrl_msg()
126 "%s - rq 0x%02x, val %#x, len %#x, result %d\n", in acm_ctrl_msg()
129 usb_autopm_put_interface(acm->control); in acm_ctrl_msg()
139 if (acm->quirks & QUIRK_CONTROL_LINE_STATE) in acm_set_control()
140 return -EOPNOTSUPP; in acm_set_control()
148 #define acm_send_break(acm, ms) \ argument
149 acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0)
155 usb_poison_urb(acm->ctrlurb); in acm_poison_urbs()
157 usb_poison_urb(acm->wb[i].urb); in acm_poison_urbs()
158 for (i = 0; i < acm->rx_buflimit; i++) in acm_poison_urbs()
159 usb_poison_urb(acm->read_urbs[i]); in acm_poison_urbs()
166 for (i = 0; i < acm->rx_buflimit; i++) in acm_unpoison_urbs()
167 usb_unpoison_urb(acm->read_urbs[i]); in acm_unpoison_urbs()
169 usb_unpoison_urb(acm->wb[i].urb); in acm_unpoison_urbs()
170 usb_unpoison_urb(acm->ctrlurb); in acm_unpoison_urbs()
187 wb = &acm->wb[wbn]; in acm_wb_alloc()
188 if (!wb->use) { in acm_wb_alloc()
189 wb->use = true; in acm_wb_alloc()
190 wb->len = 0; in acm_wb_alloc()
195 return -1; in acm_wb_alloc()
205 spin_lock_irqsave(&acm->write_lock, flags); in acm_wb_is_avail()
207 if(acm->wb[i].use) in acm_wb_is_avail()
208 n--; in acm_wb_is_avail()
209 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_wb_is_avail()
214 * Finish write. Caller must hold acm->write_lock
218 wb->use = false; in acm_write_done()
219 acm->transmitting--; in acm_write_done()
220 usb_autopm_put_interface_async(acm->control); in acm_write_done()
233 acm->transmitting++; in acm_start_wb()
235 wb->urb->transfer_buffer = wb->buf; in acm_start_wb()
236 wb->urb->transfer_dma = wb->dmah; in acm_start_wb()
237 wb->urb->transfer_buffer_length = wb->len; in acm_start_wb()
238 wb->urb->dev = acm->dev; in acm_start_wb()
240 rc = usb_submit_urb(wb->urb, GFP_ATOMIC); in acm_start_wb()
242 if (rc != -EPERM) in acm_start_wb()
243 dev_err(&acm->data->dev, in acm_start_wb()
244 "%s - usb_submit_urb(write bulk) failed: %d\n", in acm_start_wb()
260 return sprintf(buf, "%d", acm->ctrl_caps); in bmCapabilities_show()
270 memcpy(buf, acm->country_codes, acm->country_code_size); in wCountryCodes_show()
271 return acm->country_code_size; in wCountryCodes_show()
282 return sprintf(buf, "%d", acm->country_rel_date); in iCountryCodeRelDate_show()
298 switch (dr->bNotificationType) { in acm_process_notification()
300 dev_dbg(&acm->control->dev, in acm_process_notification()
301 "%s - network connection: %d\n", __func__, dr->wValue); in acm_process_notification()
305 if (le16_to_cpu(dr->wLength) != 2) { in acm_process_notification()
306 dev_dbg(&acm->control->dev, in acm_process_notification()
307 "%s - malformed serial state\n", __func__); in acm_process_notification()
312 dev_dbg(&acm->control->dev, in acm_process_notification()
313 "%s - serial state: 0x%x\n", __func__, newctrl); in acm_process_notification()
315 if (!acm->clocal && (acm->ctrlin & ~newctrl & USB_CDC_SERIAL_STATE_DCD)) { in acm_process_notification()
316 dev_dbg(&acm->control->dev, in acm_process_notification()
317 "%s - calling hangup\n", __func__); in acm_process_notification()
318 tty_port_tty_hangup(&acm->port, false); in acm_process_notification()
321 difference = acm->ctrlin ^ newctrl; in acm_process_notification()
323 if ((difference & USB_CDC_SERIAL_STATE_DCD) && acm->port.tty) { in acm_process_notification()
324 struct tty_ldisc *ld = tty_ldisc_ref(acm->port.tty); in acm_process_notification()
326 if (ld->ops->dcd_change) in acm_process_notification()
327 ld->ops->dcd_change(acm->port.tty, newctrl & USB_CDC_SERIAL_STATE_DCD); in acm_process_notification()
332 spin_lock_irqsave(&acm->read_lock, flags); in acm_process_notification()
333 acm->ctrlin = newctrl; in acm_process_notification()
334 acm->oldcount = acm->iocount; in acm_process_notification()
337 acm->iocount.dsr++; in acm_process_notification()
339 acm->iocount.dcd++; in acm_process_notification()
341 acm->iocount.brk++; in acm_process_notification()
342 tty_insert_flip_char(&acm->port, 0, TTY_BREAK); in acm_process_notification()
345 acm->iocount.rng++; in acm_process_notification()
347 acm->iocount.frame++; in acm_process_notification()
349 acm->iocount.parity++; in acm_process_notification()
351 acm->iocount.overrun++; in acm_process_notification()
352 spin_unlock_irqrestore(&acm->read_lock, flags); in acm_process_notification()
355 tty_flip_buffer_push(&acm->port); in acm_process_notification()
358 wake_up_all(&acm->wioctl); in acm_process_notification()
363 dev_dbg(&acm->control->dev, in acm_process_notification()
364 "%s - unknown notification %d received: index %d len %d\n", in acm_process_notification()
366 dr->bNotificationType, dr->wIndex, dr->wLength); in acm_process_notification()
373 struct acm *acm = urb->context; in acm_ctrl_irq()
374 struct usb_cdc_notification *dr = urb->transfer_buffer; in acm_ctrl_irq()
375 unsigned int current_size = urb->actual_length; in acm_ctrl_irq()
378 int status = urb->status; in acm_ctrl_irq()
384 case -ECONNRESET: in acm_ctrl_irq()
385 case -ENOENT: in acm_ctrl_irq()
386 case -ESHUTDOWN: in acm_ctrl_irq()
388 dev_dbg(&acm->control->dev, in acm_ctrl_irq()
389 "%s - urb shutting down with status: %d\n", in acm_ctrl_irq()
393 dev_dbg(&acm->control->dev, in acm_ctrl_irq()
394 "%s - nonzero urb status received: %d\n", in acm_ctrl_irq()
399 usb_mark_last_busy(acm->dev); in acm_ctrl_irq()
401 if (acm->nb_index) in acm_ctrl_irq()
402 dr = (struct usb_cdc_notification *)acm->notification_buffer; in acm_ctrl_irq()
404 /* size = notification-header + (optional) data */ in acm_ctrl_irq()
406 le16_to_cpu(dr->wLength); in acm_ctrl_irq()
410 if (acm->nb_size < expected_size) { in acm_ctrl_irq()
414 new_buffer = krealloc(acm->notification_buffer, in acm_ctrl_irq()
417 acm->nb_index = 0; in acm_ctrl_irq()
421 acm->notification_buffer = new_buffer; in acm_ctrl_irq()
422 acm->nb_size = alloc_size; in acm_ctrl_irq()
423 dr = (struct usb_cdc_notification *)acm->notification_buffer; in acm_ctrl_irq()
427 expected_size - acm->nb_index); in acm_ctrl_irq()
429 memcpy(&acm->notification_buffer[acm->nb_index], in acm_ctrl_irq()
430 urb->transfer_buffer, copy_size); in acm_ctrl_irq()
431 acm->nb_index += copy_size; in acm_ctrl_irq()
432 current_size = acm->nb_index; in acm_ctrl_irq()
438 acm->nb_index = 0; in acm_ctrl_irq()
443 if (retval && retval != -EPERM && retval != -ENODEV) in acm_ctrl_irq()
444 dev_err(&acm->control->dev, in acm_ctrl_irq()
445 "%s - usb_submit_urb failed: %d\n", __func__, retval); in acm_ctrl_irq()
447 dev_vdbg(&acm->control->dev, in acm_ctrl_irq()
455 if (!test_and_clear_bit(index, &acm->read_urbs_free)) in acm_submit_read_urb()
458 res = usb_submit_urb(acm->read_urbs[index], mem_flags); in acm_submit_read_urb()
460 if (res != -EPERM && res != -ENODEV) { in acm_submit_read_urb()
461 dev_err(&acm->data->dev, in acm_submit_read_urb()
465 dev_vdbg(&acm->data->dev, "intended failure %d\n", res); in acm_submit_read_urb()
467 set_bit(index, &acm->read_urbs_free); in acm_submit_read_urb()
470 dev_vdbg(&acm->data->dev, "submitted urb %d\n", index); in acm_submit_read_urb()
481 for (i = 0; i < acm->rx_buflimit; ++i) { in acm_submit_read_urbs()
494 if (!urb->actual_length) in acm_process_read_urb()
497 spin_lock_irqsave(&acm->read_lock, flags); in acm_process_read_urb()
498 tty_insert_flip_string(&acm->port, urb->transfer_buffer, in acm_process_read_urb()
499 urb->actual_length); in acm_process_read_urb()
500 spin_unlock_irqrestore(&acm->read_lock, flags); in acm_process_read_urb()
502 tty_flip_buffer_push(&acm->port); in acm_process_read_urb()
507 struct acm_rb *rb = urb->context; in acm_read_bulk_callback()
508 struct acm *acm = rb->instance; in acm_read_bulk_callback()
509 int status = urb->status; in acm_read_bulk_callback()
514 dev_vdbg(&acm->data->dev, "got urb %d, len %d, status %d\n", in acm_read_bulk_callback()
515 rb->index, urb->actual_length, status); in acm_read_bulk_callback()
519 usb_mark_last_busy(acm->dev); in acm_read_bulk_callback()
522 case -EPIPE: in acm_read_bulk_callback()
523 set_bit(EVENT_RX_STALL, &acm->flags); in acm_read_bulk_callback()
526 case -ENOENT: in acm_read_bulk_callback()
527 case -ECONNRESET: in acm_read_bulk_callback()
528 case -ESHUTDOWN: in acm_read_bulk_callback()
529 dev_dbg(&acm->data->dev, in acm_read_bulk_callback()
530 "%s - urb shutting down with status: %d\n", in acm_read_bulk_callback()
534 case -EOVERFLOW: in acm_read_bulk_callback()
535 case -EPROTO: in acm_read_bulk_callback()
536 dev_dbg(&acm->data->dev, in acm_read_bulk_callback()
537 "%s - cooling babbling device\n", __func__); in acm_read_bulk_callback()
538 usb_mark_last_busy(acm->dev); in acm_read_bulk_callback()
539 set_bit(rb->index, &acm->urbs_in_error_delay); in acm_read_bulk_callback()
540 set_bit(ACM_ERROR_DELAY, &acm->flags); in acm_read_bulk_callback()
544 dev_dbg(&acm->data->dev, in acm_read_bulk_callback()
545 "%s - nonzero urb status received: %d\n", in acm_read_bulk_callback()
556 set_bit(rb->index, &acm->read_urbs_free); in acm_read_bulk_callback()
566 schedule_delayed_work(&acm->dwork, 0); in acm_read_bulk_callback()
568 schedule_delayed_work(&acm->dwork, HZ / 2); in acm_read_bulk_callback()
572 if (test_bit(ACM_THROTTLED, &acm->flags)) in acm_read_bulk_callback()
575 acm_submit_read_urb(acm, rb->index, GFP_ATOMIC); in acm_read_bulk_callback()
581 struct acm_wb *wb = urb->context; in acm_write_bulk()
582 struct acm *acm = wb->instance; in acm_write_bulk()
584 int status = urb->status; in acm_write_bulk()
586 if (status || (urb->actual_length != urb->transfer_buffer_length)) in acm_write_bulk()
587 dev_vdbg(&acm->data->dev, "wrote len %d/%d, status %d\n", in acm_write_bulk()
588 urb->actual_length, in acm_write_bulk()
589 urb->transfer_buffer_length, in acm_write_bulk()
592 spin_lock_irqsave(&acm->write_lock, flags); in acm_write_bulk()
594 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_write_bulk()
595 set_bit(EVENT_TTY_WAKEUP, &acm->flags); in acm_write_bulk()
596 schedule_delayed_work(&acm->dwork, 0); in acm_write_bulk()
604 if (test_bit(EVENT_RX_STALL, &acm->flags)) { in acm_softint()
606 if (!acm->susp_count) { in acm_softint()
607 for (i = 0; i < acm->rx_buflimit; i++) in acm_softint()
608 usb_kill_urb(acm->read_urbs[i]); in acm_softint()
609 usb_clear_halt(acm->dev, acm->in); in acm_softint()
611 clear_bit(EVENT_RX_STALL, &acm->flags); in acm_softint()
615 if (test_and_clear_bit(ACM_ERROR_DELAY, &acm->flags)) { in acm_softint()
616 for (i = 0; i < acm->rx_buflimit; i++) in acm_softint()
617 if (test_and_clear_bit(i, &acm->urbs_in_error_delay)) in acm_softint()
621 if (test_and_clear_bit(EVENT_TTY_WAKEUP, &acm->flags)) in acm_softint()
622 tty_port_tty_wakeup(&acm->port); in acm_softint()
634 acm = acm_get_by_minor(tty->index); in acm_tty_install()
636 return -ENODEV; in acm_tty_install()
646 if (acm->quirks & DISABLE_ECHO) in acm_tty_install()
647 tty->termios.c_lflag &= ~ECHO; in acm_tty_install()
649 tty->driver_data = acm; in acm_tty_install()
654 tty_port_put(&acm->port); in acm_tty_install()
660 struct acm *acm = tty->driver_data; in acm_tty_open()
662 return tty_port_open(&acm->port, tty, filp); in acm_tty_open()
677 acm->ctrlout = val; in acm_port_dtr_rts()
680 if (res && (acm->ctrl_caps & USB_CDC_CAP_LINE)) in acm_port_dtr_rts()
682 dev_dbg(&acm->control->dev, "failed to set dtr/rts\n"); in acm_port_dtr_rts()
688 int retval = -ENODEV; in acm_port_activate()
691 mutex_lock(&acm->mutex); in acm_port_activate()
692 if (acm->disconnected) in acm_port_activate()
695 retval = usb_autopm_get_interface(acm->control); in acm_port_activate()
699 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); in acm_port_activate()
700 acm->control->needs_remote_wakeup = 1; in acm_port_activate()
702 acm->ctrlurb->dev = acm->dev; in acm_port_activate()
703 retval = usb_submit_urb(acm->ctrlurb, GFP_KERNEL); in acm_port_activate()
705 dev_err(&acm->control->dev, in acm_port_activate()
706 "%s - usb_submit_urb(ctrl irq) failed\n", __func__); in acm_port_activate()
715 clear_bit(ACM_THROTTLED, &acm->flags); in acm_port_activate()
721 usb_autopm_put_interface(acm->control); in acm_port_activate()
723 mutex_unlock(&acm->mutex); in acm_port_activate()
728 for (i = 0; i < acm->rx_buflimit; i++) in acm_port_activate()
729 usb_kill_urb(acm->read_urbs[i]); in acm_port_activate()
730 usb_kill_urb(acm->ctrlurb); in acm_port_activate()
732 usb_autopm_put_interface(acm->control); in acm_port_activate()
735 mutex_unlock(&acm->mutex); in acm_port_activate()
744 if (acm->minor != ACM_MINOR_INVALID) in acm_port_destruct()
746 usb_put_intf(acm->control); in acm_port_destruct()
747 kfree(acm->country_codes); in acm_port_destruct()
759 * hold it due to the tty-port initialised flag. in acm_port_shutdown()
762 spin_lock_irq(&acm->write_lock); in acm_port_shutdown()
763 spin_unlock_irq(&acm->write_lock); in acm_port_shutdown()
765 usb_autopm_get_interface_no_resume(acm->control); in acm_port_shutdown()
766 acm->control->needs_remote_wakeup = 0; in acm_port_shutdown()
767 usb_autopm_put_interface(acm->control); in acm_port_shutdown()
770 urb = usb_get_from_anchor(&acm->delayed); in acm_port_shutdown()
773 wb = urb->context; in acm_port_shutdown()
774 wb->use = false; in acm_port_shutdown()
775 usb_autopm_put_interface_async(acm->control); in acm_port_shutdown()
784 struct acm *acm = tty->driver_data; in acm_tty_cleanup()
786 tty_port_put(&acm->port); in acm_tty_cleanup()
791 struct acm *acm = tty->driver_data; in acm_tty_hangup()
793 tty_port_hangup(&acm->port); in acm_tty_hangup()
798 struct acm *acm = tty->driver_data; in acm_tty_close()
800 tty_port_close(&acm->port, tty, filp); in acm_tty_close()
806 struct acm *acm = tty->driver_data; in acm_tty_write()
815 dev_vdbg(&acm->data->dev, "%zu bytes from tty layer\n", count); in acm_tty_write()
817 spin_lock_irqsave(&acm->write_lock, flags); in acm_tty_write()
820 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_tty_write()
823 wb = &acm->wb[wbn]; in acm_tty_write()
825 if (!acm->dev) { in acm_tty_write()
826 wb->use = false; in acm_tty_write()
827 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_tty_write()
828 return -ENODEV; in acm_tty_write()
831 count = (count > acm->writesize) ? acm->writesize : count; in acm_tty_write()
832 dev_vdbg(&acm->data->dev, "writing %zu bytes\n", count); in acm_tty_write()
833 memcpy(wb->buf, buf, count); in acm_tty_write()
834 wb->len = count; in acm_tty_write()
836 stat = usb_autopm_get_interface_async(acm->control); in acm_tty_write()
838 wb->use = false; in acm_tty_write()
839 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_tty_write()
843 if (acm->susp_count) { in acm_tty_write()
844 usb_anchor_urb(wb->urb, &acm->delayed); in acm_tty_write()
845 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_tty_write()
850 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_tty_write()
859 struct acm *acm = tty->driver_data; in acm_tty_write_room()
864 return acm_wb_is_avail(acm) ? acm->writesize : 0; in acm_tty_write_room()
869 struct acm *acm = tty->driver_data; in acm_tty_flush_buffer()
873 spin_lock_irqsave(&acm->write_lock, flags); in acm_tty_flush_buffer()
875 if (acm->wb[i].use) in acm_tty_flush_buffer()
876 usb_unlink_urb(acm->wb[i].urb); in acm_tty_flush_buffer()
877 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_tty_flush_buffer()
882 struct acm *acm = tty->driver_data; in acm_tty_chars_in_buffer()
887 if (acm->disconnected) in acm_tty_chars_in_buffer()
892 return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize; in acm_tty_chars_in_buffer()
897 struct acm *acm = tty->driver_data; in acm_tty_throttle()
899 set_bit(ACM_THROTTLED, &acm->flags); in acm_tty_throttle()
904 struct acm *acm = tty->driver_data; in acm_tty_unthrottle()
906 clear_bit(ACM_THROTTLED, &acm->flags); in acm_tty_unthrottle()
916 struct acm *acm = tty->driver_data; in acm_tty_break_ctl()
919 if (!(acm->ctrl_caps & USB_CDC_CAP_BRK)) in acm_tty_break_ctl()
920 return -EOPNOTSUPP; in acm_tty_break_ctl()
924 dev_dbg(&acm->control->dev, in acm_tty_break_ctl()
925 "%s - send break failed\n", __func__); in acm_tty_break_ctl()
931 struct acm *acm = tty->driver_data; in acm_tty_tiocmget()
933 return (acm->ctrlout & USB_CDC_CTRL_DTR ? TIOCM_DTR : 0) | in acm_tty_tiocmget()
934 (acm->ctrlout & USB_CDC_CTRL_RTS ? TIOCM_RTS : 0) | in acm_tty_tiocmget()
935 (acm->ctrlin & USB_CDC_SERIAL_STATE_DSR ? TIOCM_DSR : 0) | in acm_tty_tiocmget()
936 (acm->ctrlin & USB_CDC_SERIAL_STATE_RING_SIGNAL ? TIOCM_RI : 0) | in acm_tty_tiocmget()
937 (acm->ctrlin & USB_CDC_SERIAL_STATE_DCD ? TIOCM_CD : 0) | in acm_tty_tiocmget()
944 struct acm *acm = tty->driver_data; in acm_tty_tiocmset()
947 newctrl = acm->ctrlout; in acm_tty_tiocmset()
955 if (acm->ctrlout == newctrl) in acm_tty_tiocmset()
957 return acm_set_control(acm, acm->ctrlout = newctrl); in acm_tty_tiocmset()
962 struct acm *acm = tty->driver_data; in get_serial_info()
964 ss->line = acm->minor; in get_serial_info()
965 mutex_lock(&acm->port.mutex); in get_serial_info()
966 ss->close_delay = jiffies_to_msecs(acm->port.close_delay) / 10; in get_serial_info()
967 ss->closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? in get_serial_info()
969 jiffies_to_msecs(acm->port.closing_wait) / 10; in get_serial_info()
970 mutex_unlock(&acm->port.mutex); in get_serial_info()
976 struct acm *acm = tty->driver_data; in set_serial_info()
980 close_delay = msecs_to_jiffies(ss->close_delay * 10); in set_serial_info()
981 closing_wait = ss->closing_wait == ASYNC_CLOSING_WAIT_NONE ? in set_serial_info()
983 msecs_to_jiffies(ss->closing_wait * 10); in set_serial_info()
985 mutex_lock(&acm->port.mutex); in set_serial_info()
988 if ((close_delay != acm->port.close_delay) || in set_serial_info()
989 (closing_wait != acm->port.closing_wait)) in set_serial_info()
990 retval = -EPERM; in set_serial_info()
992 acm->port.close_delay = close_delay; in set_serial_info()
993 acm->port.closing_wait = closing_wait; in set_serial_info()
996 mutex_unlock(&acm->port.mutex); in set_serial_info()
1007 spin_lock_irq(&acm->read_lock); in wait_serial_change()
1008 old = acm->oldcount; in wait_serial_change()
1009 new = acm->iocount; in wait_serial_change()
1010 acm->oldcount = new; in wait_serial_change()
1011 spin_unlock_irq(&acm->read_lock); in wait_serial_change()
1023 add_wait_queue(&acm->wioctl, &wait); in wait_serial_change()
1026 remove_wait_queue(&acm->wioctl, &wait); in wait_serial_change()
1027 if (acm->disconnected) { in wait_serial_change()
1031 rv = -ENODEV; in wait_serial_change()
1034 rv = -ERESTARTSYS; in wait_serial_change()
1046 struct acm *acm = tty->driver_data; in acm_tty_get_icount()
1048 icount->dsr = acm->iocount.dsr; in acm_tty_get_icount()
1049 icount->rng = acm->iocount.rng; in acm_tty_get_icount()
1050 icount->dcd = acm->iocount.dcd; in acm_tty_get_icount()
1051 icount->frame = acm->iocount.frame; in acm_tty_get_icount()
1052 icount->overrun = acm->iocount.overrun; in acm_tty_get_icount()
1053 icount->parity = acm->iocount.parity; in acm_tty_get_icount()
1054 icount->brk = acm->iocount.brk; in acm_tty_get_icount()
1062 struct acm *acm = tty->driver_data; in acm_tty_ioctl()
1063 int rv = -ENOIOCTLCMD; in acm_tty_ioctl()
1067 rv = usb_autopm_get_interface(acm->control); in acm_tty_ioctl()
1069 rv = -EIO; in acm_tty_ioctl()
1073 usb_autopm_put_interface(acm->control); in acm_tty_ioctl()
1083 struct acm *acm = tty->driver_data; in acm_tty_set_termios()
1084 struct ktermios *termios = &tty->termios; in acm_tty_set_termios()
1086 int newctrl = acm->ctrlout; in acm_tty_set_termios()
1089 newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; in acm_tty_set_termios()
1090 newline.bParityType = termios->c_cflag & PARENB ? in acm_tty_set_termios()
1091 (termios->c_cflag & PARODD ? 1 : 2) + in acm_tty_set_termios()
1092 (termios->c_cflag & CMSPAR ? 2 : 0) : 0; in acm_tty_set_termios()
1093 newline.bDataBits = tty_get_char_size(termios->c_cflag); in acm_tty_set_termios()
1096 acm->clocal = ((termios->c_cflag & CLOCAL) != 0); in acm_tty_set_termios()
1099 newline.dwDTERate = acm->line.dwDTERate; in acm_tty_set_termios()
1101 } else if (termios_old && (termios_old->c_cflag & CBAUD) == B0) { in acm_tty_set_termios()
1105 if (newctrl != acm->ctrlout) in acm_tty_set_termios()
1106 acm_set_control(acm, acm->ctrlout = newctrl); in acm_tty_set_termios()
1108 if (memcmp(&acm->line, &newline, sizeof newline)) { in acm_tty_set_termios()
1109 memcpy(&acm->line, &newline, sizeof newline); in acm_tty_set_termios()
1110 dev_dbg(&acm->control->dev, "%s - set line: %d %d %d %d\n", in acm_tty_set_termios()
1115 acm_set_line(acm, &acm->line); in acm_tty_set_termios()
1136 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) in acm_write_buffers_free()
1137 usb_free_coherent(acm->dev, acm->writesize, wb->buf, wb->dmah); in acm_write_buffers_free()
1144 for (i = 0; i < acm->rx_buflimit; i++) in acm_read_buffers_free()
1145 usb_free_coherent(acm->dev, acm->readsize, in acm_read_buffers_free()
1146 acm->read_buffers[i].base, acm->read_buffers[i].dma); in acm_read_buffers_free()
1155 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { in acm_write_buffers_alloc()
1156 wb->buf = usb_alloc_coherent(acm->dev, acm->writesize, GFP_KERNEL, in acm_write_buffers_alloc()
1157 &wb->dmah); in acm_write_buffers_alloc()
1158 if (!wb->buf) { in acm_write_buffers_alloc()
1160 --i; in acm_write_buffers_alloc()
1161 --wb; in acm_write_buffers_alloc()
1162 usb_free_coherent(acm->dev, acm->writesize, in acm_write_buffers_alloc()
1163 wb->buf, wb->dmah); in acm_write_buffers_alloc()
1165 return -ENOMEM; in acm_write_buffers_alloc()
1176 unsigned char *buffer = intf->altsetting->extra; in acm_probe()
1177 int buflen = intf->altsetting->extralen; in acm_probe()
1189 int call_intf_num = -1; in acm_probe()
1190 int data_intf_num = -1; in acm_probe()
1196 int rv = -ENOMEM; in acm_probe()
1200 quirks = (unsigned long)id->driver_info; in acm_probe()
1203 return -ENODEV; in acm_probe()
1215 return -ENODEV; in acm_probe()
1221 dev_err(&intf->dev, "Weird descriptor references\n"); in acm_probe()
1222 return -EINVAL; in acm_probe()
1226 if (intf->cur_altsetting->endpoint && in acm_probe()
1227 intf->cur_altsetting->endpoint->extralen && in acm_probe()
1228 intf->cur_altsetting->endpoint->extra) { in acm_probe()
1229 dev_dbg(&intf->dev, in acm_probe()
1231 buflen = intf->cur_altsetting->endpoint->extralen; in acm_probe()
1232 buffer = intf->cur_altsetting->endpoint->extra; in acm_probe()
1234 dev_err(&intf->dev, in acm_probe()
1236 return -EINVAL; in acm_probe()
1244 call_intf_num = cmgmd->bDataInterface; in acm_probe()
1247 if (intf->cur_altsetting->desc.bNumEndpoints == 3) { in acm_probe()
1248 dev_dbg(&intf->dev, "No union descriptor, assuming single interface\n"); in acm_probe()
1253 dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n"); in acm_probe()
1258 dev_dbg(&intf->dev, "No union descriptor, giving up\n"); in acm_probe()
1259 return -ENODEV; in acm_probe()
1262 int class = -1; in acm_probe()
1264 data_intf_num = union_header->bSlaveInterface0; in acm_probe()
1265 control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); in acm_probe()
1269 class = control_interface->cur_altsetting->desc.bInterfaceClass; in acm_probe()
1272 dev_dbg(&intf->dev, "Broken union descriptor, assuming single interface\n"); in acm_probe()
1280 dev_dbg(&intf->dev, "no interfaces\n"); in acm_probe()
1281 return -ENODEV; in acm_probe()
1285 dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); in acm_probe()
1289 dev_warn(&intf->dev,"Control and data interfaces are not separated!\n"); in acm_probe()
1293 if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) { in acm_probe()
1294 dev_err(&intf->dev, "This needs exactly 3 endpoints\n"); in acm_probe()
1295 return -EINVAL; in acm_probe()
1298 res = usb_find_common_endpoints(data_interface->cur_altsetting, in acm_probe()
1309 if (data_interface->cur_altsetting->desc.bInterfaceClass != USB_CLASS_CDC_DATA) { in acm_probe()
1310 if (control_interface->cur_altsetting->desc.bInterfaceClass == USB_CLASS_CDC_DATA) { in acm_probe()
1311 dev_dbg(&intf->dev, in acm_probe()
1315 return -EINVAL; in acm_probe()
1321 return -ENODEV; in acm_probe()
1323 if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 || in acm_probe()
1324 control_interface->cur_altsetting->desc.bNumEndpoints == 0) in acm_probe()
1325 return -EINVAL; in acm_probe()
1327 epctrl = &control_interface->cur_altsetting->endpoint[0].desc; in acm_probe()
1328 epread = &data_interface->cur_altsetting->endpoint[0].desc; in acm_probe()
1329 epwrite = &data_interface->cur_altsetting->endpoint[1].desc; in acm_probe()
1335 dev_dbg(&intf->dev, in acm_probe()
1340 dev_dbg(&intf->dev, "interfaces are valid\n"); in acm_probe()
1344 return -ENOMEM; in acm_probe()
1346 tty_port_init(&acm->port); in acm_probe()
1347 acm->port.ops = &acm_port_ops; in acm_probe()
1352 acm->combined_interfaces = combined_interfaces; in acm_probe()
1353 acm->writesize = usb_endpoint_maxp(epwrite) * 20; in acm_probe()
1354 acm->control = control_interface; in acm_probe()
1355 acm->data = data_interface; in acm_probe()
1357 usb_get_intf(acm->control); /* undone in destruct() */ in acm_probe()
1361 acm->minor = ACM_MINOR_INVALID; in acm_probe()
1365 acm->minor = minor; in acm_probe()
1366 acm->dev = usb_dev; in acm_probe()
1368 acm->ctrl_caps = h.usb_cdc_acm_descriptor->bmCapabilities; in acm_probe()
1370 acm->ctrl_caps &= ~USB_CDC_CAP_LINE; in acm_probe()
1371 acm->ctrlsize = ctrlsize; in acm_probe()
1372 acm->readsize = readsize; in acm_probe()
1373 acm->rx_buflimit = num_rx_buf; in acm_probe()
1374 INIT_DELAYED_WORK(&acm->dwork, acm_softint); in acm_probe()
1375 init_waitqueue_head(&acm->wioctl); in acm_probe()
1376 spin_lock_init(&acm->write_lock); in acm_probe()
1377 spin_lock_init(&acm->read_lock); in acm_probe()
1378 mutex_init(&acm->mutex); in acm_probe()
1380 acm->bInterval = epread->bInterval; in acm_probe()
1381 acm->in = usb_rcvintpipe(usb_dev, epread->bEndpointAddress); in acm_probe()
1383 acm->in = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); in acm_probe()
1386 acm->out = usb_sndintpipe(usb_dev, epwrite->bEndpointAddress); in acm_probe()
1388 acm->out = usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress); in acm_probe()
1389 init_usb_anchor(&acm->delayed); in acm_probe()
1390 acm->quirks = quirks; in acm_probe()
1392 buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); in acm_probe()
1395 acm->ctrl_buffer = buf; in acm_probe()
1400 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); in acm_probe()
1401 if (!acm->ctrlurb) in acm_probe()
1405 struct acm_rb *rb = &(acm->read_buffers[i]); in acm_probe()
1408 rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL, in acm_probe()
1409 &rb->dma); in acm_probe()
1410 if (!rb->base) in acm_probe()
1412 rb->index = i; in acm_probe()
1413 rb->instance = acm; in acm_probe()
1419 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in acm_probe()
1420 urb->transfer_dma = rb->dma; in acm_probe()
1422 usb_fill_int_urb(urb, acm->dev, acm->in, rb->base, in acm_probe()
1423 acm->readsize, in acm_probe()
1425 acm->bInterval); in acm_probe()
1427 usb_fill_bulk_urb(urb, acm->dev, acm->in, rb->base, in acm_probe()
1428 acm->readsize, in acm_probe()
1431 acm->read_urbs[i] = urb; in acm_probe()
1432 __set_bit(i, &acm->read_urbs_free); in acm_probe()
1435 struct acm_wb *snd = &(acm->wb[i]); in acm_probe()
1437 snd->urb = usb_alloc_urb(0, GFP_KERNEL); in acm_probe()
1438 if (!snd->urb) in acm_probe()
1442 usb_fill_int_urb(snd->urb, usb_dev, acm->out, in acm_probe()
1443 NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval); in acm_probe()
1445 usb_fill_bulk_urb(snd->urb, usb_dev, acm->out, in acm_probe()
1446 NULL, acm->writesize, acm_write_bulk, snd); in acm_probe()
1447 snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in acm_probe()
1449 snd->urb->transfer_flags |= URB_ZERO_PACKET; in acm_probe()
1450 snd->instance = acm; in acm_probe()
1455 i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); in acm_probe()
1463 acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL); in acm_probe()
1464 if (!acm->country_codes) in acm_probe()
1466 acm->country_code_size = cfd->bLength - 4; in acm_probe()
1467 memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, in acm_probe()
1468 cfd->bLength - 4); in acm_probe()
1469 acm->country_rel_date = cfd->iCountryCodeRelDate; in acm_probe()
1471 i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); in acm_probe()
1473 kfree(acm->country_codes); in acm_probe()
1474 acm->country_codes = NULL; in acm_probe()
1475 acm->country_code_size = 0; in acm_probe()
1479 i = device_create_file(&intf->dev, in acm_probe()
1482 device_remove_file(&intf->dev, &dev_attr_wCountryCodes); in acm_probe()
1483 kfree(acm->country_codes); in acm_probe()
1484 acm->country_codes = NULL; in acm_probe()
1485 acm->country_code_size = 0; in acm_probe()
1491 usb_fill_int_urb(acm->ctrlurb, usb_dev, in acm_probe()
1492 usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), in acm_probe()
1493 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, in acm_probe()
1495 epctrl->bInterval ? epctrl->bInterval : 16); in acm_probe()
1496 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in acm_probe()
1497 acm->ctrlurb->transfer_dma = acm->ctrl_dma; in acm_probe()
1498 acm->notification_buffer = NULL; in acm_probe()
1499 acm->nb_index = 0; in acm_probe()
1500 acm->nb_size = 0; in acm_probe()
1502 acm->line.dwDTERate = cpu_to_le32(9600); in acm_probe()
1503 acm->line.bDataBits = 8; in acm_probe()
1504 acm_set_line(acm, &acm->line); in acm_probe()
1506 if (!acm->combined_interfaces) { in acm_probe()
1512 tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor, in acm_probe()
1513 &control_interface->dev); in acm_probe()
1520 usb_clear_halt(usb_dev, acm->in); in acm_probe()
1521 usb_clear_halt(usb_dev, acm->out); in acm_probe()
1524 dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); in acm_probe()
1529 if (!acm->combined_interfaces) { in acm_probe()
1535 if (acm->country_codes) { in acm_probe()
1536 device_remove_file(&acm->control->dev, in acm_probe()
1538 device_remove_file(&acm->control->dev, in acm_probe()
1541 device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); in acm_probe()
1544 usb_free_urb(acm->wb[i].urb); in acm_probe()
1547 usb_free_urb(acm->read_urbs[i]); in acm_probe()
1549 usb_free_urb(acm->ctrlurb); in acm_probe()
1553 usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); in acm_probe()
1555 tty_port_put(&acm->port); in acm_probe()
1570 acm->disconnected = true; in acm_disconnect()
1577 mutex_lock(&acm->mutex); in acm_disconnect()
1578 if (acm->country_codes) { in acm_disconnect()
1579 device_remove_file(&acm->control->dev, in acm_disconnect()
1581 device_remove_file(&acm->control->dev, in acm_disconnect()
1584 wake_up_all(&acm->wioctl); in acm_disconnect()
1585 device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); in acm_disconnect()
1586 usb_set_intfdata(acm->control, NULL); in acm_disconnect()
1587 usb_set_intfdata(acm->data, NULL); in acm_disconnect()
1588 mutex_unlock(&acm->mutex); in acm_disconnect()
1590 tty = tty_port_tty_get(&acm->port); in acm_disconnect()
1596 cancel_delayed_work_sync(&acm->dwork); in acm_disconnect()
1598 tty_unregister_device(acm_tty_driver, acm->minor); in acm_disconnect()
1600 usb_free_urb(acm->ctrlurb); in acm_disconnect()
1602 usb_free_urb(acm->wb[i].urb); in acm_disconnect()
1603 for (i = 0; i < acm->rx_buflimit; i++) in acm_disconnect()
1604 usb_free_urb(acm->read_urbs[i]); in acm_disconnect()
1606 usb_free_coherent(acm->dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); in acm_disconnect()
1609 kfree(acm->notification_buffer); in acm_disconnect()
1611 if (!acm->combined_interfaces) in acm_disconnect()
1612 usb_driver_release_interface(&acm_driver, intf == acm->control ? in acm_disconnect()
1613 acm->data : acm->control); in acm_disconnect()
1615 tty_port_put(&acm->port); in acm_disconnect()
1624 spin_lock_irq(&acm->write_lock); in acm_suspend()
1626 if (acm->transmitting) { in acm_suspend()
1627 spin_unlock_irq(&acm->write_lock); in acm_suspend()
1628 return -EBUSY; in acm_suspend()
1631 cnt = acm->susp_count++; in acm_suspend()
1632 spin_unlock_irq(&acm->write_lock); in acm_suspend()
1638 cancel_delayed_work_sync(&acm->dwork); in acm_suspend()
1639 acm->urbs_in_error_delay = 0; in acm_suspend()
1650 spin_lock_irq(&acm->write_lock); in acm_resume()
1652 if (--acm->susp_count) in acm_resume()
1657 if (tty_port_initialized(&acm->port)) { in acm_resume()
1658 rv = usb_submit_urb(acm->ctrlurb, GFP_ATOMIC); in acm_resume()
1661 urb = usb_get_from_anchor(&acm->delayed); in acm_resume()
1665 acm_start_wb(acm, urb->context); in acm_resume()
1678 spin_unlock_irq(&acm->write_lock); in acm_resume()
1687 if (tty_port_initialized(&acm->port)) in acm_reset_resume()
1688 tty_port_tty_hangup(&acm->port, false); in acm_reset_resume()
1699 clear_bit(EVENT_RX_STALL, &acm->flags); in acm_pre_reset()
1700 acm->nb_index = 0; /* pending control transfers are lost */ in acm_pre_reset()
1723 { USB_DEVICE(0x076d, 0x0006), /* Denso Cradle CU-321 */
1748 { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
1751 { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */
1760 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
1781 { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */
1784 { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */
1792 { USB_DEVICE(0x2184, 0x001c) }, /* GW Instek AFG-2225 */
1793 { USB_DEVICE(0x2184, 0x0036) }, /* GW Instek AFG-125 */
1827 { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */
1833 { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */
1839 { USB_DEVICE(0xfff0, 0x0100), /* DATECS FP-2000 */
1857 * a modem and is picked up by the standard AT-command
1858 * information below. The second is 'vendor-specific' but
1891 { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */
1893 { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */
1894 { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */
1899 { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */
1902 { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */
1903 { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */
1922 /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
1999 /* control interfaces with various AT-command sets */
2053 .throttle = acm_tty_throttle,
2076 acm_tty_driver->driver_name = "acm", in acm_init()
2077 acm_tty_driver->name = "ttyACM", in acm_init()
2078 acm_tty_driver->major = ACM_TTY_MAJOR, in acm_init()
2079 acm_tty_driver->minor_start = 0, in acm_init()
2080 acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL, in acm_init()
2081 acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, in acm_init()
2082 acm_tty_driver->init_termios = tty_std_termios; in acm_init()
2083 acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | in acm_init()