verbs.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
  2. /* Copyright (c) 2015 - 2021 Intel Corporation */
  3. #ifndef IRDMA_VERBS_H
  4. #define IRDMA_VERBS_H
  5. #define IRDMA_MAX_SAVED_PHY_PGADDR 4
  6. #define IRDMA_FLUSH_DELAY_MS 20
  7. #define IRDMA_PKEY_TBL_SZ 1
  8. #define IRDMA_DEFAULT_PKEY 0xFFFF
  9. struct irdma_ucontext {
  10. struct ib_ucontext ibucontext;
  11. struct irdma_device *iwdev;
  12. struct rdma_user_mmap_entry *db_mmap_entry;
  13. struct list_head cq_reg_mem_list;
  14. spinlock_t cq_reg_mem_list_lock; /* protect CQ memory list */
  15. struct list_head qp_reg_mem_list;
  16. spinlock_t qp_reg_mem_list_lock; /* protect QP memory list */
  17. int abi_ver;
  18. u8 legacy_mode : 1;
  19. u8 use_raw_attrs : 1;
  20. };
  21. struct irdma_pd {
  22. struct ib_pd ibpd;
  23. struct irdma_sc_pd sc_pd;
  24. };
  25. union irdma_sockaddr {
  26. struct sockaddr_in saddr_in;
  27. struct sockaddr_in6 saddr_in6;
  28. };
  29. struct irdma_av {
  30. u8 macaddr[16];
  31. struct rdma_ah_attr attrs;
  32. union irdma_sockaddr sgid_addr;
  33. union irdma_sockaddr dgid_addr;
  34. u8 net_type;
  35. };
  36. struct irdma_ah {
  37. struct ib_ah ibah;
  38. struct irdma_sc_ah sc_ah;
  39. struct irdma_pd *pd;
  40. struct irdma_av av;
  41. u8 sgid_index;
  42. union ib_gid dgid;
  43. struct hlist_node list;
  44. refcount_t refcnt;
  45. struct irdma_ah *parent_ah; /* AH from cached list */
  46. };
  47. struct irdma_hmc_pble {
  48. union {
  49. u32 idx;
  50. dma_addr_t addr;
  51. };
  52. };
  53. struct irdma_cq_mr {
  54. struct irdma_hmc_pble cq_pbl;
  55. dma_addr_t shadow;
  56. bool split;
  57. };
  58. struct irdma_qp_mr {
  59. struct irdma_hmc_pble sq_pbl;
  60. struct irdma_hmc_pble rq_pbl;
  61. dma_addr_t shadow;
  62. struct page *sq_page;
  63. };
  64. struct irdma_cq_buf {
  65. struct irdma_dma_mem kmem_buf;
  66. struct irdma_cq_uk cq_uk;
  67. struct irdma_hw *hw;
  68. struct list_head list;
  69. struct work_struct work;
  70. };
  71. struct irdma_pbl {
  72. struct list_head list;
  73. union {
  74. struct irdma_qp_mr qp_mr;
  75. struct irdma_cq_mr cq_mr;
  76. };
  77. bool pbl_allocated:1;
  78. bool on_list:1;
  79. u64 user_base;
  80. struct irdma_pble_alloc pble_alloc;
  81. struct irdma_mr *iwmr;
  82. };
  83. struct irdma_mr {
  84. union {
  85. struct ib_mr ibmr;
  86. struct ib_mw ibmw;
  87. };
  88. struct ib_umem *region;
  89. int access;
  90. u8 is_hwreg;
  91. u16 type;
  92. u32 page_cnt;
  93. u64 page_size;
  94. u32 npages;
  95. u32 stag;
  96. u64 len;
  97. u64 pgaddrmem[IRDMA_MAX_SAVED_PHY_PGADDR];
  98. struct irdma_pbl iwpbl;
  99. };
  100. struct irdma_cq {
  101. struct ib_cq ibcq;
  102. struct irdma_sc_cq sc_cq;
  103. u16 cq_head;
  104. u16 cq_size;
  105. u16 cq_num;
  106. bool user_mode;
  107. atomic_t armed;
  108. enum irdma_cmpl_notify last_notify;
  109. u32 polled_cmpls;
  110. u32 cq_mem_size;
  111. struct irdma_dma_mem kmem;
  112. struct irdma_dma_mem kmem_shadow;
  113. struct completion free_cq;
  114. refcount_t refcnt;
  115. spinlock_t lock; /* for poll cq */
  116. struct irdma_pbl *iwpbl;
  117. struct irdma_pbl *iwpbl_shadow;
  118. struct list_head resize_list;
  119. struct irdma_cq_poll_info cur_cqe;
  120. struct list_head cmpl_generated;
  121. };
  122. struct irdma_cmpl_gen {
  123. struct list_head list;
  124. struct irdma_cq_poll_info cpi;
  125. };
  126. struct disconn_work {
  127. struct work_struct work;
  128. struct irdma_qp *iwqp;
  129. };
  130. struct iw_cm_id;
  131. struct irdma_qp_kmode {
  132. struct irdma_dma_mem dma_mem;
  133. struct irdma_sq_uk_wr_trk_info *sq_wrid_mem;
  134. u64 *rq_wrid_mem;
  135. };
  136. struct irdma_qp {
  137. struct ib_qp ibqp;
  138. struct irdma_sc_qp sc_qp;
  139. struct irdma_device *iwdev;
  140. struct irdma_cq *iwscq;
  141. struct irdma_cq *iwrcq;
  142. struct irdma_pd *iwpd;
  143. struct rdma_user_mmap_entry *push_wqe_mmap_entry;
  144. struct rdma_user_mmap_entry *push_db_mmap_entry;
  145. struct irdma_qp_host_ctx_info ctx_info;
  146. union {
  147. struct irdma_iwarp_offload_info iwarp_info;
  148. struct irdma_roce_offload_info roce_info;
  149. };
  150. union {
  151. struct irdma_tcp_offload_info tcp_info;
  152. struct irdma_udp_offload_info udp_info;
  153. };
  154. struct irdma_ah roce_ah;
  155. struct list_head teardown_entry;
  156. refcount_t refcnt;
  157. struct iw_cm_id *cm_id;
  158. struct irdma_cm_node *cm_node;
  159. struct delayed_work dwork_flush;
  160. struct ib_mr *lsmm_mr;
  161. atomic_t hw_mod_qp_pend;
  162. enum ib_qp_state ibqp_state;
  163. u32 qp_mem_size;
  164. u32 last_aeq;
  165. int max_send_wr;
  166. int max_recv_wr;
  167. atomic_t close_timer_started;
  168. spinlock_t lock; /* serialize posting WRs to SQ/RQ */
  169. struct irdma_qp_context *iwqp_context;
  170. void *pbl_vbase;
  171. dma_addr_t pbl_pbase;
  172. struct page *page;
  173. u8 active_conn : 1;
  174. u8 user_mode : 1;
  175. u8 hte_added : 1;
  176. u8 flush_issued : 1;
  177. u8 sig_all : 1;
  178. u8 pau_mode : 1;
  179. u8 suspend_pending : 1;
  180. u8 rsvd : 1;
  181. u8 iwarp_state;
  182. u16 term_sq_flush_code;
  183. u16 term_rq_flush_code;
  184. u8 hw_iwarp_state;
  185. u8 hw_tcp_state;
  186. struct irdma_qp_kmode kqp;
  187. struct irdma_dma_mem host_ctx;
  188. struct timer_list terminate_timer;
  189. struct irdma_pbl *iwpbl;
  190. struct irdma_dma_mem q2_ctx_mem;
  191. struct irdma_dma_mem ietf_mem;
  192. struct completion free_qp;
  193. wait_queue_head_t waitq;
  194. wait_queue_head_t mod_qp_waitq;
  195. u8 rts_ae_rcvd;
  196. };
  197. enum irdma_mmap_flag {
  198. IRDMA_MMAP_IO_NC,
  199. IRDMA_MMAP_IO_WC,
  200. };
  201. struct irdma_user_mmap_entry {
  202. struct rdma_user_mmap_entry rdma_entry;
  203. u64 bar_offset;
  204. u8 mmap_flag;
  205. };
  206. static inline u16 irdma_fw_major_ver(struct irdma_sc_dev *dev)
  207. {
  208. return (u16)FIELD_GET(IRDMA_FW_VER_MAJOR, dev->feature_info[IRDMA_FEATURE_FW_INFO]);
  209. }
  210. static inline u16 irdma_fw_minor_ver(struct irdma_sc_dev *dev)
  211. {
  212. return (u16)FIELD_GET(IRDMA_FW_VER_MINOR, dev->feature_info[IRDMA_FEATURE_FW_INFO]);
  213. }
  214. static inline void set_ib_wc_op_sq(struct irdma_cq_poll_info *cq_poll_info,
  215. struct ib_wc *entry)
  216. {
  217. switch (cq_poll_info->op_type) {
  218. case IRDMA_OP_TYPE_RDMA_WRITE:
  219. case IRDMA_OP_TYPE_RDMA_WRITE_SOL:
  220. entry->opcode = IB_WC_RDMA_WRITE;
  221. break;
  222. case IRDMA_OP_TYPE_RDMA_READ_INV_STAG:
  223. case IRDMA_OP_TYPE_RDMA_READ:
  224. entry->opcode = IB_WC_RDMA_READ;
  225. break;
  226. case IRDMA_OP_TYPE_SEND_SOL:
  227. case IRDMA_OP_TYPE_SEND_SOL_INV:
  228. case IRDMA_OP_TYPE_SEND_INV:
  229. case IRDMA_OP_TYPE_SEND:
  230. entry->opcode = IB_WC_SEND;
  231. break;
  232. case IRDMA_OP_TYPE_FAST_REG_NSMR:
  233. entry->opcode = IB_WC_REG_MR;
  234. break;
  235. case IRDMA_OP_TYPE_INV_STAG:
  236. entry->opcode = IB_WC_LOCAL_INV;
  237. break;
  238. default:
  239. entry->status = IB_WC_GENERAL_ERR;
  240. }
  241. }
  242. static inline void set_ib_wc_op_rq(struct irdma_cq_poll_info *cq_poll_info,
  243. struct ib_wc *entry, bool send_imm_support)
  244. {
  245. /**
  246. * iWARP does not support sendImm, so the presence of Imm data
  247. * must be WriteImm.
  248. */
  249. if (!send_imm_support) {
  250. entry->opcode = cq_poll_info->imm_valid ?
  251. IB_WC_RECV_RDMA_WITH_IMM :
  252. IB_WC_RECV;
  253. return;
  254. }
  255. switch (cq_poll_info->op_type) {
  256. case IB_OPCODE_RDMA_WRITE_ONLY_WITH_IMMEDIATE:
  257. case IB_OPCODE_RDMA_WRITE_LAST_WITH_IMMEDIATE:
  258. entry->opcode = IB_WC_RECV_RDMA_WITH_IMM;
  259. break;
  260. default:
  261. entry->opcode = IB_WC_RECV;
  262. }
  263. }
  264. void irdma_mcast_mac(u32 *ip_addr, u8 *mac, bool ipv4);
  265. int irdma_ib_register_device(struct irdma_device *iwdev);
  266. void irdma_ib_unregister_device(struct irdma_device *iwdev);
  267. void irdma_ib_dealloc_device(struct ib_device *ibdev);
  268. void irdma_ib_qp_event(struct irdma_qp *iwqp, enum irdma_qp_event_type event);
  269. void irdma_generate_flush_completions(struct irdma_qp *iwqp);
  270. void irdma_remove_cmpls_list(struct irdma_cq *iwcq);
  271. int irdma_generated_cmpls(struct irdma_cq *iwcq, struct irdma_cq_poll_info *cq_poll_info);
  272. #endif /* IRDMA_VERBS_H */