Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2712902pxv; Sun, 11 Jul 2021 23:32:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGO3VDQ1xd/Zmg9ZHQJximxjg98ssgdMWzTNsUUJ15B6p7XaFo4tXGclN/LJQaEuhHyr4O X-Received: by 2002:a5d:88c6:: with SMTP id i6mr38936763iol.75.1626071543686; Sun, 11 Jul 2021 23:32:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626071543; cv=none; d=google.com; s=arc-20160816; b=bgq6D9d46Zh1LiSWE9qXdQ3IdSfimGakFfZVsFZXZ+bG6KucCpe3BcNqHcqYrkBTB1 cBAdNyFneRy+Anim1BJ/7wwXDct0ArikBei9ohKyVl037gNx7KcfRqnD+F3mDwDQADy4 ci4IK3C1HqDdrLTWlboe2rv/i8KNyyAnMg2b9PjoHnANA0Cn8Vnm/3Nl/OSNBwezPqRh tUAflk74zQ9+YE8TAakCO27IPZxNND1DGqdpdPNm4EdSCIPPwt3EfmW5FJich+FDLGR1 m6NtCYbZULVIL4v6tNCfM+YhaFat7ktx5foKVOcLQAfoNt2a1DSGHWb5Vkuzc1di5iO0 6y0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FJLhXN+5wcOyawEGWmbxMuv9R/PF6rXmvXZ0Khh82Jg=; b=gTzikmRyGBq9B88eW+eVzHG72Ge7xpwk5daNzj4xwY6QENvjeIdi+94YibJO7aGWBA 9TOACdSGAf4xAIlNr/My46aSNGLlKngTUYPg78GAMp4+NwrVnRw2YlHlhHUeFunC0o4N GRLegwG6wa61HfiqLukn7TnsZDGyA+MdRkQ1lvkr4Ot5dBIKPkK0iu5+uI/BdSHrjHmq gVHBGRp1lbH6M3TZB/tPXqoQb976D62biduNKKzn99l1HI9TsE+p9e/vm//XCa89cU5+ XJ6mHxoDfq8ZgX+zpzkgOyTZHuPIHR7GHZ4Uo34K8LCe+krjbZwuZTUVWHVNsEqRhHxP wGWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JvQ+DAfh; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g24si10987168jaq.119.2021.07.11.23.32.12; Sun, 11 Jul 2021 23:32:23 -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=@linuxfoundation.org header.s=korg header.b=JvQ+DAfh; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236815AbhGLGeC (ORCPT + 99 others); Mon, 12 Jul 2021 02:34:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:48518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236018AbhGLG3l (ORCPT ); Mon, 12 Jul 2021 02:29:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A91AE60FE3; Mon, 12 Jul 2021 06:26:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071205; bh=Tuwmd8AtOPKo4ijqTTBtSqPkHGXKl1uyhUbkw1r3fpE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JvQ+DAfhVWzhwscKQQ6/tqRcJ9EJ+Is27RyJo8YUiGYk/5cC68eYADXUYSk2UlObz sESbqR8KiMRouO74h9TSvj0njbD/rBmSJgDsMO5qOvivxwtZPY8X8zLJB+AiRmrDqX Gk3O+BjNvklawBpR+l5jghUDuMdOCXvWty5zOObg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Maciej W. Rozycki" , Sasha Levin Subject: [PATCH 5.4 319/348] serial: 8250: Actually allow UPF_MAGIC_MULTIPLIER baud rates Date: Mon, 12 Jul 2021 08:11:43 +0200 Message-Id: <20210712060746.313626984@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Maciej W. Rozycki [ Upstream commit 78bcae8616ac277d6cb7f38e211493948ed73e30 ] Support for magic baud rate divisors of 32770 and 32769 used with SMSC Super I/O chips for extra baud rates of 230400 and 460800 respectively where base rate is 115200[1] has been added around Linux 2.5.64, which predates our repo history, but the origin could be identified as commit 2a717aad772f ("Merge with Linux 2.5.64.") with the old MIPS/Linux repo also at: . Code that is now in `serial8250_do_get_divisor' was added back then to `serial8250_get_divisor', but that code would only ever trigger if one of the higher baud rates was actually requested, and that cannot ever happen, because the earlier call to `serial8250_get_baud_rate' never returns them. This is because it calls `uart_get_baud_rate' with the maximum requested being the base rate, that is clk/16 or 115200 for SMSC chips at their nominal clock rate. Fix it then and allow UPF_MAGIC_MULTIPLIER baud rates to be selected, by requesting the maximum baud rate of clk/4 rather than clk/16 if the flag has been set. Also correct the minimum baud rate, observing that these ports only support actual (non-magic) divisors of up to 32767 only. [1] "FDC37M81x, PC98/99 Compliant Enhanced Super I/O Controller with Keyboard/Mouse Wake-Up", Standard Microsystems Corporation, Rev. 03/27/2000, Table 31 - "Baud Rates", p. 77 Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Maciej W. Rozycki Link: https://lore.kernel.org/r/alpine.DEB.2.21.2105190412280.29169@angie.orcam.me.uk Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/tty/serial/8250/8250_port.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c index 5b673077639b..6e93aa3623d9 100644 --- a/drivers/tty/serial/8250/8250_port.c +++ b/drivers/tty/serial/8250/8250_port.c @@ -2557,6 +2557,21 @@ static unsigned int serial8250_get_baud_rate(struct uart_port *port, struct ktermios *old) { unsigned int tolerance = port->uartclk / 100; + unsigned int min; + unsigned int max; + + /* + * Handle magic divisors for baud rates above baud_base on SMSC + * Super I/O chips. Enable custom rates of clk/4 and clk/8, but + * disable divisor values beyond 32767, which are unavailable. + */ + if (port->flags & UPF_MAGIC_MULTIPLIER) { + min = port->uartclk / 16 / UART_DIV_MAX >> 1; + max = (port->uartclk + tolerance) / 4; + } else { + min = port->uartclk / 16 / UART_DIV_MAX; + max = (port->uartclk + tolerance) / 16; + } /* * Ask the core to calculate the divisor for us. @@ -2564,9 +2579,7 @@ static unsigned int serial8250_get_baud_rate(struct uart_port *port, * slower than nominal still match standard baud rates without * causing transmission errors. */ - return uart_get_baud_rate(port, termios, old, - port->uartclk / 16 / UART_DIV_MAX, - (port->uartclk + tolerance) / 16); + return uart_get_baud_rate(port, termios, old, min, max); } void -- 2.30.2