Skip to content

Commit 152f4da

Browse files
TaeheeYookuba-moo
authored andcommitted
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`. By this patch, hds_threshol is set to the rx-copybreak value. But it will be set by `ethtool -G eth0 hds-thresh N` in the next patch. Reviewed-by: Jakub Kicinski <[email protected]> Reviewed-by: Brett Creeley <[email protected]> Tested-by: Stanislav Fomichev <[email protected]> Tested-by: Andy Gospodarek <[email protected]> Signed-off-by: Taehee Yoo <[email protected]> Reviewed-by: Michael Chan <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2d46e48 commit 152f4da

File tree

3 files changed

+63
-14
lines changed

3 files changed

+63
-14
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ MODULE_DESCRIPTION("Broadcom NetXtreme network driver");
8181

8282
#define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN)
8383
#define BNXT_RX_DMA_OFFSET NET_SKB_PAD
84-
#define BNXT_RX_COPY_THRESH 256
8584

8685
#define BNXT_TX_PUSH_THRESH 164
8786

@@ -1343,13 +1342,13 @@ static struct sk_buff *bnxt_copy_data(struct bnxt_napi *bnapi, u8 *data,
13431342
if (!skb)
13441343
return NULL;
13451344

1346-
dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh,
1345+
dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copybreak,
13471346
bp->rx_dir);
13481347

13491348
memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN,
13501349
len + NET_IP_ALIGN);
13511350

1352-
dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh,
1351+
dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copybreak,
13531352
bp->rx_dir);
13541353

13551354
skb_put(skb, len);
@@ -1842,7 +1841,7 @@ static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp,
18421841
return NULL;
18431842
}
18441843

1845-
if (len <= bp->rx_copy_thresh) {
1844+
if (len <= bp->rx_copybreak) {
18461845
skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping);
18471846
if (!skb) {
18481847
bnxt_abort_tpa(cpr, idx, agg_bufs);
@@ -2176,7 +2175,7 @@ static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
21762175
}
21772176
}
21782177

2179-
if (len <= bp->rx_copy_thresh) {
2178+
if (len <= bp->rx_copybreak) {
21802179
if (!xdp_active)
21812180
skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr);
21822181
else
@@ -4608,6 +4607,11 @@ void bnxt_set_tpa_flags(struct bnxt *bp)
46084607
bp->flags |= BNXT_FLAG_GRO;
46094608
}
46104609

4610+
static void bnxt_init_ring_params(struct bnxt *bp)
4611+
{
4612+
bp->rx_copybreak = BNXT_DEFAULT_RX_COPYBREAK;
4613+
}
4614+
46114615
/* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must
46124616
* be set on entry.
46134617
*/
@@ -4622,7 +4626,6 @@ void bnxt_set_ring_params(struct bnxt *bp)
46224626
rx_space = rx_size + ALIGN(max(NET_SKB_PAD, XDP_PACKET_HEADROOM), 8) +
46234627
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
46244628

4625-
bp->rx_copy_thresh = BNXT_RX_COPY_THRESH;
46264629
ring_size = bp->rx_ring_size;
46274630
bp->rx_agg_ring_size = 0;
46284631
bp->rx_agg_nr_pages = 0;
@@ -4667,7 +4670,9 @@ void bnxt_set_ring_params(struct bnxt *bp)
46674670
ALIGN(max(NET_SKB_PAD, XDP_PACKET_HEADROOM), 8) -
46684671
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
46694672
} else {
4670-
rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN);
4673+
rx_size = SKB_DATA_ALIGN(max(BNXT_DEFAULT_RX_COPYBREAK,
4674+
bp->rx_copybreak) +
4675+
NET_IP_ALIGN);
46714676
rx_space = rx_size + NET_SKB_PAD +
46724677
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
46734678
}
@@ -6573,16 +6578,14 @@ static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, struct bnxt_vnic_info *vnic)
65736578

65746579
req->flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT);
65756580
req->enables = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID);
6581+
req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
65766582

6577-
if (BNXT_RX_PAGE_MODE(bp)) {
6578-
req->jumbo_thresh = cpu_to_le16(bp->rx_buf_use_size);
6579-
} else {
6583+
if (!BNXT_RX_PAGE_MODE(bp) && (bp->flags & BNXT_FLAG_AGG_RINGS)) {
65806584
req->flags |= cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 |
65816585
VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6);
65826586
req->enables |=
65836587
cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID);
6584-
req->jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh);
6585-
req->hds_threshold = cpu_to_le16(bp->rx_copy_thresh);
6588+
req->hds_threshold = cpu_to_le16(bp->rx_copybreak);
65866589
}
65876590
req->vnic_id = cpu_to_le32(vnic->fw_vnic_id);
65886591
return hwrm_req_send(bp, req);
@@ -16261,6 +16264,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1626116264
bnxt_init_l2_fltr_tbl(bp);
1626216265
bnxt_set_rx_skb_mode(bp, false);
1626316266
bnxt_set_tpa_flags(bp);
16267+
bnxt_init_ring_params(bp);
1626416268
bnxt_set_ring_params(bp);
1626516269
bnxt_rdma_aux_device_init(bp);
1626616270
rc = bnxt_set_dflt_rings(bp, true);

drivers/net/ethernet/broadcom/bnxt/bnxt.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#include <linux/firmware/broadcom/tee_bnxt_fw.h>
3535
#endif
3636

37+
#define BNXT_DEFAULT_RX_COPYBREAK 256
38+
#define BNXT_MAX_RX_COPYBREAK 1024
39+
3740
extern struct list_head bnxt_block_cb_list;
3841

3942
struct page_pool;
@@ -2347,7 +2350,7 @@ struct bnxt {
23472350
enum dma_data_direction rx_dir;
23482351
u32 rx_ring_size;
23492352
u32 rx_agg_ring_size;
2350-
u32 rx_copy_thresh;
2353+
u32 rx_copybreak;
23512354
u32 rx_ring_mask;
23522355
u32 rx_agg_ring_mask;
23532356
int rx_nr_pages;

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4328,6 +4328,45 @@ static int bnxt_get_eee(struct net_device *dev, struct ethtool_keee *edata)
43284328
return 0;
43294329
}
43304330

4331+
static int bnxt_set_tunable(struct net_device *dev,
4332+
const struct ethtool_tunable *tuna,
4333+
const void *data)
4334+
{
4335+
struct bnxt *bp = netdev_priv(dev);
4336+
u32 rx_copybreak;
4337+
4338+
switch (tuna->id) {
4339+
case ETHTOOL_RX_COPYBREAK:
4340+
rx_copybreak = *(u32 *)data;
4341+
if (rx_copybreak > BNXT_MAX_RX_COPYBREAK)
4342+
return -ERANGE;
4343+
if (rx_copybreak != bp->rx_copybreak) {
4344+
if (netif_running(dev))
4345+
return -EBUSY;
4346+
bp->rx_copybreak = rx_copybreak;
4347+
}
4348+
return 0;
4349+
default:
4350+
return -EOPNOTSUPP;
4351+
}
4352+
}
4353+
4354+
static int bnxt_get_tunable(struct net_device *dev,
4355+
const struct ethtool_tunable *tuna, void *data)
4356+
{
4357+
struct bnxt *bp = netdev_priv(dev);
4358+
4359+
switch (tuna->id) {
4360+
case ETHTOOL_RX_COPYBREAK:
4361+
*(u32 *)data = bp->rx_copybreak;
4362+
break;
4363+
default:
4364+
return -EOPNOTSUPP;
4365+
}
4366+
4367+
return 0;
4368+
}
4369+
43314370
static int bnxt_read_sfp_module_eeprom_info(struct bnxt *bp, u16 i2c_addr,
43324371
u16 page_number, u8 bank,
43334372
u16 start_addr, u16 data_length,
@@ -4790,7 +4829,8 @@ static int bnxt_run_loopback(struct bnxt *bp)
47904829
cpr = &rxr->bnapi->cp_ring;
47914830
if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
47924831
cpr = rxr->rx_cpr;
4793-
pkt_size = min(bp->dev->mtu + ETH_HLEN, bp->rx_copy_thresh);
4832+
pkt_size = min(bp->dev->mtu + ETH_HLEN, max(BNXT_DEFAULT_RX_COPYBREAK,
4833+
bp->rx_copybreak));
47944834
skb = netdev_alloc_skb(bp->dev, pkt_size);
47954835
if (!skb)
47964836
return -ENOMEM;
@@ -5372,6 +5412,8 @@ const struct ethtool_ops bnxt_ethtool_ops = {
53725412
.get_link_ext_stats = bnxt_get_link_ext_stats,
53735413
.get_eee = bnxt_get_eee,
53745414
.set_eee = bnxt_set_eee,
5415+
.get_tunable = bnxt_get_tunable,
5416+
.set_tunable = bnxt_set_tunable,
53755417
.get_module_info = bnxt_get_module_info,
53765418
.get_module_eeprom = bnxt_get_module_eeprom,
53775419
.get_module_eeprom_by_page = bnxt_get_module_eeprom_by_page,

0 commit comments

Comments
 (0)