common/mlx5: query vDPA DevX capabilities
[dpdk.git] / drivers / common / mlx5 / mlx5_devx_cmds.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2019 Mellanox Technologies, Ltd
3  */
4
5 #ifndef RTE_PMD_MLX5_DEVX_CMDS_H_
6 #define RTE_PMD_MLX5_DEVX_CMDS_H_
7
8 #include "mlx5_glue.h"
9
10
11 /* devX creation object */
12 struct mlx5_devx_obj {
13         struct mlx5dv_devx_obj *obj; /* The DV object. */
14         int id; /* The object ID. */
15 };
16
17 struct mlx5_devx_mkey_attr {
18         uint64_t addr;
19         uint64_t size;
20         uint32_t umem_id;
21         uint32_t pd;
22 };
23
24 /* HCA qos attributes. */
25 struct mlx5_hca_qos_attr {
26         uint32_t sup:1; /* Whether QOS is supported. */
27         uint32_t srtcm_sup:1; /* Whether srTCM mode is supported. */
28         uint32_t flow_meter_reg_share:1;
29         /* Whether reg_c share is supported. */
30         uint8_t log_max_flow_meter;
31         /* Power of the maximum supported meters. */
32         uint8_t flow_meter_reg_c_ids;
33         /* Bitmap of the reg_Cs available for flow meter to use. */
34
35 };
36
37 struct mlx5_hca_vdpa_attr {
38         uint8_t virtio_queue_type;
39         uint32_t valid:1;
40         uint32_t desc_tunnel_offload_type:1;
41         uint32_t eth_frame_offload_type:1;
42         uint32_t virtio_version_1_0:1;
43         uint32_t tso_ipv4:1;
44         uint32_t tso_ipv6:1;
45         uint32_t tx_csum:1;
46         uint32_t rx_csum:1;
47         uint32_t event_mode:3;
48         uint32_t log_doorbell_stride:5;
49         uint32_t log_doorbell_bar_size:5;
50         uint32_t max_num_virtio_queues;
51         uint32_t umem_1_buffer_param_a;
52         uint32_t umem_1_buffer_param_b;
53         uint32_t umem_2_buffer_param_a;
54         uint32_t umem_2_buffer_param_b;
55         uint32_t umem_3_buffer_param_a;
56         uint32_t umem_3_buffer_param_b;
57         uint64_t doorbell_bar_offset;
58 };
59
60 /* HCA supports this number of time periods for LRO. */
61 #define MLX5_LRO_NUM_SUPP_PERIODS 4
62
63 /* HCA attributes. */
64 struct mlx5_hca_attr {
65         uint32_t eswitch_manager:1;
66         uint32_t flow_counters_dump:1;
67         uint8_t flow_counter_bulk_alloc_bitmap;
68         uint32_t eth_net_offloads:1;
69         uint32_t eth_virt:1;
70         uint32_t wqe_vlan_insert:1;
71         uint32_t wqe_inline_mode:2;
72         uint32_t vport_inline_mode:3;
73         uint32_t tunnel_stateless_geneve_rx:1;
74         uint32_t geneve_max_opt_len:1; /* 0x0: 14DW, 0x1: 63DW */
75         uint32_t tunnel_stateless_gtp:1;
76         uint32_t lro_cap:1;
77         uint32_t tunnel_lro_gre:1;
78         uint32_t tunnel_lro_vxlan:1;
79         uint32_t lro_max_msg_sz_mode:2;
80         uint32_t lro_timer_supported_periods[MLX5_LRO_NUM_SUPP_PERIODS];
81         uint32_t flex_parser_protocols;
82         uint32_t hairpin:1;
83         uint32_t log_max_hairpin_queues:5;
84         uint32_t log_max_hairpin_wq_data_sz:5;
85         uint32_t log_max_hairpin_num_packets:5;
86         uint32_t vhca_id:16;
87         struct mlx5_hca_qos_attr qos;
88         struct mlx5_hca_vdpa_attr vdpa;
89 };
90
91 struct mlx5_devx_wq_attr {
92         uint32_t wq_type:4;
93         uint32_t wq_signature:1;
94         uint32_t end_padding_mode:2;
95         uint32_t cd_slave:1;
96         uint32_t hds_skip_first_sge:1;
97         uint32_t log2_hds_buf_size:3;
98         uint32_t page_offset:5;
99         uint32_t lwm:16;
100         uint32_t pd:24;
101         uint32_t uar_page:24;
102         uint64_t dbr_addr;
103         uint32_t hw_counter;
104         uint32_t sw_counter;
105         uint32_t log_wq_stride:4;
106         uint32_t log_wq_pg_sz:5;
107         uint32_t log_wq_sz:5;
108         uint32_t dbr_umem_valid:1;
109         uint32_t wq_umem_valid:1;
110         uint32_t log_hairpin_num_packets:5;
111         uint32_t log_hairpin_data_sz:5;
112         uint32_t single_wqe_log_num_of_strides:4;
113         uint32_t two_byte_shift_en:1;
114         uint32_t single_stride_log_num_of_bytes:3;
115         uint32_t dbr_umem_id;
116         uint32_t wq_umem_id;
117         uint64_t wq_umem_offset;
118 };
119
120 /* Create RQ attributes structure, used by create RQ operation. */
121 struct mlx5_devx_create_rq_attr {
122         uint32_t rlky:1;
123         uint32_t delay_drop_en:1;
124         uint32_t scatter_fcs:1;
125         uint32_t vsd:1;
126         uint32_t mem_rq_type:4;
127         uint32_t state:4;
128         uint32_t flush_in_error_en:1;
129         uint32_t hairpin:1;
130         uint32_t user_index:24;
131         uint32_t cqn:24;
132         uint32_t counter_set_id:8;
133         uint32_t rmpn:24;
134         struct mlx5_devx_wq_attr wq_attr;
135 };
136
137 /* Modify RQ attributes structure, used by modify RQ operation. */
138 struct mlx5_devx_modify_rq_attr {
139         uint32_t rqn:24;
140         uint32_t rq_state:4; /* Current RQ state. */
141         uint32_t state:4; /* Required RQ state. */
142         uint32_t scatter_fcs:1;
143         uint32_t vsd:1;
144         uint32_t counter_set_id:8;
145         uint32_t hairpin_peer_sq:24;
146         uint32_t hairpin_peer_vhca:16;
147         uint64_t modify_bitmask;
148         uint32_t lwm:16; /* Contained WQ lwm. */
149 };
150
151 struct mlx5_rx_hash_field_select {
152         uint32_t l3_prot_type:1;
153         uint32_t l4_prot_type:1;
154         uint32_t selected_fields:30;
155 };
156
157 /* TIR attributes structure, used by TIR operations. */
158 struct mlx5_devx_tir_attr {
159         uint32_t disp_type:4;
160         uint32_t lro_timeout_period_usecs:16;
161         uint32_t lro_enable_mask:4;
162         uint32_t lro_max_msg_sz:8;
163         uint32_t inline_rqn:24;
164         uint32_t rx_hash_symmetric:1;
165         uint32_t tunneled_offload_en:1;
166         uint32_t indirect_table:24;
167         uint32_t rx_hash_fn:4;
168         uint32_t self_lb_block:2;
169         uint32_t transport_domain:24;
170         uint32_t rx_hash_toeplitz_key[10];
171         struct mlx5_rx_hash_field_select rx_hash_field_selector_outer;
172         struct mlx5_rx_hash_field_select rx_hash_field_selector_inner;
173 };
174
175 /* RQT attributes structure, used by RQT operations. */
176 struct mlx5_devx_rqt_attr {
177         uint32_t rqt_max_size:16;
178         uint32_t rqt_actual_size:16;
179         uint32_t rq_list[];
180 };
181
182 /* TIS attributes structure. */
183 struct mlx5_devx_tis_attr {
184         uint32_t strict_lag_tx_port_affinity:1;
185         uint32_t tls_en:1;
186         uint32_t lag_tx_port_affinity:4;
187         uint32_t prio:4;
188         uint32_t transport_domain:24;
189 };
190
191 /* SQ attributes structure, used by SQ create operation. */
192 struct mlx5_devx_create_sq_attr {
193         uint32_t rlky:1;
194         uint32_t cd_master:1;
195         uint32_t fre:1;
196         uint32_t flush_in_error_en:1;
197         uint32_t allow_multi_pkt_send_wqe:1;
198         uint32_t min_wqe_inline_mode:3;
199         uint32_t state:4;
200         uint32_t reg_umr:1;
201         uint32_t allow_swp:1;
202         uint32_t hairpin:1;
203         uint32_t user_index:24;
204         uint32_t cqn:24;
205         uint32_t packet_pacing_rate_limit_index:16;
206         uint32_t tis_lst_sz:16;
207         uint32_t tis_num:24;
208         struct mlx5_devx_wq_attr wq_attr;
209 };
210
211 /* SQ attributes structure, used by SQ modify operation. */
212 struct mlx5_devx_modify_sq_attr {
213         uint32_t sq_state:4;
214         uint32_t state:4;
215         uint32_t hairpin_peer_rq:24;
216         uint32_t hairpin_peer_vhca:16;
217 };
218
219 /* mlx5_devx_cmds.c */
220
221 struct mlx5_devx_obj *mlx5_devx_cmd_flow_counter_alloc(struct ibv_context *ctx,
222                                                        uint32_t bulk_sz);
223 int mlx5_devx_cmd_destroy(struct mlx5_devx_obj *obj);
224 int mlx5_devx_cmd_flow_counter_query(struct mlx5_devx_obj *dcs,
225                                      int clear, uint32_t n_counters,
226                                      uint64_t *pkts, uint64_t *bytes,
227                                      uint32_t mkey, void *addr,
228                                      struct mlx5dv_devx_cmd_comp *cmd_comp,
229                                      uint64_t async_id);
230 int mlx5_devx_cmd_query_hca_attr(struct ibv_context *ctx,
231                                  struct mlx5_hca_attr *attr);
232 struct mlx5_devx_obj *mlx5_devx_cmd_mkey_create(struct ibv_context *ctx,
233                                               struct mlx5_devx_mkey_attr *attr);
234 int mlx5_devx_get_out_command_status(void *out);
235 int mlx5_devx_cmd_qp_query_tis_td(struct ibv_qp *qp, uint32_t tis_num,
236                                   uint32_t *tis_td);
237 struct mlx5_devx_obj *mlx5_devx_cmd_create_rq(struct ibv_context *ctx,
238                                        struct mlx5_devx_create_rq_attr *rq_attr,
239                                        int socket);
240 int mlx5_devx_cmd_modify_rq(struct mlx5_devx_obj *rq,
241                             struct mlx5_devx_modify_rq_attr *rq_attr);
242 struct mlx5_devx_obj *mlx5_devx_cmd_create_tir(struct ibv_context *ctx,
243                                            struct mlx5_devx_tir_attr *tir_attr);
244 struct mlx5_devx_obj *mlx5_devx_cmd_create_rqt(struct ibv_context *ctx,
245                                            struct mlx5_devx_rqt_attr *rqt_attr);
246 struct mlx5_devx_obj *mlx5_devx_cmd_create_sq(struct ibv_context *ctx,
247                                       struct mlx5_devx_create_sq_attr *sq_attr);
248 int mlx5_devx_cmd_modify_sq(struct mlx5_devx_obj *sq,
249                             struct mlx5_devx_modify_sq_attr *sq_attr);
250 struct mlx5_devx_obj *mlx5_devx_cmd_create_tis(struct ibv_context *ctx,
251                                            struct mlx5_devx_tis_attr *tis_attr);
252 struct mlx5_devx_obj *mlx5_devx_cmd_create_td(struct ibv_context *ctx);
253 int mlx5_devx_cmd_flow_dump(void *fdb_domain, void *rx_domain, void *tx_domain,
254                             FILE *file);
255 #endif /* RTE_PMD_MLX5_DEVX_CMDS_H_ */