All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] serial: 8250_dw: Minor code cleanup
@ 2017-03-29 10:04 ` Olliver Schinagl
  0 siblings, 0 replies; 10+ messages in thread
From: Olliver Schinagl @ 2017-03-29 10:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: Kefeng Wang, Andy Shevchenko, Heikki Krogerus, Jason Uy,
	Heiko Stuebner, Ed Blake, Douglas Anderson, linux-serial,
	linux-kernel, dev, Olliver Schinagl

Commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from bogus rx timeout interrupt")
added a bit check with quite a wide mask. To be concise with the other
similar calls in this driver, change it to mask against the flag we want to
check only. This thus removes a magic value/mask.

Some very minor code cleanups, such as including the bitops header for
DW_UART_MCR_SIRE, use the BIT() macro as suggested by checkpatc and
removed a whitespace to match other invocations.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
---
 drivers/tty/serial/8250/8250_dw.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index e65808c482f1..49117bdc7b6a 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -13,6 +13,7 @@
  * LCR is written whilst busy.  If it is, then a busy detect interrupt is
  * raised, the LCR needs to be rewritten and the uart status register read.
  */
+#include <linux/bitops.h>
 #include <linux/device.h>
 #include <linux/io.h>
 #include <linux/module.h>
@@ -39,16 +40,16 @@
 
 /* Component Parameter Register bits */
 #define DW_UART_CPR_ABP_DATA_WIDTH	(3 << 0)
-#define DW_UART_CPR_AFCE_MODE		(1 << 4)
-#define DW_UART_CPR_THRE_MODE		(1 << 5)
-#define DW_UART_CPR_SIR_MODE		(1 << 6)
-#define DW_UART_CPR_SIR_LP_MODE		(1 << 7)
-#define DW_UART_CPR_ADDITIONAL_FEATURES	(1 << 8)
-#define DW_UART_CPR_FIFO_ACCESS		(1 << 9)
-#define DW_UART_CPR_FIFO_STAT		(1 << 10)
-#define DW_UART_CPR_SHADOW		(1 << 11)
-#define DW_UART_CPR_ENCODED_PARMS	(1 << 12)
-#define DW_UART_CPR_DMA_EXTRA		(1 << 13)
+#define DW_UART_CPR_AFCE_MODE		BIT(4)
+#define DW_UART_CPR_THRE_MODE		BIT(5)
+#define DW_UART_CPR_SIR_MODE		BIT(6)
+#define DW_UART_CPR_SIR_LP_MODE		BIT(7)
+#define DW_UART_CPR_ADDITIONAL_FEATURES	BIT(8)
+#define DW_UART_CPR_FIFO_ACCESS		BIT(9)
+#define DW_UART_CPR_FIFO_STAT		BIT(10)
+#define DW_UART_CPR_SHADOW		BIT(11)
+#define DW_UART_CPR_ENCODED_PARMS	BIT(12)
+#define DW_UART_CPR_DMA_EXTRA		BIT(13)
 #define DW_UART_CPR_FIFO_MODE		(0xff << 16)
 /* Helper for fifo size calculation */
 #define DW_UART_CPR_FIFO_SIZE(a)	(((a >> 16) & 0xff) * 16)
@@ -217,12 +218,12 @@ static int dw8250_handle_irq(struct uart_port *p)
 	 * This problem has only been observed so far when not in DMA mode
 	 * so we limit the workaround only to non-DMA mode.
 	 */
-	if (!up->dma && ((iir & 0x3f) == UART_IIR_RX_TIMEOUT)) {
+	if (!up->dma && ((iir & UART_IIR_RX_TIMEOUT) == UART_IIR_RX_TIMEOUT)) {
 		spin_lock_irqsave(&p->lock, flags);
 		status = p->serial_in(p, UART_LSR);
 
 		if (!(status & (UART_LSR_DR | UART_LSR_BI)))
-			(void) p->serial_in(p, UART_RX);
+			(void)p->serial_in(p, UART_RX);
 
 		spin_unlock_irqrestore(&p->lock, flags);
 	}
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH] serial: 8250_dw: Minor code cleanup
@ 2017-03-29 10:04 ` Olliver Schinagl
  0 siblings, 0 replies; 10+ messages in thread
From: Olliver Schinagl @ 2017-03-29 10:04 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: Kefeng Wang, Andy Shevchenko, Heikki Krogerus, Jason Uy,
	Heiko Stuebner, Ed Blake, Douglas Anderson,
	linux-serial-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, dev-3kdeTeqwOZ9EV1b7eY7vFQ,
	Olliver Schinagl

Commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from bogus rx timeout interrupt")
added a bit check with quite a wide mask. To be concise with the other
similar calls in this driver, change it to mask against the flag we want to
check only. This thus removes a magic value/mask.

Some very minor code cleanups, such as including the bitops header for
DW_UART_MCR_SIRE, use the BIT() macro as suggested by checkpatc and
removed a whitespace to match other invocations.

Signed-off-by: Olliver Schinagl <oliver-dxLnbx3+1qmEVqv0pETR8A@public.gmane.org>
---
 drivers/tty/serial/8250/8250_dw.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
index e65808c482f1..49117bdc7b6a 100644
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -13,6 +13,7 @@
  * LCR is written whilst busy.  If it is, then a busy detect interrupt is
  * raised, the LCR needs to be rewritten and the uart status register read.
  */
