Commit e42d6c3e authored by Douglas Anderson's avatar Douglas Anderson Committed by Bjorn Andersson

serial: qcom_geni_serial: Make kgdb work even if UART isn't console

The geni serial driver had the rather sketchy hack in it where it
would adjust the number of bytes per RX FIFO word from 4 down to 1 if
it detected that CONFIG_CONSOLE_POLL was enabled (for kgdb) and this
was a console port (defined by the kernel directing output to this
port via the "console=" command line argument).

The problem with that sketchy hack is that it's possible to run kgdb
over a serial port even if it isn't used for console.

Let's avoid the hack by simply handling the 4-bytes-per-FIFO word case
for kdb.  We'll have to have a (very small) cache but that should be
fine.

A nice side effect of this patch is that an agetty (or similar)
running on this port is less likely to drop characters.  We'll
have roughly 4 times the RX FIFO depth than we used to now.

NOTE: the character cache here isn't shared between the polling API
and the non-polling API.  That means that, technically, the polling
API could eat a few extra bytes.  This doesn't seem to pose a huge
problem in reality because we'll only get several characters per FIFO
word if those characters are all received at nearly the same time and
we don't really expect non-kgdb characters to be sent to the same port
as kgdb at the exact same time we're exiting kgdb.

ALSO NOTE: we still have the sketchy hack for setting the number of
bytes per TX FIFO word in place, but that one is less bad.  kgdb
doesn't have any problem with this because it always just sends 1 byte
at a time and waits for it to finish.  The TX FIFO hack is only really
needed for console output.  In any case, a future patch will remove
that hack, too.
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: default avatarEvan Green <evgreen@chromium.org>
Signed-off-by: default avatarDouglas Anderson <dianders@chromium.org>
Link: https://lore.kernel.org/r/20200626125844.1.I8546ecb6c5beb054f70c5302d1a7293484212cd1@changeidSigned-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
parent da48dc8c
...@@ -103,11 +103,13 @@ ...@@ -103,11 +103,13 @@
#define DEFAULT_IO_MACRO_IO2_IO3_MASK GENMASK(15, 4) #define DEFAULT_IO_MACRO_IO2_IO3_MASK GENMASK(15, 4)
#define IO_MACRO_IO2_IO3_SWAP 0x4640 #define IO_MACRO_IO2_IO3_SWAP 0x4640
#ifdef CONFIG_CONSOLE_POLL struct qcom_geni_private_data {
#define CONSOLE_RX_BYTES_PW 1 /* NOTE: earlycon port will have NULL here */
#else struct uart_driver *drv;
#define CONSOLE_RX_BYTES_PW 4
#endif u32 poll_cached_bytes;
unsigned int poll_cached_bytes_cnt;
};
struct qcom_geni_serial_port { struct qcom_geni_serial_port {
struct uart_port uport; struct uart_port uport;
...@@ -129,6 +131,8 @@ struct qcom_geni_serial_port { ...@@ -129,6 +131,8 @@ struct qcom_geni_serial_port {
int wakeup_irq; int wakeup_irq;
bool rx_tx_swap; bool rx_tx_swap;
bool cts_rts_swap; bool cts_rts_swap;
struct qcom_geni_private_data private_data;
}; };
static const struct uart_ops qcom_geni_console_pops; static const struct uart_ops qcom_geni_console_pops;
...@@ -264,8 +268,9 @@ static bool qcom_geni_serial_poll_bit(struct uart_port *uport, ...@@ -264,8 +268,9 @@ static bool qcom_geni_serial_poll_bit(struct uart_port *uport,
unsigned int baud; unsigned int baud;
unsigned int fifo_bits; unsigned int fifo_bits;
unsigned long timeout_us = 20000; unsigned long timeout_us = 20000;
struct qcom_geni_private_data *private_data = uport->private_data;
if (uport->private_data) { if (private_data->drv) {
port = to_dev_port(uport, uport); port = to_dev_port(uport, uport);
baud = port->baud; baud = port->baud;
if (!baud) if (!baud)
...@@ -331,23 +336,42 @@ static void qcom_geni_serial_abort_rx(struct uart_port *uport) ...@@ -331,23 +336,42 @@ static void qcom_geni_serial_abort_rx(struct uart_port *uport)
} }
#ifdef CONFIG_CONSOLE_POLL #ifdef CONFIG_CONSOLE_POLL
static int qcom_geni_serial_get_char(struct uart_port *uport) static int qcom_geni_serial_get_char(struct uart_port *uport)
{ {
u32 rx_fifo; struct qcom_geni_private_data *private_data = uport->private_data;
u32 status; u32 status;
u32 word_cnt;
int ret;
if (!private_data->poll_cached_bytes_cnt) {
status = readl(uport->membase + SE_GENI_M_IRQ_STATUS);
writel(status, uport->membase + SE_GENI_M_IRQ_CLEAR);
status = readl(uport->membase + SE_GENI_M_IRQ_STATUS); status = readl(uport->membase + SE_GENI_S_IRQ_STATUS);
writel(status, uport->membase + SE_GENI_M_IRQ_CLEAR); writel(status, uport->membase + SE_GENI_S_IRQ_CLEAR);
status = readl(uport->membase + SE_GENI_S_IRQ_STATUS); status = readl(uport->membase + SE_GENI_RX_FIFO_STATUS);
writel(status, uport->membase + SE_GENI_S_IRQ_CLEAR); word_cnt = status & RX_FIFO_WC_MSK;
if (!word_cnt)
return NO_POLL_CHAR;
status = readl(uport->membase + SE_GENI_RX_FIFO_STATUS); if (word_cnt == 1 && (status & RX_LAST))
if (!(status & RX_FIFO_WC_MSK)) private_data->poll_cached_bytes_cnt =
return NO_POLL_CHAR; (status & RX_LAST_BYTE_VALID_MSK) >>
RX_LAST_BYTE_VALID_SHFT;
else
private_data->poll_cached_bytes_cnt = 4;
rx_fifo = readl(uport->membase + SE_GENI_RX_FIFOn); private_data->poll_cached_bytes =
return rx_fifo & 0xff; readl(uport->membase + SE_GENI_RX_FIFOn);
}
private_data->poll_cached_bytes_cnt--;
ret = private_data->poll_cached_bytes & 0xff;
private_data->poll_cached_bytes >>= 8;
return ret;
} }
static void qcom_geni_serial_poll_put_char(struct uart_port *uport, static void qcom_geni_serial_poll_put_char(struct uart_port *uport,
...@@ -837,13 +861,11 @@ static int qcom_geni_serial_port_setup(struct uart_port *uport) ...@@ -837,13 +861,11 @@ static int qcom_geni_serial_port_setup(struct uart_port *uport)
u32 proto; u32 proto;
u32 pin_swap; u32 pin_swap;
if (uart_console(uport)) { if (uart_console(uport))
port->tx_bytes_pw = 1; port->tx_bytes_pw = 1;
port->rx_bytes_pw = CONSOLE_RX_BYTES_PW; else
} else {
port->tx_bytes_pw = 4; port->tx_bytes_pw = 4;
port->rx_bytes_pw = 4; port->rx_bytes_pw = 4;
}
proto = geni_se_read_proto(&port->se); proto = geni_se_read_proto(&port->se);
if (proto != GENI_SE_UART) { if (proto != GENI_SE_UART) {
...@@ -1139,6 +1161,8 @@ static int qcom_geni_serial_earlycon_exit(struct console *con) ...@@ -1139,6 +1161,8 @@ static int qcom_geni_serial_earlycon_exit(struct console *con)
return 0; return 0;
} }
static struct qcom_geni_private_data earlycon_private_data;
static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev, static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev,
const char *opt) const char *opt)
{ {
...@@ -1154,6 +1178,8 @@ static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev, ...@@ -1154,6 +1178,8 @@ static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev,
if (!uport->membase) if (!uport->membase)
return -EINVAL; return -EINVAL;
uport->private_data = &earlycon_private_data;
memset(&se, 0, sizeof(se)); memset(&se, 0, sizeof(se));
se.base = uport->membase; se.base = uport->membase;
if (geni_se_read_proto(&se) != GENI_SE_UART) if (geni_se_read_proto(&se) != GENI_SE_UART)
...@@ -1172,6 +1198,7 @@ static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev, ...@@ -1172,6 +1198,7 @@ static int __init qcom_geni_serial_earlycon_setup(struct earlycon_device *dev,
qcom_geni_serial_poll_tx_done(uport); qcom_geni_serial_poll_tx_done(uport);
qcom_geni_serial_abort_rx(uport); qcom_geni_serial_abort_rx(uport);
geni_se_config_packing(&se, BITS_PER_BYTE, 1, false, true, false); geni_se_config_packing(&se, BITS_PER_BYTE, 1, false, true, false);
geni_se_config_packing(&se, BITS_PER_BYTE, 4, false, false, true);
geni_se_init(&se, DEF_FIFO_DEPTH_WORDS / 2, DEF_FIFO_DEPTH_WORDS - 2); geni_se_init(&se, DEF_FIFO_DEPTH_WORDS / 2, DEF_FIFO_DEPTH_WORDS - 2);
geni_se_select_mode(&se, GENI_SE_FIFO); geni_se_select_mode(&se, GENI_SE_FIFO);
...@@ -1396,7 +1423,8 @@ static int qcom_geni_serial_probe(struct platform_device *pdev) ...@@ -1396,7 +1423,8 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
return ret; return ret;
} }
uport->private_data = drv; port->private_data.drv = drv;
uport->private_data = &port->private_data;
platform_set_drvdata(pdev, port); platform_set_drvdata(pdev, port);
port->handle_rx = console ? handle_rx_console : handle_rx_uart; port->handle_rx = console ? handle_rx_console : handle_rx_uart;
...@@ -1442,7 +1470,7 @@ static int qcom_geni_serial_probe(struct platform_device *pdev) ...@@ -1442,7 +1470,7 @@ static int qcom_geni_serial_probe(struct platform_device *pdev)
static int qcom_geni_serial_remove(struct platform_device *pdev) static int qcom_geni_serial_remove(struct platform_device *pdev)
{ {
struct qcom_geni_serial_port *port = platform_get_drvdata(pdev); struct qcom_geni_serial_port *port = platform_get_drvdata(pdev);
struct uart_driver *drv = port->uport.private_data; struct uart_driver *drv = port->private_data.drv;
if (port->se.has_opp_table) if (port->se.has_opp_table)
dev_pm_opp_of_remove_table(&pdev->dev); dev_pm_opp_of_remove_table(&pdev->dev);
...@@ -1458,16 +1486,18 @@ static int __maybe_unused qcom_geni_serial_sys_suspend(struct device *dev) ...@@ -1458,16 +1486,18 @@ static int __maybe_unused qcom_geni_serial_sys_suspend(struct device *dev)
{ {
struct qcom_geni_serial_port *port = dev_get_drvdata(dev); struct qcom_geni_serial_port *port = dev_get_drvdata(dev);
struct uart_port *uport = &port->uport; struct uart_port *uport = &port->uport;
struct qcom_geni_private_data *private_data = uport->private_data;
return uart_suspend_port(uport->private_data, uport); return uart_suspend_port(private_data->drv, uport);
} }
static int __maybe_unused qcom_geni_serial_sys_resume(struct device *dev) static int __maybe_unused qcom_geni_serial_sys_resume(struct device *dev)
{ {
struct qcom_geni_serial_port *port = dev_get_drvdata(dev); struct qcom_geni_serial_port *port = dev_get_drvdata(dev);
struct uart_port *uport = &port->uport; struct uart_port *uport = &port->uport;
struct qcom_geni_private_data *private_data = uport->private_data;
return uart_resume_port(uport->private_data, uport); return uart_resume_port(private_data->drv, uport);
} }
static const struct dev_pm_ops qcom_geni_serial_pm_ops = { static const struct dev_pm_ops qcom_geni_serial_pm_ops = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment