Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1743748ybz; Sat, 2 May 2020 06:53:39 -0700 (PDT) X-Google-Smtp-Source: APiQypLW+c+PB8OQ1cyWd1sgCLFoqQAfhyRaYQ7ME0J3SJh4UffAkitkedqBTkFWIcg6/ZmgWkzH X-Received: by 2002:a17:906:3d69:: with SMTP id r9mr7747216ejf.20.1588427619696; Sat, 02 May 2020 06:53:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588427619; cv=none; d=google.com; s=arc-20160816; b=kO1obOi4qEta7bG1IefVXJPz1pKAvVv7tulRR2GdDVWnhnRJsRYfyAjZMOXjzS4255 kD3ugTm3eSeGnF8FwMMpt+INQbUM26EQg9nDtWvYI6H9AnR6P3Xw0NIViZu3UUyg54aS yVGCh5swejYS9BLJh32Ff1NLzdOIacSuqRtKrMAClV6A0CDVjAxmInN0cBVOO1I06T5l UGSqE9GXyf0pfb9R5M6AYLFi216VBfYfGTPrJ3lLkryF+TGQ4Y8OPHMfIMtV+jIGiEne 5/cUApbRHYUHfK47frGLdF6yYFRabOcyiajfvXra2NPGmNprhsKE6iJ25gw5zEtkO9e3 Tg+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=B2w7Yjj579kOYKaFV5yFB04+fEizleyx8KZ1dDAaI0c=; b=r7MYVh2sWSCzhlCos7ZHGzF9+CnE2BV0IPeuTmtVvQieuawaVtDSWbctyT2XQFa9mm rufflTVktylljnlXcQF1Nv5HiYtpff1b6sQuBxixIDVe/wUSUK/1oLtOYV7ihnRL2+hA 4FG3ohR+YLNguX/pUe6j2iAMI6GhWpDBxQkINW4utAz9dhn3dzwUuQgR6aX7myeBJffT 6tdXx2flwrVBLKly2+HHEoGZ2ed39ukNNM749OkF9xZHXfFVpwsQQV3rbEhj8PQjtzCZ 7YQRKe/zp+IOPbvRHFCmsZfidWxPTHPq1LPHvPZ9QRNrlKoYMPZmNJ9Hzp7/YYTmpr5V R2VA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c13si3569650eja.65.2020.05.02.06.53.16; Sat, 02 May 2020 06:53:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728073AbgEBNtd (ORCPT + 99 others); Sat, 2 May 2020 09:49:33 -0400 Received: from bmailout2.hostsharing.net ([83.223.78.240]:60693 "EHLO bmailout2.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727948AbgEBNtd (ORCPT ); Sat, 2 May 2020 09:49:33 -0400 Received: from h08.hostsharing.net (h08.hostsharing.net [83.223.95.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout2.hostsharing.net (Postfix) with ESMTPS id 047A62800B48B; Sat, 2 May 2020 15:49:28 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id D0F212781E5; Sat, 2 May 2020 15:49:27 +0200 (CEST) Date: Sat, 2 May 2020 15:49:27 +0200 From: Lukas Wunner To: Heiko Stuebner Cc: gregkh@linuxfoundation.org, jslaby@suse.com, andriy.shevchenko@linux.intel.com, matwey.kornilov@gmail.com, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, christoph.muellner@theobroma-systems.com, giulio.benetti@micronovasrl.com, Heiko Stuebner Subject: Re: [PATCH v2 4/7] serial: 8250: Handle implementations not having TEMT interrupt using em485 Message-ID: <20200502134927.6sb7f3na3ff3rpoa@wunner.de> References: <20200325231422.1502366-1-heiko@sntech.de> <20200325231422.1502366-5-heiko@sntech.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200325231422.1502366-5-heiko@sntech.de> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 26, 2020 at 12:14:19AM +0100, Heiko Stuebner wrote: > Some 8250 ports have a TEMT interrupt but it's not a part of the 8250 > standard, instead only available on some implementations. > > The current em485 implementation does not work on ports without it. > The only chance to make it work is to loop-read on LSR register. > > So add UART_CAP_TEMT to mark 8250 uarts having this interrupt, > update all current em485 users with that capability and make > the stop_tx function loop-read on uarts not having it. Just to get a better understanding: According to the Dw_apb_uart_db.pdf databook I've found, the UART does have a "THR empty" interrupt. So you get an interrupt once the Transmit Holding Register (and by consequence the FIFO) has been drained. Then what do you need a TEMT interrupt for? Why is the THR interrupt not sufficient? > @@ -1529,11 +1535,22 @@ static inline void __stop_tx(struct uart_8250_port *p) > /* > * To provide required timeing and allow FIFO transfer, > * __stop_tx_rs485() must be called only when both FIFO and > - * shift register are empty. It is for device driver to enable > - * interrupt on TEMT. > + * shift register are empty. If 8250 port supports it, > + * it is for device driver to enable interrupt on TEMT. > + * Otherwise must loop-read until TEMT and THRE flags are set. > */ > - if ((lsr & BOTH_EMPTY) != BOTH_EMPTY) > - return; > + if (p->capabilities & UART_CAP_TEMT) { > + if ((lsr & BOTH_EMPTY) != BOTH_EMPTY) > + return; > + } else { > + int lsr; > + > + if (readx_poll_timeout(__get_lsr, p, lsr, > + (lsr & BOTH_EMPTY) == BOTH_EMPTY, > + 0, 10000) < 0) > + pr_warn("%s: timeout waiting for fifos to empty\n", > + p->port.name); > + } Do you actually need to check for the timeout? How could this happen? Only if some other part of the driver would disable the transmitter I guess, which would be a bug. Also, note that __stop_tx() may be called from hardirq context via serial8250_tx_chars(). If the baudrate is low, you may spin for a fairly long time in IRQ context. E.g. with 9600 8N1, it takes about 1 msec for one char to transmit. Thanks, Lukas