Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1027365yba; Thu, 4 Apr 2019 02:45:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwZh5l6lsooaQaHudu9B9BADRUJ58zeZ8t+2Wog2LdiiLuxe7ELw3toW3DGmrotgi2+UnuY X-Received: by 2002:a17:902:a512:: with SMTP id s18mr5264891plq.185.1554371119378; Thu, 04 Apr 2019 02:45:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554371119; cv=none; d=google.com; s=arc-20160816; b=fNHCAfUfqZfHAGO1kXw2ZbDTufLseL+/VXSWEByytYMfqKqXQQW31fnalbG0ylvZ8s swhDKBATA93d22j4WnYMj1ZINIenmwYiJOcNVcNL2BIV5H3ScqnednMTZFQ1KEBOHnz/ vSU2OS59+EEIzAwzuUi+FoLCRnDoiUmWIgGbSbSH94IEJtcXlDCVcwu/S6gPS6IV9ivc 0KZ7LrPXZg1rVEUka5JUQTd0f31QhKwhV9jekdKUnKr65M4qMoT+BSLo3vYxnBEBNp0k 0n7WWq8ElVohU+CT8pRXxjfT7C6XlYFhQsqDLKSr7TMyqOKNrcHrYJjfcwNA5zL8Ghu5 oZvg== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mVi+Fr62fhqGK4Bj76n/hUf8zUuzMZTDjg1enjKXbis=; b=SGoh8VeudQNAS0UCXfi7vKIKz1PV65fEJ65W4yOxgWzOsS6XDykknXFl6SRzV8nv5q u54oqXC6Ir4ZIp4I6Wgfki2Mbgp6fFarZx79PQP0TAzmzj4nlk6tGjvm+GBbUb7IBoTc skP3oPYLdmafrxEXXlQ2JbZXpTDcvN0j2is4ywapE8rfkFYF+5mmc39M/jET/t58UdLj B9Y3AfQhj3IYphjB5xzVXWsgblySikZV9OliWsw0+y7k2g9Wok5TB/i1m/nJgIpGhqEP dcX5mS6IeE2qD8FLAxNzXrNOBsKB5+18whsF0Cv3GW8OAEKBmuuk1fsDEl6ngSQVhbSh CZXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XguwDsmA; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 130si15636944pgc.256.2019.04.04.02.45.03; Thu, 04 Apr 2019 02:45:19 -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; dkim=pass header.i=@kernel.org header.s=default header.b=XguwDsmA; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731124AbfDDI7r (ORCPT + 99 others); Thu, 4 Apr 2019 04:59:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:36140 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730818AbfDDI7n (ORCPT ); Thu, 4 Apr 2019 04:59:43 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1477B20652; Thu, 4 Apr 2019 08:59:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368382; bh=A+q1ljrLu88squrDz/VCmdUTab98J4rAOPHq46cfohA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XguwDsmAnO9byTKVMKm8TIvq1UeKuKc8TtQmqsRm+V8C1KG/KhLmWWW5EHwz96o8+ rILID60mB6bHvCVWhoAf10HvEOCbQIEry7STjc4GuaeF3xegCCSC0oHelgcsav2FkX JoNbZXnMIV4JPHOJtGBZIwIzlD21Lo/w122MvbZ4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Razvan Stefanescu , Richard Genoud Subject: [PATCH 4.19 004/187] tty/serial: atmel: RS485 HD w/DMA: enable RX after TX is stopped Date: Thu, 4 Apr 2019 10:45:41 +0200 Message-Id: <20190404084603.306298950@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Razvan Stefanescu commit 69646d7a3689fbe1a65ae90397d22ac3f1b8d40f upstream. 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 Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/atmel_serial.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -163,6 +163,8 @@ struct atmel_uart_port { unsigned int pending_status; spinlock_t lock_suspended; + bool hd_start_rx; /* can start RX during half-duplex operation */ + #ifdef CONFIG_PM struct { u32 cr; @@ -805,8 +807,13 @@ static void atmel_complete_tx_dma(void * 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); @@ -1252,9 +1259,20 @@ atmel_handle_transmit(struct uart_port * 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); } }