Skip to contentSkip to conversation

serial: serial_txx9 driver update

PATCH In review Atsushi Nemoto 3 participants 11 messages Jan 17, 2006 – Jan 24, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 serial: serial_txx9 driver update

This patch updates serial_txx9 driver. (diff from 2.6.16-rc1)

* More strict check in verify_port. Cleanup.
* Do not insert a char caused previous overrun.
* Fix some spin_locks.
* Do not call uart_add_one_port for absent ports.

Also, this patch removes a BROKEN tag from Kconfig. This driver has been marked as BROKEN by removal of uart_register_port, but it has been solved already on Sep 2005.

drivers/serial/Kconfig +1 -1
index 5e7199f..761c97c 100644
@@ -858,7 +858,7 @@ config SERIAL_M32R_PLDSIO
 
 config SERIAL_TXX9
 	bool "TMPTX39XX/49XX SIO support"
-	depends HAS_TXX9_SERIAL && BROKEN
+	depends HAS_TXX9_SERIAL
 	select SERIAL_CORE
 	default y
 
drivers/serial/serial_txx9.c +38 -36

193 lines not on this page · raw message

#1 lore raw
Quoted 7 lines · Atsushi Nemoto

serial_txx9_verify_port(struct uart_port *port, struct serial_struct *ser)
{
- if (ser->irq < 0 ||
- ser->baud_base < 9600 || ser->type != PORT_TXX9)
+ unsigned long new_port = (unsigned long)ser->port +
+ ((unsigned long)ser->port_high << ((sizeof(long) - sizeof(int)) * 8));

Are you sure about this part? Shifting something left by sizeof(something) seems very strange. It'll give different results on 64-bit machines for the same hardware. Are you sure it wasn't supposed to be an addition?

If this was indeed intended then can you please explain why?

If it was supposed to be an addition, wouldn't this be more clearly expressed by defining a suitable structure and using sizeof(that structure) to work out the address range?

#2 lore raw
Quoted 9 lines · Andrew Morton
Quoted 7 lines · Atsushi Nemoto

serial_txx9_verify_port(struct uart_port *port, struct serial_struct *ser)
{
- if (ser->irq < 0 ||
- ser->baud_base < 9600 || ser->type != PORT_TXX9)
+ unsigned long new_port = (unsigned long)ser->port +
+ ((unsigned long)ser->port_high << ((sizeof(long) - sizeof(int)) * 8));

Quoted 3 lines

Are you sure about this part? Shifting something left by sizeof(something) seems very strange. It'll give different results on 64-bit machines for the same hardware. Are you sure it wasn't supposed to be an addition?

There is a definition for that constant - it's called HIGH_BITS_OFFSET. No need to try to buggily recreate it.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#3 lore raw
Quoted 11 lines · Russell King
Quoted 9 lines · Andrew Morton
Quoted 7 lines · Atsushi Nemoto

serial_txx9_verify_port(struct uart_port *port, struct serial_struct *ser)
{
- if (ser->irq < 0 ||
- ser->baud_base < 9600 || ser->type != PORT_TXX9)
+ unsigned long new_port = (unsigned long)ser->port +
+ ((unsigned long)ser->port_high << ((sizeof(long) - sizeof(int)) * 8));

Quoted 5 lines
Quoted 3 lines

Are you sure about this part? Shifting something left by sizeof(something) seems very strange. It'll give different results on 64-bit machines for the same hardware. Are you sure it wasn't supposed to be an addition?

There is a definition for that constant - it's called HIGH_BITS_OFFSET.

There are two definitions, actually. drivers/serial/serial_core.c and drivers/serial/8250.h.

Quoted 1 line

No need to try to buggily recreate it.

Where's the bug in the proposed code?

Can you tell us what HIGH_BITS_OFFSET actually does? Stuffing the port address into the upper 32-bits of a ulong on 64-bit machines. Am consumed by curiosity.

#4 lore raw
Quoted 16 lines · Andrew Morton
Quoted 15 lines · Russell King
Quoted 12 lines · Andrew Morton
Quoted 7 lines · Atsushi Nemoto

serial_txx9_verify_port(struct uart_port *port, struct serial_struct *ser)
{
- if (ser->irq < 0 ||
- ser->baud_base < 9600 || ser->type != PORT_TXX9)
+ unsigned long new_port = (unsigned long)ser->port +
+ ((unsigned long)ser->port_high << ((sizeof(long) - sizeof(int)) * 8));

Are you sure about this part? Shifting something left by sizeof(something) seems very strange. It'll give different results on 64-bit machines for the same hardware. Are you sure it wasn't supposed to be an addition?

Quoted 8 lines
Quoted 1 line

There is a definition for that constant - it's called HIGH_BITS_OFFSET.

There are two definitions, actually. drivers/serial/serial_core.c and drivers/serial/8250.h.

Quoted 1 line

No need to try to buggily recreate it.

Where's the bug in the proposed code?

There isn't, but because it's wider than 80 columns, it got mis-read. As demonstrated, the 80 column rule _still_ matters for readability.

Quoted 3 lines

Can you tell us what HIGH_BITS_OFFSET actually does? Stuffing the port address into the upper 32-bits of a ulong on 64-bit machines. Am consumed by curiosity.

It's history. port in serial_struct has been declared as:

        unsigned int    port;

since the year dot, and has been exposed to userland since it's inception. I guess that 64-bit machines came along, and this was found to be inadequate. Rather than deprecate the current interface and provide a sane API, whoever did this came up with this yucky solution where

        unsigned int    port_high;

contains the address bits outside the range of "port". Presumably they assumed that sizeof(unsigned long) == 2 * sizeof(unsigned int) here. If not, this silly interface again breaks on us.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#5 lore raw
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 1 line · Russell King

Are you sure about this part? Shifting something left by sizeof(something) seems very strange. It'll give different results on 64-bit machines for the same hardware. Are you sure it wasn't supposed to be an addition?

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

There is a definition for that constant - it's called HIGH_BITS_OFFSET.

There are two definitions, actually. drivers/serial/serial_core.c and drivers/serial/8250.h.

Quoted 1 line

No need to try to buggily recreate it.

Where's the bug in the proposed code?

rmk> There isn't, but because it's wider than 80 columns, it got mis-read. rmk> As demonstrated, the 80 column rule _still_ matters for readability.

Thank you for all comments. Then I updated my patch using the HIGH_BITS_OFFSET.

---
This patch updates serial_txx9 driver. (diff from 2.6.16-rc1)

* More strict check in verify_port. Cleanup.
* Do not insert a char caused previous overrun.
* Fix some spin_locks.
* Do not call uart_add_one_port for absent ports.

Also, this patch removes a BROKEN tag from Kconfig. This driver has been marked as BROKEN by removal of uart_register_port, but it has been solved already on Sep 2005.

drivers/serial/Kconfig +1 -1
index 9fd1925..27c4676 100644
@@ -858,7 +858,7 @@ config SERIAL_M32R_PLDSIO
 
 config SERIAL_TXX9
 	bool "TMPTX39XX/49XX SIO support"
-	depends HAS_TXX9_SERIAL && BROKEN
+	depends HAS_TXX9_SERIAL
 	select SERIAL_CORE
 	default y
 
drivers/serial/serial_txx9.c +41 -36

202 lines not on this page · raw message

#6 lore raw

drivers/serial/serial_txx9.c receive_chars(struct uart_txx9_port *up, · line 336

Quoted 12 lines · Atsushi Nemoto
drivers/serial/serial_txx9.c +10 -1
-			if (disr & TXX9_SIDISR_UOER)
+			if (disr & TXX9_SIDISR_UOER) {
 				up->port.icount.overrun++;
+				/*
+				 * The receiver read buffer still hold
+				 * a char which caused overrun.
+				 * Ignore next char by adding RFDN_MASK
+				 * to ignore_status_mask temporarily.
+				 */
+				next_ignore_status_mask |=
+					TXX9_SIDISR_RFDN_MASK;
+			}

I'm not sure what you mean here.

If we successfully received the string ABCDEFGH, and the next character to be received (I) causes an overrun condition, what happens in the case that overruns are not ignored?

Will you read ABCDEFG without any errors from the UART, and then H with an overrun error? If so, you should pass to the TTY layer ABCDEFGH and then a NUL character with TTY_OVERRUN set. Note that uart_insert_char() does this for you.

Alternatively, the UART may give you: ABCDEFGI where I is marked as an overrun error. In this case, you want to pass to the TTY layer ABCDEFG, then a NUL character with TTY_OVERRUN set, then I.

If overruns are ignored, you merely omit to insert the NUL character with TTY_OVERRUN set.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#7 lore raw
Quoted 13 lines

drivers/serial/serial_txx9.c receive_chars(struct uart_txx9_port *up, · line 336

Quoted 13 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Russell King
drivers/serial/serial_txx9.c +10 -1
-			if (disr & TXX9_SIDISR_UOER)
+			if (disr & TXX9_SIDISR_UOER) {
 				up-> port.icount.overrun++;
+				/*
+				 * The receiver read buffer still hold
+				 * a char which caused overrun.
+				 * Ignore next char by adding RFDN_MASK
+				 * to ignore_status_mask temporarily.
+				 */
+				next_ignore_status_mask |=
+					TXX9_SIDISR_RFDN_MASK;
+			}

rmk> I'm not sure what you mean here.

rmk> If we successfully received the string ABCDEFGH, and the next character rmk> to be received (I) causes an overrun condition, what happens in the rmk> case that overruns are not ignored?

In this case, I will read ABCDEFG without errors, and then I with an overrun

rmk> Will you read ABCDEFG without any errors from the UART, and then H with rmk> an overrun error? If so, you should pass to the TTY layer ABCDEFGH and rmk> then a NUL character with TTY_OVERRUN set. Note that uart_insert_char() rmk> does this for you.

Yes, in this case I will read ABCDEFG without error, and then H with an overrun error. But the UART still hold "I" in its "read buffer". The "read buffer" is exist outside the receiver FIFO. So if 'J' comes in later, I will read "IJ". There is no way to clear the "read buffer" except resetting the UART.

Resetting the whole UART is too intrusive, so I chose a way in the patch (Ignore just next one char after an overrun error.)

---
Atsushi Nemoto

#8 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Atsushi Nemoto

anemo> In this case, I will read ABCDEFG without errors, and then I with an overrun

Excuse me, please ignore this broken line.
---
Atsushi Nemoto

#9 lore raw
In reply to Atsushi Nemoto
Quoted 5 lines · Atsushi Nemoto

rmk> If we successfully received the string ABCDEFGH, and the next character rmk> to be received (I) causes an overrun condition, what happens in the rmk> case that overruns are not ignored?

In this case, I will read ABCDEFG without errors, and then I with an overrun

Duely ignored.

Quoted 10 lines

rmk> Will you read ABCDEFG without any errors from the UART, and then H with rmk> an overrun error? If so, you should pass to the TTY layer ABCDEFGH and rmk> then a NUL character with TTY_OVERRUN set. Note that uart_insert_char() rmk> does this for you.

Yes, in this case I will read ABCDEFG without error, and then H with an overrun error. But the UART still hold "I" in its "read buffer". The "read buffer" is exist outside the receiver FIFO. So if 'J' comes in later, I will read "IJ". There is no way to clear the "read buffer" except resetting the UART.

Ok, so if someone sent you ABCDEFGHIJ, all before you could read anything from the UART, where I causes an overrun, you'll read ABCDEFGHJ, but the status associated with H will indicate an overrun condition?

However, either way the behaviour after the overrun condition has no bearing on what follows.

Your overrun behaviour is near enough to typical 8250 behaviour that you can use the helper provided - uart_insert_char(). This eliminates the special flag handling you seem to have created.

IOW, you want to do:

	ch = read_uart_fifo_data_register();
	status = read_uart_status_register();

	/*
	... error processing ... to set flag but omitting overrun.
	... don't do ignore processing here - uart_insert_char does
	... that for you ...
	*/

	uart_insert_char(port, status, STATUS_OVERRUN_BIT, ch, flag);

For an example, see receive_chars() in 8250.c.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#10 lore raw
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line · Russell King

Yes, in this case I will read ABCDEFG without error, and then H with an overrun error. But the UART still hold "I" in its "read buffer". The "read buffer" is exist outside the receiver FIFO. So if 'J' comes in later, I will read "IJ". There is no way to clear the "read buffer" except resetting the UART.

rmk> Ok, so if someone sent you ABCDEFGHIJ, all before you could read rmk> anything from the UART, where I causes an overrun, you'll read rmk> ABCDEFGHJ, but the status associated with H will indicate an rmk> overrun condition?

Partially incorrect. With or without the patch, "H" will indicate an overrun.

If someone sent me "ABCDEFGHI(...long delay...)J", all before I could read "ABCDEFGH", NUL with TTY_OVERRUN, then "IJ". With the patch, I will read "ABCDEFGH", NUL with TTY_OVERRUN, then "J".

I do not want to read "I" after long delay. Dropping the "I" is not a problem while I can know that an overrun happened there.

rmk> Your overrun behaviour is near enough to typical 8250 behaviour rmk> that you can use the helper provided - uart_insert_char(). This rmk> eliminates the special flag handling you seem to have created.

I suppose typical 8250 will drop "I". The TXX9 UART does not (it is described in the datasheet. Not a bug).

I have been using uart_insert_char() and it helps me to pass NUL (with TTY_OVERRUN) after "H" char. But the it is not enough to handle this queer behavior.

---
Atsushi Nemoto