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