iwch_provider.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /*
  2. * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
  3. * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
  4. *
  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:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  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.
  23. *
  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
  31. * SOFTWARE.
  32. */
  33. #ifndef __IWCH_PROVIDER_H__
  34. #define __IWCH_PROVIDER_H__
  35. #include <linux/list.h>
  36. #include <linux/spinlock.h>
  37. #include <rdma/ib_verbs.h>
  38. #include <asm/types.h>
  39. #include "t3cdev.h"
  40. #include "iwch.h"
  41. #include "cxio_wr.h"
  42. #include "cxio_hal.h"
  43. struct iwch_pd {
  44. struct ib_pd ibpd;
  45. u32 pdid;
  46. struct iwch_dev *rhp;
  47. };
  48. static inline struct iwch_pd *to_iwch_pd(struct ib_pd *ibpd)
  49. {
  50. return container_of(ibpd, struct iwch_pd, ibpd);
  51. }
  52. struct tpt_attributes {
  53. u32 stag;
  54. u32 state:1;
  55. u32 type:2;
  56. u32 rsvd:1;
  57. enum tpt_mem_perm perms;
  58. u32 remote_invaliate_disable:1;
  59. u32 zbva:1;
  60. u32 mw_bind_enable:1;
  61. u32 page_size:5;
  62. u32 pdid;
  63. u32 qpid;
  64. u32 pbl_addr;
  65. u32 len;
  66. u64 va_fbo;
  67. u32 pbl_size;
  68. };
  69. struct iwch_mr {
  70. struct ib_mr ibmr;
  71. struct iwch_dev *rhp;
  72. u64 kva;
  73. struct tpt_attributes attr;
  74. };
  75. typedef struct iwch_mw iwch_mw_handle;
  76. static inline struct iwch_mr *to_iwch_mr(struct ib_mr *ibmr)
  77. {
  78. return container_of(ibmr, struct iwch_mr, ibmr);
  79. }
  80. struct iwch_mw {
  81. struct ib_mw ibmw;
  82. struct iwch_dev *rhp;
  83. u64 kva;
  84. struct tpt_attributes attr;
  85. };
  86. static inline struct iwch_mw *to_iwch_mw(struct ib_mw *ibmw)
  87. {
  88. return container_of(ibmw, struct iwch_mw, ibmw);
  89. }
  90. struct iwch_cq {
  91. struct ib_cq ibcq;
  92. struct iwch_dev *rhp;
  93. struct t3_cq cq;
  94. spinlock_t lock;
  95. atomic_t refcnt;
  96. wait_queue_head_t wait;
  97. u32 __user *user_rptr_addr;
  98. };
  99. static inline struct iwch_cq *to_iwch_cq(struct ib_cq *ibcq)
  100. {
  101. return container_of(ibcq, struct iwch_cq, ibcq);
  102. }
  103. enum IWCH_QP_FLAGS {
  104. QP_QUIESCED = 0x01
  105. };
  106. struct iwch_mpa_attributes {
  107. u8 recv_marker_enabled;
  108. u8 xmit_marker_enabled; /* iWARP: enable inbound Read Resp. */
  109. u8 crc_enabled;
  110. u8 version; /* 0 or 1 */
  111. };
  112. struct iwch_qp_attributes {
  113. u32 scq;
  114. u32 rcq;
  115. u32 sq_num_entries;
  116. u32 rq_num_entries;
  117. u32 sq_max_sges;
  118. u32 sq_max_sges_rdma_write;
  119. u32 rq_max_sges;
  120. u32 state;
  121. u8 enable_rdma_read;
  122. u8 enable_rdma_write; /* enable inbound Read Resp. */
  123. u8 enable_bind;
  124. u8 enable_mmid0_fastreg; /* Enable STAG0 + Fast-register */
  125. /*
  126. * Next QP state. If specify the current state, only the
  127. * QP attributes will be modified.
  128. */
  129. u32 max_ord;
  130. u32 max_ird;
  131. u32 pd; /* IN */
  132. u32 next_state;
  133. char terminate_buffer[52];
  134. u32 terminate_msg_len;
  135. u8 is_terminate_local;
  136. struct iwch_mpa_attributes mpa_attr; /* IN-OUT */
  137. struct iwch_ep *llp_stream_handle;
  138. char *stream_msg_buf; /* Last stream msg. before Idle -> RTS */
  139. u32 stream_msg_buf_len; /* Only on Idle -> RTS */
  140. };
  141. struct iwch_qp {
  142. struct ib_qp ibqp;
  143. struct iwch_dev *rhp;
  144. struct iwch_ep *ep;
  145. struct iwch_qp_attributes attr;
  146. struct t3_wq wq;
  147. spinlock_t lock;
  148. atomic_t refcnt;
  149. wait_queue_head_t wait;
  150. enum IWCH_QP_FLAGS flags;
  151. struct timer_list timer;
  152. };
  153. static inline int qp_quiesced(struct iwch_qp *qhp)
  154. {
  155. return qhp->flags & QP_QUIESCED;
  156. }
  157. static inline struct iwch_qp *to_iwch_qp(struct ib_qp *ibqp)
  158. {
  159. return container_of(ibqp, struct iwch_qp, ibqp);
  160. }
  161. void iwch_qp_add_ref(struct ib_qp *qp);
  162. void iwch_qp_rem_ref(struct ib_qp *qp);
  163. struct ib_qp *iwch_get_qp(struct ib_device *dev, int qpn);
  164. struct iwch_ucontext {
  165. struct ib_ucontext ibucontext;
  166. struct cxio_ucontext uctx;
  167. u32 key;
  168. spinlock_t mmap_lock;
  169. struct list_head mmaps;
  170. };
  171. static inline struct iwch_ucontext *to_iwch_ucontext(struct ib_ucontext *c)
  172. {
  173. return container_of(c, struct iwch_ucontext, ibucontext);
  174. }
  175. struct iwch_mm_entry {
  176. struct list_head entry;
  177. u64 addr;
  178. u32 key;
  179. unsigned len;
  180. };
  181. static inline struct iwch_mm_entry *remove_mmap(struct iwch_ucontext *ucontext,
  182. u32 key, unsigned len)
  183. {
  184. struct list_head *pos, *nxt;
  185. struct iwch_mm_entry *mm;
  186. spin_lock(&ucontext->mmap_lock);
  187. list_for_each_safe(pos, nxt, &ucontext->mmaps) {
  188. mm = list_entry(pos, struct iwch_mm_entry, entry);
  189. if (mm->key == key && mm->len == len) {
  190. list_del_init(&mm->entry);
  191. spin_unlock(&ucontext->mmap_lock);
  192. PDBG("%s key 0x%x addr 0x%llx len %d\n", __FUNCTION__,
  193. key, (unsigned long long) mm->addr, mm->len);
  194. return mm;
  195. }
  196. }
  197. spin_unlock(&ucontext->mmap_lock);
  198. return NULL;
  199. }
  200. static inline void insert_mmap(struct iwch_ucontext *ucontext,
  201. struct iwch_mm_entry *mm)
  202. {
  203. spin_lock(&ucontext->mmap_lock);
  204. PDBG("%s key 0x%x addr 0x%llx len %d\n", __FUNCTION__,
  205. mm->key, (unsigned long long) mm->addr, mm->len);
  206. list_add_tail(&mm->entry, &ucontext->mmaps);
  207. spin_unlock(&ucontext->mmap_lock);
  208. }
  209. enum iwch_qp_attr_mask {
  210. IWCH_QP_ATTR_NEXT_STATE = 1 << 0,
  211. IWCH_QP_ATTR_ENABLE_RDMA_READ = 1 << 7,
  212. IWCH_QP_ATTR_ENABLE_RDMA_WRITE = 1 << 8,
  213. IWCH_QP_ATTR_ENABLE_RDMA_BIND = 1 << 9,
  214. IWCH_QP_ATTR_MAX_ORD = 1 << 11,
  215. IWCH_QP_ATTR_MAX_IRD = 1 << 12,
  216. IWCH_QP_ATTR_LLP_STREAM_HANDLE = 1 << 22,
  217. IWCH_QP_ATTR_STREAM_MSG_BUFFER = 1 << 23,
  218. IWCH_QP_ATTR_MPA_ATTR = 1 << 24,
  219. IWCH_QP_ATTR_QP_CONTEXT_ACTIVATE = 1 << 25,
  220. IWCH_QP_ATTR_VALID_MODIFY = (IWCH_QP_ATTR_ENABLE_RDMA_READ |
  221. IWCH_QP_ATTR_ENABLE_RDMA_WRITE |
  222. IWCH_QP_ATTR_MAX_ORD |
  223. IWCH_QP_ATTR_MAX_IRD |
  224. IWCH_QP_ATTR_LLP_STREAM_HANDLE |
  225. IWCH_QP_ATTR_STREAM_MSG_BUFFER |
  226. IWCH_QP_ATTR_MPA_ATTR |
  227. IWCH_QP_ATTR_QP_CONTEXT_ACTIVATE)
  228. };
  229. int iwch_modify_qp(struct iwch_dev *rhp,
  230. struct iwch_qp *qhp,
  231. enum iwch_qp_attr_mask mask,
  232. struct iwch_qp_attributes *attrs,
  233. int internal);
  234. enum iwch_qp_state {
  235. IWCH_QP_STATE_IDLE,
  236. IWCH_QP_STATE_RTS,
  237. IWCH_QP_STATE_ERROR,
  238. IWCH_QP_STATE_TERMINATE,
  239. IWCH_QP_STATE_CLOSING,
  240. IWCH_QP_STATE_TOT
  241. };
  242. static inline int iwch_convert_state(enum ib_qp_state ib_state)
  243. {
  244. switch (ib_state) {
  245. case IB_QPS_RESET:
  246. case IB_QPS_INIT:
  247. return IWCH_QP_STATE_IDLE;
  248. case IB_QPS_RTS:
  249. return IWCH_QP_STATE_RTS;
  250. case IB_QPS_SQD:
  251. return IWCH_QP_STATE_CLOSING;
  252. case IB_QPS_SQE:
  253. return IWCH_QP_STATE_TERMINATE;
  254. case IB_QPS_ERR:
  255. return IWCH_QP_STATE_ERROR;
  256. default:
  257. return -1;
  258. }
  259. }
  260. enum iwch_mem_perms {
  261. IWCH_MEM_ACCESS_LOCAL_READ = 1 << 0,
  262. IWCH_MEM_ACCESS_LOCAL_WRITE = 1 << 1,
  263. IWCH_MEM_ACCESS_REMOTE_READ = 1 << 2,
  264. IWCH_MEM_ACCESS_REMOTE_WRITE = 1 << 3,
  265. IWCH_MEM_ACCESS_ATOMICS = 1 << 4,
  266. IWCH_MEM_ACCESS_BINDING = 1 << 5,
  267. IWCH_MEM_ACCESS_LOCAL =
  268. (IWCH_MEM_ACCESS_LOCAL_READ | IWCH_MEM_ACCESS_LOCAL_WRITE),
  269. IWCH_MEM_ACCESS_REMOTE =
  270. (IWCH_MEM_ACCESS_REMOTE_WRITE | IWCH_MEM_ACCESS_REMOTE_READ)
  271. /* cannot go beyond 1 << 31 */
  272. } __attribute__ ((packed));
  273. static inline u32 iwch_convert_access(int acc)
  274. {
  275. return (acc & IB_ACCESS_REMOTE_WRITE ? IWCH_MEM_ACCESS_REMOTE_WRITE : 0)
  276. | (acc & IB_ACCESS_REMOTE_READ ? IWCH_MEM_ACCESS_REMOTE_READ : 0) |
  277. (acc & IB_ACCESS_LOCAL_WRITE ? IWCH_MEM_ACCESS_LOCAL_WRITE : 0) |
  278. (acc & IB_ACCESS_MW_BIND ? IWCH_MEM_ACCESS_BINDING : 0) |
  279. IWCH_MEM_ACCESS_LOCAL_READ;
  280. }
  281. enum iwch_mmid_state {
  282. IWCH_STAG_STATE_VALID,
  283. IWCH_STAG_STATE_INVALID
  284. };
  285. enum iwch_qp_query_flags {
  286. IWCH_QP_QUERY_CONTEXT_NONE = 0x0, /* No ctx; Only attrs */
  287. IWCH_QP_QUERY_CONTEXT_GET = 0x1, /* Get ctx + attrs */
  288. IWCH_QP_QUERY_CONTEXT_SUSPEND = 0x2, /* Not Supported */
  289. /*
  290. * Quiesce QP context; Consumer
  291. * will NOT replay outstanding WR
  292. */
  293. IWCH_QP_QUERY_CONTEXT_QUIESCE = 0x4,
  294. IWCH_QP_QUERY_CONTEXT_REMOVE = 0x8,
  295. IWCH_QP_QUERY_TEST_USERWRITE = 0x32 /* Test special */
  296. };
  297. int iwch_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  298. struct ib_send_wr **bad_wr);
  299. int iwch_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  300. struct ib_recv_wr **bad_wr);
  301. int iwch_bind_mw(struct ib_qp *qp,
  302. struct ib_mw *mw,
  303. struct ib_mw_bind *mw_bind);
  304. int iwch_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
  305. int iwch_post_terminate(struct iwch_qp *qhp, struct respQ_msg_t *rsp_msg);
  306. int iwch_register_device(struct iwch_dev *dev);
  307. void iwch_unregister_device(struct iwch_dev *dev);
  308. int iwch_quiesce_qps(struct iwch_cq *chp);
  309. int iwch_resume_qps(struct iwch_cq *chp);
  310. void stop_read_rep_timer(struct iwch_qp *qhp);
  311. int iwch_register_mem(struct iwch_dev *rhp, struct iwch_pd *php,
  312. struct iwch_mr *mhp,
  313. int shift,
  314. __be64 *page_list);
  315. int iwch_reregister_mem(struct iwch_dev *rhp, struct iwch_pd *php,
  316. struct iwch_mr *mhp,
  317. int shift,
  318. __be64 *page_list,
  319. int npages);
  320. int build_phys_page_list(struct ib_phys_buf *buffer_list,
  321. int num_phys_buf,
  322. u64 *iova_start,
  323. u64 *total_size,
  324. int *npages,
  325. int *shift,
  326. __be64 **page_list);
  327. #define IWCH_NODE_DESC "cxgb3 Chelsio Communications"
  328. #endif