From nobody Sat Oct 4 20:52:46 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 B64A92DF3F9; Tue, 12 Aug 2025 22:02:00 +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=1755036122; cv=none; b=CFiYGpocKpY+PW8v5l/4er3fk0VO5r1tqVBpef8YalyVvYOfFLFgzsaAMAKrBCsC3bHky9wDO+Xzcg/pyqyc3MhQJm39jROM+hh2+J+C7hwtWXFyQSZzbvuU3KHkAJ49KuttkhJNTpII48I+VbDelh7Qb1MmUZ7KviWnCtJdd4U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755036122; c=relaxed/simple; bh=diCsuI9hWsPC473mGUixtnjkEdOeHykLqJbaVtFnBMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WrU/jPdmwQTbuGWsG+BCo6ClUF4kBwHomX+6JjmeoUHdGebDb8MEveg5PvZwLYJabmqVsnbqCuIKSBW8Snc1OOpyguoVOCOB75adkk1DCcgIpFhI7Xj956rujIhGKw2DpvMZtsFE5aIBsBwZnL+a4QFM2ZisQF6dzGs8rHI1K/c= 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=VLtYCJsG; 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="VLtYCJsG" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-459ddf83023so36507535e9.0; Tue, 12 Aug 2025 15:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755036119; x=1755640919; 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=VLtYCJsGvAh7tm/6FPSDUwW8jt6pocGHoeB3erpA++8XzrFfgZNRTjED3+Blk7FyTa qZagel0Ka9T1Nz7u+EXahL+ENOeLgUESJrh+drSYCDjmNnCb8EMuImbc8MU2MOzmdGli JqE3P+Fn2lnNex0eyfiER9h/+bN9RKqBuPo9z7aki2tCJcKe6qhsXz1as/wy+So7Yhtt 9XaGWxp1X1timy8mhGDVIBzE0qKu0JrjvqpK3S0T08SckLOWajiT/Xfgru5xs6JnCDyR gVczvyGd/YPhjK+iC+7QtZG5rr+r2DFrZUYUUgjUsZP4nKygrNl9pJy2p4Lk8xM6N8C6 relg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755036119; x=1755640919; 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=LkeFZgRSLNl6X5Moo6SbohwDQXV15DQx8g23ZZ74UF+MAaaErfacm2uHo9xplYX7/R KJyI93P92xOCX5N1aeh/ThGYF93B4WIsTF5iwgjKiw1MU2GxZnPT1w8w1n7MF5RQ/jzH 3yd2wKugOTw3M5icqcOShT9fLPdk03onATWZ63brq5dsFrLl8Huow8CjQh9Yfp5d8Fnf XgNRchCC8zVq8ZpoCUmMzhv9faMrNBEupOh7wnnHfNhQBEoIVnVMKFzz1y04rzgmg9Cz qAYL9h7JzklL09A2ryJLu3O8LkkZvXRWOlWzAw//cZTNd4oQSSgfTURTZAQkPUJcGyCn eAjw== X-Forwarded-Encrypted: i=1; AJvYcCU7zV2D+cz7+KEoriQZp5T5HWkkn3iy1TvX7Er59RBzUc8XAEx45jBlplIcScoy6CRXj3M=@vger.kernel.org, AJvYcCUYqT4qaFppWPEkenpAK60VMVKbmp9exD01iAErNHdTORfwJpEo30VDG6I+vogX1LZ0jmpE8QCqGq8J@vger.kernel.org, AJvYcCXX90qZTdZreSQ7O60bdF0LQedyjscKUpF7bLdgpfX+XX7Q1an7TbCh1wg1JarIzOjcM8MXKyNvKqwxdFTe@vger.kernel.org X-Gm-Message-State: AOJu0YwQAA7OF6wHMZ7XJB/oKE2V4Yl5M3+Pjzk3M3KO3gGGnS/4ipdr 1XVB4/zblspKd3u0hZ7Hv5RbiyERXBYhtZVvHcRs4g3iTKV800RgC9mfTvfyVXMC X-Gm-Gg: ASbGncu/KrELrFMrrdMa65hNwMajaHOfd94yRygZqRqXmsUvcKAPW8GStrfaiSKiBAP /3DEd6+2mFbtQkfNpzGfyRTuWefLX64qrDQpAj2wUDcRdSZHJA963JGnunr1ofXQvHH/DV8+7iX vGH7CfrSKYoezw4L3VUkLHuRX7ZRFeKzMz0jzZIWYkgz1Qb8wP518xpRCf1AocMIXptdwjNwJHT pjtkQLJGW/EDk0Rl+ErmDj6xpkPD0nSUy8VJgVPbMSlh7qbPpUc6CTYMLVJbQ+FMVCHiOTEVc6B 3n3pjlyFLAyuUrGwVx2/no35ME1ofsntY/rT7nDJJOjWfsHnAvut3J5NsHxZ9mixf0GBFrttjlS 4+qEtQDbMFYFLLOT0T2Q= X-Google-Smtp-Source: AGHT+IH3JA4WbqL1N6he/EKnsddNNP6veu13mG8TokVbOj3RbB5aL/gjO0AFzS4DbjR0SKhj6tkppQ== X-Received: by 2002:a05:600c:5246:b0:456:19eb:2e09 with SMTP id 5b1f17b1804b1-45a165b2cb7mr5259715e9.8.1755036118502; Tue, 12 Aug 2025 15:01:58 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:3::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a16de760fsm3399505e9.17.2025.08.12.15.01.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 15:01:57 -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 V3 1/9] eth: fbnic: Add support for HDS configuration Date: Tue, 12 Aug 2025 15:01:42 -0700 Message-ID: <20250812220150.161848-2-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250812220150.161848-1-mohsin.bashr@gmail.com> References: <20250812220150.161848-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 20:52:46 2025 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.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 B0D172E2679; Tue, 12 Aug 2025 22:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755036127; cv=none; b=EKh+dTqdXildR3Ap5CaQEC0aGz8wuPN4qswr/RVcP+t1n17gmSmtqjVY5t9c4Hor0pOULngdjpDH/HA3UvvLpFQ8vOWwr2/LHfDu5eSGlhhtRQzSGS1/n79WNsuHuvdFv9YLZHFEG4vXK4wNKJs6y5CgYIK0RuRxJH0RXcOSe5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755036127; c=relaxed/simple; bh=8nMCVzoU/BearI+JQrhJPJzWNf0Lg3T4RMINzhVG8vg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PoMWqQ09FZyXserd/PcsNISQOwBuQqgkjUm67CkvGa6Mw0GT5IeXFp3/BaZyTp2dr6Gu8OtUvIfV/SRUnDRts6XLhX6/7aq01YmgS/6aqHCIZ9jgCwhXHxCJYHa7AaVejy5jRo6lOpAIR3PC9hpyPaKyLLEzbBwhGwGLHf+xRHI= 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=K08rgSuq; arc=none smtp.client-ip=209.85.128.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="K08rgSuq" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-459ebb6bbdfso37028095e9.0; Tue, 12 Aug 2025 15:02:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755036124; x=1755640924; 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=K08rgSuqLXvbZHgFSfkA7ipQGdescc0zsKWa3rBpj70Na/SJm3MwQzw1KqLLw8s4Bk hF2bi56SSGWmRXF9/ecDAZdUH2V4ZLzSvvTzi7RBRiJCXCRNW9VH9Wbh7RoeTlQ4p6AB RPZBZZ3gVK0S0ZnjwVynLhnwWfcvBNt7Qnngw7Km6aKeyJEJLFdw1VJijg6+GQpCvu6K q2hfmKdVppPOBKYidGG0K69MKtJvII+r1uNPwA2VLkAh3QE77yLAvQG+oEUpO8UVPKKS yw7Fw7XoEvNIOaQTyD+Lo1bzA+EEVYhDpwsX1uHTc9IKZbVkUw4dzJvwMZ9x4Jwy8O/H YGzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755036124; x=1755640924; 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=tayeZXI68DzFm2StRIf2Vn/ivVyVm8p1q9NnGDgBsPzpsTq614a32DepLRyh5TYyjA WU39o6KGlCJ8ZhkZ6OhioS251XjG/sw+2wqwTdxYoGIZUjkHJlkwP3XNEe/SXOCvbRDj 9M+n6h1JmHF24FrROJk4wE3mjz16wSK3Qx1zqct6GqLAuj77n+Zz3H3I1GJtkcjougHB 6LrGztJjz7gs3/tTUO4x/XzgScF83LlmnQt5H2yOnAyi//BgUKTmq8WIPQQD/f+Jx6TT AFu+PScaznHMw6lt+I/6ChVSDUk1luOl0Y+eANaAfP0XKdauW+GBI3us/jKXt6mPI+/1 hqRA== X-Forwarded-Encrypted: i=1; AJvYcCUgnavZeoH3xly82SAV1GmOFcOP/dROjvTgjNa31Xj9LLvJcLNee4rIHUHSSfwbV0gYEuu0i2DOdPW0@vger.kernel.org, AJvYcCVdLtxvqyA+D0/LnzJ2oSaMe0xVmNCujZWdrRJn8XWfbDo+IiHiDkrOF3AzOku7q15rlqlxbOwhIUfkHsOd@vger.kernel.org, AJvYcCXbLhb/DFHVmq9+5wY058mULlootWmmvxv0cXDklyev/0GldmOk7DciPoQ8dqcEsduP3bs=@vger.kernel.org X-Gm-Message-State: AOJu0YyBF0ScIK4prZZ3WK/Izh0GtLejlyMNShWtb0jIHwzI1qEazt/y 5/GLVhQulGxM23DbMwPVmKaVo+zHDqKYzubARXCDKqZmRJ4mF+PcVkY2m9Ccudj+ X-Gm-Gg: ASbGncvT6CWz9xdoPaMpbva32TbqtuJIje0y7o7MN99Idzv+JEe7jyuXBycup5HmX5e Fn88wg+6YiJS5OAoy8Rw7COb0v3mDg6b9VIv3z5dtHQcDcRa4+i+rhbR7RmI+qT1lRdA4Yh1Rqd 7WaL0J7silqizQuEjn+9Rn/jIzSJE4Z88UWgJVO2wb99k/EMSCIDFzVmExS/O3NDXU6oFZh82sl Jw2Iqn75BKcFpaGEs3tbGUnwiZWjeybON5VhydTRw3pFgFFhRYk8icFMKhkHl7Gx+XFxRiHFEhS 4d5FSBUrpiIFndTg8W7UfaLyJEN3vYvFe0ajW37ay6U44oT4uY9KW/fIwd+aqCDuhA3A2KYAYj6 QXLhDLIP6JnBXOEKKVHcZ9x9AWblhn6xS6Xo= X-Google-Smtp-Source: AGHT+IGA+lQaRjauHr/xIfL8afdVo3CJ1CCJYJQ7ehQBK6ony5LTadYXZaduZfT0BcLg0LjCR4h6Rg== X-Received: by 2002:a05:6000:2204:b0:3b9:16a3:cfa9 with SMTP id ffacd0b85a97d-3b917e37acamr355311f8f.18.1755036123552; Tue, 12 Aug 2025 15:02:03 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:2::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c4530a8sm45390167f8f.38.2025.08.12.15.02.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 15:02:01 -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 V3 2/9] eth: fbnic: Update Headroom Date: Tue, 12 Aug 2025 15:01:43 -0700 Message-ID: <20250812220150.161848-3-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250812220150.161848-1-mohsin.bashr@gmail.com> References: <20250812220150.161848-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 20:52:46 2025 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 0E1272D9ECF; Tue, 12 Aug 2025 22:02:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755036130; cv=none; b=BTyah2dOLafcGBdG218U1sSkQklYcYeumCKUVzo6pKv+coIgqKcEkW3HtdsCewQLRsdrvHpnxFcpsa66DKSYanNFf3T48FKjUqA2OoVHZlxBEFYX//j14Q3JwHVMrWSarHyJUJLzdUYDHK2YoUcCRMs52MKS3WWqdHoYmacwBjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755036130; c=relaxed/simple; bh=14Rs9zHg4QyJJlrXCDIaH33G+iRF67OxQsjU8vdMJdo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cw7fHPnOGEIRwX3gWfcSslIFmBjlheUSaT2yN30cWYMJrPLapIcz/DGnSqqQU/B7X8M4GaKgi7KRmPMGxJDao8aqbNjHtfCAvKE9/wTGLlWLnhnamyqZJsX04M8G9jAzFdqhZ7phZthztRI+xhtYcIRoXoi2wu2v0UPUie0P92g= 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=SBiy9oay; arc=none smtp.client-ip=209.85.221.51 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="SBiy9oay" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3b914186705so606743f8f.0; Tue, 12 Aug 2025 15:02:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755036127; x=1755640927; 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=SBiy9oayQA5aPtptex/4L5U+Z8bVc+2OlCHz3eT/C/zvVa0RYWsQ/oDY/cdHO0K32U hy3pH78wCo2noGBQaQBuexO4maEWxjOM3kYgg877Ag7UGjOVB0x85j3817KqbKTMQMli jp4bIxP9/MoYxryGomDugiz0u2zyo1vrZo9GJ/zeuaufPc/zO6gH7RgEVWFkk5jok7Gf lNd/GqLWBJnDVNzFOGxLRKGCik3kOzRrxS+p6GeB5vVN/qSs3fcCTedOoEAUEQrUMk6A uXbX7IcGe+uYEfJ0YX/2ZwYljhD9qRqrkmmM8EJ2jJQa5nEfJe2R1+k4JI2zOMu6vf0+ 1rPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755036127; x=1755640927; 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=nwTzIhdkn3PcxkKKgM/juRjAhXdtpftZxesuj8hXjmGk/UzGccHa7G0L4mXyWJ4Ne7 4Dqj0hDhqSkfLUs9UzfOB1ya36UE3m2yfNESLecdehFBpQRmg8H6JMH/fw5p/JHEY85h jRB60X4nDP9KgA6mGf4GErcB75Bt+kC+nAtB4d/xqL+iSYDBfHNqnnRDf2H0rwLA0qrd WCGkergZmJqaQztt917QMH92zjeGYIixKHnFpS9QquVBHkgEekcPqpTEG/Ew0htuqT+8 VtjISTqOiWV1RWsAGrVoXMZcq5UrIM8qtR/RNwRAXK2pGvRYOoI8nvVkFPorrKf2nFK5 7CKw== X-Forwarded-Encrypted: i=1; AJvYcCVV7GCx3aFgptSjmQ2nr7RcoZYxaJS9NQA2BQObGYg9pKWAU7i077qGwUr+Gue86VvLmUG9XIaSMhCulvri@vger.kernel.org, AJvYcCWzszr1Oil85QZdlUuzXVuDnqWrS1q2XJl17PfbGPdXZMsjMUVLtPbpO1ITFcJIh7bMxIMC2w4kM1i9@vger.kernel.org, AJvYcCX/1pcYmIT3Dr/SIgWtd1t+VPArMPwMpnsRDac5OIbLWTAmvnSVadmVYLLpZOf9csRhaOI=@vger.kernel.org X-Gm-Message-State: AOJu0YyabbMryRJ3OjuXyl4tQa7qqzOh+5W/0g3tymCBLZp7VkG3Qwqp B79LfNxxrqAK1Q38FCrVNTZ2sJXQ010VQtwJw3ghuF7EjvJLamPRC2LUfDDPdxUw X-Gm-Gg: ASbGncvPuu3HcFIp78Pr0tiPfFxabmlYOi4tcZZR5tTgMd7pBRB7GDrZwaobjudFzRZ VZz0eaKkGLc/6l1nU2xbn1/AXq/GGyHTp7uVkIyxLXjiaJFZNZDhm9Hw2Dy49Qad6G1ByYdO3DD yTaO4+3vFEAgD58QED84eqfYdlGxJdUcFWHmiik/zDaPSDkqFl6KX4Ma2ogIyV+SDXVNF+Bdt7F aOGfezwgVjP8+EZ3DJ+AqCKSItK+wnGcwjKUunt+VZG+nrkY7xxoUyWQSsszo18+QGYsHDOyvUx JXjMxo5xgkl1/fJYcEUo6z/J1Fg3aWhX0TH+AA/I/KoNeHaqURUSFJL/yzhH68gkZAWboA/CR0G wIMS+/9C8C3JQNsCKBYA= X-Google-Smtp-Source: AGHT+IE1eFrFWI41ShdEyS5u3/rwanCB94CukprRy2jfe1vfPstlPuhnnCrDpxJ1J9wOgTWV4VjgRQ== X-Received: by 2002:a05:6000:238a:b0:3b9:1697:75f0 with SMTP id ffacd0b85a97d-3b917edccd2mr364804f8f.56.1755036126820; Tue, 12 Aug 2025 15:02:06 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:4::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c3abec8sm47439921f8f.8.2025.08.12.15.02.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 15:02:06 -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 V3 3/9] eth: fbnic: Use shinfo to track frags state on Rx Date: Tue, 12 Aug 2025 15:01:44 -0700 Message-ID: <20250812220150.161848-4-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250812220150.161848-1-mohsin.bashr@gmail.com> References: <20250812220150.161848-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 20:52:46 2025 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 B5CE02E54C4; Tue, 12 Aug 2025 22:02:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755036135; cv=none; b=DpLjJsNw7xbtecdzJaubvxY4NZe3TyDRwp/yga2APmA9Pez643b4e52/5fwbQBpNfTGKcWFA5Hz0cU94iwDkCaBHl+Corvy1F2z3W+y0l6yZsVQHt+zo89RPRMnU/LkVl8WwOChGb9ebr7SMSHEsclxOJQLdA7qgLXrh7H1HSbw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755036135; c=relaxed/simple; bh=C+rBWop/URPtiQRFTVupUQvND7/3bGvm87yBA5TUHBw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bf+a6ECtOc0yclSlw70UrJa/V8/GHi/zSERr82yebHj6CTG21qRz9iXrUbgXTtYFUBSi7auPnN/sRZ/sM++HDR3/ytrKxkyuhit+nD921/i0D4J57QttPpiwBZ5MoiTL9uf0lltqdTYy6tP1BnUW7VxLyISEh3S5MWhgh/E29GU= 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=RrDwHAaW; arc=none smtp.client-ip=209.85.221.41 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="RrDwHAaW" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3b9141866dcso607136f8f.2; Tue, 12 Aug 2025 15:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755036132; x=1755640932; 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=RrDwHAaWxpsGnQsaxfwefxFvozZ0hqEngR4AWZHnpD10Y0G+R895BIIxgFkmPGgRKQ oF0xrFNSw2avcg+Hkdr6jrV5OnaSPiu9VZi0Y+AQ7IjxaSsBISUeJ4wYRqDWcTZky6AR Fc+ZvHbTdD6XRbmmEPdHixzBmAAL5wt+p2vmRRT9P0RJ6ttUWrR35l8eJFXqZ9cyWNwo Ye2JU9HJAiHXZMnOB94rMdPR+n02wanYstAiH9dqjGAwwhabWiFIGqOwANixRrq/8IE2 M8p/KreHRH5sy6GA6VSrz6zOOEWZUVSG7ErJdzJufI9pT6Ytis1dVI7G0YPgnOTI60d8 oTAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755036132; x=1755640932; 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=JnKhdbC/Xtu1tur1S2rIn+wVG4+dr7a07q9GU2Soipajny6kNOVmWvXrrBkYztzNrN 7CdnpBLEpeSY1CQDV8+jrO3Bofw2LDpsTzmXNA2YYvIPvVcgn9KEijf2q/7R6aXdZi/7 4lCOWemX0OjoODEgNoa2ap9M9JmwLBrsTEi9k/aojSGTgxdHC1L7ZZDhtjQ1LHTzbQVo 919sUOBuuHsl1VS6pRn7o3gMm8Wm6YQ09id9BSdgyT+Rd6Mi454SJQkhANiVtxgfOI8A govGK8QV+p9Gb5SuZAJTqg3c7QKJjxU4G/P6QLOF8OxgGuUsvCHhNCYGqxMG9RRDdpGG /ZBA== X-Forwarded-Encrypted: i=1; AJvYcCUs4WKjRgcepMkrdIbWLI/ZC6snnWBSn2kv0TsTHYkcMAzl2ZPzeBNYK3M9LLiHPwfW1uqqqei8CeLY@vger.kernel.org, AJvYcCW5Ec9jtRPOJLDzVHv97aPEpsEeRgKFTRhurPjvo+NqYW3E9vFsY1MmXA+9DImo1R6HjjE=@vger.kernel.org, AJvYcCXMpY6Ewa32Nchlj0M1bTkgTB+ZFISfERZLU2QV1Ire+Q0fAhGt6Ud/zx77mlnbLJsFhSdqMSGFtKIx8AqP@vger.kernel.org X-Gm-Message-State: AOJu0YxFyldyrF6HQXpf7esmmQYx+viTFGydxKTa6MEbISawZwZs3CPB JppRrgDKW3owxbRiWgNQzKOpU7Mpx344a2dxiAy9Z8Wunt2dqrjLDXJhKvNja/BC X-Gm-Gg: ASbGncsf2zHgKSFYbwaBxIp7/vAuVJwoEkhg6liSzFUdq/iLdZ9lgPESGYWxiKYyWyD CnK91qqPNMyoQSapD4cEF7+VGo/Wjbd78SMzsUiogOpLW9Fiyc46couOIdfcRHtd6/r9oBVOQS2 uijAAaZiIZXh28WtqRUqzbvTsdveljjB/5V+eyZYmshUcLjuCs2twGBbNFWpMe+I+c6sVG/AB0S HSg9m9t2zM4nuDqWtJnKOsNdu8Ppcsw23GWvpvyetFHMJl20s4c8EjcAuL6llyNvkuZigkVY6aB k8UNdoidlvjrkQAMcf7Khg0o05p/r2fKkvVgYdYLooko8SbvKsHPXqrCv1gBvD2isMRoqT4EF0k DVTfwkC/1A1/1XQBHPqM= X-Google-Smtp-Source: AGHT+IENcSsdJp2F42ucpThbb2RPVqs1xHfoHyxj5akB4HvjEGq/IvngIbaKJslviRj2/JJl4BRodg== X-Received: by 2002:a05:6000:2083:b0:3a3:7ba5:9618 with SMTP id ffacd0b85a97d-3b917ea04dcmr445770f8f.29.1755036131543; Tue, 12 Aug 2025 15:02:11 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:1::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c469582sm44555966f8f.52.2025.08.12.15.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 15:02:09 -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 V3 4/9] eth: fbnic: Prefetch packet headers on Rx Date: Tue, 12 Aug 2025 15:01:45 -0700 Message-ID: <20250812220150.161848-5-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250812220150.161848-1-mohsin.bashr@gmail.com> References: <20250812220150.161848-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 20:52:46 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 BA6AD2DF3F8; Tue, 12 Aug 2025 22:02:17 +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=1755036141; cv=none; b=l42r+kVHy5yU5o/ozlnnLvXFHRHCQqvW9Vn1GPzBLkHOwZcmKUJzLXtUxxWpZSHcdlgAMkZvSSOauv9xnWL/RkfDYKtOnAYXihbW/nsySL8NPHxf41X0Cc2Xt1LU3ha3bptOtZRttGTR4XG5t3nAgcSf0X6y4fNTJ4XocJhwGlk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755036141; c=relaxed/simple; bh=Q7X/McOJROt+1O6Y5U1wLNV8omQfXEQSD7+POEqQA+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UXGxTue/J12rn3f7S2ciN2hA5kwgXabb0wmEo+DZ/P8HuKUTqeNNiwnhOQ4/nVi9/ncSLATRkAY/R+NZKurZMKa8CoxhoJqpLl2MeHk7bNLon3wWfl+wY88tFEFC+tXadB9AlVeuVa3U3cVDG932v++yef9ho5lr9LOzkwh4jgs= 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=NJDkGoSX; 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="NJDkGoSX" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3b780bdda21so4817764f8f.3; Tue, 12 Aug 2025 15:02:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755036136; x=1755640936; 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=NJDkGoSXu47n0aCtV0Dh6ssEANiDZrx4AlE1VNT/Kwkp2Qy68LM48HWkpFdiXwMx6s Vk7chSQZXr/2pEwwR0ICOixbdWLndPf+neUIjP0MX0CSrI2tUPICOInA3DG62jqT5KHy 3+3gwO6ZVTco+biMQHWra2nnFDBZbQdH0MFdwkgbuqF/FBw6rcx9cVt1VxI1rWbuDg48 UKCNKcw8jvnCXAhylDETqZ/gI1L8E2obuzVmF6VXUvyGTA2rtS9ZlMpTDCBJ+W2JqP1h fHesIS5E/LVkQMX6U0m3aFEv/iaCdmwSAYM1vGz2aWvo1tlmHwZXoY7fVy5rMUpOe1PX BcgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755036136; x=1755640936; 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=dAKY+f5kxRryLmFt/8NdYouhWhZNc5hMuvJuX46HUnfb5oj3LM4i79ykwJm1Ev8RG5 dkhpTzDxPYHNLzmgblcrzi92wek3qNGgfBaixkhWv60bYgP8VRek4k8zgtdBZlTFbMk0 /9/KgcgFoKzMxuE2ApFp69FMNCM0j1qQM+2EjiTm4O4mSf7+65BT8Zm2NTw0HQ/5l3nu hXp3zY8MIFJPMZUpPs2xzrkgMi/H+qfkUfaTvjVP6E9L7nX0CAOH66nbEMDkKHJ9QodZ gTBoaa7gFKddV09SeV25y3vLQSISxro00tEn8clHCC3P0SLMeDwP+TuvdyckaPd6qJ64 75pw== X-Forwarded-Encrypted: i=1; AJvYcCVNV+Onlnipr3gImFsCtDcEWRDwPEXDNmbGBRf+7F/e7zDCawWTW5zGr/tlwBn22QD0i0vi0FrpPQ9Rc9iv@vger.kernel.org, AJvYcCVfR/jeMUqG3049UIRm90qPqyJ1mpBpUtKa84vTGVj5p55kfSO6JH3FjaALes8SFbieW3I=@vger.kernel.org, AJvYcCXvJGWr7j+YLzlLrh0LgbqP9m5SNChRW5SHJvuLyWdLTfsJ4ljAt4P4l/fXQ7cyeU3o6D1kPUOaBpLx@vger.kernel.org X-Gm-Message-State: AOJu0Yyrzlb/BybxE+hHOQNOlF94S3D5Ei2BdKSmoBF73IgQ2gb/h+Vm gEiw5W+QY8IXY6/pDvdiRC6LkRcHhaWct7bDjn2rCTB/C8d4Vo21f2eLImLy6H1L X-Gm-Gg: ASbGncvbMe8x2+bMM/jIos0QnekW+8YPjkLfX2IoivBIi0/qRICdjYspN1hLWnoo/bs azxfDOd2AdufZQOSPqxPExxmvycwXSMuLCo+C6FqKgFsklMk3GPudLcpFMJcWIHtCZU7YmPkSW1 K1IaRk0FhUf4JQNXxVjCF6UpWHoT6SDMr30N44DH13JTH58S/MYTTro9env4wWkJdVs911NW5K6 ecnYSUNNbpiAxNI2K40/3VAaI3jVC7L166sxSjT8iMI3GcGtor4Lt7gO+q2zqp8WSh91Lakrzlg 3RvqBg++JLjiBtWQzhtYTJfSo22z6vbjsKTLycWzgpWHhetFoLrFeIR4y9gXLJ/PHzuhIW7UHaJ hwQ+53FTTRr5vl+w9GIwgivGJS/svFA== X-Google-Smtp-Source: AGHT+IFKJiZDBqpkSZHykuJ4Mvd5/B39ZZf0Cw5i5e0Kn1bw9vCnbT8NvBadU2RnVbM+Cd9CCOauLA== X-Received: by 2002:a05:6000:2882:b0:3b5:e084:283b with SMTP id ffacd0b85a97d-3b917d30e4amr413845f8f.17.1755036135326; Tue, 12 Aug 2025 15:02:15 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:6::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c4533f1sm45960044f8f.42.2025.08.12.15.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 15:02:14 -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 V3 5/9] eth: fbnic: Add XDP pass, drop, abort support Date: Tue, 12 Aug 2025 15:01:46 -0700 Message-ID: <20250812220150.161848-6-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250812220150.161848-1-mohsin.bashr@gmail.com> References: <20250812220150.161848-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 20:52:46 2025 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 CC7DF2D978A; Tue, 12 Aug 2025 22:02:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755036142; cv=none; b=X7kowqayd2sS1ebcf/eIw1aHOYf0Qvvaj7AAb1KiE2w6hXcT9NH0JjkmR5finebINa437BSqoGj3ren5SGVL0bPvShLTafqM2jdsAMTNtBgDm6WJAyNCg73UjzKEUFsQM4vPO8KDkR1JMwAlzgaaqV2rJe9SDlutOBmSsK3UNmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755036142; c=relaxed/simple; bh=z5eh1bKAj+yTKJlbaWakuZx+ew3j2Q9i6btBmoQVet0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WXv5Rjmf/UrmEi923HJ57+j0g4FePWEVZXs+n2qHWTQaQRFCqhxLUWB247k05qXgYew8xyuJzvU31opuHxgAjrGHm/p+4UgOxEDF/x5ovvl9kuAHNXfXi25bUIIKdLGzu/3ae538Y5w8OMapvOHR6A92CqsmoLA0UuNu2SfmW1g= 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=JLHTinSn; arc=none smtp.client-ip=209.85.128.47 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="JLHTinSn" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-458bece40fcso30232965e9.3; Tue, 12 Aug 2025 15:02:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755036139; x=1755640939; 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=JLHTinSnd6s29VYhDuacd9OGdd6JuVGGvt4CKHaPBAXIL0TXgy5okkEccMHlLT0sfN RWiJvVASwhLsRPyIF7y6TPbL0QoD6zmIwvAOuOELN7pdEUCOcEmzVy1EKQK65w41sPgk ACb/8DrVCUhgQ24V0Ro7bqynMfbGJBvWJYfdfUumMPgQt668/6HKMF++gof1nx3WMjhg gX2slBCeHrHomahX2G5jYz83ekp1LxNw2sEAIzng0fY7Dg0Xm5c7nsd/vex1MQaA0q7m uUlzWRatONGhnZlW1BUQsDWTaM7vwQ+p750MH5lw7HQQdc7NeRWJGbT0XpnY+KWiRVlL UJaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755036139; x=1755640939; 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=c3OFfcMFynRgiRhnxGak8ltRZpoFgjujFoinHXxT9OL4rCcIO66+xBd15zXNcSWAGH C5nRv21XYhPB5qzYCyH7i4cS6LF/K5ghY0RrT5D5/HuPzuy61EVwRx07JdfO3tGd8epY 7Lw+WqRrpNQm5W294SOkFWzP4zcobMjnstZq+gJ2mb+hUV3/UFps8mD/WIYiox24j9Pi V81ZBVbsX5KoJXIGHW+sixTmxTs076S/AtkouXQzca5AHGJ8t+r8bsOGgTob7P6rc09G Zm9IYfWC96JDmXenTTI+P8IjlyyBkCMWl+aR2iNcLTDOaO+f0yo3eD/iOGR+IY/B1hfQ 9Aig== X-Forwarded-Encrypted: i=1; AJvYcCVP4+w1mRFVtd1OT4OwnKAAOrizuGJNivmJTgZB9XsPdhTwnt53YGIDxNKFa/xQAJdOBKs=@vger.kernel.org, AJvYcCWmtwyS//JOkWeDNhzOZ4A4478lfKbDs5MdcE9QqlN3pjRGkQzaWZHL56zx9yyzC6aQ6RyVG8gwTiE1SETd@vger.kernel.org, AJvYcCXTNBxd4pSW6HFZHxy+clfvv1J3dqKU/WwRxsT7dedaKvkpYQXfxmFpc5920pBBiRixEH3nzB8QID9V@vger.kernel.org X-Gm-Message-State: AOJu0Ywjq/2KEt8snWOo26AKomu5CkK2LuejCom9vGjAS2Dg0sN8BRH1 KXYm6rANGZoCQM1SjbSaQOKA8L46UWEVYqXXZcsmR529KiRAByFNEmzWhkoOno6c X-Gm-Gg: ASbGnct0sPyTxS0UjVdV3dbHhhekoNgAQ8TWcZYBMAptdSWPWBByFoWxCnkQov+9BsC r6TQ6pzklv3ITsTnzWTrGvjTl2fP7ZevmYw2UEa7n3ip4C/BaGI/Cv5rScNDy+ENwmMn0YaVsus cArxbU7uYYN9NZZntnmVib07P478VSkWL6kfylLL1oUEt8RElf8TozSeiZpnb43EYsNhjh5oY1B RN09bi1K0787/M+anyAIDuPOjC8lmVPN9fz/0eCUfU9krQLIV2y6eBCbv9j8Nw2n+bI1WnZ5OXm Ceno0jCXt5snH2CCOkNr0i3OCBEvCRToD7AGctxqF3nYAB+h5AqoUO1X2fWqhIRcawtyY/WHIVT c7JCso9jl9t7JN6gbDby3P2RGRvPRnFtPOBI= X-Google-Smtp-Source: AGHT+IHhj4iqHQ5uOADV6ceRwSPqogu2NR0Erv3yYYyVUsyLHfwAtdOXYs0vavSGyP/jRdYNtKeNDg== X-Received: by 2002:a05:600c:4f12:b0:455:bd8a:7e7 with SMTP id 5b1f17b1804b1-45a165afa4emr5531795e9.9.1755036138372; Tue, 12 Aug 2025 15:02:18 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:7::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a16dcbcb1sm3632495e9.3.2025.08.12.15.02.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 15:02:17 -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 V3 6/9] eth: fbnic: Add support for XDP queues Date: Tue, 12 Aug 2025 15:01:47 -0700 Message-ID: <20250812220150.161848-7-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250812220150.161848-1-mohsin.bashr@gmail.com> References: <20250812220150.161848-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 20:52:46 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 08C1A2F0687; Tue, 12 Aug 2025 22:21:23 +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=1755037285; cv=none; b=eZ7+guXqP3uiFzuIgAErnQj1A3GpTFpj8yz5ZAy5eOpollUmDsV87pP+Syv1bzMPfnUw0a67AmvzOSsFrno80lSZfnoWz0TPGv9MpywKSr2wYgp0/IZFLRDt2NIG1YjrchDcP1bHRdPt/mxW3tGS01rX0zrFq5VTc36Wjb0w/8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755037285; c=relaxed/simple; bh=YqC55mj2AR86dA7/RdCYznw/7ElZag4idFv+o2F57cw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LZ0HwGOBCLWsINVsA83anP3hBo3A29EuY2N1eaGy38ckkvklFy+XzC2jGwKBdqohcOPi9xqnhxdFVeNbvhdDYG3V6xGbrK/NF9pkUWlODweRtUlTFV25i9A0Hzc9iptS78q01FH9zRe5DoEcVYOgvE9qrhLDhPVyAuJNy3qGdso= 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=h8ek1SLF; 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="h8ek1SLF" Received: by mail-wr1-f49.google.com with SMTP id ffacd0b85a97d-3b7834f2e72so2893934f8f.2; Tue, 12 Aug 2025 15:21:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755037282; x=1755642082; 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=vIdEO3Lv0YC4PSIjYiDP/NYDWSHMj+gKzJ0lri3ow8Y=; b=h8ek1SLFEIm1rVDe/QSc0EYwgeTQ2u/yOhCht5LDFhH/pOikQKVNWeQGY+i4bv4+C0 fRVqC37rjo5FgMaaPoOldfzwBTZ1qnBT+xEROPVV/8QEHhBP4H+j21FJS5nt8OsRGARN 8s9EE5Sg7dUhSie1A7hQZz5kCL/rwgHTFvnfegrwu3NUS73pUYgoc0V/bdCTF243auts IWUmZIG5PHSbpE9+PKWbrbgRg5tN4q9WnQquHd2rMCJOl7x6b4JTjCY/YFoACrt1xZ9/ jbYutS4p+BMl/g2RviSOJMqz2DdBdmtBAye+SBoleBgzzqVe12CF3Dxo4q6S2KVwDz0+ DjTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755037282; x=1755642082; 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=vIdEO3Lv0YC4PSIjYiDP/NYDWSHMj+gKzJ0lri3ow8Y=; b=K8viM9tw9yh5s2IqcafSuvCjvgFC09IRwfenKPOcGjCA+cP9JRXy2BfKy53hqG8OJd iY2TNm2RRKCBT8vzTghkm2Ik2HoqwaWP5QstxPXldRMiEeQy4rZAZoH3r43NjlqckSWm nNpYSlpSSbKP0GqpEn6t2wqUrc27PbnxNPDExMrlj7cBugOMEnvopZE3Bk3V0iwI+SAR TFpYg+gMq3zNmPA3DcGKy08CEJRWnckH/t8VYnCHfa09jEWrPzVjPJKzq0TjNebMQovI XeHhIPHu33OVwIm4HY9372zPNq/G93g+A0AvNSTadI4uh14uc+gDIWMuXQ2ysX9WQ0iM RHkA== X-Forwarded-Encrypted: i=1; AJvYcCUzN0EVz2prO3BkeO8+Ow6e6um3j9I3MaqAeP08H48tmZh33epJ7TFug2nhmgijoxITAIULu36dDLUB@vger.kernel.org, AJvYcCVOeIr/pX6Vzbo2AQiAAvkfdBGUXu9tM6FnVG+3X5ubeS7LD9kgRmPFrZa4lBEmj6/9iTp/r5nlGiDyYZ10@vger.kernel.org, AJvYcCXFbUyOHPJKsILQKFQG1zbPJMYwM/pa0Ngfyl9DLpEBc2Ne9EbjXgSqePR1t89R4Z0uaHQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxYIKCjsOh3f2JPRUy4evrEzaj/ODeJr77Z507v88lhoEN0Hhnu 8GOcUqpqtDUT4nq7XpYZ2uDMAblm1Xzjxuj4Q0o7sAqbTRPTJNSQ05HFF+cuUTtw X-Gm-Gg: ASbGnctaRT7geRDm/Jy7flQGYeoifE2GDX4AOU1hV4h8uwF02G4cIUihhK5mbYPU4B+ 6rWE/G94M7mTWge2SkTquU7HdvXaMJrafIAYhK0G/n+QTZaqShdGPr3DCL70e9YQhwi6xHaryPR 8EMUq6IBZSwodiWmGZf+t2hC4rzw15Esez/yfBmtmrIUxoEQR5d2Yhs7NZMIcz1H47+vNsvo1v6 rZwJJWE0nIBIk3qmxTQDoW2B+7vDnt/0quM4LHRQGgq0WSW3s1NBP26P6UlZ7EDR5e9nNURoqq2 4KWatXLZWEvSD+YWAXW403zH99mJKPFJ9WCYIsW0trvgeMk4Xj/pMnKkh/W5FaRzdZM43DKoHs9 YKlRYBinD7Ar5sMkopdlHkYee X-Google-Smtp-Source: AGHT+IHA5DUl+DA0WohBTVWkK29VWMdgV6UPb962ECdnGiG2D+fadf2fCZ9elXR3p2BKlNnxuRUpxQ== X-Received: by 2002:a5d:5d10:0:b0:3b9:1457:df79 with SMTP id ffacd0b85a97d-3b917d1e6b2mr402840f8f.5.1755037281893; Tue, 12 Aug 2025 15:21:21 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:1::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a16de6f70sm3861605e9.14.2025.08.12.15.21.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 15:21:21 -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 V3 7/9] eth: fbnic: Add support for XDP_TX action Date: Tue, 12 Aug 2025 15:21:18 -0700 Message-ID: <20250812222118.254587-1-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250812220150.161848-1-mohsin.bashr@gmail.com> References: <20250812220150.161848-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..3ce1762bd11d 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 (PTR_ERR(skb) =3D=3D -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 20:52:46 2025 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 5623027604E; Tue, 12 Aug 2025 22:22:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755037380; cv=none; b=VDMWZcWJZ9eO98BmBswBrdwVmz5WXMjO1jvdDQoJp15A9b8oYsPKW8DsuWtYWPcYnsCm6qGG6QZzMAKItVjTR2VDNWqL25gNdM7XeIZ5ZkCzzfowf2Wq5PiJ/J02ajSYveRM+/ck/wDbKX2jH/P/h+CkVgms8LFG6AZU53mRvAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755037380; c=relaxed/simple; bh=+sFQSTHIOhzJPPTHZ6mF3BRYYIb5lhP24qtZkAGLV1s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=otqOSj2J6Se+oiFEWwrVU+T8RIH+a5bwlcikhFAxLVxX/Eelrx3IYm5H/Y6mFGdPUH757f9oDFdhEKsIx4zY4+kAlKj6q0pMmebUJSKbybDbAj7SjtxaQ7KIjPTfC//ig9y2M0d1V0vD/cuEbVLSVEGUXxNFAWQ7QFYqIbDKVR4= 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=WtVn9Sm1; arc=none smtp.client-ip=209.85.221.53 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="WtVn9Sm1" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3b78d13bf10so6032179f8f.1; Tue, 12 Aug 2025 15:22:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755037376; x=1755642176; 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=WS7bmnIloASKqNj5zXPdW4P/ppO3Xb5AJCzOr3LRULg=; b=WtVn9Sm1er9w2S2dhCRa/YPxh+NukpEh4fzb1d75371b+ezHkXCoG9yiMcDd1r1UOX j59vCquJEQdmw7CHpjo75AhgAujBBkIGrGwdMKcwFXB2AV0WZYKJSYZBoqw08gptG9oS Awjpq3/xPyW7Lc3SE/A45oGuuiJ0prQnJ1VOXncJQzZy7FJI9y6sqFwQvrpknA9JmMV3 aV6YNgm6XP6IQewbN7XJ0InYRYZj+0OQv7p3hNZi1Wo1fjlmaPuBH9YXN1lu7+SM1LaT AobkHNPpE9tgt4K7ewmspC2c3/iyvg0IeiU5NnXCPR9EoeVDEbjedKejRcVx1aCO4X22 y3PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755037376; x=1755642176; 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=WS7bmnIloASKqNj5zXPdW4P/ppO3Xb5AJCzOr3LRULg=; b=QOvaLXeMLleuJ2B9/8Cz1v58Z+yzwuU/XgAEQrgtHXifHECNgNjCAVSFMbylGFFApU z2s8lXtVrUXdFBo2lSxoowDFPtqMTifNn9XcsSypR1S9eA+Y/pE8KR06+MkCRrS3hlk+ w2upGskl2GQrbZGBGTEgqnz+ZF8e+rrjWSeTfAgeRYPa0UkuCLb0RiwBDPWjyDp6CwUC /NQI5EGBHAe95JFTQDucw7jX4AG+CRBBxTfUr/CsSfVyqA0fnrebcdH50+x43o8kW8IB itszekPeNSVkmpR6PRgLeNNrpI7y4QDR5sC7Y65Naf5RX4GdfyURN4MBkWt4BZb3sedI oFkg== X-Forwarded-Encrypted: i=1; AJvYcCWkgUfxcn7/DeugyhQbJ5NFHTgsrYRZsW3cg493wdwSJQxWedU4HdyyikTls1OoQHx7HuUnIsuxjjjl@vger.kernel.org, AJvYcCWt2WptgWUGy+3uD2q5e9nNHEQOyRFe+7/UE3v4Dof6vRimJEvr5desBML/LgLFp8UK8/I=@vger.kernel.org, AJvYcCXyIhBYvmO9SYnZ6JQetBtiNU1cXJDXPDQVvDoqxVvxneZX9TruQF1fEi9xtaH1SD0ZusxaoWOfognOz6iM@vger.kernel.org X-Gm-Message-State: AOJu0YzcOiPUusywhPMHL95Awffl6a9me7HMXAiobpVT6bEk3UdX9EjM J9lHRqVsmrmoW6AWp1vMO03zMot3tx5BBiHxdx0SyEP5xmHHmvU68J3keFhDxRtQ X-Gm-Gg: ASbGncuv3FneQ0lZ8kENhFRt+K7QW3yLQ6O0h0jvYhg6JRlr4ZZvCOR4JTpAGfYjEd5 D4/6mFpPr9NP1R4iRQ/Q8t7iWUGFuZQ40yrZX3AR5D/qcKVKs+j7frZUGh7elcN2zsBC8jW+U5u iBCE1RZUB0qS7wJk6JxMHHOX59KWp27xHqbYTVPLfG5kkq1Ad+f1lB9X4RjblQt6fZeEJdKuxIL zHu362iMhqPYESKKbGCNamqko4ZhGZp/8+QxyiBsZDb8854kqjOosAhP55nrsv0eDcVHpnvmK05 Z4yvkgeqZSJiaXRwUTR0a3q/573XNk8wYqwPql+pikUP/zUSEIrKrEbSE5qbY6BrH55+1dnBqfY eskyXo40eQuWJSqSvPc3h X-Google-Smtp-Source: AGHT+IGRW8XazU5RzfUKZN+cRS1p89FzfLhMPSsUMxnRANlZxTviQk72arFfrz8BYdCTYEyuoMn1Jg== X-Received: by 2002:a5d:5f56:0:b0:3b7:6828:5f78 with SMTP id ffacd0b85a97d-3b917e2da18mr371805f8f.4.1755037375963; Tue, 12 Aug 2025 15:22:55 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:70::]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45a16dffb63sm3812225e9.29.2025.08.12.15.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 15:22:55 -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 V3 8/9] eth: fbnic: Collect packet statistics for XDP Date: Tue, 12 Aug 2025 15:22:52 -0700 Message-ID: <20250812222252.261779-1-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250812220150.161848-1-mohsin.bashr@gmail.com> References: <20250812220150.161848-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 3ce1762bd11d..fd22e8f83962 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 (PTR_ERR(skb) =3D=3D -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 20:52:46 2025 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.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 DFB21280308; Tue, 12 Aug 2025 22:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755037465; cv=none; b=FafWQNMUOkHNwyBeXjLd8tOUr8mbvTSAHi1xhr+bQkVmqAI3EhOc+7SIp+fzYm0A2CcvuTONwK0yK4nobXUTb1t7isctUlmOjJPZ+ysV7GtirP/9VDF/9DZzOdzt9sexOQNlsXyF8HMQpjw6tzcQbVZDAd/HQTs0yNEe99C5HQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755037465; c=relaxed/simple; bh=VTu1YlP6cbBxPd8KlY7/RgMoLKQvCZlYMTO6Lr73lws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kJ/8AtMQ1kRi/7mVZBGK3giJque5zDKQdno4k0N21paFr0WTaXk4yLMSlP1szm2li/NweLdK3UcPAp6f5fDr8kiLhKiJVCRfvdEyatFLmc98qHxXCTWB92KEweCzWnY4ErSvtYj8MxpfCINtdcCKOZIv2WvOHJlxfX1LkZ6+cq4= 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=UsgG2lN0; arc=none smtp.client-ip=209.85.221.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="UsgG2lN0" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-3b783ea502eso203346f8f.1; Tue, 12 Aug 2025 15:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755037462; x=1755642262; 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=UsgG2lN0/dfvuiGD/r5glWiHVrG4l89saV+mlnzWnKFzmWWfFufR+ttIQPnxpwoTuK Xz4/VHGXDCCFZyoxXOcsYB36Wck3M0v2TzVxKzI87M58bJOrsPvDXPyeOWtigvfp6TPC k/i5ilA+ePGDSKJBp5IlTI+TBe7n7OwSdW43/bhUaxk65sB35FhSxL5R64J0myrBFMdp /ODx6S+LIoVfKqg+CuMxydF+3BvqxaxvF/Rh6oO8FuF8uMsGZqat9TbZXUciQZ+2aO5r 6blGBtVOavLwBOkRZhfE5gQ+4/exWFbt8EHIpPZ6VgTWGkPy0yks4wtnvR4RryW0PCxh XVtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755037462; x=1755642262; 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=Jy0kVZOLv6cZgF/rd+Xje4arfcQAK1N3xFlktuQBFrlHo+khivCawW9kSMisB+eZKe sGReooHIRzrftzvEsl5pJHPeijr1ZnKvEqGm7/gq1nFpAqwKmx1C5lMW+cDBvM5XSutR w/UTeqs19NoSdvNhdIjnA6eGeSSL1kpYy3m6+jhXv3SceJxsEeI2SZmg8ub5AiuBeaJD z/MdcSbZDmmiQLwAhia2RUQcumLXzMWvZV0mVBrGw9pAU+C/lRphYwnm+ZHDICHh6iqe uR1LG/x6qwsfp807Q834F+nZ+tiaCBrvAiBLOtHqGT3VECYye3UnXsXLTe+REImts6MY evwQ== X-Forwarded-Encrypted: i=1; AJvYcCU26KLfefZxtdrid992cL40r7mUKF/drLukWXnbj4vXvSNeqql/R0l7VnecEZjwUGC5KWw=@vger.kernel.org, AJvYcCVBTCaX7FMNyorDmaboS17h084f8ea8YKVqjlnJJZRVYZQ7GvAtA6nz1oSgFdLCash3GiDHLQuyPf/m@vger.kernel.org, AJvYcCWI3mGJrhAHMFlAZlaS29x5jOfEMts4K+loweGnVBW9gZn5cJwfPp37Oo25gsud7CRu4biFZd315jMkkvog@vger.kernel.org X-Gm-Message-State: AOJu0YxE8e5Zu+HfDuK5YSHgaEhirWFNHt+39FGQjR9tuXmjPFU3gBp8 yX2XTnstzG3jetGIt6MUHCCDdCluiYQVVNI1tYH7jw3h6qR8WJHWm9YdKBIZM3LB X-Gm-Gg: ASbGncsu4O/9fpdBv2cLXQ4wM4DcddjS01qpGSD6eLEVhmVPoGfF1Kwzw3M0x6onJrL ZscYl2Ej+VSA2P3CLZ+McaG4tP5eQoykP9xgKTeAsGkgmQvavgoD//V2sZ1CBoWBL8ngYWBgErn 6ex2HsjtwTmdzuiQ1fKAGKk4D9wYk3t1cB5U0cdzEGuup/lcM7x3A+LzdGhMKdEUn/4wdb9pnPg ipk+EC0D7gQYy/EvCH8IhsCWKu0FzmC8NobtWo+BUalXaSQH/FYomO55FEeaOOIVlHReVz6EsTA aMN+VcQvvYaeIu7SPQ1qtyM/L9Rsk4kqKsX+53FXC+8zkdFwEILYZxzaBdFLmaIrCgWgeuWzIv5 KfSCjIa6SD12uZ31sDUfKHH45jKRwv80Vf88= X-Google-Smtp-Source: AGHT+IHJr9x4tPHQB488BcmKjtF7JFP/uv+eKfUyu+Ss45vTGSVkFV0Ahpktarr49m9/oxGrmVivog== X-Received: by 2002:a05:6000:3107:b0:3b9:16e5:bd38 with SMTP id ffacd0b85a97d-3b918c4cebcmr138431f8f.4.1755037461620; Tue, 12 Aug 2025 15:24:21 -0700 (PDT) Received: from localhost ([2a03:2880:31ff:2::]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b79c3abedesm46018339f8f.3.2025.08.12.15.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Aug 2025 15:24:19 -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 V3 9/9] eth: fbnic: Report XDP stats via ethtool Date: Tue, 12 Aug 2025 15:24:17 -0700 Message-ID: <20250812222417.268420-1-mohsin.bashr@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250812220150.161848-1-mohsin.bashr@gmail.com> References: <20250812220150.161848-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