Skip to contentSkip to conversation

bnxt_en: implement device memory TCP for bnxt

PATCH Superseded Taehee Yoo 5 participants 32 messages Oct 22, 2024 – Feb 19, 2025

Subsystems (7)

v4 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Taehee Yoo

author
#0 lore raw

v4 cover bnxt_en: implement device memory TCP for bnxt

This series implements device memory TCP for bnxt_en driver and necessary ethtool command implementations.

NICs that use the bnxt_en driver support tcp-data-split feature named HDS(header-data-split).
But there is no implementation for the HDS to enable/disable by ethtool. Only getting the current HDS status is implemented and the HDS is just automatically enabled only when either LRO, HW-GRO, or JUMBO is enabled. The hds_threshold follows the rx-copybreak value but it wasn't changeable.

Currently, bnxt_en driver enables tcp-data-split by default but not always work.
There is hds_threshold value, which indicates that a packet size is larger than this value, a packet will be split into header and data. hds_threshold value has been 256, which is a default value of rx-copybreak value too.
The rx-copybreak value hasn't been allowed to change so the hds_threshold too.

This patchset decouples hds_threshold and rx-copybreak first. and make tcp-data-split, rx-copybreak, and header-data-split-thresh configurable independently.

But the default configuration is the same. The default value of rx-copybreak is 256 and default header-data-split-thresh is also 256.

There are several related options.
TPA(HW-GRO, LRO), JUMBO, jumbo_thresh(firmware command), and Aggregation Ring.

The aggregation ring is fundamental to these all features. When gro/lro/jumbo packets are received, NIC receives the first packet from the normal ring.
follow packets come from the aggregation ring.

These features are working regardless of HDS.
When TPA is enabled and HDS is disabled, the first packet contains header and payload too.
and the following packets contain payload only.
If HDS is enabled, the first packet contains the header only, and the following packets contain only payload.
So, HW-GRO/LRO is working regardless of HDS.

There is another threshold value, which is jumbo_thresh.
This is very similar to hds_thresh, but jumbo thresh doesn't split header and data.
It just split the first and following data based on length. When NIC receives 1500 sized packet, and jumbo_thresh is 256(default, but follows rx-copybreak),
the first data is 256 and the following packet size is 1500-256.

Before this patch, at least if one of GRO, LRO, and JUMBO flags is enabled, the Aggregation ring will be enabled.
If the Aggregation ring is enabled, both hds_threshold and jumbo_thresh are set to the default value of rx-copybreak.

So, GRO, LRO, JUMBO frames, they larger than 256 bytes, they will be split into header and data if the protocol is TCP or UDP. for the other protocol, jumbo_thresh works instead of hds_thresh.

This means that tcp-data-split relies on the GRO, LRO, and JUMBO flags. But by this patch, tcp-data-split no longer relies on these flags. If the tcp-data-split is enabled, the Aggregation ring will be enabled.
Also, hds_threshold no longer follows rx-copybreak value, it will be set to the header-data-split-thresh value by user-space, but the default value is still 256.

If the protocol is TCP or UDP and the HDS is disabled and Aggregation ring is enabled, a packet will be split into several pieces due to jumbo_thresh.

When single buffer XDP is attached, tcp-data-split is automatically disabled.

LRO, GRO, and JUMBO are tested with BCM57414, BCM57504 and the firmware version is 230.0.157.0.
I couldn't find any specification about minimum and maximum value of hds_threshold, but from my test result, it was about 0 ~ 1023. It means, over 1023 sized packets will be split into header and data if tcp-data-split is enabled regardless of hds_treshold value. When hds_threshold is 1500 and received packet size is 1400, HDS should not be activated, but it is activated.
The maximum value of header-data-split-thresh value is 256 because it has been working. It was decided very conservatively.

I checked out the tcp-data-split(HDS) works independently of GRO, LRO, JUMBO. Tested GRO/LRO, JUMBO with enabled HDS and disabled HDS. Also, I checked out tcp-data-split should be disabled automatically when XDP is attached and disallowed to enable it again while XDP is attached. I tested ranged values from min to max for header-data-split-thresh and rx-copybreak, and it works. header-data-split-thresh from 0 to 256, and rx-copybreak 65 to 256. When testing this patchset, I checked skb->data, skb->data_len, and nr_frags values.

By this patchset, bnxt_en driver supports a force enable tcp-data-split, but it doesn't support for disable tcp-data-split.
When tcp-data-split is explicitly enabled, HDS works always. When tcp-data-split is unknown, it depends on the current configuration of LRO/GRO/JUMBO.

The first patch implements .{set, get}_tunable() in the bnxt_en. The bnxt_en driver has been supporting the rx-copybreak feature but is not configurable, Only the default rx-copybreak value has been working. So, it changes the bnxt_en driver to be able to configure the rx-copybreak value.

The second patch adds an implementation of tcp-data-split ethtool command.
The HDS relies on the Aggregation ring, which is automatically enabled when either LRO, GRO, or large mtu is configured.
So, if the Aggregation ring is enabled, HDS is automatically enabled by it.

The third patch adds header-data-split-thresh command in the ethtool. This threshold value indicates if a received packet size is larger than this threshold, the packet's header and payload will be split. Example:

   # ethtool -G <interface name> header-data-split-thresh <value>
This option can not be used when tcp-data-split is disabled or not
supported.
   # ethtool -G enp14s0f0np0 tcp-data-split on header-data-split-thresh 256
   # ethtool -g enp14s0f0np0
   Ring parameters for enp14s0f0np0:
   Pre-set maximums:
   ...
   Current hardware settings:
   ...
   TCP data split:         on
   Header data split thresh:  256

The fourth patch adds the implementation of header-data-split-thresh logic in the bnxt_en driver.
The default value is 256, which used to be the default rx-copybreak value.

The fifth and sixth add condition checks for devmem and ethtool. If tcp-data-split is disabled or threshold value is not zero, setup of devmem will be failed.
Also, tcp-data-split and header-data-split-thresh will not be changed while devmem is running.

The sixth patch adds netmem_is_pfmemalloc() helper function.

The last patch implements device memory TCP for bnxt_en driver. It usually converts generic page_pool api to netmem page_pool api.

No dependencies exist between device memory TCP and GRO/LRO/MTU. Only tcp-data-split and header-data-split-thresh should be enabled when the device memory TCP.
While devmem TCP is set, tcp-data-split and header-data-split-thresh can't be updated because core API disallows change.

I tested the interface up/down while devmem TCP running. It works well. Also, channel count change, and rx/tx ringsize change tests work well too.

The devmem TCP test NIC is BCM57504

All necessary configuration validations exist at the core API level.

Current page_pool fails if drivers pass PP_FLAG_ALLOW_UNREADABLE_NETMEM | PP_FLAG_DMA_SYNC_DEV.
This is going to be fixed by Mina.

v4:
- Remove min rx-copybreak value.
- Do not support a disable of tcp-data-split by bnxt_en driver.
- Rename from tcp-data-split-thresh to header-data-split-thresh.
- Add ETHTOOL_RING_USE_HDS_THRS flag.
- Add dev_xdp_sb_prog_count() helper.
- Reduce hole in struct bnxt.
- Use ETHTOOL_RING_USE_HDS_THRS in bnxt_en driver.
- Improve condition check.
- Add netdev_devmem_enabled() helper.
- Add netmem_is_pfmemalloc() helper.
- Do not select NET_DEVMEM in Kconfig for bnxt_en driver.
- Pass PP_FLAG_ALLOW_UNREADABLE_NETMEM flag unconditionally.
- Use gfp flag in __bnxt_alloc_rx_netmem() in the last patch.
- Do not add *offset in the __bnxt_alloc_rx_netmem() in the last patch.
- Do not pass queue_idx to bnxt_alloc_rx_page_pool() in the last patch.
- Add Test tag from Stanislav.
- Add Review tag from Brett.
- Add page_pool_recycle_direct_netmem() helper

v3:
- Change headline
- Add condition checks for ethtool and devmem
- Fix documentation
- Move validation of tcp-data-split and thresh from dirver to core API
- Add implementation of device memory TCP for bnxt_en driver

v2:
- Add tcp-data-split-thresh ethtool command
- Implement tcp-data-split-threh in the bnxt_en driver
- Define min/max rx-copybreak value
- Update commit message

Taehee Yoo (8):
bnxt_en: add support for rx-copybreak ethtool command
bnxt_en: add support for tcp-data-split ethtool command
net: ethtool: add support for configuring header-data-split-thresh
bnxt_en: add support for header-data-split-thresh ethtool command
net: devmem: add ring parameter filtering
net: ethtool: add ring parameter filtering
net: netmem: add netmem_is_pfmemalloc() helper function
bnxt_en: add support for device memory tcp

 Documentation/netlink/specs/ethtool.yaml      |   8 +
 Documentation/networking/ethtool-netlink.rst  |  79 ++++---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c     | 212 +++++++++++++-----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  14 +-
 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c |  66 +++++-
 include/linux/ethtool.h                       |   6 +
 include/linux/netdevice.h                     |   1 +
 include/net/netdev_rx_queue.h                 |  14 ++
 include/net/netmem.h                          |   8 +
 include/net/page_pool/helpers.h               |   6 +
 include/uapi/linux/ethtool_netlink.h          |   2 +
 net/core/dev.c                                |  13 ++
 net/core/devmem.c                             |  18 ++
 net/ethtool/common.h                          |   1 +
 net/ethtool/netlink.h                         |   2 +-
 net/ethtool/rings.c                           |  50 ++++-
 16 files changed, 402 insertions(+), 98 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v4 1/8 bnxt_en: add support for rx-copybreak ethtool command

The bnxt_en driver supports rx-copybreak, but it couldn't be set by userspace. Only the default value(256) has worked.
This patch makes the bnxt_en driver support following command. ethtool --set-tunable <devname> rx-copybreak <value> and ethtool --get-tunable <devname> rx-copybreak.

---

v4:
- Remove min rx-copybreak value.
- Add Review tag from Brett.
- Add Test tag from Stanislav.

v3:
- Update copybreak value after closing nic and before opening nic when the device is running.

v2:
- Define max/vim rx_copybreak value.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c     | 23 +++++----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  5 +-
 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 48 ++++++++++++++++++-
 3 files changed, 65 insertions(+), 11 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +14 -9
index bda3742d4e32..0f5fe9ba691d 100644
@@ -81,7 +81,6 @@ MODULE_DESCRIPTION("Broadcom NetXtreme network driver");
 
 #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
 #define BNXT_RX_DMA_OFFSET NET_SKB_PAD
-#define BNXT_RX_COPY_THRESH 256
 
 #define BNXT_TX_PUSH_THRESH 164
 
@@ -1330,13 +1329,13 @@ static struct sk_buff *bnxt_copy_data(struct bnxt_napi *bnapi, u8 *data,
 	if (!skb)
 		return NULL;
 
-	dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh,
+	dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copybreak,
 				bp->rx_dir);
 
 	memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN,
 	       len + NET_IP_ALIGN);
 
-	dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh,
+	dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copybreak,
 				   bp->rx_dir);
 
 	skb_put(skb, len);
@@ -1829,7 +1828,7 @@ static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
 		return NULL;
 	}
 
-	if (len <= bp->rx_copy_thresh) {
+	if (len <= bp->rx_copybreak) {
 		skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping);
 		if (!skb) {
 			bnxt_abort_tpa(cpr, idx, agg_bufs);
@@ -2162,7 +2161,7 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
 		}
 	}
 
-	if (len <= bp->rx_copy_thresh) {
+	if (len <= bp->rx_copybreak) {
 		if (!xdp_active)
 			skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr);
 		else
@@ -4451,6 +4450,11 @@ void bnxt_set_tpa_flags(struct bnxt *bp)
 		bp->flags |= BNXT_FLAG_GRO;
 }
 
+static void bnxt_init_ring_params(struct bnxt *bp)
+{
+	bp->rx_copybreak = BNXT_DEFAULT_RX_COPYBREAK;
+}
+
 /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
  * be set on entry.
  */
@@ -4465,7 +4469,6 @@ void bnxt_set_ring_params(struct bnxt *bp)
 	rx_space = rx_size + ALIGN(max(NET_SKB_PAD, XDP_PACKET_HEADROOM), 8) +
 		SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
 
-	bp->rx_copy_thresh = BNXT_RX_COPY_THRESH;
 	ring_size = bp->rx_ring_size;
 	bp->rx_agg_ring_size = 0;
 	bp->rx_agg_nr_pages = 0;
@@ -4510,7 +4513,8 @@ void bnxt_set_ring_params(struct bnxt *bp)
 				  ALIGN(max(NET_SKB_PAD, XDP_PACKET_HEADROOM), 8) -
 				  SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
 		} else {
-			rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
+			rx_size = SKB_DATA_ALIGN(bp->rx_copybreak +
+						 NET_IP_ALIGN);
 			rx_space = rx_size + NET_SKB_PAD +
 				SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
 		}
@@ -6424,8 +6428,8 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 					  VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
 		req->enables |=
 			cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-		req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
-		req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
+		req->jumbo_thresh = cpu_to_le16(bp->rx_copybreak);
+		req->hds_threshold = cpu_to_le16(bp->rx_copybreak);
 	}
 	req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
 	return hwrm_req_send(bp, req);
@@ -15865,6 +15869,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	bnxt_init_l2_fltr_tbl(bp);
 	bnxt_set_rx_skb_mode(bp, false);
 	bnxt_set_tpa_flags(bp);
+	bnxt_init_ring_params(bp);
 	bnxt_set_ring_params(bp);
 	bnxt_rdma_aux_device_init(bp);
 	rc = bnxt_set_dflt_rings(bp, true);
drivers/net/ethernet/broadcom/bnxt/bnxt.h +4 -1
index 69231e85140b..1b83a2c8027b 100644
@@ -34,6 +34,9 @@
 #include <linux/firmware/broadcom/tee_bnxt_fw.h>
 #endif
 
+#define BNXT_DEFAULT_RX_COPYBREAK 256
+#define BNXT_MAX_RX_COPYBREAK 1024
+
 extern struct list_head bnxt_block_cb_list;
 
 struct page_pool;
@@ -2299,7 +2302,7 @@ struct bnxt {
 	enum dma_data_direction	rx_dir;
 	u32			rx_ring_size;
 	u32			rx_agg_ring_size;
-	u32			rx_copy_thresh;
+	u32			rx_copybreak;
 	u32			rx_ring_mask;
 	u32			rx_agg_ring_mask;
 	int			rx_nr_pages;
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +47 -1

66 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH net-next v4 1/8] bnxt_en: add support for rx-copybreak ethtool command

Quoted 35 lines · Taehee Yoo

The bnxt_en driver supports rx-copybreak, but it couldn't be set by userspace. Only the default value(256) has worked.
This patch makes the bnxt_en driver support following command. ethtool --set-tunable <devname> rx-copybreak <value> and ethtool --get-tunable <devname> rx-copybreak.

---

v4:
- Remove min rx-copybreak value.
- Add Review tag from Brett.
- Add Test tag from Stanislav.

v3:
- Update copybreak value after closing nic and before opening nic when the device is running.

v2:
- Define max/vim rx_copybreak value.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c     | 23 +++++----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  5 +-
 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 48 ++++++++++++++++++-
 3 files changed, 65 insertions(+), 11 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
index bda3742d4e32..0f5fe9ba691d 100644

drivers/net/ethernet/broadcom/bnxt/bnxt.c void bnxt_set_ring_params(struct bnxt *bp) · line 4517

Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
@@ -4510,7 +4513,8 @@ void bnxt_set_ring_params(struct bnxt *bp)
                                  ALIGN(max(NET_SKB_PAD, XDP_PACKET_HEADROOM), 8) -
                                  SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
                } else {
-                       rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
+                       rx_size = SKB_DATA_ALIGN(bp->rx_copybreak +
+                                                NET_IP_ALIGN);

When rx_copybreak is 0 or very small, rx_size will be very small and will be a problem. We need rx_size to be big enough to contain the packet header, so rx_size cannot be below some minimum (256?).

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6432

Quoted 11 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -2
                        rx_space = rx_size + NET_SKB_PAD +
                                SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
                }
@@ -6424,8 +6428,8 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
-               req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
+               req->jumbo_thresh = cpu_to_le16(bp->rx_copybreak);
+               req->hds_threshold = cpu_to_le16(bp->rx_copybreak);

Similarly, these thresholds should not go to 0 when rx_copybreak becomes small.

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_run_loopback(struct bnxt *bp) · line 4816

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -1
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
        return hwrm_req_send(bp, req);
@@ -4769,7 +4813,7 @@ static int bnxt_run_loopback(struct bnxt *bp)
        cpr = &rxr->bnapi->cp_ring;
        if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
                cpr = rxr->rx_cpr;
-       pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh);
+       pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copybreak);

The loopback test will also not work if rx_copybreak is very small. I think we should always use 256 bytes for the loopback test packet size. Thanks.

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
        skb = netdev_alloc_skb(bp->dev, pkt_size);
        if (!skb)
                return -ENOMEM;
author
#3 lore raw

Re: [PATCH net-next v4 1/8] bnxt_en: add support for rx-copybreak ethtool command

On Thu, Oct 24, 2024 at 3:41 PM Michael Chan

Hi Michael,
Thank you so much for the review!

Quoted 66 lines · <[email protected]> wrote:
Quoted 35 lines · Taehee Yoo

The bnxt_en driver supports rx-copybreak, but it couldn't be set by userspace. Only the default value(256) has worked.
This patch makes the bnxt_en driver support following command. ethtool --set-tunable <devname> rx-copybreak <value> and ethtool --get-tunable <devname> rx-copybreak.

---

v4:
- Remove min rx-copybreak value.
- Add Review tag from Brett.
- Add Test tag from Stanislav.

v3:
- Update copybreak value after closing nic and before opening nic when the device is running.

v2:
- Define max/vim rx_copybreak value.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c     | 23 +++++----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h     |  5 +-
 .../net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 48 ++++++++++++++++++-
 3 files changed, 65 insertions(+), 11 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
index bda3742d4e32..0f5fe9ba691d 100644

drivers/net/ethernet/broadcom/bnxt/bnxt.c void bnxt_set_ring_params(struct bnxt *bp) · line 4517

Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
@@ -4510,7 +4513,8 @@ void bnxt_set_ring_params(struct bnxt *bp)
                                  ALIGN(max(NET_SKB_PAD, XDP_PACKET_HEADROOM), 8) -
                                  SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
                } else {
-                       rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
+                       rx_size = SKB_DATA_ALIGN(bp->rx_copybreak +
+                                                NET_IP_ALIGN);

When rx_copybreak is 0 or very small, rx_size will be very small and will be a problem. We need rx_size to be big enough to contain the packet header, so rx_size cannot be below some minimum (256?).

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6432

Quoted 11 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -2
                        rx_space = rx_size + NET_SKB_PAD +
                                SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
                }
@@ -6424,8 +6428,8 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
-               req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
+               req->jumbo_thresh = cpu_to_le16(bp->rx_copybreak);
+               req->hds_threshold = cpu_to_le16(bp->rx_copybreak);

Similarly, these thresholds should not go to 0 when rx_copybreak becomes small.

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
        return hwrm_req_send(bp, req);
Quoted 14 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_run_loopback(struct bnxt *bp) · line 4816

Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -1
@@ -4769,7 +4813,7 @@ static int bnxt_run_loopback(struct bnxt *bp)
        cpr = &rxr->bnapi->cp_ring;
        if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
                cpr = rxr->rx_cpr;
-       pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh);
+       pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copybreak);

The loopback test will also not work if rx_copybreak is very small. I think we should always use 256 bytes for the loopback test packet size. Thanks.

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
        skb = netdev_alloc_skb(bp->dev, pkt_size);
        if (!skb)
                return -ENOMEM;

