Skip to content

Commit ea89261

Browse files
azaki1NipaLocal
authored andcommitted
net: ethtool: pass a pointer to parameters to get/set_rxfh ethtool ops
The get/set_rxfh ethtool ops currently takes the rxfh (RSS) parameters as direct function arguments. This will force us to change the API (and all drivers' functions) every time some new parameters are added. This is part 1/2 of the fix, as suggested in [1]: - First simplify the code by always providing a pointer to all params (indir, key and func); the fact that some of them may be NULL seems like a weird historic thing or a premature optimization. It will simplify the drivers if all pointers are always present. - Then make the functions take a dev pointer, and a pointer to a single struct wrapping all arguments. The set_* should also take an extack. Link: https://lore.kernel.org/netdev/[email protected]/ [1] Suggested-by: Jakub Kicinski <[email protected]> Suggested-by: Jacob Keller <[email protected]> Signed-off-by: Ahmed Zaki <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 40648fa commit ea89261

File tree

48 files changed

+827
-730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+827
-730
lines changed

drivers/net/ethernet/amazon/ena/ena_ethtool.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -802,15 +802,15 @@ static int ena_indirection_table_get(struct ena_adapter *adapter, u32 *indir)
802802
return rc;
803803
}
804804

805-
static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
806-
u8 *hfunc)
805+
static int ena_get_rxfh(struct net_device *netdev,
806+
struct ethtool_rxfh_param *rxfh)
807807
{
808808
struct ena_adapter *adapter = netdev_priv(netdev);
809809
enum ena_admin_hash_functions ena_func;
810810
u8 func;
811811
int rc;
812812

813-
rc = ena_indirection_table_get(adapter, indir);
813+
rc = ena_indirection_table_get(adapter, rxfh->indir);
814814
if (rc)
815815
return rc;
816816

@@ -825,7 +825,7 @@ static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
825825
return rc;
826826
}
827827

828-
rc = ena_com_get_hash_key(adapter->ena_dev, key);
828+
rc = ena_com_get_hash_key(adapter->ena_dev, rxfh->key);
829829
if (rc)
830830
return rc;
831831

@@ -842,27 +842,27 @@ static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
842842
return -EOPNOTSUPP;
843843
}
844844

845-
if (hfunc)
846-
*hfunc = func;
845+
rxfh->hfunc = func;
847846

848847
return 0;
849848
}
850849

