Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5249244rdb; Wed, 13 Dec 2023 03:32:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyG9fDtM2WDw0WXyr5HVHvxtuQeS78dowXH18XqMJL6pukL1WONTvow7pOvaDJTToXp2rX X-Received: by 2002:a17:902:a388:b0:1d3:589b:565f with SMTP id x8-20020a170902a38800b001d3589b565fmr70359pla.84.1702467145964; Wed, 13 Dec 2023 03:32:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702467145; cv=none; d=google.com; s=arc-20160816; b=US8jS/79yiH+buKo3CN5X6/5lZ2Mqd5g/NgFH9wxgs9T2YD2K3SRxtU2DOPhMwoOsl CnRw2pDJg/NTcItywr/PkGiDUb3eVkFeQ2Q64HfoSrxQkxPp/YxBs5ot8HKLhL6JS/Me j7rcvA+ux9HKixmPLbefYZFuunjD3Lyozkjng/zv6zOcH5C4dwpmmcFSIrkJmhTDHK0A petEG3HW4ZCYQXTSihm9iccjRXiqHX3WRBgwQYpawwoZrRwD/aIcuht58H6FdkkiwqrU WjPls96uZpZnxcJ5WYTZ8poj9zYpQyHLhEsCOi6ZmjTPjBATGXKHAp7Xv+Lg1zkY8hox ogLQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=AQvimq5jCY0FklDex/35qHrgsv6M5vZARwXkxe1/YiE=; fh=QtEizEezWMPccSW0U8o1LFLT1SqErEb68UiNokAWV6o=; b=pMTbhBs9QyUg0YarI7ImjBjOAeFuvtt8Uym46hyjYI3ya2x0KqSqiz3KTiwfirHKvc lYVWfogka0kqAridmFaPyLVS0jBO7NSK35rh6BVhmtEA8LX7F08jRIPJilQ7GJoIk7q+ kCUr+IvZSeq8JTEk3+Zm3SREUfRTb9VzGp51R6zBLVYbCz33sZz5hxXV328BgXc1nsfC TuUGFbljdxFI7HoetBeeMrEBDC6vjz2oVY5Z6XJ1mbWtIBESdr4csJBMIvlJ+2cwXp7l +jq/ZsPyngKHdVaduYue9QSb2dhDvYcLHAlmh56BhVtHRouR7/XCC+KQthP5FqUhpWuU ctng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Segc6WYj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id 11-20020a170902c20b00b001d06da42b0csi9196834pll.503.2023.12.13.03.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 03:32:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Segc6WYj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 02E73807441E; Wed, 13 Dec 2023 03:32:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377557AbjLMLb2 (ORCPT + 99 others); Wed, 13 Dec 2023 06:31:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235343AbjLMLbM (ORCPT ); Wed, 13 Dec 2023 06:31:12 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06E56118; Wed, 13 Dec 2023 03:31:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702467069; x=1734003069; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Mm/jnD5a3nD/eU5fD39yjfwmZu/H3YrYKJa0Yek6DpA=; b=Segc6WYjX064BzPridvo2uEnJ5Z5J6jZnSAb4E5Trv82ytKH0SUY5Ra5 3oTfU8UGNPCVQDfI+E+R7qYF4T+hkN+2chU0vpAGkbvrGf2ETCYc2qKqV mH+Sua+SPCzRQPX2zNwF+vOahUp3EfMkLgXacw9lp25wNH5pSzYCiHaTx IrbFy+Lb/Cw3SfTiYOclW8xAuAVs7vjCKw3WeThjf7QJ8bQxAsUZQSldi EFQkGO6c80XFuxlqBiikEFRaxFVEdjlAKPuf73ZmIfd2o4HZLQf6z2BzU 3r0Nzv1K8CFF5F0ePAhEQ5FGcT883aceDyzbzoKCGr4Ts/sWnfJVnKBZ/ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10922"; a="375104012" X-IronPort-AV: E=Sophos;i="6.04,272,1695711600"; d="scan'208";a="375104012" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Dec 2023 03:31:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10922"; a="844279512" X-IronPort-AV: E=Sophos;i="6.04,272,1695711600"; d="scan'208";a="844279512" Received: from newjersey.igk.intel.com ([10.102.20.203]) by fmsmga004.fm.intel.com with ESMTP; 13 Dec 2023 03:31:04 -0800 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Maciej Fijalkowski , Michal Kubiak , Larysa Zaremba , Alexander Duyck , Yunsheng Lin , David Christensen , Jesper Dangaard Brouer , Ilias Apalodimas , Paul Menzel , netdev@vger.kernel.org, intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v7 07/12] page_pool: add DMA-sync-for-CPU inline helper Date: Wed, 13 Dec 2023 12:28:30 +0100 Message-ID: <20231213112835.2262651-8-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231213112835.2262651-1-aleksander.lobakin@intel.com> References: <20231213112835.2262651-1-aleksander.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 13 Dec 2023 03:32:15 -0800 (PST) Each driver is responsible for syncing buffers written by HW for CPU before accessing them. Almost each PP-enabled driver uses the same pattern, which could be shorthanded into a static inline to make driver code a little bit more compact. Introduce a simple helper which performs DMA synchronization for the size passed from the driver. It can be used even when the pool doesn't manage DMA-syncs-for-device, just make sure the page has a correct DMA address set via page_pool_set_dma_addr(). Signed-off-by: Alexander Lobakin --- include/net/page_pool/helpers.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h index c860fad50d00..73ef4d1e12d4 100644 --- a/include/net/page_pool/helpers.h +++ b/include/net/page_pool/helpers.h @@ -52,6 +52,8 @@ #ifndef _NET_PAGE_POOL_HELPERS_H #define _NET_PAGE_POOL_HELPERS_H +#include + #include #ifdef CONFIG_PAGE_POOL_STATS @@ -382,6 +384,28 @@ static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr) return false; } +/** + * page_pool_dma_sync_for_cpu - sync Rx page for CPU after it's written by HW + * @pool: &page_pool the @page belongs to + * @page: page to sync + * @offset: offset from page start to "hard" start if using PP frags + * @dma_sync_size: size of the data written to the page + * + * Can be used as a shorthand to sync Rx pages before accessing them in the + * driver. Caller must ensure the pool was created with ``PP_FLAG_DMA_MAP``. + * Note that this version performs DMA sync unconditionally, even if the + * associated PP doesn't perform sync-for-device. + */ +static inline void page_pool_dma_sync_for_cpu(const struct page_pool *pool, + const struct page *page, + u32 offset, u32 dma_sync_size) +{ + dma_sync_single_range_for_cpu(pool->p.dev, + page_pool_get_dma_addr(page), + offset + pool->p.offset, dma_sync_size, + page_pool_get_dma_dir(pool)); +} + static inline bool page_pool_put(struct page_pool *pool) { return refcount_dec_and_test(&pool->user_cnt); -- 2.43.0