162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2022 Microsoft Corporation. All rights reserved. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef _MANA_IB_H_ 762306a36Sopenharmony_ci#define _MANA_IB_H_ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <rdma/ib_verbs.h> 1062306a36Sopenharmony_ci#include <rdma/ib_mad.h> 1162306a36Sopenharmony_ci#include <rdma/ib_umem.h> 1262306a36Sopenharmony_ci#include <rdma/mana-abi.h> 1362306a36Sopenharmony_ci#include <rdma/uverbs_ioctl.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include <net/mana/mana.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#define PAGE_SZ_BM \ 1862306a36Sopenharmony_ci (SZ_4K | SZ_8K | SZ_16K | SZ_32K | SZ_64K | SZ_128K | SZ_256K | \ 1962306a36Sopenharmony_ci SZ_512K | SZ_1M | SZ_2M) 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci/* MANA doesn't have any limit for MR size */ 2262306a36Sopenharmony_ci#define MANA_IB_MAX_MR_SIZE U64_MAX 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci/* 2562306a36Sopenharmony_ci * The hardware limit of number of MRs is greater than maximum number of MRs 2662306a36Sopenharmony_ci * that can possibly represent in 24 bits 2762306a36Sopenharmony_ci */ 2862306a36Sopenharmony_ci#define MANA_IB_MAX_MR 0xFFFFFFu 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_cistruct mana_ib_dev { 3162306a36Sopenharmony_ci struct ib_device ib_dev; 3262306a36Sopenharmony_ci struct gdma_dev *gdma_dev; 3362306a36Sopenharmony_ci}; 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_cistruct mana_ib_wq { 3662306a36Sopenharmony_ci struct ib_wq ibwq; 3762306a36Sopenharmony_ci struct ib_umem *umem; 3862306a36Sopenharmony_ci int wqe; 3962306a36Sopenharmony_ci u32 wq_buf_size; 4062306a36Sopenharmony_ci u64 gdma_region; 4162306a36Sopenharmony_ci u64 id; 4262306a36Sopenharmony_ci mana_handle_t rx_object; 4362306a36Sopenharmony_ci}; 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_cistruct mana_ib_pd { 4662306a36Sopenharmony_ci struct ib_pd ibpd; 4762306a36Sopenharmony_ci u32 pdn; 4862306a36Sopenharmony_ci mana_handle_t pd_handle; 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci /* Mutex for sharing access to vport_use_count */ 5162306a36Sopenharmony_ci struct mutex vport_mutex; 5262306a36Sopenharmony_ci int vport_use_count; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci bool tx_shortform_allowed; 5562306a36Sopenharmony_ci u32 tx_vp_offset; 5662306a36Sopenharmony_ci}; 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_cistruct mana_ib_mr { 5962306a36Sopenharmony_ci struct ib_mr ibmr; 6062306a36Sopenharmony_ci struct ib_umem *umem; 6162306a36Sopenharmony_ci mana_handle_t mr_handle; 6262306a36Sopenharmony_ci}; 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_cistruct mana_ib_cq { 6562306a36Sopenharmony_ci struct ib_cq ibcq; 6662306a36Sopenharmony_ci struct ib_umem *umem; 6762306a36Sopenharmony_ci int cqe; 6862306a36Sopenharmony_ci u64 gdma_region; 6962306a36Sopenharmony_ci u64 id; 7062306a36Sopenharmony_ci}; 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_cistruct mana_ib_qp { 7362306a36Sopenharmony_ci struct ib_qp ibqp; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci /* Work queue info */ 7662306a36Sopenharmony_ci struct ib_umem *sq_umem; 7762306a36Sopenharmony_ci int sqe; 7862306a36Sopenharmony_ci u64 sq_gdma_region; 7962306a36Sopenharmony_ci u64 sq_id; 8062306a36Sopenharmony_ci mana_handle_t tx_object; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci /* The port on the IB device, starting with 1 */ 8362306a36Sopenharmony_ci u32 port; 8462306a36Sopenharmony_ci}; 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_cistruct mana_ib_ucontext { 8762306a36Sopenharmony_ci struct ib_ucontext ibucontext; 8862306a36Sopenharmony_ci u32 doorbell; 8962306a36Sopenharmony_ci}; 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_cistruct mana_ib_rwq_ind_table { 9262306a36Sopenharmony_ci struct ib_rwq_ind_table ib_ind_table; 9362306a36Sopenharmony_ci}; 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ciint mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem, 9662306a36Sopenharmony_ci mana_handle_t *gdma_region); 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ciint mana_ib_gd_destroy_dma_region(struct mana_ib_dev *dev, 9962306a36Sopenharmony_ci mana_handle_t gdma_region); 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_cistruct ib_wq *mana_ib_create_wq(struct ib_pd *pd, 10262306a36Sopenharmony_ci struct ib_wq_init_attr *init_attr, 10362306a36Sopenharmony_ci struct ib_udata *udata); 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ciint mana_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr, 10662306a36Sopenharmony_ci u32 wq_attr_mask, struct ib_udata *udata); 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ciint mana_ib_destroy_wq(struct ib_wq *ibwq, struct ib_udata *udata); 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ciint mana_ib_create_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_table, 11162306a36Sopenharmony_ci struct ib_rwq_ind_table_init_attr *init_attr, 11262306a36Sopenharmony_ci struct ib_udata *udata); 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ciint mana_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl); 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_cistruct ib_mr *mana_ib_get_dma_mr(struct ib_pd *ibpd, int access_flags); 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_cistruct ib_mr *mana_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, 11962306a36Sopenharmony_ci u64 iova, int access_flags, 12062306a36Sopenharmony_ci struct ib_udata *udata); 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ciint mana_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata); 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ciint mana_ib_create_qp(struct ib_qp *qp, struct ib_qp_init_attr *qp_init_attr, 12562306a36Sopenharmony_ci struct ib_udata *udata); 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ciint mana_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 12862306a36Sopenharmony_ci int attr_mask, struct ib_udata *udata); 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ciint mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata); 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ciint mana_ib_cfg_vport(struct mana_ib_dev *dev, u32 port_id, 13362306a36Sopenharmony_ci struct mana_ib_pd *pd, u32 doorbell_id); 13462306a36Sopenharmony_civoid mana_ib_uncfg_vport(struct mana_ib_dev *dev, struct mana_ib_pd *pd, 13562306a36Sopenharmony_ci u32 port); 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ciint mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, 13862306a36Sopenharmony_ci struct ib_udata *udata); 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ciint mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata); 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ciint mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata); 14362306a36Sopenharmony_ciint mana_ib_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata); 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ciint mana_ib_alloc_ucontext(struct ib_ucontext *ibcontext, 14662306a36Sopenharmony_ci struct ib_udata *udata); 14762306a36Sopenharmony_civoid mana_ib_dealloc_ucontext(struct ib_ucontext *ibcontext); 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ciint mana_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma); 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ciint mana_ib_get_port_immutable(struct ib_device *ibdev, u32 port_num, 15262306a36Sopenharmony_ci struct ib_port_immutable *immutable); 15362306a36Sopenharmony_ciint mana_ib_query_device(struct ib_device *ibdev, struct ib_device_attr *props, 15462306a36Sopenharmony_ci struct ib_udata *uhw); 15562306a36Sopenharmony_ciint mana_ib_query_port(struct ib_device *ibdev, u32 port, 15662306a36Sopenharmony_ci struct ib_port_attr *props); 15762306a36Sopenharmony_ciint mana_ib_query_gid(struct ib_device *ibdev, u32 port, int index, 15862306a36Sopenharmony_ci union ib_gid *gid); 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_civoid mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext); 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci#endif 163