Lines Matching +full:overrun +full:- +full:throttle +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2010 - 2013 Johan Hovold (jhovold@gmail.com)
6 * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
40 struct device *dev = &serial->interface->dev; in usb_serial_generic_probe()
42 dev_info(dev, "The \"generic\" usb-serial driver is only for testing and one-off prototypes.\n"); in usb_serial_generic_probe()
43 dev_info(dev, "Tell linux-usb@vger.kernel.org to add your device to a proper driver.\n"); in usb_serial_generic_probe()
51 struct device *dev = &serial->interface->dev; in usb_serial_generic_calc_num_ports()
54 num_ports = max(epds->num_bulk_in, epds->num_bulk_out); in usb_serial_generic_calc_num_ports()
58 return -ENODEV; in usb_serial_generic_calc_num_ports()
71 .throttle = usb_serial_generic_throttle,
109 clear_bit(USB_SERIAL_THROTTLED, &port->flags); in usb_serial_generic_open()
111 if (port->bulk_in_size) in usb_serial_generic_open()
123 if (port->bulk_out_size) { in usb_serial_generic_close()
124 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) in usb_serial_generic_close()
125 usb_kill_urb(port->write_urbs[i]); in usb_serial_generic_close()
127 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_close()
128 kfifo_reset_out(&port->write_fifo); in usb_serial_generic_close()
129 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_close()
131 if (port->bulk_in_size) { in usb_serial_generic_close()
132 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) in usb_serial_generic_close()
133 usb_kill_urb(port->read_urbs[i]); in usb_serial_generic_close()
141 return kfifo_out_locked(&port->write_fifo, dest, size, &port->lock); in usb_serial_generic_prepare_write_buffer()
145 * usb_serial_generic_write_start - start writing buffered data
146 * @port: usb-serial port
161 if (test_and_set_bit_lock(USB_SERIAL_WRITE_BUSY, &port->flags)) in usb_serial_generic_write_start()
164 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_write_start()
165 if (!port->write_urbs_free || !kfifo_len(&port->write_fifo)) { in usb_serial_generic_write_start()
166 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); in usb_serial_generic_write_start()
167 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_start()
170 i = (int)find_first_bit(&port->write_urbs_free, in usb_serial_generic_write_start()
171 ARRAY_SIZE(port->write_urbs)); in usb_serial_generic_write_start()
172 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_start()
174 urb = port->write_urbs[i]; in usb_serial_generic_write_start()
175 count = port->serial->type->prepare_write_buffer(port, in usb_serial_generic_write_start()
176 urb->transfer_buffer, in usb_serial_generic_write_start()
177 port->bulk_out_size); in usb_serial_generic_write_start()
178 urb->transfer_buffer_length = count; in usb_serial_generic_write_start()
179 usb_serial_debug_data(&port->dev, __func__, count, urb->transfer_buffer); in usb_serial_generic_write_start()
180 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_write_start()
181 port->tx_bytes += count; in usb_serial_generic_write_start()
182 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_start()
184 clear_bit(i, &port->write_urbs_free); in usb_serial_generic_write_start()
187 dev_err_console(port, "%s - error submitting urb: %d\n", in usb_serial_generic_write_start()
189 set_bit(i, &port->write_urbs_free); in usb_serial_generic_write_start()
190 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_write_start()
191 port->tx_bytes -= count; in usb_serial_generic_write_start()
192 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_start()
194 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); in usb_serial_generic_write_start()
203 * usb_serial_generic_write - generic write function
205 * @port: usb-serial port
217 if (!port->bulk_out_size) in usb_serial_generic_write()
218 return -ENODEV; in usb_serial_generic_write()
223 count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); in usb_serial_generic_write()
234 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_write_room()
238 if (!port->bulk_out_size) in usb_serial_generic_write_room()
241 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_write_room()
242 room = kfifo_avail(&port->write_fifo); in usb_serial_generic_write_room()
243 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_room()
245 dev_dbg(&port->dev, "%s - returns %u\n", __func__, room); in usb_serial_generic_write_room()
251 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_chars_in_buffer()
255 if (!port->bulk_out_size) in usb_serial_generic_chars_in_buffer()
258 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_chars_in_buffer()
259 chars = kfifo_len(&port->write_fifo) + port->tx_bytes; in usb_serial_generic_chars_in_buffer()
260 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_chars_in_buffer()
262 dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars); in usb_serial_generic_chars_in_buffer()
269 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_wait_until_sent()
278 * Use a poll-period of roughly the time it takes to send one in usb_serial_generic_wait_until_sent()
285 dev_dbg(&port->dev, "%s - timeout = %u ms, period = %u ms\n", in usb_serial_generic_wait_until_sent()
289 while (!port->serial->type->tx_empty(port)) { in usb_serial_generic_wait_until_sent()
304 if (!test_and_clear_bit(index, &port->read_urbs_free)) in usb_serial_generic_submit_read_urb()
307 dev_dbg(&port->dev, "%s - urb %d\n", __func__, index); in usb_serial_generic_submit_read_urb()
309 res = usb_submit_urb(port->read_urbs[index], mem_flags); in usb_serial_generic_submit_read_urb()
311 if (res != -EPERM && res != -ENODEV) { in usb_serial_generic_submit_read_urb()
312 dev_err(&port->dev, in usb_serial_generic_submit_read_urb()
313 "%s - usb_submit_urb failed: %d\n", in usb_serial_generic_submit_read_urb()
316 set_bit(index, &port->read_urbs_free); in usb_serial_generic_submit_read_urb()
329 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) { in usb_serial_generic_submit_read_urbs()
337 for (; i >= 0; --i) in usb_serial_generic_submit_read_urbs()
338 usb_kill_urb(port->read_urbs[i]); in usb_serial_generic_submit_read_urbs()
346 struct usb_serial_port *port = urb->context; in usb_serial_generic_process_read_urb()
347 char *ch = urb->transfer_buffer; in usb_serial_generic_process_read_urb()
350 if (!urb->actual_length) in usb_serial_generic_process_read_urb()
357 if (port->sysrq) { in usb_serial_generic_process_read_urb()
358 for (i = 0; i < urb->actual_length; i++, ch++) { in usb_serial_generic_process_read_urb()
360 tty_insert_flip_char(&port->port, *ch, TTY_NORMAL); in usb_serial_generic_process_read_urb()
363 tty_insert_flip_string(&port->port, ch, urb->actual_length); in usb_serial_generic_process_read_urb()
365 tty_flip_buffer_push(&port->port); in usb_serial_generic_process_read_urb()
371 struct usb_serial_port *port = urb->context; in usb_serial_generic_read_bulk_callback()
372 unsigned char *data = urb->transfer_buffer; in usb_serial_generic_read_bulk_callback()
374 int status = urb->status; in usb_serial_generic_read_bulk_callback()
377 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) { in usb_serial_generic_read_bulk_callback()
378 if (urb == port->read_urbs[i]) in usb_serial_generic_read_bulk_callback()
382 dev_dbg(&port->dev, "%s - urb %d, len %d\n", __func__, i, in usb_serial_generic_read_bulk_callback()
383 urb->actual_length); in usb_serial_generic_read_bulk_callback()
386 usb_serial_debug_data(&port->dev, __func__, urb->actual_length, in usb_serial_generic_read_bulk_callback()
388 port->serial->type->process_read_urb(urb); in usb_serial_generic_read_bulk_callback()
390 case -ENOENT: in usb_serial_generic_read_bulk_callback()
391 case -ECONNRESET: in usb_serial_generic_read_bulk_callback()
392 case -ESHUTDOWN: in usb_serial_generic_read_bulk_callback()
393 dev_dbg(&port->dev, "%s - urb stopped: %d\n", in usb_serial_generic_read_bulk_callback()
397 case -EPIPE: in usb_serial_generic_read_bulk_callback()
398 dev_err(&port->dev, "%s - urb stopped: %d\n", in usb_serial_generic_read_bulk_callback()
403 dev_dbg(&port->dev, "%s - nonzero urb status: %d\n", in usb_serial_generic_read_bulk_callback()
415 set_bit(i, &port->read_urbs_free); in usb_serial_generic_read_bulk_callback()
426 if (test_bit(USB_SERIAL_THROTTLED, &port->flags)) in usb_serial_generic_read_bulk_callback()
436 struct usb_serial_port *port = urb->context; in usb_serial_generic_write_bulk_callback()
437 int status = urb->status; in usb_serial_generic_write_bulk_callback()
440 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) { in usb_serial_generic_write_bulk_callback()
441 if (port->write_urbs[i] == urb) in usb_serial_generic_write_bulk_callback()
444 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_write_bulk_callback()
445 port->tx_bytes -= urb->transfer_buffer_length; in usb_serial_generic_write_bulk_callback()
446 set_bit(i, &port->write_urbs_free); in usb_serial_generic_write_bulk_callback()
447 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_bulk_callback()
452 case -ENOENT: in usb_serial_generic_write_bulk_callback()
453 case -ECONNRESET: in usb_serial_generic_write_bulk_callback()
454 case -ESHUTDOWN: in usb_serial_generic_write_bulk_callback()
455 dev_dbg(&port->dev, "%s - urb stopped: %d\n", in usb_serial_generic_write_bulk_callback()
458 case -EPIPE: in usb_serial_generic_write_bulk_callback()
459 dev_err_console(port, "%s - urb stopped: %d\n", in usb_serial_generic_write_bulk_callback()
463 dev_err_console(port, "%s - nonzero urb status: %d\n", in usb_serial_generic_write_bulk_callback()
475 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_throttle()
477 set_bit(USB_SERIAL_THROTTLED, &port->flags); in usb_serial_generic_throttle()
483 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_unthrottle()
485 clear_bit(USB_SERIAL_THROTTLED, &port->flags); in usb_serial_generic_unthrottle()
500 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_msr_changed()
506 * Use tty-port initialised flag to detect all hangups including the in usb_serial_generic_msr_changed()
507 * one generated at USB-device disconnect. in usb_serial_generic_msr_changed()
509 if (!tty_port_initialized(&port->port)) in usb_serial_generic_msr_changed()
512 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_msr_changed()
513 cnow = port->icount; /* atomic copy*/ in usb_serial_generic_msr_changed()
514 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_msr_changed()
516 ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) || in usb_serial_generic_msr_changed()
517 ((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) || in usb_serial_generic_msr_changed()
518 ((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) || in usb_serial_generic_msr_changed()
519 ((arg & TIOCM_CTS) && (cnow.cts != cprev->cts)); in usb_serial_generic_msr_changed()
528 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_tiocmiwait()
533 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_tiocmiwait()
534 cnow = port->icount; /* atomic copy */ in usb_serial_generic_tiocmiwait()
535 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_tiocmiwait()
537 ret = wait_event_interruptible(port->port.delta_msr_wait, in usb_serial_generic_tiocmiwait()
539 if (!ret && !tty_port_initialized(&port->port)) in usb_serial_generic_tiocmiwait()
540 ret = -EIO; in usb_serial_generic_tiocmiwait()
549 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_get_icount()
553 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_get_icount()
554 cnow = port->icount; /* atomic copy */ in usb_serial_generic_get_icount()
555 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_get_icount()
557 icount->cts = cnow.cts; in usb_serial_generic_get_icount()
558 icount->dsr = cnow.dsr; in usb_serial_generic_get_icount()
559 icount->rng = cnow.rng; in usb_serial_generic_get_icount()
560 icount->dcd = cnow.dcd; in usb_serial_generic_get_icount()
561 icount->tx = cnow.tx; in usb_serial_generic_get_icount()
562 icount->rx = cnow.rx; in usb_serial_generic_get_icount()
563 icount->frame = cnow.frame; in usb_serial_generic_get_icount()
564 icount->parity = cnow.parity; in usb_serial_generic_get_icount()
565 icount->overrun = cnow.overrun; in usb_serial_generic_get_icount()
566 icount->brk = cnow.brk; in usb_serial_generic_get_icount()
567 icount->buf_overrun = cnow.buf_overrun; in usb_serial_generic_get_icount()
576 if (port->sysrq) { in usb_serial_handle_sysrq_char()
577 if (ch && time_before(jiffies, port->sysrq)) { in usb_serial_handle_sysrq_char()
579 port->sysrq = 0; in usb_serial_handle_sysrq_char()
582 port->sysrq = 0; in usb_serial_handle_sysrq_char()
590 if (!port->port.console) in usb_serial_handle_break()
593 if (!port->sysrq) { in usb_serial_handle_break()
594 port->sysrq = jiffies + HZ*5; in usb_serial_handle_break()
597 port->sysrq = 0; in usb_serial_handle_break()
604 * usb_serial_handle_dcd_change - handle a change of carrier detect state
605 * @port: usb-serial port
612 dev_dbg(&port->dev, "%s - status %d\n", __func__, status); in usb_serial_handle_dcd_change()
618 if (ld->ops->dcd_change) in usb_serial_handle_dcd_change()
619 ld->ops->dcd_change(tty, status); in usb_serial_handle_dcd_change()
625 wake_up_interruptible(&port->port.open_wait); in usb_serial_handle_dcd_change()
636 for (i = 0; i < serial->num_ports; i++) { in usb_serial_generic_resume()
637 port = serial->port[i]; in usb_serial_generic_resume()
638 if (!tty_port_initialized(&port->port)) in usb_serial_generic_resume()
641 if (port->bulk_in_size) { in usb_serial_generic_resume()
648 if (port->bulk_out_size) { in usb_serial_generic_resume()
655 return c ? -EIO : 0; in usb_serial_generic_resume()