Lines Matching +full:ports +full:- +full:block +full:- +full:group +full:- +full:count

1 // SPDX-License-Identifier: GPL-2.0
24 const u8 *f, size_t count) in tty_port_default_receive_buf() argument
29 tty = READ_ONCE(port->itty); in tty_port_default_receive_buf()
37 count = tty_ldisc_receive_buf(ld, p, f, count); in tty_port_default_receive_buf()
41 return count; in tty_port_default_receive_buf()
45 const u8 *f, size_t count) in tty_port_default_lookahead_buf() argument
50 tty = READ_ONCE(port->itty); in tty_port_default_lookahead_buf()
58 if (ld->ops->lookahead_buf) in tty_port_default_lookahead_buf()
59 ld->ops->lookahead_buf(ld->tty, p, f, count); in tty_port_default_lookahead_buf()
82 * tty_port_init - initialize tty_port
94 init_waitqueue_head(&port->open_wait); in tty_port_init()
95 init_waitqueue_head(&port->delta_msr_wait); in tty_port_init()
96 mutex_init(&port->mutex); in tty_port_init()
97 mutex_init(&port->buf_mutex); in tty_port_init()
98 spin_lock_init(&port->lock); in tty_port_init()
99 port->close_delay = (50 * HZ) / 100; in tty_port_init()
100 port->closing_wait = (3000 * HZ) / 100; in tty_port_init()
101 port->client_ops = &tty_port_default_client_ops; in tty_port_init()
102 kref_init(&port->kref); in tty_port_init()
107 * tty_port_link_device - link tty and tty_port
120 if (WARN_ON(index >= driver->num)) in tty_port_link_device()
122 driver->ports[index] = port; in tty_port_link_device()
127 * tty_port_register_device - register tty device
146 * tty_port_register_device_attr - register tty device
152 * @attr_grp: Attribute group to be set on device.
170 * tty_port_register_device_attr_serdev - register tty or serdev device
177 * @attr_grp: attribute group for the device
192 if (PTR_ERR(dev) != -ENODEV) { in tty_port_register_device_attr_serdev()
203 * tty_port_register_device_serdev - register tty or serdev device
223 * tty_port_unregister_device - deregister a tty or serdev device
248 mutex_lock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
249 if (port->xmit_buf == NULL) { in tty_port_alloc_xmit_buf()
250 port->xmit_buf = (u8 *)get_zeroed_page(GFP_KERNEL); in tty_port_alloc_xmit_buf()
251 if (port->xmit_buf) in tty_port_alloc_xmit_buf()
252 kfifo_init(&port->xmit_fifo, port->xmit_buf, PAGE_SIZE); in tty_port_alloc_xmit_buf()
254 mutex_unlock(&port->buf_mutex); in tty_port_alloc_xmit_buf()
255 if (port->xmit_buf == NULL) in tty_port_alloc_xmit_buf()
256 return -ENOMEM; in tty_port_alloc_xmit_buf()
263 mutex_lock(&port->buf_mutex); in tty_port_free_xmit_buf()
264 free_page((unsigned long)port->xmit_buf); in tty_port_free_xmit_buf()
265 port->xmit_buf = NULL; in tty_port_free_xmit_buf()
266 INIT_KFIFO(port->xmit_fifo); in tty_port_free_xmit_buf()
267 mutex_unlock(&port->buf_mutex); in tty_port_free_xmit_buf()
272 * tty_port_destroy - destroy inited port
291 if (WARN_ON(port->itty)) in tty_port_destructor()
293 free_page((unsigned long)port->xmit_buf); in tty_port_destructor()
295 if (port->ops && port->ops->destruct) in tty_port_destructor()
296 port->ops->destruct(port); in tty_port_destructor()
302 * tty_port_put - drop a reference to tty_port
306 * @port->ops->destruct() hook, or using kfree() if not provided.
311 kref_put(&port->kref, tty_port_destructor); in tty_port_put()
316 * tty_port_tty_get - get a tty reference
327 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_get()
328 tty = tty_kref_get(port->tty); in tty_port_tty_get()
329 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_get()
335 * tty_port_tty_set - set the tty of a port
346 spin_lock_irqsave(&port->lock, flags); in tty_port_tty_set()
347 tty_kref_put(port->tty); in tty_port_tty_set()
348 port->tty = tty_kref_get(tty); in tty_port_tty_set()
349 spin_unlock_irqrestore(&port->lock, flags); in tty_port_tty_set()
354 * tty_port_shutdown - internal helper to shutdown the device
361 * @port->ops->shutdown().
365 mutex_lock(&port->mutex); in tty_port_shutdown()
366 if (port->console) in tty_port_shutdown()
378 if (port->ops->shutdown) in tty_port_shutdown()
379 port->ops->shutdown(port); in tty_port_shutdown()
382 mutex_unlock(&port->mutex); in tty_port_shutdown()
386 * tty_port_hangup - hangup helper
389 * Perform port level tty hangup flag and count changes. Drop the tty
399 spin_lock_irqsave(&port->lock, flags); in tty_port_hangup()
400 port->count = 0; in tty_port_hangup()
401 tty = port->tty; in tty_port_hangup()
403 set_bit(TTY_IO_ERROR, &tty->flags); in tty_port_hangup()
404 port->tty = NULL; in tty_port_hangup()
405 spin_unlock_irqrestore(&port->lock, flags); in tty_port_hangup()
409 wake_up_interruptible(&port->open_wait); in tty_port_hangup()
410 wake_up_interruptible(&port->delta_msr_wait); in tty_port_hangup()
415 * tty_port_tty_hangup - helper to hang up a tty
430 * tty_port_tty_wakeup - helper to wake up a tty
435 port->client_ops->write_wakeup(port); in tty_port_tty_wakeup()
440 * tty_port_carrier_raised - carrier raised check
449 if (port->ops->carrier_raised == NULL) in tty_port_carrier_raised()
451 return port->ops->carrier_raised(port); in tty_port_carrier_raised()
456 * tty_port_raise_dtr_rts - Raise DTR/RTS
465 if (port->ops->dtr_rts) in tty_port_raise_dtr_rts()
466 port->ops->dtr_rts(port, true); in tty_port_raise_dtr_rts()
471 * tty_port_lower_dtr_rts - Lower DTR/RTS
480 if (port->ops->dtr_rts) in tty_port_lower_dtr_rts()
481 port->ops->dtr_rts(port, false); in tty_port_lower_dtr_rts()
486 * tty_port_block_til_ready - Waiting logic for tty open
494 * - hangup (both before and during)
495 * - non blocking open
496 * - rts/dtr/dcd
497 * - signals
498 * - port flags and counts
500 * The passed @port must implement the @port->ops->carrier_raised method if it
501 * can do carrier detect and the @port->ops->dtr_rts method if it supports
517 /* if non-blocking mode is set we can pass directly to open unless in tty_port_block_til_ready()
524 if (filp == NULL || (filp->f_flags & O_NONBLOCK)) { in tty_port_block_til_ready()
535 /* Block waiting until we can proceed. We may need to wait for the in tty_port_block_til_ready()
543 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
544 port->count--; in tty_port_block_til_ready()
545 port->blocked_open++; in tty_port_block_til_ready()
546 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
553 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE); in tty_port_block_til_ready()
558 if (port->flags & ASYNC_HUP_NOTIFY) in tty_port_block_til_ready()
559 retval = -EAGAIN; in tty_port_block_til_ready()
561 retval = -ERESTARTSYS; in tty_port_block_til_ready()
573 retval = -ERESTARTSYS; in tty_port_block_til_ready()
580 finish_wait(&port->open_wait, &wait); in tty_port_block_til_ready()
582 /* Update counts. A parallel hangup will have set count to zero and in tty_port_block_til_ready()
585 spin_lock_irqsave(&port->lock, flags); in tty_port_block_til_ready()
587 port->count++; in tty_port_block_til_ready()
588 port->blocked_open--; in tty_port_block_til_ready()
589 spin_unlock_irqrestore(&port->lock, flags); in tty_port_block_til_ready()
602 timeout = (HZ * 10 * port->drain_delay) / bps; in tty_port_drain_delay()
611 * tty_port_close_start - helper for tty->ops->close, part 1/2
616 * Decrements and checks open count. Flushes the port if this is the last
633 spin_lock_irqsave(&port->lock, flags); in tty_port_close_start()
634 if (tty->count == 1 && port->count != 1) { in tty_port_close_start()
635 tty_warn(tty, "%s: tty->count = 1 port count = %d\n", __func__, in tty_port_close_start()
636 port->count); in tty_port_close_start()
637 port->count = 1; in tty_port_close_start()
639 if (--port->count < 0) { in tty_port_close_start()
640 tty_warn(tty, "%s: bad port count (%d)\n", __func__, in tty_port_close_start()
641 port->count); in tty_port_close_start()
642 port->count = 0; in tty_port_close_start()
645 if (port->count) { in tty_port_close_start()
646 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
649 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_start()
651 tty->closing = 1; in tty_port_close_start()
654 /* Don't block on a stalled port, just pull the chain */ in tty_port_close_start()
655 if (tty->flow.tco_stopped) in tty_port_close_start()
657 if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) in tty_port_close_start()
658 tty_wait_until_sent(tty, port->closing_wait); in tty_port_close_start()
659 if (port->drain_delay) in tty_port_close_start()
671 * tty_port_close_end - helper for tty->ops->close, part 2/2
677 * line discipline and delays the close by @port->close_delay.
686 tty->closing = 0; in tty_port_close_end()
688 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
690 if (port->blocked_open) { in tty_port_close_end()
691 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
692 if (port->close_delay) in tty_port_close_end()
693 msleep_interruptible(jiffies_to_msecs(port->close_delay)); in tty_port_close_end()
694 spin_lock_irqsave(&port->lock, flags); in tty_port_close_end()
695 wake_up_interruptible(&port->open_wait); in tty_port_close_end()
697 spin_unlock_irqrestore(&port->lock, flags); in tty_port_close_end()
703 * tty_port_close - generic tty->ops->close handler
708 * It is a generic helper to be used in driver's @tty->ops->close. It wraps a
721 if (!port->console) in tty_port_close()
722 set_bit(TTY_IO_ERROR, &tty->flags); in tty_port_close()
729 * tty_port_install - generic tty->ops->install handler
741 tty->port = port; in tty_port_install()
747 * tty_port_open - generic tty->ops->open handler
752 * It is a generic helper to be used in driver's @tty->ops->open. It activates
753 * the devices using @port->ops->activate if not active already. And waits for
757 * Note that @port->ops->shutdown is not called when @port->ops->activate
758 * returns an error (on the contrary, @tty->ops->close is).
768 spin_lock_irq(&port->lock); in tty_port_open()
769 ++port->count; in tty_port_open()
770 spin_unlock_irq(&port->lock); in tty_port_open()
774 * Do the device-specific open only if the hardware isn't in tty_port_open()
779 mutex_lock(&port->mutex); in tty_port_open()
782 clear_bit(TTY_IO_ERROR, &tty->flags); in tty_port_open()
783 if (port->ops->activate) { in tty_port_open()
784 int retval = port->ops->activate(port, tty); in tty_port_open()
787 mutex_unlock(&port->mutex); in tty_port_open()
793 mutex_unlock(&port->mutex); in tty_port_open()