Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2014-2023 Broadcom 3 : : * All rights reserved. 4 : : */ 5 : : 6 : : #ifndef _BNXT_CPR_H_ 7 : : #define _BNXT_CPR_H_ 8 : : #include <stdbool.h> 9 : : 10 : : #include <rte_io.h> 11 : : #include <rte_version.h> 12 : : #include "hsi_struct_def_dpdk.h" 13 : : 14 : : struct bnxt_db_info; 15 : : 16 : : #define CMP_TYPE(cmp) \ 17 : : (((struct cmpl_base *)cmp)->type & CMPL_BASE_TYPE_MASK) 18 : : 19 : : #define CMPL_VALID(cmp, v) \ 20 : : (!!(rte_le_to_cpu_32(((struct cmpl_base *)(cmp))->info3_v) & \ 21 : : CMPL_BASE_V) == !(v)) 22 : : 23 : : /* Get completion length from completion type, in 16-byte units. */ 24 : : #define CMP_LEN(cmp_type) (((cmp_type) & 1) + 1) 25 : : 26 : : 27 : : #define ADV_RAW_CMP(idx, n) ((idx) + (n)) 28 : : #define NEXT_RAW_CMP(idx) ADV_RAW_CMP(idx, 1) 29 : : #define RING_CMP(ring, idx) ((idx) & (ring)->ring_mask) 30 : : #define RING_CMPL(ring_mask, idx) ((idx) & (ring_mask)) 31 : : #define NEXT_CMP(idx) RING_CMP(ADV_RAW_CMP(idx, 1)) 32 : : 33 : : #define DBR_TOGGLE_SFT 25 34 : : #define DB_TOGGLE(tgl) ((tgl) << DBR_TOGGLE_SFT) 35 : : 36 : : #define NQ_CN_TOGGLE_MASK 0xc0UL 37 : : #define NQ_CN_TOGGLE_SFT 6 38 : : #define NQE_CN_TOGGLE(type) (((type) & NQ_CN_TOGGLE_MASK) >> \ 39 : : NQ_CN_TOGGLE_SFT) 40 : : 41 : : #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID) 42 : : #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS) 43 : : 44 : : #define NEXT_CMPL(cpr, idx, v, inc) do { \ 45 : : (idx) += (inc); \ 46 : : if (unlikely((idx) >= (cpr)->cp_ring_struct->ring_size)) { \ 47 : : (v) = !(v); \ 48 : : (idx) = 0; \ 49 : : } \ 50 : : } while (0) 51 : : 52 : : #define B_CP_DB_REARM(cpr, raw_cons) \ 53 : : rte_write32((DB_CP_REARM_FLAGS | \ 54 : : DB_RING_IDX(&((cpr)->cp_db), raw_cons)), \ 55 : : ((cpr)->cp_db.doorbell)) 56 : : 57 : : #define B_CP_DB_ARM(cpr) rte_write32((DB_KEY_CP), \ 58 : : ((cpr)->cp_db.doorbell)) 59 : : 60 : : #define B_CP_DB_DISARM(cpr) (*(uint32_t *)((cpr)->cp_db.doorbell) = \ 61 : : DB_KEY_CP | DB_IRQ_DIS) 62 : : 63 : : #define B_CP_DIS_DB(cpr, raw_cons) \ 64 : : rte_write32_relaxed((DB_CP_FLAGS | \ 65 : : DB_RING_IDX(&((cpr)->cp_db), raw_cons)), \ 66 : : ((cpr)->cp_db.doorbell)) 67 : : 68 : : struct bnxt_db_info { 69 : : void *doorbell; 70 : : union { 71 : : uint64_t db_key64; 72 : : uint32_t db_key32; 73 : : }; 74 : : bool db_64; 75 : : uint32_t db_ring_mask; 76 : : uint32_t db_epoch_mask; 77 : : }; 78 : : 79 : : #define DB_EPOCH(db, idx) (!!((idx) & (db)->db_epoch_mask) << \ 80 : : DBR_EPOCH_SFT) 81 : : #define DB_RING_IDX(db, idx) (((idx) & (db)->db_ring_mask) | \ 82 : : DB_EPOCH(db, idx)) 83 : : 84 : : struct nqe_cn { 85 : : rte_le16_t type; 86 : : #define NQ_CN_TYPE_MASK 0x3fUL 87 : : #define NQ_CN_TYPE_SFT 0 88 : : #define NQ_CN_TYPE_CQ_NOTIFICATION 0x30UL 89 : : #define NQ_CN_TYPE_LAST NQ_CN_TYPE_CQ_NOTIFICATION 90 : : #define NQ_CN_TOGGLE_MASK 0xc0UL 91 : : #define NQ_CN_TOGGLE_SFT 6 92 : : rte_le16_t reserved16; 93 : : rte_le32_t cq_handle_low; 94 : : rte_le32_t v; 95 : : #define NQ_CN_V 0x1UL 96 : : rte_le32_t cq_handle_high; 97 : : }; 98 : : 99 : : struct bnxt_ring; 100 : : struct bnxt_cp_ring_info { 101 : : uint32_t cp_raw_cons; 102 : : 103 : : struct cmpl_base *cp_desc_ring; 104 : : struct bnxt_db_info cp_db; 105 : : rte_iova_t cp_desc_mapping; 106 : : 107 : : char *hw_stats; 108 : : uint16_t hw_ring_stats_size; 109 : : rte_iova_t hw_stats_map; 110 : : uint32_t hw_stats_ctx_id; 111 : : 112 : : struct bnxt_ring *cp_ring_struct; 113 : : bool valid; 114 : : uint32_t epoch; 115 : : uint32_t toggle; 116 : : uint8_t dpi; /* Doorbell page index for multi-doorbell support */ 117 : : 118 : : }; 119 : : 120 : : #define RX_CMP_L2_ERRORS \ 121 : : (RX_PKT_CMPL_ERRORS_BUFFER_ERROR_MASK | RX_PKT_CMPL_ERRORS_CRC_ERROR) 122 : : 123 : : struct bnxt; 124 : : void bnxt_handle_async_event(struct bnxt *bp, struct cmpl_base *cmp); 125 : : void bnxt_handle_fwd_req(struct bnxt *bp, struct cmpl_base *cmp); 126 : : int bnxt_event_hwrm_resp_handler(struct bnxt *bp, struct cmpl_base *cmp); 127 : : void bnxt_dev_reset_and_resume(void *arg); 128 : : void bnxt_wait_for_device_shutdown(struct bnxt *bp); 129 : : void bnxt_arm_nq_p5p(struct bnxt_cp_ring_info *nqr, bool enable_irq); 130 : : void bnxt_arm_rx_cq_p5p(struct bnxt_cp_ring_info *cpr, bool enable_irq); 131 : : void bnxt_process_async_msg(struct bnxt *bp, struct tx_cmpl *cmpl); 132 : : void bnxt_process_nq(struct bnxt *bp, struct bnxt_cp_ring_info *nqr, 133 : : struct bnxt_cp_ring_info *rx_cpr); 134 : : 135 : : #define EVENT_DATA1_REASON_CODE_FW_EXCEPTION_FATAL \ 136 : : HWRM_ASYNC_EVENT_CMPL_RESET_NOTIFY_EVENT_DATA1_REASON_CODE_FW_EXCEPTION_FATAL 137 : : #define EVENT_DATA1_REASON_CODE_MASK \ 138 : : HWRM_ASYNC_EVENT_CMPL_RESET_NOTIFY_EVENT_DATA1_REASON_CODE_MASK 139 : : 140 : : #define EVENT_DATA1_FLAGS_MASK \ 141 : : HWRM_ASYNC_EVENT_CMPL_ERROR_RECOVERY_EVENT_DATA1_FLAGS_MASK 142 : : 143 : : #define EVENT_DATA1_FLAGS_MASTER_FUNC \ 144 : : HWRM_ASYNC_EVENT_CMPL_ERROR_RECOVERY_EVENT_DATA1_FLAGS_MASTER_FUNC 145 : : 146 : : #define EVENT_DATA1_FLAGS_RECOVERY_ENABLED \ 147 : : HWRM_ASYNC_EVENT_CMPL_ERROR_RECOVERY_EVENT_DATA1_FLAGS_RECOVERY_ENABLED 148 : : 149 : : bool bnxt_is_recovery_enabled(struct bnxt *bp); 150 : : bool bnxt_is_primary_func(struct bnxt *bp); 151 : : 152 : : void bnxt_stop_rxtx(struct rte_eth_dev *eth_dev); 153 : : void bnxt_start_rxtx(struct rte_eth_dev *eth_dev); 154 : : 155 : : /** 156 : : * Check validity of a completion ring entry. If the entry is valid, include a 157 : : * C11 __ATOMIC_ACQUIRE fence to ensure that subsequent loads of fields in the 158 : : * completion are not hoisted by the compiler or by the CPU to come before the 159 : : * loading of the "valid" field. 160 : : * 161 : : * Note: the caller must not access any fields in the specified completion 162 : : * entry prior to calling this function. 163 : : * 164 : : * @param cmpl 165 : : * Pointer to an entry in the completion ring. 166 : : * @param raw_cons 167 : : * Raw consumer index of entry in completion ring. 168 : : * @param ring_size 169 : : * Size of completion ring. 170 : : */ 171 : : static __rte_always_inline bool 172 : : bnxt_cpr_cmp_valid(const void *cmpl, uint32_t raw_cons, uint32_t ring_size) 173 : : { 174 : : const struct cmpl_base *c = (const struct cmpl_base *)cmpl; 175 : : bool expected, valid; 176 : : 177 : 0 : expected = !(raw_cons & ring_size); 178 : 0 : valid = !!(rte_le_to_cpu_32(c->info3_v) & CMPL_BASE_V); 179 [ # # # # : 0 : if (valid == expected) { # # # # ] 180 : : rte_atomic_thread_fence(rte_memory_order_acquire); 181 : 0 : return true; 182 : : } 183 : : return false; 184 : : } 185 : : 186 : : #endif