Handle UART without interrupt on TEMT using em485
v2 cover Handle UART without interrupt on TEMT using em485
Thanks everyone for the comments. I apply most of the comments on version 1 but there is still a pending point with the Jiri comment about the safety of:
struct tty_struct *tty = p->port.state->port.tty;
I thought about adding a check with tty_port_initialized() before accessing the pointer, but I saw some other places where that same pointer is accessed without further protection, at least from what I see.
Changes from v1 to v2:
- Use UART_CAP_NOTEMT instead of UART_CAP_TEMT
- Use some predefined macro to reduce magicness
- Reset active_timer in temt timer handler
- add uart_get_byte_size
- set UART_CAP_NOTEMT in uart_config for PORT_16550A_FSL64
- Improve commit messages
- Improve grammar and spelling
- Add Giulio and Heiko SoB to reflect previous work
Eric Tremblay (3):
serial: 8250: Handle UART without interrupt on TEMT using em485
serial: 8250: Add UART_CAP_NOTEMT on PORT_16550A_FSL64
serial: 8250: add compatible for fsl,16550-FIFO64
drivers/tty/serial/8250/8250.h | 1 + drivers/tty/serial/8250/8250_of.c | 2 + drivers/tty/serial/8250/8250_port.c | 68 ++++++++++++++++++++++++++++- drivers/tty/serial/serial_core.c | 29 ++++++++---- include/linux/serial_8250.h | 2 + include/linux/serial_core.h | 2 + 6 files changed, 94 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/3 serial: 8250: Handle UART without interrupt on TEMT using em485
The patch introduce the UART_CAP_NOTEMT capability. The capability indicate that the UART doesn't have an interrupt available on TEMT.
In the case where the device does not support it, we calculate the maximum time it could take for the transmitter to empty the shift register. When we get in the situation where we get the THRE interrupt, we check if the TEMT bit is set. If it's not, we start the a timer and recall __stop_tx() after the delay.
The transmit sequence is a bit modified when the capability is set. The new timer is used between the last interrupt(THRE) and a potential stop_tx timer.
--- drivers/tty/serial/8250/8250.h | 1 + drivers/tty/serial/8250/8250_port.c | 66 ++++++++++++++++++++++++++++- drivers/tty/serial/serial_core.c | 29 +++++++++---- include/linux/serial_8250.h | 2 + include/linux/serial_core.h | 2 + 5 files changed, 91 insertions(+), 9 deletions(-)
drivers/tty/serial/8250/8250.h +1 -0
@@ -82,6 +82,7 @@ struct serial8250_config {#define UART_CAP_MINI (1 << 17)/* Mini UART on BCM283X family lacks: * STOP PARITY EPAR SPAR WLEN5 WLEN6 */ +#define UART_CAP_NOTEMT (1 << 18)/* UART without interrupt on TEMT available*/ #define UART_BUG_QUOT (1 << 0)/* UART has buggy quot LSB */ #define UART_BUG_TXEN (1 << 1)/* UART has buggy TX IIR status */
drivers/tty/serial/8250/8250_port.c +65 -1
111 lines not on this page · raw message
drivers/tty/serial/serial_core.c +21 -8
@@ -322,17 +322,12 @@ static void uart_shutdown(struct tty_struct *tty, struct uart_state *state) }/** -* uart_update_timeout - update per-port FIFO timeout. -* @port: uart_port structure describing the port +* uart_get_byte_size * @cflag: termios cflag value -* @baud: speed of the port * -* Set the port FIFO timeout value. The @cflag value should -* reflect the actual hardware settings. +* Get the size of a byte in bits. */ -void -uart_update_timeout (struct uart_port *port,unsigned int cflag, -unsigned int baud) +unsigned int uart_get_byte_size (unsigned int cflag) {unsigned int bits;
@@ -357,6 +352,24 @@ uart_update_timeout(struct uart_port *port, unsigned int cflag,if (cflag &PARENB ) bits++; +return bits; +} + +/** +* uart_update_timeout - update per-port FIFO timeout. +* @port: uart_port structure describing the port +* @cflag: termios cflag value +* @baud: speed of the port +* +* Set the port FIFO timeout value. The @cflag value should +* reflect the actual hardware settings. +*/ +void +uart_update_timeout (struct uart_port *port,unsigned int cflag, +unsigned int baud) +{ +unsigned int bits =uart_get_byte_size (cflag); +/* * The total number of bits to be transmitted in the fifo. */
include/linux/serial_8250.h +2 -0
@@ -79,7 +79,9 @@ struct uart_8250_ops {struct uart_8250_em485 {struct hrtimer start_tx_timer;/* "rs485 start tx" timer */ struct hrtimer stop_tx_timer;/* "rs485 stop tx" timer */ +struct hrtimer no_temt_timer;/* "rs485 no TEMT interrupt" timer */ struct hrtimer *active_timer;/* pointer to active timer */ +unsigned long no_temt_delay;/* Delay for no_temt_timer */ struct uart_8250_port *port;/* for hrtimer callbacks */ unsigned int tx_stopped:1 ;/* tx is currently stopped */ };
include/linux/serial_core.h +2 -0
@@ -332,6 +332,8 @@ unsigned int uart_get_baud_rate(struct uart_port *port, struct ktermios *termios unsigned int max);unsigned int uart_get_divisor (struct uart_port *port,unsigned int baud); +unsigned int uart_get_byte_size (unsigned int cflag); +/* Base timer interval for polling */ static inline int uart_poll_timeout (struct uart_port *port) {
Signature · 1 line
2.17.1
kernel test robot
build botRe: [PATCH v2 1/3] serial: 8250: Handle UART without interrupt on TEMT using em485
I love your patch! Yet something to improve:
Hi Eric,
I love your patch! Yet something to improve:
[auto build test ERROR on tty/tty-testing]
[also build test ERROR on usb/usb-testing v5.11-rc6 next-20210125] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Eric-Tremblay/Handle-UART-without-interrupt-on-TEMT-using-em485/20210205-002255 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing config: ia64-randconfig-r032-20210204 (attached as .config) compiler: ia64-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/070c956e2d260c56b13f43b7d092b4a20664248c
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Eric-Tremblay/Handle-UART-without-interrupt-on-TEMT-using-em485/20210205-002255 git checkout 070c956e2d260c56b13f43b7d092b4a20664248c
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=ia64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: "uart_get_byte_size" [drivers/tty/serial/8250/8250_base.ko] undefined!
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for FRAME_POINTER
Depends on DEBUG_KERNEL && (M68K || UML || SUPERH) || ARCH_WANT_FRAME_POINTERS
Selected by
- FAULT_INJECTION_STACKTRACE_FILTER && FAULT_INJECTION_DEBUG_FS && STACKTRACE_SUPPORT && !X86_64 && !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM && !ARC && !X86
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v2 1/3] serial: 8250: Handle UART without interrupt on TEMT using em485
Hello,
Quoted 24 lines · kernel test robot
Hi Eric,
I love your patch! Yet something to improve:
[auto build test ERROR on tty/tty-testing]
[also build test ERROR on usb/usb-testing v5.11-rc6 next-20210125] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]url: https://github.com/0day-ci/linux/commits/Eric-Tremblay/Handle-UART-without-interrupt-on-TEMT-using-em485/20210205-002255 base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing config: ia64-randconfig-r032-20210204 (attached as .config) compiler: ia64-linux-gcc (GCC) 9.3.0reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/070c956e2d260c56b13f43b7d092b4a20664248c
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Eric-Tremblay/Handle-UART-without-interrupt-on-TEMT-using-em485/20210205-002255 git checkout070c956e2d260c56b13f43b7d092b4a20664248c
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=ia64
Quoted 6 lines
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All errors (new ones prefixed by >>, old ones prefixed by <<):
Quoted 1 line
Quoted 1 line
ERROR: modpost: "
uart_get_byte_size" [drivers/tty/serial/8250/8250_base.ko] undefined!
FTR: This is a missing EXPORT_SYMBOL_GPL for uart_get_byte_size().
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Re: [PATCH v2 1/3] serial: 8250: Handle UART without interrupt on TEMT using em485
Quoted 5 lines · Uwe Kleine-König
Quoted 1 line · kernel test robot
Quoted 1 line
Quoted 1 line
ERROR: modpost: "
uart_get_byte_size" [drivers/tty/serial/8250/8250_base.ko] undefined!FTR: This is a missing
EXPORT_SYMBOL_GPLforuart_get_byte_size().
It seems we don't need that function anymore since we have similar one already.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 1/3] serial: 8250: Handle UART without interrupt on TEMT using em485
In reply to Eric TremblayQuoted 1 line · Eric Tremblay
The patch introduce the
UART_CAP_NOTEMTcapability. The capability
s/The patch//
Quoted 1 line
indicate that the UART doesn't have an interrupt available on TEMT.
indicates
Quoted 10 lines
In the case where the device does not support it, we calculate the maximum time it could take for the transmitter to empty the shift register. When we get in the situation where we get the THRE interrupt, we check if the TEMT bit is set. If it's not, we start the a timer and recall
__stop_tx()after the delay.The transmit sequence is a bit modified when the capability is set. The new timer is used between the last interrupt(THRE) and a potential
stop_txtimer.
Quoted 5 lines
Signed-off-by Giulio Benetti <[email protected]>[moved to use added UART_CAP_TEMT]Signed-off-by Heiko Stuebner <[email protected]>[moved to use added UART_CAP_NOTEMT, improve timeout]Signed-off-by Eric Tremblay <[email protected]>
Does it need Co-developed-by tag(s)?
...
Quoted 1 line
+#define
UART_CAP_NOTEMT(1 << 18) /* UART without interrupt on TEMT available*/
Missed space in the comment .
...
drivers/tty/serial/8250/8250_port.c static void serial8250_clear_fifos(struct uart_8250_port *p) · line 569
Quoted 9 lines
drivers/tty/serial/8250/8250_port.c +9
-0+static inline void serial8250_em485_update_temt_delay (struct uart_8250_port *p, +unsigned int cflag,unsigned int baud) +{ +unsigned int bits; + +if (!p->em485) +return ; + + bits =uart_get_byte_size (cflag);
Should be rebased. We have tty_get_frame_size() for a while.
Quoted 2 lines
drivers/tty/serial/8250/8250_port.c +2
-0+ p->em485->no_temt_delay = bits *NSEC_PER_SEC / baud; +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 1/3] serial: 8250: Handle UART without interrupt on TEMT using em485
In reply to Eric TremblayHello,
[dropped [email protected] from Cc: as the address doesn't seem to work any more]
Quoted 9 lines · Eric Tremblay
The patch introduce the
UART_CAP_NOTEMTcapability. The capability indicate that the UART doesn't have an interrupt available on TEMT.In the case where the device does not support it, we calculate the maximum time it could take for the transmitter to empty the shift register. When we get in the situation where we get the THRE interrupt, we check if the TEMT bit is set. If it's not, we start the a timer and recall
__stop_tx()after the delay.
Quoted 3 lines
The transmit sequence is a bit modified when the capability is set. The new timer is used between the last interrupt(THRE) and a potential
stop_txtimer.
I wonder if the required change can be simplified by just increasing the stop_tx_timer timeout as there is nothing that has to happen when the shifter is empty apart from starting the stop_tx timer.
This would require a good documentation because the semantic of the stop timer would change.
@Eric: Do you plan to address the feedback comments here? I'd volunteer as a tester if yes. Otherwise there might be some incentive to work on this series myself.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
PATCH v2 2/3 serial: 8250: Add UART_CAP_NOTEMT on PORT_16550A_FSL64
In reply to Eric TremblayThis port doesn't have an interrupt on TEMT available when using the FIFO mode.
--- drivers/tty/serial/8250/8250_port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_port.c +1 -1
@@ -262,7 +262,7 @@ static const struct serial8250_config uart_config[] = { .tx_loadsz = 63, .fcr =UART_FCR_ENABLE_FIFO |UART_FCR_R_TRIG_10 | UART_FCR7_64BYTE, - .flags = UART_CAP_FIFO, + .flags = UART_CAP_FIFO | UART_CAP_NOTEMT, }, [PORT_RT2880] = { .name = "Palmchip BK-3103",
Signature · 1 line
2.17.1
Re: [PATCH v2 2/3] serial: 8250: Add UART_CAP_NOTEMT on PORT_16550A_FSL64
Quoted 1 line · Eric Tremblay
This port doesn't have an interrupt on TEMT available when using
s/This port/Port on Freescale ... (or what is that?)/
Quoted 1 line
the FIFO mode.
With amended commit message
Quoted 21 lines
Signed-off-by Eric Tremblay <[email protected]>--- drivers/tty/serial/8250/8250_port.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/tty/serial/8250/8250_port.c +1
-1@@ -262,7 +262,7 @@ static const struct serial8250_config uart_config[] = { .tx_loadsz = 63, .fcr =UART_FCR_ENABLE_FIFO |UART_FCR_R_TRIG_10 | UART_FCR7_64BYTE, - .flags = UART_CAP_FIFO, + .flags = UART_CAP_FIFO | UART_CAP_NOTEMT, }, [PORT_RT2880] = { .name = "Palmchip BK-3103",Signature · 1 line
2.17.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 3/3 serial: 8250: add compatible for fsl,16550-FIFO64
In reply to Eric Tremblay--- drivers/tty/serial/8250/8250_of.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/tty/serial/8250/8250_of.c +2 -0
@@ -313,6 +313,8 @@ static const struct of_device_id of_platform_serial_table[] = { .data = (void *)PORT_ALTR_16550_F64, }, { .compatible = "altr,16550-FIFO128", .data = (void *)PORT_ALTR_16550_F128, }, + { .compatible = "fsl,16550-FIFO64", + .data = (void *)PORT_16550A_FSL64, }, { .compatible = "mediatek,mtk-btif", .data = (void *)PORT_MTK_BTIF, }, { .compatible = "mrvl,mmp-uart",
Signature · 1 line
2.17.1
Re: [PATCH v2 3/3] serial: 8250: add compatible for fsl,16550-FIFO64
On Thu, Feb 04, 2021 at 11:11:58AM -0500, Eric Tremblay wrote:
Needs a commit message.
Quoted 1 line
Signed-off-by Eric Tremblay <[email protected]>
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 6 lines · Eric Tremblay
Thanks everyone for the comments. I apply most of the comments on version 1 but there is still a pending point with the Jiri comment about the safety of:
structtty_struct*tty =p->port.state->port.tty;
I thought about adding a check withtty_port_initialized()before accessing the pointer, but I saw some other places where that same pointer is accessed without further protection, at least from what I see.
Thanks for the update. Unfortunately I'm a bit busy with other prioritized stuff, but I will review this next week.
Quoted 26 lines
Changes from v1 to v2:
- UseUART_CAP_NOTEMTinstead ofUART_CAP_TEMT
- Use some predefined macro to reduce magicness
- Resetactive_timerin temt timer handler
- adduart_get_byte_size
- setUART_CAP_NOTEMTinuart_configforPORT_16550A_FSL64
- Improve commit messages
- Improve grammar and spelling
- Add Giulio and Heiko SoB to reflect previous workEric Tremblay (3):
serial: 8250: Handle UART without interrupt on TEMT using em485
serial: 8250: AddUART_CAP_NOTEMTonPORT_16550A_FSL64
serial: 8250: add compatible for fsl,16550-FIFO64drivers/tty/serial/8250/8250.h | 1 + drivers/tty/serial/8250/8250_of.c | 2 + drivers/tty/serial/8250/8250_port.c | 68 ++++++++++++++++++++++++++++- drivers/tty/serial/serial_core.c | 29 ++++++++---- include/linux/serial_8250.h | 2 + include/linux/serial_core.h | 2 + 6 files changed, 94 insertions(+), 10 deletions(-)Signature · 1 line
2.17.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hello,
Quoted 10 lines · Andy Shevchenko
Quoted 6 lines · Eric Tremblay
Thanks everyone for the comments. I apply most of the comments on version 1 but there is still a pending point with the Jiri comment about the safety of:
structtty_struct*tty =p->port.state->port.tty;
I thought about adding a check withtty_port_initialized()before accessing the pointer, but I saw some other places where that same pointer is accessed without further protection, at least from what I see.Thanks for the update. Unfortunately I'm a bit busy with other prioritized stuff, but I will review this next week.
I assume this fell through the cracks as "next week" is already over ...?
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | https://www.pengutronix.de/ |
Quoted 9 lines · Uwe Kleine-König
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Eric Tremblay
Thanks everyone for the comments. I apply most of the comments on version 1 but there is still a pending point with the Jiri comment about the safety of:
structtty_struct*tty =p->port.state->port.tty;
I thought about adding a check withtty_port_initialized()before accessing the pointer, but I saw some other places where that same pointer is accessed without further protection, at least from what I see.
Quoted 4 lines
Quoted 2 lines
Thanks for the update. Unfortunately I'm a bit busy with other prioritized stuff, but I will review this next week.
I assume this fell through the cracks as "next week" is already over ...?
Indeed. Anyways, there is a kbuildbot message against patch 1 as I see and needs to be addressed. I'm going to look into the code right now.
Signature · 2 lines
With Best Regards, Andy Shevchenko