I tested ethtool -t eth0 and I checked it fails if rx-copybreak is too small. Sorry for missing that.
I think we can use max(BNXT_DEFAULT_RX_COPYBREAK, bp->rx_copybreak) for both cases.
I tested it, it works well.
So I will use that if you are okay!

Thank you so much,
Tahee Yoo

maintainer
#4 lore raw

Re: [PATCH net-next v4 1/8] bnxt_en: add support for rx-copybreak ethtool command

Quoted 53 lines · Taehee Yoo

On Thu, Oct 24, 2024 at 3:41 PM Michael Chan

Quoted 35 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c void bnxt_set_ring_params(struct bnxt *bp) · line 4517

Quoted 12 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
index bda3742d4e32..0f5fe9ba691d 100644
@@ -4510,7 +4513,8 @@ void bnxt_set_ring_params(struct bnxt *bp)
                                  ALIGN(max(NET_SKB_PAD, XDP_PACKET_HEADROOM), 8) -
                                  SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
                } else {
-                       rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
+                       rx_size = SKB_DATA_ALIGN(bp->rx_copybreak +
+                                                NET_IP_ALIGN);

When rx_copybreak is 0 or very small, rx_size will be very small and will be a problem. We need rx_size to be big enough to contain the packet header, so rx_size cannot be below some minimum (256?).

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6432

Quoted 11 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -2
                        rx_space = rx_size + NET_SKB_PAD +
                                SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
                }
@@ -6424,8 +6428,8 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
-               req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
+               req->jumbo_thresh = cpu_to_le16(bp->rx_copybreak);
+               req->hds_threshold = cpu_to_le16(bp->rx_copybreak);

Similarly, these thresholds should not go to 0 when rx_copybreak becomes small.

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
        return hwrm_req_send(bp, req);
Quoted 14 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_run_loopback(struct bnxt *bp) · line 4816

Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -1
@@ -4769,7 +4813,7 @@ static int bnxt_run_loopback(struct bnxt *bp)
        cpr = &rxr->bnapi->cp_ring;
        if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
                cpr = rxr->rx_cpr;
-       pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh);
+       pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copybreak);

The loopback test will also not work if rx_copybreak is very small. I think we should always use 256 bytes for the loopback test packet size. Thanks.

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
        skb = netdev_alloc_skb(bp->dev, pkt_size);
        if (!skb)
                return -ENOMEM;
Quoted 7 lines

I tested ethtool -t eth0 and I checked it fails if rx-copybreak is too small. Sorry for missing that.
I think we can use max(BNXT_DEFAULT_RX_COPYBREAK, bp->rx_copybreak) for both cases.
I tested it, it works well.
So I will use that if you are okay!

Yes, please go ahead. I think all 3 places I commented above should use max(BNXT_DEFAULT_RX_COPYBREAK, bp->rx_copybreak). Thanks.

author
#5 lore raw

Re: [PATCH net-next v4 1/8] bnxt_en: add support for rx-copybreak ethtool command

Quoted 63 lines · Michael Chan
Quoted 53 lines · Taehee Yoo

On Thu, Oct 24, 2024 at 3:41 PM Michael Chan

Quoted 35 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c void bnxt_set_ring_params(struct bnxt *bp) · line 4517

Quoted 12 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
index bda3742d4e32..0f5fe9ba691d 100644
@@ -4510,7 +4513,8 @@ void bnxt_set_ring_params(struct bnxt *bp)
                                  ALIGN(max(NET_SKB_PAD, XDP_PACKET_HEADROOM), 8) -
                                  SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
                } else {
-                       rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
+                       rx_size = SKB_DATA_ALIGN(bp->rx_copybreak +
+                                                NET_IP_ALIGN);

When rx_copybreak is 0 or very small, rx_size will be very small and will be a problem. We need rx_size to be big enough to contain the packet header, so rx_size cannot be below some minimum (256?).

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6432

Quoted 11 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -2
                        rx_space = rx_size + NET_SKB_PAD +
                                SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
                }
@@ -6424,8 +6428,8 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
-               req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
+               req->jumbo_thresh = cpu_to_le16(bp->rx_copybreak);
+               req->hds_threshold = cpu_to_le16(bp->rx_copybreak);

Similarly, these thresholds should not go to 0 when rx_copybreak becomes small.

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
        return hwrm_req_send(bp, req);
Quoted 14 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_run_loopback(struct bnxt *bp) · line 4816

Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -1
@@ -4769,7 +4813,7 @@ static int bnxt_run_loopback(struct bnxt *bp)
        cpr = &rxr->bnapi->cp_ring;
        if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
                cpr = rxr->rx_cpr;
-       pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh);
+       pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copybreak);

The loopback test will also not work if rx_copybreak is very small. I think we should always use 256 bytes for the loopback test packet size. Thanks.

Quoted 3 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
        skb = netdev_alloc_skb(bp->dev, pkt_size);
        if (!skb)
                return -ENOMEM;
Quoted 7 lines

I tested ethtool -t eth0 and I checked it fails if rx-copybreak is too small. Sorry for missing that.
I think we can use max(BNXT_DEFAULT_RX_COPYBREAK, bp->rx_copybreak) for both cases.
I tested it, it works well.
So I will use that if you are okay!

Quoted 2 lines

Yes, please go ahead. I think all 3 places I commented above should use max(BNXT_DEFAULT_RX_COPYBREAK, bp->rx_copybreak). Thanks.

Thanks a lot for your confirmation :)

