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).
123 * struct n_hdlc - per device instance data structure
161 struct n_hdlc *n_hdlc = tty->disc_data; in flush_rx_queue()
164 while ((buf = n_hdlc_buf_get(&n_hdlc->rx_buf_list))) in flush_rx_queue()
165 n_hdlc_buf_put(&n_hdlc->rx_free_buf_list, buf); in flush_rx_queue()
170 struct n_hdlc *n_hdlc = tty->disc_data; in flush_tx_queue()
173 while ((buf = n_hdlc_buf_get(&n_hdlc->tx_buf_list))) in flush_tx_queue()
174 n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, buf); in flush_tx_queue()
188 * n_hdlc_tty_close - line discipline close
196 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_close()
199 clear_bit(TTY_NO_WRITE_SPLIT, &tty->flags); in n_hdlc_tty_close()
201 tty->disc_data = NULL; in n_hdlc_tty_close()
204 wake_up_interruptible(&tty->read_wait); in n_hdlc_tty_close()
205 wake_up_interruptible(&tty->write_wait); in n_hdlc_tty_close()
207 cancel_work_sync(&n_hdlc->write_work); in n_hdlc_tty_close()
209 n_hdlc_free_buf_list(&n_hdlc->rx_free_buf_list); in n_hdlc_tty_close()
210 n_hdlc_free_buf_list(&n_hdlc->tx_free_buf_list); in n_hdlc_tty_close()
211 n_hdlc_free_buf_list(&n_hdlc->rx_buf_list); in n_hdlc_tty_close()
212 n_hdlc_free_buf_list(&n_hdlc->tx_buf_list); in n_hdlc_tty_close()
217 * n_hdlc_tty_open - called when line discipline changed to n_hdlc
224 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_open()
226 pr_debug("%s() called (device=%s)\n", __func__, tty->name); in n_hdlc_tty_open()
231 return -EEXIST; in n_hdlc_tty_open()
237 return -ENFILE; in n_hdlc_tty_open()
240 INIT_WORK(&n_hdlc->write_work, n_hdlc_tty_write_work); in n_hdlc_tty_open()
241 n_hdlc->tty_for_write_work = tty; in n_hdlc_tty_open()
242 tty->disc_data = n_hdlc; in n_hdlc_tty_open()
243 tty->receive_room = 65536; in n_hdlc_tty_open()
246 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); in n_hdlc_tty_open()
256 * n_hdlc_send_frames - send frames on pending send buffer list
272 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
273 if (n_hdlc->tbusy) { in n_hdlc_send_frames()
274 n_hdlc->woke_up = true; in n_hdlc_send_frames()
275 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
278 n_hdlc->tbusy = true; in n_hdlc_send_frames()
279 n_hdlc->woke_up = false; in n_hdlc_send_frames()
280 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
282 tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list); in n_hdlc_send_frames()
284 pr_debug("sending frame %p, count=%zu\n", tbuf, tbuf->count); in n_hdlc_send_frames()
287 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_hdlc_send_frames()
288 actual = tty->ops->write(tty, tbuf->buf, tbuf->count); in n_hdlc_send_frames()
291 if (actual == -ERESTARTSYS) { in n_hdlc_send_frames()
292 n_hdlc_buf_return(&n_hdlc->tx_buf_list, tbuf); in n_hdlc_send_frames()
298 actual = tbuf->count; in n_hdlc_send_frames()
300 if (actual == tbuf->count) { in n_hdlc_send_frames()
304 n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, tbuf); in n_hdlc_send_frames()
307 wake_up_interruptible(&tty->write_wait); in n_hdlc_send_frames()
310 tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list); in n_hdlc_send_frames()
318 n_hdlc_buf_return(&n_hdlc->tx_buf_list, tbuf); in n_hdlc_send_frames()
324 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); in n_hdlc_send_frames()
326 /* Clear the re-entry flag */ in n_hdlc_send_frames()
327 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
328 n_hdlc->tbusy = false; in n_hdlc_send_frames()
329 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_send_frames()
331 if (n_hdlc->woke_up) in n_hdlc_send_frames()
336 * n_hdlc_tty_write_work - Asynchronous callback for transmit wakeup
344 struct tty_struct *tty = n_hdlc->tty_for_write_work; in n_hdlc_tty_write_work()
350 * n_hdlc_tty_wakeup - Callback for transmit wakeup
357 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_wakeup()
359 schedule_work(&n_hdlc->write_work); in n_hdlc_tty_wakeup()
363 * n_hdlc_tty_receive - Called by tty driver when receive data is available
375 register struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_receive()
386 buf = n_hdlc_buf_get(&n_hdlc->rx_free_buf_list); in n_hdlc_tty_receive()
392 if (n_hdlc->rx_buf_list.count < MAX_RX_BUF_COUNT) in n_hdlc_tty_receive()
403 memcpy(buf->buf, data, count); in n_hdlc_tty_receive()
404 buf->count = count; in n_hdlc_tty_receive()
407 n_hdlc_buf_put(&n_hdlc->rx_buf_list, buf); in n_hdlc_tty_receive()
410 wake_up_interruptible(&tty->read_wait); in n_hdlc_tty_receive()
411 if (tty->fasync != NULL) in n_hdlc_tty_receive()
412 kill_fasync(&tty->fasync, SIGIO, POLL_IN); in n_hdlc_tty_receive()
417 * n_hdlc_tty_read - Called to retrieve one frame of data (if available)
431 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_read()
441 add_wait_queue(&tty->read_wait, &wait); in n_hdlc_tty_read()
444 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) { in n_hdlc_tty_read()
445 ret = -EIO; in n_hdlc_tty_read()
453 rbuf = n_hdlc_buf_get(&n_hdlc->rx_buf_list); in n_hdlc_tty_read()
459 ret = -EAGAIN; in n_hdlc_tty_read()
466 ret = -EINTR; in n_hdlc_tty_read()
471 remove_wait_queue(&tty->read_wait, &wait); in n_hdlc_tty_read()
480 if (offset >= rbuf->count) in n_hdlc_tty_read()
484 ret = -EOVERFLOW; in n_hdlc_tty_read()
489 ret = rbuf->count - offset; in n_hdlc_tty_read()
492 memcpy(kbuf, rbuf->buf+offset, ret); in n_hdlc_tty_read()
496 if (offset < rbuf->count) in n_hdlc_tty_read()
502 if (n_hdlc->rx_free_buf_list.count > DEFAULT_RX_BUF_COUNT) in n_hdlc_tty_read()
505 n_hdlc_buf_put(&n_hdlc->rx_free_buf_list, rbuf); in n_hdlc_tty_read()
512 * n_hdlc_tty_write - write a single frame of data to device
523 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_write()
532 pr_debug("%s: truncating user packet from %zu to %d\n", in n_hdlc_tty_write()
537 add_wait_queue(&tty->write_wait, &wait); in n_hdlc_tty_write()
542 tbuf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list); in n_hdlc_tty_write()
547 error = -EAGAIN; in n_hdlc_tty_write()
553 error = -EINTR; in n_hdlc_tty_write()
559 remove_wait_queue(&tty->write_wait, &wait); in n_hdlc_tty_write()
563 memcpy(tbuf->buf, data, count); in n_hdlc_tty_write()
566 tbuf->count = error = count; in n_hdlc_tty_write()
567 n_hdlc_buf_put(&n_hdlc->tx_buf_list, tbuf); in n_hdlc_tty_write()
576 * n_hdlc_tty_ioctl - process IOCTL system call for the tty device.
586 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_ioctl()
598 spin_lock_irqsave(&n_hdlc->rx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
599 buf = list_first_entry_or_null(&n_hdlc->rx_buf_list.list, in n_hdlc_tty_ioctl()
602 count = buf->count; in n_hdlc_tty_ioctl()
605 spin_unlock_irqrestore(&n_hdlc->rx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
613 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
614 buf = list_first_entry_or_null(&n_hdlc->tx_buf_list.list, in n_hdlc_tty_ioctl()
617 count += buf->count; in n_hdlc_tty_ioctl()
618 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags); in n_hdlc_tty_ioctl()
639 * n_hdlc_tty_poll - TTY callback for poll system call
651 struct n_hdlc *n_hdlc = tty->disc_data; in n_hdlc_tty_poll()
658 poll_wait(filp, &tty->read_wait, wait); in n_hdlc_tty_poll()
659 poll_wait(filp, &tty->write_wait, wait); in n_hdlc_tty_poll()
662 if (!list_empty(&n_hdlc->rx_buf_list.list)) in n_hdlc_tty_poll()
664 if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) in n_hdlc_tty_poll()
669 !list_empty(&n_hdlc->tx_free_buf_list.list)) in n_hdlc_tty_poll()
693 * n_hdlc_alloc - allocate an n_hdlc instance data structure
704 spin_lock_init(&n_hdlc->rx_free_buf_list.spinlock); in n_hdlc_alloc()
705 spin_lock_init(&n_hdlc->tx_free_buf_list.spinlock); in n_hdlc_alloc()
706 spin_lock_init(&n_hdlc->rx_buf_list.spinlock); in n_hdlc_alloc()
707 spin_lock_init(&n_hdlc->tx_buf_list.spinlock); in n_hdlc_alloc()
709 INIT_LIST_HEAD(&n_hdlc->rx_free_buf_list.list); in n_hdlc_alloc()
710 INIT_LIST_HEAD(&n_hdlc->tx_free_buf_list.list); in n_hdlc_alloc()
711 INIT_LIST_HEAD(&n_hdlc->rx_buf_list.list); in n_hdlc_alloc()
712 INIT_LIST_HEAD(&n_hdlc->tx_buf_list.list); in n_hdlc_alloc()
714 n_hdlc_alloc_buf(&n_hdlc->rx_free_buf_list, DEFAULT_RX_BUF_COUNT, "rx"); in n_hdlc_alloc()
715 n_hdlc_alloc_buf(&n_hdlc->tx_free_buf_list, DEFAULT_TX_BUF_COUNT, "tx"); in n_hdlc_alloc()
722 * n_hdlc_buf_return - put the HDLC buffer after the head of the specified list
731 spin_lock_irqsave(&buf_list->spinlock, flags); in n_hdlc_buf_return()
733 list_add(&buf->list_item, &buf_list->list); in n_hdlc_buf_return()
734 buf_list->count++; in n_hdlc_buf_return()
736 spin_unlock_irqrestore(&buf_list->spinlock, flags); in n_hdlc_buf_return()
740 * n_hdlc_buf_put - add specified HDLC buffer to tail of specified list
749 spin_lock_irqsave(&buf_list->spinlock, flags); in n_hdlc_buf_put()
751 list_add_tail(&buf->list_item, &buf_list->list); in n_hdlc_buf_put()
752 buf_list->count++; in n_hdlc_buf_put()
754 spin_unlock_irqrestore(&buf_list->spinlock, flags); in n_hdlc_buf_put()
758 * n_hdlc_buf_get - remove and return an HDLC buffer from list
770 spin_lock_irqsave(&buf_list->spinlock, flags); in n_hdlc_buf_get()
772 buf = list_first_entry_or_null(&buf_list->list, in n_hdlc_buf_get()
775 list_del(&buf->list_item); in n_hdlc_buf_get()
776 buf_list->count--; in n_hdlc_buf_get()
779 spin_unlock_irqrestore(&buf_list->spinlock, flags); in n_hdlc_buf_get()