| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* |
| 3 | * Copyright (c) 2022 Microsoft Corporation. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | #ifndef _MANA_IB_H_ |
| 7 | #define _MANA_IB_H_ |
| 8 | |
| 9 | #include <rdma/ib_verbs.h> |
| 10 | #include <rdma/ib_mad.h> |
| 11 | #include <rdma/ib_umem.h> |
| 12 | #include <rdma/mana-abi.h> |
| 13 | #include <rdma/uverbs_ioctl.h> |
| 14 | #include <linux/dmapool.h> |
| 15 | |
| 16 | #include <net/mana/mana.h> |
| 17 | #include "shadow_queue.h" |
| 18 | #include "counters.h" |
| 19 | |
| 20 | #define PAGE_SZ_BM \ |
| 21 | (SZ_4K | SZ_8K | SZ_16K | SZ_32K | SZ_64K | SZ_128K | SZ_256K | \ |
| 22 | SZ_512K | SZ_1M | SZ_2M) |
| 23 | |
| 24 | /* MANA doesn't have any limit for MR size */ |
| 25 | #define MANA_IB_MAX_MR_SIZE U64_MAX |
| 26 | |
| 27 | /* Send queue ID mask */ |
| 28 | #define MANA_SENDQ_MASK BIT(31) |
| 29 | |
| 30 | /* |
| 31 | * The hardware limit of number of MRs is greater than maximum number of MRs |
| 32 | * that can possibly represent in 24 bits |
| 33 | */ |
| 34 | #define MANA_IB_MAX_MR 0xFFFFFFu |
| 35 | |
| 36 | /* |
| 37 | * The CA timeout is approx. 260ms (4us * 2^(DELAY)) |
| 38 | */ |
| 39 | #define MANA_CA_ACK_DELAY 16 |
| 40 | |
| 41 | /* |
| 42 | * The buffer used for writing AV |
| 43 | */ |
| 44 | #define MANA_AV_BUFFER_SIZE 64 |
| 45 | |
| 46 | #define MANA_GSI_QPN (1) |
| 47 | |
| 48 | struct mana_ib_adapter_caps { |
| 49 | u32 max_sq_id; |
| 50 | u32 max_rq_id; |
| 51 | u32 max_cq_id; |
| 52 | u32 max_qp_count; |
| 53 | u32 max_cq_count; |
| 54 | u32 max_mr_count; |
| 55 | u32 max_pd_count; |
| 56 | u32 max_inbound_read_limit; |
| 57 | u32 max_outbound_read_limit; |
| 58 | u32 mw_count; |
| 59 | u32 max_srq_count; |
| 60 | u32 max_qp_wr; |
| 61 | u32 max_send_sge_count; |
| 62 | u32 max_recv_sge_count; |
| 63 | u32 max_inline_data_size; |
| 64 | u64 feature_flags; |
| 65 | u64 page_size_cap; |
| 66 | }; |
| 67 | |
| 68 | struct mana_ib_queue { |
| 69 | struct ib_umem *umem; |
| 70 | struct gdma_queue *kmem; |
| 71 | u64 gdma_region; |
| 72 | u64 id; |
| 73 | }; |
| 74 | |
| 75 | struct mana_ib_dev { |
| 76 | struct ib_device ib_dev; |
| 77 | struct gdma_dev *gdma_dev; |
| 78 | mana_handle_t adapter_handle; |
| 79 | struct gdma_queue *fatal_err_eq; |
| 80 | struct gdma_queue **eqs; |
| 81 | struct xarray qp_table_wq; |
| 82 | struct mana_ib_adapter_caps adapter_caps; |
| 83 | struct dma_pool *av_pool; |
| 84 | netdevice_tracker dev_tracker; |
| 85 | struct notifier_block nb; |
| 86 | }; |
| 87 | |
| 88 | struct mana_ib_wq { |
| 89 | struct ib_wq ibwq; |
| 90 | struct mana_ib_queue queue; |
| 91 | int wqe; |
| 92 | u32 wq_buf_size; |
| 93 | mana_handle_t rx_object; |
| 94 | }; |
| 95 | |
| 96 | struct mana_ib_pd { |
| 97 | struct ib_pd ibpd; |
| 98 | u32 pdn; |
| 99 | mana_handle_t pd_handle; |
| 100 | |
| 101 | /* Mutex for sharing access to vport_use_count */ |
| 102 | struct mutex vport_mutex; |
| 103 | int vport_use_count; |
| 104 | |
| 105 | bool tx_shortform_allowed; |
| 106 | u32 tx_vp_offset; |
| 107 | }; |
| 108 | |
| 109 | struct mana_ib_av { |
| 110 | u8 dest_ip[16]; |
| 111 | u8 dest_mac[ETH_ALEN]; |
| 112 | u16 udp_src_port; |
| 113 | u8 src_ip[16]; |
| 114 | u32 hop_limit : 8; |
| 115 | u32 reserved1 : 12; |
| 116 | u32 dscp : 6; |
| 117 | u32 reserved2 : 5; |
| 118 | u32 is_ipv6 : 1; |
| 119 | u32 reserved3 : 32; |
| 120 | }; |
| 121 | |
| 122 | struct mana_ib_ah { |
| 123 | struct ib_ah ibah; |
| 124 | struct mana_ib_av *av; |
| 125 | dma_addr_t dma_handle; |
| 126 | }; |
| 127 | |
| 128 | struct mana_ib_mr { |
| 129 | struct ib_mr ibmr; |
| 130 | struct ib_umem *umem; |
| 131 | mana_handle_t mr_handle; |
| 132 | }; |
| 133 | |
| 134 | struct mana_ib_cq { |
| 135 | struct ib_cq ibcq; |
| 136 | struct mana_ib_queue queue; |
| 137 | /* protects CQ polling */ |
| 138 | spinlock_t cq_lock; |
| 139 | struct list_head list_send_qp; |
| 140 | struct list_head list_recv_qp; |
| 141 | int cqe; |
| 142 | u32 comp_vector; |
| 143 | mana_handle_t cq_handle; |
| 144 | }; |
| 145 | |
| 146 | enum mana_rc_queue_type { |
| 147 | MANA_RC_SEND_QUEUE_REQUESTER = 0, |
| 148 | MANA_RC_SEND_QUEUE_RESPONDER, |
| 149 | MANA_RC_SEND_QUEUE_FMR, |
| 150 | MANA_RC_RECV_QUEUE_REQUESTER, |
| 151 | MANA_RC_RECV_QUEUE_RESPONDER, |
| 152 | MANA_RC_QUEUE_TYPE_MAX, |
| 153 | }; |
| 154 | |
| 155 | struct mana_ib_rc_qp { |
| 156 | struct mana_ib_queue queues[MANA_RC_QUEUE_TYPE_MAX]; |
| 157 | }; |
| 158 | |
| 159 | enum mana_ud_queue_type { |
| 160 | MANA_UD_SEND_QUEUE = 0, |
| 161 | MANA_UD_RECV_QUEUE, |
| 162 | MANA_UD_QUEUE_TYPE_MAX, |
| 163 | }; |
| 164 | |
| 165 | struct mana_ib_ud_qp { |
| 166 | struct mana_ib_queue queues[MANA_UD_QUEUE_TYPE_MAX]; |
| 167 | u32 sq_psn; |
| 168 | }; |
| 169 | |
| 170 | struct mana_ib_qp { |
| 171 | struct ib_qp ibqp; |
| 172 | |
| 173 | mana_handle_t qp_handle; |
| 174 | union { |
| 175 | struct mana_ib_queue raw_sq; |
| 176 | struct mana_ib_rc_qp rc_qp; |
| 177 | struct mana_ib_ud_qp ud_qp; |
| 178 | }; |
| 179 | |
| 180 | /* The port on the IB device, starting with 1 */ |
| 181 | u32 port; |
| 182 | |
| 183 | struct list_head cq_send_list; |
| 184 | struct list_head cq_recv_list; |
| 185 | struct shadow_queue shadow_rq; |
| 186 | struct shadow_queue shadow_sq; |
| 187 | |
| 188 | refcount_t refcount; |
| 189 | struct completion free; |
| 190 | }; |
| 191 | |
| 192 | struct mana_ib_ucontext { |
| 193 | struct ib_ucontext ibucontext; |
| 194 | u32 doorbell; |
| 195 | }; |
| 196 | |
| 197 | struct mana_ib_rwq_ind_table { |
| 198 | struct ib_rwq_ind_table ib_ind_table; |
| 199 | }; |
| 200 | |
| 201 | enum mana_ib_command_code { |
| 202 | MANA_IB_GET_ADAPTER_CAP = 0x30001, |
| 203 | MANA_IB_CREATE_ADAPTER = 0x30002, |
| 204 | MANA_IB_DESTROY_ADAPTER = 0x30003, |
| 205 | MANA_IB_CONFIG_IP_ADDR = 0x30004, |
| 206 | MANA_IB_CONFIG_MAC_ADDR = 0x30005, |
| 207 | MANA_IB_CREATE_UD_QP = 0x30006, |
| 208 | MANA_IB_DESTROY_UD_QP = 0x30007, |
| 209 | MANA_IB_CREATE_CQ = 0x30008, |
| 210 | MANA_IB_DESTROY_CQ = 0x30009, |
| 211 | MANA_IB_CREATE_RC_QP = 0x3000a, |
| 212 | MANA_IB_DESTROY_RC_QP = 0x3000b, |
| 213 | MANA_IB_SET_QP_STATE = 0x3000d, |
| 214 | MANA_IB_QUERY_VF_COUNTERS = 0x30022, |
| 215 | MANA_IB_QUERY_DEVICE_COUNTERS = 0x30023, |
| 216 | }; |
| 217 | |
| 218 | struct mana_ib_query_adapter_caps_req { |
| 219 | struct gdma_req_hdr hdr; |
| 220 | }; /*HW Data */ |
| 221 | |
| 222 | enum mana_ib_adapter_features { |
| 223 | MANA_IB_FEATURE_CLIENT_ERROR_CQE_SUPPORT = BIT(4), |
| 224 | MANA_IB_FEATURE_DEV_COUNTERS_SUPPORT = BIT(5), |
| 225 | MANA_IB_FEATURE_MULTI_PORTS_SUPPORT = BIT(6), |
| 226 | }; |
| 227 | |
| 228 | struct mana_ib_query_adapter_caps_resp { |
| 229 | struct gdma_resp_hdr hdr; |
| 230 | u32 max_sq_id; |
| 231 | u32 max_rq_id; |
| 232 | u32 max_cq_id; |
| 233 | u32 max_qp_count; |
| 234 | u32 max_cq_count; |
| 235 | u32 max_mr_count; |
| 236 | u32 max_pd_count; |
| 237 | u32 max_inbound_read_limit; |
| 238 | u32 max_outbound_read_limit; |
| 239 | u32 mw_count; |
| 240 | u32 max_srq_count; |
| 241 | u32 max_requester_sq_size; |
| 242 | u32 max_responder_sq_size; |
| 243 | u32 max_requester_rq_size; |
| 244 | u32 max_responder_rq_size; |
| 245 | u32 max_send_sge_count; |
| 246 | u32 max_recv_sge_count; |
| 247 | u32 max_inline_data_size; |
| 248 | u64 feature_flags; |
| 249 | }; /* HW Data */ |
| 250 | |
| 251 | enum mana_ib_adapter_features_request { |
| 252 | MANA_IB_FEATURE_CLIENT_ERROR_CQE_REQUEST = BIT(1), |
| 253 | }; /*HW Data */ |
| 254 | |
| 255 | struct mana_rnic_create_adapter_req { |
| 256 | struct gdma_req_hdr hdr; |
| 257 | u32 notify_eq_id; |
| 258 | u32 reserved; |
| 259 | u64 feature_flags; |
| 260 | }; /*HW Data */ |
| 261 | |
| 262 | struct mana_rnic_create_adapter_resp { |
| 263 | struct gdma_resp_hdr hdr; |
| 264 | mana_handle_t adapter; |
| 265 | }; /* HW Data */ |
| 266 | |
| 267 | struct mana_rnic_destroy_adapter_req { |
| 268 | struct gdma_req_hdr hdr; |
| 269 | mana_handle_t adapter; |
| 270 | }; /*HW Data */ |
| 271 | |
| 272 | struct mana_rnic_destroy_adapter_resp { |
| 273 | struct gdma_resp_hdr hdr; |
| 274 | }; /* HW Data */ |
| 275 | |
| 276 | enum mana_ib_addr_op { |
| 277 | ADDR_OP_ADD = 1, |
| 278 | ADDR_OP_REMOVE = 2, |
| 279 | }; |
| 280 | |
| 281 | enum sgid_entry_type { |
| 282 | SGID_TYPE_IPV4 = 1, |
| 283 | SGID_TYPE_IPV6 = 2, |
| 284 | }; |
| 285 | |
| 286 | struct mana_rnic_config_addr_req { |
| 287 | struct gdma_req_hdr hdr; |
| 288 | mana_handle_t adapter; |
| 289 | enum mana_ib_addr_op op; |
| 290 | enum sgid_entry_type sgid_type; |
| 291 | u8 ip_addr[16]; |
| 292 | }; /* HW Data */ |
| 293 | |
| 294 | struct mana_rnic_config_addr_resp { |
| 295 | struct gdma_resp_hdr hdr; |
| 296 | }; /* HW Data */ |
| 297 | |
| 298 | struct mana_rnic_config_mac_addr_req { |
| 299 | struct gdma_req_hdr hdr; |
| 300 | mana_handle_t adapter; |
| 301 | enum mana_ib_addr_op op; |
| 302 | u8 mac_addr[ETH_ALEN]; |
| 303 | u8 reserved[6]; |
| 304 | }; /* HW Data */ |
| 305 | |
| 306 | struct mana_rnic_config_mac_addr_resp { |
| 307 | struct gdma_resp_hdr hdr; |
| 308 | }; /* HW Data */ |
| 309 | |
| 310 | struct mana_rnic_create_cq_req { |
| 311 | struct gdma_req_hdr hdr; |
| 312 | mana_handle_t adapter; |
| 313 | u64 gdma_region; |
| 314 | u32 eq_id; |
| 315 | u32 doorbell_page; |
| 316 | }; /* HW Data */ |
| 317 | |
| 318 | struct mana_rnic_create_cq_resp { |
| 319 | struct gdma_resp_hdr hdr; |
| 320 | mana_handle_t cq_handle; |
| 321 | u32 cq_id; |
| 322 | u32 reserved; |
| 323 | }; /* HW Data */ |
| 324 | |
| 325 | struct mana_rnic_destroy_cq_req { |
| 326 | struct gdma_req_hdr hdr; |
| 327 | mana_handle_t adapter; |
| 328 | mana_handle_t cq_handle; |
| 329 | }; /* HW Data */ |
| 330 | |
| 331 | struct mana_rnic_destroy_cq_resp { |
| 332 | struct gdma_resp_hdr hdr; |
| 333 | }; /* HW Data */ |
| 334 | |
| 335 | enum mana_rnic_create_rc_flags { |
| 336 | MANA_RC_FLAG_NO_FMR = 2, |
| 337 | }; |
| 338 | |
| 339 | struct mana_rnic_create_qp_req { |
| 340 | struct gdma_req_hdr hdr; |
| 341 | mana_handle_t adapter; |
| 342 | mana_handle_t pd_handle; |
| 343 | mana_handle_t send_cq_handle; |
| 344 | mana_handle_t recv_cq_handle; |
| 345 | u64 dma_region[MANA_RC_QUEUE_TYPE_MAX]; |
| 346 | u64 deprecated[2]; |
| 347 | u64 flags; |
| 348 | u32 doorbell_page; |
| 349 | u32 max_send_wr; |
| 350 | u32 max_recv_wr; |
| 351 | u32 max_send_sge; |
| 352 | u32 max_recv_sge; |
| 353 | u32 reserved; |
| 354 | }; /* HW Data */ |
| 355 | |
| 356 | struct mana_rnic_create_qp_resp { |
| 357 | struct gdma_resp_hdr hdr; |
| 358 | mana_handle_t rc_qp_handle; |
| 359 | u32 queue_ids[MANA_RC_QUEUE_TYPE_MAX]; |
| 360 | u32 reserved; |
| 361 | }; /* HW Data*/ |
| 362 | |
| 363 | struct mana_rnic_destroy_rc_qp_req { |
| 364 | struct gdma_req_hdr hdr; |
| 365 | mana_handle_t adapter; |
| 366 | mana_handle_t rc_qp_handle; |
| 367 | }; /* HW Data */ |
| 368 | |
| 369 | struct mana_rnic_destroy_rc_qp_resp { |
| 370 | struct gdma_resp_hdr hdr; |
| 371 | }; /* HW Data */ |
| 372 | |
| 373 | struct mana_rnic_create_udqp_req { |
| 374 | struct gdma_req_hdr hdr; |
| 375 | mana_handle_t adapter; |
| 376 | mana_handle_t pd_handle; |
| 377 | mana_handle_t send_cq_handle; |
| 378 | mana_handle_t recv_cq_handle; |
| 379 | u64 dma_region[MANA_UD_QUEUE_TYPE_MAX]; |
| 380 | u32 qp_type; |
| 381 | u32 doorbell_page; |
| 382 | u32 max_send_wr; |
| 383 | u32 max_recv_wr; |
| 384 | u32 max_send_sge; |
| 385 | u32 max_recv_sge; |
| 386 | }; /* HW Data */ |
| 387 | |
| 388 | struct mana_rnic_create_udqp_resp { |
| 389 | struct gdma_resp_hdr hdr; |
| 390 | mana_handle_t qp_handle; |
| 391 | u32 queue_ids[MANA_UD_QUEUE_TYPE_MAX]; |
| 392 | }; /* HW Data*/ |
| 393 | |
| 394 | struct mana_rnic_destroy_udqp_req { |
| 395 | struct gdma_req_hdr hdr; |
| 396 | mana_handle_t adapter; |
| 397 | mana_handle_t qp_handle; |
| 398 | }; /* HW Data */ |
| 399 | |
| 400 | struct mana_rnic_destroy_udqp_resp { |
| 401 | struct gdma_resp_hdr hdr; |
| 402 | }; /* HW Data */ |
| 403 | |
| 404 | struct mana_ib_ah_attr { |
| 405 | u8 src_addr[16]; |
| 406 | u8 dest_addr[16]; |
| 407 | u8 src_mac[ETH_ALEN]; |
| 408 | u8 dest_mac[ETH_ALEN]; |
| 409 | u8 src_addr_type; |
| 410 | u8 dest_addr_type; |
| 411 | u8 hop_limit; |
| 412 | u8 traffic_class; |
| 413 | u16 src_port; |
| 414 | u16 dest_port; |
| 415 | u32 flow_label; |
| 416 | }; |
| 417 | |
| 418 | struct mana_rnic_set_qp_state_req { |
| 419 | struct gdma_req_hdr hdr; |
| 420 | mana_handle_t adapter; |
| 421 | mana_handle_t qp_handle; |
| 422 | u64 attr_mask; |
| 423 | u32 qp_state; |
| 424 | u32 path_mtu; |
| 425 | u32 rq_psn; |
| 426 | u32 sq_psn; |
| 427 | u32 dest_qpn; |
| 428 | u32 max_dest_rd_atomic; |
| 429 | u32 retry_cnt; |
| 430 | u32 rnr_retry; |
| 431 | u32 min_rnr_timer; |
| 432 | u32 rate_limit; |
| 433 | struct mana_ib_ah_attr ah_attr; |
| 434 | u64 reserved1; |
| 435 | u32 qkey; |
| 436 | u32 qp_access_flags; |
| 437 | u8 local_ack_timeout; |
| 438 | u8 max_rd_atomic; |
| 439 | u16 reserved2; |
| 440 | u32 reserved3; |
| 441 | }; /* HW Data */ |
| 442 | |
| 443 | struct mana_rnic_set_qp_state_resp { |
| 444 | struct gdma_resp_hdr hdr; |
| 445 | }; /* HW Data */ |
| 446 | |
| 447 | enum WQE_OPCODE_TYPES { |
| 448 | WQE_TYPE_UD_SEND = 0, |
| 449 | WQE_TYPE_UD_RECV = 8, |
| 450 | }; /* HW DATA */ |
| 451 | |
| 452 | struct rdma_send_oob { |
| 453 | u32 wqe_type : 5; |
| 454 | u32 fence : 1; |
| 455 | u32 signaled : 1; |
| 456 | u32 solicited : 1; |
| 457 | u32 psn : 24; |
| 458 | |
| 459 | u32 ssn_or_rqpn : 24; |
| 460 | u32 reserved1 : 8; |
| 461 | union { |
| 462 | struct { |
| 463 | u32 remote_qkey; |
| 464 | u32 immediate; |
| 465 | u32 reserved1; |
| 466 | u32 reserved2; |
| 467 | } ud_send; |
| 468 | }; |
| 469 | }; /* HW DATA */ |
| 470 | |
| 471 | struct mana_rdma_cqe { |
| 472 | union { |
| 473 | struct { |
| 474 | u8 cqe_type; |
| 475 | u8 data[GDMA_COMP_DATA_SIZE - 1]; |
| 476 | }; |
| 477 | struct { |
| 478 | u32 cqe_type : 8; |
| 479 | u32 vendor_error : 9; |
| 480 | u32 reserved1 : 15; |
| 481 | u32 sge_offset : 5; |
| 482 | u32 tx_wqe_offset : 27; |
| 483 | } ud_send; |
| 484 | struct { |
| 485 | u32 cqe_type : 8; |
| 486 | u32 reserved1 : 24; |
| 487 | u32 msg_len; |
| 488 | u32 src_qpn : 24; |
| 489 | u32 reserved2 : 8; |
| 490 | u32 imm_data; |
| 491 | u32 rx_wqe_offset; |
| 492 | } ud_recv; |
| 493 | }; |
| 494 | }; /* HW DATA */ |
| 495 | |
| 496 | struct mana_rnic_query_vf_cntrs_req { |
| 497 | struct gdma_req_hdr hdr; |
| 498 | mana_handle_t adapter; |
| 499 | }; /* HW Data */ |
| 500 | |
| 501 | struct mana_rnic_query_vf_cntrs_resp { |
| 502 | struct gdma_resp_hdr hdr; |
| 503 | u64 requester_timeout; |
| 504 | u64 requester_oos_nak; |
| 505 | u64 requester_rnr_nak; |
| 506 | u64 responder_rnr_nak; |
| 507 | u64 responder_oos; |
| 508 | u64 responder_dup_request; |
| 509 | u64 requester_implicit_nak; |
| 510 | u64 requester_readresp_psn_mismatch; |
| 511 | u64 nak_inv_req; |
| 512 | u64 nak_access_err; |
| 513 | u64 nak_opp_err; |
| 514 | u64 nak_inv_read; |
| 515 | u64 responder_local_len_err; |
| 516 | u64 requestor_local_prot_err; |
| 517 | u64 responder_rem_access_err; |
| 518 | u64 responder_local_qp_err; |
| 519 | u64 responder_malformed_wqe; |
| 520 | u64 general_hw_err; |
| 521 | u64 requester_rnr_nak_retries_exceeded; |
| 522 | u64 requester_retries_exceeded; |
| 523 | u64 total_fatal_err; |
| 524 | u64 received_cnps; |
| 525 | u64 num_qps_congested; |
| 526 | u64 rate_inc_events; |
| 527 | u64 num_qps_recovered; |
| 528 | u64 current_rate; |
| 529 | u64 dup_rx_req; |
| 530 | u64 tx_bytes; |
| 531 | u64 rx_bytes; |
| 532 | u64 rx_send_req; |
| 533 | u64 rx_write_req; |
| 534 | u64 rx_read_req; |
| 535 | u64 tx_pkt; |
| 536 | u64 rx_pkt; |
| 537 | }; /* HW Data */ |
| 538 | |
| 539 | struct mana_rnic_query_device_cntrs_req { |
| 540 | struct gdma_req_hdr hdr; |
| 541 | mana_handle_t adapter; |
| 542 | }; /* HW Data */ |
| 543 | |
| 544 | struct mana_rnic_query_device_cntrs_resp { |
| 545 | struct gdma_resp_hdr hdr; |
| 546 | u32 sent_cnps; |
| 547 | u32 received_ecns; |
| 548 | u32 reserved1; |
| 549 | u32 received_cnp_count; |
| 550 | u32 qp_congested_events; |
| 551 | u32 qp_recovered_events; |
| 552 | u32 rate_inc_events; |
| 553 | u32 reserved2; |
| 554 | }; /* HW Data */ |
| 555 | |
| 556 | static inline struct gdma_context *mdev_to_gc(struct mana_ib_dev *mdev) |
| 557 | { |
| 558 | return mdev->gdma_dev->gdma_context; |
| 559 | } |
| 560 | |
| 561 | static inline struct mana_ib_qp *mana_get_qp_ref(struct mana_ib_dev *mdev, |
| 562 | u32 qid, bool is_sq) |
| 563 | { |
| 564 | struct mana_ib_qp *qp; |
| 565 | unsigned long flag; |
| 566 | |
| 567 | if (is_sq) |
| 568 | qid |= MANA_SENDQ_MASK; |
| 569 | |
| 570 | xa_lock_irqsave(&mdev->qp_table_wq, flag); |
| 571 | qp = xa_load(&mdev->qp_table_wq, index: qid); |
| 572 | if (qp) |
| 573 | refcount_inc(r: &qp->refcount); |
| 574 | xa_unlock_irqrestore(&mdev->qp_table_wq, flag); |
| 575 | return qp; |
| 576 | } |
| 577 | |
| 578 | static inline void mana_put_qp_ref(struct mana_ib_qp *qp) |
| 579 | { |
| 580 | if (refcount_dec_and_test(r: &qp->refcount)) |
| 581 | complete(&qp->free); |
| 582 | } |
| 583 | |
| 584 | static inline bool mana_ib_is_rnic(struct mana_ib_dev *mdev) |
| 585 | { |
| 586 | return mdev->gdma_dev->dev_id.type == GDMA_DEVICE_MANA_IB; |
| 587 | } |
| 588 | |
| 589 | static inline struct net_device *mana_ib_get_netdev(struct ib_device *ibdev, u32 port) |
| 590 | { |
| 591 | struct mana_ib_dev *mdev = container_of(ibdev, struct mana_ib_dev, ib_dev); |
| 592 | struct gdma_context *gc = mdev_to_gc(mdev); |
| 593 | struct mana_context *mc = gc->mana.driver_data; |
| 594 | |
| 595 | if (port < 1 || port > mc->num_ports) |
| 596 | return NULL; |
| 597 | return mc->ports[port - 1]; |
| 598 | } |
| 599 | |
| 600 | static inline void copy_in_reverse(u8 *dst, const u8 *src, u32 size) |
| 601 | { |
| 602 | u32 i; |
| 603 | |
| 604 | for (i = 0; i < size; i++) |
| 605 | dst[size - 1 - i] = src[i]; |
| 606 | } |
| 607 | |
| 608 | int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq); |
| 609 | void mana_ib_remove_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq); |
| 610 | |
| 611 | int mana_ib_create_zero_offset_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, |
| 612 | mana_handle_t *gdma_region); |
| 613 | |
| 614 | int mana_ib_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, |
| 615 | mana_handle_t *gdma_region, u64 virt); |
| 616 | |
| 617 | int mana_ib_gd_destroy_dma_region(struct mana_ib_dev *dev, |
| 618 | mana_handle_t gdma_region); |
| 619 | |
| 620 | int mana_ib_create_kernel_queue(struct mana_ib_dev *mdev, u32 size, enum gdma_queue_type type, |
| 621 | struct mana_ib_queue *queue); |
| 622 | int mana_ib_create_queue(struct mana_ib_dev *mdev, u64 addr, u32 size, |
| 623 | struct mana_ib_queue *queue); |
| 624 | void mana_ib_destroy_queue(struct mana_ib_dev *mdev, struct mana_ib_queue *queue); |
| 625 | |
| 626 | struct ib_wq *mana_ib_create_wq(struct ib_pd *pd, |
| 627 | struct ib_wq_init_attr *init_attr, |
| 628 | struct ib_udata *udata); |
| 629 | |
| 630 | int mana_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr, |
| 631 | u32 wq_attr_mask, struct ib_udata *udata); |
| 632 | |
| 633 | int mana_ib_destroy_wq(struct ib_wq *ibwq, struct ib_udata *udata); |
| 634 | |
| 635 | int mana_ib_create_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_table, |
| 636 | struct ib_rwq_ind_table_init_attr *init_attr, |
| 637 | struct ib_udata *udata); |
| 638 | |
| 639 | int mana_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl); |
| 640 | |
| 641 | struct ib_mr *mana_ib_get_dma_mr(struct ib_pd *ibpd, int access_flags); |
| 642 | |
| 643 | struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, |
| 644 | u64 iova, int access_flags, |
| 645 | struct ib_dmah *dmah, |
| 646 | struct ib_udata *udata); |
| 647 | |
| 648 | int mana_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata); |
| 649 | |
| 650 | int mana_ib_create_qp(struct ib_qp *qp, struct ib_qp_init_attr *qp_init_attr, |
| 651 | struct ib_udata *udata); |
| 652 | |
| 653 | int mana_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 654 | int attr_mask, struct ib_udata *udata); |
| 655 | |
| 656 | int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata); |
| 657 | |
| 658 | int mana_ib_cfg_vport(struct mana_ib_dev *dev, u32 port_id, |
| 659 | struct mana_ib_pd *pd, u32 doorbell_id); |
| 660 | void mana_ib_uncfg_vport(struct mana_ib_dev *dev, struct mana_ib_pd *pd, |
| 661 | u32 port); |
| 662 | |
| 663 | int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, |
| 664 | struct uverbs_attr_bundle *attrs); |
| 665 | |
| 666 | int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata); |
| 667 | |
| 668 | int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata); |
| 669 | int mana_ib_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata); |
| 670 | |
| 671 | int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontext, |
| 672 | struct ib_udata *udata); |
| 673 | void mana_ib_dealloc_ucontext(struct ib_ucontext *ibcontext); |
| 674 | |
| 675 | int mana_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma); |
| 676 | |
| 677 | int mana_ib_get_port_immutable(struct ib_device *ibdev, u32 port_num, |
| 678 | struct ib_port_immutable *immutable); |
| 679 | int mana_ib_query_device(struct ib_device *ibdev, struct ib_device_attr *props, |
| 680 | struct ib_udata *uhw); |
| 681 | int mana_ib_query_port(struct ib_device *ibdev, u32 port, |
| 682 | struct ib_port_attr *props); |
| 683 | int mana_ib_query_gid(struct ib_device *ibdev, u32 port, int index, |
| 684 | union ib_gid *gid); |
| 685 | |
| 686 | void mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext); |
| 687 | |
| 688 | int mana_ib_gd_query_adapter_caps(struct mana_ib_dev *mdev); |
| 689 | int mana_eth_query_adapter_caps(struct mana_ib_dev *mdev); |
| 690 | |
| 691 | int mana_ib_create_eqs(struct mana_ib_dev *mdev); |
| 692 | |
| 693 | void mana_ib_destroy_eqs(struct mana_ib_dev *mdev); |
| 694 | |
| 695 | int mana_ib_gd_create_rnic_adapter(struct mana_ib_dev *mdev); |
| 696 | |
| 697 | int mana_ib_gd_destroy_rnic_adapter(struct mana_ib_dev *mdev); |
| 698 | |
| 699 | int mana_ib_query_pkey(struct ib_device *ibdev, u32 port, u16 index, u16 *pkey); |
| 700 | |
| 701 | enum rdma_link_layer mana_ib_get_link_layer(struct ib_device *device, u32 port_num); |
| 702 | |
| 703 | int mana_ib_gd_add_gid(const struct ib_gid_attr *attr, void **context); |
| 704 | |
| 705 | int mana_ib_gd_del_gid(const struct ib_gid_attr *attr, void **context); |
| 706 | |
| 707 | int mana_ib_gd_config_mac(struct mana_ib_dev *mdev, enum mana_ib_addr_op op, u8 *mac); |
| 708 | |
| 709 | int mana_ib_gd_create_cq(struct mana_ib_dev *mdev, struct mana_ib_cq *cq, u32 doorbell); |
| 710 | |
| 711 | int mana_ib_gd_destroy_cq(struct mana_ib_dev *mdev, struct mana_ib_cq *cq); |
| 712 | |
| 713 | int mana_ib_gd_create_rc_qp(struct mana_ib_dev *mdev, struct mana_ib_qp *qp, |
| 714 | struct ib_qp_init_attr *attr, u32 doorbell, u64 flags); |
| 715 | int mana_ib_gd_destroy_rc_qp(struct mana_ib_dev *mdev, struct mana_ib_qp *qp); |
| 716 | |
| 717 | int mana_ib_gd_create_ud_qp(struct mana_ib_dev *mdev, struct mana_ib_qp *qp, |
| 718 | struct ib_qp_init_attr *attr, u32 doorbell, u32 type); |
| 719 | int mana_ib_gd_destroy_ud_qp(struct mana_ib_dev *mdev, struct mana_ib_qp *qp); |
| 720 | |
| 721 | int mana_ib_create_ah(struct ib_ah *ibah, struct rdma_ah_init_attr *init_attr, |
| 722 | struct ib_udata *udata); |
| 723 | int mana_ib_destroy_ah(struct ib_ah *ah, u32 flags); |
| 724 | |
| 725 | int mana_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, |
| 726 | const struct ib_recv_wr **bad_wr); |
| 727 | int mana_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, |
| 728 | const struct ib_send_wr **bad_wr); |
| 729 | |
| 730 | void mana_drain_gsi_sqs(struct mana_ib_dev *mdev); |
| 731 | int mana_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc); |
| 732 | int mana_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags); |
| 733 | |
| 734 | struct ib_mr *mana_ib_reg_user_mr_dmabuf(struct ib_pd *ibpd, u64 start, u64 length, |
| 735 | u64 iova, int fd, int mr_access_flags, |
| 736 | struct ib_dmah *dmah, |
| 737 | struct uverbs_attr_bundle *attrs); |
| 738 | #endif |
| 739 | |