Received: by 2002:ab2:715a:0:b0:1fd:c064:50c with SMTP id l26csp129388lqm; Mon, 10 Jun 2024 15:26:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXgRU16eTwwk8GgbSeNi0MG3aAF2wyUFrGlP/K0I9cAONSeJLC7HFR9pHyINOUGq0hv4quT5p3FZmRbV5SQHTyHF9HTaqZnNArQgGvc3Q== X-Google-Smtp-Source: AGHT+IH/GiZVvi2zV8UkwStFBUZpp4a04xI3DNI5LTcEql7KZcQVjIZ/D6mkXBU1zul8SoE9ZeoM X-Received: by 2002:a17:906:e28f:b0:a6f:3135:e2ce with SMTP id a640c23a62f3a-a6f3135e4fcmr84691166b.68.1718058376053; Mon, 10 Jun 2024 15:26:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718058376; cv=pass; d=google.com; s=arc-20160816; b=ZolGsIwXbp8tbooPKbGRQnyArfe85AoScRECIJx63hns4BPq6HWj8RiZKPfpTY6pwe T9RRHORAb53IaJgXwgWeWaXJFIfMU90db+5wcBsEcM54NCGjTwB8tEasoFKERDO87E4m LadLwkOMlakHxvi5TVDT63N17gP9FMDl/ZOUb6I1zrm9jXgUQcoKHKl77sXQiX1jx3Ng 2zuA72L2BOVKkzAPC2g7WND1Nk/uVCNkAxIy3su+se58Fd9qnsi6CpZPf/tGSsDmCOdL DoL4lmBwTml/XwQ8M+Qm97jqPazgLj436Cx0kkO3Yh94UlV7T26Wnqim9OpIRcP7ZReI n9jA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nKk/Fcf4krWK/CutdJaQNqib/rpK58721OaB/B0Az0c=; fh=VRsn48I+dxU+uShhi6l4dUESroXp3YMFXvoxwbC+jl0=; b=rbDpkjGYAoxNI/bWOx3Iu71p0Qtn8IjAC+269Q1JJW7QVnxSE0FVz8yc6Kd/gjIzhu wQKhqsTW32EFgAFqbRe0rSUWoMFU6xvhD41piGYv3y3uAf7LceK79OcI3M8j+RwOYh+/ eBUXH0yTm8eHTxYD1Fi8kVhJO0FyYtXQzZewOXGo8Ow2AETKuI2Ra9cIpTveaXpR/npE a7W5u7QX+tcW5NPs/ISq3PA4ULPXVtt0eX7fpGbacerQ6x/QPPY3OptnljYvV0gFJW+J +OtKtuHwmrDjRBWpTrzTLK+ro0Qwid37lebmDJAz7ES5nnn6Xo6Gduw82avxxe9aAXan BBZg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Yl4MEXmL; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-208994-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208994-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f10a1ebc2si236250466b.614.2024.06.10.15.26.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 15:26:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208994-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Yl4MEXmL; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-208994-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208994-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id BF6461F22DA6 for ; Mon, 10 Jun 2024 22:26:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E180015098A; Mon, 10 Jun 2024 22:25:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Yl4MEXmL" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A71361514DC for ; Mon, 10 Jun 2024 22:25:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718058341; cv=none; b=T2fZ9otyzwUaNkyFuGputZ7DN0kLqwRMjc4RVeehTStyYbveyhfqiPz0WLrl/8e84TdZkCKg6H9LJc6y/xyGkzH+WNeHg3tkZ8bJF7s9JDTx7998z7sudmMzmyqNpI/Xc8cSVI4uqXEJr562bBcnOdbnTvJgMTJux5x1fFqos1I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718058341; c=relaxed/simple; bh=b/gmORW177pH358qwBll4nCzl18LhbdthrWxcEpd3WY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IXhksNHy9wOD27RdxsKSQv9B2lXNyPC0sxOQrj2MxvJ9DsMCt20Z4SFhtN43lTaKqcDtc9Vh817oP7YCrb9LJf59heVwkzv2KybioLA5IOoVSu57dt4+I5e9E8SfmNUuwEO1BFsiH/L08hZFH/nlldQKvjyLwxe6yevHoDY5WWI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Yl4MEXmL; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1f6da06ba24so27533875ad.2 for ; Mon, 10 Jun 2024 15:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1718058339; x=1718663139; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nKk/Fcf4krWK/CutdJaQNqib/rpK58721OaB/B0Az0c=; b=Yl4MEXmLY1Hlh4sAr3wjNFtQ3BaO0gFGzAI7U5DW1fjXy6EpvqNrx5c/Iy1oucxc5N j/DnNXxi8fGqv0KcWHqj5dByyQvsT7zXM+pynSCjm2tJmvxk8BKNBBZ+CsqYoQUyIGQ+ p1aH18VNQfC21BJV3maG+uPpiegxBXG+o9zZI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718058339; x=1718663139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nKk/Fcf4krWK/CutdJaQNqib/rpK58721OaB/B0Az0c=; b=nnR+tmVVRRwO7NTyR280kB9rcz2TsJuK2kyIt9C/wY+RwcS03rrKQfE2UcMzWWzz08 0FilPH7/pJ2p+mQ/Ra4OZybrCLbvu3HHnwjDZDip1oukTqcisdfd719eGReJU1k8clts cCx+hgEw3nvTF42LeDRvBxyP6MT53OhtIIvmHegWCWBUfIvm2DB7M9QwZuKT1wY1mZRx ElOLiUXa18nBNXf0rqhQYghxp0sZZbTvr+9+YdKB+FP2QIrk/mMFBxJDpG4pZfb/Y1mI Mpcnq04VEVy17OyjWhwLzpwE1kUV/68Z64PqARN3yKxMdwSKO0cG1d7KSvUTgnS/ynUq lSgw== X-Forwarded-Encrypted: i=1; AJvYcCValuK/Z6hPfUUByG38PV3PAPJVzxxRZk6lP30FOj7ztW/XDDDRygBWA4Fv1as2u1zM4nevexEfrZ4s5wz7GeQAJtmj/AvVm2ZzOx4u X-Gm-Message-State: AOJu0YxtgZI0vQeDF3pyZs1RQOxbEMP95/qlFU42iKO60QdWBPQZUsuO a4E0padIu007ilmRnb++GUJZvh3Xyia+Yq4LOCOr1C1smPSmSOwEJ1ZGq30K4Q== X-Received: by 2002:a17:902:dace:b0:1f7:2dca:ea39 with SMTP id d9443c01a7336-1f72dcaf3a1mr3583725ad.68.1718058338829; Mon, 10 Jun 2024 15:25:38 -0700 (PDT) Received: from dianders.sjc.corp.google.com ([2620:15c:9d:2:bba2:69f4:1b51:d0f5]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f71029e223sm29212325ad.170.2024.06.10.15.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 15:25:37 -0700 (PDT) From: Douglas Anderson To: Greg Kroah-Hartman , Jiri Slaby Cc: Yicong Yang , Tony Lindgren , Andy Shevchenko , Johan Hovold , John Ogness , linux-arm-msm@vger.kernel.org, Bjorn Andersson , Konrad Dybcio , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Stephen Boyd , linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Douglas Anderson Subject: [PATCH v4 2/8] tty: serial: Add uart_fifo_timeout_ms() Date: Mon, 10 Jun 2024 15:24:20 -0700 Message-ID: <20240610152420.v4.2.I65a6430ab75f74d20c28b5c5f819dd5b8455933d@changeid> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog In-Reply-To: <20240610222515.3023730-1-dianders@chromium.org> References: <20240610222515.3023730-1-dianders@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current uart_fifo_timeout() returns jiffies, which is not always the most convenient for callers. Add a variant uart_fifo_timeout_ms() that returns the timeout in milliseconds. NOTES: - msecs_to_jiffies() rounds up, unlike nsecs_to_jiffies(). This is because msecs_to_jiffies() is actually intended for device drivers to calculate timeout value. This means we don't need to take the max of the timeout and "1" since the timeout will always be > 0 ms (we add 20 ms of slop). - uart_fifo_timeout_ms() returns "unsigned int" but we leave uart_fifo_timeout() returning "unsigned long". This matches the types of msecs_to_jiffies(). Suggested-by: Ilpo Järvinen Signed-off-by: Douglas Anderson --- Changes in v4: - New include/linux/serial_core.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 8cb65f50e830..97968acfd564 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -889,14 +889,21 @@ unsigned int uart_get_divisor(struct uart_port *port, unsigned int baud); /* * Calculates FIFO drain time. */ -static inline unsigned long uart_fifo_timeout(struct uart_port *port) +static inline unsigned int uart_fifo_timeout_ms(struct uart_port *port) { u64 fifo_timeout = (u64)READ_ONCE(port->frame_time) * port->fifosize; + unsigned int fifo_timeout_ms = div_u64(fifo_timeout, NSEC_PER_MSEC); - /* Add .02 seconds of slop */ - fifo_timeout += 20 * NSEC_PER_MSEC; + /* + * Add .02 seconds of slop. This also helps account for the fact that + * when we converted from ns to ms that we didn't round up. + */ + return fifo_timeout_ms + 20; +} - return max(nsecs_to_jiffies(fifo_timeout), 1UL); +static inline unsigned long uart_fifo_timeout(struct uart_port *port) +{ + return msecs_to_jiffies(uart_fifo_timeout_ms(port)); } /* Base timer interval for polling */ -- 2.45.2.505.gda0bf45e8d-goog