From c4314b02d9d73364a2467690fb574193353d058b Mon Sep 17 00:00:00 2001 From: Chandana Kishori Chiluveru Date: Mon, 12 Jul 2021 10:42:14 +0530 Subject: [PATCH] serial: msm_geni_serial: Bailout from wait_for_transfers_inflight This change is to avoid potential race btw stop rx and incoming SOC RX data in parallel. During suspend path wait_for_transfers_inflight() logic will check for TX/RX data pending for completion. Check for RX_LEN_IN status in wait_for_transfers_inflight() and return -EBUSY to avoid race between stop_rx and SOC RX data. Change-Id: I28702d3dc11ee4b6d3fe5b4bad9a19099d8cf725 Signed-off-by: Chandana Kishori Chiluveru --- drivers/tty/serial/msm_geni_serial.c | 47 ++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/msm_geni_serial.c b/drivers/tty/serial/msm_geni_serial.c index b695777b6ec4..0656d65c7b74 100644 --- a/drivers/tty/serial/msm_geni_serial.c +++ b/drivers/tty/serial/msm_geni_serial.c @@ -531,16 +531,17 @@ static bool check_transfers_inflight(struct uart_port *uport) return xfer_on; } -static void wait_for_transfers_inflight(struct uart_port *uport) +static int wait_for_transfers_inflight(struct uart_port *uport) { int iter = 0; struct msm_geni_serial_port *port = GET_DEV_PORT(uport); unsigned int geni_status; + u32 rx_len_in = 0; geni_status = geni_read_reg_nolog(uport->membase, SE_GENI_STATUS); /* Possible stop rx is called before this. */ if (!(geni_status & S_GENI_CMD_ACTIVE)) - return; + return 0; while (iter < WAIT_XFER_MAX_ITER) { if (check_transfers_inflight(uport)) { @@ -552,9 +553,18 @@ static void wait_for_transfers_inflight(struct uart_port *uport) } } if (check_transfers_inflight(uport)) { + rx_len_in = + geni_read_reg_nolog(uport->membase, SE_DMA_RX_LEN_IN); + if (rx_len_in) { + IPC_LOG_MSG(port->ipc_log_misc, + "%s: Bailout rx_len_in is set\n", + __func__); + return -EBUSY; + } geni_se_dump_dbg_regs(&port->serial_rsc, uport->membase, port->ipc_log_misc); } + return 0; } static int vote_clock_on(struct uart_port *uport) @@ -581,6 +591,7 @@ static int vote_clock_off(struct uart_port *uport) { struct msm_geni_serial_port *port = GET_DEV_PORT(uport); int usage_count; + int ret = 0; if (!pm_runtime_enabled(uport->dev)) { dev_err(uport->dev, "RPM not available.Can't enable clocks\n"); @@ -594,7 +605,12 @@ static int vote_clock_off(struct uart_port *uport) __func__, port->ioctl_count); return -EPERM; } - wait_for_transfers_inflight(uport); + ret = wait_for_transfers_inflight(uport); + if (ret) + IPC_LOG_MSG(port->ipc_log_pwr, + "%s: wait_for_transfer_inflight return ret:%d\n", + __func__, ret); + port->ioctl_count--; msm_geni_serial_power_off(uport); usage_count = atomic_read(&uport->dev->power.usage_count); @@ -647,6 +663,7 @@ static int msm_geni_serial_ioctl(struct uart_port *uport, unsigned int cmd, static void msm_geni_serial_break_ctl(struct uart_port *uport, int ctl) { struct msm_geni_serial_port *port = GET_DEV_PORT(uport); + int ret = 0; if (!uart_console(uport) && device_pending_suspend(uport)) { IPC_LOG_MSG(port->ipc_log_misc, @@ -656,7 +673,12 @@ static void msm_geni_serial_break_ctl(struct uart_port *uport, int ctl) } if (ctl) { - wait_for_transfers_inflight(uport); + ret = wait_for_transfers_inflight(uport); + if (ret) + IPC_LOG_MSG(port->ipc_log_misc, + "%s: wait_for_transfer_inflight return ret:%d\n", + __func__, ret); + geni_setup_m_cmd(uport->membase, UART_START_BREAK, 0); } else { geni_setup_m_cmd(uport->membase, UART_STOP_BREAK, 0); @@ -2339,7 +2361,12 @@ static void msm_geni_serial_shutdown(struct uart_port *uport) disable_irq(uport->irq); } else { msm_geni_serial_power_on(uport); - wait_for_transfers_inflight(uport); + ret = wait_for_transfers_inflight(uport); + if (ret) + IPC_LOG_MSG(msm_port->ipc_log_misc, + "%s: wait_for_transfer_inflight return ret:%d\n", + __func__, ret); + msm_geni_serial_stop_tx(uport); } @@ -3532,7 +3559,15 @@ static int msm_geni_serial_runtime_suspend(struct device *dev) IPC_LOG_MSG(port->ipc_log_pwr, "%s: Start\n", __func__); /* Flow off from UART */ msm_geni_serial_set_manual_flow(false, port); - wait_for_transfers_inflight(&port->uport); + ret = wait_for_transfers_inflight(&port->uport); + if (ret) { + IPC_LOG_MSG(port->ipc_log_pwr, + "%s: wait_for_transfer_inflight return ret:%d\n", + __func__, ret); + /* Flow on from UART */ + msm_geni_serial_allow_rx(port); + return -EBUSY; + } /* * Stop Rx. * Disable Interrupt