+#include <linux/bitops.h>
 #include <linux/device.h>
 #include <linux/io.h>
 #include <linux/module.h>
@@ -39,16 +40,16 @@
 
 /* Component Parameter Register bits */
 #define DW_UART_CPR_ABP_DATA_WIDTH	(3 << 0)
-#define DW_UART_CPR_AFCE_MODE		(1 << 4)
-#define DW_UART_CPR_THRE_MODE		(1 << 5)
-#define DW_UART_CPR_SIR_MODE		(1 << 6)
-#define DW_UART_CPR_SIR_LP_MODE		(1 << 7)
-#define DW_UART_CPR_ADDITIONAL_FEATURES	(1 << 8)
-#define DW_UART_CPR_FIFO_ACCESS		(1 << 9)
-#define DW_UART_CPR_FIFO_STAT		(1 << 10)
-#define DW_UART_CPR_SHADOW		(1 << 11)
-#define DW_UART_CPR_ENCODED_PARMS	(1 << 12)
-#define DW_UART_CPR_DMA_EXTRA		(1 << 13)
+#define DW_UART_CPR_AFCE_MODE		BIT(4)
+#define DW_UART_CPR_THRE_MODE		BIT(5)
+#define DW_UART_CPR_SIR_MODE		BIT(6)
+#define DW_UART_CPR_SIR_LP_MODE		BIT(7)
+#define DW_UART_CPR_ADDITIONAL_FEATURES	BIT(8)
+#define DW_UART_CPR_FIFO_ACCESS		BIT(9)
+#define DW_UART_CPR_FIFO_STAT		BIT(10)
+#define DW_UART_CPR_SHADOW		BIT(11)
+#define DW_UART_CPR_ENCODED_PARMS	BIT(12)
+#define DW_UART_CPR_DMA_EXTRA		BIT(13)
 #define DW_UART_CPR_FIFO_MODE		(0xff << 16)
 /* Helper for fifo size calculation */
 #define DW_UART_CPR_FIFO_SIZE(a)	(((a >> 16) & 0xff) * 16)
@@ -217,12 +218,12 @@ static int dw8250_handle_irq(struct uart_port *p)
 	 * This problem has only been observed so far when not in DMA mode
 	 * so we limit the workaround only to non-DMA mode.
 	 */
-	if (!up->dma && ((iir & 0x3f) == UART_IIR_RX_TIMEOUT)) {
+	if (!up->dma && ((iir & UART_IIR_RX_TIMEOUT) == UART_IIR_RX_TIMEOUT)) {
 		spin_lock_irqsave(&p->lock, flags);
 		status = p->serial_in(p, UART_LSR);
 
 		if (!(status & (UART_LSR_DR | UART_LSR_BI)))
-			(void) p->serial_in(p, UART_RX);
+			(void)p->serial_in(p, UART_RX);
 
 		spin_unlock_irqrestore(&p->lock, flags);
 	}
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] serial: 8250_dw: Minor code cleanup
@ 2017-03-29 15:50   ` Doug Anderson
  0 siblings, 0 replies; 10+ messages in thread
From: Doug Anderson @ 2017-03-29 15:50 UTC (permalink / raw)
  To: Olliver Schinagl
  Cc: Greg Kroah-Hartman, Jiri Slaby, Kefeng Wang, Andy Shevchenko,
	Heikki Krogerus, Jason Uy, Heiko Stuebner, Ed Blake,
	linux-serial, linux-kernel, dev

Hi,

On Wed, Mar 29, 2017 at 3:04 AM, Olliver Schinagl <oliver@schinagl.nl> wrote:
> Commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from bogus rx timeout interrupt")
> added a bit check with quite a wide mask. To be concise with the other
> similar calls in this driver, change it to mask against the flag we want to
> check only. This thus removes a magic value/mask.

How certain are you that your patch is correct?  You are now basically
checking to see if the bits "0xc" are set in the IIR.  Previously the
patch ensured that the bits 0x33 were clear.

Have you tried looking through the kernel for other places where
UART_IIR_RX_TIMEOUT is referenced?  In 8250_omap.c and 8250_port.c I
believe you'll find it masking against 0x3f.  In omap-serial.c you'll
see a mask against 0x3e.

Looking at the TRM for rk3399, I see that bits 4 and 5 (bitmask 0x30)
as "reserved".  I see the following definitions for bits 3:0:

0000 = modem status
0001 = no interrupt pending
0010 = THR empty
0100 = received data available
0110 = receiver line status
0111 = busy detect
1100 = character timeout

...so while your patch will probably function OK, it would also
function equally well to simply test bit 3 (0x80) and ignore
everything else.  ...but IMHO it is more correct to at least mask the
IIR with 0x0F and confirm that bits 2 and 3 are set and bits 0 and 1
are zero.  ...and since the main 8250 code uses 0x3f, that seems even
better to me (despite the fact that it seems to be relying on the fact
that the "reserved" bits come back as 0).


If you want to make a fix, I'd suggest adding a #define for 0x3f and
using it in various places.


> Some very minor code cleanups, such as including the bitops header for
> DW_UART_MCR_SIRE, use the BIT() macro as suggested by checkpatc and
> removed a whitespace to match other invocations.

Maybe it's just me, but it seems like a bad idea to combine these
cleanups in the same patch with a functional change..

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] serial: 8250_dw: Minor code cleanup
@ 2017-03-29 15:50   ` Doug Anderson
  0 siblings, 0 replies; 10+ messages in thread
