user.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /* SPDX-License-Identifier: GPL-2.0 or Linux-OpenIB */
  2. /* Copyright (c) 2015 - 2020 Intel Corporation */
  3. #ifndef IRDMA_USER_H
  4. #define IRDMA_USER_H
  5. #define irdma_handle void *
  6. #define irdma_adapter_handle irdma_handle
  7. #define irdma_qp_handle irdma_handle
  8. #define irdma_cq_handle irdma_handle
  9. #define irdma_pd_id irdma_handle
  10. #define irdma_stag_handle irdma_handle
  11. #define irdma_stag_index u32
  12. #define irdma_stag u32
  13. #define irdma_stag_key u8
  14. #define irdma_tagged_offset u64
  15. #define irdma_access_privileges u32
  16. #define irdma_physical_fragment u64
  17. #define irdma_address_list u64 *
  18. #define IRDMA_MAX_MR_SIZE 0x200000000000ULL
  19. #define IRDMA_ACCESS_FLAGS_LOCALREAD 0x01
  20. #define IRDMA_ACCESS_FLAGS_LOCALWRITE 0x02
  21. #define IRDMA_ACCESS_FLAGS_REMOTEREAD_ONLY 0x04
  22. #define IRDMA_ACCESS_FLAGS_REMOTEREAD 0x05
  23. #define IRDMA_ACCESS_FLAGS_REMOTEWRITE_ONLY 0x08
  24. #define IRDMA_ACCESS_FLAGS_REMOTEWRITE 0x0a
  25. #define IRDMA_ACCESS_FLAGS_BIND_WINDOW 0x10
  26. #define IRDMA_ACCESS_FLAGS_ZERO_BASED 0x20
  27. #define IRDMA_ACCESS_FLAGS_ALL 0x3f
  28. #define IRDMA_OP_TYPE_RDMA_WRITE 0x00
  29. #define IRDMA_OP_TYPE_RDMA_READ 0x01
  30. #define IRDMA_OP_TYPE_SEND 0x03
  31. #define IRDMA_OP_TYPE_SEND_INV 0x04
  32. #define IRDMA_OP_TYPE_SEND_SOL 0x05
  33. #define IRDMA_OP_TYPE_SEND_SOL_INV 0x06
  34. #define IRDMA_OP_TYPE_RDMA_WRITE_SOL 0x0d
  35. #define IRDMA_OP_TYPE_BIND_MW 0x08
  36. #define IRDMA_OP_TYPE_FAST_REG_NSMR 0x09
  37. #define IRDMA_OP_TYPE_INV_STAG 0x0a
  38. #define IRDMA_OP_TYPE_RDMA_READ_INV_STAG 0x0b
  39. #define IRDMA_OP_TYPE_NOP 0x0c
  40. #define IRDMA_OP_TYPE_REC 0x3e
  41. #define IRDMA_OP_TYPE_REC_IMM 0x3f
  42. #define IRDMA_FLUSH_MAJOR_ERR 1
  43. enum irdma_device_caps_const {
  44. IRDMA_WQE_SIZE = 4,
  45. IRDMA_CQP_WQE_SIZE = 8,
  46. IRDMA_CQE_SIZE = 4,
  47. IRDMA_EXTENDED_CQE_SIZE = 8,
  48. IRDMA_AEQE_SIZE = 2,
  49. IRDMA_CEQE_SIZE = 1,
  50. IRDMA_CQP_CTX_SIZE = 8,
  51. IRDMA_SHADOW_AREA_SIZE = 8,
  52. IRDMA_QUERY_FPM_BUF_SIZE = 176,
  53. IRDMA_COMMIT_FPM_BUF_SIZE = 176,
  54. IRDMA_GATHER_STATS_BUF_SIZE = 1024,
  55. IRDMA_MIN_IW_QP_ID = 0,
  56. IRDMA_MAX_IW_QP_ID = 262143,
  57. IRDMA_MIN_CEQID = 0,
  58. IRDMA_MAX_CEQID = 1023,
  59. IRDMA_CEQ_MAX_COUNT = IRDMA_MAX_CEQID + 1,
  60. IRDMA_MIN_CQID = 0,
  61. IRDMA_MAX_CQID = 524287,
  62. IRDMA_MIN_AEQ_ENTRIES = 1,
  63. IRDMA_MAX_AEQ_ENTRIES = 524287,
  64. IRDMA_MIN_CEQ_ENTRIES = 1,
  65. IRDMA_MAX_CEQ_ENTRIES = 262143,
  66. IRDMA_MIN_CQ_SIZE = 1,
  67. IRDMA_MAX_CQ_SIZE = 1048575,
  68. IRDMA_DB_ID_ZERO = 0,
  69. IRDMA_MAX_WQ_FRAGMENT_COUNT = 13,
  70. IRDMA_MAX_SGE_RD = 13,
  71. IRDMA_MAX_OUTBOUND_MSG_SIZE = 2147483647,
  72. IRDMA_MAX_INBOUND_MSG_SIZE = 2147483647,
  73. IRDMA_MAX_PUSH_PAGE_COUNT = 1024,
  74. IRDMA_MAX_PE_ENA_VF_COUNT = 32,
  75. IRDMA_MAX_VF_FPM_ID = 47,
  76. IRDMA_MAX_SQ_PAYLOAD_SIZE = 2145386496,
  77. IRDMA_MAX_INLINE_DATA_SIZE = 101,
  78. IRDMA_MAX_WQ_ENTRIES = 32768,
  79. IRDMA_Q2_BUF_SIZE = 256,
  80. IRDMA_QP_CTX_SIZE = 256,
  81. IRDMA_MAX_PDS = 262144,
  82. };
  83. enum irdma_addressing_type {
  84. IRDMA_ADDR_TYPE_ZERO_BASED = 0,
  85. IRDMA_ADDR_TYPE_VA_BASED = 1,
  86. };
  87. enum irdma_flush_opcode {
  88. FLUSH_INVALID = 0,
  89. FLUSH_GENERAL_ERR,
  90. FLUSH_PROT_ERR,
  91. FLUSH_REM_ACCESS_ERR,
  92. FLUSH_LOC_QP_OP_ERR,
  93. FLUSH_REM_OP_ERR,
  94. FLUSH_LOC_LEN_ERR,
  95. FLUSH_FATAL_ERR,
  96. FLUSH_RETRY_EXC_ERR,
  97. FLUSH_MW_BIND_ERR,
  98. FLUSH_REM_INV_REQ_ERR,
  99. };
  100. enum irdma_cmpl_status {
  101. IRDMA_COMPL_STATUS_SUCCESS = 0,
  102. IRDMA_COMPL_STATUS_FLUSHED,
  103. IRDMA_COMPL_STATUS_INVALID_WQE,
  104. IRDMA_COMPL_STATUS_QP_CATASTROPHIC,
  105. IRDMA_COMPL_STATUS_REMOTE_TERMINATION,
  106. IRDMA_COMPL_STATUS_INVALID_STAG,
  107. IRDMA_COMPL_STATUS_BASE_BOUND_VIOLATION,
  108. IRDMA_COMPL_STATUS_ACCESS_VIOLATION,
  109. IRDMA_COMPL_STATUS_INVALID_PD_ID,
  110. IRDMA_COMPL_STATUS_WRAP_ERROR,
  111. IRDMA_COMPL_STATUS_STAG_INVALID_PDID,
  112. IRDMA_COMPL_STATUS_RDMA_READ_ZERO_ORD,
  113. IRDMA_COMPL_STATUS_QP_NOT_PRIVLEDGED,
  114. IRDMA_COMPL_STATUS_STAG_NOT_INVALID,
  115. IRDMA_COMPL_STATUS_INVALID_PHYS_BUF_SIZE,
  116. IRDMA_COMPL_STATUS_INVALID_PHYS_BUF_ENTRY,
  117. IRDMA_COMPL_STATUS_INVALID_FBO,
  118. IRDMA_COMPL_STATUS_INVALID_LEN,
  119. IRDMA_COMPL_STATUS_INVALID_ACCESS,
  120. IRDMA_COMPL_STATUS_PHYS_BUF_LIST_TOO_LONG,
  121. IRDMA_COMPL_STATUS_INVALID_VIRT_ADDRESS,
  122. IRDMA_COMPL_STATUS_INVALID_REGION,
  123. IRDMA_COMPL_STATUS_INVALID_WINDOW,
  124. IRDMA_COMPL_STATUS_INVALID_TOTAL_LEN,
  125. IRDMA_COMPL_STATUS_UNKNOWN,
  126. };
  127. enum irdma_cmpl_notify {
  128. IRDMA_CQ_COMPL_EVENT = 0,
  129. IRDMA_CQ_COMPL_SOLICITED = 1,
  130. };
  131. enum irdma_qp_caps {
  132. IRDMA_WRITE_WITH_IMM = 1,
  133. IRDMA_SEND_WITH_IMM = 2,
  134. IRDMA_ROCE = 4,
  135. IRDMA_PUSH_MODE = 8,
  136. };
  137. struct irdma_qp_uk;
  138. struct irdma_cq_uk;
  139. struct irdma_qp_uk_init_info;
  140. struct irdma_cq_uk_init_info;
  141. struct irdma_ring {
  142. u32 head;
  143. u32 tail;
  144. u32 size;
  145. };
  146. struct irdma_cqe {
  147. __le64 buf[IRDMA_CQE_SIZE];
  148. };
  149. struct irdma_extended_cqe {
  150. __le64 buf[IRDMA_EXTENDED_CQE_SIZE];
  151. };
  152. struct irdma_post_send {
  153. struct ib_sge *sg_list;
  154. u32 num_sges;
  155. u32 qkey;
  156. u32 dest_qp;
  157. u32 ah_id;
  158. };
  159. struct irdma_post_rq_info {
  160. u64 wr_id;
  161. struct ib_sge *sg_list;
  162. u32 num_sges;
  163. };
  164. struct irdma_rdma_write {
  165. struct ib_sge *lo_sg_list;
  166. u32 num_lo_sges;
  167. struct ib_sge rem_addr;
  168. };
  169. struct irdma_rdma_read {
  170. struct ib_sge *lo_sg_list;
  171. u32 num_lo_sges;
  172. struct ib_sge rem_addr;
  173. };
  174. struct irdma_bind_window {
  175. irdma_stag mr_stag;
  176. u64 bind_len;
  177. void *va;
  178. enum irdma_addressing_type addressing_type;
  179. bool ena_reads:1;
  180. bool ena_writes:1;
  181. irdma_stag mw_stag;
  182. bool mem_window_type_1:1;
  183. };
  184. struct irdma_inv_local_stag {
  185. irdma_stag target_stag;
  186. };
  187. struct irdma_post_sq_info {
  188. u64 wr_id;
  189. u8 op_type;
  190. u8 l4len;
  191. bool signaled:1;
  192. bool read_fence:1;
  193. bool local_fence:1;
  194. bool inline_data:1;
  195. bool imm_data_valid:1;
  196. bool push_wqe:1;
  197. bool report_rtt:1;
  198. bool udp_hdr:1;
  199. bool defer_flag:1;
  200. u32 imm_data;
  201. u32 stag_to_inv;
  202. union {
  203. struct irdma_post_send send;
  204. struct irdma_rdma_write rdma_write;
  205. struct irdma_rdma_read rdma_read;
  206. struct irdma_bind_window bind_window;
  207. struct irdma_inv_local_stag inv_local_stag;
  208. } op;
  209. };
  210. struct irdma_cq_poll_info {
  211. u64 wr_id;
  212. irdma_qp_handle qp_handle;
  213. u32 bytes_xfered;
  214. u32 tcp_seq_num_rtt;
  215. u32 qp_id;
  216. u32 ud_src_qpn;
  217. u32 imm_data;
  218. irdma_stag inv_stag; /* or L_R_Key */
  219. enum irdma_cmpl_status comp_status;
  220. u16 major_err;
  221. u16 minor_err;
  222. u16 ud_vlan;
  223. u8 ud_smac[6];
  224. u8 op_type;
  225. u8 q_type;
  226. bool stag_invalid_set:1; /* or L_R_Key set */
  227. bool push_dropped:1;
  228. bool error:1;
  229. bool solicited_event:1;
  230. bool ipv4:1;
  231. bool ud_vlan_valid:1;
  232. bool ud_smac_valid:1;
  233. bool imm_valid:1;
  234. };
  235. int irdma_uk_inline_rdma_write(struct irdma_qp_uk *qp,
  236. struct irdma_post_sq_info *info, bool post_sq);
  237. int irdma_uk_inline_send(struct irdma_qp_uk *qp,
  238. struct irdma_post_sq_info *info, bool post_sq);
  239. int irdma_uk_post_nop(struct irdma_qp_uk *qp, u64 wr_id, bool signaled,
  240. bool post_sq);
  241. int irdma_uk_post_receive(struct irdma_qp_uk *qp,
  242. struct irdma_post_rq_info *info);
  243. void irdma_uk_qp_post_wr(struct irdma_qp_uk *qp);
  244. int irdma_uk_rdma_read(struct irdma_qp_uk *qp, struct irdma_post_sq_info *info,
  245. bool inv_stag, bool post_sq);
  246. int irdma_uk_rdma_write(struct irdma_qp_uk *qp, struct irdma_post_sq_info *info,
  247. bool post_sq);
  248. int irdma_uk_send(struct irdma_qp_uk *qp, struct irdma_post_sq_info *info,
  249. bool post_sq);
  250. int irdma_uk_stag_local_invalidate(struct irdma_qp_uk *qp,
  251. struct irdma_post_sq_info *info,
  252. bool post_sq);
  253. struct irdma_wqe_uk_ops {
  254. void (*iw_copy_inline_data)(u8 *dest, struct ib_sge *sge_list,
  255. u32 num_sges, u8 polarity);
  256. u16 (*iw_inline_data_size_to_quanta)(u32 data_size);
  257. void (*iw_set_fragment)(__le64 *wqe, u32 offset, struct ib_sge *sge,
  258. u8 valid);
  259. void (*iw_set_mw_bind_wqe)(__le64 *wqe,
  260. struct irdma_bind_window *op_info);
  261. };
  262. int irdma_uk_cq_poll_cmpl(struct irdma_cq_uk *cq,
  263. struct irdma_cq_poll_info *info);
  264. void irdma_uk_cq_request_notification(struct irdma_cq_uk *cq,
  265. enum irdma_cmpl_notify cq_notify);
  266. void irdma_uk_cq_resize(struct irdma_cq_uk *cq, void *cq_base, int size);
  267. void irdma_uk_cq_set_resized_cnt(struct irdma_cq_uk *qp, u16 cnt);
  268. void irdma_uk_cq_init(struct irdma_cq_uk *cq,
  269. struct irdma_cq_uk_init_info *info);
  270. int irdma_uk_qp_init(struct irdma_qp_uk *qp,
  271. struct irdma_qp_uk_init_info *info);
  272. struct irdma_sq_uk_wr_trk_info {
  273. u64 wrid;
  274. u32 wr_len;
  275. u16 quanta;
  276. u8 reserved[2];
  277. };
  278. struct irdma_qp_quanta {
  279. __le64 elem[IRDMA_WQE_SIZE];
  280. };
  281. struct irdma_qp_uk {
  282. struct irdma_qp_quanta *sq_base;
  283. struct irdma_qp_quanta *rq_base;
  284. struct irdma_uk_attrs *uk_attrs;
  285. u32 __iomem *wqe_alloc_db;
  286. struct irdma_sq_uk_wr_trk_info *sq_wrtrk_array;
  287. u64 *rq_wrid_array;
  288. __le64 *shadow_area;
  289. __le32 *push_db;
  290. __le64 *push_wqe;
  291. struct irdma_ring sq_ring;
  292. struct irdma_ring rq_ring;
  293. struct irdma_ring initial_ring;
  294. u32 qp_id;
  295. u32 qp_caps;
  296. u32 sq_size;
  297. u32 rq_size;
  298. u32 max_sq_frag_cnt;
  299. u32 max_rq_frag_cnt;
  300. u32 max_inline_data;
  301. struct irdma_wqe_uk_ops wqe_ops;
  302. u16 conn_wqes;
  303. u8 qp_type;
  304. u8 swqe_polarity;
  305. u8 swqe_polarity_deferred;
  306. u8 rwqe_polarity;
  307. u8 rq_wqe_size;
  308. u8 rq_wqe_size_multiplier;
  309. bool deferred_flag:1;
  310. bool push_mode:1; /* whether the last post wqe was pushed */
  311. bool push_dropped:1;
  312. bool first_sq_wq:1;
  313. bool sq_flush_complete:1; /* Indicates flush was seen and SQ was empty after the flush */
  314. bool rq_flush_complete:1; /* Indicates flush was seen and RQ was empty after the flush */
  315. bool destroy_pending:1; /* Indicates the QP is being destroyed */
  316. void *back_qp;
  317. u8 dbg_rq_flushed;
  318. u8 sq_flush_seen;
  319. u8 rq_flush_seen;
  320. };
  321. struct irdma_cq_uk {
  322. struct irdma_cqe *cq_base;
  323. u32 __iomem *cqe_alloc_db;
  324. u32 __iomem *cq_ack_db;
  325. __le64 *shadow_area;
  326. u32 cq_id;
  327. u32 cq_size;
  328. struct irdma_ring cq_ring;
  329. u8 polarity;
  330. bool avoid_mem_cflct:1;
  331. };
  332. struct irdma_qp_uk_init_info {
  333. struct irdma_qp_quanta *sq;
  334. struct irdma_qp_quanta *rq;
  335. struct irdma_uk_attrs *uk_attrs;
  336. u32 __iomem *wqe_alloc_db;
  337. __le64 *shadow_area;
  338. struct irdma_sq_uk_wr_trk_info *sq_wrtrk_array;
  339. u64 *rq_wrid_array;
  340. u32 qp_id;
  341. u32 qp_caps;
  342. u32 sq_size;
  343. u32 rq_size;
  344. u32 max_sq_frag_cnt;
  345. u32 max_rq_frag_cnt;
  346. u32 max_inline_data;
  347. u8 first_sq_wq;
  348. u8 type;
  349. int abi_ver;
  350. bool legacy_mode;
  351. };
  352. struct irdma_cq_uk_init_info {
  353. u32 __iomem *cqe_alloc_db;
  354. u32 __iomem *cq_ack_db;
  355. struct irdma_cqe *cq_base;
  356. __le64 *shadow_area;
  357. u32 cq_size;
  358. u32 cq_id;
  359. bool avoid_mem_cflct;
  360. };
  361. __le64 *irdma_qp_get_next_send_wqe(struct irdma_qp_uk *qp, u32 *wqe_idx,
  362. u16 quanta, u32 total_size,
  363. struct irdma_post_sq_info *info);
  364. __le64 *irdma_qp_get_next_recv_wqe(struct irdma_qp_uk *qp, u32 *wqe_idx);
  365. void irdma_uk_clean_cq(void *q, struct irdma_cq_uk *cq);
  366. int irdma_nop(struct irdma_qp_uk *qp, u64 wr_id, bool signaled, bool post_sq);
  367. int irdma_fragcnt_to_quanta_sq(u32 frag_cnt, u16 *quanta);
  368. int irdma_fragcnt_to_wqesize_rq(u32 frag_cnt, u16 *wqe_size);
  369. void irdma_get_wqe_shift(struct irdma_uk_attrs *uk_attrs, u32 sge,
  370. u32 inline_data, u8 *shift);
  371. int irdma_get_sqdepth(struct irdma_uk_attrs *uk_attrs, u32 sq_size, u8 shift,
  372. u32 *wqdepth);
  373. int irdma_get_rqdepth(struct irdma_uk_attrs *uk_attrs, u32 rq_size, u8 shift,
  374. u32 *wqdepth);
  375. void irdma_qp_push_wqe(struct irdma_qp_uk *qp, __le64 *wqe, u16 quanta,
  376. u32 wqe_idx, bool post_sq);
  377. void irdma_clr_wqes(struct irdma_qp_uk *qp, u32 qp_wqe_idx);
  378. #endif /* IRDMA_USER_H */