Skip to content

Commit 2e4592d

Browse files
vikasbrcmkuba-moo
authored andcommitted
bnxt_en: Change MSIX/NQs allocation policy
The existing scheme sets aside a number of MSIX/NQs for the RoCE driver whether the RoCE driver is registered or not. This scheme is not flexible and limits the resources available for the L2 rings if RoCE is never used. Modify the scheme so that the RoCE MSIX/NQs can be used by the L2 driver if they are not used for RoCE. The MSIX/NQs are now represented by 3 fields. bp->ulp_num_msix_want contains the desired default value, edev->ulp_num_msix_vec contains the available value (but not necessarily in use), and ulp_tbl->msix_requested contains the actual value in use by RoCE. The L2 driver can dip into edev->ulp_num_msix_vec if necessary. We need to add rtnl_lock() back in bnxt_register_dev() and bnxt_unregister_dev() to synchronize the MSIX usage between L2 and RoCE. Reviewed-by: Andy Gospodarek <andrew.gospodarek@broadcom.com> Signed-off-by: Vikas Gupta <vikas.gupta@broadcom.com> Signed-off-by: Michael Chan <michael.chan@broadcom.com> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Link: https://lore.kernel.org/r/20240409215431.41424-6-michael.chan@broadcom.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 194fad5 commit 2e4592d

File tree

4 files changed

+92
-19
lines changed

4 files changed

+92
-19
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7549,6 +7549,20 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
75497549
if (!netif_is_rxfh_configured(bp->dev))
75507550
bnxt_set_dflt_rss_indir_tbl(bp, NULL);
75517551

7552+
if (!bnxt_ulp_registered(bp->edev) && BNXT_NEW_RM(bp)) {
7553+
int resv_msix, resv_ctx, ulp_msix, ulp_ctxs;
7554+
struct bnxt_hw_resc *hw_resc;
7555+
7556+
hw_resc = &bp->hw_resc;
7557+
resv_msix = hw_resc->resv_irqs - bp->cp_nr_rings;
7558+
ulp_msix = bnxt_get_ulp_msix_num(bp);
7559+
ulp_msix = min_t(int, resv_msix, ulp_msix);
7560+
bnxt_set_ulp_msix_num(bp, ulp_msix);
7561+
resv_ctx = hw_resc->resv_stat_ctxs - bp->cp_nr_rings;
7562+
ulp_ctxs = min(resv_ctx, bnxt_get_ulp_stat_ctxs(bp));
7563+
bnxt_set_ulp_stat_ctxs(bp, ulp_ctxs);
7564+
}
7565+
75527566
return rc;
75537567
}
75547568

@@ -14982,6 +14996,7 @@ static void bnxt_trim_dflt_sh_rings(struct bnxt *bp)
1498214996
static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
1498314997
{
1498414998
int dflt_rings, max_rx_rings, max_tx_rings, rc;
14999+
int avail_msix;
1498515000

1498615001
if (!bnxt_can_reserve_rings(bp))
1498715002
return 0;
@@ -15009,6 +15024,14 @@ static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh)
1500915024
bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings;
1501015025
bp->tx_nr_rings = bp->tx_nr_rings_per_tc;
1501115026