From: Doug Anderson @ 2017-03-29 15:50 UTC (permalink / raw)
  To: Olliver Schinagl
  Cc: Greg Kroah-Hartman, Jiri Slaby, Kefeng Wang, Andy Shevchenko,
	Heikki Krogerus, Jason Uy, Heiko Stuebner, Ed Blake,
	linux-serial-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, dev-3kdeTeqwOZ9EV1b7eY7vFQ

Hi,

On Wed, Mar 29, 2017 at 3:04 AM, Olliver Schinagl <oliver-dxLnbx3+1qmEVqv0pETR8A@public.gmane.org> wrote:
> Commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from bogus rx timeout interrupt")
> added a bit check with quite a wide mask. To be concise with the other
> similar calls in this driver, change it to mask against the flag we want to
> check only. This thus removes a magic value/mask.

How certain are you that your patch is correct?  You are now basically
checking to see if the bits "0xc" are set in the IIR.  Previously the
patch ensured that the bits 0x33 were clear.

Have you tried looking through the kernel for other places where
UART_IIR_RX_TIMEOUT is referenced?  In 8250_omap.c and 8250_port.c I
believe you'll find it masking against 0x3f.  In omap-serial.c you'll
see a mask against 0x3e.

Looking at the TRM for rk3399, I see that bits 4 and 5 (bitmask 0x30)
as "reserved".  I see the following definitions for bits 3:0:

0000 = modem status
0001 = no interrupt pending
0010 = THR empty
0100 = received data available
0110 = receiver line status
0111 = busy detect
1100 = character timeout

...so while your patch will probably function OK, it would also
function equally well to simply test bit 3 (0x80) and ignore
everything else.  ...but IMHO it is more correct to at least mask the
IIR with 0x0F and confirm that bits 2 and 3 are set and bits 0 and 1
are zero.  ...and since the main 8250 code uses 0x3f, that seems even
better to me (despite the fact that it seems to be relying on the fact
that the "reserved" bits come back as 0).


If you want to make a fix, I'd suggest adding a #define for 0x3f and
using it in various places.


> Some very minor code cleanups, such as including the bitops header for
> DW_UART_MCR_SIRE, use the BIT() macro as suggested by checkpatc and
> removed a whitespace to match other invocations.

Maybe it's just me, but it seems like a bad idea to combine these
cleanups in the same patch with a functional change..

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] serial: 8250_dw: Minor code cleanup
@ 2017-03-29 17:10     ` Olliver Schinagl
  0 siblings, 0 replies; 10+ messages in thread
From: Olliver Schinagl @ 2017-03-29 17:10 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Greg Kroah-Hartman, Jiri Slaby, Kefeng Wang, Andy Shevchenko,
	Heikki Krogerus, Jason Uy, Heiko Stuebner, Ed Blake,
	linux-serial, linux-kernel, dev

Hey Doug,

On 29-03-17 17:50, Doug Anderson wrote:
> Hi,
>
> On Wed, Mar 29, 2017 at 3:04 AM, Olliver Schinagl <oliver@schinagl.nl> wrote:
>> Commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from bogus rx timeout interrupt")
>> added a bit check with quite a wide mask. To be concise with the other
>> similar calls in this driver, change it to mask against the flag we want to
>> check only. This thus removes a magic value/mask.
>
> How certain are you that your patch is correct?  You are now basically
> checking to see if the bits "0xc" are set in the IIR.  Previously the
> patch ensured that the bits 0x33 were clear.

You raise a good point. And after writing two replies that made perfect 
sense, I just realized looking at the table you wisely posted below, I 
should have spotted that the interrupts are not bits! So very good catch 
and my bad indeed.

>
> Have you tried looking through the kernel for other places where
> UART_IIR_RX_TIMEOUT is referenced?  In 8250_omap.c and 8250_port.c I
> believe you'll find it masking against 0x3f.  In omap-serial.c you'll
> see a mask against 0x3e.
>
> Looking at the TRM for rk3399, I see that bits 4 and 5 (bitmask 0x30)
> as "reserved".  I see the following definitions for bits 3:0:
>
> 0000 = modem status
> 0001 = no interrupt pending
> 0010 = THR empty
> 0100 = received data available
> 0110 = receiver line status
> 0111 = busy detect
> 1100 = character timeout
>
> ...so while your patch will probably function OK, it would also
> function equally well to simply test bit 3 (0x80) and ignore
> everything else.  ...but IMHO it is more correct to at least mask the
> IIR with 0x0F and confirm that bits 2 and 3 are set and bits 0 and 1
> are zero.  ...and since the main 8250 code uses 0x3f, that seems even
> better to me (despite the fact that it seems to be relying on the fact
> that the "reserved" bits come back as 0).

I strongly agree with you here, I did it wrong, but 0x3f really is wrong 
too imo. The bits to look at are 3:0, bits 4:5 are reserved and we 
should never look at those, as as you rightfully put it are being relied 
on to be 0 (which may always be the case) but imo is still wrong and 
thus the mask should be 0x0f.

Going to the horse's mouth [0] which is the documentation of the IP 
block used in all these designs, they also say the same thing. 4 bits 
and while I don't have any of the other datasheets of other 8250 cores, 
I bet they are the same?

And then, the following is actually wrong on the same grounds, from the 
8250_dw.c


if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {

This just happens to work as it is the only way this can match, but 
clearly it is wrong then, right?

I'll check against the same mask of 0x0f here as well.
>
>
> If you want to make a fix, I'd suggest adding a #define for 0x3f and
> using it in various places.
Yeah I'll do that, add the define next to the others for 0x0f, unless 
someone says it is a good idea (or needed idea) to mask against the 
reserved bits as well.

>
>
>> Some very minor code cleanups, such as including the bitops header for
>> DW_UART_MCR_SIRE, use the BIT() macro as suggested by checkpatc and
>> removed a whitespace to match other invocations.
>
> Maybe it's just me, but it seems like a bad idea to combine these
> cleanups in the same patch with a functional change..
Well with the oversight of the bit check above, it becomes obvious that 
it is a bigger change indeed. I will change it!

Olliver

>

[0] http://linux-sunxi.org/images/d/d2/Dw_apb_uart_db.pdf

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] serial: 8250_dw: Minor code cleanup
@ 2017-03-29 17:10     ` Olliver Schinagl
  0 siblings, 0 replies; 10+ messages in thread
