Lines Matching +full:overrun +full:- +full:throttle +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0+
3 * cdc-acm.c
41 #include "cdc-acm.h"
71 mutex_lock(&acm->mutex); in acm_get_by_minor()
72 if (acm->disconnected) { in acm_get_by_minor()
73 mutex_unlock(&acm->mutex); in acm_get_by_minor()
76 tty_port_get(&acm->port); in acm_get_by_minor()
77 mutex_unlock(&acm->mutex); in acm_get_by_minor()
102 idr_remove(&acm_minors, acm->minor); in acm_release_minor()
115 retval = usb_autopm_get_interface(acm->control); in acm_ctrl_msg()
119 retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), in acm_ctrl_msg()
121 acm->control->altsetting[0].desc.bInterfaceNumber, in acm_ctrl_msg()
124 dev_dbg(&acm->control->dev, in acm_ctrl_msg()
125 "%s - rq 0x%02x, val %#x, len %#x, result %d\n", in acm_ctrl_msg()
128 usb_autopm_put_interface(acm->control); in acm_ctrl_msg()
138 if (acm->quirks & QUIRK_CONTROL_LINE_STATE) in acm_set_control()
139 return -EOPNOTSUPP; in acm_set_control()
147 #define acm_send_break(acm, ms) \ argument
148 acm_ctrl_msg(acm, USB_CDC_REQ_SEND_BREAK, ms, NULL, 0)
154 usb_kill_urb(acm->ctrlurb); in acm_kill_urbs()
156 usb_kill_urb(acm->wb[i].urb); in acm_kill_urbs()
157 for (i = 0; i < acm->rx_buflimit; i++) in acm_kill_urbs()
158 usb_kill_urb(acm->read_urbs[i]); in acm_kill_urbs()
174 wb = &acm->wb[wbn]; in acm_wb_alloc()
175 if (!wb->use) { in acm_wb_alloc()
176 wb->use = true; in acm_wb_alloc()
177 wb->len = 0; in acm_wb_alloc()
182 return -1; in acm_wb_alloc()
192 spin_lock_irqsave(&acm->write_lock, flags); in acm_wb_is_avail()
194 if(acm->wb[i].use) in acm_wb_is_avail()
195 n--; in acm_wb_is_avail()
196 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_wb_is_avail()
201 * Finish write. Caller must hold acm->write_lock
205 wb->use = false; in acm_write_done()
206 acm->transmitting--; in acm_write_done()
207 usb_autopm_put_interface_async(acm->control); in acm_write_done()
220 acm->transmitting++; in acm_start_wb()
222 wb->urb->transfer_buffer = wb->buf; in acm_start_wb()
223 wb->urb->transfer_dma = wb->dmah; in acm_start_wb()
224 wb->urb->transfer_buffer_length = wb->len; in acm_start_wb()
225 wb->urb->dev = acm->dev; in acm_start_wb()
227 rc = usb_submit_urb(wb->urb, GFP_ATOMIC); in acm_start_wb()
229 dev_err(&acm->data->dev, in acm_start_wb()
230 "%s - usb_submit_urb(write bulk) failed: %d\n", in acm_start_wb()
246 return sprintf(buf, "%d", acm->ctrl_caps); in bmCapabilities_show()
256 memcpy(buf, acm->country_codes, acm->country_code_size); in wCountryCodes_show()
257 return acm->country_code_size; in wCountryCodes_show()
268 return sprintf(buf, "%d", acm->country_rel_date); in iCountryCodeRelDate_show()
284 switch (dr->bNotificationType) { in acm_process_notification()
286 dev_dbg(&acm->control->dev, in acm_process_notification()
287 "%s - network connection: %d\n", __func__, dr->wValue); in acm_process_notification()
291 if (le16_to_cpu(dr->wLength) != 2) { in acm_process_notification()
292 dev_dbg(&acm->control->dev, in acm_process_notification()
293 "%s - malformed serial state\n", __func__); in acm_process_notification()
298 dev_dbg(&acm->control->dev, in acm_process_notification()
299 "%s - serial state: 0x%x\n", __func__, newctrl); in acm_process_notification()
301 if (!acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { in acm_process_notification()
302 dev_dbg(&acm->control->dev, in acm_process_notification()
303 "%s - calling hangup\n", __func__); in acm_process_notification()
304 tty_port_tty_hangup(&acm->port, false); in acm_process_notification()
307 difference = acm->ctrlin ^ newctrl; in acm_process_notification()
308 spin_lock_irqsave(&acm->read_lock, flags); in acm_process_notification()
309 acm->ctrlin = newctrl; in acm_process_notification()
310 acm->oldcount = acm->iocount; in acm_process_notification()
313 acm->iocount.dsr++; in acm_process_notification()
315 acm->iocount.dcd++; in acm_process_notification()
317 acm->iocount.brk++; in acm_process_notification()
319 acm->iocount.rng++; in acm_process_notification()
321 acm->iocount.frame++; in acm_process_notification()
323 acm->iocount.parity++; in acm_process_notification()
325 acm->iocount.overrun++; in acm_process_notification()
326 spin_unlock_irqrestore(&acm->read_lock, flags); in acm_process_notification()
329 wake_up_all(&acm->wioctl); in acm_process_notification()
334 dev_dbg(&acm->control->dev, in acm_process_notification()
335 "%s - unknown notification %d received: index %d len %d\n", in acm_process_notification()
337 dr->bNotificationType, dr->wIndex, dr->wLength); in acm_process_notification()
344 struct acm *acm = urb->context; in acm_ctrl_irq()
345 struct usb_cdc_notification *dr = urb->transfer_buffer; in acm_ctrl_irq()
346 unsigned int current_size = urb->actual_length; in acm_ctrl_irq()
349 int status = urb->status; in acm_ctrl_irq()
355 case -ECONNRESET: in acm_ctrl_irq()
356 case -ENOENT: in acm_ctrl_irq()
357 case -ESHUTDOWN: in acm_ctrl_irq()
359 dev_dbg(&acm->control->dev, in acm_ctrl_irq()
360 "%s - urb shutting down with status: %d\n", in acm_ctrl_irq()
364 dev_dbg(&acm->control->dev, in acm_ctrl_irq()
365 "%s - nonzero urb status received: %d\n", in acm_ctrl_irq()
370 usb_mark_last_busy(acm->dev); in acm_ctrl_irq()
372 if (acm->nb_index) in acm_ctrl_irq()
373 dr = (struct usb_cdc_notification *)acm->notification_buffer; in acm_ctrl_irq()
375 /* size = notification-header + (optional) data */ in acm_ctrl_irq()
377 le16_to_cpu(dr->wLength); in acm_ctrl_irq()
381 if (acm->nb_size < expected_size) { in acm_ctrl_irq()
385 new_buffer = krealloc(acm->notification_buffer, in acm_ctrl_irq()
388 acm->nb_index = 0; in acm_ctrl_irq()
392 acm->notification_buffer = new_buffer; in acm_ctrl_irq()
393 acm->nb_size = alloc_size; in acm_ctrl_irq()
394 dr = (struct usb_cdc_notification *)acm->notification_buffer; in acm_ctrl_irq()
398 expected_size - acm->nb_index); in acm_ctrl_irq()
400 memcpy(&acm->notification_buffer[acm->nb_index], in acm_ctrl_irq()
401 urb->transfer_buffer, copy_size); in acm_ctrl_irq()
402 acm->nb_index += copy_size; in acm_ctrl_irq()
403 current_size = acm->nb_index; in acm_ctrl_irq()
409 acm->nb_index = 0; in acm_ctrl_irq()
414 if (retval && retval != -EPERM && retval != -ENODEV) in acm_ctrl_irq()
415 dev_err(&acm->control->dev, in acm_ctrl_irq()
416 "%s - usb_submit_urb failed: %d\n", __func__, retval); in acm_ctrl_irq()
418 dev_vdbg(&acm->control->dev, in acm_ctrl_irq()
426 if (!test_and_clear_bit(index, &acm->read_urbs_free)) in acm_submit_read_urb()
429 res = usb_submit_urb(acm->read_urbs[index], mem_flags); in acm_submit_read_urb()
431 if (res != -EPERM && res != -ENODEV) { in acm_submit_read_urb()
432 dev_err(&acm->data->dev, in acm_submit_read_urb()
436 dev_vdbg(&acm->data->dev, "intended failure %d\n", res); in acm_submit_read_urb()
438 set_bit(index, &acm->read_urbs_free); in acm_submit_read_urb()
441 dev_vdbg(&acm->data->dev, "submitted urb %d\n", index); in acm_submit_read_urb()
452 for (i = 0; i < acm->rx_buflimit; ++i) { in acm_submit_read_urbs()
463 if (!urb->actual_length) in acm_process_read_urb()
466 tty_insert_flip_string(&acm->port, urb->transfer_buffer, in acm_process_read_urb()
467 urb->actual_length); in acm_process_read_urb()
468 tty_flip_buffer_push(&acm->port); in acm_process_read_urb()
473 struct acm_rb *rb = urb->context; in acm_read_bulk_callback()
474 struct acm *acm = rb->instance; in acm_read_bulk_callback()
475 int status = urb->status; in acm_read_bulk_callback()
480 dev_vdbg(&acm->data->dev, "got urb %d, len %d, status %d\n", in acm_read_bulk_callback()
481 rb->index, urb->actual_length, status); in acm_read_bulk_callback()
483 if (!acm->dev) { in acm_read_bulk_callback()
484 dev_dbg(&acm->data->dev, "%s - disconnected\n", __func__); in acm_read_bulk_callback()
490 usb_mark_last_busy(acm->dev); in acm_read_bulk_callback()
493 case -EPIPE: in acm_read_bulk_callback()
494 set_bit(EVENT_RX_STALL, &acm->flags); in acm_read_bulk_callback()
497 case -ENOENT: in acm_read_bulk_callback()
498 case -ECONNRESET: in acm_read_bulk_callback()
499 case -ESHUTDOWN: in acm_read_bulk_callback()
500 dev_dbg(&acm->data->dev, in acm_read_bulk_callback()
501 "%s - urb shutting down with status: %d\n", in acm_read_bulk_callback()
505 case -EOVERFLOW: in acm_read_bulk_callback()
506 case -EPROTO: in acm_read_bulk_callback()
507 dev_dbg(&acm->data->dev, in acm_read_bulk_callback()
508 "%s - cooling babbling device\n", __func__); in acm_read_bulk_callback()
509 usb_mark_last_busy(acm->dev); in acm_read_bulk_callback()
510 set_bit(rb->index, &acm->urbs_in_error_delay); in acm_read_bulk_callback()
511 set_bit(ACM_ERROR_DELAY, &acm->flags); in acm_read_bulk_callback()
515 dev_dbg(&acm->data->dev, in acm_read_bulk_callback()
516 "%s - nonzero urb status received: %d\n", in acm_read_bulk_callback()
527 set_bit(rb->index, &acm->read_urbs_free); in acm_read_bulk_callback()
537 schedule_delayed_work(&acm->dwork, 0); in acm_read_bulk_callback()
539 schedule_delayed_work(&acm->dwork, HZ / 2); in acm_read_bulk_callback()
543 if (test_bit(ACM_THROTTLED, &acm->flags)) in acm_read_bulk_callback()
546 acm_submit_read_urb(acm, rb->index, GFP_ATOMIC); in acm_read_bulk_callback()
552 struct acm_wb *wb = urb->context; in acm_write_bulk()
553 struct acm *acm = wb->instance; in acm_write_bulk()
555 int status = urb->status; in acm_write_bulk()
557 if (status || (urb->actual_length != urb->transfer_buffer_length)) in acm_write_bulk()
558 dev_vdbg(&acm->data->dev, "wrote len %d/%d, status %d\n", in acm_write_bulk()
559 urb->actual_length, in acm_write_bulk()
560 urb->transfer_buffer_length, in acm_write_bulk()
563 spin_lock_irqsave(&acm->write_lock, flags); in acm_write_bulk()
565 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_write_bulk()
566 set_bit(EVENT_TTY_WAKEUP, &acm->flags); in acm_write_bulk()
567 schedule_delayed_work(&acm->dwork, 0); in acm_write_bulk()
575 if (test_bit(EVENT_RX_STALL, &acm->flags)) { in acm_softint()
577 if (!acm->susp_count) { in acm_softint()
578 for (i = 0; i < acm->rx_buflimit; i++) in acm_softint()
579 usb_kill_urb(acm->read_urbs[i]); in acm_softint()
580 usb_clear_halt(acm->dev, acm->in); in acm_softint()
582 clear_bit(EVENT_RX_STALL, &acm->flags); in acm_softint()
586 if (test_and_clear_bit(ACM_ERROR_DELAY, &acm->flags)) { in acm_softint()
587 for (i = 0; i < acm->rx_buflimit; i++) in acm_softint()
588 if (test_and_clear_bit(i, &acm->urbs_in_error_delay)) in acm_softint()
592 if (test_and_clear_bit(EVENT_TTY_WAKEUP, &acm->flags)) in acm_softint()
593 tty_port_tty_wakeup(&acm->port); in acm_softint()
605 acm = acm_get_by_minor(tty->index); in acm_tty_install()
607 return -ENODEV; in acm_tty_install()
617 if (acm->quirks & DISABLE_ECHO) in acm_tty_install()
618 tty->termios.c_lflag &= ~ECHO; in acm_tty_install()
620 tty->driver_data = acm; in acm_tty_install()
625 tty_port_put(&acm->port); in acm_tty_install()
631 struct acm *acm = tty->driver_data; in acm_tty_open()
633 return tty_port_open(&acm->port, tty, filp); in acm_tty_open()
648 acm->ctrlout = val; in acm_port_dtr_rts()
651 if (res && (acm->ctrl_caps & USB_CDC_CAP_LINE)) in acm_port_dtr_rts()
652 dev_err(&acm->control->dev, "failed to set dtr/rts\n"); in acm_port_dtr_rts()
658 int retval = -ENODEV; in acm_port_activate()
661 mutex_lock(&acm->mutex); in acm_port_activate()
662 if (acm->disconnected) in acm_port_activate()
665 retval = usb_autopm_get_interface(acm->control); in acm_port_activate()
673 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); in acm_port_activate()
674 acm->control->needs_remote_wakeup = 1; in acm_port_activate()
676 acm->ctrlurb->dev = acm->dev; in acm_port_activate()
677 retval = usb_submit_urb(acm->ctrlurb, GFP_KERNEL); in acm_port_activate()
679 dev_err(&acm->control->dev, in acm_port_activate()
680 "%s - usb_submit_urb(ctrl irq) failed\n", __func__); in acm_port_activate()
689 clear_bit(ACM_THROTTLED, &acm->flags); in acm_port_activate()
695 usb_autopm_put_interface(acm->control); in acm_port_activate()
697 mutex_unlock(&acm->mutex); in acm_port_activate()
702 for (i = 0; i < acm->rx_buflimit; i++) in acm_port_activate()
703 usb_kill_urb(acm->read_urbs[i]); in acm_port_activate()
704 usb_kill_urb(acm->ctrlurb); in acm_port_activate()
706 usb_autopm_put_interface(acm->control); in acm_port_activate()
709 mutex_unlock(&acm->mutex); in acm_port_activate()
719 usb_put_intf(acm->control); in acm_port_destruct()
720 kfree(acm->country_codes); in acm_port_destruct()
732 * hold it due to the tty-port initialised flag. in acm_port_shutdown()
734 spin_lock_irq(&acm->write_lock); in acm_port_shutdown()
735 spin_unlock_irq(&acm->write_lock); in acm_port_shutdown()
737 usb_autopm_get_interface_no_resume(acm->control); in acm_port_shutdown()
738 acm->control->needs_remote_wakeup = 0; in acm_port_shutdown()
739 usb_autopm_put_interface(acm->control); in acm_port_shutdown()
742 urb = usb_get_from_anchor(&acm->delayed); in acm_port_shutdown()
745 wb = urb->context; in acm_port_shutdown()
746 wb->use = false; in acm_port_shutdown()
747 usb_autopm_put_interface_async(acm->control); in acm_port_shutdown()
755 struct acm *acm = tty->driver_data; in acm_tty_cleanup()
757 tty_port_put(&acm->port); in acm_tty_cleanup()
762 struct acm *acm = tty->driver_data; in acm_tty_hangup()
764 tty_port_hangup(&acm->port); in acm_tty_hangup()
769 struct acm *acm = tty->driver_data; in acm_tty_close()
771 tty_port_close(&acm->port, tty, filp); in acm_tty_close()
777 struct acm *acm = tty->driver_data; in acm_tty_write()
786 dev_vdbg(&acm->data->dev, "%d bytes from tty layer\n", count); in acm_tty_write()
788 spin_lock_irqsave(&acm->write_lock, flags); in acm_tty_write()
791 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_tty_write()
794 wb = &acm->wb[wbn]; in acm_tty_write()
796 if (!acm->dev) { in acm_tty_write()
797 wb->use = false; in acm_tty_write()
798 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_tty_write()
799 return -ENODEV; in acm_tty_write()
802 count = (count > acm->writesize) ? acm->writesize : count; in acm_tty_write()
803 dev_vdbg(&acm->data->dev, "writing %d bytes\n", count); in acm_tty_write()
804 memcpy(wb->buf, buf, count); in acm_tty_write()
805 wb->len = count; in acm_tty_write()
807 stat = usb_autopm_get_interface_async(acm->control); in acm_tty_write()
809 wb->use = false; in acm_tty_write()
810 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_tty_write()
814 if (acm->susp_count) { in acm_tty_write()
815 usb_anchor_urb(wb->urb, &acm->delayed); in acm_tty_write()
816 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_tty_write()
821 spin_unlock_irqrestore(&acm->write_lock, flags); in acm_tty_write()
830 struct acm *acm = tty->driver_data; in acm_tty_write_room()
835 return acm_wb_is_avail(acm) ? acm->writesize : 0; in acm_tty_write_room()
840 struct acm *acm = tty->driver_data; in acm_tty_chars_in_buffer()
845 if (acm->disconnected) in acm_tty_chars_in_buffer()
850 return (ACM_NW - acm_wb_is_avail(acm)) * acm->writesize; in acm_tty_chars_in_buffer()
855 struct acm *acm = tty->driver_data; in acm_tty_throttle()
857 set_bit(ACM_THROTTLED, &acm->flags); in acm_tty_throttle()
862 struct acm *acm = tty->driver_data; in acm_tty_unthrottle()
864 clear_bit(ACM_THROTTLED, &acm->flags); in acm_tty_unthrottle()
874 struct acm *acm = tty->driver_data; in acm_tty_break_ctl()
879 dev_dbg(&acm->control->dev, in acm_tty_break_ctl()
880 "%s - send break failed\n", __func__); in acm_tty_break_ctl()
886 struct acm *acm = tty->driver_data; in acm_tty_tiocmget()
888 return (acm->ctrlout & ACM_CTRL_DTR ? TIOCM_DTR : 0) | in acm_tty_tiocmget()
889 (acm->ctrlout & ACM_CTRL_RTS ? TIOCM_RTS : 0) | in acm_tty_tiocmget()
890 (acm->ctrlin & ACM_CTRL_DSR ? TIOCM_DSR : 0) | in acm_tty_tiocmget()
891 (acm->ctrlin & ACM_CTRL_RI ? TIOCM_RI : 0) | in acm_tty_tiocmget()
892 (acm->ctrlin & ACM_CTRL_DCD ? TIOCM_CD : 0) | in acm_tty_tiocmget()
899 struct acm *acm = tty->driver_data; in acm_tty_tiocmset()
902 newctrl = acm->ctrlout; in acm_tty_tiocmset()
910 if (acm->ctrlout == newctrl) in acm_tty_tiocmset()
912 return acm_set_control(acm, acm->ctrlout = newctrl); in acm_tty_tiocmset()
917 struct acm *acm = tty->driver_data; in get_serial_info()
919 ss->xmit_fifo_size = acm->writesize; in get_serial_info()
920 ss->baud_base = le32_to_cpu(acm->line.dwDTERate); in get_serial_info()
921 ss->close_delay = jiffies_to_msecs(acm->port.close_delay) / 10; in get_serial_info()
922 ss->closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? in get_serial_info()
924 jiffies_to_msecs(acm->port.closing_wait) / 10; in get_serial_info()
930 struct acm *acm = tty->driver_data; in set_serial_info()
935 close_delay = msecs_to_jiffies(ss->close_delay * 10); in set_serial_info()
936 closing_wait = ss->closing_wait == ASYNC_CLOSING_WAIT_NONE ? in set_serial_info()
938 msecs_to_jiffies(ss->closing_wait * 10); in set_serial_info()
941 old_close_delay = jiffies_to_msecs(acm->port.close_delay) / 10; in set_serial_info()
942 old_closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ? in set_serial_info()
944 jiffies_to_msecs(acm->port.closing_wait) / 10; in set_serial_info()
946 mutex_lock(&acm->port.mutex); in set_serial_info()
949 if ((ss->close_delay != old_close_delay) || in set_serial_info()
950 (ss->closing_wait != old_closing_wait)) in set_serial_info()
951 retval = -EPERM; in set_serial_info()
953 retval = -EOPNOTSUPP; in set_serial_info()
955 acm->port.close_delay = close_delay; in set_serial_info()
956 acm->port.closing_wait = closing_wait; in set_serial_info()
959 mutex_unlock(&acm->port.mutex); in set_serial_info()
970 spin_lock_irq(&acm->read_lock); in wait_serial_change()
971 old = acm->oldcount; in wait_serial_change()
972 new = acm->iocount; in wait_serial_change()
973 acm->oldcount = new; in wait_serial_change()
974 spin_unlock_irq(&acm->read_lock); in wait_serial_change()
986 add_wait_queue(&acm->wioctl, &wait); in wait_serial_change()
989 remove_wait_queue(&acm->wioctl, &wait); in wait_serial_change()
990 if (acm->disconnected) { in wait_serial_change()
994 rv = -ENODEV; in wait_serial_change()
997 rv = -ERESTARTSYS; in wait_serial_change()
1009 struct acm *acm = tty->driver_data; in acm_tty_get_icount()
1011 icount->dsr = acm->iocount.dsr; in acm_tty_get_icount()
1012 icount->rng = acm->iocount.rng; in acm_tty_get_icount()
1013 icount->dcd = acm->iocount.dcd; in acm_tty_get_icount()
1014 icount->frame = acm->iocount.frame; in acm_tty_get_icount()
1015 icount->overrun = acm->iocount.overrun; in acm_tty_get_icount()
1016 icount->parity = acm->iocount.parity; in acm_tty_get_icount()
1017 icount->brk = acm->iocount.brk; in acm_tty_get_icount()
1025 struct acm *acm = tty->driver_data; in acm_tty_ioctl()
1026 int rv = -ENOIOCTLCMD; in acm_tty_ioctl()
1030 rv = usb_autopm_get_interface(acm->control); in acm_tty_ioctl()
1032 rv = -EIO; in acm_tty_ioctl()
1036 usb_autopm_put_interface(acm->control); in acm_tty_ioctl()
1046 struct acm *acm = tty->driver_data; in acm_tty_set_termios()
1047 struct ktermios *termios = &tty->termios; in acm_tty_set_termios()
1049 int newctrl = acm->ctrlout; in acm_tty_set_termios()
1052 newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; in acm_tty_set_termios()
1053 newline.bParityType = termios->c_cflag & PARENB ? in acm_tty_set_termios()
1054 (termios->c_cflag & PARODD ? 1 : 2) + in acm_tty_set_termios()
1055 (termios->c_cflag & CMSPAR ? 2 : 0) : 0; in acm_tty_set_termios()
1056 switch (termios->c_cflag & CSIZE) { in acm_tty_set_termios()
1072 acm->clocal = ((termios->c_cflag & CLOCAL) != 0); in acm_tty_set_termios()
1075 newline.dwDTERate = acm->line.dwDTERate; in acm_tty_set_termios()
1077 } else if (termios_old && (termios_old->c_cflag & CBAUD) == B0) { in acm_tty_set_termios()
1081 if (newctrl != acm->ctrlout) in acm_tty_set_termios()
1082 acm_set_control(acm, acm->ctrlout = newctrl); in acm_tty_set_termios()
1084 if (memcmp(&acm->line, &newline, sizeof newline)) { in acm_tty_set_termios()
1085 memcpy(&acm->line, &newline, sizeof newline); in acm_tty_set_termios()
1086 dev_dbg(&acm->control->dev, "%s - set line: %d %d %d %d\n", in acm_tty_set_termios()
1091 acm_set_line(acm, &acm->line); in acm_tty_set_termios()
1112 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) in acm_write_buffers_free()
1113 usb_free_coherent(acm->dev, acm->writesize, wb->buf, wb->dmah); in acm_write_buffers_free()
1120 for (i = 0; i < acm->rx_buflimit; i++) in acm_read_buffers_free()
1121 usb_free_coherent(acm->dev, acm->readsize, in acm_read_buffers_free()
1122 acm->read_buffers[i].base, acm->read_buffers[i].dma); in acm_read_buffers_free()
1131 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { in acm_write_buffers_alloc()
1132 wb->buf = usb_alloc_coherent(acm->dev, acm->writesize, GFP_KERNEL, in acm_write_buffers_alloc()
1133 &wb->dmah); in acm_write_buffers_alloc()
1134 if (!wb->buf) { in acm_write_buffers_alloc()
1136 --i; in acm_write_buffers_alloc()
1137 --wb; in acm_write_buffers_alloc()
1138 usb_free_coherent(acm->dev, acm->writesize, in acm_write_buffers_alloc()
1139 wb->buf, wb->dmah); in acm_write_buffers_alloc()
1141 return -ENOMEM; in acm_write_buffers_alloc()
1152 unsigned char *buffer = intf->altsetting->extra; in acm_probe()
1153 int buflen = intf->altsetting->extralen; in acm_probe()
1165 int call_intf_num = -1; in acm_probe()
1166 int data_intf_num = -1; in acm_probe()
1172 int rv = -ENOMEM; in acm_probe()
1176 quirks = (unsigned long)id->driver_info; in acm_probe()
1179 return -ENODEV; in acm_probe()
1191 return -ENODEV; in acm_probe()
1197 dev_err(&intf->dev, "Weird descriptor references\n"); in acm_probe()
1198 return -EINVAL; in acm_probe()
1202 if (intf->cur_altsetting->endpoint && in acm_probe()
1203 intf->cur_altsetting->endpoint->extralen && in acm_probe()
1204 intf->cur_altsetting->endpoint->extra) { in acm_probe()
1205 dev_dbg(&intf->dev, in acm_probe()
1207 buflen = intf->cur_altsetting->endpoint->extralen; in acm_probe()
1208 buffer = intf->cur_altsetting->endpoint->extra; in acm_probe()
1210 dev_err(&intf->dev, in acm_probe()
1212 return -EINVAL; in acm_probe()
1220 call_intf_num = cmgmd->bDataInterface; in acm_probe()
1223 if (intf->cur_altsetting->desc.bNumEndpoints == 3) { in acm_probe()
1224 dev_dbg(&intf->dev, "No union descriptor, assuming single interface\n"); in acm_probe()
1229 dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n"); in acm_probe()
1234 dev_dbg(&intf->dev, "No union descriptor, giving up\n"); in acm_probe()
1235 return -ENODEV; in acm_probe()
1238 int class = -1; in acm_probe()
1240 data_intf_num = union_header->bSlaveInterface0; in acm_probe()
1241 control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); in acm_probe()
1245 class = control_interface->cur_altsetting->desc.bInterfaceClass; in acm_probe()
1248 dev_dbg(&intf->dev, "Broken union descriptor, assuming single interface\n"); in acm_probe()
1256 dev_dbg(&intf->dev, "no interfaces\n"); in acm_probe()
1257 return -ENODEV; in acm_probe()
1261 dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n"); in acm_probe()
1265 dev_warn(&intf->dev,"Control and data interfaces are not separated!\n"); in acm_probe()
1269 if (data_interface->cur_altsetting->desc.bNumEndpoints != 3) { in acm_probe()
1270 dev_err(&intf->dev, "This needs exactly 3 endpoints\n"); in acm_probe()
1271 return -EINVAL; in acm_probe()
1274 res = usb_find_common_endpoints(data_interface->cur_altsetting, in acm_probe()
1285 if (data_interface->cur_altsetting->desc.bInterfaceClass != USB_CLASS_CDC_DATA) { in acm_probe()
1286 if (control_interface->cur_altsetting->desc.bInterfaceClass == USB_CLASS_CDC_DATA) { in acm_probe()
1287 dev_dbg(&intf->dev, in acm_probe()
1291 return -EINVAL; in acm_probe()
1297 return -ENODEV; in acm_probe()
1301 dev_dbg(&intf->dev, "The data interface isn't available\n"); in acm_probe()
1302 return -EBUSY; in acm_probe()
1306 if (data_interface->cur_altsetting->desc.bNumEndpoints < 2 || in acm_probe()
1307 control_interface->cur_altsetting->desc.bNumEndpoints == 0) in acm_probe()
1308 return -EINVAL; in acm_probe()
1310 epctrl = &control_interface->cur_altsetting->endpoint[0].desc; in acm_probe()
1311 epread = &data_interface->cur_altsetting->endpoint[0].desc; in acm_probe()
1312 epwrite = &data_interface->cur_altsetting->endpoint[1].desc; in acm_probe()
1318 dev_dbg(&intf->dev, in acm_probe()
1323 dev_dbg(&intf->dev, "interfaces are valid\n"); in acm_probe()
1329 tty_port_init(&acm->port); in acm_probe()
1330 acm->port.ops = &acm_port_ops; in acm_probe()
1335 acm->combined_interfaces = combined_interfaces; in acm_probe()
1336 acm->writesize = usb_endpoint_maxp(epwrite) * 20; in acm_probe()
1337 acm->control = control_interface; in acm_probe()
1338 acm->data = data_interface; in acm_probe()
1340 usb_get_intf(acm->control); /* undone in destruct() */ in acm_probe()
1346 acm->minor = minor; in acm_probe()
1347 acm->dev = usb_dev; in acm_probe()
1349 acm->ctrl_caps = h.usb_cdc_acm_descriptor->bmCapabilities; in acm_probe()
1351 acm->ctrl_caps &= ~USB_CDC_CAP_LINE; in acm_probe()
1352 acm->ctrlsize = ctrlsize; in acm_probe()
1353 acm->readsize = readsize; in acm_probe()
1354 acm->rx_buflimit = num_rx_buf; in acm_probe()
1355 INIT_DELAYED_WORK(&acm->dwork, acm_softint); in acm_probe()
1356 init_waitqueue_head(&acm->wioctl); in acm_probe()
1357 spin_lock_init(&acm->write_lock); in acm_probe()
1358 spin_lock_init(&acm->read_lock); in acm_probe()
1359 mutex_init(&acm->mutex); in acm_probe()
1361 acm->bInterval = epread->bInterval; in acm_probe()
1362 acm->in = usb_rcvintpipe(usb_dev, epread->bEndpointAddress); in acm_probe()
1364 acm->in = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); in acm_probe()
1367 acm->out = usb_sndintpipe(usb_dev, epwrite->bEndpointAddress); in acm_probe()
1369 acm->out = usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress); in acm_probe()
1370 init_usb_anchor(&acm->delayed); in acm_probe()
1371 acm->quirks = quirks; in acm_probe()
1373 buf = usb_alloc_coherent(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); in acm_probe()
1376 acm->ctrl_buffer = buf; in acm_probe()
1381 acm->ctrlurb = usb_alloc_urb(0, GFP_KERNEL); in acm_probe()
1382 if (!acm->ctrlurb) in acm_probe()
1386 struct acm_rb *rb = &(acm->read_buffers[i]); in acm_probe()
1389 rb->base = usb_alloc_coherent(acm->dev, readsize, GFP_KERNEL, in acm_probe()
1390 &rb->dma); in acm_probe()
1391 if (!rb->base) in acm_probe()
1393 rb->index = i; in acm_probe()
1394 rb->instance = acm; in acm_probe()
1400 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in acm_probe()
1401 urb->transfer_dma = rb->dma; in acm_probe()
1403 usb_fill_int_urb(urb, acm->dev, acm->in, rb->base, in acm_probe()
1404 acm->readsize, in acm_probe()
1406 acm->bInterval); in acm_probe()
1408 usb_fill_bulk_urb(urb, acm->dev, acm->in, rb->base, in acm_probe()
1409 acm->readsize, in acm_probe()
1412 acm->read_urbs[i] = urb; in acm_probe()
1413 __set_bit(i, &acm->read_urbs_free); in acm_probe()
1416 struct acm_wb *snd = &(acm->wb[i]); in acm_probe()
1418 snd->urb = usb_alloc_urb(0, GFP_KERNEL); in acm_probe()
1419 if (snd->urb == NULL) in acm_probe()
1423 usb_fill_int_urb(snd->urb, usb_dev, acm->out, in acm_probe()
1424 NULL, acm->writesize, acm_write_bulk, snd, epwrite->bInterval); in acm_probe()
1426 usb_fill_bulk_urb(snd->urb, usb_dev, acm->out, in acm_probe()
1427 NULL, acm->writesize, acm_write_bulk, snd); in acm_probe()
1428 snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in acm_probe()
1430 snd->urb->transfer_flags |= URB_ZERO_PACKET; in acm_probe()
1431 snd->instance = acm; in acm_probe()
1436 i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); in acm_probe()
1444 acm->country_codes = kmalloc(cfd->bLength - 4, GFP_KERNEL); in acm_probe()
1445 if (!acm->country_codes) in acm_probe()
1447 acm->country_code_size = cfd->bLength - 4; in acm_probe()
1448 memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, in acm_probe()
1449 cfd->bLength - 4); in acm_probe()
1450 acm->country_rel_date = cfd->iCountryCodeRelDate; in acm_probe()
1452 i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); in acm_probe()
1454 kfree(acm->country_codes); in acm_probe()
1455 acm->country_codes = NULL; in acm_probe()
1456 acm->country_code_size = 0; in acm_probe()
1460 i = device_create_file(&intf->dev, in acm_probe()
1463 device_remove_file(&intf->dev, &dev_attr_wCountryCodes); in acm_probe()
1464 kfree(acm->country_codes); in acm_probe()
1465 acm->country_codes = NULL; in acm_probe()
1466 acm->country_code_size = 0; in acm_probe()
1472 usb_fill_int_urb(acm->ctrlurb, usb_dev, in acm_probe()
1473 usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), in acm_probe()
1474 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, in acm_probe()
1476 epctrl->bInterval ? epctrl->bInterval : 16); in acm_probe()
1477 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in acm_probe()
1478 acm->ctrlurb->transfer_dma = acm->ctrl_dma; in acm_probe()
1479 acm->notification_buffer = NULL; in acm_probe()
1480 acm->nb_index = 0; in acm_probe()
1481 acm->nb_size = 0; in acm_probe()
1483 dev_info(&intf->dev, "ttyACM%d: USB ACM device\n", minor); in acm_probe()
1485 acm->line.dwDTERate = cpu_to_le32(9600); in acm_probe()
1486 acm->line.bDataBits = 8; in acm_probe()
1487 acm_set_line(acm, &acm->line); in acm_probe()
1492 tty_dev = tty_port_register_device(&acm->port, acm_tty_driver, minor, in acm_probe()
1493 &control_interface->dev); in acm_probe()
1500 usb_clear_halt(usb_dev, acm->in); in acm_probe()
1501 usb_clear_halt(usb_dev, acm->out); in acm_probe()
1506 if (acm->country_codes) { in acm_probe()
1507 device_remove_file(&acm->control->dev, in acm_probe()
1509 device_remove_file(&acm->control->dev, in acm_probe()
1511 kfree(acm->country_codes); in acm_probe()
1513 device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); in acm_probe()
1517 usb_free_urb(acm->wb[i].urb); in acm_probe()
1520 usb_free_urb(acm->read_urbs[i]); in acm_probe()
1522 usb_free_urb(acm->ctrlurb); in acm_probe()
1526 usb_free_coherent(usb_dev, ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); in acm_probe()
1528 tty_port_put(&acm->port); in acm_probe()
1543 mutex_lock(&acm->mutex); in acm_disconnect()
1544 acm->disconnected = true; in acm_disconnect()
1545 if (acm->country_codes) { in acm_disconnect()
1546 device_remove_file(&acm->control->dev, in acm_disconnect()
1548 device_remove_file(&acm->control->dev, in acm_disconnect()
1551 wake_up_all(&acm->wioctl); in acm_disconnect()
1552 device_remove_file(&acm->control->dev, &dev_attr_bmCapabilities); in acm_disconnect()
1553 usb_set_intfdata(acm->control, NULL); in acm_disconnect()
1554 usb_set_intfdata(acm->data, NULL); in acm_disconnect()
1555 mutex_unlock(&acm->mutex); in acm_disconnect()
1557 tty = tty_port_tty_get(&acm->port); in acm_disconnect()
1564 cancel_delayed_work_sync(&acm->dwork); in acm_disconnect()
1566 tty_unregister_device(acm_tty_driver, acm->minor); in acm_disconnect()
1568 usb_free_urb(acm->ctrlurb); in acm_disconnect()
1570 usb_free_urb(acm->wb[i].urb); in acm_disconnect()
1571 for (i = 0; i < acm->rx_buflimit; i++) in acm_disconnect()
1572 usb_free_urb(acm->read_urbs[i]); in acm_disconnect()
1574 usb_free_coherent(acm->dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); in acm_disconnect()
1577 kfree(acm->notification_buffer); in acm_disconnect()
1579 if (!acm->combined_interfaces) in acm_disconnect()
1580 usb_driver_release_interface(&acm_driver, intf == acm->control ? in acm_disconnect()
1581 acm->data : acm->control); in acm_disconnect()
1583 tty_port_put(&acm->port); in acm_disconnect()
1592 spin_lock_irq(&acm->write_lock); in acm_suspend()
1594 if (acm->transmitting) { in acm_suspend()
1595 spin_unlock_irq(&acm->write_lock); in acm_suspend()
1596 return -EBUSY; in acm_suspend()
1599 cnt = acm->susp_count++; in acm_suspend()
1600 spin_unlock_irq(&acm->write_lock); in acm_suspend()
1606 cancel_delayed_work_sync(&acm->dwork); in acm_suspend()
1607 acm->urbs_in_error_delay = 0; in acm_suspend()
1618 spin_lock_irq(&acm->write_lock); in acm_resume()
1620 if (--acm->susp_count) in acm_resume()
1623 if (tty_port_initialized(&acm->port)) { in acm_resume()
1624 rv = usb_submit_urb(acm->ctrlurb, GFP_ATOMIC); in acm_resume()
1627 urb = usb_get_from_anchor(&acm->delayed); in acm_resume()
1631 acm_start_wb(acm, urb->context); in acm_resume()
1644 spin_unlock_irq(&acm->write_lock); in acm_resume()
1653 if (tty_port_initialized(&acm->port)) in acm_reset_resume()
1654 tty_port_tty_hangup(&acm->port, false); in acm_reset_resume()
1665 clear_bit(EVENT_RX_STALL, &acm->flags); in acm_pre_reset()
1666 acm->nb_index = 0; /* pending control transfers are lost */ in acm_pre_reset()
1689 { USB_DEVICE(0x076d, 0x0006), /* Denso Cradle CU-321 */
1714 { USB_DEVICE(0x0482, 0x0203), /* KYOCERA AH-K3001V */
1717 { USB_DEVICE(0x079b, 0x000f), /* BT On-Air USB MODEM */
1726 { USB_DEVICE(0x0ace, 0x1611), /* ZyDAS 56K USB MODEM - new version */
1744 { USB_DEVICE(0x0572, 0x1324), /* Conexant USB MODEM RD02-D400 */
1747 { USB_DEVICE(0x0572, 0x1328), /* Shiro / Aztech USB MODEM UM-3100 */
1755 { USB_DEVICE(0x2184, 0x001c) }, /* GW Instek AFG-2225 */
1756 { USB_DEVICE(0x2184, 0x0036) }, /* GW Instek AFG-125 */
1790 { USB_DEVICE(0x0572, 0x1340), /* Conexant CX93010-2x UCMxx */
1796 { USB_DEVICE(0x1bbb, 0x0003), /* Alcatel OT-I650 */
1802 { USB_DEVICE(0xfff0, 0x0100), /* DATECS FP-2000 */
1817 * a modem and is picked up by the standard AT-command
1818 * information below. The second is 'vendor-specific' but
1851 { NOKIA_PCSUITE_ACM_INFO(0x04F0), }, /* Nokia N95 & N95-3 NAM */
1854 { NOKIA_PCSUITE_ACM_INFO(0x0099), }, /* Nokia 6210 Navigator, RM-367 */
1855 { NOKIA_PCSUITE_ACM_INFO(0x0128), }, /* Nokia 6210 Navigator, RM-419 */
1860 { NOKIA_PCSUITE_ACM_INFO(0x003a), }, /* Nokia N96 & N96-3 */
1863 { NOKIA_PCSUITE_ACM_INFO(0x01f5), }, /* Nokia N97, RM-505 */
1864 { NOKIA_PCSUITE_ACM_INFO(0x02e3), }, /* Nokia 5230, RM-588 */
1883 /* NOTE: non-Nokia COMM/ACM/0xff is likely MSFT RNDIS... NOT a modem! */
1932 /* control interfaces with various AT-command sets */
1985 .throttle = acm_tty_throttle,
2006 return -ENOMEM; in acm_init()
2007 acm_tty_driver->driver_name = "acm", in acm_init()
2008 acm_tty_driver->name = "ttyACM", in acm_init()
2009 acm_tty_driver->major = ACM_TTY_MAJOR, in acm_init()
2010 acm_tty_driver->minor_start = 0, in acm_init()
2011 acm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL, in acm_init()
2012 acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, in acm_init()
2013 acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; in acm_init()
2014 acm_tty_driver->init_termios = tty_std_termios; in acm_init()
2015 acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | in acm_init()