Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2015 6WIND S.A.
3 : : * Copyright 2020 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #include <stddef.h>
7 : : #include <unistd.h>
8 : : #include <string.h>
9 : : #include <stdint.h>
10 : : #include <stdlib.h>
11 : : #include <errno.h>
12 : : #include <net/if.h>
13 : : #include <linux/rtnetlink.h>
14 : : #include <linux/sockios.h>
15 : : #include <linux/ethtool.h>
16 : : #include <fcntl.h>
17 : :
18 : : #include <rte_malloc.h>
19 : : #include <ethdev_driver.h>
20 : : #include <ethdev_pci.h>
21 : : #include <rte_pci.h>
22 : : #include <bus_driver.h>
23 : : #include <bus_pci_driver.h>
24 : : #include <bus_auxiliary_driver.h>
25 : : #include <rte_common.h>
26 : : #include <rte_kvargs.h>
27 : : #include <rte_rwlock.h>
28 : : #include <rte_spinlock.h>
29 : : #include <rte_string_fns.h>
30 : : #include <rte_alarm.h>
31 : : #include <rte_eal_paging.h>
32 : :
33 : : #include <mlx5_glue.h>
34 : : #include <mlx5_devx_cmds.h>
35 : : #include <mlx5_common.h>
36 : : #include <mlx5_common_mp.h>
37 : : #include <mlx5_common_mr.h>
38 : : #include <mlx5_malloc.h>
39 : :
40 : : #include "mlx5_defs.h"
41 : : #include "mlx5.h"
42 : : #include "mlx5_common_os.h"
43 : : #include "mlx5_utils.h"
44 : : #include "mlx5_rxtx.h"
45 : : #include "mlx5_rx.h"
46 : : #include "mlx5_tx.h"
47 : : #include "mlx5_autoconf.h"
48 : : #include "mlx5_flow.h"
49 : : #include "rte_pmd_mlx5.h"
50 : : #include "mlx5_verbs.h"
51 : : #include "mlx5_nl.h"
52 : : #include "mlx5_devx.h"
53 : :
54 : : #ifndef HAVE_IBV_MLX5_MOD_MPW
55 : : #define MLX5DV_CONTEXT_FLAGS_MPW_ALLOWED (1 << 2)
56 : : #define MLX5DV_CONTEXT_FLAGS_ENHANCED_MPW (1 << 3)
57 : : #endif
58 : :
59 : : #ifndef HAVE_IBV_MLX5_MOD_CQE_128B_COMP
60 : : #define MLX5DV_CONTEXT_FLAGS_CQE_128B_COMP (1 << 4)
61 : : #endif
62 : :
63 : : static const char *MZ_MLX5_PMD_SHARED_DATA = "mlx5_pmd_shared_data";
64 : :
65 : : /* Spinlock for mlx5_shared_data allocation. */
66 : : static rte_spinlock_t mlx5_shared_data_lock = RTE_SPINLOCK_INITIALIZER;
67 : :
68 : : /* Process local data for secondary processes. */
69 : : static struct mlx5_local_data mlx5_local_data;
70 : :
71 : : /* rte flow indexed pool configuration. */
72 : : static const struct mlx5_indexed_pool_config default_icfg[] = {
73 : : {
74 : : .size = sizeof(struct rte_flow),
75 : : .trunk_size = 64,
76 : : .need_lock = 1,
77 : : .release_mem_en = 0,
78 : : .malloc = mlx5_malloc,
79 : : .free = mlx5_free,
80 : : .per_core_cache = 0,
81 : : .type = "ctl_flow_ipool",
82 : : },
83 : : {
84 : : .size = sizeof(struct rte_flow),
85 : : .trunk_size = 64,
86 : : .grow_trunk = 3,
87 : : .grow_shift = 2,
88 : : .need_lock = 1,
89 : : .release_mem_en = 0,
90 : : .malloc = mlx5_malloc,
91 : : .free = mlx5_free,
92 : : .per_core_cache = 1 << 14,
93 : : .type = "rte_flow_ipool",
94 : : },
95 : : {
96 : : .size = sizeof(struct rte_flow),
97 : : .trunk_size = 64,
98 : : .grow_trunk = 3,
99 : : .grow_shift = 2,
100 : : .need_lock = 1,
101 : : .release_mem_en = 0,
102 : : .malloc = mlx5_malloc,
103 : : .free = mlx5_free,
104 : : .per_core_cache = 0,
105 : : .type = "mcp_flow_ipool",
106 : : },
107 : : };
108 : :
109 : : /**
110 : : * Set the completion channel file descriptor interrupt as non-blocking.
111 : : *
112 : : * @param[in] rxq_obj
113 : : * Pointer to RQ channel object, which includes the channel fd
114 : : *
115 : : * @param[out] fd
116 : : * The file descriptor (representing the interrupt) used in this channel.
117 : : *
118 : : * @return
119 : : * 0 on successfully setting the fd to non-blocking, non-zero otherwise.
120 : : */
121 : : int
122 : 0 : mlx5_os_set_nonblock_channel_fd(int fd)
123 : : {
124 : : int flags;
125 : :
126 : 0 : flags = fcntl(fd, F_GETFL);
127 : 0 : return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
128 : : }
129 : :
130 : : /**
131 : : * Get mlx5 device attributes. The glue function query_device_ex() is called
132 : : * with out parameter of type 'struct ibv_device_attr_ex *'. Then fill in mlx5
133 : : * device attributes from the glue out parameter.
134 : : *
135 : : * @param sh
136 : : * Pointer to shared device context.
137 : : *
138 : : * @return
139 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
140 : : */
141 : : int
142 : 0 : mlx5_os_capabilities_prepare(struct mlx5_dev_ctx_shared *sh)
143 : : {
144 : : int err;
145 : 0 : struct mlx5_common_device *cdev = sh->cdev;
146 : 0 : struct mlx5_hca_attr *hca_attr = &cdev->config.hca_attr;
147 : 0 : struct ibv_device_attr_ex attr_ex = { .comp_mask = 0 };
148 : 0 : struct mlx5dv_context dv_attr = { .comp_mask = 0 };
149 : :
150 : 0 : err = mlx5_glue->query_device_ex(cdev->ctx, NULL, &attr_ex);
151 [ # # ]: 0 : if (err) {
152 : 0 : rte_errno = errno;
153 : 0 : return -rte_errno;
154 : : }
155 : : #ifdef HAVE_IBV_MLX5_MOD_SWP
156 : 0 : dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_SWP;
157 : : #endif
158 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
159 : 0 : dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_TUNNEL_OFFLOADS;
160 : : #endif
161 : : #ifdef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
162 : 0 : dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_STRIDING_RQ;
163 : : #endif
164 : : #ifdef HAVE_IBV_DEVICE_ATTR_ESW_MGR_REG_C0
165 : : dv_attr.comp_mask |= MLX5DV_CONTEXT_MASK_REG_C0;
166 : : #endif
167 : 0 : err = mlx5_glue->dv_query_device(cdev->ctx, &dv_attr);
168 [ # # ]: 0 : if (err) {
169 : 0 : rte_errno = errno;
170 : 0 : return -rte_errno;
171 : : }
172 : 0 : memset(&sh->dev_cap, 0, sizeof(struct mlx5_dev_cap));
173 [ # # ]: 0 : if (mlx5_dev_is_pci(cdev->dev))
174 : 0 : sh->dev_cap.vf = mlx5_dev_is_vf_pci(RTE_BUS_DEVICE(cdev->dev,
175 : : struct rte_pci_device));
176 : : else
177 : 0 : sh->dev_cap.sf = 1;
178 : 0 : sh->dev_cap.max_qp_wr = attr_ex.orig_attr.max_qp_wr;
179 : 0 : sh->dev_cap.max_sge = attr_ex.orig_attr.max_sge;
180 : 0 : sh->dev_cap.max_cq = attr_ex.orig_attr.max_cq;
181 : 0 : sh->dev_cap.max_qp = attr_ex.orig_attr.max_qp;
182 : : #ifdef HAVE_MLX5DV_DR_ACTION_DEST_DEVX_TIR
183 : 0 : sh->dev_cap.dest_tir = 1;
184 : : #endif
185 : : #if defined(HAVE_IBV_FLOW_DV_SUPPORT) && defined(HAVE_MLX5DV_DR)
186 : 0 : DRV_LOG(DEBUG, "DV flow is supported.");
187 : 0 : sh->dev_cap.dv_flow_en = 1;
188 : : #endif
189 : : #ifdef HAVE_MLX5DV_DR_ESWITCH
190 [ # # # # ]: 0 : if (hca_attr->eswitch_manager && sh->dev_cap.dv_flow_en && sh->esw_mode)
191 : 0 : sh->dev_cap.dv_esw_en = 1;
192 : : #endif
193 : : /*
194 : : * Multi-packet send is supported by ConnectX-4 Lx PF as well
195 : : * as all ConnectX-5 devices.
196 : : */
197 [ # # ]: 0 : if (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_MPW_ALLOWED) {
198 [ # # ]: 0 : if (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_ENHANCED_MPW) {
199 : 0 : DRV_LOG(DEBUG, "Enhanced MPW is supported.");
200 : 0 : sh->dev_cap.mps = MLX5_MPW_ENHANCED;
201 : : } else {
202 : 0 : DRV_LOG(DEBUG, "MPW is supported.");
203 : 0 : sh->dev_cap.mps = MLX5_MPW;
204 : : }
205 : : } else {
206 : 0 : DRV_LOG(DEBUG, "MPW isn't supported.");
207 : 0 : sh->dev_cap.mps = MLX5_MPW_DISABLED;
208 : : }
209 : : #if (RTE_CACHE_LINE_SIZE == 128)
210 : : if (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_CQE_128B_COMP)
211 : : sh->dev_cap.cqe_comp = 1;
212 : : DRV_LOG(DEBUG, "Rx CQE 128B compression is %ssupported.",
213 : : sh->dev_cap.cqe_comp ? "" : "not ");
214 : : #else
215 : 0 : sh->dev_cap.cqe_comp = 1;
216 : : #endif
217 : : #ifdef HAVE_IBV_DEVICE_MPLS_SUPPORT
218 : 0 : sh->dev_cap.mpls_en =
219 : : ((dv_attr.tunnel_offloads_caps &
220 : 0 : MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_CW_MPLS_OVER_GRE) &&
221 : : (dv_attr.tunnel_offloads_caps &
222 : : MLX5DV_RAW_PACKET_CAP_TUNNELED_OFFLOAD_CW_MPLS_OVER_UDP));
223 [ # # ]: 0 : DRV_LOG(DEBUG, "MPLS over GRE/UDP tunnel offloading is %ssupported.",
224 : : sh->dev_cap.mpls_en ? "" : "not ");
225 : : #else
226 : : DRV_LOG(WARNING,
227 : : "MPLS over GRE/UDP tunnel offloading disabled due to old OFED/rdma-core version or firmware configuration");
228 : : #endif
229 : : #if defined(HAVE_IBV_WQ_FLAG_RX_END_PADDING)
230 : : sh->dev_cap.hw_padding = !!attr_ex.rx_pad_end_addr_align;
231 : : #elif defined(HAVE_IBV_WQ_FLAGS_PCI_WRITE_END_PADDING)
232 : 0 : sh->dev_cap.hw_padding = !!(attr_ex.device_cap_flags_ex &
233 : : IBV_DEVICE_PCI_WRITE_END_PADDING);
234 : : #endif
235 : 0 : sh->dev_cap.hw_csum =
236 : 0 : !!(attr_ex.device_cap_flags_ex & IBV_DEVICE_RAW_IP_CSUM);
237 [ # # ]: 0 : DRV_LOG(DEBUG, "Checksum offloading is %ssupported.",
238 : : sh->dev_cap.hw_csum ? "" : "not ");
239 : 0 : sh->dev_cap.hw_vlan_strip = !!(attr_ex.raw_packet_caps &
240 : : IBV_RAW_PACKET_CAP_CVLAN_STRIPPING);
241 [ # # ]: 0 : DRV_LOG(DEBUG, "VLAN stripping is %ssupported.",
242 : : (sh->dev_cap.hw_vlan_strip ? "" : "not "));
243 : 0 : sh->dev_cap.hw_fcs_strip = !!(attr_ex.raw_packet_caps &
244 : : IBV_RAW_PACKET_CAP_SCATTER_FCS);
245 : : #if !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V42) && \
246 : : !defined(HAVE_IBV_DEVICE_COUNTERS_SET_V45)
247 : : DRV_LOG(DEBUG, "Counters are not supported.");
248 : : #endif
249 : : /*
250 : : * DPDK doesn't support larger/variable indirection tables.
251 : : * Once DPDK supports it, take max size from device attr.
252 : : */
253 : 0 : sh->dev_cap.ind_table_max_size =
254 : 0 : RTE_MIN(attr_ex.rss_caps.max_rwq_indirection_table_size,
255 : : (unsigned int)RTE_ETH_RSS_RETA_SIZE_512);
256 : 0 : DRV_LOG(DEBUG, "Maximum Rx indirection table size is %u",
257 : : sh->dev_cap.ind_table_max_size);
258 [ # # ]: 0 : sh->dev_cap.tso = (attr_ex.tso_caps.max_tso > 0 &&
259 [ # # ]: 0 : (attr_ex.tso_caps.supported_qpts &
260 : : (1 << IBV_QPT_RAW_PACKET)));
261 [ # # ]: 0 : if (sh->dev_cap.tso)
262 : 0 : sh->dev_cap.tso_max_payload_sz = attr_ex.tso_caps.max_tso;
263 [ # # ]: 0 : strlcpy(sh->dev_cap.fw_ver, attr_ex.orig_attr.fw_ver,
264 : : sizeof(sh->dev_cap.fw_ver));
265 : : #ifdef HAVE_IBV_MLX5_MOD_SWP
266 [ # # ]: 0 : if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_SWP)
267 : 0 : sh->dev_cap.swp = dv_attr.sw_parsing_caps.sw_parsing_offloads &
268 : : (MLX5_SW_PARSING_CAP |
269 : : MLX5_SW_PARSING_CSUM_CAP |
270 : : MLX5_SW_PARSING_TSO_CAP);
271 : 0 : DRV_LOG(DEBUG, "SWP support: %u", sh->dev_cap.swp);
272 : : #endif
273 : : #ifdef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT
274 [ # # ]: 0 : if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_STRIDING_RQ) {
275 : : struct mlx5dv_striding_rq_caps *strd_rq_caps =
276 : : &dv_attr.striding_rq_caps;
277 : :
278 : 0 : sh->dev_cap.mprq.enabled = 1;
279 : 0 : sh->dev_cap.mprq.log_min_stride_size =
280 : 0 : strd_rq_caps->min_single_stride_log_num_of_bytes;
281 : 0 : sh->dev_cap.mprq.log_max_stride_size =
282 : 0 : strd_rq_caps->max_single_stride_log_num_of_bytes;
283 : 0 : sh->dev_cap.mprq.log_min_stride_num =
284 : 0 : strd_rq_caps->min_single_wqe_log_num_of_strides;
285 : 0 : sh->dev_cap.mprq.log_max_stride_num =
286 : 0 : strd_rq_caps->max_single_wqe_log_num_of_strides;
287 : 0 : sh->dev_cap.mprq.log_min_stride_wqe_size =
288 : 0 : cdev->config.devx ?
289 [ # # ]: 0 : hca_attr->log_min_stride_wqe_sz :
290 : : MLX5_MPRQ_LOG_MIN_STRIDE_WQE_SIZE;
291 : 0 : DRV_LOG(DEBUG, "\tmin_single_stride_log_num_of_bytes: %u",
292 : : sh->dev_cap.mprq.log_min_stride_size);
293 : 0 : DRV_LOG(DEBUG, "\tmax_single_stride_log_num_of_bytes: %u",
294 : : sh->dev_cap.mprq.log_max_stride_size);
295 : 0 : DRV_LOG(DEBUG, "\tmin_single_wqe_log_num_of_strides: %u",
296 : : sh->dev_cap.mprq.log_min_stride_num);
297 : 0 : DRV_LOG(DEBUG, "\tmax_single_wqe_log_num_of_strides: %u",
298 : : sh->dev_cap.mprq.log_max_stride_num);
299 : 0 : DRV_LOG(DEBUG, "\tmin_stride_wqe_log_size: %u",
300 : : sh->dev_cap.mprq.log_min_stride_wqe_size);
301 : 0 : DRV_LOG(DEBUG, "\tsupported_qpts: %d",
302 : : strd_rq_caps->supported_qpts);
303 : 0 : DRV_LOG(DEBUG, "Device supports Multi-Packet RQ.");
304 : : }
305 : : #endif
306 : : #ifdef HAVE_IBV_DEVICE_TUNNEL_SUPPORT
307 [ # # ]: 0 : if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_TUNNEL_OFFLOADS) {
308 : 0 : sh->dev_cap.tunnel_en = dv_attr.tunnel_offloads_caps &
309 : : (MLX5_TUNNELED_OFFLOADS_VXLAN_CAP |
310 : : MLX5_TUNNELED_OFFLOADS_GRE_CAP |
311 : : MLX5_TUNNELED_OFFLOADS_GENEVE_CAP);
312 : : }
313 [ # # ]: 0 : if (sh->dev_cap.tunnel_en) {
314 [ # # # # : 0 : DRV_LOG(DEBUG, "Tunnel offloading is supported for %s%s%s",
# # ]
315 : : sh->dev_cap.tunnel_en &
316 : : MLX5_TUNNELED_OFFLOADS_VXLAN_CAP ? "[VXLAN]" : "",
317 : : sh->dev_cap.tunnel_en &
318 : : MLX5_TUNNELED_OFFLOADS_GRE_CAP ? "[GRE]" : "",
319 : : sh->dev_cap.tunnel_en &
320 : : MLX5_TUNNELED_OFFLOADS_GENEVE_CAP ? "[GENEVE]" : "");
321 : : } else {
322 : 0 : DRV_LOG(DEBUG, "Tunnel offloading is not supported.");
323 : : }
324 : : #else
325 : : DRV_LOG(WARNING,
326 : : "Tunnel offloading disabled due to old OFED/rdma-core version");
327 : : #endif
328 [ # # ]: 0 : if (hca_attr->log_max_current_uc_list > 0)
329 : 0 : sh->dev_cap.max_uc_mac_addrs = RTE_BIT32(hca_attr->log_max_current_uc_list);
330 : : else
331 : 0 : sh->dev_cap.max_uc_mac_addrs = MLX5_MAX_UC_MAC_ADDRESSES;
332 [ # # ]: 0 : if (hca_attr->log_max_current_mc_list > 0)
333 : 0 : sh->dev_cap.max_mc_mac_addrs = RTE_BIT32(hca_attr->log_max_current_mc_list);
334 : : else
335 : 0 : sh->dev_cap.max_mc_mac_addrs = MLX5_MAX_MC_MAC_ADDRESSES;
336 : 0 : sh->dev_cap.max_mac_addrs =
337 : 0 : sh->dev_cap.max_uc_mac_addrs + sh->dev_cap.max_mc_mac_addrs;
338 [ # # ]: 0 : if (!sh->cdev->config.devx)
339 : : return 0;
340 : : /* Check capabilities for Packet Pacing. */
341 : 0 : DRV_LOG(DEBUG, "Timestamp counter frequency %u kHz.",
342 : : hca_attr->dev_freq_khz);
343 [ # # ]: 0 : DRV_LOG(DEBUG, "Packet pacing is %ssupported.",
344 : : hca_attr->qos.packet_pacing ? "" : "not ");
345 [ # # ]: 0 : DRV_LOG(DEBUG, "Cross channel ops are %ssupported.",
346 : : hca_attr->cross_channel ? "" : "not ");
347 [ # # ]: 0 : DRV_LOG(DEBUG, "WQE index ignore is %ssupported.",
348 : : hca_attr->wqe_index_ignore ? "" : "not ");
349 [ # # ]: 0 : DRV_LOG(DEBUG, "Non-wire SQ feature is %ssupported.",
350 : : hca_attr->non_wire_sq ? "" : "not ");
351 [ # # ]: 0 : DRV_LOG(DEBUG, "Static WQE SQ feature is %ssupported (%d)",
352 : : hca_attr->log_max_static_sq_wq ? "" : "not ",
353 : : hca_attr->log_max_static_sq_wq);
354 [ # # ]: 0 : DRV_LOG(DEBUG, "WQE rate PP mode is %ssupported.",
355 : : hca_attr->qos.wqe_rate_pp ? "" : "not ");
356 : 0 : sh->dev_cap.txpp_en = hca_attr->qos.packet_pacing;
357 [ # # ]: 0 : if (!hca_attr->cross_channel) {
358 : 0 : DRV_LOG(DEBUG,
359 : : "Cross channel operations are required for packet pacing.");
360 : 0 : sh->dev_cap.txpp_en = 0;
361 : : }
362 [ # # ]: 0 : if (!hca_attr->wqe_index_ignore) {
363 : 0 : DRV_LOG(DEBUG,
364 : : "WQE index ignore feature is required for packet pacing.");
365 : 0 : sh->dev_cap.txpp_en = 0;
366 : : }
367 [ # # ]: 0 : if (!hca_attr->non_wire_sq) {
368 : 0 : DRV_LOG(DEBUG,
369 : : "Non-wire SQ feature is required for packet pacing.");
370 : 0 : sh->dev_cap.txpp_en = 0;
371 : : }
372 [ # # ]: 0 : if (!hca_attr->log_max_static_sq_wq) {
373 : 0 : DRV_LOG(DEBUG,
374 : : "Static WQE SQ feature is required for packet pacing.");
375 : 0 : sh->dev_cap.txpp_en = 0;
376 : : }
377 [ # # ]: 0 : if (!hca_attr->qos.wqe_rate_pp) {
378 : 0 : DRV_LOG(DEBUG,
379 : : "WQE rate mode is required for packet pacing.");
380 : 0 : sh->dev_cap.txpp_en = 0;
381 : : }
382 : : #ifndef HAVE_MLX5DV_DEVX_UAR_OFFSET
383 : : DRV_LOG(DEBUG,
384 : : "DevX does not provide UAR offset, can't create queues for packet pacing.");
385 : : sh->dev_cap.txpp_en = 0;
386 : : #endif
387 : 0 : sh->dev_cap.scatter_fcs_w_decap_disable =
388 : 0 : hca_attr->scatter_fcs_w_decap_disable;
389 : 0 : sh->dev_cap.rq_delay_drop_en = hca_attr->rq_delay_drop;
390 : 0 : mlx5_rt_timestamp_config(sh, hca_attr);
391 : 0 : sh->dev_cap.esw_info.vhca_id = hca_attr->vhca_id;
392 : : #ifdef HAVE_IBV_DEVICE_ATTR_ESW_MGR_REG_C0
393 : : if (dv_attr.comp_mask & MLX5DV_CONTEXT_MASK_REG_C0) {
394 : : sh->dev_cap.esw_info.regc_value = dv_attr.reg_c0.value;
395 : : sh->dev_cap.esw_info.regc_mask = dv_attr.reg_c0.mask;
396 : : }
397 : : #else
398 : 0 : sh->dev_cap.esw_info.regc_value = 0;
399 : 0 : sh->dev_cap.esw_info.regc_mask = 0;
400 : : #endif
401 : 0 : sh->dev_cap.esw_info.is_set = 1;
402 : 0 : return 0;
403 : : }
404 : :
405 : : /**
406 : : * Detect misc5 support or not
407 : : *
408 : : * @param[in] priv
409 : : * Device private data pointer
410 : : */
411 : : #ifdef HAVE_MLX5DV_DR
412 : : static void
413 : 0 : __mlx5_discovery_misc5_cap(struct mlx5_priv *priv)
414 : : {
415 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
416 : : /* Dummy VxLAN matcher to detect rdma-core misc5 cap
417 : : * Case: IPv4--->UDP--->VxLAN--->vni
418 : : */
419 : : void *tbl;
420 : : struct mlx5_flow_dv_match_params matcher_mask;
421 : : void *match_m;
422 : : void *matcher;
423 : : void *headers_m;
424 : : void *misc5_m;
425 : : uint32_t *tunnel_header_m;
426 : : struct mlx5dv_flow_matcher_attr dv_attr;
427 : :
428 : : memset(&matcher_mask, 0, sizeof(matcher_mask));
429 : 0 : matcher_mask.size = sizeof(matcher_mask.buf);
430 : : match_m = matcher_mask.buf;
431 : : headers_m = MLX5_ADDR_OF(fte_match_param, match_m, outer_headers);
432 : : misc5_m = MLX5_ADDR_OF(fte_match_param,
433 : : match_m, misc_parameters_5);
434 : : tunnel_header_m = (uint32_t *)
435 : : MLX5_ADDR_OF(fte_match_set_misc5,
436 : : misc5_m, tunnel_header_1);
437 : : MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_protocol, 0xff);
438 [ # # ]: 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_m, ip_version, 4);
439 : 0 : MLX5_SET(fte_match_set_lyr_2_4, headers_m, udp_dport, 0xffff);
440 : 0 : *tunnel_header_m = 0xffffff;
441 : :
442 : 0 : tbl = mlx5_glue->dr_create_flow_tbl(priv->sh->rx_domain, 1);
443 [ # # ]: 0 : if (!tbl) {
444 : 0 : DRV_LOG(INFO, "No SW steering support");
445 : 0 : return;
446 : : }
447 : 0 : dv_attr.type = IBV_FLOW_ATTR_NORMAL;
448 : 0 : dv_attr.match_mask = (void *)&matcher_mask;
449 : 0 : dv_attr.match_criteria_enable =
450 : : (1 << MLX5_MATCH_CRITERIA_ENABLE_OUTER_BIT) |
451 : : (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC5_BIT);
452 : 0 : dv_attr.priority = 3;
453 : : #ifdef HAVE_MLX5DV_DR_ESWITCH
454 : : void *misc2_m;
455 [ # # ]: 0 : if (priv->sh->config.dv_esw_en) {
456 : : /* FDB enabled reg_c_0 */
457 : 0 : dv_attr.match_criteria_enable |=
458 : : (1 << MLX5_MATCH_CRITERIA_ENABLE_MISC2_BIT);
459 : : misc2_m = MLX5_ADDR_OF(fte_match_param,
460 : : match_m, misc_parameters_2);
461 [ # # ]: 0 : MLX5_SET(fte_match_set_misc2, misc2_m,
462 : : metadata_reg_c_0, 0xffff);
463 : : }
464 : : #endif
465 : 0 : matcher = mlx5_glue->dv_create_flow_matcher(priv->sh->cdev->ctx,
466 : : &dv_attr, tbl);
467 [ # # ]: 0 : if (matcher) {
468 : 0 : priv->sh->misc5_cap = 1;
469 : 0 : mlx5_glue->dv_destroy_flow_matcher(matcher);
470 : : }
471 : 0 : mlx5_glue->dr_destroy_flow_tbl(tbl);
472 : : #else
473 : : RTE_SET_USED(priv);
474 : : #endif
475 : : }
476 : : #endif
477 : :
478 : : /**
479 : : * Initialize DR related data within private structure.
480 : : * Routine checks the reference counter and does actual
481 : : * resources creation/initialization only if counter is zero.
482 : : *
483 : : * @param[in] eth_dev
484 : : * Pointer to the device.
485 : : *
486 : : * @return
487 : : * Zero on success, positive error code otherwise.
488 : : */
489 : : static int
490 : 0 : mlx5_alloc_shared_dr(struct rte_eth_dev *eth_dev)
491 : : {
492 : 0 : struct mlx5_priv *priv = eth_dev->data->dev_private;
493 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
494 : : char s[MLX5_NAME_SIZE] __rte_unused;
495 : : int err;
496 : :
497 : : MLX5_ASSERT(sh && sh->refcnt);
498 [ # # ]: 0 : if (sh->refcnt > 1)
499 : : return 0;
500 : 0 : err = mlx5_alloc_table_hash_list(priv);
501 [ # # ]: 0 : if (err)
502 : 0 : goto error;
503 : 0 : sh->default_miss_action =
504 : 0 : mlx5_glue->dr_create_flow_action_default_miss();
505 [ # # ]: 0 : if (!sh->default_miss_action)
506 : 0 : DRV_LOG(WARNING, "Default miss action is not supported.");
507 : : /* The resources below are only valid with DV support. */
508 : : #ifdef HAVE_IBV_FLOW_DV_SUPPORT
509 : : /* Init shared flex parsers list, no need lcore_share */
510 : 0 : snprintf(s, sizeof(s), "%s_flex_parsers_list", sh->ibdev_name);
511 : 0 : sh->flex_parsers_dv = mlx5_list_create(s, sh, false,
512 : : mlx5_flex_parser_create_cb,
513 : : mlx5_flex_parser_match_cb,
514 : : mlx5_flex_parser_remove_cb,
515 : : mlx5_flex_parser_clone_cb,
516 : : mlx5_flex_parser_clone_free_cb);
517 [ # # ]: 0 : if (!sh->flex_parsers_dv)
518 : 0 : goto error;
519 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
520 [ # # ]: 0 : if (sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
521 [ # # ]: 0 : sh->dv_regc0_mask) {
522 : : /* Reuse DV callback functions. */
523 : 0 : sh->mreg_cp_tbl = mlx5_hlist_create(MLX5_FLOW_MREG_HNAME,
524 : : MLX5_FLOW_MREG_HTABLE_SZ,
525 : : false, true, eth_dev,
526 : : mlx5_flow_nta_mreg_create_cb,
527 : : mlx5_flow_dv_mreg_match_cb,
528 : : mlx5_flow_nta_mreg_remove_cb,
529 : : mlx5_flow_dv_mreg_clone_cb,
530 : : mlx5_flow_dv_mreg_clone_free_cb);
531 [ # # ]: 0 : if (!sh->mreg_cp_tbl) {
532 : : err = ENOMEM;
533 : 0 : goto error;
534 : : }
535 : : }
536 : 0 : return 0;
537 : : }
538 : : /* Init port id action list. */
539 : : snprintf(s, sizeof(s), "%s_port_id_action_list", sh->ibdev_name);
540 : 0 : sh->port_id_action_list = mlx5_list_create(s, sh, true,
541 : : mlx5_flow_dv_port_id_create_cb,
542 : : mlx5_flow_dv_port_id_match_cb,
543 : : mlx5_flow_dv_port_id_remove_cb,
544 : : mlx5_flow_dv_port_id_clone_cb,
545 : : mlx5_flow_dv_port_id_clone_free_cb);
546 [ # # ]: 0 : if (!sh->port_id_action_list)
547 : 0 : goto error;
548 : : /* Init push vlan action list. */
549 : : snprintf(s, sizeof(s), "%s_push_vlan_action_list", sh->ibdev_name);
550 : 0 : sh->push_vlan_action_list = mlx5_list_create(s, sh, true,
551 : : mlx5_flow_dv_push_vlan_create_cb,
552 : : mlx5_flow_dv_push_vlan_match_cb,
553 : : mlx5_flow_dv_push_vlan_remove_cb,
554 : : mlx5_flow_dv_push_vlan_clone_cb,
555 : : mlx5_flow_dv_push_vlan_clone_free_cb);
556 [ # # ]: 0 : if (!sh->push_vlan_action_list)
557 : 0 : goto error;
558 : : /* Init sample action list. */
559 : : snprintf(s, sizeof(s), "%s_sample_action_list", sh->ibdev_name);
560 : 0 : sh->sample_action_list = mlx5_list_create(s, sh, true,
561 : : mlx5_flow_dv_sample_create_cb,
562 : : mlx5_flow_dv_sample_match_cb,
563 : : mlx5_flow_dv_sample_remove_cb,
564 : : mlx5_flow_dv_sample_clone_cb,
565 : : mlx5_flow_dv_sample_clone_free_cb);
566 [ # # ]: 0 : if (!sh->sample_action_list)
567 : 0 : goto error;
568 : : /* Init dest array action list. */
569 : : snprintf(s, sizeof(s), "%s_dest_array_list", sh->ibdev_name);
570 : 0 : sh->dest_array_list = mlx5_list_create(s, sh, true,
571 : : mlx5_flow_dv_dest_array_create_cb,
572 : : mlx5_flow_dv_dest_array_match_cb,
573 : : mlx5_flow_dv_dest_array_remove_cb,
574 : : mlx5_flow_dv_dest_array_clone_cb,
575 : : mlx5_flow_dv_dest_array_clone_free_cb);
576 [ # # ]: 0 : if (!sh->dest_array_list)
577 : 0 : goto error;
578 : : #else
579 : : if (priv->sh->config.dv_flow_en == 2)
580 : : return 0;
581 : : #endif
582 : : #ifdef HAVE_MLX5DV_DR
583 : : void *domain;
584 : :
585 : : /* Reference counter is zero, we should initialize structures. */
586 : 0 : domain = mlx5_glue->dr_create_domain(sh->cdev->ctx,
587 : : MLX5DV_DR_DOMAIN_TYPE_NIC_RX);
588 [ # # ]: 0 : if (!domain) {
589 : 0 : DRV_LOG(ERR, "ingress mlx5dv_dr_create_domain failed");
590 : 0 : err = errno;
591 : 0 : goto error;
592 : : }
593 : 0 : sh->rx_domain = domain;
594 : 0 : domain = mlx5_glue->dr_create_domain(sh->cdev->ctx,
595 : : MLX5DV_DR_DOMAIN_TYPE_NIC_TX);
596 [ # # ]: 0 : if (!domain) {
597 : 0 : DRV_LOG(ERR, "egress mlx5dv_dr_create_domain failed");
598 : 0 : err = errno;
599 : 0 : goto error;
600 : : }
601 : 0 : sh->tx_domain = domain;
602 : : #ifdef HAVE_MLX5DV_DR_ESWITCH
603 [ # # ]: 0 : if (sh->config.dv_esw_en) {
604 : 0 : domain = mlx5_glue->dr_create_domain(sh->cdev->ctx,
605 : : MLX5DV_DR_DOMAIN_TYPE_FDB);
606 [ # # ]: 0 : if (!domain) {
607 : 0 : DRV_LOG(ERR, "FDB mlx5dv_dr_create_domain failed");
608 : 0 : err = errno;
609 : 0 : goto error;
610 : : }
611 : 0 : sh->fdb_domain = domain;
612 : : }
613 : : /*
614 : : * The drop action is just some dummy placeholder in rdma-core. It
615 : : * does not belong to domains and has no any attributes, and, can be
616 : : * shared by the entire device.
617 : : */
618 : 0 : sh->dr_drop_action = mlx5_glue->dr_create_flow_action_drop();
619 [ # # ]: 0 : if (!sh->dr_drop_action) {
620 : 0 : DRV_LOG(ERR, "FDB mlx5dv_dr_create_flow_action_drop");
621 : 0 : err = errno;
622 : 0 : goto error;
623 : : }
624 : :
625 [ # # ]: 0 : if (sh->config.dv_flow_en == 1) {
626 : : /* Query availability of metadata reg_c's. */
627 [ # # ]: 0 : if (!priv->sh->metadata_regc_check_flag) {
628 : 0 : err = mlx5_flow_discover_mreg_c(eth_dev);
629 [ # # ]: 0 : if (err < 0) {
630 : 0 : err = -err;
631 : 0 : goto error;
632 : : }
633 : : }
634 [ # # ]: 0 : if (!mlx5_flow_ext_mreg_supported(eth_dev)) {
635 : 0 : DRV_LOG(DEBUG,
636 : : "port %u extensive metadata register is not supported",
637 : : eth_dev->data->port_id);
638 [ # # ]: 0 : if (sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY) {
639 : 0 : DRV_LOG(ERR, "metadata mode %u is not supported "
640 : : "(no metadata registers available)",
641 : : sh->config.dv_xmeta_en);
642 : : err = ENOTSUP;
643 : 0 : goto error;
644 : : }
645 : : }
646 [ # # # # ]: 0 : if (sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
647 [ # # ]: 0 : mlx5_flow_ext_mreg_supported(eth_dev) && sh->dv_regc0_mask) {
648 : 0 : sh->mreg_cp_tbl = mlx5_hlist_create(MLX5_FLOW_MREG_HNAME,
649 : : MLX5_FLOW_MREG_HTABLE_SZ,
650 : : false, true, eth_dev,
651 : : mlx5_flow_dv_mreg_create_cb,
652 : : mlx5_flow_dv_mreg_match_cb,
653 : : mlx5_flow_dv_mreg_remove_cb,
654 : : mlx5_flow_dv_mreg_clone_cb,
655 : : mlx5_flow_dv_mreg_clone_free_cb);
656 [ # # ]: 0 : if (!sh->mreg_cp_tbl) {
657 : : err = ENOMEM;
658 : 0 : goto error;
659 : : }
660 : : }
661 : : }
662 : : #endif
663 [ # # # # ]: 0 : if (!sh->tunnel_hub && sh->config.dv_miss_info)
664 : 0 : err = mlx5_alloc_tunnel_hub(sh);
665 [ # # ]: 0 : if (err) {
666 : 0 : DRV_LOG(ERR, "mlx5_alloc_tunnel_hub failed err=%d", err);
667 : 0 : goto error;
668 : : }
669 [ # # ]: 0 : if (sh->config.reclaim_mode == MLX5_RCM_AGGR) {
670 : 0 : mlx5_glue->dr_reclaim_domain_memory(sh->rx_domain, 1);
671 : 0 : mlx5_glue->dr_reclaim_domain_memory(sh->tx_domain, 1);
672 [ # # ]: 0 : if (sh->fdb_domain)
673 : 0 : mlx5_glue->dr_reclaim_domain_memory(sh->fdb_domain, 1);
674 : : }
675 : 0 : sh->pop_vlan_action = mlx5_glue->dr_create_flow_action_pop_vlan();
676 [ # # ]: 0 : if (!sh->config.allow_duplicate_pattern) {
677 : : #ifndef HAVE_MLX5_DR_ALLOW_DUPLICATE
678 : : DRV_LOG(WARNING, "Disallow duplicate pattern is not supported - maybe old rdma-core version?");
679 : : #endif
680 : 0 : mlx5_glue->dr_allow_duplicate_rules(sh->rx_domain, 0);
681 : 0 : mlx5_glue->dr_allow_duplicate_rules(sh->tx_domain, 0);
682 [ # # ]: 0 : if (sh->fdb_domain)
683 : 0 : mlx5_glue->dr_allow_duplicate_rules(sh->fdb_domain, 0);
684 : : }
685 : :
686 : 0 : __mlx5_discovery_misc5_cap(priv);
687 : : #endif /* HAVE_MLX5DV_DR */
688 : 0 : LIST_INIT(&sh->shared_rxqs);
689 : 0 : return 0;
690 : 0 : error:
691 : : /* Rollback the created objects. */
692 [ # # ]: 0 : if (sh->rx_domain) {
693 : 0 : mlx5_glue->dr_destroy_domain(sh->rx_domain);
694 : 0 : sh->rx_domain = NULL;
695 : : }
696 [ # # ]: 0 : if (sh->tx_domain) {
697 : 0 : mlx5_glue->dr_destroy_domain(sh->tx_domain);
698 : 0 : sh->tx_domain = NULL;
699 : : }
700 [ # # ]: 0 : if (sh->fdb_domain) {
701 : 0 : mlx5_glue->dr_destroy_domain(sh->fdb_domain);
702 : 0 : sh->fdb_domain = NULL;
703 : : }
704 [ # # ]: 0 : if (sh->dr_drop_action) {
705 : 0 : mlx5_glue->destroy_flow_action(sh->dr_drop_action);
706 : 0 : sh->dr_drop_action = NULL;
707 : : }
708 [ # # ]: 0 : if (sh->pop_vlan_action) {
709 : 0 : mlx5_glue->destroy_flow_action(sh->pop_vlan_action);
710 : 0 : sh->pop_vlan_action = NULL;
711 : : }
712 [ # # ]: 0 : if (sh->encaps_decaps) {
713 : 0 : mlx5_hlist_destroy(sh->encaps_decaps);
714 : 0 : sh->encaps_decaps = NULL;
715 : : }
716 [ # # ]: 0 : if (sh->modify_cmds) {
717 : 0 : mlx5_hlist_destroy(sh->modify_cmds);
718 : 0 : sh->modify_cmds = NULL;
719 : : }
720 [ # # ]: 0 : if (sh->tag_table) {
721 : : /* tags should be destroyed with flow before. */
722 : 0 : mlx5_hlist_destroy(sh->tag_table);
723 : 0 : sh->tag_table = NULL;
724 : : }
725 [ # # ]: 0 : if (sh->tunnel_hub) {
726 : 0 : mlx5_release_tunnel_hub(sh, priv->dev_port);
727 : 0 : sh->tunnel_hub = NULL;
728 : : }
729 : 0 : mlx5_free_table_hash_list(priv);
730 [ # # ]: 0 : if (sh->port_id_action_list) {
731 : 0 : mlx5_list_destroy(sh->port_id_action_list);
732 : 0 : sh->port_id_action_list = NULL;
733 : : }
734 [ # # ]: 0 : if (sh->push_vlan_action_list) {
735 : 0 : mlx5_list_destroy(sh->push_vlan_action_list);
736 : 0 : sh->push_vlan_action_list = NULL;
737 : : }
738 [ # # ]: 0 : if (sh->sample_action_list) {
739 : 0 : mlx5_list_destroy(sh->sample_action_list);
740 : 0 : sh->sample_action_list = NULL;
741 : : }
742 [ # # ]: 0 : if (sh->dest_array_list) {
743 : 0 : mlx5_list_destroy(sh->dest_array_list);
744 : 0 : sh->dest_array_list = NULL;
745 : : }
746 [ # # ]: 0 : if (sh->mreg_cp_tbl) {
747 : 0 : mlx5_hlist_destroy(sh->mreg_cp_tbl);
748 : 0 : sh->mreg_cp_tbl = NULL;
749 : : }
750 : : return err;
751 : : }
752 : :
753 : : #ifdef HAVE_MLX5DV_DR
754 : : static void
755 : 0 : mlx5_destroy_send_to_kernel_action(struct mlx5_dev_ctx_shared *sh)
756 : : {
757 : : int i;
758 : :
759 [ # # ]: 0 : for (i = 0; i < MLX5DR_TABLE_TYPE_MAX; i++) {
760 [ # # ]: 0 : if (sh->send_to_kernel_action[i].action) {
761 : : void *action = sh->send_to_kernel_action[i].action;
762 : :
763 : 0 : mlx5_glue->destroy_flow_action(action);
764 : 0 : sh->send_to_kernel_action[i].action = NULL;
765 : : }
766 [ # # ]: 0 : if (sh->send_to_kernel_action[i].tbl) {
767 : : struct mlx5_flow_tbl_resource *tbl =
768 : : sh->send_to_kernel_action[i].tbl;
769 : :
770 : 0 : mlx5_flow_dv_tbl_resource_release(sh, tbl);
771 : 0 : sh->send_to_kernel_action[i].tbl = NULL;
772 : : }
773 : : }
774 : 0 : }
775 : : #endif /* HAVE_MLX5DV_DR */
776 : :
777 : : /**
778 : : * Destroy DR related data within private structure.
779 : : *
780 : : * @param[in] priv
781 : : * Pointer to the private device data structure.
782 : : */
783 : : void
784 : 0 : mlx5_os_free_shared_dr(struct mlx5_priv *priv)
785 : : {
786 : 0 : struct mlx5_dev_ctx_shared *sh = priv->sh;
787 : : struct mlx5_rxq_ctrl *rxq_ctrl;
788 : : int i = 0;
789 : :
790 : : MLX5_ASSERT(sh && sh->refcnt);
791 [ # # ]: 0 : if (sh->refcnt > 1)
792 : : return;
793 [ # # ]: 0 : LIST_FOREACH(rxq_ctrl, &sh->shared_rxqs, next) {
794 : 0 : DRV_LOG(DEBUG, "port %u Rx Queue %u still referenced",
795 : : priv->dev_data->port_id, rxq_ctrl->rxq.idx);
796 : 0 : ++i;
797 : : }
798 [ # # ]: 0 : if (i > 0)
799 : 0 : DRV_LOG(WARNING, "port %u some Rx queues still remain %d",
800 : : priv->dev_data->port_id, i);
801 : : MLX5_ASSERT(LIST_EMPTY(&sh->shared_rxqs));
802 : : #ifdef HAVE_MLX5DV_DR
803 : 0 : mlx5_destroy_send_to_kernel_action(sh);
804 [ # # ]: 0 : if (sh->rx_domain) {
805 : 0 : mlx5_glue->dr_destroy_domain(sh->rx_domain);
806 : 0 : sh->rx_domain = NULL;
807 : : }
808 [ # # ]: 0 : if (sh->tx_domain) {
809 : 0 : mlx5_glue->dr_destroy_domain(sh->tx_domain);
810 : 0 : sh->tx_domain = NULL;
811 : : }
812 : : #ifdef HAVE_MLX5DV_DR_ESWITCH
813 [ # # ]: 0 : if (sh->fdb_domain) {
814 : 0 : mlx5_glue->dr_destroy_domain(sh->fdb_domain);
815 : 0 : sh->fdb_domain = NULL;
816 : : }
817 [ # # ]: 0 : if (sh->dr_drop_action) {
818 : 0 : mlx5_glue->destroy_flow_action(sh->dr_drop_action);
819 : 0 : sh->dr_drop_action = NULL;
820 : : }
821 : : #endif
822 [ # # ]: 0 : if (sh->pop_vlan_action) {
823 : 0 : mlx5_glue->destroy_flow_action(sh->pop_vlan_action);
824 : 0 : sh->pop_vlan_action = NULL;
825 : : }
826 [ # # ]: 0 : for (i = 0; i < MLX5DR_TABLE_TYPE_MAX; i++) {
827 [ # # ]: 0 : if (sh->send_to_kernel_action[i].action) {
828 : : void *action = sh->send_to_kernel_action[i].action;
829 : :
830 : 0 : mlx5_glue->destroy_flow_action(action);
831 : 0 : sh->send_to_kernel_action[i].action = NULL;
832 : : }
833 [ # # ]: 0 : if (sh->send_to_kernel_action[i].tbl) {
834 : : struct mlx5_flow_tbl_resource *tbl =
835 : : sh->send_to_kernel_action[i].tbl;
836 : :
837 : 0 : mlx5_flow_dv_tbl_resource_release(sh, tbl);
838 : 0 : sh->send_to_kernel_action[i].tbl = NULL;
839 : : }
840 : : }
841 : : #endif /* HAVE_MLX5DV_DR */
842 [ # # ]: 0 : if (sh->default_miss_action)
843 : 0 : mlx5_glue->destroy_flow_action
844 : : (sh->default_miss_action);
845 [ # # ]: 0 : if (sh->encaps_decaps) {
846 : 0 : mlx5_hlist_destroy(sh->encaps_decaps);
847 : 0 : sh->encaps_decaps = NULL;
848 : : }
849 [ # # ]: 0 : if (sh->modify_cmds) {
850 : 0 : mlx5_hlist_destroy(sh->modify_cmds);
851 : 0 : sh->modify_cmds = NULL;
852 : : }
853 [ # # ]: 0 : if (sh->tag_table) {
854 : : /* tags should be destroyed with flow before. */
855 : 0 : mlx5_hlist_destroy(sh->tag_table);
856 : 0 : sh->tag_table = NULL;
857 : : }
858 [ # # ]: 0 : if (sh->tunnel_hub) {
859 : 0 : mlx5_release_tunnel_hub(sh, priv->dev_port);
860 : 0 : sh->tunnel_hub = NULL;
861 : : }
862 : 0 : mlx5_free_table_hash_list(priv);
863 [ # # ]: 0 : if (sh->port_id_action_list) {
864 : 0 : mlx5_list_destroy(sh->port_id_action_list);
865 : 0 : sh->port_id_action_list = NULL;
866 : : }
867 [ # # ]: 0 : if (sh->push_vlan_action_list) {
868 : 0 : mlx5_list_destroy(sh->push_vlan_action_list);
869 : 0 : sh->push_vlan_action_list = NULL;
870 : : }
871 [ # # ]: 0 : if (sh->sample_action_list) {
872 : 0 : mlx5_list_destroy(sh->sample_action_list);
873 : 0 : sh->sample_action_list = NULL;
874 : : }
875 [ # # ]: 0 : if (sh->dest_array_list) {
876 : 0 : mlx5_list_destroy(sh->dest_array_list);
877 : 0 : sh->dest_array_list = NULL;
878 : : }
879 [ # # ]: 0 : if (sh->mreg_cp_tbl) {
880 : 0 : mlx5_hlist_destroy(sh->mreg_cp_tbl);
881 : 0 : sh->mreg_cp_tbl = NULL;
882 : : }
883 : : }
884 : :
885 : : /**
886 : : * Initialize shared data between primary and secondary process.
887 : : *
888 : : * A memzone is reserved by primary process and secondary processes attach to
889 : : * the memzone.
890 : : *
891 : : * @return
892 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
893 : : */
894 : : static int
895 : 0 : mlx5_init_shared_data(void)
896 : : {
897 : : const struct rte_memzone *mz;
898 : : int ret = 0;
899 : :
900 : : rte_spinlock_lock(&mlx5_shared_data_lock);
901 [ # # ]: 0 : if (mlx5_shared_data == NULL) {
902 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
903 : : /* Allocate shared memory. */
904 : 0 : mz = rte_memzone_reserve(MZ_MLX5_PMD_SHARED_DATA,
905 : : sizeof(*mlx5_shared_data),
906 : : SOCKET_ID_ANY, 0);
907 [ # # ]: 0 : if (mz == NULL) {
908 : 0 : DRV_LOG(ERR,
909 : : "Cannot allocate mlx5 shared data");
910 : 0 : ret = -rte_errno;
911 : 0 : goto error;
912 : : }
913 : 0 : mlx5_shared_data = mz->addr;
914 : : memset(mlx5_shared_data, 0, sizeof(*mlx5_shared_data));
915 : 0 : rte_spinlock_init(&mlx5_shared_data->lock);
916 : : } else {
917 : : /* Lookup allocated shared memory. */
918 : 0 : mz = rte_memzone_lookup(MZ_MLX5_PMD_SHARED_DATA);
919 [ # # ]: 0 : if (mz == NULL) {
920 : 0 : DRV_LOG(ERR,
921 : : "Cannot attach mlx5 shared data");
922 : 0 : ret = -rte_errno;
923 : 0 : goto error;
924 : : }
925 : 0 : mlx5_shared_data = mz->addr;
926 : : memset(&mlx5_local_data, 0, sizeof(mlx5_local_data));
927 : : }
928 : : }
929 : 0 : error:
930 : : rte_spinlock_unlock(&mlx5_shared_data_lock);
931 : 0 : return ret;
932 : : }
933 : :
934 : : /**
935 : : * PMD global initialization.
936 : : *
937 : : * Independent from individual device, this function initializes global
938 : : * per-PMD data structures distinguishing primary and secondary processes.
939 : : * Hence, each initialization is called once per a process.
940 : : *
941 : : * @return
942 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
943 : : */
944 : : static int
945 : 0 : mlx5_init_once(void)
946 : : {
947 : : struct mlx5_shared_data *sd;
948 : : struct mlx5_local_data *ld = &mlx5_local_data;
949 : : int ret = 0;
950 : :
951 [ # # ]: 0 : if (mlx5_init_shared_data())
952 : 0 : return -rte_errno;
953 : 0 : sd = mlx5_shared_data;
954 : : MLX5_ASSERT(sd);
955 : 0 : rte_spinlock_lock(&sd->lock);
956 [ # # # ]: 0 : switch (rte_eal_process_type()) {
957 : 0 : case RTE_PROC_PRIMARY:
958 [ # # ]: 0 : if (sd->init_done)
959 : : break;
960 : 0 : ret = mlx5_mp_init_primary(MLX5_MP_NAME,
961 : : mlx5_mp_os_primary_handle);
962 [ # # ]: 0 : if (ret)
963 : 0 : goto out;
964 : 0 : sd->init_done = true;
965 : 0 : break;
966 : 0 : case RTE_PROC_SECONDARY:
967 [ # # ]: 0 : if (ld->init_done)
968 : : break;
969 : 0 : ret = mlx5_mp_init_secondary(MLX5_MP_NAME,
970 : : mlx5_mp_os_secondary_handle);
971 [ # # ]: 0 : if (ret)
972 : 0 : goto out;
973 : 0 : ++sd->secondary_cnt;
974 : 0 : ld->init_done = true;
975 : 0 : break;
976 : : default:
977 : : break;
978 : : }
979 : 0 : out:
980 : : rte_spinlock_unlock(&sd->lock);
981 : 0 : return ret;
982 : : }
983 : :
984 : : /**
985 : : * DR flow drop action support detect.
986 : : *
987 : : * @param dev
988 : : * Pointer to rte_eth_dev structure.
989 : : *
990 : : */
991 : : static void
992 : 0 : mlx5_flow_drop_action_config(struct rte_eth_dev *dev __rte_unused)
993 : : {
994 : : #ifdef HAVE_MLX5DV_DR
995 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
996 : :
997 [ # # # # ]: 0 : if (!priv->sh->config.dv_flow_en || !priv->sh->dr_drop_action)
998 : : return;
999 : : /**
1000 : : * DR supports drop action placeholder when it is supported;
1001 : : * otherwise, use the queue drop action.
1002 : : */
1003 [ # # ]: 0 : if (!priv->sh->drop_action_check_flag) {
1004 [ # # ]: 0 : if (!mlx5_flow_discover_dr_action_support(dev))
1005 : 0 : priv->sh->dr_root_drop_action_en = 1;
1006 : 0 : priv->sh->drop_action_check_flag = 1;
1007 : : }
1008 [ # # ]: 0 : if (priv->sh->dr_root_drop_action_en)
1009 : 0 : priv->root_drop_action = priv->sh->dr_drop_action;
1010 : : else
1011 : 0 : priv->root_drop_action = priv->drop_queue.hrxq->action;
1012 : : #endif
1013 : : }
1014 : :
1015 : : static void
1016 : 0 : mlx5_queue_counter_id_prepare(struct rte_eth_dev *dev)
1017 : : {
1018 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
1019 : 0 : void *ctx = priv->sh->cdev->ctx;
1020 : :
1021 : 0 : priv->q_counters = mlx5_devx_cmd_queue_counter_alloc(ctx, NULL);
1022 [ # # ]: 0 : if (!priv->q_counters) {
1023 : 0 : struct ibv_cq *cq = mlx5_glue->create_cq(ctx, 1, NULL, NULL, 0);
1024 : : struct ibv_wq *wq;
1025 : :
1026 : 0 : DRV_LOG(DEBUG, "Port %d queue counter object cannot be created "
1027 : : "by DevX - fall-back to use the kernel driver global "
1028 : : "queue counter.", dev->data->port_id);
1029 : :
1030 : : /* Create WQ by kernel and query its queue counter ID. */
1031 [ # # ]: 0 : if (cq) {
1032 : 0 : wq = mlx5_glue->create_wq(ctx,
1033 : 0 : &(struct ibv_wq_init_attr){
1034 : : .wq_type = IBV_WQT_RQ,
1035 : : .max_wr = 1,
1036 : : .max_sge = 1,
1037 : 0 : .pd = priv->sh->cdev->pd,
1038 : : .cq = cq,
1039 : : });
1040 [ # # ]: 0 : if (wq) {
1041 : : /* Counter is assigned only on RDY state. */
1042 : 0 : int ret = mlx5_glue->modify_wq(wq,
1043 : 0 : &(struct ibv_wq_attr){
1044 : : .attr_mask = IBV_WQ_ATTR_STATE,
1045 : : .wq_state = IBV_WQS_RDY,
1046 : : });
1047 : :
1048 [ # # ]: 0 : if (ret == 0)
1049 : 0 : mlx5_devx_cmd_wq_query(wq,
1050 : : &priv->counter_set_id);
1051 : 0 : claim_zero(mlx5_glue->destroy_wq(wq));
1052 : : }
1053 : 0 : claim_zero(mlx5_glue->destroy_cq(cq));
1054 : : }
1055 : : } else {
1056 : 0 : priv->counter_set_id = priv->q_counters->id;
1057 : : }
1058 [ # # ]: 0 : if (priv->counter_set_id == 0)
1059 : 0 : DRV_LOG(INFO, "Part of the port %d statistics will not be "
1060 : : "available.", dev->data->port_id);
1061 : 0 : }
1062 : :
1063 : : static inline bool
1064 : : mlx5_ignore_pf_representor(const struct rte_eth_devargs *eth_da)
1065 : : {
1066 : 0 : return (eth_da->flags & RTE_ETH_DEVARG_REPRESENTOR_IGNORE_PF) != 0;
1067 : : }
1068 : :
1069 : : static bool
1070 : : is_standard_eswitch(const struct mlx5_dev_spawn_data *spawn)
1071 : : {
1072 : 0 : bool is_bond = spawn->pf_bond >= 0;
1073 : :
1074 [ # # # # : 0 : return !is_bond && spawn->nb_uplinks <= 1 && spawn->nb_hpfs <= 1;
# # # # #
# ]
1075 : : }
1076 : :
1077 : : static bool
1078 : : is_hpf(const struct mlx5_dev_spawn_data *spawn)
1079 : : {
1080 [ # # # # : 0 : return spawn->info.port_name == -1 &&
# # # # ]
1081 [ # # # # ]: 0 : spawn->info.name_type == MLX5_PHYS_PORT_NAME_TYPE_PFHPF;
1082 : : }
1083 : :
1084 : : static int
1085 : 0 : build_port_name(struct rte_device *dpdk_dev,
1086 : : struct mlx5_dev_spawn_data *spawn,
1087 : : char *name,
1088 : : size_t name_sz)
1089 : : {
1090 : 0 : bool is_bond = spawn->pf_bond >= 0;
1091 : : int written = 0;
1092 : : int ret;
1093 : :
1094 [ # # ]: 0 : ret = snprintf(name, name_sz, "%s", dpdk_dev->name);
1095 [ # # ]: 0 : if (ret < 0)
1096 : : return ret;
1097 : : written += ret;
1098 [ # # ]: 0 : if (written >= (int)name_sz)
1099 : : return written;
1100 : :
1101 : : /*
1102 : : * Whenever bond device is detected, include IB device name.
1103 : : * This is kept to keep port naming backward compatible.
1104 : : */
1105 [ # # ]: 0 : if (is_bond) {
1106 [ # # ]: 0 : ret = snprintf(name + written, name_sz - written, "_%s", spawn->phys_dev_name);
1107 [ # # ]: 0 : if (ret < 0)
1108 : : return ret;
1109 : 0 : written += ret;
1110 [ # # ]: 0 : if (written >= (int)name_sz)
1111 : : return written;
1112 : : }
1113 : :
1114 [ # # ]: 0 : if (spawn->info.name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK) {
1115 : : /* Add port to name if and only if there is more than one uplink. */
1116 [ # # ]: 0 : if (spawn->nb_uplinks <= 1)
1117 : 0 : goto end;
1118 : :
1119 [ # # ]: 0 : ret = snprintf(name + written, name_sz - written, "_p%u", spawn->info.port_name);
1120 [ # # ]: 0 : if (ret < 0)
1121 : : return ret;
1122 : 0 : written += ret;
1123 : : if (written >= (int)name_sz)
1124 : : return written;
1125 [ # # ]: 0 : } else if (spawn->info.representor) {
1126 : : /*
1127 : : * If port is a representor, then switchdev has been enabled.
1128 : : * In that case add controller, PF and VF/SF indexes to port name
1129 : : * if at least one of these conditions are met:
1130 : : * 1. Device is a bond (VF-LAG).
1131 : : * 2. There are multiple uplinks (MPESW).
1132 : : * 3. There are multiple host PFs (BlueField socket direct).
1133 : : *
1134 : : * If none of these conditions apply, then it is assumed that
1135 : : * this device manages a single non-shared E-Switch with single controller,
1136 : : * where there is only one uplink/PF and one host PF (on BlueField).
1137 : : */
1138 [ # # ]: 0 : if (!is_standard_eswitch(spawn))
1139 [ # # ]: 0 : ret = snprintf(name + written, name_sz - written,
1140 : : "_representor_c%dpf%d%s%u",
1141 : : spawn->info.ctrl_num,
1142 : : spawn->info.pf_num,
1143 : : spawn->info.name_type ==
1144 : : MLX5_PHYS_PORT_NAME_TYPE_PFSF ? "sf" : "vf",
1145 : : spawn->info.port_name);
1146 : : else
1147 [ # # ]: 0 : ret = snprintf(name + written, name_sz - written, "_representor_%s%u",
1148 : : spawn->info.name_type ==
1149 : : MLX5_PHYS_PORT_NAME_TYPE_PFSF ? "sf" : "vf",
1150 : : spawn->info.port_name);
1151 [ # # ]: 0 : if (ret < 0)
1152 : : return ret;
1153 : 0 : written += ret;
1154 : : if (written >= (int)name_sz)
1155 : : return written;
1156 : : }
1157 : :
1158 : 0 : end:
1159 : : return written;
1160 : : }
1161 : :
1162 : : static bool
1163 : : representor_match_uplink(const struct mlx5_dev_spawn_data *spawn,
1164 : : uint16_t port_name,
1165 : : const struct rte_eth_devargs *eth_da,
1166 : : uint16_t eth_da_pf_num)
1167 : : {
1168 : 0 : if (spawn->info.name_type != MLX5_PHYS_PORT_NAME_TYPE_UPLINK)
1169 : : return false;
1170 : : /* One of the uplinks will be a transfer proxy. Must be probed always. */
1171 [ # # # # ]: 0 : if (spawn->info.master)
1172 : : return true;
1173 [ # # # # ]: 0 : if (mlx5_ignore_pf_representor(eth_da))
1174 : : return false;
1175 : :
1176 : 0 : return port_name == eth_da_pf_num;
1177 : : }
1178 : :
1179 : : static bool
1180 : 0 : representor_match_port(const struct mlx5_dev_spawn_data *spawn,
1181 : : const struct rte_eth_devargs *eth_da)
1182 : : {
1183 [ # # ]: 0 : for (uint16_t p = 0; p < eth_da->nb_ports; ++p) {
1184 : 0 : uint16_t pf_num = eth_da->ports[p];
1185 : :
1186 : : /* PF representor in devargs is interpreted as probing uplink port. */
1187 [ # # ]: 0 : if (eth_da->type == RTE_ETH_REPRESENTOR_PF) {
1188 [ # # # # ]: 0 : if (representor_match_uplink(spawn, spawn->info.port_name, eth_da, pf_num))
1189 : : return true;
1190 : :
1191 : 0 : continue;
1192 : : }
1193 : :
1194 : : /* Allow probing related uplink when VF/SF representor is requested. */
1195 [ # # ]: 0 : if ((eth_da->type == RTE_ETH_REPRESENTOR_VF ||
1196 [ # # ]: 0 : eth_da->type == RTE_ETH_REPRESENTOR_SF) &&
1197 [ # # ]: 0 : representor_match_uplink(spawn, spawn->info.pf_num, eth_da, pf_num))
1198 : : return true;
1199 : :
1200 : : /* Uplink ports should not be matched against representor_ports. */
1201 [ # # ]: 0 : if (spawn->info.name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK)
1202 : 0 : continue;
1203 : :
1204 [ # # ]: 0 : for (uint16_t f = 0; f < eth_da->nb_representor_ports; ++f) {
1205 [ # # ]: 0 : uint16_t port_num = eth_da->representor_ports[f];
1206 : : bool pf_num_match;
1207 : : bool rep_num_match;
1208 : :
1209 : : /*
1210 : : * In standard E-Switch case, allow probing VFs even if wrong PF index
1211 : : * was provided.
1212 : : */
1213 [ # # ]: 0 : if (is_standard_eswitch(spawn))
1214 : : pf_num_match = true;
1215 : : else
1216 : 0 : pf_num_match = spawn->info.pf_num == pf_num;
1217 : :
1218 : : /* Host PF is indicated through VF/SF representor index == -1. */
1219 [ # # ]: 0 : if (is_hpf(spawn))
1220 : 0 : rep_num_match = port_num == UINT16_MAX;
1221 : : else
1222 : 0 : rep_num_match = port_num == spawn->info.port_name;
1223 : :
1224 [ # # ]: 0 : if (pf_num_match && rep_num_match)
1225 : : return true;
1226 : : }
1227 : : }
1228 : :
1229 : : return false;
1230 : : }
1231 : :
1232 : : /**
1233 : : * Check if representor spawn info match devargs.
1234 : : *
1235 : : * @param spawn
1236 : : * Verbs device parameters (name, port, switch_info) to spawn.
1237 : : * @param eth_da
1238 : : * Device devargs to probe.
1239 : : *
1240 : : * @return
1241 : : * Match result.
1242 : : */
1243 : : static bool
1244 : 0 : mlx5_representor_match(struct mlx5_dev_spawn_data *spawn,
1245 : : struct rte_eth_devargs *eth_da)
1246 : : {
1247 : : struct mlx5_switch_info *switch_info = &spawn->info;
1248 : : unsigned int c;
1249 [ # # ]: 0 : bool ignore_ctrl_num = eth_da->nb_mh_controllers == 0 ||
1250 [ # # ]: 0 : switch_info->name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK;
1251 : :
1252 [ # # # # : 0 : switch (eth_da->type) {
# ]
1253 : 0 : case RTE_ETH_REPRESENTOR_PF:
1254 [ # # ]: 0 : if (switch_info->name_type != MLX5_PHYS_PORT_NAME_TYPE_UPLINK) {
1255 : 0 : rte_errno = EBUSY;
1256 : 0 : return false;
1257 : : }
1258 : : break;
1259 : : case RTE_ETH_REPRESENTOR_SF:
1260 [ # # ]: 0 : if (!is_hpf(spawn) &&
1261 [ # # # # ]: 0 : switch_info->name_type != MLX5_PHYS_PORT_NAME_TYPE_PFSF &&
1262 : : switch_info->name_type != MLX5_PHYS_PORT_NAME_TYPE_UPLINK) {
1263 : 0 : rte_errno = EBUSY;
1264 : 0 : return false;
1265 : : }
1266 : : break;
1267 : : case RTE_ETH_REPRESENTOR_VF:
1268 [ # # ]: 0 : if (!is_hpf(spawn) &&
1269 [ # # # # ]: 0 : switch_info->name_type != MLX5_PHYS_PORT_NAME_TYPE_PFVF &&
1270 : : switch_info->name_type != MLX5_PHYS_PORT_NAME_TYPE_UPLINK) {
1271 : 0 : rte_errno = EBUSY;
1272 : 0 : return false;
1273 : : }
1274 : : break;
1275 : 0 : case RTE_ETH_REPRESENTOR_NONE:
1276 : 0 : rte_errno = EBUSY;
1277 : 0 : return false;
1278 : 0 : default:
1279 : 0 : rte_errno = ENOTSUP;
1280 : 0 : DRV_LOG(ERR, "unsupported representor type");
1281 : 0 : return false;
1282 : : }
1283 [ # # ]: 0 : if (!ignore_ctrl_num) {
1284 [ # # ]: 0 : for (c = 0; c < eth_da->nb_mh_controllers; ++c) {
1285 : 0 : uint16_t ctrl_num = eth_da->mh_controllers[c];
1286 : :
1287 [ # # # # ]: 0 : if (spawn->info.ctrl_num == ctrl_num &&
1288 : 0 : representor_match_port(spawn, eth_da))
1289 : : return true;
1290 : : }
1291 : : } else {
1292 [ # # ]: 0 : if (representor_match_port(spawn, eth_da))
1293 : : return true;
1294 : : }
1295 : 0 : rte_errno = EBUSY;
1296 : 0 : return false;
1297 : : }
1298 : :
1299 : : /**
1300 : : * Spawn an Ethernet device from Verbs information.
1301 : : *
1302 : : * @param dpdk_dev
1303 : : * Backing DPDK device.
1304 : : * @param spawn
1305 : : * Verbs device parameters (name, port, switch_info) to spawn.
1306 : : * @param eth_da
1307 : : * Device arguments.
1308 : : * @param mkvlist
1309 : : * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
1310 : : *
1311 : : * @return
1312 : : * A valid Ethernet device object on success, NULL otherwise and rte_errno
1313 : : * is set. The following errors are defined:
1314 : : *
1315 : : * EBUSY: device is not supposed to be spawned.
1316 : : * EEXIST: device is already spawned
1317 : : */
1318 : : static struct rte_eth_dev *
1319 : 0 : mlx5_dev_spawn(struct rte_device *dpdk_dev,
1320 : : struct mlx5_dev_spawn_data *spawn,
1321 : : struct rte_eth_devargs *eth_da,
1322 : : struct mlx5_kvargs_ctrl *mkvlist)
1323 : : {
1324 : 0 : const struct mlx5_switch_info *switch_info = &spawn->info;
1325 : : struct mlx5_dev_ctx_shared *sh = NULL;
1326 : 0 : struct ibv_port_attr port_attr = { .state = IBV_PORT_NOP };
1327 : : struct rte_eth_dev *eth_dev = NULL;
1328 : : struct mlx5_priv *priv = NULL;
1329 : : int err = 0;
1330 : : struct rte_ether_addr mac;
1331 : : char name[RTE_ETH_NAME_MAX_LEN];
1332 : : int own_domain_id = 0;
1333 : : uint16_t port_id;
1334 : 0 : struct mlx5_port_info vport_info = { .query_flags = 0 };
1335 : : int nl_rdma;
1336 : : int i;
1337 : : struct mlx5_indexed_pool_config icfg[RTE_DIM(default_icfg)];
1338 : :
1339 : : memcpy(icfg, default_icfg, sizeof(icfg));
1340 : : /* Determine if this port representor is supposed to be spawned. */
1341 [ # # # # : 0 : if (switch_info->representor && dpdk_dev->devargs &&
# # ]
1342 : 0 : !mlx5_representor_match(spawn, eth_da))
1343 : : return NULL;
1344 : : /* Build device name. */
1345 : 0 : err = build_port_name(dpdk_dev, spawn, name, sizeof(name));
1346 [ # # ]: 0 : if (err < 0) {
1347 : 0 : DRV_LOG(ERR, "Failed to build port name for IB device %s/%u",
1348 : : spawn->phys_dev_name, spawn->phys_port);
1349 : 0 : rte_errno = EINVAL;
1350 : 0 : return NULL;
1351 : : }
1352 [ # # ]: 0 : if (err >= (int)sizeof(name))
1353 : 0 : DRV_LOG(WARNING, "device name overflow %s", name);
1354 : : /* check if the device is already spawned */
1355 [ # # ]: 0 : if (rte_eth_dev_get_port_by_name(name, &port_id) == 0) {
1356 : : /*
1357 : : * When device is already spawned, its devargs should be set
1358 : : * as used. otherwise, mlx5_kvargs_validate() will fail.
1359 : : */
1360 [ # # ]: 0 : if (mkvlist)
1361 : 0 : mlx5_port_args_set_used(name, port_id, mkvlist);
1362 : 0 : rte_errno = EEXIST;
1363 : 0 : return NULL;
1364 : : }
1365 : 0 : DRV_LOG(DEBUG, "naming Ethernet device \"%s\"", name);
1366 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
1367 : : struct mlx5_mp_id mp_id;
1368 : : int fd;
1369 : :
1370 : 0 : eth_dev = rte_eth_dev_attach_secondary(name);
1371 [ # # ]: 0 : if (eth_dev == NULL) {
1372 : 0 : DRV_LOG(ERR, "can not attach rte ethdev");
1373 : 0 : rte_errno = ENOMEM;
1374 : 0 : return NULL;
1375 : : }
1376 : 0 : eth_dev->device = dpdk_dev;
1377 : 0 : eth_dev->dev_ops = &mlx5_dev_sec_ops;
1378 : 0 : eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status;
1379 : 0 : eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status;
1380 : 0 : err = mlx5_proc_priv_init(eth_dev);
1381 [ # # ]: 0 : if (err)
1382 : : return NULL;
1383 : 0 : mlx5_mp_id_init(&mp_id, eth_dev->data->port_id);
1384 : : /* Receive command fd from primary process */
1385 : 0 : fd = mlx5_mp_req_verbs_cmd_fd(&mp_id);
1386 [ # # ]: 0 : if (fd < 0)
1387 : 0 : goto err_secondary;
1388 : : /* Remap UAR for Tx queues. */
1389 : 0 : err = mlx5_tx_uar_init_secondary(eth_dev, fd);
1390 : 0 : close(fd);
1391 [ # # ]: 0 : if (err)
1392 : 0 : goto err_secondary;
1393 : : /*
1394 : : * Ethdev pointer is still required as input since
1395 : : * the primary device is not accessible from the
1396 : : * secondary process.
1397 : : */
1398 : 0 : eth_dev->rx_pkt_burst = mlx5_select_rx_function(eth_dev);
1399 : 0 : eth_dev->tx_pkt_burst = mlx5_select_tx_function(eth_dev);
1400 : 0 : return eth_dev;
1401 : 0 : err_secondary:
1402 : 0 : mlx5_dev_close(eth_dev);
1403 : 0 : return NULL;
1404 : : }
1405 : 0 : sh = mlx5_alloc_shared_dev_ctx(spawn, mkvlist);
1406 [ # # ]: 0 : if (!sh)
1407 : : return NULL;
1408 : 0 : nl_rdma = mlx5_nl_init(NETLINK_RDMA, 0);
1409 : : /* Check port status. */
1410 [ # # ]: 0 : if (spawn->phys_port <= UINT8_MAX) {
1411 : : /* Legacy Verbs api only support u8 port number. */
1412 : 0 : err = mlx5_glue->query_port(sh->cdev->ctx, spawn->phys_port,
1413 : : &port_attr);
1414 [ # # ]: 0 : if (err) {
1415 : 0 : DRV_LOG(ERR, "port query failed: %s", strerror(err));
1416 : 0 : goto error;
1417 : : }
1418 [ # # ]: 0 : if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) {
1419 : 0 : DRV_LOG(ERR, "port is not configured in Ethernet mode");
1420 : : err = EINVAL;
1421 : 0 : goto error;
1422 : : }
1423 [ # # ]: 0 : } else if (nl_rdma >= 0) {
1424 : : /* IB doesn't allow more than 255 ports, must be Ethernet. */
1425 : 0 : err = mlx5_nl_port_state(nl_rdma,
1426 : : spawn->phys_dev_name,
1427 : 0 : spawn->phys_port, &spawn->cdev->dev_info);
1428 [ # # ]: 0 : if (err < 0) {
1429 : 0 : DRV_LOG(INFO, "Failed to get netlink port state: %s",
1430 : : strerror(rte_errno));
1431 : 0 : err = -rte_errno;
1432 : 0 : goto error;
1433 : : }
1434 : 0 : port_attr.state = (enum ibv_port_state)err;
1435 : : }
1436 [ # # ]: 0 : if (port_attr.state != IBV_PORT_ACTIVE)
1437 : 0 : DRV_LOG(INFO, "port is not active: \"%s\" (%d)",
1438 : : mlx5_glue->port_state_str(port_attr.state),
1439 : : port_attr.state);
1440 : : /* Allocate private eth device data. */
1441 : 0 : priv = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
1442 : : sizeof(*priv),
1443 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1444 [ # # ]: 0 : if (priv == NULL) {
1445 : 0 : DRV_LOG(ERR, "priv allocation failure");
1446 : : err = ENOMEM;
1447 : 0 : goto error;
1448 : : }
1449 : 0 : priv->sh = sh;
1450 : 0 : priv->dev_port = spawn->phys_port;
1451 : 0 : priv->pci_dev = spawn->pci_dev;
1452 : 0 : priv->mac = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
1453 : 0 : sizeof(*priv->mac) * sh->dev_cap.max_mac_addrs,
1454 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1455 [ # # ]: 0 : if (priv->mac == NULL) {
1456 : 0 : DRV_LOG(ERR, "Failed to allocate MAC address array.");
1457 : : err = ENOMEM;
1458 : 0 : goto error;
1459 : : }
1460 : 0 : priv->mac_own = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
1461 : 0 : RTE_BITSET_SIZE(sh->dev_cap.max_mac_addrs),
1462 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
1463 [ # # ]: 0 : if (priv->mac_own == NULL) {
1464 : 0 : DRV_LOG(ERR, "Failed to allocate MAC ownership bitmap.");
1465 : : err = ENOMEM;
1466 : 0 : goto error;
1467 : : }
1468 : : /* Some internal functions rely on Netlink sockets, open them now. */
1469 : 0 : priv->nl_socket_rdma = nl_rdma;
1470 : 0 : priv->nl_socket_route = mlx5_nl_init(NETLINK_ROUTE, 0);
1471 : 0 : priv->representor = !!switch_info->representor;
1472 : 0 : priv->master = !!switch_info->master;
1473 : 0 : priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
1474 : 0 : priv->vport_meta_tag = 0;
1475 : 0 : priv->vport_meta_mask = 0;
1476 : 0 : priv->pf_bond = spawn->pf_bond;
1477 : 0 : priv->mpesw_port = spawn->mpesw_port;
1478 : 0 : priv->mpesw_uplink = false;
1479 : 0 : priv->mpesw_owner = spawn->info.mpesw_owner;
1480 [ # # ]: 0 : if (mlx5_is_port_on_mpesw_device(priv))
1481 : 0 : priv->mpesw_uplink = (spawn->info.name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK);
1482 : :
1483 [ # # ]: 0 : DRV_LOG(DEBUG,
1484 : : "dev_port=%u bus=%s pci=%s master=%d representor=%d pf_bond=%d "
1485 : : "mpesw_port=%d mpesw_uplink=%d",
1486 : : priv->dev_port, dpdk_dev->bus->name,
1487 : : priv->pci_dev ? priv->pci_dev->name : "NONE",
1488 : : priv->master, priv->representor, priv->pf_bond,
1489 : : priv->mpesw_port, priv->mpesw_uplink);
1490 : :
1491 [ # # # # ]: 0 : if (mlx5_is_port_on_mpesw_device(priv) && priv->sh->config.dv_flow_en != 2) {
1492 : 0 : DRV_LOG(ERR, "MPESW device is supported only with HWS");
1493 : : err = ENOTSUP;
1494 : 0 : goto error;
1495 : : }
1496 : : /*
1497 : : * If we have E-Switch we should determine the vport attributes.
1498 : : * E-Switch may use either source vport field or reg_c[0] metadata
1499 : : * register to match on vport index. The engaged part of metadata
1500 : : * register is defined by mask.
1501 : : */
1502 [ # # ]: 0 : if (sh->esw_mode) {
1503 : 0 : err = mlx5_glue->devx_port_query(sh->cdev->ctx,
1504 : : spawn->phys_port,
1505 : : &vport_info);
1506 [ # # ]: 0 : if (err) {
1507 : 0 : DRV_LOG(WARNING,
1508 : : "Cannot query devx port %d on device %s",
1509 : : spawn->phys_port, spawn->phys_dev_name);
1510 : 0 : vport_info.query_flags = 0;
1511 : : }
1512 : : }
1513 [ # # ]: 0 : if (vport_info.query_flags & MLX5_PORT_QUERY_REG_C0) {
1514 : 0 : priv->vport_meta_tag = vport_info.vport_meta_tag;
1515 : 0 : priv->vport_meta_mask = vport_info.vport_meta_mask;
1516 [ # # ]: 0 : if (!priv->vport_meta_mask) {
1517 : 0 : DRV_LOG(ERR,
1518 : : "vport zero mask for port %d on bonding device %s",
1519 : : spawn->phys_port, spawn->phys_dev_name);
1520 : : err = ENOTSUP;
1521 : 0 : goto error;
1522 : : }
1523 [ # # ]: 0 : if (priv->vport_meta_tag & ~priv->vport_meta_mask) {
1524 : 0 : DRV_LOG(ERR,
1525 : : "Invalid vport tag for port %d on bonding device %s",
1526 : : spawn->phys_port, spawn->phys_dev_name);
1527 : : err = ENOTSUP;
1528 : 0 : goto error;
1529 : : }
1530 : : }
1531 [ # # ]: 0 : if (vport_info.query_flags & MLX5_PORT_QUERY_VPORT_VHCA_ID)
1532 : 0 : priv->vport_vhca_id = vport_info.vport_vhca_id;
1533 [ # # ]: 0 : if (vport_info.query_flags & MLX5_PORT_QUERY_VPORT) {
1534 : 0 : priv->vport_id = vport_info.vport_id;
1535 [ # # # # ]: 0 : } else if (spawn->pf_bond >= 0 && sh->esw_mode) {
1536 : 0 : DRV_LOG(ERR,
1537 : : "Cannot deduce vport index for port %d on bonding device %s",
1538 : : spawn->phys_port, spawn->phys_dev_name);
1539 : : err = ENOTSUP;
1540 : 0 : goto error;
1541 : : } else {
1542 : : /*
1543 : : * Suppose vport index in compatible way. Kernel/rdma_core
1544 : : * support single E-Switch per PF configurations only and
1545 : : * vport_id field contains the vport index for associated VF,
1546 : : * which is deduced from representor port name.
1547 : : * For example, let's have the IB device port 10, it has
1548 : : * attached network device eth0, which has port name attribute
1549 : : * pf0vf2, we can deduce the VF number as 2, and set vport index
1550 : : * as 3 (2+1). This assigning schema should be changed if the
1551 : : * multiple E-Switch instances per PF configurations or/and PCI
1552 : : * subfunctions are added.
1553 : : */
1554 [ # # ]: 0 : priv->vport_id = switch_info->representor ?
1555 : 0 : switch_info->port_name + 1 : -1;
1556 : : }
1557 : 0 : priv->representor_id = mlx5_representor_id_encode(switch_info,
1558 : : eth_da->type);
1559 : : /*
1560 : : * Look for sibling devices in order to reuse their switch domain
1561 : : * if any, otherwise allocate one.
1562 : : */
1563 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dpdk_dev) {
1564 : 0 : const struct mlx5_priv *opriv =
1565 : 0 : rte_eth_devices[port_id].data->dev_private;
1566 : :
1567 [ # # ]: 0 : if (!opriv ||
1568 [ # # ]: 0 : opriv->sh != priv->sh ||
1569 [ # # ]: 0 : opriv->domain_id ==
1570 : : RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID)
1571 : : continue;
1572 : 0 : priv->domain_id = opriv->domain_id;
1573 : 0 : DRV_LOG(DEBUG, "dev_port-%u inherit domain_id=%u\n",
1574 : : priv->dev_port, priv->domain_id);
1575 : 0 : break;
1576 : : }
1577 [ # # ]: 0 : if (priv->domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID) {
1578 : 0 : err = rte_eth_switch_domain_alloc(&priv->domain_id);
1579 [ # # ]: 0 : if (err) {
1580 : 0 : err = rte_errno;
1581 : 0 : DRV_LOG(ERR, "unable to allocate switch domain: %s",
1582 : : strerror(rte_errno));
1583 : 0 : goto error;
1584 : : }
1585 : : own_domain_id = 1;
1586 : 0 : DRV_LOG(DEBUG, "dev_port-%u new domain_id=%u\n",
1587 : : priv->dev_port, priv->domain_id);
1588 : : }
1589 [ # # ]: 0 : if (sh->cdev->config.devx) {
1590 : : struct mlx5_hca_attr *hca_attr = &sh->cdev->config.hca_attr;
1591 : :
1592 : 0 : sh->steering_format_version = hca_attr->steering_format_version;
1593 : : #if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO_EXT)
1594 [ # # # # ]: 0 : if (hca_attr->qos.sup && hca_attr->qos.flow_meter_old &&
1595 : : sh->config.dv_flow_en) {
1596 [ # # ]: 0 : if (sh->registers.aso_reg != REG_NON) {
1597 : 0 : priv->mtr_en = 1;
1598 : 0 : priv->mtr_reg_share = hca_attr->qos.flow_meter;
1599 : : }
1600 : : }
1601 [ # # ]: 0 : if (hca_attr->qos.sup && hca_attr->qos.flow_meter_aso_sup) {
1602 : : uint32_t log_obj_size =
1603 : : rte_log2_u32(MLX5_ASO_MTRS_PER_POOL >> 1);
1604 : 0 : if (log_obj_size >=
1605 [ # # ]: 0 : hca_attr->qos.log_meter_aso_granularity &&
1606 : : log_obj_size <=
1607 [ # # ]: 0 : hca_attr->qos.log_meter_aso_max_alloc)
1608 : 0 : sh->meter_aso_en = 1;
1609 : : }
1610 [ # # ]: 0 : if (priv->mtr_en) {
1611 : 0 : err = mlx5_aso_flow_mtrs_mng_init(priv->sh);
1612 [ # # ]: 0 : if (err) {
1613 : 0 : err = -err;
1614 : 0 : goto error;
1615 : : }
1616 : : }
1617 [ # # ]: 0 : if (hca_attr->flow.tunnel_header_0_1)
1618 : 0 : sh->tunnel_header_0_1 = 1;
1619 [ # # ]: 0 : if (hca_attr->flow.tunnel_header_2_3)
1620 : 0 : sh->tunnel_header_2_3 = 1;
1621 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO_EXT */
1622 : : #ifdef HAVE_MLX5_DR_CREATE_ACTION_ASO
1623 [ # # # # ]: 0 : if (hca_attr->flow_hit_aso && sh->registers.aso_reg == REG_C_3) {
1624 : 0 : sh->flow_hit_aso_en = 1;
1625 : 0 : err = mlx5_flow_aso_age_mng_init(sh);
1626 [ # # ]: 0 : if (err) {
1627 : 0 : err = -err;
1628 : 0 : goto error;
1629 : : }
1630 : 0 : DRV_LOG(DEBUG, "Flow Hit ASO is supported.");
1631 : : }
1632 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */
1633 : : #if defined (HAVE_MLX5_DR_CREATE_ACTION_ASO) && \
1634 : : defined (HAVE_MLX5_DR_ACTION_ASO_CT)
1635 : : /* HWS create CT ASO SQ based on HWS configure queue number. */
1636 [ # # # # ]: 0 : if (sh->config.dv_flow_en != 2 &&
1637 [ # # ]: 0 : hca_attr->ct_offload && sh->registers.aso_reg == REG_C_3) {
1638 : 0 : err = mlx5_flow_aso_ct_mng_init(sh);
1639 [ # # ]: 0 : if (err) {
1640 : 0 : err = -err;
1641 : 0 : goto error;
1642 : : }
1643 : 0 : DRV_LOG(DEBUG, "CT ASO is supported.");
1644 : 0 : sh->ct_aso_en = 1;
1645 : : }
1646 : : #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO && HAVE_MLX5_DR_ACTION_ASO_CT */
1647 : : #if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE)
1648 [ # # # # ]: 0 : if (hca_attr->log_max_ft_sampler_num > 0 &&
1649 : : sh->config.dv_flow_en) {
1650 : 0 : priv->sampler_en = 1;
1651 : 0 : DRV_LOG(DEBUG, "Sampler enabled!");
1652 : : } else {
1653 : 0 : priv->sampler_en = 0;
1654 [ # # ]: 0 : if (!hca_attr->log_max_ft_sampler_num)
1655 : 0 : DRV_LOG(WARNING,
1656 : : "No available register for sampler.");
1657 : : else
1658 : 0 : DRV_LOG(DEBUG, "DV flow is not supported!");
1659 : : }
1660 : : #endif
1661 [ # # ]: 0 : if (hca_attr->lag_rx_port_affinity) {
1662 : 0 : sh->lag_rx_port_affinity_en = 1;
1663 : 0 : DRV_LOG(DEBUG, "LAG Rx Port Affinity enabled");
1664 : : }
1665 : 0 : priv->num_lag_ports = hca_attr->num_lag_ports;
1666 : 0 : DRV_LOG(DEBUG, "The number of lag ports is %d", priv->num_lag_ports);
1667 : : }
1668 : : /* Process parameters and store port configuration on priv structure. */
1669 : 0 : err = mlx5_port_args_config(priv, mkvlist, &priv->config);
1670 [ # # ]: 0 : if (err) {
1671 : 0 : err = rte_errno;
1672 : 0 : DRV_LOG(ERR, "Failed to process port configure: %s",
1673 : : strerror(rte_errno));
1674 : 0 : goto error;
1675 : : }
1676 : 0 : eth_dev = rte_eth_dev_allocate(name);
1677 [ # # ]: 0 : if (eth_dev == NULL) {
1678 : 0 : DRV_LOG(ERR, "can not allocate rte ethdev");
1679 : : err = ENOMEM;
1680 : 0 : goto error;
1681 : : }
1682 : 0 : priv->port_info.type = spawn->info.name_type;
1683 : 0 : priv->port_info.ctrl_num = spawn->info.ctrl_num;
1684 : 0 : priv->port_info.pf_num = spawn->info.pf_num;
1685 : 0 : priv->port_info.port_num = spawn->info.port_name;
1686 [ # # ]: 0 : if (priv->representor) {
1687 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
1688 : 0 : eth_dev->data->representor_id = eth_dev->data->port_id;
1689 [ # # ]: 0 : MLX5_ETH_FOREACH_DEV(port_id, dpdk_dev) {
1690 : 0 : struct mlx5_priv *opriv =
1691 : 0 : rte_eth_devices[port_id].data->dev_private;
1692 [ # # # # ]: 0 : if (opriv &&
1693 : 0 : opriv->master &&
1694 [ # # ]: 0 : opriv->domain_id == priv->domain_id &&
1695 [ # # ]: 0 : opriv->sh == priv->sh) {
1696 : 0 : eth_dev->data->backer_port_id = port_id;
1697 : 0 : break;
1698 : : }
1699 : : }
1700 [ # # ]: 0 : if (port_id >= RTE_MAX_ETHPORTS)
1701 : 0 : eth_dev->data->backer_port_id = eth_dev->data->port_id;
1702 : : }
1703 : 0 : priv->mp_id.port_id = eth_dev->data->port_id;
1704 : 0 : strlcpy(priv->mp_id.name, MLX5_MP_NAME, RTE_MP_MAX_NAME_LEN);
1705 : : /*
1706 : : * Store associated network device interface index. This index
1707 : : * is permanent throughout the lifetime of device. So, we may store
1708 : : * the ifindex here and use the cached value further.
1709 : : */
1710 : : MLX5_ASSERT(spawn->ifindex);
1711 : 0 : priv->if_index = spawn->ifindex;
1712 : 0 : priv->lag_affinity_idx = sh->refcnt - 1;
1713 : 0 : eth_dev->data->dev_private = priv;
1714 : 0 : priv->dev_data = eth_dev->data;
1715 : 0 : eth_dev->data->mac_addrs = priv->mac;
1716 : 0 : eth_dev->device = dpdk_dev;
1717 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1718 : : /* Fetch minimum and maximum allowed MTU from the device. */
1719 : 0 : mlx5_get_mtu_bounds(eth_dev, &priv->min_mtu, &priv->max_mtu);
1720 : : /* Configure the first MAC address by default. */
1721 [ # # ]: 0 : if (mlx5_get_mac(eth_dev, &mac.addr_bytes)) {
1722 : 0 : DRV_LOG(ERR,
1723 : : "port %u cannot get MAC address, is mlx5_en"
1724 : : " loaded? (errno: %s)",
1725 : : eth_dev->data->port_id, strerror(rte_errno));
1726 : : err = ENODEV;
1727 : 0 : goto error;
1728 : : }
1729 : 0 : DRV_LOG(INFO,
1730 : : "port %u MAC address is " RTE_ETHER_ADDR_PRT_FMT,
1731 : : eth_dev->data->port_id, RTE_ETHER_ADDR_BYTES(&mac));
1732 : : #ifdef RTE_PMD_MLX5_DEBUG
1733 : : {
1734 : : char ifname[MLX5_NAMESIZE];
1735 : :
1736 : : if (mlx5_get_ifname(eth_dev, ifname) == 0)
1737 : : DRV_LOG(DEBUG, "port %u ifname is \"%s\"",
1738 : : eth_dev->data->port_id, ifname);
1739 : : else
1740 : : DRV_LOG(DEBUG, "port %u ifname is unknown",
1741 : : eth_dev->data->port_id);
1742 : : }
1743 : : #endif
1744 : : /* Get actual MTU if possible. */
1745 : 0 : err = mlx5_get_mtu(eth_dev, ð_dev->data->mtu);
1746 [ # # ]: 0 : if (err) {
1747 : 0 : err = rte_errno;
1748 : 0 : goto error;
1749 : : }
1750 : 0 : DRV_LOG(DEBUG, "port %u MTU is %u", eth_dev->data->port_id,
1751 : : eth_dev->data->mtu);
1752 : : /* Initialize burst functions to prevent crashes before link-up. */
1753 : 0 : eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
1754 : 0 : eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
1755 : 0 : eth_dev->dev_ops = &mlx5_dev_ops;
1756 : 0 : eth_dev->rx_descriptor_status = mlx5_rx_descriptor_status;
1757 : 0 : eth_dev->tx_descriptor_status = mlx5_tx_descriptor_status;
1758 : 0 : eth_dev->rx_queue_count = mlx5_rx_queue_count;
1759 : : /* Register MAC address. */
1760 : 0 : claim_zero(mlx5_mac_addr_add(eth_dev, &mac, 0, 0));
1761 : : /* Sync mac addresses for PF or VF/SF if vf_nl_en is true */
1762 [ # # # # ]: 0 : if ((!sh->dev_cap.vf && !sh->dev_cap.sf) || sh->config.vf_nl_en)
1763 : 0 : mlx5_nl_mac_addr_sync(priv->nl_socket_route,
1764 : : mlx5_ifindex(eth_dev),
1765 : 0 : eth_dev->data->mac_addrs,
1766 : 0 : sh->dev_cap.max_uc_mac_addrs,
1767 : 0 : sh->dev_cap.max_mac_addrs);
1768 [ # # ]: 0 : priv->ctrl_flows = 0;
1769 : : rte_spinlock_init(&priv->flow_list_lock);
1770 : 0 : TAILQ_INIT(&priv->flow_meters);
1771 [ # # ]: 0 : if (priv->mtr_en) {
1772 : 0 : priv->mtr_profile_tbl = mlx5_l3t_create(MLX5_L3T_TYPE_PTR);
1773 [ # # ]: 0 : if (!priv->mtr_profile_tbl)
1774 : 0 : goto error;
1775 : : }
1776 : : /* Bring Ethernet device up. */
1777 : 0 : DRV_LOG(DEBUG, "port %u forcing Ethernet interface up",
1778 : : eth_dev->data->port_id);
1779 : : /* Read link status in case it is up and there will be no event. */
1780 : 0 : mlx5_link_update(eth_dev, 0);
1781 : : /* Watch LSC interrupts between port probe and port start. */
1782 : 0 : priv->sh->port[priv->dev_port - 1].nl_ih_port_id = eth_dev->data->port_id;
1783 : 0 : mlx5_set_link_up(eth_dev);
1784 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
1785 : 0 : icfg[i].release_mem_en = !!sh->config.reclaim_mode;
1786 [ # # ]: 0 : if (sh->config.reclaim_mode)
1787 : 0 : icfg[i].per_core_cache = 0;
1788 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1789 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
1790 : : icfg[i].size = sizeof(struct rte_flow_hw) + sizeof(struct rte_flow_nt2hws);
1791 : 0 : icfg[i].size += sizeof(struct rte_flow_hw_aux);
1792 : : }
1793 : : #endif
1794 : 0 : priv->flows[i] = mlx5_ipool_create(&icfg[i]);
1795 [ # # ]: 0 : if (!priv->flows[i])
1796 : 0 : goto error;
1797 : : }
1798 : : /* Create context for virtual machine VLAN workaround. */
1799 [ # # ]: 0 : priv->vmwa_context = mlx5_vlan_vmwa_init(eth_dev, spawn->ifindex);
1800 : : /* Linux DevX object operations also require DV flow and Dest TIR. */
1801 [ # # # # : 0 : if (mlx5_devx_available(sh) && sh->config.dv_flow_en && sh->dev_cap.dest_tir) {
# # ]
1802 : 0 : priv->obj_ops = mlx5_devx_obj_ops;
1803 : 0 : mlx5_queue_counter_id_prepare(eth_dev);
1804 : 0 : priv->obj_ops.lb_dummy_queue_create =
1805 : : mlx5_rxq_ibv_obj_dummy_lb_create;
1806 : 0 : priv->obj_ops.lb_dummy_queue_release =
1807 : : mlx5_rxq_ibv_obj_dummy_lb_release;
1808 [ # # ]: 0 : } else if (spawn->max_port > UINT8_MAX) {
1809 : : /* Verbs can't support ports larger than 255 by design. */
1810 : 0 : DRV_LOG(ERR, "must enable DV and ESW when RDMA link ports > 255");
1811 : : err = ENOTSUP;
1812 : 0 : goto error;
1813 : : } else {
1814 : 0 : priv->obj_ops = mlx5_ibv_obj_ops;
1815 : : }
1816 : : /*
1817 : : * When user configures remote PD and CTX and device creates RxQ by
1818 : : * DevX, external RxQ is both supported and requested.
1819 : : */
1820 [ # # # # : 0 : if (mlx5_imported_pd_and_ctx(sh->cdev) && mlx5_devx_obj_ops_en(priv)) {
# # ]
1821 : 0 : priv->ext_rxqs = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
1822 : : sizeof(struct mlx5_external_q) *
1823 : : MLX5_MAX_EXT_RX_QUEUES, 0,
1824 : : SOCKET_ID_ANY);
1825 [ # # ]: 0 : if (priv->ext_rxqs == NULL) {
1826 : 0 : DRV_LOG(ERR, "Fail to allocate external RxQ array.");
1827 : : err = ENOMEM;
1828 : 0 : goto error;
1829 : : }
1830 : 0 : priv->ext_txqs = mlx5_malloc(MLX5_MEM_ZERO | MLX5_MEM_RTE,
1831 : : sizeof(struct mlx5_external_q) *
1832 : : MLX5_MAX_EXT_TX_QUEUES, 0,
1833 : : SOCKET_ID_ANY);
1834 [ # # ]: 0 : if (priv->ext_txqs == NULL) {
1835 : 0 : DRV_LOG(ERR, "Fail to allocate external TxQ array.");
1836 : : err = ENOMEM;
1837 : 0 : goto error;
1838 : : }
1839 : 0 : DRV_LOG(DEBUG, "External queue is supported.");
1840 : : }
1841 [ # # # # ]: 0 : if (sh->config.tx_pp && !mlx5_devx_obj_ops_en(priv)) {
1842 : : /*
1843 : : * HAVE_MLX5DV_DEVX_UAR_OFFSET is required to support
1844 : : * packet pacing and already checked above.
1845 : : * Hence, we should only make sure the SQs will be created
1846 : : * with DevX, not with Verbs.
1847 : : * Verbs allocates the SQ UAR on its own and it can't be shared
1848 : : * with Clock Queue UAR as required for Tx scheduling.
1849 : : */
1850 : 0 : DRV_LOG(ERR, "Verbs SQs, UAR can't be shared as required for packet pacing");
1851 : : err = ENODEV;
1852 : 0 : goto error;
1853 : : }
1854 : 0 : priv->drop_queue.hrxq = mlx5_drop_action_create(eth_dev);
1855 [ # # ]: 0 : if (!priv->drop_queue.hrxq)
1856 : 0 : goto error;
1857 : 0 : priv->hrxqs = mlx5_list_create("hrxq", eth_dev, true,
1858 : : mlx5_hrxq_create_cb,
1859 : : mlx5_hrxq_match_cb,
1860 : : mlx5_hrxq_remove_cb,
1861 : : mlx5_hrxq_clone_cb,
1862 : : mlx5_hrxq_clone_free_cb);
1863 [ # # ]: 0 : if (!priv->hrxqs)
1864 : 0 : goto error;
1865 : 0 : mlx5_set_metadata_mask(eth_dev);
1866 [ # # ]: 0 : if (sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1867 [ # # ]: 0 : !priv->sh->dv_regc0_mask) {
1868 : 0 : DRV_LOG(ERR, "metadata mode %u is not supported "
1869 : : "(no metadata reg_c[0] is available)",
1870 : : sh->config.dv_xmeta_en);
1871 : : err = ENOTSUP;
1872 : 0 : goto error;
1873 : : }
1874 : : rte_rwlock_init(&priv->ind_tbls_lock);
1875 [ # # ]: 0 : if (sh->config.dv_flow_en) {
1876 : 0 : err = mlx5_alloc_shared_dr(eth_dev);
1877 [ # # ]: 0 : if (err)
1878 : 0 : goto error;
1879 [ # # ]: 0 : if (mlx5_flex_item_port_init(eth_dev) < 0)
1880 : 0 : goto error;
1881 : : }
1882 [ # # ]: 0 : if (sh->phdev->config.ipv6_tc_fallback == MLX5_IPV6_TC_UNKNOWN) {
1883 : 0 : sh->phdev->config.ipv6_tc_fallback = MLX5_IPV6_TC_OK;
1884 [ # # ]: 0 : if (!sh->cdev->config.hca_attr.modify_outer_ipv6_traffic_class ||
1885 [ # # # # ]: 0 : (sh->config.dv_flow_en == 1 && mlx5_flow_discover_ipv6_tc_support(eth_dev)))
1886 : 0 : sh->phdev->config.ipv6_tc_fallback = MLX5_IPV6_TC_FALLBACK;
1887 : : }
1888 : : rte_spinlock_init(&priv->hw_ctrl_lock);
1889 : 0 : LIST_INIT(&priv->hw_ctrl_flows);
1890 : 0 : LIST_INIT(&priv->hw_ext_ctrl_flows);
1891 [ # # ]: 0 : if (priv->sh->config.dv_flow_en == 2) {
1892 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1893 : : /*
1894 : : * Unified FDB flag is only needed for the actions created on the transfer
1895 : : * port. proxy port. It is not needed on the following ports:
1896 : : * 1. NIC PF / VF / SF
1897 : : * 2. in Verbs or DV/DR mode
1898 : : * 3. with unsupported FW
1899 : : * 4. all representors in HWS
1900 : : */
1901 [ # # ]: 0 : priv->unified_fdb_en = sh->cdev->config.hca_attr.fdb_unified_en &&
1902 [ # # ]: 0 : priv->master &&
1903 [ # # ]: 0 : priv->vport_meta_mask != 0;
1904 : : /* Jump FDB Rx works only with unified FDB enabled. */
1905 [ # # ]: 0 : if (priv->unified_fdb_en)
1906 : 0 : priv->jump_fdb_rx_en = sh->cdev->config.hca_attr.jump_fdb_rx_en;
1907 [ # # # # ]: 0 : DRV_LOG(DEBUG, "port %u: unified FDB %s enabled, jump_fdb_rx %s enabled.",
1908 : : eth_dev->data->port_id,
1909 : : priv->unified_fdb_en ? "is" : "isn't",
1910 : : priv->jump_fdb_rx_en ? "is" : "isn't");
1911 : : /* Without vport metadata, PMD must rely on source_vport match. */
1912 [ # # # # ]: 0 : if (priv->sh->config.dv_esw_en && priv->vport_meta_mask == 0)
1913 : 0 : priv->vport_match = 1;
1914 [ # # ]: 0 : if (priv->sh->config.dv_esw_en)
1915 : 0 : mlx5_flow_hw_set_port_info(eth_dev);
1916 [ # # ]: 0 : if (priv->sh->config.dv_esw_en &&
1917 [ # # # # ]: 0 : priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_LEGACY &&
1918 : : priv->sh->config.dv_xmeta_en != MLX5_XMETA_MODE_META32_HWS) {
1919 : 0 : DRV_LOG(ERR,
1920 : : "metadata mode %u is not supported in HWS eswitch mode",
1921 : : priv->sh->config.dv_xmeta_en);
1922 : : err = ENOTSUP;
1923 : 0 : goto error;
1924 : : }
1925 [ # # # # ]: 0 : if (priv->sh->config.dv_esw_en &&
1926 : 0 : mlx5_flow_hw_create_vport_action(eth_dev)) {
1927 : 0 : DRV_LOG(ERR, "port %u failed to create vport action",
1928 : : eth_dev->data->port_id);
1929 : : err = EINVAL;
1930 : 0 : goto error;
1931 : : }
1932 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
1933 : 0 : return eth_dev;
1934 : : #else
1935 : : DRV_LOG(ERR, "DV support is missing for HWS.");
1936 : : goto error;
1937 : : #endif
1938 : : }
1939 [ # # ]: 0 : if (!priv->sh->flow_priority_check_flag) {
1940 : : /* Supported Verbs flow priority number detection. */
1941 : 0 : err = mlx5_flow_discover_priorities(eth_dev);
1942 : 0 : priv->sh->flow_max_priority = err;
1943 : 0 : priv->sh->flow_priority_check_flag = 1;
1944 : : } else {
1945 : 0 : err = priv->sh->flow_max_priority;
1946 : : }
1947 [ # # ]: 0 : if (err < 0) {
1948 : 0 : err = -err;
1949 : 0 : goto error;
1950 : : }
1951 : : rte_spinlock_init(&priv->shared_act_sl);
1952 : 0 : mlx5_flow_counter_mode_config(eth_dev);
1953 : 0 : mlx5_flow_drop_action_config(eth_dev);
1954 [ # # ]: 0 : if (sh->config.dv_flow_en)
1955 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
1956 : : return eth_dev;
1957 : 0 : error:
1958 [ # # ]: 0 : if (priv) {
1959 : 0 : priv->sh->port[priv->dev_port - 1].nl_ih_port_id =
1960 : : RTE_MAX_ETHPORTS;
1961 : 0 : rte_io_wmb();
1962 : : #ifdef HAVE_MLX5_HWS_SUPPORT
1963 [ # # ]: 0 : if (eth_dev &&
1964 [ # # ]: 0 : priv->sh &&
1965 [ # # ]: 0 : priv->sh->config.dv_flow_en == 2 &&
1966 : : priv->sh->config.dv_esw_en)
1967 : 0 : mlx5_flow_hw_destroy_vport_action(eth_dev);
1968 : : #endif
1969 [ # # ]: 0 : if (priv->sh)
1970 : 0 : mlx5_os_free_shared_dr(priv);
1971 [ # # ]: 0 : if (priv->nl_socket_route >= 0)
1972 : 0 : close(priv->nl_socket_route);
1973 [ # # ]: 0 : if (priv->vmwa_context)
1974 : 0 : mlx5_vlan_vmwa_exit(priv->vmwa_context);
1975 [ # # ]: 0 : for (i = 0; i < MLX5_FLOW_TYPE_MAXI; i++) {
1976 [ # # ]: 0 : if (!priv->flows[i])
1977 : 0 : continue;
1978 : 0 : mlx5_ipool_destroy(priv->flows[i]);
1979 : : }
1980 [ # # # # ]: 0 : if (eth_dev && priv->drop_queue.hrxq)
1981 : 0 : mlx5_drop_action_destroy(eth_dev);
1982 [ # # ]: 0 : if (priv->mtr_profile_tbl)
1983 : 0 : mlx5_l3t_destroy(priv->mtr_profile_tbl);
1984 [ # # ]: 0 : if (own_domain_id)
1985 : 0 : claim_zero(rte_eth_switch_domain_free(priv->domain_id));
1986 [ # # ]: 0 : if (priv->hrxqs)
1987 : 0 : mlx5_list_destroy(priv->hrxqs);
1988 [ # # # # ]: 0 : if (eth_dev && priv->flex_item_map)
1989 : 0 : mlx5_flex_item_port_cleanup(eth_dev);
1990 : 0 : mlx5_free(priv->ext_rxqs);
1991 : 0 : mlx5_free(priv->ext_txqs);
1992 : 0 : mlx5_free(priv->mac);
1993 : 0 : mlx5_free(priv->mac_own);
1994 : 0 : mlx5_free(priv);
1995 [ # # ]: 0 : if (eth_dev != NULL) {
1996 : 0 : eth_dev->data->mac_addrs = NULL;
1997 : 0 : eth_dev->data->dev_private = NULL;
1998 : : }
1999 : : }
2000 [ # # ]: 0 : if (eth_dev != NULL)
2001 : 0 : rte_eth_dev_release_port(eth_dev);
2002 : : if (sh)
2003 : 0 : mlx5_free_shared_dev_ctx(sh);
2004 [ # # ]: 0 : if (nl_rdma >= 0)
2005 : 0 : close(nl_rdma);
2006 : : MLX5_ASSERT(err > 0);
2007 : 0 : rte_errno = err;
2008 : 0 : return NULL;
2009 : : }
2010 : :
2011 : : /**
2012 : : * Comparison callback to sort device data.
2013 : : *
2014 : : * This is meant to be used with qsort().
2015 : : *
2016 : : * @param a[in]
2017 : : * Pointer to pointer to first data object.
2018 : : * @param b[in]
2019 : : * Pointer to pointer to second data object.
2020 : : *
2021 : : * @return
2022 : : * 0 if both objects are equal, less than 0 if the first argument is less
2023 : : * than the second, greater than 0 otherwise.
2024 : : */
2025 : : static int
2026 : 0 : mlx5_dev_spawn_data_cmp(const void *a, const void *b)
2027 : : {
2028 : : const struct mlx5_switch_info *si_a =
2029 : : &((const struct mlx5_dev_spawn_data *)a)->info;
2030 : : const struct mlx5_switch_info *si_b =
2031 : : &((const struct mlx5_dev_spawn_data *)b)->info;
2032 : 0 : int uplink_a = si_a->name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK;
2033 : 0 : int uplink_b = si_b->name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK;
2034 : : int ret;
2035 : :
2036 : : /* Uplink ports first. */
2037 : 0 : ret = uplink_b - uplink_a;
2038 [ # # ]: 0 : if (ret)
2039 : : return ret;
2040 : : /* Then master devices. */
2041 : 0 : ret = si_b->master - si_a->master;
2042 [ # # ]: 0 : if (ret)
2043 : : return ret;
2044 : : /* Then representor devices. */
2045 : 0 : ret = si_b->representor - si_a->representor;
2046 [ # # ]: 0 : if (ret)
2047 : : return ret;
2048 : : /* Unidentified devices come last in no specific order. */
2049 [ # # ]: 0 : if (!si_a->representor)
2050 : : return 0;
2051 : : /* Order representors by name. */
2052 : 0 : return si_a->port_name - si_b->port_name;
2053 : : }
2054 : :
2055 : : /**
2056 : : * Match PCI information for possible slaves of bonding device.
2057 : : *
2058 : : * @param[in] ibdev
2059 : : * Pointer to IB device.
2060 : : * @param[in] pci_dev
2061 : : * Pointer to primary PCI address structure to match.
2062 : : * @param[in] nl_rdma
2063 : : * Netlink RDMA group socket handle.
2064 : : * @param[in] owner
2065 : : * Representor owner PF index.
2066 : : * @param[in] dev_info
2067 : : * Cached mlx5 device information.
2068 : : * @param[out] bond_info
2069 : : * Pointer to bonding information.
2070 : : *
2071 : : * @return
2072 : : * negative value if no bonding device found, otherwise
2073 : : * positive index of slave PF in bonding.
2074 : : */
2075 : : static int
2076 : 0 : mlx5_device_bond_pci_match(const struct ibv_device *ibdev,
2077 : : const struct rte_pci_addr *pci_dev,
2078 : : int nl_rdma, uint16_t owner,
2079 : : struct mlx5_dev_info *dev_info,
2080 : : struct mlx5_bond_info *bond_info)
2081 : : {
2082 : : char ifname[IF_NAMESIZE + 1];
2083 : : unsigned int ifindex;
2084 : : unsigned int np, i;
2085 : : FILE *bond_file = NULL, *file;
2086 : : int pf = -1;
2087 : : int ret;
2088 : 0 : uint8_t cur_guid[32] = {0};
2089 [ # # ]: 0 : uint8_t guid[32] = {0};
2090 : :
2091 : : /*
2092 : : * Try to get master device name. If something goes wrong suppose
2093 : : * the lack of kernel support and no bonding devices.
2094 : : */
2095 : : memset(bond_info, 0, sizeof(*bond_info));
2096 [ # # ]: 0 : if (nl_rdma < 0)
2097 : : return -1;
2098 [ # # ]: 0 : if (!mlx5_os_is_device_bond(ibdev))
2099 : : return -1;
2100 : 0 : np = mlx5_nl_portnum(nl_rdma, ibdev->name, dev_info);
2101 [ # # ]: 0 : if (!np)
2102 : : return -1;
2103 [ # # ]: 0 : if (mlx5_get_device_guid(pci_dev, cur_guid, sizeof(cur_guid)) < 0)
2104 : : return -1;
2105 : : /*
2106 : : * The master device might not be on the predefined port(not on port
2107 : : * index 1, it is not guaranteed), we have to scan all Infiniband
2108 : : * device ports and find master.
2109 : : */
2110 [ # # ]: 0 : for (i = 1; i <= np; ++i) {
2111 : : /* Check whether Infiniband port is populated. */
2112 : 0 : ifindex = mlx5_nl_ifindex(nl_rdma, ibdev->name, i, dev_info);
2113 [ # # ]: 0 : if (!ifindex)
2114 : 0 : continue;
2115 [ # # ]: 0 : if (!if_indextoname(ifindex, ifname))
2116 : 0 : continue;
2117 : : /* Try to read bonding slave names from sysfs. */
2118 : 0 : MKSTR(slaves,
2119 : : "/sys/class/net/%s/master/bonding/slaves", ifname);
2120 : 0 : bond_file = fopen(slaves, "r");
2121 [ # # ]: 0 : if (bond_file)
2122 : : break;
2123 : : }
2124 [ # # ]: 0 : if (!bond_file)
2125 : : return -1;
2126 : : /* Use safe format to check maximal buffer length. */
2127 : : MLX5_ASSERT(atol(RTE_STR(IF_NAMESIZE)) == IF_NAMESIZE);
2128 [ # # ]: 0 : while (fscanf(bond_file, "%" RTE_STR(IF_NAMESIZE) "s", ifname) == 1) {
2129 : : char tmp_str[IF_NAMESIZE + 32];
2130 : : struct rte_pci_addr pci_addr;
2131 : : struct mlx5_switch_info info;
2132 : : int ret;
2133 : :
2134 : : /* Process slave interface names in the loop. */
2135 : : snprintf(tmp_str, sizeof(tmp_str),
2136 : : "/sys/class/net/%s", ifname);
2137 [ # # ]: 0 : if (mlx5_get_pci_addr(tmp_str, &pci_addr)) {
2138 : 0 : DRV_LOG(WARNING,
2139 : : "Cannot get PCI address for netdev \"%s\".",
2140 : : ifname);
2141 : 0 : continue;
2142 : : }
2143 : : /* Slave interface PCI address match found. */
2144 : : snprintf(tmp_str, sizeof(tmp_str),
2145 : : "/sys/class/net/%s/phys_port_name", ifname);
2146 : 0 : file = fopen(tmp_str, "rb");
2147 [ # # ]: 0 : if (!file)
2148 : : break;
2149 : 0 : info.name_type = MLX5_PHYS_PORT_NAME_TYPE_NOTSET;
2150 [ # # ]: 0 : if (fscanf(file, "%32s", tmp_str) == 1) {
2151 : 0 : mlx5_translate_port_name(tmp_str, &info);
2152 : 0 : fclose(file);
2153 : : } else {
2154 : 0 : fclose(file);
2155 : 0 : break;
2156 : : }
2157 : : /* Only process PF ports. */
2158 [ # # ]: 0 : if (info.name_type != MLX5_PHYS_PORT_NAME_TYPE_LEGACY &&
2159 : : info.name_type != MLX5_PHYS_PORT_NAME_TYPE_UPLINK)
2160 : 0 : continue;
2161 : : /* Check max bonding member. */
2162 [ # # ]: 0 : if (info.port_name >= MLX5_BOND_MAX_PORTS) {
2163 : 0 : DRV_LOG(WARNING, "bonding index out of range, "
2164 : : "please increase MLX5_BOND_MAX_PORTS: %s",
2165 : : tmp_str);
2166 : 0 : break;
2167 : : }
2168 : : /* Get ifindex. */
2169 : : snprintf(tmp_str, sizeof(tmp_str),
2170 : : "/sys/class/net/%s/ifindex", ifname);
2171 : 0 : file = fopen(tmp_str, "rb");
2172 [ # # ]: 0 : if (!file)
2173 : : break;
2174 : 0 : ret = fscanf(file, "%u", &ifindex);
2175 : 0 : fclose(file);
2176 [ # # ]: 0 : if (ret != 1)
2177 : : break;
2178 : : /* Save bonding info. */
2179 : 0 : snprintf(bond_info->ports[info.port_name].ifname,
2180 : : sizeof(bond_info->ports[0].ifname), "%s", ifname);
2181 : 0 : bond_info->ports[info.port_name].pci_addr = pci_addr;
2182 : 0 : bond_info->ports[info.port_name].ifindex = ifindex;
2183 : 0 : bond_info->n_port++;
2184 : : /*
2185 : : * Under socket direct mode, bonding will use
2186 : : * system_image_guid as identification.
2187 : : * After OFED 5.4, guid is readable (ret >= 0) under sysfs.
2188 : : * All bonding members should have the same guid even if driver
2189 : : * is using PCIe BDF.
2190 : : */
2191 : 0 : ret = mlx5_get_device_guid(&pci_addr, guid, sizeof(guid));
2192 [ # # ]: 0 : if (ret < 0)
2193 : : break;
2194 [ # # ]: 0 : else if (ret > 0) {
2195 [ # # ]: 0 : if (!memcmp(guid, cur_guid, sizeof(guid)) &&
2196 [ # # # # ]: 0 : owner == info.port_name &&
2197 [ # # ]: 0 : (owner != 0 || (owner == 0 &&
2198 : 0 : !rte_pci_addr_cmp(pci_dev, &pci_addr))))
2199 : 0 : pf = info.port_name;
2200 [ # # ]: 0 : } else if (pci_dev->domain == pci_addr.domain &&
2201 [ # # ]: 0 : pci_dev->bus == pci_addr.bus &&
2202 : 0 : pci_dev->devid == pci_addr.devid &&
2203 [ # # ]: 0 : ((pci_dev->function == 0 &&
2204 [ # # ]: 0 : pci_dev->function + owner == pci_addr.function) ||
2205 [ # # ]: 0 : (pci_dev->function == owner &&
2206 [ # # ]: 0 : pci_addr.function == owner)))
2207 : 0 : pf = info.port_name;
2208 : : }
2209 : 0 : fclose(bond_file);
2210 [ # # ]: 0 : if (pf >= 0) {
2211 : : /* Get bond interface info */
2212 : 0 : ret = mlx5_sysfs_bond_info(ifindex, &bond_info->ifindex,
2213 : 0 : bond_info->ifname);
2214 [ # # ]: 0 : if (ret)
2215 : 0 : DRV_LOG(ERR, "unable to get bond info: %s",
2216 : : strerror(rte_errno));
2217 : : else
2218 : 0 : DRV_LOG(INFO, "PF device %u, bond device %u(%s)",
2219 : : ifindex, bond_info->ifindex, bond_info->ifname);
2220 : : }
2221 [ # # ]: 0 : if (owner == 0 && pf != 0) {
2222 : 0 : DRV_LOG(INFO, "PCIe instance " PCI_PRI_FMT " isn't bonding owner",
2223 : : pci_dev->domain, pci_dev->bus, pci_dev->devid,
2224 : : pci_dev->function);
2225 : : }
2226 : : return pf;
2227 : : }
2228 : :
2229 : : static int
2230 : 0 : mlx5_nl_esw_multiport_get(struct rte_pci_addr *pci_addr, int *enabled)
2231 : : {
2232 : 0 : char pci_addr_str[PCI_PRI_STR_SIZE] = { 0 };
2233 : : int nlsk_fd;
2234 : : int devlink_id;
2235 : : int ret;
2236 : :
2237 : : /* Provide correct value to have defined enabled state in case of an error. */
2238 : 0 : *enabled = 0;
2239 : 0 : rte_pci_device_name(pci_addr, pci_addr_str, sizeof(pci_addr_str));
2240 : 0 : nlsk_fd = mlx5_nl_init(NETLINK_GENERIC, 0);
2241 [ # # ]: 0 : if (nlsk_fd < 0)
2242 : : return nlsk_fd;
2243 : 0 : devlink_id = mlx5_nl_devlink_family_id_get(nlsk_fd);
2244 [ # # ]: 0 : if (devlink_id < 0) {
2245 : : ret = devlink_id;
2246 : 0 : DRV_LOG(DEBUG, "Unable to get devlink family id for Multiport E-Switch checks "
2247 : : "by netlink, for PCI device %s", pci_addr_str);
2248 : 0 : goto close_nlsk_fd;
2249 : : }
2250 : 0 : ret = mlx5_nl_devlink_esw_multiport_get(nlsk_fd, devlink_id, pci_addr_str, enabled);
2251 [ # # ]: 0 : if (ret < 0)
2252 : 0 : DRV_LOG(DEBUG, "Unable to get Multiport E-Switch state by Netlink.");
2253 : 0 : close_nlsk_fd:
2254 : 0 : close(nlsk_fd);
2255 : 0 : return ret;
2256 : : }
2257 : :
2258 : : #define SYSFS_MPESW_PARAM_MAX_LEN 16
2259 : :
2260 : : static int
2261 : 0 : mlx5_sysfs_esw_multiport_get(struct ibv_device *ibv, struct rte_pci_addr *pci_addr, int *enabled,
2262 : : struct mlx5_dev_info *dev_info)
2263 : : {
2264 : : int nl_rdma;
2265 : : unsigned int n_ports;
2266 : : unsigned int i;
2267 : : int ret;
2268 : :
2269 : : /* Provide correct value to have defined enabled state in case of an error. */
2270 : 0 : *enabled = 0;
2271 : 0 : nl_rdma = mlx5_nl_init(NETLINK_RDMA, 0);
2272 [ # # ]: 0 : if (nl_rdma < 0)
2273 : : return nl_rdma;
2274 : 0 : n_ports = mlx5_nl_portnum(nl_rdma, ibv->name, dev_info);
2275 [ # # ]: 0 : if (!n_ports) {
2276 : 0 : ret = -rte_errno;
2277 : 0 : goto close_nl_rdma;
2278 : : }
2279 [ # # ]: 0 : for (i = 1; i <= n_ports; ++i) {
2280 : : unsigned int ifindex;
2281 : : char ifname[IF_NAMESIZE + 1];
2282 : 0 : struct rte_pci_addr if_pci_addr = { 0 };
2283 : : char mpesw[SYSFS_MPESW_PARAM_MAX_LEN + 1];
2284 : : FILE *sysfs;
2285 : : int n;
2286 : :
2287 : 0 : ifindex = mlx5_nl_ifindex(nl_rdma, ibv->name, i, dev_info);
2288 [ # # ]: 0 : if (!ifindex)
2289 : 0 : continue;
2290 [ # # ]: 0 : if (!if_indextoname(ifindex, ifname))
2291 : 0 : continue;
2292 : 0 : MKSTR(sysfs_if_path, "/sys/class/net/%s", ifname);
2293 [ # # ]: 0 : if (mlx5_get_pci_addr(sysfs_if_path, &if_pci_addr))
2294 : 0 : continue;
2295 [ # # ]: 0 : if (pci_addr->domain != if_pci_addr.domain ||
2296 [ # # ]: 0 : pci_addr->bus != if_pci_addr.bus ||
2297 : 0 : pci_addr->devid != if_pci_addr.devid ||
2298 [ # # ]: 0 : pci_addr->function != if_pci_addr.function)
2299 : 0 : continue;
2300 : 0 : MKSTR(sysfs_mpesw_path,
2301 : : "/sys/class/net/%s/compat/devlink/lag_port_select_mode", ifname);
2302 : 0 : sysfs = fopen(sysfs_mpesw_path, "r");
2303 [ # # ]: 0 : if (!sysfs)
2304 : 0 : continue;
2305 : 0 : n = fscanf(sysfs, "%" RTE_STR(SYSFS_MPESW_PARAM_MAX_LEN) "s", mpesw);
2306 : 0 : fclose(sysfs);
2307 [ # # ]: 0 : if (n != 1)
2308 : 0 : continue;
2309 : : ret = 0;
2310 [ # # ]: 0 : if (strcmp(mpesw, "multiport_esw") == 0) {
2311 : 0 : *enabled = 1;
2312 : 0 : break;
2313 : : }
2314 : 0 : *enabled = 0;
2315 : 0 : break;
2316 : : }
2317 [ # # ]: 0 : if (i > n_ports) {
2318 : 0 : DRV_LOG(DEBUG, "Unable to get Multiport E-Switch state by sysfs.");
2319 : 0 : rte_errno = ENOENT;
2320 : : ret = -rte_errno;
2321 : : }
2322 : :
2323 : 0 : close_nl_rdma:
2324 : 0 : close(nl_rdma);
2325 : 0 : return ret;
2326 : : }
2327 : :
2328 : : static int
2329 : 0 : mlx5_is_mpesw_enabled(struct ibv_device *ibv, struct rte_pci_addr *ibv_pci_addr, int *enabled,
2330 : : struct mlx5_dev_info *dev_info)
2331 : : {
2332 : : /*
2333 : : * Try getting Multiport E-Switch state through netlink interface
2334 : : * If unable, try sysfs interface. If that is unable as well,
2335 : : * assume that Multiport E-Switch is disabled and return an error.
2336 : : */
2337 [ # # # # ]: 0 : if (mlx5_nl_esw_multiport_get(ibv_pci_addr, enabled) >= 0 ||
2338 : 0 : mlx5_sysfs_esw_multiport_get(ibv, ibv_pci_addr, enabled, dev_info) >= 0)
2339 : 0 : return 0;
2340 : 0 : DRV_LOG(DEBUG, "Unable to check MPESW state for IB device %s "
2341 : : "(PCI: " PCI_PRI_FMT ")",
2342 : : ibv->name,
2343 : : ibv_pci_addr->domain, ibv_pci_addr->bus,
2344 : : ibv_pci_addr->devid, ibv_pci_addr->function);
2345 : 0 : *enabled = 0;
2346 : 0 : return -rte_errno;
2347 : : }
2348 : :
2349 : : static int
2350 : 0 : mlx5_device_mpesw_pci_match(struct ibv_device *ibv,
2351 : : const struct rte_pci_addr *owner_pci,
2352 : : int nl_rdma, struct mlx5_dev_info *dev_info)
2353 : : {
2354 : 0 : struct rte_pci_addr ibdev_pci_addr = { 0 };
2355 : 0 : char ifname[IF_NAMESIZE + 1] = { 0 };
2356 : : unsigned int ifindex;
2357 : : unsigned int np;
2358 : : unsigned int i;
2359 : 0 : int enabled = 0;
2360 : : int ret;
2361 : :
2362 : : /* Check if IB device's PCI address matches the probed PCI address. */
2363 [ # # ]: 0 : if (mlx5_get_pci_addr(ibv->ibdev_path, &ibdev_pci_addr)) {
2364 : 0 : DRV_LOG(DEBUG, "Skipping MPESW check for IB device %s since "
2365 : : "there is no underlying PCI device", ibv->name);
2366 : 0 : rte_errno = ENOENT;
2367 : 0 : return -rte_errno;
2368 : : }
2369 [ # # ]: 0 : if (ibdev_pci_addr.domain != owner_pci->domain ||
2370 [ # # ]: 0 : ibdev_pci_addr.bus != owner_pci->bus ||
2371 : 0 : ibdev_pci_addr.devid != owner_pci->devid ||
2372 [ # # ]: 0 : ibdev_pci_addr.function != owner_pci->function) {
2373 : : return -1;
2374 : : }
2375 : : /* Check if IB device has MPESW enabled. */
2376 [ # # ]: 0 : if (mlx5_is_mpesw_enabled(ibv, &ibdev_pci_addr, &enabled, dev_info))
2377 : : return -1;
2378 [ # # ]: 0 : if (!enabled)
2379 : : return -1;
2380 : : /* Iterate through IB ports to find MPESW master uplink port. */
2381 [ # # ]: 0 : if (nl_rdma < 0)
2382 : : return -1;
2383 : 0 : np = mlx5_nl_portnum(nl_rdma, ibv->name, dev_info);
2384 [ # # ]: 0 : if (!np)
2385 : : return -1;
2386 [ # # ]: 0 : for (i = 1; i <= np; ++i) {
2387 : 0 : struct rte_pci_addr pci_addr = { 0 };
2388 : : FILE *file;
2389 : : char port_name[IF_NAMESIZE + 1];
2390 : : struct mlx5_switch_info info;
2391 : :
2392 : : /* Check whether IB port has a corresponding netdev. */
2393 : 0 : ifindex = mlx5_nl_ifindex(nl_rdma, ibv->name, i, dev_info);
2394 [ # # ]: 0 : if (!ifindex)
2395 : 0 : continue;
2396 [ # # ]: 0 : if (!if_indextoname(ifindex, ifname))
2397 : 0 : continue;
2398 : : /* Read port name and determine its type. */
2399 : 0 : MKSTR(ifphysportname, "/sys/class/net/%s/phys_port_name", ifname);
2400 : 0 : file = fopen(ifphysportname, "rb");
2401 [ # # ]: 0 : if (!file)
2402 : 0 : continue;
2403 : 0 : ret = fscanf(file, "%16s", port_name);
2404 : 0 : fclose(file);
2405 [ # # ]: 0 : if (ret != 1)
2406 : 0 : continue;
2407 : : memset(&info, 0, sizeof(info));
2408 : 0 : mlx5_translate_port_name(port_name, &info);
2409 [ # # ]: 0 : if (info.name_type != MLX5_PHYS_PORT_NAME_TYPE_UPLINK)
2410 : 0 : continue;
2411 : : /* Fetch PCI address of the device to which the netdev is bound. */
2412 : 0 : MKSTR(ifpath, "/sys/class/net/%s", ifname);
2413 [ # # ]: 0 : if (mlx5_get_pci_addr(ifpath, &pci_addr))
2414 : 0 : continue;
2415 [ # # ]: 0 : if (pci_addr.domain == ibdev_pci_addr.domain &&
2416 : : pci_addr.bus == ibdev_pci_addr.bus &&
2417 [ # # ]: 0 : pci_addr.devid == ibdev_pci_addr.devid &&
2418 : : pci_addr.function == ibdev_pci_addr.function) {
2419 : : MLX5_ASSERT(info.port_name >= 0);
2420 : 0 : return info.port_name;
2421 : : }
2422 : : }
2423 : : /* No matching MPESW uplink port was found. */
2424 : : return -1;
2425 : : }
2426 : :
2427 : : static void
2428 : 0 : calc_nb_uplinks_hpfs(struct ibv_device **ibv_match,
2429 : : unsigned int nd,
2430 : : struct mlx5_dev_spawn_data *list,
2431 : : unsigned int ns)
2432 : : {
2433 [ # # ]: 0 : for (unsigned int i = 0; i != nd; i++) {
2434 : : uint32_t nb_uplinks = 0;
2435 : : uint32_t nb_hpfs = 0;
2436 : : uint32_t j;
2437 : :
2438 [ # # ]: 0 : for (unsigned int j = 0; j != ns; j++) {
2439 [ # # ]: 0 : if (strcmp(ibv_match[i]->name, list[j].phys_dev_name) != 0)
2440 : 0 : continue;
2441 : :
2442 [ # # ]: 0 : if (list[j].info.name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK)
2443 : 0 : nb_uplinks++;
2444 [ # # ]: 0 : else if (list[j].info.name_type == MLX5_PHYS_PORT_NAME_TYPE_PFHPF)
2445 : 0 : nb_hpfs++;
2446 : : }
2447 : :
2448 [ # # ]: 0 : if (nb_uplinks > 0 || nb_hpfs > 0) {
2449 [ # # ]: 0 : for (j = 0; j != ns; j++) {
2450 [ # # ]: 0 : if (strcmp(ibv_match[i]->name, list[j].phys_dev_name) != 0)
2451 : 0 : continue;
2452 : :
2453 : 0 : list[j].nb_uplinks = nb_uplinks;
2454 : 0 : list[j].nb_hpfs = nb_hpfs;
2455 : : }
2456 : :
2457 : 0 : DRV_LOG(DEBUG, "IB device %s has %u uplinks, %u host PFs",
2458 : : ibv_match[i]->name,
2459 : : nb_uplinks,
2460 : : nb_hpfs);
2461 : : } else {
2462 : 0 : DRV_LOG(DEBUG, "IB device %s unable to recognize uplinks/host PFs",
2463 : : ibv_match[i]->name);
2464 : : }
2465 : : }
2466 : 0 : }
2467 : :
2468 : : /**
2469 : : * Register a PCI device within bonding.
2470 : : *
2471 : : * This function spawns Ethernet devices out of a given PCI device and
2472 : : * bonding owner PF index.
2473 : : *
2474 : : * @param[in] cdev
2475 : : * Pointer to common mlx5 device structure.
2476 : : * @param[in] req_eth_da
2477 : : * Requested ethdev device argument.
2478 : : * @param[in] owner_id
2479 : : * Requested owner PF port ID within bonding device, default to 0.
2480 : : * @param[in, out] mkvlist
2481 : : * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
2482 : : *
2483 : : * @return
2484 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
2485 : : */
2486 : : static int
2487 : 0 : mlx5_os_pci_probe_pf(struct mlx5_common_device *cdev,
2488 : : struct rte_eth_devargs *req_eth_da,
2489 : : uint16_t owner_id, struct mlx5_kvargs_ctrl *mkvlist)
2490 : 0 : {
2491 : : struct ibv_device **ibv_list;
2492 : : /*
2493 : : * Number of found IB Devices matching with requested PCI BDF.
2494 : : * nd != 1 means there are multiple IB devices over the same
2495 : : * PCI device and we have representors and master.
2496 : : */
2497 : : unsigned int nd = 0;
2498 : : /*
2499 : : * Number of found IB device Ports. nd = 1 and np = 1..n means
2500 : : * we have the single multiport IB device, and there may be
2501 : : * representors attached to some of found ports.
2502 : : */
2503 : : unsigned int np = 0;
2504 : : /*
2505 : : * Number of DPDK ethernet devices to Spawn - either over
2506 : : * multiple IB devices or multiple ports of single IB device.
2507 : : * Actually this is the number of iterations to spawn.
2508 : : */
2509 : : unsigned int ns = 0;
2510 : : /*
2511 : : * Bonding device
2512 : : * < 0 - no bonding device (single one)
2513 : : * >= 0 - bonding device (value is slave PF index)
2514 : : */
2515 : : int bd = -1;
2516 : : /*
2517 : : * Multiport E-Switch (MPESW) device:
2518 : : * < 0 - no MPESW device or could not determine if it is MPESW device,
2519 : : * >= 0 - MPESW device. Value is the port index of the MPESW owner.
2520 : : */
2521 : : int mpesw = MLX5_MPESW_PORT_INVALID;
2522 : 0 : struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(cdev->dev, *pci_dev);
2523 : : struct mlx5_dev_spawn_data *list = NULL;
2524 : 0 : struct rte_eth_devargs eth_da = *req_eth_da;
2525 : 0 : struct rte_pci_addr owner_pci = pci_dev->addr; /* Owner PF. */
2526 : : struct mlx5_bond_info bond_info;
2527 : 0 : int ret = -1;
2528 : :
2529 : 0 : errno = 0;
2530 : 0 : ibv_list = mlx5_glue->get_device_list(&ret);
2531 [ # # ]: 0 : if (!ibv_list) {
2532 [ # # ]: 0 : rte_errno = errno ? errno : ENOSYS;
2533 : 0 : DRV_LOG(ERR, "Cannot list devices, is ib_uverbs loaded?");
2534 : 0 : return -rte_errno;
2535 : : }
2536 : : /*
2537 : : * First scan the list of all Infiniband devices to find
2538 : : * matching ones, gathering into the list.
2539 : : */
2540 : 0 : struct ibv_device *ibv_match[ret + 1];
2541 : 0 : struct mlx5_dev_info *info, tmp_info[ret];
2542 : 0 : int nl_route = mlx5_nl_init(NETLINK_ROUTE, 0);
2543 : 0 : int nl_rdma = mlx5_nl_init(NETLINK_RDMA, 0);
2544 : : unsigned int i;
2545 : :
2546 : : memset(tmp_info, 0, sizeof(tmp_info));
2547 [ # # ]: 0 : while (ret-- > 0) {
2548 : : struct rte_pci_addr pci_addr;
2549 : :
2550 [ # # # # ]: 0 : if (cdev->config.probe_opt && cdev->dev_info.port_num) {
2551 [ # # ]: 0 : if (strcmp(ibv_list[ret]->name, cdev->dev_info.ibname)) {
2552 : 0 : DRV_LOG(INFO, "Unmatched caching device \"%s\" \"%s\"",
2553 : : cdev->dev_info.ibname, ibv_list[ret]->name);
2554 : 0 : continue;
2555 : : }
2556 : 0 : info = &cdev->dev_info;
2557 : : } else {
2558 : 0 : info = &tmp_info[ret];
2559 : : }
2560 : 0 : DRV_LOG(DEBUG, "Checking device \"%s\"", ibv_list[ret]->name);
2561 : 0 : bd = mlx5_device_bond_pci_match(ibv_list[ret], &owner_pci,
2562 : : nl_rdma, owner_id,
2563 : : info,
2564 : : &bond_info);
2565 [ # # ]: 0 : if (bd >= 0) {
2566 : : /*
2567 : : * Bonding device detected. Only one match is allowed,
2568 : : * the bonding is supported over multi-port IB device,
2569 : : * there should be no matches on representor PCI
2570 : : * functions or non VF LAG bonding devices with
2571 : : * specified address.
2572 : : */
2573 [ # # ]: 0 : if (nd) {
2574 : 0 : DRV_LOG(ERR,
2575 : : "multiple PCI match on bonding device"
2576 : : "\"%s\" found", ibv_list[ret]->name);
2577 : 0 : rte_errno = ENOENT;
2578 : 0 : ret = -rte_errno;
2579 : 0 : goto exit;
2580 : : }
2581 : : /* Amend owner pci address if owner PF ID specified. */
2582 [ # # ]: 0 : if (eth_da.nb_representor_ports)
2583 : 0 : owner_pci.function += owner_id;
2584 : 0 : DRV_LOG(INFO,
2585 : : "PCI information matches for slave %d bonding device \"%s\"",
2586 : : bd, ibv_list[ret]->name);
2587 : 0 : ibv_match[nd++] = ibv_list[ret];
2588 : 0 : break;
2589 : : }
2590 : 0 : mpesw = mlx5_device_mpesw_pci_match(ibv_list[ret], &owner_pci, nl_rdma,
2591 : : info);
2592 [ # # ]: 0 : if (mpesw >= 0) {
2593 : : /*
2594 : : * MPESW device detected. Only one matching IB device is allowed,
2595 : : * so if any matches were found previously, fail gracefully.
2596 : : */
2597 [ # # ]: 0 : if (nd) {
2598 : 0 : DRV_LOG(ERR,
2599 : : "PCI information matches MPESW device \"%s\", "
2600 : : "but multiple matching PCI devices were found. "
2601 : : "Probing failed.",
2602 : : ibv_list[ret]->name);
2603 : 0 : rte_errno = ENOENT;
2604 : 0 : ret = -rte_errno;
2605 : 0 : goto exit;
2606 : : }
2607 : 0 : DRV_LOG(INFO,
2608 : : "PCI information matches MPESW device \"%s\"",
2609 : : ibv_list[ret]->name);
2610 : 0 : ibv_match[nd++] = ibv_list[ret];
2611 : 0 : break;
2612 : : }
2613 : : /* Bonding or MPESW device was not found. */
2614 [ # # ]: 0 : if (mlx5_get_pci_addr(ibv_list[ret]->ibdev_path,
2615 : : &pci_addr)) {
2616 [ # # ]: 0 : if (tmp_info[ret].port_info != NULL)
2617 : 0 : mlx5_free(tmp_info[ret].port_info);
2618 : 0 : memset(&tmp_info[ret], 0, sizeof(tmp_info[0]));
2619 : 0 : continue;
2620 : : }
2621 [ # # ]: 0 : if (rte_pci_addr_cmp(&owner_pci, &pci_addr) != 0) {
2622 [ # # ]: 0 : if (tmp_info[ret].port_info != NULL)
2623 : 0 : mlx5_free(tmp_info[ret].port_info);
2624 : 0 : memset(&tmp_info[ret], 0, sizeof(tmp_info[0]));
2625 : 0 : continue;
2626 : : }
2627 : 0 : DRV_LOG(INFO, "PCI information matches for device \"%s\"",
2628 : : ibv_list[ret]->name);
2629 : 0 : ibv_match[nd++] = ibv_list[ret];
2630 : : }
2631 : 0 : ibv_match[nd] = NULL;
2632 [ # # ]: 0 : if (!nd) {
2633 : : /* No device matches, just complain and bail out. */
2634 : 0 : DRV_LOG(WARNING,
2635 : : "PF %u doesn't have Verbs device matches PCI device " PCI_PRI_FMT ","
2636 : : " are kernel drivers loaded?",
2637 : : owner_id, owner_pci.domain, owner_pci.bus,
2638 : : owner_pci.devid, owner_pci.function);
2639 : 0 : rte_errno = ENOENT;
2640 : 0 : ret = -rte_errno;
2641 : 0 : goto exit;
2642 : : }
2643 [ # # ]: 0 : if (nd == 1) {
2644 [ # # ]: 0 : if (!cdev->dev_info.port_num) {
2645 [ # # ]: 0 : for (i = 0; i < RTE_DIM(tmp_info); i++) {
2646 [ # # ]: 0 : if (tmp_info[i].port_num) {
2647 : 0 : cdev->dev_info = tmp_info[i];
2648 : 0 : break;
2649 : : }
2650 : : }
2651 : : }
2652 : : /*
2653 : : * Found single matching device may have multiple ports.
2654 : : * Each port may be representor, we have to check the port
2655 : : * number and check the representors existence.
2656 : : */
2657 [ # # ]: 0 : if (nl_rdma >= 0)
2658 : 0 : np = mlx5_nl_portnum(nl_rdma, ibv_match[0]->name, &cdev->dev_info);
2659 [ # # ]: 0 : if (!np)
2660 : 0 : DRV_LOG(WARNING,
2661 : : "Cannot get IB device \"%s\" ports number.",
2662 : : ibv_match[0]->name);
2663 [ # # ]: 0 : if (bd >= 0 && !np) {
2664 : 0 : DRV_LOG(ERR, "Cannot get ports for bonding device.");
2665 : 0 : rte_errno = ENOENT;
2666 : 0 : ret = -rte_errno;
2667 : 0 : goto exit;
2668 : : }
2669 [ # # ]: 0 : if (mpesw >= 0 && !np) {
2670 : 0 : DRV_LOG(ERR, "Cannot get ports for MPESW device.");
2671 : 0 : rte_errno = ENOENT;
2672 : 0 : ret = -rte_errno;
2673 : 0 : goto exit;
2674 : : }
2675 : : } else {
2676 : : /* Can't handle one common device with multiple IB devices caching */
2677 [ # # ]: 0 : for (i = 0; i < RTE_DIM(tmp_info); i++) {
2678 [ # # ]: 0 : if (tmp_info[i].port_info != NULL)
2679 : 0 : mlx5_free(tmp_info[i].port_info);
2680 : 0 : memset(&tmp_info[i], 0, sizeof(tmp_info[0]));
2681 : : }
2682 : 0 : DRV_LOG(INFO, "Cannot handle multiple IB devices info caching in single common device.");
2683 : : }
2684 : : /* Now we can determine the maximal amount of devices to be spawned. */
2685 [ # # ]: 0 : list = mlx5_malloc(MLX5_MEM_ZERO,
2686 : 0 : sizeof(struct mlx5_dev_spawn_data) * (np ? np : nd),
2687 : : RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
2688 [ # # ]: 0 : if (!list) {
2689 : 0 : DRV_LOG(ERR, "Spawn data array allocation failure.");
2690 : 0 : rte_errno = ENOMEM;
2691 : 0 : ret = -rte_errno;
2692 : 0 : goto exit;
2693 : : }
2694 [ # # # # ]: 0 : if (bd >= 0 || mpesw >= 0 || np > 1) {
2695 : : /*
2696 : : * Single IB device with multiple ports found,
2697 : : * it may be E-Switch master device and representors.
2698 : : * We have to perform identification through the ports.
2699 : : */
2700 : : MLX5_ASSERT(nl_rdma >= 0);
2701 : : MLX5_ASSERT(ns == 0);
2702 : : MLX5_ASSERT(nd == 1);
2703 : : MLX5_ASSERT(np);
2704 [ # # ]: 0 : for (i = 1; i <= np; ++i) {
2705 : 0 : list[ns].bond_info = &bond_info;
2706 : 0 : list[ns].max_port = np;
2707 : 0 : list[ns].phys_port = i;
2708 : 0 : list[ns].phys_dev_name = ibv_match[0]->name;
2709 : 0 : list[ns].eth_dev = NULL;
2710 : 0 : list[ns].pci_dev = pci_dev;
2711 : 0 : list[ns].cdev = cdev;
2712 : 0 : list[ns].pf_bond = bd;
2713 : 0 : list[ns].mpesw_port = MLX5_MPESW_PORT_INVALID;
2714 : 0 : list[ns].ifindex = mlx5_nl_ifindex(nl_rdma,
2715 : : ibv_match[0]->name,
2716 : : i, &cdev->dev_info);
2717 [ # # ]: 0 : if (!list[ns].ifindex) {
2718 : : /*
2719 : : * No network interface index found for the
2720 : : * specified port, it means there is no
2721 : : * representor on this port. It's OK,
2722 : : * there can be disabled ports, for example
2723 : : * if sriov_numvfs < sriov_totalvfs.
2724 : : */
2725 : 0 : continue;
2726 : : }
2727 : 0 : ret = -1;
2728 [ # # ]: 0 : if (nl_route >= 0)
2729 : 0 : ret = mlx5_nl_switch_info(nl_route,
2730 : : list[ns].ifindex,
2731 : : &list[ns].info);
2732 [ # # # # ]: 0 : if (ret || (!list[ns].info.representor &&
2733 : : !list[ns].info.master)) {
2734 : : /*
2735 : : * We failed to recognize representors with
2736 : : * Netlink, let's try to perform the task
2737 : : * with sysfs.
2738 : : */
2739 : 0 : ret = mlx5_sysfs_switch_info(list[ns].ifindex,
2740 : : &list[ns].info);
2741 : : }
2742 [ # # # # ]: 0 : if (!ret && bd >= 0) {
2743 [ # # # ]: 0 : switch (list[ns].info.name_type) {
2744 : 0 : case MLX5_PHYS_PORT_NAME_TYPE_UPLINK:
2745 [ # # ]: 0 : if (np == 1) {
2746 : : /*
2747 : : * Force standalone bonding
2748 : : * device for ROCE LAG
2749 : : * configurations.
2750 : : */
2751 : 0 : list[ns].info.master = 0;
2752 : 0 : list[ns].info.representor = 0;
2753 : : }
2754 : 0 : ns++;
2755 : 0 : break;
2756 : 0 : case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
2757 : : /* Fallthrough */
2758 : : case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
2759 : : /* Fallthrough */
2760 : : case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
2761 [ # # ]: 0 : if (list[ns].info.pf_num == bd)
2762 : 0 : ns++;
2763 : : break;
2764 : : default:
2765 : : break;
2766 : : }
2767 : 0 : continue;
2768 : : }
2769 [ # # # # ]: 0 : if (!ret && mpesw >= 0) {
2770 [ # # # ]: 0 : switch (list[ns].info.name_type) {
2771 : 0 : case MLX5_PHYS_PORT_NAME_TYPE_UPLINK:
2772 : : /* Owner port is treated as master port. */
2773 [ # # ]: 0 : if (list[ns].info.port_name == mpesw) {
2774 : 0 : list[ns].info.master = 1;
2775 : 0 : list[ns].info.representor = 0;
2776 : : } else {
2777 : 0 : list[ns].info.master = 0;
2778 : 0 : list[ns].info.representor = 1;
2779 : : }
2780 : : /*
2781 : : * Ports of this type have uplink port index
2782 : : * encoded in the name. This index is also a PF index.
2783 : : */
2784 : 0 : list[ns].info.pf_num = list[ns].info.port_name;
2785 : 0 : list[ns].mpesw_port = list[ns].info.port_name;
2786 : 0 : list[ns].info.mpesw_owner = mpesw;
2787 : 0 : ns++;
2788 : 0 : break;
2789 : 0 : case MLX5_PHYS_PORT_NAME_TYPE_PFHPF:
2790 : : case MLX5_PHYS_PORT_NAME_TYPE_PFVF:
2791 : : case MLX5_PHYS_PORT_NAME_TYPE_PFSF:
2792 : : /*
2793 : : * Ports of this type have PF index encoded in name,
2794 : : * which translate to the related uplink port index.
2795 : : */
2796 : 0 : list[ns].mpesw_port = list[ns].info.pf_num;
2797 : : /* MPESW owner is also saved but not used now. */
2798 : 0 : list[ns].info.mpesw_owner = mpesw;
2799 : 0 : ns++;
2800 : 0 : break;
2801 : : default:
2802 : : break;
2803 : : }
2804 : 0 : continue;
2805 : : }
2806 [ # # ]: 0 : if (!ret && (list[ns].info.representor ^
2807 [ # # ]: 0 : list[ns].info.master))
2808 : 0 : ns++;
2809 : : }
2810 : : } else {
2811 : : /*
2812 : : * The existence of several matching entries (nd > 1) means
2813 : : * port representors have been instantiated. No existing Verbs
2814 : : * call nor sysfs entries can tell them apart, this can only
2815 : : * be done through Netlink calls assuming kernel drivers are
2816 : : * recent enough to support them.
2817 : : *
2818 : : * In the event of identification failure through Netlink,
2819 : : * try again through sysfs, then:
2820 : : *
2821 : : * 1. A single IB device matches (nd == 1) with single
2822 : : * port (np=0/1) and is not a representor, assume
2823 : : * no switch support.
2824 : : *
2825 : : * 2. Otherwise no safe assumptions can be made;
2826 : : * complain louder and bail out.
2827 : : */
2828 [ # # ]: 0 : for (i = 0; i != nd; ++i) {
2829 [ # # ]: 0 : memset(&list[ns].info, 0, sizeof(list[ns].info));
2830 : 0 : list[ns].bond_info = NULL;
2831 : 0 : list[ns].max_port = 1;
2832 : 0 : list[ns].phys_port = 1;
2833 : 0 : list[ns].phys_dev_name = ibv_match[i]->name;
2834 : 0 : list[ns].eth_dev = NULL;
2835 : 0 : list[ns].pci_dev = pci_dev;
2836 : 0 : list[ns].cdev = cdev;
2837 : 0 : list[ns].pf_bond = -1;
2838 : 0 : list[ns].mpesw_port = MLX5_MPESW_PORT_INVALID;
2839 : 0 : list[ns].ifindex = 0;
2840 [ # # ]: 0 : if (nl_rdma >= 0)
2841 : 0 : list[ns].ifindex = mlx5_nl_ifindex
2842 : : (nl_rdma,
2843 : : ibv_match[i]->name,
2844 : : 1, &cdev->dev_info);
2845 [ # # ]: 0 : if (!list[ns].ifindex) {
2846 : : char ifname[IF_NAMESIZE];
2847 : :
2848 : : /*
2849 : : * Netlink failed, it may happen with old
2850 : : * ib_core kernel driver (before 4.16).
2851 : : * We can assume there is old driver because
2852 : : * here we are processing single ports IB
2853 : : * devices. Let's try sysfs to retrieve
2854 : : * the ifindex. The method works for
2855 : : * master device only.
2856 : : */
2857 [ # # ]: 0 : if (nd > 1) {
2858 : : /*
2859 : : * Multiple devices found, assume
2860 : : * representors, can not distinguish
2861 : : * master/representor and retrieve
2862 : : * ifindex via sysfs.
2863 : : */
2864 : 0 : continue;
2865 : : }
2866 : 0 : ret = mlx5_get_ifname_sysfs
2867 : 0 : (ibv_match[i]->ibdev_path, ifname);
2868 [ # # ]: 0 : if (!ret)
2869 : 0 : list[ns].ifindex =
2870 : 0 : if_nametoindex(ifname);
2871 [ # # ]: 0 : if (!list[ns].ifindex) {
2872 : : /*
2873 : : * No network interface index found
2874 : : * for the specified device, it means
2875 : : * there it is neither representor
2876 : : * nor master.
2877 : : */
2878 : 0 : continue;
2879 : : }
2880 : : }
2881 : 0 : ret = -1;
2882 [ # # ]: 0 : if (nl_route >= 0)
2883 : 0 : ret = mlx5_nl_switch_info(nl_route,
2884 : : list[ns].ifindex,
2885 : : &list[ns].info);
2886 [ # # # # ]: 0 : if (ret || (!list[ns].info.representor &&
2887 : : !list[ns].info.master)) {
2888 : : /*
2889 : : * We failed to recognize representors with
2890 : : * Netlink, let's try to perform the task
2891 : : * with sysfs.
2892 : : */
2893 : 0 : ret = mlx5_sysfs_switch_info(list[ns].ifindex,
2894 : : &list[ns].info);
2895 : : }
2896 [ # # ]: 0 : if (!ret && (list[ns].info.representor ^
2897 [ # # ]: 0 : list[ns].info.master)) {
2898 : 0 : ns++;
2899 [ # # ]: 0 : } else if ((nd == 1) &&
2900 [ # # ]: 0 : !list[ns].info.representor &&
2901 : : !list[ns].info.master) {
2902 : : /*
2903 : : * Single IB device with one physical port and
2904 : : * attached network device.
2905 : : * May be SRIOV is not enabled or there is no
2906 : : * representors.
2907 : : */
2908 : 0 : DRV_LOG(INFO, "No E-Switch support detected.");
2909 : 0 : ns++;
2910 : 0 : break;
2911 : : }
2912 : : }
2913 [ # # ]: 0 : if (!ns) {
2914 : 0 : DRV_LOG(ERR,
2915 : : "Unable to recognize master/representors on the multiple IB devices.");
2916 : 0 : rte_errno = ENOENT;
2917 : 0 : ret = -rte_errno;
2918 : 0 : goto exit;
2919 : : }
2920 : : /*
2921 : : * New kernels may add the switch_id attribute for the case
2922 : : * there is no E-Switch and we wrongly recognized the only
2923 : : * device as master. Override this if there is the single
2924 : : * device with single port and new device name format present.
2925 : : */
2926 [ # # ]: 0 : if (nd == 1 &&
2927 [ # # ]: 0 : list[0].info.name_type == MLX5_PHYS_PORT_NAME_TYPE_UPLINK) {
2928 : 0 : list[0].info.master = 0;
2929 : 0 : list[0].info.representor = 0;
2930 : : }
2931 : : }
2932 : : MLX5_ASSERT(ns);
2933 : : /* Calculate number of uplinks and host PFs for each matched IB device. */
2934 : 0 : calc_nb_uplinks_hpfs(ibv_match, nd, list, ns);
2935 : : /*
2936 : : * Sort list to probe devices in natural order for users convenience
2937 : : * (i.e. master first, then representors from lowest to highest ID).
2938 : : */
2939 : 0 : qsort(list, ns, sizeof(*list), mlx5_dev_spawn_data_cmp);
2940 [ # # ]: 0 : if (eth_da.type != RTE_ETH_REPRESENTOR_NONE) {
2941 : : /* Set devargs default values. */
2942 [ # # # # ]: 0 : if (eth_da.nb_ports == 0 && ns > 0) {
2943 [ # # # # ]: 0 : if (list[0].pf_bond >= 0 && list[0].info.representor)
2944 : 0 : DRV_LOG(WARNING, "Representor on Bonding device should use pf#vf# syntax: %s",
2945 : : pci_dev->device.devargs->args);
2946 : 0 : eth_da.nb_ports = 1;
2947 : 0 : eth_da.ports[0] = list[0].info.port_name;
2948 : : }
2949 [ # # ]: 0 : if (eth_da.nb_representor_ports == 0) {
2950 : 0 : eth_da.nb_representor_ports = 1;
2951 : 0 : eth_da.representor_ports[0] = 0;
2952 : : }
2953 : : }
2954 [ # # ]: 0 : for (i = 0; i != ns; ++i) {
2955 : : uint32_t restore;
2956 : :
2957 : 0 : list[i].eth_dev = mlx5_dev_spawn(cdev->dev, &list[i], ð_da,
2958 : : mkvlist);
2959 [ # # ]: 0 : if (!list[i].eth_dev) {
2960 [ # # ]: 0 : if (rte_errno != EBUSY && rte_errno != EEXIST)
2961 : : break;
2962 : : /* Device is disabled or already spawned. Ignore it. */
2963 : 0 : continue;
2964 : : }
2965 : 0 : restore = list[i].eth_dev->data->dev_flags;
2966 : 0 : rte_eth_copy_pci_info(list[i].eth_dev, pci_dev);
2967 : : /**
2968 : : * Each representor has a dedicated interrupts vector.
2969 : : * rte_eth_copy_pci_info() assigns PF interrupts handle to
2970 : : * representor eth_dev object because representor and PF
2971 : : * share the same PCI address.
2972 : : * Override representor device with a dedicated
2973 : : * interrupts handle here.
2974 : : * Representor interrupts handle is released in mlx5_dev_stop().
2975 : : */
2976 [ # # ]: 0 : if (list[i].info.representor) {
2977 : : struct rte_intr_handle *intr_handle =
2978 : 0 : rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_SHARED);
2979 [ # # ]: 0 : if (intr_handle == NULL) {
2980 : 0 : DRV_LOG(ERR,
2981 : : "port %u failed to allocate memory for interrupt handler "
2982 : : "Rx interrupts will not be supported",
2983 : : i);
2984 : 0 : rte_errno = ENOMEM;
2985 : 0 : ret = -rte_errno;
2986 : 0 : goto exit;
2987 : : }
2988 : 0 : list[i].eth_dev->intr_handle = intr_handle;
2989 : : }
2990 : : /* Restore non-PCI flags cleared by the above call. */
2991 : 0 : list[i].eth_dev->data->dev_flags |= restore;
2992 : 0 : rte_eth_dev_probing_finish(list[i].eth_dev);
2993 : : }
2994 [ # # ]: 0 : if (i != ns) {
2995 : 0 : DRV_LOG(ERR,
2996 : : "probe of PCI device " PCI_PRI_FMT " aborted after"
2997 : : " encountering an error: %s",
2998 : : owner_pci.domain, owner_pci.bus,
2999 : : owner_pci.devid, owner_pci.function,
3000 : : strerror(rte_errno));
3001 : 0 : ret = -rte_errno;
3002 : : /* Roll back. */
3003 [ # # ]: 0 : while (i--) {
3004 [ # # ]: 0 : if (!list[i].eth_dev)
3005 : 0 : continue;
3006 : 0 : mlx5_dev_close(list[i].eth_dev);
3007 : 0 : claim_zero(rte_eth_dev_release_port(list[i].eth_dev));
3008 : : }
3009 : : /* Restore original error. */
3010 : 0 : rte_errno = -ret;
3011 : : } else {
3012 : 0 : ret = 0;
3013 : : }
3014 : 0 : exit:
3015 : : /*
3016 : : * Do the routine cleanup:
3017 : : * - close opened Netlink sockets
3018 : : * - free allocated spawn data array
3019 : : * - free the Infiniband device list
3020 : : */
3021 [ # # ]: 0 : if (nl_rdma >= 0)
3022 : 0 : close(nl_rdma);
3023 [ # # ]: 0 : if (nl_route >= 0)
3024 : 0 : close(nl_route);
3025 [ # # ]: 0 : if (list)
3026 : 0 : mlx5_free(list);
3027 : : MLX5_ASSERT(ibv_list);
3028 : 0 : mlx5_glue->free_device_list(ibv_list);
3029 [ # # ]: 0 : if (ret) {
3030 [ # # ]: 0 : if (cdev->dev_info.port_info != NULL)
3031 : 0 : mlx5_free(cdev->dev_info.port_info);
3032 : 0 : memset(&cdev->dev_info, 0, sizeof(cdev->dev_info));
3033 : : }
3034 : 0 : return ret;
3035 : : }
3036 : :
3037 : : static int
3038 : 0 : mlx5_os_parse_eth_devargs(struct rte_device *dev,
3039 : : struct rte_eth_devargs *eth_da)
3040 : : {
3041 : : int ret = 0;
3042 : :
3043 [ # # ]: 0 : if (dev->devargs == NULL)
3044 : : return 0;
3045 : : memset(eth_da, 0, sizeof(*eth_da));
3046 : : /* Parse representor information first from class argument. */
3047 [ # # ]: 0 : if (dev->devargs->cls_str)
3048 : 0 : ret = rte_eth_devargs_parse(dev->devargs->cls_str, eth_da, 1);
3049 [ # # ]: 0 : if (ret < 0) {
3050 : 0 : DRV_LOG(ERR, "failed to parse device arguments: %s",
3051 : : dev->devargs->cls_str);
3052 : 0 : return -rte_errno;
3053 : : }
3054 [ # # # # ]: 0 : if (eth_da->type == RTE_ETH_REPRESENTOR_NONE && dev->devargs->args) {
3055 : : /* Parse legacy device argument */
3056 : 0 : ret = rte_eth_devargs_parse(dev->devargs->args, eth_da, 1);
3057 [ # # ]: 0 : if (ret < 0) {
3058 : 0 : DRV_LOG(ERR, "failed to parse device arguments: %s",
3059 : : dev->devargs->args);
3060 : 0 : return -rte_errno;
3061 : : }
3062 : : }
3063 : : return 0;
3064 : : }
3065 : :
3066 : : /**
3067 : : * Callback to register a PCI device.
3068 : : *
3069 : : * This function spawns Ethernet devices out of a given PCI device.
3070 : : *
3071 : : * @param[in] cdev
3072 : : * Pointer to common mlx5 device structure.
3073 : : * @param[in, out] mkvlist
3074 : : * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
3075 : : *
3076 : : * @return
3077 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3078 : : */
3079 : : static int
3080 : 0 : mlx5_os_pci_probe(struct mlx5_common_device *cdev,
3081 : : struct mlx5_kvargs_ctrl *mkvlist)
3082 : : {
3083 : 0 : struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(cdev->dev, *pci_dev);
3084 : 0 : struct rte_eth_devargs eth_da = { .nb_ports = 0 };
3085 : : int ret = 0;
3086 : : uint16_t p;
3087 : :
3088 : 0 : ret = mlx5_os_parse_eth_devargs(cdev->dev, ð_da);
3089 [ # # ]: 0 : if (ret != 0)
3090 : : return ret;
3091 : :
3092 [ # # ]: 0 : if (eth_da.nb_ports > 0) {
3093 : : /* Iterate all port if devargs pf is range: "pf[0-1]vf[...]". */
3094 [ # # ]: 0 : for (p = 0; p < eth_da.nb_ports; p++) {
3095 : 0 : ret = mlx5_os_pci_probe_pf(cdev, ð_da,
3096 : 0 : eth_da.ports[p], mkvlist);
3097 [ # # ]: 0 : if (ret) {
3098 : 0 : DRV_LOG(INFO, "Probe of PCI device " PCI_PRI_FMT " "
3099 : : "aborted due to proding failure of PF %u",
3100 : : pci_dev->addr.domain, pci_dev->addr.bus,
3101 : : pci_dev->addr.devid, pci_dev->addr.function,
3102 : : eth_da.ports[p]);
3103 : 0 : mlx5_net_remove(cdev);
3104 [ # # ]: 0 : if (p != 0)
3105 : : break;
3106 : : }
3107 : : }
3108 : : } else {
3109 : 0 : ret = mlx5_os_pci_probe_pf(cdev, ð_da, 0, mkvlist);
3110 : : }
3111 : : return ret;
3112 : : }
3113 : :
3114 : : /* Probe a single SF device on auxiliary bus, no representor support. */
3115 : : static int
3116 : 0 : mlx5_os_auxiliary_probe(struct mlx5_common_device *cdev,
3117 : : struct mlx5_kvargs_ctrl *mkvlist)
3118 : : {
3119 : 0 : struct rte_eth_devargs eth_da = { .nb_ports = 0 };
3120 : 0 : struct mlx5_dev_spawn_data spawn = {
3121 : : .pf_bond = -1,
3122 : : .mpesw_port = MLX5_MPESW_PORT_INVALID,
3123 : : };
3124 : 0 : struct rte_device *dev = cdev->dev;
3125 : : struct rte_auxiliary_device *adev = RTE_BUS_DEVICE(dev, *adev);
3126 : : struct rte_eth_dev *eth_dev;
3127 : : int ret = 0;
3128 : :
3129 : : /* Parse ethdev devargs. */
3130 : 0 : ret = mlx5_os_parse_eth_devargs(dev, ð_da);
3131 [ # # ]: 0 : if (ret != 0)
3132 : : return ret;
3133 : : /* Init spawn data. */
3134 : 0 : spawn.max_port = 1;
3135 : 0 : spawn.phys_port = 1;
3136 [ # # ]: 0 : spawn.phys_dev_name = mlx5_os_get_ctx_device_name(cdev->ctx);
3137 : 0 : ret = mlx5_auxiliary_get_ifindex(dev->name);
3138 [ # # ]: 0 : if (ret < 0) {
3139 : 0 : DRV_LOG(ERR, "failed to get ethdev ifindex: %s", dev->name);
3140 : 0 : return ret;
3141 : : }
3142 : 0 : spawn.ifindex = ret;
3143 : 0 : spawn.cdev = cdev;
3144 : : /* Spawn device. */
3145 : 0 : eth_dev = mlx5_dev_spawn(dev, &spawn, ð_da, mkvlist);
3146 [ # # ]: 0 : if (eth_dev == NULL)
3147 : 0 : return -rte_errno;
3148 : : /* Post create. */
3149 : 0 : eth_dev->intr_handle = adev->intr_handle;
3150 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3151 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
3152 : 0 : eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_RMV;
3153 : 0 : eth_dev->data->numa_node = dev->numa_node;
3154 : : }
3155 : 0 : rte_eth_dev_probing_finish(eth_dev);
3156 : 0 : return 0;
3157 : : }
3158 : :
3159 : : /**
3160 : : * Net class driver callback to probe a device.
3161 : : *
3162 : : * This function probe PCI bus device(s) or a single SF on auxiliary bus.
3163 : : *
3164 : : * @param[in] cdev
3165 : : * Pointer to the common mlx5 device.
3166 : : * @param[in, out] mkvlist
3167 : : * Pointer to mlx5 kvargs control, can be NULL if there is no devargs.
3168 : : *
3169 : : * @return
3170 : : * 0 on success, a negative errno value otherwise and rte_errno is set.
3171 : : */
3172 : : int
3173 : 0 : mlx5_os_net_probe(struct mlx5_common_device *cdev,
3174 : : struct mlx5_kvargs_ctrl *mkvlist)
3175 : : {
3176 : : int ret;
3177 : :
3178 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3179 : 0 : mlx5_pmd_socket_init();
3180 : 0 : ret = mlx5_init_once();
3181 [ # # ]: 0 : if (ret) {
3182 : 0 : DRV_LOG(ERR, "Unable to init PMD global data: %s",
3183 : : strerror(rte_errno));
3184 : 0 : return -rte_errno;
3185 : : }
3186 : 0 : ret = mlx5_probe_again_args_validate(cdev, mkvlist);
3187 [ # # ]: 0 : if (ret) {
3188 : 0 : DRV_LOG(ERR, "Probe again parameters are not compatible : %s",
3189 : : strerror(rte_errno));
3190 : 0 : return -rte_errno;
3191 : : }
3192 [ # # ]: 0 : if (mlx5_dev_is_pci(cdev->dev))
3193 : 0 : return mlx5_os_pci_probe(cdev, mkvlist);
3194 : : else
3195 : 0 : return mlx5_os_auxiliary_probe(cdev, mkvlist);
3196 : : }
3197 : :
3198 : : /**
3199 : : * Cleanup resources when the last device is closed.
3200 : : */
3201 : : void
3202 : 0 : mlx5_os_net_cleanup(void)
3203 : : {
3204 : 0 : mlx5_pmd_socket_uninit();
3205 : 0 : }
3206 : :
3207 : : /**
3208 : : * Install shared asynchronous device events handler.
3209 : : * This function is implemented to support event sharing
3210 : : * between multiple ports of single IB device.
3211 : : *
3212 : : * @param sh
3213 : : * Pointer to mlx5_dev_ctx_shared object.
3214 : : */
3215 : : void
3216 : 0 : mlx5_os_dev_shared_handler_install(struct mlx5_dev_ctx_shared *sh)
3217 : : {
3218 : 0 : struct ibv_context *ctx = sh->cdev->ctx;
3219 : : int nlsk_fd;
3220 : 0 : uint8_t rdma_monitor_supp = 0;
3221 : :
3222 : 0 : sh->intr_handle = mlx5_os_interrupt_handler_create
3223 : : (RTE_INTR_INSTANCE_F_SHARED, true,
3224 : : ctx->async_fd, mlx5_dev_interrupt_handler, sh);
3225 [ # # ]: 0 : if (!sh->intr_handle) {
3226 : 0 : DRV_LOG(ERR, "Failed to allocate intr_handle.");
3227 : 0 : return;
3228 : : }
3229 [ # # ]: 0 : if (sh->cdev->dev_info.probe_opt &&
3230 [ # # ]: 0 : sh->cdev->dev_info.port_num > 1 &&
3231 [ # # ]: 0 : !sh->rdma_monitor_supp) {
3232 : 0 : nlsk_fd = mlx5_nl_rdma_monitor_init();
3233 [ # # ]: 0 : if (nlsk_fd < 0) {
3234 : 0 : DRV_LOG(ERR, "Failed to create a socket for RDMA Netlink events: %s",
3235 : : rte_strerror(rte_errno));
3236 : 0 : return;
3237 : : }
3238 [ # # ]: 0 : if (mlx5_nl_rdma_monitor_cap_get(nlsk_fd, &rdma_monitor_supp)) {
3239 : 0 : DRV_LOG(ERR, "Failed to query RDMA monitor support: %s",
3240 : : rte_strerror(rte_errno));
3241 : 0 : close(nlsk_fd);
3242 : 0 : return;
3243 : : }
3244 : 0 : sh->rdma_monitor_supp = rdma_monitor_supp;
3245 [ # # ]: 0 : if (sh->rdma_monitor_supp) {
3246 : 0 : sh->intr_handle_ib = mlx5_os_interrupt_handler_create
3247 : : (RTE_INTR_INSTANCE_F_SHARED, true,
3248 : : nlsk_fd, mlx5_dev_interrupt_handler_ib, sh);
3249 [ # # ]: 0 : if (sh->intr_handle_ib == NULL) {
3250 : 0 : DRV_LOG(ERR, "Fail to allocate intr_handle");
3251 : 0 : close(nlsk_fd);
3252 : 0 : return;
3253 : : }
3254 : 0 : sh->cdev->dev_info.async_mon_ready = 1;
3255 : : } else {
3256 : 0 : close(nlsk_fd);
3257 [ # # ]: 0 : if (sh->cdev->dev_info.probe_opt) {
3258 : 0 : DRV_LOG(INFO, "Failed to create rdma link monitor, disable probe optimization");
3259 : 0 : sh->cdev->dev_info.probe_opt = 0;
3260 : 0 : mlx5_free(sh->cdev->dev_info.port_info);
3261 : 0 : sh->cdev->dev_info.port_info = NULL;
3262 : : }
3263 : : }
3264 : : }
3265 : 0 : nlsk_fd = mlx5_nl_init(NETLINK_ROUTE, RTMGRP_LINK);
3266 [ # # ]: 0 : if (nlsk_fd < 0) {
3267 : 0 : DRV_LOG(ERR, "Failed to create a socket for Netlink events: %s",
3268 : : rte_strerror(rte_errno));
3269 : 0 : return;
3270 : : }
3271 : 0 : sh->intr_handle_nl = mlx5_os_interrupt_handler_create
3272 : : (RTE_INTR_INSTANCE_F_SHARED, true,
3273 : : nlsk_fd, mlx5_dev_interrupt_handler_nl, sh);
3274 [ # # ]: 0 : if (sh->intr_handle_nl == NULL) {
3275 : 0 : DRV_LOG(ERR, "Fail to allocate intr_handle");
3276 : 0 : return;
3277 : : }
3278 [ # # ]: 0 : if (sh->cdev->config.devx) {
3279 : : #ifdef HAVE_IBV_DEVX_ASYNC
3280 : : struct mlx5dv_devx_cmd_comp *devx_comp;
3281 : :
3282 : 0 : sh->devx_comp = (void *)mlx5_glue->devx_create_cmd_comp(ctx);
3283 : : devx_comp = sh->devx_comp;
3284 [ # # ]: 0 : if (!devx_comp) {
3285 : 0 : DRV_LOG(INFO, "failed to allocate devx_comp.");
3286 : 0 : return;
3287 : : }
3288 : 0 : sh->intr_handle_devx = mlx5_os_interrupt_handler_create
3289 : : (RTE_INTR_INSTANCE_F_SHARED, true,
3290 : : devx_comp->fd,
3291 : : mlx5_dev_interrupt_handler_devx, sh);
3292 [ # # ]: 0 : if (!sh->intr_handle_devx) {
3293 : 0 : DRV_LOG(ERR, "Failed to allocate intr_handle.");
3294 : 0 : return;
3295 : : }
3296 : : #endif /* HAVE_IBV_DEVX_ASYNC */
3297 : : }
3298 : : }
3299 : :
3300 : : /**
3301 : : * Uninstall shared asynchronous device events handler.
3302 : : * This function is implemented to support event sharing
3303 : : * between multiple ports of single IB device.
3304 : : *
3305 : : * @param dev
3306 : : * Pointer to mlx5_dev_ctx_shared object.
3307 : : */
3308 : : void
3309 : 0 : mlx5_os_dev_shared_handler_uninstall(struct mlx5_dev_ctx_shared *sh)
3310 : : {
3311 : : int fd;
3312 : :
3313 : 0 : mlx5_os_interrupt_handler_destroy(sh->intr_handle,
3314 : : mlx5_dev_interrupt_handler, sh);
3315 : 0 : fd = rte_intr_fd_get(sh->intr_handle_nl);
3316 : 0 : mlx5_os_interrupt_handler_destroy(sh->intr_handle_nl,
3317 : : mlx5_dev_interrupt_handler_nl, sh);
3318 [ # # ]: 0 : if (fd >= 0)
3319 : 0 : close(fd);
3320 : : #ifdef HAVE_IBV_DEVX_ASYNC
3321 : 0 : mlx5_os_interrupt_handler_destroy(sh->intr_handle_devx,
3322 : : mlx5_dev_interrupt_handler_devx, sh);
3323 [ # # ]: 0 : if (sh->devx_comp)
3324 : 0 : mlx5_glue->devx_destroy_cmd_comp(sh->devx_comp);
3325 : : #endif
3326 : 0 : fd = rte_intr_fd_get(sh->intr_handle_ib);
3327 : 0 : mlx5_os_interrupt_handler_destroy(sh->intr_handle_ib,
3328 : : mlx5_dev_interrupt_handler_ib, sh);
3329 [ # # ]: 0 : if (fd >= 0)
3330 : 0 : close(fd);
3331 : 0 : }
3332 : :
3333 : : /**
3334 : : * Read statistics by a named counter.
3335 : : *
3336 : : * @param[in] priv
3337 : : * Pointer to the private device data structure.
3338 : : * @param[in] ctr_name
3339 : : * Pointer to the name of the statistic counter to read
3340 : : * @param[out] stat
3341 : : * Pointer to read statistic value.
3342 : : * @return
3343 : : * 0 on success and stat is valud, 1 if failed to read the value
3344 : : * rte_errno is set.
3345 : : *
3346 : : */
3347 : : int
3348 : 0 : mlx5_os_read_dev_stat(struct mlx5_priv *priv, const char *ctr_name,
3349 : : uint64_t *stat)
3350 : : {
3351 : : int fd;
3352 : :
3353 [ # # ]: 0 : if (priv->sh) {
3354 [ # # ]: 0 : if (priv->q_counters != NULL &&
3355 [ # # ]: 0 : strcmp(ctr_name, "out_of_buffer") == 0) {
3356 : 0 : return mlx5_read_queue_counter(priv->q_counters, ctr_name, stat);
3357 : : }
3358 [ # # ]: 0 : if (priv->q_counter_hairpin != NULL &&
3359 [ # # ]: 0 : strcmp(ctr_name, "hairpin_out_of_buffer") == 0) {
3360 : 0 : return mlx5_read_queue_counter(priv->q_counter_hairpin, ctr_name, stat);
3361 : : }
3362 : 0 : MKSTR(path, "%s/ports/%d/hw_counters/%s",
3363 : : priv->sh->ibdev_path,
3364 : : priv->dev_port,
3365 : : ctr_name);
3366 : : fd = open(path, O_RDONLY);
3367 : : /*
3368 : : * in switchdev the file location is not per port
3369 : : * but rather in <ibdev_path>/hw_counters/<file_name>.
3370 : : */
3371 [ # # ]: 0 : if (fd == -1) {
3372 : 0 : MKSTR(path1, "%s/hw_counters/%s",
3373 : : priv->sh->ibdev_path,
3374 : : ctr_name);
3375 : : fd = open(path1, O_RDONLY);
3376 : : }
3377 [ # # ]: 0 : if (fd != -1) {
3378 : 0 : char buf[21] = {'\0'};
3379 : : ssize_t n = read(fd, buf, sizeof(buf));
3380 : :
3381 : 0 : close(fd);
3382 [ # # ]: 0 : if (n != -1) {
3383 : 0 : *stat = strtoull(buf, NULL, 10);
3384 : 0 : return 0;
3385 : : }
3386 : : }
3387 : : }
3388 : 0 : *stat = 0;
3389 : 0 : return 1;
3390 : : }
3391 : :
3392 : : /**
3393 : : * Remove a MAC address from device
3394 : : *
3395 : : * @param dev
3396 : : * Pointer to Ethernet device structure.
3397 : : * @param index
3398 : : * MAC address index.
3399 : : */
3400 : : void
3401 : 0 : mlx5_os_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
3402 : : {
3403 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3404 : 0 : const int vf = priv->sh->dev_cap.vf;
3405 : :
3406 [ # # ]: 0 : if (vf)
3407 : 0 : mlx5_nl_mac_addr_remove(priv->nl_socket_route,
3408 : : mlx5_ifindex(dev),
3409 : 0 : &dev->data->mac_addrs[index]);
3410 : 0 : rte_bitset_clear(priv->mac_own, index);
3411 : 0 : }
3412 : :
3413 : : /**
3414 : : * Adds a MAC address to the device
3415 : : *
3416 : : * @param dev
3417 : : * Pointer to Ethernet device structure.
3418 : : * @param mac_addr
3419 : : * MAC address to register.
3420 : : * @param index
3421 : : * MAC address index.
3422 : : *
3423 : : * @return
3424 : : * 0 on success, a negative errno value otherwise
3425 : : */
3426 : : int
3427 : 0 : mlx5_os_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac,
3428 : : uint32_t index)
3429 : : {
3430 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3431 : 0 : const int vf = priv->sh->dev_cap.vf;
3432 : : int ret = 0;
3433 : :
3434 [ # # ]: 0 : if (vf)
3435 : 0 : ret = mlx5_nl_mac_addr_add(priv->nl_socket_route,
3436 : : mlx5_ifindex(dev),
3437 : : mac);
3438 [ # # ]: 0 : if (!ret)
3439 : 0 : rte_bitset_set(priv->mac_own, index);
3440 : :
3441 : 0 : return ret;
3442 : : }
3443 : :
3444 : : /**
3445 : : * Modify a VF MAC address
3446 : : *
3447 : : * @param priv
3448 : : * Pointer to device private data.
3449 : : * @param mac_addr
3450 : : * MAC address to modify into.
3451 : : * @param iface_idx
3452 : : * Net device interface index
3453 : : * @param vf_index
3454 : : * VF index
3455 : : *
3456 : : * @return
3457 : : * 0 on success, a negative errno value otherwise
3458 : : */
3459 : : int
3460 : 0 : mlx5_os_vf_mac_addr_modify(struct mlx5_priv *priv,
3461 : : unsigned int iface_idx,
3462 : : struct rte_ether_addr *mac_addr,
3463 : : int vf_index)
3464 : : {
3465 : 0 : return mlx5_nl_vf_mac_addr_modify
3466 : : (priv->nl_socket_route, iface_idx, mac_addr, vf_index);
3467 : : }
3468 : :
3469 : : /**
3470 : : * Set device promiscuous mode
3471 : : *
3472 : : * @param dev
3473 : : * Pointer to Ethernet device structure.
3474 : : * @param enable
3475 : : * 0 - promiscuous is disabled, otherwise - enabled
3476 : : *
3477 : : * @return
3478 : : * 0 on success, a negative error value otherwise
3479 : : */
3480 : : int
3481 : 0 : mlx5_os_set_promisc(struct rte_eth_dev *dev, int enable)
3482 : : {
3483 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3484 : :
3485 : 0 : return mlx5_nl_promisc(priv->nl_socket_route,
3486 : : mlx5_ifindex(dev), !!enable);
3487 : : }
3488 : :
3489 : : /**
3490 : : * Set device promiscuous mode
3491 : : *
3492 : : * @param dev
3493 : : * Pointer to Ethernet device structure.
3494 : : * @param enable
3495 : : * 0 - all multicase is disabled, otherwise - enabled
3496 : : *
3497 : : * @return
3498 : : * 0 on success, a negative error value otherwise
3499 : : */
3500 : : int
3501 : 0 : mlx5_os_set_allmulti(struct rte_eth_dev *dev, int enable)
3502 : : {
3503 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3504 : :
3505 : 0 : return mlx5_nl_allmulti(priv->nl_socket_route,
3506 : : mlx5_ifindex(dev), !!enable);
3507 : : }
3508 : :
3509 : : /**
3510 : : * Get device promiscuous mode
3511 : : *
3512 : : * @param dev
3513 : : * Pointer to Ethernet device structure.
3514 : : *
3515 : : * @return
3516 : : * True if promiscuous mode is enabled, false otherwise.
3517 : : */
3518 : : bool
3519 : 0 : mlx5_os_get_promisc(struct rte_eth_dev *dev)
3520 : : {
3521 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3522 : :
3523 : 0 : return mlx5_nl_get_promisc(priv->nl_socket_route, mlx5_ifindex(dev));
3524 : : }
3525 : :
3526 : : /**
3527 : : * Get device all multicast mode
3528 : : *
3529 : : * @param dev
3530 : : * Pointer to Ethernet device structure.
3531 : : *
3532 : : * @return
3533 : : * True if all multicast mode is enabled, false otherwise.
3534 : : */
3535 : : bool
3536 : 0 : mlx5_os_get_allmulti(struct rte_eth_dev *dev)
3537 : : {
3538 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3539 : :
3540 : 0 : return mlx5_nl_get_allmulti(priv->nl_socket_route, mlx5_ifindex(dev));
3541 : : }
3542 : :
3543 : : /**
3544 : : * Flush device MAC addresses
3545 : : *
3546 : : * @param dev
3547 : : * Pointer to Ethernet device structure.
3548 : : *
3549 : : */
3550 : : void
3551 : 0 : mlx5_os_mac_addr_flush(struct rte_eth_dev *dev)
3552 : : {
3553 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3554 : 0 : const int vf = priv->sh->dev_cap.vf;
3555 : : int i;
3556 : :
3557 [ # # ]: 0 : for (i = priv->sh->dev_cap.max_mac_addrs - 1; i >= 0; --i) {
3558 [ # # ]: 0 : if (rte_bitset_test(priv->mac_own, i)) {
3559 [ # # ]: 0 : if (vf)
3560 : 0 : mlx5_nl_mac_addr_remove(priv->nl_socket_route,
3561 : : mlx5_ifindex(dev),
3562 : 0 : &dev->data->mac_addrs[i]);
3563 : 0 : rte_bitset_clear(priv->mac_own, i);
3564 : : }
3565 : : }
3566 : 0 : }
3567 : :
3568 : : static bool
3569 : : mlx5_hws_is_supported(struct mlx5_dev_ctx_shared *sh)
3570 : : {
3571 [ # # # # ]: 0 : return (sh->cdev->config.devx &&
3572 : : sh->cdev->config.hca_attr.wqe_based_flow_table_sup);
3573 : : }
3574 : :
3575 : : static bool
3576 : : mlx5_sws_is_any_supported(struct mlx5_dev_ctx_shared *sh)
3577 : : {
3578 : : struct mlx5_common_device *cdev = sh->cdev;
3579 : : struct mlx5_hca_attr *hca_attr = &cdev->config.hca_attr;
3580 : :
3581 [ # # # # ]: 0 : if (hca_attr->rx_sw_owner_v2 || hca_attr->rx_sw_owner)
3582 : : return true;
3583 : :
3584 [ # # # # ]: 0 : if (hca_attr->tx_sw_owner_v2 || hca_attr->tx_sw_owner)
3585 : : return true;
3586 : :
3587 [ # # # # : 0 : if (hca_attr->eswitch_manager && (hca_attr->esw_sw_owner_v2 || hca_attr->esw_sw_owner))
# # # # ]
3588 : 0 : return true;
3589 : :
3590 : : return false;
3591 : : }
3592 : :
3593 : : /**
3594 : : * Initialize default shared configuration for arguments related to flow engine.
3595 : : *
3596 : : * @param[in] sh
3597 : : * Pointer to shared configuration.
3598 : : * @param[in] sh
3599 : : * Pointer to shared device context.
3600 : : */
3601 : : void
3602 [ # # ]: 0 : mlx5_os_default_flow_config(struct mlx5_sh_config *config, struct mlx5_dev_ctx_shared *sh)
3603 : : {
3604 : : bool hws_is_supported = mlx5_hws_is_supported(sh);
3605 : : bool sws_is_supported = mlx5_sws_is_any_supported(sh);
3606 : :
3607 [ # # ]: 0 : if (!sws_is_supported && hws_is_supported)
3608 : 0 : config->dv_flow_en = 2;
3609 : : else
3610 : 0 : config->dv_flow_en = 1;
3611 : :
3612 [ # # ]: 0 : if (config->dv_flow_en == 2)
3613 : 0 : config->allow_duplicate_pattern = 0;
3614 : : else
3615 : 0 : config->allow_duplicate_pattern = 1;
3616 : 0 : }
3617 : :
3618 : : static bool
3619 : 0 : mlx5_kvargs_is_used(struct mlx5_kvargs_ctrl *mkvlist, const char *key)
3620 : : {
3621 : : const struct rte_kvargs_pair *pair;
3622 : : uint32_t i;
3623 : :
3624 [ # # ]: 0 : for (i = 0; i < mkvlist->kvlist->count; ++i) {
3625 : : pair = &mkvlist->kvlist->pairs[i];
3626 [ # # # # ]: 0 : if (strcmp(pair->key, key) == 0 && mkvlist->is_used[i])
3627 : : return true;
3628 : : }
3629 : : return false;
3630 : : }
3631 : :
3632 [ # # ]: 0 : void mlx5_os_fixup_flow_en(struct mlx5_sh_config *config,
3633 : : struct mlx5_dev_ctx_shared *sh)
3634 : : {
3635 : : bool hws_is_supported = mlx5_hws_is_supported(sh);
3636 : : bool sws_is_supported = mlx5_sws_is_any_supported(sh);
3637 : :
3638 : : /* Inform user if DV flow is not supported. */
3639 [ # # # # ]: 0 : if (config->dv_flow_en == 1 && !sws_is_supported && hws_is_supported) {
3640 : 0 : DRV_LOG(WARNING, "DV flow is not supported. Changing to HWS mode.");
3641 : 0 : config->dv_flow_en = 2;
3642 : : }
3643 : 0 : }
3644 : :
3645 : : void
3646 : 0 : mlx5_os_fixup_duplicate_pattern(struct mlx5_sh_config *config,
3647 : : struct mlx5_kvargs_ctrl *mkvlist,
3648 : : const char *key)
3649 : : {
3650 : : /* Handle allow_duplicate_pattern based on final dv_flow_en mode.
3651 : : * HWS mode (dv_flow_en=2) doesn't support duplicate patterns.
3652 : : * Warn only if user explicitly requested an incompatible setting.
3653 : : */
3654 [ # # # # ]: 0 : bool allow_dup_pattern_set = mkvlist != NULL &&
3655 : 0 : mlx5_kvargs_is_used(mkvlist, key);
3656 [ # # ]: 0 : if (config->dv_flow_en == 2) {
3657 [ # # # # ]: 0 : if (config->allow_duplicate_pattern == 1 && allow_dup_pattern_set)
3658 : 0 : DRV_LOG(WARNING, "Duplicate pattern is not supported with HWS. Disabling it.");
3659 : 0 : config->allow_duplicate_pattern = 0;
3660 [ # # ]: 0 : } else if (!allow_dup_pattern_set) {
3661 : : /* Non-HWS mode: set default to 1 only if not explicitly set by user */
3662 : 0 : config->allow_duplicate_pattern = 1;
3663 : : }
3664 : 0 : }
|