Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2025 Huawei Technologies Co., Ltd 3 : : */ 4 : : 5 : : #ifndef _HINIC3_NIC_IO_H_ 6 : : #define _HINIC3_NIC_IO_H_ 7 : : 8 : : #include "hinic3_ethdev.h" 9 : : 10 : : #define HINIC3_SQ_WQEBB_SHIFT 4 11 : : #define HINIC3_RQ_WQEBB_SHIFT 3 12 : : 13 : : #define HINIC3_SQ_WQEBB_SIZE RTE_BIT32(HINIC3_SQ_WQEBB_SHIFT) 14 : : #define HINIC3_CQE_SIZE_SHIFT 4 15 : : 16 : : /* Ci addr should RTE_CACHE_SIZE(64B) alignment for performance. */ 17 : : #define HINIC3_CI_Q_ADDR_SIZE 64 18 : : 19 : : #define CI_TABLE_SIZE(num_qps, pg_sz) \ 20 : : (RTE_ALIGN((num_qps) * HINIC3_CI_Q_ADDR_SIZE, pg_sz)) 21 : : 22 : : #define HINIC3_CI_VADDR(base_addr, q_id) \ 23 : : ((volatile uint8_t *)(base_addr) + (q_id) * HINIC3_CI_Q_ADDR_SIZE) 24 : : 25 : : #define HINIC3_CI_PADDR(base_paddr, q_id) \ 26 : : ((base_paddr) + (q_id) * HINIC3_CI_Q_ADDR_SIZE) 27 : : 28 : : enum hinic3_rq_wqe_type { 29 : : HINIC3_COMPACT_RQ_WQE, 30 : : HINIC3_NORMAL_RQ_WQE, 31 : : HINIC3_EXTEND_RQ_WQE 32 : : }; 33 : : 34 : : enum hinic3_queue_type { 35 : : HINIC3_SQ, 36 : : HINIC3_RQ, 37 : : HINIC3_MAX_QUEUE_TYPE, 38 : : }; 39 : : 40 : : /* Doorbell info. */ 41 : : struct hinic3_db { 42 : : uint32_t db_info; 43 : : uint32_t pi_hi; 44 : : }; 45 : : 46 : : #define DB_INFO_QID_SHIFT 0 47 : : #define DB_INFO_NON_FILTER_SHIFT 22 48 : : #define DB_INFO_CFLAG_SHIFT 23 49 : : #define DB_INFO_COS_SHIFT 24 50 : : #define DB_INFO_TYPE_SHIFT 27 51 : : 52 : : #define DB_INFO_QID_MASK 0x1FFFU 53 : : #define DB_INFO_NON_FILTER_MASK 0x1U 54 : : #define DB_INFO_CFLAG_MASK 0x1U 55 : : #define DB_INFO_COS_MASK 0x7U 56 : : #define DB_INFO_TYPE_MASK 0x1FU 57 : : #define DB_INFO_SET(val, member) \ 58 : : (((uint32_t)(val) & DB_INFO_##member##_MASK) << DB_INFO_##member##_SHIFT) 59 : : 60 : : #define DB_PI_LOW_MASK 0xFFU 61 : : #define DB_PI_HIGH_MASK 0xFFU 62 : : #define DB_PI_LOW(pi) ((pi) & DB_PI_LOW_MASK) 63 : : #define DB_PI_HI_SHIFT 8 64 : : #define DB_PI_HIGH(pi) (((pi) >> DB_PI_HI_SHIFT) & DB_PI_HIGH_MASK) 65 : : #define DB_INFO_UPPER_32(val) (((uint64_t)(val)) << 32) 66 : : 67 : : #define DB_ADDR(db_addr, pi) ((uint64_t *)(db_addr) + DB_PI_LOW(pi)) 68 : : #define SRC_TYPE 1 69 : : 70 : : /* Cflag data path. */ 71 : : #define SQ_CFLAG_DP 0 72 : : #define RQ_CFLAG_DP 1 73 : : 74 : : #define MASKED_QUEUE_IDX(queue, idx) ((idx) & (queue)->q_mask) 75 : : 76 : : #define NIC_WQE_ADDR(queue, idx) \ 77 : : ({ \ 78 : : typeof(queue) __queue = (queue); \ 79 : : (void *)((uint64_t)(__queue->queue_buf_vaddr) + \ 80 : : ((idx) << __queue->wqebb_shift)); \ 81 : : }) 82 : : 83 : : /** 84 : : * Write send queue doorbell. 85 : : * 86 : : * @param[in] db_addr 87 : : * Doorbell address. 88 : : * @param[in] q_id 89 : : * Send queue id. 90 : : * @param[in] cos 91 : : * Send queue cos. 92 : : * @param[in] cflag 93 : : * Cflag data path. 94 : : * @param[in] pi 95 : : * Send queue pi. 96 : : */ 97 : : static inline void 98 : 0 : hinic3_write_db(void *db_addr, uint16_t q_id, int cos, uint8_t cflag, uint16_t pi) 99 : : { 100 : 0 : uint64_t db = DB_PI_HIGH(pi); 101 : : 102 : 0 : db = DB_INFO_UPPER_32(db) | DB_INFO_SET(SRC_TYPE, TYPE) | 103 : 0 : DB_INFO_SET(cflag, CFLAG) | DB_INFO_SET(cos, COS) | 104 : 0 : DB_INFO_SET(q_id, QID); 105 : : 106 : : rte_atomic_thread_fence(rte_memory_order_release); /**< Write all before the doorbell. */ 107 : : /* Hardware will do endianness converting. */ 108 : 0 : rte_write64(db, DB_ADDR(db_addr, pi)); 109 : 0 : } 110 : : 111 : : /** 112 : : * Get minimum RX buffer size for device. 113 : : * 114 : : * @param[in] nic_dev 115 : : * Pointer to ethernet device structure. 116 : : */ 117 : : void hinic3_get_func_rx_buf_size(struct hinic3_nic_dev *nic_dev); 118 : : 119 : : /** 120 : : * Initialize qps contexts, set SQ ci attributes, arm all SQ. 121 : : * 122 : : * Function will perform following steps: 123 : : * - Initialize SQ contexts. 124 : : * - Initialize RQ contexts. 125 : : * - Clean QP offload contexts of SQ and RQ. 126 : : * - Set root context for device. 127 : : * - Configure CI tables for each SQ. 128 : : * 129 : : * @param[in] nic_dev 130 : : * Pointer to ethernet device structure. 131 : : * 132 : : * @return 133 : : * 0 on success, non-zero on failure. 134 : : */ 135 : : int hinic3_init_qp_ctxts(struct hinic3_nic_dev *nic_dev); 136 : : 137 : : /** 138 : : * Free queue pair context. 139 : : * 140 : : * @param[in] hwdev 141 : : * Pointer to hardware device structure. 142 : : */ 143 : : void hinic3_free_qp_ctxts(struct hinic3_hwdev *hwdev); 144 : : 145 : : /** 146 : : * Update driver feature capabilities. 147 : : * 148 : : * @param[in] nic_dev 149 : : * Pointer to ethernet device structure. 150 : : * @param[out] s_feature 151 : : * s_feature driver supported. 152 : : * 153 : : * @return 154 : : * 0 on success, non-zero on failure. 155 : : */ 156 : : void hinic3_update_driver_feature(struct hinic3_nic_dev *nic_dev, uint64_t s_feature); 157 : : 158 : : /** 159 : : * Get driver feature capabilities. 160 : : * 161 : : * @param[in] nic_dev 162 : : * Pointer to ethernet device structure. 163 : : * 164 : : * @return 165 : : * Feature capabilities of driver. 166 : : */ 167 : : uint64_t hinic3_get_driver_feature(struct hinic3_nic_dev *nic_dev); 168 : : 169 : : #endif /* _HINIC3_NIC_IO_H_ */