From: Olliver Schinagl @ 2017-03-29 17:10 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Greg Kroah-Hartman, Jiri Slaby, Kefeng Wang, Andy Shevchenko,
	Heikki Krogerus, Jason Uy, Heiko Stuebner, Ed Blake,
	linux-serial-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, dev-3kdeTeqwOZ9EV1b7eY7vFQ

Hey Doug,

On 29-03-17 17:50, Doug Anderson wrote:
> Hi,
>
> On Wed, Mar 29, 2017 at 3:04 AM, Olliver Schinagl <oliver-dxLnbx3+1qmEVqv0pETR8A@public.gmane.org> wrote:
>> Commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from bogus rx timeout interrupt")
>> added a bit check with quite a wide mask. To be concise with the other
>> similar calls in this driver, change it to mask against the flag we want to
>> check only. This thus removes a magic value/mask.
>
> How certain are you that your patch is correct?  You are now basically
> checking to see if the bits "0xc" are set in the IIR.  Previously the
> patch ensured that the bits 0x33 were clear.

You raise a good point. And after writing two replies that made perfect 
sense, I just realized looking at the table you wisely posted below, I 
should have spotted that the interrupts are not bits! So very good catch 
and my bad indeed.

>
> Have you tried looking through the kernel for other places where
> UART_IIR_RX_TIMEOUT is referenced?  In 8250_omap.c and 8250_port.c I
> believe you'll find it masking against 0x3f.  In omap-serial.c you'll
> see a mask against 0x3e.
>
> Looking at the TRM for rk3399, I see that bits 4 and 5 (bitmask 0x30)
> as "reserved".  I see the following definitions for bits 3:0:
>
> 0000 = modem status
> 0001 = no interrupt pending
> 0010 = THR empty
> 0100 = received data available
> 0110 = receiver line status
> 0111 = busy detect
> 1100 = character timeout
>
> ...so while your patch will probably function OK, it would also
> function equally well to simply test bit 3 (0x80) and ignore
> everything else.  ...but IMHO it is more correct to at least mask the
> IIR with 0x0F and confirm that bits 2 and 3 are set and bits 0 and 1
> are zero.  ...and since the main 8250 code uses 0x3f, that seems even
> better to me (despite the fact that it seems to be relying on the fact
> that the "reserved" bits come back as 0).

I strongly agree with you here, I did it wrong, but 0x3f really is wrong 
too imo. The bits to look at are 3:0, bits 4:5 are reserved and we 
should never look at those, as as you rightfully put it are being relied 
on to be 0 (which may always be the case) but imo is still wrong and 
thus the mask should be 0x0f.

Going to the horse's mouth [0] which is the documentation of the IP 
block used in all these designs, they also say the same thing. 4 bits 
and while I don't have any of the other datasheets of other 8250 cores, 
I bet they are the same?

And then, the following is actually wrong on the same grounds, from the 
8250_dw.c


