Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp581823lqc; Fri, 8 Mar 2024 06:20:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUOcjKO+HnqqdCHfXAyQC+LluCV2LoleTRmzC/ONFPsyA5389+dIdd8qMiOglV3NK7EujlMYXSUgTABP4qaume5BzGUsbYKROTR9JSjsA== X-Google-Smtp-Source: AGHT+IGA8RZdP3EH+w83z84+NyBoUdxhZmlN0IJjpQLj6L6sY8ffjFrhw6AA7ic+otkj9PzW745T X-Received: by 2002:a0c:e353:0:b0:690:97ed:fe30 with SMTP id a19-20020a0ce353000000b0069097edfe30mr6605036qvm.30.1709907657222; Fri, 08 Mar 2024 06:20:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709907657; cv=pass; d=google.com; s=arc-20160816; b=bH/bOajRKXM/sePaSxu/E46mBJa9UHJDBYt7N2FQwoVRY6zxDDw6tF62uZ+XWYQy+G drIKT4mVbS5l9EBTPmDICJWL7fMr5njSfUYC3CSauemtLZrTGv6I059bRD/3gOjTajfE GLkkg9QUyLgu4z5E9xwp4JIU1Izv6mkrOky3yDZyVsfAaLaoKqNFQ+vm3nZIUopp6njt m/w3hrKllirkFYzX6KF8BV7BpL93jDzaI04bLb/uF0DcQq1iy0hK+f4byJA14LraOas5 NfpZwUPv1SW7vAPiafPpP9KG8IOrupiSUDFfApej7u1iuSGvoI7q3nMapxnbaPR4o/qf G6dw== 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=cP32Q3dEgPXhmR3/rYVgH7UWTRGTR3MvWVNydA/XXaI=; fh=rVoWC3S/ODW8/s5CSXkLktge4mq/2qNd5hep4xQmFoM=; b=TZ0buXtj+IyW/K5L4oaMZkfwe/cNxHvNbpQCqimIy8m7XiaMdpMHztFT2AY5riOQYs sJHBNZmDQV8S0YrcHK+tP8mhqn0I2wzbX1Df98sZule1nXVZpmj6Jq1V0q4z+O79SB9P A0byHqRl3Ghd4WhjbAoFeQ76LW4+B6ByrsGfJDLKaLYW942prNSjJNt+awfi4kFBO08m 4muAy8stNjO+GMQrxqUgWTqmW1xE16NDOnua/oS6iNet2yK/duM0hcwZWWQYXNfznd+C AEXW5ZvhemSJ6Yja1W2yc9d35CvT+PKU6+THlevOpTuVHLPEW1jWLrepHdOJ8XtdcSj2 GPhQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZO9nCLXT; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-97156-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97156-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a8-20020a056214062800b0068cc3b0f1e4si18771430qvx.411.2024.03.08.06.20.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 06:20:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-97156-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZO9nCLXT; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-97156-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-97156-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EC4AB1C2266D for ; Fri, 8 Mar 2024 14:20:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C69635B666; Fri, 8 Mar 2024 14:19:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="ZO9nCLXT" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 532E95B21D; Fri, 8 Mar 2024 14:19:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.20 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709907552; cv=none; b=NYkbsDDUsApQqXwuLMKMRJk+QQLtpv2ly+bS5TLgcGNf0pZeS57+o5rdZ4kl7ox+UcW1b/nuRSL+BnxteGW4v4lQzUOAO4go7XSHxrb61Xc5v+UTUvh1WVRpLqt7ivB8yq5XSyBuJPMfog5tGGHTBzV6C/Pd0LJq68+wXAadxrs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709907552; c=relaxed/simple; bh=OhUqtf35fdgCEyiIWVQHl/adPq6y26tJ1DJr2rp+7fQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y0QtNEFaD42ilQ21R9rYrQaeb8pPym9Uf+KKASjz8zL8H3/2sGTYTTLWM6vMpLiNx43iBJq8EjL389+utVi28BPDXnTg72HMzuSsw9OEBYYPMnZ317Uw0KQYfZ9CCH1Rns/xjNFkvD4sOxgwAaw9IZqHCTN2ZNTKRMu3gGiawPM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=ZO9nCLXT; arc=none smtp.client-ip=198.175.65.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709907550; x=1741443550; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OhUqtf35fdgCEyiIWVQHl/adPq6y26tJ1DJr2rp+7fQ=; b=ZO9nCLXTOn2zWcE8vYt/ZKmM7Sc7FWSn8Xp3qBclxIM5lsSjN6d4JINp XvHfJVDTKV04Fpj305ViDMSwBJLGzU0q2yFxM17xvvW+0gpp/GQBuWrb7 CvaqYGbq43QzB6/Hgq09uHi0o/BqTaYIIEtfDYGyAxLiFKdtV6U2ppcrj 1Ou6/zKmoJt1C/nNqRBe3l+2/c2B5l4ndIBHJU6YQmVIjJQGUTaJuyt/n /dhg1S/WBxl4iN5IvQ3JUa2HUWQUoszrJkP2gPuSSO0Zmf5bCzBuqs8Ja 6BzkJLLuH9sBrIJJA9QI/i5Rrp51qF3enSer/mgG0VPc0S1KsV+iIWi7w Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11006"; a="4504603" X-IronPort-AV: E=Sophos;i="6.07,109,1708416000"; d="scan'208";a="4504603" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2024 06:19:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,109,1708416000"; d="scan'208";a="15177243" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa005.jf.intel.com with ESMTP; 08 Mar 2024 06:19:06 -0800 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Alexander Duyck , Yunsheng Lin , David Christensen , Jesper Dangaard Brouer , Ilias Apalodimas , Paul Menzel , nex.sw.ncis.osdt.itp.upstreaming@intel.com, netdev@vger.kernel.org, intel-wired-lan@lists.osuosl.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v8 5/8] page_pool: add DMA-sync-for-CPU inline helper Date: Fri, 8 Mar 2024 15:18:30 +0100 Message-ID: <20240308141833.2966600-6-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240308141833.2966600-1-aleksander.lobakin@intel.com> References: <20240308141833.2966600-1-aleksander.lobakin@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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); -- 2.44.0