Lines Matching +full:packet +full:- +full:oriented
1 // SPDX-License-Identifier: GPL-1.0+
16 * tty device drivers that support bit-synchronous HDLC communications.
18 * All HDLC data is frame oriented which means:
23 * a byte count in the range of 2-65535 bytes (2 is min HDLC frame
55 * oriented such as N_PPP).
125 * struct n_hdlc - per device instance data structure
165 struct n_hdlc *n_hdlc = tty->disc_data; in flush_rx_queue()
168 while ((buf = n_hdlc_buf_get(&n_hdlc->rx_buf_list))) in flush_rx_queue()
169 n_hdlc_buf_put(&n_hdlc->rx_free_buf_list, buf); in flush_rx_queue()
174 struct n_hdlc *n_hdlc = tty->disc_data; in flush_tx_queue()
177 while ((buf = n_hdlc_buf_get(&n_hdlc->tx_buf_list))) in flush_tx_queue()
178 n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, buf); in flush_tx_queue()
192 * n_hdlc_tty_close - line discipline close
200 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_close()
202 if (n_hdlc->magic != HDLC_MAGIC) { in n_hdlc_tty_close()
207 clear_bit(TTY_NO_WRITE_SPLIT, &tty->flags); in n_hdlc_tty_close()
209 tty->disc_data = NULL; in n_hdlc_tty_close()
212 wake_up_interruptible(&tty->read_wait); in n_hdlc_tty_close()
213 wake_up_interruptible(&tty->write_wait); in n_hdlc_tty_close()
215 cancel_work_sync(&n_hdlc->write_work); in n_hdlc_tty_close()
217 n_hdlc_free_buf_list(&n_hdlc->rx_free_buf_list); in n_hdlc_tty_close()
218 n_hdlc_free_buf_list(&n_hdlc->tx_free_buf_list); in n_hdlc_tty_close()
219 n_hdlc_free_buf_list(&n_hdlc->rx_buf_list); in n_hdlc_tty_close()
220 n_hdlc_free_buf_list(&n_hdlc->tx_buf_list); in n_hdlc_tty_close()
225 * n_hdlc_tty_open - called when line discipline changed to n_hdlc
232 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_open()
234 pr_debug("%s() called (device=%s)\n", __func__, tty->name); in n_hdlc_tty_open()
239 return -EEXIST; in n_hdlc_tty_open()
245 return -ENFILE; in n_hdlc_tty_open()
248 INIT_WORK(&n_hdlc->write_work, n_hdlc_tty_write_work); in n_hdlc_tty_open()
249 n_hdlc->tty_for_write_work = tty; in n_hdlc_tty_open()
250 tty->disc_data = n_hdlc; in n_hdlc_tty_open()
251 tty->receive_room = 65536; in n_hdlc_tty_open()
254 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); in n_hdlc_tty_open()
264 * n_hdlc_send_frames - send frames on pending send buffer list
280 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
281 if (n_hdlc->tbusy) { in n_hdlc_send_frames()
282 n_hdlc->woke_up = true; in n_hdlc_send_frames()
283 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
286 n_hdlc->tbusy = true; in n_hdlc_send_frames()
287 n_hdlc->woke_up = false; in n_hdlc_send_frames()
288 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
290 tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list); in n_hdlc_send_frames()
292 pr_debug("sending frame %p, count=%d\n", tbuf, tbuf->count); in n_hdlc_send_frames()
295 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_hdlc_send_frames()
296 actual = tty->ops->write(tty, tbuf->buf, tbuf->count); in n_hdlc_send_frames()
299 if (actual == -ERESTARTSYS) { in n_hdlc_send_frames()
300 n_hdlc_buf_return(&n_hdlc->tx_buf_list, tbuf); in n_hdlc_send_frames()
306 actual = tbuf->count; in n_hdlc_send_frames()
308 if (actual == tbuf->count) { in n_hdlc_send_frames()
312 n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, tbuf); in n_hdlc_send_frames()
315 wake_up_interruptible(&tty->write_wait); in n_hdlc_send_frames()
318 tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list); in n_hdlc_send_frames()
326 n_hdlc_buf_return(&n_hdlc->tx_buf_list, tbuf); in n_hdlc_send_frames()
332 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_hdlc_send_frames()
334 /* Clear the re-entry flag */ in n_hdlc_send_frames()
335 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
336 n_hdlc->tbusy = false; in n_hdlc_send_frames()
337 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
339 if (n_hdlc->woke_up) in n_hdlc_send_frames()
344 * n_hdlc_tty_write_work - Asynchronous callback for transmit wakeup
352 struct tty_struct *tty = n_hdlc->tty_for_write_work; in n_hdlc_tty_write_work()
358 * n_hdlc_tty_wakeup - Callback for transmit wakeup
365 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_wakeup()
367 schedule_work(&n_hdlc->write_work); in n_hdlc_tty_wakeup()
371 * n_hdlc_tty_receive - Called by tty driver when receive data is available
383 register struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_receive()
389 if (n_hdlc->magic != HDLC_MAGIC) { in n_hdlc_tty_receive()
400 buf = n_hdlc_buf_get(&n_hdlc->rx_free_buf_list); in n_hdlc_tty_receive()
406 if (n_hdlc->rx_buf_list.count < MAX_RX_BUF_COUNT) in n_hdlc_tty_receive()
417 memcpy(buf->buf, data, count); in n_hdlc_tty_receive()
418 buf->count = count; in n_hdlc_tty_receive()
421 n_hdlc_buf_put(&n_hdlc->rx_buf_list, buf); in n_hdlc_tty_receive()
424 wake_up_interruptible(&tty->read_wait); in n_hdlc_tty_receive()
425 if (tty->fasync != NULL) in n_hdlc_tty_receive()
426 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_hdlc_tty_receive()
431 * n_hdlc_tty_read - Called to retrieve one frame of data (if available)
443 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_read()
453 add_wait_queue(&tty->read_wait, &wait); in n_hdlc_tty_read()
456 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { in n_hdlc_tty_read()
457 ret = -EIO; in n_hdlc_tty_read()
465 rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list); in n_hdlc_tty_read()
471 ret = -EAGAIN; in n_hdlc_tty_read()
478 ret = -EINTR; in n_hdlc_tty_read()
483 remove_wait_queue(&tty->read_wait, &wait); in n_hdlc_tty_read()
492 if (offset >= rbuf->count) in n_hdlc_tty_read()
496 ret = -EOVERFLOW; in n_hdlc_tty_read()
501 ret = rbuf->count - offset; in n_hdlc_tty_read()
504 memcpy(kbuf, rbuf->buf+offset, ret); in n_hdlc_tty_read()
508 if (offset < rbuf->count) in n_hdlc_tty_read()
514 if (n_hdlc->rx_free_buf_list.count > DEFAULT_RX_BUF_COUNT) in n_hdlc_tty_read()
517 n_hdlc_buf_put(&n_hdlc->rx_free_buf_list, rbuf); in n_hdlc_tty_read()
524 * n_hdlc_tty_write - write a single frame of data to device
535 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_write()
542 if (n_hdlc->magic != HDLC_MAGIC) in n_hdlc_tty_write()
543 return -EIO; in n_hdlc_tty_write()
547 pr_debug("%s: truncating user packet from %zu to %d\n", in n_hdlc_tty_write()
552 add_wait_queue(&tty->write_wait, &wait); in n_hdlc_tty_write()
557 tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list); in n_hdlc_tty_write()
562 error = -EAGAIN; in n_hdlc_tty_write()
568 error = -EINTR; in n_hdlc_tty_write()
574 remove_wait_queue(&tty->write_wait, &wait); in n_hdlc_tty_write()
578 memcpy(tbuf->buf, data, count); in n_hdlc_tty_write()
581 tbuf->count = error = count; in n_hdlc_tty_write()
582 n_hdlc_buf_put(&n_hdlc->tx_buf_list, tbuf); in n_hdlc_tty_write()
591 * n_hdlc_tty_ioctl - process IOCTL system call for the tty device.
602 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_ioctl()
611 if (n_hdlc->magic != HDLC_MAGIC) in n_hdlc_tty_ioctl()
612 return -EBADF; in n_hdlc_tty_ioctl()
618 spin_lock_irqsave(&n_hdlc->rx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
619 buf = list_first_entry_or_null(&n_hdlc->rx_buf_list.list, in n_hdlc_tty_ioctl()
622 count = buf->count; in n_hdlc_tty_ioctl()
625 spin_unlock_irqrestore(&n_hdlc->rx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
633 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
634 buf = list_first_entry_or_null(&n_hdlc->tx_buf_list.list, in n_hdlc_tty_ioctl()
637 count += buf->count; in n_hdlc_tty_ioctl()
638 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
659 * n_hdlc_tty_poll - TTY callback for poll system call
671 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_poll()
674 if (n_hdlc->magic != HDLC_MAGIC) in n_hdlc_tty_poll()
681 poll_wait(filp, &tty->read_wait, wait); in n_hdlc_tty_poll()
682 poll_wait(filp, &tty->write_wait, wait); in n_hdlc_tty_poll()
685 if (!list_empty(&n_hdlc->rx_buf_list.list)) in n_hdlc_tty_poll()
687 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_hdlc_tty_poll()
692 !list_empty(&n_hdlc->tx_free_buf_list.list)) in n_hdlc_tty_poll()
716 * n_hdlc_alloc - allocate an n_hdlc instance data structure
727 spin_lock_init(&n_hdlc->rx_free_buf_list.spinlock); in n_hdlc_alloc()
728 spin_lock_init(&n_hdlc->tx_free_buf_list.spinlock); in n_hdlc_alloc()
729 spin_lock_init(&n_hdlc->rx_buf_list.spinlock); in n_hdlc_alloc()
730 spin_lock_init(&n_hdlc->tx_buf_list.spinlock); in n_hdlc_alloc()
732 INIT_LIST_HEAD(&n_hdlc->rx_free_buf_list.list); in n_hdlc_alloc()
733 INIT_LIST_HEAD(&n_hdlc->tx_free_buf_list.list); in n_hdlc_alloc()
734 INIT_LIST_HEAD(&n_hdlc->rx_buf_list.list); in n_hdlc_alloc()
735 INIT_LIST_HEAD(&n_hdlc->tx_buf_list.list); in n_hdlc_alloc()
737 n_hdlc_alloc_buf(&n_hdlc->rx_free_buf_list, DEFAULT_RX_BUF_COUNT, "rx"); in n_hdlc_alloc()
738 n_hdlc_alloc_buf(&n_hdlc->tx_free_buf_list, DEFAULT_TX_BUF_COUNT, "tx"); in n_hdlc_alloc()
741 n_hdlc->magic = HDLC_MAGIC; in n_hdlc_alloc()
748 * n_hdlc_buf_return - put the HDLC buffer after the head of the specified list
757 spin_lock_irqsave(&buf_list->spinlock, flags); in n_hdlc_buf_return()
759 list_add(&buf->list_item, &buf_list->list); in n_hdlc_buf_return()
760 buf_list->count++; in n_hdlc_buf_return()
762 spin_unlock_irqrestore(&buf_list->spinlock, flags); in n_hdlc_buf_return()
766 * n_hdlc_buf_put - add specified HDLC buffer to tail of specified list
775 spin_lock_irqsave(&buf_list->spinlock, flags); in n_hdlc_buf_put()
777 list_add_tail(&buf->list_item, &buf_list->list); in n_hdlc_buf_put()
778 buf_list->count++; in n_hdlc_buf_put()
780 spin_unlock_irqrestore(&buf_list->spinlock, flags); in n_hdlc_buf_put()
784 * n_hdlc_buf_get - remove and return an HDLC buffer from list
796 spin_lock_irqsave(&buf_list->spinlock, flags); in n_hdlc_buf_get()
798 buf = list_first_entry_or_null(&buf_list->list, in n_hdlc_buf_get()
801 list_del(&buf->list_item); in n_hdlc_buf_get()
802 buf_list->count--; in n_hdlc_buf_get()
805 spin_unlock_irqrestore(&buf_list->spinlock, flags); in n_hdlc_buf_get()