if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {

This just happens to work as it is the only way this can match, but 
clearly it is wrong then, right?

I'll check against the same mask of 0x0f here as well.
>
>
> If you want to make a fix, I'd suggest adding a #define for 0x3f and
> using it in various places.
Yeah I'll do that, add the define next to the others for 0x0f, unless 
someone says it is a good idea (or needed idea) to mask against the 
reserved bits as well.

>
>
>> Some very minor code cleanups, such as including the bitops header for
>> DW_UART_MCR_SIRE, use the BIT() macro as suggested by checkpatc and
>> removed a whitespace to match other invocations.
>
> Maybe it's just me, but it seems like a bad idea to combine these
> cleanups in the same patch with a functional change..
Well with the oversight of the bit check above, it becomes obvious that 
it is a bigger change indeed. I will change it!

Olliver

>

[0] http://linux-sunxi.org/images/d/d2/Dw_apb_uart_db.pdf

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] serial: 8250_dw: Minor code cleanup
@ 2017-03-29 17:20       ` Olliver Schinagl
  0 siblings, 0 replies; 10+ messages in thread
From: Olliver Schinagl @ 2017-03-29 17:20 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Greg Kroah-Hartman, Jiri Slaby, Kefeng Wang, Andy Shevchenko,
	Heikki Krogerus, Jason Uy, Heiko Stuebner, Ed Blake,
	linux-serial, linux-kernel, dev

Hey Doug,

On 29-03-17 19:10, Olliver Schinagl wrote:
> Hey Doug,
>
> On 29-03-17 17:50, Doug Anderson wrote:
>> Hi,
>>
>> On Wed, Mar 29, 2017 at 3:04 AM, Olliver Schinagl <oliver@schinagl.nl>
>> wrote:
>>> Commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from
>>> bogus rx timeout interrupt")
>>> added a bit check with quite a wide mask. To be concise with the other
>>> similar calls in this driver, change it to mask against the flag we
>>> want to
>>> check only. This thus removes a magic value/mask.
>>
>> How certain are you that your patch is correct?  You are now basically
>> checking to see if the bits "0xc" are set in the IIR.  Previously the
>> patch ensured that the bits 0x33 were clear.
>
> You raise a good point. And after writing two replies that made perfect
> sense, I just realized looking at the table you wisely posted below, I
> should have spotted that the interrupts are not bits! So very good catch
> and my bad indeed.
>
>>
>> Have you tried looking through the kernel for other places where
>> UART_IIR_RX_TIMEOUT is referenced?  In 8250_omap.c and 8250_port.c I
>> believe you'll find it masking against 0x3f.  In omap-serial.c you'll
>> see a mask against 0x3e.
I just checked the 8250_omap case and the reason they mask against 0x3f 
is because they have 2 extra bits in the iir, e.g. the 'reserved' bits 
are not reserved there but used. So either 8250_omap is not based on the 
same designware IP or they added it ontop of the DW ip.

And thus, would the define be UART_IIR_MASK or UART_IIR_DW_MASK and 
UART_IIR_OMAP_MASK? Or do we, as mentioned earlier, rely on the fact 
that it is supposed to be reserved but always read as 0?

The 0x3e case seems to be where the busy flag is to be always ignored, 
so UART_IIR_NOBUSY_MASK? But also kind of ugly, as this is not a 
bitfield irq! so it should be changed there to read:

UART_IIR_BUSY: /* fallthrough */
default:
	break;

right?

>>
>> Looking at the TRM for rk3399, I see that bits 4 and 5 (bitmask 0x30)
>> as "reserved".  I see the following definitions for bits 3:0:
>>
>> 0000 = modem status
>> 0001 = no interrupt pending
>> 0010 = THR empty
>> 0100 = received data available
>> 0110 = receiver line status
>> 0111 = busy detect
>> 1100 = character timeout
>>
>> ...so while your patch will probably function OK, it would also
>> function equally well to simply test bit 3 (0x80) and ignore
>> everything else.  ...but IMHO it is more correct to at least mask the
>> IIR with 0x0F and confirm that bits 2 and 3 are set and bits 0 and 1
>> are zero.  ...and since the main 8250 code uses 0x3f, that seems even
>> better to me (despite the fact that it seems to be relying on the fact
>> that the "reserved" bits come back as 0).
>
> I strongly agree with you here, I did it wrong, but 0x3f really is wrong
> too imo. The bits to look at are 3:0, bits 4:5 are reserved and we
> should never look at those, as as you rightfully put it are being relied
> on to be 0 (which may always be the case) but imo is still wrong and
> thus the mask should be 0x0f.
>
> Going to the horse's mouth [0] which is the documentation of the IP
> block used in all these designs, they also say the same thing. 4 bits
> and while I don't have any of the other datasheets of other 8250 cores,
> I bet they are the same?
>
> And then, the following is actually wrong on the same grounds, from the
> 8250_dw.c
>
>
> if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
>
> This just happens to work as it is the only way this can match, but
> clearly it is wrong then, right?
>
> I'll check against the same mask of 0x0f here as well.
>>
>>
>> If you want to make a fix, I'd suggest adding a #define for 0x3f and
>> using it in various places.
> Yeah I'll do that, add the define next to the others for 0x0f, unless
> someone says it is a good idea (or needed idea) to mask against the
> reserved bits as well.
>
>>
>>
>>> Some very minor code cleanups, such as including the bitops header for
>>> DW_UART_MCR_SIRE, use the BIT() macro as suggested by checkpatc and
>>> removed a whitespace to match other invocations.
>>
>> Maybe it's just me, but it seems like a bad idea to combine these
>> cleanups in the same patch with a functional change..
> Well with the oversight of the bit check above, it becomes obvious that
> it is a bigger change indeed. I will change it!
>
> Olliver
>
>>
>
> [0] http://linux-sunxi.org/images/d/d2/Dw_apb_uart_db.pdf

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] serial: 8250_dw: Minor code cleanup
@ 2017-03-29 17:20       ` Olliver Schinagl
  0 siblings, 0 replies; 10+ messages in thread
