tty/serial: Process XON/XOFF robustly
Subsystems (15)
v3 cover tty/serial: Process XON/XOFF robustly
XON/XOFF are used for software flow-control on serial lines. XON and XOFF appear as characters within the stream but should be processed as soon as possible.
The characters received by the UART drivers are in intermediate buffers until TTY receives them. In the case where the TTY is not read from, the characters may get stuck into those intermediate buffers until user-space reads from the TTY. Among the characters stuck in the buffers, can also be those XON/XOFF flow control characters. A stuck flow-control character is not very useful.
This patch series addresses the issue by checking if TTY is slow to process characters, that is, eats less than the given amount. If TTY is slow, a lookahead is invoked for the characters that remain in the intermediate buffer(s).
Then at a later time, receive_buf needs to ensure the flow-control actions are not retaken when those same characters get pushed to TTY. The necessary guards for that are added by the second patch of the series.
This patch series fixes an issue but I'm not able to pinpoint to a specific commit id to provide a Fixes tag. The last patch of the series is not needed for minimal fix (and has a small chance of regression too), thus that patch shouldn't be sent to stable.
v1 -> v2:
- Add flow ctrl char funcs in separate change & rework logic a bit. I believe it's now cleaner than it would have been with the suggestions during v1 review, please recheck.
- Renamed n_tty_lookahead_special to n_tty_lookahead_flow_ctrl
- Fixed logic for START_CHAR == STOP_CHAR case
- Use unsigned int for lookahead_count in receive_buf call chain
- Use consistent types in lookahead call chain
- Improved indentation & line splits for function params
- Corrected tty_ldisc.h comments documenting tty_ldisc_ops
- Tweaked comment format
v2 -> v3:
- Split preparatory patch moving/rearranging code to two
- Fix closing path giving change for ... || xx to execute instead of skipping the flow-control char
- Use the same flow-control char function on closing path (just a cleanup, non-fix as last patch, a small change of regression exists)
Ilpo Järvinen (5):
tty: Add function for handling flow control chars
tty: Simplify receive flow control char logic
tty: Add lookahead param to receive_buf
tty: Implement lookahead to process XON/XOFF timely
tty: Use flow-control char function on closing path
drivers/accessibility/speakup/spk_ttyio.c | 2 +- drivers/bluetooth/hci_ldisc.c | 2 +- drivers/char/pcmcia/synclink_cs.c | 2 +- drivers/input/serio/serport.c | 4 +- drivers/isdn/capi/capi.c | 2 +- drivers/misc/ti-st/st_core.c | 2 +- drivers/net/caif/caif_serial.c | 4 +- drivers/net/can/slcan.c | 2 +- drivers/net/hamradio/6pack.c | 4 +- drivers/net/hamradio/mkiss.c | 2 +- drivers/net/mctp/mctp-serial.c | 2 +- drivers/net/ppp/ppp_async.c | 2 +- drivers/net/ppp/ppp_synctty.c | 2 +- drivers/net/slip/slip.c | 2 +- drivers/tty/n_gsm.c | 2 +- drivers/tty/n_hdlc.c | 2 +- drivers/tty/n_null.c | 2 +- drivers/tty/n_tty.c | 102 +++++++++++++++------- drivers/tty/serdev/serdev-ttyport.c | 3 +- drivers/tty/synclink_gt.c | 2 +- drivers/tty/tty_buffer.c | 67 +++++++++++--- drivers/tty/tty_io.c | 2 +- drivers/tty/tty_port.c | 26 +++++- drivers/tty/vt/selection.c | 2 +- include/linux/tty_buffer.h | 1 + include/linux/tty_flip.h | 2 +- include/linux/tty_ldisc.h | 31 +++++-- include/linux/tty_port.h | 5 +- net/nfc/nci/uart.c | 2 +- sound/soc/codecs/cx20442.c | 2 +- sound/soc/ti/ams-delta.c | 2 +- 31 files changed, 205 insertions(+), 84 deletions(-)
Signature · 1 line
2.30.2
PATCH v3 1/5 tty: Add function for handling flow control chars
Move receive path flow control character handling to own function.
No functional changes.
--- drivers/tty/n_tty.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-)
drivers/tty/n_tty.c +18 -11
@@ -1220,21 +1220,28 @@ n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c)process_echoes (tty); } +/* Returns true if c is consumed as flow-control character */ +static bool n_tty_receive_char_flow_ctrl (struct tty_struct *tty,unsigned char c) +{ +if (c ==START_CHAR (tty)) { +start_tty (tty); +process_echoes (tty); +return true; + } +if (c ==STOP_CHAR (tty)) { +stop_tty (tty); +return true; + } + +return false; +} +static void n_tty_receive_char_special (struct tty_struct *tty,unsigned char c) {struct n_tty_data *ldata = tty->disc_data; -if (I_IXON (tty)) { -if (c ==START_CHAR (tty)) { -start_tty (tty); -process_echoes (tty); -return ; - } -if (c ==STOP_CHAR (tty)) { -stop_tty (tty); -return ; - } - } +if (I_IXON (tty) &&n_tty_receive_char_flow_ctrl (tty, c)) +return ;if (L_ISIG (tty)) {if (c ==INTR_CHAR (tty)) {
Signature · 1 line
2.30.2
PATCH v3 2/5 tty: Simplify receive flow control char logic
In reply to Ilpo JärvinenAdd a helper to check if the character is a flow control one. Reorder return places, add else for the case where START_CHAR and STOP_CHAR are the same, w/o else both would match.
This seems cleanest approach once skipping due to lookahead is added by the next patch. Its downside is the duplicated START_CHAR and STOP_CHAR checks.
--- drivers/tty/n_tty.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/tty/n_tty.c +10 -5
@@ -1220,20 +1220,25 @@ n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c)process_echoes (tty); } +static bool n_tty_is_char_flow_ctrl (struct tty_struct *tty,unsigned char c) +{ +return c ==START_CHAR (tty) || c ==STOP_CHAR (tty); +} +/* Returns true if c is consumed as flow-control character */ static bool n_tty_receive_char_flow_ctrl (struct tty_struct *tty,unsigned char c) { +if (!n_tty_is_char_flow_ctrl (tty, c)) +return false; +if (c ==START_CHAR (tty)) {start_tty (tty);process_echoes (tty); -return true; - } -if (c ==STOP_CHAR (tty)) { + }else if (c ==STOP_CHAR (tty)) {stop_tty (tty); -return true; } -return false; +return true; }static void n_tty_receive_char_special (struct tty_struct *tty,unsigned char c)
Signature · 1 line
2.30.2
Greg KH
maintainerRe: [PATCH v3 2/5] tty: Simplify receive flow control char logic
Quoted 29 lines · Ilpo Järvinen
Add a helper to check if the character is a flow control one. Reorder return places, add else for the case where
START_CHARandSTOP_CHARare the same, w/o else both would match.This seems cleanest approach once skipping due to lookahead is added by the next patch. Its downside is the duplicated
START_CHARandSTOP_CHARchecks.Signed-off-by Ilpo Järvinen <[email protected]>--- drivers/tty/n_tty.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)drivers/tty/n_tty.c +5
-0@@ -1220,20 +1220,25 @@ n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c)process_echoes (tty); } +static bool n_tty_is_char_flow_ctrl (struct tty_struct *tty,unsigned char c) +{ +return c ==START_CHAR (tty) || c ==STOP_CHAR (tty); +} +/* Returns true if c is consumed as flow-control character */ static bool n_tty_receive_char_flow_ctrl (struct tty_struct *tty,unsigned char c) {
drivers/tty/n_tty.c n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c) · line 1237
Quoted 10 lines
drivers/tty/n_tty.c +4
-3+if (!n_tty_is_char_flow_ctrl (tty, c)) +return false; +if (c ==START_CHAR (tty)) {start_tty (tty);process_echoes (tty); -return true; - } -if (c ==STOP_CHAR (tty)) { + }else if (c ==STOP_CHAR (tty)) {
The else is always true here now so why check it again?
Just return in the above if statement and then call stop_tty().
thanks,
greg k-h
PATCH v3 3/5 tty: Add lookahead param to receive_buf
In reply to Ilpo JärvinenAfter lookahead for XON/XOFF characters is added by the next patch, the receive side needs to ensure the flow-control actions are not retaken later on when those same characters get received by TTY.
Thus, pass lookahead count to receive_buf and skip flow-control character actions if already taken for the character in question. Lookahead count will become live after the next patch.
The logic in n_tty_receive_char_closing is bit tricky. The lookahead_done checks cannot be combined with the main conditions because doing so would give chance for the part after || in the else if condition to execute when lookahead done is set (rather than just skipping the flow-control character like it should).
--- drivers/accessibility/speakup/spk_ttyio.c | 2 +- drivers/bluetooth/hci_ldisc.c | 2 +- drivers/char/pcmcia/synclink_cs.c | 2 +- drivers/input/serio/serport.c | 4 +- drivers/isdn/capi/capi.c | 2 +- drivers/misc/ti-st/st_core.c | 2 +- drivers/net/caif/caif_serial.c | 4 +- drivers/net/can/slcan.c | 2 +- drivers/net/hamradio/6pack.c | 4 +- drivers/net/hamradio/mkiss.c | 2 +- drivers/net/mctp/mctp-serial.c | 2 +- drivers/net/ppp/ppp_async.c | 2 +- drivers/net/ppp/ppp_synctty.c | 2 +- drivers/net/slip/slip.c | 2 +- drivers/tty/n_gsm.c | 2 +- drivers/tty/n_hdlc.c | 2 +- drivers/tty/n_null.c | 2 +- drivers/tty/n_tty.c | 53 ++++++++++++++--------- drivers/tty/serdev/serdev-ttyport.c | 3 +- drivers/tty/synclink_gt.c | 2 +- drivers/tty/tty_buffer.c | 8 ++-- drivers/tty/tty_io.c | 2 +- drivers/tty/tty_port.c | 5 ++- drivers/tty/vt/selection.c | 2 +- include/linux/tty_flip.h | 2 +- include/linux/tty_ldisc.h | 20 ++++++--- include/linux/tty_port.h | 3 +- net/nfc/nci/uart.c | 2 +- sound/soc/codecs/cx20442.c | 2 +- sound/soc/ti/ams-delta.c | 2 +- 30 files changed, 83 insertions(+), 63 deletions(-)
drivers/accessibility/speakup/spk_ttyio.c +1 -1
@@ -73,7 +73,7 @@ static void spk_ttyio_ldisc_close(struct tty_struct *tty)static int spk_ttyio_receive_buf2 (struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count) +const char *fp,int count,unsigned int lookahead_count) {struct spk_ldisc_data *ldisc_data = tty->disc_data;struct spk_synth *synth = ldisc_data->synth;
drivers/bluetooth/hci_ldisc.c +1 -1
@@ -596,7 +596,7 @@ static void hci_uart_tty_wakeup(struct tty_struct *tty)* Return Value: None */ static void hci_uart_tty_receive (struct tty_struct *tty,const u8 *data, -const char *flags,int count) +const char *flags,int count,unsigned int lookahead_count) {struct hci_uart *hu = tty->disc_data;
drivers/char/pcmcia/synclink_cs.c +1 -1
@@ -501,7 +501,7 @@ static void ldisc_receive_buf(struct tty_struct *tty, ld =tty_ldisc_ref (tty);if (ld) {if (ld->ops->receive_buf) - ld->ops->receive_buf (tty, data, flags, count); + ld->ops->receive_buf (tty, data, flags, count,0 );tty_ldisc_deref (ld); } }
drivers/input/serio/serport.c +2 -2
@@ -114,8 +114,8 @@ static void serport_ldisc_close(struct tty_struct *tty)* 'interrupt' routine. */ -static void serport_ldisc_receive (struct tty_struct *tty, -const unsigned char *cp,const char *fp,int count) +static void serport_ldisc_receive (struct tty_struct *tty,const unsigned char *cp, +const char *fp,int count,unsigned int lookahead_count) {struct serport *serport = (struct serport *) tty->disc_data;unsigned long flags;
drivers/isdn/capi/capi.c +1 -1
@@ -454,7 +454,7 @@ static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb)skb_pull (skb,CAPIMSG_LEN (skb->data));pr_debug ("capi: DATA_B3_RESP %u len=%d => ldisc\n" , datahandle, skb->len); - ld->ops->receive_buf (tty, skb->data,NULL , skb->len); + ld->ops->receive_buf (tty, skb->data,NULL , skb->len,0 ); }else {printk (KERN_ERR "capi: send DATA_B3_RESP failed=%x\n" , errcode);
drivers/misc/ti-st/st_core.c +1 -1
@@ -797,7 +797,7 @@ static void st_tty_close(struct tty_struct *tty) }static void st_tty_receive (struct tty_struct *tty,const unsigned char *data, -const char *tty_flags,int count) +const char *tty_flags,int count,unsigned int lookahead_count) {#ifdef VERBOSE print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE,
drivers/net/caif/caif_serial.c +2 -2
@@ -159,7 +159,7 @@ static inline void debugfs_tx(struct ser_device *ser, const u8 *data, int size)#endif static void ldisc_receive (struct tty_struct *tty,const u8 *data, -const char *flags,int count) +const char *flags,int count,unsigned int lookahead_count) {struct sk_buff *skb =NULL ;struct ser_device *ser;
@@ -237,7 +237,7 @@ static int handle_tx(struct ser_device *ser)update_tty_status (ser); }else { tty_wr = len; -ldisc_receive (tty, skb->data,NULL , len); +ldisc_receive (tty, skb->data,NULL , len,0 ); } ser->dev->stats.tx_packets++; ser->dev->stats.tx_bytes += tty_wr;
drivers/net/can/slcan.c +1 -1
@@ -471,7 +471,7 @@ static void slc_setup(struct net_device *dev)static void slcan_receive_buf (struct tty_struct *tty,const unsigned char *cp,const char *fp, -int count) +int count,unsigned int lookahead_count) {struct slcan *sl = (struct slcan *) tty->disc_data;
drivers/net/hamradio/6pack.c +2 -2
@@ -426,8 +426,8 @@ static void sixpack_write_wakeup(struct tty_struct *tty)* a block of 6pack data has been received, which can now be decapsulated * and sent on to some IP layer for further processing. */ -static void sixpack_receive_buf (struct tty_struct *tty, -const unsigned char *cp,const char *fp,int count) +static void sixpack_receive_buf (struct tty_struct *tty,const unsigned char *cp, +const char *fp,int count,unsigned int lookahead_count) {struct sixpack *sp;int count1;
drivers/net/hamradio/mkiss.c +1 -1
@@ -875,7 +875,7 @@ static int mkiss_ioctl(struct tty_struct *tty, unsigned int cmd,* and sent on to the AX.25 layer for further processing. */ static void mkiss_receive_buf (struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count) +const char *fp,int count,unsigned int lookahead_count) {struct mkiss *ax =mkiss_get (tty);
drivers/net/mctp/mctp-serial.c +1 -1
@@ -390,7 +390,7 @@ static void mctp_serial_push(struct mctp_serial *dev, unsigned char c)static void mctp_serial_tty_receive_buf (struct tty_struct *tty,const unsigned char *c, -const char *f,int len) +const char *f,int len,unsigned int lookahead_count) {struct mctp_serial *dev = tty->disc_data;int i;
drivers/net/ppp/ppp_async.c +1 -1
@@ -338,7 +338,7 @@ ppp_asynctty_poll(struct tty_struct *tty, struct file *file, poll_table *wait)/* May sleep, don't call from interrupt level or with interrupts disabled */ static void ppp_asynctty_receive (struct tty_struct *tty,const unsigned char *buf, -const char *cflags,int count) +const char *cflags,int count,unsigned int lookahead_count) {struct asyncppp *ap =ap_get (tty);unsigned long flags;
drivers/net/ppp/ppp_synctty.c +1 -1
@@ -331,7 +331,7 @@ ppp_sync_poll(struct tty_struct *tty, struct file *file, poll_table *wait)/* May sleep, don't call from interrupt level or with interrupts disabled */ static void ppp_sync_receive (struct tty_struct *tty,const unsigned char *buf, -const char *cflags,int count) +const char *cflags,int count,unsigned int lookahead_count) {struct syncppp *ap =sp_get (tty);unsigned long flags;
drivers/net/slip/slip.c +1 -1
@@ -686,7 +686,7 @@ static void sl_setup(struct net_device *dev)*/ static void slip_receive_buf (struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count) +const char *fp,int count,unsigned int lookahead_count) {struct slip *sl = tty->disc_data;
drivers/tty/n_gsm.c +1 -1
@@ -2500,7 +2500,7 @@ static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) }static void gsmld_receive_buf (struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count) +const char *fp,int count,unsigned int lookahead_count) {struct gsm_mux *gsm = tty->disc_data;char flags =TTY_NORMAL ;
drivers/tty/n_hdlc.c +1 -1
@@ -379,7 +379,7 @@ static void n_hdlc_tty_wakeup(struct tty_struct *tty)* interpreted as one HDLC frame. */ static void n_hdlc_tty_receive (struct tty_struct *tty,const __u8 *data, -const char *flags,int count) +const char *flags,int count,unsigned int lookahead_count) { registerstruct n_hdlc *n_hdlc = tty->disc_data; registerstruct n_hdlc_buf *buf;
drivers/tty/n_null.c +1 -1
@@ -34,7 +34,7 @@ static ssize_t n_null_write(struct tty_struct *tty, struct file *file,static void n_null_receivebuf (struct tty_struct *tty,const unsigned char *cp,const char *fp, -int cnt) +int cnt,unsigned int lookahead_count) { }
drivers/tty/n_tty.c +32 -21
144 lines not on this page · raw message
drivers/tty/serdev/serdev-ttyport.c +2 -1
@@ -23,7 +23,8 @@ struct serport {*/ static int ttyport_receive_buf (struct tty_port *port,const unsigned char *cp, -const unsigned char *fp,size_t count) +const unsigned char *fp,size_t count, +unsigned int lookahead_count) {struct serdev_controller *ctrl = port->client_data;struct serport *serport =serdev_controller_get_drvdata (ctrl);
drivers/tty/synclink_gt.c +1 -1
@@ -582,7 +582,7 @@ static void ldisc_receive_buf(struct tty_struct *tty, ld =tty_ldisc_ref (tty);if (ld) {if (ld->ops->receive_buf) - ld->ops->receive_buf (tty, data, flags, count); + ld->ops->receive_buf (tty, data, flags, count,0 );tty_ldisc_deref (ld); } }
drivers/tty/tty_buffer.c +4 -4
@@ -445,14 +445,14 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);* Returns: the number of bytes processed. */ int tty_ldisc_receive_buf (struct tty_ldisc *ld,const unsigned char *p, -const char *f,int count) +const char *f,int count,unsigned int lookahead_count) {if (ld->ops->receive_buf2) - count = ld->ops->receive_buf2 (ld->tty, p, f, count); + count = ld->ops->receive_buf2 (ld->tty, p, f, count, lookahead_count);else { count =min_t (int, count, ld->tty->receive_room);if (count && ld->ops->receive_buf) - ld->ops->receive_buf (ld->tty, p, f, count); + ld->ops->receive_buf (ld->tty, p, f, count, lookahead_count); }return count; }
@@ -468,7 +468,7 @@ receive_buf(struct tty_port *port, struct tty_buffer *head, int count)if (~head->flags &TTYB_NORMAL ) f =flag_buf_ptr (head, head->read); - n = port->client_ops->receive_buf (port, p, f, count); + n = port->client_ops->receive_buf (port, p, f, count,0 );if (n >0 )memset (p,0 , n);return n;
drivers/tty/tty_io.c +1 -1
@@ -2290,7 +2290,7 @@ static int tiocsti(struct tty_struct *tty, char __user *p)return -EIO ;tty_buffer_lock_exclusive (tty->port);if (ld->ops->receive_buf) - ld->ops->receive_buf (tty, &ch, &mbz,1 ); + ld->ops->receive_buf (tty, &ch, &mbz,1 ,0 );tty_buffer_unlock_exclusive (tty->port);tty_ldisc_deref (ld);return 0 ;
drivers/tty/tty_port.c +3 -2
@@ -22,7 +22,8 @@static int tty_port_default_receive_buf (struct tty_port *port,const unsigned char *p, -const unsigned char *f,size_t count) +const unsigned char *f,size_t count, +unsigned int lookahead_count) {int ret;struct tty_struct *tty;
@@ -36,7 +37,7 @@ static int tty_port_default_receive_buf(struct tty_port *port,if (!disc)return 0 ; - ret =tty_ldisc_receive_buf (disc, p, (char *)f, count); + ret =tty_ldisc_receive_buf (disc, p, (char *)f, count, lookahead_count);tty_ldisc_deref (disc);
drivers/tty/vt/selection.c +1 -1
@@ -406,7 +406,7 @@ int paste_selection(struct tty_struct *tty)__set_current_state (TASK_RUNNING ); count = vc_sel.buf_len - pasted; count =tty_ldisc_receive_buf (ld, vc_sel.buffer + pasted,NULL , - count); + count,0 ); pasted += count; }mutex_unlock (&vc_sel.lock);
include/linux/tty_flip.h +1 -1
@@ -42,7 +42,7 @@ static inline int tty_insert_flip_string(struct tty_port *port, }int tty_ldisc_receive_buf (struct tty_ldisc *ld,const unsigned char *p, -const char *f,int count); +const char *f,int count,unsigned int lookahead_count);void tty_buffer_lock_exclusive (struct tty_port *port);void tty_buffer_unlock_exclusive (struct tty_port *port);
include/linux/tty_ldisc.h +13 -7
@@ -152,14 +152,17 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,* Can sleep. * * @receive_buf: [DRV] ``void ()(struct tty_struct *tty, -* const unsigned char *cp, const char *fp, int count)`` +* const unsigned char *cp, const char *fp, int count, +* unsigned int lookahead_count)`` * * This function is called by the low-level tty driver to send characters * received by the hardware to the line discpline for processing. @cp is * a pointer to the buffer of input character received by the device. @fp * is a pointer to an array of flag bytes which indicate whether a * character was received with a parity error, etc. @fp may be %NULL to -* indicate all data received is %TTY_NORMAL. +* indicate all data received is %TTY_NORMAL. The number of characters is +* indicated with @count and characters for which lookahead was already +* performed with @lookahead_count. * * @write_wakeup: [DRV] ``void ()(struct tty_struct *tty)`` *
@@ -176,15 +179,18 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,* exclusively by the %N_PPS (Pulse-Per-Second) line discipline. * * @receive_buf2: [DRV] ``int ()(struct tty_struct *tty, -* const unsigned char *cp, const char *fp, int count)`` +* const unsigned char *cp, const char *fp, int count, +* unsigned int lookahead_count)`` * * This function is called by the low-level tty driver to send characters * received by the hardware to the line discpline for processing. @cp is a * pointer to the buffer of input character received by the device. @fp * is a pointer to an array of flag bytes which indicate whether a * character was received with a parity error, etc. @fp may be %NULL to -* indicate all data received is %TTY_NORMAL. If assigned, prefer this -* function for automatic flow control. +* indicate all data received is %TTY_NORMAL. The number of characters is +* indicated with @count and characters for which lookahead was already +* performed with @lookahead_count. If assigned, prefer this function for +* automatic flow control. * * @owner: module containting this ldisc (for reference counting) *
@@ -224,11 +230,11 @@ struct tty_ldisc_ops {* The following routines are called from below. */ void (*receive_buf)(struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count); +const char *fp,int count,unsigned int lookahead_count);void (*write_wakeup)(struct tty_struct *tty);void (*dcd_change)(struct tty_struct *tty,unsigned int status);int (*receive_buf2)(struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count); +const char *fp,int count,unsigned int lookahead_count);struct module *owner; };
include/linux/tty_port.h +2 -1
@@ -39,7 +39,8 @@ struct tty_port_operations { };struct tty_port_client_operations { -int (*receive_buf)(struct tty_port *port,const unsigned char *,const unsigned char *,size_t ); +int (*receive_buf)(struct tty_port *port,const unsigned char *, +const unsigned char *,size_t ,unsigned int lookahead_count);void (*write_wakeup)(struct tty_port *port); };
net/nfc/nci/uart.c +1 -1
@@ -296,7 +296,7 @@ static int nci_uart_default_recv_buf(struct nci_uart *nu, const u8 *data,* Return Value: None */ static void nci_uart_tty_receive (struct tty_struct *tty,const u8 *data, -const char *flags,int count) +const char *flags,int count,unsigned int lookahead_count) {struct nci_uart *nu = (void *)tty->disc_data;
sound/soc/codecs/cx20442.c +1 -1
@@ -259,7 +259,7 @@ static void v253_hangup(struct tty_struct *tty)/* Line discipline .receive_buf() */ static void v253_receive (struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count) +const char *fp,int count,unsigned int lookahead_count) {struct snd_soc_component *component = tty->disc_data;struct cx20442_priv *cx20442;
sound/soc/ti/ams-delta.c +1 -1
@@ -337,7 +337,7 @@ static void cx81801_hangup(struct tty_struct *tty)/* Line discipline .receive_buf() */ static void cx81801_receive (struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count) +const char *fp,int count,unsigned int lookahead_count) {struct snd_soc_component *component = tty->disc_data;const unsigned char *c;
Signature · 1 line
2.30.2
Greg KH
maintainerRe: [PATCH v3 3/5] tty: Add lookahead param to receive_buf
Quoted 2 lines · Ilpo Järvinen
After lookahead for XON/XOFF characters is added by the next patch,
There is no "next" in a series. This commit needs to be justified here, right?
Quoted 8 lines
the receive side needs to ensure the flow-control actions are not retaken later on when those same characters get received by TTY.
Thus, pass lookahead count to
receive_bufand skip flow-control character actions if already taken for the character in question. Lookahead count will become live after the next patch.
You have all 72 columns, please use them.
Quoted 47 lines
The logic in
n_tty_receive_char_closingis bit tricky. Thelookahead_donechecks cannot be combined with the main conditions because doing so would give chance for the part after || in the else if condition to execute when lookahead done is set (rather than just skipping the flow-control character like it should).Signed-off-by Ilpo Järvinen <[email protected]>--- drivers/accessibility/speakup/spk_ttyio.c | 2 +- drivers/bluetooth/hci_ldisc.c | 2 +- drivers/char/pcmcia/synclink_cs.c | 2 +- drivers/input/serio/serport.c | 4 +- drivers/isdn/capi/capi.c | 2 +- drivers/misc/ti-st/st_core.c | 2 +- drivers/net/caif/caif_serial.c | 4 +- drivers/net/can/slcan.c | 2 +- drivers/net/hamradio/6pack.c | 4 +- drivers/net/hamradio/mkiss.c | 2 +- drivers/net/mctp/mctp-serial.c | 2 +- drivers/net/ppp/ppp_async.c | 2 +- drivers/net/ppp/ppp_synctty.c | 2 +- drivers/net/slip/slip.c | 2 +- drivers/tty/n_gsm.c | 2 +- drivers/tty/n_hdlc.c | 2 +- drivers/tty/n_null.c | 2 +- drivers/tty/n_tty.c | 53 ++++++++++++++--------- drivers/tty/serdev/serdev-ttyport.c | 3 +- drivers/tty/synclink_gt.c | 2 +- drivers/tty/tty_buffer.c | 8 ++-- drivers/tty/tty_io.c | 2 +- drivers/tty/tty_port.c | 5 ++- drivers/tty/vt/selection.c | 2 +- include/linux/tty_flip.h | 2 +- include/linux/tty_ldisc.h | 20 ++++++--- include/linux/tty_port.h | 3 +- net/nfc/nci/uart.c | 2 +- sound/soc/codecs/cx20442.c | 2 +- sound/soc/ti/ams-delta.c | 2 +- 30 files changed, 83 insertions(+), 63 deletions(-)drivers/accessibility/speakup/spk_ttyio.c +0
-0
drivers/accessibility/speakup/spk_ttyio.c static void spk_ttyio_ldisc_close(struct tty_struct *tty) · line 76
Quoted 5 lines
drivers/accessibility/speakup/spk_ttyio.c +1
-1@@ -73,7 +73,7 @@ static void spk_ttyio_ldisc_close(struct tty_struct *tty)static int spk_ttyio_receive_buf2 (struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count) +const char *fp,int count,unsigned int lookahead_count)
Ick, adding yet-another-parameter to a function is a mess as it's hard to know what to do with this and what it means just by looking at when it is called.
Quoted 84 lines
drivers/accessibility/speakup/spk_ttyio.c +0
-0{struct spk_ldisc_data *ldisc_data = tty->disc_data;struct spk_synth *synth = ldisc_data->synth;drivers/bluetooth/hci_ldisc.c +1
-1@@ -596,7 +596,7 @@ static void hci_uart_tty_wakeup(struct tty_struct *tty)* Return Value: None */ static void hci_uart_tty_receive (struct tty_struct *tty,const u8 *data, -const char *flags,int count) +const char *flags,int count,unsigned int lookahead_count) {struct hci_uart *hu = tty->disc_data;drivers/char/pcmcia/synclink_cs.c +1
-1@@ -501,7 +501,7 @@ static void ldisc_receive_buf(struct tty_struct *tty, ld =tty_ldisc_ref (tty);if (ld) {if (ld->ops->receive_buf) - ld->ops->receive_buf (tty, data, flags, count); + ld->ops->receive_buf (tty, data, flags, count,0 );tty_ldisc_deref (ld); } }drivers/input/serio/serport.c +2
-2@@ -114,8 +114,8 @@ static void serport_ldisc_close(struct tty_struct *tty)* 'interrupt' routine. */ -static void serport_ldisc_receive (struct tty_struct *tty, -const unsigned char *cp,const char *fp,int count) +static void serport_ldisc_receive (struct tty_struct *tty,const unsigned char *cp, +const char *fp,int count,unsigned int lookahead_count) {struct serport *serport = (struct serport *) tty->disc_data;unsigned long flags;drivers/isdn/capi/capi.c +1
-1@@ -454,7 +454,7 @@ static int handle_recv_skb(struct capiminor *mp, struct sk_buff *skb)skb_pull (skb,CAPIMSG_LEN (skb->data));pr_debug ("capi: DATA_B3_RESP %u len=%d => ldisc\n" , datahandle, skb->len); - ld->ops->receive_buf (tty, skb->data,NULL , skb->len); + ld->ops->receive_buf (tty, skb->data,NULL , skb->len,0 ); }else {printk (KERN_ERR "capi: send DATA_B3_RESP failed=%x\n" , errcode);drivers/misc/ti-st/st_core.c +1
-1@@ -797,7 +797,7 @@ static void st_tty_close(struct tty_struct *tty) }static void st_tty_receive (struct tty_struct *tty,const unsigned char *data, -const char *tty_flags,int count) +const char *tty_flags,int count,unsigned int lookahead_count) {#ifdef VERBOSE print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE,drivers/net/caif/caif_serial.c +1
-1@@ -159,7 +159,7 @@ static inline void debugfs_tx(struct ser_device *ser, const u8 *data, int size)#endif static void ldisc_receive (struct tty_struct *tty,const u8 *data, -const char *flags,int count) +const char *flags,int count,unsigned int lookahead_count) {struct sk_buff *skb =NULL ;struct ser_device *ser;
drivers/net/caif/caif_serial.c static int handle_tx(struct ser_device *ser) · line 240
Quoted 5 lines
drivers/net/caif/caif_serial.c +1
-1@@ -237,7 +237,7 @@ static int handle_tx(struct ser_device *ser)update_tty_status (ser); }else { tty_wr = len; -ldisc_receive (tty, skb->data,NULL , len); +ldisc_receive (tty, skb->data,NULL , len,0 );
See, what does 0 here mean? Who knows? Not a good api :(
Quoted 142 lines
drivers/net/caif/caif_serial.c +0
-0} ser->dev->stats.tx_packets++; ser->dev->stats.tx_bytes += tty_wr;drivers/net/can/slcan.c +1
-1@@ -471,7 +471,7 @@ static void slc_setup(struct net_device *dev)static void slcan_receive_buf (struct tty_struct *tty,const unsigned char *cp,const char *fp, -int count) +int count,unsigned int lookahead_count) {struct slcan *sl = (struct slcan *) tty->disc_data;drivers/net/hamradio/6pack.c +2
-2@@ -426,8 +426,8 @@ static void sixpack_write_wakeup(struct tty_struct *tty)* a block of 6pack data has been received, which can now be decapsulated * and sent on to some IP layer for further processing. */ -static void sixpack_receive_buf (struct tty_struct *tty, -const unsigned char *cp,const char *fp,int count) +static void sixpack_receive_buf (struct tty_struct *tty,const unsigned char *cp, +const char *fp,int count,unsigned int lookahead_count) {struct sixpack *sp;int count1;drivers/net/hamradio/mkiss.c +1
-1@@ -875,7 +875,7 @@ static int mkiss_ioctl(struct tty_struct *tty, unsigned int cmd,* and sent on to the AX.25 layer for further processing. */ static void mkiss_receive_buf (struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count) +const char *fp,int count,unsigned int lookahead_count) {struct mkiss *ax =mkiss_get (tty);drivers/net/mctp/mctp-serial.c +1
-1@@ -390,7 +390,7 @@ static void mctp_serial_push(struct mctp_serial *dev, unsigned char c)static void mctp_serial_tty_receive_buf (struct tty_struct *tty,const unsigned char *c, -const char *f,int len) +const char *f,int len,unsigned int lookahead_count) {struct mctp_serial *dev = tty->disc_data;int i;drivers/net/ppp/ppp_async.c +1
-1@@ -338,7 +338,7 @@ ppp_asynctty_poll(struct tty_struct *tty, struct file *file, poll_table *wait)/* May sleep, don't call from interrupt level or with interrupts disabled */ static void ppp_asynctty_receive (struct tty_struct *tty,const unsigned char *buf, -const char *cflags,int count) +const char *cflags,int count,unsigned int lookahead_count) {struct asyncppp *ap =ap_get (tty);unsigned long flags;drivers/net/ppp/ppp_synctty.c +1
-1@@ -331,7 +331,7 @@ ppp_sync_poll(struct tty_struct *tty, struct file *file, poll_table *wait)/* May sleep, don't call from interrupt level or with interrupts disabled */ static void ppp_sync_receive (struct tty_struct *tty,const unsigned char *buf, -const char *cflags,int count) +const char *cflags,int count,unsigned int lookahead_count) {struct syncppp *ap =sp_get (tty);unsigned long flags;drivers/net/slip/slip.c +1
-1@@ -686,7 +686,7 @@ static void sl_setup(struct net_device *dev)*/ static void slip_receive_buf (struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count) +const char *fp,int count,unsigned int lookahead_count) {struct slip *sl = tty->disc_data;drivers/tty/n_gsm.c +1
-1@@ -2500,7 +2500,7 @@ static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) }static void gsmld_receive_buf (struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count) +const char *fp,int count,unsigned int lookahead_count) {struct gsm_mux *gsm = tty->disc_data;char flags =TTY_NORMAL ;drivers/tty/n_hdlc.c +1
-1@@ -379,7 +379,7 @@ static void n_hdlc_tty_wakeup(struct tty_struct *tty)* interpreted as one HDLC frame. */ static void n_hdlc_tty_receive (struct tty_struct *tty,const __u8 *data, -const char *flags,int count) +const char *flags,int count,unsigned int lookahead_count) { registerstruct n_hdlc *n_hdlc = tty->disc_data; registerstruct n_hdlc_buf *buf;drivers/tty/n_null.c +1
-1@@ -34,7 +34,7 @@ static ssize_t n_null_write(struct tty_struct *tty, struct file *file,static void n_null_receivebuf (struct tty_struct *tty,const unsigned char *cp,const char *fp, -int cnt) +int cnt,unsigned int lookahead_count) { }drivers/tty/n_tty.c +0
-0@@ -1226,11 +1226,15 @@ static bool n_tty_is_char_flow_ctrl(struct tty_struct *tty, unsigned char c) }
drivers/tty/n_tty.c static bool n_tty_is_char_flow_ctrl(struct tty_struct *tty, unsigned char c) · line 1236
Quoted 10 lines
drivers/tty/n_tty.c +4
-1/* Returns true if c is consumed as flow-control character */ -static bool n_tty_receive_char_flow_ctrl (struct tty_struct *tty,unsigned char c) +static bool n_tty_receive_char_flow_ctrl (struct tty_struct *tty,unsigned char c, +bool lookahead_done) {if (!n_tty_is_char_flow_ctrl (tty, c))return false; +if (lookahead_done) +return true;
Why would this function be called if this option was true?
Quoted 20 lines
drivers/tty/n_tty.c +4
-2+if (c ==START_CHAR (tty)) {start_tty (tty);process_echoes (tty);@@ -1241,11 +1245,12 @@ static bool n_tty_receive_char_flow_ctrl(struct tty_struct *tty, unsigned char creturn true; } -static void n_tty_receive_char_special (struct tty_struct *tty,unsigned char c) +static void n_tty_receive_char_special (struct tty_struct *tty,unsigned char c, +bool lookahead_done) {struct n_tty_data *ldata = tty->disc_data; -if (I_IXON (tty) &&n_tty_receive_char_flow_ctrl (tty, c)) +if (I_IXON (tty) &&n_tty_receive_char_flow_ctrl (tty, c, lookahead_done))return ;if (L_ISIG (tty)) {
drivers/tty/n_tty.c static void n_tty_receive_char(struct tty_struct *tty, unsigned char c) · line 1409
Quoted 6 lines
drivers/tty/n_tty.c +2
-1@@ -1400,7 +1405,8 @@ static void n_tty_receive_char(struct tty_struct *tty, unsigned char c)put_tty_queue (c, ldata); } -static void n_tty_receive_char_closing (struct tty_struct *tty,unsigned char c) +static void n_tty_receive_char_closing (struct tty_struct *tty,unsigned char c, +bool lookahead_done)
bool here, yet characters elsewhere? That's messy :(
the overall idea is good, this implementation isn't quite there yet.
I did take the first patch in the series, it made sense.
thanks,
greg k-h
Re: [PATCH v3 3/5] tty: Add lookahead param to receive_buf
Quoted 6 lines · Greg KH
Quoted 6 lines
drivers/accessibility/speakup/spk_ttyio.c +0
-0@@ -73,7 +73,7 @@ static void spk_ttyio_ldisc_close(struct tty_struct *tty)
Quoted 8 lines
drivers/accessibility/speakup/spk_ttyio.c static void spk_ttyio_ldisc_close(struct tty_struct *tty) · line 76
Quoted 4 lines
drivers/accessibility/speakup/spk_ttyio.c +1
-1static int spk_ttyio_receive_buf2 (struct tty_struct *tty,const unsigned char *cp, -const char *fp,int count) +const char *fp,int count,unsigned int lookahead_count)Ick, adding yet-another-parameter to a function is a mess as it's hard to know what to do with this and what it means just by looking at when it is called.
To be honest, I didn't like it either but just couldn't find another way... That is, not until now that you pushed.
I think I can add lookahead_count into n_tty_data, then both layers (n_tty and tty_buffer) that depend on it will indepedently keep track of it rather than passing it through the whole callchain.
Quoted 8 lines
Quoted 8 lines
drivers/accessibility/speakup/spk_ttyio.c +2
-1/* Returns true if c is consumed as flow-control character */ -static bool n_tty_receive_char_flow_ctrl (struct tty_struct *tty,unsigned char c) +static bool n_tty_receive_char_flow_ctrl (struct tty_struct *tty,unsigned char c, +bool lookahead_done) {if (!n_tty_is_char_flow_ctrl (tty, c))return false;
Quoted 4 lines
drivers/accessibility/speakup/spk_ttyio.c
Quoted 2 lines
drivers/accessibility/speakup/spk_ttyio.c +2
-0+if (lookahead_done) +return true;Why would this function be called if this option was true?
Agreed, it makes sense to move the check before call (and then I also don't need to reorganize this function anymore).
Quoted 1 line
the overall idea is good, this implementation isn't quite there yet.
Thanks for taking a look.
Signature · 1 line
i.
Re: [PATCH v3 3/5] tty: Add lookahead param to receive_buf
Quoted 10 lines · Ilpo Järvinen
Quoted 8 lines · Greg KH
Quoted 8 lines
/* Returns true if c is consumed as flow-control character */
drivers/tty/n_tty.c +2
-1-static bool n_tty_receive_char_flow_ctrl (struct tty_struct *tty,unsigned char c) +static bool n_tty_receive_char_flow_ctrl (struct tty_struct *tty,unsigned char c, +bool lookahead_done) {if (!n_tty_is_char_flow_ctrl (tty, c))return false;
Quoted 7 lines
Quoted 4 lines
drivers/tty/n_tty.c static bool n_tty_is_char_flow_ctrl(struct tty_struct *tty, unsigned char c) · line 1236
Quoted 2 lines
drivers/tty/n_tty.c +2
-0+if (lookahead_done) +return true;Why would this function be called if this option was true?
Agreed, it makes sense to move the check before call (and then I also don't need to reorganize this function anymore).
I think I want to renege on this. The reason is that on flow control char, two things must occur:
a) it must not be treated as normal char
b) if not yet processed, flow control actions need to be taken
When the check is inside, return value of n_tty_receive_char_flow_ctrl decides a), and b) is kept internal to n_tty_receive_char_flow_ctrl().
If I more that lookahead_done check into the caller domain, things get IMHO a lot more messy. Effectively, I have three options for the calling domain to chose from:
if (I_IXON(tty)) {
if (!lookahead_done) {
if (n_tty_receive_char_flow_ctrl(tty, c))
return;
} else if (n_tty_is_char_flow_ctrl(tty, c)) {
return;
}
}or
if (I_IXON(tty)) {
if ((!lookahead_done && n_tty_receive_char_flow_ctrl(tty, c)) ||
(lookahead_done && n_tty_is_char_flow_ctrl(tty, c))) {
return;
}vs
if (I_IXON(tty) && n_tty_receive_char_flow_ctrl(tty, c, lookahead_done))
return;I heavily prefer that last option.
Signature · 1 line
i.
Greg KH
maintainerRe: [PATCH v3 3/5] tty: Add lookahead param to receive_buf
Quoted 49 lines · Ilpo Järvinen
Quoted 10 lines · Ilpo Järvinen
Quoted 8 lines · Greg KH
Quoted 8 lines
/* Returns true if c is consumed as flow-control character */
drivers/tty/n_tty.c +2
-1-static bool n_tty_receive_char_flow_ctrl (struct tty_struct *tty,unsigned char c) +static bool n_tty_receive_char_flow_ctrl (struct tty_struct *tty,unsigned char c, +bool lookahead_done) {if (!n_tty_is_char_flow_ctrl (tty, c))return false;Quoted 7 lines
Quoted 4 lines
drivers/tty/n_tty.c static bool n_tty_is_char_flow_ctrl(struct tty_struct *tty, unsigned char c) · line 1236
Quoted 2 lines
drivers/tty/n_tty.c +2
-0+if (lookahead_done) +return true;Why would this function be called if this option was true?
Agreed, it makes sense to move the check before call (and then I also don't need to reorganize this function anymore).
I think I want to renege on this. The reason is that on flow control char, two things must occur:
a) it must not be treated as normal char
b) if not yet processed, flow control actions need to be takenWhen the check is inside, return value of
n_tty_receive_char_flow_ctrldecides a), and b) is kept internal ton_tty_receive_char_flow_ctrl().If I more that
lookahead_donecheck into the caller domain, things get IMHO a lot more messy. Effectively, I have three options for the calling domain to chose from:if (I_IXON(tty)) { if (!lookahead_done) { if (n_tty_receive_char_flow_ctrl(tty, c)) return; } else if (n_tty_is_char_flow_ctrl(tty, c)) { return; } }or
if (I_IXON(tty)) { if ((!lookahead_done && n_tty_receive_char_flow_ctrl(tty, c)) || (lookahead_done && n_tty_is_char_flow_ctrl(tty, c))) { return; }
Quoted 6 lines
vs
if (I_IXON(tty) && n_tty_receive_char_flow_ctrl(tty, c, lookahead_done)) return;I heavily prefer that last option.
Ok, then document the heck out of it please.
greg k-h
PATCH v3 4/5 tty: Implement lookahead to process XON/XOFF timely
In reply to Ilpo JärvinenWhen tty is not read from, XON/XOFF may get stuck into an intermediate buffer. As those characters are there to do software flow-control, it is not very useful. In the case where neither end reads from ttys, the receiving ends might not be able receive the XOFF characters and just keep sending more data to the opposite direction. This problem is almost guaranteed to occur with DMA which sends data in large chunks.
If TTY is slow to process characters, that is, eats less than given amount in receive_buf, invoke lookahead for the rest of the chars to process potential XON/XOFF characters.
The guards necessary for ensuring the XON/XOFF character are processed only once were added by the previous patch. All this patch needs to do on that front is to pass the lookahead count (that can now be non-zero) into port->client_ops->receive_buf().
--- drivers/tty/n_tty.c | 18 +++++++++++ drivers/tty/tty_buffer.c | 61 +++++++++++++++++++++++++++++++------- drivers/tty/tty_port.c | 21 +++++++++++++ include/linux/tty_buffer.h | 1 + include/linux/tty_ldisc.h | 11 +++++++ include/linux/tty_port.h | 2 ++ 6 files changed, 104 insertions(+), 10 deletions(-)
drivers/tty/n_tty.c +18 -0
@@ -1465,6 +1465,23 @@ n_tty_receive_char_lnext(struct tty_struct *tty, unsigned char c, char flag)n_tty_receive_char_flagged (tty, c, flag); } +static void n_tty_lookahead_flow_ctrl (struct tty_struct *tty,const unsigned char *cp, +const unsigned char *fp,unsigned int count) +{ +unsigned char flag =TTY_NORMAL ; + +if (!I_IXON (tty)) +return ; + +while (count--) { +if (fp) + flag = *fp++; +if (likely (flag ==TTY_NORMAL )) +n_tty_receive_char_flow_ctrl (tty, *cp, false); + cp++; + } +} +static void n_tty_receive_buf_real_raw (struct tty_struct *tty,const unsigned char *cp,const char *fp,int count)
@@ -2420,6 +2437,7 @@ static struct tty_ldisc_ops n_tty_ops = { .receive_buf = n_tty_receive_buf, .write_wakeup = n_tty_write_wakeup, .receive_buf2 = n_tty_receive_buf2, + .lookahead_buf = n_tty_lookahead_flow_ctrl, };/**
drivers/tty/tty_buffer.c +51 -10
112 lines not on this page · raw message
drivers/tty/tty_port.c +21 -0
@@ -44,6 +44,26 @@ static int tty_port_default_receive_buf(struct tty_port *port,return ret; } +static void tty_port_default_lookahead_buf (struct tty_port *port,const unsigned char *p, +const unsigned char *f,unsigned int count) +{ +struct tty_struct *tty; +struct tty_ldisc *disc; + + tty =READ_ONCE (port->itty); +if (!tty) +return ; + + disc =tty_ldisc_ref (tty); +if (!disc) +return ; + +if (disc->ops->lookahead_buf) + disc->ops->lookahead_buf (disc->tty, p, f, count); + +tty_ldisc_deref (disc); +} +static void tty_port_default_wakeup (struct tty_port *port) {struct tty_struct *tty =tty_port_tty_get (port);
@@ -56,6 +76,7 @@ static void tty_port_default_wakeup(struct tty_port *port)const struct tty_port_client_operations tty_port_default_client_ops = { .receive_buf = tty_port_default_receive_buf, + .lookahead_buf = tty_port_default_lookahead_buf, .write_wakeup = tty_port_default_wakeup, };EXPORT_SYMBOL_GPL (tty_port_default_client_ops);
include/linux/tty_buffer.h +1 -0
@@ -15,6 +15,7 @@ struct tty_buffer {int used;int size;int commit; +int lookahead;/* Lazy update on recv, can become less than "read" */ int read;int flags;/* Data points here */
include/linux/tty_ldisc.h +11 -0
@@ -192,6 +192,15 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,* performed with @lookahead_count. If assigned, prefer this function for * automatic flow control. * +* @lookahead_buf: [DRV] ``void ()(struct tty_struct *tty, +* const unsigned char *cp, const char *fp, int count) +* +* This function is called by the low-level tty driver for characters +* not eaten by receive_buf or receive_buf2. It is useful for processing +* high-priority characters such as software flow-control characters that +* could otherwise get stuck into the intermediate buffer until tty has +* room to receive them. +* * @owner: module containting this ldisc (for reference counting) * * This structure defines the interface between the tty line discipline
@@ -235,6 +244,8 @@ struct tty_ldisc_ops {void (*dcd_change)(struct tty_struct *tty,unsigned int status);int (*receive_buf2)(struct tty_struct *tty,const unsigned char *cp,const char *fp,int count,unsigned int lookahead_count); +void (*lookahead_buf)(struct tty_struct *tty,const unsigned char *cp, +const unsigned char *fp,unsigned int count);struct module *owner; };
include/linux/tty_port.h +2 -0
@@ -41,6 +41,8 @@ struct tty_port_operations {struct tty_port_client_operations {int (*receive_buf)(struct tty_port *port,const unsigned char *,const unsigned char *,size_t ,unsigned int lookahead_count); +void (*lookahead_buf)(struct tty_port *port,const unsigned char *cp, +const unsigned char *fp,unsigned int count);void (*write_wakeup)(struct tty_port *port); };
Signature · 1 line
2.30.2
PATCH v3 5/5 tty: Use flow-control char function on closing path
In reply to Ilpo JärvinenUse n_tty_receive_char_flow_ctrl also on the closing path. This makes the code cleaner and consistent.
However, there a small change of regression!
The earlier closing path has a small difference compared with the normal receive path. If START_CHAR and STOP_CHAR are equal, their precedence is different depending on which path a character is processed. I don't know whether this difference was intentional or not, and if equal START_CHAR and STOP_CHAR is actually used anywhere. But it feels not so useful corner case.
While this change would logically belong to those earlier changes, having a separate patch for this is useful. If this regresses, bisect can pinpoint this change rather than the large patch. Also, this change is not necessary to minimal fix for the issue addressed in the previous patch.
--- drivers/tty/n_tty.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/tty/n_tty.c +4 -9
@@ -1414,15 +1414,10 @@ static void n_tty_receive_char_closing(struct tty_struct *tty, unsigned char c, c =tolower (c);if (I_IXON (tty)) { -if (c ==STOP_CHAR (tty)) { -if (!lookahead_done) -stop_tty (tty); - }else if (c ==START_CHAR (tty) && lookahead_done) { -return ; - }else if (c ==START_CHAR (tty) || - (tty->flow.stopped && !tty->flow.tco_stopped &&I_IXANY (tty) && - c !=INTR_CHAR (tty) && c !=QUIT_CHAR (tty) && - c !=SUSP_CHAR (tty))) { +if (!n_tty_receive_char_flow_ctrl (tty, c, lookahead_done) && + tty->flow.stopped && !tty->flow.tco_stopped &&I_IXANY (tty) && + c !=INTR_CHAR (tty) && c !=QUIT_CHAR (tty) && + c !=SUSP_CHAR (tty)) {start_tty (tty);process_echoes (tty); }
Signature · 1 line
2.30.2
Re: [PATCH v3 5/5] tty: Use flow-control char function on closing path
Quoted 12 lines · Ilpo Järvinen
Use
n_tty_receive_char_flow_ctrlalso on the closing path. This makes the code cleaner and consistent.However, there a small change of regression!
The earlier closing path has a small difference compared with the normal receive path. If
START_CHARandSTOP_CHARare equal, their precedence is different depending on which path a character is processed. I don't know whether this difference was intentional or not, and if equalSTART_CHARandSTOP_CHARis actually used anywhere. But it feels not so useful corner case.
Quoted 5 lines
While this change would logically belong to those earlier changes, having a separate patch for this is useful. If this regresses, bisect can pinpoint this change rather than the large patch. Also, this change is not necessary to minimal fix for the issue addressed in the previous patch.
This is nice, if it flies!
FWIW,
Quoted 32 lines
Signed-off-by Ilpo Järvinen <[email protected]>--- drivers/tty/n_tty.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)drivers/tty/n_tty.c +4
-9@@ -1414,15 +1414,10 @@ static void n_tty_receive_char_closing(struct tty_struct *tty, unsigned char c, c =tolower (c);if (I_IXON (tty)) { -if (c ==STOP_CHAR (tty)) { -if (!lookahead_done) -stop_tty (tty); - }else if (c ==START_CHAR (tty) && lookahead_done) { -return ; - }else if (c ==START_CHAR (tty) || - (tty->flow.stopped && !tty->flow.tco_stopped &&I_IXANY (tty) && - c !=INTR_CHAR (tty) && c !=QUIT_CHAR (tty) && - c !=SUSP_CHAR (tty))) { +if (!n_tty_receive_char_flow_ctrl (tty, c, lookahead_done) && + tty->flow.stopped && !tty->flow.tco_stopped &&I_IXANY (tty) && + c !=INTR_CHAR (tty) && c !=QUIT_CHAR (tty) && + c !=SUSP_CHAR (tty)) {start_tty (tty);process_echoes (tty); }Signature · 1 line
2.30.2
Signature · 2 lines
With Best Regards, Andy Shevchenko