Skip to content

Commit

Permalink
bnxt_en: Refactor bnxt_need_reserve_rings().
Browse files Browse the repository at this point in the history
Refactor bnxt_need_reserve_rings() slightly so that __bnxt_reserve_rings()
can call it and remove some duplicated code.

Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Michael Chan authored and David S. Miller committed Apr 1, 2018
1 parent e5811b8 commit 4e41dc5
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions drivers/net/ethernet/broadcom/bnxt/bnxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -4753,6 +4753,30 @@ static int bnxt_cp_rings_in_use(struct bnxt *bp)
return cp;
}

static bool bnxt_need_reserve_rings(struct bnxt *bp)
{
struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
int cp = bp->cp_nr_rings;
int rx = bp->rx_nr_rings;
int vnic = 1, grp = rx;

if (bp->hwrm_spec_code < 0x10601)
return false;

if (hw_resc->resv_tx_rings != bp->tx_nr_rings)
return true;

if (bp->flags & BNXT_FLAG_RFS)
vnic = rx + 1;
if (bp->flags & BNXT_FLAG_AGG_RINGS)
rx <<= 1;
if ((bp->flags & BNXT_FLAG_NEW_RM) &&
(hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cp ||
hw_resc->resv_hw_ring_grps != grp || hw_resc->resv_vnics != vnic))
return true;
return false;
}

static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max,
bool shared);

Expand All @@ -4766,7 +4790,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
bool sh = false;
int vnic = 1;

if (bp->hwrm_spec_code < 0x10601)
if (!bnxt_need_reserve_rings(bp))
return 0;

if (bp->flags & BNXT_FLAG_SHARED_RINGS)
Expand All @@ -4775,14 +4799,7 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
vnic = rx + 1;
if (bp->flags & BNXT_FLAG_AGG_RINGS)
rx <<= 1;

grp = bp->rx_nr_rings;
if (tx == hw_resc->resv_tx_rings &&
(!(bp->flags & BNXT_FLAG_NEW_RM) ||
(rx == hw_resc->resv_rx_rings &&
grp == hw_resc->resv_hw_ring_grps &&
cp == hw_resc->resv_cp_rings && vnic == hw_resc->resv_vnics)))
return 0;

rc = bnxt_hwrm_reserve_rings(bp, tx, rx, grp, cp, vnic);
if (rc)
Expand Down Expand Up @@ -4826,30 +4843,6 @@ static int __bnxt_reserve_rings(struct bnxt *bp)
return rc;
}

static bool bnxt_need_reserve_rings(struct bnxt *bp)
{
struct bnxt_hw_resc *hw_resc = &bp->hw_resc;
int rx = bp->rx_nr_rings;
int vnic = 1;

if (bp->hwrm_spec_code < 0x10601)
return false;

if (hw_resc->resv_tx_rings != bp->tx_nr_rings)
return true;

if (bp->flags & BNXT_FLAG_RFS)
vnic = rx + 1;
if (bp->flags & BNXT_FLAG_AGG_RINGS)
rx <<= 1;
if ((bp->flags & BNXT_FLAG_NEW_RM) &&
(hw_resc->resv_rx_rings != rx ||
hw_resc->resv_cp_rings != bp->cp_nr_rings ||
hw_resc->resv_vnics != vnic))
return true;
return false;
}

static int bnxt_hwrm_check_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings,
int ring_grps, int cp_rings, int vnics)
{
Expand Down

0 comments on commit 4e41dc5

Please sign in to comment.