From: Olliver Schinagl @ 2017-03-29 17:20 UTC (permalink / raw)
  To: Doug Anderson
  Cc: Greg Kroah-Hartman, Jiri Slaby, Kefeng Wang, Andy Shevchenko,
	Heikki Krogerus, Jason Uy, Heiko Stuebner, Ed Blake,
	linux-serial-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, dev-3kdeTeqwOZ9EV1b7eY7vFQ

Hey Doug,

On 29-03-17 19:10, Olliver Schinagl wrote:
> Hey Doug,
>
> On 29-03-17 17:50, Doug Anderson wrote:
>> Hi,
>>
>> On Wed, Mar 29, 2017 at 3:04 AM, Olliver Schinagl <oliver-dxLnbx3+1qmEVqv0pETR8A@public.gmane.org>
>> wrote:
>>> Commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from
>>> bogus rx timeout interrupt")
>>> added a bit check with quite a wide mask. To be concise with the other
>>> similar calls in this driver, change it to mask against the flag we
>>> want to
>>> check only. This thus removes a magic value/mask.
>>
>> How certain are you that your patch is correct?  You are now basically
>> checking to see if the bits "0xc" are set in the IIR.  Previously the
>> patch ensured that the bits 0x33 were clear.
>
> You raise a good point. And after writing two replies that made perfect
> sense, I just realized looking at the table you wisely posted below, I
> should have spotted that the interrupts are not bits! So very good catch
> and my bad indeed.
>
>>
>> Have you tried looking through the kernel for other places where
>> UART_IIR_RX_TIMEOUT is referenced?  In 8250_omap.c and 8250_port.c I
>> believe you'll find it masking against 0x3f.  In omap-serial.c you'll
>> see a mask against 0x3e.
I just checked the 8250_omap case and the reason they mask against 0x3f 
is because they have 2 extra bits in the iir, e.g. the 'reserved' bits 
are not reserved there but used. So either 8250_omap is not based on the 
same designware IP or they added it ontop of the DW ip.

And thus, would the define be UART_IIR_MASK or UART_IIR_DW_MASK and 
UART_IIR_OMAP_MASK? Or do we, as mentioned earlier, rely on the fact 
that it is supposed to be reserved but always read as 0?

The 0x3e case seems to be where the busy flag is to be always ignored, 
so UART_IIR_NOBUSY_MASK? But also kind of ugly, as this is not a 
bitfield irq! so it should be changed there to read:

UART_IIR_BUSY: /* fallthrough */
default:
	break;

right?

