Skip to content

Commit b9e0c47

Browse files
Michael Chankuba-moo
authored andcommitted
bnxt_en: Add db_ring_mask and related macro to bnxt_db_info struct.
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 <[email protected]> Signed-off-by: Michael Chan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 236e237 commit b9e0c47

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

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

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,18 @@ static bool bnxt_vf_pciid(enum board_idx idx)
254254
writel(DB_CP_IRQ_DIS_FLAGS, db)
255255

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

259259
#define BNXT_DB_NQ_P5(db, idx) \
260-
bnxt_writeq(bp, (db)->db_key64 | DBR_TYPE_NQ | RING_CMP(idx), \
260+
bnxt_writeq(bp, (db)->db_key64 | DBR_TYPE_NQ | DB_RING_IDX(db, idx),\
261261
(db)->doorbell)
262262

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

266266
#define BNXT_DB_NQ_ARM_P5(db, idx) \
267-
bnxt_writeq(bp, (db)->db_key64 | DBR_TYPE_NQ_ARM | RING_CMP(idx),\
268-
(db)->doorbell)
267+
bnxt_writeq(bp, (db)->db_key64 | DBR_TYPE_NQ_ARM | \
268+
DB_RING_IDX(db, idx), (db)->doorbell)
269269

270270
static void bnxt_db_nq(struct bnxt *bp, struct bnxt_db_info *db, u32 idx)
271271
{
@@ -287,7 +287,7 @@ static void bnxt_db_cq(struct bnxt *bp, struct bnxt_db_info *db, u32 idx)
287287
{
288288
if (bp->flags & BNXT_FLAG_CHIP_P5)
289289
bnxt_writeq(bp, db->db_key64 | DBR_TYPE_CQ_ARMALL |
290-
RING_CMP(idx), db->doorbell);
290+
DB_RING_IDX(db, idx), db->doorbell);
291291
else
292292
BNXT_DB_CQ(db, idx);
293293
}
@@ -526,7 +526,8 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
526526
memcpy(txbd, tx_push1, sizeof(*txbd));
527527
prod = NEXT_TX(prod);
528528
tx_push->doorbell =
529-
cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod);
529+
cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH |
530+
DB_RING_IDX(&txr->tx_db, prod));
530531
WRITE_ONCE(txr->tx_prod, prod);
531532

532533
tx_buf->is_push = 1;
@@ -2871,7 +2872,8 @@ static void __bnxt_poll_cqs_done(struct bnxt *bp, struct bnxt_napi *bnapi,
28712872
if (cpr2->had_work_done) {
28722873
db = &cpr2->cp_db;
28732874
bnxt_writeq(bp, db->db_key64 | dbr_type |
2874-
RING_CMP(cpr2->cp_raw_cons), db->doorbell);
2875+
DB_RING_IDX(db, cpr2->cp_raw_cons),
2876+
db->doorbell);
28752877
cpr2->had_work_done = 0;
28762878
}
28772879
}
@@ -5987,6 +5989,26 @@ static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx)
59875989
}
59885990
}
59895991

5992+
static void bnxt_set_db_mask(struct bnxt *bp, struct bnxt_db_info *db,
5993+
u32 ring_type)
5994+
{
5995+
switch (ring_type) {
5996+
case HWRM_RING_ALLOC_TX:
5997+
db->db_ring_mask = bp->tx_ring_mask;
5998+
break;
5999+
case HWRM_RING_ALLOC_RX:
6000+
db->db_ring_mask = bp->rx_ring_mask;
6001+
break;
6002+
case HWRM_RING_ALLOC_AGG:
6003+
db->db_ring_mask = bp->rx_agg_ring_mask;
6004+
break;
6005+
case HWRM_RING_ALLOC_CMPL:
6006+
case HWRM_RING_ALLOC_NQ:
6007+
db->db_ring_mask = bp->cp_ring_mask;
6008+
break;
6009+
}
6010+
}
6011+
59906012
static void bnxt_set_db(struct bnxt *bp, struct bnxt_db_info *db, u32 ring_type,
59916013
u32 map_idx, u32 xid)
59926014
{
@@ -6026,6 +6048,7 @@ static void bnxt_set_db(struct bnxt *bp, struct bnxt_db_info *db, u32 ring_type,
60266048
break;
60276049
}
60286050
}
6051+
bnxt_set_db_mask(bp, db, ring_type);
60296052
}
60306053

60316054
static int bnxt_hwrm_ring_alloc(struct bnxt *bp)

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,11 @@ struct bnxt_db_info {
813813
u64 db_key64;
814814
u32 db_key32;
815815
};
816+
u32 db_ring_mask;
816817
};
817818

819+
#define DB_RING_IDX(db, idx) ((idx) & (db)->db_ring_mask)
820+
818821
struct bnxt_tx_ring_info {
819822
struct bnxt_napi *bnapi;
820823
struct bnxt_cp_ring_info *tx_cpr;
@@ -2353,9 +2356,10 @@ static inline void bnxt_db_write_relaxed(struct bnxt *bp,
23532356
struct bnxt_db_info *db, u32 idx)
23542357
{
23552358
if (bp->flags & BNXT_FLAG_CHIP_P5) {
2356-
bnxt_writeq_relaxed(bp, db->db_key64 | idx, db->doorbell);
2359+
bnxt_writeq_relaxed(bp, db->db_key64 | DB_RING_IDX(db, idx),
2360+
db->doorbell);
23572361
} else {
2358-
u32 db_val = db->db_key32 | idx;
2362+
u32 db_val = db->db_key32 | DB_RING_IDX(db, idx);
23592363

23602364
writel_relaxed(db_val, db->doorbell);
23612365
if (bp->flags & BNXT_FLAG_DOUBLE_DB)
@@ -2368,9 +2372,10 @@ static inline void bnxt_db_write(struct bnxt *bp, struct bnxt_db_info *db,
23682372
u32 idx)
23692373
{
23702374
if (bp->flags & BNXT_FLAG_CHIP_P5) {
2371-
bnxt_writeq(bp, db->db_key64 | idx, db->doorbell);
2375+
bnxt_writeq(bp, db->db_key64 | DB_RING_IDX(db, idx),
2376+
db->doorbell);
23722377
} else {
2373-
u32 db_val = db->db_key32 | idx;
2378+
u32 db_val = db->db_key32 | DB_RING_IDX(db, idx);
23742379

23752380
writel(db_val, db->doorbell);
23762381
if (bp->flags & BNXT_FLAG_DOUBLE_DB)

0 commit comments

Comments
 (0)