2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 * $Id: mthca.h 4182 2005-11-28 21:14:30Z roland $
39 #include <cl_spinlock.h>
40 #include <mlnx_uvp_verbs.h>
42 #include "mlnx_uvp_debug.h"
52 MTHCA_CQ_ENTRY_SIZE = 0x20
56 MTHCA_QP_TABLE_BITS = 8,
57 MTHCA_QP_TABLE_SIZE = 1 << MTHCA_QP_TABLE_BITS,
58 MTHCA_QP_TABLE_MASK = MTHCA_QP_TABLE_SIZE - 1
62 MTHCA_DB_REC_PAGE_SIZE = 4096,
63 MTHCA_DB_REC_PER_PAGE = MTHCA_DB_REC_PAGE_SIZE / 8
67 MTHCA_DB_TYPE_INVALID = 0x0,
68 MTHCA_DB_TYPE_CQ_SET_CI = 0x1,
69 MTHCA_DB_TYPE_CQ_ARM = 0x2,
70 MTHCA_DB_TYPE_SQ = 0x3,
71 MTHCA_DB_TYPE_RQ = 0x4,
72 MTHCA_DB_TYPE_SRQ = 0x5,
73 MTHCA_DB_TYPE_GROUP_SEP = 0x7
77 MTHCA_OPCODE_NOP = 0x00,
78 MTHCA_OPCODE_RDMA_WRITE = 0x08,
79 MTHCA_OPCODE_RDMA_WRITE_IMM = 0x09,
80 MTHCA_OPCODE_SEND = 0x0a,
81 MTHCA_OPCODE_SEND_IMM = 0x0b,
82 MTHCA_OPCODE_RDMA_READ = 0x10,
83 MTHCA_OPCODE_ATOMIC_CS = 0x11,
84 MTHCA_OPCODE_ATOMIC_FA = 0x12,
85 MTHCA_OPCODE_BIND_MW = 0x18,
86 MTHCA_OPCODE_INVALID = 0xff
91 struct mthca_db_table;
93 struct mthca_context {
94 struct ibv_context ibv_ctx;
96 cl_spinlock_t uar_lock;
97 struct mthca_db_table *db_tab;
100 struct mthca_qp **table;
102 } qp_table[MTHCA_QP_TABLE_SIZE];
103 HANDLE qp_table_mutex;
107 enum mthca_hca_type hca_type;
111 struct ibv_pd ibv_pd;
112 struct mthca_ah_page *ah_list;
118 struct ibv_cq ibv_cq;
125 /* Next fields are mem-free only */
131 uint32_t *p_u_arm_sn;
135 struct ibv_srq ibv_srq;
149 /* Next fields are mem-free only */
166 /* Next fields are mem-free only */
172 struct ibv_qp ibv_qp;
193 uint32_t sl_tclass_flowlabel;
199 ib_av_attr_t av_attr;
200 ib_pd_handle_t h_uvp_pd;
201 struct mthca_ah_page *page;
205 struct mthca_ah_page {
206 struct mthca_ah_page *prev, *next;
213 static inline unsigned long align(unsigned long val, unsigned long align)
215 return (val + align - 1) & ~(align - 1);
218 static inline uintptr_t db_align(uint32_t *db)
220 return (uintptr_t) db & ~((uintptr_t) MTHCA_DB_REC_PAGE_SIZE - 1);
223 #define to_mxxx(xxx, type) \
224 ((struct mthca_##type *) \
225 ((uint8_t *) ib##xxx - offsetof(struct mthca_##type, ibv_##xxx)))
227 static inline struct mthca_context *to_mctx(struct ibv_context *ibctx)
229 return to_mxxx(ctx, context);
232 static inline struct mthca_pd *to_mpd(struct ibv_pd *ibpd)
234 return to_mxxx(pd, pd);
237 static inline struct mthca_cq *to_mcq(struct ibv_cq *ibcq)
239 return to_mxxx(cq, cq);
242 static inline struct mthca_srq *to_msrq(struct ibv_srq *ibsrq)
244 return to_mxxx(srq, srq);
247 static inline struct mthca_qp *to_mqp(struct ibv_qp *ibqp)
249 return to_mxxx(qp, qp);
252 static inline int mthca_is_memfree(struct ibv_context *ibctx)
254 return to_mctx(ibctx)->hca_type == MTHCA_ARBEL;
257 int mthca_alloc_db(struct mthca_db_table *db_tab, enum mthca_db_type type,
259 void mthca_set_db_qn(uint32_t *db, enum mthca_db_type type, uint32_t qn);
260 void mthca_free_db(struct mthca_db_table *db_tab, enum mthca_db_type type, int db_index);
261 struct mthca_db_table *mthca_alloc_db_tab(int uarc_size);
262 void mthca_free_db_tab(struct mthca_db_table *db_tab);
264 int mthca_query_device(struct ibv_context *context,
265 struct ibv_device_attr *attr);
266 int mthca_query_port(struct ibv_context *context, uint8_t port,
267 struct ibv_port_attr *attr);
269 struct ibv_pd *mthca_alloc_pd(struct ibv_context *context,
270 struct ibv_alloc_pd_resp *resp_p);
272 int mthca_free_pd(struct ibv_pd *pd);
274 struct ibv_cq *mthca_create_cq_pre(struct ibv_context *context, int *cqe,
275 struct ibv_create_cq *req);
276 struct ibv_cq *mthca_create_cq_post(struct ibv_context *context,
277 struct ibv_create_cq_resp *resp);
278 int mthca_destroy_cq(struct ibv_cq *cq);
279 int mthca_poll_cq(struct ibv_cq *cq, int ne, struct _ib_wc *wc);
280 int mthca_poll_cq_list(struct ibv_cq *ibcq,
281 struct _ib_wc** const pp_free_wclist,
282 struct _ib_wc** const pp_done_wclist );
283 int mthca_tavor_arm_cq(struct ibv_cq *cq, int solicited);
284 int mthca_arbel_arm_cq(struct ibv_cq *cq, int solicited);
285 void mthca_cq_clean(struct mthca_cq *cq, uint32_t qpn,
286 struct mthca_srq *srq);
287 void mthca_init_cq_buf(struct mthca_cq *cq, int nent);
289 struct ibv_srq *mthca_create_srq(struct ibv_pd *pd,
290 struct ibv_srq_init_attr *attr);
291 int mthca_modify_srq(struct ibv_srq *srq,
292 struct ibv_srq_attr *attr,
293 enum ibv_srq_attr_mask mask);
294 int mthca_destroy_srq(struct ibv_srq *srq);
295 int mthca_alloc_srq_buf(struct ibv_pd *pd, struct ibv_srq_attr *attr,
296 struct mthca_srq *srq);
297 void mthca_free_srq_wqe(struct mthca_srq *srq, int ind);
298 int mthca_tavor_post_srq_recv(struct ibv_srq *ibsrq,
299 struct _ib_recv_wr *wr,
300 struct _ib_recv_wr **bad_wr);
301 int mthca_arbel_post_srq_recv(struct ibv_srq *ibsrq,
302 struct _ib_recv_wr *wr,
303 struct _ib_recv_wr **bad_wr);
304 struct ibv_qp *mthca_create_qp_pre(struct ibv_pd *pd,
305 struct ibv_qp_init_attr *attr, struct ibv_create_qp *req);
306 struct ibv_qp *mthca_create_qp_post(struct ibv_pd *pd,
307 struct ibv_create_qp_resp *resp);
308 int mthca_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
309 enum ibv_qp_attr_mask attr_mask);
310 int mthca_destroy_qp(struct ibv_qp *qp);
311 void mthca_init_qp_indices(struct mthca_qp *qp);
312 int mthca_tavor_post_send(struct ibv_qp *ibqp, struct _ib_send_wr *wr,
313 struct _ib_send_wr **bad_wr);
314 int mthca_tavor_post_recv(struct ibv_qp *ibqp, struct _ib_recv_wr *wr,
315 struct _ib_recv_wr **bad_wr);
316 int mthca_arbel_post_send(struct ibv_qp *ibqp, struct _ib_send_wr *wr,
317 struct _ib_send_wr **bad_wr);
318 int mthca_arbel_post_recv(struct ibv_qp *ibqp, struct _ib_recv_wr *wr,
319 struct _ib_recv_wr **bad_wr);
320 int mthca_alloc_qp_buf(struct ibv_pd *pd, struct ibv_qp_cap *cap,
321 ib_qp_type_t type, struct mthca_qp *qp);
322 struct mthca_qp *mthca_find_qp(struct mthca_context *ctx, uint32_t qpn);
323 int mthca_store_qp(struct mthca_context *ctx, uint32_t qpn, struct mthca_qp *qp);
324 void mthca_clear_qp(struct mthca_context *ctx, uint32_t qpn);
325 int mthca_free_err_wqe(struct mthca_qp *qp, int is_send,
326 int index, int *dbd, uint32_t *new_wqe);
327 int mthca_alloc_av(struct mthca_pd *pd, struct ibv_ah_attr *attr,
328 struct mthca_ah *ah, struct ibv_create_ah_resp *resp);
329 void mthca_free_av(struct mthca_ah *ah);
330 int mthca_attach_mcast(struct ibv_qp *qp, union ibv_gid *gid, uint16_t lid);
331 int mthca_detach_mcast(struct ibv_qp *qp, union ibv_gid *gid, uint16_t lid);
332 struct ibv_context *mthca_alloc_context(struct ibv_get_context_resp *resp_p);
333 void mthca_free_context(struct ibv_context *ibctx);