>>
>> Looking at the TRM for rk3399, I see that bits 4 and 5 (bitmask 0x30)
>> as "reserved".  I see the following definitions for bits 3:0:
>>
>> 0000 = modem status
>> 0001 = no interrupt pending
>> 0010 = THR empty
>> 0100 = received data available
>> 0110 = receiver line status
>> 0111 = busy detect
>> 1100 = character timeout
>>
>> ...so while your patch will probably function OK, it would also
>> function equally well to simply test bit 3 (0x80) and ignore
>> everything else.  ...but IMHO it is more correct to at least mask the
>> IIR with 0x0F and confirm that bits 2 and 3 are set and bits 0 and 1
>> are zero.  ...and since the main 8250 code uses 0x3f, that seems even
>> better to me (despite the fact that it seems to be relying on the fact
>> that the "reserved" bits come back as 0).
>
> I strongly agree with you here, I did it wrong, but 0x3f really is wrong
> too imo. The bits to look at are 3:0, bits 4:5 are reserved and we
> should never look at those, as as you rightfully put it are being relied
> on to be 0 (which may always be the case) but imo is still wrong and
> thus the mask should be 0x0f.
>
> Going to the horse's mouth [0] which is the documentation of the IP
> block used in all these designs, they also say the same thing. 4 bits
> and while I don't have any of the other datasheets of other 8250 cores,
> I bet they are the same?
>
> And then, the following is actually wrong on the same grounds, from the
> 8250_dw.c
>
>
> if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
>
> This just happens to work as it is the only way this can match, but
> clearly it is wrong then, right?
>
> I'll check against the same mask of 0x0f here as well.
>>
>>
>> If you want to make a fix, I'd suggest adding a #define for 0x3f and
>> using it in various places.
> Yeah I'll do that, add the define next to the others for 0x0f, unless
> someone says it is a good idea (or needed idea) to mask against the
> reserved bits as well.
>
>>
>>
>>> Some very minor code cleanups, such as including the bitops header for
>>> DW_UART_MCR_SIRE, use the BIT() macro as suggested by checkpatc and
>>> removed a whitespace to match other invocations.
>>
>> Maybe it's just me, but it seems like a bad idea to combine these
>> cleanups in the same patch with a functional change..
> Well with the oversight of the bit check above, it becomes obvious that
> it is a bigger change indeed. I will change it!
>
> Olliver
>
>>
>
> [0] http://linux-sunxi.org/images/d/d2/Dw_apb_uart_db.pdf

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] serial: 8250_dw: Minor code cleanup
@ 2017-03-29 18:38       ` Doug Anderson
  0 siblings, 0 replies; 10+ messages in thread
From: Doug Anderson @ 2017-03-29 18:38 UTC (permalink / raw)
  To: Olliver Schinagl
  Cc: Greg Kroah-Hartman, Jiri Slaby, Kefeng Wang, Andy Shevchenko,
	Heikki Krogerus, Jason Uy, Heiko Stuebner, Ed Blake,
	linux-serial, linux-kernel, dev

Hi,

On Wed, Mar 29, 2017 at 10:10 AM, Olliver Schinagl
<o.schinagl@ultimaker.com> wrote:
> Hey Doug,
>
> On 29-03-17 17:50, Doug Anderson wrote:
>>
>> Hi,
>>
>> On Wed, Mar 29, 2017 at 3:04 AM, Olliver Schinagl <oliver@schinagl.nl>
>> wrote:
>>>
>>> Commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from bogus
>>> rx timeout interrupt")
>>> added a bit check with quite a wide mask. To be concise with the other
>>> similar calls in this driver, change it to mask against the flag we want
>>> to
>>> check only. This thus removes a magic value/mask.
>>
>>
>> How certain are you that your patch is correct?  You are now basically
>> checking to see if the bits "0xc" are set in the IIR.  Previously the
>> patch ensured that the bits 0x33 were clear.
>
>
> You raise a good point. And after writing two replies that made perfect
> sense, I just realized looking at the table you wisely posted below, I
> should have spotted that the interrupts are not bits! So very good catch and
> my bad indeed.
>
>>
>> Have you tried looking through the kernel for other places where
>> UART_IIR_RX_TIMEOUT is referenced?  In 8250_omap.c and 8250_port.c I
>> believe you'll find it masking against 0x3f.  In omap-serial.c you'll
>> see a mask against 0x3e.
>>
>> Looking at the TRM for rk3399, I see that bits 4 and 5 (bitmask 0x30)
>> as "reserved".  I see the following definitions for bits 3:0:
>>
>> 0000 = modem status
>> 0001 = no interrupt pending
>> 0010 = THR empty
>> 0100 = received data available
>> 0110 = receiver line status
>> 0111 = busy detect
>> 1100 = character timeout
>>
>> ...so while your patch will probably function OK, it would also
>> function equally well to simply test bit 3 (0x80) and ignore
>> everything else.  ...but IMHO it is more correct to at least mask the
>> IIR with 0x0F and confirm that bits 2 and 3 are set and bits 0 and 1
>> are zero.  ...and since the main 8250 code uses 0x3f, that seems even
>> better to me (despite the fact that it seems to be relying on the fact
>> that the "reserved" bits come back as 0).
>
>
> I strongly agree with you here, I did it wrong, but 0x3f really is wrong too
> imo. The bits to look at are 3:0, bits 4:5 are reserved and we should never
> look at those, as as you rightfully put it are being relied on to be 0
> (which may always be the case) but imo is still wrong and thus the mask
> should be 0x0f.

Personally I can't predict which would be better: 0xf or 0x3f.
Certainly someone wrote handle_rx_dma() purposely masking against 0x3f
rather than 0xf, probably because they were trying to handle:

#define UART_IIR_XOFF           0x10 /* OMAP XOFF/Special Character */
#define UART_IIR_CTS_RTS_DSR    0x20 /* OMAP CTS/RTS/DSR Change */

...so in our case we don't have those special OMAP IIR bits, so we
likely don't need 0x3f and 0x0f would work fine.

...but one could also argue this:

1. If anyone enables DMA on a dw_8250 then they'll run the code in
handle_rx_dma() which masks against 0x3f.  ...so that implies that if
those reserved bits are even non-zero we're already broken (assuming
we use DMA).

2. It might be better to be consistent than to have two different values here.


Perhaps the absolute "cleanest" way would be to store a "interrupt ID
mask" somewhere and have it default to 0xf.  ...then OMAP can override
it to 0x3f or 0x3e or whatever.


Anyway, this is the type of discussion that takes a lot of time to
talk about but it probably won't actually affect correctness much one
way or the other.  If you want to change this to 0xf then I'm not
opposed to it, though I personally wouldn't bother until it becomes a
problem.


> Going to the horse's mouth [0] which is the documentation of the IP block
> used in all these designs, they also say the same thing. 4 bits and while I
> don't have any of the other datasheets of other 8250 cores, I bet they are
> the same?

Everyone has extended 8250 in their own special ways, so I'm not
convinced they'll all be the same.

>
> And then, the following is actually wrong on the same grounds, from the
> 8250_dw.c
>
>
> if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
>
> This just happens to work as it is the only way this can match, but clearly
> it is wrong then, right?
>
> I'll check against the same mask of 0x0f here as well.

On the 8250 datasheet I have it is clearly wrong.  There are lots and
lots of 8250 devices out there and they all have their own "special"
IP, so presumably you'll want lots of testing if you touch this.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] serial: 8250_dw: Minor code cleanup
@ 2017-03-29 18:38       ` Doug Anderson
  0 siblings, 0 replies; 10+ messages in thread
From: Doug Anderson @ 2017-03-29 18:38 UTC (permalink / raw)
  To: Olliver Schinagl
  Cc: Greg Kroah-Hartman, Jiri Slaby, Kefeng Wang, Andy Shevchenko,
	Heikki Krogerus, Jason Uy, Heiko Stuebner, Ed Blake,
	linux-serial-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, dev-3kdeTeqwOZ9EV1b7eY7vFQ

Hi,