I asked about jumbo_thresh in another thread, I would like to do it based on that thread for jumbo_thresh.
And hds_thresh value will be configured by
`ethtool -G eth0 header-data-split-thresh 0", so that we need to allow 0 ~ 256 value.
I think you indicated jumbo_thresh only, right?

Thank you so much!
Taehee Yoo

author
#6 lore raw

PATCH v4 2/8 bnxt_en: add support for tcp-data-split ethtool command

In reply to Taehee Yoo

NICs that uses bnxt_en driver supports tcp-data-split feature by the name of HDS(header-data-split).
But there is no implementation for the HDS to enable or disable by ethtool.
Only getting the current HDS status is implemented and The HDS is just automatically enabled only when either LRO, HW-GRO, or JUMBO is enabled. The hds_threshold follows rx-copybreak value. and it was unchangeable.

This implements ethtool -G <interface name> tcp-data-split <value> command option.
The value can be <on>, <off>, and <auto> but the <auto> will be automatically changed to <on>.

HDS feature relies on the aggregation ring.
So, if HDS is enabled, the bnxt_en driver initializes the aggregation ring.
This is the reason why BNXT_FLAG_AGG_RINGS contains HDS condition.

---

v4:
- Do not support disable tcp-data-split.
- Add Test tag from Stanislav.

v3:
- No changes.

v2:
- Do not set hds_threshold to 0.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c         |  8 +++-----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h         |  5 +++--
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 13 +++++++++++++
 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +3 -5
index 0f5fe9ba691d..91ea42ff9b17 100644
@@ -4473,7 +4473,7 @@ void bnxt_set_ring_params(struct bnxt *bp)
 	bp->rx_agg_ring_size = 0;
 	bp->rx_agg_nr_pages = 0;
 
-	if (bp->flags & BNXT_FLAG_TPA)
+	if (bp->flags & BNXT_FLAG_TPA || bp->flags & BNXT_FLAG_HDS)
 		agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE);
 
 	bp->flags &= ~BNXT_FLAG_JUMBO;
@@ -6420,15 +6420,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
 	req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
 	req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+	req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
-	if (BNXT_RX_PAGE_MODE(bp)) {
-		req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
-	} else {
+	if (bp->flags & BNXT_FLAG_AGG_RINGS) {
 		req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
 					  VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
 		req->enables |=
 			cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-		req->jumbo_thresh = cpu_to_le16(bp->rx_copybreak);
 		req->hds_threshold = cpu_to_le16(bp->rx_copybreak);
 	}
 	req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
drivers/net/ethernet/broadcom/bnxt/bnxt.h +3 -2
index 1b83a2c8027b..432bc19b35ea 100644
@@ -2201,8 +2201,6 @@ struct bnxt {
 	#define BNXT_FLAG_TPA		(BNXT_FLAG_LRO | BNXT_FLAG_GRO)
 	#define BNXT_FLAG_JUMBO		0x10
 	#define BNXT_FLAG_STRIP_VLAN	0x20
-	#define BNXT_FLAG_AGG_RINGS	(BNXT_FLAG_JUMBO | BNXT_FLAG_GRO | \
-					 BNXT_FLAG_LRO)
 	#define BNXT_FLAG_RFS		0x100
 	#define BNXT_FLAG_SHARED_RINGS	0x200
 	#define BNXT_FLAG_PORT_STATS	0x400
@@ -2223,6 +2221,9 @@ struct bnxt {
 	#define BNXT_FLAG_ROCE_MIRROR_CAP	0x4000000
 	#define BNXT_FLAG_TX_COAL_CMPL	0x8000000
 	#define BNXT_FLAG_PORT_STATS_EXT	0x10000000
+	#define BNXT_FLAG_HDS		0x20000000
+	#define BNXT_FLAG_AGG_RINGS	(BNXT_FLAG_JUMBO | BNXT_FLAG_GRO | \
+					 BNXT_FLAG_LRO | BNXT_FLAG_HDS)
 
 	#define BNXT_FLAG_ALL_CONFIG_FEATS (BNXT_FLAG_TPA |		\
 					    BNXT_FLAG_RFS |		\
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +13 -0
index 9af0a3f34750..5172d0547e0c 100644
@@ -854,9 +854,21 @@ static int bnxt_set_ringparam(struct net_device *dev,
 	    (ering->tx_pending < BNXT_MIN_TX_DESC_CNT))
 		return -EINVAL;
 
+	if (kernel_ering->tcp_data_split == ETHTOOL_TCP_DATA_SPLIT_DISABLED)
+		return -EOPNOTSUPP;
+
 	if (netif_running(dev))
 		bnxt_close_nic(bp, false, false);
 
+	switch (kernel_ering->tcp_data_split) {
+	case ETHTOOL_TCP_DATA_SPLIT_ENABLED:
+		bp->flags |= BNXT_FLAG_HDS;
+		break;
+	case ETHTOOL_TCP_DATA_SPLIT_UNKNOWN:
+		bp->flags &= ~BNXT_FLAG_HDS;
+		break;
+	}
+
 	bp->rx_ring_size = ering->rx_pending;
 	bp->tx_ring_size = ering->tx_pending;
 	bnxt_set_ring_params(bp);
@@ -5345,6 +5357,7 @@ const struct ethtool_ops bnxt_ethtool_ops = {
 				     ETHTOOL_COALESCE_STATS_BLOCK_USECS |
 				     ETHTOOL_COALESCE_USE_ADAPTIVE_RX |
 				     ETHTOOL_COALESCE_USE_CQE,
+	.supported_ring_params	= ETHTOOL_RING_USE_TCP_DATA_SPLIT,
 	.get_link_ksettings	= bnxt_get_link_ksettings,
 	.set_link_ksettings	= bnxt_set_link_ksettings,
 	.get_fec_stats		= bnxt_get_fec_stats,
Signature · 1 line
2.34.1
maintainer
#7 lore raw

Re: [PATCH net-next v4 2/8] bnxt_en: add support for tcp-data-split ethtool command

Quoted 44 lines · Taehee Yoo

NICs that uses bnxt_en driver supports tcp-data-split feature by the name of HDS(header-data-split).
But there is no implementation for the HDS to enable or disable by ethtool.
Only getting the current HDS status is implemented and The HDS is just automatically enabled only when either LRO, HW-GRO, or JUMBO is enabled. The hds_threshold follows rx-copybreak value. and it was unchangeable.

This implements ethtool -G <interface name> tcp-data-split <value> command option.
The value can be <on>, <off>, and <auto> but the <auto> will be automatically changed to <on>.

HDS feature relies on the aggregation ring.
So, if HDS is enabled, the bnxt_en driver initializes the aggregation ring.
This is the reason why BNXT_FLAG_AGG_RINGS contains HDS condition.

---

v4:
- Do not support disable tcp-data-split.
- Add Test tag from Stanislav.

v3:
- No changes.

v2:
- Do not set hds_threshold to 0.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c         |  8 +++-----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h         |  5 +++--
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 13 +++++++++++++
 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -0
index 0f5fe9ba691d..91ea42ff9b17 100644

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6425

Quoted 7 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -2
@@ -6420,15 +6420,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+       req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
-       if (BNXT_RX_PAGE_MODE(bp)) {
-               req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);

Please explain why this "if" condition is removed. BNXT_RX_PAGE_MODE() means that we are in XDP mode and we currently don't support HDS in XDP mode. Added Andy Gospo to CC so he can also comment.

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -2
-       } else {
+       if (bp->flags & BNXT_FLAG_AGG_RINGS) {
                req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copybreak);
                req->hds_threshold = cpu_to_le16(bp->rx_copybreak);
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
author
#8 lore raw

Re: [PATCH net-next v4 2/8] bnxt_en: add support for tcp-data-split ethtool command

On Fri, Oct 25, 2024 at 2:02 PM Michael Chan

Hi Michael,
Thank you so much for the review!

Quoted 51 lines · <[email protected]> wrote:
Quoted 49 lines · Taehee Yoo

NICs that uses bnxt_en driver supports tcp-data-split feature by the name of HDS(header-data-split).
But there is no implementation for the HDS to enable or disable by ethtool.
Only getting the current HDS status is implemented and The HDS is just automatically enabled only when either LRO, HW-GRO, or JUMBO is enabled. The hds_threshold follows rx-copybreak value. and it was unchangeable.

This implements ethtool -G <interface name> tcp-data-split <value> command option.
The value can be <on>, <off>, and <auto> but the <auto> will be automatically changed to <on>.

HDS feature relies on the aggregation ring.
So, if HDS is enabled, the bnxt_en driver initializes the aggregation ring.
This is the reason why BNXT_FLAG_AGG_RINGS contains HDS condition.

---

v4:
- Do not support disable tcp-data-split.
- Add Test tag from Stanislav.

v3:
- No changes.

v2:
- Do not set hds_threshold to 0.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c         |  8 +++-----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h         |  5 +++--
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 13 +++++++++++++
 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
index 0f5fe9ba691d..91ea42ff9b17 100644
@@ -6420,15 +6420,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+       req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
Quoted 7 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6425

Quoted 2 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -2
-       if (BNXT_RX_PAGE_MODE(bp)) {
-               req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);

Please explain why this "if" condition is removed. BNXT_RX_PAGE_MODE() means that we are in XDP mode and we currently don't support HDS in XDP mode. Added Andy Gospo to CC so he can also comment.

Yes,
The reason why the "if" condition is removed is to make rx-copybreak a pure software feature.

The current jumbo_thresh follows the rx-copybreak value, however, I thought the rx-copybreak value should not affect any hardware function. So, I thought following rx_buf_use_size instead of rx_copybreak is okay. By this change, jumbo_thresh always follows rx_buf_use_size,
so I removed the "if" condition.
Oh, on second thought, it changes a default behavior, it's not my intention. What value would be good for jumbo_thresh following?
What do you think?

Quoted 11 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6432

Quoted 11 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -2
-       } else {
+       if (bp->flags & BNXT_FLAG_AGG_RINGS) {
                req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copybreak);
                req->hds_threshold = cpu_to_le16(bp->rx_copybreak);
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);

Thank you so much for the review!
Taehee Yoo

#9 lore raw

Re: [PATCH net-next v4 2/8] bnxt_en: add support for tcp-data-split ethtool command

In reply to Michael Chan
Quoted 50 lines · Michael Chan
Quoted 49 lines · Taehee Yoo

NICs that uses bnxt_en driver supports tcp-data-split feature by the name of HDS(header-data-split).
But there is no implementation for the HDS to enable or disable by ethtool.
Only getting the current HDS status is implemented and The HDS is just automatically enabled only when either LRO, HW-GRO, or JUMBO is enabled. The hds_threshold follows rx-copybreak value. and it was unchangeable.

This implements ethtool -G <interface name> tcp-data-split <value> command option.
The value can be <on>, <off>, and <auto> but the <auto> will be automatically changed to <on>.

HDS feature relies on the aggregation ring.
So, if HDS is enabled, the bnxt_en driver initializes the aggregation ring.
This is the reason why BNXT_FLAG_AGG_RINGS contains HDS condition.

---

v4:
- Do not support disable tcp-data-split.
- Add Test tag from Stanislav.

v3:
- No changes.

v2:
- Do not set hds_threshold to 0.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c         |  8 +++-----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h         |  5 +++--
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 13 +++++++++++++
 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
index 0f5fe9ba691d..91ea42ff9b17 100644
@@ -6420,15 +6420,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+       req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6425

Quoted 2 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -2
-       if (BNXT_RX_PAGE_MODE(bp)) {
-               req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);

Please explain why this "if" condition is removed. BNXT_RX_PAGE_MODE() means that we are in XDP mode and we currently don't support HDS in XDP mode. Added Andy Gospo to CC so he can also comment.

In bnxt_set_rx_skb_mode we set BNXT_FLAG_RX_PAGE_MODE and clear BNXT_FLAG_AGG_RINGS, so this should work. The only issue is that we have spots in the driver where we check BNXT_RX_PAGE_MODE(bp) to indicate that XDP single-buffer mode is enabled on the device.

If you need to respin this series I would prefer that the change is like below to key off the page mode being disabled and BNXT_FLAG_AGG_RINGS being enabled to setup HDS. This will serve as a reminder that this is for XDP.

@@ -6418,15 +6418,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)

        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);

+ req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);

- if (BNXT_RX_PAGE_MODE(bp)) {
- req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
- } else {

+       if (!BNXT_RX_PAGE_MODE(bp) && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
                req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
                req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -2
-       } else {
+       if (bp->flags & BNXT_FLAG_AGG_RINGS) {
                req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copybreak);
                req->hds_threshold = cpu_to_le16(bp->rx_copybreak);
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
maintainer
#10 lore raw

Re: [PATCH net-next v4 2/8] bnxt_en: add support for tcp-data-split ethtool command

Quoted 61 lines · Andy Gospodarek
Quoted 50 lines · Michael Chan
Quoted 49 lines · Taehee Yoo

NICs that uses bnxt_en driver supports tcp-data-split feature by the name of HDS(header-data-split).
But there is no implementation for the HDS to enable or disable by ethtool.
Only getting the current HDS status is implemented and The HDS is just automatically enabled only when either LRO, HW-GRO, or JUMBO is enabled. The hds_threshold follows rx-copybreak value. and it was unchangeable.

This implements ethtool -G <interface name> tcp-data-split <value> command option.
The value can be <on>, <off>, and <auto> but the <auto> will be automatically changed to <on>.

HDS feature relies on the aggregation ring.
So, if HDS is enabled, the bnxt_en driver initializes the aggregation ring.
This is the reason why BNXT_FLAG_AGG_RINGS contains HDS condition.

---

v4:
- Do not support disable tcp-data-split.
- Add Test tag from Stanislav.

v3:
- No changes.

v2:
- Do not set hds_threshold to 0.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c         |  8 +++-----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h         |  5 +++--
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 13 +++++++++++++
 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
index 0f5fe9ba691d..91ea42ff9b17 100644
@@ -6420,15 +6420,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+       req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6425

Quoted 2 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -2
-       if (BNXT_RX_PAGE_MODE(bp)) {
-               req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);

Please explain why this "if" condition is removed. BNXT_RX_PAGE_MODE() means that we are in XDP mode and we currently don't support HDS in XDP mode. Added Andy Gospo to CC so he can also comment.

Quoted 2 lines

In bnxt_set_rx_skb_mode we set BNXT_FLAG_RX_PAGE_MODE and clear BNXT_FLAG_AGG_RINGS

The BNXT_FLAG_AGG_RINGS flag is true if the JUMBO, GRO, or LRO flag is set. So even though it is initially cleared in bnxt_set_rx_skb_mode(), we'll set the JUMBO flag if we are in multi-buffer XDP mode. Again, we don't enable HDS in any XDP mode so I think we need to keep the original logic here to skip setting the HDS threshold if BNXT_FLAG_RX_PAGE_MODE is set.

Quoted 28 lines

, so this should work. The only issue is that we
have spots in the driver where we check BNXT_RX_PAGE_MODE(bp) to indicate that XDP single-buffer mode is enabled on the device.

If you need to respin this series I would prefer that the change is like below to key off the page mode being disabled and BNXT_FLAG_AGG_RINGS being enabled to setup HDS. This will serve as a reminder that this is for XDP.

drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -4
@@ -6418,15 +6418,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+       req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
-       if (BNXT_RX_PAGE_MODE(bp)) {
-               req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
-       } else {
+       if (!BNXT_RX_PAGE_MODE(bp) && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
                req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
                req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
author
#11 lore raw

Re: [PATCH net-next v4 2/8] bnxt_en: add support for tcp-data-split ethtool command

Quoted 3 lines · Michael Chan

On Fri, Oct 25, 2024 at 12:24 PM Andy Gospodarek
<[email protected]> wrote:

Hi Andy,
Thank you so much for your review!

Quoted 64 lines
Quoted 61 lines · Michael Chan
Quoted 50 lines · Taehee Yoo
Quoted 49 lines

NICs that uses bnxt_en driver supports tcp-data-split feature by the name of HDS(header-data-split).
But there is no implementation for the HDS to enable or disable by ethtool.
Only getting the current HDS status is implemented and The HDS is just automatically enabled only when either LRO, HW-GRO, or JUMBO is enabled. The hds_threshold follows rx-copybreak value. and it was unchangeable.

This implements ethtool -G <interface name> tcp-data-split <value> command option.
The value can be <on>, <off>, and <auto> but the <auto> will be automatically changed to <on>.

HDS feature relies on the aggregation ring.
So, if HDS is enabled, the bnxt_en driver initializes the aggregation ring.
This is the reason why BNXT_FLAG_AGG_RINGS contains HDS condition.

---

v4:
- Do not support disable tcp-data-split.
- Add Test tag from Stanislav.

v3:
- No changes.

v2:
- Do not set hds_threshold to 0.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c         |  8 +++-----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h         |  5 +++--
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 13 +++++++++++++
 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
index 0f5fe9ba691d..91ea42ff9b17 100644
@@ -6420,15 +6420,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+       req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6425

Quoted 2 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -2
-       if (BNXT_RX_PAGE_MODE(bp)) {
-               req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);

Please explain why this "if" condition is removed. BNXT_RX_PAGE_MODE() means that we are in XDP mode and we currently don't support HDS in XDP mode. Added Andy Gospo to CC so he can also comment.

Quoted 2 lines

In bnxt_set_rx_skb_mode we set BNXT_FLAG_RX_PAGE_MODE and clear BNXT_FLAG_AGG_RINGS

Quoted 6 lines

The BNXT_FLAG_AGG_RINGS flag is true if the JUMBO, GRO, or LRO flag is set. So even though it is initially cleared in bnxt_set_rx_skb_mode(), we'll set the JUMBO flag if we are in multi-buffer XDP mode. Again, we don't enable HDS in any XDP mode so I think we need to keep the original logic here to skip setting the HDS threshold if BNXT_FLAG_RX_PAGE_MODE is set.

I thought the HDS is disallowed only when single-buffer XDP is set. By this series, Core API disallows tcp-data-split only when single-buffer XDP is set, but it allows tcp-data-split to set when multi-buffer XDP is set.

+ if (kernel_ringparam.tcp_data_split == ETHTOOL_TCP_DATA_SPLIT_ENABLED &&
+ dev_xdp_sb_prog_count(dev)) {
+ NL_SET_ERR_MSG(info->extack,
+ "tcp-data-split can not be enabled with
single buffer XDP");
+ return -EINVAL;
+ }

I think other drivers would allow tcp-data-split on multi buffer XDP, so I wouldn't like to remove this condition check code.

I will not set HDS if XDP is set in the bnxt_hwrm_vnic_set_hds() In addition, I think we need to add a condition to check XDP is set in bnxt_set_ringparam().

Quoted 16 lines
Quoted 16 lines

, so this should work. The only issue is that we
have spots in the driver where we check BNXT_RX_PAGE_MODE(bp) to indicate that XDP single-buffer mode is enabled on the device.

If you need to respin this series I would prefer that the change is like below to key off the page mode being disabled and BNXT_FLAG_AGG_RINGS being enabled to setup HDS. This will serve as a reminder that this is for XDP.

drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
@@ -6418,15 +6418,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+       req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
Quoted 13 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6432

Quoted 13 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -4
-       if (BNXT_RX_PAGE_MODE(bp)) {
-               req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
-       } else {
+       if (!BNXT_RX_PAGE_MODE(bp) && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
                req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
                req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);

Thanks a lot!
Taehee Yoo

#12 lore raw

Re: [PATCH net-next v4 2/8] bnxt_en: add support for tcp-data-split ethtool command

Quoted 79 lines · Taehee Yoo
Quoted 3 lines · Michael Chan

On Fri, Oct 25, 2024 at 12:24 PM Andy Gospodarek
<[email protected]> wrote:

Hi Andy,
Thank you so much for your review!

Quoted 64 lines
Quoted 61 lines · Michael Chan
Quoted 50 lines · Taehee Yoo
Quoted 49 lines

NICs that uses bnxt_en driver supports tcp-data-split feature by the name of HDS(header-data-split).
But there is no implementation for the HDS to enable or disable by ethtool.
Only getting the current HDS status is implemented and The HDS is just automatically enabled only when either LRO, HW-GRO, or JUMBO is enabled. The hds_threshold follows rx-copybreak value. and it was unchangeable.

This implements ethtool -G <interface name> tcp-data-split <value> command option.
The value can be <on>, <off>, and <auto> but the <auto> will be automatically changed to <on>.

HDS feature relies on the aggregation ring.
So, if HDS is enabled, the bnxt_en driver initializes the aggregation ring.
This is the reason why BNXT_FLAG_AGG_RINGS contains HDS condition.

---

v4:
- Do not support disable tcp-data-split.
- Add Test tag from Stanislav.

v3:
- No changes.

v2:
- Do not set hds_threshold to 0.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c         |  8 +++-----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h         |  5 +++--
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 13 +++++++++++++
 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
index 0f5fe9ba691d..91ea42ff9b17 100644
@@ -6420,15 +6420,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+       req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6425

Quoted 2 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -2
-       if (BNXT_RX_PAGE_MODE(bp)) {
-               req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);

Please explain why this "if" condition is removed. BNXT_RX_PAGE_MODE() means that we are in XDP mode and we currently don't support HDS in XDP mode. Added Andy Gospo to CC so he can also comment.

Quoted 2 lines

In bnxt_set_rx_skb_mode we set BNXT_FLAG_RX_PAGE_MODE and clear BNXT_FLAG_AGG_RINGS

Quoted 6 lines

The BNXT_FLAG_AGG_RINGS flag is true if the JUMBO, GRO, or LRO flag is set. So even though it is initially cleared in bnxt_set_rx_skb_mode(), we'll set the JUMBO flag if we are in multi-buffer XDP mode. Again, we don't enable HDS in any XDP mode so I think we need to keep the original logic here to skip setting the HDS threshold if BNXT_FLAG_RX_PAGE_MODE is set.

Quoted 4 lines

I thought the HDS is disallowed only when single-buffer XDP is set. By this series, Core API disallows tcp-data-split only when single-buffer XDP is set, but it allows tcp-data-split to set when multi-buffer XDP is set.

So you are saying that a user could set copybreak with ethtool (included in patch 1) and when a multibuffer XDP program is attached to an interface with an MTU of 9k, only the header will be in the first page and all the TCP data will be in the pages that follow?

Quoted 11 lines
(quoted diff) +4 -0
+       if (kernel_ringparam.tcp_data_split == ETHTOOL_TCP_DATA_SPLIT_ENABLED &&
+           dev_xdp_sb_prog_count(dev)) {
+               NL_SET_ERR_MSG(info->extack,
+                              "tcp-data-split can not be enabled with

single buffer XDP");

(quoted diff) +2 -0
+               return -EINVAL;
+       }

I think other drivers would allow tcp-data-split on multi buffer XDP, so I wouldn't like to remove this condition check code.

I have no problem keeping that logic in the core kernel. I'm just asking you to please preserve the existing logic since it is functionally equivalent and easier to read/compare to other spots where XDP single-buffer mode is used.

Quoted 36 lines

I will not set HDS if XDP is set in the bnxt_hwrm_vnic_set_hds() In addition, I think we need to add a condition to check XDP is set in bnxt_set_ringparam().

Quoted 16 lines
Quoted 16 lines

, so this should work. The only issue is that we
have spots in the driver where we check BNXT_RX_PAGE_MODE(bp) to indicate that XDP single-buffer mode is enabled on the device.

If you need to respin this series I would prefer that the change is like below to key off the page mode being disabled and BNXT_FLAG_AGG_RINGS being enabled to setup HDS. This will serve as a reminder that this is for XDP.

drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
@@ -6418,15 +6418,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+       req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
Quoted 13 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6432

Quoted 13 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -4
-       if (BNXT_RX_PAGE_MODE(bp)) {
-               req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
-       } else {
+       if (!BNXT_RX_PAGE_MODE(bp) && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
                req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
                req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);

Thanks a lot!
Taehee Yoo

author
#13 lore raw

Re: [PATCH net-next v4 2/8] bnxt_en: add support for tcp-data-split ethtool command

Quoted 86 lines · Andy Gospodarek
Quoted 79 lines · Taehee Yoo
Quoted 3 lines · Michael Chan

On Fri, Oct 25, 2024 at 12:24 PM Andy Gospodarek
<[email protected]> wrote:

Hi Andy,
Thank you so much for your review!

Quoted 64 lines
Quoted 61 lines · Michael Chan
Quoted 50 lines · Taehee Yoo
Quoted 49 lines

NICs that uses bnxt_en driver supports tcp-data-split feature by the name of HDS(header-data-split).
But there is no implementation for the HDS to enable or disable by ethtool.
Only getting the current HDS status is implemented and The HDS is just automatically enabled only when either LRO, HW-GRO, or JUMBO is enabled. The hds_threshold follows rx-copybreak value. and it was unchangeable.

This implements ethtool -G <interface name> tcp-data-split <value> command option.
The value can be <on>, <off>, and <auto> but the <auto> will be automatically changed to <on>.

HDS feature relies on the aggregation ring.
So, if HDS is enabled, the bnxt_en driver initializes the aggregation ring.
This is the reason why BNXT_FLAG_AGG_RINGS contains HDS condition.

---

v4:
- Do not support disable tcp-data-split.
- Add Test tag from Stanislav.

v3:
- No changes.

v2:
- Do not set hds_threshold to 0.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c         |  8 +++-----
 drivers/net/ethernet/broadcom/bnxt/bnxt.h         |  5 +++--
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 13 +++++++++++++
 3 files changed, 19 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
index 0f5fe9ba691d..91ea42ff9b17 100644
@@ -6420,15 +6420,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+       req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
Quoted 8 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6425

Quoted 2 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +0 -2
-       if (BNXT_RX_PAGE_MODE(bp)) {
-               req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);

Please explain why this "if" condition is removed. BNXT_RX_PAGE_MODE() means that we are in XDP mode and we currently don't support HDS in XDP mode. Added Andy Gospo to CC so he can also comment.

Quoted 2 lines

In bnxt_set_rx_skb_mode we set BNXT_FLAG_RX_PAGE_MODE and clear BNXT_FLAG_AGG_RINGS

Quoted 6 lines

The BNXT_FLAG_AGG_RINGS flag is true if the JUMBO, GRO, or LRO flag is set. So even though it is initially cleared in bnxt_set_rx_skb_mode(), we'll set the JUMBO flag if we are in multi-buffer XDP mode. Again, we don't enable HDS in any XDP mode so I think we need to keep the original logic here to skip setting the HDS threshold if BNXT_FLAG_RX_PAGE_MODE is set.

Quoted 4 lines

I thought the HDS is disallowed only when single-buffer XDP is set. By this series, Core API disallows tcp-data-split only when single-buffer XDP is set, but it allows tcp-data-split to set when multi-buffer XDP is set.

Quoted 5 lines

So you are saying that a user could set copybreak with ethtool (included in patch 1) and when a multibuffer XDP program is attached to an interface with an MTU of 9k, only the header will be in the first page and all the TCP data will be in the pages that follow?

I think you asked about hds_threshold = bp->rx_copybreak right?

By this patchset, rx-copybreak will be a pure software feature. hds_threshold value will be set by ethtool -G eth0 header-data-split-thresh N. This is implemented in 4/8 patch.
Sorry, I missed commenting in this commit message that hds_threshold value will no longer follow bp->rx_copybreak.

If HDS is allowed when multi buffer XDP is attached, xdp program will see only the header on the first page. But As Michael and you suggested, HDS is not going to be allowed if XDP is attached.
If I misunderstood your question, please let me know!

Quoted 8 lines
Quoted 8 lines
(quoted diff) +4 -0
+       if (kernel_ringparam.tcp_data_split == ETHTOOL_TCP_DATA_SPLIT_ENABLED &&
+           dev_xdp_sb_prog_count(dev)) {
+               NL_SET_ERR_MSG(info->extack,
+                              "tcp-data-split can not be enabled with

single buffer XDP");

(quoted diff) +2 -0
+               return -EINVAL;
+       }
Quoted 8 lines
Quoted 3 lines

I think other drivers would allow tcp-data-split on multi buffer XDP, so I wouldn't like to remove this condition check code.

I have no problem keeping that logic in the core kernel. I'm just asking you to please preserve the existing logic since it is functionally equivalent and easier to read/compare to other spots where XDP single-buffer mode is used.

Thanks a lot for the explanation and confirmation! I will preserve the existing logic.

Quoted 37 lines
Quoted 37 lines

I will not set HDS if XDP is set in the bnxt_hwrm_vnic_set_hds() In addition, I think we need to add a condition to check XDP is set in bnxt_set_ringparam().

Quoted 16 lines
Quoted 16 lines

, so this should work. The only issue is that we
have spots in the driver where we check BNXT_RX_PAGE_MODE(bp) to indicate that XDP single-buffer mode is enabled on the device.

If you need to respin this series I would prefer that the change is like below to key off the page mode being disabled and BNXT_FLAG_AGG_RINGS being enabled to setup HDS. This will serve as a reminder that this is for XDP.

drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -0
@@ -6418,15 +6418,13 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 
        req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
        req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
+       req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
 
Quoted 13 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic) · line 6432

Quoted 13 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +1 -4
-       if (BNXT_RX_PAGE_MODE(bp)) {
-               req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
-       } else {
+       if (!BNXT_RX_PAGE_MODE(bp) && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
                req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
                                          VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
                req->enables |=
                        cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-               req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
                req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
        }
        req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);

Thanks a lot!
Taehee Yoo

author
#14 lore raw

PATCH v4 3/8 net: ethtool: add support for configuring header-data-split-thresh

In reply to Taehee Yoo

The header-data-split-thresh option configures the threshold value of the header-data-split.
If a received packet size is larger than this threshold value, a packet will be split into header and payload.
The header indicates TCP and UDP header, but it depends on driver spec. The bnxt_en driver supports HDS(Header-Data-Split) configuration at FW level, affecting TCP and UDP too.
So, If header-data-split-thresh is set, it affects UDP and TCP packets.

Example:

   # ethtool -G <interface name> header-data-split-thresh <value>
   # ethtool -G enp14s0f0np0 tcp-data-split on header-data-split-thresh 256
   # ethtool -g enp14s0f0np0
   Ring parameters for enp14s0f0np0:
   Pre-set maximums:
   ...
   Header data split thresh:  256
   Current hardware settings:
   ...
   TCP data split:         on
   Header data split thresh:  256

The default/min/max values are not defined in the ethtool so the drivers should define themself.
The 0 value means that all TCP/UDP packets' header and payload will be split.

In general cases, HDS can increase the overhead of host memory and PCIe bus because it copies data twice.
So users should consider the overhead of HDS.
If the HDS threshold is 0 and then the copybreak is 256 and the packet's payload is 8 bytes.
So, two pages are used, one for headers and one for payloads. By the copybreak, only the headers page is copied and then it can be reused immediately and then a payloads page is still used. If the HDS threshold is larger than 8, both headers and payloads are copied and then a page can be recycled immediately.
So, too low HDS threshold has larger disadvantages than advantages aspect of performance in general cases.
Users should consider the overhead of this feature.

---

v4:
- Fix 80 charactor wrap.
- Rename from tcp-data-split-thresh to header-data-split-thresh
- Add description about overhead of HDS.
- Add ETHTOOL_RING_USE_HDS_THRS flag.
- Add dev_xdp_sb_prog_count() helper.
- Add Test tag from Stanislav.

v3:
- Fix documentation and ynl
- Update error messages
- Validate configuration of tcp-data-split and tcp-data-split-thresh

v2:
- Patch added.

 Documentation/netlink/specs/ethtool.yaml     |  8 ++
 Documentation/networking/ethtool-netlink.rst | 79 ++++++++++++--------
 include/linux/ethtool.h                      |  6 ++
 include/linux/netdevice.h                    |  1 +
 include/uapi/linux/ethtool_netlink.h         |  2 +
 net/core/dev.c                               | 13 ++++
 net/ethtool/netlink.h                        |  2 +-
 net/ethtool/rings.c                          | 37 ++++++++-
 8 files changed, 115 insertions(+), 33 deletions(-)
Documentation/netlink/specs/ethtool.yaml +8 -0
index 6a050d755b9c..3e1f54324cbc 100644
@@ -215,6 +215,12 @@ attribute-sets:
       -
         name: tx-push-buf-len-max
         type: u32
+      -
+        name: header-data-split-thresh
+        type: u32
+      -
+        name: header-data-split-thresh-max
+        type: u32
 
   -
     name: mm-stat
@@ -1393,6 +1399,8 @@ operations:
             - rx-push
             - tx-push-buf-len
             - tx-push-buf-len-max
+            - header-data-split-thresh
+            - header-data-split-thresh-max
       dump: *ring-get-op
     -
       name: rings-set
Documentation/networking/ethtool-netlink.rst +49 -30

97 lines not on this page · raw message

include/linux/ethtool.h +6 -0
index 12f6dc567598..021fd21f3914 100644
@@ -78,6 +78,8 @@ enum {
  * @cqe_size: Size of TX/RX completion queue event
  * @tx_push_buf_len: Size of TX push buffer
  * @tx_push_buf_max_len: Maximum allowed size of TX push buffer
+ * @hds_thresh: Threshold value of header-data-split-thresh
+ * @hds_thresh_max: Maximum allowed threshold of header-data-split-thresh
  */
 struct kernel_ethtool_ringparam {
 	u32	rx_buf_len;
@@ -87,6 +89,8 @@ struct kernel_ethtool_ringparam {
 	u32	cqe_size;
 	u32	tx_push_buf_len;
 	u32	tx_push_buf_max_len;
+	u32	hds_thresh;
+	u32	hds_thresh_max;
 };
 
 /**
@@ -97,6 +101,7 @@ struct kernel_ethtool_ringparam {
  * @ETHTOOL_RING_USE_RX_PUSH: capture for setting rx_push
  * @ETHTOOL_RING_USE_TX_PUSH_BUF_LEN: capture for setting tx_push_buf_len
  * @ETHTOOL_RING_USE_TCP_DATA_SPLIT: capture for setting tcp_data_split
+ * @ETHTOOL_RING_USE_HDS_THRS: capture for setting header-data-split-thresh
  */
 enum ethtool_supported_ring_param {
 	ETHTOOL_RING_USE_RX_BUF_LEN		= BIT(0),
@@ -105,6 +110,7 @@ enum ethtool_supported_ring_param {
 	ETHTOOL_RING_USE_RX_PUSH		= BIT(3),
 	ETHTOOL_RING_USE_TX_PUSH_BUF_LEN	= BIT(4),
 	ETHTOOL_RING_USE_TCP_DATA_SPLIT		= BIT(5),
+	ETHTOOL_RING_USE_HDS_THRS		= BIT(6),
 };
 
 #define __ETH_RSS_HASH_BIT(bit)	((u32)1 << (bit))
include/linux/netdevice.h +1 -0
index 8feaca12655e..e155b767a08d 100644
@@ -4010,6 +4010,7 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
 
 int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog);
 u8 dev_xdp_prog_count(struct net_device *dev);
+u8 dev_xdp_sb_prog_count(struct net_device *dev);
 int dev_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf);
 u32 dev_xdp_prog_id(struct net_device *dev, enum bpf_xdp_mode mode);
 
include/uapi/linux/ethtool_netlink.h +2 -0
index 283305f6b063..7087c5c51017 100644
@@ -364,6 +364,8 @@ enum {
 	ETHTOOL_A_RINGS_RX_PUSH,			/* u8 */
 	ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN,		/* u32 */
 	ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN_MAX,		/* u32 */
+	ETHTOOL_A_RINGS_HEADER_DATA_SPLIT_THRESH,	/* u32 */
+	ETHTOOL_A_RINGS_HEADER_DATA_SPLIT_THRESH_MAX,	/* u32 */
 
 	/* add new constants above here */
 	__ETHTOOL_A_RINGS_CNT,
net/core/dev.c +13 -0
index c682173a7642..890cd2bd0864 100644
@@ -9431,6 +9431,19 @@ u8 dev_xdp_prog_count(struct net_device *dev)
 }
 EXPORT_SYMBOL_GPL(dev_xdp_prog_count);
 
+u8 dev_xdp_sb_prog_count(struct net_device *dev)
+{
+	u8 count = 0;
+	int i;
+
+	for (i = 0; i < __MAX_XDP_MODE; i++)
+		if (dev->xdp_state[i].prog &&
+		    !dev->xdp_state[i].prog->aux->xdp_has_frags)
+			count++;
+	return count;
+}
+EXPORT_SYMBOL_GPL(dev_xdp_sb_prog_count);
+
 int dev_xdp_propagate(struct net_device *dev, struct netdev_bpf *bpf)
 {
 	if (!dev->netdev_ops->ndo_bpf)
net/ethtool/netlink.h +1 -1
index 203b08eb6c6f..9f51a252ebe0 100644
@@ -455,7 +455,7 @@ extern const struct nla_policy ethnl_features_set_policy[ETHTOOL_A_FEATURES_WANT
 extern const struct nla_policy ethnl_privflags_get_policy[ETHTOOL_A_PRIVFLAGS_HEADER + 1];
 extern const struct nla_policy ethnl_privflags_set_policy[ETHTOOL_A_PRIVFLAGS_FLAGS + 1];
 extern const struct nla_policy ethnl_rings_get_policy[ETHTOOL_A_RINGS_HEADER + 1];
-extern const struct nla_policy ethnl_rings_set_policy[ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN_MAX + 1];
+extern const struct nla_policy ethnl_rings_set_policy[ETHTOOL_A_RINGS_HEADER_DATA_SPLIT_THRESH_MAX + 1];
 extern const struct nla_policy ethnl_channels_get_policy[ETHTOOL_A_CHANNELS_HEADER + 1];
 extern const struct nla_policy ethnl_channels_set_policy[ETHTOOL_A_CHANNELS_COMBINED_COUNT + 1];
 extern const struct nla_policy ethnl_coalesce_get_policy[ETHTOOL_A_COALESCE_HEADER + 1];
net/ethtool/rings.c +35 -2
index b7865a14fdf8..e1fd82a91014 100644
@@ -61,7 +61,11 @@ static int rings_reply_size(const struct ethnl_req_info *req_base,
 	       nla_total_size(sizeof(u8))  +	/* _RINGS_TX_PUSH */
 	       nla_total_size(sizeof(u8))) +	/* _RINGS_RX_PUSH */
 	       nla_total_size(sizeof(u32)) +	/* _RINGS_TX_PUSH_BUF_LEN */
-	       nla_total_size(sizeof(u32));	/* _RINGS_TX_PUSH_BUF_LEN_MAX */
+	       nla_total_size(sizeof(u32)) +	/* _RINGS_TX_PUSH_BUF_LEN_MAX */
+	       nla_total_size(sizeof(u32)) +
+	       /* _RINGS_HEADER_DATA_SPLIT_THRESH */
+	       nla_total_size(sizeof(u32));
+	       /* _RINGS_HEADER_DATA_SPLIT_THRESH_MAX*/
 }
 
 static int rings_fill_reply(struct sk_buff *skb,
@@ -108,7 +112,12 @@ static int rings_fill_reply(struct sk_buff *skb,
 	     (nla_put_u32(skb, ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN_MAX,
 			  kr->tx_push_buf_max_len) ||
 	      nla_put_u32(skb, ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN,
-			  kr->tx_push_buf_len))))
+			  kr->tx_push_buf_len))) ||
+	    ((supported_ring_params & ETHTOOL_RING_USE_HDS_THRS) &&
+	     (nla_put_u32(skb, ETHTOOL_A_RINGS_HEADER_DATA_SPLIT_THRESH,
+			  kr->hds_thresh) ||
+	      nla_put_u32(skb, ETHTOOL_A_RINGS_HEADER_DATA_SPLIT_THRESH_MAX,
+			  kr->hds_thresh_max))))
 		return -EMSGSIZE;
 
 	return 0;
@@ -130,6 +139,7 @@ const struct nla_policy ethnl_rings_set_policy[] = {
 	[ETHTOOL_A_RINGS_TX_PUSH]		= NLA_POLICY_MAX(NLA_U8, 1),
 	[ETHTOOL_A_RINGS_RX_PUSH]		= NLA_POLICY_MAX(NLA_U8, 1),
 	[ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN]	= { .type = NLA_U32 },
+	[ETHTOOL_A_RINGS_HEADER_DATA_SPLIT_THRESH]	= { .type = NLA_U32 },
 };
 
 static int
@@ -155,6 +165,14 @@ ethnl_set_rings_validate(struct ethnl_req_info *req_info,
 		return -EOPNOTSUPP;
 	}
 
+	if (tb[ETHTOOL_A_RINGS_HEADER_DATA_SPLIT_THRESH] &&
+	    !(ops->supported_ring_params & ETHTOOL_RING_USE_HDS_THRS)) {
+		NL_SET_ERR_MSG_ATTR(info->extack,
+				    tb[ETHTOOL_A_RINGS_HEADER_DATA_SPLIT_THRESH],
+				    "setting header-data-split-thresh is not supported");
+		return -EOPNOTSUPP;
+	}
+
 	if (tb[ETHTOOL_A_RINGS_CQE_SIZE] &&
 	    !(ops->supported_ring_params & ETHTOOL_RING_USE_CQE_SIZE)) {
 		NL_SET_ERR_MSG_ATTR(info->extack,
@@ -222,9 +240,24 @@ ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info)
 			tb[ETHTOOL_A_RINGS_RX_PUSH], &mod);
 	ethnl_update_u32(&kernel_ringparam.tx_push_buf_len,
 			 tb[ETHTOOL_A_RINGS_TX_PUSH_BUF_LEN], &mod);
+	ethnl_update_u32(&kernel_ringparam.hds_thresh,
+			 tb[ETHTOOL_A_RINGS_HEADER_DATA_SPLIT_THRESH], &mod);
 	if (!mod)
 		return 0;
 
+	if (kernel_ringparam.tcp_data_split == ETHTOOL_TCP_DATA_SPLIT_ENABLED &&
+	    dev_xdp_sb_prog_count(dev)) {
+		NL_SET_ERR_MSG(info->extack,
+			       "tcp-data-split can not be enabled with single buffer XDP");
+		return -EINVAL;
+	}
+
+	if (kernel_ringparam.hds_thresh > kernel_ringparam.hds_thresh_max) {
+		NL_SET_BAD_ATTR(info->extack,
+				tb[ETHTOOL_A_RINGS_HEADER_DATA_SPLIT_THRESH_MAX]);
+		return -ERANGE;
+	}
+
 	/* ensure new ring parameters are within limits */
 	if (ringparam.rx_pending > ringparam.rx_max_pending)
 		err_attr = tb[ETHTOOL_A_RINGS_RX];
Signature · 1 line
2.34.1
#15 lore raw

Re: [PATCH net-next v4 3/8] net: ethtool: add support for configuring header-data-split-thresh

Quoted 13 lines · Taehee Yoo

The header-data-split-thresh option configures the threshold value of the header-data-split.
If a received packet size is larger than this threshold value, a packet will be split into header and payload.
The header indicates TCP and UDP header, but it depends on driver spec. The bnxt_en driver supports HDS(Header-Data-Split) configuration at FW level, affecting TCP and UDP too.
So, If header-data-split-thresh is set, it affects UDP and TCP packets.

Example:

   # ethtool -G <interface name> header-data-split-thresh <value>
Quoted 10 lines
   # ethtool -G enp14s0f0np0 tcp-data-split on header-data-split-thresh 256
   # ethtool -g enp14s0f0np0
   Ring parameters for enp14s0f0np0:
   Pre-set maximums:
   ...
   Header data split thresh:  256
   Current hardware settings:
   ...
   TCP data split:         on
   Header data split thresh:  256

This is a nit, feel free to ignore, but I wonder if we should call it 'Data split thresh' instead of 'Header data split threshold'.

It was a bit weird for me to refer to the feature as tcp-data-split, but the threshold as hds_threshold which i guess is short for header split threshold. Aligning the names to 'TCP data split [threshold]' would be nice I think.

Signature · 2 lines
Thanks,
Mina
author
#16 lore raw

Re: [PATCH net-next v4 3/8] net: ethtool: add support for configuring header-data-split-thresh

Quoted 26 lines · Mina Almasry
Quoted 13 lines · Taehee Yoo

The header-data-split-thresh option configures the threshold value of the header-data-split.
If a received packet size is larger than this threshold value, a packet will be split into header and payload.
The header indicates TCP and UDP header, but it depends on driver spec. The bnxt_en driver supports HDS(Header-Data-Split) configuration at FW level, affecting TCP and UDP too.
So, If header-data-split-thresh is set, it affects UDP and TCP packets.

Example:

   # ethtool -G <interface name> header-data-split-thresh <value>
Quoted 10 lines
   # ethtool -G enp14s0f0np0 tcp-data-split on header-data-split-thresh 256
   # ethtool -g enp14s0f0np0
   Ring parameters for enp14s0f0np0:
   Pre-set maximums:
   ...
   Header data split thresh:  256
   Current hardware settings:
   ...
   TCP data split:         on
   Header data split thresh:  256
Quoted 7 lines

This is a nit, feel free to ignore, but I wonder if we should call it 'Data split thresh' instead of 'Header data split threshold'.

It was a bit weird for me to refer to the feature as tcp-data-split, but the threshold as hds_threshold which i guess is short for header split threshold. Aligning the names to 'TCP data split [threshold]' would be nice I think.

The reason why I used it is that I thought a command name and print should be the same or very similar. Both "Data split thresh" and "TCP data split threshold" are similar to the command. But "Header data split thresh" is the same as the command. it's very clear. So I still prefer "Header data split thresh". But If you prefer these names, I will change it.

Thanks a lot!
Taehee Yoo

Quoted 4 lines

--
Thanks,
Mina

author
#17 lore raw

PATCH v4 4/8 bnxt_en: add support for header-data-split-thresh ethtool command

In reply to Taehee Yoo

The bnxt_en driver has configured the hds_threshold value automatically when TPA is enabled based on the rx-copybreak default value. Now the header-data-split-thresh ethtool command is added, so it adds an implementation of header-data-split-thresh option.

Configuration of the header-data-split-thresh is allowed only when the header-data-split is enabled. The default value of header-data-split-thresh is 256, which is the default value of rx-copybreak, which used to be the hds_thresh value.

# Example:

   # ethtool -G enp14s0f0np0 tcp-data-split on header-data-split-thresh 256
   # ethtool -g enp14s0f0np0
   Ring parameters for enp14s0f0np0:
   Pre-set maximums:
   ...
   Header data split thresh:  256
   Current hardware settings:
   ...
   TCP data split:         on
   Header data split thresh:  256

---

v4:
- Reduce hole in struct bnxt.
- Add ETHTOOL_RING_USE_HDS_THRS to indicate bnxt_en driver support header-data-split-thresh option.
- Add Test tag from Stanislav.

v3:
- Drop validation logic tcp-data-split and tcp-data-split-thresh.

v2:
- Patch added.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c         | 3 ++-
 drivers/net/ethernet/broadcom/bnxt/bnxt.h         | 2 ++
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 7 ++++++-
 3 files changed, 10 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
index 91ea42ff9b17..7d9da483b867 100644
@@ -4453,6 +4453,7 @@ void bnxt_set_tpa_flags(struct bnxt *bp)
 static void bnxt_init_ring_params(struct bnxt *bp)
 {
 	bp->rx_copybreak = BNXT_DEFAULT_RX_COPYBREAK;
+	bp->hds_threshold = BNXT_DEFAULT_RX_COPYBREAK;
 }
 
 /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
@@ -6427,7 +6428,7 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
 					  VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
 		req->enables |=
 			cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
-		req->hds_threshold = cpu_to_le16(bp->rx_copybreak);
+		req->hds_threshold = cpu_to_le16(bp->hds_threshold);
 	}
 	req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
 	return hwrm_req_send(bp, req);
drivers/net/ethernet/broadcom/bnxt/bnxt.h +2 -0
index 432bc19b35ea..e467341f1e5b 100644
@@ -2361,6 +2361,8 @@ struct bnxt {
 	u8			q_ids[BNXT_MAX_QUEUE];
 	u8			max_q;
 	u8			num_tc;
+#define BNXT_HDS_THRESHOLD_MAX	256
+	u16			hds_threshold;
 
 	unsigned int		current_interval;
 #define BNXT_TIMER_INTERVAL	HZ
drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c +6 -1
index 5172d0547e0c..73e821a23f56 100644
@@ -840,6 +840,9 @@ static void bnxt_get_ringparam(struct net_device *dev,
 	ering->rx_pending = bp->rx_ring_size;
 	ering->rx_jumbo_pending = bp->rx_agg_ring_size;
 	ering->tx_pending = bp->tx_ring_size;
+
+	kernel_ering->hds_thresh = bp->hds_threshold;
+	kernel_ering->hds_thresh_max = BNXT_HDS_THRESHOLD_MAX;
 }
 
 static int bnxt_set_ringparam(struct net_device *dev,
@@ -869,6 +872,7 @@ static int bnxt_set_ringparam(struct net_device *dev,
 		break;
 	}
 
+	bp->hds_threshold = (u16)kernel_ering->hds_thresh;
 	bp->rx_ring_size = ering->rx_pending;
 	bp->tx_ring_size = ering->tx_pending;
 	bnxt_set_ring_params(bp);
@@ -5357,7 +5361,8 @@ const struct ethtool_ops bnxt_ethtool_ops = {
 				     ETHTOOL_COALESCE_STATS_BLOCK_USECS |
 				     ETHTOOL_COALESCE_USE_ADAPTIVE_RX |
 				     ETHTOOL_COALESCE_USE_CQE,
-	.supported_ring_params	= ETHTOOL_RING_USE_TCP_DATA_SPLIT,
+	.supported_ring_params	= ETHTOOL_RING_USE_TCP_DATA_SPLIT |
+				  ETHTOOL_RING_USE_HDS_THRS,
 	.get_link_ksettings	= bnxt_get_link_ksettings,
 	.set_link_ksettings	= bnxt_set_link_ksettings,
 	.get_fec_stats		= bnxt_get_fec_stats,
Signature · 1 line
2.34.1
author
#18 lore raw

PATCH v4 5/8 net: devmem: add ring parameter filtering

In reply to Taehee Yoo

If driver doesn't support ring parameter or tcp-data-split configuration is not sufficient, the devmem should not be set up.
Before setup the devmem, tcp-data-split should be ON and header-data-split-thresh value should be 0.

---

v4:
- Check condition before __netif_get_rx_queue().
- Separate condition check.
- Add Test tag from Stanislav.

v3:
- Patch added.

 net/core/devmem.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
net/core/devmem.c +18 -0
index 11b91c12ee11..3425e872e87a 100644
@@ -8,6 +8,8 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/ethtool.h>
+#include <linux/ethtool_netlink.h>
 #include <linux/genalloc.h>
 #include <linux/mm.h>
 #include <linux/netdevice.h>
@@ -131,6 +133,8 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 				    struct net_devmem_dmabuf_binding *binding,
 				    struct netlink_ext_ack *extack)
 {
+	struct kernel_ethtool_ringparam kernel_ringparam = {};
+	struct ethtool_ringparam ringparam = {};
 	struct netdev_rx_queue *rxq;
 	u32 xa_idx;
 	int err;
@@ -140,6 +144,20 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
 		return -ERANGE;
 	}
 
+	if (!dev->ethtool_ops->get_ringparam)
+		return -EOPNOTSUPP;
+
+	dev->ethtool_ops->get_ringparam(dev, &ringparam, &kernel_ringparam,
+					extack);
+	if (kernel_ringparam.tcp_data_split != ETHTOOL_TCP_DATA_SPLIT_ENABLED) {
+		NL_SET_ERR_MSG(extack, "tcp-data-split is disabled");
+		return -EINVAL;
+	}
+	if (kernel_ringparam.hds_thresh) {
+		NL_SET_ERR_MSG(extack, "header-data-split-thresh is not zero");
+		return -EINVAL;
+	}
+
 	rxq = __netif_get_rx_queue(dev, rxq_idx);
 	if (rxq->mp_params.mp_priv) {
 		NL_SET_ERR_MSG(extack, "designated queue already memory provider bound");
Signature · 1 line
2.34.1
#19 lore raw

Re: [PATCH net-next v4 5/8] net: devmem: add ring parameter filtering

Hi Taehee, sorry for the late reply. I was out on vacation and needed to catch up on some stuff when I got back.

Quoted 44 lines · Taehee Yoo

If driver doesn't support ring parameter or tcp-data-split configuration is not sufficient, the devmem should not be set up.
Before setup the devmem, tcp-data-split should be ON and header-data-split-thresh value should be 0.

---

v4:
- Check condition before __netif_get_rx_queue().
- Separate condition check.
- Add Test tag from Stanislav.

v3:
- Patch added.

 net/core/devmem.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
net/core/devmem.c +4 -0
index 11b91c12ee11..3425e872e87a 100644
@@ -8,6 +8,8 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/ethtool.h>
+#include <linux/ethtool_netlink.h>
 #include <linux/genalloc.h>
 #include <linux/mm.h>
 #include <linux/netdevice.h>
@@ -131,6 +133,8 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
                                    struct net_devmem_dmabuf_binding *binding,
                                    struct netlink_ext_ack *extack)
 {
+       struct kernel_ethtool_ringparam kernel_ringparam = {};
+       struct ethtool_ringparam ringparam = {};
        struct netdev_rx_queue *rxq;
        u32 xa_idx;
        int err;

net/core/devmem.c int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, · line 149

Quoted 6 lines
net/core/devmem.c +3 -0
@@ -140,6 +144,20 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
                return -ERANGE;
        }
 
+       if (!dev->ethtool_ops->get_ringparam)
+               return -EOPNOTSUPP;
+

Maybe an error code not EOPNOTSUPP. I think that gets returned when NET_DEVMEM is not compiled in and other situations like that. Lets pick another error code? Maybe ENODEV.

Also consider extack error message. But it's very unlikely to hit this error, so maybe not necessary.

net/core/devmem.c int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, · line 160

Quoted 11 lines
net/core/devmem.c +11 -0
+       dev->ethtool_ops->get_ringparam(dev, &ringparam, &kernel_ringparam,
+                                       extack);
+       if (kernel_ringparam.tcp_data_split != ETHTOOL_TCP_DATA_SPLIT_ENABLED) {
+               NL_SET_ERR_MSG(extack, "tcp-data-split is disabled");
+               return -EINVAL;
+       }
+       if (kernel_ringparam.hds_thresh) {
+               NL_SET_ERR_MSG(extack, "header-data-split-thresh is not zero");
+               return -EINVAL;
+       }
+

Thinking about drivers that support tcp-data-split, but don't support any kind of hds_thresh. For us (GVE), the hds_thresh is implicitly always 0.

Does the driver need to explicitly set hds_thresh to 0? If so, that adds a bit of churn to driver code. Is it possible to detect in this function that the driver doesn't support hds_thresh and allow the binding if so?

I see in the previous patch you do something like:

supported_ring_params & ETHTOOL_RING_USE_HDS_THRS

To detect there is hds_thresh support. I was wondering if something like this is possible so we don't have to update GVE and all future drivers to explicitly set thresh to 0.

Other than that, looks fine to me.

Signature · 2 lines
Thanks,
Mina
author
#20 lore raw

Re: [PATCH net-next v4 5/8] net: devmem: add ring parameter filtering

Quoted 3 lines · Mina Almasry

Hi Taehee, sorry for the late reply. I was out on vacation and needed to catch up on some stuff when I got back.

Hi Mina,
Thank you so much for your review :)

Quoted 49 lines · Taehee Yoo
Quoted 47 lines

If driver doesn't support ring parameter or tcp-data-split configuration is not sufficient, the devmem should not be set up.
Before setup the devmem, tcp-data-split should be ON and header-data-split-thresh value should be 0.

---

v4:
- Check condition before __netif_get_rx_queue().
- Separate condition check.
- Add Test tag from Stanislav.

v3:
- Patch added.

 net/core/devmem.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
net/core/devmem.c +4 -0
index 11b91c12ee11..3425e872e87a 100644
@@ -8,6 +8,8 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/ethtool.h>
+#include <linux/ethtool_netlink.h>
 #include <linux/genalloc.h>
 #include <linux/mm.h>
 #include <linux/netdevice.h>
@@ -131,6 +133,8 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
                                    struct net_devmem_dmabuf_binding *binding,
                                    struct netlink_ext_ack *extack)
 {
+       struct kernel_ethtool_ringparam kernel_ringparam = {};
+       struct ethtool_ringparam ringparam = {};
        struct netdev_rx_queue *rxq;
        u32 xa_idx;
        int err;
@@ -140,6 +144,20 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
                return -ERANGE;
        }
 
Quoted 7 lines

net/core/devmem.c int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, · line 149

Quoted 3 lines
net/core/devmem.c +3 -0
+       if (!dev->ethtool_ops->get_ringparam)
+               return -EOPNOTSUPP;
+

Maybe an error code not EOPNOTSUPP. I think that gets returned when NET_DEVMEM is not compiled in and other situations like that. Lets pick another error code? Maybe ENODEV.

There are several same code in the ethtool core.
It returns EOPNOTSUPP consistently.
In the v3 series, Brett reviewed it.
So, I changed it from EINVAL to EOPNOTSUPP it was reasonable to me. So I prefer EOPNOTSUPP but I will follow your decision. What do you think?

Quoted 3 lines

Also consider extack error message. But it's very unlikely to hit this error, so maybe not necessary.

I removed extack from the v3. because ethtool doesn't use extack for the same logic. It was reasonable to me.

Quoted 22 lines

net/core/devmem.c int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, · line 160

Quoted 12 lines
net/core/devmem.c +11 -0
+       dev->ethtool_ops->get_ringparam(dev, &ringparam, &kernel_ringparam,
+                                       extack);
+       if (kernel_ringparam.tcp_data_split != ETHTOOL_TCP_DATA_SPLIT_ENABLED) {
+               NL_SET_ERR_MSG(extack, "tcp-data-split is disabled");
+               return -EINVAL;
+       }
+       if (kernel_ringparam.hds_thresh) {
+               NL_SET_ERR_MSG(extack, "header-data-split-thresh is not zero");
+               return -EINVAL;
+       }
+

Thinking about drivers that support tcp-data-split, but don't support any kind of hds_thresh. For us (GVE), the hds_thresh is implicitly always 0.

Does the driver need to explicitly set hds_thresh to 0? If so, that adds a bit of churn to driver code. Is it possible to detect in this function that the driver doesn't support hds_thresh and allow the binding if so?

Quoted 7 lines

I see in the previous patch you do something like:

supported_ring_params & ETHTOOL_RING_USE_HDS_THRS

To detect there is hds_thresh support. I was wondering if something like this is possible so we don't have to update GVE and all future drivers to explicitly set thresh to 0.

How about setting maximum hds_threshold to 0?
The default value of hds_threshold of course 0.
I think gve code does not need to change much, just adding like below will be okay.

I think if drivers don't support setting hds_threshold explicitly, it is actually the same as support only 0.
So, there is no problem I think.

I didn't analyze gve driver code, So I might think it too optimistically.

#define GVE_HDS_THRESHOLD_MAX 0 kernel_ering->hds_thresh = GVE_HDS_THRESHOLD_MAX; kernel_ering->hds_thresh_max = GVE_HDS_THRESHOLD_MAX;
...
.supported_ring_params = ETHTOOL_RING_USE_TCP_DATA_SPLIT | ETHTOOL_RING_USE_HDS_THRS,

ethtool command may show like this.
ethtool -g enp7s0f3np3
Ring parameters for enp7s0f3np3:
Pre-set maximums:
...
Header data split thresh: 0
Current hardware settings:
...

TCP data split:         on
Header data split thresh:       0

If a driver can't set up hds_threshold, ethtool command may show like this. ethtool -g enp7s0f3np3
Ring parameters for enp7s0f3np3:
Pre-set maximums:

TX push buff len:       n/a
Header data split thresh:       n/a
Current hardware settings:
...
TCP data split:         on
Header data split thresh:       n/a

Thanks a lot!
Taehee Yoo

Quoted 7 lines

Other than that, looks fine to me.

--
Thanks,
Mina

Reviewed-by
#21 lore raw

Re: [PATCH net-next v4 5/8] net: devmem: add ring parameter filtering

Quoted 74 lines · Taehee Yoo
Quoted 3 lines · Mina Almasry

Hi Taehee, sorry for the late reply. I was out on vacation and needed to catch up on some stuff when I got back.

Hi Mina,
Thank you so much for your review :)

Quoted 49 lines · Taehee Yoo
Quoted 47 lines

If driver doesn't support ring parameter or tcp-data-split configuration is not sufficient, the devmem should not be set up.
Before setup the devmem, tcp-data-split should be ON and header-data-split-thresh value should be 0.

---

v4:
- Check condition before __netif_get_rx_queue().
- Separate condition check.
- Add Test tag from Stanislav.

v3:
- Patch added.

 net/core/devmem.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
net/core/devmem.c +4 -0
index 11b91c12ee11..3425e872e87a 100644
@@ -8,6 +8,8 @@
  */
 
 #include <linux/dma-buf.h>
+#include <linux/ethtool.h>
+#include <linux/ethtool_netlink.h>
 #include <linux/genalloc.h>
 #include <linux/mm.h>
 #include <linux/netdevice.h>
@@ -131,6 +133,8 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
                                    struct net_devmem_dmabuf_binding *binding,
                                    struct netlink_ext_ack *extack)
 {
+       struct kernel_ethtool_ringparam kernel_ringparam = {};
+       struct ethtool_ringparam ringparam = {};
        struct netdev_rx_queue *rxq;
        u32 xa_idx;
        int err;
@@ -140,6 +144,20 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,
                return -ERANGE;
        }
 
Quoted 7 lines

net/core/devmem.c int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, · line 149

Quoted 3 lines
net/core/devmem.c +3 -0
+       if (!dev->ethtool_ops->get_ringparam)
+               return -EOPNOTSUPP;
+

Maybe an error code not EOPNOTSUPP. I think that gets returned when NET_DEVMEM is not compiled in and other situations like that. Lets pick another error code? Maybe ENODEV.

There are several same code in the ethtool core.
It returns EOPNOTSUPP consistently.
In the v3 series, Brett reviewed it.
So, I changed it from EINVAL to EOPNOTSUPP it was reasonable to me. So I prefer EOPNOTSUPP but I will follow your decision. What do you think?

Quoted 1 line
Quoted 6 lines
Quoted 2 lines

Also consider extack error message. But it's very unlikely to hit this error, so maybe not necessary.

I removed extack from the v3. because ethtool doesn't use extack for the same logic. It was reasonable to me.

Ah, looks like I accidentally re-opened discussion on a couple of items that you're already aligned on. Not critical. This is fine by me.

Quoted 39 lines
Quoted 22 lines

net/core/devmem.c int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx, · line 160

Quoted 12 lines
net/core/devmem.c +11 -0
+       dev->ethtool_ops->get_ringparam(dev, &ringparam, &kernel_ringparam,
+                                       extack);
+       if (kernel_ringparam.tcp_data_split != ETHTOOL_TCP_DATA_SPLIT_ENABLED) {
+               NL_SET_ERR_MSG(extack, "tcp-data-split is disabled");
+               return -EINVAL;
+       }
+       if (kernel_ringparam.hds_thresh) {
+               NL_SET_ERR_MSG(extack, "header-data-split-thresh is not zero");
+               return -EINVAL;
+       }
+

Thinking about drivers that support tcp-data-split, but don't support any kind of hds_thresh. For us (GVE), the hds_thresh is implicitly always 0.

Does the driver need to explicitly set hds_thresh to 0? If so, that adds a bit of churn to driver code. Is it possible to detect in this function that the driver doesn't support hds_thresh and allow the binding if so?

Quoted 7 lines

I see in the previous patch you do something like:

supported_ring_params & ETHTOOL_RING_USE_HDS_THRS

To detect there is hds_thresh support. I was wondering if something like this is possible so we don't have to update GVE and all future drivers to explicitly set thresh to 0.

How about setting maximum hds_threshold to 0?
The default value of hds_threshold of course 0.
I think gve code does not need to change much, just adding like below will be okay.

I think if drivers don't support setting hds_threshold explicitly, it is actually the same as support only 0.
So, there is no problem I think.

Quoted 9 lines

I didn't analyze gve driver code, So I might think it too optimistically.

#define GVE_HDS_THRESHOLD_MAX 0 kernel_ering->hds_thresh = GVE_HDS_THRESHOLD_MAX; kernel_ering->hds_thresh_max = GVE_HDS_THRESHOLD_MAX;
...
.supported_ring_params = ETHTOOL_RING_USE_TCP_DATA_SPLIT | ETHTOOL_RING_USE_HDS_THRS,

OK, if you can think of a way to do this without any churn to other drivers, that would be better, but this is fine by me either way.

Signature · 2 lines
Thanks,
Mina
author
#22 lore raw

PATCH v4 6/8 net: ethtool: add ring parameter filtering

In reply to Taehee Yoo

While the devmem is running, the tcp-data-split and header-data-split-thresh configuration should not be changed. If user tries to change tcp-data-split and threshold value while the devmem is running, it fails and shows extack message.

---

v4:
- Add netdev_devmem_enabled() helper.
- Add Test tag from Stanislav.

v3:
- Patch added

 include/net/netdev_rx_queue.h | 14 ++++++++++++++
 net/ethtool/common.h          |  1 +
 net/ethtool/rings.c           | 13 +++++++++++++
 3 files changed, 28 insertions(+)
include/net/netdev_rx_queue.h +14 -0
index 596836abf7bf..7fbb64ce8d89 100644
@@ -55,6 +55,20 @@ get_netdev_rx_queue_index(struct netdev_rx_queue *queue)
 	return index;
 }
 
+static inline bool netdev_devmem_enabled(struct net_device *dev)
+{
+	struct netdev_rx_queue *queue;
+	int i;
+
+	for (i = 0; i < dev->real_num_rx_queues; i++) {
+		queue = __netif_get_rx_queue(dev, i);
+		if (queue->mp_params.mp_priv)
+			return true;
+	}
+
+	return false;
+}
+
 int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq);
 
 #endif
net/ethtool/common.h +1 -0
index 4a2de3ce7354..5b8e5847ba3c 100644
@@ -5,6 +5,7 @@
 
 #include <linux/netdevice.h>
 #include <linux/ethtool.h>
+#include <net/netdev_rx_queue.h>
 
 #define ETHTOOL_DEV_FEATURE_WORDS	DIV_ROUND_UP(NETDEV_FEATURE_COUNT, 32)
 
net/ethtool/rings.c +13 -0
index e1fd82a91014..ca313c301081 100644
@@ -258,6 +258,19 @@ ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info)
 		return -ERANGE;
 	}
 
+	if (netdev_devmem_enabled(dev)) {
+		if (kernel_ringparam.tcp_data_split !=
+		    ETHTOOL_TCP_DATA_SPLIT_ENABLED) {
+			NL_SET_ERR_MSG(info->extack,
+				       "tcp-data-split should be enabled while devmem is running");
+			return -EINVAL;
+		} else if (kernel_ringparam.hds_thresh) {
+			NL_SET_ERR_MSG(info->extack,
+				       "header-data-split-thresh should be zero while devmem is running");
+			return -EINVAL;
+		}
+	}
+
 	/* ensure new ring parameters are within limits */
 	if (ringparam.rx_pending > ringparam.rx_max_pending)
 		err_attr = tb[ETHTOOL_A_RINGS_RX];
Signature · 1 line
2.34.1
#23 lore raw

Re: [PATCH net-next v4 6/8] net: ethtool: add ring parameter filtering

Quoted 27 lines · Taehee Yoo

While the devmem is running, the tcp-data-split and header-data-split-thresh configuration should not be changed. If user tries to change tcp-data-split and threshold value while the devmem is running, it fails and shows extack message.

---

v4:
- Add netdev_devmem_enabled() helper.
- Add Test tag from Stanislav.

v3:
- Patch added

 include/net/netdev_rx_queue.h | 14 ++++++++++++++
 net/ethtool/common.h          |  1 +
 net/ethtool/rings.c           | 13 +++++++++++++
 3 files changed, 28 insertions(+)
include/net/netdev_rx_queue.h +0 -0
index 596836abf7bf..7fbb64ce8d89 100644

include/net/netdev_rx_queue.h get_netdev_rx_queue_index(struct netdev_rx_queue *queue) · line 58

Quoted 4 lines
include/net/netdev_rx_queue.h +1 -0
@@ -55,6 +55,20 @@ get_netdev_rx_queue_index(struct netdev_rx_queue *queue)
        return index;
 }
 
+static inline bool netdev_devmem_enabled(struct net_device *dev)

Mega nit: netdev_memory_provider_enabled().

This is actually not devmem specific, and there is already an io_uring provider in the works.

But, also, we already have dev_get_min_mp_channel_count() defined in linux/netdevice.h. Lets re-use that one instead of adding another helper that does almost the same thing. Sorry, I should have remembered we already have this helper in the last iteration.

Other than that, looks fine to me.

Quoted 33 lines
include/net/netdev_rx_queue.h +13 -0
+{
+       struct netdev_rx_queue *queue;
+       int i;
+
+       for (i = 0; i < dev->real_num_rx_queues; i++) {
+               queue = __netif_get_rx_queue(dev, i);
+               if (queue->mp_params.mp_priv)
+                       return true;
+       }
+
+       return false;
+}
+
 int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq);
 
 #endif
net/ethtool/common.h +1 -0
index 4a2de3ce7354..5b8e5847ba3c 100644
@@ -5,6 +5,7 @@
 
 #include <linux/netdevice.h>
 #include <linux/ethtool.h>
+#include <net/netdev_rx_queue.h>
 
 #define ETHTOOL_DEV_FEATURE_WORDS      DIV_ROUND_UP(NETDEV_FEATURE_COUNT, 32)
 
net/ethtool/rings.c +0 -0
index e1fd82a91014..ca313c301081 100644

net/ethtool/rings.c ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info) · line 265

Quoted 8 lines
net/ethtool/rings.c +5 -0
@@ -258,6 +258,19 @@ ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info)
                return -ERANGE;
        }
 
+       if (netdev_devmem_enabled(dev)) {
+               if (kernel_ringparam.tcp_data_split !=
+                   ETHTOOL_TCP_DATA_SPLIT_ENABLED) {
+                       NL_SET_ERR_MSG(info->extack,
+                                      "tcp-data-split should be enabled while devmem is running");

Maybe: "can't disable tcp-data-split while device has memory provider enabled"

net/ethtool/rings.c ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info) · line 269

Quoted 4 lines
net/ethtool/rings.c +4 -0
+                       return -EINVAL;
+               } else if (kernel_ringparam.hds_thresh) {
+                       NL_SET_ERR_MSG(info->extack,
+                                      "header-data-split-thresh should be zero while devmem is running");

Maybe: "can't set non-zero hds_thresh while device is memory provider enabled".

Signature · 2 lines
Thanks,
Mina
author
#24 lore raw

Re: [PATCH net-next v4 6/8] net: ethtool: add ring parameter filtering

Quoted 36 lines · Mina Almasry
Quoted 27 lines · Taehee Yoo

While the devmem is running, the tcp-data-split and header-data-split-thresh configuration should not be changed. If user tries to change tcp-data-split and threshold value while the devmem is running, it fails and shows extack message.

---

v4:
- Add netdev_devmem_enabled() helper.
- Add Test tag from Stanislav.

v3:
- Patch added

 include/net/netdev_rx_queue.h | 14 ++++++++++++++
 net/ethtool/common.h          |  1 +
 net/ethtool/rings.c           | 13 +++++++++++++
 3 files changed, 28 insertions(+)
include/net/netdev_rx_queue.h +0 -0
index 596836abf7bf..7fbb64ce8d89 100644

include/net/netdev_rx_queue.h get_netdev_rx_queue_index(struct netdev_rx_queue *queue) · line 58

Quoted 4 lines
include/net/netdev_rx_queue.h +1 -0
@@ -55,6 +55,20 @@ get_netdev_rx_queue_index(struct netdev_rx_queue *queue)
        return index;
 }
 
+static inline bool netdev_devmem_enabled(struct net_device *dev)

Mega nit: netdev_memory_provider_enabled().

Quoted 7 lines

This is actually not devmem specific, and there is already an io_uring provider in the works.

But, also, we already have dev_get_min_mp_channel_count() defined in linux/netdevice.h. Lets re-use that one instead of adding another helper that does almost the same thing. Sorry, I should have remembered we already have this helper in the last iteration.

Ah, I didn't catch it too.
I will use dev_get_min_mp_channel_count() instead. Thanks a lot!

Quoted 39 lines

Other than that, looks fine to me.

Quoted 36 lines
include/net/netdev_rx_queue.h +13 -0
+{
+       struct netdev_rx_queue *queue;
+       int i;
+
+       for (i = 0; i < dev->real_num_rx_queues; i++) {
+               queue = __netif_get_rx_queue(dev, i);
+               if (queue->mp_params.mp_priv)
+                       return true;
+       }
+
+       return false;
+}
+
 int netdev_rx_queue_restart(struct net_device *dev, unsigned int rxq);
 
 #endif
net/ethtool/common.h +1 -0
index 4a2de3ce7354..5b8e5847ba3c 100644
@@ -5,6 +5,7 @@
 
 #include <linux/netdevice.h>
 #include <linux/ethtool.h>
+#include <net/netdev_rx_queue.h>
 
 #define ETHTOOL_DEV_FEATURE_WORDS      DIV_ROUND_UP(NETDEV_FEATURE_COUNT, 32)
 
net/ethtool/rings.c +0 -0
index e1fd82a91014..ca313c301081 100644
@@ -258,6 +258,19 @@ ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info)
                return -ERANGE;
        }
 
Quoted 7 lines

net/ethtool/rings.c ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info) · line 265

Quoted 5 lines
net/ethtool/rings.c +5 -0
+       if (netdev_devmem_enabled(dev)) {
+               if (kernel_ringparam.tcp_data_split !=
+                   ETHTOOL_TCP_DATA_SPLIT_ENABLED) {
+                       NL_SET_ERR_MSG(info->extack,
+                                      "tcp-data-split should be enabled while devmem is running");

Maybe: "can't disable tcp-data-split while device has memory provider enabled"

Thanks! I will use it!

Quoted 7 lines

net/ethtool/rings.c ethnl_set_rings(struct ethnl_req_info *req_info, struct genl_info *info) · line 269

Quoted 5 lines
net/ethtool/rings.c +4 -0
+                       return -EINVAL;
+               } else if (kernel_ringparam.hds_thresh) {
+                       NL_SET_ERR_MSG(info->extack,
+                                      "header-data-split-thresh should be zero while devmem is running");

Maybe: "can't set non-zero hds_thresh while device is memory provider enabled".

Thanks, I will use it too.

Thanks a lot!
Taehee Yoo

Quoted 5 lines

--
Thanks,
Mina

author
#25 lore raw

PATCH v4 7/8 net: netmem: add netmem_is_pfmemalloc() helper function

In reply to Taehee Yoo

The netmem_is_pfmemalloc() is a netmem version of page_is_pfmemalloc().

---

v4:
- Patch added.

 include/net/netmem.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/net/netmem.h +8 -0
index 8a6e20be4b9d..49ae2bf05362 100644
@@ -171,4 +171,12 @@ static inline unsigned long netmem_get_dma_addr(netmem_ref netmem)
 	return __netmem_clear_lsb(netmem)->dma_addr;
 }
 
+static inline bool netmem_is_pfmemalloc(netmem_ref netmem)
+{
+	if (netmem_is_net_iov(netmem))
+		return false;
+
+	return page_is_pfmemalloc(netmem_to_page(netmem));
+}
+
 #endif /* _NET_NETMEM_H */
Signature · 1 line
2.34.1
author
#27 lore raw

PATCH v4 8/8 bnxt_en: add support for device memory tcp

In reply to Taehee Yoo

Currently, bnxt_en driver satisfies the requirements of Device memory TCP, which is tcp-data-split.
So, it implements Device memory TCP for bnxt_en driver.

From now on, the aggregation ring handles netmem_ref instead of page regardless of the on/off of netmem.
So, for the aggregation ring, memory will be handled with the netmem page_pool API instead of generic page_pool API.

If Devmem is enabled, netmem_ref is used as-is and if Devmem is not enabled, netmem_ref will be converted to page and that is used.

Driver recognizes whether the devmem is set or unset based on the mp_params.mp_priv is not NULL.
Only if devmem is set, it passes PP_FLAG_ALLOW_UNREADABLE_NETMEM.

---

v4:
- Do not select NET_DEVMEM in Kconfig.
- Pass PP_FLAG_ALLOW_UNREADABLE_NETMEM flag unconditionally.
- Add __bnxt_rx_agg_pages_xdp().
- Use gfp flag in __bnxt_alloc_rx_netmem().
- Do not add *offset in the __bnxt_alloc_rx_netmem().
- Do not pass queue_idx to bnxt_alloc_rx_page_pool().
- Add Test tag from Stanislav.
- Add page_pool_recycle_direct_netmem() helper.

v3:
- Patch added.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 182 ++++++++++++++++------
 drivers/net/ethernet/broadcom/bnxt/bnxt.h |   2 +-
 include/net/page_pool/helpers.h           |   6 +
 3 files changed, 142 insertions(+), 48 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +135 -47
index 7d9da483b867..7924b1da0413 100644
@@ -55,6 +55,7 @@
 #include <net/page_pool/helpers.h>
 #include <linux/align.h>
 #include <net/netdev_queues.h>
+#include <net/netdev_rx_queue.h>
 
 #include "bnxt_hsi.h"
 #include "bnxt.h"
@@ -863,6 +864,22 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
 		bnapi->events &= ~BNXT_TX_CMP_EVENT;
 }
 
+static netmem_ref __bnxt_alloc_rx_netmem(struct bnxt *bp, dma_addr_t *mapping,
+					 struct bnxt_rx_ring_info *rxr,
+					 unsigned int *offset,
+					 gfp_t gfp)
+{
+	netmem_ref netmem;
+
+	netmem = page_pool_alloc_netmem(rxr->page_pool, gfp);
+	if (!netmem)
+		return 0;
+	*offset = 0;
+
+	*mapping = page_pool_get_dma_addr_netmem(netmem);
+	return netmem;
+}
+
 static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
 					 struct bnxt_rx_ring_info *rxr,
 					 unsigned int *offset,
@@ -972,21 +989,21 @@ static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
 	return next;
 }
 
-static inline int bnxt_alloc_rx_page(struct bnxt *bp,
-				     struct bnxt_rx_ring_info *rxr,
-				     u16 prod, gfp_t gfp)
+static inline int bnxt_alloc_rx_netmem(struct bnxt *bp,
+				       struct bnxt_rx_ring_info *rxr,
+				       u16 prod, gfp_t gfp)
 {
 	struct rx_bd *rxbd =
 		&rxr->rx_agg_desc_ring[RX_AGG_RING(bp, prod)][RX_IDX(prod)];
 	struct bnxt_sw_rx_agg_bd *rx_agg_buf;
-	struct page *page;
-	dma_addr_t mapping;
 	u16 sw_prod = rxr->rx_sw_agg_prod;
 	unsigned int offset = 0;
+	dma_addr_t mapping;
+	netmem_ref netmem;
 
-	page = __bnxt_alloc_rx_page(bp, &mapping, rxr, &offset, gfp);
+	netmem = __bnxt_alloc_rx_netmem(bp, &mapping, rxr, &offset, gfp);
 
-	if (!page)
+	if (!netmem)
 		return -ENOMEM;
 
 	if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
@@ -996,7 +1013,7 @@ static inline int bnxt_alloc_rx_page(struct bnxt *bp,
 	rx_agg_buf = &rxr->rx_agg_ring[sw_prod];
 	rxr->rx_sw_agg_prod = RING_RX_AGG(bp, NEXT_RX_AGG(sw_prod));
 
-	rx_agg_buf->page = page;
+	rx_agg_buf->netmem = netmem;
 	rx_agg_buf->offset = offset;
 	rx_agg_buf->mapping = mapping;
 	rxbd->rx_bd_haddr = cpu_to_le64(mapping);
@@ -1044,7 +1061,7 @@ static void bnxt_reuse_rx_agg_bufs(struct bnxt_cp_ring_info *cpr, u16 idx,
 		struct rx_agg_cmp *agg;
 		struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf;
 		struct rx_bd *prod_bd;
-		struct page *page;
+		netmem_ref netmem;
 
 		if (p5_tpa)
 			agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, start + i);
@@ -1061,11 +1078,11 @@ static void bnxt_reuse_rx_agg_bufs(struct bnxt_cp_ring_info *cpr, u16 idx,
 		cons_rx_buf = &rxr->rx_agg_ring[cons];
 
 		/* It is possible for sw_prod to be equal to cons, so
-		 * set cons_rx_buf->page to NULL first.
+		 * set cons_rx_buf->netmem to 0 first.
 		 */
-		page = cons_rx_buf->page;
-		cons_rx_buf->page = NULL;
-		prod_rx_buf->page = page;
+		netmem = cons_rx_buf->netmem;
+		cons_rx_buf->netmem = 0;
+		prod_rx_buf->netmem = netmem;
 		prod_rx_buf->offset = cons_rx_buf->offset;
 
 		prod_rx_buf->mapping = cons_rx_buf->mapping;
@@ -1190,29 +1207,104 @@ static struct sk_buff *bnxt_rx_skb(struct bnxt *bp,
 	return skb;
 }
 
-static u32 __bnxt_rx_agg_pages(struct bnxt *bp,
-			       struct bnxt_cp_ring_info *cpr,
-			       struct skb_shared_info *shinfo,
-			       u16 idx, u32 agg_bufs, bool tpa,
-			       struct xdp_buff *xdp)
+static bool __bnxt_rx_agg_pages_skb(struct bnxt *bp,
+				    struct bnxt_cp_ring_info *cpr,
+				    struct sk_buff *skb,
+				    u16 idx, u32 agg_bufs, bool tpa)
 {
 	struct bnxt_napi *bnapi = cpr->bnapi;
 	struct pci_dev *pdev = bp->pdev;
-	struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
-	u16 prod = rxr->rx_agg_prod;
+	struct bnxt_rx_ring_info *rxr;
 	u32 i, total_frag_len = 0;
 	bool p5_tpa = false;
+	u16 prod;
+
+	rxr = bnapi->rx_ring;
+	prod = rxr->rx_agg_prod;
 
 	if ((bp->flags & BNXT_FLAG_CHIP_P5_PLUS) && tpa)
 		p5_tpa = true;
 
 	for (i = 0; i < agg_bufs; i++) {
-		skb_frag_t *frag = &shinfo->frags[i];
-		u16 cons, frag_len;
+		struct bnxt_sw_rx_agg_bd *cons_rx_buf;
 		struct rx_agg_cmp *agg;
+		u16 cons, frag_len;
+		dma_addr_t mapping;
+		netmem_ref netmem;
+
+		if (p5_tpa)
+			agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, i);
+		else
+			agg = bnxt_get_agg(bp, cpr, idx, i);
+		cons = agg->rx_agg_cmp_opaque;
+		frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) &
+			    RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
+
+		cons_rx_buf = &rxr->rx_agg_ring[cons];
+		skb_add_rx_frag_netmem(skb, i, cons_rx_buf->netmem,
+				       cons_rx_buf->offset, frag_len,
+				       BNXT_RX_PAGE_SIZE);
+		__clear_bit(cons, rxr->rx_agg_bmap);
+
+		/* It is possible for bnxt_alloc_rx_netmem() to allocate
+		 * a sw_prod index that equals the cons index, so we
+		 * need to clear the cons entry now.
+		 */
+		mapping = cons_rx_buf->mapping;
+		netmem = cons_rx_buf->netmem;
+		cons_rx_buf->netmem = 0;
+
+		if (bnxt_alloc_rx_netmem(bp, rxr, prod, GFP_ATOMIC) != 0) {
+			skb->len -= frag_len;
+			skb->data_len -= frag_len;
+			skb->truesize -= BNXT_RX_PAGE_SIZE;
+			--skb_shinfo(skb)->nr_frags;
+			cons_rx_buf->netmem = netmem;
+
+			/* Update prod since possibly some pages have been
+			 * allocated already.
+			 */
+			rxr->rx_agg_prod = prod;
+			bnxt_reuse_rx_agg_bufs(cpr, idx, i, agg_bufs - i, tpa);
+			return 0;
+		}
+
+		dma_sync_single_for_cpu(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE,
+					bp->rx_dir);
+
+		total_frag_len += frag_len;
+		prod = NEXT_RX_AGG(prod);
+	}
+	rxr->rx_agg_prod = prod;
+	return total_frag_len;
+}
+
+static u32 __bnxt_rx_agg_pages_xdp(struct bnxt *bp,
+				   struct bnxt_cp_ring_info *cpr,
+				   struct skb_shared_info *shinfo,
+				   u16 idx, u32 agg_bufs, bool tpa,
+				   struct xdp_buff *xdp)
+{
+	struct bnxt_napi *bnapi = cpr->bnapi;
+	struct pci_dev *pdev = bp->pdev;
+	struct bnxt_rx_ring_info *rxr;
+	u32 i, total_frag_len = 0;
+	bool p5_tpa = false;
+	u16 prod;
+
+	rxr = bnapi->rx_ring;
+	prod = rxr->rx_agg_prod;
+
+	if ((bp->flags & BNXT_FLAG_CHIP_P5_PLUS) && tpa)
+		p5_tpa = true;
+
+	for (i = 0; i < agg_bufs; i++) {
 		struct bnxt_sw_rx_agg_bd *cons_rx_buf;
-		struct page *page;
+		skb_frag_t *frag = &shinfo->frags[i];
+		struct rx_agg_cmp *agg;
+		u16 cons, frag_len;
 		dma_addr_t mapping;
+		netmem_ref netmem;
 
 		if (p5_tpa)
 			agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, i);
@@ -1223,9 +1315,10 @@ static u32 __bnxt_rx_agg_pages(struct bnxt *bp,
 			    RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
 
 		cons_rx_buf = &rxr->rx_agg_ring[cons];
-		skb_frag_fill_page_desc(frag, cons_rx_buf->page,
-					cons_rx_buf->offset, frag_len);
+		skb_frag_fill_netmem_desc(frag, cons_rx_buf->netmem,
+					  cons_rx_buf->offset, frag_len);
 		shinfo->nr_frags = i + 1;
+
 		__clear_bit(cons, rxr->rx_agg_bmap);
 
 		/* It is possible for bnxt_alloc_rx_page() to allocate
@@ -1233,15 +1326,15 @@ static u32 __bnxt_rx_agg_pages(struct bnxt *bp,
 		 * need to clear the cons entry now.
 		 */
 		mapping = cons_rx_buf->mapping;
-		page = cons_rx_buf->page;
-		cons_rx_buf->page = NULL;
+		netmem = cons_rx_buf->netmem;
+		cons_rx_buf->netmem = 0;
 
-		if (xdp && page_is_pfmemalloc(page))
+		if (netmem_is_pfmemalloc(netmem))
 			xdp_buff_set_frag_pfmemalloc(xdp);
 
-		if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) {
+		if (bnxt_alloc_rx_netmem(bp, rxr, prod, GFP_ATOMIC) != 0) {
 			--shinfo->nr_frags;
-			cons_rx_buf->page = page;
+			cons_rx_buf->netmem = netmem;
 
 			/* Update prod since possibly some pages have been
 			 * allocated already.
@@ -1266,20 +1359,12 @@ static struct sk_buff *bnxt_rx_agg_pages_skb(struct bnxt *bp,
 					     struct sk_buff *skb, u16 idx,
 					     u32 agg_bufs, bool tpa)
 {
-	struct skb_shared_info *shinfo = skb_shinfo(skb);
-	u32 total_frag_len = 0;
-
-	total_frag_len = __bnxt_rx_agg_pages(bp, cpr, shinfo, idx,
-					     agg_bufs, tpa, NULL);
-	if (!total_frag_len) {
+	if (!__bnxt_rx_agg_pages_skb(bp, cpr, skb, idx, agg_bufs, tpa)) {
 		skb_mark_for_recycle(skb);
 		dev_kfree_skb(skb);
 		return NULL;
 	}
 
-	skb->data_len += total_frag_len;
-	skb->len += total_frag_len;
-	skb->truesize += BNXT_RX_PAGE_SIZE * agg_bufs;
 	return skb;
 }
 
@@ -1294,8 +1379,8 @@ static u32 bnxt_rx_agg_pages_xdp(struct bnxt *bp,
 	if (!xdp_buff_has_frags(xdp))
 		shinfo->nr_frags = 0;
 
-	total_frag_len = __bnxt_rx_agg_pages(bp, cpr, shinfo,
-					     idx, agg_bufs, tpa, xdp);
+	total_frag_len = __bnxt_rx_agg_pages_xdp(bp, cpr, shinfo,
+						 idx, agg_bufs, tpa, xdp);
 	if (total_frag_len) {
 		xdp_buff_set_frags_flag(xdp);
 		shinfo->nr_frags = agg_bufs;
@@ -3341,15 +3426,15 @@ static void bnxt_free_one_rx_agg_ring(struct bnxt *bp, struct bnxt_rx_ring_info
 
 	for (i = 0; i < max_idx; i++) {
 		struct bnxt_sw_rx_agg_bd *rx_agg_buf = &rxr->rx_agg_ring[i];
-		struct page *page = rx_agg_buf->page;
+		netmem_ref netmem = rx_agg_buf->netmem;
 
-		if (!page)
+		if (!netmem)
 			continue;
 
-		rx_agg_buf->page = NULL;
+		rx_agg_buf->netmem = 0;
 		__clear_bit(i, rxr->rx_agg_bmap);
 
-		page_pool_recycle_direct(rxr->page_pool, page);
+		page_pool_recycle_direct_netmem(rxr->page_pool, netmem);
 	}
 }
 
@@ -3620,7 +3705,10 @@ static int bnxt_alloc_rx_page_pool(struct bnxt *bp,
 	pp.dev = &bp->pdev->dev;
 	pp.dma_dir = bp->rx_dir;
 	pp.max_len = PAGE_SIZE;
-	pp.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
+	pp.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV |
+		   PP_FLAG_ALLOW_UNREADABLE_NETMEM;
+	pp.queue_idx = rxr->bnapi->index;
+	pp.order = 0;
 
 	rxr->page_pool = page_pool_create(&pp);
 	if (IS_ERR(rxr->page_pool)) {
@@ -4153,7 +4241,7 @@ static void bnxt_alloc_one_rx_ring_page(struct bnxt *bp,
 
 	prod = rxr->rx_agg_prod;
 	for (i = 0; i < bp->rx_agg_ring_size; i++) {
-		if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL)) {
+		if (bnxt_alloc_rx_netmem(bp, rxr, prod, GFP_KERNEL)) {
 			netdev_warn(bp->dev, "init'ed rx ring %d with %d/%d pages only\n",
 				    ring_nr, i, bp->rx_ring_size);
 			break;
drivers/net/ethernet/broadcom/bnxt/bnxt.h +1 -1
index e467341f1e5b..c38b0a8836e2 100644
@@ -894,7 +894,7 @@ struct bnxt_sw_rx_bd {
 };
 
 struct bnxt_sw_rx_agg_bd {
-	struct page		*page;
+	netmem_ref		netmem;
 	unsigned int		offset;
 	dma_addr_t		mapping;
 };
include/net/page_pool/helpers.h +6 -0
index 793e6fd78bc5..0149f6f6208f 100644
@@ -382,6 +382,12 @@ static inline void page_pool_recycle_direct(struct page_pool *pool,
 	page_pool_put_full_page(pool, page, true);
 }
 
+static inline void page_pool_recycle_direct_netmem(struct page_pool *pool,
+						   netmem_ref netmem)
+{
+	page_pool_put_full_netmem(pool, netmem, true);
+}
+
 #define PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA	\
 		(sizeof(dma_addr_t) > sizeof(unsigned long))
 
Signature · 1 line
2.34.1
#28 lore raw

Re: [PATCH net-next v4 8/8] bnxt_en: add support for device memory tcp

Quoted 10 lines · Taehee Yoo

Currently, bnxt_en driver satisfies the requirements of Device memory TCP, which is tcp-data-split.
So, it implements Device memory TCP for bnxt_en driver.

From now on, the aggregation ring handles netmem_ref instead of page regardless of the on/off of netmem.
So, for the aggregation ring, memory will be handled with the netmem page_pool API instead of generic page_pool API.

Quoted 6 lines

If Devmem is enabled, netmem_ref is used as-is and if Devmem is not enabled, netmem_ref will be converted to page and that is used.

Driver recognizes whether the devmem is set or unset based on the mp_params.mp_priv is not NULL.
Only if devmem is set, it passes PP_FLAG_ALLOW_UNREADABLE_NETMEM.

Looks like in the latest version, you pass PP_FLAG_ALLOW_UNREADABLE_NETMEM unconditionally, so this line is obsolete.

However, I think you should only pass PP_FLAG_ALLOW_UNREADABLE_NETMEM if hds_thresh==0 and tcp-data-split==1, because otherwise the driver is not configured well enough to handle unreadable netmem, right? I know that we added checks in the devmem binding to detect hds_thresh and tcp-data-split, but we should keep another layer of protection in the driver. The driver should not set PP_FLAG_ALLOW_UNREADABLE_NETMEM unless it's configured to be able to handle unreadable netmem.

Quoted 125 lines

---

v4:
- Do not select NET_DEVMEM in Kconfig.
- Pass PP_FLAG_ALLOW_UNREADABLE_NETMEM flag unconditionally.
- Add __bnxt_rx_agg_pages_xdp().
- Use gfp flag in __bnxt_alloc_rx_netmem().
- Do not add *offset in the __bnxt_alloc_rx_netmem().
- Do not pass queue_idx to bnxt_alloc_rx_page_pool().
- Add Test tag from Stanislav.
- Add page_pool_recycle_direct_netmem() helper.

v3:
- Patch added.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 182 ++++++++++++++++------
 drivers/net/ethernet/broadcom/bnxt/bnxt.h |   2 +-
 include/net/page_pool/helpers.h           |   6 +
 3 files changed, 142 insertions(+), 48 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +30 -13
index 7d9da483b867..7924b1da0413 100644
@@ -55,6 +55,7 @@
 #include <net/page_pool/helpers.h>
 #include <linux/align.h>
 #include <net/netdev_queues.h>
+#include <net/netdev_rx_queue.h>
 
 #include "bnxt_hsi.h"
 #include "bnxt.h"
@@ -863,6 +864,22 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
                bnapi->events &= ~BNXT_TX_CMP_EVENT;
 }
 
+static netmem_ref __bnxt_alloc_rx_netmem(struct bnxt *bp, dma_addr_t *mapping,
+                                        struct bnxt_rx_ring_info *rxr,
+                                        unsigned int *offset,
+                                        gfp_t gfp)
+{
+       netmem_ref netmem;
+
+       netmem = page_pool_alloc_netmem(rxr->page_pool, gfp);
+       if (!netmem)
+               return 0;
+       *offset = 0;
+
+       *mapping = page_pool_get_dma_addr_netmem(netmem);
+       return netmem;
+}
+
 static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
                                         struct bnxt_rx_ring_info *rxr,
                                         unsigned int *offset,
@@ -972,21 +989,21 @@ static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
        return next;
 }
 
-static inline int bnxt_alloc_rx_page(struct bnxt *bp,
-                                    struct bnxt_rx_ring_info *rxr,
-                                    u16 prod, gfp_t gfp)
+static inline int bnxt_alloc_rx_netmem(struct bnxt *bp,
+                                      struct bnxt_rx_ring_info *rxr,
+                                      u16 prod, gfp_t gfp)
 {
        struct rx_bd *rxbd =
                &rxr->rx_agg_desc_ring[RX_AGG_RING(bp, prod)][RX_IDX(prod)];
        struct bnxt_sw_rx_agg_bd *rx_agg_buf;
-       struct page *page;
-       dma_addr_t mapping;
        u16 sw_prod = rxr->rx_sw_agg_prod;
        unsigned int offset = 0;
+       dma_addr_t mapping;
+       netmem_ref netmem;
 
-       page = __bnxt_alloc_rx_page(bp, &mapping, rxr, &offset, gfp);
+       netmem = __bnxt_alloc_rx_netmem(bp, &mapping, rxr, &offset, gfp);
 
-       if (!page)
+       if (!netmem)
                return -ENOMEM;
 
        if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
@@ -996,7 +1013,7 @@ static inline int bnxt_alloc_rx_page(struct bnxt *bp,
        rx_agg_buf = &rxr->rx_agg_ring[sw_prod];
        rxr->rx_sw_agg_prod = RING_RX_AGG(bp, NEXT_RX_AGG(sw_prod));
 
-       rx_agg_buf->page = page;
+       rx_agg_buf->netmem = netmem;
        rx_agg_buf->offset = offset;
        rx_agg_buf->mapping = mapping;
        rxbd->rx_bd_haddr = cpu_to_le64(mapping);
@@ -1044,7 +1061,7 @@ static void bnxt_reuse_rx_agg_bufs(struct bnxt_cp_ring_info *cpr, u16 idx,
                struct rx_agg_cmp *agg;
                struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf;
                struct rx_bd *prod_bd;
-               struct page *page;
+               netmem_ref netmem;
 
                if (p5_tpa)
                        agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, start + i);
@@ -1061,11 +1078,11 @@ static void bnxt_reuse_rx_agg_bufs(struct bnxt_cp_ring_info *cpr, u16 idx,
                cons_rx_buf = &rxr->rx_agg_ring[cons];
 
                /* It is possible for sw_prod to be equal to cons, so
-                * set cons_rx_buf->page to NULL first.
+                * set cons_rx_buf->netmem to 0 first.
                 */
-               page = cons_rx_buf->page;
-               cons_rx_buf->page = NULL;
-               prod_rx_buf->page = page;
+               netmem = cons_rx_buf->netmem;
+               cons_rx_buf->netmem = 0;
+               prod_rx_buf->netmem = netmem;
                prod_rx_buf->offset = cons_rx_buf->offset;
 
                prod_rx_buf->mapping = cons_rx_buf->mapping;
@@ -1190,29 +1207,104 @@ static struct sk_buff *bnxt_rx_skb(struct bnxt *bp,
        return skb;
 }
 

drivers/net/ethernet/broadcom/bnxt/bnxt.c static struct sk_buff *bnxt_rx_skb(struct bnxt *bp, · line 1214

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4 -5
-static u32 __bnxt_rx_agg_pages(struct bnxt *bp,
-                              struct bnxt_cp_ring_info *cpr,
-                              struct skb_shared_info *shinfo,
-                              u16 idx, u32 agg_bufs, bool tpa,
-                              struct xdp_buff *xdp)
+static bool __bnxt_rx_agg_pages_skb(struct bnxt *bp,
+                                   struct bnxt_cp_ring_info *cpr,
+                                   struct sk_buff *skb,
+                                   u16 idx, u32 agg_bufs, bool tpa)
 {

To be honest I could not immediately understand why __bnxt_rx_agg_pages needed to be split into __bnxt_rx_agg_pages_skb and __bnxt_rx_agg_pages_xdp.

Fundamentally speaking we wanted the netmem transition to be as smooth and low-churn as possible for drivers. The only big changes in this patch are the split between skb and xdp. That points to a problem in the design of netmem maybe.

For xdp, core makes sure that if xdp is enabled on the device, then the netmem is always pages (never unreadable). So I think netmem should be able to handle xdp as well as skb. Can you give more details on why the split?

Quoted 54 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +40 -4
        struct bnxt_napi *bnapi = cpr->bnapi;
        struct pci_dev *pdev = bp->pdev;
-       struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
-       u16 prod = rxr->rx_agg_prod;
+       struct bnxt_rx_ring_info *rxr;
        u32 i, total_frag_len = 0;
        bool p5_tpa = false;
+       u16 prod;
+
+       rxr = bnapi->rx_ring;
+       prod = rxr->rx_agg_prod;
 
        if ((bp->flags & BNXT_FLAG_CHIP_P5_PLUS) && tpa)
                p5_tpa = true;
 
        for (i = 0; i < agg_bufs; i++) {
-               skb_frag_t *frag = &shinfo->frags[i];
-               u16 cons, frag_len;
+               struct bnxt_sw_rx_agg_bd *cons_rx_buf;
                struct rx_agg_cmp *agg;
+               u16 cons, frag_len;
+               dma_addr_t mapping;
+               netmem_ref netmem;
+
+               if (p5_tpa)
+                       agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, i);
+               else
+                       agg = bnxt_get_agg(bp, cpr, idx, i);
+               cons = agg->rx_agg_cmp_opaque;
+               frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) &
+                           RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
+
+               cons_rx_buf = &rxr->rx_agg_ring[cons];
+               skb_add_rx_frag_netmem(skb, i, cons_rx_buf->netmem,
+                                      cons_rx_buf->offset, frag_len,
+                                      BNXT_RX_PAGE_SIZE);
+               __clear_bit(cons, rxr->rx_agg_bmap);
+
+               /* It is possible for bnxt_alloc_rx_netmem() to allocate
+                * a sw_prod index that equals the cons index, so we
+                * need to clear the cons entry now.
+                */
+               mapping = cons_rx_buf->mapping;
+               netmem = cons_rx_buf->netmem;
+               cons_rx_buf->netmem = 0;
+
+               if (bnxt_alloc_rx_netmem(bp, rxr, prod, GFP_ATOMIC) != 0) {
+                       skb->len -= frag_len;
+                       skb->data_len -= frag_len;
+                       skb->truesize -= BNXT_RX_PAGE_SIZE;
+                       --skb_shinfo(skb)->nr_frags;
+                       cons_rx_buf->netmem = netmem;
+
+                       /* Update prod since possibly some pages have been

drivers/net/ethernet/broadcom/bnxt/bnxt.c static struct sk_buff *bnxt_rx_skb(struct bnxt *bp, · line 1274

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10 -0
+                        * allocated already.
+                        */
+                       rxr->rx_agg_prod = prod;
+                       bnxt_reuse_rx_agg_bufs(cpr, idx, i, agg_bufs - i, tpa);
+                       return 0;
+               }
+
+               dma_sync_single_for_cpu(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE,
+                                       bp->rx_dir);
+

You should probably use page_pool_dma_sync_for_cpu. I'm merging a change to make that function skip dma-syncing for net_iov:

https://lore.kernel.org/netdev/[email protected]/

Which is necessary following Jason Gunthorpe's guidance.

Quoted 125 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +46 -23
+               total_frag_len += frag_len;
+               prod = NEXT_RX_AGG(prod);
+       }
+       rxr->rx_agg_prod = prod;
+       return total_frag_len;
+}
+
+static u32 __bnxt_rx_agg_pages_xdp(struct bnxt *bp,
+                                  struct bnxt_cp_ring_info *cpr,
+                                  struct skb_shared_info *shinfo,
+                                  u16 idx, u32 agg_bufs, bool tpa,
+                                  struct xdp_buff *xdp)
+{
+       struct bnxt_napi *bnapi = cpr->bnapi;
+       struct pci_dev *pdev = bp->pdev;
+       struct bnxt_rx_ring_info *rxr;
+       u32 i, total_frag_len = 0;
+       bool p5_tpa = false;
+       u16 prod;
+
+       rxr = bnapi->rx_ring;
+       prod = rxr->rx_agg_prod;
+
+       if ((bp->flags & BNXT_FLAG_CHIP_P5_PLUS) && tpa)
+               p5_tpa = true;
+
+       for (i = 0; i < agg_bufs; i++) {
                struct bnxt_sw_rx_agg_bd *cons_rx_buf;
-               struct page *page;
+               skb_frag_t *frag = &shinfo->frags[i];
+               struct rx_agg_cmp *agg;
+               u16 cons, frag_len;
                dma_addr_t mapping;
+               netmem_ref netmem;
 
                if (p5_tpa)
                        agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, i);
@@ -1223,9 +1315,10 @@ static u32 __bnxt_rx_agg_pages(struct bnxt *bp,
                            RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
 
                cons_rx_buf = &rxr->rx_agg_ring[cons];
-               skb_frag_fill_page_desc(frag, cons_rx_buf->page,
-                                       cons_rx_buf->offset, frag_len);
+               skb_frag_fill_netmem_desc(frag, cons_rx_buf->netmem,
+                                         cons_rx_buf->offset, frag_len);
                shinfo->nr_frags = i + 1;
+
                __clear_bit(cons, rxr->rx_agg_bmap);
 
                /* It is possible for bnxt_alloc_rx_page() to allocate
@@ -1233,15 +1326,15 @@ static u32 __bnxt_rx_agg_pages(struct bnxt *bp,
                 * need to clear the cons entry now.
                 */
                mapping = cons_rx_buf->mapping;
-               page = cons_rx_buf->page;
-               cons_rx_buf->page = NULL;
+               netmem = cons_rx_buf->netmem;
+               cons_rx_buf->netmem = 0;
 
-               if (xdp && page_is_pfmemalloc(page))
+               if (netmem_is_pfmemalloc(netmem))
                        xdp_buff_set_frag_pfmemalloc(xdp);
 
-               if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) {
+               if (bnxt_alloc_rx_netmem(bp, rxr, prod, GFP_ATOMIC) != 0) {
                        --shinfo->nr_frags;
-                       cons_rx_buf->page = page;
+                       cons_rx_buf->netmem = netmem;
 
                        /* Update prod since possibly some pages have been
                         * allocated already.
@@ -1266,20 +1359,12 @@ static struct sk_buff *bnxt_rx_agg_pages_skb(struct bnxt *bp,
                                             struct sk_buff *skb, u16 idx,
                                             u32 agg_bufs, bool tpa)
 {
-       struct skb_shared_info *shinfo = skb_shinfo(skb);
-       u32 total_frag_len = 0;
-
-       total_frag_len = __bnxt_rx_agg_pages(bp, cpr, shinfo, idx,
-                                            agg_bufs, tpa, NULL);
-       if (!total_frag_len) {
+       if (!__bnxt_rx_agg_pages_skb(bp, cpr, skb, idx, agg_bufs, tpa)) {
                skb_mark_for_recycle(skb);
                dev_kfree_skb(skb);
                return NULL;
        }
 
-       skb->data_len += total_frag_len;
-       skb->len += total_frag_len;
-       skb->truesize += BNXT_RX_PAGE_SIZE * agg_bufs;
        return skb;
 }
 
@@ -1294,8 +1379,8 @@ static u32 bnxt_rx_agg_pages_xdp(struct bnxt *bp,
        if (!xdp_buff_has_frags(xdp))
                shinfo->nr_frags = 0;
 
-       total_frag_len = __bnxt_rx_agg_pages(bp, cpr, shinfo,
-                                            idx, agg_bufs, tpa, xdp);
+       total_frag_len = __bnxt_rx_agg_pages_xdp(bp, cpr, shinfo,
+                                                idx, agg_bufs, tpa, xdp);
        if (total_frag_len) {
                xdp_buff_set_frags_flag(xdp);
                shinfo->nr_frags = agg_bufs;
@@ -3341,15 +3426,15 @@ static void bnxt_free_one_rx_agg_ring(struct bnxt *bp, struct bnxt_rx_ring_info
 
        for (i = 0; i < max_idx; i++) {
                struct bnxt_sw_rx_agg_bd *rx_agg_buf = &rxr->rx_agg_ring[i];
-               struct page *page = rx_agg_buf->page;
+               netmem_ref netmem = rx_agg_buf->netmem;
 
-               if (!page)
+               if (!netmem)
                        continue;
 
-               rx_agg_buf->page = NULL;
+               rx_agg_buf->netmem = 0;
                __clear_bit(i, rxr->rx_agg_bmap);
 
-               page_pool_recycle_direct(rxr->page_pool, page);
+               page_pool_recycle_direct_netmem(rxr->page_pool, netmem);
        }
 }
 

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_alloc_rx_page_pool(struct bnxt *bp, · line 3709

Quoted 6 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
@@ -3620,7 +3705,10 @@ static int bnxt_alloc_rx_page_pool(struct bnxt *bp,
        pp.dev = &bp->pdev->dev;
        pp.dma_dir = bp->rx_dir;
        pp.max_len = PAGE_SIZE;
-       pp.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
+       pp.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV |
+                  PP_FLAG_ALLOW_UNREADABLE_NETMEM;

PP_FLAG_ALLOW_UNREADABLE_NETMEM should only be set when the driver can handle unreadable netmem. I.e. when hds_thresh==0 and tcp-data-split==1.

Signature · 2 lines
Thanks,
Mina
author
#29 lore raw

Re: [PATCH net-next v4 8/8] bnxt_en: add support for device memory tcp

Quoted 15 lines · Mina Almasry
Quoted 13 lines · Taehee Yoo

Currently, bnxt_en driver satisfies the requirements of Device memory TCP, which is tcp-data-split.
So, it implements Device memory TCP for bnxt_en driver.

From now on, the aggregation ring handles netmem_ref instead of page regardless of the on/off of netmem.
So, for the aggregation ring, memory will be handled with the netmem page_pool API instead of generic page_pool API.

If Devmem is enabled, netmem_ref is used as-is and if Devmem is not enabled, netmem_ref will be converted to page and that is used.

Quoted 7 lines
Quoted 3 lines

Driver recognizes whether the devmem is set or unset based on the mp_params.mp_priv is not NULL.
Only if devmem is set, it passes PP_FLAG_ALLOW_UNREADABLE_NETMEM.

Looks like in the latest version, you pass PP_FLAG_ALLOW_UNREADABLE_NETMEM unconditionally, so this line is obsolete.

Okay, I will remove this line.

Quoted 8 lines

However, I think you should only pass PP_FLAG_ALLOW_UNREADABLE_NETMEM if hds_thresh==0 and tcp-data-split==1, because otherwise the driver is not configured well enough to handle unreadable netmem, right? I know that we added checks in the devmem binding to detect hds_thresh and tcp-data-split, but we should keep another layer of protection in the driver. The driver should not set PP_FLAG_ALLOW_UNREADABLE_NETMEM unless it's configured to be able to handle unreadable netmem.

Okay, I agree, I will pass PP_FLAG_ALLOW_UNREADABLE_NETMEM only when hds_thresh==0 and tcp-data-split==1.

Quoted 146 lines
Quoted 126 lines

---

v4:
- Do not select NET_DEVMEM in Kconfig.
- Pass PP_FLAG_ALLOW_UNREADABLE_NETMEM flag unconditionally.
- Add __bnxt_rx_agg_pages_xdp().
- Use gfp flag in __bnxt_alloc_rx_netmem().
- Do not add *offset in the __bnxt_alloc_rx_netmem().
- Do not pass queue_idx to bnxt_alloc_rx_page_pool().
- Add Test tag from Stanislav.
- Add page_pool_recycle_direct_netmem() helper.

v3:
- Patch added.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 182 ++++++++++++++++------
 drivers/net/ethernet/broadcom/bnxt/bnxt.h |   2 +-
 include/net/page_pool/helpers.h           |   6 +
 3 files changed, 142 insertions(+), 48 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +30 -13
index 7d9da483b867..7924b1da0413 100644
@@ -55,6 +55,7 @@
 #include <net/page_pool/helpers.h>
 #include <linux/align.h>
 #include <net/netdev_queues.h>
+#include <net/netdev_rx_queue.h>
 
 #include "bnxt_hsi.h"
 #include "bnxt.h"
@@ -863,6 +864,22 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
                bnapi->events &= ~BNXT_TX_CMP_EVENT;
 }
 
+static netmem_ref __bnxt_alloc_rx_netmem(struct bnxt *bp, dma_addr_t *mapping,
+                                        struct bnxt_rx_ring_info *rxr,
+                                        unsigned int *offset,
+                                        gfp_t gfp)
+{
+       netmem_ref netmem;
+
+       netmem = page_pool_alloc_netmem(rxr->page_pool, gfp);
+       if (!netmem)
+               return 0;
+       *offset = 0;
+
+       *mapping = page_pool_get_dma_addr_netmem(netmem);
+       return netmem;
+}
+
 static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping,
                                         struct bnxt_rx_ring_info *rxr,
                                         unsigned int *offset,
@@ -972,21 +989,21 @@ static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx)
        return next;
 }
 
-static inline int bnxt_alloc_rx_page(struct bnxt *bp,
-                                    struct bnxt_rx_ring_info *rxr,
-                                    u16 prod, gfp_t gfp)
+static inline int bnxt_alloc_rx_netmem(struct bnxt *bp,
+                                      struct bnxt_rx_ring_info *rxr,
+                                      u16 prod, gfp_t gfp)
 {
        struct rx_bd *rxbd =
                &rxr->rx_agg_desc_ring[RX_AGG_RING(bp, prod)][RX_IDX(prod)];
        struct bnxt_sw_rx_agg_bd *rx_agg_buf;
-       struct page *page;
-       dma_addr_t mapping;
        u16 sw_prod = rxr->rx_sw_agg_prod;
        unsigned int offset = 0;
+       dma_addr_t mapping;
+       netmem_ref netmem;
 
-       page = __bnxt_alloc_rx_page(bp, &mapping, rxr, &offset, gfp);
+       netmem = __bnxt_alloc_rx_netmem(bp, &mapping, rxr, &offset, gfp);
 
-       if (!page)
+       if (!netmem)
                return -ENOMEM;
 
        if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap)))
@@ -996,7 +1013,7 @@ static inline int bnxt_alloc_rx_page(struct bnxt *bp,
        rx_agg_buf = &rxr->rx_agg_ring[sw_prod];
        rxr->rx_sw_agg_prod = RING_RX_AGG(bp, NEXT_RX_AGG(sw_prod));
 
-       rx_agg_buf->page = page;
+       rx_agg_buf->netmem = netmem;
        rx_agg_buf->offset = offset;
        rx_agg_buf->mapping = mapping;
        rxbd->rx_bd_haddr = cpu_to_le64(mapping);
@@ -1044,7 +1061,7 @@ static void bnxt_reuse_rx_agg_bufs(struct bnxt_cp_ring_info *cpr, u16 idx,
                struct rx_agg_cmp *agg;
                struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf;
                struct rx_bd *prod_bd;
-               struct page *page;
+               netmem_ref netmem;
 
                if (p5_tpa)
                        agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, start + i);
@@ -1061,11 +1078,11 @@ static void bnxt_reuse_rx_agg_bufs(struct bnxt_cp_ring_info *cpr, u16 idx,
                cons_rx_buf = &rxr->rx_agg_ring[cons];
 
                /* It is possible for sw_prod to be equal to cons, so
-                * set cons_rx_buf->page to NULL first.
+                * set cons_rx_buf->netmem to 0 first.
                 */
-               page = cons_rx_buf->page;
-               cons_rx_buf->page = NULL;
-               prod_rx_buf->page = page;
+               netmem = cons_rx_buf->netmem;
+               cons_rx_buf->netmem = 0;
+               prod_rx_buf->netmem = netmem;
                prod_rx_buf->offset = cons_rx_buf->offset;
 
                prod_rx_buf->mapping = cons_rx_buf->mapping;
@@ -1190,29 +1207,104 @@ static struct sk_buff *bnxt_rx_skb(struct bnxt *bp,
        return skb;
 }
 

drivers/net/ethernet/broadcom/bnxt/bnxt.c static struct sk_buff *bnxt_rx_skb(struct bnxt *bp, · line 1214

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +4 -5
-static u32 __bnxt_rx_agg_pages(struct bnxt *bp,
-                              struct bnxt_cp_ring_info *cpr,
-                              struct skb_shared_info *shinfo,
-                              u16 idx, u32 agg_bufs, bool tpa,
-                              struct xdp_buff *xdp)
+static bool __bnxt_rx_agg_pages_skb(struct bnxt *bp,
+                                   struct bnxt_cp_ring_info *cpr,
+                                   struct sk_buff *skb,
+                                   u16 idx, u32 agg_bufs, bool tpa)
 {

To be honest I could not immediately understand why __bnxt_rx_agg_pages needed to be split into __bnxt_rx_agg_pages_skb and __bnxt_rx_agg_pages_xdp.

Fundamentally speaking we wanted the netmem transition to be as smooth and low-churn as possible for drivers. The only big changes in this patch are the split between skb and xdp. That points to a problem in the design of netmem maybe.

Quoted 4 lines

For xdp, core makes sure that if xdp is enabled on the device, then the netmem is always pages (never unreadable). So I think netmem should be able to handle xdp as well as skb. Can you give more details on why the split?

In the v3 patch, there was an opinion that refactoring for separating into skb path and xdp path in the future. So I changed.
As you feel, I think separating skb path and xdp path is not directly related to the purpose of this patch.
I agree the separating them but no need to be included in this patchset. I will revert it.

Quoted 69 lines
Quoted 55 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +40 -4
        struct bnxt_napi *bnapi = cpr->bnapi;
        struct pci_dev *pdev = bp->pdev;
-       struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
-       u16 prod = rxr->rx_agg_prod;
+       struct bnxt_rx_ring_info *rxr;
        u32 i, total_frag_len = 0;
        bool p5_tpa = false;
+       u16 prod;
+
+       rxr = bnapi->rx_ring;
+       prod = rxr->rx_agg_prod;
 
        if ((bp->flags & BNXT_FLAG_CHIP_P5_PLUS) && tpa)
                p5_tpa = true;
 
        for (i = 0; i < agg_bufs; i++) {
-               skb_frag_t *frag = &shinfo->frags[i];
-               u16 cons, frag_len;
+               struct bnxt_sw_rx_agg_bd *cons_rx_buf;
                struct rx_agg_cmp *agg;
+               u16 cons, frag_len;
+               dma_addr_t mapping;
+               netmem_ref netmem;
+
+               if (p5_tpa)
+                       agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, i);
+               else
+                       agg = bnxt_get_agg(bp, cpr, idx, i);
+               cons = agg->rx_agg_cmp_opaque;
+               frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) &
+                           RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
+
+               cons_rx_buf = &rxr->rx_agg_ring[cons];
+               skb_add_rx_frag_netmem(skb, i, cons_rx_buf->netmem,
+                                      cons_rx_buf->offset, frag_len,
+                                      BNXT_RX_PAGE_SIZE);
+               __clear_bit(cons, rxr->rx_agg_bmap);
+
+               /* It is possible for bnxt_alloc_rx_netmem() to allocate
+                * a sw_prod index that equals the cons index, so we
+                * need to clear the cons entry now.
+                */
+               mapping = cons_rx_buf->mapping;
+               netmem = cons_rx_buf->netmem;
+               cons_rx_buf->netmem = 0;
+
+               if (bnxt_alloc_rx_netmem(bp, rxr, prod, GFP_ATOMIC) != 0) {
+                       skb->len -= frag_len;
+                       skb->data_len -= frag_len;
+                       skb->truesize -= BNXT_RX_PAGE_SIZE;
+                       --skb_shinfo(skb)->nr_frags;
+                       cons_rx_buf->netmem = netmem;
+
+                       /* Update prod since possibly some pages have been

drivers/net/ethernet/broadcom/bnxt/bnxt.c static struct sk_buff *bnxt_rx_skb(struct bnxt *bp, · line 1274

Quoted 10 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +10 -0
+                        * allocated already.
+                        */
+                       rxr->rx_agg_prod = prod;
+                       bnxt_reuse_rx_agg_bufs(cpr, idx, i, agg_bufs - i, tpa);
+                       return 0;
+               }
+
+               dma_sync_single_for_cpu(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE,
+                                       bp->rx_dir);
+

You should probably use page_pool_dma_sync_for_cpu. I'm merging a change to make that function skip dma-syncing for net_iov:

Quoted 3 lines

https://lore.kernel.org/netdev/[email protected]/

Which is necessary following Jason Gunthorpe's guidance.

Okay, no problem.
I will wait to merge it then I will use that then send a v5 patch.

Quoted 125 lines
Quoted 125 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +46 -23
+               total_frag_len += frag_len;
+               prod = NEXT_RX_AGG(prod);
+       }
+       rxr->rx_agg_prod = prod;
+       return total_frag_len;
+}
+
+static u32 __bnxt_rx_agg_pages_xdp(struct bnxt *bp,
+                                  struct bnxt_cp_ring_info *cpr,
+                                  struct skb_shared_info *shinfo,
+                                  u16 idx, u32 agg_bufs, bool tpa,
+                                  struct xdp_buff *xdp)
+{
+       struct bnxt_napi *bnapi = cpr->bnapi;
+       struct pci_dev *pdev = bp->pdev;
+       struct bnxt_rx_ring_info *rxr;
+       u32 i, total_frag_len = 0;
+       bool p5_tpa = false;
+       u16 prod;
+
+       rxr = bnapi->rx_ring;
+       prod = rxr->rx_agg_prod;
+
+       if ((bp->flags & BNXT_FLAG_CHIP_P5_PLUS) && tpa)
+               p5_tpa = true;
+
+       for (i = 0; i < agg_bufs; i++) {
                struct bnxt_sw_rx_agg_bd *cons_rx_buf;
-               struct page *page;
+               skb_frag_t *frag = &shinfo->frags[i];
+               struct rx_agg_cmp *agg;
+               u16 cons, frag_len;
                dma_addr_t mapping;
+               netmem_ref netmem;
 
                if (p5_tpa)
                        agg = bnxt_get_tpa_agg_p5(bp, rxr, idx, i);
@@ -1223,9 +1315,10 @@ static u32 __bnxt_rx_agg_pages(struct bnxt *bp,
                            RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT;
 
                cons_rx_buf = &rxr->rx_agg_ring[cons];
-               skb_frag_fill_page_desc(frag, cons_rx_buf->page,
-                                       cons_rx_buf->offset, frag_len);
+               skb_frag_fill_netmem_desc(frag, cons_rx_buf->netmem,
+                                         cons_rx_buf->offset, frag_len);
                shinfo->nr_frags = i + 1;
+
                __clear_bit(cons, rxr->rx_agg_bmap);
 
                /* It is possible for bnxt_alloc_rx_page() to allocate
@@ -1233,15 +1326,15 @@ static u32 __bnxt_rx_agg_pages(struct bnxt *bp,
                 * need to clear the cons entry now.
                 */
                mapping = cons_rx_buf->mapping;
-               page = cons_rx_buf->page;
-               cons_rx_buf->page = NULL;
+               netmem = cons_rx_buf->netmem;
+               cons_rx_buf->netmem = 0;
 
-               if (xdp && page_is_pfmemalloc(page))
+               if (netmem_is_pfmemalloc(netmem))
                        xdp_buff_set_frag_pfmemalloc(xdp);
 
-               if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) {
+               if (bnxt_alloc_rx_netmem(bp, rxr, prod, GFP_ATOMIC) != 0) {
                        --shinfo->nr_frags;
-                       cons_rx_buf->page = page;
+                       cons_rx_buf->netmem = netmem;
 
                        /* Update prod since possibly some pages have been
                         * allocated already.
@@ -1266,20 +1359,12 @@ static struct sk_buff *bnxt_rx_agg_pages_skb(struct bnxt *bp,
                                             struct sk_buff *skb, u16 idx,
                                             u32 agg_bufs, bool tpa)
 {
-       struct skb_shared_info *shinfo = skb_shinfo(skb);
-       u32 total_frag_len = 0;
-
-       total_frag_len = __bnxt_rx_agg_pages(bp, cpr, shinfo, idx,
-                                            agg_bufs, tpa, NULL);
-       if (!total_frag_len) {
+       if (!__bnxt_rx_agg_pages_skb(bp, cpr, skb, idx, agg_bufs, tpa)) {
                skb_mark_for_recycle(skb);
                dev_kfree_skb(skb);
                return NULL;
        }
 
-       skb->data_len += total_frag_len;
-       skb->len += total_frag_len;
-       skb->truesize += BNXT_RX_PAGE_SIZE * agg_bufs;
        return skb;
 }
 
@@ -1294,8 +1379,8 @@ static u32 bnxt_rx_agg_pages_xdp(struct bnxt *bp,
        if (!xdp_buff_has_frags(xdp))
                shinfo->nr_frags = 0;
 
-       total_frag_len = __bnxt_rx_agg_pages(bp, cpr, shinfo,
-                                            idx, agg_bufs, tpa, xdp);
+       total_frag_len = __bnxt_rx_agg_pages_xdp(bp, cpr, shinfo,
+                                                idx, agg_bufs, tpa, xdp);
        if (total_frag_len) {
                xdp_buff_set_frags_flag(xdp);
                shinfo->nr_frags = agg_bufs;
@@ -3341,15 +3426,15 @@ static void bnxt_free_one_rx_agg_ring(struct bnxt *bp, struct bnxt_rx_ring_info
 
        for (i = 0; i < max_idx; i++) {
                struct bnxt_sw_rx_agg_bd *rx_agg_buf = &rxr->rx_agg_ring[i];
-               struct page *page = rx_agg_buf->page;
+               netmem_ref netmem = rx_agg_buf->netmem;
 
-               if (!page)
+               if (!netmem)
                        continue;
 
-               rx_agg_buf->page = NULL;
+               rx_agg_buf->netmem = 0;
                __clear_bit(i, rxr->rx_agg_bmap);
 
-               page_pool_recycle_direct(rxr->page_pool, page);
+               page_pool_recycle_direct_netmem(rxr->page_pool, netmem);
        }
 }
 
Quoted 11 lines

drivers/net/ethernet/broadcom/bnxt/bnxt.c static int bnxt_alloc_rx_page_pool(struct bnxt *bp, · line 3709

Quoted 7 lines
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -1
@@ -3620,7 +3705,10 @@ static int bnxt_alloc_rx_page_pool(struct bnxt *bp,
        pp.dev = &bp->pdev->dev;
        pp.dma_dir = bp->rx_dir;
        pp.max_len = PAGE_SIZE;
-       pp.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
+       pp.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV |
+                  PP_FLAG_ALLOW_UNREADABLE_NETMEM;

PP_FLAG_ALLOW_UNREADABLE_NETMEM should only be set when the driver can handle unreadable netmem. I.e. when hds_thresh==0 and tcp-data-split==1.

Okay, I will add a condition for that.

Thanks a lot!
Taehee Yoo

Quoted 5 lines

--
Thanks,
Mina

#30 lore raw

Re: [PATCH net-next v4 8/8] bnxt_en: add support for device memory tcp

Quoted 35 lines · Taehee Yoo
Quoted 15 lines · Mina Almasry
Quoted 13 lines · Taehee Yoo

Currently, bnxt_en driver satisfies the requirements of Device memory TCP, which is tcp-data-split.
So, it implements Device memory TCP for bnxt_en driver.

From now on, the aggregation ring handles netmem_ref instead of page regardless of the on/off of netmem.
So, for the aggregation ring, memory will be handled with the netmem page_pool API instead of generic page_pool API.

If Devmem is enabled, netmem_ref is used as-is and if Devmem is not enabled, netmem_ref will be converted to page and that is used.

Quoted 7 lines
Quoted 3 lines

Driver recognizes whether the devmem is set or unset based on the mp_params.mp_priv is not NULL.
Only if devmem is set, it passes PP_FLAG_ALLOW_UNREADABLE_NETMEM.

Looks like in the latest version, you pass PP_FLAG_ALLOW_UNREADABLE_NETMEM unconditionally, so this line is obsolete.

Okay, I will remove this line.

Quoted 8 lines

However, I think you should only pass PP_FLAG_ALLOW_UNREADABLE_NETMEM if hds_thresh==0 and tcp-data-split==1, because otherwise the driver is not configured well enough to handle unreadable netmem, right? I know that we added checks in the devmem binding to detect hds_thresh and tcp-data-split, but we should keep another layer of protection in the driver. The driver should not set PP_FLAG_ALLOW_UNREADABLE_NETMEM unless it's configured to be able to handle unreadable netmem.

Quoted 26 lines

Okay, I agree, I will pass PP_FLAG_ALLOW_UNREADABLE_NETMEM only when hds_thresh==0 and tcp-data-split==1.

Quoted 23 lines
Quoted 23 lines

---

v4:
- Do not select NET_DEVMEM in Kconfig.
- Pass PP_FLAG_ALLOW_UNREADABLE_NETMEM flag unconditionally.
- Add __bnxt_rx_agg_pages_xdp().
- Use gfp flag in __bnxt_alloc_rx_netmem().
- Do not add *offset in the __bnxt_alloc_rx_netmem().
- Do not pass queue_idx to bnxt_alloc_rx_page_pool().
- Add Test tag from Stanislav.
- Add page_pool_recycle_direct_netmem() helper.

v3:
- Patch added.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 182 ++++++++++++++++------
 drivers/net/ethernet/broadcom/bnxt/bnxt.h |   2 +-
 include/net/page_pool/helpers.h           |   6 +
 3 files changed, 142 insertions(+), 48 deletions(-)

Hi Taehee, what is your plan with this patch? Are you still working on it? I noticed that you dropped it in later versions of this series. With io_uring zero copy Rx now merged I also need bnxt support, but I don't want to duplicate efforts. Please let me know, thanks!

author
#31 lore raw

Re: [PATCH net-next v4 8/8] bnxt_en: add support for device memory tcp

Quoted 64 lines · David Wei
Quoted 35 lines · Taehee Yoo
Quoted 15 lines · Mina Almasry
Quoted 13 lines · Taehee Yoo

Currently, bnxt_en driver satisfies the requirements of Device memory TCP, which is tcp-data-split.
So, it implements Device memory TCP for bnxt_en driver.

From now on, the aggregation ring handles netmem_ref instead of page regardless of the on/off of netmem.
So, for the aggregation ring, memory will be handled with the netmem page_pool API instead of generic page_pool API.

If Devmem is enabled, netmem_ref is used as-is and if Devmem is not enabled, netmem_ref will be converted to page and that is used.

Quoted 7 lines
Quoted 3 lines

Driver recognizes whether the devmem is set or unset based on the mp_params.mp_priv is not NULL.
Only if devmem is set, it passes PP_FLAG_ALLOW_UNREADABLE_NETMEM.

Looks like in the latest version, you pass PP_FLAG_ALLOW_UNREADABLE_NETMEM unconditionally, so this line is obsolete.

Okay, I will remove this line.

Quoted 8 lines

However, I think you should only pass PP_FLAG_ALLOW_UNREADABLE_NETMEM if hds_thresh==0 and tcp-data-split==1, because otherwise the driver is not configured well enough to handle unreadable netmem, right? I know that we added checks in the devmem binding to detect hds_thresh and tcp-data-split, but we should keep another layer of protection in the driver. The driver should not set PP_FLAG_ALLOW_UNREADABLE_NETMEM unless it's configured to be able to handle unreadable netmem.

Quoted 26 lines

Okay, I agree, I will pass PP_FLAG_ALLOW_UNREADABLE_NETMEM only when hds_thresh==0 and tcp-data-split==1.

Quoted 23 lines
Quoted 23 lines

---

v4:
- Do not select NET_DEVMEM in Kconfig.
- Pass PP_FLAG_ALLOW_UNREADABLE_NETMEM flag unconditionally.
- Add __bnxt_rx_agg_pages_xdp().
- Use gfp flag in __bnxt_alloc_rx_netmem().
- Do not add *offset in the __bnxt_alloc_rx_netmem().
- Do not pass queue_idx to bnxt_alloc_rx_page_pool().
- Add Test tag from Stanislav.
- Add page_pool_recycle_direct_netmem() helper.

v3:
- Patch added.

 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 182 ++++++++++++++++------
 drivers/net/ethernet/broadcom/bnxt/bnxt.h |   2 +-
 include/net/page_pool/helpers.h           |   6 +
 3 files changed, 142 insertions(+), 48 deletions(-)
Quoted 4 lines

Hi Taehee, what is your plan with this patch? Are you still working on it? I noticed that you dropped it in later versions of this series. With io_uring zero copy Rx now merged I also need bnxt support, but I don't want to duplicate efforts. Please let me know, thanks!

Hi David,
Sorry for the late! I'm still working on it.
I implemented a working patch, but there are several bugs. So I'm thinking about how to deal with it.
And then, I would like to send this patch after fixing bugs.

Thanks a lot!
Taehee Yoo