Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp743657imm; Tue, 5 Jun 2018 03:53:13 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKX23piDrxiI6ZWKiE4Z8ZEwixKztIhNzMpzUZf0oQBoTuJGAtgFOlPwDAAknbYSSHEdQvP X-Received: by 2002:a65:4502:: with SMTP id n2-v6mr19915847pgq.95.1528195993360; Tue, 05 Jun 2018 03:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528195993; cv=none; d=google.com; s=arc-20160816; b=rQL/htojCM+fx6HdUAnNyWfK4egErL/Sd9jn7ml9vvdyOMTG91LXzM9VRGsPBO5uzg N6nuqmwZvF8PaQDCmstX0EzChtdlI4CzItOabtRFyeNgnmtSkKVAyJtXM7XTW6NFJT6O Dz08I/ay6FC1t3pHKD3Mz76inqFzJm4j+D2V3OtdWYWas+pxDgcavNMkwRwCivT0jUc1 ORkb6Ueub9T8Aifgrv2uWmX+55pfk8O4CwUXoCd3wsO5eHsQIoZ5ldjiZQG5x4rX5VGm yIK/QiS3Fk4Tk+J1lEaJLMTfjYVm6DuOv/x5hAwJc2qMHAJ13hD4Jvw2jSzTaXbW4pGj uYpw== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=GKznL9NTqnNJY/B+Q3Vzh8IjvyUxFqohbO9nnxUvelg=; b=d4A4wcRMOeqAUASw71sLlUbyEwZ8cqA1eT5j/W95zqnRp45InoW9obzQn4ZfT6XRfZ yqeehCBNYjQ0t3UkizcO8pvsGEGzA5zelFdyMgmSzYNpC+8R/+1gtFmJoGZHzmSFkMT9 SDPGSxErANGzj+LOvs2VXtUeeq7dy/KBlNq/gz5ehniPqYJi4iHZr7U60ifO2YrCEmvy c0qvVDjsIkkAVE/cQbCGLune78hKNWOKgtZUqqiHR4O9bKks4ShkYVic8+JgAeBUdN44 q7j2RQ8y4j5ONEVtba1IAwHr2hErIY+KxSjjP3GFa1t9pM8O2725j5ZqE+HL+eSt2lX/ VxPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pJ7FTAfk; 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 u74-v6si38310551pgc.186.2018.06.05.03.52.58; Tue, 05 Jun 2018 03:53:13 -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=pJ7FTAfk; 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 S1751836AbeFEKwT (ORCPT + 99 others); Tue, 5 Jun 2018 06:52:19 -0400 Received: from mail-ot0-f195.google.com ([74.125.82.195]:43582 "EHLO mail-ot0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751534AbeFEKwR (ORCPT ); Tue, 5 Jun 2018 06:52:17 -0400 Received: by mail-ot0-f195.google.com with SMTP id i19-v6so2212837otk.10; Tue, 05 Jun 2018 03:52:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=GKznL9NTqnNJY/B+Q3Vzh8IjvyUxFqohbO9nnxUvelg=; b=pJ7FTAfktWQUGzMjcXn6U1lpcmZOihTO5am/Pbs+PjBjHOPVv25ZW2bClt2fjx0qAf DAHot/R0cUmwzNb8H1Ebm/4Y7XLryAs2KAsDPGIHn7o7DzPin66rB3IvXLNaJnHFkSm+ Nu1jj3MbBQdZY8VXlAonJHVCLzmiRywRQPyWNV3+fPUA6VkjMqHmACNn8ynGSjcW2jRu MytDkbGXIyNg3nbpAC0Hq8PMudNXx258tUInoP2LevI/Y+c3AjZyIyLlQyxf5uWVU+p/ 1L6WWiMqjTZNBCnMfXZKtjpcW7CB7FGFFpdLjccHL6d0qA5CoDkw8epHd9D993ZwZ+Bg eu8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=GKznL9NTqnNJY/B+Q3Vzh8IjvyUxFqohbO9nnxUvelg=; b=nH+UketvB6rff2LQ5zxdjeeoSn8IpHeroj46uUwSDTWHnml0UtmGIHbVE20YECGisI lzKdPImDOOzEvKQPr28qV6w86YO5Dkh18Ah72oYHpbaxao1hBDS60VebQRq+z5uBMoH9 vjXKe4Iq8LlHt9G/mYEWe3jaYr3MzJXl4tlYNedRehJMESW/ROvbMjh/po076eDJpMay 6fHSyS2o1oiwCGcdz8bOTK2SdF+iudvR0mZDtroLZtjy82z7xA5j06gklSBREa+1gxz5 189t8le3O/4+k7PDAqhlqdin86WdTQIFyWUHFRwlfGGpt8To1+m7mVE+lqUNObk0SBBt UuaQ== X-Gm-Message-State: APt69E2GtycNR/L/Rj38OhBHgqpsEUehptEqTKG5gba4Yhh3/4Cups90 +qtFT0VgNM3JI710557RnWSAXjNDJyqHYjYHxMw= X-Received: by 2002:a9d:3835:: with SMTP id i50-v6mr12108572otc.382.1528195936407; Tue, 05 Jun 2018 03:52:16 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:743:0:0:0:0:0 with HTTP; Tue, 5 Jun 2018 03:51:56 -0700 (PDT) In-Reply-To: References: <20180601124021.102970-1-giulio.benetti@micronovasrl.com> <20180601124021.102970-5-giulio.benetti@micronovasrl.com> From: "Matwey V. Kornilov" Date: Tue, 5 Jun 2018 13:51:56 +0300 Message-ID: Subject: Re: [PATCH 4/8] serial: 8250: Handle case port doesn't have TEMT interrupt using em485. To: Giulio Benetti Cc: Greg Kroah-Hartman , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-06-04 21:50 GMT+03:00 Giulio Benetti = : > Il 04/06/2018 19:40, Matwey V. Kornilov ha scritto: >> >> 01.06.2018 15:40, Giulio Benetti =D0=BF=D0=B8=D1=88=D0=B5=D1=82: >>> >>> 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, in= t >>> 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 =3D serial8250_em485_init(up); >>> + int ret =3D serial8250_em485_init(up, false); >>> if (ret) { >>> rs485->flags &=3D ~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 =3D serial8250_em485_init(up); >>> + int ret =3D serial8250_em485_init(up, true); >>> if (ret) { >>> rs485->flags &=3D ~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 emulati= ng >>> * @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/afte= r >>> * 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 o= f >>> - * 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 implementati= on >>> defined. >>> * >>> * The function is supposed to be called from .rs485_config callba= ck >>> * 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 =3D >>> &serial8250_em485_handle_start_tx; >>> p->em485->port =3D p; >>> p->em485->active_timer =3D NULL; >>> + p->em485->has_temt_isr =3D 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 a= re >>> set. >>> */ >>> - if ((lsr & BOTH_EMPTY) !=3D BOTH_EMPTY) >>> - return; >>> + if (em485->has_temt_isr) { >>> + if ((lsr & BOTH_EMPTY) !=3D BOTH_EMPTY) >>> + return; >>> + } else { >>> + while ((lsr & BOTH_EMPTY) !=3D BOTH_EMPTY) { >>> + lsr =3D serial_in(p, UART_LSR); >>> + cpu_relax(); >>> + } >> >> >> What happens if TEMP never be empty after interruption occurring? >> > > I've added the field has_temt_isr to identify if peripheral provides or n= ot > TEMT interrupt. In DW case, differentely from OMAP case, there is not TEM= T > interrupt, at least on Datasheet I've found. > At this time I don't have access to latest Datasheet. > > Specifying has_temt_isr =3D false during serial8250_em485_init(), > I assume TEMT interrupt is not available and also is not enabled. > > IMHO the only possible case to loop inside there is if shift register is > costantly filled, but soon or late it will get empty(hope I didn't miss > something). Well, I would not rely on this behavior. Eventually, powersave or something else disable transmit with characters left in buffer, or happens something like that. Could I ask to split the series into fixes and new features? I see that the fixes can be applied, probably it would be better to apply them separately from discussing new features. > > -- > Giulio Benetti > CTO > > MICRONOVA SRL > Sede: Via A. Niedda 3 - 35010 Vigonza (PD) > Tel. 049/8931563 - Fax 049/8931346 > Cod.Fiscale - P.IVA 02663420285 > Capitale Sociale =E2=82=AC 26.000 i.v. > Iscritta al Reg. Imprese di Padova N. 02663420285 > Numero R.E.A. 258642 --=20 With best regards, Matwey V. Kornilov