Skip to content

Commit be10eb7

Browse files
Paul Fulghumtorvalds
authored andcommitted
tty: n_hdlc add buffer flushing
Add flush_buffer tty callback to flush rx buffers. Add TCFLSH ioctl processing to flush tx buffers. Increase default tx buffers from 1 to 3. Remove unneeded flush_buffer call in open callback. Remove vendor specific CVS version string. Signed-off-by: Paul Fulghum <[email protected]> Signed-off-by: Alan Cox <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 90ceb96 commit be10eb7

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

drivers/char/n_hdlc.c

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* Paul Mackerras <[email protected]>
1111
*
1212
* Original release 01/11/99
13-
* $Id: n_hdlc.c,v 4.8 2003/05/06 21:18:51 paulkf Exp $
1413
*
1514
* This code is released under the GNU General Public License (GPL)
1615
*
@@ -79,7 +78,6 @@
7978
*/
8079

8180
#define HDLC_MAGIC 0x239e
82-
#define HDLC_VERSION "$Revision: 4.8 $"
8381

8482
#include <linux/module.h>
8583
#include <linux/init.h>
@@ -114,7 +112,7 @@
114112
#define MAX_HDLC_FRAME_SIZE 65535
115113
#define DEFAULT_RX_BUF_COUNT 10
116114
#define MAX_RX_BUF_COUNT 60
117-
#define DEFAULT_TX_BUF_COUNT 1
115+
#define DEFAULT_TX_BUF_COUNT 3
118116

119117
struct n_hdlc_buf {
120118
struct n_hdlc_buf *link;
@@ -199,6 +197,31 @@ static void n_hdlc_tty_wakeup(struct tty_struct *tty);
199197
#define tty2n_hdlc(tty) ((struct n_hdlc *) ((tty)->disc_data))
200198
#define n_hdlc2tty(n_hdlc) ((n_hdlc)->tty)
201199

200+
static void flush_rx_queue(struct tty_struct *tty)
201+
{
202+
struct n_hdlc *n_hdlc = tty2n_hdlc(tty);
203+
struct n_hdlc_buf *buf;
204+
205+
while ((buf = n_hdlc_buf_get(&n_hdlc->rx_buf_list)))
206+
n_hdlc_buf_put(&n_hdlc->rx_free_buf_list, buf);
207+
}
208+
209+
static void flush_tx_queue(struct tty_struct *tty)
210+
{
211+
struct n_hdlc *n_hdlc = tty2n_hdlc(tty);
212+
struct n_hdlc_buf *buf;
213+
unsigned long flags;
214+
215+
while ((buf = n_hdlc_buf_get(&n_hdlc->tx_buf_list)))
216+
n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, buf);
217+
spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags);
218+
if (n_hdlc->tbuf) {
219+
n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, n_hdlc->tbuf);
220+
n_hdlc->tbuf = NULL;
221+
}
222+
spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags);
223+
}
224+
202225
static struct tty_ldisc_ops n_hdlc_ldisc = {
203226
.owner = THIS_MODULE,
204227
.magic = TTY_LDISC_MAGIC,
@@ -211,6 +234,7 @@ static struct tty_ldisc_ops n_hdlc_ldisc = {
211234
.poll = n_hdlc_tty_poll,
212235
.receive_buf = n_hdlc_tty_receive,
213236
.write_wakeup = n_hdlc_tty_wakeup,
237+
.flush_buffer = flush_rx_queue,
214238
};
215239

216240
/**
@@ -341,10 +365,7 @@ static int n_hdlc_tty_open (struct tty_struct *tty)
341365
set_bit(TTY_NO_WRITE_SPLIT,&tty->flags);
342366
#endif
343367

344-
/* Flush any pending characters in the driver and discipline. */
345-
if (tty->ldisc->ops->flush_buffer)
346-
tty->ldisc->ops->flush_buffer(tty);
347-
368+
/* flush receive data from driver */
348369
tty_driver_flush_buffer(tty);
349370

350371
if (debuglevel >= DEBUG_LEVEL_INFO)
@@ -763,6 +784,14 @@ static int n_hdlc_tty_ioctl(struct tty_struct *tty, struct file *file,
763784
error = put_user(count, (int __user *)arg);
764785
break;
765786

787+
case TCFLSH:
788+
switch (arg) {
789+
case TCIOFLUSH:
790+
case TCOFLUSH:
791+
flush_tx_queue(tty);
792+
}
793+
/* fall through to default */
794+
766795
default:
767796
error = n_tty_ioctl_helper(tty, file, cmd, arg);
768797
break;
@@ -919,8 +948,7 @@ static struct n_hdlc_buf* n_hdlc_buf_get(struct n_hdlc_buf_list *list)
919948
} /* end of n_hdlc_buf_get() */
920949

921950
static char hdlc_banner[] __initdata =
922-
KERN_INFO "HDLC line discipline: version " HDLC_VERSION
923-
", maxframe=%u\n";
951+
KERN_INFO "HDLC line discipline maxframe=%u\n";
924952
static char hdlc_register_ok[] __initdata =
925953
KERN_INFO "N_HDLC line discipline registered.\n";
926954
static char hdlc_register_fail[] __initdata =

0 commit comments

Comments
 (0)