From patchwork Sat Dec 23 02:55:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Lobakin X-Patchwork-Id: 182893 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1462421dyi; Fri, 22 Dec 2023 19:08:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaCfGDZfI+qjByrPgpLHScqsW1MaHZFOqEBbgnQYFxhvFSBodQborswdIMyMdmvqimmx1N X-Received: by 2002:a05:6808:23cf:b0:3bb:9673:4edd with SMTP id bq15-20020a05680823cf00b003bb96734eddmr629967oib.50.1703300896369; Fri, 22 Dec 2023 19:08:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703300896; cv=none; d=google.com; s=arc-20160816; b=NtztFgIu4s4tdIND+mB+PA7m7LDpGmFZgzPwWc0/0H1ZLBNgNz8EoDPpLG78qTuvdj gq9vXbruXWwVwsyVzhOmMv0+0FAEhFCFDnXxUThJ7pfGv0Yij83gEjm4stK6RY7dg2YP ahWcmwz6XyaZXoBnk9ZmRbe/yAOIeJgOoCc/vopip/Wt/8hrONlqpAeNP10QZCHv8unV BrRcG36iXQJjFInzB+0Ej8usXzuG5TTK+Sk6hnAXCBOOOVnmjTYpc6HjZ3Pfe1l+7X9I smOYJufoKmEzmBk2gDpeq6dgUxMbJlFPH/RpqX20i4pTzwf0sJMRYgR8XGMkk9RJX1iK Egbg== 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=eOc4ws114/3ovN048yP45G2yo363lXTzug+TpLuPtdM=; fh=J3H3jkZRTdH/CD0R7uXO8r43FYFiJ1FqB2ouoqeBxmQ=; b=IP3ijtjcmutBTBQtdvBIz9Eupi2aGZHuppA1ZFpWswdb1Kiv2GMUzq/JjrWLMf3LBj f1JAopM9xWgt2fAuYiZoJMfDNpNUalCuBoZoeYPytcImyNFzF/rS6/AcZbEahhMYMXpM rsEdGvl5iUCpmWxJQ105pAwBfC6+V5Q/xI0hHqKA/u8UP47gQWSgamqdRtppLCJZUE4Z y3A8F3kO4TsZW9gSOsBNVhWeMvSRfadECXF/spV2z2lZmeT90cLU3C2FDtEhkaHE6kV2 bMbyDCFGa+EEQCHmo+1nmvjnq3IxJW9C4+HphX4ST9r4KtvyK1k8kO3PG5vXjOs5VR9P x9/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KgpMNTpM; spf=pass (google.com: domain of linux-kernel+bounces-10241-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10241-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id cb9-20020a056a02070900b005cd8fa82040si535442pgb.614.2023.12.22.19.08.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 19:08:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-10241-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=KgpMNTpM; spf=pass (google.com: domain of linux-kernel+bounces-10241-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-10241-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 36E08B22BAC for ; Sat, 23 Dec 2023 03:07:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ECD3A39FCC; Sat, 23 Dec 2023 02:59:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="KgpMNTpM" 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 E2AC2381D9; Sat, 23 Dec 2023 02:59:41 +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=1703300381; x=1734836381; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vBLq+bSc90hU1HHgtTujEszVAfYomJgRRmZIp5oafNw=; b=KgpMNTpMHEveGBfy/CV+TPZH3CG5dMunsdBMtmT+eLHkOU1DEGDqparU 4Bt/dxr9FdhIUwOowWK9VcqVmHtiLbHCTqCrqyOUBbcYhy9zC8hCcWUps X3Zn4l1ElI8vsRM7KSvuQqpnLQ/slNkXc8+byLRaYbPLOrmxKIhhPI4gv y3b7Kem20FJT5AO9GO1JtT3zaq/0IqTrJDYGjkXFd3jygyfX4LzUjn6cZ Ij2x2Bs0hSZ7vANq4L7/LqsfvPQASEn1y6EWPh1W8jvCdSVRj6gz4xFt/ IksZy8iAynQg/1PJlcr2EQMwo/7+XbYC3weTTbnTF+hHfiODW3Y2Hf/Ig Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10932"; a="386611034" X-IronPort-AV: E=Sophos;i="6.04,298,1695711600"; d="scan'208";a="386611034" 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:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,298,1695711600"; d="scan'208";a="25537631" Received: from newjersey.igk.intel.com ([10.102.20.203]) by orviesa001.jf.intel.com with ESMTP; 22 Dec 2023 18:59:38 -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 25/34] idpf: add support for .ndo_xdp_xmit() Date: Sat, 23 Dec 2023 03:55:45 +0100 Message-ID: <20231223025554.2316836-26-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786040441104082341 X-GMAIL-MSGID: 1786040441104082341 Use libie XDP infra to implement .ndo_xdp_xmit() in idpf. The Tx callbacks are reused from XDP_TX code. XDP redirect target feature is set/cleared depending on the XDP prog presence, as for now we still don't allocate XDP Tx queues when there's no program. Signed-off-by: Alexander Lobakin --- drivers/net/ethernet/intel/idpf/idpf_lib.c | 1 + drivers/net/ethernet/intel/idpf/idpf_xdp.c | 34 ++++++++++++++++++++++ drivers/net/ethernet/intel/idpf/idpf_xdp.h | 2 ++ 3 files changed, 37 insertions(+) diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c b/drivers/net/ethernet/intel/idpf/idpf_lib.c index a19704c4c421..7c3d45f84e1b 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_lib.c +++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c @@ -2451,6 +2451,7 @@ static const struct net_device_ops idpf_netdev_ops_splitq = { .ndo_set_features = idpf_set_features, .ndo_tx_timeout = idpf_tx_timeout, .ndo_bpf = idpf_xdp, + .ndo_xdp_xmit = idpf_xdp_xmit, }; static const struct net_device_ops idpf_netdev_ops_singleq = { diff --git a/drivers/net/ethernet/intel/idpf/idpf_xdp.c b/drivers/net/ethernet/intel/idpf/idpf_xdp.c index b9952ebda4fb..b4f096186302 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_xdp.c +++ b/drivers/net/ethernet/intel/idpf/idpf_xdp.c @@ -313,6 +313,35 @@ bool __idpf_xdp_run_prog(struct xdp_buff *xdp, struct libie_xdp_tx_bulk *bq) return libie_xdp_run_prog(xdp, bq, idpf_xdp_tx_flush_bulk); } +/** + * idpf_xdp_xmit - submit packets to xdp ring for transmission + * @dev: netdev + * @n: number of xdp frames to be transmitted + * @frames: xdp frames to be transmitted + * @flags: transmit flags + * + * Returns number of frames successfully sent. Frames that fail are + * free'ed via XDP return API. + * For error cases, a negative errno code is returned and no-frames + * are transmitted (caller must handle freeing frames). + */ +int idpf_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames, + u32 flags) +{ + struct idpf_netdev_priv *np = netdev_priv(dev); + struct idpf_vport *vport = np->vport; + + if (unlikely(!netif_carrier_ok(dev) || !vport->link_up)) + return -ENETDOWN; + if (unlikely(!idpf_xdp_is_prog_ena(vport))) + return -ENXIO; + + return libie_xdp_xmit_do_bulk(dev, n, frames, flags, + &vport->txqs[vport->xdp_txq_offset], + vport->num_xdp_txq, idpf_xdp_tx_prep, + idpf_xdp_tx_xmit, idpf_xdp_tx_finalize); +} + /** * idpf_xdp_reconfig_queues - reconfigure queues after the XDP setup * @vport: vport to load or unload XDP for @@ -410,6 +439,11 @@ idpf_xdp_setup_prog(struct idpf_vport *vport, struct bpf_prog *prog, return err; } + if (prog) + xdp_features_set_redirect_target(vport->netdev, false); + else + xdp_features_clear_redirect_target(vport->netdev); + if (vport_is_up) { err = idpf_vport_open(vport, false); if (err) { diff --git a/drivers/net/ethernet/intel/idpf/idpf_xdp.h b/drivers/net/ethernet/intel/idpf/idpf_xdp.h index 1f299c268ca5..f1444482f69d 100644 --- a/drivers/net/ethernet/intel/idpf/idpf_xdp.h +++ b/drivers/net/ethernet/intel/idpf/idpf_xdp.h @@ -31,6 +31,8 @@ static inline void idpf_xdp_finalize_rx(struct libie_xdp_tx_bulk *bq) __idpf_xdp_finalize_rx(bq); } +int idpf_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames, + u32 flags); int idpf_xdp(struct net_device *netdev, struct netdev_bpf *xdp); #endif /* _IDPF_XDP_H_ */