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()
72 .throttle = usb_serial_generic_throttle,
110 clear_bit(USB_SERIAL_THROTTLED, &port->flags); in usb_serial_generic_open()
112 if (port->bulk_in_size) in usb_serial_generic_open()
124 if (port->bulk_out_size) { in usb_serial_generic_close()
125 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) in usb_serial_generic_close()
126 usb_kill_urb(port->write_urbs[i]); in usb_serial_generic_close()
128 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_close()
129 kfifo_reset_out(&port->write_fifo); in usb_serial_generic_close()
130 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_close()
132 if (port->bulk_in_size) { in usb_serial_generic_close()
133 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) in usb_serial_generic_close()
134 usb_kill_urb(port->read_urbs[i]); in usb_serial_generic_close()
142 return kfifo_out_locked(&port->write_fifo, dest, size, &port->lock); in usb_serial_generic_prepare_write_buffer()
146 * usb_serial_generic_write_start - start writing buffered data
147 * @port: usb-serial port
162 if (test_and_set_bit_lock(USB_SERIAL_WRITE_BUSY, &port->flags)) in usb_serial_generic_write_start()
165 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_write_start()
166 if (!port->write_urbs_free || !kfifo_len(&port->write_fifo)) { in usb_serial_generic_write_start()
167 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); in usb_serial_generic_write_start()
168 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_start()
171 i = (int)find_first_bit(&port->write_urbs_free, in usb_serial_generic_write_start()
172 ARRAY_SIZE(port->write_urbs)); in usb_serial_generic_write_start()
173 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_start()
175 urb = port->write_urbs[i]; in usb_serial_generic_write_start()
176 count = port->serial->type->prepare_write_buffer(port, in usb_serial_generic_write_start()
177 urb->transfer_buffer, in usb_serial_generic_write_start()
178 port->bulk_out_size); in usb_serial_generic_write_start()
179 urb->transfer_buffer_length = count; in usb_serial_generic_write_start()
180 usb_serial_debug_data(&port->dev, __func__, count, urb->transfer_buffer); in usb_serial_generic_write_start()
181 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_write_start()
182 port->tx_bytes += count; in usb_serial_generic_write_start()
183 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_start()
185 clear_bit(i, &port->write_urbs_free); in usb_serial_generic_write_start()
188 dev_err_console(port, "%s - error submitting urb: %d\n", in usb_serial_generic_write_start()
190 set_bit(i, &port->write_urbs_free); in usb_serial_generic_write_start()
191 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_write_start()
192 port->tx_bytes -= count; in usb_serial_generic_write_start()
193 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_start()
195 clear_bit_unlock(USB_SERIAL_WRITE_BUSY, &port->flags); in usb_serial_generic_write_start()
204 * usb_serial_generic_write - generic write function
206 * @port: usb-serial port
218 if (!port->bulk_out_size) in usb_serial_generic_write()
219 return -ENODEV; in usb_serial_generic_write()
224 count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock); in usb_serial_generic_write()
235 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_write_room()
239 if (!port->bulk_out_size) in usb_serial_generic_write_room()
242 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_write_room()
243 room = kfifo_avail(&port->write_fifo); in usb_serial_generic_write_room()
244 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_room()
246 dev_dbg(&port->dev, "%s - returns %d\n", __func__, room); in usb_serial_generic_write_room()
252 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_chars_in_buffer()
256 if (!port->bulk_out_size) in usb_serial_generic_chars_in_buffer()
259 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_chars_in_buffer()
260 chars = kfifo_len(&port->write_fifo) + port->tx_bytes; in usb_serial_generic_chars_in_buffer()
261 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_chars_in_buffer()
263 dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars); in usb_serial_generic_chars_in_buffer()
270 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_wait_until_sent()
279 * Use a poll-period of roughly the time it takes to send one in usb_serial_generic_wait_until_sent()
286 dev_dbg(&port->dev, "%s - timeout = %u ms, period = %u ms\n", in usb_serial_generic_wait_until_sent()
290 while (!port->serial->type->tx_empty(port)) { in usb_serial_generic_wait_until_sent()
305 if (!test_and_clear_bit(index, &port->read_urbs_free)) in usb_serial_generic_submit_read_urb()
308 dev_dbg(&port->dev, "%s - urb %d\n", __func__, index); in usb_serial_generic_submit_read_urb()
310 res = usb_submit_urb(port->read_urbs[index], mem_flags); in usb_serial_generic_submit_read_urb()
312 if (res != -EPERM && res != -ENODEV) { in usb_serial_generic_submit_read_urb()
313 dev_err(&port->dev, in usb_serial_generic_submit_read_urb()
314 "%s - usb_submit_urb failed: %d\n", in usb_serial_generic_submit_read_urb()
317 set_bit(index, &port->read_urbs_free); in usb_serial_generic_submit_read_urb()
330 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) { in usb_serial_generic_submit_read_urbs()
338 for (; i >= 0; --i) in usb_serial_generic_submit_read_urbs()
339 usb_kill_urb(port->read_urbs[i]); in usb_serial_generic_submit_read_urbs()
347 struct usb_serial_port *port = urb->context; in usb_serial_generic_process_read_urb()
348 char *ch = urb->transfer_buffer; in usb_serial_generic_process_read_urb()
351 if (!urb->actual_length) in usb_serial_generic_process_read_urb()
358 if (port->sysrq) { in usb_serial_generic_process_read_urb()
359 for (i = 0; i < urb->actual_length; i++, ch++) { in usb_serial_generic_process_read_urb()
361 tty_insert_flip_char(&port->port, *ch, TTY_NORMAL); in usb_serial_generic_process_read_urb()
364 tty_insert_flip_string(&port->port, ch, urb->actual_length); in usb_serial_generic_process_read_urb()
366 tty_flip_buffer_push(&port->port); in usb_serial_generic_process_read_urb()
372 struct usb_serial_port *port = urb->context; in usb_serial_generic_read_bulk_callback()
373 unsigned char *data = urb->transfer_buffer; in usb_serial_generic_read_bulk_callback()
375 int status = urb->status; in usb_serial_generic_read_bulk_callback()
378 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i) { in usb_serial_generic_read_bulk_callback()
379 if (urb == port->read_urbs[i]) in usb_serial_generic_read_bulk_callback()
383 dev_dbg(&port->dev, "%s - urb %d, len %d\n", __func__, i, in usb_serial_generic_read_bulk_callback()
384 urb->actual_length); in usb_serial_generic_read_bulk_callback()
387 usb_serial_debug_data(&port->dev, __func__, urb->actual_length, in usb_serial_generic_read_bulk_callback()
389 port->serial->type->process_read_urb(urb); in usb_serial_generic_read_bulk_callback()
391 case -ENOENT: in usb_serial_generic_read_bulk_callback()
392 case -ECONNRESET: in usb_serial_generic_read_bulk_callback()
393 case -ESHUTDOWN: in usb_serial_generic_read_bulk_callback()
394 dev_dbg(&port->dev, "%s - urb stopped: %d\n", in usb_serial_generic_read_bulk_callback()
398 case -EPIPE: in usb_serial_generic_read_bulk_callback()
399 dev_err(&port->dev, "%s - urb stopped: %d\n", in usb_serial_generic_read_bulk_callback()
404 dev_dbg(&port->dev, "%s - nonzero urb status: %d\n", in usb_serial_generic_read_bulk_callback()
416 set_bit(i, &port->read_urbs_free); in usb_serial_generic_read_bulk_callback()
427 if (test_bit(USB_SERIAL_THROTTLED, &port->flags)) in usb_serial_generic_read_bulk_callback()
437 struct usb_serial_port *port = urb->context; in usb_serial_generic_write_bulk_callback()
438 int status = urb->status; in usb_serial_generic_write_bulk_callback()
441 for (i = 0; i < ARRAY_SIZE(port->write_urbs); ++i) { in usb_serial_generic_write_bulk_callback()
442 if (port->write_urbs[i] == urb) in usb_serial_generic_write_bulk_callback()
445 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_write_bulk_callback()
446 port->tx_bytes -= urb->transfer_buffer_length; in usb_serial_generic_write_bulk_callback()
447 set_bit(i, &port->write_urbs_free); in usb_serial_generic_write_bulk_callback()
448 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_write_bulk_callback()
453 case -ENOENT: in usb_serial_generic_write_bulk_callback()
454 case -ECONNRESET: in usb_serial_generic_write_bulk_callback()
455 case -ESHUTDOWN: in usb_serial_generic_write_bulk_callback()
456 dev_dbg(&port->dev, "%s - urb stopped: %d\n", in usb_serial_generic_write_bulk_callback()
459 case -EPIPE: in usb_serial_generic_write_bulk_callback()
460 dev_err_console(port, "%s - urb stopped: %d\n", in usb_serial_generic_write_bulk_callback()
464 dev_err_console(port, "%s - nonzero urb status: %d\n", in usb_serial_generic_write_bulk_callback()
476 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_throttle()
478 set_bit(USB_SERIAL_THROTTLED, &port->flags); in usb_serial_generic_throttle()
484 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_unthrottle()
486 clear_bit(USB_SERIAL_THROTTLED, &port->flags); in usb_serial_generic_unthrottle()
501 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_msr_changed()
507 * Use tty-port initialised flag to detect all hangups including the in usb_serial_generic_msr_changed()
508 * one generated at USB-device disconnect. in usb_serial_generic_msr_changed()
510 if (!tty_port_initialized(&port->port)) in usb_serial_generic_msr_changed()
513 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_msr_changed()
514 cnow = port->icount; /* atomic copy*/ in usb_serial_generic_msr_changed()
515 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_msr_changed()
517 ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) || in usb_serial_generic_msr_changed()
518 ((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) || in usb_serial_generic_msr_changed()
519 ((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) || in usb_serial_generic_msr_changed()
520 ((arg & TIOCM_CTS) && (cnow.cts != cprev->cts)); in usb_serial_generic_msr_changed()
529 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_tiocmiwait()
534 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_tiocmiwait()
535 cnow = port->icount; /* atomic copy */ in usb_serial_generic_tiocmiwait()
536 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_tiocmiwait()
538 ret = wait_event_interruptible(port->port.delta_msr_wait, in usb_serial_generic_tiocmiwait()
540 if (!ret && !tty_port_initialized(&port->port)) in usb_serial_generic_tiocmiwait()
541 ret = -EIO; in usb_serial_generic_tiocmiwait()
550 struct usb_serial_port *port = tty->driver_data; in usb_serial_generic_get_icount()
554 spin_lock_irqsave(&port->lock, flags); in usb_serial_generic_get_icount()
555 cnow = port->icount; /* atomic copy */ in usb_serial_generic_get_icount()
556 spin_unlock_irqrestore(&port->lock, flags); in usb_serial_generic_get_icount()
558 icount->cts = cnow.cts; in usb_serial_generic_get_icount()
559 icount->dsr = cnow.dsr; in usb_serial_generic_get_icount()
560 icount->rng = cnow.rng; in usb_serial_generic_get_icount()
561 icount->dcd = cnow.dcd; in usb_serial_generic_get_icount()
562 icount->tx = cnow.tx; in usb_serial_generic_get_icount()
563 icount->rx = cnow.rx; in usb_serial_generic_get_icount()
564 icount->frame = cnow.frame; in usb_serial_generic_get_icount()
565 icount->parity = cnow.parity; in usb_serial_generic_get_icount()
566 icount->overrun = cnow.overrun; in usb_serial_generic_get_icount()
567 icount->brk = cnow.brk; in usb_serial_generic_get_icount()
568 icount->buf_overrun = cnow.buf_overrun; in usb_serial_generic_get_icount()
577 if (port->sysrq) { in usb_serial_handle_sysrq_char()
578 if (ch && time_before(jiffies, port->sysrq)) { in usb_serial_handle_sysrq_char()
580 port->sysrq = 0; in usb_serial_handle_sysrq_char()
583 port->sysrq = 0; in usb_serial_handle_sysrq_char()
591 if (!port->port.console) in usb_serial_handle_break()
594 if (!port->sysrq) { in usb_serial_handle_break()
595 port->sysrq = jiffies + HZ*5; in usb_serial_handle_break()
598 port->sysrq = 0; in usb_serial_handle_break()
605 * usb_serial_handle_dcd_change - handle a change of carrier detect state
606 * @port: usb-serial port
613 dev_dbg(&port->dev, "%s - status %d\n", __func__, status); in usb_serial_handle_dcd_change()
619 if (ld->ops->dcd_change) in usb_serial_handle_dcd_change()
620 ld->ops->dcd_change(tty, status); in usb_serial_handle_dcd_change()
626 wake_up_interruptible(&port->port.open_wait); in usb_serial_handle_dcd_change()
637 for (i = 0; i < serial->num_ports; i++) { in usb_serial_generic_resume()
638 port = serial->port[i]; in usb_serial_generic_resume()
639 if (!tty_port_initialized(&port->port)) in usb_serial_generic_resume()
642 if (port->bulk_in_size) { in usb_serial_generic_resume()
649 if (port->bulk_out_size) { in usb_serial_generic_resume()
656 return c ? -EIO : 0; in usb_serial_generic_resume()