Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3948629rwb; Mon, 21 Nov 2022 01:35:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf6oIBSeSHULXkXnYPMX5fF/z/Kmh9xXcJqhqkWu1ZV85AnyrrTAVnmDFhv9avJIaKhPoKS8 X-Received: by 2002:a17:902:cacd:b0:17f:7d9a:4952 with SMTP id y13-20020a170902cacd00b0017f7d9a4952mr5159012pld.117.1669023304888; Mon, 21 Nov 2022 01:35:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669023304; cv=none; d=google.com; s=arc-20160816; b=DoGgh9oCCLKPfPmcu3sktkckuWJXTJETF1vbH5KFynO9wMAkMNz6ZA2+b5kOhVRs64 DVQuqy+e3Si1JDLkRD87C2ecP+pRCyMwfruqCXXrZtf/nMmDiXp1C6r8h7XmGJTuF5BU 14ylODyKm7E7evOhsUZXDvpBZ77QfYSHgyQsjBrZ2o28XUV1zFPEaKQaYPKJFJu82GZC JNnd2aygEXSzksBsN2EyTdTOR5AeZhMAKz7z0ROys8HpcZ0f0f0+/kXp3qR5BT9xWW5d WyVGB1HdajqK0zLVg/cpBLh37/XG0fW8EZZOAvpRhX9UqA+gea2EDOO0sH74GB3IhvxS xyag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id; bh=zHnEp5FbFvmb3QyLSn3I57RXTnQLn/CFzXwFULZoeMg=; b=xzDtJ+UIp34IsRTpCJ1PhGZkp5w+GlZ/U1UHWFN/dHj9PbGk9CKO2odbPpJGvT+80t 0atVzfR7bTH1Hoag35HUfU3L3NPSq0x5I+/6Q/g7az7wmjo3AkWCKUEgmlrhR6P45Ybn +pnX4S4NnrCHNlN0Gd6mJNQo/3KN8eK9Zzr0i9t1dJnmsHERJgpv7sSxyl18qd4EGo1A MJxHX5q//IeEZiMkkNpewx8g4yYqGl4T4EsufNRvu2ORtLtD/kyWCje6AEvLfXjeuCZi 3zSde/bncoYHqfoEaIM9lJXJ259IPfxjHDpKAZzlwPii5or4vC/SK7W/JIcFdkZQjlDa ijgQ== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bm18-20020a656e92000000b00438766f903asi10754300pgb.490.2022.11.21.01.34.52; Mon, 21 Nov 2022 01:35:04 -0800 (PST) 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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229702AbiKUI4z (ORCPT + 91 others); Mon, 21 Nov 2022 03:56:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbiKUIzy (ORCPT ); Mon, 21 Nov 2022 03:55:54 -0500 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 403208CF13; Mon, 21 Nov 2022 00:54:38 -0800 (PST) Received: by mail-ej1-f54.google.com with SMTP id ud5so26881771ejc.4; Mon, 21 Nov 2022 00:54:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zHnEp5FbFvmb3QyLSn3I57RXTnQLn/CFzXwFULZoeMg=; b=Vj0U12xbWCZoKyJot67nB0PfE8EE6tZyG1QgXJK9uveeLpLQM+geA0rF00mADEEhru 5g5Wbn1K7SHbb9uygrRK4k53jO+9KJd2YiU1e2m4T1ralnom58q8Dk2faGbIu2ULkRuw HPFOI3BXwESTWjG5aqzyeQZFYQHen0CHloC9Tvsh2qFTgrrn+APs3dD2dgoKvL9E/4OE u7lnfD4fHwus0Aokj9UjFAzZ3oSdAZ8HCDNu3uyQtcVHZFxLXzVF91+fzSELyBQqza12 glf2KWfVqmiDLeFY9Jf0u8rofGH4oR/ojm3UA1h4MgwByvdYorz+ofC1wbe895QE6QDL W3Xw== X-Gm-Message-State: ANoB5pnhzEuGPmQ38cdVEmRrxC4/8yrfFkNNiLIW56onCAfUD08Bk4Dx rPGDCzGWieA2yO9mZHULmZU= X-Received: by 2002:a17:906:1412:b0:7a0:3313:a775 with SMTP id p18-20020a170906141200b007a03313a775mr3833703ejc.474.1669020876784; Mon, 21 Nov 2022 00:54:36 -0800 (PST) Received: from ?IPV6:2a0b:e7c0:0:107::aaaa:49? ([2a0b:e7c0:0:107::aaaa:49]) by smtp.gmail.com with ESMTPSA id f16-20020a17090631d000b0073d81b0882asm4725365ejf.7.2022.11.21.00.54.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Nov 2022 00:54:36 -0800 (PST) Message-ID: Date: Mon, 21 Nov 2022 09:54:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Content-Language: en-US To: Gabriel Somlo , linux-kernel@vger.kernel.org Cc: linux-serial@vger.kernel.org, gregkh@linuxfoundation.org, kgugala@antmicro.com, mholenko@antmicro.com, joel@jms.id.au, david.abdurachmanov@gmail.com, florent@enjoy-digital.fr, geert@linux-m68k.org, ilpo.jarvinen@linux.intel.com References: <20221118145512.509950-1-gsomlo@gmail.com> <20221118145512.509950-13-gsomlo@gmail.com> From: Jiri Slaby Subject: Re: [PATCH v5 12/14] serial: liteuart: add IRQ support for the RX path In-Reply-To: <20221118145512.509950-13-gsomlo@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no 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 On 18. 11. 22, 15:55, Gabriel Somlo wrote: > Add support for IRQ-driven RX. Support for the TX path will be added > in a separate commit. > > Signed-off-by: Gabriel Somlo > Reviewed-by: Ilpo Järvinen > --- > > Changes from v4: > - using dev_err() instead of a combo of pr_err() and pr_fmt() > - dropped "get irq" comment in probe() > >> Changes from v3: >> - add shadow irq register to support polling mode and avoid reading >> hardware mmio irq register to learn which irq flags are enabled >> - this also simplifies both liteuart_interrupt() and liteuart_startup() > > drivers/tty/serial/liteuart.c | 76 +++++++++++++++++++++++++++++++---- > 1 file changed, 69 insertions(+), 7 deletions(-) > > diff --git a/drivers/tty/serial/liteuart.c b/drivers/tty/serial/liteuart.c > index 8a6e176be08e..678c37c952cf 100644 > --- a/drivers/tty/serial/liteuart.c > +++ b/drivers/tty/serial/liteuart.c > @@ -7,6 +7,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -46,6 +47,7 @@ struct liteuart_port { > struct uart_port port; > struct timer_list timer; > u32 id; > + u8 irq_reg; > }; > > #define to_liteuart_port(port) container_of(port, struct liteuart_port, port) > @@ -76,6 +78,19 @@ static void liteuart_putchar(struct uart_port *port, unsigned char ch) > litex_write8(port->membase + OFF_RXTX, ch); > } > > +static void liteuart_update_irq_reg(struct uart_port *port, bool set, u8 mask) > +{ > + struct liteuart_port *uart = to_liteuart_port(port); > + > + if (set) > + uart->irq_reg |= mask; > + else > + uart->irq_reg &= ~mask; > + > + if (port->irq) > + litex_write8(port->membase + OFF_EV_ENABLE, uart->irq_reg); > +} > + > static void liteuart_stop_tx(struct uart_port *port) > { > } > @@ -129,13 +144,27 @@ static void liteuart_rx_chars(struct uart_port *port) > tty_flip_buffer_push(&port->state->port); > } > > +static irqreturn_t liteuart_interrupt(int irq, void *data) > +{ > + struct liteuart_port *uart = data; > + struct uart_port *port = &uart->port; > + u8 isr; > + > + spin_lock(&port->lock); > + isr = litex_read8(port->membase + OFF_EV_PENDING) & uart->irq_reg; > + if (isr & EV_RX) > + liteuart_rx_chars(port); > + spin_unlock(&port->lock); > + > + return IRQ_RETVAL(isr); > +} > + > static void liteuart_timer(struct timer_list *t) > { > struct liteuart_port *uart = from_timer(uart, t, timer); > struct uart_port *port = &uart->port; > > - liteuart_rx_chars(port); > - > + liteuart_interrupt(0, port); Are you sure spin_lock() is safe from this path? I assume so, but have you thought about it? > mod_timer(&uart->timer, jiffies + uart_poll_timeout(port)); > } > > @@ -161,19 +190,46 @@ static unsigned int liteuart_get_mctrl(struct uart_port *port) > static int liteuart_startup(struct uart_port *port) > { > struct liteuart_port *uart = to_liteuart_port(port); > + unsigned long flags; > + int ret; > > - /* disable events */ > - litex_write8(port->membase + OFF_EV_ENABLE, 0); > + if (port->irq) { > + ret = request_irq(port->irq, liteuart_interrupt, 0, > + KBUILD_MODNAME, uart); Just asking: cannot the irq be shared? > + if (ret) { > + dev_err(port->dev, > + "line %d irq %d failed: switch to polling\n", > + port->line, port->irq); That is, it should be only dev_warn(), or? > + port->irq = 0; > + } > + } thanks, -- js suse labs