15027+
avail_msix = bnxt_get_max_func_irqs(bp) - bp->cp_nr_rings;
15028+
if (avail_msix >= BNXT_MIN_ROCE_CP_RINGS) {
15029+
int ulp_num_msix = min(avail_msix, bp->ulp_num_msix_want);
15030+
15031+
bnxt_set_ulp_msix_num(bp, ulp_num_msix);
15032+
bnxt_set_dflt_ulp_stat_ctxs(bp);
15033+
}
15034+
1501215035
rc = __bnxt_reserve_rings(bp);
1501315036
if (rc && rc != -ENODEV)
1501415037
netdev_warn(bp->dev, "Unable to reserve tx rings\n");
@@ -15358,6 +15381,7 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1535815381
bnxt_set_rx_skb_mode(bp, false);
1535915382
bnxt_set_tpa_flags(bp);
1536015383
bnxt_set_ring_params(bp);
15384+
bnxt_rdma_aux_device_init(bp);
1536115385
rc = bnxt_set_dflt_rings(bp, true);
1536215386
if (rc) {
1536315387
if (BNXT_VF(bp) && rc == -ENODEV) {
@@ -15411,7 +15435,6 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1541115435
if (BNXT_SUPPORTS_NTUPLE_VNIC(bp))
1541215436
bnxt_init_multi_rss_ctx(bp);
1541315437

15414-
bnxt_rdma_aux_device_init(bp);
1541515438

1541615439
rc = register_netdev(dev);
1541715440
if (rc)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,7 @@ struct bnxt {
23032303

23042304
struct bnxt_irq *irq_tbl;
23052305
int total_irqs;
2306+
int ulp_num_msix_want;
23062307
u8 mac_addr[ETH_ALEN];
23072308

23082309
#ifdef CONFIG_BNXT_DCB

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

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,46 @@ static void bnxt_fill_msix_vecs(struct bnxt *bp, struct bnxt_msix_entry *ent)
4848
}
4949
}
5050

51+
int bnxt_get_ulp_msix_num(struct bnxt *bp)
52+
{
53+
if (bp->edev)
54+
return bp->edev->ulp_num_msix_vec;
55+
return 0;
56+
}
57+
58+
void bnxt_set_ulp_msix_num(struct bnxt *bp, int num)
59+
{
60+
if (bp->edev)
61+
bp->edev->ulp_num_msix_vec = num;
62+
}
63+
64+
int bnxt_get_ulp_stat_ctxs(struct bnxt *bp)
65+
{
66+
if (bp->edev)
67+
return bp->edev->ulp_num_ctxs;
68+
return 0;
69+
}
70+
71+
void bnxt_set_ulp_stat_ctxs(struct bnxt *bp, int num_ulp_ctx)
72+
{
73+
if (bp->edev)
74+
bp->edev->ulp_num_ctxs = num_ulp_ctx;
75+
}
76+
77+
void bnxt_set_dflt_ulp_stat_ctxs(struct bnxt *bp)
78+
{
79+
if (bp->edev) {
80+
bp->edev->ulp_num_ctxs = BNXT_MIN_ROCE_STAT_CTXS;
81+
/* Reserve one additional stat_ctx for PF0 (except
82+
* on 1-port NICs) as it also creates one stat_ctx
83+
* for PF1 in case of RoCE bonding.
84+
*/
85+
if (BNXT_PF(bp) && !bp->pf.port_id &&
86+
bp->port_count > 1)
87+
bp->edev->ulp_num_ctxs++;
88+
}
89+
}
90+
5191
int bnxt_register_dev(struct bnxt_en_dev *edev,
5292
struct bnxt_ulp_ops *ulp_ops,
5393
void *handle)
@@ -56,11 +96,19 @@ int bnxt_register_dev(struct bnxt_en_dev *edev,
5696
struct bnxt *bp = netdev_priv(dev);
5797
unsigned int max_stat_ctxs;
5898
struct bnxt_ulp *ulp;
99+
int rc = 0;
59100

101+
rtnl_lock();
102+
if (!bp->irq_tbl) {
103+
rc = -ENODEV;
104+
goto exit;
105+
}
60106
max_stat_ctxs = bnxt_get_max_func_stat_ctxs(bp);
61107
if (max_stat_ctxs <= BNXT_MIN_ROCE_STAT_CTXS ||
62-
bp->cp_nr_rings == max_stat_ctxs)
63-
return -ENOMEM;
108+
bp->cp_nr_rings == max_stat_ctxs) {
109+
rc = -ENOMEM;
110+
goto exit;
111+
}
64112

65113
ulp = edev->ulp_tbl;
66114
ulp->handle = handle;
@@ -69,9 +117,13 @@ int bnxt_register_dev(struct bnxt_en_dev *edev,
69117
if (test_bit(BNXT_STATE_OPEN, &bp->state))
70118
bnxt_hwrm_vnic_cfg(bp, &bp->vnic_info[BNXT_VNIC_DEFAULT]);
71119

120+
edev->ulp_tbl->msix_requested = bnxt_get_ulp_msix_num(bp);
121+
72122
bnxt_fill_msix_vecs(bp, bp->edev->msix_entries);
73123
edev->flags |= BNXT_EN_FLAG_MSIX_REQUESTED;
74-
return 0;
124+
exit:
125+
rtnl_unlock();
126+
return rc;
75127
}
76128
EXPORT_SYMBOL(bnxt_register_dev);
77129

@@ -83,8 +135,10 @@ void bnxt_unregister_dev(struct bnxt_en_dev *edev)
83135
int i = 0;
84136

85137
ulp = edev->ulp_tbl;
138+
rtnl_lock();
86139
if (ulp->msix_requested)
87140
edev->flags &= ~BNXT_EN_FLAG_MSIX_REQUESTED;
141+
edev->ulp_tbl->msix_requested = 0;
88142

89143
if (ulp->max_async_event_id)
90144
bnxt_hwrm_func_drv_rgtr(bp, NULL, 0, true);
@@ -97,11 +151,12 @@ void bnxt_unregister_dev(struct bnxt_en_dev *edev)
97151
msleep(100);
98152
i++;
99153
}
154+
rtnl_unlock();
100155
return;
101156
}
102157
EXPORT_SYMBOL(bnxt_unregister_dev);
103158

