Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp678677pxb; Tue, 5 Apr 2022 18:26:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9xpi6gAZmWdFCB/Ekq//mws6gDFEPLSyTsbMBo95lODH8zWtZ5RLVwKK/HNGGq9MrWnZf X-Received: by 2002:a50:fe81:0:b0:419:16a5:d265 with SMTP id d1-20020a50fe81000000b0041916a5d265mr6424528edt.4.1649208366217; Tue, 05 Apr 2022 18:26:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649208366; cv=none; d=google.com; s=arc-20160816; b=Cd4cRaxLeo+THCHUeAc/Xpn1BgeSjBOlrd2zl5oaclKiqfv6gQMEqXpGptjqf1IbA5 ufiRB9X+4NWXyOdPu35YcQ5pW8/lZg51OzK/HvJ1kjYQ4sjypxx7ESUPjpE0DXey8MK8 r9Ar1bz8O4xUY5YPH07yobmhYQmzGnAjOZLNATz9XB5k6yFsV6HwzRzDN8qNFOMzVzs+ QUbE03g9w50ZxyI3WITA3ZdsAe8WPuRbGnXw7O3mxuWU5gEW4IHorSMSqFvR3tz8GlqJ 2rid6AqQdXelYhZ52NWtiyyQp/6KnS9FVQTl0R6hSkOWugDGhN+vITvbXV4+IO7CLLEM L97Q== 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=Cbi6IOE1dF//+4drU4vr6igG9ElMP6kFDIx+YkxLdbg=; b=djc3/C+ybFx2tEVNbhaUGZ+HTQ7V5ET364wiAg49+PtNHB/SOzyksv/5ZyXKGdGnmC DXKIpp+BcUy9gRzk9u4toGFK2KKolJ7B/Y3ILteejeDmZGh5VAZsjSY1rCVXAM0MHxkr ksD3pG1JE8yzzCYXjg5wcppQNm51+MBLImW0age2zTAnLgRNK0To08QsitG+03eYxZ99 UrE6GLN9o5GOSs6hAPaGJ6/RXGMlTQGGqgAvWpb4vBfSoO3qoHj+GeFDb6L/ziI6u+WT SJSBRCVzI0lhPA6FCJS6MjF/qUO8mNJiAUdBK6CaEaOgZLqFvrULAEjMb/WcOUlfgTIm OOpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TGfj6wFf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id vp14-20020a17090712ce00b006dfb07cee44si9042789ejb.814.2022.04.05.18.25.41; Tue, 05 Apr 2022 18:26:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TGfj6wFf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S238311AbiDEJcV (ORCPT + 99 others); Tue, 5 Apr 2022 05:32:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239504AbiDEIUI (ORCPT ); Tue, 5 Apr 2022 04:20:08 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65691B83; Tue, 5 Apr 2022 01:14:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 167CDB81BAC; Tue, 5 Apr 2022 08:14:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66264C385A1; Tue, 5 Apr 2022 08:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146485; bh=WcL+NXvQBZHCnmbnNDwWuBj2td89mQiyOMS49zpQNb8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TGfj6wFfs24JYaCzr9O8vUwdFNM3Cr+ynSwdLaVT3iQrv+hG6UcxSpMHXhPaRILj2 Xp1LmP9iz+DLIB9WuvXhlQJlHsZw8RiZrS9ntP0paJBlSukMLiW1hmrqVkRdxXURN3 cd7W/kb91YXAJ2z4sy4AFbqoOHvS/BCAIsmkkLas= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gilles Buloz , Andy Shevchenko , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Sasha Levin Subject: [PATCH 5.17 0781/1126] serial: 8250: fix XOFF/XON sending when DMA is used Date: Tue, 5 Apr 2022 09:25:28 +0200 Message-Id: <20220405070430.500467964@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilpo Järvinen [ Upstream commit f58c252e30cf74f68b0054293adc03b5923b9f0e ] When 8250 UART is using DMA, x_char (XON/XOFF) is never sent to the wire. After this change, x_char is injected correctly. Create uart_xchar_out() helper for sending the x_char out and accounting related to it. It seems that almost every driver does these same steps with x_char. Except for 8250, however, almost all currently lack .serial_out so they cannot immediately take advantage of this new helper. The downside of this patch is that it might reintroduce the problems some devices faced with mixed DMA/non-DMA transfer which caused revert f967fc8f165f (Revert "serial: 8250_dma: don't bother DMA with small transfers"). However, the impact should be limited to cases with XON/XOFF (that didn't work with DMA capable devices to begin with so this problem is not very likely to cause a major issue, if any at all). Fixes: 9ee4b83e51f74 ("serial: 8250: Add support for dmaengine") Reported-by: Gilles Buloz Tested-by: Gilles Buloz Reviewed-by: Andy Shevchenko Signed-off-by: Ilpo Järvinen Link: https://lore.kernel.org/r/20220314091432.4288-2-ilpo.jarvinen@linux.intel.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/8250/8250_dma.c | 11 ++++++++++- drivers/tty/serial/8250/8250_port.c | 4 +--- drivers/tty/serial/serial_core.c | 14 ++++++++++++++ include/linux/serial_core.h | 2 ++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/8250/8250_dma.c b/drivers/tty/serial/8250/8250_dma.c index 890fa7ddaa7f..b3c3f7e5851a 100644 --- a/drivers/tty/serial/8250/8250_dma.c +++ b/drivers/tty/serial/8250/8250_dma.c @@ -64,10 +64,19 @@ int serial8250_tx_dma(struct uart_8250_port *p) struct uart_8250_dma *dma = p->dma; struct circ_buf *xmit = &p->port.state->xmit; struct dma_async_tx_descriptor *desc; + struct uart_port *up = &p->port; int ret; - if (dma->tx_running) + if (dma->tx_running) { + if (up->x_char) { + dmaengine_pause(dma->txchan); + uart_xchar_out(up, UART_TX); + dmaengine_resume(dma->txchan); + } return 0; + } else if (up->x_char) { + uart_xchar_out(up, UART_TX); + } if (uart_tx_stopped(&p->port) || uart_circ_empty(xmit)) { /* We have been called from __dma_tx_complete() */ diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index fd0339d22491..9f116e75956e 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -1819,9 +1819,7 @@ void serial8250_tx_chars(struct uart_8250_port *up) int count; if (port->x_char) { - serial_out(up, UART_TX, port->x_char); - port->icount.tx++; - port->x_char = 0; + uart_xchar_out(port, UART_TX); return; } if (uart_tx_stopped(port)) { diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 0db90be4c3bc..f67540ae2a88 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -644,6 +644,20 @@ static void uart_flush_buffer(struct tty_struct *tty) tty_port_tty_wakeup(&state->port); } +/* + * This function performs low-level write of high-priority XON/XOFF + * character and accounting for it. + * + * Requires uart_port to implement .serial_out(). + */ +void uart_xchar_out(struct uart_port *uport, int offset) +{ + serial_port_out(uport, offset, uport->x_char); + uport->icount.tx++; + uport->x_char = 0; +} +EXPORT_SYMBOL_GPL(uart_xchar_out); + /* * This function is used to send a high-priority XON/XOFF character to * the device diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index c58cc142d23f..8c32935e1059 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -458,6 +458,8 @@ extern void uart_handle_cts_change(struct uart_port *uport, extern void uart_insert_char(struct uart_port *port, unsigned int status, unsigned int overrun, unsigned int ch, unsigned int flag); +void uart_xchar_out(struct uart_port *uport, int offset); + #ifdef CONFIG_MAGIC_SYSRQ_SERIAL #define SYSRQ_TIMEOUT (HZ * 5) -- 2.34.1