Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp206285ybh; Tue, 14 Jul 2020 23:10:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCTt3Kwu87GfN8HSAcMrq/dZbzDYtlwLPGLN0kqZx/u55IuMJ6ChHnbTYkSwtBLMqWOYRi X-Received: by 2002:aa7:d58c:: with SMTP id r12mr8482587edq.160.1594793457949; Tue, 14 Jul 2020 23:10:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594793457; cv=none; d=google.com; s=arc-20160816; b=a26Rd9q9bGPuHsllANCyYmMQ0IIIVDForuos7Vfw8c4Q3mKXMoVDy8b5awpwfbgdQY IPwW8J3qR5TlFeF6h+OwHl/eqPCWzG9va2pDiX759ha+Cu/IdwXfNfobemmh5rDZlM2c E0nf64vPbo6CrOAMxbb+3DCE08E/J/tOGGGURd70c/JW/FWZrZ32i+UTK/QfyurQnG6y JIyJYohCsAjVSyVysLA/c9RPY/S1rU1Bi+bieWG/o4Ch9psJ7LcKFfzB0XWh5gOj7qgq c+fEs0G0TKduinsu1nBGyT9vfKybC7g8rtueOhFMMbKUuVo7plsvP7audLQpDvcEzVBV jYpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=FzipDiDAYZY58rqh2kzcXYBD7EF+tctB+0O3KKzLNz4=; b=CZjC3DLM/GYuVX6H0XVsjKTl9/p/MAMq4uZjXczKAzp8h1JVNF6lopl69Zc39EXl43 GCuH2PKksQxA/9uy8lyB1+bfENKXr0gU2dWmMsNb2vTnzTi0/qSZ1WZRjbF6prpdVFVs uLgHWarUdf3+j2fiHFNPDRq0T+iITUWpCBMPS0UaZXsFFVYvsrY2cRNMDAB5Q10lr3MP AN8T5UVwy/PMUev85QdtigPRnHYpIvDVptGExGSpNdhUad/ASnPwu3IqscLw2LXFUkvf kRs2i0tMjtjbqttuJ1nM1mDgWwwv0Msw6UhL2HAdSECheHK5YsEngITMcofPf/Y1+zDy Z0Mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=d2SmiiK9; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d15si675233ejt.185.2020.07.14.23.10.12; Tue, 14 Jul 2020 23:10:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=d2SmiiK9; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728110AbgGOFmN (ORCPT + 99 others); Wed, 15 Jul 2020 01:42:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725832AbgGOFmM (ORCPT ); Wed, 15 Jul 2020 01:42:12 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A72EC061755 for ; Tue, 14 Jul 2020 22:42:12 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id f23so976987iof.6 for ; Tue, 14 Jul 2020 22:42:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=FzipDiDAYZY58rqh2kzcXYBD7EF+tctB+0O3KKzLNz4=; b=d2SmiiK9RFir0tNVLiwsWneH8WEOVeZ1SBJW+gMYBzXE+LjnQ6p9R6IyK72TJZc/nr RQe0LtOvyt7j1XCc6EWFxN1UXLs4CCtGO6FbX+Nj9MTAzMJoid2s0rBvqfagAx5UbhfZ rGs7lWy/xi/JHmW8/b5gE9ZqzLzKFeM/1MIDU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FzipDiDAYZY58rqh2kzcXYBD7EF+tctB+0O3KKzLNz4=; b=OUPWQsW8Hplrk0EL12qYv3Lz5mL6TxbJzlzaKXu+tsaP6vSfInwkxciErqmWMfMg19 elJflxEx7M7MXp+hANTRnNVJRccaPz5AOVsZDRtt/zb+eq35fpeJp0e2iHqWcxfAGQoM 9OabicefYV/Fy/UsDyosSG6BKDMmVg2f6j6p35q0SBif8i61rKKZnM+HOusfYJM/npK0 ucpp9i7vunrtrx5h5jms75smf21ufwWDItr5xN77J4r0cgbfSLDTDiXn1RN6ON71Dtek 3fbzHm78e5kDEMc1wCq5VZqzpholGBDVi+lts5xKYEKAvUMDJCPSbWcgXOv3qfxX8Y9p l+yQ== X-Gm-Message-State: AOAM532nhYj7I+eGCR0FyfUUHyPwk/Jzmm2j2S2UeCavgiStUWLAuoPN lPj7WYfFzolJYc9OnkS51DD17XkJLgw= X-Received: by 2002:a05:6602:154d:: with SMTP id h13mr8615816iow.210.1594791731233; Tue, 14 Jul 2020 22:42:11 -0700 (PDT) Received: from mail-io1-f54.google.com (mail-io1-f54.google.com. [209.85.166.54]) by smtp.gmail.com with ESMTPSA id p11sm608707ilb.55.2020.07.14.22.42.10 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 14 Jul 2020 22:42:10 -0700 (PDT) Received: by mail-io1-f54.google.com with SMTP id l17so977758iok.7 for ; Tue, 14 Jul 2020 22:42:10 -0700 (PDT) X-Received: by 2002:a05:6602:2008:: with SMTP id y8mr8441205iod.69.1594791376034; Tue, 14 Jul 2020 22:36:16 -0700 (PDT) MIME-Version: 1.0 References: <20200714124113.20918-1-Sergey.Semin@baikalelectronics.ru> In-Reply-To: From: Claire Chang Date: Wed, 15 Jul 2020 13:36:04 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] serial: 8250_mtk: Fix high-speed baud rates clamping To: Daniel Winkler Cc: Serge Semin , Nicolas Boichat , Greg Kroah-Hartman , Jiri Slaby , Matthias Brugger , Serge Semin , Alexey Malahov , Aaron Sierra , Andy Shevchenko , Lukas Wunner , Vignesh Raghavendra , linux-serial@vger.kernel.org, "moderated list:ARM/Mediatek SoC support" , BlueZ , chromeos-bluetooth-upstreaming , abhishekpandit@chromium.org, stable@vger.kernel.org, linux-arm Mailing List , lkml Content-Type: text/plain; charset="UTF-8" Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org On Wed, Jul 15, 2020 at 4:45 AM Daniel Winkler wrote: > > Thank you Sergey for looking into this. Adding folks working on this > platform to perform validation of the proposed patch. > > Best, > Daniel > > On Tue, Jul 14, 2020 at 5:41 AM Serge Semin > wrote: > > > > Commit 7b668c064ec3 ("serial: 8250: Fix max baud limit in generic 8250 > > port") fixed limits of a baud rate setting for a generic 8250 port. > > In other words since that commit the baud rate has been permitted to be > > within [uartclk / 16 / UART_DIV_MAX; uartclk / 16], which is absolutely > > normal for a standard 8250 UART port. But there are custom 8250 ports, > > which provide extended baud rate limits. In particular the Mediatek 8250 > > port can work with baud rates up to "uartclk" speed. > > > > Normally that and any other peculiarity is supposed to be handled in a > > custom set_termios() callback implemented in the vendor-specific > > 8250-port glue-driver. Currently that is how it's done for the most of > > the vendor-specific 8250 ports, but for some reason for Mediatek a > > solution has been spread out to both the glue-driver and to the generic > > 8250-port code. Due to that a bug has been introduced, which permitted the > > extended baud rate limit for all even for standard 8250-ports. The bug > > has been fixed by the commit 7b668c064ec3 ("serial: 8250: Fix max baud > > limit in generic 8250 port") by narrowing the baud rates limit back down to > > the normal bounds. Unfortunately by doing so we also broke the > > Mediatek-specific extended bauds feature. > > > > A fix of the problem described above is twofold. First since we can't get > > back the extended baud rate limits feature to the generic set_termios() > > function and that method supports only a standard baud rates range, the > > requested baud rate must be locally stored before calling it and then > > restored back to the new termios structure after the generic set_termios() > > finished its magic business. By doing so we still use the > > serial8250_do_set_termios() method to set the LCR/MCR/FCR/etc. registers, > > while the extended baud rate setting procedure will be performed later in > > the custom Mediatek-specific set_termios() callback. Second since a true > > baud rate is now fully calculated in the custom set_termios() method we > > need to locally update the port timeout by calling the > > uart_update_timeout() function. After the fixes described above are > > implemented in the 8250_mtk.c driver, the Mediatek 8250-port should > > get back to normally working with extended baud rates. > > > > Link: https://lore.kernel.org/linux-serial/20200701211337.3027448-1-danielwinkler@google.com > > > > Fixes: 7b668c064ec3 ("serial: 8250: Fix max baud limit in generic 8250 port") > > Reported-by: Daniel Winkler > > Signed-off-by: Serge Semin Tested-by: Claire Chang > > > > --- > > > > Folks, sorry for a delay with the problem fix. A solution is turned out to > > be a bit more complicated than I originally thought in my comment to the > > Daniel revert-patch. > > > > Please also note, that I don't have a Mediatek hardware to test the > > solution suggested in the patch. The code is written as on so called > > the tip of the pen after digging into the 8250_mtk.c and 8250_port.c > > drivers code. So please Daniel or someone with Mediatek 8250-port > > available on a board test this patch first and report about the results in > > reply to this emailing thread. After that, if your conclusion is positive > > and there is no objection against the solution design the patch can be > > merged in. I tested it with mt8183 + QCA6174. The UART Bluetooth works fine with this fix. Thanks! > > > > Cc: Alexey Malahov > > Cc: Daniel Winkler > > Cc: Aaron Sierra > > Cc: Andy Shevchenko > > Cc: Lukas Wunner > > Cc: Vignesh Raghavendra > > Cc: linux-serial@vger.kernel.org > > Cc: linux-mediatek@lists.infradead.org > > Cc: BlueZ > > Cc: chromeos-bluetooth-upstreaming > > Cc: abhishekpandit@chromium.org > > Cc: stable@vger.kernel.org > > --- > > drivers/tty/serial/8250/8250_mtk.c | 18 ++++++++++++++++++ > > 1 file changed, 18 insertions(+) > > > > diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c > > index f839380c2f4c..98b8a3e30733 100644 > > --- a/drivers/tty/serial/8250/8250_mtk.c > > +++ b/drivers/tty/serial/8250/8250_mtk.c > > @@ -306,8 +306,21 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios, > > } > > #endif > > > > + /* > > + * Store the requested baud rate before calling the generic 8250 > > + * set_termios method. Standard 8250 port expects bauds to be > > + * no higher than (uartclk / 16) so the baud will be clamped if it > > + * gets out of that bound. Mediatek 8250 port supports speed > > + * higher than that, therefore we'll get original baud rate back > > + * after calling the generic set_termios method and recalculate > > + * the speed later in this method. > > + */ > > + baud = tty_termios_baud_rate(termios); > > + > > serial8250_do_set_termios(port, termios, old); > > > > + tty_termios_encode_baud_rate(termios, baud, baud); > > + > > /* > > * Mediatek UARTs use an extra highspeed register (MTK_UART_HIGHS) > > * > > @@ -339,6 +352,11 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios, > > */ > > spin_lock_irqsave(&port->lock, flags); > > > > + /* > > + * Update the per-port timeout. > > + */ > > + uart_update_timeout(port, termios->c_cflag, baud); > > + > > /* set DLAB we have cval saved in up->lcr from the call to the core */ > > serial_port_out(port, UART_LCR, up->lcr | UART_LCR_DLAB); > > serial_dl_write(up, quot); > > -- > > 2.26.2 > >