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