qp.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef MLX4_QP_H
  33. #define MLX4_QP_H
  34. #include <linux/types.h>
  35. #include <linux/mlx4/device.h>
  36. #define MLX4_INVALID_LKEY 0x100
  37. enum mlx4_qp_optpar {
  38. MLX4_QP_OPTPAR_ALT_ADDR_PATH = 1 << 0,
  39. MLX4_QP_OPTPAR_RRE = 1 << 1,
  40. MLX4_QP_OPTPAR_RAE = 1 << 2,
  41. MLX4_QP_OPTPAR_RWE = 1 << 3,
  42. MLX4_QP_OPTPAR_PKEY_INDEX = 1 << 4,
  43. MLX4_QP_OPTPAR_Q_KEY = 1 << 5,
  44. MLX4_QP_OPTPAR_RNR_TIMEOUT = 1 << 6,
  45. MLX4_QP_OPTPAR_PRIMARY_ADDR_PATH = 1 << 7,
  46. MLX4_QP_OPTPAR_SRA_MAX = 1 << 8,
  47. MLX4_QP_OPTPAR_RRA_MAX = 1 << 9,
  48. MLX4_QP_OPTPAR_PM_STATE = 1 << 10,
  49. MLX4_QP_OPTPAR_RETRY_COUNT = 1 << 12,
  50. MLX4_QP_OPTPAR_RNR_RETRY = 1 << 13,
  51. MLX4_QP_OPTPAR_ACK_TIMEOUT = 1 << 14,
  52. MLX4_QP_OPTPAR_SCHED_QUEUE = 1 << 16,
  53. MLX4_QP_OPTPAR_COUNTER_INDEX = 1 << 20
  54. };
  55. enum mlx4_qp_state {
  56. MLX4_QP_STATE_RST = 0,
  57. MLX4_QP_STATE_INIT = 1,
  58. MLX4_QP_STATE_RTR = 2,
  59. MLX4_QP_STATE_RTS = 3,
  60. MLX4_QP_STATE_SQER = 4,
  61. MLX4_QP_STATE_SQD = 5,
  62. MLX4_QP_STATE_ERR = 6,
  63. MLX4_QP_STATE_SQ_DRAINING = 7,
  64. MLX4_QP_NUM_STATE
  65. };
  66. enum {
  67. MLX4_QP_ST_RC = 0x0,
  68. MLX4_QP_ST_UC = 0x1,
  69. MLX4_QP_ST_RD = 0x2,
  70. MLX4_QP_ST_UD = 0x3,
  71. MLX4_QP_ST_XRC = 0x6,
  72. MLX4_QP_ST_MLX = 0x7
  73. };
  74. enum {
  75. MLX4_QP_PM_MIGRATED = 0x3,
  76. MLX4_QP_PM_ARMED = 0x0,
  77. MLX4_QP_PM_REARM = 0x1
  78. };
  79. enum {
  80. /* params1 */
  81. MLX4_QP_BIT_SRE = 1 << 15,
  82. MLX4_QP_BIT_SWE = 1 << 14,
  83. MLX4_QP_BIT_SAE = 1 << 13,
  84. /* params2 */
  85. MLX4_QP_BIT_RRE = 1 << 15,
  86. MLX4_QP_BIT_RWE = 1 << 14,
  87. MLX4_QP_BIT_RAE = 1 << 13,
  88. MLX4_QP_BIT_RIC = 1 << 4,
  89. };
  90. enum {
  91. MLX4_RSS_HASH_XOR = 0,
  92. MLX4_RSS_HASH_TOP = 1,
  93. MLX4_RSS_UDP_IPV6 = 1 << 0,
  94. MLX4_RSS_UDP_IPV4 = 1 << 1,
  95. MLX4_RSS_TCP_IPV6 = 1 << 2,
  96. MLX4_RSS_IPV6 = 1 << 3,
  97. MLX4_RSS_TCP_IPV4 = 1 << 4,
  98. MLX4_RSS_IPV4 = 1 << 5,
  99. /* offset of mlx4_rss_context within mlx4_qp_context.pri_path */
  100. MLX4_RSS_OFFSET_IN_QPC_PRI_PATH = 0x24,
  101. /* offset of being RSS indirection QP within mlx4_qp_context.flags */
  102. MLX4_RSS_QPC_FLAG_OFFSET = 13,
  103. };
  104. struct mlx4_rss_context {
  105. __be32 base_qpn;
  106. __be32 default_qpn;
  107. u16 reserved;
  108. u8 hash_fn;
  109. u8 flags;
  110. __be32 rss_key[10];
  111. __be32 base_qpn_udp;
  112. };
  113. struct mlx4_qp_path {
  114. u8 fl;
  115. u8 reserved1[2];
  116. u8 pkey_index;
  117. u8 counter_index;
  118. u8 grh_mylmc;
  119. __be16 rlid;
  120. u8 ackto;
  121. u8 mgid_index;
  122. u8 static_rate;
  123. u8 hop_limit;
  124. __be32 tclass_flowlabel;
  125. u8 rgid[16];
  126. u8 sched_queue;
  127. u8 vlan_index;
  128. u8 feup;
  129. u8 reserved3;
  130. u8 reserved4[2];
  131. u8 dmac[6];
  132. };
  133. struct mlx4_qp_context {
  134. __be32 flags;
  135. __be32 pd;
  136. u8 mtu_msgmax;
  137. u8 rq_size_stride;
  138. u8 sq_size_stride;
  139. u8 rlkey;
  140. __be32 usr_page;
  141. __be32 local_qpn;
  142. __be32 remote_qpn;
  143. struct mlx4_qp_path pri_path;
  144. struct mlx4_qp_path alt_path;
  145. __be32 params1;
  146. u32 reserved1;
  147. __be32 next_send_psn;
  148. __be32 cqn_send;
  149. u32 reserved2[2];
  150. __be32 last_acked_psn;
  151. __be32 ssn;
  152. __be32 params2;
  153. __be32 rnr_nextrecvpsn;
  154. __be32 xrcd;
  155. __be32 cqn_recv;
  156. __be64 db_rec_addr;
  157. __be32 qkey;
  158. __be32 srqn;
  159. __be32 msn;
  160. __be16 rq_wqe_counter;
  161. __be16 sq_wqe_counter;
  162. u32 reserved3[2];
  163. __be32 param3;
  164. __be32 nummmcpeers_basemkey;
  165. u8 log_page_size;
  166. u8 reserved4[2];
  167. u8 mtt_base_addr_h;
  168. __be32 mtt_base_addr_l;
  169. u32 reserved5[10];
  170. };
  171. /* Which firmware version adds support for NEC (NoErrorCompletion) bit */
  172. #define MLX4_FW_VER_WQE_CTRL_NEC mlx4_fw_ver(2, 2, 232)
  173. enum {
  174. MLX4_WQE_CTRL_NEC = 1 << 29,
  175. MLX4_WQE_CTRL_FENCE = 1 << 6,
  176. MLX4_WQE_CTRL_CQ_UPDATE = 3 << 2,
  177. MLX4_WQE_CTRL_SOLICITED = 1 << 1,
  178. MLX4_WQE_CTRL_IP_CSUM = 1 << 4,
  179. MLX4_WQE_CTRL_TCP_UDP_CSUM = 1 << 5,
  180. MLX4_WQE_CTRL_INS_VLAN = 1 << 6,
  181. MLX4_WQE_CTRL_STRONG_ORDER = 1 << 7,
  182. MLX4_WQE_CTRL_FORCE_LOOPBACK = 1 << 0,
  183. };
  184. struct mlx4_wqe_ctrl_seg {
  185. __be32 owner_opcode;
  186. __be16 vlan_tag;
  187. u8 ins_vlan;
  188. u8 fence_size;
  189. /*
  190. * High 24 bits are SRC remote buffer; low 8 bits are flags:
  191. * [7] SO (strong ordering)
  192. * [5] TCP/UDP checksum
  193. * [4] IP checksum
  194. * [3:2] C (generate completion queue entry)
  195. * [1] SE (solicited event)
  196. * [0] FL (force loopback)
  197. */
  198. union {
  199. __be32 srcrb_flags;
  200. __be16 srcrb_flags16[2];
  201. };
  202. /*
  203. * imm is immediate data for send/RDMA write w/ immediate;
  204. * also invalidation key for send with invalidate; input
  205. * modifier for WQEs on CCQs.
  206. */
  207. __be32 imm;
  208. };
  209. enum {
  210. MLX4_WQE_MLX_VL15 = 1 << 17,
  211. MLX4_WQE_MLX_SLR = 1 << 16
  212. };
  213. struct mlx4_wqe_mlx_seg {
  214. u8 owner;
  215. u8 reserved1[2];
  216. u8 opcode;
  217. __be16 sched_prio;
  218. u8 reserved2;
  219. u8 size;
  220. /*
  221. * [17] VL15
  222. * [16] SLR
  223. * [15:12] static rate
  224. * [11:8] SL
  225. * [4] ICRC
  226. * [3:2] C
  227. * [0] FL (force loopback)
  228. */
  229. __be32 flags;
  230. __be16 rlid;
  231. u16 reserved3;
  232. };
  233. struct mlx4_wqe_datagram_seg {
  234. __be32 av[8];
  235. __be32 dqpn;
  236. __be32 qkey;
  237. __be16 vlan;
  238. u8 mac[6];
  239. };
  240. struct mlx4_wqe_lso_seg {
  241. __be32 mss_hdr_size;
  242. __be32 header[0];
  243. };
  244. struct mlx4_wqe_bind_seg {
  245. __be32 flags1;
  246. __be32 flags2;
  247. __be32 new_rkey;
  248. __be32 lkey;
  249. __be64 addr;
  250. __be64 length;
  251. };
  252. enum {
  253. MLX4_WQE_FMR_PERM_LOCAL_READ = 1 << 27,
  254. MLX4_WQE_FMR_PERM_LOCAL_WRITE = 1 << 28,
  255. MLX4_WQE_FMR_PERM_REMOTE_READ = 1 << 29,
  256. MLX4_WQE_FMR_PERM_REMOTE_WRITE = 1 << 30,
  257. MLX4_WQE_FMR_PERM_ATOMIC = 1 << 31
  258. };
  259. struct mlx4_wqe_fmr_seg {
  260. __be32 flags;
  261. __be32 mem_key;
  262. __be64 buf_list;
  263. __be64 start_addr;
  264. __be64 reg_len;
  265. __be32 offset;
  266. __be32 page_size;
  267. u32 reserved[2];
  268. };
  269. struct mlx4_wqe_fmr_ext_seg {
  270. u8 flags;
  271. u8 reserved;
  272. __be16 app_mask;
  273. __be16 wire_app_tag;
  274. __be16 mem_app_tag;
  275. __be32 wire_ref_tag_base;
  276. __be32 mem_ref_tag_base;
  277. };
  278. struct mlx4_wqe_local_inval_seg {
  279. __be32 flags;
  280. u32 reserved1;
  281. __be32 mem_key;
  282. u32 reserved2[2];
  283. __be32 guest_id;
  284. __be64 pa;
  285. };
  286. struct mlx4_wqe_raddr_seg {
  287. __be64 raddr;
  288. __be32 rkey;
  289. u32 reserved;
  290. };
  291. struct mlx4_wqe_atomic_seg {
  292. __be64 swap_add;
  293. __be64 compare;
  294. };
  295. struct mlx4_wqe_masked_atomic_seg {
  296. __be64 swap_add;
  297. __be64 compare;
  298. __be64 swap_add_mask;
  299. __be64 compare_mask;
  300. };
  301. struct mlx4_wqe_data_seg {
  302. __be32 byte_count;
  303. __be32 lkey;
  304. __be64 addr;
  305. };
  306. enum {
  307. MLX4_INLINE_ALIGN = 64,
  308. MLX4_INLINE_SEG = 1 << 31,
  309. };
  310. struct mlx4_wqe_inline_seg {
  311. __be32 byte_count;
  312. };
  313. int mlx4_qp_modify(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
  314. enum mlx4_qp_state cur_state, enum mlx4_qp_state new_state,
  315. struct mlx4_qp_context *context, enum mlx4_qp_optpar optpar,
  316. int sqd_event, struct mlx4_qp *qp);
  317. int mlx4_qp_query(struct mlx4_dev *dev, struct mlx4_qp *qp,
  318. struct mlx4_qp_context *context);
  319. int mlx4_qp_to_ready(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
  320. struct mlx4_qp_context *context,
  321. struct mlx4_qp *qp, enum mlx4_qp_state *qp_state);
  322. static inline struct mlx4_qp *__mlx4_qp_lookup(struct mlx4_dev *dev, u32 qpn)
  323. {
  324. return radix_tree_lookup(&dev->qp_table_tree, qpn & (dev->caps.num_qps - 1));
  325. }
  326. void mlx4_qp_remove(struct mlx4_dev *dev, struct mlx4_qp *qp);
  327. #endif /* MLX4_QP_H */