• Home
  • Raw
  • Download

Lines Matching +full:frame +full:- +full:buffer

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:
20 * 1. tty write calls represent one complete transmit frame of data
21 * The device driver should accept the complete frame or none of
22 * the frame (busy) in the write method. Each write call should have
23 * a byte count in the range of 2-65535 bytes (2 is min HDLC frame
26 * CCITT CRC32, 4 crc bytes are required, so the maximum size frame
28 * CRC16, the maximum application frame size would be 65533.
32 * one received frame. The device driver should bypass
33 * the tty flip buffer and call the line discipline receive
41 * 3. tty read calls returns an entire frame of data or nothing.
49 * otherwise the count of the next available frame is returned.
50 * (instead of the sum of all received frame counts).
54 * this line discipline (or another line discipline that is frame
64 * and frame orientation of HDLC communications.
125 * struct n_hdlc - per device instance data structure
129 * @tx_buf_list: list of pending transmit frame buffers
130 * @rx_buf_list: list of received frame buffers
131 * @tx_free_buf_list: list unused transmit frame buffers
132 * @rx_free_buf_list: list unused received frame buffers
147 * HDLC buffer list manipulation functions
160 /* max frame size for memory allocations */
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
268 * Send frames on pending send buffer list until the driver does not accept a
269 * frame (busy) this function is called after adding a frame to the send buffer
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()
303 /* if transmit error, throw frame away by */ in n_hdlc_send_frames()
306 actual = tbuf->count; in n_hdlc_send_frames()
308 if (actual == tbuf->count) { in n_hdlc_send_frames()
309 pr_debug("frame %p completed\n", tbuf); in n_hdlc_send_frames()
311 /* free current transmit buffer */ 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()
317 /* get next pending transmit buffer */ in n_hdlc_send_frames()
318 tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list); in n_hdlc_send_frames()
320 pr_debug("frame %p pending\n", tbuf); in n_hdlc_send_frames()
323 * the buffer was not accepted by driver, 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
378 * interpreted as one HDLC frame.
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()
399 /* get a free HDLC buffer */ in n_hdlc_tty_receive()
400 buf = n_hdlc_buf_get(&n_hdlc->rx_free_buf_list); in n_hdlc_tty_receive()
404 * buffer unless the maximum count has been reached in n_hdlc_tty_receive()
406 if (n_hdlc->rx_buf_list.count < MAX_RX_BUF_COUNT) in n_hdlc_tty_receive()
416 /* copy received data to HDLC buffer */ 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()
420 /* add HDLC buffer to list of received frames */ 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)
434 * @buf: pointer to returned data buffer
435 * @nr: size of returned data buffer
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
527 * @data: pointer to transmit data (one frame)
528 * @count: size of transmit frame in bytes
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()
545 /* verify frame size */ 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()
577 /* Retrieve the user's buffer */ 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()
617 /* in next available frame (if any) */ 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()
632 /* add size of next output frame in queue */ 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()
707 pr_debug("%s(), kmalloc() failed for %s buffer %u\n", in n_hdlc_alloc_buf()
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
749 * @buf_list: pointer to the buffer list
750 * @buf: pointer to the buffer
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
767 * @buf_list: pointer to buffer list
768 * @buf: pointer to buffer
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
785 * @buf_list: pointer to HDLC buffer list
787 * Remove and return an HDLC buffer from the head of the specified HDLC buffer
789 * Returns a pointer to HDLC buffer if available, otherwise %NULL.
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()