Skip to content

Commit

Permalink
bnxt_en: Add db_ring_mask and related macro to bnxt_db_info struct.
Browse files Browse the repository at this point in the history
This allows the doorbell related logic to mask the doorbell index
to the proper range before writing the doorbell.

The current code masks the doorbell index immediately to keep it in the
legal ranges for the most part.  Subsequent patches will change the
logic so that the index increments unbounded and it only gets masked
before use.  This is preparation work for the new chip that requires an
additional Epoch bit in the doorbell that needs to toggle when the index
has wrapped around.

This patch just adds the basic infrastructure and the logic is largely
unchanged.  We now replace RING_CMP() with the new DB_RING_IDX() at
appropriate places where we mask the completion ring index before
writing the doorbell.

Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Link: https://lore.kernel.org/r/20231120234405.194542-10-michael.chan@broadcom.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Michael Chan authored and Jakub Kicinski committed Nov 22, 2023
1 parent 236e237 commit b9e0c47
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
39 changes: 31 additions & 8 deletions drivers/net/ethernet/broadcom/bnxt/bnxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,18 @@ static bool bnxt_vf_pciid(enum board_idx idx)
writel(DB_CP_IRQ_DIS_FLAGS, db)

#define BNXT_DB_CQ(db, idx) \
writel(DB_CP_FLAGS | RING_CMP(idx), (db)->doorbell)
writel(DB_CP_FLAGS | DB_RING_IDX(db, idx), (db)->doorbell)

#define BNXT_DB_NQ_P5(db, idx) \
bnxt_writeq(bp, (db)->db_key64 | DBR_TYPE_NQ | RING_CMP(idx), \
bnxt_writeq(bp, (db)->db_key64 | DBR_TYPE_NQ | DB_RING_IDX(db, idx),\
(db)->doorbell)

#define BNXT_DB_CQ_ARM(db, idx) \
writel(DB_CP_REARM_FLAGS | RING_CMP(idx), (db)->doorbell)
writel(DB_CP_REARM_FLAGS | DB_RING_IDX(db, idx), (db)->doorbell)

#define BNXT_DB_NQ_ARM_P5(db, idx) \
bnxt_writeq(bp, (db)->db_key64 | DBR_TYPE_NQ_ARM | RING_CMP(idx),\
(db)->doorbell)
bnxt_writeq(bp, (db)->db_key64 | DBR_TYPE_NQ_ARM | \
DB_RING_IDX(db, idx), (db)->doorbell)

static void bnxt_db_nq(struct bnxt *bp, struct bnxt_db_info *db, u32 idx)
{
Expand All @@ -287,7 +287,7 @@ static void bnxt_db_cq(struct bnxt *bp, struct bnxt_db_info *db, u32 idx)
{
if (bp->flags & BNXT_FLAG_CHIP_P5)
bnxt_writeq(bp, db->db_key64 | DBR_TYPE_CQ_ARMALL |
RING_CMP(idx), db->doorbell);
DB_RING_IDX(db, idx), db->doorbell);
else
BNXT_DB_CQ(db, idx);
}
Expand Down Expand Up @@ -526,7 +526,8 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
memcpy(txbd, tx_push1, sizeof(*txbd));
prod = NEXT_TX(prod);
tx_push->doorbell =
cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod);
cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH |
DB_RING_IDX(&txr->tx_db, prod));
WRITE_ONCE(txr->tx_prod, prod);

tx_buf->is_push = 1;
Expand Down Expand Up @@ -2871,7 +2872,8 @@ static void __bnxt_poll_cqs_done(struct bnxt *bp, struct bnxt_napi *bnapi,
if (cpr2->had_work_done) {
db = &cpr2->cp_db;
bnxt_writeq(bp, db->db_key64 | dbr_type |
RING_CMP(cpr2->cp_raw_cons), db->doorbell);
DB_RING_IDX(db, cpr2->cp_raw_cons),
db->doorbell);
cpr2->had_work_done = 0;
}
}
Expand Down Expand Up @@ -5987,6 +5989,26 @@ static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx)
}
}

static void bnxt_set_db_mask(struct bnxt *bp, struct bnxt_db_info *db,
u32 ring_type)
{
switch (ring_type) {
case HWRM_RING_ALLOC_TX:
db->db_ring_mask = bp->tx_ring_mask;
break;
case HWRM_RING_ALLOC_RX:
db->db_ring_mask = bp->rx_ring_mask;
break;
case HWRM_RING_ALLOC_AGG:
db->db_ring_mask = bp->rx_agg_ring_mask;
break;
case HWRM_RING_ALLOC_CMPL:
case HWRM_RING_ALLOC_NQ:
db->db_ring_mask = bp->cp_ring_mask;
break;
}
}

static void bnxt_set_db(struct bnxt *bp, struct bnxt_db_info *db, u32 ring_type,
u32 map_idx, u32 xid)
{
Expand Down Expand Up @@ -6026,6 +6048,7 @@ static void bnxt_set_db(struct bnxt *bp, struct bnxt_db_info *db, u32 ring_type,
break;
}
}
bnxt_set_db_mask(bp, db, ring_type);
}

static int bnxt_hwrm_ring_alloc(struct bnxt *bp)
Expand Down
13 changes: 9 additions & 4 deletions drivers/net/ethernet/broadcom/bnxt/bnxt.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,11 @@ struct bnxt_db_info {
u64 db_key64;
u32 db_key32;
};
u32 db_ring_mask;
};

#define DB_RING_IDX(db, idx) ((idx) & (db)->db_ring_mask)

struct bnxt_tx_ring_info {
struct bnxt_napi *bnapi;
struct bnxt_cp_ring_info *tx_cpr;
Expand Down Expand Up @@ -2353,9 +2356,10 @@ static inline void bnxt_db_write_relaxed(struct bnxt *bp,
struct bnxt_db_info *db, u32 idx)
{
if (bp->flags & BNXT_FLAG_CHIP_P5) {
bnxt_writeq_relaxed(bp, db->db_key64 | idx, db->doorbell);
bnxt_writeq_relaxed(bp, db->db_key64 | DB_RING_IDX(db, idx),
db->doorbell);
} else {
u32 db_val = db->db_key32 | idx;
u32 db_val = db->db_key32 | DB_RING_IDX(db, idx);

writel_relaxed(db_val, db->doorbell);
if (bp->flags & BNXT_FLAG_DOUBLE_DB)
Expand All @@ -2368,9 +2372,10 @@ static inline void bnxt_db_write(struct bnxt *bp, struct bnxt_db_info *db,
u32 idx)
{
if (bp->flags & BNXT_FLAG_CHIP_P5) {
bnxt_writeq(bp, db->db_key64 | idx, db->doorbell);
bnxt_writeq(bp, db->db_key64 | DB_RING_IDX(db, idx),
db->doorbell);
} else {
u32 db_val = db->db_key32 | idx;
u32 db_val = db->db_key32 | DB_RING_IDX(db, idx);

writel(db_val, db->doorbell);
if (bp->flags & BNXT_FLAG_DOUBLE_DB)
Expand Down

0 comments on commit b9e0c47

Please sign in to comment.