Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4374375img; Tue, 26 Mar 2019 08:13:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqya9ZlVANOLPeIP06cXk03ZZsNDC46lu2wkJR87TC/WApnoq8ZPecdToZHbA1eHCE6Rj2sc X-Received: by 2002:a63:d84b:: with SMTP id k11mr29182638pgj.281.1553613203020; Tue, 26 Mar 2019 08:13:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553613203; cv=none; d=google.com; s=arc-20160816; b=0EqOVO6nPcGM0EUy4xnHsn+rPhZPBTqh2c4qy5vPT+6oztWtO5k7nJ68uV1vWXPKr3 CO2J7BOLd7V9dmfgQky8MjUWJR6klEfFArIP6zCnNaRHHSJmZpvatN7zOLYzZOR5dRNn g6+wdIr2XPodsIck4cLHQPjJWy6YttoTdGgKgffdWArAX2vnm3zU0gQgGZ101cmTbcuo qqZ0n2TPD5p0wB6FDHPr9H4dV9aJsyzLFgZyWMZU8rizgssRooXqbpR/WTav+xVW8hlo fVXTCMJh45O0yfYVHw1P5lnZYQD2DnpNNe8a52QZbGm6ydkN2Lv9jfPcgag3SaQC94By Q+dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=fb4j0uY9FLhquSCixMsfFtNFLP8mQKtQz4i6DOQ+OZY=; b=dKIc9NxkRx7b6QJAVKzS9lASyT1jOwbpcSJ8zTzSQWgOnwoRkGcR+hKv+yiJjL5x0k q/XZTpuANO9RC87UtKoWEerF3rNYuQGo0SHN7j3N0ng384XTtc+eLT1PPENdlSzOVkcy rVgTOyNHv3Bz6tOHJILIz7teVTrPzSj3bWrCg461CG2HejlIKfMLmrObsJgCcsKA7eZV HwaekgxdPeoqqrX+t7zRmHdjEgnq0yyUNZm9NpEZmZsDA/o1W/FhhcqGHBBWOyJUnb3F mimWDWFezuGFT5F+DoKKsBvYj0EoetQi+SV8mxswlRyx5TCAXU7ZMRAKNHuEVihfBl66 dY0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bb11si16815919plb.420.2019.03.26.08.13.07; Tue, 26 Mar 2019 08:13:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731546AbfCZPMP (ORCPT + 99 others); Tue, 26 Mar 2019 11:12:15 -0400 Received: from mout01.posteo.de ([185.67.36.141]:51844 "EHLO mout01.posteo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731919AbfCZPMN (ORCPT ); Tue, 26 Mar 2019 11:12:13 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 60847160066 for ; Tue, 26 Mar 2019 16:12:09 +0100 (CET) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 44TF3W3CJYz6tmK; Tue, 26 Mar 2019 16:12:07 +0100 (CET) Subject: Re: [PATCH v2 2/2] tty/serial: atmel: RS485 HD w/DMA: enable RX after TX is stopped To: Razvan Stefanescu , Greg Kroah-Hartman , Jiri Slaby Cc: Gil Weber , Nicolas Ferre , Alexandre Belloni , Ludovic Desroches , linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <20190319132035.18481-1-razvan.stefanescu@microchip.com> <20190319132035.18481-3-razvan.stefanescu@microchip.com> From: Richard Genoud Message-ID: <58640e9d-5570-3649-31cd-3ffcd0d6c3af@sorico.fr> Date: Tue, 26 Mar 2019 16:12:05 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <20190319132035.18481-3-razvan.stefanescu@microchip.com> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 19/03/2019 à 14:20, Razvan Stefanescu a écrit : > In half-duplex operation, RX should be started after TX completes. > > If DMA is used, there is a case when the DMA transfer completes but the > TX FIFO is not emptied, so the RX cannot be restarted just yet. > > Use a boolean variable to store this state and rearm TX interrupt mask > to be signaled again that the transfer finished. In interrupt transmit > handler this variable is used to start RX. A warning message is generated > if RX is activated before TX fifo is cleared. > > Fixes: b389f173aaa1 ("tty/serial: atmel: RS485 half duplex w/DMA: enable > RX after TX is done") > Signed-off-by: Razvan Stefanescu Acked-by: Richard Genoud NB: backport on kernel older than 4.20 will fail because of the iso7816 variables fidi_min/fidi_max. > --- > Changelog: > v2: > - start RX and display warning in case of error > - add fix info > > drivers/tty/serial/atmel_serial.c | 25 ++++++++++++++++++++++--- > 1 file changed, 22 insertions(+), 3 deletions(-) > > diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c > index b4b89a16a41b..5b2f859c327c 100644 > --- a/drivers/tty/serial/atmel_serial.c > +++ b/drivers/tty/serial/atmel_serial.c > @@ -166,6 +166,8 @@ struct atmel_uart_port { > unsigned int pending_status; > spinlock_t lock_suspended; > > + bool hd_start_rx; /* can start RX during half-duplex operation */ > + > /* ISO7816 */ > unsigned int fidi_min; > unsigned int fidi_max; > @@ -933,8 +935,13 @@ static void atmel_complete_tx_dma(void *arg) > if (!uart_circ_empty(xmit)) > atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_tx); > else if (atmel_uart_is_half_duplex(port)) { > - /* DMA done, stop TX, start RX for RS485 */ > - atmel_start_rx(port); > + /* > + * DMA done, re-enable TXEMPTY and signal that we can stop > + * TX and start RX for RS485 > + */ > + atmel_port->hd_start_rx = true; > + atmel_uart_writel(port, ATMEL_US_IER, > + atmel_port->tx_done_mask); > } > > spin_unlock_irqrestore(&port->lock, flags); > @@ -1378,9 +1385,20 @@ atmel_handle_transmit(struct uart_port *port, unsigned int pending) > struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); > > if (pending & atmel_port->tx_done_mask) { > - /* Either PDC or interrupt transmission */ > atmel_uart_writel(port, ATMEL_US_IDR, > atmel_port->tx_done_mask); > + > + /* Start RX if flag was set and FIFO is empty */ > + if (atmel_port->hd_start_rx) { > + if (!(atmel_uart_readl(port, ATMEL_US_CSR) > + & ATMEL_US_TXEMPTY)) > + dev_warn(port->dev, "Should start RX, but TX fifo is not empty\n"); > + > + atmel_port->hd_start_rx = false; > + atmel_start_rx(port); > + return; > + } > + > atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_tx); > } > } >