]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
bnxt_en: Add db_ring_mask and related macro to bnxt_db_info struct.
authorMichael Chan <michael.chan@broadcom.com>
Mon, 20 Nov 2023 23:44:01 +0000 (15:44 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 22 Nov 2023 01:32:48 +0000 (17:32 -0800)
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>
drivers/net/ethernet/broadcom/bnxt/bnxt.c
drivers/net/ethernet/broadcom/bnxt/bnxt.h

index 85d1fdb616cac5591053fa02b339b19856f28922..48c443d52344618e5e7bc8ee7cf065653c4f6733 100644 (file)
@@ -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)
 {
@@ -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);
 }
@@ -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;
@@ -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;
                }
        }
@@ -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)
 {
@@ -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)
index a591f950ce14141dfb78a14bd3c32c7622f41c34..7d79a2c8d3c364c52f542ed02e36dff22a0652fd 100644 (file)
@@ -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;
@@ -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)
@@ -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)