Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4607177pxj; Wed, 12 May 2021 09:08:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlFJ64+++70DRcr6E+Vyq9L9gr1vVCQ8Wboh1QYfhSKz4RIQWm0mWGrIMn/AS/uCpRktTM X-Received: by 2002:a50:8fe6:: with SMTP id y93mr44061387edy.224.1620835700474; Wed, 12 May 2021 09:08:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835700; cv=none; d=google.com; s=arc-20160816; b=NA4gG7yczCz1h+zWMwoHSPekM9LO9WAb1Voo3AOMpQAUdJPdOQQ/7kUeFQdYB984Y9 TSAG/Z4C53zfIZvMrAogLedRyEst3ZChoecaMSx7M+m6pF9HAUc45qRGTfDcjujKwxHt PLfTP4zW8StpvcF2ZZE06pqiTsjEwpFrU8fykfHW9PKf3zhA5YmUvmy45EHlxUef87d7 Y/LYAfV8WDzHsvfvngPW/gJR5n+m0PRJ+CHIQejssAh1xxUsjcBL63KJ2GkmCx+U2qP1 QYTZClAjvjttr0fXTEOeNiI8p27DRZusA/mi/VIGgfFJy2xuhnT18qS2C6wBxPuYwhTj 6m2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=k+hNOgmLUgpTEPiH8yrZFgtHm4pojIT/cxkpKF4SWrs=; b=i2vKJzQ9ryR/x4vzXIzCA5L4AiivOuWVvMG3Ms5l6tRVcdDopWochfH0HtOdXzPqmf QvxRMQLyAD748TCMkWdFKewtSKqOYpU69f8hqq9inCtHaBil8cyPwB5d8SoudM26WNEK giJ9WEsGWLcbWGd6r2OPmizDbkX7bfv0gijvFGREm8XIW4wGmjr/nN+V3AEY+cB4AtnB Y7oC2xyXc4/rrwJz8J9r1q7XjU6oR+V7vhosf99grJZrOoEnd4BGlQQ5SVptVFA2pSVe BTnRsm/TG0lD2A9bJpanXXop5J4B/2XbmkRdaKh0ylV3jUqBqX3/yWzCU0rrNAxNOFSa R6Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rIgIdKsI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g19si112705edu.41.2021.05.12.09.07.55; Wed, 12 May 2021 09:08:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=rIgIdKsI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238395AbhELQEc (ORCPT + 99 others); Wed, 12 May 2021 12:04:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:40396 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235555AbhELP2b (ORCPT ); Wed, 12 May 2021 11:28:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BBF4461C24; Wed, 12 May 2021 15:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832425; bh=kX150s1Ymg4Ua5g2q+5MLrgZHq/tJpM78ypxZUsZkf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rIgIdKsIl7UmdTX6mDRvafLCSaZE70SCISsA2Q6Ek48ZZr6efGWbLsMLv121ArAzW gtSoAByeMiA6MVrDOks9N010+WjWsckHW5HJiyynpqIfh3/DTVFXKUp2md6ff4I7SB flZn9H0Tc8U5WJEjEE4vBYQdgb/wE8uze6UQauZs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dario Binacchi , Sasha Levin Subject: [PATCH 5.10 274/530] serial: omap: fix rs485 half-duplex filtering Date: Wed, 12 May 2021 16:46:24 +0200 Message-Id: <20210512144828.817543016@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dario Binacchi [ Upstream commit e2a5e8448e7393e96ccde346c68764b40a52cc10 ] Data received during half-duplex transmission must be filtered. If the target device responds quickly, emptying the FIFO at the end of the transmission can erase not only the echo characters but also part of the response message. By keeping the receive interrupt enabled even during transmission, it allows you to filter each echo character and only in a number equal to those transmitted. The issue was generated by a target device that started responding 240us later having received a request in communication at 115200bps. Sometimes, some messages received by the target were missing some of the first bytes. Fixes: 3a13884abea0 ("tty/serial: omap: empty the RX FIFO at the end of half-duplex TX") Signed-off-by: Dario Binacchi Link: https://lore.kernel.org/r/20210418094705.27014-1-dariobin@libero.it Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/omap-serial.c | 39 ++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c index 1583e93b2202..84e8158088cd 100644 --- a/drivers/tty/serial/omap-serial.c +++ b/drivers/tty/serial/omap-serial.c @@ -159,6 +159,8 @@ struct uart_omap_port { u32 calc_latency; struct work_struct qos_work; bool is_suspending; + + unsigned int rs485_tx_filter_count; }; #define to_uart_omap_port(p) ((container_of((p), struct uart_omap_port, port))) @@ -329,19 +331,6 @@ static void serial_omap_stop_tx(struct uart_port *port) serial_out(up, UART_IER, up->ier); } - if ((port->rs485.flags & SER_RS485_ENABLED) && - !(port->rs485.flags & SER_RS485_RX_DURING_TX)) { - /* - * Empty the RX FIFO, we are not interested in anything - * received during the half-duplex transmission. - */ - serial_out(up, UART_FCR, up->fcr | UART_FCR_CLEAR_RCVR); - /* Re-enable RX interrupts */ - up->ier |= UART_IER_RLSI | UART_IER_RDI; - up->port.read_status_mask |= UART_LSR_DR; - serial_out(up, UART_IER, up->ier); - } - pm_runtime_mark_last_busy(up->dev); pm_runtime_put_autosuspend(up->dev); } @@ -367,6 +356,10 @@ static void transmit_chars(struct uart_omap_port *up, unsigned int lsr) serial_out(up, UART_TX, up->port.x_char); up->port.icount.tx++; up->port.x_char = 0; + if ((up->port.rs485.flags & SER_RS485_ENABLED) && + !(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) + up->rs485_tx_filter_count++; + return; } if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) { @@ -378,6 +371,10 @@ static void transmit_chars(struct uart_omap_port *up, unsigned int lsr) serial_out(up, UART_TX, xmit->buf[xmit->tail]); xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); up->port.icount.tx++; + if ((up->port.rs485.flags & SER_RS485_ENABLED) && + !(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) + up->rs485_tx_filter_count++; + if (uart_circ_empty(xmit)) break; } while (--count > 0); @@ -421,7 +418,7 @@ static void serial_omap_start_tx(struct uart_port *port) if ((port->rs485.flags & SER_RS485_ENABLED) && !(port->rs485.flags & SER_RS485_RX_DURING_TX)) - serial_omap_stop_rx(port); + up->rs485_tx_filter_count = 0; serial_omap_enable_ier_thri(up); pm_runtime_mark_last_busy(up->dev); @@ -492,8 +489,13 @@ static void serial_omap_rlsi(struct uart_omap_port *up, unsigned int lsr) * Read one data character out to avoid stalling the receiver according * to the table 23-246 of the omap4 TRM. */ - if (likely(lsr & UART_LSR_DR)) + if (likely(lsr & UART_LSR_DR)) { serial_in(up, UART_RX); + if ((up->port.rs485.flags & SER_RS485_ENABLED) && + !(up->port.rs485.flags & SER_RS485_RX_DURING_TX) && + up->rs485_tx_filter_count) + up->rs485_tx_filter_count--; + } up->port.icount.rx++; flag = TTY_NORMAL; @@ -544,6 +546,13 @@ static void serial_omap_rdi(struct uart_omap_port *up, unsigned int lsr) return; ch = serial_in(up, UART_RX); + if ((up->port.rs485.flags & SER_RS485_ENABLED) && + !(up->port.rs485.flags & SER_RS485_RX_DURING_TX) && + up->rs485_tx_filter_count) { + up->rs485_tx_filter_count--; + return; + } + flag = TTY_NORMAL; up->port.icount.rx++; -- 2.30.2