1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */ 2 /* 3 * Copyright 2018-2026 Amazon.com, Inc. or its affiliates. All rights reserved. 4 */ 5 6 #ifndef _EFA_COM_CMD_H_ 7 #define _EFA_COM_CMD_H_ 8 9 #include "efa_com.h" 10 11 #define EFA_GID_SIZE 16 12 13 struct efa_com_create_qp_params { 14 u64 rq_base_addr; 15 u32 send_cq_idx; 16 u32 recv_cq_idx; 17 /* 18 * Send descriptor ring size in bytes, 19 * sufficient for user-provided number of WQEs and SGL size 20 */ 21 u32 sq_ring_size_in_bytes; 22 /* Max number of WQEs that will be posted on send queue */ 23 u32 sq_depth; 24 /* Recv descriptor ring size in bytes */ 25 u32 rq_ring_size_in_bytes; 26 u32 rq_depth; 27 u16 pd; 28 u16 uarn; 29 u8 qp_type; 30 u8 sl; 31 u8 unsolicited_write_recv : 1; 32 }; 33 34 struct efa_com_create_qp_result { 35 u32 qp_handle; 36 u32 qp_num; 37 u32 sq_db_offset; 38 u32 rq_db_offset; 39 u32 llq_descriptors_offset; 40 u16 send_sub_cq_idx; 41 u16 recv_sub_cq_idx; 42 }; 43 44 struct efa_com_modify_qp_params { 45 u32 modify_mask; 46 u32 qp_handle; 47 u32 qp_state; 48 u32 cur_qp_state; 49 u32 qkey; 50 u32 sq_psn; 51 u8 sq_drained_async_notify; 52 u8 rnr_retry; 53 }; 54 55 struct efa_com_query_qp_params { 56 u32 qp_handle; 57 }; 58 59 struct efa_com_query_qp_result { 60 u32 qp_state; 61 u32 qkey; 62 u32 sq_draining; 63 u32 sq_psn; 64 u8 rnr_retry; 65 }; 66 67 struct efa_com_destroy_qp_params { 68 u32 qp_handle; 69 }; 70 71 struct efa_com_create_cq_params { 72 /* cq physical base address in OS memory */ 73 dma_addr_t dma_addr; 74 /* completion queue depth in # of entries */ 75 u16 sub_cq_depth; 76 u16 num_sub_cqs; 77 u16 uarn; 78 u16 eqn; 79 u8 entry_size_in_bytes; 80 u8 interrupt_mode_enabled : 1; 81 u8 set_src_addr : 1; 82 }; 83 84 struct efa_com_create_cq_result { 85 /* cq identifier */ 86 u16 cq_idx; 87 /* actual cq depth in # of entries */ 88 u16 actual_depth; 89 u32 db_off; 90 bool db_valid; 91 }; 92 93 struct efa_com_destroy_cq_params { 94 u16 cq_idx; 95 }; 96 97 struct efa_com_create_ah_params { 98 u16 pdn; 99 /* Destination address in network byte order */ 100 u8 dest_addr[EFA_GID_SIZE]; 101 }; 102 103 struct efa_com_create_ah_result { 104 u16 ah; 105 }; 106 107 struct efa_com_destroy_ah_params { 108 u16 ah; 109 u16 pdn; 110 }; 111 112 struct efa_com_get_device_attr_result { 113 u8 addr[EFA_GID_SIZE]; 114 u64 page_size_cap; 115 u64 max_mr_pages; 116 u64 guid; 117 u32 mtu; 118 u32 fw_version; 119 u32 admin_api_version; 120 u32 device_version; 121 u32 supported_features; 122 u32 phys_addr_width; 123 u32 virt_addr_width; 124 u32 max_qp; 125 u32 max_sq_depth; /* wqes */ 126 u32 max_rq_depth; /* wqes */ 127 u32 max_cq; 128 u32 max_cq_depth; /* cqes */ 129 u32 inline_buf_size; 130 u32 inline_buf_size_ex; 131 u32 max_mr; 132 u32 max_pd; 133 u32 max_ah; 134 u32 max_llq_size; 135 u32 max_rdma_size; 136 u32 device_caps; 137 u32 max_eq; 138 u32 max_eq_depth; 139 u32 event_bitmask; /* EQ events bitmask */ 140 u16 sub_cqs_per_cq; 141 u16 max_sq_sge; 142 u16 max_rq_sge; 143 u16 max_wr_rdma_sge; 144 u16 max_tx_batch; 145 u16 min_sq_depth; 146 u16 max_link_speed_gbps; 147 u8 db_bar; 148 }; 149 150 struct efa_com_get_hw_hints_result { 151 u16 mmio_read_timeout; 152 u16 driver_watchdog_timeout; 153 u16 admin_completion_timeout; 154 u16 poll_interval; 155 u32 reserved[4]; 156 }; 157 158 struct efa_com_mem_addr { 159 u32 mem_addr_low; 160 u32 mem_addr_high; 161 }; 162 163 /* Used at indirect mode page list chunks for chaining */ 164 struct efa_com_ctrl_buff_info { 165 /* indicates length of the buffer pointed by control_buffer_address. */ 166 u32 length; 167 /* points to control buffer (direct or indirect) */ 168 struct efa_com_mem_addr address; 169 }; 170 171 struct efa_com_reg_mr_params { 172 /* Memory region length, in bytes. */ 173 u64 mr_length_in_bytes; 174 /* IO Virtual Address associated with this MR. */ 175 u64 iova; 176 /* words 8:15: Physical Buffer List, each element is page-aligned. */ 177 union { 178 /* 179 * Inline array of physical addresses of app pages 180 * (optimization for short region reservations) 181 */ 182 u64 inline_pbl_array[4]; 183 /* 184 * Describes the next physically contiguous chunk of indirect 185 * page list. A page list contains physical addresses of command 186 * data pages. Data pages are 4KB; page list chunks are 187 * variable-sized. 188 */ 189 struct efa_com_ctrl_buff_info pbl; 190 } pbl; 191 /* number of pages in PBL (redundant, could be calculated) */ 192 u32 page_num; 193 /* Protection Domain */ 194 u16 pd; 195 /* 196 * phys_page_size_shift - page size is (1 << phys_page_size_shift) 197 * Page size is used for building the Virtual to Physical 198 * address mapping 199 */ 200 u8 page_shift; 201 /* see permissions field of struct efa_admin_reg_mr_cmd */ 202 u8 permissions; 203 u8 inline_pbl; 204 u8 indirect; 205 }; 206 207 struct efa_com_mr_interconnect_info { 208 u16 recv_ic_id; 209 u16 rdma_read_ic_id; 210 u16 rdma_recv_ic_id; 211 u8 recv_ic_id_valid : 1; 212 u8 rdma_read_ic_id_valid : 1; 213 u8 rdma_recv_ic_id_valid : 1; 214 }; 215 216 struct efa_com_reg_mr_result { 217 /* 218 * To be used in conjunction with local buffers references in SQ and 219 * RQ WQE 220 */ 221 u32 l_key; 222 /* 223 * To be used in incoming RDMA semantics messages to refer to remotely 224 * accessed memory region 225 */ 226 u32 r_key; 227 struct efa_com_mr_interconnect_info ic_info; 228 }; 229 230 struct efa_com_dereg_mr_params { 231 u32 l_key; 232 }; 233 234 struct efa_com_alloc_pd_result { 235 u16 pdn; 236 }; 237 238 struct efa_com_dealloc_pd_params { 239 u16 pdn; 240 }; 241 242 struct efa_com_alloc_uar_result { 243 u16 uarn; 244 }; 245 246 struct efa_com_dealloc_uar_params { 247 u16 uarn; 248 }; 249 250 struct efa_com_get_stats_params { 251 /* see enum efa_admin_get_stats_type */ 252 u8 type; 253 /* see enum efa_admin_get_stats_scope */ 254 u8 scope; 255 u16 scope_modifier; 256 }; 257 258 struct efa_com_basic_stats { 259 u64 tx_bytes; 260 u64 tx_pkts; 261 u64 rx_bytes; 262 u64 rx_pkts; 263 u64 rx_drops; 264 }; 265 266 struct efa_com_messages_stats { 267 u64 send_bytes; 268 u64 send_wrs; 269 u64 recv_bytes; 270 u64 recv_wrs; 271 }; 272 273 struct efa_com_rdma_read_stats { 274 u64 read_wrs; 275 u64 read_bytes; 276 u64 read_wr_err; 277 u64 read_resp_bytes; 278 }; 279 280 struct efa_com_rdma_write_stats { 281 u64 write_wrs; 282 u64 write_bytes; 283 u64 write_wr_err; 284 u64 write_recv_bytes; 285 }; 286 287 struct efa_com_network_stats { 288 u64 retrans_bytes; 289 u64 retrans_pkts; 290 u64 retrans_timeout_events; 291 u64 unresponsive_remote_events; 292 u64 impaired_remote_conn_events; 293 }; 294 295 union efa_com_get_stats_result { 296 struct efa_com_basic_stats basic_stats; 297 struct efa_com_messages_stats messages_stats; 298 struct efa_com_rdma_read_stats rdma_read_stats; 299 struct efa_com_rdma_write_stats rdma_write_stats; 300 struct efa_com_network_stats network_stats; 301 }; 302 303 int efa_com_create_qp(struct efa_com_dev *edev, 304 struct efa_com_create_qp_params *params, 305 struct efa_com_create_qp_result *res); 306 int efa_com_modify_qp(struct efa_com_dev *edev, 307 struct efa_com_modify_qp_params *params); 308 int efa_com_query_qp(struct efa_com_dev *edev, 309 struct efa_com_query_qp_params *params, 310 struct efa_com_query_qp_result *result); 311 int efa_com_destroy_qp(struct efa_com_dev *edev, 312 struct efa_com_destroy_qp_params *params); 313 int efa_com_create_cq(struct efa_com_dev *edev, 314 struct efa_com_create_cq_params *params, 315 struct efa_com_create_cq_result *result); 316 int efa_com_destroy_cq(struct efa_com_dev *edev, 317 struct efa_com_destroy_cq_params *params); 318 int efa_com_register_mr(struct efa_com_dev *edev, 319 struct efa_com_reg_mr_params *params, 320 struct efa_com_reg_mr_result *result); 321 int efa_com_dereg_mr(struct efa_com_dev *edev, 322 struct efa_com_dereg_mr_params *params); 323 int efa_com_create_ah(struct efa_com_dev *edev, 324 struct efa_com_create_ah_params *params, 325 struct efa_com_create_ah_result *result); 326 int efa_com_destroy_ah(struct efa_com_dev *edev, 327 struct efa_com_destroy_ah_params *params); 328 int efa_com_get_device_attr(struct efa_com_dev *edev, 329 struct efa_com_get_device_attr_result *result); 330 int efa_com_get_hw_hints(struct efa_com_dev *edev, 331 struct efa_com_get_hw_hints_result *result); 332 bool 333 efa_com_check_supported_feature_id(struct efa_com_dev *edev, 334 enum efa_admin_aq_feature_id feature_id); 335 int efa_com_set_feature_ex(struct efa_com_dev *edev, 336 struct efa_admin_set_feature_resp *set_resp, 337 struct efa_admin_set_feature_cmd *set_cmd, 338 enum efa_admin_aq_feature_id feature_id, 339 dma_addr_t control_buf_dma_addr, 340 u32 control_buff_size); 341 int efa_com_set_aenq_config(struct efa_com_dev *edev, u32 groups); 342 int efa_com_alloc_pd(struct efa_com_dev *edev, 343 struct efa_com_alloc_pd_result *result); 344 int efa_com_dealloc_pd(struct efa_com_dev *edev, 345 struct efa_com_dealloc_pd_params *params); 346 int efa_com_alloc_uar(struct efa_com_dev *edev, 347 struct efa_com_alloc_uar_result *result); 348 int efa_com_dealloc_uar(struct efa_com_dev *edev, 349 struct efa_com_dealloc_uar_params *params); 350 int efa_com_get_stats(struct efa_com_dev *edev, 351 struct efa_com_get_stats_params *params, 352 union efa_com_get_stats_result *result); 353 354 #endif /* _EFA_COM_CMD_H_ */ 355