On Wed, Mar 29, 2017 at 10:10 AM, Olliver Schinagl
<o.schinagl-U3FVU11NWA554TAoqtyWWQ@public.gmane.org> wrote:
> Hey Doug,
>
> On 29-03-17 17:50, Doug Anderson wrote:
>>
>> Hi,
>>
>> On Wed, Mar 29, 2017 at 3:04 AM, Olliver Schinagl <oliver-dxLnbx3+1qmEVqv0pETR8A@public.gmane.org>
>> wrote:
>>>
>>> Commit 424d79183af0 ("serial: 8250_dw: Avoid "too much work" from bogus
>>> rx timeout interrupt")
>>> added a bit check with quite a wide mask. To be concise with the other
>>> similar calls in this driver, change it to mask against the flag we want
>>> to
>>> check only. This thus removes a magic value/mask.
>>
>>
>> How certain are you that your patch is correct?  You are now basically
>> checking to see if the bits "0xc" are set in the IIR.  Previously the
>> patch ensured that the bits 0x33 were clear.
>
>
> You raise a good point. And after writing two replies that made perfect
> sense, I just realized looking at the table you wisely posted below, I
> should have spotted that the interrupts are not bits! So very good catch and
> my bad indeed.
>
>>
>> Have you tried looking through the kernel for other places where
>> UART_IIR_RX_TIMEOUT is referenced?  In 8250_omap.c and 8250_port.c I
>> believe you'll find it masking against 0x3f.  In omap-serial.c you'll
>> see a mask against 0x3e.
>>
>> Looking at the TRM for rk3399, I see that bits 4 and 5 (bitmask 0x30)
>> as "reserved".  I see the following definitions for bits 3:0:
>>
>> 0000 = modem status
>> 0001 = no interrupt pending
>> 0010 = THR empty
>> 0100 = received data available
>> 0110 = receiver line status
>> 0111 = busy detect
>> 1100 = character timeout
>>
>> ...so while your patch will probably function OK, it would also
>> function equally well to simply test bit 3 (0x80) and ignore
>> everything else.  ...but IMHO it is more correct to at least mask the
>> IIR with 0x0F and confirm that bits 2 and 3 are set and bits 0 and 1
>> are zero.  ...and since the main 8250 code uses 0x3f, that seems even
>> better to me (despite the fact that it seems to be relying on the fact
>> that the "reserved" bits come back as 0).
>
>
> I strongly agree with you here, I did it wrong, but 0x3f really is wrong too
> imo. The bits to look at are 3:0, bits 4:5 are reserved and we should never
> look at those, as as you rightfully put it are being relied on to be 0
> (which may always be the case) but imo is still wrong and thus the mask
> should be 0x0f.

Personally I can't predict which would be better: 0xf or 0x3f.
Certainly someone wrote handle_rx_dma() purposely masking against 0x3f
rather than 0xf, probably because they were trying to handle:

#define UART_IIR_XOFF           0x10 /* OMAP XOFF/Special Character */
#define UART_IIR_CTS_RTS_DSR    0x20 /* OMAP CTS/RTS/DSR Change */

...so in our case we don't have those special OMAP IIR bits, so we
likely don't need 0x3f and 0x0f would work fine.

...but one could also argue this:

1. If anyone enables DMA on a dw_8250 then they'll run the code in
handle_rx_dma() which masks against 0x3f.  ...so that implies that if
those reserved bits are even non-zero we're already broken (assuming
we use DMA).

2. It might be better to be consistent than to have two different values here.


Perhaps the absolute "cleanest" way would be to store a "interrupt ID
mask" somewhere and have it default to 0xf.  ...then OMAP can override
it to 0x3f or 0x3e or whatever.


Anyway, this is the type of discussion that takes a lot of time to
talk about but it probably won't actually affect correctness much one
way or the other.  If you want to change this to 0xf then I'm not
opposed to it, though I personally wouldn't bother until it becomes a
problem.


> Going to the horse's mouth [0] which is the documentation of the IP block
> used in all these designs, they also say the same thing. 4 bits and while I
> don't have any of the other datasheets of other 8250 cores, I bet they are
> the same?

Everyone has extended 8250 in their own special ways, so I'm not
convinced they'll all be the same.

>
> And then, the following is actually wrong on the same grounds, from the
> 8250_dw.c
>
>
> if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
>
> This just happens to work as it is the only way this can match, but clearly
> it is wrong then, right?
>
> I'll check against the same mask of 0x0f here as well.

On the 8250 datasheet I have it is clearly wrong.  There are lots and
lots of 8250 devices out there and they all have their own "special"
IP, so presumably you'll want lots of testing if you touch this.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-03-29 18:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-29 10:04 [PATCH] serial: 8250_dw: Minor code cleanup Olliver Schinagl
2017-03-29 10:04 ` Olliver Schinagl
2017-03-29 15:50 ` Doug Anderson
2017-03-29 15:50   ` Doug Anderson
2017-03-29 17:10   ` Olliver Schinagl
2017-03-29 17:10     ` Olliver Schinagl
2017-03-29 17:20     ` Olliver Schinagl
2017-03-29 17:20       ` Olliver Schinagl
2017-03-29 18:38     ` Doug Anderson
2017-03-29 18:38       ` Doug Anderson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.