851-
static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
852-
const u8 *key, const u8 hfunc)
850+
static int ena_set_rxfh(struct net_device *netdev,
851+
struct ethtool_rxfh_param *rxfh,
852+
struct netlink_ext_ack *extack)
853853
{
854854
struct ena_adapter *adapter = netdev_priv(netdev);
855855
struct ena_com_dev *ena_dev = adapter->ena_dev;
856856
enum ena_admin_hash_functions func = 0;
857857
int rc;
858858

859-
if (indir) {
860-
rc = ena_indirection_table_set(adapter, indir);
859+
if (rxfh->indir) {
860+
rc = ena_indirection_table_set(adapter, rxfh->indir);
861861
if (rc)
862862
return rc;
863863
}
864864

865-
switch (hfunc) {
865+
switch (rxfh->hfunc) {
866866
case ETH_RSS_HASH_NO_CHANGE:
867867
func = ena_com_get_current_hash_function(ena_dev);
868868
break;
@@ -874,12 +874,12 @@ static int ena_set_rxfh(struct net_device *netdev, const u32 *indir,
874874
break;
875875
default:
876876
netif_err(adapter, drv, netdev, "Unsupported hfunc %d\n",
877-
hfunc);
877+
rxfh->hfunc);
878878
return -EOPNOTSUPP;
879879
}
880880

881-
if (key || func) {
882-
rc = ena_com_fill_hash_function(ena_dev, func, key,
881+
if (rxfh->key || func) {
882+
rc = ena_com_fill_hash_function(ena_dev, func, rxfh->key,
883883
ENA_HASH_KEY_SIZE,
884884
0xFFFFFFFF);
885885
if (unlikely(rc)) {

drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -527,47 +527,48 @@ static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
527527
return ARRAY_SIZE(pdata->rss_table);
528528
}
529529

530-
static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
531-
u8 *hfunc)
530+
static int xgbe_get_rxfh(struct net_device *netdev,
531+
struct ethtool_rxfh_param *rxfh)
532532
{
533533
struct xgbe_prv_data *pdata = netdev_priv(netdev);
534534
unsigned int i;
535535

536-
if (indir) {
536+
if (rxfh->indir) {
537537
for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
538-
indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
539-
MAC_RSSDR, DMCH);
538+
rxfh->indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
539+
MAC_RSSDR, DMCH);
540540
}
541541

542-
if (key)
543-
memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
542+
if (rxfh->key)
543+
memcpy(rxfh->key, pdata->rss_key, sizeof(pdata->rss_key));
544544

545-
if (hfunc)
546-
*hfunc = ETH_RSS_HASH_TOP;
545+
rxfh->hfunc = ETH_RSS_HASH_TOP;
547546

548547
return 0;
549548
}
550549

551-
static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
552-
const u8 *key, const u8 hfunc)
550+
static int xgbe_set_rxfh(struct net_device *netdev,
551+
struct ethtool_rxfh_param *rxfh,
552+
struct netlink_ext_ack *extack)
553553
{
554554
struct xgbe_prv_data *pdata = netdev_priv(netdev);
555555
struct xgbe_hw_if *hw_if = &pdata->hw_if;
556556
unsigned int ret;
557557

558-
if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) {
558+
if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
559+
rxfh->hfunc != ETH_RSS_HASH_TOP) {
559560
netdev_err(netdev, "unsupported hash function\n");
560561
return -EOPNOTSUPP;
561562
}
562563

563-
if (indir) {
564-
ret = hw_if->set_rss_lookup_table(pdata, indir);
564+
if (rxfh->indir) {
565+
ret = hw_if->set_rss_lookup_table(pdata, rxfh->indir);
565566
if (ret)
566567
return ret;
567568
}
568569

569-
if (key) {
570-
ret = hw_if->set_rss_hash_key(pdata, key);
570+
if (rxfh->key) {
571+
ret = hw_if->set_rss_hash_key(pdata, rxfh->key);
571572
if (ret)
572573
return ret;
573574
}

drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -447,30 +447,30 @@ static u32 aq_ethtool_get_rss_key_size(struct net_device *ndev)
447447
return sizeof(cfg->aq_rss.hash_secret_key);
448448
}
449449

450-
static int aq_ethtool_get_rss(struct net_device *ndev, u32 *indir, u8 *key,
451-
u8 *hfunc)
450+
static int aq_ethtool_get_rss(struct net_device *ndev,
451+
struct ethtool_rxfh_param *rxfh)
452452
{
453453
struct aq_nic_s *aq_nic = netdev_priv(ndev);
454454
struct aq_nic_cfg_s *cfg;
455455
unsigned int i = 0U;
456456

457457
cfg = aq_nic_get_cfg(aq_nic);
458458

459-
if (hfunc)
460-
*hfunc = ETH_RSS_HASH_TOP; /* Toeplitz */
461-
if (indir) {
459+
rxfh->hfunc = ETH_RSS_HASH_TOP; /* Toeplitz */
460+
if (rxfh->indir) {
462461
for (i = 0; i < AQ_CFG_RSS_INDIRECTION_TABLE_MAX; i++)
463-
indir[i] = cfg->aq_rss.indirection_table[i];
462+
rxfh->indir[i] = cfg->aq_rss.indirection_table[i];
464463
}
465-
if (key)
466-
memcpy(key, cfg->aq_rss.hash_secret_key,
464+
if (rxfh->key)
465+
memcpy(rxfh->key, cfg->aq_rss.hash_secret_key,
467466
sizeof(cfg->aq_rss.hash_secret_key));
468467

469468
return 0;
470469
}
471470

472-
static int aq_ethtool_set_rss(struct net_device *netdev, const u32 *indir,
473-
const u8 *key, const u8 hfunc)
471+
static int aq_ethtool_set_rss(struct net_device *netdev,
472+
struct ethtool_rxfh_param *rxfh,
473+
struct netlink_ext_ack *extack)
474474
{
475475
struct aq_nic_s *aq_nic = netdev_priv(netdev);
476476
struct aq_nic_cfg_s *cfg;
@@ -482,16 +482,17 @@ static int aq_ethtool_set_rss(struct net_device *netdev, const u32 *indir,
482482
rss_entries = cfg->aq_rss.indirection_table_size;
483483

484484
/* We do not allow change in unsupported parameters */
485-
if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
485+
if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
486+
rxfh->hfunc != ETH_RSS_HASH_TOP)
486487
return -EOPNOTSUPP;
487488
/* Fill out the redirection table */
488-
if (indir)
489+
if (rxfh->indir)
489490
for (i = 0; i < rss_entries; i++)
490-
cfg->aq_rss.indirection_table[i] = indir[i];
491+
cfg->aq_rss.indirection_table[i] = rxfh->indir[i];
491492

492493
/* Fill out the rss hash key */
493-
if (key) {
494-
memcpy(cfg->aq_rss.hash_secret_key, key,
494+
if (rxfh->key) {
495+
memcpy(cfg->aq_rss.hash_secret_key, rxfh->key,
495496
sizeof(cfg->aq_rss.hash_secret_key));
496497
err = aq_nic->aq_hw_ops->hw_rss_hash_set(aq_nic->aq_hw,
497498
&cfg->aq_rss);

drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3486,16 +3486,15 @@ static u32 bnx2x_get_rxfh_indir_size(struct net_device *dev)
34863486
return T_ETH_INDIRECTION_TABLE_SIZE;
34873487
}
34883488

3489-
static int bnx2x_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
3490-
u8 *hfunc)
3489+
static int bnx2x_get_rxfh(struct net_device *dev,
3490+
struct ethtool_rxfh_param *rxfh)
34913491
{
34923492
struct bnx2x *bp = netdev_priv(dev);
34933493
u8 ind_table[T_ETH_INDIRECTION_TABLE_SIZE] = {0};
34943494
size_t i;
34953495

3496-
if (hfunc)
3497-
*hfunc = ETH_RSS_HASH_TOP;
3498-
if (!indir)
3496+
rxfh->hfunc = ETH_RSS_HASH_TOP;
3497+
if (!rxfh->indir)
34993498
return 0;
35003499

35013500
/* Get the current configuration of the RSS indirection table */
@@ -3511,25 +3510,27 @@ static int bnx2x_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
35113510
* queue.
35123511
*/
35133512
for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++)
3514-
indir[i] = ind_table[i] - bp->fp->cl_id;
3513+
rxfh->indir[i] = ind_table[i] - bp->fp->cl_id;
35153514

35163515
return 0;
35173516
}
35183517

3519-
static int bnx2x_set_rxfh(struct net_device *dev, const u32 *indir,
3520-
const u8 *key, const u8 hfunc)
3518+
static int bnx2x_set_rxfh(struct net_device *dev,
3519+
struct ethtool_rxfh_param *rxfh,
3520+
struct netlink_ext_ack *extack)
35213521
{
35223522
struct bnx2x *bp = netdev_priv(dev);
35233523
size_t i;
35243524

35253525
/* We require at least one supported parameter to be changed and no
35263526
* change in any of the unsupported parameters
35273527
*/
3528-
if (key ||
3529-
(hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
3528+
if (rxfh->key ||
3529+
(rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
3530+
rxfh->hfunc != ETH_RSS_HASH_TOP))
35303531
return -EOPNOTSUPP;
35313532

3532-
if (!indir)
3533+
if (!rxfh->indir)
35333534
return 0;
35343535

35353536
for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
@@ -3542,7 +3543,7 @@ static int bnx2x_set_rxfh(struct net_device *dev, const u32 *indir,
35423543
* align the received table to the Client ID of the leading RSS
35433544
* queue
35443545
*/
3545-
bp->rss_conf_obj.ind_table[i] = indir[i] + bp->fp->cl_id;
3546+
bp->rss_conf_obj.ind_table[i] = rxfh->indir[i] + bp->fp->cl_id;
35463547
}
35473548

35483549
if (bp->state == BNX2X_STATE_OPEN)

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,49 +1333,49 @@ static u32 bnxt_get_rxfh_key_size(struct net_device *dev)
13331333
return HW_HASH_KEY_SIZE;
13341334
}
13351335

1336-
static int bnxt_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
1337-
u8 *hfunc)
1336+
static int bnxt_get_rxfh(struct net_device *dev,
1337+
struct ethtool_rxfh_param *rxfh)
13381338
{
13391339
struct bnxt *bp = netdev_priv(dev);
13401340
struct bnxt_vnic_info *vnic;
13411341
u32 i, tbl_size;
13421342

1343-
if (hfunc)
1344-
*hfunc = ETH_RSS_HASH_TOP;
1343+
rxfh->hfunc = ETH_RSS_HASH_TOP;
13451344

13461345
if (!bp->vnic_info)
13471346
return 0;
13481347

13491348
vnic = &bp->vnic_info[0];
1350-
if (indir && bp->rss_indir_tbl) {
1349+
if (rxfh->indir && bp->rss_indir_tbl) {
13511350
tbl_size = bnxt_get_rxfh_indir_size(dev);
13521351
for (i = 0; i < tbl_size; i++)
1353-
indir[i] = bp->rss_indir_tbl[i];
1352+
rxfh->indir[i] = bp->rss_indir_tbl[i];
13541353
}
13551354

1356-
if (key && vnic->rss_hash_key)
1357-
memcpy(key, vnic->rss_hash_key, HW_HASH_KEY_SIZE);
1355+
if (rxfh->key && vnic->rss_hash_key)
1356+
memcpy(rxfh->key, vnic->rss_hash_key, HW_HASH_KEY_SIZE);
13581357

13591358
return 0;
13601359
}
13611360

1362-
static int bnxt_set_rxfh(struct net_device *dev, const u32 *indir,
1363-
const u8 *key, const u8 hfunc)
1361+
static int bnxt_set_rxfh(struct net_device *dev,
1362+
struct ethtool_rxfh_param *rxfh,
1363+
struct netlink_ext_ack *extack)
13641364
{
13651365
struct bnxt *bp = netdev_priv(dev);
13661366
int rc = 0;
13671367

1368-
if (hfunc && hfunc != ETH_RSS_HASH_TOP)
1368+
if (rxfh->hfunc && rxfh->hfunc != ETH_RSS_HASH_TOP)
13691369
return -EOPNOTSUPP;
13701370

1371-
if (key)
1371+
if (rxfh->key)
13721372
return -EOPNOTSUPP;
13731373

1374-
if (indir) {
1374+
if (rxfh->indir) {
13751375
u32 i, pad, tbl_size = bnxt_get_rxfh_indir_size(dev);
13761376

13771377
for (i = 0; i < tbl_size; i++)
1378-
bp->rss_indir_tbl[i] = indir[i];
1378+
bp->rss_indir_tbl[i] = rxfh->indir[i];
13791379
pad = bp->rss_indir_tbl_entries - tbl_size;
13801380
if (pad)
13811381
memset(&bp->rss_indir_tbl[i], 0, pad * sizeof(u16));

drivers/net/ethernet/broadcom/tg3.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12745,40 +12745,40 @@ static u32 tg3_get_rxfh_indir_size(struct net_device *dev)
1274512745
return size;
1274612746
}
1274712747

12748-
static int tg3_get_rxfh(struct net_device *dev, u32 *indir, u8 *key, u8 *hfunc)
12748+
static int tg3_get_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh)
1274912749
{
1275012750
struct tg3 *tp = netdev_priv(dev);
1275112751
int i;
1275212752

12753-
if (hfunc)
12754-
*hfunc = ETH_RSS_HASH_TOP;
12755-
if (!indir)
12753+
rxfh->hfunc = ETH_RSS_HASH_TOP;
12754+
if (!rxfh->indir)
1275612755
return 0;
1275712756

1275812757
for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++)
12759-
indir[i] = tp->rss_ind_tbl[i];
12758+
rxfh->indir[i] = tp->rss_ind_tbl[i];
1276012759

1276112760
return 0;
1276212761
}
1276312762

12764-
static int tg3_set_rxfh(struct net_device *dev, const u32 *indir, const u8 *key,
12765-
const u8 hfunc)
12763+
static int tg3_set_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh,
12764+
struct netlink_ext_ack *extack)
1276612765
{
1276712766
struct tg3 *tp = netdev_priv(dev);
1276812767
size_t i;
1276912768

1277012769
/* We require at least one supported parameter to be changed and no
1277112770
* change in any of the unsupported parameters
1277212771
*/
12773-
if (key ||
12774-
(hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
12772+
if (rxfh->key ||
12773+
(rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
12774+
rxfh->hfunc != ETH_RSS_HASH_TOP))
1277512775
return -EOPNOTSUPP;
1277612776

12777-
if (!indir)
12777+
if (!rxfh->indir)
1277812778
return 0;
1277912779

1278012780
for (i = 0; i < TG3_RSS_INDIR_TBL_SIZE; i++)
12781-
tp->rss_ind_tbl[i] = indir[i];
12781+
tp->rss_ind_tbl[i] = rxfh->indir[i];
1278212782

1278312783
if (!netif_running(dev) || !tg3_flag(tp, ENABLE_RSS))
1278412784
return 0;

0 commit comments

Comments
 (0)