2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * $Id: mthca_provider.h 3047 2005-08-10 03:59:35Z roland $
37 #ifndef MTHCA_PROVIDER_H
38 #define MTHCA_PROVIDER_H
42 #include <iba/ib_ci.h>
44 typedef uint32_t mthca_mpt_access_t;
45 #define MTHCA_MPT_FLAG_ATOMIC (1 << 14)
46 #define MTHCA_MPT_FLAG_REMOTE_WRITE (1 << 13)
47 #define MTHCA_MPT_FLAG_REMOTE_READ (1 << 12)
48 #define MTHCA_MPT_FLAG_LOCAL_WRITE (1 << 11)
49 #define MTHCA_MPT_FLAG_LOCAL_READ (1 << 10)
52 struct scatterlist direct;
53 struct scatterlist *page_list;
61 struct mthca_user_db_table;
63 struct mthca_ucontext {
64 struct ib_ucontext ibucontext;
66 struct mthca_user_db_table *db_tab;
76 //NB: the start of this structure is to be equal to mlnx_mro_t !
77 //NB: the structure was not inserted here for not to mix driver and provider structures
79 #ifdef WIN_TO_BE_REMOVED
82 struct mthca_mtt *mtt;
88 struct ib_fmr_attr attr;
89 struct mthca_mtt *mtt;
93 struct mthca_mpt_entry __iomem *mpt;
97 struct mthca_mpt_entry *mpt;
107 struct mthca_mr ntmr;
112 struct mthca_dev *dev;
120 struct scatterlist *page_list;
122 KDPC dpc; /* DPC for MSI-X interrupts */
123 spinlock_t lock; /* spinlock for simult DPCs */
136 enum mthca_ah_type type;
143 * Quick description of our CQ/QP locking scheme:
145 * We have one global lock that protects dev->cq/qp_table. Each
146 * struct mthca_cq/qp also has its own lock. An individual qp lock
147 * may be taken inside of an individual cq lock. Both cqs attached to
148 * a qp may be locked, with the send cq locked first. No other
149 * nesting should be done.
151 * Each struct mthca_cq/qp also has an atomic_t ref count. The
152 * pointer from the cq/qp_table to the struct counts as one reference.
153 * This reference also is good for access through the consumer API, so
154 * modifying the CQ/QP etc doesn't need to take another reference.
155 * Access because of a completion being polled does need a reference.
157 * Finally, each struct mthca_cq/qp has a wait_queue_head_t for the
158 * destroy function to sleep on.
160 * This means that access from the consumer API requires nothing but
161 * taking the struct's lock.
163 * Access because of a completion event should go as follows:
164 * - lock cq/qp_table and look up struct
165 * - increment ref count in struct
166 * - drop cq/qp_table lock
167 * - lock struct, do your thing, and unlock struct
168 * - decrement ref count; if zero, wake up waiters
170 * To destroy a CQ/QP, we can do the following:
171 * - lock cq/qp_table, remove pointer, unlock cq/qp_table lock
172 * - decrement ref count
173 * - wait_event until ref count is zero
175 * It is the consumer's responsibilty to make sure that no QP
176 * operations (WQE posting or state modification) are pending when the
177 * QP is destroyed. Also, the consumer must make sure that calls to
178 * qp_modify are serialized.
180 * Possible optimizations (wait for profile data to see if/where we
181 * have locks bouncing between CPUs):
182 * - split cq/qp table lock into n separate (cache-aligned) locks,
183 * indexed (say) by the page in the table
184 * - split QP struct lock into three (one for common info, one for the
185 * send queue and one for the receive queue)
187 //TODO: check correctness of the above requirement: "It is the consumer's responsibilty to make sure that no QP
188 // operations (WQE posting or state modification) are pending when the QP is destroyed"
192 void *cq_context; // leo: for IBAL shim
200 /* Next fields are Arbel only */
207 union mthca_buf queue;
209 wait_queue_head_t wait;
222 u16 counter; /* Arbel only */
223 int db_index; /* Arbel only */
224 __be32 *db; /* Arbel only */
229 union mthca_buf queue;
232 wait_queue_head_t wait;
246 int db_index; /* Arbel only */
252 void *qp_context; // leo: for IBAL shim
253 //TODO: added just because absense of ibv_query_qp
254 // thereafter it may be worth to be replaced by struct ib_qp_attr qp_attr;
255 struct ib_qp_init_attr qp_init_attr; // leo: for query_qp
268 enum ib_sig_type sq_policy;
273 union mthca_buf queue;
275 wait_queue_head_t wait;
284 struct ib_ud_header ud_header;
285 struct scatterlist sg;
288 static inline struct mthca_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
290 return container_of(ibucontext, struct mthca_ucontext, ibucontext);
293 static inline struct mthca_fmr *to_mfmr(struct ib_fmr *ibmr)
295 return container_of(ibmr, struct mthca_fmr, ibmr);
298 static inline struct mthca_mr *to_mmr(struct ib_mr *ibmr)
300 return container_of(ibmr, struct mthca_mr, ibmr);
303 static inline struct mthca_pd *to_mpd(struct ib_pd *ibpd)
305 return container_of(ibpd, struct mthca_pd, ibpd);
308 static inline struct mthca_ah *to_mah(struct ib_ah *ibah)
310 return container_of(ibah, struct mthca_ah, ibah);
313 static inline struct mthca_cq *to_mcq(struct ib_cq *ibcq)
315 return container_of(ibcq, struct mthca_cq, ibcq);
318 static inline struct mthca_srq *to_msrq(struct ib_srq *ibsrq)
320 return container_of(ibsrq, struct mthca_srq, ibsrq);
323 static inline struct mthca_qp *to_mqp(struct ib_qp *ibqp)
325 return container_of(ibqp, struct mthca_qp, ibqp);
328 static inline struct mthca_sqp *to_msqp(struct mthca_qp *qp)
330 return container_of(qp, struct mthca_sqp, qp);
333 static inline uint8_t start_port(struct ib_device *device)
335 return device->node_type == IB_NODE_SWITCH ? 0 : 1;
338 static inline uint8_t end_port(struct ib_device *device)
340 return device->node_type == IB_NODE_SWITCH ? 0 : device->phys_port_cnt;
343 static inline int ib_copy_from_umv_buf(void *dest, ci_umv_buf_t* const p_umv_buf, size_t len)
345 RtlCopyMemory(dest, p_umv_buf->p_inout_buf, len);
349 static inline int ib_copy_to_umv_buf(ci_umv_buf_t* const p_umv_buf, void *src, size_t len)
351 if (p_umv_buf->output_size < len) {
352 p_umv_buf->status = IB_INSUFFICIENT_MEMORY;
353 p_umv_buf->output_size = 0;
356 RtlCopyMemory(p_umv_buf->p_inout_buf, src, len);
357 p_umv_buf->status = IB_SUCCESS;
358 p_umv_buf->output_size = (uint32_t)len;
365 int mthca_query_device(struct ib_device *ibdev,
366 struct ib_device_attr *props);
368 int mthca_query_port(struct ib_device *ibdev,
369 u8 port, struct ib_port_attr *props);
371 int mthca_modify_port(struct ib_device *ibdev,
372 u8 port, int port_modify_mask,
373 struct ib_port_modify *props);
375 int mthca_query_pkey(struct ib_device *ibdev,
376 u8 port, u16 index, u16 *pkey);
378 int mthca_query_gid(struct ib_device *ibdev, u8 port,
379 int index, union ib_gid *gid);
381 struct ib_ucontext *mthca_alloc_ucontext(struct ib_device *ibdev,
382 ci_umv_buf_t* const p_umv_buf);
384 int mthca_dealloc_ucontext(struct ib_ucontext *context);
386 struct ib_pd *mthca_alloc_pd(struct ib_device *ibdev,
387 struct ib_ucontext *context,
388 ci_umv_buf_t* const p_umv_buf);
390 int mthca_dealloc_pd(struct ib_pd *pd);
392 struct ib_ah *mthca_ah_create(struct ib_pd *pd,
393 struct ib_ah_attr *ah_attr);
395 int mthca_ah_destroy(struct ib_ah *ah);
397 struct ib_srq *mthca_create_srq(struct ib_pd *pd,
398 struct ib_srq_init_attr *init_attr,
399 ci_umv_buf_t* const p_umv_buf);
401 int mthca_destroy_srq(struct ib_srq *srq);
403 struct ib_qp *mthca_create_qp(struct ib_pd *pd,
404 struct ib_qp_init_attr *init_attr,
405 ci_umv_buf_t* const p_umv_buf);
407 int mthca_destroy_qp(struct ib_qp *qp);
409 struct ib_cq *mthca_create_cq(struct ib_device *ibdev, int entries,
410 struct ib_ucontext *context,
411 ci_umv_buf_t* const p_umv_buf);
413 int mthca_destroy_cq(struct ib_cq *cq);
415 struct ib_mr *mthca_get_dma_mr(struct ib_pd *pd, mthca_qp_access_t acc);
417 struct ib_mr *mthca_reg_phys_mr(struct ib_pd *pd,
418 struct ib_phys_buf *buffer_list,
420 mthca_qp_access_t acc,
423 struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd,
424 void* __ptr64 vaddr, uint64_t length, uint64_t hca_va, mthca_qp_access_t acc);
426 int mthca_dereg_mr(struct ib_mr *mr);
428 struct ib_fmr *mthca_alloc_fmr(struct ib_pd *pd, mthca_qp_access_t acc,
429 struct ib_fmr_attr *fmr_attr);
431 int mthca_dealloc_fmr(struct ib_fmr *fmr);
433 int mthca_unmap_fmr(struct list_head *fmr_list);
435 int mthca_poll_cq_list(
436 IN struct ib_cq *ibcq,
437 IN OUT ib_wc_t** const pp_free_wclist,
438 OUT ib_wc_t** const pp_done_wclist );
441 #endif /* MTHCA_PROVIDER_H */