TTY improve n_gsm support
v2 cover TTY improve n_gsm support
Hello,
This series is the second version of patch improving n_gms support especially with TELIT LE910. However the fix should benefit to any modem supporting cmux.
The first patch is just about improving debugging output.
The second one removes a tty optimization which make the LE910 hang.
The last one fixes an issue observed on the LE910 but should benefit to all the modem. We observed that pretty quickly the transfer done using the virtual tty were blocked. We found that it was due of a wakeup to the real tty. Without this fix, the real tty wait for indefinitely.
Thanks to Jiri Slaby for the review.
Changelog:
v1 -> v2:
- don't replace the pr_info by pr_debug
- remove the superfluous printk("\n");
- use --follow option with git log to find the original commit to fix
- use tty_port_tty_wakeup
- use 'for' loop instead of 'while'
Gregory
Gregory CLEMENT (3):
tty: n_gsm: Improve debug output
tty: n_gsm: Fix SOF skipping
tty: n_gsm: Fix waking up upper tty layer when room available
drivers/tty/n_gsm.c | 48 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 23 deletions(-)
Signature · 1 line
2.26.2
PATCH v2 1/3 tty: n_gsm: Improve debug output
Use appropriate print helpers for debug messages.
--- drivers/tty/n_gsm.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/tty/n_gsm.c +2 -12
@@ -504,18 +504,8 @@ static void gsm_print_packet(const char *hdr, int addr, int cr,else pr_cont ("(F)" ); -if (dlen) { -int ct =0 ; -while (dlen--) { -if (ct %8 ==0 ) { -pr_cont ("\n" ); -pr_debug (" " ); - } -pr_cont ("%02X " , *data++); - ct++; - } - } -pr_cont ("\n" ); +if (dlen) +print_hex_dump_bytes ("" ,DUMP_PREFIX_NONE , data, dlen); }
Signature · 1 line
2.26.2
Re: [PATCH v2 1/3] tty: n_gsm: Improve debug output
Quoted 18 lines · Gregory CLEMENT
Use appropriate print helpers for debug messages.
Signed-off-by Gregory CLEMENT <[email protected]>--- drivers/tty/n_gsm.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)drivers/tty/n_gsm.c +0
-3@@ -504,18 +504,8 @@ static void gsm_print_packet(const char *hdr, int addr, int cr,else pr_cont ("(F)" ); -if (dlen) { -int ct =0 ; -while (dlen--) {
drivers/tty/n_gsm.c static void gsm_print_packet(const char *hdr, int addr, int cr, · line 507
Quoted 10 lines
drivers/tty/n_gsm.c +1
-9-if (ct %8 ==0 ) { -pr_cont ("\n" ); -pr_debug (" " ); - } -pr_cont ("%02X " , *data++); - ct++; - } - } -pr_cont ("\n" ); +if (dlen)
This test is superfluous. print_hex_dump_* won't write anything when zero length is passed to it.
drivers/tty/n_gsm.c static void gsm_print_packet(const char *hdr, int addr, int cr, · line 509
Quoted 2 lines
drivers/tty/n_gsm.c +1
-0+print_hex_dump_bytes ("" ,DUMP_PREFIX_NONE , data, dlen); }
thanks,
Signature · 2 lines
js suse labs
Re: [PATCH v2 1/3] tty: n_gsm: Improve debug output
Hello Jiri,
Quoted 16 lines · Gregory CLEMENT
Quoted 15 lines
Use appropriate print helpers for debug messages.
Signed-off-by Gregory CLEMENT <[email protected]>--- drivers/tty/n_gsm.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)drivers/tty/n_gsm.c +0
-0@@ -504,18 +504,8 @@ static void gsm_print_packet(const char *hdr, int addr, int cr,else pr_cont ("(F)" );
Quoted 16 lines
drivers/tty/n_gsm.c static void gsm_print_packet(const char *hdr, int addr, int cr, · line 507
Quoted 13 lines
drivers/tty/n_gsm.c +1
-12-if (dlen) { -int ct =0 ; -while (dlen--) { -if (ct %8 ==0 ) { -pr_cont ("\n" ); -pr_debug (" " ); - } -pr_cont ("%02X " , *data++); - ct++; - } - } -pr_cont ("\n" ); +if (dlen)This test is superfluous. print_hex_dump_* won't write anything when zero length is passed to it.
As I will send a v3 due to the issue found on the last patch, I am also going to fix this.
Gregory
Quoted 8 lines
drivers/tty/n_gsm.c static void gsm_print_packet(const char *hdr, int addr, int cr, · line 509
Quoted 3 lines
drivers/tty/n_gsm.c +1
-0+print_hex_dump_bytes ("" ,DUMP_PREFIX_NONE , data, dlen); }thanks,
Signature · 2 lines
js suse labs
Signature · 3 lines
Gregory Clement, Bootlin Embedded Linux and Kernel engineering http://bootlin.com
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/3] tty: n_gsm: Improve debug output
Quoted 35 lines · Gregory CLEMENT
Hello Jiri,
Quoted 16 lines · Gregory CLEMENT
Quoted 15 lines
Use appropriate print helpers for debug messages.
Signed-off-by Gregory CLEMENT <[email protected]>--- drivers/tty/n_gsm.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)drivers/tty/n_gsm.c +0
-0@@ -504,18 +504,8 @@ static void gsm_print_packet(const char *hdr, int addr, int cr,else pr_cont ("(F)" );Quoted 16 lines
drivers/tty/n_gsm.c static void gsm_print_packet(const char *hdr, int addr, int cr, · line 507
Quoted 13 lines
drivers/tty/n_gsm.c +1
-12-if (dlen) { -int ct =0 ; -while (dlen--) { -if (ct %8 ==0 ) { -pr_cont ("\n" ); -pr_debug (" " ); - } -pr_cont ("%02X " , *data++); - ct++; - } - } -pr_cont ("\n" ); +if (dlen)This test is superfluous. print_hex_dump_* won't write anything when zero length is passed to it.
Quoted 2 lines
As I will send a v3 due to the issue found on the last patch, I am also going to fix this.
Ugh, as I already applied this series, should I just revert them all, or are you going to send fix-ups on top of what I have applied instead?
thanks,
greg k-h
Re: [PATCH v2 1/3] tty: n_gsm: Improve debug output
Hello Greg,
Quoted 36 lines · Gregory CLEMENT
Quoted 35 lines
Hello Jiri,
Quoted 32 lines · Gregory CLEMENT
Quoted 18 lines
Use appropriate print helpers for debug messages.
Signed-off-by Gregory CLEMENT <[email protected]>--- drivers/tty/n_gsm.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)drivers/tty/n_gsm.c +0
-3@@ -504,18 +504,8 @@ static void gsm_print_packet(const char *hdr, int addr, int cr,else pr_cont ("(F)" ); -if (dlen) { -int ct =0 ; -while (dlen--) {drivers/tty/n_gsm.c static void gsm_print_packet(const char *hdr, int addr, int cr, · line 507
Quoted 10 lines
drivers/tty/n_gsm.c +1
-9-if (ct %8 ==0 ) { -pr_cont ("\n" ); -pr_debug (" " ); - } -pr_cont ("%02X " , *data++); - ct++; - } - } -pr_cont ("\n" ); +if (dlen)This test is superfluous. print_hex_dump_* won't write anything when zero length is passed to it.
Quoted 5 lines
Quoted 2 lines
As I will send a v3 due to the issue found on the last patch, I am also going to fix this.
Ugh, as I already applied this series, should I just revert them all, or are you going to send fix-ups on top of what I have applied instead?
I was about to send a new series, but I can just send fix-ups. It's up to you.
Gregory
Quoted 4 lines
thanks,
greg k-h
Signature · 3 lines
Gregory Clement, Bootlin Embedded Linux and Kernel engineering http://bootlin.com
Greg Kroah-Hartman
maintainerRe: [PATCH v2 1/3] tty: n_gsm: Improve debug output
Quoted 38 lines · Gregory CLEMENT
Hello Greg,
Quoted 36 lines · Gregory CLEMENT
Quoted 35 lines
Hello Jiri,
Quoted 32 lines · Gregory CLEMENT
Quoted 18 lines
Use appropriate print helpers for debug messages.
Signed-off-by Gregory CLEMENT <[email protected]>--- drivers/tty/n_gsm.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)drivers/tty/n_gsm.c +0
-3@@ -504,18 +504,8 @@ static void gsm_print_packet(const char *hdr, int addr, int cr,else pr_cont ("(F)" ); -if (dlen) { -int ct =0 ; -while (dlen--) {drivers/tty/n_gsm.c static void gsm_print_packet(const char *hdr, int addr, int cr, · line 507
Quoted 10 lines
drivers/tty/n_gsm.c +1
-9-if (ct %8 ==0 ) { -pr_cont ("\n" ); -pr_debug (" " ); - } -pr_cont ("%02X " , *data++); - ct++; - } - } -pr_cont ("\n" ); +if (dlen)This test is superfluous. print_hex_dump_* won't write anything when zero length is passed to it.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
As I will send a v3 due to the issue found on the last patch, I am also going to fix this.
Ugh, as I already applied this series, should I just revert them all, or are you going to send fix-ups on top of what I have applied instead?
I was about to send a new series, but I can just send fix-ups. It's up to you.
fix-ups are less work for me :)
PATCH 1/1 tty: n_gsm: gsm_print_packet: use scnprintf to avoid pr_cont
Use a temporary buffer to avoid multiple pr_cont uses.
---
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Ugh, as I already applied this series, should I just revert them all, or are you going to send fix-ups on top of what I have applied instead?
I was about to send a new series, but I can just send fix-ups. It's up to you.
fix-ups are less work for me :)
Perhaps use something like this instead?
It does increase object size a tiny bit.
drivers/tty/n_gsm.c | 71 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 29 deletions(-)
drivers/tty/n_gsm.c +42 -29
@@ -454,58 +454,71 @@ static u8 gsm_encode_modem(const struct gsm_dlci *dlci)*/ static void gsm_print_packet (const char *hdr,int addr,int cr, -u8 control,const u8 *data,int dlen) +u8 control,const u8 *data,int dlen) { +char buf[100 ]; +char *p; +char *type; +if (!(debug &1 ))return ; -pr_info ("%s %d) %c: " , hdr, addr,"RC" [cr]); + p = buf; + p +=scnprintf (p, buf - p,"%s %d) %c: " , hdr, addr,"RC" [cr]);switch (control & ~PF ) {case SABM : -pr_cont ("SABM" ); + type ="SABM" ;break ;case UA : -pr_cont ("UA" ); + type ="UA" ;break ;case DISC : -pr_cont ("DISC" ); + type ="DISC" ;break ;case DM : -pr_cont ("DM" ); + type ="DM" ;break ;case UI : -pr_cont ("UI" ); + type ="UI" ;break ;case UIH : -pr_cont ("UIH" ); + type ="UIH" ;break ;default : -if (!(control &0x01 )) { -pr_cont ("I N(S)%d N(R)%d" , - (control &0x0E ) >>1 , (control &0xE0 ) >>5 ); - }else switch (control &0x0F ) { -case RR : -pr_cont ("RR(%d)" , (control &0xE0 ) >>5 ); -break ; -case RNR : -pr_cont ("RNR(%d)" , (control &0xE0 ) >>5 ); -break ; -case REJ : -pr_cont ("REJ(%d)" , (control &0xE0 ) >>5 ); -break ; -default : -pr_cont ("[%02X]" , control); + type =NULL ; +break ; + } + +if (type) { + p +=scnprintf (p, buf - p,"%s" , type); + }else if (!(control &0x01 )) { + p +=scnprintf (p, buf - p,"I N(S)%d N(R)%d" , + (control &0x0E ) >>1 , (control &0xE0 ) >>5 ); + }else { +switch (control &0x0F ) { +case RR : + p +=scnprintf (p, buf - p,"RR(%d)" , + (control &0xE0 ) >>5 ); +break ; +case RNR : + p +=scnprintf (p, buf - p,"RNR(%d)" , + (control &0xE0 ) >>5 ); +break ; +case REJ : + p +=scnprintf (p, buf - p,"REJ(%d)" , + (control &0xE0 ) >>5 ); +break ; +default : + p +=scnprintf (p, buf - p,"[%02X]" , control); +break ; } } -if (control &PF ) -pr_cont ("(P)" ); -else -pr_cont ("(F)" ); + p +=scnprintf (p, buf - p,"(%c)" , control &PF ?'P' :'F' ); -if (dlen) -print_hex_dump_bytes ("" ,DUMP_PREFIX_NONE , data, dlen); +pr_info ("%s\n" , buf); +print_hex_dump_bytes ("" ,DUMP_PREFIX_NONE , data, dlen); }
PATCH v2 2/3 tty: n_gsm: Fix SOF skipping
In reply to Gregory CLEMENTFor at least some modems like the TELIT LE910, skipping SOF makes transfers blocking indefinitely after a short amount of data transferred.
Given the small improvement provided by skipping the SOF (just one byte on about 100 bytes), it seems better to completely remove this "feature" than make it optional.
--- drivers/tty/n_gsm.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/tty/n_gsm.c +1 -7
@@ -667,7 +667,6 @@ static void gsm_data_kick(struct gsm_mux *gsm) {struct gsm_msg *msg, *nmsg;int len; -int skip_sof =0 ;list_for_each_entry_safe (msg, nmsg, &gsm->tx_list, list) {if (gsm->constipated && msg->addr)
@@ -689,15 +688,10 @@ static void gsm_data_kick(struct gsm_mux *gsm)print_hex_dump_bytes ("gsm_data_kick: " ,DUMP_PREFIX_OFFSET , gsm->txframe, len); - -if (gsm->output (gsm, gsm->txframe + skip_sof, - len - skip_sof) <0 ) +if (gsm->output (gsm, gsm->txframe, len) <0 )break ;/* FIXME: Can eliminate one SOF in many more cases */ gsm->tx_bytes -= msg->len; -/* For a burst of frames skip the extra SOF within the -burst */ - skip_sof =1 ;list_del (&msg->list);kfree (msg);
Signature · 1 line
2.26.2
PATCH v2 3/3 tty: n_gsm: Fix waking up upper tty layer when room available
In reply to Gregory CLEMENTWarn the upper layer when n_gms is ready to receive data again. Without this the associated virtual tty remains blocked indefinitely.
--- drivers/tty/n_gsm.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/tty/n_gsm.c +22 -4
@@ -663,7 +663,7 @@ static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len,* FIXME: lock against link layer control transmissions */ -static void gsm_data_kick (struct gsm_mux *gsm) +static void gsm_data_kick (struct gsm_mux *gsm,struct gsm_dlci *dlci) {struct gsm_msg *msg, *nmsg;int len;
@@ -695,6 +695,24 @@ static void gsm_data_kick(struct gsm_mux *gsm)list_del (&msg->list);kfree (msg); + +if (dlci) { +tty_port_tty_wakeup (&dlci->port); + }else { +int i =0 ; + +for (i =0 ; i <NUM_DLCI ; i++) { +struct gsm_dlci *dlci; + + dlci = gsm->dlci[i]; +if (dlci ==NULL ) { + i++; +continue ; + } + +tty_port_tty_wakeup (&dlci->port); + } + } } }
@@ -746,7 +764,7 @@ static void __gsm_data_queue(struct gsm_dlci *dlci, struct gsm_msg *msg)/* Add to the actual output queue */ list_add_tail (&msg->list, &gsm->tx_list); gsm->tx_bytes += msg->len; -gsm_data_kick (gsm); +gsm_data_kick (gsm, dlci); }/**
@@ -1207,7 +1225,7 @@ static void gsm_control_message(struct gsm_mux *gsm, unsigned int command,gsm_control_reply (gsm,CMD_FCON ,NULL ,0 );/* Kick the link in case it is idling */ spin_lock_irqsave (&gsm->tx_lock, flags); -gsm_data_kick (gsm); +gsm_data_kick (gsm,NULL );spin_unlock_irqrestore (&gsm->tx_lock, flags);break ;case CMD_FCOFF :
@@ -2529,7 +2547,7 @@ static void gsmld_write_wakeup(struct tty_struct *tty)/* Queue poll */ clear_bit (TTY_DO_WRITE_WAKEUP , &tty->flags);spin_lock_irqsave (&gsm->tx_lock, flags); -gsm_data_kick (gsm); +gsm_data_kick (gsm,NULL );if (gsm->tx_bytes <TX_THRESH_LO ) {gsm_dlci_data_sweep (gsm); }
Signature · 1 line
2.26.2
Re: [PATCH v2 3/3] tty: n_gsm: Fix waking up upper tty layer when room available
Quoted 29 lines · Gregory CLEMENT
Warn the upper layer when
n_gmsis ready to receive data again. Without this the associated virtual tty remains blocked indefinitely.Fixes e1eaea46bb40 ("tty: n_gsm line discipline")Signed-off-by Gregory CLEMENT <[email protected]>--- drivers/tty/n_gsm.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)drivers/tty/n_gsm.c +3
-1@@ -663,7 +663,7 @@ static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len,* FIXME: lock against link layer control transmissions */ -static void gsm_data_kick (struct gsm_mux *gsm) +static void gsm_data_kick (struct gsm_mux *gsm,struct gsm_dlci *dlci) {struct gsm_msg *msg, *nmsg;int len;@@ -695,6 +695,24 @@ static void gsm_data_kick(struct gsm_mux *gsm)list_del (&msg->list);kfree (msg); + +if (dlci) {
drivers/tty/n_gsm.c static void gsm_data_kick(struct gsm_mux *gsm) · line 709
Quoted 10 lines
drivers/tty/n_gsm.c +10
-0+tty_port_tty_wakeup (&dlci->port); + }else { +int i =0 ; + +for (i =0 ; i <NUM_DLCI ; i++) { +struct gsm_dlci *dlci; + + dlci = gsm->dlci[i]; +if (dlci ==NULL ) { + i++;
This "i++" looks bogus here.
drivers/tty/n_gsm.c static void gsm_data_kick(struct gsm_mux *gsm) · line 713
Quoted 4 lines
drivers/tty/n_gsm.c +4
-0+continue ; + } + +tty_port_tty_wakeup (&dlci->port);
So simply:
for (i = 0; i < NUM_DLCI; i++) {
struct gsm_dlci *dlci = gsm->dlci[i];
if (dlci)
tty_port_tty_wakeup(&dlci->port); }
? Or even maybe directly:
for (i = 0; i < NUM_DLCI; i++)
if (gsm->dlci[i])
tty_port_tty_wakeup(&gsm->dlci[i]->port);
thanks,
Signature · 2 lines
js suse labs
Re: [PATCH v2 3/3] tty: n_gsm: Fix waking up upper tty layer when room available
Hi Jiri,
Quoted 26 lines · Gregory CLEMENT
Quoted 25 lines
Warn the upper layer when
n_gmsis ready to receive data again. Without this the associated virtual tty remains blocked indefinitely.Fixes e1eaea46bb40 ("tty: n_gsm line discipline")Signed-off-by Gregory CLEMENT <[email protected]>--- drivers/tty/n_gsm.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)drivers/tty/n_gsm.c +1
-1@@ -663,7 +663,7 @@ static struct gsm_msg *gsm_data_alloc(struct gsm_mux *gsm, u8 addr, int len,* FIXME: lock against link layer control transmissions */ -static void gsm_data_kick (struct gsm_mux *gsm) +static void gsm_data_kick (struct gsm_mux *gsm,struct gsm_dlci *dlci) {struct gsm_msg *msg, *nmsg;int len;@@ -695,6 +695,24 @@ static void gsm_data_kick(struct gsm_mux *gsm)
Quoted 16 lines
Quoted 4 lines
drivers/tty/n_gsm.c +2
-0list_del (&msg->list);kfree (msg); + +if (dlci) {drivers/tty/n_gsm.c static void gsm_data_kick(struct gsm_mux *gsm) · line 709
Quoted 10 lines
drivers/tty/n_gsm.c +10
-0+tty_port_tty_wakeup (&dlci->port); + }else { +int i =0 ; + +for (i =0 ; i <NUM_DLCI ; i++) { +struct gsm_dlci *dlci; + + dlci = gsm->dlci[i]; +if (dlci ==NULL ) { + i++;This "i++" looks bogus here.
You're right!
Sorry for this.
Quoted 11 lines
drivers/tty/n_gsm.c static void gsm_data_kick(struct gsm_mux *gsm) · line 713
Quoted 5 lines
drivers/tty/n_gsm.c +4
-0+continue ; + } + +tty_port_tty_wakeup (&dlci->port);So simply:
for (i = 0; i <NUM_DLCI; i++) {
structgsm_dlci*dlci = gsm->dlci[i];
if (dlci)
Quoted 7 lines
tty_port_tty_wakeup(&dlci->port); }? Or even maybe directly:
for (i = 0; i <NUM_DLCI; i++)
if (gsm->dlci[i])tty_port_tty_wakeup(&gsm->dlci[i]->port);
I will do this, thanks,
Gregory
Quoted 5 lines
thanks,
Signature · 2 lines
js suse labs
Signature · 3 lines
Gregory Clement, Bootlin Embedded Linux and Kernel engineering http://bootlin.com