From nobody Sat Oct 4 17:29:47 2025 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 599842F99BF; Wed, 13 Aug 2025 22:13:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123214; cv=none; b=Ul32e9p6Wi8YGbiDooeNRSotJTsiZuMoY4ZQFmOAN//M7XfSuzaD+wLZfRd1F50yxFzXybi+h+8um5oDxnAKRffupbrmzNdPdepDN+Z8Fphs9y7JevFY394QLPZrRWavhWBYdij9b/voCmP+zXr8+ygvqTYgohzIp0aIIuIXmg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123214; c=relaxed/simple; bh=diCsuI9hWsPC473mGUixtnjkEdOeHykLqJbaVtFnBMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z+vzj7R+4yynvkGHQqMi8+lGuAdoewyoh1HAbIzmz3G5QtdR35fFu0ZDtbJ0NMDoy7M4UicssZ9lzfqONA4frB8fj7Zo/sDrZM9R9tLFx5ydJQZS+yGC9NgQVyHh60oG83+/sSF+KCuJE4J+ObTKiNQZqudGXIH29o9do/sKANw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KFO+Zd4d; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KFO+Zd4d" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3b9e414252dso156780f8f.3; Wed, 13 Aug 2025 15:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755123210; x=1755728010; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FzffaNbuaREaEmpag6LLHmQceARFZNpQ4mFVUhH7Bw4=; b=KFO+Zd4dqo4PzYwUIeke/EJ1FtC9L5TMQjbzF4tPWNJcfa6g/mAJSw+9QA+smPHJ4n gve2VaL+IrHLORtq/4GUIyU1+1FVTA+TBEzS9NvLOVfQYKyNbPyrG0Ox0oAW/vwj44cM MywInX7L+XI3RNCPwyu5eGC7st6fQqLLXvC/9jXF37X7a60WxKb+ElT1x1ACySInJpTO d2L7qltZtrghyaS6UaynbqXeY9ji3k6OINrkQmRb1OnEnLI0oH0hqq8/Pa820mZrtzWb LOcBIwpkfMvAxwULWccg15SQj7SON0jgYZOGeHF6aISppEFBvZHbnAoUb/fEapowfmoB ZoHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755123210; x=1755728010; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FzffaNbuaREaEmpag6LLHmQceARFZNpQ4mFVUhH7Bw4=; b=Adfmk4whojDFm/wUpZOgA/QnlL83XQLhUak7yIOPtN88hxayRhay8aB9VpJ7cVl9BC 3HT0ffq6pNtZlvRw211gmzLoW0UmKbCMW5m9k+B+lnnGoChaN7JvC/Vq7S/0Dj1z/tHT MZyzJB3hBmxDWO82WrctFniYeOD36n0ACKgQLNE94WI1xHG8WNo7SZ4WdulZSu5cku0h XhM4sAGE5vYeEWEVNthhFz1WDY468DQPL05Ap1MbS4w0zi5+mBOsHvx0JeARi/MJb85Z XSbLtDV1rrMXYeVTX/WGHAckmeDbFAI5OX1OyooYiUDMvEh81ouCQF/y8qUfhhuHt23K wBlg== X-Forwarded-Encrypted: i=1; AJvYcCVfkl2gJRWqJfrbNUHQTTuBRdHw+oNJE7/Kqe11UDy4blIC9fjh8z5N4Db8dKz/lTfSj07RmMqDBuZ31pXx@vger.kernel.org, AJvYcCWMbjczRo2O8ziP/xHWLxHM4zjRhYNPPpqisGs1soYF0iOWh0sftZSv6uKW+3agLnaysGuwgOCLvASk@vger.kernel.org, AJvYcCX/R/c6zDfIOisTFAimOj+WbfOgQN023mEONmkVKy9XDrs1L0oy/5ZLKoYwu6Py9y7yG/4=@vger.kernel.org X-Gm-Message-State: AOJu0YzlZw/VO+eIQbsSBWgx4P/b0Lf6ZCEM8HGPYaDbnDgcd3/h9DjV gCubT86vNPgXmmykV1y+M/AHtuRKkP9R66lt4cIXlMowCecPuJFeh1+T82G6noHZ X-Gm-Gg: ASbGnctxZAAS0pOZx1BBV0AylyK9KVSkiZM222T1pPH6CEQrg4GVzR9EXj3PIn7Q2aZ lsS/VVdTY6DFemDm+LqDhr9gTvUpfRzke2/8vl9j2gH9opKqG3vpmx9zl3J9NT2zNXo9JgGBp1L mOW/Ir28IYKyywFMG7W364TcyiruIMTLYbt/1TiK7VopNpma+Gtt66GujyFwQe0eTa4FUUjno6n EUNEtulZtkqZj9+7mxaK/ZzueM2WuMk30BxhX/0b7FrugEQOjKjSB6yRkE++9yuBvww2PwlMY0r IpjCGtkhk23N5pkhL3+lt6il8lxCULhCp+zEoYgzPFz/sb5rkF6fZebEH3xWzhKc9sOLGWiQSIX P1aRVtK2wqVW5Rm+TSFQwzuPgQYeGYhM= X-Google-Smtp-Source: AGHT+IEHzjwGMcWiLJKH/d0/fbpHRcxeewf4XshcjjykG8yqXkkKfQIl3An9ZLfRicEOU/R8icUetQ== X-Received: by 2002:a5d:5f8f:0:b0:3b7:9bfe:4f64 with SMTP id ffacd0b85a97d-3b9fc382c99mr634922f8f.54.1755123209902; Wed, 13 Aug 2025 15:13:29 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:44::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b91330bfa3sm6616519f8f.29.2025.08.13.15.13.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 15:13:29 -0700 (PDT) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: aleksander.lobakin@intel.com, alexanderduyck@fb.com, andrew+netdev@lunn.ch, ast@kernel.org, bpf@vger.kernel.org, corbet@lwn.net, daniel@iogearbox.net, davem@davemloft.net, edumazet@google.com, hawk@kernel.org, horms@kernel.org, john.fastabend@gmail.com, kernel-team@meta.com, kuba@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mohsin.bashr@gmail.com, pabeni@redhat.com, sdf@fomichev.me, vadim.fedorenko@linux.dev Subject: [PATCH net-next V4 1/9] eth: fbnic: Add support for HDS configuration Date: Wed, 13 Aug 2025 15:13:11 -0700 Message-ID: <20250813221319.3367670-2-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250813221319.3367670-1-mohsin.bashr@gmail.com> References: <20250813221319.3367670-1-mohsin.bashr@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for configuring the header data split threshold. For fbnic, the tcp data split support is enabled all the time. Fbnic supports a maximum buffer size of 4KB. However, the reservation for the headroom, tailroom, and padding reduce the max header size accordingly. ethtool_hds -g eth0 Ring parameters for eth0: Pre-set maximums: ... HDS thresh: 3584 Current hardware settings: ... HDS thresh: 1536 Verify hds tests in ksft-net-drv are passing ksft-net-drv]# ./drivers/net/hds.py TAP version 13 1..13 ok 1 hds.get_hds ok 2 hds.get_hds_thresh ok 3 hds.set_hds_disable # SKIP disabling of HDS not supported by ... ... ... ok 12 hds.ioctl_set_xdp ok 13 hds.ioctl_enabled_set_xdp \# Totals: pass:12 fail:0 xfail:0 xpass:0 skip:1 error:0 Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 21 ++++++++++++++++--- .../net/ethernet/meta/fbnic/fbnic_netdev.c | 4 ++++ .../net/ethernet/meta/fbnic/fbnic_netdev.h | 2 ++ drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 17 +++++++++++---- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 7 ++++++- 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/= ethernet/meta/fbnic/fbnic_ethtool.c index dc7ba8d5fc43..8ae2ecbae06c 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c @@ -2,6 +2,7 @@ /* Copyright (c) Meta Platforms, Inc. and affiliates. */ =20 #include +#include #include #include #include @@ -160,6 +161,7 @@ static void fbnic_clone_swap_cfg(struct fbnic_net *orig, swap(clone->num_rx_queues, orig->num_rx_queues); swap(clone->num_tx_queues, orig->num_tx_queues); swap(clone->num_napi, orig->num_napi); + swap(clone->hds_thresh, orig->hds_thresh); } =20 static void fbnic_aggregate_vector_counters(struct fbnic_net *fbn, @@ -277,15 +279,21 @@ fbnic_get_ringparam(struct net_device *netdev, struct= ethtool_ringparam *ring, ring->rx_mini_pending =3D fbn->hpq_size; ring->rx_jumbo_pending =3D fbn->ppq_size; ring->tx_pending =3D fbn->txq_size; + + kernel_ring->tcp_data_split =3D ETHTOOL_TCP_DATA_SPLIT_ENABLED; + kernel_ring->hds_thresh_max =3D FBNIC_HDS_THRESH_MAX; + kernel_ring->hds_thresh =3D fbn->hds_thresh; } =20 static void fbnic_set_rings(struct fbnic_net *fbn, - struct ethtool_ringparam *ring) + struct ethtool_ringparam *ring, + struct kernel_ethtool_ringparam *kernel_ring) { fbn->rcq_size =3D ring->rx_pending; fbn->hpq_size =3D ring->rx_mini_pending; fbn->ppq_size =3D ring->rx_jumbo_pending; fbn->txq_size =3D ring->tx_pending; + fbn->hds_thresh =3D kernel_ring->hds_thresh; } =20 static int @@ -316,8 +324,13 @@ fbnic_set_ringparam(struct net_device *netdev, struct = ethtool_ringparam *ring, return -EINVAL; } =20 + if (kernel_ring->tcp_data_split =3D=3D ETHTOOL_TCP_DATA_SPLIT_DISABLED) { + NL_SET_ERR_MSG_MOD(extack, "Cannot disable TCP data split"); + return -EINVAL; + } + if (!netif_running(netdev)) { - fbnic_set_rings(fbn, ring); + fbnic_set_rings(fbn, ring, kernel_ring); return 0; } =20 @@ -325,7 +338,7 @@ fbnic_set_ringparam(struct net_device *netdev, struct e= thtool_ringparam *ring, if (!clone) return -ENOMEM; =20 - fbnic_set_rings(clone, ring); + fbnic_set_rings(clone, ring, kernel_ring); =20 err =3D fbnic_alloc_napi_vectors(clone); if (err) @@ -1678,6 +1691,8 @@ fbnic_get_rmon_stats(struct net_device *netdev, static const struct ethtool_ops fbnic_ethtool_ops =3D { .supported_coalesce_params =3D ETHTOOL_COALESCE_USECS | ETHTOOL_COALESCE_RX_MAX_FRAMES, + .supported_ring_params =3D ETHTOOL_RING_USE_TCP_DATA_SPLIT | + ETHTOOL_RING_USE_HDS_THRS, .rxfh_max_num_contexts =3D FBNIC_RPC_RSS_TBL_COUNT, .get_drvinfo =3D fbnic_get_drvinfo, .get_regs_len =3D fbnic_get_regs_len, diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c b/drivers/net/e= thernet/meta/fbnic/fbnic_netdev.c index e67e99487a27..a7eb7a367b98 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c @@ -695,6 +695,10 @@ struct net_device *fbnic_netdev_alloc(struct fbnic_dev= *fbd) fbn->rx_usecs =3D FBNIC_RX_USECS_DEFAULT; fbn->rx_max_frames =3D FBNIC_RX_FRAMES_DEFAULT; =20 + /* Initialize the hds_thresh */ + netdev->cfg->hds_thresh =3D FBNIC_HDS_THRESH_DEFAULT; + fbn->hds_thresh =3D FBNIC_HDS_THRESH_DEFAULT; + default_queues =3D netif_get_num_default_rss_queues(); if (default_queues > fbd->max_num_queues) default_queues =3D fbd->max_num_queues; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.h b/drivers/net/e= thernet/meta/fbnic/fbnic_netdev.h index 86576ae04262..04c5c7ed6c3a 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.h @@ -31,6 +31,8 @@ struct fbnic_net { u32 ppq_size; u32 rcq_size; =20 + u32 hds_thresh; + u16 rx_usecs; u16 tx_usecs; =20 diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.c index f9543d03485f..7c69f6381d9e 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -2232,13 +2232,22 @@ static void fbnic_enable_rcq(struct fbnic_napi_vect= or *nv, { struct fbnic_net *fbn =3D netdev_priv(nv->napi.dev); u32 log_size =3D fls(rcq->size_mask); - u32 rcq_ctl; + u32 hds_thresh =3D fbn->hds_thresh; + u32 rcq_ctl =3D 0; =20 fbnic_config_drop_mode_rcq(nv, rcq); =20 - rcq_ctl =3D FIELD_PREP(FBNIC_QUEUE_RDE_CTL1_PADLEN_MASK, FBNIC_RX_PAD) | - FIELD_PREP(FBNIC_QUEUE_RDE_CTL1_MAX_HDR_MASK, - FBNIC_RX_MAX_HDR) | + /* Force lower bound on MAX_HEADER_BYTES. Below this, all frames should + * be split at L4. It would also result in the frames being split at + * L2/L3 depending on the frame size. + */ + if (fbn->hds_thresh < FBNIC_HDR_BYTES_MIN) { + rcq_ctl =3D FBNIC_QUEUE_RDE_CTL0_EN_HDR_SPLIT; + hds_thresh =3D FBNIC_HDR_BYTES_MIN; + } + + rcq_ctl |=3D FIELD_PREP(FBNIC_QUEUE_RDE_CTL1_PADLEN_MASK, FBNIC_RX_PAD) | + FIELD_PREP(FBNIC_QUEUE_RDE_CTL1_MAX_HDR_MASK, hds_thresh) | FIELD_PREP(FBNIC_QUEUE_RDE_CTL1_PAYLD_OFF_MASK, FBNIC_RX_PAYLD_OFFSET) | FIELD_PREP(FBNIC_QUEUE_RDE_CTL1_PAYLD_PG_CL_MASK, diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.h index 34693596e5eb..7d27712d5462 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h @@ -53,7 +53,6 @@ struct fbnic_net; #define FBNIC_RX_HROOM \ (ALIGN(FBNIC_RX_TROOM + NET_SKB_PAD, 128) - FBNIC_RX_TROOM) #define FBNIC_RX_PAD 0 -#define FBNIC_RX_MAX_HDR (1536 - FBNIC_RX_PAD) #define FBNIC_RX_PAYLD_OFFSET 0 #define FBNIC_RX_PAYLD_PG_CL 0 =20 @@ -61,6 +60,12 @@ struct fbnic_net; #define FBNIC_RING_F_CTX BIT(1) #define FBNIC_RING_F_STATS BIT(2) /* Ring's stats may be used */ =20 +#define FBNIC_HDS_THRESH_MAX \ + (4096 - FBNIC_RX_HROOM - FBNIC_RX_TROOM - FBNIC_RX_PAD) +#define FBNIC_HDS_THRESH_DEFAULT \ + (1536 - FBNIC_RX_PAD) +#define FBNIC_HDR_BYTES_MIN 128 + struct fbnic_pkt_buff { struct xdp_buff buff; ktime_t hwtstamp; --=20 2.47.3 From nobody Sat Oct 4 17:29:47 2025 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C846F302CD6; Wed, 13 Aug 2025 22:13:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123216; cv=none; b=Yrt4/vZsR3wAAfqtnm8omuqNheQvQ0rcMeOmbHHpyT1YDnIO7nBWf5v7D04H0o7ZS1qMaMewoOfkFdaq+vxkV0PqMRfLxRVyWCqI6/CL3y2gFH+hb4Xa8lLetG3FJym9AvybInougVXQAIMf7mIJYWya8EGSnieLkX3D73uouAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123216; c=relaxed/simple; bh=8nMCVzoU/BearI+JQrhJPJzWNf0Lg3T4RMINzhVG8vg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MqypEpMDVgaidseJkTSQPWKeXa7IZyVoSWdAtK+fh8wlBd9IFiwyQilQlNnYL5Y6p1lp/c1wgZLD/HFhoWf3rPl7Nt78doha6x3CTHp9M9HWAtLFcDfqa2Y49Qig5cWIQ9EhjuXk3rNWh5GXcpRLs2/QT832uKj+L8rhMKHzwRQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FPmdyhQp; arc=none smtp.client-ip=209.85.221.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FPmdyhQp" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-3b9d41bea3cso250669f8f.0; Wed, 13 Aug 2025 15:13:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755123213; x=1755728013; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=DYPaKl7yRBI57VFUozUf+op94ciBF1/TM6xrDSp5DaE=; b=FPmdyhQpfb3oNHOwncD/urLJX/dI+wHgDjDwbzNQJPn5UL/C3uRIO/+BQXs24OMh0v B0lANMekeuvgZkHmoZ2jV+yO48r3bRA/tKqGfXoU6uc3WJe3+yidpC6nQlV7GGgvYiTR 1GMh/RWlbdCOLnuXPYaO2Rjft64Mr0rmc8RakqjVEIACSs1OoaYcBt839OlRglbt2xpC UxNf5h4vIbvKqGUGlvbhP9CeXHbvIGwblit88CCBIDLfkyJ/6No+744qHjun5PS7SoEp PVv7+xFUdT40U4PocRVLfQTC8H2f8WKTQFP/2x0HO2I3mIaTKG9zpH7U8zwOh/El0tOy C31w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755123213; x=1755728013; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DYPaKl7yRBI57VFUozUf+op94ciBF1/TM6xrDSp5DaE=; b=A23XQ382lbq7M5XCG35C+2Lfvyz6QFq74ogJRMv+h6CsGNH7H/TIuAW2GLllJZO1Zf zH2UMlqRiXG6mcL/bcMNb1N9YA2hwHJ9GadRd4v7M4diXuGd4f6Lo/lxZ8150Yet7guW MoP2hX9uFQHd9vBYPzL4gGIu1rjpX8a2yucVbzudlJ+AD+wfC5H1bTZL2gcSV6NU7ZlD XLqK1LqAgmnHE6c/SqoaNb6iJ2a1/YBMCd7Auvr8zRv0LP7D0oD89P5us041ASItYoEV Xxs966OOqxlyuZyMe5arxJ1pBVTBmC3i9dxGwLPz+N+S2jTV49ld/JmQRfELEDQX7coe Yo0Q== X-Forwarded-Encrypted: i=1; AJvYcCUXvDJHG+xiSjWsnfo9AnebnZi8OahJMcoClHgfNtzzztLCGN0h2DO5OHHS00mFES/s5pvdVJc+gunQ1LqN@vger.kernel.org, AJvYcCWWNXL4T3JKTeU0wZoR0zKRPvWbMj1Mk9p6Q3lN+yjFDnXX7RrSz4JZ3KpV8WpQOjd4xKQeHtDQ8Myr@vger.kernel.org, AJvYcCWftTgmz/H18wQfNl6NGVxQcpKmAtJEJadWDFIG6yfTVUMKcDvFeJYBF2zyg77lq8PkrFs=@vger.kernel.org X-Gm-Message-State: AOJu0Yxax/fMo0G4iGygGhvpXSx5GgPfX09h1SABvOBrxAI8yVhaOgPN nZBMRB3pcOfjW+WB3W07hBTGc/m96ge8YiFhhJQ93DUB3Rehu9zXvA4yFgoBcZYm X-Gm-Gg: ASbGncuhYTLdPscNmVR5NhsUJEsvtKyudKSpG7wXVyO0bV7KkYyvvhcz8Ff+Q6K76c/ 0zwW1yyZVpXmUO+5DdA9Bk/uGE5aeCjnroFLf8CkGR+/ez9u7c3SNl8A9VgMJQW8hLlgNCxg2Yr oAYUMFXmn/Z/5H8e6/9w3OWzs6HRdmnuOARlzYKTli4Y6CwKYArS5iG83lpWPdfK4/jnhezjILd OdUf1T+sz+K1q4LrAHgc0mZAYma4+4V30hV9xe61CuSSknm1llCzK5YojjbE+HpCAx+EdW3Xt1g VsngW9hvVLCWnthc6UAZnn58n/jwzydalBGdL4JHIdXeYYuWPx7avj5ptH2yr+s/HBz6zUGDFsp A7Kt61yzzf6ZAz6l4 X-Google-Smtp-Source: AGHT+IEtNr9tIyfdS4Z5+3OPGbZFCCW4AxkgVbCTYKpGBwPpPyvIp8dl3iL1QeEGzxZy5ObvSW19GQ== X-Received: by 2002:a05:6000:2505:b0:3b7:8880:181a with SMTP id ffacd0b85a97d-3b9e41793e2mr819501f8f.13.1755123212601; Wed, 13 Aug 2025 15:13:32 -0700 (PDT) Received: from localhost ([2a03:2880:31ff::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b911469bffsm7837565f8f.36.2025.08.13.15.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 15:13:31 -0700 (PDT) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: aleksander.lobakin@intel.com, alexanderduyck@fb.com, andrew+netdev@lunn.ch, ast@kernel.org, bpf@vger.kernel.org, corbet@lwn.net, daniel@iogearbox.net, davem@davemloft.net, edumazet@google.com, hawk@kernel.org, horms@kernel.org, john.fastabend@gmail.com, kernel-team@meta.com, kuba@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mohsin.bashr@gmail.com, pabeni@redhat.com, sdf@fomichev.me, vadim.fedorenko@linux.dev Subject: [PATCH net-next V4 2/9] eth: fbnic: Update Headroom Date: Wed, 13 Aug 2025 15:13:12 -0700 Message-ID: <20250813221319.3367670-3-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250813221319.3367670-1-mohsin.bashr@gmail.com> References: <20250813221319.3367670-1-mohsin.bashr@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fbnic currently reserves a minimum of 64B headroom, but this is insufficient for inserting additional headers (e.g., IPV6) via XDP, as only 24 bytes are available for adjustment. To address this limitation, increase the headroom to a larger value while ensuring better page use. Although the resulting headroom (192B) is smaller than the recommended value (256B), forcing the headroom to 256B would require aligning to 256B (as opposed to the current 128B), which can push the max headroom to 511B. Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.h index 7d27712d5462..66c84375e299 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h @@ -50,8 +50,9 @@ struct fbnic_net; =20 #define FBNIC_RX_TROOM \ SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) +#define FBNIC_RX_HROOM_PAD 128 #define FBNIC_RX_HROOM \ - (ALIGN(FBNIC_RX_TROOM + NET_SKB_PAD, 128) - FBNIC_RX_TROOM) + (ALIGN(FBNIC_RX_TROOM + FBNIC_RX_HROOM_PAD, 128) - FBNIC_RX_TROOM) #define FBNIC_RX_PAD 0 #define FBNIC_RX_PAYLD_OFFSET 0 #define FBNIC_RX_PAYLD_PG_CL 0 --=20 2.47.3 From nobody Sat Oct 4 17:29:47 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 841E730AAB8; Wed, 13 Aug 2025 22:13:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123219; cv=none; b=OnjTbAFy7LvxV4oI+/3lKodL5ueLdWL9SpgGMbw7r0EP15fK57FSt9d//d8IUGbFcVrMgWZXwb6TlqY4vn8nLI6qSpe6siAVGK588Tz75HcEpAYETfahGrrAUjRt4SDwXm6ZIW4ZJzgKdRm8+RbLv9Ffh9wF55pxhml5PnZONcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123219; c=relaxed/simple; bh=14Rs9zHg4QyJJlrXCDIaH33G+iRF67OxQsjU8vdMJdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OHgXqS9XYlXvcTpFJh83H+kgTHb2HJWR9ymtsqcVqJ7QZ0Wx+H7jMTqq5iCqM+oifY2vFf4C4dunm1Tlwr9HVPvDMBvVe3jI4/9wVyBAicHd1wwSVpslxwzefTUonzNiMHV85DAufHeHkXhGwZ2oBzQI0vLVZKJx3tQW4kPfdJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UDAk8/QZ; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UDAk8/QZ" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3b9a342e8ffso240751f8f.0; Wed, 13 Aug 2025 15:13:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755123215; x=1755728015; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HXGxGfMZImq48xpQEp7KdaMDkTKOy1FyiWgUccTmK/M=; b=UDAk8/QZh5eYXW6i8xtj5ZXCj1MutN6Fmk9oxx3tpycMbS3e9O4iqnaleVZSS3uA61 13MMm4QzzVna3ZkJNL4z0QCax3YXqMLLXbavH6URdiPnueXKFkaNwkrbg1PLm1YSSyvp Wh+cBgn/Q9ndJS6yGQu6k4MCqeI7ZnUJACJ4hm9qVTK9B4cMCjR2cSJjDXFCjgxJLqjl w1m0T6rd+7z518xnJ+lX/rM4BuioMGN5wKHeDQKLyEW6oMDn28jdIn5eNnYxh9Q2zcWl oL6sJ6B805lwE2Vq3Osv5WuGSVbRJmIJpY++4ywmVcILk3iVlHaDQn6qlu60sNK0LB3N l4rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755123215; x=1755728015; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HXGxGfMZImq48xpQEp7KdaMDkTKOy1FyiWgUccTmK/M=; b=aABGpVtDRxoQx0PgMZ8f5ksQrsIz4huEgc9uUXtNct90OdvEIJcyHirOt05c8zvFiL h6O4zsEr3nQQcf1R4OiI1cjfVlEk2vHpD406zk/sBldX//zAp0SaNY0l5JUdMBbnEh7W plsAmNu8R4zAJVn72utYQIcSAvH2S89QFFset/bDnQHR9xDEvZOP52GcfMcjCu7/2Bbw yEffwvHL+aZPsiBUjP2gdE11hfvBTxJ90PNaQ6yWeClGh2KYTMkQVcbr2f48kgSNyz5y QVe4yrJUJgOpfoEMhsy7Wuq3oZ7O7OYjkQLb0eEvwMvEnGoupzhfJLFGTxjlKDmSe8XP 6c6Q== X-Forwarded-Encrypted: i=1; AJvYcCVoBOv4RpVVDeiLO7khgp6vK0suqPc/LAXovfzcCkYm1/EG9Bvz46PzWiQSYpFnTY1n9Vw=@vger.kernel.org, AJvYcCXN/N/HdGC8S4XPXQJU0S13nBPs8j4NfnPtTpkIzwDy3vdOwYF3uJQuf3XNf36HCp3+T/95KoBgQu25i54M@vger.kernel.org, AJvYcCXZyzSIZ3ePt1x7azl1FRPry1t2TiU/G0MNJbPSHUtBlfo5jocFW9QTwNCvtY/p7Y0+70swuu3BSDfQ@vger.kernel.org X-Gm-Message-State: AOJu0YxZ81aB5fHNbJhn8UI6MiQKuEKcMQ2QD1bcIbOna2UKT6+TUbeD 5Ioqb1xQAeTEw48obIskiSZz7XEtQ2IRMHhsCa6pRXaUmYkad3Z0/Thh4aiFgTK5 X-Gm-Gg: ASbGncu+27dlmDTmMioLCrxhAbyBp+WpwMhyFNeBO5nR88cDzRcbTtJmm7ND0YS82KG /OMEDNSI/rPTNFbP8X3hWN1Aeb1OYABlYd5BdRwe2YgMdagkW2zNGDSzyOCfwA0m/vz4fmfNP/6 el48I+Rtqza1Uxz6gI6kbgMqYRuxdV+uPTC5GE/VJd7xIX46ZH5j1Q+BMifzKNttHEgxyZvmwdF 2crtoD3/dVzS6OmqekSv3BN+G5DkeSG+aNvXOMhpSzi8+WU6Us1/dj+rKDWS6bEyxGkl4e5cOzo n1ovyB/xrlPKvwFJ+tWRjMxVG2ZvjX63V00M+RJsvs8SrfAsO80OZ/+2TWuZ9DbC0P+eMqxa5tG Sw3ANxgQb5mHoYyAQVV97wNzD X-Google-Smtp-Source: AGHT+IFVKxwpknkJMwJp39+E2cpeTEbHUO63EDnfXbOJaqCPW5YMugfnoQbe1n9vLbpVGJlj05LG+Q== X-Received: by 2002:a05:6000:26c3:b0:3b8:d25e:f480 with SMTP id ffacd0b85a97d-3ba50d6364dmr167421f8f.29.1755123215425; Wed, 13 Aug 2025 15:13:35 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:9::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c3ac158sm49900361f8f.4.2025.08.13.15.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 15:13:34 -0700 (PDT) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: aleksander.lobakin@intel.com, alexanderduyck@fb.com, andrew+netdev@lunn.ch, ast@kernel.org, bpf@vger.kernel.org, corbet@lwn.net, daniel@iogearbox.net, davem@davemloft.net, edumazet@google.com, hawk@kernel.org, horms@kernel.org, john.fastabend@gmail.com, kernel-team@meta.com, kuba@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mohsin.bashr@gmail.com, pabeni@redhat.com, sdf@fomichev.me, vadim.fedorenko@linux.dev Subject: [PATCH net-next V4 3/9] eth: fbnic: Use shinfo to track frags state on Rx Date: Wed, 13 Aug 2025 15:13:13 -0700 Message-ID: <20250813221319.3367670-4-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250813221319.3367670-1-mohsin.bashr@gmail.com> References: <20250813221319.3367670-1-mohsin.bashr@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove local fields that track frags state and instead store this information directly in the shinfo struct. This change is necessary because the current implementation can lead to inaccuracies in certain scenarios, such as when using XDP multi-buff support. Specifically, the XDP program may update nr_frags without updating the local variables, resulting in an inconsistent state. Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 80 ++++++-------------- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 4 +- 2 files changed, 26 insertions(+), 58 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.c index 7c69f6381d9e..2adbe175ac09 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -892,9 +892,8 @@ static void fbnic_pkt_prepare(struct fbnic_napi_vector = *nv, u64 rcd, xdp_prepare_buff(&pkt->buff, hdr_start, headroom, len - FBNIC_RX_PAD, true); =20 - pkt->data_truesize =3D 0; - pkt->data_len =3D 0; - pkt->nr_frags =3D 0; + pkt->hwtstamp =3D 0; + pkt->add_frag_failed =3D false; } =20 static void fbnic_add_rx_frag(struct fbnic_napi_vector *nv, u64 rcd, @@ -905,8 +904,8 @@ static void fbnic_add_rx_frag(struct fbnic_napi_vector = *nv, u64 rcd, unsigned int pg_off =3D FIELD_GET(FBNIC_RCD_AL_BUFF_OFF_MASK, rcd); unsigned int len =3D FIELD_GET(FBNIC_RCD_AL_BUFF_LEN_MASK, rcd); struct page *page =3D fbnic_page_pool_get(&qt->sub1, pg_idx); - struct skb_shared_info *shinfo; unsigned int truesize; + bool added; =20 truesize =3D FIELD_GET(FBNIC_RCD_AL_PAGE_FIN, rcd) ? FBNIC_BD_FRAG_SIZE - pg_off : ALIGN(len, 128); @@ -918,34 +917,34 @@ static void fbnic_add_rx_frag(struct fbnic_napi_vecto= r *nv, u64 rcd, dma_sync_single_range_for_cpu(nv->dev, page_pool_get_dma_addr(page), pg_off, truesize, DMA_BIDIRECTIONAL); =20 - /* Add page to xdp shared info */ - shinfo =3D xdp_get_shared_info_from_buff(&pkt->buff); - - /* We use gso_segs to store truesize */ - pkt->data_truesize +=3D truesize; - - __skb_fill_page_desc_noacc(shinfo, pkt->nr_frags++, page, pg_off, len); - - /* Store data_len in gso_size */ - pkt->data_len +=3D len; + added =3D xdp_buff_add_frag(&pkt->buff, page_to_netmem(page), pg_off, len, + truesize); + if (unlikely(!added)) { + pkt->add_frag_failed =3D true; + netdev_err_once(nv->napi.dev, + "Failed to add fragment to xdp_buff\n"); + } } =20 static void fbnic_put_pkt_buff(struct fbnic_napi_vector *nv, struct fbnic_pkt_buff *pkt, int budget) { - struct skb_shared_info *shinfo; struct page *page; - int nr_frags; =20 if (!pkt->buff.data_hard_start) return; =20 - shinfo =3D xdp_get_shared_info_from_buff(&pkt->buff); - nr_frags =3D pkt->nr_frags; + if (xdp_buff_has_frags(&pkt->buff)) { + struct skb_shared_info *shinfo; + int nr_frags; =20 - while (nr_frags--) { - page =3D skb_frag_page(&shinfo->frags[nr_frags]); - page_pool_put_full_page(nv->page_pool, page, !!budget); + shinfo =3D xdp_get_shared_info_from_buff(&pkt->buff); + nr_frags =3D shinfo->nr_frags; + + while (nr_frags--) { + page =3D skb_frag_page(&shinfo->frags[nr_frags]); + page_pool_put_full_page(nv->page_pool, page, !!budget); + } } =20 page =3D virt_to_page(pkt->buff.data_hard_start); @@ -955,43 +954,12 @@ static void fbnic_put_pkt_buff(struct fbnic_napi_vect= or *nv, static struct sk_buff *fbnic_build_skb(struct fbnic_napi_vector *nv, struct fbnic_pkt_buff *pkt) { - unsigned int nr_frags =3D pkt->nr_frags; - struct skb_shared_info *shinfo; - unsigned int truesize; struct sk_buff *skb; =20 - truesize =3D xdp_data_hard_end(&pkt->buff) + FBNIC_RX_TROOM - - pkt->buff.data_hard_start; - - /* Build frame around buffer */ - skb =3D napi_build_skb(pkt->buff.data_hard_start, truesize); - if (unlikely(!skb)) + skb =3D xdp_build_skb_from_buff(&pkt->buff); + if (!skb) return NULL; =20 - /* Push data pointer to start of data, put tail to end of data */ - skb_reserve(skb, pkt->buff.data - pkt->buff.data_hard_start); - __skb_put(skb, pkt->buff.data_end - pkt->buff.data); - - /* Add tracking for metadata at the start of the frame */ - skb_metadata_set(skb, pkt->buff.data - pkt->buff.data_meta); - - /* Add Rx frags */ - if (nr_frags) { - /* Verify that shared info didn't move */ - shinfo =3D xdp_get_shared_info_from_buff(&pkt->buff); - WARN_ON(skb_shinfo(skb) !=3D shinfo); - - skb->truesize +=3D pkt->data_truesize; - skb->data_len +=3D pkt->data_len; - shinfo->nr_frags =3D nr_frags; - skb->len +=3D pkt->data_len; - } - - skb_mark_for_recycle(skb); - - /* Set MAC header specific fields */ - skb->protocol =3D eth_type_trans(skb, nv->napi.dev); - /* Add timestamp if present */ if (pkt->hwtstamp) skb_hwtstamps(skb)->hwtstamp =3D pkt->hwtstamp; @@ -1094,7 +1062,9 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *= nv, /* We currently ignore the action table index */ break; case FBNIC_RCD_TYPE_META: - if (likely(!fbnic_rcd_metadata_err(rcd))) + if (unlikely(pkt->add_frag_failed)) + skb =3D NULL; + else if (likely(!fbnic_rcd_metadata_err(rcd))) skb =3D fbnic_build_skb(nv, pkt); =20 /* Populate skb and invalidate XDP */ diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.h index 66c84375e299..d236152bbaaa 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h @@ -70,9 +70,7 @@ struct fbnic_net; struct fbnic_pkt_buff { struct xdp_buff buff; ktime_t hwtstamp; - u32 data_truesize; - u16 data_len; - u16 nr_frags; + bool add_frag_failed; }; =20 struct fbnic_queue_stats { --=20 2.47.3 From nobody Sat Oct 4 17:29:47 2025 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8032330E854; Wed, 13 Aug 2025 22:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123222; cv=none; b=eLHwVmifQgiIOJyyYBdI675Mt2j8mh5DNk92cqrGsumlwit9n7uHux+98pJT7deq+iQBqn1sw1xM5JJGuA+wlSrzgXLW8T2VBT3xhLTZEeb+3TszFED6MvvYGQt6EPrn4t34ITSO7fka9FI/onrRIPvNjDP+GoISA4xt5Yh9AI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123222; c=relaxed/simple; bh=C+rBWop/URPtiQRFTVupUQvND7/3bGvm87yBA5TUHBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P7d29HcgrYJhVJ4beZGv8M9Wkln/IzwIilaDkY21jYF9g9N3d0En+u73ah70a4GmkHvmJ0wuHfbhTQIFDxsJ85+svDFjNS1wxQoiMpZIgb2uYvH/28JpJ5X2o1YAk+Y4AVHAy5vIf5DlkL0zWVbqGx5NHu3jxRg4Lp3ZTMEUqas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HygGpMvx; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HygGpMvx" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-45a1b00f187so1190165e9.0; Wed, 13 Aug 2025 15:13:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755123218; x=1755728018; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5lZHQWGUeCx38FxMOkWUZ+QfdA43fkpKsDYcpuopkjg=; b=HygGpMvxY5bpkb10fv+UCyj8BRWEKZRlXvHgb9axuy4wqd/MkZySCADR/hT4UnfAI7 2wWXOS1LY9oTnGdO8jpFh+uzB2dZ/kfO+BomzTUPYtrXhXbfnqnvfyrCXA8BSJY7n7zY NWQC2Y6UoNIrilB/7KXTlEu4mXx9w1c74HHYB5Vd/jnyyH/YmXNo7fyMAJmWl1X2XfbP NhulgnXBFt9Kuguzy1fOkhPwRGSLZ3QLMX5BWy7KzmfkJ/7laYEES0pvnVkipDQddJbc f62LFmmVQa0ehjtdFCtJfOCLQbTxirRab72/obEG4b0dD8RTfc87SHjRq7oRtcBudoam 0mfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755123218; x=1755728018; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5lZHQWGUeCx38FxMOkWUZ+QfdA43fkpKsDYcpuopkjg=; b=ZjqIm9bhXrgKKvtq+afSLQGsUXluPLj/Zeh4FcqWy4DimtCrtkahzd9ZE8SOmPmGAu n7fkMrtmM6dkBZPVkzkSgYt5Q8h/g7sVHpceKDFS8hG9KhwU0Jt7VoD2xFPEnODNeyFk 9aIkAEfcAtUJxYWn0WzsmsB2LYJE3Z0MEwAEfuj5vo6bb/o4qC1GZhSFax4WCar/HVQn T6iGyd0tnujEPL5DSPkFJSdixZk8GqsXjIeDN+3gbluyTbyP84T/pdK6gsLoI1//xRqz Bvt37Uh2yBi/x8lTzZft6qB9QKHPAgXgGAYL47IhiYHEl6G8eNuSOlN5DIoG+h8O63DC xxfQ== X-Forwarded-Encrypted: i=1; AJvYcCVKzkMEw1FWSC0hdjy0Gnnk5vGh2WtWo9lkw2EhAM161GMq6nfpaecdVogj061a1WAfKAt7DVzx6gJYtSRU@vger.kernel.org, AJvYcCVh1JeGmI6ENmPHMNbeiGB0TzKWedTXvbz9jVO4YNTq4H0bV64T8g7awUF+M3C3Pj9A11aP0s0jJqoZ@vger.kernel.org, AJvYcCXOVWg5/k0NBlzDvnO7foeUiavaJfBk5TpG16zoLpk78QunT/V8jPEfYybFIfA22p2wFGU=@vger.kernel.org X-Gm-Message-State: AOJu0YxJwj2IhtcDHd8PuKml77euYGzbeQ4dlYXpjsYW/KKA2ULvZfge 5FYno3PT+DGwMgR7YDNTcDhA6IXJJTutBW+bqyG1OXTBsE9nAJB+TGFOzNiXGY3y X-Gm-Gg: ASbGncuVTWmr+fyLUZLhEHn9UchNLVD03EnhFb+AQqFOb5+xGWscjf33XGHzWy67vZS Sr1MlrRYDyT/1pMRcM0hLuDQT/vnKRaFsfVZbdN5RnshaxLDk9BcMUg7FG8q/unOW/UOpJjp8IO N6tYMDLp50stw0/YPp0JRUT2+lOVr4F+2wHafunNJqyM9FKYgv0P8rQFjxMuc5nIE+toLoHEssz 2QeiyxqyHvtDaejh9m4AbzjGrFhSMZoLQ9oPpi51oifbJPRp/gLtdAY0+SgfqCw/GeHVPwMEkDN yANQ0O+F8WxeZ9fuFSJKGL6cqddfwS2ZGVPfa7h6LOH35IVqxPvmEEAOIfmO2wjIRZ3aS292sfi buecipOGVR5R7K+XXPR4U X-Google-Smtp-Source: AGHT+IHrsQ+9dDzk+oorVaNBNHERtEjkMW/gH3KTy6HYtB6IlnBeuZoCMiiPLd8fevWYY5tWyDXcdQ== X-Received: by 2002:a05:600c:1390:b0:456:21d2:c6f7 with SMTP id 5b1f17b1804b1-45a1b667e8fmr2678465e9.23.1755123218126; Wed, 13 Aug 2025 15:13:38 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:48::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a1a5161e5sm16936955e9.7.2025.08.13.15.13.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 15:13:37 -0700 (PDT) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: aleksander.lobakin@intel.com, alexanderduyck@fb.com, andrew+netdev@lunn.ch, ast@kernel.org, bpf@vger.kernel.org, corbet@lwn.net, daniel@iogearbox.net, davem@davemloft.net, edumazet@google.com, hawk@kernel.org, horms@kernel.org, john.fastabend@gmail.com, kernel-team@meta.com, kuba@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mohsin.bashr@gmail.com, pabeni@redhat.com, sdf@fomichev.me, vadim.fedorenko@linux.dev Subject: [PATCH net-next V4 4/9] eth: fbnic: Prefetch packet headers on Rx Date: Wed, 13 Aug 2025 15:13:14 -0700 Message-ID: <20250813221319.3367670-5-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250813221319.3367670-1-mohsin.bashr@gmail.com> References: <20250813221319.3367670-1-mohsin.bashr@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Issue a prefetch for the start of the buffer on Rx to try to avoid cache miss on packet headers. Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.c index 2adbe175ac09..65d1e40addec 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -888,7 +888,7 @@ static void fbnic_pkt_prepare(struct fbnic_napi_vector = *nv, u64 rcd, =20 /* Build frame around buffer */ hdr_start =3D page_address(page) + hdr_pg_start; - + net_prefetch(pkt->buff.data); xdp_prepare_buff(&pkt->buff, hdr_start, headroom, len - FBNIC_RX_PAD, true); =20 --=20 2.47.3 From nobody Sat Oct 4 17:29:47 2025 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BA7F2FCBFA; Wed, 13 Aug 2025 22:13:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123225; cv=none; b=VSeD06pZPUujQEtpkxODNpGv+zhxT1VxSYJlkPRJDtDgMu7NZUe7ZJTWlAsRtExwACTMja/PFAOuMeCoCxUCsrmMo8gdakX0WcHRY9pKoXvXkwcKa9SvY055TdkSr5n1jeSHwAnvXvjGjTgGUGhsB+TP5reYpoiwnzi6wyfvLrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123225; c=relaxed/simple; bh=Q7X/McOJROt+1O6Y5U1wLNV8omQfXEQSD7+POEqQA+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=m4f+tzggUkLmGYsu3XoCyq+a4F/Xr5LJ4/VCdIEb0gOLbtXtGI9WTTvqbFsWDzHIJdm5vIOCx704mZDqFv/oR1m6cuezaYvApbMQS/ZDJE7XQa0/p9MNEUWP+9zlCMHUpFxGDMqZmCBI4TDPP88TvS6ivbK12a6J73oFvfeFlJE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VtXPu93m; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VtXPu93m" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-45a1b0b6ac4so1173375e9.2; Wed, 13 Aug 2025 15:13:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755123221; x=1755728021; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jKu1YHWyZI2rIL/UlujNk1oC14mLmUdFcb6Re9G/vMs=; b=VtXPu93mWJcdfJaqAa/ZFW/0m7ULoF4vwW438PQM3z656ZyvZP6XTyGF2NDKrcjOGr X8OBgKfvGiDiyE8PF0XQbJrfg+uVB4upLMsh4pmBuBKg+HDBlyQHzhrw6STB2yyrtbFE mwsK+dnVDN/033PLIve2zrHJjV1LBXzuNBYsDCBpbFWUcGEl/EVf3+/eYiu/Wvm2hVDA Q2JQBbiLrZJG5BaSK58CjgKgZxUgusWOTbIl0ZpdRVZP4vAQ+M9Lt2h8yqPeaLaO8uYl s7JBcr97BznMs8JtKNI8V4hdWYMOnWJTThlpxDXemb3GeIhXnLKxtkGe+kX3pga8qP6O 9qeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755123221; x=1755728021; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jKu1YHWyZI2rIL/UlujNk1oC14mLmUdFcb6Re9G/vMs=; b=Q8Ye7rADE4lQG8i3q/Ef92Zbamk+49oA/AOBE03L+zKsf0h8Tu/rSo+FMoMPV1E7RE LutcYBC10V7mnDKgMDjoG7nvoqHKBdWunZY2dKVokkroX8xSQnT768XjQ9EDs5xMCi/a pPj/Q7Yq9k3iq2BPfYtwEM/UdzhhvFaIvPnTRTZqHno2zRBZ3niy/a2R0SNluVqPHqhR 2+YN7hw6gKPcAsWqW8QnU3aEOra6KbAm2ABmbkOEIMUi10mYjJYksWauW2nD/6b5+c7C VogJuaiyRuJJri36M7yFicM0mz7ezOtIDjZiAcxcnijnDzj0DAn249bmDQDd7X39vDyJ vvVQ== X-Forwarded-Encrypted: i=1; AJvYcCUpzOLcoY02gNJbAMQm8P3SYQllKrMzqZoBabSu9yXTl6mJIAx7kHZlCXdEix/QEK7uf9E=@vger.kernel.org, AJvYcCVVIsbPwwa9krHEpa8E1eKz6dvONco2E2BN0EFc7WmNdvTTVEd4ehp+97PveAtnCic94nvYt+wWBdgA@vger.kernel.org, AJvYcCXnul/zD314bSk3fzZiiTTuvjV1uHXg3q+py/2Qkfyc3BRYqoGLyxUjBnoThIqfClTREKRNsBICoxmB8PQ/@vger.kernel.org X-Gm-Message-State: AOJu0Yz2dkoqG3/0kt/yoH6Y8OoH8VWlaq0Ts3HPkdrJa2Tp7LE8cLu1 MQdFAEDyjxpPweMdN9Qb4WhaSZV4DsLqLPCs4VfXU6TTTl94RPFbxOz/rAPq60Ge X-Gm-Gg: ASbGncsKzFhCyOJY8G0NfU/i2Ugct9Ad+Py7jWYflM5zDGjKxToXuJSi7MaYOObb38Z XlH/tZooFMGL/tWVnPy6GhMsxSR+3+lZdGGMGyL0CN8nLetf3XaLJ7004OgMoWA6TZpNytj4H+4 01qqTNFK6XTsm4kMtZgDGQ8/7cl9qnOzEYXRNJnzSs93vwK5cc9yTscoLKcjSPfZUBg5MDSlo+r /TATFLJBUG5zyMt3zckWiJuVk3J714LSZhTrvikBzri1tFZscbo9yP7l+utZuYqO5NTxxlB/6f2 owxAYQIMx9BaVBD3CzNBU+381/wevu9FlNS0dHjCGt95D76Avr13EwQHgJxwbckhar3I7UhxWgO oo/f3Tryebr6LRKtC3Z7fTSb6vBJyBWs= X-Google-Smtp-Source: AGHT+IGziTKd40E+elbXEwJn2AYMCymOkqU0RInEzBY56WqsulNstT9rkbfUWFy+oTDNeSZy5PCvBw== X-Received: by 2002:a05:600c:1c90:b0:458:bc58:850c with SMTP id 5b1f17b1804b1-45a1b605874mr2907895e9.1.1755123221061; Wed, 13 Aug 2025 15:13:41 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:4b::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a1b855707sm1275775e9.5.2025.08.13.15.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 15:13:40 -0700 (PDT) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: aleksander.lobakin@intel.com, alexanderduyck@fb.com, andrew+netdev@lunn.ch, ast@kernel.org, bpf@vger.kernel.org, corbet@lwn.net, daniel@iogearbox.net, davem@davemloft.net, edumazet@google.com, hawk@kernel.org, horms@kernel.org, john.fastabend@gmail.com, kernel-team@meta.com, kuba@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mohsin.bashr@gmail.com, pabeni@redhat.com, sdf@fomichev.me, vadim.fedorenko@linux.dev Subject: [PATCH net-next V4 5/9] eth: fbnic: Add XDP pass, drop, abort support Date: Wed, 13 Aug 2025 15:13:15 -0700 Message-ID: <20250813221319.3367670-6-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250813221319.3367670-1-mohsin.bashr@gmail.com> References: <20250813221319.3367670-1-mohsin.bashr@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add basic support for attaching an XDP program to the device and support for PASS/DROP/ABORT actions. In fbnic, buffers are always mapped as DMA_BIDIRECTIONAL. The BPF program pointer can be read either on a per-packet basis or on a per-NAPI poll basis. Both approaches are functionally equivalent, in the current code. Stick to per-packet as it limits number of arguments we need to pass around. On the XDP hot path, check that packets with fragments are only allowed when multi-buffer support is enabled for the XDP program. Ideally, this check should not be necessary because ndo_bpf verifies that for XDP programs without multi-buff support, MTU is less than the hds_thresh. However, the MTU currently does not enforce the receive size which would require cleaning up the data path and bouncing the link. For practical reasons, prioritize the ability to enter and exit BPF mode with different MTU sizes without requiring a full reconfig. Testing: Hook a simple XDP program that passes all the packets destined for a specific port iperf3 -c 192.168.1.10 -P 5 -p 12345 Connecting to host 192.168.1.10, port 12345 [ 5] local 192.168.1.9 port 46702 connected to 192.168.1.10 port 12345 [ ID] Interval Transfer Bitrate Retr Cwnd - - - - - - - - - - - - - - - - - - - - - - - - - [SUM] 1.00-2.00 sec 3.86 GBytes 33.2 Gbits/sec 0 XDP_DROP: Hook an XDP program that drops packets destined for a specific port iperf3 -c 192.168.1.10 -P 5 -p 12345 ^C- - - - - - - - - - - - - - - - - - - - - - - - - [ ID] Interval Transfer Bitrate Retr [SUM] 0.00-0.00 sec 0.00 Bytes 0.00 bits/sec 0 sender [SUM] 0.00-0.00 sec 0.00 Bytes 0.00 bits/sec receiver iperf3: interrupt - the client has terminated XDP with HDS: - Validate XDP attachment failure when HDS is low ~] ethtool -G eth0 hds-thresh 512 ~] sudo ip link set eth0 xdpdrv obj xdp_pass_12345.o sec xdp ~] Error: fbnic: MTU too high, or HDS threshold is too low for single buffer XDP. - Validate successful XDP attachment when HDS threshold is appropriate ~] ethtool -G eth0 hds-thresh 1536 ~] sudo ip link set eth0 xdpdrv obj xdp_pass_12345.o sec xdp - Validate when the XDP program is attached, changing HDS thresh to a lower value fails ~] ethtool -G eth0 hds-thresh 512 ~] netlink error: fbnic: Use higher HDS threshold or multi-buf capable program - Validate HDS thresh does not matter when xdp frags support is available ~] ethtool -G eth0 hds-thresh 512 ~] sudo ip link set eth0 xdpdrv obj xdp_pass_mb_12345.o sec xdp.frags Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 11 +++ .../net/ethernet/meta/fbnic/fbnic_netdev.c | 35 +++++++ .../net/ethernet/meta/fbnic/fbnic_netdev.h | 5 + drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 96 +++++++++++++++++-- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 1 + 5 files changed, 141 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/= ethernet/meta/fbnic/fbnic_ethtool.c index 8ae2ecbae06c..742b557d0e56 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c @@ -329,6 +329,17 @@ fbnic_set_ringparam(struct net_device *netdev, struct = ethtool_ringparam *ring, return -EINVAL; } =20 + /* If an XDP program is attached, we should check for potential frame + * splitting. If the new HDS threshold can cause splitting, we should + * only allow if the attached XDP program can handle frags. + */ + if (fbnic_check_split_frames(fbn->xdp_prog, netdev->mtu, + kernel_ring->hds_thresh)) { + NL_SET_ERR_MSG_MOD(extack, + "Use higher HDS threshold or multi-buf capable program"); + return -EINVAL; + } + if (!netif_running(netdev)) { fbnic_set_rings(fbn, ring, kernel_ring); return 0; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c b/drivers/net/e= thernet/meta/fbnic/fbnic_netdev.c index a7eb7a367b98..fb81d1a7bc51 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c @@ -508,6 +508,40 @@ static void fbnic_get_stats64(struct net_device *dev, } } =20 +bool fbnic_check_split_frames(struct bpf_prog *prog, unsigned int mtu, + u32 hds_thresh) +{ + if (!prog) + return false; + + if (prog->aux->xdp_has_frags) + return false; + + return mtu + ETH_HLEN > hds_thresh; +} + +static int fbnic_bpf(struct net_device *netdev, struct netdev_bpf *bpf) +{ + struct bpf_prog *prog =3D bpf->prog, *prev_prog; + struct fbnic_net *fbn =3D netdev_priv(netdev); + + if (bpf->command !=3D XDP_SETUP_PROG) + return -EINVAL; + + if (fbnic_check_split_frames(prog, netdev->mtu, + fbn->hds_thresh)) { + NL_SET_ERR_MSG_MOD(bpf->extack, + "MTU too high, or HDS threshold is too low for single buffer XDP"); + return -EOPNOTSUPP; + } + + prev_prog =3D xchg(&fbn->xdp_prog, prog); + if (prev_prog) + bpf_prog_put(prev_prog); + + return 0; +} + static const struct net_device_ops fbnic_netdev_ops =3D { .ndo_open =3D fbnic_open, .ndo_stop =3D fbnic_stop, @@ -517,6 +551,7 @@ static const struct net_device_ops fbnic_netdev_ops =3D= { .ndo_set_mac_address =3D fbnic_set_mac, .ndo_set_rx_mode =3D fbnic_set_rx_mode, .ndo_get_stats64 =3D fbnic_get_stats64, + .ndo_bpf =3D fbnic_bpf, .ndo_hwtstamp_get =3D fbnic_hwtstamp_get, .ndo_hwtstamp_set =3D fbnic_hwtstamp_set, }; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.h b/drivers/net/e= thernet/meta/fbnic/fbnic_netdev.h index 04c5c7ed6c3a..bfa79ea910d8 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.h @@ -18,6 +18,8 @@ #define FBNIC_TUN_GSO_FEATURES NETIF_F_GSO_IPXIP6 =20 struct fbnic_net { + struct bpf_prog *xdp_prog; + struct fbnic_ring *tx[FBNIC_MAX_TXQS]; struct fbnic_ring *rx[FBNIC_MAX_RXQS]; =20 @@ -104,4 +106,7 @@ int fbnic_phylink_ethtool_ksettings_get(struct net_devi= ce *netdev, int fbnic_phylink_get_fecparam(struct net_device *netdev, struct ethtool_fecparam *fecparam); int fbnic_phylink_init(struct net_device *netdev); + +bool fbnic_check_split_frames(struct bpf_prog *prog, + unsigned int mtu, u32 hds_threshold); #endif /* _FBNIC_NETDEV_H_ */ diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.c index 65d1e40addec..a669e169e3ad 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -2,17 +2,26 @@ /* Copyright (c) Meta Platforms, Inc. and affiliates. */ =20 #include +#include +#include #include #include #include #include #include +#include =20 #include "fbnic.h" #include "fbnic_csr.h" #include "fbnic_netdev.h" #include "fbnic_txrx.h" =20 +enum { + FBNIC_XDP_PASS =3D 0, + FBNIC_XDP_CONSUME, + FBNIC_XDP_LEN_ERR, +}; + enum { FBNIC_XMIT_CB_TS =3D 0x01, }; @@ -877,7 +886,7 @@ static void fbnic_pkt_prepare(struct fbnic_napi_vector = *nv, u64 rcd, =20 headroom =3D hdr_pg_off - hdr_pg_start + FBNIC_RX_PAD; frame_sz =3D hdr_pg_end - hdr_pg_start; - xdp_init_buff(&pkt->buff, frame_sz, NULL); + xdp_init_buff(&pkt->buff, frame_sz, &qt->xdp_rxq); hdr_pg_start +=3D (FBNIC_RCD_AL_BUFF_FRAG_MASK & rcd) * FBNIC_BD_FRAG_SIZE; =20 @@ -967,6 +976,39 @@ static struct sk_buff *fbnic_build_skb(struct fbnic_na= pi_vector *nv, return skb; } =20 +static struct sk_buff *fbnic_run_xdp(struct fbnic_napi_vector *nv, + struct fbnic_pkt_buff *pkt) +{ + struct fbnic_net *fbn =3D netdev_priv(nv->napi.dev); + struct bpf_prog *xdp_prog; + int act; + + xdp_prog =3D READ_ONCE(fbn->xdp_prog); + if (!xdp_prog) + goto xdp_pass; + + /* Should never happen, config paths enforce HDS threshold > MTU */ + if (xdp_buff_has_frags(&pkt->buff) && !xdp_prog->aux->xdp_has_frags) + return ERR_PTR(-FBNIC_XDP_LEN_ERR); + + act =3D bpf_prog_run_xdp(xdp_prog, &pkt->buff); + switch (act) { + case XDP_PASS: +xdp_pass: + return fbnic_build_skb(nv, pkt); + default: + bpf_warn_invalid_xdp_action(nv->napi.dev, xdp_prog, act); + fallthrough; + case XDP_ABORTED: + trace_xdp_exception(nv->napi.dev, xdp_prog, act); + fallthrough; + case XDP_DROP: + break; + } + + return ERR_PTR(-FBNIC_XDP_CONSUME); +} + static enum pkt_hash_types fbnic_skb_hash_type(u64 rcd) { return (FBNIC_RCD_META_L4_TYPE_MASK & rcd) ? PKT_HASH_TYPE_L4 : @@ -1065,7 +1107,7 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *= nv, if (unlikely(pkt->add_frag_failed)) skb =3D NULL; else if (likely(!fbnic_rcd_metadata_err(rcd))) - skb =3D fbnic_build_skb(nv, pkt); + skb =3D fbnic_run_xdp(nv, pkt); =20 /* Populate skb and invalidate XDP */ if (!IS_ERR_OR_NULL(skb)) { @@ -1251,6 +1293,7 @@ static void fbnic_free_napi_vector(struct fbnic_net *= fbn, } =20 for (j =3D 0; j < nv->rxt_count; j++, i++) { + xdp_rxq_info_unreg(&nv->qt[i].xdp_rxq); fbnic_remove_rx_ring(fbn, &nv->qt[i].sub0); fbnic_remove_rx_ring(fbn, &nv->qt[i].sub1); fbnic_remove_rx_ring(fbn, &nv->qt[i].cmpl); @@ -1423,6 +1466,11 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev = *fbd, struct fbnic_net *fbn, fbnic_ring_init(&qt->cmpl, db, rxq_idx, FBNIC_RING_F_STATS); fbn->rx[rxq_idx] =3D &qt->cmpl; =20 + err =3D xdp_rxq_info_reg(&qt->xdp_rxq, fbn->netdev, rxq_idx, + nv->napi.napi_id); + if (err) + goto free_ring_cur_qt; + /* Update Rx queue index */ rxt_count--; rxq_idx +=3D v_count; @@ -1433,6 +1481,25 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev = *fbd, struct fbnic_net *fbn, =20 return 0; =20 + while (rxt_count < nv->rxt_count) { + qt--; + + xdp_rxq_info_unreg(&qt->xdp_rxq); +free_ring_cur_qt: + fbnic_remove_rx_ring(fbn, &qt->sub0); + fbnic_remove_rx_ring(fbn, &qt->sub1); + fbnic_remove_rx_ring(fbn, &qt->cmpl); + rxt_count++; + } + while (txt_count < nv->txt_count) { + qt--; + + fbnic_remove_tx_ring(fbn, &qt->sub0); + fbnic_remove_tx_ring(fbn, &qt->cmpl); + + txt_count++; + } + fbnic_napi_free_irq(fbd, nv); pp_destroy: page_pool_destroy(nv->page_pool); napi_del: @@ -1709,8 +1776,10 @@ static void fbnic_free_nv_resources(struct fbnic_net= *fbn, for (i =3D 0; i < nv->txt_count; i++) fbnic_free_qt_resources(fbn, &nv->qt[i]); =20 - for (j =3D 0; j < nv->rxt_count; j++, i++) + for (j =3D 0; j < nv->rxt_count; j++, i++) { fbnic_free_qt_resources(fbn, &nv->qt[i]); + xdp_rxq_info_unreg_mem_model(&nv->qt[i].xdp_rxq); + } } =20 static int fbnic_alloc_nv_resources(struct fbnic_net *fbn, @@ -1722,19 +1791,32 @@ static int fbnic_alloc_nv_resources(struct fbnic_ne= t *fbn, for (i =3D 0; i < nv->txt_count; i++) { err =3D fbnic_alloc_tx_qt_resources(fbn, &nv->qt[i]); if (err) - goto free_resources; + goto free_qt_resources; } =20 /* Allocate Rx Resources */ for (j =3D 0; j < nv->rxt_count; j++, i++) { + /* Register XDP memory model for completion queue */ + err =3D xdp_reg_mem_model(&nv->qt[i].xdp_rxq.mem, + MEM_TYPE_PAGE_POOL, + nv->page_pool); + if (err) + goto xdp_unreg_mem_model; + err =3D fbnic_alloc_rx_qt_resources(fbn, &nv->qt[i]); if (err) - goto free_resources; + goto xdp_unreg_cur_model; } =20 return 0; =20 -free_resources: +xdp_unreg_mem_model: + while (j-- && i--) { + fbnic_free_qt_resources(fbn, &nv->qt[i]); +xdp_unreg_cur_model: + xdp_rxq_info_unreg_mem_model(&nv->qt[i].xdp_rxq); + } +free_qt_resources: while (i--) fbnic_free_qt_resources(fbn, &nv->qt[i]); return err; @@ -2026,7 +2108,7 @@ void fbnic_flush(struct fbnic_net *fbn) memset(qt->cmpl.desc, 0, qt->cmpl.size); =20 fbnic_put_pkt_buff(nv, qt->cmpl.pkt, 0); - qt->cmpl.pkt->buff.data_hard_start =3D NULL; + memset(qt->cmpl.pkt, 0, sizeof(struct fbnic_pkt_buff)); } } } diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.h index d236152bbaaa..5536f72a1c85 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h @@ -128,6 +128,7 @@ struct fbnic_ring { =20 struct fbnic_q_triad { struct fbnic_ring sub0, sub1, cmpl; + struct xdp_rxq_info xdp_rxq; }; =20 struct fbnic_napi_vector { --=20 2.47.3 From nobody Sat Oct 4 17:29:47 2025 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 414EE2F49FA; Wed, 13 Aug 2025 22:13:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123228; cv=none; b=VoZQGkdiC4HUZQZIKujqKSlEVs7ZOouzEpHTaWRorUUdL3jrU64IRAedMuY6duCOtybW4NxBvCPOr/nHPDwlCF+hl+Vy8raUea9cyOe8K3N2bUqvUA8L8oHD7NzhOdn+v3DLfyXwms1VivqWY6gm/x3N7FuLas+OW5xi39PX03A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123228; c=relaxed/simple; bh=z5eh1bKAj+yTKJlbaWakuZx+ew3j2Q9i6btBmoQVet0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WoWwV2RKAbqCD/mcjEZdpZbFHKW+HnZT94xGlqGjEZMRzgv1jhylR5vOMJ+DvD3chPfpulmXG7hRc+N/vnS5aofs7dsf6C1A2EliM4sTtQjZ6fBLpA4fA6Z+XZIpJqBAHQCwvWHXlDHFV2Zhi/Hjt9TK4iQQ41jtRBQ/88SBXeo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C3fOHgLW; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C3fOHgLW" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-45a1b05a49cso2063895e9.1; Wed, 13 Aug 2025 15:13:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755123224; x=1755728024; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y1WHY4FNnRPffvIFwMJXVzB++hI6LqZV5e64X1VQUxE=; b=C3fOHgLWcBmgR7okknNTdSatf/CvHtbDepu6QWRf7XkmA8Jgl7GunpD16pf85AS2WM EMbnUAQ/jXdupbqWgnv7oqEheskBsnYTYM2dqFIQUTjLAuH0vmtTP4WfJ5DdjY6jmSMD I+KM8xVqbZpBZryUja+mM8eggTky15OvNH3xNAa5PEcwBgD0JlenQ59x5q7ho+RyOL/M FIYWsDENNVESH56BLja1XX7dvJNO20sApNCIXGDy0eQhDv+QyGWMRrNzmHLycYoJcTD3 k/gicMmz1q6FmNwmVDXUH0OSMU8rwo+fp4V0NLvOg0qW6LEk2jqXZJNKXeAE6Z2x9bs6 a3Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755123224; x=1755728024; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y1WHY4FNnRPffvIFwMJXVzB++hI6LqZV5e64X1VQUxE=; b=a5RZoubaKZk7L7+xC50K4R/IfN7K8OeFlRrvz++1ztWnX2nvSJCZ76b8PRoH5PHI0q lU/MK1lQ/eMYzlfL2nq6Tz7q8OAvLa9H2PEnfIKSkyB0hq3ozd0ainCh5Qiopd+VBsVo fl/OdK6GwYOIA5PqODo2StXNCj86HhNdVj8GnrqLlcr2erdh9BiFe396na2+K5vdx2vR v2KQo/ohy7b5q2HsazVRKCRX2HxUYq8WlNhsMQgXajB753khgolJOixKy2ahl7cghRfk lcKPh9hO03/s8Sg9AHaAOwZgYG46zdZsBdl+LmXi7NVsF+xgPcgOcp/+PMvRCr/vy3jx yeyw== X-Forwarded-Encrypted: i=1; AJvYcCV9TsgrGmjoy+dEiggbyb4uc5ph8Ukrg5sV9NpZ5y1W1648VFMtbIZDshoPm8537y/EPMg=@vger.kernel.org, AJvYcCWeGx5LWzZ4TbnOActsQDEKYcWof6jLpmyL5ik2475j/6fNB9dwnED5dYsDPl7FsrWtyqE43FaE9R0/Yd9L@vger.kernel.org, AJvYcCWhbpX6h19vnE3Xr4tGYD9rdYquuGYuZpuDivAaUYRC2u6GX/GABTQ/Y4eT/JusyKx/yaGkhcjo50tV@vger.kernel.org X-Gm-Message-State: AOJu0Yz4ZlZO3oA4lIsHD+CsPg4jCvGvkGiFAlToSL4irLcTHm0N/i6d kveSmrUHTK7dyzfmGAOAyLPnwy3cVO7MvlePWEJ/GejhvTNDpdr3vN+lArv3jWt2 X-Gm-Gg: ASbGnctDEEpCNSpQBuZna5u4SYmrh+4zAUpJDH8jTidLMyqOV5Qw+2Hoagqr7E+8Oa/ MlBD0nhSnD2xlPRg+nJW39vUOHStk2O0ckRaP0QHVvtYb0WObnIUHUFQ0HAGuh/DcX6vE5ViZyq K76j4pb4fjhtgbIUoChnnuok1zVuET09aBohr7ex96pMX/2AVvg3/8Vcp9huPfoinl3Jg2mf+9i Dqqx2AWGkSFsMkSOazbjP8GL9AqWGXwH1TySgnePCwG9rx39S8c56Y4IoL/xoJ93zTn9j8+9bhY 8BWUoZ+HoBei/I+PyEa60VnQL6CVjZHUcnqvLSNcVwCaVEv3ckRZepuVGaOvAFYEabpZXZyzVUN oHglFcvP6drMQR8Lf2w2ZyA== X-Google-Smtp-Source: AGHT+IF6URqt4VoRd2z/e0hbQJPvnTL3PiSzpsNPje5yQq9DUnJsjGdwOv/RSXlPoPJqLIo4E4eaTw== X-Received: by 2002:a05:600c:3509:b0:458:bd2a:496f with SMTP id 5b1f17b1804b1-45a1b646dc0mr2575445e9.21.1755123223657; Wed, 13 Aug 2025 15:13:43 -0700 (PDT) Received: from localhost ([2a03:2880:31ff::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a1a518f50sm16445735e9.11.2025.08.13.15.13.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 15:13:42 -0700 (PDT) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: aleksander.lobakin@intel.com, alexanderduyck@fb.com, andrew+netdev@lunn.ch, ast@kernel.org, bpf@vger.kernel.org, corbet@lwn.net, daniel@iogearbox.net, davem@davemloft.net, edumazet@google.com, hawk@kernel.org, horms@kernel.org, john.fastabend@gmail.com, kernel-team@meta.com, kuba@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mohsin.bashr@gmail.com, pabeni@redhat.com, sdf@fomichev.me, vadim.fedorenko@linux.dev Subject: [PATCH net-next V4 6/9] eth: fbnic: Add support for XDP queues Date: Wed, 13 Aug 2025 15:13:16 -0700 Message-ID: <20250813221319.3367670-7-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250813221319.3367670-1-mohsin.bashr@gmail.com> References: <20250813221319.3367670-1-mohsin.bashr@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for allocating XDP_TX queues and configuring ring support. FBNIC has been designed with XDP support in mind. Each Tx queue has 2 submission queues and one completion queue, with the expectation that one of the submission queues will be used by the stack, and the other by XDP. XDP queues are populated by XDP_TX and start from index 128 in the TX queue array. The support for XDP_TX is added in the next patch. Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- .../net/ethernet/meta/fbnic/fbnic_netdev.h | 2 +- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 139 +++++++++++++++++- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 7 + 3 files changed, 142 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.h b/drivers/net/e= thernet/meta/fbnic/fbnic_netdev.h index bfa79ea910d8..0a6347f28210 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.h @@ -20,7 +20,7 @@ struct fbnic_net { struct bpf_prog *xdp_prog; =20 - struct fbnic_ring *tx[FBNIC_MAX_TXQS]; + struct fbnic_ring *tx[FBNIC_MAX_TXQS + FBNIC_MAX_XDPQS]; struct fbnic_ring *rx[FBNIC_MAX_RXQS]; =20 struct fbnic_napi_vector *napi[FBNIC_MAX_NAPI_VECTORS]; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.c index a669e169e3ad..8c7709f707e6 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -615,6 +615,37 @@ static void fbnic_clean_twq0(struct fbnic_napi_vector = *nv, int napi_budget, } } =20 +static void fbnic_clean_twq1(struct fbnic_napi_vector *nv, bool pp_allow_d= irect, + struct fbnic_ring *ring, bool discard, + unsigned int hw_head) +{ + unsigned int head =3D ring->head; + u64 total_bytes =3D 0; + + while (hw_head !=3D head) { + struct page *page; + u64 twd; + + if (unlikely(!(ring->desc[head] & FBNIC_TWD_TYPE(AL)))) + goto next_desc; + + twd =3D le64_to_cpu(ring->desc[head]); + page =3D ring->tx_buf[head]; + + total_bytes +=3D FIELD_GET(FBNIC_TWD_LEN_MASK, twd); + + page_pool_put_page(nv->page_pool, page, -1, pp_allow_direct); +next_desc: + head++; + head &=3D ring->size_mask; + } + + if (!total_bytes) + return; + + ring->head =3D head; +} + static void fbnic_clean_tsq(struct fbnic_napi_vector *nv, struct fbnic_ring *ring, u64 tcd, int *ts_head, int *head0) @@ -698,12 +729,21 @@ static void fbnic_page_pool_drain(struct fbnic_ring *= ring, unsigned int idx, } =20 static void fbnic_clean_twq(struct fbnic_napi_vector *nv, int napi_budget, - struct fbnic_q_triad *qt, s32 ts_head, s32 head0) + struct fbnic_q_triad *qt, s32 ts_head, s32 head0, + s32 head1) { if (head0 >=3D 0) fbnic_clean_twq0(nv, napi_budget, &qt->sub0, false, head0); else if (ts_head >=3D 0) fbnic_clean_twq0(nv, napi_budget, &qt->sub0, false, ts_head); + + if (head1 >=3D 0) { + qt->cmpl.deferred_head =3D -1; + if (napi_budget) + fbnic_clean_twq1(nv, true, &qt->sub1, false, head1); + else + qt->cmpl.deferred_head =3D head1; + } } =20 static void @@ -711,6 +751,7 @@ fbnic_clean_tcq(struct fbnic_napi_vector *nv, struct fb= nic_q_triad *qt, int napi_budget) { struct fbnic_ring *cmpl =3D &qt->cmpl; + s32 head1 =3D cmpl->deferred_head; s32 head0 =3D -1, ts_head =3D -1; __le64 *raw_tcd, done; u32 head =3D cmpl->head; @@ -728,7 +769,10 @@ fbnic_clean_tcq(struct fbnic_napi_vector *nv, struct f= bnic_q_triad *qt, =20 switch (FIELD_GET(FBNIC_TCD_TYPE_MASK, tcd)) { case FBNIC_TCD_TYPE_0: - if (!(tcd & FBNIC_TCD_TWQ1)) + if (tcd & FBNIC_TCD_TWQ1) + head1 =3D FIELD_GET(FBNIC_TCD_TYPE0_HEAD1_MASK, + tcd); + else head0 =3D FIELD_GET(FBNIC_TCD_TYPE0_HEAD0_MASK, tcd); /* Currently all err status bits are related to @@ -761,7 +805,7 @@ fbnic_clean_tcq(struct fbnic_napi_vector *nv, struct fb= nic_q_triad *qt, } =20 /* Unmap and free processed buffers */ - fbnic_clean_twq(nv, napi_budget, qt, ts_head, head0); + fbnic_clean_twq(nv, napi_budget, qt, ts_head, head0, head1); } =20 static void fbnic_clean_bdq(struct fbnic_napi_vector *nv, int napi_budget, @@ -1268,6 +1312,17 @@ static void fbnic_remove_tx_ring(struct fbnic_net *f= bn, fbn->tx[txr->q_idx] =3D NULL; } =20 +static void fbnic_remove_xdp_ring(struct fbnic_net *fbn, + struct fbnic_ring *xdpr) +{ + if (!(xdpr->flags & FBNIC_RING_F_STATS)) + return; + + /* Remove pointer to the Tx ring */ + WARN_ON(fbn->tx[xdpr->q_idx] && fbn->tx[xdpr->q_idx] !=3D xdpr); + fbn->tx[xdpr->q_idx] =3D NULL; +} + static void fbnic_remove_rx_ring(struct fbnic_net *fbn, struct fbnic_ring *rxr) { @@ -1289,6 +1344,7 @@ static void fbnic_free_napi_vector(struct fbnic_net *= fbn, =20 for (i =3D 0; i < nv->txt_count; i++) { fbnic_remove_tx_ring(fbn, &nv->qt[i].sub0); + fbnic_remove_xdp_ring(fbn, &nv->qt[i].sub1); fbnic_remove_tx_ring(fbn, &nv->qt[i].cmpl); } =20 @@ -1363,6 +1419,7 @@ static void fbnic_ring_init(struct fbnic_ring *ring, = u32 __iomem *doorbell, ring->doorbell =3D doorbell; ring->q_idx =3D q_idx; ring->flags =3D flags; + ring->deferred_head =3D -1; } =20 static int fbnic_alloc_napi_vector(struct fbnic_dev *fbd, struct fbnic_net= *fbn, @@ -1372,11 +1429,18 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev= *fbd, struct fbnic_net *fbn, { int txt_count =3D txq_count, rxt_count =3D rxq_count; u32 __iomem *uc_addr =3D fbd->uc_addr0; + int xdp_count =3D 0, qt_count, err; struct fbnic_napi_vector *nv; struct fbnic_q_triad *qt; - int qt_count, err; u32 __iomem *db; =20 + /* We need to reserve at least one Tx Queue Triad for an XDP ring */ + if (rxq_count) { + xdp_count =3D 1; + if (!txt_count) + txt_count =3D 1; + } + qt_count =3D txt_count + rxq_count; if (!qt_count) return -EINVAL; @@ -1425,12 +1489,13 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev= *fbd, struct fbnic_net *fbn, qt =3D nv->qt; =20 while (txt_count) { + u8 flags =3D FBNIC_RING_F_CTX | FBNIC_RING_F_STATS; + /* Configure Tx queue */ db =3D &uc_addr[FBNIC_QUEUE(txq_idx) + FBNIC_QUEUE_TWQ0_TAIL]; =20 /* Assign Tx queue to netdev if applicable */ if (txq_count > 0) { - u8 flags =3D FBNIC_RING_F_CTX | FBNIC_RING_F_STATS; =20 fbnic_ring_init(&qt->sub0, db, txq_idx, flags); fbn->tx[txq_idx] =3D &qt->sub0; @@ -1440,6 +1505,28 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev = *fbd, struct fbnic_net *fbn, FBNIC_RING_F_DISABLED); } =20 + /* Configure XDP queue */ + db =3D &uc_addr[FBNIC_QUEUE(txq_idx) + FBNIC_QUEUE_TWQ1_TAIL]; + + /* Assign XDP queue to netdev if applicable + * + * The setup for this is in itself a bit different. + * 1. We only need one XDP Tx queue per NAPI vector. + * 2. We associate it to the first Rx queue index. + * 3. The hardware side is associated based on the Tx Queue. + * 4. The netdev queue is offset by FBNIC_MAX_TXQs. + */ + if (xdp_count > 0) { + unsigned int xdp_idx =3D FBNIC_MAX_TXQS + rxq_idx; + + fbnic_ring_init(&qt->sub1, db, xdp_idx, flags); + fbn->tx[xdp_idx] =3D &qt->sub1; + xdp_count--; + } else { + fbnic_ring_init(&qt->sub1, db, 0, + FBNIC_RING_F_DISABLED); + } + /* Configure Tx completion queue */ db =3D &uc_addr[FBNIC_QUEUE(txq_idx) + FBNIC_QUEUE_TCQ_HEAD]; fbnic_ring_init(&qt->cmpl, db, 0, 0); @@ -1495,6 +1582,7 @@ static int fbnic_alloc_napi_vector(struct fbnic_dev *= fbd, struct fbnic_net *fbn, qt--; =20 fbnic_remove_tx_ring(fbn, &qt->sub0); + fbnic_remove_xdp_ring(fbn, &qt->sub1); fbnic_remove_tx_ring(fbn, &qt->cmpl); =20 txt_count++; @@ -1729,6 +1817,10 @@ static int fbnic_alloc_tx_qt_resources(struct fbnic_= net *fbn, if (err) return err; =20 + err =3D fbnic_alloc_tx_ring_resources(fbn, &qt->sub1); + if (err) + goto free_sub0; + err =3D fbnic_alloc_tx_ring_resources(fbn, &qt->cmpl); if (err) goto free_sub1; @@ -1736,6 +1828,8 @@ static int fbnic_alloc_tx_qt_resources(struct fbnic_n= et *fbn, return 0; =20 free_sub1: + fbnic_free_ring_resources(dev, &qt->sub1); +free_sub0: fbnic_free_ring_resources(dev, &qt->sub0); return err; } @@ -1923,6 +2017,15 @@ static void fbnic_disable_twq0(struct fbnic_ring *tx= r) fbnic_ring_wr32(txr, FBNIC_QUEUE_TWQ0_CTL, twq_ctl); } =20 +static void fbnic_disable_twq1(struct fbnic_ring *txr) +{ + u32 twq_ctl =3D fbnic_ring_rd32(txr, FBNIC_QUEUE_TWQ1_CTL); + + twq_ctl &=3D ~FBNIC_QUEUE_TWQ_CTL_ENABLE; + + fbnic_ring_wr32(txr, FBNIC_QUEUE_TWQ1_CTL, twq_ctl); +} + static void fbnic_disable_tcq(struct fbnic_ring *txr) { fbnic_ring_wr32(txr, FBNIC_QUEUE_TCQ_CTL, 0); @@ -1968,6 +2071,7 @@ void fbnic_disable(struct fbnic_net *fbn) struct fbnic_q_triad *qt =3D &nv->qt[t]; =20 fbnic_disable_twq0(&qt->sub0); + fbnic_disable_twq1(&qt->sub1); fbnic_disable_tcq(&qt->cmpl); } =20 @@ -2082,6 +2186,8 @@ void fbnic_flush(struct fbnic_net *fbn) =20 /* Clean the work queues of unprocessed work */ fbnic_clean_twq0(nv, 0, &qt->sub0, true, qt->sub0.tail); + fbnic_clean_twq1(nv, false, &qt->sub1, true, + qt->sub1.tail); =20 /* Reset completion queue descriptor ring */ memset(qt->cmpl.desc, 0, qt->cmpl.size); @@ -2156,6 +2262,28 @@ static void fbnic_enable_twq0(struct fbnic_ring *twq) fbnic_ring_wr32(twq, FBNIC_QUEUE_TWQ0_CTL, FBNIC_QUEUE_TWQ_CTL_ENABLE); } =20 +static void fbnic_enable_twq1(struct fbnic_ring *twq) +{ + u32 log_size =3D fls(twq->size_mask); + + if (!twq->size_mask) + return; + + /* Reset head/tail */ + fbnic_ring_wr32(twq, FBNIC_QUEUE_TWQ1_CTL, FBNIC_QUEUE_TWQ_CTL_RESET); + twq->tail =3D 0; + twq->head =3D 0; + + /* Store descriptor ring address and size */ + fbnic_ring_wr32(twq, FBNIC_QUEUE_TWQ1_BAL, lower_32_bits(twq->dma)); + fbnic_ring_wr32(twq, FBNIC_QUEUE_TWQ1_BAH, upper_32_bits(twq->dma)); + + /* Write lower 4 bits of log size as 64K ring size is 0 */ + fbnic_ring_wr32(twq, FBNIC_QUEUE_TWQ1_SIZE, log_size & 0xf); + + fbnic_ring_wr32(twq, FBNIC_QUEUE_TWQ1_CTL, FBNIC_QUEUE_TWQ_CTL_ENABLE); +} + static void fbnic_enable_tcq(struct fbnic_napi_vector *nv, struct fbnic_ring *tcq) { @@ -2341,6 +2469,7 @@ void fbnic_enable(struct fbnic_net *fbn) struct fbnic_q_triad *qt =3D &nv->qt[t]; =20 fbnic_enable_twq0(&qt->sub0); + fbnic_enable_twq1(&qt->sub1); fbnic_enable_tcq(nv, &qt->cmpl); } =20 diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.h index 5536f72a1c85..0e92d11115a6 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h @@ -35,6 +35,7 @@ struct fbnic_net; =20 #define FBNIC_MAX_TXQS 128u #define FBNIC_MAX_RXQS 128u +#define FBNIC_MAX_XDPQS 128u =20 /* These apply to TWQs, TCQ, RCQ */ #define FBNIC_QUEUE_SIZE_MIN 16u @@ -119,6 +120,12 @@ struct fbnic_ring { =20 u32 head, tail; /* Head/Tail of ring */ =20 + /* Deferred_head is used to cache the head for TWQ1 if an attempt + * is made to clean TWQ1 with zero napi_budget. We do not use it for + * any other ring. + */ + s32 deferred_head; + struct fbnic_queue_stats stats; =20 /* Slow path fields follow */ --=20 2.47.3 From nobody Sat Oct 4 17:29:47 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C77133002BE; Wed, 13 Aug 2025 22:13:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123231; cv=none; b=NbQE6kNK/DIz8L5S10cIMToMIXyqjtzroP/hIVRHuVav3qM/JZAW4dmmPIuS2Fn4ddYeiWtkzLYc84eHrZJEPGGcgB9vZ0InkSh/SydS5YfEu2dthX2fTpEDNNlVz8OeQfAISZvQ+oe/dqieOnCEtWX+pJiggSybbtn+LI5Vovw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123231; c=relaxed/simple; bh=iGLPwLTWNwop6RMFh7j0QYriyX4zvp+U62kQYD5P7BY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WZPfLjcDddAldfrZj+MaxkjdPodL1OhCunATeIr2DqZ1pv+2GBpYSWO7f8ez8KYa7FIl4J6Y5qw+VtVw8doOW4ScUtcALGS6IdsUh4xX6J7/5ETOQXb9apnTDrJl/TFqxj/tq4ENdJpHhYKfF4uzTB927/hqGoNMsN++Rnx8vrk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mkopFhum; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mkopFhum" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3b9d41cd38dso200716f8f.0; Wed, 13 Aug 2025 15:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755123228; x=1755728028; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=M9TwM/oJ+vBg3tLeYBvNykLhtDAg9/aYnDOk66ERKqU=; b=mkopFhumm0nRGJHUNXHPfJ5XuGivqFRVcmtC7X6/1LsUbxOgrv7/7s2Ktu/Lp0gVzO PNoUFn5jDmjJb90K89caKqI76/SPURa992ib2N3ZqFt3Sx4q/Vh2XG1wMf8vV78y8thw xXU/M3d6DFav6+xu+qFsat3ScpVQPWwhOhFKdj5ZG6vzcrBUkSw6WkkXy6jETY/FH5Fq w0ohP30tDFLGK2cxTmX3l1e/8tAdYMavnpwaBVPWRNNjlnVBLUXh10RE6P8JuUoS1GZa JvRaOcfxn0aCov1Jq7ym6wHu0fFcNQvR91TPiVY7Zdk4ftOD5AXCFA+16sRhd/qIEu8l K9iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755123228; x=1755728028; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M9TwM/oJ+vBg3tLeYBvNykLhtDAg9/aYnDOk66ERKqU=; b=QPmN9W6TZG729y71q8hn+D6bIw9FOAtoROwMhmJPLwtEMd7sfH+zyuQ5qv7xmVzaS8 GuLoNddiOu90An74VzCvMGkU7YauZOgNQ4L6N3TPdmKwakcLFTjYr6gkfcZlhQTaAHfC HMSOz+lOqklN73KcAUTsUT8nslivOuSPDroKsYU4ZukWfPC8jwxzLuDZBNJHIeJ9li77 mKFt0Y5F32mgsPV878K6lUQAMQQP1AJjb7bxulRLBhGeZ/23bOK5VORDr4HuSr9j8FSv tqO3o7rSFNv16+GK73rDGVkg+T4r4BdxT7dDppGeda9hZ9e/Ecgnk//FJaDUYdZuvw9k hJVg== X-Forwarded-Encrypted: i=1; AJvYcCUy9rP0Vi7TNI4WfKjuBRjuPmhl6my1LJkzPzFgBC13QCk/kCNiTe9SIqGYXxiakj6psRE=@vger.kernel.org, AJvYcCVG2yRDYXvkFk2jQHK27t4aYJz11xC829ITCQWv2hddZDvnCwf/ITE0/d042yzRiPG9yLRjnhJK1hO/@vger.kernel.org, AJvYcCXRBxTdnGq3yoEFmC5K/WiYRFDA5+G2a5J11lA7SaN21AJUwOo2UimDru7cJ5z04hlExgsyxCPmHHMSTZ3B@vger.kernel.org X-Gm-Message-State: AOJu0YwXbYhMNeADvQCbtlD8rQkJL7+cE2wwZWuwhVFNuHfmS+QfKV9A g8dx6/MIgTfyJPGmIa8oZ7mk8C6/Hp7RevVU4tJlfzqx4atGfDXmjF5bxiusPk9P X-Gm-Gg: ASbGncuK1FTUJB8MhKBYDv+PDH/g9q3FtH8qI1anZkMfmI7ee54R2T7o/k5/3KN3vxh 6M5NpcXLAKP63aEg2oNZHX1cxtJD5KHDPPVI7QX8h5Cawxm8D91loZd+RR74RBcROQoIPebqssk W32FHflNqPoHaW1ALLC3x1zGR4ufvhnS+K1WuKcM+vKkh9D885k2g1Mw7zC7Gp2Tk6+JyLR2ihc IKhf+fz7gMg6Ole4k96huJrKGrqWB0j8WC7IGY7+aZK7ZrpXxTQptpId8VAQ21jeB06ruq/N64w BP9UOds6ibltrb7QHVRCVB/qnOfJqU7seiixEEOzxBldScYdyaPeVxtBDdPH+IfmJPyZFCmQBfZ 4OpCVzWoTNj+nz9+GTJK3GeTZtskejOuRMAo= X-Google-Smtp-Source: AGHT+IH4Q1XAD40GRpI0mu9XNK438yyqymK/KYQGRaX8w3+/UTg+oY+MoLpSuVNMSfAsopCTn26I3Q== X-Received: by 2002:a05:6000:178d:b0:3b7:8dd1:d7a1 with SMTP id ffacd0b85a97d-3b9e41785a6mr527545f8f.19.1755123227349; Wed, 13 Aug 2025 15:13:47 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:7::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c3c4d02sm47548992f8f.33.2025.08.13.15.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 15:13:45 -0700 (PDT) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: aleksander.lobakin@intel.com, alexanderduyck@fb.com, andrew+netdev@lunn.ch, ast@kernel.org, bpf@vger.kernel.org, corbet@lwn.net, daniel@iogearbox.net, davem@davemloft.net, edumazet@google.com, hawk@kernel.org, horms@kernel.org, john.fastabend@gmail.com, kernel-team@meta.com, kuba@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mohsin.bashr@gmail.com, pabeni@redhat.com, sdf@fomichev.me, vadim.fedorenko@linux.dev Subject: [PATCH net-next V4 7/9] eth: fbnic: Add support for XDP_TX action Date: Wed, 13 Aug 2025 15:13:17 -0700 Message-ID: <20250813221319.3367670-8-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250813221319.3367670-1-mohsin.bashr@gmail.com> References: <20250813221319.3367670-1-mohsin.bashr@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for XDP_TX action and cleaning the associated work. Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 85 +++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.c index 8c7709f707e6..de3610a7491a 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -19,6 +19,7 @@ enum { FBNIC_XDP_PASS =3D 0, FBNIC_XDP_CONSUME, + FBNIC_XDP_TX, FBNIC_XDP_LEN_ERR, }; =20 @@ -1020,6 +1021,80 @@ static struct sk_buff *fbnic_build_skb(struct fbnic_= napi_vector *nv, return skb; } =20 +static long fbnic_pkt_tx(struct fbnic_napi_vector *nv, + struct fbnic_pkt_buff *pkt) +{ + struct fbnic_ring *ring =3D &nv->qt[0].sub1; + int size, offset, nsegs =3D 1, data_len =3D 0; + unsigned int tail =3D ring->tail; + struct skb_shared_info *shinfo; + skb_frag_t *frag =3D NULL; + struct page *page; + dma_addr_t dma; + __le64 *twd; + + if (unlikely(xdp_buff_has_frags(&pkt->buff))) { + shinfo =3D xdp_get_shared_info_from_buff(&pkt->buff); + nsegs +=3D shinfo->nr_frags; + data_len =3D shinfo->xdp_frags_size; + frag =3D &shinfo->frags[0]; + } + + if (fbnic_desc_unused(ring) < nsegs) + return -FBNIC_XDP_CONSUME; + + page =3D virt_to_page(pkt->buff.data_hard_start); + offset =3D offset_in_page(pkt->buff.data); + dma =3D page_pool_get_dma_addr(page); + + size =3D pkt->buff.data_end - pkt->buff.data; + + while (nsegs--) { + dma_sync_single_range_for_device(nv->dev, dma, offset, size, + DMA_BIDIRECTIONAL); + dma +=3D offset; + + ring->tx_buf[tail] =3D page; + + twd =3D &ring->desc[tail]; + *twd =3D cpu_to_le64(FIELD_PREP(FBNIC_TWD_ADDR_MASK, dma) | + FIELD_PREP(FBNIC_TWD_LEN_MASK, size) | + FIELD_PREP(FBNIC_TWD_TYPE_MASK, + FBNIC_TWD_TYPE_AL)); + + tail++; + tail &=3D ring->size_mask; + + if (!data_len) + break; + + offset =3D skb_frag_off(frag); + page =3D skb_frag_page(frag); + dma =3D page_pool_get_dma_addr(page); + + size =3D skb_frag_size(frag); + data_len -=3D size; + frag++; + } + + *twd |=3D FBNIC_TWD_TYPE(LAST_AL); + + ring->tail =3D tail; + + return -FBNIC_XDP_TX; +} + +static void fbnic_pkt_commit_tail(struct fbnic_napi_vector *nv, + unsigned int pkt_tail) +{ + struct fbnic_ring *ring =3D &nv->qt[0].sub1; + + /* Force DMA writes to flush before writing to tail */ + dma_wmb(); + + writel(pkt_tail, ring->doorbell); +} + static struct sk_buff *fbnic_run_xdp(struct fbnic_napi_vector *nv, struct fbnic_pkt_buff *pkt) { @@ -1040,6 +1115,8 @@ static struct sk_buff *fbnic_run_xdp(struct fbnic_nap= i_vector *nv, case XDP_PASS: xdp_pass: return fbnic_build_skb(nv, pkt); + case XDP_TX: + return ERR_PTR(fbnic_pkt_tx(nv, pkt)); default: bpf_warn_invalid_xdp_action(nv->napi.dev, xdp_prog, act); fallthrough; @@ -1104,10 +1181,10 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector= *nv, struct fbnic_q_triad *qt, int budget) { unsigned int packets =3D 0, bytes =3D 0, dropped =3D 0, alloc_failed =3D = 0; + s32 head0 =3D -1, head1 =3D -1, pkt_tail =3D -1; u64 csum_complete =3D 0, csum_none =3D 0; struct fbnic_ring *rcq =3D &qt->cmpl; struct fbnic_pkt_buff *pkt; - s32 head0 =3D -1, head1 =3D -1; __le64 *raw_rcd, done; u32 head =3D rcq->head; =20 @@ -1163,6 +1240,9 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *= nv, bytes +=3D skb->len; =20 napi_gro_receive(&nv->napi, skb); + } else if (skb =3D=3D ERR_PTR(-FBNIC_XDP_TX)) { + pkt_tail =3D nv->qt[0].sub1.tail; + bytes +=3D xdp_get_buff_len(&pkt->buff); } else { if (!skb) { alloc_failed++; @@ -1198,6 +1278,9 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *= nv, rcq->stats.rx.csum_none +=3D csum_none; u64_stats_update_end(&rcq->stats.syncp); =20 + if (pkt_tail >=3D 0) + fbnic_pkt_commit_tail(nv, pkt_tail); + /* Unmap and free processed buffers */ if (head0 >=3D 0) fbnic_clean_bdq(nv, budget, &qt->sub0, head0); --=20 2.47.3 From nobody Sat Oct 4 17:29:47 2025 Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDB802FE047; Wed, 13 Aug 2025 22:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123235; cv=none; b=OE37j1TnrkEhrMxW+pE5mPkBQwgixJMFi2VKvtyti4enA6+aeh7Kg/X3+jrQw9djaGvt6JAbg1rnYMe0s4UQTUTXBH3LveBuMNxXGKBVvzWfwMqeavvnjRU3oF4V3qzvVsmYb5QjZzkthkm0Wai05YreGDneBZbd2sADv1pAG80= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123235; c=relaxed/simple; bh=xaA4RSq0V6h1SP7FTxnJhxwH5ejnIQwO18xfXvM2oC8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dNGiefDoYMdS6fy36V1rKb04Qmb6qrdm+7gxIlpzQGwbjMHwtnHrk9BKB/boJvOPE/LAPO6tVh0ilSAhaBXnhchZz3htviudCmUs+0jUuTrWOcribsr6fVnMfcLqOqlcumHVhYgQojFR+o/ZdMNZYqZQV3Zl+fpcGTNbghqkdlg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MfBi4ejf; arc=none smtp.client-ip=209.85.221.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MfBi4ejf" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3b9e418ba08so129095f8f.3; Wed, 13 Aug 2025 15:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755123230; x=1755728030; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=gSyIWkXh8OSSWsOy/M8T9tWgun3ERfCH/jd30J9A/6I=; b=MfBi4ejfubK9IJjwBugKFcllSqdIUJVFk2NCddMcbHav4+ZpKMnI6bnTNB0pmmJRGh p7SaZV0/dezi/2qOClujFOdSuJsqhjjwpYJq5jbZ+fYq+u/hmTpRUMyVloZO6ix15/zM DYoi9juYr2fEf5drdsuWVv2nCw4tYW3DeBnSrXMnJVqetoAtOQOQyRBK5rUB4qcXAjQD OcyfbFKddzjgWSocHo9fAsIdJtj/KHJE3rrr/A12X7IpVdUcywrWtF7k2hEOZxGLWk+J xUFm6bkO1cYSyvTPVJz5hG98QD9c+skYfva3tLr9JhLqQZAyUHjfs1/Fp5wRDKwOE8/Y HKMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755123230; x=1755728030; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gSyIWkXh8OSSWsOy/M8T9tWgun3ERfCH/jd30J9A/6I=; b=lLS22gNhp2RKGuDZFbUcFivUJdei5G24J+ViF3W9lnN19zN3UfCRLDss89A6TFPQiL /Fx4Gw3t4Autiesr72Qjde96ZcHNOd67220O2+k6cUhg+fMJf28NU/Kq46gnTcmvPQt8 bHEkwajwnU0OPEu44YV6fZ4Sy3uSPd+eZlntcgxkNlzo03NbyK/0YIknbKmXjjXrUoGO 1RowV+jR9xFk+xcIACekoW4vPVCuU1a2AKrKusR2bkMiaO/f49Ygti1wTkrrHTRQyhbz ohsUYVttOKZCTRDWR6+SLpc5FHg29yW9wABJno6ReYr9ED2Is24/bSnMgBlm+RIMlCm2 NGhg== X-Forwarded-Encrypted: i=1; AJvYcCWZmbkymrBHW+SE7/Me1+hTVSENXFv8izmzUC40bhMuoyKfhrWiiRlEcGq0CVz0G7kVVHQ=@vger.kernel.org, AJvYcCWw5NnNIxwynvTXpizNLxy4zxejUYdA23MWxJNSCw5fpUrjqU8flowVpuUzyGO7f2CejAaEw4vVH2nT@vger.kernel.org, AJvYcCXXvXYvRzNNOuUrDNEsN6SSXN1tdRokNjRbvyw7Gh72tEHLNpPRuKZeBghwDujxJjulr+UCvFJ8WiDE/6Td@vger.kernel.org X-Gm-Message-State: AOJu0YzYAfzrr1wxqAAs974ebLbrDlpwaU1V3DuCGlJXIqiXqQaC8ROt DBs7zwGzMeJ+xclm6/aORKRU4WdMQ2kI4M9MzZqZcqn8JJWOe8DjnfFDpeCuUeJU X-Gm-Gg: ASbGncsecpsR9wY+5aAqg87r/HUf14nTv6jpt4wetNtt25sOXpQajvBKwcztEPEG7i6 6RaCY06e63uYBYBTMwRcspJz3WKYfjGdSdM7Q6RvnjnR+WLlryne8AMJIE/SwPm1SpWCg8UfvPZ YevGLYWy8Rdf+UO+piCZEbSeY4K6ntY5KMUoQ8TPBQIFIQ5k3I411GZ9dB2PzSjAVFAHpGQB+Kq P38z4at6Wnc+h94WjLYXYWMHadN1IIrgNdipN3g+154u6DgmvpvYuGkKy9cr0wTzKWOYR2yPYhb bMUx4fxIzULMOR2ZQF2KevrEriQ0XCEkbSbxyZKV9321kDEfQxEiKdxsyCCjlWrNdm4JUDO9S53 Ew86effFyuVbAzvG0WlQ26Cwb3A== X-Google-Smtp-Source: AGHT+IFR7qj7UEq//1I60zsqGzL3EeC/iFmwTTtM0wb3uPUeUiy9uBOslwTmMwdAtn5jiWKZrTRGHA== X-Received: by 2002:a05:6000:4387:b0:3b8:d79a:6a60 with SMTP id ffacd0b85a97d-3b9e752ca93mr578101f8f.3.1755123230162; Wed, 13 Aug 2025 15:13:50 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:73::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c3b95f4sm48839991f8f.23.2025.08.13.15.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 15:13:49 -0700 (PDT) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: aleksander.lobakin@intel.com, alexanderduyck@fb.com, andrew+netdev@lunn.ch, ast@kernel.org, bpf@vger.kernel.org, corbet@lwn.net, daniel@iogearbox.net, davem@davemloft.net, edumazet@google.com, hawk@kernel.org, horms@kernel.org, john.fastabend@gmail.com, kernel-team@meta.com, kuba@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mohsin.bashr@gmail.com, pabeni@redhat.com, sdf@fomichev.me, vadim.fedorenko@linux.dev Subject: [PATCH net-next V4 8/9] eth: fbnic: Collect packet statistics for XDP Date: Wed, 13 Aug 2025 15:13:18 -0700 Message-ID: <20250813221319.3367670-9-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250813221319.3367670-1-mohsin.bashr@gmail.com> References: <20250813221319.3367670-1-mohsin.bashr@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for XDP statistics collection and reporting via rtnl_link and netdev_queue API. For XDP programs without frags support, fbnic requires MTU to be less than the HDS threshold. If an over-sized frame is received, the frame is dropped and recorded as rx_length_errors reported via ip stats to highlight that this is an error. Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- .../device_drivers/ethernet/meta/fbnic.rst | 11 ++++ .../net/ethernet/meta/fbnic/fbnic_netdev.c | 36 ++++++++++++- drivers/net/ethernet/meta/fbnic/fbnic_txrx.c | 51 +++++++++++++++++-- drivers/net/ethernet/meta/fbnic/fbnic_txrx.h | 1 + 4 files changed, 94 insertions(+), 5 deletions(-) diff --git a/Documentation/networking/device_drivers/ethernet/meta/fbnic.rs= t b/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst index afb8353daefd..fb6559fa4be4 100644 --- a/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst +++ b/Documentation/networking/device_drivers/ethernet/meta/fbnic.rst @@ -160,3 +160,14 @@ behavior and potential performance bottlenecks. credit exhaustion - ``pcie_ob_rd_no_np_cred``: Read requests dropped due to non-post= ed credit exhaustion + +XDP Length Error: +~~~~~~~~~~~~~~~~~ + +For XDP programs without frags support, fbnic tries to make sure that MTU = fits +into a single buffer. If an oversized frame is received and gets fragmente= d, +it is dropped and the following netlink counters are updated + + - ``rx-length``: number of frames dropped due to lack of fragmentation + support in the attached XDP program + - ``rx-errors``: total number of packets with errors received on the in= terface diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c b/drivers/net/e= thernet/meta/fbnic/fbnic_netdev.c index fb81d1a7bc51..b8b684ad376b 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_netdev.c @@ -407,11 +407,12 @@ static void fbnic_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats64) { u64 rx_bytes, rx_packets, rx_dropped =3D 0, rx_errors =3D 0; + u64 rx_over =3D 0, rx_missed =3D 0, rx_length =3D 0; u64 tx_bytes, tx_packets, tx_dropped =3D 0; struct fbnic_net *fbn =3D netdev_priv(dev); struct fbnic_dev *fbd =3D fbn->fbd; struct fbnic_queue_stats *stats; - u64 rx_over =3D 0, rx_missed =3D 0; + unsigned int start, i; =20 fbnic_get_hw_stats(fbd); @@ -489,6 +490,7 @@ static void fbnic_get_stats64(struct net_device *dev, stats64->rx_missed_errors =3D rx_missed; =20 for (i =3D 0; i < fbn->num_rx_queues; i++) { + struct fbnic_ring *xdpr =3D fbn->tx[FBNIC_MAX_TXQS + i]; struct fbnic_ring *rxr =3D fbn->rx[i]; =20 if (!rxr) @@ -500,11 +502,29 @@ static void fbnic_get_stats64(struct net_device *dev, rx_bytes =3D stats->bytes; rx_packets =3D stats->packets; rx_dropped =3D stats->dropped; + rx_length =3D stats->rx.length_errors; } while (u64_stats_fetch_retry(&stats->syncp, start)); =20 stats64->rx_bytes +=3D rx_bytes; stats64->rx_packets +=3D rx_packets; stats64->rx_dropped +=3D rx_dropped; + stats64->rx_errors +=3D rx_length; + stats64->rx_length_errors +=3D rx_length; + + if (!xdpr) + continue; + + stats =3D &xdpr->stats; + do { + start =3D u64_stats_fetch_begin(&stats->syncp); + tx_bytes =3D stats->bytes; + tx_packets =3D stats->packets; + tx_dropped =3D stats->dropped; + } while (u64_stats_fetch_retry(&stats->syncp, start)); + + stats64->tx_bytes +=3D tx_bytes; + stats64->tx_packets +=3D tx_packets; + stats64->tx_dropped +=3D tx_dropped; } } =20 @@ -603,6 +623,7 @@ static void fbnic_get_queue_stats_tx(struct net_device = *dev, int idx, struct fbnic_ring *txr =3D fbn->tx[idx]; struct fbnic_queue_stats *stats; u64 stop, wake, csum, lso; + struct fbnic_ring *xdpr; unsigned int start; u64 bytes, packets; =20 @@ -626,6 +647,19 @@ static void fbnic_get_queue_stats_tx(struct net_device= *dev, int idx, tx->hw_gso_wire_packets =3D lso; tx->stop =3D stop; tx->wake =3D wake; + + xdpr =3D fbn->tx[FBNIC_MAX_TXQS + idx]; + if (xdpr) { + stats =3D &xdpr->stats; + do { + start =3D u64_stats_fetch_begin(&stats->syncp); + bytes =3D stats->bytes; + packets =3D stats->packets; + } while (u64_stats_fetch_retry(&stats->syncp, start)); + + tx->bytes +=3D bytes; + tx->packets +=3D packets; + } } =20 static void fbnic_get_base_stats(struct net_device *dev, diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.c index de3610a7491a..fea4577e38d4 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.c @@ -620,8 +620,8 @@ static void fbnic_clean_twq1(struct fbnic_napi_vector *= nv, bool pp_allow_direct, struct fbnic_ring *ring, bool discard, unsigned int hw_head) { + u64 total_bytes =3D 0, total_packets =3D 0; unsigned int head =3D ring->head; - u64 total_bytes =3D 0; =20 while (hw_head !=3D head) { struct page *page; @@ -633,6 +633,11 @@ static void fbnic_clean_twq1(struct fbnic_napi_vector = *nv, bool pp_allow_direct, twd =3D le64_to_cpu(ring->desc[head]); page =3D ring->tx_buf[head]; =20 + /* TYPE_AL is 2, TYPE_LAST_AL is 3. So this trick gives + * us one increment per packet, with no branches. + */ + total_packets +=3D FIELD_GET(FBNIC_TWD_TYPE_MASK, twd) - + FBNIC_TWD_TYPE_AL; total_bytes +=3D FIELD_GET(FBNIC_TWD_LEN_MASK, twd); =20 page_pool_put_page(nv->page_pool, page, -1, pp_allow_direct); @@ -645,6 +650,18 @@ static void fbnic_clean_twq1(struct fbnic_napi_vector = *nv, bool pp_allow_direct, return; =20 ring->head =3D head; + + if (discard) { + u64_stats_update_begin(&ring->stats.syncp); + ring->stats.dropped +=3D total_packets; + u64_stats_update_end(&ring->stats.syncp); + return; + } + + u64_stats_update_begin(&ring->stats.syncp); + ring->stats.bytes +=3D total_bytes; + ring->stats.packets +=3D total_packets; + u64_stats_update_end(&ring->stats.syncp); } =20 static void fbnic_clean_tsq(struct fbnic_napi_vector *nv, @@ -1040,8 +1057,12 @@ static long fbnic_pkt_tx(struct fbnic_napi_vector *n= v, frag =3D &shinfo->frags[0]; } =20 - if (fbnic_desc_unused(ring) < nsegs) + if (fbnic_desc_unused(ring) < nsegs) { + u64_stats_update_begin(&ring->stats.syncp); + ring->stats.dropped++; + u64_stats_update_end(&ring->stats.syncp); return -FBNIC_XDP_CONSUME; + } =20 page =3D virt_to_page(pkt->buff.data_hard_start); offset =3D offset_in_page(pkt->buff.data); @@ -1181,8 +1202,8 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *= nv, struct fbnic_q_triad *qt, int budget) { unsigned int packets =3D 0, bytes =3D 0, dropped =3D 0, alloc_failed =3D = 0; + u64 csum_complete =3D 0, csum_none =3D 0, length_errors =3D 0; s32 head0 =3D -1, head1 =3D -1, pkt_tail =3D -1; - u64 csum_complete =3D 0, csum_none =3D 0; struct fbnic_ring *rcq =3D &qt->cmpl; struct fbnic_pkt_buff *pkt; __le64 *raw_rcd, done; @@ -1247,6 +1268,8 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *= nv, if (!skb) { alloc_failed++; dropped++; + } else if (skb =3D=3D ERR_PTR(-FBNIC_XDP_LEN_ERR)) { + length_errors++; } else { dropped++; } @@ -1276,6 +1299,7 @@ static int fbnic_clean_rcq(struct fbnic_napi_vector *= nv, rcq->stats.rx.alloc_failed +=3D alloc_failed; rcq->stats.rx.csum_complete +=3D csum_complete; rcq->stats.rx.csum_none +=3D csum_none; + rcq->stats.rx.length_errors +=3D length_errors; u64_stats_update_end(&rcq->stats.syncp); =20 if (pkt_tail >=3D 0) @@ -1359,8 +1383,9 @@ void fbnic_aggregate_ring_rx_counters(struct fbnic_ne= t *fbn, fbn->rx_stats.rx.alloc_failed +=3D stats->rx.alloc_failed; fbn->rx_stats.rx.csum_complete +=3D stats->rx.csum_complete; fbn->rx_stats.rx.csum_none +=3D stats->rx.csum_none; + fbn->rx_stats.rx.length_errors +=3D stats->rx.length_errors; /* Remember to add new stats here */ - BUILD_BUG_ON(sizeof(fbn->rx_stats.rx) / 8 !=3D 3); + BUILD_BUG_ON(sizeof(fbn->rx_stats.rx) / 8 !=3D 4); } =20 void fbnic_aggregate_ring_tx_counters(struct fbnic_net *fbn, @@ -1382,6 +1407,22 @@ void fbnic_aggregate_ring_tx_counters(struct fbnic_n= et *fbn, BUILD_BUG_ON(sizeof(fbn->tx_stats.twq) / 8 !=3D 6); } =20 +static void fbnic_aggregate_ring_xdp_counters(struct fbnic_net *fbn, + struct fbnic_ring *xdpr) +{ + struct fbnic_queue_stats *stats =3D &xdpr->stats; + + if (!(xdpr->flags & FBNIC_RING_F_STATS)) + return; + + /* Capture stats from queues before dissasociating them */ + fbn->rx_stats.bytes +=3D stats->bytes; + fbn->rx_stats.packets +=3D stats->packets; + fbn->rx_stats.dropped +=3D stats->dropped; + fbn->tx_stats.bytes +=3D stats->bytes; + fbn->tx_stats.packets +=3D stats->packets; +} + static void fbnic_remove_tx_ring(struct fbnic_net *fbn, struct fbnic_ring *txr) { @@ -1401,6 +1442,8 @@ static void fbnic_remove_xdp_ring(struct fbnic_net *f= bn, if (!(xdpr->flags & FBNIC_RING_F_STATS)) return; =20 + fbnic_aggregate_ring_xdp_counters(fbn, xdpr); + /* Remove pointer to the Tx ring */ WARN_ON(fbn->tx[xdpr->q_idx] && fbn->tx[xdpr->q_idx] !=3D xdpr); fbn->tx[xdpr->q_idx] =3D NULL; diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h b/drivers/net/eth= ernet/meta/fbnic/fbnic_txrx.h index 0e92d11115a6..873440ca6a31 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h +++ b/drivers/net/ethernet/meta/fbnic/fbnic_txrx.h @@ -90,6 +90,7 @@ struct fbnic_queue_stats { u64 alloc_failed; u64 csum_complete; u64 csum_none; + u64 length_errors; } rx; }; u64 dropped; --=20 2.47.3 From nobody Sat Oct 4 17:29:47 2025 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46D5C2FE067; Wed, 13 Aug 2025 22:13:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123237; cv=none; b=txjhduxFPOTx3XMnxvhcSWFyKCPtA9pROd36ReKjqZr3Mw0ustkIzxQIjYhb2t+tPwaltWazAp1B7vkJ5TGb+aNRpGqACIIF5dXQX7UAoGU8LcLcKewq8FICXFYvJnQ2EFDrM3LZT6Z3vlHsgnOXay0orYMZFVWW5ypxBmyGCpQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755123237; c=relaxed/simple; bh=VTu1YlP6cbBxPd8KlY7/RgMoLKQvCZlYMTO6Lr73lws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cjH8y/RkbTLXSJ4TrsMjEeuT2QhV4JWK+MK/V1et/BaJx+9fDIHv/B4H+mbWe3vtQYxI9qha+wmxN7AZc+q86EFNEqKlnDOypWKEe/8qHz/DF/zHplGRZoAmvOgbS97G6K7Qq+H2/2VOMbajaxLzQdlQKKC31YieLm/IVjEWwTo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RjtgX1a9; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RjtgX1a9" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-45a1b001f55so1374695e9.0; Wed, 13 Aug 2025 15:13:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755123233; x=1755728033; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rtjUK0AZOjm4eF0vnry/hWr4fc/ZinEdNV9kmjIXNAY=; b=RjtgX1a93HGEm3VhOTw/CVWVGuLeDsVdnkMCpQed8DHC+nIzKJVFFs/EqnOQoklQk0 VNfOQPwHLCyLI4ZEsdnDW5K7MlheIP+t7qcd07mZYK4i03kcjhqx9pHwvVUze+VuHeDA Ip3s2SDRpj5JkfvM7GapzPkJaSCRwT52kyVlJP1o2FPiw3xK0lwrRmUTwCkOmAhkRFMu AE0C78fSj8Z3NhxFaBXJdKqVgCxna/H2KQCvoJP6nlyXLrBseUk/kAQhroW9fQhFtHcc etVZplB/LQRsVaCt3rhCezXWrOdbDuoFhBTfJTSc2qqZGtz1rPFCgpsggj+WMpa3BlUx fX/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755123233; x=1755728033; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rtjUK0AZOjm4eF0vnry/hWr4fc/ZinEdNV9kmjIXNAY=; b=DzXvH5qcMwOCfMM8C2onpjcWmvuuVkRWAIdwbMByC+0KT09tedlGRzuh/sh0NZWNh/ bOgHtxDBCB44FUyBZgNib/6th+Tg5Cn4OXqMLpM9ZhUhxUplrFO9BD5Oxna6QLkXR09c yA/e7kjlcC1m+xLWDJUtx+xRy/RI+byFKxXwrIBXz9Z/Srj/0OvkEUi1ojOAhZj5TRdJ PkVyDR6HhgsyQAJUsCgdz4E9qhvzO1i07q6mDfAMHY5Wvtc7sPnzOu6gpLzFtxOVvi+d P3XrittofbWE3jP/mh6ERj8NZU+y39mzpOUH6kaMcvdMXCdqI4vpt67g6NfsgTuDK6qu ozfw== X-Forwarded-Encrypted: i=1; AJvYcCU/ySMAQObuT9NI0sxITyInzIfJOeqpreQKoyv+xDGWqK1GRKc7XWEG4fMRW9Nh2IPV9nkv7GmRUafWwc51@vger.kernel.org, AJvYcCWd6pm86q9uslxwd3gTO4gdEA5bg5P3KFxykdfGoUCbWWX0x2oJSZ6tb/hU1bdtOFYuA1Y=@vger.kernel.org, AJvYcCXrzH+CYv+Dxa//PFIKNnXrIZetToLuoluWioaIH9zL+UecUj4rgZiBPGlzLfwj3bAaAZ5rDo+881bA@vger.kernel.org X-Gm-Message-State: AOJu0Yz1dsiTZeT0nr2Aspij6yPfYaIn3kqx2eYAdymvRoW9vaw8Ga6j ahVfsDmlFpwdb6gxqfR1Wjue2BslNr3ARjp3AU5DdQjFD5R8zUut335C8EAOoSUv X-Gm-Gg: ASbGnct0QR6CYnY8VSYdf3dYZkEw4lniD4Uz8gVxo1OEoAVdbBcC6k6I0wv1CRIKWcp 2nXr1HLgLp38al48BYVRKtQbISc5EFdUVec+3+HOxmaNclGdxr05q6sIOwitPxdo7zjy1eWA3XZ XG/a0VHSfu0xnRWgbjyAVJi/U1bZo90fXG6Z9lmxlsoUxOJVNrIbMo5XGHKHfZB8y906YuMQTHm +wA8vVMTi4wR4NlwBT39Qm0X/xAcZ/y/qgvMpUmxweUKI6UkrEdjy8Ji8r6jejPft8AQy1cbxVP 3P5D/0JntuFx2rDHWdr72wGncNl2iM5EI1pBpW9ytY8os0tAX3j3CM67C1cmIiRjfa8wUNPymvQ raFk7IgSu+q+fPw6WIbrQwYWaTA== X-Google-Smtp-Source: AGHT+IEgB2v+gCGAWANNa3EKMpLphRvnlwapSV7jWPPQcd9HuQt+NoEXnt3jKfFlDc25gkCc0Dio4g== X-Received: by 2002:a05:600c:4f16:b0:442:e9eb:1b48 with SMTP id 5b1f17b1804b1-45a1b65634bmr2958025e9.24.1755123232973; Wed, 13 Aug 2025 15:13:52 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:71::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a1a59019dsm15967745e9.21.2025.08.13.15.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 15:13:52 -0700 (PDT) From: Mohsin Bashir To: netdev@vger.kernel.org Cc: aleksander.lobakin@intel.com, alexanderduyck@fb.com, andrew+netdev@lunn.ch, ast@kernel.org, bpf@vger.kernel.org, corbet@lwn.net, daniel@iogearbox.net, davem@davemloft.net, edumazet@google.com, hawk@kernel.org, horms@kernel.org, john.fastabend@gmail.com, kernel-team@meta.com, kuba@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, mohsin.bashr@gmail.com, pabeni@redhat.com, sdf@fomichev.me, vadim.fedorenko@linux.dev Subject: [PATCH net-next V4 9/9] eth: fbnic: Report XDP stats via ethtool Date: Wed, 13 Aug 2025 15:13:19 -0700 Message-ID: <20250813221319.3367670-10-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250813221319.3367670-1-mohsin.bashr@gmail.com> References: <20250813221319.3367670-1-mohsin.bashr@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support to collect XDP stats via ethtool API. We record packets and bytes sent, and packets dropped on the XDP_TX path. ethtool -S eth0 | grep xdp | grep -v "0" xdp_tx_queue_13_packets: 2 xdp_tx_queue_13_bytes: 16126 Signed-off-by: Jakub Kicinski Signed-off-by: Mohsin Bashir --- .../net/ethernet/meta/fbnic/fbnic_ethtool.c | 50 ++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c b/drivers/net/= ethernet/meta/fbnic/fbnic_ethtool.c index 742b557d0e56..ceb8f88ae41c 100644 --- a/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c +++ b/drivers/net/ethernet/meta/fbnic/fbnic_ethtool.c @@ -112,6 +112,20 @@ static const struct fbnic_stat fbnic_gstrings_hw_q_sta= ts[] =3D { FBNIC_HW_RXB_DEQUEUE_STATS_LEN * FBNIC_RXB_DEQUEUE_INDICES + \ FBNIC_HW_Q_STATS_LEN * FBNIC_MAX_QUEUES) =20 +#define FBNIC_QUEUE_STAT(name, stat) \ + FBNIC_STAT_FIELDS(fbnic_ring, name, stat) + +static const struct fbnic_stat fbnic_gstrings_xdp_stats[] =3D { + FBNIC_QUEUE_STAT("xdp_tx_queue_%u_packets", stats.packets), + FBNIC_QUEUE_STAT("xdp_tx_queue_%u_bytes", stats.bytes), + FBNIC_QUEUE_STAT("xdp_tx_queue_%u_dropped", stats.dropped), +}; + +#define FBNIC_XDP_STATS_LEN ARRAY_SIZE(fbnic_gstrings_xdp_stats) + +#define FBNIC_STATS_LEN \ + (FBNIC_HW_STATS_LEN + FBNIC_XDP_STATS_LEN * FBNIC_MAX_XDPQS) + static void fbnic_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvin= fo) { @@ -422,6 +436,16 @@ static void fbnic_get_rxb_dequeue_strings(u8 **data, u= nsigned int idx) ethtool_sprintf(data, stat->string, idx); } =20 +static void fbnic_get_xdp_queue_strings(u8 **data, unsigned int idx) +{ + const struct fbnic_stat *stat; + int i; + + stat =3D fbnic_gstrings_xdp_stats; + for (i =3D 0; i < FBNIC_XDP_STATS_LEN; i++, stat++) + ethtool_sprintf(data, stat->string, idx); +} + static void fbnic_get_strings(struct net_device *dev, u32 sset, u8 *data) { const struct fbnic_stat *stat; @@ -447,6 +471,9 @@ static void fbnic_get_strings(struct net_device *dev, u= 32 sset, u8 *data) for (i =3D 0; i < FBNIC_HW_Q_STATS_LEN; i++, stat++) ethtool_sprintf(&data, stat->string, idx); } + + for (i =3D 0; i < FBNIC_MAX_XDPQS; i++) + fbnic_get_xdp_queue_strings(&data, i); break; } } @@ -464,6 +491,24 @@ static void fbnic_report_hw_stats(const struct fbnic_s= tat *stat, } } =20 +static void fbnic_get_xdp_queue_stats(struct fbnic_ring *ring, u64 **data) +{ + const struct fbnic_stat *stat; + int i; + + if (!ring) { + *data +=3D FBNIC_XDP_STATS_LEN; + return; + } + + stat =3D fbnic_gstrings_xdp_stats; + for (i =3D 0; i < FBNIC_XDP_STATS_LEN; i++, stat++, (*data)++) { + u8 *p =3D (u8 *)ring + stat->offset; + + **data =3D *(u64 *)p; + } +} + static void fbnic_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *stats, u64 *data) { @@ -511,13 +556,16 @@ static void fbnic_get_ethtool_stats(struct net_device= *dev, FBNIC_HW_Q_STATS_LEN, &data); } spin_unlock(&fbd->hw_stats_lock); + + for (i =3D 0; i < FBNIC_MAX_XDPQS; i++) + fbnic_get_xdp_queue_stats(fbn->tx[i + FBNIC_MAX_TXQS], &data); } =20 static int fbnic_get_sset_count(struct net_device *dev, int sset) { switch (sset) { case ETH_SS_STATS: - return FBNIC_HW_STATS_LEN; + return FBNIC_STATS_LEN; default: return -EOPNOTSUPP; } --=20 2.47.3