From patchwork Tue Aug 30 13:13:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ilpo_J=C3=A4rvinen?= X-Patchwork-Id: 601435 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 684FAECAAA1 for ; Tue, 30 Aug 2022 13:14:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230165AbiH3NOK (ORCPT ); Tue, 30 Aug 2022 09:14:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230216AbiH3NOH (ORCPT ); Tue, 30 Aug 2022 09:14:07 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC411BADB0; Tue, 30 Aug 2022 06:13:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661865238; x=1693401238; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WNwFYsnxejnsb3PAJO0FgVsTN5fGGjYc+Bh4CgV230I=; b=J0HQsEEc87tbKRNG5dFjQMYN1XWgeAnaQzfYo68JROEDCvytzd6zbqTR KsVJp8BQlfzVH1SlbeZQSOb0yNS1cpk8fqBUuYD39bnfJZn+Ea8E5f0IT 2/xwaJ5+EJMz3uublVXgVXYJ3qrn/KQeRLvj2rKnUZd8Hp2sNzBSzHSse QpP9lF2kdsXPXijhWo1qMG1e4IcvGBwkuFl4WL0fJ16rAq4det9w9h3hM l0HoTANGqwYMh3NfrUuq/8ie1C6C5uGGKKzAi2U6NeT5Bt4cYIgtbFLjE pvNwTlrvuLk41nkyy0GWYzM05vGqYu4qe40oKlpwtvIFePhqz8goXvbSl Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10455"; a="278188143" X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="278188143" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 06:13:57 -0700 X-IronPort-AV: E=Sophos;i="5.93,275,1654585200"; d="scan'208";a="672860926" Received: from arnesgom-mobl.ger.corp.intel.com (HELO ijarvine-MOBL2.ger.corp.intel.com) ([10.252.54.235]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 06:13:55 -0700 From: =?utf-8?q?Ilpo_J=C3=A4rvinen?= To: Greg Kroah-Hartman , Jiri Slaby , linux-serial@vger.kernel.org, Andy Shevchenko , linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Andy Shevchenko Subject: [PATCH v2 1/3] serial: Create uart_xmit_advance() Date: Tue, 30 Aug 2022 16:13:41 +0300 Message-Id: <20220830131343.25968-2-ilpo.jarvinen@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220830131343.25968-1-ilpo.jarvinen@linux.intel.com> References: <20220830131343.25968-1-ilpo.jarvinen@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org A very common pattern in the drivers is to advance xmit tail index and do bookkeeping of Tx'ed characters. Create uart_xmit_advance() to handle it. Reviewed-by: Andy Shevchenko Signed-off-by: Ilpo Järvinen --- include/linux/serial_core.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index aef3145f2032..ffc7b8cb7a7f 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -616,6 +616,23 @@ struct uart_state { /* number of characters left in xmit buffer before we ask for more */ #define WAKEUP_CHARS 256 +/** + * uart_xmit_advance - Advance xmit buffer and account Tx'ed chars + * @up: uart_port structure describing the port + * @chars: number of characters sent + * + * This function advances the tail of circular xmit buffer by the number of + * @chars transmitted and handles accounting of transmitted bytes (into + * @up's icount.tx). + */ +static inline void uart_xmit_advance(struct uart_port *up, unsigned int chars) +{ + struct circ_buf *xmit = &up->state->xmit; + + xmit->tail = (xmit->tail + chars) & (UART_XMIT_SIZE - 1); + up->icount.tx += chars; +} + struct module; struct tty_driver;