tty: pl011: Work around QDF2400 E44 stuck BUSY bit
Subsystems (4)
PATCH v2 1/1 tty: pl011: Work around QDF2400 E44 stuck BUSY bit
The Qualcomm Datacenter Technologies QDF2400 family of SoCs contains a custom (non-PrimeCell) implementation of the SBSA UART. Occasionally the BUSY bit in the Flag Register gets stuck as 1, erratum 44 for both 2432v1 and 2400v1 SoCs. Checking that the Transmit FIFO Empty (TXFE) bit is 0, instead of checking that the BUSY bit is 1, works around the issue. To facilitate this substitution when UART AMBA Port (UAP) data is available, introduce vendor-specific inversion of Feature Register bits. For the earlycon case, implement alternative putc and early_write functions. Similar to what how ARMv8 ACPI PCI quirks are detected during MCFG parsing, check the OEM fields of the Serial Port Console Redirection (SPCR) ACPI table to determine if the current platform is known to be affected by the erratum.
---
Changes in v2:
* Improved comments per Timur
* Removed #ifdef CONFIG_QCOM_QDF2400_ERRATUM_44 per Robin
* Moved from MIDR based affected system detection to ACPI based per Mark and Robin
* Combined earlycon and UAP-available workarounds back into one patch
* Keeping Russell's Acked-by because I don't think I've drastically changed the PL011 bits, but please let me know if I'm wrong
* Happy Valentine's Day!
--- Documentation/arm64/silicon-errata.txt | 2 + drivers/acpi/spcr.c | 8 ++++ drivers/tty/serial/amba-pl011.c | 67 ++++++++++++++++++++++++++++++---- 3 files changed, 70 insertions(+), 7 deletions(-)
Documentation/arm64/silicon-errata.txt +2 -0
@@ -68,3 +68,5 @@ stable kernels. | | | | | | Qualcomm Tech. | Falkor v1 | E1003 | QCOM_FALKOR_ERRATUM_1003 | | Qualcomm Tech. | Falkor v1 | E1009 | QCOM_FALKOR_ERRATUM_1009 | +| Qualcomm Tech. | QDF2432v1 UART | SoC E44 | N/A | +| Qualcomm Tech. | QDF2400v1 UART | SoC E44 | N/A |
drivers/acpi/spcr.c +8 -0
@@ -93,6 +93,14 @@ int __init parse_spcr(bool earlycon) goto done; } +if (!memcmp (table->header.oem_id,"QCOM " ,ACPI_OEM_ID_SIZE )) +if (!memcmp (table->header.oem_table_id,"QDF2432 " , +ACPI_OEM_TABLE_ID_SIZE ) || + (!memcmp (table->header.oem_table_id, +"QDF2400 " ,ACPI_OEM_TABLE_ID_SIZE ) && + table->header.oem_revision ==0 )) + uart ="qdf2400_e44" ; +snprintf (opts,sizeof (opts),"%s,%s,0x%llx,%d" , uart, iotype, table->serial_port.address, baud_rate);
drivers/tty/serial/amba-pl011.c +60 -7
117 lines not on this page · raw message
Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 4 lines · Christopher Covington
The Qualcomm Datacenter Technologies QDF2400 family of SoCs contains a custom (non-PrimeCell) implementation of the SBSA UART. Occasionally the BUSY bit in the Flag Register gets stuck as 1, erratum 44 for both 2432v1 and 2400v1 SoCs. Checking that the Transmit FIFO Empty (TXFE) bit is 0,
Quoted 8 lines
instead of checking that the BUSY bit is 1, works around the issue. To facilitate this substitution when UART AMBA Port (UAP) data is available, introduce vendor-specific inversion of Feature Register bits. For the earlycon case, implement alternative putc and
early_writefunctions. Similar to what how ARMv8 ACPI PCI quirks are detected during MCFG parsing, check the OEM fields of the Serial Port Console Redirection (SPCR) ACPI table to determine if the current platform is known to be affected by the erratum.
Please break this up into paragraphs.
drivers/acpi/spcr.c int __init parse_spcr(bool earlycon) · line 103
Quoted 8 lines
drivers/acpi/spcr.c +8
-0+if (!memcmp (table->header.oem_id,"QCOM " ,ACPI_OEM_ID_SIZE )) +if (!memcmp (table->header.oem_table_id,"QDF2432 " , +ACPI_OEM_TABLE_ID_SIZE ) || + (!memcmp (table->header.oem_table_id, +"QDF2400 " ,ACPI_OEM_TABLE_ID_SIZE ) && + table->header.oem_revision ==0 )) + uart ="qdf2400_e44" ; +
Hey, you just wrote this
And it looks crazy
But here's my function
So call it, maybe?
static bool needs_qdf2400_e44(struct acpi_table_header *h)
{
const char *id;
/* The erratum only applies to Qualcomm Technologies SOCs */
if (memcmp(h->oem_id, "QCOM ", ACPI_OEM_ID_SIZE))
return False;
id = h->oem_table_id;
if (!memcmp(id, "QDF2432 ", ACPI_OEM_TABLE_ID_SIZE))
return True;
if (!memcmp(id, "QDF2000 ", ACPI_OEM_TABLE_ID_SIZE) &&
h->oem_revision == 0)
return True;
return False;
}...
if (needs_qdf2400_e44(&table->header)) uart = "qdf2400_e44";
drivers/tty/serial/amba-pl011.c static struct vendor_data vendor_sbsa = { · line 152
Quoted 8 lines
drivers/tty/serial/amba-pl011.c +8
-0+/* +* Erratum 44 for QDF2432v1 and QDF2400v1 SoCs describes the BUSY bit as +* occasionally getting stuck as 1. To avoid the potential for a hang, check +* TXFE == 0 instead of BUSY == 1. This may not be suitable for all UART +* implementations, so only do so if an affected platform is detected in +* parse_spcr(). +*/ +static bool qdf2400_e44 = false;
Please rename this to needs_qdf2400_e44
drivers/tty/serial/amba-pl011.c static unsigned int pl011_tx_empty(struct uart_port *port) · line 1546
Quoted 9 lines
static u16 pl011_st_offsets[REG_ARRAY_SIZE] = {
drivers/tty/serial/amba-pl011.c +1
-1[REG_DR] = UART01x_DR, [REG_ST_DMAWM] = ST_UART011_DMAWM,@@ -1518,7 +1543,8 @@ static unsigned int pl011_tx_empty(struct uart_port *port) {struct uart_amba_port *uap = container_of(port, struct uart_amba_port, port); -unsigned int status =pl011_read (uap,REG_FR ); +/* Allow feature register bits to be inverted to work around errata */
Blank line above the comment, please.
Quoted 21 lines
drivers/tty/serial/amba-pl011.c +6
-3+unsigned int status =pl011_read (uap,REG_FR ) ^ uap->vendor->inv_fr;return status & (uap->vendor->fr_busy | UART01x_FR_TXFF) ?0 :TIOCSER_TEMT ; }@@ -2215,10 +2241,12 @@ pl011_console_write(struct console *co, const char *s, unsigned int count)uart_console_write (&uap->port, s, count, pl011_console_putchar);/* -* Finally, wait for transmitter to become empty -* and restore the TCR +* Finally, wait for transmitter to become empty and restore the +* TCR. Allow feature register bits to be inverted to work around +* errata. */ -while (pl011_read (uap,REG_FR ) & uap->vendor->fr_busy) +while ((pl011_read (uap,REG_FR ) ^ uap->vendor->inv_fr) + & uap->vendor->fr_busy)cpu_relax ();if (!uap->vendor->always_enabled)pl011_write (old_cr, uap,REG_CR );
drivers/tty/serial/amba-pl011.c static int __init pl011_console_match(struct console *co, char *name, int idx, · line 2373
Quoted 7 lines
drivers/tty/serial/amba-pl011.c +3
-1@@ -2340,8 +2368,13 @@ static int __init pl011_console_match(struct console *co, char *name, int idx,resource_size_t addr;int i; -if (strcmp (name,"pl011" ) !=0 ) +if (strcmp (name,"qdf2400_e44" ) ==0 ) { +if (!qdf2400_e44) +pr_info ("UART: Working around QDF2400 SoC erratum 44" );
Just use pr_once(), and you can skip the "if (!qdf2400_e44)". Although I don't understand why you need to do that. pl011_console_match() should only be called once anyway, right?
Quoted 9 lines
drivers/tty/serial/amba-pl011.c +3
-0+ qdf2400_e44 = true; + }else if (strcmp (name,"pl011" ) !=0 ) {return -ENODEV ; + }if (uart_parse_earlycon (options, &iotype, &addr, &options))return -ENODEV ;@@ -2383,6 +2416,25 @@ static struct console amba_console = {
drivers/tty/serial/amba-pl011.c static struct console amba_console = { · line 2426
Quoted 10 lines
drivers/tty/serial/amba-pl011.c +8
-0#define AMBA_CONSOLE (&amba_console) +static void qdf2400_e44_putc (struct uart_port *port,int c) +{ +while (readl (port->membase + UART01x_FR) & UART01x_FR_TXFF) +cpu_relax (); +if (port->iotype ==UPIO_MEM32 ) +writel (c, port->membase + UART01x_DR); +else +writeb (c, port->membase + UART01x_DR);
I think you can ignore the UPIO_MEM32 test and always use writel(), even on the QDF2400.
Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.
Mark Rutland
Acked-byHi,
Quoted 10 lines · Timur Tabi
drivers/acpi/spcr.c int __init parse_spcr(bool earlycon) · line 103
Quoted 8 lines · Christopher Covington
drivers/acpi/spcr.c +8
-0+if (!memcmp (table->header.oem_id,"QCOM " ,ACPI_OEM_ID_SIZE )) +if (!memcmp (table->header.oem_table_id,"QDF2432 " , +ACPI_OEM_TABLE_ID_SIZE ) || + (!memcmp (table->header.oem_table_id, +"QDF2400 " ,ACPI_OEM_TABLE_ID_SIZE ) && + table->header.oem_revision ==0 )) + uart ="qdf2400_e44" ; +
Thanks for reworking this. I'm much happier with this than the MIDR check.
Splitting out the test into its own function, as Timur suggested, would generally be nicer. Minor comments on that below.
Quoted 2 lines
static bool
needs_qdf2400_e44(struct acpi_table_header *h){
This is detecting the presence of the erratum so, has_qdf2400_e44() or needs__qdf2400_e44_workaround() would be better names. I'd personally prefer the former, but either is fine.
Quoted 9 lines
const char *id; /* The erratum only applies to Qualcomm Technologies SOCs */ if (memcmp(h->oem_id, "QCOM ", ACPI_OEM_ID_SIZE)) return False; id = h->oem_table_id; if (!memcmp(id, "QDF2432 ", ACPI_OEM_TABLE_ID_SIZE))
Quoted 8 lines
return True; if (!memcmp(id, "QDF2000 ", ACPI_OEM_TABLE_ID_SIZE) && h->oem_revision == 0) return True; return False; }
s/False/false/g
s/True/true/g
With that, this looks fine to me. I'm not too familiar with the pl011 driver. On the assumption the other changes have already been vetted:
Thanks,
Mark.
Quoted 21 lines · Timur Tabi
Quoted 11 lines · Christopher Covington
The Qualcomm Datacenter Technologies QDF2400 family of SoCs contains a custom (non-PrimeCell) implementation of the SBSA UART. Occasionally the
BUSY bit in the Flag Register gets stuck as 1, erratum 44 for both 2432v1
and 2400v1 SoCs. Checking that the Transmit FIFO Empty (TXFE) bit is 0,
instead of checking that the BUSY bit is 1, works around the issue. To facilitate this substitution when UART AMBA Port (UAP) data is available,
introduce vendor-specific inversion of Feature Register bits. For theQuoted 8 lines
earlycon case, implement alternative putc and
early_writefunctions. Similar to what how ARMv8 ACPI PCI quirks are detected during MCFG parsing,
check the OEM fields of the Serial Port Console Redirection (SPCR) ACPI
table to determine if the current platform is known to be affected by the
erratum.
Quoted 1 line
Please break this up into paragraphs.
Sure
Quoted 34 lines
drivers/acpi/spcr.c int __init parse_spcr(bool earlycon) · line 103
Quoted 8 lines
drivers/acpi/spcr.c +8
-0+if (!memcmp (table->header.oem_id,"QCOM " ,ACPI_OEM_ID_SIZE )) +if (!memcmp (table->header.oem_table_id,"QDF2432 " , +ACPI_OEM_TABLE_ID_SIZE ) || + (!memcmp (table->header.oem_table_id, +"QDF2400 " ,ACPI_OEM_TABLE_ID_SIZE ) && + table->header.oem_revision ==0 )) + uart ="qdf2400_e44" ; +Hey, you just wrote this
And it looks crazy
But here's my function
So call it, maybe?static bool
needs_qdf2400_e44(struct acpi_table_header *h){ const char *id; /* The erratum only applies to Qualcomm Technologies SOCs */ if (memcmp(h->oem_id, "QCOM ", ACPI_OEM_ID_SIZE)) return False; id = h->oem_table_id; if (!memcmp(id, "QDF2432 ", ACPI_OEM_TABLE_ID_SIZE)) return True; if (!memcmp(id, "QDF2000 ", ACPI_OEM_TABLE_ID_SIZE) && h->oem_revision == 0) return True; return False; }
Quoted 4 lines
...
if (needs_qdf2400_e44(&table->header)) uart = "qdf2400_e44";
Sure
Quoted 6 lines
Quoted 6 lines
+/*
+ * Erratum 44 for QDF2432v1 and QDF2400v1 SoCs describes the BUSY bit as
+ * occasionally getting stuck as 1. To avoid the potential for a hang, check
+ * TXFE == 0 instead of BUSY == 1. This may not be suitable for all
Quoted 8 lines
Quoted 6 lines
UART
+ * implementations, so only do so if an affected platform is detected in
+ *parse_spcr().
+ */
+static boolqdf2400_e44= false;Please rename this to
needs_qdf2400_e44
Nothing needs QDF2400 erratum 44. Software should try to detect the presence
of the erratum. So I think qdf2400_e44_detected or qdf2400_e44_present would
make sense. But those suffixes don't add substantial value in my opinion.
Affected hardware needs the *workaround* to the erratum. So I think needs_qdf2400_e44_workaround makes sense. But it's pretty lengthy.
If qdf2400_e44 is too cryptic, how about qdf2400_erratum_44?
Quoted 5 lines
Quoted 5 lines
static u16 pl011_st_offsets[REG_ARRAY_SIZE] = {
drivers/tty/serial/amba-pl011.c +0
-0[REG_DR] = UART01x_DR, [REG_ST_DMAWM] = ST_UART011_DMAWM,@@ -1518,7 +1543,8 @@ static unsigned int pl011_tx_empty(struct uart_port *port)
Quoted 8 lines
drivers/tty/serial/amba-pl011.c static unsigned int pl011_tx_empty(struct uart_port *port)
Quoted 6 lines
drivers/tty/serial/amba-pl011.c +1
-1{struct uart_amba_port *uap = container_of(port, struct uart_amba_port, port); -unsigned int status = pl011_read(uap, REG_FR); +/* Allow feature register bits to be inverted to work around errata */ Blank line above the comment, please.
Sure
Quoted 26 lines
Quoted 26 lines
drivers/tty/serial/amba-pl011.c +1
-0+unsigned int status =pl011_read (uap,REG_FR ) ^ uap->vendor->inv_fr; return status & (uap->vendor->fr_busy | UART01x_FR_TXFF) ?drivers/tty/serial/amba-pl011.c +5
-30 : TIOCSER_TEMT; }@@ -2215,10 +2241,12 @@ pl011_console_write(struct console *co, const char *s, unsigned int count) uart_console_write(&uap->port, s, count, pl011_console_putchar);/* -* Finally, wait for transmitter to become empty -* and restore the TCR +* Finally, wait for transmitter to become empty and restore the +* TCR. Allow feature register bits to be inverted to work around +* errata. */ -while (pl011_read (uap,REG_FR ) & uap->vendor->fr_busy) +while ((pl011_read (uap,REG_FR ) ^ uap->vendor->inv_fr) + & uap->vendor->fr_busy)cpu_relax ();if (!uap->vendor->always_enabled)drivers/tty/serial/amba-pl011.c +0
-0pl011_write (old_cr, uap,REG_CR );@@ -2340,8 +2368,13 @@ static int __init pl011_console_match(struct console *co, char *name, int idx, resource_size_t addr;int i;
Quoted 8 lines
drivers/tty/serial/amba-pl011.c static int __init pl011_console_match(struct console *co, char *name, int idx, · line 2373
Quoted 4 lines
drivers/tty/serial/amba-pl011.c +3
-1-if (strcmp (name,"pl011" ) !=0 ) +if (strcmp (name,"qdf2400_e44" ) ==0 ) { +if (!qdf2400_e44) +pr_info ("UART: Working around QDF2400 SoC erratum 44" );Just use
pr_once(), and you can skip the "if (!qdf2400_e44)". Although I don't understand why you need to do that.pl011_console_match()should only be called once anyway, right?
Sure. In my debugging I saw it printed 3 times. Keep in mind there are at least two UARTs, one for the DB9 socket on the front of the chassis and connected to the BMC for Serial Over LAN. Maybe the first hit was from earlycon or SPCR parsing, I don't really know.
Quoted 11 lines
Quoted 11 lines
drivers/tty/serial/amba-pl011.c +3
-0+ qdf2400_e44 = true; + }else if (strcmp (name,"pl011" ) !=0 ) {return -ENODEV ; + }if (uart_parse_earlycon (options, &iotype, &addr, &options))drivers/tty/serial/amba-pl011.c +0
-0return -ENODEV ;@@ -2383,6 +2416,25 @@ static struct console amba_console = {#define AMBA_CONSOLE (&amba_console)
Quoted 11 lines
drivers/tty/serial/amba-pl011.c static struct console amba_console = { · line 2426
Quoted 8 lines
drivers/tty/serial/amba-pl011.c +8
-0+static void qdf2400_e44_putc (struct uart_port *port,int c) +{ +while (readl (port->membase + UART01x_FR) & UART01x_FR_TXFF) +cpu_relax (); +if (port->iotype ==UPIO_MEM32 ) +writel (c, port->membase + UART01x_DR); +else +writeb (c, port->membase + UART01x_DR);I think you can ignore the
UPIO_MEM32test and always usewritel(), even on the QDF2400.
Sure
Cheers,
Cov
--
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Quoted 3 lines · Christopher Covington
Nothing needs QDF2400 erratum 44. Software should try to detect the presence of the erratum. So I think
qdf2400_e44_detectedorqdf2400_e44_presentwould make sense. But those suffixes don't add substantial value in my opinion.
I'd be okay with qdf2400_e44_detected or qdf2400_e44_present. I think it's a lot clearer. Another idea is "has_qdf2400_e44".
Signature · 3 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation.