Skip to content

Commit fbcfc8e

Browse files
Michael Chandavem330
authored andcommitted
bnxt_en: Reserve completion rings and MSIX for bnxt_re RDMA driver.
Add additional logic to reserve completion rings for the bnxt_re driver when it requests MSIX vectors. The function bnxt_cp_rings_in_use() will return the total number of completion rings used by both drivers that need to be reserved. If the network interface in up, we will close and open the NIC to reserve the new set of completion rings and re-initialize the vectors. Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4e41dc5 commit fbcfc8e

File tree

3 files changed

+65
-16
lines changed

3 files changed

+65
-16
lines changed

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

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4756,7 +4756,7 @@ static int bnxt_cp_rings_in_use(struct bnxt *bp)
47564756
static bool bnxt_need_reserve_rings(struct bnxt *bp)
47574757
{
47584758
struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
4759-
int cp = bp->cp_nr_rings;
4759+
int cp = bnxt_cp_rings_in_use(bp);
47604760
int rx = bp->rx_nr_rings;
47614761
int vnic = 1, grp = rx;
47624762

@@ -4783,9 +4783,9 @@ static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
47834783
static int __bnxt_reserve_rings(struct bnxt *bp)
47844784
{
47854785
struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
4786+
int cp = bnxt_cp_rings_in_use(bp);
47864787
int tx = bp->tx_nr_rings;
47874788
int rx = bp->rx_nr_rings;
4788-
int cp = bp->cp_nr_rings;
47894789
int grp, rx_rings, rc;
47904790
bool sh = false;
47914791
int vnic = 1;
@@ -5908,7 +5908,7 @@ void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max)
59085908
bp->hw_resc.max_cp_rings = max;
59095909
}
59105910

5911-
static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
5911+
unsigned int bnxt_get_max_func_irqs(struct bnxt *bp)
59125912
{
59135913
struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
59145914

@@ -5920,6 +5920,26 @@ void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs)
59205920
bp->hw_resc.max_irqs = max_irqs;
59215921
}
59225922

5923+
int bnxt_get_avail_msix(struct bnxt *bp, int num)
5924+
{
5925+
int max_cp = bnxt_get_max_func_cp_rings(bp);
5926+
int max_irq = bnxt_get_max_func_irqs(bp);
5927+
int total_req = bp->cp_nr_rings + num;
5928+
int max_idx, avail_msix;
5929+
5930+
max_idx = min_t(int, bp->total_irqs, max_cp);
5931+
avail_msix = max_idx - bp->cp_nr_rings;
5932+
if (!(bp->flags & BNXT_FLAG_NEW_RM) || avail_msix >= num)
5933+
return avail_msix;
5934+
5935+
if (max_irq < total_req) {
5936+
num = max_irq - bp->cp_nr_rings;
5937+
if (num <= 0)
5938+
return 0;
5939+
}
5940+
return num;
5941+
}
5942+
59235943
static int bnxt_get_num_msix(struct bnxt *bp)
59245944
{
59255945
if (!(bp->flags & BNXT_FLAG_NEW_RM))
@@ -5930,7 +5950,7 @@ static int bnxt_get_num_msix(struct bnxt *bp)
59305950

59315951
static int bnxt_init_msix(struct bnxt *bp)
59325952
{
5933-
int i, total_vecs, max, rc = 0, min = 1;
5953+
int i, total_vecs, max, rc = 0, min = 1, ulp_msix;
59345954
struct msix_entry *msix_ent;
59355955

59365956
total_vecs = bnxt_get_num_msix(bp);
@@ -5951,7 +5971,8 @@ static int bnxt_init_msix(struct bnxt *bp)
59515971
min = 2;
59525972

59535973
total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs);
5954-
if (total_vecs < 0) {
5974+
ulp_msix = bnxt_get_ulp_msix_num(bp);
5975+
if (total_vecs < 0 || total_vecs < ulp_msix) {
59555976
rc = -ENODEV;
59565977
goto msix_setup_exit;
59575978
}
@@ -5964,7 +5985,7 @@ static int bnxt_init_msix(struct bnxt *bp)
59645985
bp->total_irqs = total_vecs;
59655986
/* Trim rings based upon num of vectors allocated */
59665987
rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings,
5967-
total_vecs, min == 1);
5988+
total_vecs - ulp_msix, min == 1);
59685989
if (rc)
59695990
goto msix_setup_exit;
59705991

@@ -6028,9 +6049,8 @@ static void bnxt_clear_int_mode(struct bnxt *bp)
60286049
bp->flags &= ~BNXT_FLAG_USING_MSIX;
60296050
}
60306051

