1fd710bb1SScott Branden /* SPDX-License-Identifier: BSD-3-Clause 2e6e8f03eSRandy Schacher * Copyright(c) 2014-2023 Broadcom 38e7405f7SAjit Khaparde * All rights reserved. 48e7405f7SAjit Khaparde */ 58e7405f7SAjit Khaparde 68e7405f7SAjit Khaparde #ifndef _BNXT_RING_H_ 78e7405f7SAjit Khaparde #define _BNXT_RING_H_ 88e7405f7SAjit Khaparde 98e7405f7SAjit Khaparde #include <inttypes.h> 108e7405f7SAjit Khaparde 118e7405f7SAjit Khaparde #include <rte_memory.h> 128e7405f7SAjit Khaparde 13c7de4195SAjit Khaparde #define RING_ADV(idx, n) ((idx) + (n)) 14c7de4195SAjit Khaparde #define RING_NEXT(idx) RING_ADV(idx, 1) 15c7de4195SAjit Khaparde #define RING_IDX(ring, idx) ((idx) & (ring)->ring_mask) 168e7405f7SAjit Khaparde 178e7405f7SAjit Khaparde #define DB_IDX_MASK 0xffffff 188e7405f7SAjit Khaparde #define DB_IDX_VALID (0x1 << 26) 198e7405f7SAjit Khaparde #define DB_IRQ_DIS (0x1 << 27) 208e7405f7SAjit Khaparde #define DB_KEY_TX (0x0 << 28) 218e7405f7SAjit Khaparde #define DB_KEY_RX (0x1 << 28) 228e7405f7SAjit Khaparde #define DB_KEY_CP (0x2 << 28) 238e7405f7SAjit Khaparde #define DB_KEY_ST (0x3 << 28) 248e7405f7SAjit Khaparde #define DB_KEY_TX_PUSH (0x4 << 28) 258e7405f7SAjit Khaparde #define DB_LONG_TX_PUSH (0x2 << 24) 268e7405f7SAjit Khaparde 274af53269SAjit Khaparde #define DEFAULT_CP_RING_SIZE 4096 288e7405f7SAjit Khaparde #define DEFAULT_RX_RING_SIZE 256 298e7405f7SAjit Khaparde #define DEFAULT_TX_RING_SIZE 256 308e7405f7SAjit Khaparde 3145c6e1c6SAjit Khaparde #define AGG_RING_SIZE_FACTOR 4 32edafb57bSAjit Khaparde #define AGG_RING_MULTIPLIER 2 338e7405f7SAjit Khaparde 348e7405f7SAjit Khaparde /* These assume 4k pages */ 358e7405f7SAjit Khaparde #define MAX_RX_DESC_CNT (8 * 1024) 368e7405f7SAjit Khaparde #define MAX_TX_DESC_CNT (4 * 1024) 378e7405f7SAjit Khaparde #define MAX_CP_DESC_CNT (16 * 1024) 388e7405f7SAjit Khaparde 398e7405f7SAjit Khaparde #define INVALID_HW_RING_ID ((uint16_t)-1) 40daef48efSAjit Khaparde #define INVALID_STATS_CTX_ID ((uint16_t)-1) 41*80317ff6SFarah Smith #define MPC_HW_COS_ID ((uint16_t)-2) 428e7405f7SAjit Khaparde 438e7405f7SAjit Khaparde struct bnxt_ring { 448e7405f7SAjit Khaparde void *bd; 45df6e0a06SSantosh Shukla rte_iova_t bd_dma; 468e7405f7SAjit Khaparde uint32_t ring_size; 478e7405f7SAjit Khaparde uint32_t ring_mask; 488e7405f7SAjit Khaparde 498e7405f7SAjit Khaparde int vmem_size; 508e7405f7SAjit Khaparde void **vmem; 518e7405f7SAjit Khaparde 528e7405f7SAjit Khaparde uint16_t fw_ring_id; /* Ring id filled by Chimp FW */ 53f8168ca0SLance Richardson uint16_t fw_rx_ring_id; 542bb1d5dbSAjit Khaparde const void *mem_zone; 558e7405f7SAjit Khaparde }; 568e7405f7SAjit Khaparde 578e7405f7SAjit Khaparde struct bnxt_ring_grp_info { 588e7405f7SAjit Khaparde uint16_t fw_stats_ctx; 598e7405f7SAjit Khaparde uint16_t fw_grp_id; 608e7405f7SAjit Khaparde uint16_t rx_fw_ring_id; 618e7405f7SAjit Khaparde uint16_t cp_fw_ring_id; 628e7405f7SAjit Khaparde uint16_t ag_fw_ring_id; 638e7405f7SAjit Khaparde }; 648e7405f7SAjit Khaparde 658e7405f7SAjit Khaparde struct bnxt; 666eb3cc22SAjit Khaparde struct bnxt_tx_ring_info; 676eb3cc22SAjit Khaparde struct bnxt_rx_ring_info; 686eb3cc22SAjit Khaparde struct bnxt_cp_ring_info; 698e7405f7SAjit Khaparde void bnxt_free_ring(struct bnxt_ring *ring); 701bf01f51SKalesh AP int bnxt_alloc_ring_grps(struct bnxt *bp); 71c6c90a33SLance Richardson int bnxt_alloc_rings(struct bnxt *bp, unsigned int socket_id, uint16_t qidx, 7223460b4cSAjit Khaparde struct bnxt_tx_queue *txq, 7323460b4cSAjit Khaparde struct bnxt_rx_queue *rxq, 746eb3cc22SAjit Khaparde struct bnxt_cp_ring_info *cp_ring_info, 75f8168ca0SLance Richardson struct bnxt_cp_ring_info *nq_ring_info, 766eb3cc22SAjit Khaparde const char *suffix); 7714255b35SAjit Khaparde int bnxt_alloc_hwrm_rx_ring(struct bnxt *bp, int queue_index); 784ace85a7SAjit Khaparde int bnxt_alloc_hwrm_rings(struct bnxt *bp); 79bd0a14c9SLance Richardson int bnxt_alloc_async_cp_ring(struct bnxt *bp); 80bd0a14c9SLance Richardson void bnxt_free_async_cp_ring(struct bnxt *bp); 81bd0a14c9SLance Richardson int bnxt_alloc_async_ring_struct(struct bnxt *bp); 82683e5cf7SLance Richardson int bnxt_alloc_rxtx_nq_ring(struct bnxt *bp); 83683e5cf7SLance Richardson void bnxt_free_rxtx_nq_ring(struct bnxt *bp); 84*80317ff6SFarah Smith void bnxt_init_dflt_coal(struct bnxt_coal *coal); 85*80317ff6SFarah Smith int bnxt_alloc_cmpl_ring(struct bnxt *bp, int queue_index, 86*80317ff6SFarah Smith struct bnxt_cp_ring_info *cpr); 87*80317ff6SFarah Smith void bnxt_set_db(struct bnxt *bp, 88*80317ff6SFarah Smith struct bnxt_db_info *db, 89*80317ff6SFarah Smith uint32_t ring_type, 90*80317ff6SFarah Smith uint32_t map_idx, 91*80317ff6SFarah Smith uint32_t fid, 92*80317ff6SFarah Smith uint32_t ring_mask); 938e7405f7SAjit Khaparde 94bb0546edSLance Richardson static inline void bnxt_db_write(struct bnxt_db_info *db, uint32_t idx) 95bb0546edSLance Richardson { 96c7de4195SAjit Khaparde uint32_t db_idx = DB_RING_IDX(db, idx); 97c7de4195SAjit Khaparde void *doorbell = db->doorbell; 98c7de4195SAjit Khaparde 99c7de4195SAjit Khaparde if (db->db_64) { 100c7de4195SAjit Khaparde uint64_t key_idx = db->db_key64 | db_idx; 101c7de4195SAjit Khaparde 10232767b9dSAjit Khaparde rte_compiler_barrier(); 10332767b9dSAjit Khaparde rte_write64_relaxed(key_idx, doorbell); 104c7de4195SAjit Khaparde } else { 105c7de4195SAjit Khaparde uint32_t key_idx = db->db_key32 | db_idx; 106c7de4195SAjit Khaparde 107c7de4195SAjit Khaparde rte_write32(key_idx, doorbell); 108c7de4195SAjit Khaparde } 109bb0546edSLance Richardson } 110bb0546edSLance Richardson 111*80317ff6SFarah Smith static inline void bnxt_db_mpc_write(struct bnxt_db_info *db, uint32_t idx, uint32_t epoch) 112*80317ff6SFarah Smith { 113*80317ff6SFarah Smith uint32_t db_idx = DB_RING_IDX(db, idx); 114*80317ff6SFarah Smith void *doorbell = db->doorbell; 115*80317ff6SFarah Smith 116*80317ff6SFarah Smith if (likely(db->db_64)) { 117*80317ff6SFarah Smith uint64_t key_idx = db->db_key64 | db_idx | 118*80317ff6SFarah Smith (epoch << 24); 119*80317ff6SFarah Smith rte_write64_relaxed(key_idx, doorbell); 120*80317ff6SFarah Smith } else { 121*80317ff6SFarah Smith uint32_t key_idx = db->db_key32 | db_idx; 122*80317ff6SFarah Smith 123*80317ff6SFarah Smith rte_write32_relaxed(key_idx, doorbell); 124*80317ff6SFarah Smith } 125*80317ff6SFarah Smith } 126*80317ff6SFarah Smith 1274af9d0c7SLance Richardson /* Ring an NQ doorbell and disable interrupts for the ring. */ 128f8168ca0SLance Richardson static inline void bnxt_db_nq(struct bnxt_cp_ring_info *cpr) 129f8168ca0SLance Richardson { 130c7de4195SAjit Khaparde uint32_t db_idx = DB_RING_IDX(&cpr->cp_db, cpr->cp_raw_cons); 131c7de4195SAjit Khaparde uint64_t key_idx = cpr->cp_db.db_key64 | DBR_TYPE_NQ | db_idx; 132c7de4195SAjit Khaparde void *doorbell = cpr->cp_db.doorbell; 133c7de4195SAjit Khaparde 134c7de4195SAjit Khaparde 1354af9d0c7SLance Richardson if (unlikely(!cpr->cp_db.db_64)) 1364af9d0c7SLance Richardson return; 137f8168ca0SLance Richardson 138c7de4195SAjit Khaparde rte_write64(key_idx, doorbell); 1394af9d0c7SLance Richardson } 1404af9d0c7SLance Richardson 1414af9d0c7SLance Richardson /* Ring an NQ doorbell and enable interrupts for the ring. */ 1424af9d0c7SLance Richardson static inline void bnxt_db_nq_arm(struct bnxt_cp_ring_info *cpr) 1434af9d0c7SLance Richardson { 144c7de4195SAjit Khaparde uint32_t db_idx = DB_RING_IDX(&cpr->cp_db, cpr->cp_raw_cons); 145c7de4195SAjit Khaparde uint64_t key_idx = cpr->cp_db.db_key64 | DBR_TYPE_NQ_ARM | db_idx; 146c7de4195SAjit Khaparde void *doorbell = cpr->cp_db.doorbell; 147c7de4195SAjit Khaparde 1484af9d0c7SLance Richardson if (unlikely(!cpr->cp_db.db_64)) 1494af9d0c7SLance Richardson return; 1504af9d0c7SLance Richardson 151c7de4195SAjit Khaparde rte_write64(key_idx, doorbell); 152f8168ca0SLance Richardson } 153f8168ca0SLance Richardson 154bb0546edSLance Richardson static inline void bnxt_db_cq(struct bnxt_cp_ring_info *cpr) 155bb0546edSLance Richardson { 156f8168ca0SLance Richardson struct bnxt_db_info *db = &cpr->cp_db; 157c7de4195SAjit Khaparde uint32_t idx = DB_RING_IDX(&cpr->cp_db, cpr->cp_raw_cons); 158f8168ca0SLance Richardson 159d1816ceaSLance Richardson if (db->db_64) { 160d1816ceaSLance Richardson uint64_t key_idx = db->db_key64 | idx; 161d1816ceaSLance Richardson void *doorbell = db->doorbell; 162d1816ceaSLance Richardson 163bfc1d458SRahul Gupta rte_compiler_barrier(); 164d1816ceaSLance Richardson rte_write64_relaxed(key_idx, doorbell); 165d1816ceaSLance Richardson } else { 166d1816ceaSLance Richardson uint32_t cp_raw_cons = cpr->cp_raw_cons; 167d1816ceaSLance Richardson 168d1816ceaSLance Richardson rte_compiler_barrier(); 169d1816ceaSLance Richardson B_CP_DIS_DB(cpr, cp_raw_cons); 170d1816ceaSLance Richardson } 171bb0546edSLance Richardson } 172*80317ff6SFarah Smith 173*80317ff6SFarah Smith static inline void bnxt_db_mpc_cq(struct bnxt_cp_ring_info *cpr) 174*80317ff6SFarah Smith { 175*80317ff6SFarah Smith struct bnxt_db_info *db = &cpr->cp_db; 176*80317ff6SFarah Smith uint32_t idx = DB_RING_IDX(&cpr->cp_db, cpr->cp_raw_cons); 177*80317ff6SFarah Smith 178*80317ff6SFarah Smith if (likely(db->db_64)) { 179*80317ff6SFarah Smith uint64_t key_idx = db->db_key64 | idx | 180*80317ff6SFarah Smith (cpr->epoch << 24); 181*80317ff6SFarah Smith void *doorbell = db->doorbell; 182*80317ff6SFarah Smith 183*80317ff6SFarah Smith rte_compiler_barrier(); 184*80317ff6SFarah Smith rte_write64_relaxed(key_idx, doorbell); 185*80317ff6SFarah Smith } else { 186*80317ff6SFarah Smith uint32_t cp_raw_cons = cpr->cp_raw_cons; 187*80317ff6SFarah Smith 188*80317ff6SFarah Smith rte_compiler_barrier(); 189*80317ff6SFarah Smith B_CP_DIS_DB(cpr, cp_raw_cons); 190*80317ff6SFarah Smith } 191*80317ff6SFarah Smith } 192*80317ff6SFarah Smith 1938e7405f7SAjit Khaparde #endif 194