qp.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. /*
  2. * Copyright (c) 2013, Mellanox Technologies 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 MLX5_QP_H
  33. #define MLX5_QP_H
  34. #include <linux/mlx5/device.h>
  35. #include <linux/mlx5/driver.h>
  36. #define MLX5_INVALID_LKEY 0x100
  37. #define MLX5_SIG_WQE_SIZE (MLX5_SEND_WQE_BB * 5)
  38. #define MLX5_DIF_SIZE 8
  39. #define MLX5_STRIDE_BLOCK_OP 0x400
  40. #define MLX5_CPY_GRD_MASK 0xc0
  41. #define MLX5_CPY_APP_MASK 0x30
  42. #define MLX5_CPY_REF_MASK 0x0f
  43. #define MLX5_BSF_INC_REFTAG (1 << 6)
  44. #define MLX5_BSF_INL_VALID (1 << 15)
  45. #define MLX5_BSF_REFRESH_DIF (1 << 14)
  46. #define MLX5_BSF_REPEAT_BLOCK (1 << 7)
  47. #define MLX5_BSF_APPTAG_ESCAPE 0x1
  48. #define MLX5_BSF_APPREF_ESCAPE 0x2
  49. enum mlx5_qp_optpar {
  50. MLX5_QP_OPTPAR_ALT_ADDR_PATH = 1 << 0,
  51. MLX5_QP_OPTPAR_RRE = 1 << 1,
  52. MLX5_QP_OPTPAR_RAE = 1 << 2,
  53. MLX5_QP_OPTPAR_RWE = 1 << 3,
  54. MLX5_QP_OPTPAR_PKEY_INDEX = 1 << 4,
  55. MLX5_QP_OPTPAR_Q_KEY = 1 << 5,
  56. MLX5_QP_OPTPAR_RNR_TIMEOUT = 1 << 6,
  57. MLX5_QP_OPTPAR_PRIMARY_ADDR_PATH = 1 << 7,
  58. MLX5_QP_OPTPAR_SRA_MAX = 1 << 8,
  59. MLX5_QP_OPTPAR_RRA_MAX = 1 << 9,
  60. MLX5_QP_OPTPAR_PM_STATE = 1 << 10,
  61. MLX5_QP_OPTPAR_RETRY_COUNT = 1 << 12,
  62. MLX5_QP_OPTPAR_RNR_RETRY = 1 << 13,
  63. MLX5_QP_OPTPAR_ACK_TIMEOUT = 1 << 14,
  64. MLX5_QP_OPTPAR_PRI_PORT = 1 << 16,
  65. MLX5_QP_OPTPAR_SRQN = 1 << 18,
  66. MLX5_QP_OPTPAR_CQN_RCV = 1 << 19,
  67. MLX5_QP_OPTPAR_DC_HS = 1 << 20,
  68. MLX5_QP_OPTPAR_DC_KEY = 1 << 21,
  69. };
  70. enum mlx5_qp_state {
  71. MLX5_QP_STATE_RST = 0,
  72. MLX5_QP_STATE_INIT = 1,
  73. MLX5_QP_STATE_RTR = 2,
  74. MLX5_QP_STATE_RTS = 3,
  75. MLX5_QP_STATE_SQER = 4,
  76. MLX5_QP_STATE_SQD = 5,
  77. MLX5_QP_STATE_ERR = 6,
  78. MLX5_QP_STATE_SQ_DRAINING = 7,
  79. MLX5_QP_STATE_SUSPENDED = 9,
  80. MLX5_QP_NUM_STATE
  81. };
  82. enum {
  83. MLX5_QP_ST_RC = 0x0,
  84. MLX5_QP_ST_UC = 0x1,
  85. MLX5_QP_ST_UD = 0x2,
  86. MLX5_QP_ST_XRC = 0x3,
  87. MLX5_QP_ST_MLX = 0x4,
  88. MLX5_QP_ST_DCI = 0x5,
  89. MLX5_QP_ST_DCT = 0x6,
  90. MLX5_QP_ST_QP0 = 0x7,
  91. MLX5_QP_ST_QP1 = 0x8,
  92. MLX5_QP_ST_RAW_ETHERTYPE = 0x9,
  93. MLX5_QP_ST_RAW_IPV6 = 0xa,
  94. MLX5_QP_ST_SNIFFER = 0xb,
  95. MLX5_QP_ST_SYNC_UMR = 0xe,
  96. MLX5_QP_ST_PTP_1588 = 0xd,
  97. MLX5_QP_ST_REG_UMR = 0xc,
  98. MLX5_QP_ST_MAX
  99. };
  100. enum {
  101. MLX5_QP_PM_MIGRATED = 0x3,
  102. MLX5_QP_PM_ARMED = 0x0,
  103. MLX5_QP_PM_REARM = 0x1
  104. };
  105. enum {
  106. MLX5_NON_ZERO_RQ = 0 << 24,
  107. MLX5_SRQ_RQ = 1 << 24,
  108. MLX5_CRQ_RQ = 2 << 24,
  109. MLX5_ZERO_LEN_RQ = 3 << 24
  110. };
  111. enum {
  112. /* params1 */
  113. MLX5_QP_BIT_SRE = 1 << 15,
  114. MLX5_QP_BIT_SWE = 1 << 14,
  115. MLX5_QP_BIT_SAE = 1 << 13,
  116. /* params2 */
  117. MLX5_QP_BIT_RRE = 1 << 15,
  118. MLX5_QP_BIT_RWE = 1 << 14,
  119. MLX5_QP_BIT_RAE = 1 << 13,
  120. MLX5_QP_BIT_RIC = 1 << 4,
  121. };
  122. enum {
  123. MLX5_WQE_CTRL_CQ_UPDATE = 2 << 2,
  124. MLX5_WQE_CTRL_SOLICITED = 1 << 1,
  125. };
  126. enum {
  127. MLX5_SEND_WQE_BB = 64,
  128. };
  129. enum {
  130. MLX5_WQE_FMR_PERM_LOCAL_READ = 1 << 27,
  131. MLX5_WQE_FMR_PERM_LOCAL_WRITE = 1 << 28,
  132. MLX5_WQE_FMR_PERM_REMOTE_READ = 1 << 29,
  133. MLX5_WQE_FMR_PERM_REMOTE_WRITE = 1 << 30,
  134. MLX5_WQE_FMR_PERM_ATOMIC = 1 << 31
  135. };
  136. enum {
  137. MLX5_FENCE_MODE_NONE = 0 << 5,
  138. MLX5_FENCE_MODE_INITIATOR_SMALL = 1 << 5,
  139. MLX5_FENCE_MODE_STRONG_ORDERING = 3 << 5,
  140. MLX5_FENCE_MODE_SMALL_AND_FENCE = 4 << 5,
  141. };
  142. enum {
  143. MLX5_QP_LAT_SENSITIVE = 1 << 28,
  144. MLX5_QP_BLOCK_MCAST = 1 << 30,
  145. MLX5_QP_ENABLE_SIG = 1 << 31,
  146. };
  147. enum {
  148. MLX5_RCV_DBR = 0,
  149. MLX5_SND_DBR = 1,
  150. };
  151. enum {
  152. MLX5_FLAGS_INLINE = 1<<7,
  153. MLX5_FLAGS_CHECK_FREE = 1<<5,
  154. };
  155. struct mlx5_wqe_fmr_seg {
  156. __be32 flags;
  157. __be32 mem_key;
  158. __be64 buf_list;
  159. __be64 start_addr;
  160. __be64 reg_len;
  161. __be32 offset;
  162. __be32 page_size;
  163. u32 reserved[2];
  164. };
  165. struct mlx5_wqe_ctrl_seg {
  166. __be32 opmod_idx_opcode;
  167. __be32 qpn_ds;
  168. u8 signature;
  169. u8 rsvd[2];
  170. u8 fm_ce_se;
  171. __be32 imm;
  172. };
  173. struct mlx5_wqe_xrc_seg {
  174. __be32 xrc_srqn;
  175. u8 rsvd[12];
  176. };
  177. struct mlx5_wqe_masked_atomic_seg {
  178. __be64 swap_add;
  179. __be64 compare;
  180. __be64 swap_add_mask;
  181. __be64 compare_mask;
  182. };
  183. struct mlx5_av {
  184. union {
  185. struct {
  186. __be32 qkey;
  187. __be32 reserved;
  188. } qkey;
  189. __be64 dc_key;
  190. } key;
  191. __be32 dqp_dct;
  192. u8 stat_rate_sl;
  193. u8 fl_mlid;
  194. __be16 rlid;
  195. u8 reserved0[10];
  196. u8 tclass;
  197. u8 hop_limit;
  198. __be32 grh_gid_fl;
  199. u8 rgid[16];
  200. };
  201. struct mlx5_wqe_datagram_seg {
  202. struct mlx5_av av;
  203. };
  204. struct mlx5_wqe_raddr_seg {
  205. __be64 raddr;
  206. __be32 rkey;
  207. u32 reserved;
  208. };
  209. struct mlx5_wqe_atomic_seg {
  210. __be64 swap_add;
  211. __be64 compare;
  212. };
  213. struct mlx5_wqe_data_seg {
  214. __be32 byte_count;
  215. __be32 lkey;
  216. __be64 addr;
  217. };
  218. struct mlx5_wqe_umr_ctrl_seg {
  219. u8 flags;
  220. u8 rsvd0[3];
  221. __be16 klm_octowords;
  222. __be16 bsf_octowords;
  223. __be64 mkey_mask;
  224. u8 rsvd1[32];
  225. };
  226. struct mlx5_seg_set_psv {
  227. __be32 psv_num;
  228. __be16 syndrome;
  229. __be16 status;
  230. __be32 transient_sig;
  231. __be32 ref_tag;
  232. };
  233. struct mlx5_seg_get_psv {
  234. u8 rsvd[19];
  235. u8 num_psv;
  236. __be32 l_key;
  237. __be64 va;
  238. __be32 psv_index[4];
  239. };
  240. struct mlx5_seg_check_psv {
  241. u8 rsvd0[2];
  242. __be16 err_coalescing_op;
  243. u8 rsvd1[2];
  244. __be16 xport_err_op;
  245. u8 rsvd2[2];
  246. __be16 xport_err_mask;
  247. u8 rsvd3[7];
  248. u8 num_psv;
  249. __be32 l_key;
  250. __be64 va;
  251. __be32 psv_index[4];
  252. };
  253. struct mlx5_rwqe_sig {
  254. u8 rsvd0[4];
  255. u8 signature;
  256. u8 rsvd1[11];
  257. };
  258. struct mlx5_wqe_signature_seg {
  259. u8 rsvd0[4];
  260. u8 signature;
  261. u8 rsvd1[11];
  262. };
  263. struct mlx5_wqe_inline_seg {
  264. __be32 byte_count;
  265. };
  266. enum mlx5_sig_type {
  267. MLX5_DIF_CRC = 0x1,
  268. MLX5_DIF_IPCS = 0x2,
  269. };
  270. struct mlx5_bsf_inl {
  271. __be16 vld_refresh;
  272. __be16 dif_apptag;
  273. __be32 dif_reftag;
  274. u8 sig_type;
  275. u8 rp_inv_seed;
  276. u8 rsvd[3];
  277. u8 dif_inc_ref_guard_check;
  278. __be16 dif_app_bitmask_check;
  279. };
  280. struct mlx5_bsf {
  281. struct mlx5_bsf_basic {
  282. u8 bsf_size_sbs;
  283. u8 check_byte_mask;
  284. union {
  285. u8 copy_byte_mask;
  286. u8 bs_selector;
  287. u8 rsvd_wflags;
  288. } wire;
  289. union {
  290. u8 bs_selector;
  291. u8 rsvd_mflags;
  292. } mem;
  293. __be32 raw_data_size;
  294. __be32 w_bfs_psv;
  295. __be32 m_bfs_psv;
  296. } basic;
  297. struct mlx5_bsf_ext {
  298. __be32 t_init_gen_pro_size;
  299. __be32 rsvd_epi_size;
  300. __be32 w_tfs_psv;
  301. __be32 m_tfs_psv;
  302. } ext;
  303. struct mlx5_bsf_inl w_inl;
  304. struct mlx5_bsf_inl m_inl;
  305. };
  306. struct mlx5_klm {
  307. __be32 bcount;
  308. __be32 key;
  309. __be64 va;
  310. };
  311. struct mlx5_stride_block_entry {
  312. __be16 stride;
  313. __be16 bcount;
  314. __be32 key;
  315. __be64 va;
  316. };
  317. struct mlx5_stride_block_ctrl_seg {
  318. __be32 bcount_per_cycle;
  319. __be32 op;
  320. __be32 repeat_count;
  321. u16 rsvd;
  322. __be16 num_entries;
  323. };
  324. struct mlx5_core_qp {
  325. struct mlx5_core_rsc_common common; /* must be first */
  326. void (*event) (struct mlx5_core_qp *, int);
  327. int qpn;
  328. struct mlx5_rsc_debug *dbg;
  329. int pid;
  330. };
  331. struct mlx5_qp_path {
  332. u8 fl;
  333. u8 rsvd3;
  334. u8 free_ar;
  335. u8 pkey_index;
  336. u8 rsvd0;
  337. u8 grh_mlid;
  338. __be16 rlid;
  339. u8 ackto_lt;
  340. u8 mgid_index;
  341. u8 static_rate;
  342. u8 hop_limit;
  343. __be32 tclass_flowlabel;
  344. u8 rgid[16];
  345. u8 rsvd1[4];
  346. u8 sl;
  347. u8 port;
  348. u8 rsvd2[6];
  349. };
  350. struct mlx5_qp_context {
  351. __be32 flags;
  352. __be32 flags_pd;
  353. u8 mtu_msgmax;
  354. u8 rq_size_stride;
  355. __be16 sq_crq_size;
  356. __be32 qp_counter_set_usr_page;
  357. __be32 wire_qpn;
  358. __be32 log_pg_sz_remote_qpn;
  359. struct mlx5_qp_path pri_path;
  360. struct mlx5_qp_path alt_path;
  361. __be32 params1;
  362. u8 reserved2[4];
  363. __be32 next_send_psn;
  364. __be32 cqn_send;
  365. u8 reserved3[8];
  366. __be32 last_acked_psn;
  367. __be32 ssn;
  368. __be32 params2;
  369. __be32 rnr_nextrecvpsn;
  370. __be32 xrcd;
  371. __be32 cqn_recv;
  372. __be64 db_rec_addr;
  373. __be32 qkey;
  374. __be32 rq_type_srqn;
  375. __be32 rmsn;
  376. __be16 hw_sq_wqe_counter;
  377. __be16 sw_sq_wqe_counter;
  378. __be16 hw_rcyclic_byte_counter;
  379. __be16 hw_rq_counter;
  380. __be16 sw_rcyclic_byte_counter;
  381. __be16 sw_rq_counter;
  382. u8 rsvd0[5];
  383. u8 cgs;
  384. u8 cs_req;
  385. u8 cs_res;
  386. __be64 dc_access_key;
  387. u8 rsvd1[24];
  388. };
  389. struct mlx5_create_qp_mbox_in {
  390. struct mlx5_inbox_hdr hdr;
  391. __be32 input_qpn;
  392. u8 rsvd0[4];
  393. __be32 opt_param_mask;
  394. u8 rsvd1[4];
  395. struct mlx5_qp_context ctx;
  396. u8 rsvd3[16];
  397. __be64 pas[0];
  398. };
  399. struct mlx5_create_qp_mbox_out {
  400. struct mlx5_outbox_hdr hdr;
  401. __be32 qpn;
  402. u8 rsvd0[4];
  403. };
  404. struct mlx5_destroy_qp_mbox_in {
  405. struct mlx5_inbox_hdr hdr;
  406. __be32 qpn;
  407. u8 rsvd0[4];
  408. };
  409. struct mlx5_destroy_qp_mbox_out {
  410. struct mlx5_outbox_hdr hdr;
  411. u8 rsvd0[8];
  412. };
  413. struct mlx5_modify_qp_mbox_in {
  414. struct mlx5_inbox_hdr hdr;
  415. __be32 qpn;
  416. u8 rsvd1[4];
  417. __be32 optparam;
  418. u8 rsvd0[4];
  419. struct mlx5_qp_context ctx;
  420. };
  421. struct mlx5_modify_qp_mbox_out {
  422. struct mlx5_outbox_hdr hdr;
  423. u8 rsvd0[8];
  424. };
  425. struct mlx5_query_qp_mbox_in {
  426. struct mlx5_inbox_hdr hdr;
  427. __be32 qpn;
  428. u8 rsvd[4];
  429. };
  430. struct mlx5_query_qp_mbox_out {
  431. struct mlx5_outbox_hdr hdr;
  432. u8 rsvd1[8];
  433. __be32 optparam;
  434. u8 rsvd0[4];
  435. struct mlx5_qp_context ctx;
  436. u8 rsvd2[16];
  437. __be64 pas[0];
  438. };
  439. struct mlx5_conf_sqp_mbox_in {
  440. struct mlx5_inbox_hdr hdr;
  441. __be32 qpn;
  442. u8 rsvd[3];
  443. u8 type;
  444. };
  445. struct mlx5_conf_sqp_mbox_out {
  446. struct mlx5_outbox_hdr hdr;
  447. u8 rsvd[8];
  448. };
  449. struct mlx5_alloc_xrcd_mbox_in {
  450. struct mlx5_inbox_hdr hdr;
  451. u8 rsvd[8];
  452. };
  453. struct mlx5_alloc_xrcd_mbox_out {
  454. struct mlx5_outbox_hdr hdr;
  455. __be32 xrcdn;
  456. u8 rsvd[4];
  457. };
  458. struct mlx5_dealloc_xrcd_mbox_in {
  459. struct mlx5_inbox_hdr hdr;
  460. __be32 xrcdn;
  461. u8 rsvd[4];
  462. };
  463. struct mlx5_dealloc_xrcd_mbox_out {
  464. struct mlx5_outbox_hdr hdr;
  465. u8 rsvd[8];
  466. };
  467. static inline struct mlx5_core_qp *__mlx5_qp_lookup(struct mlx5_core_dev *dev, u32 qpn)
  468. {
  469. return radix_tree_lookup(&dev->priv.qp_table.tree, qpn);
  470. }
  471. static inline struct mlx5_core_mr *__mlx5_mr_lookup(struct mlx5_core_dev *dev, u32 key)
  472. {
  473. return radix_tree_lookup(&dev->priv.mr_table.tree, key);
  474. }
  475. int mlx5_core_create_qp(struct mlx5_core_dev *dev,
  476. struct mlx5_core_qp *qp,
  477. struct mlx5_create_qp_mbox_in *in,
  478. int inlen);
  479. int mlx5_core_qp_modify(struct mlx5_core_dev *dev, enum mlx5_qp_state cur_state,
  480. enum mlx5_qp_state new_state,
  481. struct mlx5_modify_qp_mbox_in *in, int sqd_event,
  482. struct mlx5_core_qp *qp);
  483. int mlx5_core_destroy_qp(struct mlx5_core_dev *dev,
  484. struct mlx5_core_qp *qp);
  485. int mlx5_core_qp_query(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp,
  486. struct mlx5_query_qp_mbox_out *out, int outlen);
  487. int mlx5_core_xrcd_alloc(struct mlx5_core_dev *dev, u32 *xrcdn);
  488. int mlx5_core_xrcd_dealloc(struct mlx5_core_dev *dev, u32 xrcdn);
  489. void mlx5_init_qp_table(struct mlx5_core_dev *dev);
  490. void mlx5_cleanup_qp_table(struct mlx5_core_dev *dev);
  491. int mlx5_debug_qp_add(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp);
  492. void mlx5_debug_qp_remove(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp);
  493. static inline const char *mlx5_qp_type_str(int type)
  494. {
  495. switch (type) {
  496. case MLX5_QP_ST_RC: return "RC";
  497. case MLX5_QP_ST_UC: return "C";
  498. case MLX5_QP_ST_UD: return "UD";
  499. case MLX5_QP_ST_XRC: return "XRC";
  500. case MLX5_QP_ST_MLX: return "MLX";
  501. case MLX5_QP_ST_QP0: return "QP0";
  502. case MLX5_QP_ST_QP1: return "QP1";
  503. case MLX5_QP_ST_RAW_ETHERTYPE: return "RAW_ETHERTYPE";
  504. case MLX5_QP_ST_RAW_IPV6: return "RAW_IPV6";
  505. case MLX5_QP_ST_SNIFFER: return "SNIFFER";
  506. case MLX5_QP_ST_SYNC_UMR: return "SYNC_UMR";
  507. case MLX5_QP_ST_PTP_1588: return "PTP_1588";
  508. case MLX5_QP_ST_REG_UMR: return "REG_UMR";
  509. default: return "Invalid transport type";
  510. }
  511. }
  512. static inline const char *mlx5_qp_state_str(int state)
  513. {
  514. switch (state) {
  515. case MLX5_QP_STATE_RST:
  516. return "RST";
  517. case MLX5_QP_STATE_INIT:
  518. return "INIT";
  519. case MLX5_QP_STATE_RTR:
  520. return "RTR";
  521. case MLX5_QP_STATE_RTS:
  522. return "RTS";
  523. case MLX5_QP_STATE_SQER:
  524. return "SQER";
  525. case MLX5_QP_STATE_SQD:
  526. return "SQD";
  527. case MLX5_QP_STATE_ERR:
  528. return "ERR";
  529. case MLX5_QP_STATE_SQ_DRAINING:
  530. return "SQ_DRAINING";
  531. case MLX5_QP_STATE_SUSPENDED:
  532. return "SUSPENDED";
  533. default: return "Invalid QP state";
  534. }
  535. }
  536. #endif /* MLX5_QP_H */