Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp485173img; Mon, 18 Mar 2019 07:33:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgedVxbzivH8ORVG6jmWFNi5n07UCsDk0s4BD9z+AYu4VNvLaif3dYeiSx9yghLZn1K7qi X-Received: by 2002:a62:1882:: with SMTP id 124mr19531692pfy.101.1552919593115; Mon, 18 Mar 2019 07:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552919593; cv=none; d=google.com; s=arc-20160816; b=nhV3DiOcvAzwIEHz/AmtDhy8vhxl/Ps0X/e32vqZRK32sBojNMfJy9VJLqtV4I5wSa z1eAXT5HQxGpezRQudoqNYczxGuovve0PIwQkMe+lUgbdGix0UWftBL7+ytQRUBy0wWm BjPvpnInhi2w69kBRtE8iFYbd6LkamR3M+CcQNmnEqiGUfLpTF4bD6NL8vWsA7vI/0BE o4bZsjIKZu3J3V5uQJWI4CCzTZTrtPXXXmOwxRkrMq4vslZ6y6QNyStU+znR5Tuw3IX7 mw78keVLat1saviXntmw6+5E72LhA4B3I/fIpd6FK8lzPs7cGJH04Qc9uK0gv02iK0GD FWkA== 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=JxqhC2xwOgalbM2dBeQs6LignjGK3x0RrNurwzNN0Nc=; b=rQvD3mWCG/z8kl6FvCTfNzN26qztOoTYXhvndEb6qRxRIUvXfwdAjRIpntPkvudOb+ ts0OyEOyfGl3E/PR5mZSfwgKAOcd1ktJO3p/jMPv1Nd6E+TN8f0HpcVGb6mmCVKIsAHF Mm3X4JjSdThv1JDtwOigM4b9H2qSYViowzVYftc66d+QMFSaJ5z+wPqeVRBgdbXyMqX2 dY5qv693N2vyoHbx0CvTXK7w9HcZMJuISRw1ip+kHVHJo/0q9lHP0yN4Qcxv0gdoUg1w ZtZI9h4Eo8NFW27XfCTUlEcxTmXVPaHgdQPY9fM8M0Ize44/pWm0HHtap0RtrMeaJ1OD v7AA== 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 x14si9347549pgq.185.2019.03.18.07.32.57; Mon, 18 Mar 2019 07:33:13 -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 S1727716AbfCROav (ORCPT + 99 others); Mon, 18 Mar 2019 10:30:51 -0400 Received: from mout01.posteo.de ([185.67.36.141]:59085 "EHLO mout01.posteo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727183AbfCROau (ORCPT ); Mon, 18 Mar 2019 10:30:50 -0400 Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id EFDE4160060 for ; Mon, 18 Mar 2019 15:30:47 +0100 (CET) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 44NJWT3PTtz6tmQ; Mon, 18 Mar 2019 15:30:45 +0100 (CET) Subject: Re: [PATCH 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: <20190315092334.13246-1-razvan.stefanescu@microchip.com> <20190315092334.13246-3-razvan.stefanescu@microchip.com> From: Richard Genoud Message-ID: Date: Mon, 18 Mar 2019 15:30:45 +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: <20190315092334.13246-3-razvan.stefanescu@microchip.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ adding Gil Weber in Cc: ] Le 15/03/2019 à 10:23, 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. I was sure I've already seen something like that. Gil, could you give it a test ? you can add : Cc: stable@vger.kernel.org Fixes: b389f173aaa1 ("tty/serial: atmel: RS485 half duplex w/DMA: enable RX after TX is done") Since patch 1/2 is needed for this one, I think you should add also Cc:stable / Fixes: to the previous patch. > Signed-off-by: Razvan Stefanescu > --- > 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 a6577b1c4461..b0141dcbbb61 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; > @@ -934,8 +936,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); > @@ -1379,9 +1386,21 @@ 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) { > + atmel_port->hd_start_rx = false; > + atmel_start_rx(port); > + } else { > + dev_warn(port->dev, "Should start RX, but TX fifo is not empty\n"); What will happen in this case ? > + } > + return; > + } > + > atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_tx); > } > } > Thanks !