Loading...
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
15#include <net/mana/mana.h>
16
17#define PAGE_SZ_BM \
18 (SZ_4K | SZ_8K | SZ_16K | SZ_32K | SZ_64K | SZ_128K | SZ_256K | \
19 SZ_512K | SZ_1M | SZ_2M)
20
21/* MANA doesn't have any limit for MR size */
22#define MANA_IB_MAX_MR_SIZE U64_MAX
23
24/*
25 * The hardware limit of number of MRs is greater than maximum number of MRs
26 * that can possibly represent in 24 bits
27 */
28#define MANA_IB_MAX_MR 0xFFFFFFu
29
30struct mana_ib_adapter_caps {
31 u32 max_sq_id;
32 u32 max_rq_id;
33 u32 max_cq_id;
34 u32 max_qp_count;
35 u32 max_cq_count;
36 u32 max_mr_count;
37 u32 max_pd_count;
38 u32 max_inbound_read_limit;
39 u32 max_outbound_read_limit;
40 u32 mw_count;
41 u32 max_srq_count;
42 u32 max_qp_wr;
43 u32 max_send_sge_count;
44 u32 max_recv_sge_count;
45 u32 max_inline_data_size;
46};
47
48struct mana_ib_dev {
49 struct ib_device ib_dev;
50 struct gdma_dev *gdma_dev;
51 struct mana_ib_adapter_caps adapter_caps;
52};
53
54struct mana_ib_wq {
55 struct ib_wq ibwq;
56 struct ib_umem *umem;
57 int wqe;
58 u32 wq_buf_size;
59 u64 gdma_region;
60 u64 id;
61 mana_handle_t rx_object;
62};
63
64struct mana_ib_pd {
65 struct ib_pd ibpd;
66 u32 pdn;
67 mana_handle_t pd_handle;
68
69 /* Mutex for sharing access to vport_use_count */
70 struct mutex vport_mutex;
71 int vport_use_count;
72
73 bool tx_shortform_allowed;
74 u32 tx_vp_offset;
75};
76
77struct mana_ib_mr {
78 struct ib_mr ibmr;
79 struct ib_umem *umem;
80 mana_handle_t mr_handle;
81};
82
83struct mana_ib_cq {
84 struct ib_cq ibcq;
85 struct ib_umem *umem;
86 int cqe;
87 u64 gdma_region;
88 u64 id;
89 u32 comp_vector;
90};
91
92struct mana_ib_qp {
93 struct ib_qp ibqp;
94
95 /* Work queue info */
96 struct ib_umem *sq_umem;
97 int sqe;
98 u64 sq_gdma_region;
99 u64 sq_id;
100 mana_handle_t tx_object;
101
102 /* The port on the IB device, starting with 1 */
103 u32 port;
104};
105
106struct mana_ib_ucontext {
107 struct ib_ucontext ibucontext;
108 u32 doorbell;
109};
110
111struct mana_ib_rwq_ind_table {
112 struct ib_rwq_ind_table ib_ind_table;
113};
114
115enum mana_ib_command_code {
116 MANA_IB_GET_ADAPTER_CAP = 0x30001,
117};
118
119struct mana_ib_query_adapter_caps_req {
120 struct gdma_req_hdr hdr;
121}; /*HW Data */
122
123struct mana_ib_query_adapter_caps_resp {
124 struct gdma_resp_hdr hdr;
125 u32 max_sq_id;
126 u32 max_rq_id;
127 u32 max_cq_id;
128 u32 max_qp_count;
129 u32 max_cq_count;
130 u32 max_mr_count;
131 u32 max_pd_count;
132 u32 max_inbound_read_limit;
133 u32 max_outbound_read_limit;
134 u32 mw_count;
135 u32 max_srq_count;
136 u32 max_requester_sq_size;
137 u32 max_responder_sq_size;
138 u32 max_requester_rq_size;
139 u32 max_responder_rq_size;
140 u32 max_send_sge_count;
141 u32 max_recv_sge_count;
142 u32 max_inline_data_size;
143}; /* HW Data */
144
145int mana_ib_gd_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
146 mana_handle_t *gdma_region);
147
148int mana_ib_gd_destroy_dma_region(struct mana_ib_dev *dev,
149 mana_handle_t gdma_region);
150
151struct ib_wq *mana_ib_create_wq(struct ib_pd *pd,
152 struct ib_wq_init_attr *init_attr,
153 struct ib_udata *udata);
154
155int mana_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr,
156 u32 wq_attr_mask, struct ib_udata *udata);
157
158int mana_ib_destroy_wq(struct ib_wq *ibwq, struct ib_udata *udata);
159
160int mana_ib_create_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_table,
161 struct ib_rwq_ind_table_init_attr *init_attr,
162 struct ib_udata *udata);
163
164int mana_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl);
165
166struct ib_mr *mana_ib_get_dma_mr(struct ib_pd *ibpd, int access_flags);
167
168struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
169 u64 iova, int access_flags,
170 struct ib_udata *udata);
171
172int mana_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata);
173
174int mana_ib_create_qp(struct ib_qp *qp, struct ib_qp_init_attr *qp_init_attr,
175 struct ib_udata *udata);
176
177int mana_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
178 int attr_mask, struct ib_udata *udata);
179
180int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata);
181
182int mana_ib_cfg_vport(struct mana_ib_dev *dev, u32 port_id,
183 struct mana_ib_pd *pd, u32 doorbell_id);
184void mana_ib_uncfg_vport(struct mana_ib_dev *dev, struct mana_ib_pd *pd,
185 u32 port);
186
187int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
188 struct ib_udata *udata);
189
190int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata);
191
192int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata);
193int mana_ib_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata);
194
195int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontext,
196 struct ib_udata *udata);
197void mana_ib_dealloc_ucontext(struct ib_ucontext *ibcontext);
198
199int mana_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma);
200
201int mana_ib_get_port_immutable(struct ib_device *ibdev, u32 port_num,
202 struct ib_port_immutable *immutable);
203int mana_ib_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
204 struct ib_udata *uhw);
205int mana_ib_query_port(struct ib_device *ibdev, u32 port,
206 struct ib_port_attr *props);
207int mana_ib_query_gid(struct ib_device *ibdev, u32 port, int index,
208 union ib_gid *gid);
209
210void mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext);
211
212int mana_ib_gd_query_adapter_caps(struct mana_ib_dev *mdev);
213
214void mana_ib_cq_handler(void *ctx, struct gdma_queue *gdma_cq);
215#endif
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
15#include <net/mana/mana.h>
16
17#define PAGE_SZ_BM \
18 (SZ_4K | SZ_8K | SZ_16K | SZ_32K | SZ_64K | SZ_128K | SZ_256K | \
19 SZ_512K | SZ_1M | SZ_2M)
20
21/* MANA doesn't have any limit for MR size */
22#define MANA_IB_MAX_MR_SIZE U64_MAX
23
24/*
25 * The hardware limit of number of MRs is greater than maximum number of MRs
26 * that can possibly represent in 24 bits
27 */
28#define MANA_IB_MAX_MR 0xFFFFFFu
29
30struct mana_ib_adapter_caps {
31 u32 max_sq_id;
32 u32 max_rq_id;
33 u32 max_cq_id;
34 u32 max_qp_count;
35 u32 max_cq_count;
36 u32 max_mr_count;
37 u32 max_pd_count;
38 u32 max_inbound_read_limit;
39 u32 max_outbound_read_limit;
40 u32 mw_count;
41 u32 max_srq_count;
42 u32 max_qp_wr;
43 u32 max_send_sge_count;
44 u32 max_recv_sge_count;
45 u32 max_inline_data_size;
46};
47
48struct mana_ib_queue {
49 struct ib_umem *umem;
50 u64 gdma_region;
51 u64 id;
52};
53
54struct mana_ib_dev {
55 struct ib_device ib_dev;
56 struct gdma_dev *gdma_dev;
57 struct mana_ib_adapter_caps adapter_caps;
58};
59
60struct mana_ib_wq {
61 struct ib_wq ibwq;
62 struct ib_umem *umem;
63 int wqe;
64 u32 wq_buf_size;
65 u64 gdma_region;
66 u64 id;
67 mana_handle_t rx_object;
68};
69
70struct mana_ib_pd {
71 struct ib_pd ibpd;
72 u32 pdn;
73 mana_handle_t pd_handle;
74
75 /* Mutex for sharing access to vport_use_count */
76 struct mutex vport_mutex;
77 int vport_use_count;
78
79 bool tx_shortform_allowed;
80 u32 tx_vp_offset;
81};
82
83struct mana_ib_mr {
84 struct ib_mr ibmr;
85 struct ib_umem *umem;
86 mana_handle_t mr_handle;
87};
88
89struct mana_ib_cq {
90 struct ib_cq ibcq;
91 struct mana_ib_queue queue;
92 int cqe;
93 u32 comp_vector;
94};
95
96struct mana_ib_qp {
97 struct ib_qp ibqp;
98
99 /* Work queue info */
100 struct ib_umem *sq_umem;
101 int sqe;
102 u64 sq_gdma_region;
103 u64 sq_id;
104 mana_handle_t tx_object;
105
106 /* The port on the IB device, starting with 1 */
107 u32 port;
108};
109
110struct mana_ib_ucontext {
111 struct ib_ucontext ibucontext;
112 u32 doorbell;
113};
114
115struct mana_ib_rwq_ind_table {
116 struct ib_rwq_ind_table ib_ind_table;
117};
118
119enum mana_ib_command_code {
120 MANA_IB_GET_ADAPTER_CAP = 0x30001,
121};
122
123struct mana_ib_query_adapter_caps_req {
124 struct gdma_req_hdr hdr;
125}; /*HW Data */
126
127struct mana_ib_query_adapter_caps_resp {
128 struct gdma_resp_hdr hdr;
129 u32 max_sq_id;
130 u32 max_rq_id;
131 u32 max_cq_id;
132 u32 max_qp_count;
133 u32 max_cq_count;
134 u32 max_mr_count;
135 u32 max_pd_count;
136 u32 max_inbound_read_limit;
137 u32 max_outbound_read_limit;
138 u32 mw_count;
139 u32 max_srq_count;
140 u32 max_requester_sq_size;
141 u32 max_responder_sq_size;
142 u32 max_requester_rq_size;
143 u32 max_responder_rq_size;
144 u32 max_send_sge_count;
145 u32 max_recv_sge_count;
146 u32 max_inline_data_size;
147}; /* HW Data */
148
149static inline struct gdma_context *mdev_to_gc(struct mana_ib_dev *mdev)
150{
151 return mdev->gdma_dev->gdma_context;
152}
153
154static inline struct net_device *mana_ib_get_netdev(struct ib_device *ibdev, u32 port)
155{
156 struct mana_ib_dev *mdev = container_of(ibdev, struct mana_ib_dev, ib_dev);
157 struct gdma_context *gc = mdev_to_gc(mdev);
158 struct mana_context *mc = gc->mana.driver_data;
159
160 if (port < 1 || port > mc->num_ports)
161 return NULL;
162 return mc->ports[port - 1];
163}
164
165int mana_ib_install_cq_cb(struct mana_ib_dev *mdev, struct mana_ib_cq *cq);
166
167int mana_ib_create_zero_offset_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
168 mana_handle_t *gdma_region);
169
170int mana_ib_create_dma_region(struct mana_ib_dev *dev, struct ib_umem *umem,
171 mana_handle_t *gdma_region, u64 virt);
172
173int mana_ib_gd_destroy_dma_region(struct mana_ib_dev *dev,
174 mana_handle_t gdma_region);
175
176int mana_ib_create_queue(struct mana_ib_dev *mdev, u64 addr, u32 size,
177 struct mana_ib_queue *queue);
178void mana_ib_destroy_queue(struct mana_ib_dev *mdev, struct mana_ib_queue *queue);
179
180struct ib_wq *mana_ib_create_wq(struct ib_pd *pd,
181 struct ib_wq_init_attr *init_attr,
182 struct ib_udata *udata);
183
184int mana_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr,
185 u32 wq_attr_mask, struct ib_udata *udata);
186
187int mana_ib_destroy_wq(struct ib_wq *ibwq, struct ib_udata *udata);
188
189int mana_ib_create_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_table,
190 struct ib_rwq_ind_table_init_attr *init_attr,
191 struct ib_udata *udata);
192
193int mana_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl);
194
195struct ib_mr *mana_ib_get_dma_mr(struct ib_pd *ibpd, int access_flags);
196
197struct ib_mr *mana_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
198 u64 iova, int access_flags,
199 struct ib_udata *udata);
200
201int mana_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata);
202
203int mana_ib_create_qp(struct ib_qp *qp, struct ib_qp_init_attr *qp_init_attr,
204 struct ib_udata *udata);
205
206int mana_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
207 int attr_mask, struct ib_udata *udata);
208
209int mana_ib_destroy_qp(struct ib_qp *ibqp, struct ib_udata *udata);
210
211int mana_ib_cfg_vport(struct mana_ib_dev *dev, u32 port_id,
212 struct mana_ib_pd *pd, u32 doorbell_id);
213void mana_ib_uncfg_vport(struct mana_ib_dev *dev, struct mana_ib_pd *pd,
214 u32 port);
215
216int mana_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
217 struct ib_udata *udata);
218
219int mana_ib_destroy_cq(struct ib_cq *ibcq, struct ib_udata *udata);
220
221int mana_ib_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata);
222int mana_ib_dealloc_pd(struct ib_pd *ibpd, struct ib_udata *udata);
223
224int mana_ib_alloc_ucontext(struct ib_ucontext *ibcontext,
225 struct ib_udata *udata);
226void mana_ib_dealloc_ucontext(struct ib_ucontext *ibcontext);
227
228int mana_ib_mmap(struct ib_ucontext *ibcontext, struct vm_area_struct *vma);
229
230int mana_ib_get_port_immutable(struct ib_device *ibdev, u32 port_num,
231 struct ib_port_immutable *immutable);
232int mana_ib_query_device(struct ib_device *ibdev, struct ib_device_attr *props,
233 struct ib_udata *uhw);
234int mana_ib_query_port(struct ib_device *ibdev, u32 port,
235 struct ib_port_attr *props);
236int mana_ib_query_gid(struct ib_device *ibdev, u32 port, int index,
237 union ib_gid *gid);
238
239void mana_ib_disassociate_ucontext(struct ib_ucontext *ibcontext);
240
241int mana_ib_gd_query_adapter_caps(struct mana_ib_dev *mdev);
242#endif