Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3876292imm; Mon, 4 Jun 2018 10:41:24 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIvCJdaZfYceJ5IV8zGP4nIsH1ieQihz1wZ0DiKrKSqmaZOkCYcLnbqDDtm0XApFIizYMdv X-Received: by 2002:a65:4081:: with SMTP id t1-v6mr18399666pgp.32.1528134084449; Mon, 04 Jun 2018 10:41:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528134084; cv=none; d=google.com; s=arc-20160816; b=0+/5pWTDaLqoU4jEVDt32EuGRB6X3kxmdcb7v3RVvNVQxG+r1V2HFjKtydAtZUHmLO 5w6jtn9SvXYcWLDw7qvNHWSv0A0LMSF1fi3Pc4eskngRzdf72g33LAX84cf5LWhku0jw P1wZu8VsZzQHgS+gUSPtRKrnLoKRJ7uHwvYbRAiOoAMiZVk1cMRBWlAs01kbeXIoax6o VDIBwrfDwJDOS9LZ4oZSKi35ExLEzoeRhUaPDFWwqsI25eE70V/CfcqK+rZWmpNq1Bu0 dAXZOMH/CihSzXE3bfOIY7L0hOZSfUffJ+J10sUUuL6MjwLvvcfGLM8a8EO7TaMiMCJG +QqA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:newsgroups:cc:to :subject:dkim-signature:arc-authentication-results; bh=c2ZlXJG3r3fPF19X7SZppaHK+u29pCCkyWVNOsepXMs=; b=JR7oCHlO64Nn0xrt1x36f3uVXYcWeai7HTKsme7HqE2LfzY/WzOFlauqlvOfQz32rB Jmn8E/ZmA3WyNhTlXuEefMYEchWwEHq7Ye3i43jYEuBXuop6AXa82u2SZndF3iT7f4/5 2OMO5L27WIVdEHnMJ+7R0uKVpG2UGY8r+rS46i9hrIIT0nOHc3A1oSx63UM0HTbVxCRU tbE+7fbAKeP64D3vpYrGDBSGNANfpNYI22GfE4hNZjeNqG0KDA3QVI4QvTf05t+VMeJ1 OMvvrjAqIpBMDxqLY8fjWou1e3mTAtPQW91HzMFOWjnlX1YpuZHIiQ0J50AKHxdABGrH Bs1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JfiQi1N/; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s88-v6si46257615pfa.339.2018.06.04.10.41.09; Mon, 04 Jun 2018 10:41:24 -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=@gmail.com header.s=20161025 header.b=JfiQi1N/; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751242AbeFDRkl (ORCPT + 99 others); Mon, 4 Jun 2018 13:40:41 -0400 Received: from mail-lf0-f67.google.com ([209.85.215.67]:37361 "EHLO mail-lf0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751015AbeFDRki (ORCPT ); Mon, 4 Jun 2018 13:40:38 -0400 Received: by mail-lf0-f67.google.com with SMTP id r2-v6so26510139lff.4; Mon, 04 Jun 2018 10:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:newsgroups:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=c2ZlXJG3r3fPF19X7SZppaHK+u29pCCkyWVNOsepXMs=; b=JfiQi1N/yJXiJOHWOW5rVCl+p8e79MfWGDBhbXo0sxDBvOz0Aomy3DFZy/IkBCu4fy sx17G9DaDgyxGk2ehoVo+PU4BYipWiD14xSLcWZHYd4lsxDqLxhGATi8j33sz8QqNK9U FxwamJwIzcBxTXiryoo15w37irqR+IDcUySUlFTX4ufHxegU67hdN6KVOAjdaIkDopbw TDoY5InO0AAzolncmJ/DApel9FnLDh71kaud5rVFX5kupAJCeLpgyu51x92yVFUABqYN pjGHwlrlQGPHYZxbBmsxSdZwFnVvH2USi/gNLmyxnV/99i//4B98RCIoRjgEec2f6kfL vBjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:newsgroups:references:from:openpgp :autocrypt:message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=c2ZlXJG3r3fPF19X7SZppaHK+u29pCCkyWVNOsepXMs=; b=oJuPmUZwrf2WsrkjP6YH15Njt/l12tErY7zzggsBFZXdGBg+AnarXPTrkcEbBIHD3S GFBWiBnn6xFawoh4ETPysfUogV1cDkuABUeZFFBkQOel2M/8HIEzsU4DqOp/cOjQauEG RJygs9csxvbuhpg9qtbiBmadcSDHke2MHDlG93ChP91jrEFhG8VxywxI2c1BlQMVbHUs f7Wt2fmboAjzbfNoRu1xC5bg8pW26NdsglsaNKqBNZmYr1jRxpJxbyuaf3O+wRnJQ17e hbRZDd5dW8oyqkpUMPfsAPdV7rd8hQzoFbMt90048iFW3pDUkYD4PpsI1cwROyQVzehB P65w== X-Gm-Message-State: ALKqPwe9IKHYlYMWWNiyYzd001eicYfnutoookBwli1V2lyI/iejAfnA 2KNCzl8OYAxAsmatTAQFc9i06h3G X-Received: by 2002:a19:949d:: with SMTP id o29-v6mr14221664lfk.56.1528134036449; Mon, 04 Jun 2018 10:40:36 -0700 (PDT) Received: from [192.168.185.4] ([92.243.181.209]) by smtp.googlemail.com with ESMTPSA id h90-v6sm4619131ljf.65.2018.06.04.10.40.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 10:40:35 -0700 (PDT) Subject: Re: [PATCH 4/8] serial: 8250: Handle case port doesn't have TEMT interrupt using em485. To: Giulio Benetti , Greg Kroah-Hartman Cc: Jiri Slaby , Andy Shevchenko , Kees Cook , Matthias Brugger , Allen Pais , Sean Young , Ed Blake , Stefan Potyra , Philipp Zabel , Joshua Scott , Vignesh R , Rolf Evers-Fischer , Aaron Sierra , Rafael Gago , Joel Stanley , Sean Wang , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Newsgroups: gmane.linux.kernel,gmane.linux.serial References: <20180601124021.102970-1-giulio.benetti@micronovasrl.com> <20180601124021.102970-5-giulio.benetti@micronovasrl.com> From: "Matwey V. Kornilov" Openpgp: preference=signencrypt Autocrypt: addr=matwey.kornilov@gmail.com; keydata= xsBNBFqzfRUBCACb5yTIRtEkXBVptbSuDzrxxTo7aN2YrxjQBbCAP3rxJtOYLh0pvx7Q6jdc hax0oiDsLIDXRpOonAq3jhdeXogw3PAi82S4srSToSiWY+9/Cj5mxGjAEhkPyXAfCQgI9rT5 FW5jPXrDsspXxqRv1vtCfxr0lZ47sYT1osy5j24prhNiSyv/NAs9YuV7BN7gvyTO+h6/LQw9 EzCXA8KlbbETGptTw3oN6pudmXO615FIsbizP74B4Z9CWu5FjhGBANphZSPajxLi4jEOIQ9o QS7MOmHnkXpntszp25H8FuEcAAFJ78KtyIWEirTlTNB4HRREn6rkwmRafx2jhkw4lhClABEB AAHNLk1hdHdleSBWLiBLb3JuaWxvdiA8bWF0d2V5Lmtvcm5pbG92QGdtYWlsLmNvbT7CwHkE EwECACMFAlqzfRUCGwMHCwkIBwMCAQYVCAIJCgsEFgIDAQIeAQIXgAAKCRAC/Q9fWLJKf1Kj B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o iVEx2OEW32jH2g== Message-ID: Date: Mon, 4 Jun 2018 20:40:29 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180601124021.102970-5-giulio.benetti@micronovasrl.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 01.06.2018 15:40, Giulio Benetti пишет: > Some 8250 ports only have TEMT interrupt, so current implementation > can't work for ports without it. The only chance to make it work is to > loop-read on LSR register. > > With NO TEMT interrupt check if both TEMT and THRE are set looping on > LSR register. > > Signed-off-by: Giulio Benetti > --- > drivers/tty/serial/8250/8250.h | 2 +- > drivers/tty/serial/8250/8250_dw.c | 2 +- > drivers/tty/serial/8250/8250_omap.c | 2 +- > drivers/tty/serial/8250/8250_port.c | 26 ++++++++++++++++++-------- > include/linux/serial_8250.h | 1 + > 5 files changed, 22 insertions(+), 11 deletions(-) > > diff --git a/drivers/tty/serial/8250/8250.h b/drivers/tty/serial/8250/8250.h > index ebfb0bd5bef5..5c6ae5f69432 100644 > --- a/drivers/tty/serial/8250/8250.h > +++ b/drivers/tty/serial/8250/8250.h > @@ -136,7 +136,7 @@ void serial8250_rpm_put(struct uart_8250_port *p); > void serial8250_rpm_get_tx(struct uart_8250_port *p); > void serial8250_rpm_put_tx(struct uart_8250_port *p); > > -int serial8250_em485_init(struct uart_8250_port *p); > +int serial8250_em485_init(struct uart_8250_port *p, bool has_temt_isr); > void serial8250_em485_destroy(struct uart_8250_port *p); > > static inline void serial8250_out_MCR(struct uart_8250_port *up, int value) > diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c > index 0f8b4da03d4e..888280ff5451 100644 > --- a/drivers/tty/serial/8250/8250_dw.c > +++ b/drivers/tty/serial/8250/8250_dw.c > @@ -330,7 +330,7 @@ static int dw8250_rs485_config(struct uart_port *p, > * are idempotent > */ > if (rs485->flags & SER_RS485_ENABLED) { > - int ret = serial8250_em485_init(up); > + int ret = serial8250_em485_init(up, false); > > if (ret) { > rs485->flags &= ~SER_RS485_ENABLED; > diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c > index 624b501fd253..ab483c8b30c8 100644 > --- a/drivers/tty/serial/8250/8250_omap.c > +++ b/drivers/tty/serial/8250/8250_omap.c > @@ -725,7 +725,7 @@ static int omap_8250_rs485_config(struct uart_port *port, > * are idempotent > */ > if (rs485->flags & SER_RS485_ENABLED) { > - int ret = serial8250_em485_init(up); > + int ret = serial8250_em485_init(up, true); > > if (ret) { > rs485->flags &= ~SER_RS485_ENABLED; > diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c > index 95833cbc4338..e14badbbf181 100644 > --- a/drivers/tty/serial/8250/8250_port.c > +++ b/drivers/tty/serial/8250/8250_port.c > @@ -599,15 +599,16 @@ EXPORT_SYMBOL_GPL(serial8250_rpm_put); > /** > * serial8250_em485_init() - put uart_8250_port into rs485 emulating > * @p: uart_8250_port port instance > + * @p: bool specify if 8250 port has TEMT interrupt or not > * > * The function is used to start rs485 software emulating on the > * &struct uart_8250_port* @p. Namely, RTS is switched before/after > * transmission. The function is idempotent, so it is safe to call it > * multiple times. > * > - * The caller MUST enable interrupt on empty shift register before > - * calling serial8250_em485_init(). This interrupt is not a part of > - * 8250 standard, but implementation defined. > + * If has_temt_isr is passed as true, the caller MUST enable interrupt > + * on empty shift register before calling serial8250_em485_init(). > + * This interrupt is not a part of 8250 standard, but implementation defined. > * > * The function is supposed to be called from .rs485_config callback > * or from any other callback protected with p->port.lock spinlock. > @@ -616,7 +617,7 @@ EXPORT_SYMBOL_GPL(serial8250_rpm_put); > * > * Return 0 - success, -errno - otherwise > */ > -int serial8250_em485_init(struct uart_8250_port *p) > +int serial8250_em485_init(struct uart_8250_port *p, bool has_temt_isr) > { > if (p->em485) > return 0; > @@ -633,6 +634,7 @@ int serial8250_em485_init(struct uart_8250_port *p) > p->em485->start_tx_timer.function = &serial8250_em485_handle_start_tx; > p->em485->port = p; > p->em485->active_timer = NULL; > + p->em485->has_temt_isr = has_temt_isr; > serial8250_em485_rts_after_send(p); > > return 0; > @@ -1517,11 +1519,19 @@ 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 (em485->has_temt_isr) { > + if ((lsr & BOTH_EMPTY) != BOTH_EMPTY) > + return; > + } else { > + while ((lsr & BOTH_EMPTY) != BOTH_EMPTY) { > + lsr = serial_in(p, UART_LSR); > + cpu_relax(); > + } What happens if TEMP never be empty after interruption occurring? > + } > > em485->active_timer = NULL; > > diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h > index a27ef5f56431..9b13cf59726b 100644 > --- a/include/linux/serial_8250.h > +++ b/include/linux/serial_8250.h > @@ -83,6 +83,7 @@ struct uart_8250_em485 { > struct hrtimer start_tx_timer; /* "rs485 start tx" timer */ > struct hrtimer stop_tx_timer; /* "rs485 stop tx" timer */ > struct hrtimer *active_timer; /* pointer to active timer */ > + bool has_temt_isr; /* say if 8250 has TEMT interrupt or no */ > struct uart_8250_port *port; /* for hrtimer callbacks */ > }; > >