104-
int bnxt_get_ulp_msix_num(struct bnxt *bp)
159+
static int bnxt_set_dflt_ulp_msix(struct bnxt *bp)
105160
{
106161
u32 roce_msix = BNXT_VF(bp) ?
107162
BNXT_MAX_VF_ROCE_MSIX : BNXT_MAX_ROCE_MSIX;
@@ -110,18 +165,6 @@ int bnxt_get_ulp_msix_num(struct bnxt *bp)
110165
min_t(u32, roce_msix, num_online_cpus()) : 0);
111166
}
112167

113-
int bnxt_get_ulp_stat_ctxs(struct bnxt *bp)
114-
{
115-
if (bnxt_ulp_registered(bp->edev)) {
116-
struct bnxt_en_dev *edev = bp->edev;
117-
118-
if (edev->ulp_tbl->msix_requested)
119-
return BNXT_MIN_ROCE_STAT_CTXS;
120-
}
121-
122-
return 0;
123-
}
124-
125168
int bnxt_send_msg(struct bnxt_en_dev *edev,
126169
struct bnxt_fw_msg *fw_msg)
127170
{
@@ -336,7 +379,6 @@ static void bnxt_set_edev_info(struct bnxt_en_dev *edev, struct bnxt *bp)
336379
edev->pf_port_id = bp->pf.port_id;
337380
edev->en_state = bp->state;
338381
edev->bar0 = bp->bar0;
339-
edev->ulp_tbl->msix_requested = bnxt_get_ulp_msix_num(bp);
340382
}
341383

342384
void bnxt_rdma_aux_device_add(struct bnxt *bp)
@@ -409,6 +451,7 @@ void bnxt_rdma_aux_device_init(struct bnxt *bp)
409451
aux_priv->edev = edev;
410452
bp->edev = edev;
411453
bnxt_set_edev_info(edev, bp);
454+
bp->ulp_num_msix_want = bnxt_set_dflt_ulp_msix(bp);
412455

413456
return;
414457

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,23 @@ struct bnxt_en_dev {
8585
* updated in resume.
8686
*/
8787
void __iomem *bar0;
88+
89+
u16 ulp_num_msix_vec;
90+
u16 ulp_num_ctxs;
8891
};
8992

9093
static inline bool bnxt_ulp_registered(struct bnxt_en_dev *edev)
9194
{
92-
if (edev && edev->ulp_tbl)
95+
if (edev && rcu_access_pointer(edev->ulp_tbl->ulp_ops))
9396
return true;
9497
return false;
9598
}
9699

97100
int bnxt_get_ulp_msix_num(struct bnxt *bp);
101+
void bnxt_set_ulp_msix_num(struct bnxt *bp, int num);
98102
int bnxt_get_ulp_stat_ctxs(struct bnxt *bp);
103+
void bnxt_set_ulp_stat_ctxs(struct bnxt *bp, int num_ctxs);
104+
void bnxt_set_dflt_ulp_stat_ctxs(struct bnxt *bp);
99105
void bnxt_ulp_stop(struct bnxt *bp);
100106
void bnxt_ulp_start(struct bnxt *bp, int err);
101107
void bnxt_ulp_sriov_cfg(struct bnxt *bp, int num_vfs);

0 commit comments

Comments
 (0)