mthca_provider.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * Copyright (c) 2004 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved.
  4. * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
  5. *
  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:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  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.
  24. *
  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
  32. * SOFTWARE.
  33. *
  34. * $Id: mthca_provider.h 1349 2004-12-16 21:09:43Z roland $
  35. */
  36. #ifndef MTHCA_PROVIDER_H
  37. #define MTHCA_PROVIDER_H
  38. #include <rdma/ib_verbs.h>
  39. #include <rdma/ib_pack.h>
  40. #define MTHCA_MPT_FLAG_ATOMIC (1 << 14)
  41. #define MTHCA_MPT_FLAG_REMOTE_WRITE (1 << 13)
  42. #define MTHCA_MPT_FLAG_REMOTE_READ (1 << 12)
  43. #define MTHCA_MPT_FLAG_LOCAL_WRITE (1 << 11)
  44. #define MTHCA_MPT_FLAG_LOCAL_READ (1 << 10)
  45. struct mthca_buf_list {
  46. void *buf;
  47. DECLARE_PCI_UNMAP_ADDR(mapping)
  48. };
  49. union mthca_buf {
  50. struct mthca_buf_list direct;
  51. struct mthca_buf_list *page_list;
  52. };
  53. struct mthca_uar {
  54. unsigned long pfn;
  55. int index;
  56. };
  57. struct mthca_user_db_table;
  58. struct mthca_ucontext {
  59. struct ib_ucontext ibucontext;
  60. struct mthca_uar uar;
  61. struct mthca_user_db_table *db_tab;
  62. int reg_mr_warned;
  63. };
  64. struct mthca_mtt;
  65. struct mthca_mr {
  66. struct ib_mr ibmr;
  67. struct ib_umem *umem;
  68. struct mthca_mtt *mtt;
  69. };
  70. struct mthca_fmr {
  71. struct ib_fmr ibmr;
  72. struct ib_fmr_attr attr;
  73. struct mthca_mtt *mtt;
  74. int maps;
  75. union {
  76. struct {
  77. struct mthca_mpt_entry __iomem *mpt;
  78. u64 __iomem *mtts;
  79. } tavor;
  80. struct {
  81. struct mthca_mpt_entry *mpt;
  82. __be64 *mtts;
  83. dma_addr_t dma_handle;
  84. } arbel;
  85. } mem;
  86. };
  87. struct mthca_pd {
  88. struct ib_pd ibpd;
  89. u32 pd_num;
  90. atomic_t sqp_count;
  91. struct mthca_mr ntmr;
  92. int privileged;
  93. };
  94. struct mthca_eq {
  95. struct mthca_dev *dev;
  96. int eqn;
  97. u32 eqn_mask;
  98. u32 cons_index;
  99. u16 msi_x_vector;
  100. u16 msi_x_entry;
  101. int have_irq;
  102. int nent;
  103. struct mthca_buf_list *page_list;
  104. struct mthca_mr mr;
  105. };
  106. struct mthca_av;
  107. enum mthca_ah_type {
  108. MTHCA_AH_ON_HCA,
  109. MTHCA_AH_PCI_POOL,
  110. MTHCA_AH_KMALLOC
  111. };
  112. struct mthca_ah {
  113. struct ib_ah ibah;
  114. enum mthca_ah_type type;
  115. u32 key;
  116. struct mthca_av *av;
  117. dma_addr_t avdma;
  118. };
  119. /*
  120. * Quick description of our CQ/QP locking scheme:
  121. *
  122. * We have one global lock that protects dev->cq/qp_table. Each
  123. * struct mthca_cq/qp also has its own lock. An individual qp lock
  124. * may be taken inside of an individual cq lock. Both cqs attached to
  125. * a qp may be locked, with the cq with the lower cqn locked first.
  126. * No other nesting should be done.
  127. *
  128. * Each struct mthca_cq/qp also has an ref count, protected by the
  129. * corresponding table lock. The pointer from the cq/qp_table to the
  130. * struct counts as one reference. This reference also is good for
  131. * access through the consumer API, so modifying the CQ/QP etc doesn't
  132. * need to take another reference. Access to a QP because of a
  133. * completion being polled does not need a reference either.
  134. *
  135. * Finally, each struct mthca_cq/qp has a wait_queue_head_t for the
  136. * destroy function to sleep on.
  137. *
  138. * This means that access from the consumer API requires nothing but
  139. * taking the struct's lock.
  140. *
  141. * Access because of a completion event should go as follows:
  142. * - lock cq/qp_table and look up struct
  143. * - increment ref count in struct
  144. * - drop cq/qp_table lock
  145. * - lock struct, do your thing, and unlock struct
  146. * - decrement ref count; if zero, wake up waiters
  147. *
  148. * To destroy a CQ/QP, we can do the following:
  149. * - lock cq/qp_table
  150. * - remove pointer and decrement ref count
  151. * - unlock cq/qp_table lock
  152. * - wait_event until ref count is zero
  153. *
  154. * It is the consumer's responsibilty to make sure that no QP
  155. * operations (WQE posting or state modification) are pending when a
  156. * QP is destroyed. Also, the consumer must make sure that calls to
  157. * qp_modify are serialized. Similarly, the consumer is responsible
  158. * for ensuring that no CQ resize operations are pending when a CQ
  159. * is destroyed.
  160. *
  161. * Possible optimizations (wait for profile data to see if/where we
  162. * have locks bouncing between CPUs):
  163. * - split cq/qp table lock into n separate (cache-aligned) locks,
  164. * indexed (say) by the page in the table
  165. * - split QP struct lock into three (one for common info, one for the
  166. * send queue and one for the receive queue)
  167. */
  168. struct mthca_cq_buf {
  169. union mthca_buf queue;
  170. struct mthca_mr mr;
  171. int is_direct;
  172. };
  173. struct mthca_cq_resize {
  174. struct mthca_cq_buf buf;
  175. int cqe;
  176. enum {
  177. CQ_RESIZE_ALLOC,
  178. CQ_RESIZE_READY,
  179. CQ_RESIZE_SWAPPED
  180. } state;
  181. };
  182. struct mthca_cq {
  183. struct ib_cq ibcq;
  184. spinlock_t lock;
  185. int refcount;
  186. int cqn;
  187. u32 cons_index;
  188. struct mthca_cq_buf buf;
  189. struct mthca_cq_resize *resize_buf;
  190. int is_kernel;
  191. /* Next fields are Arbel only */
  192. int set_ci_db_index;
  193. __be32 *set_ci_db;
  194. int arm_db_index;
  195. __be32 *arm_db;
  196. int arm_sn;
  197. wait_queue_head_t wait;
  198. struct mutex mutex;
  199. };
  200. struct mthca_srq {
  201. struct ib_srq ibsrq;
  202. spinlock_t lock;
  203. int refcount;
  204. int srqn;
  205. int max;
  206. int max_gs;
  207. int wqe_shift;
  208. int first_free;
  209. int last_free;
  210. u16 counter; /* Arbel only */
  211. int db_index; /* Arbel only */
  212. __be32 *db; /* Arbel only */
  213. void *last;
  214. int is_direct;
  215. u64 *wrid;
  216. union mthca_buf queue;
  217. struct mthca_mr mr;
  218. wait_queue_head_t wait;
  219. struct mutex mutex;
  220. };
  221. struct mthca_wq {
  222. spinlock_t lock;
  223. int max;
  224. unsigned next_ind;
  225. unsigned last_comp;
  226. unsigned head;
  227. unsigned tail;
  228. void *last;
  229. int max_gs;
  230. int wqe_shift;
  231. int db_index; /* Arbel only */
  232. __be32 *db;
  233. };
  234. struct mthca_qp {
  235. struct ib_qp ibqp;
  236. int refcount;
  237. u32 qpn;
  238. int is_direct;
  239. u8 port; /* for SQP and memfree use only */
  240. u8 alt_port; /* for memfree use only */
  241. u8 transport;
  242. u8 state;
  243. u8 atomic_rd_en;
  244. u8 resp_depth;
  245. struct mthca_mr mr;
  246. struct mthca_wq rq;
  247. struct mthca_wq sq;
  248. enum ib_sig_type sq_policy;
  249. int send_wqe_offset;
  250. int max_inline_data;
  251. u64 *wrid;
  252. union mthca_buf queue;
  253. wait_queue_head_t wait;
  254. struct mutex mutex;
  255. };
  256. struct mthca_sqp {
  257. struct mthca_qp qp;
  258. int pkey_index;
  259. u32 qkey;
  260. u32 send_psn;
  261. struct ib_ud_header ud_header;
  262. int header_buf_size;
  263. void *header_buf;
  264. dma_addr_t header_dma;
  265. };
  266. static inline struct mthca_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
  267. {
  268. return container_of(ibucontext, struct mthca_ucontext, ibucontext);
  269. }
  270. static inline struct mthca_fmr *to_mfmr(struct ib_fmr *ibmr)
  271. {
  272. return container_of(ibmr, struct mthca_fmr, ibmr);
  273. }
  274. static inline struct mthca_mr *to_mmr(struct ib_mr *ibmr)
  275. {
  276. return container_of(ibmr, struct mthca_mr, ibmr);
  277. }
  278. static inline struct mthca_pd *to_mpd(struct ib_pd *ibpd)
  279. {
  280. return container_of(ibpd, struct mthca_pd, ibpd);
  281. }
  282. static inline struct mthca_ah *to_mah(struct ib_ah *ibah)
  283. {
  284. return container_of(ibah, struct mthca_ah, ibah);
  285. }
  286. static inline struct mthca_cq *to_mcq(struct ib_cq *ibcq)
  287. {
  288. return container_of(ibcq, struct mthca_cq, ibcq);
  289. }
  290. static inline struct mthca_srq *to_msrq(struct ib_srq *ibsrq)
  291. {
  292. return container_of(ibsrq, struct mthca_srq, ibsrq);
  293. }
  294. static inline struct mthca_qp *to_mqp(struct ib_qp *ibqp)
  295. {
  296. return container_of(ibqp, struct mthca_qp, ibqp);
  297. }
  298. static inline struct mthca_sqp *to_msqp(struct mthca_qp *qp)
  299. {
  300. return container_of(qp, struct mthca_sqp, qp);
  301. }
  302. #endif /* MTHCA_PROVIDER_H */