Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright (c) 2022 NVIDIA Corporation & Affiliates 3 : : */ 4 : : 5 : : #ifndef MLX5DR_SEND_H_ 6 : : #define MLX5DR_SEND_H_ 7 : : 8 : : #define MLX5DR_NUM_SEND_RINGS 1 9 : : 10 : : /* As a single operation requires at least two WQEBBS. 11 : : * This means a maximum of 16 such operations per rule. 12 : : */ 13 : : #define MAX_WQES_PER_RULE 32 14 : : 15 : : /* WQE Control segment. */ 16 : : struct mlx5dr_wqe_ctrl_seg { 17 : : __be32 opmod_idx_opcode; 18 : : __be32 qpn_ds; 19 : : __be32 flags; 20 : : __be32 imm; 21 : : }; 22 : : 23 : : enum mlx5dr_wqe_opcode { 24 : : MLX5DR_WQE_OPCODE_TBL_ACCESS = 0x2c, 25 : : }; 26 : : 27 : : enum mlx5dr_wqe_opmod { 28 : : MLX5DR_WQE_OPMOD_GTA_STE = 0, 29 : : MLX5DR_WQE_OPMOD_GTA_MOD_ARG = 1, 30 : : }; 31 : : 32 : : enum mlx5dr_wqe_gta_opcode { 33 : : MLX5DR_WQE_GTA_OP_ACTIVATE = 0, 34 : : MLX5DR_WQE_GTA_OP_DEACTIVATE = 1, 35 : : }; 36 : : 37 : : enum mlx5dr_wqe_gta_opmod { 38 : : MLX5DR_WQE_GTA_OPMOD_STE = 0, 39 : : MLX5DR_WQE_GTA_OPMOD_MOD_ARG = 1, 40 : : }; 41 : : 42 : : enum mlx5dr_wqe_gta_sz { 43 : : MLX5DR_WQE_SZ_GTA_CTRL = 48, 44 : : MLX5DR_WQE_SZ_GTA_DATA = 64, 45 : : }; 46 : : 47 : : struct mlx5dr_wqe_gta_ctrl_seg { 48 : : __be32 op_dirix; 49 : : __be32 stc_ix[5]; 50 : : __be32 rsvd0[6]; 51 : : }; 52 : : 53 : : struct mlx5dr_wqe_gta_data_seg_ste { 54 : : __be32 rsvd0_ctr_id; 55 : : __be32 rsvd1_definer; 56 : : __be32 rsvd2[3]; 57 : : union { 58 : : struct { 59 : : __be32 action[3]; 60 : : __be32 tag[8]; 61 : : }; 62 : : __be32 jumbo[11]; 63 : : }; 64 : : }; 65 : : 66 : : struct mlx5dr_wqe_gta_data_seg_arg { 67 : : __be32 action_args[8]; 68 : : }; 69 : : 70 : : struct mlx5dr_wqe_gta { 71 : : struct mlx5dr_wqe_gta_ctrl_seg gta_ctrl; 72 : : union { 73 : : struct mlx5dr_wqe_gta_data_seg_ste seg_ste; 74 : : struct mlx5dr_wqe_gta_data_seg_arg seg_arg; 75 : : }; 76 : : }; 77 : : 78 : : struct mlx5dr_send_ring_cq { 79 : : uint8_t *buf; 80 : : uint32_t cons_index; 81 : : uint32_t ncqe_mask; 82 : : uint32_t buf_sz; 83 : : uint32_t ncqe; 84 : : uint32_t cqe_log_sz; 85 : : __be32 *db; 86 : : uint16_t poll_wqe; 87 : : struct ibv_cq *ibv_cq; 88 : : uint32_t cqn; 89 : : uint32_t cqe_sz; 90 : : }; 91 : : 92 : : struct mlx5dr_send_ring_priv { 93 : : struct mlx5dr_rule *rule; 94 : : void *user_data; 95 : : uint32_t num_wqebbs; 96 : : uint32_t id; 97 : : uint32_t retry_id; 98 : : uint32_t *used_id; 99 : : }; 100 : : 101 : : struct mlx5dr_send_ring_dep_wqe { 102 : : struct mlx5dr_wqe_gta_ctrl_seg wqe_ctrl; 103 : : struct mlx5dr_wqe_gta_data_seg_ste wqe_data; 104 : : struct mlx5dr_rule *rule; 105 : : uint32_t rtc_0; 106 : : uint32_t rtc_1; 107 : : uint32_t retry_rtc_0; 108 : : uint32_t retry_rtc_1; 109 : : uint32_t direct_index; 110 : : void *user_data; 111 : : }; 112 : : 113 : : struct mlx5dr_send_ring_sq { 114 : : char *buf; 115 : : uint32_t sqn; 116 : : __be32 *db; 117 : : void *reg_addr; 118 : : uint16_t cur_post; 119 : : uint16_t buf_mask; 120 : : struct mlx5dr_send_ring_priv *wr_priv; 121 : : unsigned int last_idx; 122 : : struct mlx5dr_send_ring_dep_wqe *dep_wqe; 123 : : unsigned int head_dep_idx; 124 : : unsigned int tail_dep_idx; 125 : : struct mlx5dr_devx_obj *obj; 126 : : struct mlx5dv_devx_umem *buf_umem; 127 : : struct mlx5dv_devx_umem *db_umem; 128 : : }; 129 : : 130 : : struct mlx5dr_send_ring { 131 : : struct mlx5dr_send_ring_cq send_cq; 132 : : struct mlx5dr_send_ring_sq send_sq; 133 : : }; 134 : : 135 : : struct mlx5dr_completed_poll_entry { 136 : : void *user_data; 137 : : enum rte_flow_op_status status; 138 : : }; 139 : : 140 : : struct mlx5dr_completed_poll { 141 : : struct mlx5dr_completed_poll_entry *entries; 142 : : uint16_t ci; 143 : : uint16_t pi; 144 : : uint16_t mask; 145 : : }; 146 : : 147 : : struct mlx5dr_send_engine { 148 : : struct mlx5dr_send_ring send_ring[MLX5DR_NUM_SEND_RINGS]; /* For now 1:1 mapping */ 149 : : struct mlx5dv_devx_uar *uar; /* Uar is shared between rings of a queue */ 150 : : struct mlx5dr_completed_poll completed; 151 : : uint16_t used_entries; 152 : : uint16_t th_entries; 153 : : uint16_t rings; 154 : : uint16_t num_entries; 155 : : bool err; 156 : : } __rte_cache_aligned; 157 : : 158 : : struct mlx5dr_send_engine_post_ctrl { 159 : : struct mlx5dr_send_engine *queue; 160 : : struct mlx5dr_send_ring *send_ring; 161 : : size_t num_wqebbs; 162 : : }; 163 : : 164 : : struct mlx5dr_send_engine_post_attr { 165 : : uint8_t opcode; 166 : : uint8_t opmod; 167 : : uint8_t notify_hw; 168 : : uint8_t fence; 169 : : uint8_t match_definer_id; 170 : : uint8_t range_definer_id; 171 : : size_t len; 172 : : struct mlx5dr_rule *rule; 173 : : uint32_t id; 174 : : uint32_t retry_id; 175 : : uint32_t *used_id; 176 : : void *user_data; 177 : : }; 178 : : 179 : : struct mlx5dr_send_ste_attr { 180 : : /* rtc / retry_rtc / used_id_rtc override send_attr */ 181 : : uint32_t rtc_0; 182 : : uint32_t rtc_1; 183 : : uint32_t retry_rtc_0; 184 : : uint32_t retry_rtc_1; 185 : : uint32_t *used_id_rtc_0; 186 : : uint32_t *used_id_rtc_1; 187 : : bool wqe_tag_is_jumbo; 188 : : uint8_t gta_opcode; 189 : : uint32_t direct_index; 190 : : struct mlx5dr_send_engine_post_attr send_attr; 191 : : struct mlx5dr_rule_match_tag *wqe_tag; 192 : : struct mlx5dr_rule_match_tag *range_wqe_tag; 193 : : struct mlx5dr_wqe_gta_ctrl_seg *wqe_ctrl; 194 : : struct mlx5dr_wqe_gta_data_seg_ste *wqe_data; 195 : : struct mlx5dr_wqe_gta_data_seg_ste *range_wqe_data; 196 : : }; 197 : : 198 : : /** 199 : : * Provide safe 64bit store operation to mlx5 UAR region for 200 : : * both 32bit and 64bit architectures. 201 : : * 202 : : * @param val 203 : : * value to write in CPU endian format. 204 : : * @param addr 205 : : * Address to write to. 206 : : * @param lock 207 : : * Address of the lock to use for that UAR access. 208 : : */ 209 : : static __rte_always_inline void 210 : : mlx5dr_uar_write64_relaxed(uint64_t val, void *addr) 211 : : { 212 : : #ifdef RTE_ARCH_64 213 : 0 : *(uint64_t *)addr = val; 214 : : #else /* !RTE_ARCH_64 */ 215 : : *(uint32_t *)addr = val; 216 : : rte_io_wmb(); 217 : : *((uint32_t *)addr + 1) = val >> 32; 218 : : #endif 219 : : } 220 : : 221 : : struct mlx5dr_send_ring_dep_wqe * 222 : : mlx5dr_send_add_new_dep_wqe(struct mlx5dr_send_engine *queue); 223 : : 224 : : void mlx5dr_send_abort_new_dep_wqe(struct mlx5dr_send_engine *queue); 225 : : 226 : : void mlx5dr_send_all_dep_wqe(struct mlx5dr_send_engine *queue); 227 : : 228 : : void mlx5dr_send_queue_close(struct mlx5dr_send_engine *queue); 229 : : 230 : : int mlx5dr_send_queue_open(struct mlx5dr_context *ctx, 231 : : struct mlx5dr_send_engine *queue, 232 : : uint16_t queue_size); 233 : : 234 : : void mlx5dr_send_queues_close(struct mlx5dr_context *ctx); 235 : : 236 : : int mlx5dr_send_queues_open(struct mlx5dr_context *ctx, 237 : : uint16_t queues, 238 : : uint16_t queue_size); 239 : : 240 : : struct mlx5dr_send_engine_post_ctrl 241 : : mlx5dr_send_engine_post_start(struct mlx5dr_send_engine *queue); 242 : : 243 : : void mlx5dr_send_engine_post_req_wqe(struct mlx5dr_send_engine_post_ctrl *ctrl, 244 : : char **buf, size_t *len); 245 : : 246 : : void mlx5dr_send_engine_post_end(struct mlx5dr_send_engine_post_ctrl *ctrl, 247 : : struct mlx5dr_send_engine_post_attr *attr); 248 : : 249 : : void mlx5dr_send_ste(struct mlx5dr_send_engine *queue, 250 : : struct mlx5dr_send_ste_attr *ste_attr); 251 : : 252 : : void mlx5dr_send_stes_fw(struct mlx5dr_send_engine *queue, 253 : : struct mlx5dr_send_ste_attr *ste_attr); 254 : : 255 : : void mlx5dr_send_engine_flush_queue(struct mlx5dr_send_engine *queue); 256 : : 257 : : static inline bool mlx5dr_send_engine_empty(struct mlx5dr_send_engine *queue) 258 : : { 259 : : struct mlx5dr_send_ring_sq *send_sq = &queue->send_ring->send_sq; 260 : : struct mlx5dr_send_ring_cq *send_cq = &queue->send_ring->send_cq; 261 : : 262 [ # # ]: 0 : return ((send_sq->cur_post & send_sq->buf_mask) == send_cq->poll_wqe); 263 : : } 264 : : 265 : : static inline bool mlx5dr_send_engine_full(struct mlx5dr_send_engine *queue) 266 : : { 267 [ # # # # : 0 : return queue->used_entries >= queue->th_entries; # # ] 268 : : } 269 : : 270 : : static inline void mlx5dr_send_engine_inc_rule(struct mlx5dr_send_engine *queue) 271 : : { 272 [ # # # # : 0 : queue->used_entries++; # # # # ] 273 : : } 274 : : 275 : : static inline void mlx5dr_send_engine_dec_rule(struct mlx5dr_send_engine *queue) 276 : : { 277 : 0 : queue->used_entries--; 278 : 0 : } 279 : : 280 : : static inline void mlx5dr_send_engine_gen_comp(struct mlx5dr_send_engine *queue, 281 : : void *user_data, 282 : : int comp_status) 283 : : { 284 : : struct mlx5dr_completed_poll *comp = &queue->completed; 285 : : 286 : 0 : comp->entries[comp->pi].status = comp_status; 287 : 0 : comp->entries[comp->pi].user_data = user_data; 288 : : 289 : 0 : comp->pi = (comp->pi + 1) & comp->mask; 290 : 0 : } 291 : : 292 : : static inline bool mlx5dr_send_engine_err(struct mlx5dr_send_engine *queue) 293 : : { 294 [ # # # # : 0 : return queue->err; # # # # ] 295 : : } 296 : : 297 : : #endif /* MLX5DR_SEND_H_ */