6031-
static int bnxt_reserve_rings(struct bnxt *bp)
6052+
int bnxt_reserve_rings(struct bnxt *bp)
60326053
{
6033-
int orig_cp = bp->hw_resc.resv_cp_rings;
60346054
int tcs = netdev_get_num_tc(bp->dev);
60356055
int rc;
60366056

@@ -6042,7 +6062,8 @@ static int bnxt_reserve_rings(struct bnxt *bp)
60426062
netdev_err(bp->dev, "ring reservation failure rc: %d\n", rc);
60436063
return rc;
60446064
}
6045-
if ((bp->flags & BNXT_FLAG_NEW_RM) && bp->cp_nr_rings > orig_cp) {
6065+
if ((bp->flags & BNXT_FLAG_NEW_RM) &&
6066+
(bnxt_get_num_msix(bp) != bp->total_irqs)) {
60466067
bnxt_clear_int_mode(bp);
60476068
rc = bnxt_init_int_mode(bp);
60486069
if (rc)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,10 @@ unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp);
14541454
void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max);
14551455
unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp);
14561456
void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max);
1457+
unsigned int bnxt_get_max_func_irqs(struct bnxt *bp);
14571458
void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max);
1459+
int bnxt_get_avail_msix(struct bnxt *bp, int num);
1460+
int bnxt_reserve_rings(struct bnxt *bp);
14581461
void bnxt_tx_disable(struct bnxt *bp);
14591462
void bnxt_tx_enable(struct bnxt *bp);
14601463
int bnxt_hwrm_set_pause(struct bnxt *);

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, int ulp_id,
108108
struct bnxt *bp = netdev_priv(dev);
109109
int max_idx, max_cp_rings;
110110
int avail_msix, i, idx;
111+
int rc = 0;
111112

112113
ASSERT_RTNL();
113114
if (ulp_id != BNXT_ROCE_ULP)
@@ -120,26 +121,46 @@ static int bnxt_req_msix_vecs(struct bnxt_en_dev *edev, int ulp_id,
120121
return -EAGAIN;
121122

122123
max_cp_rings = bnxt_get_max_func_cp_rings(bp);
123-
max_idx = min_t(int, bp->total_irqs, max_cp_rings);
124-
avail_msix = max_idx - bp->cp_nr_rings;
124+
avail_msix = bnxt_get_avail_msix(bp, num_msix);
125125
if (!avail_msix)
126126
return -ENOMEM;
127127
if (avail_msix > num_msix)
128128
avail_msix = num_msix;
129129

130-
if (bp->flags & BNXT_FLAG_NEW_RM)
130+
if (bp->flags & BNXT_FLAG_NEW_RM) {
131131
idx = bp->cp_nr_rings;
132-
else
132+
} else {
133+
max_idx = min_t(int, bp->total_irqs, max_cp_rings);
133134
idx = max_idx - avail_msix;
135+
}
134136
edev->ulp_tbl[ulp_id].msix_base = idx;
137+
edev->ulp_tbl[ulp_id].msix_requested = avail_msix;
138+
if (bp->total_irqs < (idx + avail_msix)) {
139+
if (netif_running(dev)) {
140+
bnxt_close_nic(bp, true, false);
141+
rc = bnxt_open_nic(bp, true, false);
142+
} else {
143+
rc = bnxt_reserve_rings(bp);
144+
}
145+
}
146+
if (rc) {
147+
edev->ulp_tbl[ulp_id].msix_requested = 0;
148+
return -EAGAIN;
149+
}
150+
151+
if (bp->flags & BNXT_FLAG_NEW_RM) {
152+
struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
153+
154+
avail_msix = hw_resc->resv_cp_rings - bp->cp_nr_rings;
155+
edev->ulp_tbl[ulp_id].msix_requested = avail_msix;
156+
}
135157
for (i = 0; i < avail_msix; i++) {
136158
ent[i].vector = bp->irq_tbl[idx + i].vector;
137159
ent[i].ring_idx = idx + i;
138160
ent[i].db_offset = (idx + i) * 0x80;
139161
}
140-
bnxt_set_max_func_irqs(bp, max_idx - avail_msix);
162+
bnxt_set_max_func_irqs(bp, bnxt_get_max_func_irqs(bp) - avail_msix);
141163
bnxt_set_max_func_cp_rings(bp, max_cp_rings - avail_msix);
142-
edev->ulp_tbl[ulp_id].msix_requested = avail_msix;
143164
return avail_msix;
144165
}
145166

@@ -157,7 +178,11 @@ static int bnxt_free_msix_vecs(struct bnxt_en_dev *edev, int ulp_id)
157178
msix_requested = edev->ulp_tbl[ulp_id].msix_requested;
158179
bnxt_set_max_func_cp_rings(bp, max_cp_rings + msix_requested);
159180
edev->ulp_tbl[ulp_id].msix_requested = 0;
160-
bnxt_set_max_func_irqs(bp, bp->total_irqs);
181+
bnxt_set_max_func_irqs(bp, bnxt_get_max_func_irqs(bp) + msix_requested);
182+
if (netif_running(dev)) {
183+
bnxt_close_nic(bp, true, false);
184+
bnxt_open_nic(bp, true, false);
185+
}
161186
return 0;
162187
}
163188

0 commit comments

Comments
 (0)