Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4869519pjb; Mon, 27 Jul 2020 07:14:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsolQtGW/BDKghx5rdvHj5Urvqqq9RXuveqL3FqsWFrd3LbFvqnkV1dB6qWroOgGt3AtDc X-Received: by 2002:a17:906:140e:: with SMTP id p14mr17630375ejc.430.1595859280960; Mon, 27 Jul 2020 07:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595859280; cv=none; d=google.com; s=arc-20160816; b=D3lkARDrpxXtLCFZ3AWTB2RZmzvr7wuCZ9fsZEtjd096LaaoGbtFoYvvH0+X6NeF6P P0TiWNi0ya/UUuokMvMTNyASk/N+tXSctlt0wO4Jd5w1Np8vBhqYB9AzW/xPmHfb76Y+ vpEz5Adbt/1AyFw7zlmqKKEa2WKNUduzSgTbudoljIEeZZWQ5NG6y4H+LqL2+5VrecMv +ukwrUJFJ7/vrXsfBmelPc5sQOLMcl273TGCoV3v3/ClTPHMuK92gOomz61naO8CpdL5 MnpfAOnDv8QSl+uM2wtA7bQEmUwoxTUZqwk9C9OGC9MCZK5KRUf66xSTryX5iOyB9xTd SxZA== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=KP5CTdsl3wqqdgapCklmsP5Khez+I0RvNuc8ukLJNQY=; b=oYvKIgARHKa1GgnmGJr4xobTqKGS18I+oeKfXtNmgvgahdKjlR7al2nQpToND/4XIx PDqCc1C0mjKok+9dVbO9a4mkAWjQVEYxW1CjJIdxOPZrjjCRRQqEv6d7qKeL4PDuA+ki dFIyNFFWqf11LYUpaIUV1mikw/RJklnPOem/XjSIWo18ZJJvDHDMH0wdVKNilJp9mzs+ mXzUA6GE+rDJasvodwaBsM6VP6QAd8HpXqRZcp/mk3O7+9Svl7X845fU1AXR17sZypC/ 7ocYbfJh6gUDZFnw2b/qUVthmqwwzMdPm2ep9J4kp6n7SgR/vn2WacRKJC6NYbhK8H5Q aIpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="r0m/KmFj"; 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 t15si4522449ejx.660.2020.07.27.07.14.18; Mon, 27 Jul 2020 07:14:40 -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; dkim=pass header.i=@kernel.org header.s=default header.b="r0m/KmFj"; 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 S1730267AbgG0OMt (ORCPT + 99 others); Mon, 27 Jul 2020 10:12:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:37244 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730253AbgG0OMq (ORCPT ); Mon, 27 Jul 2020 10:12:46 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C9A232073E; Mon, 27 Jul 2020 14:12:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859165; bh=fDDFY8It2TGktthmAacBh2/DZrA7MmSualpCudu0cWc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r0m/KmFja61hFkXyoF81yY83sUibV1OiLvPQL7Um8rH+G+RSDA632AUTmNREjzE37 zlVPWVxYJtCEzoRUvuup0fAIFw6DBDMnRLqKv9qPZKVCzo6clQHmpky3VXxOSyZYOF zKlwVT1Wno/5mBNUVp0DOax3TwLJ6EB2zxaJ3Kes= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Winkler , Serge Semin , Claire Chang Subject: [PATCH 4.19 71/86] serial: 8250_mtk: Fix high-speed baud rates clamping Date: Mon, 27 Jul 2020 16:04:45 +0200 Message-Id: <20200727134917.979893845@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134914.312934924@linuxfoundation.org> References: <20200727134914.312934924@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Serge Semin commit 551e553f0d4ab623e2a6f424ab5834f9c7b5229c upstream. 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 Cc: stable Tested-by: Claire Chang Link: https://lore.kernel.org/r/20200714124113.20918-1-Sergey.Semin@baikalelectronics.ru Signed-off-by: Greg Kroah-Hartman --- drivers/tty/serial/8250/8250_mtk.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) --- a/drivers/tty/serial/8250/8250_mtk.c +++ b/drivers/tty/serial/8250/8250_mtk.c @@ -36,8 +36,21 @@ mtk8250_set_termios(struct uart_port *po unsigned long flags; unsigned int baud, quot; + /* + * 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 (UART_MTK_HIGHS) * @@ -76,6 +89,11 @@ mtk8250_set_termios(struct uart_port *po */ 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);