• Home
  • Raw
  • Download

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).
126 * struct n_hdlc - per device instance data structure
166 struct n_hdlc *n_hdlc = tty->disc_data; in flush_rx_queue()
169 while ((buf = n_hdlc_buf_get(&n_hdlc->rx_buf_list))) in flush_rx_queue()
170 n_hdlc_buf_put(&n_hdlc->rx_free_buf_list, buf); in flush_rx_queue()
175 struct n_hdlc *n_hdlc = tty->disc_data; in flush_tx_queue()
178 while ((buf = n_hdlc_buf_get(&n_hdlc->tx_buf_list))) in flush_tx_queue()
179 n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, buf); in flush_tx_queue()
193 * n_hdlc_tty_close - line discipline close
201 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_close()
203 if (n_hdlc->magic != HDLC_MAGIC) { in n_hdlc_tty_close()
208 clear_bit(TTY_NO_WRITE_SPLIT, &tty->flags); in n_hdlc_tty_close()
210 tty->disc_data = NULL; in n_hdlc_tty_close()
213 wake_up_interruptible(&tty->read_wait); in n_hdlc_tty_close()
214 wake_up_interruptible(&tty->write_wait); in n_hdlc_tty_close()
216 cancel_work_sync(&n_hdlc->write_work); in n_hdlc_tty_close()
218 n_hdlc_free_buf_list(&n_hdlc->rx_free_buf_list); in n_hdlc_tty_close()
219 n_hdlc_free_buf_list(&n_hdlc->tx_free_buf_list); in n_hdlc_tty_close()
220 n_hdlc_free_buf_list(&n_hdlc->rx_buf_list); in n_hdlc_tty_close()
221 n_hdlc_free_buf_list(&n_hdlc->tx_buf_list); in n_hdlc_tty_close()
226 * n_hdlc_tty_open - called when line discipline changed to n_hdlc
233 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_open()
235 pr_debug("%s() called (device=%s)\n", __func__, tty->name); in n_hdlc_tty_open()
240 return -EEXIST; in n_hdlc_tty_open()
246 return -ENFILE; in n_hdlc_tty_open()
249 INIT_WORK(&n_hdlc->write_work, n_hdlc_tty_write_work); in n_hdlc_tty_open()
250 n_hdlc->tty_for_write_work = tty; in n_hdlc_tty_open()
251 tty->disc_data = n_hdlc; in n_hdlc_tty_open()
252 tty->receive_room = 65536; in n_hdlc_tty_open()
255 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); in n_hdlc_tty_open()
265 * n_hdlc_send_frames - send frames on pending send buffer list
281 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
282 if (n_hdlc->tbusy) { in n_hdlc_send_frames()
283 n_hdlc->woke_up = true; in n_hdlc_send_frames()
284 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
287 n_hdlc->tbusy = true; in n_hdlc_send_frames()
288 n_hdlc->woke_up = false; in n_hdlc_send_frames()
289 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
291 tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list); in n_hdlc_send_frames()
293 pr_debug("sending frame %p, count=%d\n", tbuf, tbuf->count); in n_hdlc_send_frames()
296 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_hdlc_send_frames()
297 actual = tty->ops->write(tty, tbuf->buf, tbuf->count); in n_hdlc_send_frames()
300 if (actual == -ERESTARTSYS) { in n_hdlc_send_frames()
301 n_hdlc_buf_return(&n_hdlc->tx_buf_list, tbuf); in n_hdlc_send_frames()
307 actual = tbuf->count; in n_hdlc_send_frames()
309 if (actual == tbuf->count) { in n_hdlc_send_frames()
313 n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, tbuf); in n_hdlc_send_frames()
316 wake_up_interruptible(&tty->write_wait); in n_hdlc_send_frames()
319 tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list); in n_hdlc_send_frames()
327 n_hdlc_buf_return(&n_hdlc->tx_buf_list, tbuf); in n_hdlc_send_frames()
333 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_hdlc_send_frames()
335 /* Clear the re-entry flag */ in n_hdlc_send_frames()
336 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
337 n_hdlc->tbusy = false; in n_hdlc_send_frames()
338 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
340 if (n_hdlc->woke_up) in n_hdlc_send_frames()
345 * n_hdlc_tty_write_work - Asynchronous callback for transmit wakeup
353 struct tty_struct *tty = n_hdlc->tty_for_write_work; in n_hdlc_tty_write_work()
359 * n_hdlc_tty_wakeup - Callback for transmit wakeup
366 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_wakeup()
368 schedule_work(&n_hdlc->write_work); in n_hdlc_tty_wakeup()
372 * n_hdlc_tty_receive - Called by tty driver when receive data is available
384 register struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_receive()
390 if (n_hdlc->magic != HDLC_MAGIC) { in n_hdlc_tty_receive()
401 buf = n_hdlc_buf_get(&n_hdlc->rx_free_buf_list); in n_hdlc_tty_receive()
407 if (n_hdlc->rx_buf_list.count < MAX_RX_BUF_COUNT) in n_hdlc_tty_receive()
418 memcpy(buf->buf, data, count); in n_hdlc_tty_receive()
419 buf->count = count; in n_hdlc_tty_receive()
422 n_hdlc_buf_put(&n_hdlc->rx_buf_list, buf); in n_hdlc_tty_receive()
425 wake_up_interruptible(&tty->read_wait); in n_hdlc_tty_receive()
426 if (tty->fasync != NULL) in n_hdlc_tty_receive()
427 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_hdlc_tty_receive()
432 * n_hdlc_tty_read - Called to retrieve one frame of data (if available)
444 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_read()
454 add_wait_queue(&tty->read_wait, &wait); in n_hdlc_tty_read()
457 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { in n_hdlc_tty_read()
458 ret = -EIO; in n_hdlc_tty_read()
466 rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list); in n_hdlc_tty_read()
472 ret = -EAGAIN; in n_hdlc_tty_read()
479 ret = -EINTR; in n_hdlc_tty_read()
484 remove_wait_queue(&tty->read_wait, &wait); in n_hdlc_tty_read()
493 if (offset >= rbuf->count) in n_hdlc_tty_read()
497 ret = -EOVERFLOW; in n_hdlc_tty_read()
502 ret = rbuf->count - offset; in n_hdlc_tty_read()
505 memcpy(kbuf, rbuf->buf+offset, ret); in n_hdlc_tty_read()
509 if (offset < rbuf->count) in n_hdlc_tty_read()
515 if (n_hdlc->rx_free_buf_list.count > DEFAULT_RX_BUF_COUNT) in n_hdlc_tty_read()
518 n_hdlc_buf_put(&n_hdlc->rx_free_buf_list, rbuf); in n_hdlc_tty_read()
525 * n_hdlc_tty_write - write a single frame of data to device
536 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_write()
543 if (n_hdlc->magic != HDLC_MAGIC) in n_hdlc_tty_write()
544 return -EIO; in n_hdlc_tty_write()
548 pr_debug("%s: truncating user packet from %zu to %d\n", in n_hdlc_tty_write()
553 add_wait_queue(&tty->write_wait, &wait); in n_hdlc_tty_write()
558 tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list); in n_hdlc_tty_write()
563 error = -EAGAIN; in n_hdlc_tty_write()
569 error = -EINTR; in n_hdlc_tty_write()
575 remove_wait_queue(&tty->write_wait, &wait); in n_hdlc_tty_write()
579 memcpy(tbuf->buf, data, count); in n_hdlc_tty_write()
582 tbuf->count = error = count; in n_hdlc_tty_write()
583 n_hdlc_buf_put(&n_hdlc->tx_buf_list, tbuf); in n_hdlc_tty_write()
592 * n_hdlc_tty_ioctl - process IOCTL system call for the tty device.
603 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_ioctl()
612 if (n_hdlc->magic != HDLC_MAGIC) in n_hdlc_tty_ioctl()
613 return -EBADF; in n_hdlc_tty_ioctl()
619 spin_lock_irqsave(&n_hdlc->rx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
620 buf = list_first_entry_or_null(&n_hdlc->rx_buf_list.list, in n_hdlc_tty_ioctl()
623 count = buf->count; in n_hdlc_tty_ioctl()
626 spin_unlock_irqrestore(&n_hdlc->rx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
634 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
635 buf = list_first_entry_or_null(&n_hdlc->tx_buf_list.list, in n_hdlc_tty_ioctl()
638 count += buf->count; in n_hdlc_tty_ioctl()
639 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
660 * n_hdlc_tty_poll - TTY callback for poll system call
672 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_poll()
675 if (n_hdlc->magic != HDLC_MAGIC) in n_hdlc_tty_poll()
682 poll_wait(filp, &tty->read_wait, wait); in n_hdlc_tty_poll()
683 poll_wait(filp, &tty->write_wait, wait); in n_hdlc_tty_poll()
686 if (!list_empty(&n_hdlc->rx_buf_list.list)) in n_hdlc_tty_poll()
688 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_hdlc_tty_poll()
693 !list_empty(&n_hdlc->tx_free_buf_list.list)) in n_hdlc_tty_poll()
717 * n_hdlc_alloc - allocate an n_hdlc instance data structure
728 spin_lock_init(&n_hdlc->rx_free_buf_list.spinlock); in n_hdlc_alloc()
729 spin_lock_init(&n_hdlc->tx_free_buf_list.spinlock); in n_hdlc_alloc()
730 spin_lock_init(&n_hdlc->rx_buf_list.spinlock); in n_hdlc_alloc()
731 spin_lock_init(&n_hdlc->tx_buf_list.spinlock); in n_hdlc_alloc()
733 INIT_LIST_HEAD(&n_hdlc->rx_free_buf_list.list); in n_hdlc_alloc()
734 INIT_LIST_HEAD(&n_hdlc->tx_free_buf_list.list); in n_hdlc_alloc()
735 INIT_LIST_HEAD(&n_hdlc->rx_buf_list.list); in n_hdlc_alloc()
736 INIT_LIST_HEAD(&n_hdlc->tx_buf_list.list); in n_hdlc_alloc()
738 n_hdlc_alloc_buf(&n_hdlc->rx_free_buf_list, DEFAULT_RX_BUF_COUNT, "rx"); in n_hdlc_alloc()
739 n_hdlc_alloc_buf(&n_hdlc->tx_free_buf_list, DEFAULT_TX_BUF_COUNT, "tx"); in n_hdlc_alloc()
742 n_hdlc->magic = HDLC_MAGIC; in n_hdlc_alloc()
749 * n_hdlc_buf_return - put the HDLC buffer after the head of the specified list
758 spin_lock_irqsave(&buf_list->spinlock, flags); in n_hdlc_buf_return()
760 list_add(&buf->list_item, &buf_list->list); in n_hdlc_buf_return()
761 buf_list->count++; in n_hdlc_buf_return()
763 spin_unlock_irqrestore(&buf_list->spinlock, flags); in n_hdlc_buf_return()
767 * n_hdlc_buf_put - add specified HDLC buffer to tail of specified list
776 spin_lock_irqsave(&buf_list->spinlock, flags); in n_hdlc_buf_put()
778 list_add_tail(&buf->list_item, &buf_list->list); in n_hdlc_buf_put()
779 buf_list->count++; in n_hdlc_buf_put()
781 spin_unlock_irqrestore(&buf_list->spinlock, flags); in n_hdlc_buf_put()
785 * n_hdlc_buf_get - remove and return an HDLC buffer from list
797 spin_lock_irqsave(&buf_list->spinlock, flags); in n_hdlc_buf_get()
799 buf = list_first_entry_or_null(&buf_list->list, in n_hdlc_buf_get()
802 list_del(&buf->list_item); in n_hdlc_buf_get()
803 buf_list->count--; in n_hdlc_buf_get()
806 spin_unlock_irqrestore(&buf_list->spinlock, flags); in n_hdlc_buf_get()