2 * Copyright (c) 2006-2016 Chelsio, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40 #include <sys/errno.h>
42 #include <infiniband/driver.h>
43 #include <infiniband/udma_barrier.h>
44 #include <sys/queue.h>
47 extern unsigned long c4iw_page_size;
48 extern unsigned long c4iw_page_shift;
49 extern unsigned long c4iw_page_mask;
54 struct verbs_device ibv_dev;
55 unsigned chip_version;
57 struct c4iw_mr **mmid2ptr;
59 struct c4iw_qp **qpid2ptr;
61 struct c4iw_cq **cqid2ptr;
62 pthread_spinlock_t lock;
63 TAILQ_ENTRY(c4iw_dev) list;
67 static inline int dev_is_t6(struct c4iw_dev *dev)
69 return dev->chip_version == CHELSIO_T6;
72 static inline int dev_is_t5(struct c4iw_dev *dev)
74 return dev->chip_version == CHELSIO_T5;
77 static inline int dev_is_t4(struct c4iw_dev *dev)
79 return dev->chip_version == CHELSIO_T4;
83 struct ibv_context ibv_ctx;
84 struct t4_dev_status_page *status_page;
98 static inline u32 c4iw_mmid(u32 stag)
104 struct ibv_cq ibv_cq;
105 struct c4iw_dev *rhp;
107 pthread_spinlock_t lock;
108 #ifdef STALL_DETECTION
115 struct ibv_qp ibv_qp;
116 struct c4iw_dev *rhp;
118 pthread_spinlock_t lock;
122 #define to_c4iw_xxx(xxx, type) \
123 ((struct c4iw_##type *) \
124 ((void *) ib##xxx - offsetof(struct c4iw_##type, ibv_##xxx)))
126 static inline struct c4iw_dev *to_c4iw_dev(struct ibv_device *ibdev)
128 return to_c4iw_xxx(dev, dev);
131 static inline struct c4iw_context *to_c4iw_context(struct ibv_context *ibctx)
133 return to_c4iw_xxx(ctx, context);
136 static inline struct c4iw_pd *to_c4iw_pd(struct ibv_pd *ibpd)
138 return to_c4iw_xxx(pd, pd);
141 static inline struct c4iw_cq *to_c4iw_cq(struct ibv_cq *ibcq)
143 return to_c4iw_xxx(cq, cq);
146 static inline struct c4iw_qp *to_c4iw_qp(struct ibv_qp *ibqp)
148 return to_c4iw_xxx(qp, qp);
151 static inline struct c4iw_mr *to_c4iw_mr(struct ibv_mr *ibmr)
153 return to_c4iw_xxx(mr, mr);
156 static inline struct c4iw_qp *get_qhp(struct c4iw_dev *rhp, u32 qid)
158 return rhp->qpid2ptr[qid];
161 static inline struct c4iw_cq *get_chp(struct c4iw_dev *rhp, u32 qid)
163 return rhp->cqid2ptr[qid];
166 static inline unsigned long_log2(unsigned long x)
169 for (x >>= 1; x > 0; x >>= 1)
174 int c4iw_query_device(struct ibv_context *context,
175 struct ibv_device_attr *attr);
176 int c4iw_query_port(struct ibv_context *context, uint8_t port,
177 struct ibv_port_attr *attr);
179 struct ibv_pd *c4iw_alloc_pd(struct ibv_context *context);
180 int c4iw_free_pd(struct ibv_pd *pd);
182 struct ibv_mr *c4iw_reg_mr(struct ibv_pd *pd, void *addr,
183 size_t length, int access);
184 int c4iw_dereg_mr(struct ibv_mr *mr);
186 struct ibv_cq *c4iw_create_cq(struct ibv_context *context, int cqe,
187 struct ibv_comp_channel *channel,
189 int c4iw_resize_cq(struct ibv_cq *cq, int cqe);
190 int c4iw_destroy_cq(struct ibv_cq *cq);
191 int c4iw_poll_cq(struct ibv_cq *cq, int ne, struct ibv_wc *wc);
192 int c4iw_arm_cq(struct ibv_cq *cq, int solicited);
193 void c4iw_cq_event(struct ibv_cq *cq);
194 void c4iw_init_cq_buf(struct c4iw_cq *cq, int nent);
196 struct ibv_srq *c4iw_create_srq(struct ibv_pd *pd,
197 struct ibv_srq_init_attr *attr);
198 int c4iw_modify_srq(struct ibv_srq *srq,
199 struct ibv_srq_attr *attr,
201 int c4iw_destroy_srq(struct ibv_srq *srq);
202 int c4iw_post_srq_recv(struct ibv_srq *ibsrq,
203 struct ibv_recv_wr *wr,
204 struct ibv_recv_wr **bad_wr);
206 struct ibv_qp *c4iw_create_qp(struct ibv_pd *pd,
207 struct ibv_qp_init_attr *attr);
208 int c4iw_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr,
210 int c4iw_destroy_qp(struct ibv_qp *qp);
211 int c4iw_query_qp(struct ibv_qp *qp,
212 struct ibv_qp_attr *attr,
214 struct ibv_qp_init_attr *init_attr);
215 void c4iw_flush_qp(struct c4iw_qp *qhp);
216 void c4iw_flush_qps(struct c4iw_dev *dev);
217 int c4iw_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr,
218 struct ibv_send_wr **bad_wr);
219 int c4iw_post_receive(struct ibv_qp *ibqp, struct ibv_recv_wr *wr,
220 struct ibv_recv_wr **bad_wr);
221 struct ibv_ah *c4iw_create_ah(struct ibv_pd *pd,
222 struct ibv_ah_attr *ah_attr);
223 int c4iw_destroy_ah(struct ibv_ah *ah);
224 int c4iw_attach_mcast(struct ibv_qp *qp, const union ibv_gid *gid,
226 int c4iw_detach_mcast(struct ibv_qp *qp, const union ibv_gid *gid,
228 void c4iw_async_event(struct ibv_async_event *event);
229 void c4iw_flush_hw_cq(struct c4iw_cq *chp);
230 int c4iw_flush_rq(struct t4_wq *wq, struct t4_cq *cq, int count);
231 void c4iw_flush_sq(struct c4iw_qp *qhp);
232 void c4iw_count_rcqes(struct t4_cq *cq, struct t4_wq *wq, int *count);
237 static inline unsigned long align(unsigned long val, unsigned long align)
239 return (val + align - 1) & ~(align - 1);
244 #define INC_STAT(a) { c4iw_stats.a++; }
257 extern struct c4iw_stats c4iw_stats;
262 #ifdef STALL_DETECTION
263 void dump_state(void);