From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Tim Kryger <tim.kryger@linaro.org>,
Matt Porter <matt.porter@linaro.org>,
Markus Mayer <markus.mayer@linaro.org>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Wang Nan <wangnan0@huawei.com>
Subject: [PATCH 3.10 47/53] serial: 8250_dw: Improve unwritable LCR workaround
Date: Mon, 7 Jul 2014 16:58:32 -0700 [thread overview]
Message-ID: <20140707235830.711863058@linuxfoundation.org> (raw)
In-Reply-To: <20140707235829.281783607@linuxfoundation.org>
3.10-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tim Kryger <tim.kryger@linaro.org>
commit c49436b657d0a56a6ad90d14a7c3041add7cf64d upstream.
When configured with UART_16550_COMPATIBLE=NO or in versions prior to
the introduction of this option, the Designware UART will ignore writes
to the LCR if the UART is busy. The current workaround saves a copy of
the last written LCR and re-writes it in the ISR for a special interrupt
that is raised when a write was ignored.
Unfortunately, interrupts are typically disabled prior to performing a
sequence of register writes that include the LCR so the point at which
the retry occurs is too late. An example is serial8250_do_set_termios()
where an ignored LCR write results in the baud divisor not being set and
instead a garbage character is sent out the transmitter.
Furthermore, since serial_port_out() offers no way to indicate failure,
a serious effort must be made to ensure that the LCR is actually updated
before returning back to the caller. This is difficult, however, as a
UART that was busy during the first attempt is likely to still be busy
when a subsequent attempt is made unless some extra action is taken.
This updated workaround reads back the LCR after each write to confirm
that the new value was accepted by the hardware. Should the hardware
ignore a write, the TX/RX FIFOs are cleared and the receive buffer read
before attempting to rewrite the LCR out of the hope that doing so will
force the UART into an idle state. While this may seem unnecessarily
aggressive, writes to the LCR are used to change the baud rate, parity,
stop bit, or data length so the data that may be lost is likely not
important. Admittedly, this is far from ideal but it seems to be the
best that can be done given the hardware limitations.
Lastly, the revised workaround doesn't touch the LCR in the ISR, so it
avoids the possibility of a "serial8250: too much work for irq" lock up.
This problem is rare in real situations but can be reproduced easily by
wiring up two UARTs and running the following commands.
# stty -F /dev/ttyS1 echo
# stty -F /dev/ttyS2 echo
# cat /dev/ttyS1 &
[1] 375
# echo asdf > /dev/ttyS1
asdf
[ 27.700000] serial8250: too much work for irq96
[ 27.700000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.710000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.720000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.730000] serial8250: too much work for irq96
[ 27.740000] serial8250: too much work for irq96
Signed-off-by: Tim Kryger <tim.kryger@linaro.org>
Reviewed-by: Matt Porter <matt.porter@linaro.org>
Reviewed-by: Markus Mayer <markus.mayer@linaro.org>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
[wangnan: backport to 3.10.43:
- adjust context
- remove unneeded local var]
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/tty/serial/8250/8250_dw.c | 42 ++++++++++++++++++++++++++++----------
1 file changed, 32 insertions(+), 10 deletions(-)
--- a/drivers/tty/serial/8250/8250_dw.c
+++ b/drivers/tty/serial/8250/8250_dw.c
@@ -54,7 +54,6 @@
struct dw8250_data {
- int last_lcr;
int last_mcr;
int line;
struct clk *clk;
@@ -73,17 +72,33 @@ static inline int dw8250_modify_msr(stru
return value;
}
+static void dw8250_force_idle(struct uart_port *p)
+{
+ serial8250_clear_and_reinit_fifos(container_of
+ (p, struct uart_8250_port, port));
+ (void)p->serial_in(p, UART_RX);
+}
+
static void dw8250_serial_out(struct uart_port *p, int offset, int value)
{
struct dw8250_data *d = p->private_data;
- if (offset == UART_LCR)
- d->last_lcr = value;
-
if (offset == UART_MCR)
d->last_mcr = value;
writeb(value, p->membase + (offset << p->regshift));
+
+ /* Make sure LCR write wasn't ignored */
+ if (offset == UART_LCR) {
+ int tries = 1000;
+ while (tries--) {
+ if (value == p->serial_in(p, UART_LCR))
+ return;
+ dw8250_force_idle(p);
+ writeb(value, p->membase + (UART_LCR << p->regshift));
+ }
+ dev_err(p->dev, "Couldn't set LCR to %d\n", value);
+ }
}
static unsigned int dw8250_serial_in(struct uart_port *p, int offset)
@@ -97,13 +112,22 @@ static void dw8250_serial_out32(struct u
{
struct dw8250_data *d = p->private_data;
- if (offset == UART_LCR)
- d->last_lcr = value;
-
if (offset == UART_MCR)
d->last_mcr = value;
writel(value, p->membase + (offset << p->regshift));
+
+ /* Make sure LCR write wasn't ignored */
+ if (offset == UART_LCR) {
+ int tries = 1000;
+ while (tries--) {
+ if (value == p->serial_in(p, UART_LCR))
+ return;
+ dw8250_force_idle(p);
+ writel(value, p->membase + (UART_LCR << p->regshift));
+ }
+ dev_err(p->dev, "Couldn't set LCR to %d\n", value);
+ }
}
static unsigned int dw8250_serial_in32(struct uart_port *p, int offset)
@@ -115,15 +139,13 @@ static unsigned int dw8250_serial_in32(s
static int dw8250_handle_irq(struct uart_port *p)
{
- struct dw8250_data *d = p->private_data;
unsigned int iir = p->serial_in(p, UART_IIR);
if (serial8250_handle_irq(p, iir)) {
return 1;
} else if ((iir & UART_IIR_BUSY) == UART_IIR_BUSY) {
- /* Clear the USR and write the LCR again. */
+ /* Clear the USR */
(void)p->serial_in(p, DW_UART_USR);
- p->serial_out(p, UART_LCR, d->last_lcr);
return 1;
}
next prev parent reply other threads:[~2014-07-07 23:58 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-07 23:57 [PATCH 3.10 00/53] 3.10.48-stable review Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 01/53] ibmvscsi: Abort init sequence during error recovery Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 02/53] ibmvscsi: Add memory barriers for send / receive Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 03/53] virtio-scsi: avoid cancelling uninitialized work items Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 04/53] virtio-scsi: fix various bad behavior on aborted requests Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 05/53] xhci: correct burst count field for isoc transfers on 1.0 xhci hosts Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 06/53] xhci: Fix runtime suspended xhci from blocking system suspend Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 07/53] USB: option: add device ID for SpeedUp SU9800 usb 3g modem Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 09/53] USB: ftdi_sio: fix null deref at port probe Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 11/53] rt2x00: disable TKIP on USB Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 12/53] rt2x00: fix rfkill regression on rt2500pci Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 13/53] mtd: eLBC NAND: fix subpage write support Greg Kroah-Hartman
2014-07-07 23:57 ` [PATCH 3.10 14/53] mtd: nand: omap: fix BCHx ecc.correct to return detected bit-flips in erased-page Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 15/53] drm/radeon: only apply hdmi bpc pll flags when encoder mode is hdmi Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 16/53] drm/radeon: fix typo in radeon_connector_is_dp12_capable() Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 17/53] drm/radeon/dp: fix lane/clock setup for dp 1.2 capable devices Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 18/53] drm/radeon/atom: fix dithering on certain panels Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 20/53] drm/vmwgfx: Fix incorrect write to read-only register v2: Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 21/53] Bluetooth: Fix SSP acceptor just-works confirmation without MITM Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 22/53] Bluetooth: Fix check for connection encryption Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 23/53] Bluetooth: Fix locking of hdev when calling into SMP code Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 24/53] dm thin: update discard_granularity to reflect the thin-pool blocksize Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 25/53] rbd: use reference counts for image requests Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 26/53] rbd: handle parent_overlap on writes correctly Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 27/53] hwmon: (ina2xx) Cast to s16 on shunt and current regs Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 28/53] mac80211: dont check netdev state for debugfs read/write Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 30/53] iwlwifi: pcie: try to get ownership several times Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 31/53] ARM: OMAP2+: Fix parser-bug in platform muxing code Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 34/53] CIFS: fix mount failure with broken pathnames when smb3 mount with mapchars option Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 35/53] ext4: Fix buffer double free in ext4_alloc_branch() Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 36/53] ext4: Fix hole punching for files with indirect blocks Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 37/53] KVM: x86: Increase the number of fixed MTRR regs to 10 Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 38/53] KVM: x86: preserve the high 32-bits of the PAT register Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 39/53] iio: of_iio_channel_get_by_name() returns non-null pointers for error legs Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 40/53] nfsd: fix rare symlink decoding bug Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 41/53] tools: ffs-test: fix header values endianess Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 42/53] tracing: Remove ftrace_stop/start() from reading the trace file Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 43/53] md: flush writes before starting a recovery Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 44/53] irqchip: spear_shirq: Fix interrupt offset Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 45/53] mmc: rtsx: add R1-no-CRC mmc command type handle Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 46/53] serial: 8250_dw: Report CTS asserted for auto flow Greg Kroah-Hartman
2014-07-07 23:58 ` Greg Kroah-Hartman [this message]
2014-07-07 23:58 ` [PATCH 3.10 48/53] serial: 8250_dw: Fix LCR workaround regression Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 49/53] ALSA: usb-audio: Suppress repetitive debug messages from retire_playback_urb() Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 50/53] ALSA: usb-audio: Prevent printk ratelimiting from spamming kernel log while DEBUG not defined Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 51/53] arch/unicore32/mm/alignment.c: include "asm/pgtable.h" to avoid compiling error Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 52/53] drivers/video/fbdev/fb-puv3.c: Add header files for function unifb_mmap Greg Kroah-Hartman
2014-07-07 23:58 ` [PATCH 3.10 53/53] sym53c8xx_2: Set DID_REQUEUE return code when aborting squeue Greg Kroah-Hartman
2014-07-08 13:19 ` [PATCH 3.10 00/53] 3.10.48-stable review Guenter Roeck
2014-07-08 22:15 ` Greg Kroah-Hartman
2014-07-09 10:21 ` Luis Henriques
2014-07-15 0:59 ` Greg Kroah-Hartman
2014-07-08 19:31 ` Shuah Khan
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=20140707235830.711863058@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=markus.mayer@linaro.org \
--cc=matt.porter@linaro.org \
--cc=stable@vger.kernel.org \
--cc=tim.kryger@linaro.org \
--cc=wangnan0@huawei.com \
/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).