From patchwork Tue Jan 11 16:44:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Caron X-Patchwork-Id: 12710048 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B73CFC433EF for ; Tue, 11 Jan 2022 16:47:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TWMm5yfu4ow9Yj2OyU6aWTubfqhTI9HtT+kpP+V6H08=; b=tzlXov3eXCI1vN fnuuU54NMzaHT+CSzope7kAIMwLVpKFYzdoOz7HV1ZQRYYExsYFM/DiXpjeNuQNOUrDxpoxuw71xL g+Wo8b8lls0SeD/VgzoyKSZzFqH3rwOBS5rhJkml7FDn8jetvZ4vwF7ZCtblJV+bbtwzEgbZE7P8q BVTDijEjC6ivcbYCU4/qkVjS7e9xw+Szv2q5Gn5MQB7xHhBqU29ox2Dae6t0cApmCZqwHr2tkCrw9 +S8fd8zUkGxQGnLR00q4kVcG65U13rzxNvQ3ggnuwYuRrQjzuAIaJ32egfoWrfdeHtsnVu73ctWy8 cFPSgRDowEX2omcK3OEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7KHc-00GwzC-KQ; Tue, 11 Jan 2022 16:46:04 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7KHH-00Gws8-EI for linux-arm-kernel@lists.infradead.org; Tue, 11 Jan 2022 16:45:44 +0000 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20BGCfWb022160; Tue, 11 Jan 2022 17:45:26 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=DUFh1SKt2sWCGI0makXOoBN/QEWeJJpABfJYD6qhEeA=; b=RunS487M0nGsePY944EKUzlt0hPZcCSlcyeUFE75ZRIcmwUrCKVhJ2ZYpeF0rgmtQZ7T fG2ow+YI+lWSfPpKjaYO3nr5/Q9406Zbhcx6tA7cHOkeOEsIOmPNI3wUSI3sqzhgKT2n mOUEm/7ol5dVeBa7boYn7P9I2aKSxaoRaoxHkGMFQob9/VcSCIG69elFlHZjWc5fZYc5 +IlxludzNtaurwf3P34BQtgTGYYwJD7UHWVfnBRVYTZayfspcXyg4nomiMW/m7CuRqD1 cS15Q5hNSmcXVK66uekf/wXjoALxkabNOqFHcqEhfCftqLk+oQhZkad/yyJamg0Oq/kl fw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3dh2m5uyub-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jan 2022 17:45:25 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3DDDC10002A; Tue, 11 Jan 2022 17:45:25 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 353E1245FC8; Tue, 11 Jan 2022 17:45:25 +0100 (CET) Received: from localhost (10.75.127.46) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Tue, 11 Jan 2022 17:45:24 +0100 From: Valentin Caron To: Greg Kroah-Hartman CC: Jiri Slaby , Maxime Coquelin , Alexandre Torgue , Erwan Le Ray , Valentin Caron , , , , Subject: [PATCH 1/2] serial: stm32: prevent TDR register overwrite when sending x_char Date: Tue, 11 Jan 2022 17:44:40 +0100 Message-ID: <20220111164441.6178-2-valentin.caron@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220111164441.6178-1-valentin.caron@foss.st.com> References: <20220111164441.6178-1-valentin.caron@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-11_04,2022-01-11_01,2021-12-02_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220111_084543_807019_33347300 X-CRM114-Status: GOOD ( 17.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When sending x_char in stm32_usart_transmit_chars(), driver can overwrite the value of TDR register by the value of x_char. If this happens, the previous value that was present in TDR register will not be sent through uart. This code checks if the previous value in TDR register is sent before writing the x_char value into register. Fixes: 48a6092fb41f ("serial: stm32-usart: Add STM32 USART Driver") Signed-off-by: Valentin Caron --- drivers/tty/serial/stm32-usart.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index 1f89ab0e49ac..c1b8828451c8 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -550,11 +550,23 @@ static void stm32_usart_transmit_chars(struct uart_port *port) struct stm32_port *stm32_port = to_stm32_port(port); const struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; struct circ_buf *xmit = &port->state->xmit; + u32 isr; + int ret; if (port->x_char) { if (stm32_usart_tx_dma_started(stm32_port) && stm32_usart_tx_dma_enabled(stm32_port)) stm32_usart_clr_bits(port, ofs->cr3, USART_CR3_DMAT); + + /* Check that TDR is empty before filling FIFO */ + ret = + readl_relaxed_poll_timeout_atomic(port->membase + ofs->isr, + isr, + (isr & USART_SR_TXE), + 10, 1000); + if (ret) + dev_warn(port->dev, "1 character may be erased\n"); + writel_relaxed(port->x_char, port->membase + ofs->tdr); port->x_char = 0; port->icount.tx++; From patchwork Tue Jan 11 16:44:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Valentin Caron X-Patchwork-Id: 12710047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 79EA3C433EF for ; Tue, 11 Jan 2022 16:47:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YpQZDtSkNpZJ2XBbJ7yT1INTaZ1tp+F9S+p8NiRNErw=; b=Ayqy9A5FsyLlIc GjXBQpBbrpjK3P1UFf7j/xspBZ1HXMm9zKvFZjSzWfhsZawuz604guEwrZ5nGK0/jEtqIvM2VoIsB opmhNZmVe/xiT/PsUOBYTjUGTc9CvTA5n60qLfMDfRAL0+H5uZ63OItL2ZcuJsoFaLtvPKaE8GL7N nOjs94Y468fsw/M67wxEt0dIbO+Pl4ncxkFID80W2XQAKJxTbd0cWjwBtwKlmwT2mDmiy+ykzZVXi 5rrKQyryoaK1zhTvul9SvPFIuebtSAivo3nQ9ERmNqFvJFdMU9QrYuct4qmnOeQ6gaIkXuJEcJ5yb CineRMKO4W/AIKCr5ljA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7KHS-00Gwvv-Da; Tue, 11 Jan 2022 16:45:54 +0000 Received: from mx07-00178001.pphosted.com ([185.132.182.106]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n7KHF-00Gws1-WD for linux-arm-kernel@lists.infradead.org; Tue, 11 Jan 2022 16:45:43 +0000 Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20BBoEdc023994; Tue, 11 Jan 2022 17:45:27 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=HadlWm8vPa6gLGI+Lp8NuxhfCBgbLjPprgpIUAa/Nhs=; b=5D3HQTTKTA+NA0N4Kr33bvBZnp8rDT3ckfd7OqdskD1Qn79//ciQiEh6dpWgWCYzFmjb dKBNwWNI3XcSoYBr2+3DA4ENzVecprnEAxsuzOsY0/sHkNNEIbpuEELuBF2QLdiu/N7R iXQPfEEqO+3ZYK/kRg0Lz5NwsyLA/cIYgDAHBn/B+LmFof+Myf2Qy4A0EtSw+K/yo53f cyN0PRiBhYMX1qeJhRY2hqIlg30GJeolRX0cmOYk3PEoY72+ubBjbaq49JVT3Bo+awKg dZodkOS/T6mxs2l2CErR6I8tUBqWEY8zJ4B+sLTd8b9+WLmaQ39pG3JDYa7XU8eiMrj6 jQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3dh9cb9c6a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Jan 2022 17:45:27 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id E2A4710002A; Tue, 11 Jan 2022 17:45:26 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id DB358245FC8; Tue, 11 Jan 2022 17:45:26 +0100 (CET) Received: from localhost (10.75.127.45) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Tue, 11 Jan 2022 17:45:26 +0100 From: Valentin Caron To: Greg Kroah-Hartman CC: Jiri Slaby , Maxime Coquelin , Alexandre Torgue , Erwan Le Ray , Valentin Caron , , , , Subject: [PATCH 2/2] serial: stm32: fix software flow control transfer Date: Tue, 11 Jan 2022 17:44:41 +0100 Message-ID: <20220111164441.6178-3-valentin.caron@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220111164441.6178-1-valentin.caron@foss.st.com> References: <20220111164441.6178-1-valentin.caron@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-11_04,2022-01-11_01,2021-12-02_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220111_084542_380405_9D411822 X-CRM114-Status: GOOD ( 16.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org x_char is ignored by stm32_usart_start_tx() when xmit buffer is empty. Fix start_tx condition to allow x_char to be sent. Fixes: 48a6092fb41f ("serial: stm32-usart: Add STM32 USART Driver") Signed-off-by: Erwan Le Ray Signed-off-by: Valentin Caron --- drivers/tty/serial/stm32-usart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index c1b8828451c8..9570002d07e7 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -742,7 +742,7 @@ static void stm32_usart_start_tx(struct uart_port *port) struct serial_rs485 *rs485conf = &port->rs485; struct circ_buf *xmit = &port->state->xmit; - if (uart_circ_empty(xmit)) + if (uart_circ_empty(xmit) && !port->x_char) return; if (rs485conf->flags & SER_RS485_ENABLED) {