From patchwork Mon Dec 11 17:13:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Villeneuve X-Patchwork-Id: 176820 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7205579vqy; Mon, 11 Dec 2023 09:14:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMN3lLAETQ4QpJ9NVNXo/p/LwyQqqYx1lQVQqePtKMjBLD7TlPjIA6HKp1uP/iBj4Rrpv5 X-Received: by 2002:a05:6a21:3398:b0:18f:97c:8235 with SMTP id yy24-20020a056a21339800b0018f097c8235mr2730241pzb.63.1702314876993; Mon, 11 Dec 2023 09:14:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702314876; cv=none; d=google.com; s=arc-20160816; b=D6BEwvcSHk7Sp5rkertSUS6u8O8kBw1pSEtPTgKiWvxrGTaLuHr4bnfJQ/Bj6obnm0 LgbC7PB4ZT2mdd6hwkjwGBq7San3EmgulamXYUo8T0mMbzskSG4ZHz23F/QrxwshiRHu hJkjrx/94U0Kt5ZHM7r4HnkFMp7CLjBIOo8lpZhz1I7tbSf4xyIYf13MCx3oIiFekGe7 EO4NFEalVJsMeYfwYyk1o0Wz+ZdLhKbyHP3as0n+Jw2oTb2CL7YjzCkRbUQo2Bn75ipu k/lh6kLzyXJyPiVj9cuxEmIsP16qhcWEKlHkn3crMmqDQEvjGaMJTTGNCnvQbsE/nGUI WGTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from:dkim-signature; bh=RCNf4eOZsNZBVrawgicgoHTfnt8dk8reDpBLuDlxyRQ=; fh=Qi6QlO2FjtC4agQOlKQZuiYC/gSB+DjbcPQ9tqrzTiE=; b=dQsa2CAE1RVuJAKM9JZjCRkhag0oHpSd4q9RhC7PgxqzKItMUH0ue+pvPurHtkIvFf utyXqnsVfYRAhnDYbFjN2Wsm7mr1/gH+a4x6Yf+NHAj0UnpX8TDMAXkvfV3CdPCewUH4 DmJ0nx6zCagDy8+JiC8Zz2q5nkEAXqmWl21XxQXjqQnIgfjX9EUVqbdDQ6fiODsSrYK3 /4cuSeqGFApCyxrbSdDO809fWMSAInddsytTE51ue1vrVnho/m33BlehEbza2KPkSzI8 zbH/GajeMztRNm5Wd/5sopscShB1UI/vFiY5qJyEw/qnXcfrn36Yc/LHEVg2/BZFIQjm S6kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b=X96dM4g3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id g26-20020aa7875a000000b006ce7afb03absi6222906pfo.131.2023.12.11.09.14.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 09:14:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@hugovil.com header.s=x header.b=X96dM4g3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 5CEF380617F4; Mon, 11 Dec 2023 09:14:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344546AbjLKROM (ORCPT + 99 others); Mon, 11 Dec 2023 12:14:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235006AbjLKROH (ORCPT ); Mon, 11 Dec 2023 12:14:07 -0500 Received: from mail.hugovil.com (mail.hugovil.com [162.243.120.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FBBEE9; Mon, 11 Dec 2023 09:14:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=hugovil.com ; s=x; h=Subject:Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Cc:To :From:subject:date:message-id:reply-to; bh=RCNf4eOZsNZBVrawgicgoHTfnt8dk8reDpBLuDlxyRQ=; b=X96dM4g3l4No577Bf7WIWEpoad XmPG7kYFvJXG6KjP3FqpW4K9cG3oU3sd8YON/mQMbLyB5y17Y6n28gCfwrjFIUdhsWV6frA7EJaJ1 14/MVS8kUVkG/JsrSaIi/u0LbhuncEMp7md/1r5yo6rxmqoKlsh32260jX9+a9S/bUNg=; Received: from modemcable168.174-80-70.mc.videotron.ca ([70.80.174.168]:56730 helo=pettiford.lan) by mail.hugovil.com with esmtpa (Exim 4.92) (envelope-from ) id 1rCjr5-0003yC-EK; Mon, 11 Dec 2023 12:14:08 -0500 From: Hugo Villeneuve To: gregkh@linuxfoundation.org, jirislaby@kernel.org, hvilleneuve@dimonoff.com, jringle@gridpoint.com, tomasz.mon@camlingroup.com Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, hugo@hugovil.com, stable@vger.kernel.org Date: Mon, 11 Dec 2023 12:13:53 -0500 Message-Id: <20231211171353.2901416-7-hugo@hugovil.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211171353.2901416-1-hugo@hugovil.com> References: <20231211171353.2901416-1-hugo@hugovil.com> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 70.80.174.168 X-SA-Exim-Mail-From: hugo@hugovil.com X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 Subject: [PATCH v2 6/6] serial: sc16is7xx: fix unconditional activation of THRI interrupt X-SA-Exim-Version: 4.2.1 (built Wed, 08 May 2019 21:11:16 +0000) X-SA-Exim-Scanned: Yes (on mail.hugovil.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 11 Dec 2023 09:14:32 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785006524743427598 X-GMAIL-MSGID: 1785006524743427598 From: Hugo Villeneuve Commit cc4c1d05eb10 ("sc16is7xx: Properly resume TX after stop") changed behavior to unconditionnaly set the THRI interrupt in sc16is7xx_tx_proc(). For example when sending a 65 bytes message, and assuming the Tx FIFO is initially empty, sc16is7xx_handle_tx() will write the first 64 bytes of the message to the FIFO and sc16is7xx_tx_proc() will then activate THRI. When the THRI IRQ is fired, the driver will write the remaining byte of the message to the FIFO, and disable THRI by calling sc16is7xx_stop_tx(). When sending a 2 bytes message, sc16is7xx_handle_tx() will write the 2 bytes of the message to the FIFO and call sc16is7xx_stop_tx(), disabling THRI. After sc16is7xx_handle_tx() exits, control returns to sc16is7xx_tx_proc() which will unconditionally set THRI. When the THRI IRQ is fired, the driver simply acknowledges the interrupt and does nothing more, since all the data has already been written to the FIFO. This results in 2 register writes and 4 register reads all for nothing and taking precious cycles from the I2C/SPI bus. Fix this by enabling the THRI interrupt only when we fill the Tx FIFO to its maximum capacity and there are remaining bytes to send in the message. Fixes: cc4c1d05eb10 ("sc16is7xx: Properly resume TX after stop") Cc: stable@vger.kernel.org Signed-off-by: Hugo Villeneuve --- drivers/tty/serial/sc16is7xx.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c index 7e4b9b52841d..e40e4a99277e 100644 --- a/drivers/tty/serial/sc16is7xx.c +++ b/drivers/tty/serial/sc16is7xx.c @@ -687,6 +687,8 @@ static void sc16is7xx_handle_tx(struct uart_port *port) if (uart_circ_empty(xmit)) sc16is7xx_stop_tx(port); + else + sc16is7xx_ier_set(port, SC16IS7XX_IER_THRI_BIT); uart_port_unlock_irqrestore(port, flags); } @@ -815,7 +817,6 @@ static void sc16is7xx_tx_proc(struct kthread_work *ws) { struct uart_port *port = &(to_sc16is7xx_one(ws, tx_work)->port); struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); - unsigned long flags; if ((port->rs485.flags & SER_RS485_ENABLED) && (port->rs485.delay_rts_before_send > 0)) @@ -824,10 +825,6 @@ static void sc16is7xx_tx_proc(struct kthread_work *ws) mutex_lock(&one->efr_lock); sc16is7xx_handle_tx(port); mutex_unlock(&one->efr_lock); - - uart_port_lock_irqsave(port, &flags); - sc16is7xx_ier_set(port, SC16IS7XX_IER_THRI_BIT); - uart_port_unlock_irqrestore(port, flags); } static void sc16is7xx_reconf_rs485(struct uart_port *port)