diff mbox series

[2/2,v2] alpha: add a delay before serial port read

Message ID alpine.LRH.2.02.2005061122440.16395@file01.intranet.prod.int.rdu2.redhat.com
State Not Applicable
Headers show
Series None | expand

Commit Message

Mikulas Patocka May 6, 2020, 3:29 p.m. UTC
On Wed, 6 May 2020, Greg Kroah-Hartman wrote:

> > Index: linux-stable/drivers/tty/serial/8250/8250_port.c
> > ===================================================================
> > --- linux-stable.orig/drivers/tty/serial/8250/8250_port.c	2020-05-06 08:25:19.000000000 +0200
> > +++ linux-stable/drivers/tty/serial/8250/8250_port.c	2020-05-06 09:04:17.000000000 +0200
> > @@ -442,6 +442,10 @@ static unsigned int mem32be_serial_in(st
> >  
> >  static unsigned int io_serial_in(struct uart_port *p, int offset)
> >  {
> > +#ifdef CONFIG_ALPHA
> > +/* we need a small delay, the Alpha Avanti chipset locks up with back-to-back accesses */
> > +	ndelay(300);
> > +#endif
> 
> We really do not like #ifdef in .c files, especially ones that cause a
> coding style violation :)
> 
> Why can't you do this as a quirk for this specific chipset?  You should
> tie it to the serial port hardware type, not to the CPU type.
> 
> thanks,
> 
> greg k-h

Do you want this patch? It enables the delay based on the specific PCI-ISA 
bridge.

There is still "#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)" because 
if we want to reference a variable defined by the PCI subsystem in the 
arch/alpha tree, we must do it conditionally. If you want to get rid of 
these #ifs, please describe how.

Mikulas


From: Mikulas Patocka <mpatocka@redhat.com>

The patch 92d7223a74235054f2aa7227d207d9c57f84dca0 ("alpha: io: reorder
barriers to guarantee writeX() and iowriteX() ordering #2") broke boot on
the Alpha Avanti platform.

The patch changes timing between accesses to the ISA bus, in particular,
it reduces the time between "write" access and a subsequent "read" access.

This causes lock-up when accessing the real time clock and serial ports.

This patch fixes the serial ports by adding a small delay before the "inb"
instruction.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: 92d7223a7423 ("alpha: io: reorder barriers to guarantee writeX() and iowriteX() ordering #2")
Cc: stable@vger.kernel.org	# v4.17+

---
 arch/alpha/include/asm/pci.h        |    2 ++
 arch/alpha/kernel/pci.c             |    4 ++++
 drivers/tty/serial/8250/8250_core.c |    7 +++++++
 drivers/tty/serial/8250/8250_port.c |    3 +++
 include/linux/serial_core.h         |    1 +
 5 files changed, 17 insertions(+)

Comments

Greg Kroah-Hartman May 6, 2020, 3:49 p.m. UTC | #1
On Wed, May 06, 2020 at 11:29:29AM -0400, Mikulas Patocka wrote:
> 
> 
> On Wed, 6 May 2020, Greg Kroah-Hartman wrote:
> 
> > > Index: linux-stable/drivers/tty/serial/8250/8250_port.c
> > > ===================================================================
> > > --- linux-stable.orig/drivers/tty/serial/8250/8250_port.c	2020-05-06 08:25:19.000000000 +0200
> > > +++ linux-stable/drivers/tty/serial/8250/8250_port.c	2020-05-06 09:04:17.000000000 +0200
> > > @@ -442,6 +442,10 @@ static unsigned int mem32be_serial_in(st
> > >  
> > >  static unsigned int io_serial_in(struct uart_port *p, int offset)
> > >  {
> > > +#ifdef CONFIG_ALPHA
> > > +/* we need a small delay, the Alpha Avanti chipset locks up with back-to-back accesses */
> > > +	ndelay(300);
> > > +#endif
> > 
> > We really do not like #ifdef in .c files, especially ones that cause a
> > coding style violation :)
> > 
> > Why can't you do this as a quirk for this specific chipset?  You should
> > tie it to the serial port hardware type, not to the CPU type.
> > 
> > thanks,
> > 
> > greg k-h
> 
> Do you want this patch? It enables the delay based on the specific PCI-ISA 
> bridge.
> 
> There is still "#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)" because 
> if we want to reference a variable defined by the PCI subsystem in the 
> arch/alpha tree, we must do it conditionally. If you want to get rid of 
> these #ifs, please describe how.
> 
> Mikulas
> 
> 
> From: Mikulas Patocka <mpatocka@redhat.com>
> 
> The patch 92d7223a74235054f2aa7227d207d9c57f84dca0 ("alpha: io: reorder
> barriers to guarantee writeX() and iowriteX() ordering #2") broke boot on
> the Alpha Avanti platform.
> 
> The patch changes timing between accesses to the ISA bus, in particular,
> it reduces the time between "write" access and a subsequent "read" access.
> 
> This causes lock-up when accessing the real time clock and serial ports.
> 
> This patch fixes the serial ports by adding a small delay before the "inb"
> instruction.
> 
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Fixes: 92d7223a7423 ("alpha: io: reorder barriers to guarantee writeX() and iowriteX() ordering #2")
> Cc: stable@vger.kernel.org	# v4.17+
> 
> ---
>  arch/alpha/include/asm/pci.h        |    2 ++
>  arch/alpha/kernel/pci.c             |    4 ++++
>  drivers/tty/serial/8250/8250_core.c |    7 +++++++
>  drivers/tty/serial/8250/8250_port.c |    3 +++
>  include/linux/serial_core.h         |    1 +
>  5 files changed, 17 insertions(+)
> 
> Index: linux-stable/include/linux/serial_core.h
> ===================================================================
> --- linux-stable.orig/include/linux/serial_core.h	2020-05-06 17:16:28.000000000 +0200
> +++ linux-stable/include/linux/serial_core.h	2020-05-06 17:16:28.000000000 +0200
> @@ -154,6 +154,7 @@ struct uart_port {
>  
>  	/* quirks must be updated while holding port mutex */
>  #define UPQ_NO_TXEN_TEST	BIT(0)
> +#define UPQ_DELAY_BEFORE_READ	BIT(1)
>  
>  	unsigned int		read_status_mask;	/* driver specific */
>  	unsigned int		ignore_status_mask;	/* driver specific */
> Index: linux-stable/drivers/tty/serial/8250/8250_core.c
> ===================================================================
> --- linux-stable.orig/drivers/tty/serial/8250/8250_core.c	2020-05-06 17:16:28.000000000 +0200
> +++ linux-stable/drivers/tty/serial/8250/8250_core.c	2020-05-06 17:16:28.000000000 +0200
> @@ -37,6 +37,9 @@
>  #ifdef CONFIG_SPARC
>  #include <linux/sunserialcore.h>
>  #endif
> +#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)
> +#include <linux/pci.h>
> +#endif

Don't need the #if for this.

>  
>  #include <asm/irq.h>
>  
> @@ -490,6 +493,10 @@ static void univ8250_rsa_support(struct
>  static inline void serial8250_apply_quirks(struct uart_8250_port *up)
>  {
>  	up->port.quirks |= skip_txen_test ? UPQ_NO_TXEN_TEST : 0;
> +#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)
> +	if (alpha_serial_port_needs_delay)
> +		up->port.quirks |= UPQ_DELAY_BEFORE_READ;
> +#endif

Why is a #define needed here?

You can do this same type of change without any #ifdefs in any .c files
and that would be much nicer.

thanks,

greg k-h
Mikulas Patocka May 6, 2020, 3:57 p.m. UTC | #2
On Wed, 6 May 2020, Greg Kroah-Hartman wrote:

> On Wed, May 06, 2020 at 11:29:29AM -0400, Mikulas Patocka wrote:
> > 
> > 
> > On Wed, 6 May 2020, Greg Kroah-Hartman wrote:
> > 
> > > > Index: linux-stable/drivers/tty/serial/8250/8250_port.c
> > > > ===================================================================
> > > > --- linux-stable.orig/drivers/tty/serial/8250/8250_port.c	2020-05-06 08:25:19.000000000 +0200
> > > > +++ linux-stable/drivers/tty/serial/8250/8250_port.c	2020-05-06 09:04:17.000000000 +0200
> > > > @@ -442,6 +442,10 @@ static unsigned int mem32be_serial_in(st
> > > >  
> > > >  static unsigned int io_serial_in(struct uart_port *p, int offset)
> > > >  {
> > > > +#ifdef CONFIG_ALPHA
> > > > +/* we need a small delay, the Alpha Avanti chipset locks up with back-to-back accesses */
> > > > +	ndelay(300);
> > > > +#endif
> > > 
> > > We really do not like #ifdef in .c files, especially ones that cause a
> > > coding style violation :)
> > > 
> > > Why can't you do this as a quirk for this specific chipset?  You should
> > > tie it to the serial port hardware type, not to the CPU type.
> > > 
> > > thanks,
> > > 
> > > greg k-h
> > 
> > Do you want this patch? It enables the delay based on the specific PCI-ISA 
> > bridge.
> > 
> > There is still "#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)" because 
> > if we want to reference a variable defined by the PCI subsystem in the 
> > arch/alpha tree, we must do it conditionally. If you want to get rid of 
> > these #ifs, please describe how.
> > 
> > Mikulas
> > 
> > 
> > From: Mikulas Patocka <mpatocka@redhat.com>
> > 
> > The patch 92d7223a74235054f2aa7227d207d9c57f84dca0 ("alpha: io: reorder
> > barriers to guarantee writeX() and iowriteX() ordering #2") broke boot on
> > the Alpha Avanti platform.
> > 
> > The patch changes timing between accesses to the ISA bus, in particular,
> > it reduces the time between "write" access and a subsequent "read" access.
> > 
> > This causes lock-up when accessing the real time clock and serial ports.
> > 
> > This patch fixes the serial ports by adding a small delay before the "inb"
> > instruction.
> > 
> > Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> > Fixes: 92d7223a7423 ("alpha: io: reorder barriers to guarantee writeX() and iowriteX() ordering #2")
> > Cc: stable@vger.kernel.org	# v4.17+
> > 
> > ---
> >  arch/alpha/include/asm/pci.h        |    2 ++
> >  arch/alpha/kernel/pci.c             |    4 ++++
> >  drivers/tty/serial/8250/8250_core.c |    7 +++++++
> >  drivers/tty/serial/8250/8250_port.c |    3 +++
> >  include/linux/serial_core.h         |    1 +
> >  5 files changed, 17 insertions(+)
> > 
> > Index: linux-stable/include/linux/serial_core.h
> > ===================================================================
> > --- linux-stable.orig/include/linux/serial_core.h	2020-05-06 17:16:28.000000000 +0200
> > +++ linux-stable/include/linux/serial_core.h	2020-05-06 17:16:28.000000000 +0200
> > @@ -154,6 +154,7 @@ struct uart_port {
> >  
> >  	/* quirks must be updated while holding port mutex */
> >  #define UPQ_NO_TXEN_TEST	BIT(0)
> > +#define UPQ_DELAY_BEFORE_READ	BIT(1)
> >  
> >  	unsigned int		read_status_mask;	/* driver specific */
> >  	unsigned int		ignore_status_mask;	/* driver specific */
> > Index: linux-stable/drivers/tty/serial/8250/8250_core.c
> > ===================================================================
> > --- linux-stable.orig/drivers/tty/serial/8250/8250_core.c	2020-05-06 17:16:28.000000000 +0200
> > +++ linux-stable/drivers/tty/serial/8250/8250_core.c	2020-05-06 17:16:28.000000000 +0200
> > @@ -37,6 +37,9 @@
> >  #ifdef CONFIG_SPARC
> >  #include <linux/sunserialcore.h>
> >  #endif
> > +#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)
> > +#include <linux/pci.h>
> > +#endif
> 
> Don't need the #if for this.

You're right.

> >  #include <asm/irq.h>
> >  
> > @@ -490,6 +493,10 @@ static void univ8250_rsa_support(struct
> >  static inline void serial8250_apply_quirks(struct uart_8250_port *up)
> >  {
> >  	up->port.quirks |= skip_txen_test ? UPQ_NO_TXEN_TEST : 0;
> > +#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)
> > +	if (alpha_serial_port_needs_delay)
> > +		up->port.quirks |= UPQ_DELAY_BEFORE_READ;
> > +#endif
> 
> Why is a #define needed here?
> 
> You can do this same type of change without any #ifdefs in any .c files
> and that would be much nicer.

Because alpha_serial_port_needs_delay is defined only on Alpha - so we 
need to guard accesses to it with #ifdef CONFIG_ALPHA - otherwise the 
kernel wouldn't link on non-Alpha platforms.

Should I make it defined for all architectures?

Mikulas
Greg Kroah-Hartman May 6, 2020, 4:08 p.m. UTC | #3
On Wed, May 06, 2020 at 11:57:08AM -0400, Mikulas Patocka wrote:
> 
> 
> On Wed, 6 May 2020, Greg Kroah-Hartman wrote:
> 
> > On Wed, May 06, 2020 at 11:29:29AM -0400, Mikulas Patocka wrote:
> > > 
> > > 
> > > On Wed, 6 May 2020, Greg Kroah-Hartman wrote:
> > > 
> > > > > Index: linux-stable/drivers/tty/serial/8250/8250_port.c
> > > > > ===================================================================
> > > > > --- linux-stable.orig/drivers/tty/serial/8250/8250_port.c	2020-05-06 08:25:19.000000000 +0200
> > > > > +++ linux-stable/drivers/tty/serial/8250/8250_port.c	2020-05-06 09:04:17.000000000 +0200
> > > > > @@ -442,6 +442,10 @@ static unsigned int mem32be_serial_in(st
> > > > >  
> > > > >  static unsigned int io_serial_in(struct uart_port *p, int offset)
> > > > >  {
> > > > > +#ifdef CONFIG_ALPHA
> > > > > +/* we need a small delay, the Alpha Avanti chipset locks up with back-to-back accesses */
> > > > > +	ndelay(300);
> > > > > +#endif
> > > > 
> > > > We really do not like #ifdef in .c files, especially ones that cause a
> > > > coding style violation :)
> > > > 
> > > > Why can't you do this as a quirk for this specific chipset?  You should
> > > > tie it to the serial port hardware type, not to the CPU type.
> > > > 
> > > > thanks,
> > > > 
> > > > greg k-h
> > > 
> > > Do you want this patch? It enables the delay based on the specific PCI-ISA 
> > > bridge.
> > > 
> > > There is still "#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)" because 
> > > if we want to reference a variable defined by the PCI subsystem in the 
> > > arch/alpha tree, we must do it conditionally. If you want to get rid of 
> > > these #ifs, please describe how.
> > > 
> > > Mikulas
> > > 
> > > 
> > > From: Mikulas Patocka <mpatocka@redhat.com>
> > > 
> > > The patch 92d7223a74235054f2aa7227d207d9c57f84dca0 ("alpha: io: reorder
> > > barriers to guarantee writeX() and iowriteX() ordering #2") broke boot on
> > > the Alpha Avanti platform.
> > > 
> > > The patch changes timing between accesses to the ISA bus, in particular,
> > > it reduces the time between "write" access and a subsequent "read" access.
> > > 
> > > This causes lock-up when accessing the real time clock and serial ports.
> > > 
> > > This patch fixes the serial ports by adding a small delay before the "inb"
> > > instruction.
> > > 
> > > Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> > > Fixes: 92d7223a7423 ("alpha: io: reorder barriers to guarantee writeX() and iowriteX() ordering #2")
> > > Cc: stable@vger.kernel.org	# v4.17+
> > > 
> > > ---
> > >  arch/alpha/include/asm/pci.h        |    2 ++
> > >  arch/alpha/kernel/pci.c             |    4 ++++
> > >  drivers/tty/serial/8250/8250_core.c |    7 +++++++
> > >  drivers/tty/serial/8250/8250_port.c |    3 +++
> > >  include/linux/serial_core.h         |    1 +
> > >  5 files changed, 17 insertions(+)
> > > 
> > > Index: linux-stable/include/linux/serial_core.h
> > > ===================================================================
> > > --- linux-stable.orig/include/linux/serial_core.h	2020-05-06 17:16:28.000000000 +0200
> > > +++ linux-stable/include/linux/serial_core.h	2020-05-06 17:16:28.000000000 +0200
> > > @@ -154,6 +154,7 @@ struct uart_port {
> > >  
> > >  	/* quirks must be updated while holding port mutex */
> > >  #define UPQ_NO_TXEN_TEST	BIT(0)
> > > +#define UPQ_DELAY_BEFORE_READ	BIT(1)
> > >  
> > >  	unsigned int		read_status_mask;	/* driver specific */
> > >  	unsigned int		ignore_status_mask;	/* driver specific */
> > > Index: linux-stable/drivers/tty/serial/8250/8250_core.c
> > > ===================================================================
> > > --- linux-stable.orig/drivers/tty/serial/8250/8250_core.c	2020-05-06 17:16:28.000000000 +0200
> > > +++ linux-stable/drivers/tty/serial/8250/8250_core.c	2020-05-06 17:16:28.000000000 +0200
> > > @@ -37,6 +37,9 @@
> > >  #ifdef CONFIG_SPARC
> > >  #include <linux/sunserialcore.h>
> > >  #endif
> > > +#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)
> > > +#include <linux/pci.h>
> > > +#endif
> > 
> > Don't need the #if for this.
> 
> You're right.
> 
> > >  #include <asm/irq.h>
> > >  
> > > @@ -490,6 +493,10 @@ static void univ8250_rsa_support(struct
> > >  static inline void serial8250_apply_quirks(struct uart_8250_port *up)
> > >  {
> > >  	up->port.quirks |= skip_txen_test ? UPQ_NO_TXEN_TEST : 0;
> > > +#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)
> > > +	if (alpha_serial_port_needs_delay)
> > > +		up->port.quirks |= UPQ_DELAY_BEFORE_READ;
> > > +#endif
> > 
> > Why is a #define needed here?
> > 
> > You can do this same type of change without any #ifdefs in any .c files
> > and that would be much nicer.
> 
> Because alpha_serial_port_needs_delay is defined only on Alpha - so we 
> need to guard accesses to it with #ifdef CONFIG_ALPHA - otherwise the 
> kernel wouldn't link on non-Alpha platforms.
> 
> Should I make it defined for all architectures?

Yes, it's not the first time we have had to do things like this :)

But, there is no other way to detect this based on hardware
signatures/types instead?  That is usually the best way to do it, right?

thanks,

greg k-h
diff mbox series

Patch

Index: linux-stable/include/linux/serial_core.h
===================================================================
--- linux-stable.orig/include/linux/serial_core.h	2020-05-06 17:16:28.000000000 +0200
+++ linux-stable/include/linux/serial_core.h	2020-05-06 17:16:28.000000000 +0200
@@ -154,6 +154,7 @@  struct uart_port {
 
 	/* quirks must be updated while holding port mutex */
 #define UPQ_NO_TXEN_TEST	BIT(0)
+#define UPQ_DELAY_BEFORE_READ	BIT(1)
 
 	unsigned int		read_status_mask;	/* driver specific */
 	unsigned int		ignore_status_mask;	/* driver specific */
Index: linux-stable/drivers/tty/serial/8250/8250_core.c
===================================================================
--- linux-stable.orig/drivers/tty/serial/8250/8250_core.c	2020-05-06 17:16:28.000000000 +0200
+++ linux-stable/drivers/tty/serial/8250/8250_core.c	2020-05-06 17:16:28.000000000 +0200
@@ -37,6 +37,9 @@ 
 #ifdef CONFIG_SPARC
 #include <linux/sunserialcore.h>
 #endif
+#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)
+#include <linux/pci.h>
+#endif
 
 #include <asm/irq.h>
 
@@ -490,6 +493,10 @@  static void univ8250_rsa_support(struct
 static inline void serial8250_apply_quirks(struct uart_8250_port *up)
 {
 	up->port.quirks |= skip_txen_test ? UPQ_NO_TXEN_TEST : 0;
+#if defined(CONFIG_ALPHA) && defined(CONFIG_PCI)
+	if (alpha_serial_port_needs_delay)
+		up->port.quirks |= UPQ_DELAY_BEFORE_READ;
+#endif
 }
 
 static void __init serial8250_isa_init_ports(void)
Index: linux-stable/arch/alpha/include/asm/pci.h
===================================================================
--- linux-stable.orig/arch/alpha/include/asm/pci.h	2020-05-06 17:16:28.000000000 +0200
+++ linux-stable/arch/alpha/include/asm/pci.h	2020-05-06 17:16:28.000000000 +0200
@@ -97,4 +97,6 @@  extern void pci_adjust_legacy_attr(struc
 extern int pci_create_resource_files(struct pci_dev *dev);
 extern void pci_remove_resource_files(struct pci_dev *dev);
 
+extern int alpha_serial_port_needs_delay;
+
 #endif /* __ALPHA_PCI_H */
Index: linux-stable/arch/alpha/kernel/pci.c
===================================================================
--- linux-stable.orig/arch/alpha/kernel/pci.c	2020-05-06 17:16:28.000000000 +0200
+++ linux-stable/arch/alpha/kernel/pci.c	2020-05-06 17:16:28.000000000 +0200
@@ -61,9 +61,13 @@  struct pci_controller *pci_isa_hose;
  * Quirks.
  */
 
+int alpha_serial_port_needs_delay = 0;
+EXPORT_SYMBOL(alpha_serial_port_needs_delay);
+
 static void quirk_isa_bridge(struct pci_dev *dev)
 {
 	dev->class = PCI_CLASS_BRIDGE_ISA << 8;
+	alpha_serial_port_needs_delay = 1;
 }
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82378, quirk_isa_bridge);
 
Index: linux-stable/drivers/tty/serial/8250/8250_port.c
===================================================================
--- linux-stable.orig/drivers/tty/serial/8250/8250_port.c	2020-05-06 17:16:28.000000000 +0200
+++ linux-stable/drivers/tty/serial/8250/8250_port.c	2020-05-06 17:16:32.000000000 +0200
@@ -442,6 +442,9 @@  static unsigned int mem32be_serial_in(st
 
 static unsigned int io_serial_in(struct uart_port *p, int offset)
 {
+	if (unlikely(p->quirks & UPQ_DELAY_BEFORE_READ))
+		ndelay(300);
+
 	offset = offset << p->regshift;
 	return inb(p->iobase + offset);
 }