From patchwork Thu Apr 18 11:36:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 1924932 X-Patchwork-Delegate: anthony.l.nguyen@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=osuosl.org header.i=@osuosl.org header.a=rsa-sha256 header.s=default header.b=iUWWfvqi; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=osuosl.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver=patchwork.ozlabs.org) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VKwjZ6G98z1yZP for ; Thu, 18 Apr 2024 21:37:06 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 59DF2416C2; Thu, 18 Apr 2024 11:37:05 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id UGyTDkII48zT; Thu, 18 Apr 2024 11:37:03 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.166.34; helo=ash.osuosl.org; envelope-from=intel-wired-lan-bounces@osuosl.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 7AFE4416AC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osuosl.org; s=default; t=1713440223; bh=cP32Q3dEgPXhmR3/rYVgH7UWTRGTR3MvWVNydA/XXaI=; h=From:To:Date:In-Reply-To:References:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=iUWWfvqiRKrwnWvPv+NepvLDcMQ7BLR/nL8kMH20mN1DKYrG3JSPCHxkGAci2u0XO ZenFXbFPyeSExawe4JDUXyuQ/GZ18X0RmE1qiBXSkS34MFnYnucs5bWfZaZSUsQeXk zNbDDp45qFZasXHUTajzCBSP2NL5EBxSttdmEay+enGsZLcbdnUkGOnjMVbOkz7Msh KRNzkrRWnwdCVhAS6VumE4FQeVqWgZ+vyCdAVgdaU7dIDdZv2J2n1bwTwuY+zH+sHV wXXthXU9hzcE0M0X5nWywWavVBK+V8SpIIlHB4CrxXVq0N9Gjuj3abNu7kR5KULj/J KGlfeDViWAxTg== Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by smtp2.osuosl.org (Postfix) with ESMTP id 7AFE4416AC; Thu, 18 Apr 2024 11:37:03 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id 27B061BF3F2 for ; Thu, 18 Apr 2024 11:37:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 216F960BA4 for ; Thu, 18 Apr 2024 11:37:02 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id OIl1W4PQ4SWM for ; Thu, 18 Apr 2024 11:37:01 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=192.198.163.11; helo=mgamail.intel.com; envelope-from=aleksander.lobakin@intel.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 604CF60BA0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 604CF60BA0 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by smtp3.osuosl.org (Postfix) with ESMTPS id 604CF60BA0 for ; Thu, 18 Apr 2024 11:37:01 +0000 (UTC) X-CSE-ConnectionGUID: 4alj6gXqR0qXdpRkT9ct4w== X-CSE-MsgGUID: Da3hhuwYToS+hTxmTt67RQ== X-IronPort-AV: E=McAfee;i="6600,9927,11047"; a="19587794" X-IronPort-AV: E=Sophos;i="6.07,212,1708416000"; d="scan'208";a="19587794" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Apr 2024 04:37:01 -0700 X-CSE-ConnectionGUID: nnD24O+AS8Ou8XYPzWCoNw== X-CSE-MsgGUID: i7kHYavwRdepzRSa2rF85g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,212,1708416000"; d="scan'208";a="27586122" Received: from newjersey.igk.intel.com ([10.102.20.203]) by fmviesa004.fm.intel.com with ESMTP; 18 Apr 2024 04:36:57 -0700 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Date: Thu, 18 Apr 2024 13:36:12 +0200 Message-ID: <20240418113616.1108566-7-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240418113616.1108566-1-aleksander.lobakin@intel.com> References: <20240418113616.1108566-1-aleksander.lobakin@intel.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1713440221; x=1744976221; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OhUqtf35fdgCEyiIWVQHl/adPq6y26tJ1DJr2rp+7fQ=; b=DtyCqZki4N2mfsrLOR80iko2QDBcSN1uE1ah2kllTy4kzdQ9UZjK1tBO 4B9UquFLDW3jGHg5PZu0S3guP9/F5RwvEzsgJTDXZ6uRf9FXANGWjsEjV ddwshXo7gg3kDN7Kj+fSB1xYLN2rF1XP4Pq9uU1b+huWlUWHWQviExuCy Z/vrFMgPR2vHUwrXazbwTscG2h3MrcppZpvcDuIrV3UIRQpmDUxlLEpfC 8Q7t3W6voPzN6O3ecKr+iGXxkOifQNyWQm/2273q220rhSpmVbXIPvacW J5K4jXbvRsgqsPUWAQNlzkfpxVsF99mA8Lsyp8tRMYDA7BARrlpTE4Hxs w==; X-Mailman-Original-Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=intel.com X-Mailman-Original-Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=DtyCqZki Subject: [Intel-wired-lan] [PATCH net-next v10 06/10] page_pool: add DMA-sync-for-CPU inline helper X-BeenThere: intel-wired-lan@osuosl.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jesper Dangaard Brouer , linux-mm@kvack.org, Przemek Kitszel , Alexander Duyck , Ilias Apalodimas , linux-kernel@vger.kernel.org, Alexander Lobakin , Yunsheng Lin , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, nex.sw.ncis.osdt.itp.upstreaming@intel.com, Christoph Lameter , Andrew Morton , Vlastimil Babka Errors-To: intel-wired-lan-bounces@osuosl.org Sender: "Intel-wired-lan" 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 Reviewed-by: Ilias Apalodimas --- 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 c7bb06750e85..873631c79ab1 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 @@ -395,6 +397,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);