Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1185420rdb; Fri, 22 Dec 2023 19:04:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHi1Fm1TaBTbkQNjlI/0hjDttI/nUUh1EF7fTBlg1AlrU9KpJzqm7zYoj/uelwpi8yfTLHd X-Received: by 2002:a50:d69d:0:b0:553:a410:c8a3 with SMTP id r29-20020a50d69d000000b00553a410c8a3mr1260141edi.62.1703300653186; Fri, 22 Dec 2023 19:04:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703300653; cv=none; d=google.com; s=arc-20160816; b=hsC5YxhDnAHRPb0xqLjftxZrNBE+NMS2cxeCr7xbiBNtk2KiFbCQnlBVjX5weB+8jV SY3UGHYw0GwfsjguhcNVI4y2ToETDNea8WosaAjrNXNZ7q6prLixPfRA7356wmGiedHh jdfNmCPsXJCXNNnR3xsf/f8vcit77cRHb19aqJwnvM/0QHD/igZX1mfUxHSHNv/k5A3S CGmcPZ2LMF1pY6lvS4AsaQBWCc5cZ8bJBT/LWvxfu/AM/rrk/gtr36qQj8myXy+28cVI f6DJ3IuQyXZn8HlM9k6XOnNy/w1lciGUHHTMA5CBjK3PGai47uPhmaWJTnYbas0+T2fy 9DqA== ARC-Message-Signature: i=1; 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=H3ys+8LalD7qsA92ufykH6V9CIt0PqKTU8BsCMQduo4=; fh=J3H3jkZRTdH/CD0R7uXO8r43FYFiJ1FqB2ouoqeBxmQ=; b=nWXa3WOv3FpZw/2D9R11A2hVmBQAb0rT32NCANywydAduwrvWB1TQjmaJfCL37SyPG blALMi7jePoG5vL+2luIK6npFftb3Xo06L7+zrmnoamOq5cPzCw8rUMUl8NvGTSeeDrz C9oyUw9mXJ0V3fuJzOjQBfRSwycC743hWb+mtYEUaMJ0ax3wxN/EXe5FS2ebrizirL+3 5GGvDfmsz9/ueuP25wnLXkQcO3rhQ77b+xE0bZUJBbmb9AgxlW8f+yruZNJ41GGf2hxF ucM7dW6PLm9VTQUk2InVWGzrqOd7zsXwUb/WY+UB17LnDzjjxOa4ljRsTKkBDpMbN6kP KPew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OS8gWTJo; spf=pass (google.com: domain of linux-kernel+bounces-10233-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10233-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id e22-20020a50d4d6000000b005536d89328fsi479556edj.609.2023.12.22.19.04.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 19:04:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10233-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=@intel.com header.s=Intel header.b=OS8gWTJo; spf=pass (google.com: domain of linux-kernel+bounces-10233-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10233-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 am.mirrors.kernel.org (Postfix) with ESMTPS id ECED21F2413F for ; Sat, 23 Dec 2023 03:04:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 587458814; Sat, 23 Dec 2023 02:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OS8gWTJo" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.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 310D728DDF; Sat, 23 Dec 2023 02:59:09 +0000 (UTC) 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=1703300349; x=1734836349; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VNPt1nK0AOP2pNwVFe078A89NwhgBYFYVPqNFR4BfTE=; b=OS8gWTJoJJ0wBk47XVF5PlPL0QGjq/8FzWdu2YwytECsswF3/zbQ2rlU mciXwrChmCprP/re8dk51H6a6di8GEBbBC4uf+Wai4K0Fm2Y3t0/0I//a sJ4pgO1QRiio0z/b3uAuynWU4zzjk3WbB5w3bkE8hPiB5bZuyBloMvWdV cDH1bqFBIbt2gmPlPAbgbx8RoC4HulcR6XaUXnrnawyexHNSCjX2049eF Ua02gX7ROOL5ZpAabD0sKsf2I7eMwXYv+DVDwNW15XVAOcBLulfmf9NH1 zsCCFXX25ryp2h+XNaBxVM2SvDe/qH2lE0Q9aJiQBSIpTqQS5XmfeoaP2 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="386610936" X-IronPort-AV: E=Sophos;i="6.04,298,1695711600"; d="scan'208";a="386610936" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Dec 2023 18:59:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,298,1695711600"; d="scan'208";a="25537535" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa001.jf.intel.com with ESMTP; 22 Dec 2023 18:59:05 -0800 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Maciej Fijalkowski , Michal Kubiak , Larysa Zaremba , Alexei Starovoitov , Daniel Borkmann , Willem de Bruijn , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC net-next 17/34] libie: support native XDP and register memory model Date: Sat, 23 Dec 2023 03:55:37 +0100 Message-ID: <20231223025554.2316836-18-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231223025554.2316836-1-aleksander.lobakin@intel.com> References: <20231223025554.2316836-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 Expand libie's Page Pool functionality by adding native XDP support. This means picking the appropriate headroom and DMA direction. Also, register all the created &page_pools as XDP memory models. A driver then can call xdp_rxq_info_attach_page_pool() when registering its RxQ info. Signed-off-by: Alexander Lobakin --- drivers/net/ethernet/intel/libie/rx.c | 32 ++++++++++++++++++++++----- include/linux/net/intel/libie/rx.h | 6 ++++- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/intel/libie/rx.c b/drivers/net/ethernet/intel/libie/rx.c index 3d3b19d2b40d..b4c404958f25 100644 --- a/drivers/net/ethernet/intel/libie/rx.c +++ b/drivers/net/ethernet/intel/libie/rx.c @@ -52,7 +52,7 @@ static u32 libie_rx_hw_len_truesize(const struct page_pool_params *pp, static void libie_rx_page_pool_params(struct libie_buf_queue *bq, struct page_pool_params *pp) { - pp->offset = LIBIE_SKB_HEADROOM; + pp->offset = bq->xdp ? LIBIE_XDP_HEADROOM : LIBIE_SKB_HEADROOM; /* HW-writeable / syncable length per one page */ pp->max_len = LIBIE_RX_BUF_LEN(pp->offset); @@ -132,17 +132,34 @@ int libie_rx_page_pool_create(struct libie_buf_queue *bq, .dev = napi->dev->dev.parent, .netdev = napi->dev, .napi = napi, - .dma_dir = DMA_FROM_DEVICE, }; + struct xdp_mem_info mem; + struct page_pool *pool; + int ret; + + pp.dma_dir = bq->xdp ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE; if (!bq->hsplit) libie_rx_page_pool_params(bq, &pp); else if (!libie_rx_page_pool_params_zc(bq, &pp)) return -EINVAL; - bq->pp = page_pool_create(&pp); + pool = page_pool_create(&pp); + if (IS_ERR(pool)) + return PTR_ERR(pool); + + ret = xdp_reg_mem_model(&mem, MEM_TYPE_PAGE_POOL, pool); + if (ret) + goto err_mem; + + bq->pp = pool; + + return 0; - return PTR_ERR_OR_ZERO(bq->pp); +err_mem: + page_pool_destroy(pool); + + return ret; } EXPORT_SYMBOL_NS_GPL(libie_rx_page_pool_create, LIBIE); @@ -152,7 +169,12 @@ EXPORT_SYMBOL_NS_GPL(libie_rx_page_pool_create, LIBIE); */ void libie_rx_page_pool_destroy(struct libie_buf_queue *bq) { - page_pool_destroy(bq->pp); + struct xdp_mem_info mem = { + .type = MEM_TYPE_PAGE_POOL, + .id = bq->pp->xdp_mem_id, + }; + + xdp_unreg_mem_model(&mem); bq->pp = NULL; } EXPORT_SYMBOL_NS_GPL(libie_rx_page_pool_destroy, LIBIE); diff --git a/include/linux/net/intel/libie/rx.h b/include/linux/net/intel/libie/rx.h index 87ad8f9e89c7..8eda4ac8028c 100644 --- a/include/linux/net/intel/libie/rx.h +++ b/include/linux/net/intel/libie/rx.h @@ -15,8 +15,10 @@ /* Space reserved in front of each frame */ #define LIBIE_SKB_HEADROOM (NET_SKB_PAD + NET_IP_ALIGN) +#define LIBIE_XDP_HEADROOM (ALIGN(XDP_PACKET_HEADROOM, NET_SKB_PAD) + \ + NET_IP_ALIGN) /* Maximum headroom to calculate max MTU below */ -#define LIBIE_MAX_HEADROOM LIBIE_SKB_HEADROOM +#define LIBIE_MAX_HEADROOM LIBIE_XDP_HEADROOM /* Link layer / L2 overhead: Ethernet, 2 VLAN tags (C + S), FCS */ #define LIBIE_RX_LL_LEN (ETH_HLEN + 2 * VLAN_HLEN + ETH_FCS_LEN) /* Maximum supported L2-L4 header length */ @@ -87,6 +89,7 @@ enum libie_rx_buf_type { * @rx_buf_len: HW-writeable length per each buffer * @type: type of the buffers this queue has * @hsplit: flag whether header split is enabled + * @xdp: flag indicating whether XDP is enabled */ struct libie_buf_queue { struct page_pool *pp; @@ -100,6 +103,7 @@ struct libie_buf_queue { enum libie_rx_buf_type type:2; bool hsplit:1; + bool xdp:1; }; int libie_rx_page_pool_create(struct libie_buf_queue *bq, -- 2.43.0