10
10
* Paul Mackerras <[email protected] >
11
11
*
12
12
* Original release 01/11/99
13
- * $Id: n_hdlc.c,v 4.8 2003/05/06 21:18:51 paulkf Exp $
14
13
*
15
14
* This code is released under the GNU General Public License (GPL)
16
15
*
79
78
*/
80
79
81
80
#define HDLC_MAGIC 0x239e
82
- #define HDLC_VERSION "$Revision: 4.8 $"
83
81
84
82
#include <linux/module.h>
85
83
#include <linux/init.h>
114
112
#define MAX_HDLC_FRAME_SIZE 65535
115
113
#define DEFAULT_RX_BUF_COUNT 10
116
114
#define MAX_RX_BUF_COUNT 60
117
- #define DEFAULT_TX_BUF_COUNT 1
115
+ #define DEFAULT_TX_BUF_COUNT 3
118
116
119
117
struct n_hdlc_buf {
120
118
struct n_hdlc_buf * link ;
@@ -199,6 +197,31 @@ static void n_hdlc_tty_wakeup(struct tty_struct *tty);
199
197
#define tty2n_hdlc (tty ) ((struct n_hdlc *) ((tty)->disc_data))
200
198
#define n_hdlc2tty (n_hdlc ) ((n_hdlc)->tty)
201
199
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
+
202
225
static struct tty_ldisc_ops n_hdlc_ldisc = {
203
226
.owner = THIS_MODULE ,
204
227
.magic = TTY_LDISC_MAGIC ,
@@ -211,6 +234,7 @@ static struct tty_ldisc_ops n_hdlc_ldisc = {
211
234
.poll = n_hdlc_tty_poll ,
212
235
.receive_buf = n_hdlc_tty_receive ,
213
236
.write_wakeup = n_hdlc_tty_wakeup ,
237
+ .flush_buffer = flush_rx_queue ,
214
238
};
215
239
216
240
/**
@@ -341,10 +365,7 @@ static int n_hdlc_tty_open (struct tty_struct *tty)
341
365
set_bit (TTY_NO_WRITE_SPLIT ,& tty -> flags );
342
366
#endif
343
367
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 */
348
369
tty_driver_flush_buffer (tty );
349
370
350
371
if (debuglevel >= DEBUG_LEVEL_INFO )
@@ -763,6 +784,14 @@ static int n_hdlc_tty_ioctl(struct tty_struct *tty, struct file *file,
763
784
error = put_user (count , (int __user * )arg );
764
785
break ;
765
786
787
+ case TCFLSH :
788
+ switch (arg ) {
789
+ case TCIOFLUSH :
790
+ case TCOFLUSH :
791
+ flush_tx_queue (tty );
792
+ }
793
+ /* fall through to default */
794
+
766
795
default :
767
796
error = n_tty_ioctl_helper (tty , file , cmd , arg );
768
797
break ;
@@ -919,8 +948,7 @@ static struct n_hdlc_buf* n_hdlc_buf_get(struct n_hdlc_buf_list *list)
919
948
} /* end of n_hdlc_buf_get() */
920
949
921
950
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" ;
924
952
static char hdlc_register_ok [] __initdata =
925
953
KERN_INFO "N_HDLC line discipline registered.\n" ;
926
954
static char hdlc_register_fail [] __initdata =
0 commit comments