linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mikulas Patocka <mpatocka@redhat.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Richard Henderson <rth@twiddle.net>,
	Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
	Matt Turner <mattst88@gmail.com>,
	linux-alpha@vger.kernel.org, Sinan Kaya <okaya@codeaurora.org>,
	Arnd Bergmann <arnd@arndb.de>,
	linux-serial@vger.kernel.org, linux-rtc@vger.kernel.org
Subject: [PATCH 2/2 v3] alpha: add a delay before serial port read
Date: Wed, 6 May 2020 13:04:38 -0400 (EDT)	[thread overview]
Message-ID: <alpine.LRH.2.02.2005061245500.18599@file01.intranet.prod.int.rdu2.redhat.com> (raw)
In-Reply-To: <20200506160823.GA3559699@kroah.com>



On Wed, 6 May 2020, Greg Kroah-Hartman wrote:

> 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:
> > > > 
> > > > @@ -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 :)

I've created this patch that adds a global macro/variable 
serial_port_needs_delay. I've also deleted UPQ_DELAY_BEFORE_READ and test 
serial_port_needs_delay directly in io_serial_in, so that the compiler 
will optimize it out on non-alpha architectures.

> 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?

It's hard to detect Alpha without using '#ifdef CONFIG_ALPHA' :) The ISA 
serial port hardware is simple, so I think that you can't distinguish it 
just based on its behavior.

> thanks,
> 
> greg k-h
> 


From: Mikulas Patocka <mpatocka@redhat.com>

alpha: add a delay before serial port read

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        |    3 +++
 arch/alpha/kernel/pci.c             |    4 ++++
 drivers/tty/serial/8250/8250_port.c |    4 ++++
 include/linux/pci.h                 |    4 ++++
 4 files changed, 15 insertions(+)

Index: linux-stable/arch/alpha/include/asm/pci.h
===================================================================
--- linux-stable.orig/arch/alpha/include/asm/pci.h	2020-05-06 18:54:24.000000000 +0200
+++ linux-stable/arch/alpha/include/asm/pci.h	2020-05-06 18:54:24.000000000 +0200
@@ -97,4 +97,7 @@ 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 serial_port_needs_delay;
+#define serial_port_needs_delay	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 18:54:24.000000000 +0200
+++ linux-stable/arch/alpha/kernel/pci.c	2020-05-06 18:54:24.000000000 +0200
@@ -61,9 +61,13 @@ struct pci_controller *pci_isa_hose;
  * Quirks.
  */
 
+int serial_port_needs_delay = 0;
+EXPORT_SYMBOL(serial_port_needs_delay);
+
 static void quirk_isa_bridge(struct pci_dev *dev)
 {
 	dev->class = PCI_CLASS_BRIDGE_ISA << 8;
+	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 18:54:24.000000000 +0200
+++ linux-stable/drivers/tty/serial/8250/8250_port.c	2020-05-06 18:54:24.000000000 +0200
@@ -30,6 +30,7 @@
 #include <linux/uaccess.h>
 #include <linux/pm_runtime.h>
 #include <linux/ktime.h>
+#include <linux/pci.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -442,6 +443,9 @@ static unsigned int mem32be_serial_in(st
 
 static unsigned int io_serial_in(struct uart_port *p, int offset)
 {
+	if (serial_port_needs_delay)
+		ndelay(300);
+
 	offset = offset << p->regshift;
 	return inb(p->iobase + offset);
 }
Index: linux-stable/include/linux/pci.h
===================================================================
--- linux-stable.orig/include/linux/pci.h	2020-05-06 18:54:24.000000000 +0200
+++ linux-stable/include/linux/pci.h	2020-05-06 18:54:24.000000000 +0200
@@ -2384,6 +2384,10 @@ static inline bool pci_is_thunderbolt_at
 	return false;
 }
 
+#ifndef serial_port_needs_delay
+#define serial_port_needs_delay	0
+#endif
+
 #if defined(CONFIG_PCIEPORTBUS) || defined(CONFIG_EEH)
 void pci_uevent_ers(struct pci_dev *pdev, enum  pci_ers_result err_type);
 #endif


  reply	other threads:[~2020-05-06 17:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-06 11:23 [PATCH 2/2] alpha: add a delay before serial port read Mikulas Patocka
2020-05-06 11:47 ` Greg Kroah-Hartman
2020-05-06 15:29   ` [PATCH 2/2 v2] " Mikulas Patocka
2020-05-06 15:49     ` Greg Kroah-Hartman
2020-05-06 15:57       ` Mikulas Patocka
2020-05-06 16:08         ` Greg Kroah-Hartman
2020-05-06 17:04           ` Mikulas Patocka [this message]
2020-05-06 17:45             ` [PATCH 2/2 v3] " Greg Kroah-Hartman
2020-05-07  8:18               ` [PATCH 2/2 v4] " Mikulas Patocka
2020-05-07  8:52                 ` Greg Kroah-Hartman
2020-05-07 10:53                   ` Mikulas Patocka
2020-05-07 11:10                     ` Greg Kroah-Hartman
2020-05-07 12:53                       ` Mikulas Patocka
2020-05-07 12:57                       ` [PATCH 2/2 v5] " Mikulas Patocka
2020-05-07 13:58                         ` Greg Kroah-Hartman
2020-05-07 14:03                           ` Mikulas Patocka
2020-05-10  0:13                 ` [PATCH 2/2 v4] " Maciej W. Rozycki
2020-05-23 10:37                   ` Mikulas Patocka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LRH.2.02.2005061245500.18599@file01.intranet.prod.int.rdu2.redhat.com \
    --to=mpatocka@redhat.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=ink@jurassic.park.msu.ru \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=mattst88@gmail.com \
    --cc=okaya@codeaurora.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).