bnxt_en: Refactor RSS indir alloc/set functions
authorPavan Chebbi <pavan.chebbi@broadcom.com>
Mon, 25 Mar 2024 22:28:56 +0000 (15:28 -0700)
committerJakub Kicinski <kuba@kernel.org>
Fri, 29 Mar 2024 05:34:40 +0000 (22:34 -0700)
We will need to dynamically allocate and change indirection tables
for additional RSS contexts.  Add the rss_ctx pointer parameter to
bnxt_alloc_rss_indir_tbl() and bnxt_set_dflt_rss_indir_tbl().
Existing usage will always pass rss_ctx as NULL which means the
default RSS context.

When supporting additional RSS contexts in subsequent patches, we'll
pass the valid rss_ctx to these 2 functions.

Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com>
Signed-off-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Link: https://lore.kernel.org/r/20240325222902.220712-7-michael.chan@broadcom.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/broadcom/bnxt/bnxt.c
drivers/net/ethernet/broadcom/bnxt/bnxt.h

index 0ede267..80ccb5a 100644 (file)
@@ -6026,9 +6026,10 @@ static u16 bnxt_cp_ring_for_tx(struct bnxt *bp, struct bnxt_tx_ring_info *txr)
                return bnxt_cp_ring_from_grp(bp, &txr->tx_ring_struct);
 }
 
-static int bnxt_alloc_rss_indir_tbl(struct bnxt *bp)
+int bnxt_alloc_rss_indir_tbl(struct bnxt *bp, struct bnxt_rss_ctx *rss_ctx)
 {
        int entries;
+       u16 *tbl;
 
        if (bp->flags & BNXT_FLAG_CHIP_P5_PLUS)
                entries = BNXT_MAX_RSS_TABLE_ENTRIES_P5;
@@ -6036,16 +6037,22 @@ static int bnxt_alloc_rss_indir_tbl(struct bnxt *bp)
                entries = HW_HASH_INDEX_SIZE;
 
        bp->rss_indir_tbl_entries = entries;
-       bp->rss_indir_tbl = kmalloc_array(entries, sizeof(*bp->rss_indir_tbl),
-                                         GFP_KERNEL);
-       if (!bp->rss_indir_tbl)
+       tbl = kmalloc_array(entries, sizeof(*bp->rss_indir_tbl), GFP_KERNEL);
+       if (!tbl)
                return -ENOMEM;
+
+       if (rss_ctx)
+               rss_ctx->rss_indir_tbl = tbl;
+       else
+               bp->rss_indir_tbl = tbl;
+
        return 0;
 }
 
-static void bnxt_set_dflt_rss_indir_tbl(struct bnxt *bp)
+void bnxt_set_dflt_rss_indir_tbl(struct bnxt *bp, struct bnxt_rss_ctx *rss_ctx)
 {
        u16 max_rings, max_entries, pad, i;
+       u16 *rss_indir_tbl;
 
        if (!bp->rx_nr_rings)
                return;
@@ -6056,13 +6063,17 @@ static void bnxt_set_dflt_rss_indir_tbl(struct bnxt *bp)
                max_rings = bp->rx_nr_rings;
 
        max_entries = bnxt_get_rxfh_indir_size(bp->dev);
+       if (rss_ctx)
+               rss_indir_tbl = &rss_ctx->rss_indir_tbl[0];
+       else
+               rss_indir_tbl = &bp->rss_indir_tbl[0];
 
        for (i = 0; i < max_entries; i++)
-               bp->rss_indir_tbl[i] = ethtool_rxfh_indir_default(i, max_rings);
+               rss_indir_tbl[i] = ethtool_rxfh_indir_default(i, max_rings);
 
        pad = bp->rss_indir_tbl_entries - max_entries;
        if (pad)
-               memset(&bp->rss_indir_tbl[i], 0, pad * sizeof(u16));
+               memset(&rss_indir_tbl[i], 0, pad * sizeof(u16));
 }
 
 static u16 bnxt_get_max_rss_ring(struct bnxt *bp)
@@ -7341,7 +7352,7 @@ static void bnxt_check_rss_tbl_no_rmgr(struct bnxt *bp)
        if (hw_resc->resv_rx_rings != bp->rx_nr_rings) {
                hw_resc->resv_rx_rings = bp->rx_nr_rings;
                if (!netif_is_rxfh_configured(bp->dev))
-                       bnxt_set_dflt_rss_indir_tbl(bp);
+                       bnxt_set_dflt_rss_indir_tbl(bp, NULL);
        }
 }
 
@@ -7497,7 +7508,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
                return -ENOMEM;
 
        if (!netif_is_rxfh_configured(bp->dev))
-               bnxt_set_dflt_rss_indir_tbl(bp);
+               bnxt_set_dflt_rss_indir_tbl(bp, NULL);
 
        return rc;
 }
@@ -15119,7 +15130,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                        bp->flags |= BNXT_FLAG_CHIP_P7;
        }
 
-       rc = bnxt_alloc_rss_indir_tbl(bp);
+       rc = bnxt_alloc_rss_indir_tbl(bp, NULL);
        if (rc)
                goto init_err_pci_clean;
 
index 4d3104c..181758f 100644 (file)
@@ -2715,6 +2715,8 @@ int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp,
 int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp,
                                      struct bnxt_ntuple_filter *fltr);
 void bnxt_fill_ipv6_mask(__be32 mask[4]);
+int bnxt_alloc_rss_indir_tbl(struct bnxt *bp, struct bnxt_rss_ctx *rss_ctx);
+void bnxt_set_dflt_rss_indir_tbl(struct bnxt *bp, struct bnxt_rss_ctx *rss_ctx);
 int bnxt_get_nr_rss_ctxs(struct bnxt *bp, int rx_rings);
 int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic);
 int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings);