Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : *
3 : : * Copyright(c) 2019-2021 Xilinx, Inc.
4 : : * Copyright(c) 2016-2019 Solarflare Communications Inc.
5 : : *
6 : : * This software was jointly developed between OKTET Labs (under contract
7 : : * for Solarflare) and Solarflare Communications, Inc.
8 : : */
9 : :
10 : : #include <stdbool.h>
11 : :
12 : : #include <dev_driver.h>
13 : : #include <ethdev_driver.h>
14 : : #include <ethdev_pci.h>
15 : : #include <rte_pci.h>
16 : : #include <bus_pci_driver.h>
17 : : #include <rte_errno.h>
18 : : #include <rte_string_fns.h>
19 : : #include <rte_stdatomic.h>
20 : : #include <rte_bitops.h>
21 : : #include <rte_ethdev.h>
22 : : #include <rte_ether.h>
23 : :
24 : : #include "efx.h"
25 : :
26 : : #include "sfc.h"
27 : : #include "sfc_debug.h"
28 : : #include "sfc_log.h"
29 : : #include "sfc_kvargs.h"
30 : : #include "sfc_ev.h"
31 : : #include "sfc_rx.h"
32 : : #include "sfc_tx.h"
33 : : #include "sfc_flow.h"
34 : : #include "sfc_flow_tunnel.h"
35 : : #include "sfc_dp.h"
36 : : #include "sfc_dp_rx.h"
37 : : #include "sfc_repr.h"
38 : : #include "sfc_sw_stats.h"
39 : : #include "sfc_switch.h"
40 : : #include "sfc_nic_dma.h"
41 : :
42 : : #define SFC_XSTAT_ID_INVALID_VAL UINT64_MAX
43 : : #define SFC_XSTAT_ID_INVALID_NAME '\0'
44 : :
45 : : static struct sfc_dp_list sfc_dp_head =
46 : : TAILQ_HEAD_INITIALIZER(sfc_dp_head);
47 : :
48 : :
49 : : static void sfc_eth_dev_clear_ops(struct rte_eth_dev *dev);
50 : :
51 : :
52 : : static int
53 : 0 : sfc_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
54 : : {
55 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
56 : : efx_nic_fw_info_t enfi;
57 : : int ret;
58 : : int rc;
59 : :
60 : 0 : rc = efx_nic_get_fw_version(sa->nic, &enfi);
61 [ # # ]: 0 : if (rc != 0)
62 : 0 : return -rc;
63 : :
64 : 0 : ret = snprintf(fw_version, fw_size,
65 : : "%" PRIu16 ".%" PRIu16 ".%" PRIu16 ".%" PRIu16,
66 : 0 : enfi.enfi_mc_fw_version[0], enfi.enfi_mc_fw_version[1],
67 [ # # ]: 0 : enfi.enfi_mc_fw_version[2], enfi.enfi_mc_fw_version[3]);
68 [ # # ]: 0 : if (ret < 0)
69 : : return ret;
70 : :
71 [ # # ]: 0 : if (enfi.enfi_dpcpu_fw_ids_valid) {
72 : 0 : size_t dpcpu_fw_ids_offset = MIN(fw_size - 1, (size_t)ret);
73 : : int ret_extra;
74 : :
75 : 0 : ret_extra = snprintf(fw_version + dpcpu_fw_ids_offset,
76 : : fw_size - dpcpu_fw_ids_offset,
77 : : " rx%" PRIx16 " tx%" PRIx16,
78 : 0 : enfi.enfi_rx_dpcpu_fw_id,
79 [ # # ]: 0 : enfi.enfi_tx_dpcpu_fw_id);
80 [ # # ]: 0 : if (ret_extra < 0)
81 : : return ret_extra;
82 : :
83 : 0 : ret += ret_extra;
84 : : }
85 : :
86 [ # # ]: 0 : if (fw_size < (size_t)(++ret))
87 : : return ret;
88 : : else
89 : 0 : return 0;
90 : : }
91 : :
92 : : static int
93 : 0 : sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
94 : : {
95 : : const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
96 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
97 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
98 : 0 : const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
99 : : struct sfc_rss *rss = &sas->rss;
100 : : struct sfc_mae *mae = &sa->mae;
101 : :
102 : 0 : sfc_log_init(sa, "entry");
103 : :
104 : 0 : dev_info->min_mtu = RTE_ETHER_MIN_MTU;
105 : 0 : dev_info->max_mtu = EFX_MAC_SDU_MAX;
106 : :
107 : 0 : dev_info->max_rx_pktlen = encp->enc_mac_pdu_max;
108 : :
109 : 0 : dev_info->max_vfs = sa->sriov.num_vfs;
110 : :
111 : : /* Autonegotiation may be disabled */
112 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_FIXED;
113 [ # # ]: 0 : if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_1000FDX))
114 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_1G;
115 [ # # ]: 0 : if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_10000FDX))
116 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_10G;
117 [ # # ]: 0 : if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_25000FDX))
118 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_25G;
119 [ # # ]: 0 : if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_40000FDX))
120 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_40G;
121 [ # # ]: 0 : if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_50000FDX))
122 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_50G;
123 [ # # ]: 0 : if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_100000FDX))
124 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_100G;
125 [ # # ]: 0 : if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_200000FDX))
126 : 0 : dev_info->speed_capa |= RTE_ETH_LINK_SPEED_200G;
127 : :
128 : 0 : dev_info->max_rx_queues = sa->rxq_max;
129 : 0 : dev_info->max_tx_queues = sa->txq_max;
130 : :
131 : : /* By default packets are dropped if no descriptors are available */
132 : 0 : dev_info->default_rxconf.rx_drop_en = 1;
133 : :
134 : 0 : dev_info->rx_queue_offload_capa = sfc_rx_get_queue_offload_caps(sa);
135 : :
136 : : /*
137 : : * rx_offload_capa includes both device and queue offloads since
138 : : * the latter may be requested on a per device basis which makes
139 : : * sense when some offloads are needed to be set on all queues.
140 : : */
141 : 0 : dev_info->rx_offload_capa = sfc_rx_get_dev_offload_caps(sa) |
142 : 0 : dev_info->rx_queue_offload_capa;
143 : :
144 : 0 : dev_info->tx_queue_offload_capa = sfc_tx_get_queue_offload_caps(sa);
145 : :
146 : : /*
147 : : * tx_offload_capa includes both device and queue offloads since
148 : : * the latter may be requested on a per device basis which makes
149 : : * sense when some offloads are needed to be set on all queues.
150 : : */
151 : 0 : dev_info->tx_offload_capa = sfc_tx_get_dev_offload_caps(sa) |
152 : 0 : dev_info->tx_queue_offload_capa;
153 : :
154 [ # # ]: 0 : if (rss->context_type != EFX_RX_SCALE_UNAVAILABLE) {
155 : : uint64_t rte_hf = 0;
156 : : unsigned int i;
157 : :
158 [ # # ]: 0 : for (i = 0; i < rss->hf_map_nb_entries; ++i)
159 : 0 : rte_hf |= rss->hf_map[i].rte;
160 : :
161 : 0 : dev_info->reta_size = EFX_RSS_TBL_SIZE;
162 : 0 : dev_info->hash_key_size = EFX_RSS_KEY_SIZE;
163 : 0 : dev_info->flow_type_rss_offloads = rte_hf;
164 : : }
165 : :
166 : : /* Initialize to hardware limits */
167 : 0 : dev_info->rx_desc_lim.nb_max = sa->rxq_max_entries;
168 : 0 : dev_info->rx_desc_lim.nb_min = sa->rxq_min_entries;
169 : : /* The RXQ hardware requires that the descriptor count is a power
170 : : * of 2, but rx_desc_lim cannot properly describe that constraint.
171 : : */
172 : 0 : dev_info->rx_desc_lim.nb_align = sa->rxq_min_entries;
173 : :
174 : : /* Initialize to hardware limits */
175 : 0 : dev_info->tx_desc_lim.nb_max = sa->txq_max_entries;
176 : 0 : dev_info->tx_desc_lim.nb_min = sa->txq_min_entries;
177 : : /*
178 : : * The TXQ hardware requires that the descriptor count is a power
179 : : * of 2, but tx_desc_lim cannot properly describe that constraint
180 : : */
181 : 0 : dev_info->tx_desc_lim.nb_align = sa->txq_min_entries;
182 : :
183 [ # # ]: 0 : if (sap->dp_rx->get_dev_info != NULL)
184 : 0 : sap->dp_rx->get_dev_info(dev_info);
185 [ # # ]: 0 : if (sap->dp_tx->get_dev_info != NULL)
186 : 0 : sap->dp_tx->get_dev_info(dev_info);
187 : :
188 : 0 : dev_info->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
189 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
190 : : dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
191 : :
192 [ # # ]: 0 : if (mae->status == SFC_MAE_STATUS_SUPPORTED ||
193 : : mae->status == SFC_MAE_STATUS_ADMIN) {
194 : 0 : dev_info->switch_info.name = dev->device->driver->name;
195 : 0 : dev_info->switch_info.domain_id = mae->switch_domain_id;
196 : 0 : dev_info->switch_info.port_id = mae->switch_port_id;
197 : : }
198 : :
199 : 0 : return 0;
200 : : }
201 : :
202 : : static const uint32_t *
203 : 0 : sfc_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
204 : : {
205 : : const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
206 : :
207 : 0 : return sap->dp_rx->supported_ptypes_get(sap->shared->tunnel_encaps,
208 : : no_of_elements);
209 : : }
210 : :
211 : : static int
212 : 0 : sfc_dev_configure(struct rte_eth_dev *dev)
213 : : {
214 : 0 : struct rte_eth_dev_data *dev_data = dev->data;
215 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
216 : : int rc;
217 : :
218 : 0 : sfc_log_init(sa, "entry n_rxq=%u n_txq=%u",
219 : : dev_data->nb_rx_queues, dev_data->nb_tx_queues);
220 : :
221 : 0 : sfc_adapter_lock(sa);
222 [ # # ]: 0 : switch (sa->state) {
223 : 0 : case SFC_ETHDEV_CONFIGURED:
224 : : /* FALLTHROUGH */
225 : : case SFC_ETHDEV_INITIALIZED:
226 : 0 : rc = sfc_configure(sa);
227 : 0 : break;
228 : 0 : default:
229 : 0 : sfc_err(sa, "unexpected adapter state %u to configure",
230 : : sa->state);
231 : : rc = EINVAL;
232 : 0 : break;
233 : : }
234 : : sfc_adapter_unlock(sa);
235 : :
236 : 0 : sfc_log_init(sa, "done %d", rc);
237 : : SFC_ASSERT(rc >= 0);
238 : 0 : return -rc;
239 : : }
240 : :
241 : : static int
242 : 0 : sfc_dev_start(struct rte_eth_dev *dev)
243 : : {
244 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
245 : : int rc;
246 : :
247 : 0 : sfc_log_init(sa, "entry");
248 : :
249 : 0 : sfc_adapter_lock(sa);
250 : 0 : rc = sfc_start(sa);
251 : : sfc_adapter_unlock(sa);
252 : :
253 : 0 : sfc_log_init(sa, "done %d", rc);
254 : : SFC_ASSERT(rc >= 0);
255 : 0 : return -rc;
256 : : }
257 : :
258 : : static void
259 [ # # ]: 0 : sfc_dev_get_rte_link(struct rte_eth_dev *dev, int wait_to_complete,
260 : : struct rte_eth_link *link)
261 : : {
262 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
263 : :
264 : : SFC_ASSERT(link != NULL);
265 : :
266 [ # # ]: 0 : if (sa->state != SFC_ETHDEV_STARTED) {
267 : 0 : sfc_port_link_mode_to_info(EFX_LINK_UNKNOWN, 0, link);
268 [ # # ]: 0 : } else if (wait_to_complete) {
269 : : efx_link_mode_t link_mode;
270 : :
271 [ # # ]: 0 : if (efx_port_poll(sa->nic, &link_mode) != 0)
272 : 0 : link_mode = EFX_LINK_UNKNOWN;
273 : 0 : sfc_port_link_mode_to_info(link_mode, sa->port.phy_adv_cap,
274 : : link);
275 : : } else {
276 : 0 : sfc_ev_mgmt_qpoll(sa);
277 : 0 : rte_eth_linkstatus_get(dev, link);
278 : : }
279 : 0 : }
280 : :
281 : : static int
282 : 0 : sfc_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
283 : : {
284 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
285 : : struct rte_eth_link current_link;
286 : : int ret;
287 : :
288 : 0 : sfc_log_init(sa, "entry");
289 : :
290 : 0 : sfc_dev_get_rte_link(dev, wait_to_complete, ¤t_link);
291 : :
292 : : ret = rte_eth_linkstatus_set(dev, ¤t_link);
293 : : if (ret == 0)
294 [ # # ]: 0 : sfc_notice(sa, "Link status is %s",
295 : : current_link.link_status ? "UP" : "DOWN");
296 : :
297 : 0 : return ret;
298 : : }
299 : :
300 : : static int
301 [ # # ]: 0 : sfc_dev_speed_lanes_get(struct rte_eth_dev *dev, uint32_t *lane_countp)
302 : : {
303 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
304 : : struct sfc_port *port;
305 : : int rc = 0;
306 : :
307 [ # # ]: 0 : if (lane_countp == NULL)
308 : : return -EINVAL;
309 : :
310 : 0 : sfc_adapter_lock(sa);
311 : : port = &sa->port;
312 : :
313 [ # # ]: 0 : if (sa->state != SFC_ETHDEV_STARTED) {
314 : : /* The API wants 'active' lanes, so it is safe to indicate 0. */
315 : 0 : *lane_countp = 0;
316 : 0 : goto unlock;
317 : : }
318 : :
319 [ # # ]: 0 : if (port->phy_lane_count_active == EFX_PHY_LANE_COUNT_DEFAULT) {
320 : : rc = ENOTSUP;
321 : 0 : goto unlock;
322 : : }
323 : :
324 : 0 : *lane_countp = port->phy_lane_count_active;
325 : :
326 : 0 : unlock:
327 : : sfc_adapter_unlock(sa);
328 : 0 : return -rc;
329 : : }
330 : :
331 : : static int
332 : 0 : sfc_dev_speed_lanes_set(struct rte_eth_dev *dev, uint32_t lane_count)
333 : : {
334 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
335 : : int rc = 0;
336 : :
337 : 0 : sfc_adapter_lock(sa);
338 : :
339 [ # # ]: 0 : if (sa->state == SFC_ETHDEV_STARTED) {
340 : : rc = EBUSY;
341 : 0 : goto unlock;
342 : : }
343 : :
344 [ # # ]: 0 : if (lane_count == 0) {
345 : : rc = EINVAL;
346 : 0 : goto unlock;
347 : : }
348 : :
349 : 0 : sa->port.phy_lane_count_req = lane_count;
350 : :
351 : 0 : unlock:
352 : : sfc_adapter_unlock(sa);
353 : 0 : return -rc;
354 : : }
355 : :
356 : : static int
357 : : sfc_dev_speed_lane_cap_handle(const efx_nic_cfg_t *encp,
358 : : efx_link_mode_t link_mode,
359 : : unsigned int *nb_caps_to_fillp,
360 : : struct rte_eth_speed_lanes_capa **capp)
361 : : {
362 : 0 : uint32_t lane_counts = encp->enc_phy_lane_counts[link_mode].ed_u32[0];
363 : : struct rte_eth_speed_lanes_capa *cap = *capp;
364 : : uint32_t speed;
365 : :
366 [ # # ]: 0 : if (lane_counts == 0) {
367 : : /*
368 : : * The mask of supported lane counts for this link mode is
369 : : * empty. Do not waste output entries for such link modes.
370 : : */
371 : : return 0;
372 : : }
373 : :
374 : : switch (link_mode) {
375 : : case EFX_LINK_1000FDX:
376 : : speed = RTE_ETH_SPEED_NUM_1G;
377 : : break;
378 : : case EFX_LINK_10000FDX:
379 : : speed = RTE_ETH_SPEED_NUM_10G;
380 : : break;
381 : : case EFX_LINK_25000FDX:
382 : : speed = RTE_ETH_SPEED_NUM_25G;
383 : : break;
384 : : case EFX_LINK_40000FDX:
385 : : speed = RTE_ETH_SPEED_NUM_40G;
386 : : break;
387 : : case EFX_LINK_50000FDX:
388 : : speed = RTE_ETH_SPEED_NUM_50G;
389 : : break;
390 : : case EFX_LINK_100000FDX:
391 : : speed = RTE_ETH_SPEED_NUM_100G;
392 : : break;
393 : : case EFX_LINK_200000FDX:
394 : : speed = RTE_ETH_SPEED_NUM_200G;
395 : : break;
396 : : default:
397 : : /* No lane counts for this link mode. */
398 : : return 0;
399 : : }
400 : :
401 [ # # ]: 0 : if (*nb_caps_to_fillp == 0) {
402 [ # # ]: 0 : if (cap == NULL) {
403 : : /* Dry run. Indicate that an entry is available. */
404 : : return 1;
405 : : }
406 : :
407 : : /* We have run out of space in the user output buffer. */
408 : 0 : return 0;
409 : : }
410 : :
411 : 0 : cap->capa = lane_counts;
412 : 0 : cap->speed = speed;
413 : :
414 : 0 : --(*nb_caps_to_fillp);
415 : 0 : ++(*capp);
416 : 0 : return 1;
417 : : }
418 : :
419 : : static int
420 : 0 : sfc_dev_speed_lanes_get_capa(struct rte_eth_dev *dev,
421 : : struct rte_eth_speed_lanes_capa *caps,
422 : : unsigned int nb_caps)
423 : : {
424 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
425 : 0 : const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
426 : : efx_link_mode_t i;
427 : : int ret = 0;
428 : :
429 : 0 : sfc_adapter_lock(sa);
430 : :
431 [ # # ]: 0 : if (sa->state < SFC_ETHDEV_INITIALIZED) {
432 : : ret = -ENODEV;
433 : 0 : goto unlock;
434 : : }
435 : :
436 [ # # ]: 0 : for (i = 0; i < EFX_LINK_NMODES; ++i)
437 : 0 : ret += sfc_dev_speed_lane_cap_handle(encp, i, &nb_caps, &caps);
438 : :
439 : 0 : unlock:
440 : : sfc_adapter_unlock(sa);
441 : 0 : return ret;
442 : : }
443 : :
444 : : static int
445 : 0 : sfc_dev_stop(struct rte_eth_dev *dev)
446 : : {
447 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
448 : :
449 : 0 : sfc_log_init(sa, "entry");
450 : :
451 : 0 : sfc_adapter_lock(sa);
452 : 0 : sfc_stop(sa);
453 : : sfc_adapter_unlock(sa);
454 : :
455 : 0 : sfc_log_init(sa, "done");
456 : :
457 : 0 : return 0;
458 : : }
459 : :
460 : : static int
461 : 0 : sfc_dev_set_link_up(struct rte_eth_dev *dev)
462 : : {
463 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
464 : : int rc;
465 : :
466 : 0 : sfc_log_init(sa, "entry");
467 : :
468 : 0 : sfc_adapter_lock(sa);
469 : 0 : rc = sfc_start(sa);
470 : : sfc_adapter_unlock(sa);
471 : :
472 : : SFC_ASSERT(rc >= 0);
473 : 0 : return -rc;
474 : : }
475 : :
476 : : static int
477 : 0 : sfc_dev_set_link_down(struct rte_eth_dev *dev)
478 : : {
479 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
480 : :
481 : 0 : sfc_log_init(sa, "entry");
482 : :
483 : 0 : sfc_adapter_lock(sa);
484 : 0 : sfc_stop(sa);
485 : : sfc_adapter_unlock(sa);
486 : :
487 : 0 : return 0;
488 : : }
489 : :
490 : : static void
491 : : sfc_eth_dev_secondary_clear_ops(struct rte_eth_dev *dev)
492 : : {
493 : 0 : free(dev->process_private);
494 : 0 : rte_eth_dev_release_port(dev);
495 : : }
496 : :
497 : : static int
498 : 0 : sfc_dev_close(struct rte_eth_dev *dev)
499 : : {
500 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
501 : :
502 : 0 : sfc_log_init(sa, "entry");
503 : :
504 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
505 : : sfc_eth_dev_secondary_clear_ops(dev);
506 : 0 : return 0;
507 : : }
508 : :
509 : 0 : sfc_pre_detach(sa);
510 : :
511 : 0 : sfc_adapter_lock(sa);
512 [ # # # # ]: 0 : switch (sa->state) {
513 : 0 : case SFC_ETHDEV_STARTED:
514 : 0 : sfc_stop(sa);
515 : : SFC_ASSERT(sa->state == SFC_ETHDEV_CONFIGURED);
516 : : /* FALLTHROUGH */
517 : 0 : case SFC_ETHDEV_CONFIGURED:
518 : 0 : sfc_close(sa);
519 : : SFC_ASSERT(sa->state == SFC_ETHDEV_INITIALIZED);
520 : : /* FALLTHROUGH */
521 : : case SFC_ETHDEV_INITIALIZED:
522 : : break;
523 : 0 : default:
524 : 0 : sfc_err(sa, "unexpected adapter state %u on close", sa->state);
525 : 0 : break;
526 : : }
527 : :
528 : : /*
529 : : * Cleanup all resources.
530 : : * Rollback primary process sfc_eth_dev_init() below.
531 : : */
532 : :
533 : 0 : sfc_eth_dev_clear_ops(dev);
534 : :
535 : 0 : sfc_nic_dma_detach(sa);
536 : 0 : sfc_detach(sa);
537 : 0 : sfc_unprobe(sa);
538 : :
539 : 0 : sfc_kvargs_cleanup(sa);
540 : :
541 : : sfc_adapter_unlock(sa);
542 : : sfc_adapter_lock_fini(sa);
543 : :
544 : 0 : sfc_log_init(sa, "done");
545 : :
546 : : /* Required for logging, so cleanup last */
547 : : sa->eth_dev = NULL;
548 : :
549 : 0 : free(sa);
550 : :
551 : 0 : return 0;
552 : : }
553 : :
554 : : static int
555 [ # # ]: 0 : sfc_dev_filter_set(struct rte_eth_dev *dev, enum sfc_dev_filter_mode mode,
556 : : boolean_t enabled)
557 : : {
558 : : struct sfc_port *port;
559 : : boolean_t *toggle;
560 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
561 : : boolean_t allmulti = (mode == SFC_DEV_FILTER_MODE_ALLMULTI);
562 [ # # ]: 0 : const char *desc = (allmulti) ? "all-multi" : "promiscuous";
563 : : int rc = 0;
564 : :
565 : 0 : sfc_adapter_lock(sa);
566 : :
567 : : port = &sa->port;
568 [ # # ]: 0 : toggle = (allmulti) ? (&port->allmulti) : (&port->promisc);
569 : :
570 [ # # ]: 0 : if (*toggle != enabled) {
571 [ # # ]: 0 : *toggle = enabled;
572 : :
573 [ # # ]: 0 : if (sfc_sa2shared(sa)->isolated) {
574 : 0 : sfc_warn(sa, "isolated mode is active on the port");
575 : 0 : sfc_warn(sa, "the change is to be applied on the next "
576 : : "start provided that isolated mode is "
577 : : "disabled prior the next start");
578 [ # # # # ]: 0 : } else if ((sa->state == SFC_ETHDEV_STARTED) &&
579 : 0 : ((rc = sfc_set_rx_mode(sa)) != 0)) {
580 : 0 : *toggle = !(enabled);
581 [ # # ]: 0 : sfc_warn(sa, "Failed to %s %s mode, rc = %d",
582 : : ((enabled) ? "enable" : "disable"), desc, rc);
583 : :
584 : : /*
585 : : * For promiscuous and all-multicast filters a
586 : : * permission failure should be reported as an
587 : : * unsupported filter.
588 : : */
589 [ # # ]: 0 : if (rc == EPERM)
590 : : rc = ENOTSUP;
591 : : }
592 : : }
593 : :
594 : : sfc_adapter_unlock(sa);
595 : 0 : return rc;
596 : : }
597 : :
598 : : static int
599 : 0 : sfc_dev_promisc_enable(struct rte_eth_dev *dev)
600 : : {
601 : 0 : int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_TRUE);
602 : :
603 : : SFC_ASSERT(rc >= 0);
604 : 0 : return -rc;
605 : : }
606 : :
607 : : static int
608 : 0 : sfc_dev_promisc_disable(struct rte_eth_dev *dev)
609 : : {
610 : 0 : int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_FALSE);
611 : :
612 : : SFC_ASSERT(rc >= 0);
613 : 0 : return -rc;
614 : : }
615 : :
616 : : static int
617 : 0 : sfc_dev_allmulti_enable(struct rte_eth_dev *dev)
618 : : {
619 : 0 : int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_TRUE);
620 : :
621 : : SFC_ASSERT(rc >= 0);
622 : 0 : return -rc;
623 : : }
624 : :
625 : : static int
626 : 0 : sfc_dev_allmulti_disable(struct rte_eth_dev *dev)
627 : : {
628 : 0 : int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_FALSE);
629 : :
630 : : SFC_ASSERT(rc >= 0);
631 : 0 : return -rc;
632 : : }
633 : :
634 : : static int
635 : 0 : sfc_rx_queue_setup(struct rte_eth_dev *dev, uint16_t ethdev_qid,
636 : : uint16_t nb_rx_desc, unsigned int socket_id,
637 : : const struct rte_eth_rxconf *rx_conf,
638 : : struct rte_mempool *mb_pool)
639 : : {
640 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
641 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
642 : 0 : sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
643 : : struct sfc_rxq_info *rxq_info;
644 : : sfc_sw_index_t sw_index;
645 : : int rc;
646 : :
647 : 0 : sfc_log_init(sa, "RxQ=%u nb_rx_desc=%u socket_id=%u",
648 : : ethdev_qid, nb_rx_desc, socket_id);
649 : :
650 : 0 : sfc_adapter_lock(sa);
651 : :
652 : : sw_index = sfc_rxq_sw_index_by_ethdev_rx_qid(sas, sfc_ethdev_qid);
653 : 0 : rc = sfc_rx_qinit(sa, sw_index, nb_rx_desc, socket_id,
654 : : rx_conf, mb_pool);
655 [ # # ]: 0 : if (rc != 0)
656 : 0 : goto fail_rx_qinit;
657 : :
658 : 0 : rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
659 : 0 : dev->data->rx_queues[ethdev_qid] = rxq_info->dp;
660 : :
661 : : sfc_adapter_unlock(sa);
662 : :
663 : 0 : return 0;
664 : :
665 : : fail_rx_qinit:
666 : : sfc_adapter_unlock(sa);
667 : : SFC_ASSERT(rc > 0);
668 : 0 : return -rc;
669 : : }
670 : :
671 : : static void
672 : 0 : sfc_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
673 : : {
674 : 0 : struct sfc_dp_rxq *dp_rxq = dev->data->rx_queues[qid];
675 : : struct sfc_rxq *rxq;
676 : : struct sfc_adapter *sa;
677 : : sfc_sw_index_t sw_index;
678 : :
679 [ # # ]: 0 : if (dp_rxq == NULL)
680 : : return;
681 : :
682 : 0 : rxq = sfc_rxq_by_dp_rxq(dp_rxq);
683 : 0 : sa = rxq->evq->sa;
684 : 0 : sfc_adapter_lock(sa);
685 : :
686 : 0 : sw_index = dp_rxq->dpq.queue_id;
687 : :
688 : 0 : sfc_log_init(sa, "RxQ=%u", sw_index);
689 : :
690 : 0 : sfc_rx_qfini(sa, sw_index);
691 : :
692 : : sfc_adapter_unlock(sa);
693 : : }
694 : :
695 : : static int
696 : 0 : sfc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t ethdev_qid,
697 : : uint16_t nb_tx_desc, unsigned int socket_id,
698 : : const struct rte_eth_txconf *tx_conf)
699 : : {
700 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
701 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
702 : : struct sfc_txq_info *txq_info;
703 : : sfc_sw_index_t sw_index;
704 : : int rc;
705 : :
706 : 0 : sfc_log_init(sa, "TxQ = %u, nb_tx_desc = %u, socket_id = %u",
707 : : ethdev_qid, nb_tx_desc, socket_id);
708 : :
709 : 0 : sfc_adapter_lock(sa);
710 : :
711 : : sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
712 : 0 : rc = sfc_tx_qinit(sa, sw_index, nb_tx_desc, socket_id, tx_conf);
713 [ # # ]: 0 : if (rc != 0)
714 : 0 : goto fail_tx_qinit;
715 : :
716 : 0 : txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
717 : 0 : dev->data->tx_queues[ethdev_qid] = txq_info->dp;
718 : :
719 : : sfc_adapter_unlock(sa);
720 : 0 : return 0;
721 : :
722 : : fail_tx_qinit:
723 : : sfc_adapter_unlock(sa);
724 : : SFC_ASSERT(rc > 0);
725 : 0 : return -rc;
726 : : }
727 : :
728 : : static void
729 : 0 : sfc_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
730 : : {
731 : 0 : struct sfc_dp_txq *dp_txq = dev->data->tx_queues[qid];
732 : : struct sfc_txq *txq;
733 : : sfc_sw_index_t sw_index;
734 : : struct sfc_adapter *sa;
735 : :
736 [ # # ]: 0 : if (dp_txq == NULL)
737 : : return;
738 : :
739 : 0 : txq = sfc_txq_by_dp_txq(dp_txq);
740 : 0 : sw_index = dp_txq->dpq.queue_id;
741 : :
742 : : SFC_ASSERT(txq->evq != NULL);
743 : 0 : sa = txq->evq->sa;
744 : :
745 : 0 : sfc_log_init(sa, "TxQ = %u", sw_index);
746 : :
747 : 0 : sfc_adapter_lock(sa);
748 : :
749 : 0 : sfc_tx_qfini(sa, sw_index);
750 : :
751 : : sfc_adapter_unlock(sa);
752 : : }
753 : :
754 : : static void
755 : 0 : sfc_stats_get_dp_rx(struct sfc_adapter *sa, uint64_t *pkts, uint64_t *bytes)
756 : : {
757 : : struct sfc_adapter_shared *sas = sfc_sa2shared(sa);
758 : : uint64_t pkts_sum = 0;
759 : : uint64_t bytes_sum = 0;
760 : : unsigned int i;
761 : :
762 [ # # ]: 0 : for (i = 0; i < sas->ethdev_rxq_count; ++i) {
763 : : struct sfc_rxq_info *rxq_info;
764 : :
765 : 0 : rxq_info = sfc_rxq_info_by_ethdev_qid(sas, i);
766 [ # # ]: 0 : if (rxq_info->state & SFC_RXQ_INITIALIZED) {
767 : : union sfc_pkts_bytes qstats;
768 : :
769 : 0 : sfc_pkts_bytes_get(&rxq_info->dp->dpq.stats, &qstats);
770 : 0 : pkts_sum += qstats.pkts -
771 : 0 : sa->sw_stats.reset_rx_pkts[i];
772 : 0 : bytes_sum += qstats.bytes -
773 : 0 : sa->sw_stats.reset_rx_bytes[i];
774 : : }
775 : : }
776 : :
777 : 0 : *pkts = pkts_sum;
778 : 0 : *bytes = bytes_sum;
779 : 0 : }
780 : :
781 : : static void
782 : 0 : sfc_stats_get_dp_tx(struct sfc_adapter *sa, uint64_t *pkts, uint64_t *bytes)
783 : : {
784 : : struct sfc_adapter_shared *sas = sfc_sa2shared(sa);
785 : : uint64_t pkts_sum = 0;
786 : : uint64_t bytes_sum = 0;
787 : : unsigned int i;
788 : :
789 [ # # ]: 0 : for (i = 0; i < sas->ethdev_txq_count; ++i) {
790 : : struct sfc_txq_info *txq_info;
791 : :
792 : 0 : txq_info = sfc_txq_info_by_ethdev_qid(sas, i);
793 [ # # ]: 0 : if (txq_info->state & SFC_TXQ_INITIALIZED) {
794 : : union sfc_pkts_bytes qstats;
795 : :
796 : 0 : sfc_pkts_bytes_get(&txq_info->dp->dpq.stats, &qstats);
797 : 0 : pkts_sum += qstats.pkts -
798 : 0 : sa->sw_stats.reset_tx_pkts[i];
799 : 0 : bytes_sum += qstats.bytes -
800 : 0 : sa->sw_stats.reset_tx_bytes[i];
801 : : }
802 : : }
803 : :
804 : 0 : *pkts = pkts_sum;
805 : 0 : *bytes = bytes_sum;
806 : 0 : }
807 : :
808 : : /*
809 : : * Some statistics are computed as A - B where A and B each increase
810 : : * monotonically with some hardware counter(s) and the counters are read
811 : : * asynchronously.
812 : : *
813 : : * If packet X is counted in A, but not counted in B yet, computed value is
814 : : * greater than real.
815 : : *
816 : : * If packet X is not counted in A at the moment of reading the counter,
817 : : * but counted in B at the moment of reading the counter, computed value
818 : : * is less than real.
819 : : *
820 : : * However, counter which grows backward is worse evil than slightly wrong
821 : : * value. So, let's try to guarantee that it never happens except may be
822 : : * the case when the MAC stats are zeroed as a result of a NIC reset.
823 : : */
824 : : static void
825 : : sfc_update_diff_stat(uint64_t *stat, uint64_t newval)
826 : : {
827 [ # # ]: 0 : if ((int64_t)(newval - *stat) > 0 || newval == 0)
828 : 0 : *stat = newval;
829 : : }
830 : :
831 : : static int
832 : 0 : sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
833 : : struct eth_queue_stats *qstats __rte_unused)
834 : : {
835 : : const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
836 : 0 : bool have_dp_rx_stats = sap->dp_rx->features & SFC_DP_RX_FEAT_STATS;
837 : 0 : bool have_dp_tx_stats = sap->dp_tx->features & SFC_DP_TX_FEAT_STATS;
838 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
839 : : struct sfc_port *port = &sa->port;
840 : : uint64_t *mac_stats;
841 : : int ret;
842 : :
843 : 0 : sfc_adapter_lock(sa);
844 : :
845 [ # # ]: 0 : if (have_dp_rx_stats) {
846 : 0 : sfc_stats_get_dp_rx(sa, &stats->ipackets, &stats->ibytes);
847 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.offloads &
848 : : RTE_ETH_RX_OFFLOAD_KEEP_CRC) {
849 : 0 : stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
850 : : }
851 : : }
852 [ # # ]: 0 : if (have_dp_tx_stats)
853 : 0 : sfc_stats_get_dp_tx(sa, &stats->opackets, &stats->obytes);
854 : :
855 : 0 : ret = sfc_port_update_mac_stats(sa, B_FALSE);
856 [ # # ]: 0 : if (ret != 0)
857 : 0 : goto unlock;
858 : :
859 : 0 : mac_stats = port->mac_stats_buf;
860 : :
861 [ # # ]: 0 : if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask,
862 : : EFX_MAC_VADAPTER_RX_UNICAST_PACKETS)) {
863 [ # # ]: 0 : if (!have_dp_rx_stats) {
864 : 0 : stats->ipackets =
865 : 0 : mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_PACKETS] +
866 : 0 : mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_PACKETS] +
867 : 0 : mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_PACKETS];
868 : : stats->ibytes =
869 : 0 : mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_BYTES] +
870 : 0 : mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_BYTES] +
871 : 0 : mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_BYTES];
872 : :
873 : : /* CRC is included in these stats, but shouldn't be */
874 : 0 : stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
875 : : }
876 [ # # ]: 0 : if (!have_dp_tx_stats) {
877 : 0 : stats->opackets =
878 : 0 : mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_PACKETS] +
879 : 0 : mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_PACKETS] +
880 : 0 : mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_PACKETS];
881 : : stats->obytes =
882 : 0 : mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_BYTES] +
883 : 0 : mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_BYTES] +
884 : 0 : mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_BYTES];
885 : :
886 : : /* CRC is included in these stats, but shouldn't be */
887 : 0 : stats->obytes -= stats->opackets * RTE_ETHER_CRC_LEN;
888 : : }
889 : 0 : stats->imissed = mac_stats[EFX_MAC_VADAPTER_RX_BAD_PACKETS];
890 : 0 : stats->oerrors = mac_stats[EFX_MAC_VADAPTER_TX_BAD_PACKETS];
891 : : } else {
892 [ # # ]: 0 : if (!have_dp_tx_stats) {
893 : 0 : stats->opackets = mac_stats[EFX_MAC_TX_PKTS];
894 : 0 : stats->obytes = mac_stats[EFX_MAC_TX_OCTETS] -
895 : 0 : mac_stats[EFX_MAC_TX_PKTS] * RTE_ETHER_CRC_LEN;
896 : : }
897 : :
898 : : /*
899 : : * Take into account stats which are whenever supported
900 : : * on EF10. If some stat is not supported by current
901 : : * firmware variant or HW revision, it is guaranteed
902 : : * to be zero in mac_stats.
903 : : */
904 : 0 : stats->imissed =
905 : 0 : mac_stats[EFX_MAC_RX_NODESC_DROP_CNT] +
906 : 0 : mac_stats[EFX_MAC_PM_TRUNC_BB_OVERFLOW] +
907 : 0 : mac_stats[EFX_MAC_PM_DISCARD_BB_OVERFLOW] +
908 : 0 : mac_stats[EFX_MAC_PM_TRUNC_VFIFO_FULL] +
909 : 0 : mac_stats[EFX_MAC_PM_DISCARD_VFIFO_FULL] +
910 : 0 : mac_stats[EFX_MAC_PM_TRUNC_QBB] +
911 : 0 : mac_stats[EFX_MAC_PM_DISCARD_QBB] +
912 : 0 : mac_stats[EFX_MAC_PM_DISCARD_MAPPING] +
913 : 0 : mac_stats[EFX_MAC_RXDP_Q_DISABLED_PKTS] +
914 : 0 : mac_stats[EFX_MAC_RXDP_DI_DROPPED_PKTS];
915 : 0 : stats->ierrors =
916 : 0 : mac_stats[EFX_MAC_RX_FCS_ERRORS] +
917 : 0 : mac_stats[EFX_MAC_RX_ALIGN_ERRORS] +
918 : 0 : mac_stats[EFX_MAC_RX_JABBER_PKTS];
919 : : /* no oerrors counters supported on EF10 */
920 : :
921 [ # # ]: 0 : if (!have_dp_rx_stats) {
922 : : /* Exclude missed, errors and pauses from Rx packets */
923 : 0 : sfc_update_diff_stat(&port->ipackets,
924 : 0 : mac_stats[EFX_MAC_RX_PKTS] -
925 [ # # ]: 0 : mac_stats[EFX_MAC_RX_PAUSE_PKTS] -
926 : : stats->imissed - stats->ierrors);
927 : 0 : stats->ipackets = port->ipackets;
928 : 0 : stats->ibytes = mac_stats[EFX_MAC_RX_OCTETS] -
929 : 0 : mac_stats[EFX_MAC_RX_PKTS] * RTE_ETHER_CRC_LEN;
930 : : }
931 : : }
932 : :
933 : 0 : unlock:
934 : : sfc_adapter_unlock(sa);
935 : : SFC_ASSERT(ret >= 0);
936 : 0 : return -ret;
937 : : }
938 : :
939 : : static int
940 : 0 : sfc_stats_reset(struct rte_eth_dev *dev)
941 : : {
942 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
943 : : struct sfc_port *port = &sa->port;
944 : : int rc;
945 : :
946 : 0 : sfc_adapter_lock(sa);
947 : :
948 [ # # ]: 0 : if (sa->state != SFC_ETHDEV_STARTED) {
949 : : /*
950 : : * The operation cannot be done if port is not started; it
951 : : * will be scheduled to be done during the next port start
952 : : */
953 : 0 : port->mac_stats_reset_pending = B_TRUE;
954 : : sfc_adapter_unlock(sa);
955 : 0 : return 0;
956 : : }
957 : :
958 : 0 : rc = sfc_port_reset_mac_stats(sa);
959 [ # # ]: 0 : if (rc != 0)
960 : 0 : sfc_err(sa, "failed to reset statistics (rc = %d)", rc);
961 : :
962 : 0 : sfc_sw_xstats_reset(sa);
963 : :
964 : : sfc_adapter_unlock(sa);
965 : :
966 : : SFC_ASSERT(rc >= 0);
967 : 0 : return -rc;
968 : : }
969 : :
970 : : static unsigned int
971 : 0 : sfc_xstats_get_nb_supported(struct sfc_adapter *sa)
972 : : {
973 : : struct sfc_port *port = &sa->port;
974 : : unsigned int nb_supported;
975 : :
976 : 0 : sfc_adapter_lock(sa);
977 : 0 : nb_supported = port->mac_stats_nb_supported +
978 : 0 : sfc_sw_xstats_get_nb_supported(sa);
979 : : sfc_adapter_unlock(sa);
980 : :
981 : 0 : return nb_supported;
982 : : }
983 : :
984 : : static int
985 [ # # ]: 0 : sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
986 : : unsigned int xstats_count)
987 : : {
988 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
989 : 0 : unsigned int nb_written = 0;
990 : 0 : unsigned int nb_supported = 0;
991 : : int rc;
992 : :
993 [ # # ]: 0 : if (unlikely(xstats == NULL))
994 : 0 : return sfc_xstats_get_nb_supported(sa);
995 : :
996 : 0 : rc = sfc_port_get_mac_stats(sa, xstats, xstats_count, &nb_written);
997 [ # # ]: 0 : if (rc < 0)
998 : : return rc;
999 : :
1000 : 0 : nb_supported = rc;
1001 : 0 : sfc_sw_xstats_get_vals(sa, xstats, xstats_count, &nb_written,
1002 : : &nb_supported);
1003 : :
1004 : 0 : return nb_supported;
1005 : : }
1006 : :
1007 : : static int
1008 [ # # ]: 0 : sfc_xstats_get_names(struct rte_eth_dev *dev,
1009 : : struct rte_eth_xstat_name *xstats_names,
1010 : : unsigned int xstats_count)
1011 : : {
1012 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1013 : : struct sfc_port *port = &sa->port;
1014 : : unsigned int i;
1015 : 0 : unsigned int nstats = 0;
1016 : 0 : unsigned int nb_written = 0;
1017 : : int ret;
1018 : :
1019 [ # # ]: 0 : if (unlikely(xstats_names == NULL))
1020 : 0 : return sfc_xstats_get_nb_supported(sa);
1021 : :
1022 [ # # ]: 0 : for (i = 0; i < EFX_MAC_NSTATS; ++i) {
1023 [ # # ]: 0 : if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) {
1024 [ # # ]: 0 : if (nstats < xstats_count) {
1025 : 0 : strlcpy(xstats_names[nstats].name,
1026 : : efx_mac_stat_name(sa->nic, i),
1027 : : sizeof(xstats_names[0].name));
1028 : 0 : nb_written++;
1029 : : }
1030 : 0 : nstats++;
1031 : : }
1032 : : }
1033 : :
1034 : 0 : ret = sfc_sw_xstats_get_names(sa, xstats_names, xstats_count,
1035 : : &nb_written, &nstats);
1036 [ # # ]: 0 : if (ret != 0) {
1037 : : SFC_ASSERT(ret < 0);
1038 : : return ret;
1039 : : }
1040 : :
1041 : 0 : return nstats;
1042 : : }
1043 : :
1044 : : static int
1045 [ # # ]: 0 : sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
1046 : : uint64_t *values, unsigned int n)
1047 : : {
1048 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1049 : : struct sfc_port *port = &sa->port;
1050 : : unsigned int nb_supported;
1051 : : unsigned int i;
1052 : : int rc;
1053 : :
1054 [ # # ]: 0 : if (unlikely(ids == NULL || values == NULL))
1055 : : return -EINVAL;
1056 : :
1057 : : /*
1058 : : * Values array could be filled in nonsequential order. Fill values with
1059 : : * constant indicating invalid ID first.
1060 : : */
1061 [ # # ]: 0 : for (i = 0; i < n; i++)
1062 : 0 : values[i] = SFC_XSTAT_ID_INVALID_VAL;
1063 : :
1064 : 0 : rc = sfc_port_get_mac_stats_by_id(sa, ids, values, n);
1065 [ # # ]: 0 : if (rc != 0)
1066 : : return rc;
1067 : :
1068 : 0 : nb_supported = port->mac_stats_nb_supported;
1069 : 0 : sfc_sw_xstats_get_vals_by_id(sa, ids, values, n, &nb_supported);
1070 : :
1071 : : /* Return number of written stats before invalid ID is encountered. */
1072 [ # # ]: 0 : for (i = 0; i < n; i++) {
1073 [ # # ]: 0 : if (values[i] == SFC_XSTAT_ID_INVALID_VAL)
1074 : 0 : return i;
1075 : : }
1076 : :
1077 : 0 : return n;
1078 : : }
1079 : :
1080 : : static int
1081 [ # # ]: 0 : sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
1082 : : const uint64_t *ids,
1083 : : struct rte_eth_xstat_name *xstats_names,
1084 : : unsigned int size)
1085 : : {
1086 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1087 : : struct sfc_port *port = &sa->port;
1088 : : unsigned int nb_supported;
1089 : : unsigned int i;
1090 : : int ret;
1091 : :
1092 [ # # ]: 0 : if (unlikely(xstats_names == NULL && ids != NULL) ||
1093 [ # # ]: 0 : unlikely(xstats_names != NULL && ids == NULL))
1094 : : return -EINVAL;
1095 : :
1096 [ # # ]: 0 : if (unlikely(xstats_names == NULL && ids == NULL))
1097 : 0 : return sfc_xstats_get_nb_supported(sa);
1098 : :
1099 : : /*
1100 : : * Names array could be filled in nonsequential order. Fill names with
1101 : : * string indicating invalid ID first.
1102 : : */
1103 [ # # ]: 0 : for (i = 0; i < size; i++)
1104 : 0 : xstats_names[i].name[0] = SFC_XSTAT_ID_INVALID_NAME;
1105 : :
1106 : 0 : sfc_adapter_lock(sa);
1107 : :
1108 : : SFC_ASSERT(port->mac_stats_nb_supported <=
1109 : : RTE_DIM(port->mac_stats_by_id));
1110 : :
1111 [ # # ]: 0 : for (i = 0; i < size; i++) {
1112 [ # # ]: 0 : if (ids[i] < port->mac_stats_nb_supported) {
1113 : 0 : strlcpy(xstats_names[i].name,
1114 : : efx_mac_stat_name(sa->nic,
1115 : : port->mac_stats_by_id[ids[i]]),
1116 : : sizeof(xstats_names[0].name));
1117 : : }
1118 : : }
1119 : :
1120 : 0 : nb_supported = port->mac_stats_nb_supported;
1121 : :
1122 : : sfc_adapter_unlock(sa);
1123 : :
1124 : 0 : ret = sfc_sw_xstats_get_names_by_id(sa, ids, xstats_names, size,
1125 : : &nb_supported);
1126 [ # # ]: 0 : if (ret != 0) {
1127 : : SFC_ASSERT(ret < 0);
1128 : : return ret;
1129 : : }
1130 : :
1131 : : /* Return number of written names before invalid ID is encountered. */
1132 [ # # ]: 0 : for (i = 0; i < size; i++) {
1133 [ # # ]: 0 : if (xstats_names[i].name[0] == SFC_XSTAT_ID_INVALID_NAME)
1134 : 0 : return i;
1135 : : }
1136 : :
1137 : 0 : return size;
1138 : : }
1139 : :
1140 : : static int
1141 : 0 : sfc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1142 : : {
1143 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1144 : : unsigned int wanted_fc, link_fc;
1145 : :
1146 : : memset(fc_conf, 0, sizeof(*fc_conf));
1147 : :
1148 : 0 : sfc_adapter_lock(sa);
1149 : :
1150 [ # # ]: 0 : if (sa->state == SFC_ETHDEV_STARTED)
1151 : 0 : efx_mac_fcntl_get(sa->nic, &wanted_fc, &link_fc);
1152 : : else
1153 : 0 : link_fc = sa->port.flow_ctrl;
1154 : :
1155 [ # # # # : 0 : switch (link_fc) {
# ]
1156 : 0 : case 0:
1157 : 0 : fc_conf->mode = RTE_ETH_FC_NONE;
1158 : 0 : break;
1159 : 0 : case EFX_FCNTL_RESPOND:
1160 : 0 : fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
1161 : 0 : break;
1162 : 0 : case EFX_FCNTL_GENERATE:
1163 : 0 : fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
1164 : 0 : break;
1165 : 0 : case (EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE):
1166 : 0 : fc_conf->mode = RTE_ETH_FC_FULL;
1167 : 0 : break;
1168 : 0 : default:
1169 : 0 : sfc_err(sa, "%s: unexpected flow control value %#x",
1170 : : __func__, link_fc);
1171 : : }
1172 : :
1173 : 0 : fc_conf->autoneg = sa->port.flow_ctrl_autoneg;
1174 : :
1175 : : sfc_adapter_unlock(sa);
1176 : :
1177 : 0 : return 0;
1178 : : }
1179 : :
1180 : : static int
1181 [ # # ]: 0 : sfc_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
1182 : : {
1183 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1184 : : struct sfc_port *port = &sa->port;
1185 : : unsigned int fcntl;
1186 : : int rc;
1187 : :
1188 [ # # # # ]: 0 : if (fc_conf->high_water != 0 || fc_conf->low_water != 0 ||
1189 [ # # ]: 0 : fc_conf->pause_time != 0 || fc_conf->send_xon != 0 ||
1190 [ # # ]: 0 : fc_conf->mac_ctrl_frame_fwd != 0) {
1191 : 0 : sfc_err(sa, "unsupported flow control settings specified");
1192 : : rc = EINVAL;
1193 : 0 : goto fail_inval;
1194 : : }
1195 : :
1196 [ # # ]: 0 : switch (fc_conf->mode) {
1197 : : case RTE_ETH_FC_NONE:
1198 : : fcntl = 0;
1199 : : break;
1200 : : case RTE_ETH_FC_RX_PAUSE:
1201 : : fcntl = EFX_FCNTL_RESPOND;
1202 : : break;
1203 : : case RTE_ETH_FC_TX_PAUSE:
1204 : : fcntl = EFX_FCNTL_GENERATE;
1205 : : break;
1206 : : case RTE_ETH_FC_FULL:
1207 : : fcntl = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
1208 : : break;
1209 : 0 : default:
1210 : : rc = EINVAL;
1211 : 0 : goto fail_inval;
1212 : : }
1213 : :
1214 : 0 : sfc_adapter_lock(sa);
1215 : :
1216 [ # # ]: 0 : if (sa->state == SFC_ETHDEV_STARTED) {
1217 : 0 : rc = efx_mac_fcntl_set(sa->nic, fcntl, fc_conf->autoneg);
1218 [ # # ]: 0 : if (rc != 0)
1219 : 0 : goto fail_mac_fcntl_set;
1220 : : }
1221 : :
1222 : 0 : port->flow_ctrl = fcntl;
1223 : 0 : port->flow_ctrl_autoneg = fc_conf->autoneg;
1224 : :
1225 : : sfc_adapter_unlock(sa);
1226 : :
1227 : 0 : return 0;
1228 : :
1229 : : fail_mac_fcntl_set:
1230 : : sfc_adapter_unlock(sa);
1231 : 0 : fail_inval:
1232 : : SFC_ASSERT(rc > 0);
1233 : 0 : return -rc;
1234 : : }
1235 : :
1236 : : static int
1237 : 0 : sfc_check_scatter_on_all_rx_queues(struct sfc_adapter *sa, size_t pdu)
1238 : : {
1239 : : struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
1240 : 0 : const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1241 : : boolean_t scatter_enabled;
1242 : : const char *error;
1243 : : unsigned int i;
1244 : :
1245 [ # # ]: 0 : for (i = 0; i < sas->rxq_count; i++) {
1246 [ # # ]: 0 : if ((sas->rxq_info[i].state & SFC_RXQ_INITIALIZED) == 0)
1247 : 0 : continue;
1248 : :
1249 : 0 : scatter_enabled = (sas->rxq_info[i].type_flags &
1250 : : EFX_RXQ_FLAG_SCATTER);
1251 : :
1252 [ # # ]: 0 : if (!sfc_rx_check_scatter(pdu, sa->rxq_ctrl[i].buf_size,
1253 : 0 : encp->enc_rx_prefix_size,
1254 : : scatter_enabled,
1255 : 0 : encp->enc_rx_scatter_max, &error)) {
1256 : 0 : sfc_err(sa, "MTU check for RxQ %u failed: %s", i,
1257 : : error);
1258 : 0 : return EINVAL;
1259 : : }
1260 : : }
1261 : :
1262 : : return 0;
1263 : : }
1264 : :
1265 : : static int
1266 : 0 : sfc_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
1267 : : {
1268 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1269 : 0 : const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1270 : 0 : size_t pdu = efx_mac_pdu_from_sdu(sa->nic, mtu);
1271 : : size_t old_pdu;
1272 : : int rc;
1273 : :
1274 : 0 : sfc_log_init(sa, "mtu=%u", mtu);
1275 : :
1276 : : rc = EINVAL;
1277 [ # # ]: 0 : if (pdu < encp->enc_mac_pdu_min) {
1278 : 0 : sfc_err(sa, "too small MTU %u (PDU size %u less than min %u)",
1279 : : (unsigned int)mtu, (unsigned int)pdu,
1280 : : encp->enc_mac_pdu_min);
1281 : 0 : goto fail_inval;
1282 : : }
1283 [ # # ]: 0 : if (pdu > encp->enc_mac_pdu_max) {
1284 : 0 : sfc_err(sa, "too big MTU %u (PDU size %u greater than max %u)",
1285 : : (unsigned int)mtu, (unsigned int)pdu,
1286 : : encp->enc_mac_pdu_max);
1287 : 0 : goto fail_inval;
1288 : : }
1289 : :
1290 : 0 : sfc_adapter_lock(sa);
1291 : :
1292 : 0 : rc = sfc_check_scatter_on_all_rx_queues(sa, pdu);
1293 [ # # ]: 0 : if (rc != 0)
1294 : 0 : goto fail_check_scatter;
1295 : :
1296 [ # # ]: 0 : if (pdu != sa->port.pdu) {
1297 [ # # ]: 0 : if (sa->state == SFC_ETHDEV_STARTED) {
1298 : 0 : sfc_stop(sa);
1299 : :
1300 : 0 : old_pdu = sa->port.pdu;
1301 : 0 : sa->port.pdu = pdu;
1302 : 0 : rc = sfc_start(sa);
1303 [ # # ]: 0 : if (rc != 0)
1304 : 0 : goto fail_start;
1305 : : } else {
1306 : 0 : sa->port.pdu = pdu;
1307 : : }
1308 : : }
1309 : :
1310 : : sfc_adapter_unlock(sa);
1311 : :
1312 : 0 : sfc_log_init(sa, "done");
1313 : 0 : return 0;
1314 : :
1315 : : fail_start:
1316 : 0 : sa->port.pdu = old_pdu;
1317 [ # # ]: 0 : if (sfc_start(sa) != 0)
1318 : 0 : sfc_err(sa, "cannot start with neither new (%u) nor old (%u) "
1319 : : "PDU max size - port is stopped",
1320 : : (unsigned int)pdu, (unsigned int)old_pdu);
1321 : :
1322 : 0 : fail_check_scatter:
1323 : : sfc_adapter_unlock(sa);
1324 : :
1325 : 0 : fail_inval:
1326 : 0 : sfc_log_init(sa, "failed %d", rc);
1327 : : SFC_ASSERT(rc > 0);
1328 : 0 : return -rc;
1329 : : }
1330 : : static int
1331 : 0 : sfc_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1332 : : {
1333 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1334 : 0 : const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1335 : : struct sfc_port *port = &sa->port;
1336 : 0 : struct rte_ether_addr *old_addr = &dev->data->mac_addrs[0];
1337 : : int rc = 0;
1338 : :
1339 : 0 : sfc_adapter_lock(sa);
1340 : :
1341 [ # # ]: 0 : if (rte_is_same_ether_addr(mac_addr, &port->default_mac_addr))
1342 : 0 : goto unlock;
1343 : :
1344 : : /*
1345 : : * Copy the address to the device private data so that
1346 : : * it could be recalled in the case of adapter restart.
1347 : : */
1348 : : rte_ether_addr_copy(mac_addr, &port->default_mac_addr);
1349 : :
1350 : : /*
1351 : : * Neither of the two following checks can return
1352 : : * an error. The new MAC address is preserved in
1353 : : * the device private data and can be activated
1354 : : * on the next port start if the user prevents
1355 : : * isolated mode from being enabled.
1356 : : */
1357 [ # # ]: 0 : if (sfc_sa2shared(sa)->isolated) {
1358 : 0 : sfc_warn(sa, "isolated mode is active on the port");
1359 : 0 : sfc_warn(sa, "will not set MAC address");
1360 : 0 : goto unlock;
1361 : : }
1362 : :
1363 [ # # ]: 0 : if (sa->state != SFC_ETHDEV_STARTED) {
1364 : 0 : sfc_notice(sa, "the port is not started");
1365 : 0 : sfc_notice(sa, "the new MAC address will be set on port start");
1366 : :
1367 : 0 : goto unlock;
1368 : : }
1369 : :
1370 [ # # ]: 0 : if (encp->enc_allow_set_mac_with_installed_filters) {
1371 : 0 : rc = efx_mac_addr_set(sa->nic, mac_addr->addr_bytes);
1372 [ # # ]: 0 : if (rc != 0) {
1373 : 0 : sfc_err(sa, "cannot set MAC address (rc = %u)", rc);
1374 : 0 : goto unlock;
1375 : : }
1376 : :
1377 : : /*
1378 : : * Changing the MAC address by means of MCDI request
1379 : : * has no effect on received traffic, therefore
1380 : : * we also need to update unicast filters
1381 : : */
1382 : 0 : rc = sfc_set_rx_mode_unchecked(sa);
1383 [ # # ]: 0 : if (rc != 0) {
1384 : 0 : sfc_err(sa, "cannot set filter (rc = %u)", rc);
1385 : : /* Rollback the old address */
1386 : 0 : (void)efx_mac_addr_set(sa->nic, old_addr->addr_bytes);
1387 : 0 : (void)sfc_set_rx_mode_unchecked(sa);
1388 : : }
1389 : : } else {
1390 : 0 : sfc_warn(sa, "cannot set MAC address with filters installed");
1391 : 0 : sfc_warn(sa, "adapter will be restarted to pick the new MAC");
1392 : 0 : sfc_warn(sa, "(some traffic may be dropped)");
1393 : :
1394 : : /*
1395 : : * Since setting MAC address with filters installed is not
1396 : : * allowed on the adapter, the new MAC address will be set
1397 : : * by means of adapter restart. sfc_start() shall retrieve
1398 : : * the new address from the device private data and set it.
1399 : : */
1400 : 0 : sfc_stop(sa);
1401 : 0 : rc = sfc_start(sa);
1402 [ # # ]: 0 : if (rc != 0)
1403 : 0 : sfc_err(sa, "cannot restart adapter (rc = %u)", rc);
1404 : : }
1405 : :
1406 : 0 : unlock:
1407 [ # # ]: 0 : if (rc != 0)
1408 : : rte_ether_addr_copy(old_addr, &port->default_mac_addr);
1409 : :
1410 : : sfc_adapter_unlock(sa);
1411 : :
1412 : : SFC_ASSERT(rc >= 0);
1413 : 0 : return -rc;
1414 : : }
1415 : :
1416 : :
1417 : : static int
1418 [ # # ]: 0 : sfc_set_mc_addr_list(struct rte_eth_dev *dev,
1419 : : struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr)
1420 : : {
1421 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1422 : : struct sfc_port *port = &sa->port;
1423 [ # # ]: 0 : uint8_t *mc_addrs = port->mcast_addrs;
1424 : : int rc;
1425 : : unsigned int i;
1426 : :
1427 [ # # ]: 0 : if (sfc_sa2shared(sa)->isolated) {
1428 : 0 : sfc_err(sa, "isolated mode is active on the port");
1429 : 0 : sfc_err(sa, "will not set multicast address list");
1430 : 0 : return -ENOTSUP;
1431 : : }
1432 : :
1433 [ # # ]: 0 : if (mc_addrs == NULL)
1434 : : return -ENOBUFS;
1435 : :
1436 [ # # ]: 0 : if (nb_mc_addr > port->max_mcast_addrs) {
1437 : 0 : sfc_err(sa, "too many multicast addresses: %u > %u",
1438 : : nb_mc_addr, port->max_mcast_addrs);
1439 : 0 : return -EINVAL;
1440 : : }
1441 : :
1442 [ # # ]: 0 : for (i = 0; i < nb_mc_addr; ++i) {
1443 : 0 : rte_memcpy(mc_addrs, mc_addr_set[i].addr_bytes,
1444 : : EFX_MAC_ADDR_LEN);
1445 : 0 : mc_addrs += EFX_MAC_ADDR_LEN;
1446 : : }
1447 : :
1448 : 0 : port->nb_mcast_addrs = nb_mc_addr;
1449 : :
1450 [ # # ]: 0 : if (sa->state != SFC_ETHDEV_STARTED)
1451 : : return 0;
1452 : :
1453 : 0 : rc = efx_mac_multicast_list_set(sa->nic, port->mcast_addrs,
1454 : : port->nb_mcast_addrs);
1455 [ # # ]: 0 : if (rc != 0)
1456 : 0 : sfc_err(sa, "cannot set multicast address list (rc = %u)", rc);
1457 : :
1458 : : SFC_ASSERT(rc >= 0);
1459 : 0 : return -rc;
1460 : : }
1461 : :
1462 : : /*
1463 : : * The function is used by the secondary process as well. It must not
1464 : : * use any process-local pointers from the adapter data.
1465 : : */
1466 : : static void
1467 : 0 : sfc_rx_queue_info_get(struct rte_eth_dev *dev, uint16_t ethdev_qid,
1468 : : struct rte_eth_rxq_info *qinfo)
1469 : : {
1470 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1471 : 0 : sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1472 : : struct sfc_rxq_info *rxq_info;
1473 : :
1474 : 0 : rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1475 : :
1476 : 0 : qinfo->mp = rxq_info->refill_mb_pool;
1477 : 0 : qinfo->conf.rx_free_thresh = rxq_info->refill_threshold;
1478 : 0 : qinfo->conf.rx_drop_en = 1;
1479 : 0 : qinfo->conf.rx_deferred_start = rxq_info->deferred_start;
1480 : 0 : qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
1481 [ # # ]: 0 : if (rxq_info->type_flags & EFX_RXQ_FLAG_SCATTER) {
1482 : 0 : qinfo->conf.offloads |= RTE_ETH_RX_OFFLOAD_SCATTER;
1483 : 0 : qinfo->scattered_rx = 1;
1484 : : }
1485 : 0 : qinfo->nb_desc = rxq_info->entries;
1486 : 0 : }
1487 : :
1488 : : /*
1489 : : * The function is used by the secondary process as well. It must not
1490 : : * use any process-local pointers from the adapter data.
1491 : : */
1492 : : static void
1493 : 0 : sfc_tx_queue_info_get(struct rte_eth_dev *dev, uint16_t ethdev_qid,
1494 : : struct rte_eth_txq_info *qinfo)
1495 : : {
1496 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1497 : : struct sfc_txq_info *txq_info;
1498 : :
1499 : : SFC_ASSERT(ethdev_qid < sas->ethdev_txq_count);
1500 : :
1501 : 0 : txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
1502 : :
1503 : : memset(qinfo, 0, sizeof(*qinfo));
1504 : :
1505 : 0 : qinfo->conf.offloads = txq_info->offloads;
1506 : 0 : qinfo->conf.tx_free_thresh = txq_info->free_thresh;
1507 : 0 : qinfo->conf.tx_deferred_start = txq_info->deferred_start;
1508 : 0 : qinfo->nb_desc = txq_info->entries;
1509 : 0 : }
1510 : :
1511 : : /*
1512 : : * The function is used by the secondary process as well. It must not
1513 : : * use any process-local pointers from the adapter data.
1514 : : */
1515 : : static int
1516 : 0 : sfc_rx_queue_count(void *rx_queue)
1517 : : {
1518 : : struct sfc_dp_rxq *dp_rxq = rx_queue;
1519 : : const struct sfc_dp_rx *dp_rx;
1520 : : struct sfc_rxq_info *rxq_info;
1521 : :
1522 : 0 : dp_rx = sfc_dp_rx_by_dp_rxq(dp_rxq);
1523 : 0 : rxq_info = sfc_rxq_info_by_dp_rxq(dp_rxq);
1524 : :
1525 [ # # ]: 0 : if ((rxq_info->state & SFC_RXQ_STARTED) == 0)
1526 : : return 0;
1527 : :
1528 : 0 : return dp_rx->qdesc_npending(dp_rxq);
1529 : : }
1530 : :
1531 : : /*
1532 : : * The function is used by the secondary process as well. It must not
1533 : : * use any process-local pointers from the adapter data.
1534 : : */
1535 : : static int
1536 : 0 : sfc_rx_descriptor_status(void *queue, uint16_t offset)
1537 : : {
1538 : : struct sfc_dp_rxq *dp_rxq = queue;
1539 : : const struct sfc_dp_rx *dp_rx;
1540 : :
1541 : 0 : dp_rx = sfc_dp_rx_by_dp_rxq(dp_rxq);
1542 : :
1543 : 0 : return dp_rx->qdesc_status(dp_rxq, offset);
1544 : : }
1545 : :
1546 : : /*
1547 : : * The function is used by the secondary process as well. It must not
1548 : : * use any process-local pointers from the adapter data.
1549 : : */
1550 : : static int
1551 : 0 : sfc_tx_descriptor_status(void *queue, uint16_t offset)
1552 : : {
1553 : : struct sfc_dp_txq *dp_txq = queue;
1554 : : const struct sfc_dp_tx *dp_tx;
1555 : :
1556 : 0 : dp_tx = sfc_dp_tx_by_dp_txq(dp_txq);
1557 : :
1558 : 0 : return dp_tx->qdesc_status(dp_txq, offset);
1559 : : }
1560 : :
1561 : : static int
1562 : 0 : sfc_rx_queue_start(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1563 : : {
1564 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1565 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1566 : 0 : sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1567 : : struct sfc_rxq_info *rxq_info;
1568 : : sfc_sw_index_t sw_index;
1569 : : int rc;
1570 : :
1571 : 0 : sfc_log_init(sa, "RxQ=%u", ethdev_qid);
1572 : :
1573 : 0 : sfc_adapter_lock(sa);
1574 : :
1575 : : rc = EINVAL;
1576 [ # # ]: 0 : if (sa->state != SFC_ETHDEV_STARTED)
1577 : 0 : goto fail_not_started;
1578 : :
1579 : 0 : rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1580 [ # # ]: 0 : if (rxq_info->state != SFC_RXQ_INITIALIZED)
1581 : 0 : goto fail_not_setup;
1582 : :
1583 : : sw_index = sfc_rxq_sw_index_by_ethdev_rx_qid(sas, sfc_ethdev_qid);
1584 : 0 : rc = sfc_rx_qstart(sa, sw_index);
1585 [ # # ]: 0 : if (rc != 0)
1586 : 0 : goto fail_rx_qstart;
1587 : :
1588 : 0 : rxq_info->deferred_started = B_TRUE;
1589 : :
1590 : : sfc_adapter_unlock(sa);
1591 : :
1592 : 0 : return 0;
1593 : :
1594 : : fail_rx_qstart:
1595 : 0 : fail_not_setup:
1596 : 0 : fail_not_started:
1597 : : sfc_adapter_unlock(sa);
1598 : : SFC_ASSERT(rc > 0);
1599 : 0 : return -rc;
1600 : : }
1601 : :
1602 : : static int
1603 : 0 : sfc_rx_queue_stop(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1604 : : {
1605 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1606 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1607 : 0 : sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
1608 : : struct sfc_rxq_info *rxq_info;
1609 : : sfc_sw_index_t sw_index;
1610 : :
1611 : 0 : sfc_log_init(sa, "RxQ=%u", ethdev_qid);
1612 : :
1613 : 0 : sfc_adapter_lock(sa);
1614 : :
1615 : : sw_index = sfc_rxq_sw_index_by_ethdev_rx_qid(sas, sfc_ethdev_qid);
1616 : 0 : sfc_rx_qstop(sa, sw_index);
1617 : :
1618 : 0 : rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
1619 : 0 : rxq_info->deferred_started = B_FALSE;
1620 : :
1621 : : sfc_adapter_unlock(sa);
1622 : :
1623 : 0 : return 0;
1624 : : }
1625 : :
1626 : : static int
1627 : 0 : sfc_tx_queue_start(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1628 : : {
1629 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1630 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1631 : : struct sfc_txq_info *txq_info;
1632 : : sfc_sw_index_t sw_index;
1633 : : int rc;
1634 : :
1635 : 0 : sfc_log_init(sa, "TxQ = %u", ethdev_qid);
1636 : :
1637 : 0 : sfc_adapter_lock(sa);
1638 : :
1639 : : rc = EINVAL;
1640 [ # # ]: 0 : if (sa->state != SFC_ETHDEV_STARTED)
1641 : 0 : goto fail_not_started;
1642 : :
1643 : 0 : txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
1644 [ # # ]: 0 : if (txq_info->state != SFC_TXQ_INITIALIZED)
1645 : 0 : goto fail_not_setup;
1646 : :
1647 : : sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
1648 : 0 : rc = sfc_tx_qstart(sa, sw_index);
1649 [ # # ]: 0 : if (rc != 0)
1650 : 0 : goto fail_tx_qstart;
1651 : :
1652 : 0 : txq_info->deferred_started = B_TRUE;
1653 : :
1654 : : sfc_adapter_unlock(sa);
1655 : 0 : return 0;
1656 : :
1657 : : fail_tx_qstart:
1658 : :
1659 : 0 : fail_not_setup:
1660 : 0 : fail_not_started:
1661 : : sfc_adapter_unlock(sa);
1662 : : SFC_ASSERT(rc > 0);
1663 : 0 : return -rc;
1664 : : }
1665 : :
1666 : : static int
1667 : 0 : sfc_tx_queue_stop(struct rte_eth_dev *dev, uint16_t ethdev_qid)
1668 : : {
1669 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1670 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1671 : : struct sfc_txq_info *txq_info;
1672 : : sfc_sw_index_t sw_index;
1673 : :
1674 : 0 : sfc_log_init(sa, "TxQ = %u", ethdev_qid);
1675 : :
1676 : 0 : sfc_adapter_lock(sa);
1677 : :
1678 : : sw_index = sfc_txq_sw_index_by_ethdev_tx_qid(sas, ethdev_qid);
1679 : 0 : sfc_tx_qstop(sa, sw_index);
1680 : :
1681 : 0 : txq_info = sfc_txq_info_by_ethdev_qid(sas, ethdev_qid);
1682 : 0 : txq_info->deferred_started = B_FALSE;
1683 : :
1684 : : sfc_adapter_unlock(sa);
1685 : 0 : return 0;
1686 : : }
1687 : :
1688 : : static efx_tunnel_protocol_t
1689 : : sfc_tunnel_rte_type_to_efx_udp_proto(enum rte_eth_tunnel_type rte_type)
1690 : : {
1691 : 0 : switch (rte_type) {
1692 : : case RTE_ETH_TUNNEL_TYPE_VXLAN:
1693 : : return EFX_TUNNEL_PROTOCOL_VXLAN;
1694 : : case RTE_ETH_TUNNEL_TYPE_GENEVE:
1695 : : return EFX_TUNNEL_PROTOCOL_GENEVE;
1696 : : default:
1697 : : return EFX_TUNNEL_NPROTOS;
1698 : : }
1699 : : }
1700 : :
1701 : : enum sfc_udp_tunnel_op_e {
1702 : : SFC_UDP_TUNNEL_ADD_PORT,
1703 : : SFC_UDP_TUNNEL_DEL_PORT,
1704 : : };
1705 : :
1706 : : static int
1707 [ # # ]: 0 : sfc_dev_udp_tunnel_op(struct rte_eth_dev *dev,
1708 : : struct rte_eth_udp_tunnel *tunnel_udp,
1709 : : enum sfc_udp_tunnel_op_e op)
1710 : : {
1711 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1712 : : efx_tunnel_protocol_t tunnel_proto;
1713 : : int rc;
1714 : :
1715 [ # # # # ]: 0 : sfc_log_init(sa, "%s udp_port=%u prot_type=%u",
1716 : : (op == SFC_UDP_TUNNEL_ADD_PORT) ? "add" :
1717 : : (op == SFC_UDP_TUNNEL_DEL_PORT) ? "delete" : "unknown",
1718 : : tunnel_udp->udp_port, tunnel_udp->prot_type);
1719 : :
1720 : : tunnel_proto =
1721 [ # # # ]: 0 : sfc_tunnel_rte_type_to_efx_udp_proto(tunnel_udp->prot_type);
1722 : : if (tunnel_proto >= EFX_TUNNEL_NPROTOS) {
1723 : : rc = ENOTSUP;
1724 : 0 : goto fail_bad_proto;
1725 : : }
1726 : :
1727 : 0 : sfc_adapter_lock(sa);
1728 : :
1729 [ # # # ]: 0 : switch (op) {
1730 : 0 : case SFC_UDP_TUNNEL_ADD_PORT:
1731 : 0 : rc = efx_tunnel_config_udp_add(sa->nic,
1732 : 0 : tunnel_udp->udp_port,
1733 : : tunnel_proto);
1734 : 0 : break;
1735 : 0 : case SFC_UDP_TUNNEL_DEL_PORT:
1736 : 0 : rc = efx_tunnel_config_udp_remove(sa->nic,
1737 : 0 : tunnel_udp->udp_port,
1738 : : tunnel_proto);
1739 : 0 : break;
1740 : 0 : default:
1741 : : rc = EINVAL;
1742 : 0 : goto fail_bad_op;
1743 : : }
1744 : :
1745 [ # # ]: 0 : if (rc != 0)
1746 : 0 : goto fail_op;
1747 : :
1748 [ # # ]: 0 : if (sa->state == SFC_ETHDEV_STARTED) {
1749 : 0 : rc = efx_tunnel_reconfigure(sa->nic);
1750 [ # # ]: 0 : if (rc == EAGAIN) {
1751 : : /*
1752 : : * Configuration is accepted by FW and MC reboot
1753 : : * is initiated to apply the changes. MC reboot
1754 : : * will be handled in a usual way (MC reboot
1755 : : * event on management event queue and adapter
1756 : : * restart).
1757 : : */
1758 : : rc = 0;
1759 [ # # ]: 0 : } else if (rc != 0) {
1760 : 0 : goto fail_reconfigure;
1761 : : }
1762 : : }
1763 : :
1764 : : sfc_adapter_unlock(sa);
1765 : 0 : return 0;
1766 : :
1767 : : fail_reconfigure:
1768 : : /* Remove/restore entry since the change makes the trouble */
1769 [ # # ]: 0 : switch (op) {
1770 : 0 : case SFC_UDP_TUNNEL_ADD_PORT:
1771 : 0 : (void)efx_tunnel_config_udp_remove(sa->nic,
1772 : 0 : tunnel_udp->udp_port,
1773 : : tunnel_proto);
1774 : 0 : break;
1775 : 0 : case SFC_UDP_TUNNEL_DEL_PORT:
1776 : 0 : (void)efx_tunnel_config_udp_add(sa->nic,
1777 : 0 : tunnel_udp->udp_port,
1778 : : tunnel_proto);
1779 : 0 : break;
1780 : : }
1781 : :
1782 : 0 : fail_op:
1783 : 0 : fail_bad_op:
1784 : : sfc_adapter_unlock(sa);
1785 : :
1786 : 0 : fail_bad_proto:
1787 : : SFC_ASSERT(rc > 0);
1788 : 0 : return -rc;
1789 : : }
1790 : :
1791 : : static int
1792 : 0 : sfc_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
1793 : : struct rte_eth_udp_tunnel *tunnel_udp)
1794 : : {
1795 : 0 : return sfc_dev_udp_tunnel_op(dev, tunnel_udp, SFC_UDP_TUNNEL_ADD_PORT);
1796 : : }
1797 : :
1798 : : static int
1799 : 0 : sfc_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
1800 : : struct rte_eth_udp_tunnel *tunnel_udp)
1801 : : {
1802 : 0 : return sfc_dev_udp_tunnel_op(dev, tunnel_udp, SFC_UDP_TUNNEL_DEL_PORT);
1803 : : }
1804 : :
1805 : : /*
1806 : : * The function is used by the secondary process as well. It must not
1807 : : * use any process-local pointers from the adapter data.
1808 : : */
1809 : : static int
1810 [ # # ]: 0 : sfc_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1811 : : struct rte_eth_rss_conf *rss_conf)
1812 : : {
1813 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1814 : 0 : struct sfc_rss *rss = &sas->rss;
1815 : :
1816 [ # # ]: 0 : if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE)
1817 : : return -ENOTSUP;
1818 : :
1819 : : /*
1820 : : * Mapping of hash configuration between RTE and EFX is not one-to-one,
1821 : : * hence, conversion is done here to derive a correct set of RTE_ETH_RSS
1822 : : * flags which corresponds to the active EFX configuration stored
1823 : : * locally in 'sfc_adapter' and kept up-to-date
1824 : : */
1825 : 0 : rss_conf->rss_hf = sfc_rx_hf_efx_to_rte(rss, rss->hash_types);
1826 : 0 : rss_conf->rss_key_len = EFX_RSS_KEY_SIZE;
1827 [ # # ]: 0 : if (rss_conf->rss_key != NULL)
1828 : : rte_memcpy(rss_conf->rss_key, rss->key, EFX_RSS_KEY_SIZE);
1829 : :
1830 : : return 0;
1831 : : }
1832 : :
1833 : : static int
1834 [ # # ]: 0 : sfc_dev_rss_hash_update(struct rte_eth_dev *dev,
1835 : : struct rte_eth_rss_conf *rss_conf)
1836 : : {
1837 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1838 : : struct sfc_rss *rss = &sfc_sa2shared(sa)->rss;
1839 : : unsigned int efx_hash_types;
1840 : : unsigned int n_contexts;
1841 : : unsigned int mode_i = 0;
1842 : : unsigned int key_i = 0;
1843 : : uint32_t contexts[2];
1844 : : unsigned int i = 0;
1845 : : int rc = 0;
1846 : :
1847 [ # # ]: 0 : if (sfc_sa2shared(sa)->isolated)
1848 : : return -ENOTSUP;
1849 : :
1850 [ # # ]: 0 : if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE) {
1851 : 0 : sfc_err(sa, "RSS is not available");
1852 : 0 : return -ENOTSUP;
1853 : : }
1854 : :
1855 [ # # ]: 0 : if (rss->channels == 0) {
1856 : 0 : sfc_err(sa, "RSS is not configured");
1857 : 0 : return -EINVAL;
1858 : : }
1859 : :
1860 [ # # ]: 0 : if ((rss_conf->rss_key != NULL) &&
1861 [ # # ]: 0 : (rss_conf->rss_key_len != sizeof(rss->key))) {
1862 : 0 : sfc_err(sa, "RSS key size is wrong (should be %zu)",
1863 : : sizeof(rss->key));
1864 : 0 : return -EINVAL;
1865 : : }
1866 : :
1867 : 0 : sfc_adapter_lock(sa);
1868 : :
1869 : 0 : rc = sfc_rx_hf_rte_to_efx(sa, rss_conf->rss_hf, &efx_hash_types);
1870 [ # # ]: 0 : if (rc != 0)
1871 : 0 : goto fail_rx_hf_rte_to_efx;
1872 : :
1873 : 0 : contexts[0] = EFX_RSS_CONTEXT_DEFAULT;
1874 : 0 : contexts[1] = rss->dummy_ctx.nic_handle;
1875 [ # # ]: 0 : n_contexts = (rss->dummy_ctx.nic_handle_refcnt == 0) ? 1 : 2;
1876 : :
1877 [ # # ]: 0 : for (mode_i = 0; mode_i < n_contexts; mode_i++) {
1878 : 0 : rc = efx_rx_scale_mode_set(sa->nic, contexts[mode_i],
1879 : : rss->hash_alg, efx_hash_types,
1880 : : B_TRUE);
1881 [ # # ]: 0 : if (rc != 0)
1882 : 0 : goto fail_scale_mode_set;
1883 : : }
1884 : :
1885 [ # # ]: 0 : if (rss_conf->rss_key != NULL) {
1886 [ # # ]: 0 : if (sa->state == SFC_ETHDEV_STARTED) {
1887 [ # # ]: 0 : for (key_i = 0; key_i < n_contexts; key_i++) {
1888 : 0 : rc = efx_rx_scale_key_set(sa->nic,
1889 : : contexts[key_i],
1890 : : rss_conf->rss_key,
1891 : : sizeof(rss->key));
1892 [ # # ]: 0 : if (rc != 0)
1893 : 0 : goto fail_scale_key_set;
1894 : : }
1895 : : }
1896 : :
1897 : 0 : rte_memcpy(rss->key, rss_conf->rss_key, sizeof(rss->key));
1898 : : }
1899 : :
1900 : 0 : rss->hash_types = efx_hash_types;
1901 : :
1902 : : sfc_adapter_unlock(sa);
1903 : :
1904 : 0 : return 0;
1905 : :
1906 : : fail_scale_key_set:
1907 [ # # ]: 0 : for (i = 0; i < key_i; i++) {
1908 [ # # ]: 0 : if (efx_rx_scale_key_set(sa->nic, contexts[i], rss->key,
1909 : : sizeof(rss->key)) != 0)
1910 : 0 : sfc_err(sa, "failed to restore RSS key");
1911 : : }
1912 : :
1913 : 0 : fail_scale_mode_set:
1914 [ # # ]: 0 : for (i = 0; i < mode_i; i++) {
1915 [ # # ]: 0 : if (efx_rx_scale_mode_set(sa->nic, contexts[i],
1916 : : EFX_RX_HASHALG_TOEPLITZ,
1917 : : rss->hash_types, B_TRUE) != 0)
1918 : 0 : sfc_err(sa, "failed to restore RSS mode");
1919 : : }
1920 : :
1921 : 0 : fail_rx_hf_rte_to_efx:
1922 : : sfc_adapter_unlock(sa);
1923 : 0 : return -rc;
1924 : : }
1925 : :
1926 : : /*
1927 : : * The function is used by the secondary process as well. It must not
1928 : : * use any process-local pointers from the adapter data.
1929 : : */
1930 : : static int
1931 [ # # ]: 0 : sfc_dev_rss_reta_query(struct rte_eth_dev *dev,
1932 : : struct rte_eth_rss_reta_entry64 *reta_conf,
1933 : : uint16_t reta_size)
1934 : : {
1935 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1936 : : struct sfc_rss *rss = &sas->rss;
1937 : : int entry;
1938 : :
1939 [ # # # # ]: 0 : if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE || sas->isolated)
1940 : : return -ENOTSUP;
1941 : :
1942 [ # # ]: 0 : if (rss->channels == 0)
1943 : : return -EINVAL;
1944 : :
1945 [ # # ]: 0 : if (reta_size != EFX_RSS_TBL_SIZE)
1946 : : return -EINVAL;
1947 : :
1948 [ # # ]: 0 : for (entry = 0; entry < reta_size; entry++) {
1949 : 0 : int grp = entry / RTE_ETH_RETA_GROUP_SIZE;
1950 : 0 : int grp_idx = entry % RTE_ETH_RETA_GROUP_SIZE;
1951 : :
1952 [ # # ]: 0 : if ((reta_conf[grp].mask >> grp_idx) & 1)
1953 : 0 : reta_conf[grp].reta[grp_idx] = rss->tbl[entry];
1954 : : }
1955 : :
1956 : : return 0;
1957 : : }
1958 : :
1959 : : static int
1960 [ # # ]: 0 : sfc_dev_rss_reta_update(struct rte_eth_dev *dev,
1961 : : struct rte_eth_rss_reta_entry64 *reta_conf,
1962 : : uint16_t reta_size)
1963 : : {
1964 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1965 : : struct sfc_rss *rss = &sfc_sa2shared(sa)->rss;
1966 : : unsigned int *rss_tbl_new;
1967 : : uint16_t entry;
1968 : : int rc = 0;
1969 : :
1970 : :
1971 [ # # ]: 0 : if (sfc_sa2shared(sa)->isolated)
1972 : : return -ENOTSUP;
1973 : :
1974 [ # # ]: 0 : if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE) {
1975 : 0 : sfc_err(sa, "RSS is not available");
1976 : 0 : return -ENOTSUP;
1977 : : }
1978 : :
1979 [ # # ]: 0 : if (rss->channels == 0) {
1980 : 0 : sfc_err(sa, "RSS is not configured");
1981 : 0 : return -EINVAL;
1982 : : }
1983 : :
1984 [ # # ]: 0 : if (reta_size != EFX_RSS_TBL_SIZE) {
1985 : 0 : sfc_err(sa, "RETA size is wrong (should be %u)",
1986 : : EFX_RSS_TBL_SIZE);
1987 : 0 : return -EINVAL;
1988 : : }
1989 : :
1990 : 0 : rss_tbl_new = rte_zmalloc("rss_tbl_new", sizeof(rss->tbl), 0);
1991 [ # # ]: 0 : if (rss_tbl_new == NULL)
1992 : : return -ENOMEM;
1993 : :
1994 : 0 : sfc_adapter_lock(sa);
1995 : :
1996 [ # # ]: 0 : rte_memcpy(rss_tbl_new, rss->tbl, sizeof(rss->tbl));
1997 : :
1998 [ # # ]: 0 : for (entry = 0; entry < reta_size; entry++) {
1999 : 0 : int grp_idx = entry % RTE_ETH_RETA_GROUP_SIZE;
2000 : : struct rte_eth_rss_reta_entry64 *grp;
2001 : :
2002 : 0 : grp = &reta_conf[entry / RTE_ETH_RETA_GROUP_SIZE];
2003 : :
2004 [ # # ]: 0 : if (grp->mask & (1ull << grp_idx)) {
2005 [ # # ]: 0 : if (grp->reta[grp_idx] >= rss->channels) {
2006 : : rc = EINVAL;
2007 : 0 : goto bad_reta_entry;
2008 : : }
2009 : 0 : rss_tbl_new[entry] = grp->reta[grp_idx];
2010 : : }
2011 : : }
2012 : :
2013 [ # # ]: 0 : if (sa->state == SFC_ETHDEV_STARTED) {
2014 : 0 : rc = efx_rx_scale_tbl_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
2015 : : rss_tbl_new, EFX_RSS_TBL_SIZE);
2016 [ # # ]: 0 : if (rc != 0)
2017 : 0 : goto fail_scale_tbl_set;
2018 : : }
2019 : :
2020 : : rte_memcpy(rss->tbl, rss_tbl_new, sizeof(rss->tbl));
2021 : :
2022 : 0 : fail_scale_tbl_set:
2023 : 0 : bad_reta_entry:
2024 : : sfc_adapter_unlock(sa);
2025 : :
2026 : 0 : rte_free(rss_tbl_new);
2027 : :
2028 : : SFC_ASSERT(rc >= 0);
2029 : 0 : return -rc;
2030 : : }
2031 : :
2032 : : static int
2033 : 0 : sfc_dev_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
2034 : : const struct rte_flow_ops **ops)
2035 : : {
2036 : 0 : *ops = &sfc_flow_ops;
2037 : 0 : return 0;
2038 : : }
2039 : :
2040 : : static int
2041 [ # # ]: 0 : sfc_pool_ops_supported(struct rte_eth_dev *dev, const char *pool)
2042 : : {
2043 : : const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
2044 : :
2045 : : /*
2046 : : * If Rx datapath does not provide callback to check mempool,
2047 : : * all pools are supported.
2048 : : */
2049 [ # # ]: 0 : if (sap->dp_rx->pool_ops_supported == NULL)
2050 : : return 1;
2051 : :
2052 : 0 : return sap->dp_rx->pool_ops_supported(pool);
2053 : : }
2054 : :
2055 : : static int
2056 : 0 : sfc_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t ethdev_qid)
2057 : : {
2058 : : const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
2059 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2060 : 0 : sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
2061 : : struct sfc_rxq_info *rxq_info;
2062 : :
2063 : 0 : rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
2064 : :
2065 : 0 : return sap->dp_rx->intr_enable(rxq_info->dp);
2066 : : }
2067 : :
2068 : : static int
2069 : 0 : sfc_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t ethdev_qid)
2070 : : {
2071 : : const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
2072 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2073 : 0 : sfc_ethdev_qid_t sfc_ethdev_qid = ethdev_qid;
2074 : : struct sfc_rxq_info *rxq_info;
2075 : :
2076 : 0 : rxq_info = sfc_rxq_info_by_ethdev_qid(sas, sfc_ethdev_qid);
2077 : :
2078 : 0 : return sap->dp_rx->intr_disable(rxq_info->dp);
2079 : : }
2080 : :
2081 : : struct sfc_mport_journal_ctx {
2082 : : struct sfc_adapter *sa;
2083 : : uint16_t switch_domain_id;
2084 : : uint32_t mcdi_handle;
2085 : : bool controllers_assigned;
2086 : : efx_pcie_interface_t *controllers;
2087 : : size_t nb_controllers;
2088 : : };
2089 : :
2090 : : static int
2091 : 0 : sfc_journal_ctx_add_controller(struct sfc_mport_journal_ctx *ctx,
2092 : : efx_pcie_interface_t intf)
2093 : : {
2094 : : efx_pcie_interface_t *new_controllers;
2095 : : size_t i, target;
2096 : : size_t new_size;
2097 : :
2098 [ # # ]: 0 : if (ctx->controllers == NULL) {
2099 : 0 : ctx->controllers = rte_malloc("sfc_controller_mapping",
2100 : : sizeof(ctx->controllers[0]), 0);
2101 [ # # ]: 0 : if (ctx->controllers == NULL)
2102 : : return ENOMEM;
2103 : :
2104 : 0 : ctx->controllers[0] = intf;
2105 : 0 : ctx->nb_controllers = 1;
2106 : :
2107 : 0 : return 0;
2108 : : }
2109 : :
2110 [ # # ]: 0 : for (i = 0; i < ctx->nb_controllers; i++) {
2111 [ # # ]: 0 : if (ctx->controllers[i] == intf)
2112 : : return 0;
2113 [ # # ]: 0 : if (ctx->controllers[i] > intf)
2114 : : break;
2115 : : }
2116 : : target = i;
2117 : :
2118 : 0 : ctx->nb_controllers += 1;
2119 : 0 : new_size = ctx->nb_controllers * sizeof(ctx->controllers[0]);
2120 : :
2121 : 0 : new_controllers = rte_realloc(ctx->controllers, new_size, 0);
2122 [ # # ]: 0 : if (new_controllers == NULL) {
2123 : 0 : rte_free(ctx->controllers);
2124 : 0 : return ENOMEM;
2125 : : }
2126 : 0 : ctx->controllers = new_controllers;
2127 : :
2128 [ # # ]: 0 : for (i = target + 1; i < ctx->nb_controllers; i++)
2129 : 0 : ctx->controllers[i] = ctx->controllers[i - 1];
2130 : :
2131 : 0 : ctx->controllers[target] = intf;
2132 : :
2133 : 0 : return 0;
2134 : : }
2135 : :
2136 : : static efx_rc_t
2137 : 0 : sfc_process_mport_journal_entry(struct sfc_mport_journal_ctx *ctx,
2138 : : efx_mport_desc_t *mport)
2139 : : {
2140 : : struct sfc_mae_switch_port_request req;
2141 : : efx_mport_sel_t entity_selector;
2142 : : efx_mport_sel_t ethdev_mport;
2143 : : uint16_t switch_port_id;
2144 : : efx_rc_t efx_rc;
2145 : : int rc;
2146 : :
2147 : 0 : sfc_dbg(ctx->sa,
2148 : : "processing mport id %u (controller %u pf %u vf %u)",
2149 : : mport->emd_id.id, mport->emd_vnic.ev_intf,
2150 : : mport->emd_vnic.ev_pf, mport->emd_vnic.ev_vf);
2151 : 0 : efx_mae_mport_invalid(ðdev_mport);
2152 : :
2153 [ # # ]: 0 : if (!ctx->controllers_assigned) {
2154 : 0 : rc = sfc_journal_ctx_add_controller(ctx,
2155 : : mport->emd_vnic.ev_intf);
2156 [ # # ]: 0 : if (rc != 0)
2157 : : return rc;
2158 : : }
2159 : :
2160 : : /* Build Mport selector */
2161 : 0 : efx_rc = efx_mae_mport_by_pcie_mh_function(mport->emd_vnic.ev_intf,
2162 : 0 : mport->emd_vnic.ev_pf,
2163 : 0 : mport->emd_vnic.ev_vf,
2164 : : &entity_selector);
2165 [ # # ]: 0 : if (efx_rc != 0) {
2166 : 0 : sfc_err(ctx->sa, "failed to build entity mport selector for c%upf%uvf%u",
2167 : : mport->emd_vnic.ev_intf,
2168 : : mport->emd_vnic.ev_pf,
2169 : : mport->emd_vnic.ev_vf);
2170 : 0 : return efx_rc;
2171 : : }
2172 : :
2173 : 0 : rc = sfc_mae_switch_port_id_by_entity(ctx->switch_domain_id,
2174 : : &entity_selector,
2175 : : SFC_MAE_SWITCH_PORT_REPRESENTOR,
2176 : : &switch_port_id);
2177 [ # # # ]: 0 : switch (rc) {
2178 : : case 0:
2179 : : /* Already registered */
2180 : : break;
2181 : 0 : case ENOENT:
2182 : : /*
2183 : : * No representor has been created for this entity.
2184 : : * Create a dummy switch registry entry with an invalid ethdev
2185 : : * mport selector. When a corresponding representor is created,
2186 : : * this entry will be updated.
2187 : : */
2188 : 0 : req.type = SFC_MAE_SWITCH_PORT_REPRESENTOR;
2189 : 0 : req.entity_mportp = &entity_selector;
2190 : 0 : req.ethdev_mportp = ðdev_mport;
2191 : 0 : req.ethdev_port_id = RTE_MAX_ETHPORTS;
2192 : 0 : req.port_data.repr.intf = mport->emd_vnic.ev_intf;
2193 : 0 : req.port_data.repr.pf = mport->emd_vnic.ev_pf;
2194 : 0 : req.port_data.repr.vf = mport->emd_vnic.ev_vf;
2195 : :
2196 : 0 : rc = sfc_mae_assign_switch_port(ctx->switch_domain_id,
2197 : : &req, &switch_port_id);
2198 [ # # ]: 0 : if (rc != 0) {
2199 : 0 : sfc_err(ctx->sa,
2200 : : "failed to assign MAE switch port for c%upf%uvf%u: %s",
2201 : : mport->emd_vnic.ev_intf,
2202 : : mport->emd_vnic.ev_pf,
2203 : : mport->emd_vnic.ev_vf,
2204 : : rte_strerror(rc));
2205 : 0 : return rc;
2206 : : }
2207 : : break;
2208 : 0 : default:
2209 : 0 : sfc_err(ctx->sa, "failed to find MAE switch port for c%upf%uvf%u: %s",
2210 : : mport->emd_vnic.ev_intf,
2211 : : mport->emd_vnic.ev_pf,
2212 : : mport->emd_vnic.ev_vf,
2213 : : rte_strerror(rc));
2214 : 0 : return rc;
2215 : : }
2216 : :
2217 : : return 0;
2218 : : }
2219 : :
2220 : : static efx_rc_t
2221 : 0 : sfc_process_mport_journal_cb(void *data, efx_mport_desc_t *mport,
2222 : : size_t mport_len)
2223 : : {
2224 : : struct sfc_mport_journal_ctx *ctx = data;
2225 : :
2226 [ # # # # ]: 0 : if (ctx == NULL || ctx->sa == NULL) {
2227 : 0 : SFC_GENERIC_LOG(ERR, "received NULL context or SFC adapter");
2228 : 0 : return EINVAL;
2229 : : }
2230 : :
2231 [ # # ]: 0 : if (mport_len != sizeof(*mport)) {
2232 : 0 : sfc_err(ctx->sa, "actual and expected mport buffer sizes differ");
2233 : 0 : return EINVAL;
2234 : : }
2235 : :
2236 : : SFC_ASSERT(sfc_adapter_is_locked(ctx->sa));
2237 : :
2238 : : /*
2239 : : * If a zombie flag is set, it means the mport has been marked for
2240 : : * deletion and cannot be used for any new operations. The mport will
2241 : : * be destroyed completely once all references to it are released.
2242 : : */
2243 [ # # ]: 0 : if (mport->emd_zombie) {
2244 : 0 : sfc_dbg(ctx->sa, "mport is a zombie, skipping");
2245 : 0 : return 0;
2246 : : }
2247 [ # # ]: 0 : if (mport->emd_type != EFX_MPORT_TYPE_VNIC) {
2248 : 0 : sfc_dbg(ctx->sa, "mport is not a VNIC, skipping");
2249 : 0 : return 0;
2250 : : }
2251 [ # # ]: 0 : if (mport->emd_vnic.ev_client_type != EFX_MPORT_VNIC_CLIENT_FUNCTION) {
2252 : 0 : sfc_dbg(ctx->sa, "mport is not a function, skipping");
2253 : 0 : return 0;
2254 : : }
2255 [ # # ]: 0 : if (mport->emd_vnic.ev_handle == ctx->mcdi_handle) {
2256 : 0 : sfc_dbg(ctx->sa, "mport is this driver instance, skipping");
2257 : 0 : return 0;
2258 : : }
2259 : :
2260 : 0 : return sfc_process_mport_journal_entry(ctx, mport);
2261 : : }
2262 : :
2263 : : static int
2264 : 0 : sfc_process_mport_journal(struct sfc_adapter *sa)
2265 : : {
2266 : : struct sfc_mport_journal_ctx ctx;
2267 : : const efx_pcie_interface_t *controllers;
2268 : : size_t nb_controllers;
2269 : : efx_rc_t efx_rc;
2270 : : int rc;
2271 : :
2272 : : memset(&ctx, 0, sizeof(ctx));
2273 : 0 : ctx.sa = sa;
2274 : 0 : ctx.switch_domain_id = sa->mae.switch_domain_id;
2275 : :
2276 : 0 : efx_rc = efx_mcdi_get_own_client_handle(sa->nic, &ctx.mcdi_handle);
2277 [ # # ]: 0 : if (efx_rc != 0) {
2278 : 0 : sfc_err(sa, "failed to get own MCDI handle");
2279 : : SFC_ASSERT(efx_rc > 0);
2280 : 0 : return efx_rc;
2281 : : }
2282 : :
2283 : 0 : rc = sfc_mae_switch_domain_controllers(ctx.switch_domain_id,
2284 : : &controllers, &nb_controllers);
2285 [ # # ]: 0 : if (rc != 0) {
2286 : 0 : sfc_err(sa, "failed to get controller mapping");
2287 : 0 : return rc;
2288 : : }
2289 : :
2290 : 0 : ctx.controllers_assigned = controllers != NULL;
2291 : 0 : ctx.controllers = NULL;
2292 : 0 : ctx.nb_controllers = 0;
2293 : :
2294 : 0 : efx_rc = efx_mae_read_mport_journal(sa->nic,
2295 : : sfc_process_mport_journal_cb, &ctx);
2296 [ # # ]: 0 : if (efx_rc != 0) {
2297 : 0 : sfc_err(sa, "failed to process MAE mport journal");
2298 : : SFC_ASSERT(efx_rc > 0);
2299 : 0 : return efx_rc;
2300 : : }
2301 : :
2302 [ # # ]: 0 : if (controllers == NULL) {
2303 : 0 : rc = sfc_mae_switch_domain_map_controllers(ctx.switch_domain_id,
2304 : : ctx.controllers,
2305 : : ctx.nb_controllers);
2306 [ # # ]: 0 : if (rc != 0)
2307 : 0 : return rc;
2308 : : }
2309 : :
2310 : : return 0;
2311 : : }
2312 : :
2313 : : static void
2314 : 0 : sfc_count_representors_cb(enum sfc_mae_switch_port_type type,
2315 : : const efx_mport_sel_t *ethdev_mportp __rte_unused,
2316 : : uint16_t ethdev_port_id __rte_unused,
2317 : : const efx_mport_sel_t *entity_mportp __rte_unused,
2318 : : uint16_t switch_port_id __rte_unused,
2319 : : union sfc_mae_switch_port_data *port_datap
2320 : : __rte_unused,
2321 : : void *user_datap)
2322 : : {
2323 : : int *counter = user_datap;
2324 : :
2325 : : SFC_ASSERT(counter != NULL);
2326 : :
2327 [ # # ]: 0 : if (type == SFC_MAE_SWITCH_PORT_REPRESENTOR)
2328 : 0 : (*counter)++;
2329 : 0 : }
2330 : :
2331 : : struct sfc_get_representors_ctx {
2332 : : struct rte_eth_representor_info *info;
2333 : : struct sfc_adapter *sa;
2334 : : uint16_t switch_domain_id;
2335 : : const efx_pcie_interface_t *controllers;
2336 : : size_t nb_controllers;
2337 : : };
2338 : :
2339 : : static void
2340 : 0 : sfc_get_representors_cb(enum sfc_mae_switch_port_type type,
2341 : : const efx_mport_sel_t *ethdev_mportp __rte_unused,
2342 : : uint16_t ethdev_port_id __rte_unused,
2343 : : const efx_mport_sel_t *entity_mportp __rte_unused,
2344 : : uint16_t switch_port_id,
2345 : : union sfc_mae_switch_port_data *port_datap,
2346 : : void *user_datap)
2347 : : {
2348 : : struct sfc_get_representors_ctx *ctx = user_datap;
2349 : : struct rte_eth_representor_range *range;
2350 : : int ret;
2351 : : int rc;
2352 : :
2353 : : SFC_ASSERT(ctx != NULL);
2354 : : SFC_ASSERT(ctx->info != NULL);
2355 : : SFC_ASSERT(ctx->sa != NULL);
2356 : :
2357 [ # # ]: 0 : if (type != SFC_MAE_SWITCH_PORT_REPRESENTOR) {
2358 : 0 : sfc_dbg(ctx->sa, "not a representor, skipping");
2359 : 0 : return;
2360 : : }
2361 [ # # ]: 0 : if (ctx->info->nb_ranges >= ctx->info->nb_ranges_alloc) {
2362 : 0 : sfc_dbg(ctx->sa, "info structure is full already");
2363 : 0 : return;
2364 : : }
2365 : :
2366 : : range = &ctx->info->ranges[ctx->info->nb_ranges];
2367 : 0 : rc = sfc_mae_switch_controller_from_mapping(ctx->controllers,
2368 : : ctx->nb_controllers,
2369 : : port_datap->repr.intf,
2370 : : &range->controller);
2371 [ # # ]: 0 : if (rc != 0) {
2372 : 0 : sfc_err(ctx->sa, "invalid representor controller: %d",
2373 : : port_datap->repr.intf);
2374 : 0 : range->controller = -1;
2375 : : }
2376 : 0 : range->pf = port_datap->repr.pf;
2377 : 0 : range->id_base = switch_port_id;
2378 : 0 : range->id_end = switch_port_id;
2379 : :
2380 [ # # ]: 0 : if (port_datap->repr.vf != EFX_PCI_VF_INVALID) {
2381 : 0 : range->type = RTE_ETH_REPRESENTOR_VF;
2382 : 0 : range->vf = port_datap->repr.vf;
2383 : 0 : ret = snprintf(range->name, RTE_DEV_NAME_MAX_LEN,
2384 : : "c%dpf%dvf%d", range->controller, range->pf,
2385 : : range->vf);
2386 : : } else {
2387 : 0 : range->type = RTE_ETH_REPRESENTOR_PF;
2388 : 0 : ret = snprintf(range->name, RTE_DEV_NAME_MAX_LEN,
2389 : : "c%dpf%d", range->controller, range->pf);
2390 : : }
2391 [ # # ]: 0 : if (ret >= RTE_DEV_NAME_MAX_LEN) {
2392 : 0 : sfc_err(ctx->sa, "representor name has been truncated: %s",
2393 : : range->name);
2394 : : }
2395 : :
2396 : 0 : ctx->info->nb_ranges++;
2397 : : }
2398 : :
2399 : : static int
2400 : 0 : sfc_representor_info_get(struct rte_eth_dev *dev,
2401 : : struct rte_eth_representor_info *info)
2402 : : {
2403 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2404 : : struct sfc_get_representors_ctx get_repr_ctx;
2405 : : const efx_nic_cfg_t *nic_cfg;
2406 : : uint16_t switch_domain_id;
2407 : : uint32_t nb_repr;
2408 : : int controller;
2409 : : int rc;
2410 : :
2411 : 0 : sfc_adapter_lock(sa);
2412 : :
2413 [ # # ]: 0 : if (sa->mae.status != SFC_MAE_STATUS_ADMIN) {
2414 : : sfc_adapter_unlock(sa);
2415 : 0 : return -ENOTSUP;
2416 : : }
2417 : :
2418 : 0 : rc = sfc_process_mport_journal(sa);
2419 [ # # ]: 0 : if (rc != 0) {
2420 : : sfc_adapter_unlock(sa);
2421 : : SFC_ASSERT(rc > 0);
2422 : 0 : return -rc;
2423 : : }
2424 : :
2425 : 0 : switch_domain_id = sa->mae.switch_domain_id;
2426 : :
2427 : 0 : nb_repr = 0;
2428 : 0 : rc = sfc_mae_switch_ports_iterate(switch_domain_id,
2429 : : sfc_count_representors_cb,
2430 : : &nb_repr);
2431 [ # # ]: 0 : if (rc != 0) {
2432 : : sfc_adapter_unlock(sa);
2433 : : SFC_ASSERT(rc > 0);
2434 : 0 : return -rc;
2435 : : }
2436 : :
2437 [ # # ]: 0 : if (info == NULL) {
2438 : : sfc_adapter_unlock(sa);
2439 : 0 : return nb_repr;
2440 : : }
2441 : :
2442 : 0 : rc = sfc_mae_switch_domain_controllers(switch_domain_id,
2443 : : &get_repr_ctx.controllers,
2444 : : &get_repr_ctx.nb_controllers);
2445 [ # # ]: 0 : if (rc != 0) {
2446 : : sfc_adapter_unlock(sa);
2447 : : SFC_ASSERT(rc > 0);
2448 : 0 : return -rc;
2449 : : }
2450 : :
2451 : 0 : nic_cfg = efx_nic_cfg_get(sa->nic);
2452 : :
2453 : 0 : rc = sfc_mae_switch_domain_get_controller(switch_domain_id,
2454 : 0 : nic_cfg->enc_intf,
2455 : : &controller);
2456 [ # # ]: 0 : if (rc != 0) {
2457 : 0 : sfc_err(sa, "invalid controller: %d", nic_cfg->enc_intf);
2458 : 0 : controller = -1;
2459 : : }
2460 : :
2461 : 0 : info->controller = controller;
2462 : 0 : info->pf = nic_cfg->enc_pf;
2463 : :
2464 : 0 : get_repr_ctx.info = info;
2465 : 0 : get_repr_ctx.sa = sa;
2466 : 0 : get_repr_ctx.switch_domain_id = switch_domain_id;
2467 : 0 : rc = sfc_mae_switch_ports_iterate(switch_domain_id,
2468 : : sfc_get_representors_cb,
2469 : : &get_repr_ctx);
2470 [ # # ]: 0 : if (rc != 0) {
2471 : : sfc_adapter_unlock(sa);
2472 : : SFC_ASSERT(rc > 0);
2473 : 0 : return -rc;
2474 : : }
2475 : :
2476 : : sfc_adapter_unlock(sa);
2477 : 0 : return nb_repr;
2478 : : }
2479 : :
2480 : : static int
2481 : 0 : sfc_rx_metadata_negotiate(struct rte_eth_dev *dev, uint64_t *features)
2482 : : {
2483 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2484 : : uint64_t supported = 0;
2485 : :
2486 : 0 : sfc_adapter_lock(sa);
2487 : :
2488 [ # # ]: 0 : if ((sa->priv.dp_rx->features & SFC_DP_RX_FEAT_FLOW_FLAG) != 0)
2489 : : supported |= RTE_ETH_RX_METADATA_USER_FLAG;
2490 : :
2491 [ # # ]: 0 : if ((sa->priv.dp_rx->features & SFC_DP_RX_FEAT_FLOW_MARK) != 0)
2492 : 0 : supported |= RTE_ETH_RX_METADATA_USER_MARK;
2493 : :
2494 [ # # ]: 0 : if (sfc_ft_is_supported(sa))
2495 : 0 : supported |= RTE_ETH_RX_METADATA_TUNNEL_ID;
2496 : :
2497 : 0 : sa->negotiated_rx_metadata = supported & *features;
2498 : 0 : *features = sa->negotiated_rx_metadata;
2499 : :
2500 : : sfc_adapter_unlock(sa);
2501 : :
2502 : 0 : return 0;
2503 : : }
2504 : :
2505 : : /*
2506 : : * When adding support for new speeds/capabilities, make sure to adjust
2507 : : * validity checks conducted by 'sfc_fec_capa_check' for user input.
2508 : : */
2509 : : static unsigned int
2510 : 0 : sfc_fec_get_capa_speed_to_fec(uint32_t supported_caps,
2511 : : struct rte_eth_fec_capa *speed_fec_capa)
2512 : : {
2513 : : unsigned int num = 0;
2514 : : bool baser = false;
2515 : : bool rs = false;
2516 : :
2517 [ # # ]: 0 : if (supported_caps & EFX_PHY_CAP_FEC_BIT(BASER_FEC))
2518 : : baser = true;
2519 [ # # ]: 0 : if (supported_caps & EFX_PHY_CAP_FEC_BIT(RS_FEC))
2520 : : rs = true;
2521 : :
2522 : : /*
2523 : : * NOFEC can always be requested, but if the link technology for the
2524 : : * intended speed mandates FEC, doing so will not bring the link up.
2525 : : *
2526 : : * FW cannot report supported FEC modes per speed/link technology,
2527 : : * so use best-effort approximation to fill in the capabilities.
2528 : : *
2529 : : * Do not indicate 'AUTO'. This bit is reserved for user
2530 : : * input. It has nothing to do with capability reporting.
2531 : : */
2532 [ # # ]: 0 : if (supported_caps & (1u << EFX_PHY_CAP_10000FDX)) {
2533 [ # # ]: 0 : if (speed_fec_capa != NULL) {
2534 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_10G;
2535 : 0 : speed_fec_capa[num].capa =
2536 : : RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
2537 [ # # ]: 0 : if (baser) {
2538 : 0 : speed_fec_capa[num].capa |=
2539 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
2540 : : }
2541 : : }
2542 : : num++;
2543 : : }
2544 [ # # ]: 0 : if (supported_caps & (1u << EFX_PHY_CAP_25000FDX)) {
2545 [ # # ]: 0 : if (speed_fec_capa != NULL) {
2546 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_25G;
2547 : 0 : speed_fec_capa[num].capa =
2548 : : RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
2549 [ # # ]: 0 : if (baser) {
2550 : 0 : speed_fec_capa[num].capa |=
2551 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
2552 : : }
2553 [ # # ]: 0 : if (rs) {
2554 : 0 : speed_fec_capa[num].capa |=
2555 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
2556 : : }
2557 : : }
2558 : 0 : num++;
2559 : : }
2560 [ # # ]: 0 : if (supported_caps & (1u << EFX_PHY_CAP_40000FDX)) {
2561 [ # # ]: 0 : if (speed_fec_capa != NULL) {
2562 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_40G;
2563 : 0 : speed_fec_capa[num].capa =
2564 : : RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
2565 [ # # ]: 0 : if (baser) {
2566 : 0 : speed_fec_capa[num].capa |=
2567 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
2568 : : }
2569 : : }
2570 : 0 : num++;
2571 : : }
2572 [ # # ]: 0 : if (supported_caps & (1u << EFX_PHY_CAP_50000FDX)) {
2573 [ # # ]: 0 : if (speed_fec_capa != NULL) {
2574 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_50G;
2575 : 0 : speed_fec_capa[num].capa =
2576 : : RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
2577 [ # # ]: 0 : if (baser) {
2578 : 0 : speed_fec_capa[num].capa |=
2579 : : RTE_ETH_FEC_MODE_CAPA_MASK(BASER);
2580 : : }
2581 [ # # ]: 0 : if (rs) {
2582 : 0 : speed_fec_capa[num].capa |=
2583 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
2584 : : }
2585 : : }
2586 : 0 : num++;
2587 : : }
2588 [ # # ]: 0 : if (supported_caps & (1u << EFX_PHY_CAP_100000FDX)) {
2589 [ # # ]: 0 : if (speed_fec_capa != NULL) {
2590 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_100G;
2591 : 0 : speed_fec_capa[num].capa =
2592 : : RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
2593 [ # # ]: 0 : if (rs) {
2594 : 0 : speed_fec_capa[num].capa |=
2595 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
2596 : : }
2597 : : }
2598 : 0 : num++;
2599 : : }
2600 [ # # ]: 0 : if (supported_caps & (1u << EFX_PHY_CAP_200000FDX)) {
2601 [ # # ]: 0 : if (speed_fec_capa != NULL) {
2602 : 0 : speed_fec_capa[num].speed = RTE_ETH_SPEED_NUM_200G;
2603 : 0 : speed_fec_capa[num].capa =
2604 : : RTE_ETH_FEC_MODE_CAPA_MASK(NOFEC);
2605 [ # # ]: 0 : if (rs) {
2606 : 0 : speed_fec_capa[num].capa |=
2607 : : RTE_ETH_FEC_MODE_CAPA_MASK(RS);
2608 : : }
2609 : : }
2610 : 0 : num++;
2611 : : }
2612 : :
2613 : 0 : return num;
2614 : : }
2615 : :
2616 : : static int
2617 : 0 : sfc_fec_get_capability(struct rte_eth_dev *dev,
2618 : : struct rte_eth_fec_capa *speed_fec_capa,
2619 : : unsigned int num)
2620 : : {
2621 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2622 : : unsigned int num_entries;
2623 : : uint32_t supported_caps;
2624 : :
2625 : 0 : sfc_adapter_lock(sa);
2626 : :
2627 : 0 : efx_phy_adv_cap_get(sa->nic, EFX_PHY_CAP_PERM, &supported_caps);
2628 : :
2629 : 0 : num_entries = sfc_fec_get_capa_speed_to_fec(supported_caps, NULL);
2630 [ # # ]: 0 : if (speed_fec_capa == NULL || num < num_entries)
2631 : 0 : goto adapter_unlock;
2632 : :
2633 : 0 : num_entries = sfc_fec_get_capa_speed_to_fec(supported_caps,
2634 : : speed_fec_capa);
2635 : :
2636 : 0 : adapter_unlock:
2637 : : sfc_adapter_unlock(sa);
2638 : :
2639 : 0 : return num_entries;
2640 : : }
2641 : :
2642 : : static uint32_t
2643 : 0 : sfc_efx_caps_to_fec(uint32_t caps, bool is_25g)
2644 : : {
2645 : 0 : bool rs_req = caps & EFX_PHY_CAP_FEC_BIT(RS_FEC_REQUESTED);
2646 : 0 : bool rs = caps & EFX_PHY_CAP_FEC_BIT(RS_FEC);
2647 : : bool baser_req;
2648 : : bool baser;
2649 : :
2650 [ # # ]: 0 : if (is_25g) {
2651 : 0 : baser = caps & EFX_PHY_CAP_FEC_BIT(25G_BASER_FEC);
2652 : 0 : baser_req = caps & EFX_PHY_CAP_FEC_BIT(25G_BASER_FEC_REQUESTED);
2653 : : } else {
2654 : 0 : baser = caps & EFX_PHY_CAP_FEC_BIT(BASER_FEC);
2655 : 0 : baser_req = caps & EFX_PHY_CAP_FEC_BIT(BASER_FEC_REQUESTED);
2656 : : }
2657 : :
2658 [ # # ]: 0 : if (!baser && !rs)
2659 : : return RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC);
2660 : :
2661 [ # # ]: 0 : if (rs_req)
2662 : : return RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS);
2663 : :
2664 [ # # ]: 0 : if (baser_req)
2665 : 0 : return RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER);
2666 : :
2667 : : return 0;
2668 : : }
2669 : :
2670 : : static int
2671 : 0 : sfc_fec_get(struct rte_eth_dev *dev, uint32_t *fec_capa)
2672 : : {
2673 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2674 : : struct sfc_port *port = &sa->port;
2675 : : struct rte_eth_link current_link;
2676 : : efx_phy_fec_type_t active_fec;
2677 : : bool is_25g = false;
2678 : : int rc = 0;
2679 : :
2680 : 0 : sfc_adapter_lock(sa);
2681 : :
2682 : 0 : sfc_dev_get_rte_link(dev, 1, ¤t_link);
2683 : :
2684 [ # # ]: 0 : if (current_link.link_status == RTE_ETH_LINK_DOWN) {
2685 : 0 : uint32_t speed = current_link.link_speed;
2686 : :
2687 [ # # ]: 0 : if (port->fec_auto) {
2688 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_AUTO);
2689 : 0 : goto adapter_unlock;
2690 : : }
2691 : :
2692 : 0 : is_25g = (speed == RTE_ETH_SPEED_NUM_25G ||
2693 : 0 : speed == RTE_ETH_SPEED_NUM_50G);
2694 : :
2695 : 0 : *fec_capa = sfc_efx_caps_to_fec(port->fec_cfg, is_25g);
2696 [ # # ]: 0 : if (*fec_capa == 0)
2697 : : rc = ENOTSUP;
2698 : :
2699 : 0 : goto adapter_unlock;
2700 : : }
2701 : :
2702 : 0 : rc = efx_phy_fec_type_get(sa->nic, &active_fec);
2703 [ # # ]: 0 : if (rc != 0)
2704 : 0 : goto adapter_unlock;
2705 : :
2706 [ # # # # ]: 0 : switch (active_fec) {
2707 : 0 : case EFX_PHY_FEC_NONE:
2708 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC);
2709 : 0 : break;
2710 : 0 : case EFX_PHY_FEC_BASER:
2711 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER);
2712 : 0 : break;
2713 : 0 : case EFX_PHY_FEC_RS:
2714 : 0 : *fec_capa = RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS);
2715 : 0 : break;
2716 : : default:
2717 : : rc = ENOTSUP;
2718 : : break;
2719 : : }
2720 : :
2721 : 0 : adapter_unlock:
2722 : : sfc_adapter_unlock(sa);
2723 : :
2724 [ # # ]: 0 : if (rc != 0)
2725 : 0 : sfc_err(sa, "failed to get FEC mode");
2726 : :
2727 : : SFC_ASSERT(rc >= 0);
2728 : 0 : return -rc;
2729 : : }
2730 : :
2731 : : /*
2732 : : * When adding checks for new speeds and/or capabilities, keep that consistent
2733 : : * with capabilities that 'sfc_fec_get_capa_speed_to_fec' reports to the user.
2734 : : */
2735 : : static int
2736 [ # # ]: 0 : sfc_fec_capa_check(struct rte_eth_dev *dev, uint32_t fec_capa,
2737 : : uint32_t supported_caps)
2738 : : {
2739 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2740 : : unsigned int ncaps = rte_popcount32(fec_capa);
2741 : : /* Set by 'sfc_phy_cap_from_link_speeds'. */
2742 : 0 : uint32_t speeds_cur = sa->port.phy_adv_cap;
2743 : : uint32_t speeds_baser = 0;
2744 : : uint32_t speeds_rs = 0;
2745 : :
2746 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_AUTO)) {
2747 [ # # ]: 0 : if (ncaps == 1) {
2748 : : /* Let the FW choose a best-effort setting. */
2749 : : return 0;
2750 : : } else {
2751 : : /*
2752 : : * Each requested FEC capability must be supported in
2753 : : * general and at least one speed that supports this
2754 : : * FEC mode must be currently advertised/configured.
2755 : : */
2756 : : }
2757 [ # # ]: 0 : } else if (ncaps != 1) {
2758 : : /*
2759 : : * Fixed FEC mode does not allow for multiple capabilities.
2760 : : * Empty mask is invalid, as No-FEC has a capability bit.
2761 : : */
2762 : : return EINVAL;
2763 [ # # ]: 0 : } else if (fec_capa & RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC)) {
2764 : : /* No-FEC is assumed to be always acceptable. */
2765 : : return 0;
2766 : : }
2767 : :
2768 : : /* 25G BASE-R is accounted for separately below. */
2769 : : speeds_baser |= (1U << EFX_PHY_CAP_50000FDX);
2770 : : speeds_baser |= (1U << EFX_PHY_CAP_40000FDX);
2771 : : speeds_baser |= (1U << EFX_PHY_CAP_10000FDX);
2772 : :
2773 : : speeds_rs |= (1U << EFX_PHY_CAP_200000FDX);
2774 : : speeds_rs |= (1U << EFX_PHY_CAP_100000FDX);
2775 : : speeds_rs |= (1U << EFX_PHY_CAP_50000FDX);
2776 : : speeds_rs |= (1U << EFX_PHY_CAP_25000FDX);
2777 : :
2778 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER)) {
2779 : : bool supported = false;
2780 : :
2781 [ # # ]: 0 : if ((supported_caps & EFX_PHY_CAP_FEC_BIT(25G_BASER_FEC)) &&
2782 [ # # ]: 0 : (speeds_cur & (1U << EFX_PHY_CAP_25000FDX)))
2783 : : supported = true;
2784 : :
2785 [ # # ]: 0 : if ((supported_caps & EFX_PHY_CAP_FEC_BIT(BASER_FEC)) &&
2786 [ # # ]: 0 : (speeds_cur & speeds_baser))
2787 : : supported = true;
2788 : :
2789 [ # # ]: 0 : if (!supported)
2790 : : return ENOTSUP;
2791 : : }
2792 : :
2793 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS)) {
2794 [ # # ]: 0 : if ((supported_caps & EFX_PHY_CAP_FEC_BIT(RS_FEC)) == 0 ||
2795 [ # # ]: 0 : (speeds_cur & speeds_rs) == 0)
2796 : 0 : return ENOTSUP;
2797 : : }
2798 : :
2799 : : return 0;
2800 : : }
2801 : :
2802 : : static int
2803 : 0 : sfc_fec_capa_to_efx(uint32_t supported_caps, uint32_t fec_capa,
2804 : : uint32_t *efx_fec_caps)
2805 : : {
2806 : : bool fec_is_set = false;
2807 : : bool auto_fec = false;
2808 : : bool nofec = false;
2809 : : uint32_t ret = 0;
2810 : :
2811 [ # # ]: 0 : if (efx_fec_caps == NULL)
2812 : : return EINVAL;
2813 : :
2814 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_AUTO))
2815 : : auto_fec = true;
2816 : :
2817 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_NOFEC))
2818 : : nofec = true;
2819 : :
2820 [ # # ]: 0 : if (fec_capa == RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_AUTO)) {
2821 : : ret |= (EFX_PHY_CAP_FEC_BIT(BASER_FEC) |
2822 : : EFX_PHY_CAP_FEC_BIT(25G_BASER_FEC) |
2823 : 0 : EFX_PHY_CAP_FEC_BIT(RS_FEC)) & supported_caps;
2824 : 0 : goto done;
2825 : : }
2826 : :
2827 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_RS)) {
2828 : : fec_is_set = true;
2829 : :
2830 [ # # ]: 0 : if (supported_caps & EFX_PHY_CAP_FEC_BIT(RS_FEC)) {
2831 : : ret |= EFX_PHY_CAP_FEC_BIT(RS_FEC) |
2832 : : EFX_PHY_CAP_FEC_BIT(RS_FEC_REQUESTED);
2833 : : }
2834 : : }
2835 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_BASER)) {
2836 [ # # ]: 0 : if (!auto_fec && fec_is_set)
2837 : : return EINVAL;
2838 : :
2839 [ # # ]: 0 : if (supported_caps & EFX_PHY_CAP_FEC_BIT(BASER_FEC)) {
2840 : 0 : ret |= EFX_PHY_CAP_FEC_BIT(BASER_FEC) |
2841 : : EFX_PHY_CAP_FEC_BIT(BASER_FEC_REQUESTED);
2842 : : }
2843 [ # # ]: 0 : if (supported_caps & EFX_PHY_CAP_FEC_BIT(25G_BASER_FEC)) {
2844 : 0 : ret |= EFX_PHY_CAP_FEC_BIT(25G_BASER_FEC) |
2845 : : EFX_PHY_CAP_FEC_BIT(25G_BASER_FEC_REQUESTED);
2846 : : }
2847 : : }
2848 : :
2849 [ # # ]: 0 : if (ret == 0 && !nofec)
2850 : : return ENOTSUP;
2851 : :
2852 : 0 : done:
2853 : 0 : *efx_fec_caps = ret;
2854 : 0 : return 0;
2855 : : }
2856 : :
2857 : : static int
2858 : 0 : sfc_fec_set(struct rte_eth_dev *dev, uint32_t fec_capa)
2859 : : {
2860 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2861 : : struct sfc_port *port = &sa->port;
2862 : : uint32_t supported_caps;
2863 : : uint32_t efx_fec_caps;
2864 : : uint32_t updated_caps;
2865 : : int rc = 0;
2866 : :
2867 : 0 : sfc_adapter_lock(sa);
2868 : :
2869 : 0 : efx_phy_adv_cap_get(sa->nic, EFX_PHY_CAP_PERM, &supported_caps);
2870 : :
2871 : 0 : rc = sfc_fec_capa_check(dev, fec_capa, supported_caps);
2872 [ # # ]: 0 : if (rc != 0)
2873 : 0 : goto adapter_unlock;
2874 : :
2875 : 0 : rc = sfc_fec_capa_to_efx(supported_caps, fec_capa, &efx_fec_caps);
2876 [ # # ]: 0 : if (rc != 0)
2877 : 0 : goto adapter_unlock;
2878 : :
2879 [ # # ]: 0 : if (sa->state == SFC_ETHDEV_STARTED) {
2880 : 0 : efx_phy_adv_cap_get(sa->nic, EFX_PHY_CAP_CURRENT,
2881 : : &updated_caps);
2882 : :
2883 : : /* Keep pause capabilities set by efx_mac_fcntl_set(). */
2884 : 0 : updated_caps = (updated_caps & EFX_PHY_CAP_PAUSE_MASK) |
2885 : 0 : (port->phy_adv_cap & ~EFX_PHY_CAP_PAUSE_MASK);
2886 : :
2887 : 0 : updated_caps = (updated_caps & ~EFX_PHY_CAP_FEC_MASK) |
2888 : 0 : (efx_fec_caps & EFX_PHY_CAP_FEC_MASK);
2889 : :
2890 : 0 : rc = efx_phy_adv_cap_set(sa->nic, updated_caps);
2891 [ # # ]: 0 : if (rc != 0)
2892 : 0 : goto adapter_unlock;
2893 : : }
2894 : :
2895 : 0 : port->fec_cfg = efx_fec_caps;
2896 : : /*
2897 : : * There is no chance to recognize AUTO mode from the
2898 : : * saved FEC capabilities as AUTO mode can have the same
2899 : : * set of bits as any other mode from the EFX point of view.
2900 : : * Save it in the proper variable.
2901 : : */
2902 [ # # ]: 0 : if (fec_capa & RTE_ETH_FEC_MODE_TO_CAPA(RTE_ETH_FEC_AUTO))
2903 : 0 : port->fec_auto = true;
2904 : : else
2905 : 0 : port->fec_auto = false;
2906 : :
2907 : 0 : adapter_unlock:
2908 : : sfc_adapter_unlock(sa);
2909 : :
2910 : : SFC_ASSERT(rc >= 0);
2911 : 0 : return -rc;
2912 : : }
2913 : :
2914 : : static uint64_t
2915 : 0 : sfc_get_restore_flags(__rte_unused struct rte_eth_dev *dev,
2916 : : __rte_unused enum rte_eth_dev_operation op)
2917 : : {
2918 : : /* sfc PMD does not require any configuration restore */
2919 : 0 : return 0;
2920 : : }
2921 : :
2922 : : static const struct eth_dev_ops sfc_eth_dev_ops = {
2923 : : .dev_configure = sfc_dev_configure,
2924 : : .dev_start = sfc_dev_start,
2925 : : .dev_stop = sfc_dev_stop,
2926 : : .dev_set_link_up = sfc_dev_set_link_up,
2927 : : .dev_set_link_down = sfc_dev_set_link_down,
2928 : : .dev_close = sfc_dev_close,
2929 : : .promiscuous_enable = sfc_dev_promisc_enable,
2930 : : .promiscuous_disable = sfc_dev_promisc_disable,
2931 : : .allmulticast_enable = sfc_dev_allmulti_enable,
2932 : : .allmulticast_disable = sfc_dev_allmulti_disable,
2933 : : .link_update = sfc_dev_link_update,
2934 : : .speed_lanes_get = sfc_dev_speed_lanes_get,
2935 : : .speed_lanes_set = sfc_dev_speed_lanes_set,
2936 : : .speed_lanes_get_capa = sfc_dev_speed_lanes_get_capa,
2937 : : .stats_get = sfc_stats_get,
2938 : : .stats_reset = sfc_stats_reset,
2939 : : .xstats_get = sfc_xstats_get,
2940 : : .xstats_reset = sfc_stats_reset,
2941 : : .xstats_get_names = sfc_xstats_get_names,
2942 : : .dev_infos_get = sfc_dev_infos_get,
2943 : : .dev_supported_ptypes_get = sfc_dev_supported_ptypes_get,
2944 : : .mtu_set = sfc_dev_set_mtu,
2945 : : .rx_queue_start = sfc_rx_queue_start,
2946 : : .rx_queue_stop = sfc_rx_queue_stop,
2947 : : .tx_queue_start = sfc_tx_queue_start,
2948 : : .tx_queue_stop = sfc_tx_queue_stop,
2949 : : .rx_queue_setup = sfc_rx_queue_setup,
2950 : : .rx_queue_release = sfc_rx_queue_release,
2951 : : .rx_queue_intr_enable = sfc_rx_queue_intr_enable,
2952 : : .rx_queue_intr_disable = sfc_rx_queue_intr_disable,
2953 : : .tx_queue_setup = sfc_tx_queue_setup,
2954 : : .tx_queue_release = sfc_tx_queue_release,
2955 : : .flow_ctrl_get = sfc_flow_ctrl_get,
2956 : : .flow_ctrl_set = sfc_flow_ctrl_set,
2957 : : .mac_addr_set = sfc_mac_addr_set,
2958 : : .udp_tunnel_port_add = sfc_dev_udp_tunnel_port_add,
2959 : : .udp_tunnel_port_del = sfc_dev_udp_tunnel_port_del,
2960 : : .reta_update = sfc_dev_rss_reta_update,
2961 : : .reta_query = sfc_dev_rss_reta_query,
2962 : : .rss_hash_update = sfc_dev_rss_hash_update,
2963 : : .rss_hash_conf_get = sfc_dev_rss_hash_conf_get,
2964 : : .flow_ops_get = sfc_dev_flow_ops_get,
2965 : : .set_mc_addr_list = sfc_set_mc_addr_list,
2966 : : .rxq_info_get = sfc_rx_queue_info_get,
2967 : : .txq_info_get = sfc_tx_queue_info_get,
2968 : : .fw_version_get = sfc_fw_version_get,
2969 : : .xstats_get_by_id = sfc_xstats_get_by_id,
2970 : : .xstats_get_names_by_id = sfc_xstats_get_names_by_id,
2971 : : .pool_ops_supported = sfc_pool_ops_supported,
2972 : : .representor_info_get = sfc_representor_info_get,
2973 : : .rx_metadata_negotiate = sfc_rx_metadata_negotiate,
2974 : : .fec_get_capability = sfc_fec_get_capability,
2975 : : .fec_get = sfc_fec_get,
2976 : : .fec_set = sfc_fec_set,
2977 : : .get_restore_flags = sfc_get_restore_flags,
2978 : : };
2979 : :
2980 : : struct sfc_ethdev_init_data {
2981 : : uint16_t nb_representors;
2982 : : };
2983 : :
2984 : : /**
2985 : : * Duplicate a string in potentially shared memory required for
2986 : : * multi-process support.
2987 : : *
2988 : : * strdup() allocates from process-local heap/memory.
2989 : : */
2990 : : static char *
2991 : 0 : sfc_strdup(const char *str)
2992 : : {
2993 : : size_t size;
2994 : : char *copy;
2995 : :
2996 [ # # ]: 0 : if (str == NULL)
2997 : : return NULL;
2998 : :
2999 : 0 : size = strlen(str) + 1;
3000 : 0 : copy = rte_malloc(__func__, size, 0);
3001 [ # # ]: 0 : if (copy != NULL)
3002 : : rte_memcpy(copy, str, size);
3003 : :
3004 : : return copy;
3005 : : }
3006 : :
3007 : : static int
3008 [ # # # ]: 0 : sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
3009 : : {
3010 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
3011 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
3012 : : const struct sfc_dp_rx *dp_rx;
3013 : : const struct sfc_dp_tx *dp_tx;
3014 : : const efx_nic_cfg_t *encp;
3015 : : unsigned int avail_caps = 0;
3016 : 0 : const char *rx_name = NULL;
3017 : 0 : const char *tx_name = NULL;
3018 : : int rc;
3019 : :
3020 [ # # # ]: 0 : switch (sa->family) {
3021 : 0 : case EFX_FAMILY_HUNTINGTON:
3022 : : case EFX_FAMILY_MEDFORD:
3023 : : case EFX_FAMILY_MEDFORD2:
3024 : : case EFX_FAMILY_MEDFORD4:
3025 : : avail_caps |= SFC_DP_HW_FW_CAP_EF10;
3026 : : avail_caps |= SFC_DP_HW_FW_CAP_RX_EFX;
3027 : : avail_caps |= SFC_DP_HW_FW_CAP_TX_EFX;
3028 : 0 : break;
3029 : 0 : case EFX_FAMILY_RIVERHEAD:
3030 : : avail_caps |= SFC_DP_HW_FW_CAP_EF100;
3031 : 0 : break;
3032 : : default:
3033 : : break;
3034 : : }
3035 : :
3036 : 0 : encp = efx_nic_cfg_get(sa->nic);
3037 [ # # ]: 0 : if (encp->enc_rx_es_super_buffer_supported)
3038 : 0 : avail_caps |= SFC_DP_HW_FW_CAP_RX_ES_SUPER_BUFFER;
3039 : :
3040 : 0 : rc = sfc_kvargs_process_opt(sa, SFC_KVARG_RX_DATAPATH,
3041 : : sfc_kvarg_string_handler, &rx_name);
3042 [ # # ]: 0 : if (rc != 0)
3043 : 0 : goto fail_kvarg_rx_datapath;
3044 : :
3045 [ # # ]: 0 : if (rx_name != NULL) {
3046 : : dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, rx_name);
3047 : : if (dp_rx == NULL) {
3048 : 0 : sfc_err(sa, "Rx datapath %s not found", rx_name);
3049 : : rc = ENOENT;
3050 : 0 : goto fail_dp_rx;
3051 : : }
3052 [ # # ]: 0 : if (!sfc_dp_match_hw_fw_caps(&dp_rx->dp, avail_caps)) {
3053 : 0 : sfc_err(sa,
3054 : : "Insufficient Hw/FW capabilities to use Rx datapath %s",
3055 : : rx_name);
3056 : : rc = EINVAL;
3057 : 0 : goto fail_dp_rx_caps;
3058 : : }
3059 : : } else {
3060 : : dp_rx = sfc_dp_find_rx_by_caps(&sfc_dp_head, avail_caps);
3061 : : if (dp_rx == NULL) {
3062 : 0 : sfc_err(sa, "Rx datapath by caps %#x not found",
3063 : : avail_caps);
3064 : : rc = ENOENT;
3065 : 0 : goto fail_dp_rx;
3066 : : }
3067 : : }
3068 : :
3069 : 0 : sas->dp_rx_name = sfc_strdup(dp_rx->dp.name);
3070 [ # # ]: 0 : if (sas->dp_rx_name == NULL) {
3071 : : rc = ENOMEM;
3072 : 0 : goto fail_dp_rx_name;
3073 : : }
3074 : :
3075 [ # # ]: 0 : if (strcmp(dp_rx->dp.name, SFC_KVARG_DATAPATH_EF10_ESSB) == 0) {
3076 : : /* FLAG and MARK are always available from Rx prefix. */
3077 : 0 : sa->negotiated_rx_metadata |= RTE_ETH_RX_METADATA_USER_FLAG;
3078 : 0 : sa->negotiated_rx_metadata |= RTE_ETH_RX_METADATA_USER_MARK;
3079 : : }
3080 : :
3081 : 0 : sfc_notice(sa, "use %s Rx datapath", sas->dp_rx_name);
3082 : :
3083 : 0 : rc = sfc_kvargs_process_opt(sa, SFC_KVARG_TX_DATAPATH,
3084 : : sfc_kvarg_string_handler, &tx_name);
3085 [ # # ]: 0 : if (rc != 0)
3086 : 0 : goto fail_kvarg_tx_datapath;
3087 : :
3088 [ # # ]: 0 : if (tx_name != NULL) {
3089 : : dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, tx_name);
3090 : : if (dp_tx == NULL) {
3091 : 0 : sfc_err(sa, "Tx datapath %s not found", tx_name);
3092 : : rc = ENOENT;
3093 : 0 : goto fail_dp_tx;
3094 : : }
3095 [ # # ]: 0 : if (!sfc_dp_match_hw_fw_caps(&dp_tx->dp, avail_caps)) {
3096 : 0 : sfc_err(sa,
3097 : : "Insufficient Hw/FW capabilities to use Tx datapath %s",
3098 : : tx_name);
3099 : : rc = EINVAL;
3100 : 0 : goto fail_dp_tx_caps;
3101 : : }
3102 : : } else {
3103 : : dp_tx = sfc_dp_find_tx_by_caps(&sfc_dp_head, avail_caps);
3104 : : if (dp_tx == NULL) {
3105 : 0 : sfc_err(sa, "Tx datapath by caps %#x not found",
3106 : : avail_caps);
3107 : : rc = ENOENT;
3108 : 0 : goto fail_dp_tx;
3109 : : }
3110 : : }
3111 : :
3112 : 0 : sas->dp_tx_name = sfc_strdup(dp_tx->dp.name);
3113 [ # # ]: 0 : if (sas->dp_tx_name == NULL) {
3114 : : rc = ENOMEM;
3115 : 0 : goto fail_dp_tx_name;
3116 : : }
3117 : :
3118 : 0 : sfc_notice(sa, "use %s Tx datapath", sas->dp_tx_name);
3119 : :
3120 : 0 : sa->priv.dp_rx = dp_rx;
3121 : 0 : sa->priv.dp_tx = dp_tx;
3122 : :
3123 : 0 : dev->rx_pkt_burst = dp_rx->pkt_burst;
3124 : 0 : dev->tx_pkt_prepare = dp_tx->pkt_prepare;
3125 : 0 : dev->tx_pkt_burst = dp_tx->pkt_burst;
3126 : :
3127 : 0 : dev->rx_queue_count = sfc_rx_queue_count;
3128 : 0 : dev->rx_descriptor_status = sfc_rx_descriptor_status;
3129 : 0 : dev->tx_descriptor_status = sfc_tx_descriptor_status;
3130 : 0 : dev->dev_ops = &sfc_eth_dev_ops;
3131 : :
3132 : 0 : return 0;
3133 : :
3134 : : fail_dp_tx_name:
3135 : 0 : fail_dp_tx_caps:
3136 : 0 : fail_dp_tx:
3137 : 0 : fail_kvarg_tx_datapath:
3138 : 0 : rte_free(sas->dp_rx_name);
3139 : 0 : sas->dp_rx_name = NULL;
3140 : :
3141 : : fail_dp_rx_name:
3142 : : fail_dp_rx_caps:
3143 : : fail_dp_rx:
3144 : : fail_kvarg_rx_datapath:
3145 : : return rc;
3146 : : }
3147 : :
3148 : : static void
3149 : 0 : sfc_eth_dev_clear_ops(struct rte_eth_dev *dev)
3150 : : {
3151 : : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
3152 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
3153 : :
3154 : 0 : dev->dev_ops = NULL;
3155 : 0 : dev->tx_pkt_prepare = NULL;
3156 : 0 : dev->rx_pkt_burst = NULL;
3157 : 0 : dev->tx_pkt_burst = NULL;
3158 : :
3159 : 0 : rte_free(sas->dp_tx_name);
3160 : 0 : sas->dp_tx_name = NULL;
3161 : 0 : sa->priv.dp_tx = NULL;
3162 : :
3163 : 0 : rte_free(sas->dp_rx_name);
3164 : 0 : sas->dp_rx_name = NULL;
3165 : 0 : sa->priv.dp_rx = NULL;
3166 : 0 : }
3167 : :
3168 : : static int
3169 [ # # ]: 0 : sfc_dev_infos_get_secondary(struct rte_eth_dev *dev,
3170 : : struct rte_eth_dev_info *dev_info)
3171 : : {
3172 : : const struct sfc_adapter_shared *sas =
3173 : : sfc_adapter_shared_by_eth_dev(dev);
3174 : 0 : bool valid = rte_atomic_load_explicit(&sas->dev_info_cache_is_valid,
3175 : : rte_memory_order_acquire);
3176 : :
3177 [ # # ]: 0 : if (!valid)
3178 : : return -EAGAIN;
3179 : :
3180 : 0 : *dev_info = sas->dev_info_cache;
3181 : :
3182 : : /*
3183 : : * The cache holds stale primary-process pointers; restore
3184 : : * the process-local values from the caller-supplied 'dev'.
3185 : : */
3186 [ # # ]: 0 : if (dev_info->switch_info.name != NULL)
3187 : 0 : dev_info->switch_info.name = dev->device->driver->name;
3188 : 0 : dev_info->device = dev->device;
3189 : 0 : return 0;
3190 : : }
3191 : :
3192 : : static const struct eth_dev_ops sfc_eth_dev_secondary_ops = {
3193 : : .dev_infos_get = sfc_dev_infos_get_secondary,
3194 : : .dev_supported_ptypes_get = sfc_dev_supported_ptypes_get,
3195 : : .reta_query = sfc_dev_rss_reta_query,
3196 : : .rss_hash_conf_get = sfc_dev_rss_hash_conf_get,
3197 : : .rxq_info_get = sfc_rx_queue_info_get,
3198 : : .txq_info_get = sfc_tx_queue_info_get,
3199 : : };
3200 : :
3201 : : static int
3202 [ # # ]: 0 : sfc_eth_dev_secondary_init(struct rte_eth_dev *dev, uint32_t logtype_main)
3203 : : {
3204 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
3205 : : struct sfc_adapter_priv *sap;
3206 : : const struct sfc_dp_rx *dp_rx;
3207 : : const struct sfc_dp_tx *dp_tx;
3208 : : int rc;
3209 : :
3210 : : /*
3211 : : * Allocate process private data from heap, since it should not
3212 : : * be located in shared memory allocated using rte_malloc() API.
3213 : : */
3214 : 0 : sap = calloc(1, sizeof(*sap));
3215 [ # # ]: 0 : if (sap == NULL) {
3216 : : rc = ENOMEM;
3217 : 0 : goto fail_alloc_priv;
3218 : : }
3219 : :
3220 : 0 : sap->logtype_main = logtype_main;
3221 : :
3222 : 0 : dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, sas->dp_rx_name);
3223 : : if (dp_rx == NULL) {
3224 : 0 : SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
3225 : : "cannot find %s Rx datapath", sas->dp_rx_name);
3226 : : rc = ENOENT;
3227 : 0 : goto fail_dp_rx;
3228 : : }
3229 [ # # ]: 0 : if (~dp_rx->features & SFC_DP_RX_FEAT_MULTI_PROCESS) {
3230 : 0 : SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
3231 : : "%s Rx datapath does not support multi-process",
3232 : : sas->dp_rx_name);
3233 : : rc = EINVAL;
3234 : 0 : goto fail_dp_rx_multi_process;
3235 : : }
3236 : :
3237 : 0 : dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, sas->dp_tx_name);
3238 : : if (dp_tx == NULL) {
3239 : 0 : SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
3240 : : "cannot find %s Tx datapath", sas->dp_tx_name);
3241 : : rc = ENOENT;
3242 : 0 : goto fail_dp_tx;
3243 : : }
3244 [ # # ]: 0 : if (~dp_tx->features & SFC_DP_TX_FEAT_MULTI_PROCESS) {
3245 : 0 : SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
3246 : : "%s Tx datapath does not support multi-process",
3247 : : sas->dp_tx_name);
3248 : : rc = EINVAL;
3249 : 0 : goto fail_dp_tx_multi_process;
3250 : : }
3251 : :
3252 : 0 : sap->dp_rx = dp_rx;
3253 : 0 : sap->dp_tx = dp_tx;
3254 : 0 : sap->shared = sas;
3255 : :
3256 : 0 : dev->process_private = sap;
3257 : 0 : dev->rx_pkt_burst = dp_rx->pkt_burst;
3258 : 0 : dev->tx_pkt_prepare = dp_tx->pkt_prepare;
3259 : 0 : dev->tx_pkt_burst = dp_tx->pkt_burst;
3260 : 0 : dev->rx_queue_count = sfc_rx_queue_count;
3261 : 0 : dev->rx_descriptor_status = sfc_rx_descriptor_status;
3262 : 0 : dev->tx_descriptor_status = sfc_tx_descriptor_status;
3263 : 0 : dev->dev_ops = &sfc_eth_dev_secondary_ops;
3264 : :
3265 : 0 : return 0;
3266 : :
3267 : : fail_dp_tx_multi_process:
3268 : 0 : fail_dp_tx:
3269 : 0 : fail_dp_rx_multi_process:
3270 : 0 : fail_dp_rx:
3271 : 0 : free(sap);
3272 : :
3273 : : fail_alloc_priv:
3274 : : return rc;
3275 : : }
3276 : :
3277 : : static void
3278 : 0 : sfc_register_dp(void)
3279 : : {
3280 : : /* Register once */
3281 [ # # ]: 0 : if (TAILQ_EMPTY(&sfc_dp_head)) {
3282 : : /* Prefer EF10 datapath */
3283 : 0 : sfc_dp_register(&sfc_dp_head, &sfc_ef100_rx.dp);
3284 : 0 : sfc_dp_register(&sfc_dp_head, &sfc_ef10_essb_rx.dp);
3285 : 0 : sfc_dp_register(&sfc_dp_head, &sfc_ef10_rx.dp);
3286 : 0 : sfc_dp_register(&sfc_dp_head, &sfc_efx_rx.dp);
3287 : :
3288 : 0 : sfc_dp_register(&sfc_dp_head, &sfc_ef100_tx.dp);
3289 : 0 : sfc_dp_register(&sfc_dp_head, &sfc_ef10_tx.dp);
3290 : 0 : sfc_dp_register(&sfc_dp_head, &sfc_efx_tx.dp);
3291 : 0 : sfc_dp_register(&sfc_dp_head, &sfc_ef10_simple_tx.dp);
3292 : : }
3293 : 0 : }
3294 : :
3295 : : static int
3296 : 0 : sfc_parse_switch_mode(struct sfc_adapter *sa, bool has_representors)
3297 : : {
3298 : 0 : const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
3299 : 0 : const char *switch_mode = NULL;
3300 : : int rc;
3301 : :
3302 : 0 : sfc_log_init(sa, "entry");
3303 : :
3304 : 0 : rc = sfc_kvargs_process_opt(sa, SFC_KVARG_SWITCH_MODE,
3305 : : sfc_kvarg_string_handler, &switch_mode);
3306 [ # # ]: 0 : if (rc != 0)
3307 : 0 : goto fail_kvargs;
3308 : :
3309 [ # # ]: 0 : if (switch_mode == NULL) {
3310 [ # # ]: 0 : sa->switchdev = encp->enc_mae_admin &&
3311 [ # # # # ]: 0 : (!encp->enc_datapath_cap_evb ||
3312 : : has_representors);
3313 [ # # ]: 0 : } else if (strcasecmp(switch_mode, SFC_KVARG_SWITCH_MODE_LEGACY) == 0) {
3314 : 0 : sa->switchdev = false;
3315 [ # # ]: 0 : } else if (strcasecmp(switch_mode,
3316 : : SFC_KVARG_SWITCH_MODE_SWITCHDEV) == 0) {
3317 : 0 : sa->switchdev = true;
3318 : : } else {
3319 : 0 : sfc_err(sa, "invalid switch mode device argument '%s'",
3320 : : switch_mode);
3321 : : rc = EINVAL;
3322 : 0 : goto fail_mode;
3323 : : }
3324 : :
3325 : 0 : sfc_log_init(sa, "done");
3326 : :
3327 : 0 : return 0;
3328 : :
3329 : : fail_mode:
3330 : 0 : fail_kvargs:
3331 : 0 : sfc_log_init(sa, "failed: %s", rte_strerror(rc));
3332 : :
3333 : 0 : return rc;
3334 : : }
3335 : :
3336 : : static int
3337 : 0 : sfc_eth_dev_init(struct rte_eth_dev *dev, void *init_params)
3338 : : {
3339 : : struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
3340 : 0 : struct rte_pci_device *pci_dev = RTE_CLASS_TO_BUS_DEVICE(dev, *pci_dev);
3341 : : struct sfc_ethdev_init_data *init_data = init_params;
3342 : : uint32_t logtype_main;
3343 : : struct sfc_adapter *sa;
3344 : : int rc;
3345 : : const efx_nic_cfg_t *encp;
3346 : : const struct rte_ether_addr *from;
3347 : : int ret;
3348 : :
3349 [ # # ]: 0 : if (sfc_efx_dev_class_get(pci_dev->device.devargs) !=
3350 : : SFC_EFX_DEV_CLASS_NET) {
3351 : 0 : SFC_GENERIC_LOG(DEBUG,
3352 : : "Incompatible device class: skip probing, should be probed by other sfc driver.");
3353 : 0 : return 1;
3354 : : }
3355 : :
3356 : 0 : rc = sfc_dp_mport_register();
3357 [ # # ]: 0 : if (rc != 0)
3358 : : return rc;
3359 : :
3360 : 0 : sfc_register_dp();
3361 : :
3362 : 0 : logtype_main = sfc_register_logtype(&pci_dev->addr,
3363 : : SFC_LOGTYPE_MAIN_STR,
3364 : : RTE_LOG_NOTICE);
3365 : :
3366 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3367 : 0 : return -sfc_eth_dev_secondary_init(dev, logtype_main);
3368 : :
3369 : : /* Required for logging */
3370 : 0 : ret = snprintf(sas->log_prefix, sizeof(sas->log_prefix),
3371 : : "PMD: sfc_efx " PCI_PRI_FMT " #%" PRIu16 ": ",
3372 : 0 : pci_dev->addr.domain, pci_dev->addr.bus,
3373 : 0 : pci_dev->addr.devid, pci_dev->addr.function,
3374 [ # # ]: 0 : dev->data->port_id);
3375 [ # # ]: 0 : if (ret < 0 || ret >= (int)sizeof(sas->log_prefix)) {
3376 : 0 : SFC_GENERIC_LOG(ERR,
3377 : : "reserved log prefix is too short for " PCI_PRI_FMT,
3378 : : pci_dev->addr.domain, pci_dev->addr.bus,
3379 : : pci_dev->addr.devid, pci_dev->addr.function);
3380 : 0 : return -EINVAL;
3381 : : }
3382 : 0 : sas->pci_addr = pci_dev->addr;
3383 : 0 : sas->port_id = dev->data->port_id;
3384 : :
3385 : : /*
3386 : : * Allocate process private data from heap, since it should not
3387 : : * be located in shared memory allocated using rte_malloc() API.
3388 : : */
3389 : 0 : sa = calloc(1, sizeof(*sa));
3390 [ # # ]: 0 : if (sa == NULL) {
3391 : : rc = ENOMEM;
3392 : 0 : goto fail_alloc_sa;
3393 : : }
3394 : :
3395 : 0 : dev->process_private = sa;
3396 : :
3397 : : /* Required for logging */
3398 : 0 : sa->priv.shared = sas;
3399 : 0 : sa->priv.logtype_main = logtype_main;
3400 : :
3401 : 0 : sa->eth_dev = dev;
3402 : :
3403 : : /* Copy PCI device info to the dev->data */
3404 : 0 : rte_eth_copy_pci_info(dev, pci_dev);
3405 : 0 : dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
3406 : :
3407 : 0 : rc = sfc_kvargs_parse(sa);
3408 [ # # ]: 0 : if (rc != 0)
3409 : 0 : goto fail_kvargs_parse;
3410 : :
3411 : 0 : sfc_log_init(sa, "entry");
3412 : :
3413 : 0 : dev->data->mac_addrs = rte_zmalloc("sfc", RTE_ETHER_ADDR_LEN, 0);
3414 [ # # ]: 0 : if (dev->data->mac_addrs == NULL) {
3415 : : rc = ENOMEM;
3416 : 0 : goto fail_mac_addrs;
3417 : : }
3418 : :
3419 : : sfc_adapter_lock_init(sa);
3420 : 0 : sfc_adapter_lock(sa);
3421 : :
3422 : 0 : sfc_log_init(sa, "probing");
3423 : 0 : rc = sfc_probe(sa);
3424 [ # # ]: 0 : if (rc != 0)
3425 : 0 : goto fail_probe;
3426 : :
3427 : : /*
3428 : : * Selecting a default switch mode requires the NIC to be probed and
3429 : : * to have its capabilities filled in.
3430 : : */
3431 : 0 : rc = sfc_parse_switch_mode(sa, init_data->nb_representors > 0);
3432 [ # # ]: 0 : if (rc != 0)
3433 : 0 : goto fail_switch_mode;
3434 : :
3435 : 0 : sfc_log_init(sa, "set device ops");
3436 : 0 : rc = sfc_eth_dev_set_ops(dev);
3437 [ # # ]: 0 : if (rc != 0)
3438 : 0 : goto fail_set_ops;
3439 : :
3440 : 0 : sfc_log_init(sa, "attaching");
3441 : 0 : rc = sfc_attach(sa);
3442 [ # # ]: 0 : if (rc != 0)
3443 : 0 : goto fail_attach;
3444 : :
3445 [ # # # # ]: 0 : if (sa->switchdev && sa->mae.status != SFC_MAE_STATUS_ADMIN) {
3446 : 0 : sfc_err(sa,
3447 : : "failed to enable switchdev mode without admin MAE privilege");
3448 : : rc = ENOTSUP;
3449 : 0 : goto fail_switchdev_no_mae;
3450 : : }
3451 : :
3452 : 0 : encp = efx_nic_cfg_get(sa->nic);
3453 : :
3454 : : /*
3455 : : * The arguments are really reverse order in comparison to
3456 : : * Linux kernel. Copy from NIC config to Ethernet device data.
3457 : : */
3458 : : from = (const struct rte_ether_addr *)(encp->enc_mac_addr);
3459 : 0 : rte_ether_addr_copy(from, &dev->data->mac_addrs[0]);
3460 : :
3461 : : /*
3462 : : * Setup the NIC DMA mapping handler. All internal mempools
3463 : : * MUST be created on attach before this point, and the
3464 : : * adapter MUST NOT create mempools with the adapter lock
3465 : : * held after this point.
3466 : : */
3467 : 0 : rc = sfc_nic_dma_attach(sa);
3468 [ # # ]: 0 : if (rc != 0)
3469 : 0 : goto fail_nic_dma_attach;
3470 : :
3471 : 0 : sa->link_ev_need_poll = encp->enc_link_ev_need_poll;
3472 : :
3473 : : sfc_adapter_unlock(sa);
3474 : :
3475 : 0 : sfc_log_init(sa, "done");
3476 : 0 : return 0;
3477 : :
3478 : : fail_nic_dma_attach:
3479 : 0 : fail_switchdev_no_mae:
3480 : 0 : sfc_detach(sa);
3481 : :
3482 : 0 : fail_attach:
3483 : 0 : sfc_eth_dev_clear_ops(dev);
3484 : :
3485 : 0 : fail_set_ops:
3486 : 0 : fail_switch_mode:
3487 : 0 : sfc_unprobe(sa);
3488 : :
3489 : 0 : fail_probe:
3490 : : sfc_adapter_unlock(sa);
3491 : : sfc_adapter_lock_fini(sa);
3492 : 0 : rte_free(dev->data->mac_addrs);
3493 : 0 : dev->data->mac_addrs = NULL;
3494 : :
3495 : 0 : fail_mac_addrs:
3496 : 0 : sfc_kvargs_cleanup(sa);
3497 : :
3498 : 0 : fail_kvargs_parse:
3499 : 0 : sfc_log_init(sa, "failed %d", rc);
3500 : 0 : dev->process_private = NULL;
3501 : 0 : free(sa);
3502 : :
3503 : 0 : fail_alloc_sa:
3504 : : SFC_ASSERT(rc > 0);
3505 : 0 : return -rc;
3506 : : }
3507 : :
3508 : : static int
3509 : 0 : sfc_eth_dev_uninit(struct rte_eth_dev *dev)
3510 : : {
3511 : 0 : sfc_dev_close(dev);
3512 : :
3513 : 0 : return 0;
3514 : : }
3515 : :
3516 : : static const struct rte_pci_id pci_id_sfc_efx_map[] = {
3517 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_FARMINGDALE) },
3518 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_FARMINGDALE_VF) },
3519 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_GREENPORT) },
3520 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_GREENPORT_VF) },
3521 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD) },
3522 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD_VF) },
3523 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD2) },
3524 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD2_VF) },
3525 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD4) },
3526 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD4_VF) },
3527 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD4_NO_LL) },
3528 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD4_NO_LL_VF) },
3529 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_XILINX, EFX_PCI_DEVID_RIVERHEAD) },
3530 : : { RTE_PCI_DEVICE(EFX_PCI_VENID_XILINX, EFX_PCI_DEVID_RIVERHEAD_VF) },
3531 : : { .vendor_id = 0 /* sentinel */ }
3532 : : };
3533 : :
3534 : : static int
3535 : 0 : sfc_parse_rte_devargs(const char *args, struct rte_eth_devargs *devargs)
3536 : : {
3537 : 0 : struct rte_eth_devargs eth_da = { .nb_representor_ports = 0 };
3538 : : int rc;
3539 : :
3540 [ # # ]: 0 : if (args != NULL) {
3541 : 0 : rc = rte_eth_devargs_parse(args, ð_da, 1);
3542 [ # # ]: 0 : if (rc < 0) {
3543 : 0 : SFC_GENERIC_LOG(ERR,
3544 : : "Failed to parse generic devargs '%s'",
3545 : : args);
3546 : 0 : return rc;
3547 : : }
3548 : : }
3549 : :
3550 : 0 : *devargs = eth_da;
3551 : :
3552 : 0 : return 0;
3553 : : }
3554 : :
3555 : : static int
3556 : 0 : sfc_eth_dev_find_or_create(struct rte_pci_device *pci_dev,
3557 : : struct sfc_ethdev_init_data *init_data,
3558 : : struct rte_eth_dev **devp,
3559 : : bool *dev_created)
3560 : : {
3561 : : struct rte_eth_dev *dev;
3562 : : bool created = false;
3563 : : int rc;
3564 : :
3565 : 0 : dev = rte_eth_dev_allocated(pci_dev->device.name);
3566 [ # # ]: 0 : if (dev == NULL) {
3567 : 0 : rc = rte_eth_dev_create(&pci_dev->device, pci_dev->device.name,
3568 : : sizeof(struct sfc_adapter_shared),
3569 : : eth_dev_pci_specific_init, pci_dev,
3570 : : sfc_eth_dev_init, init_data);
3571 [ # # ]: 0 : if (rc != 0) {
3572 : 0 : SFC_GENERIC_LOG(ERR, "Failed to create sfc ethdev '%s'",
3573 : : pci_dev->device.name);
3574 : 0 : return rc;
3575 : : }
3576 : :
3577 : : created = true;
3578 : :
3579 : 0 : dev = rte_eth_dev_allocated(pci_dev->device.name);
3580 [ # # ]: 0 : if (dev == NULL) {
3581 : 0 : SFC_GENERIC_LOG(ERR,
3582 : : "Failed to find allocated sfc ethdev '%s'",
3583 : : pci_dev->device.name);
3584 : 0 : return -ENODEV;
3585 : : }
3586 : : }
3587 : :
3588 : 0 : *devp = dev;
3589 : 0 : *dev_created = created;
3590 : :
3591 : 0 : return 0;
3592 : : }
3593 : :
3594 : : static int
3595 : 0 : sfc_eth_dev_create_repr(struct sfc_adapter *sa,
3596 : : efx_pcie_interface_t controller,
3597 : : uint16_t port,
3598 : : uint16_t repr_port,
3599 : : enum rte_eth_representor_type type)
3600 : : {
3601 : 0 : const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
3602 : : struct sfc_repr_entity_info entity;
3603 : : efx_mport_sel_t mport_sel;
3604 : : int rc;
3605 : :
3606 [ # # # # ]: 0 : switch (type) {
3607 : : case RTE_ETH_REPRESENTOR_NONE:
3608 : : return 0;
3609 : : case RTE_ETH_REPRESENTOR_VF:
3610 : : case RTE_ETH_REPRESENTOR_PF:
3611 : : break;
3612 : 0 : case RTE_ETH_REPRESENTOR_SF:
3613 : 0 : sfc_err(sa, "SF representors are not supported");
3614 : 0 : return ENOTSUP;
3615 : 0 : default:
3616 : 0 : sfc_err(sa, "unknown representor type: %d", type);
3617 : 0 : return ENOTSUP;
3618 : : }
3619 : :
3620 : 0 : rc = efx_mae_mport_by_pcie_mh_function(controller,
3621 : : port,
3622 : : repr_port,
3623 : : &mport_sel);
3624 [ # # ]: 0 : if (rc != 0) {
3625 : 0 : sfc_err(sa,
3626 : : "failed to get m-port selector for controller %u port %u repr_port %u: %s",
3627 : : controller, port, repr_port, rte_strerror(-rc));
3628 : 0 : return rc;
3629 : : }
3630 : :
3631 : : memset(&entity, 0, sizeof(entity));
3632 : 0 : entity.type = type;
3633 : 0 : entity.intf = controller;
3634 : 0 : entity.pf = port;
3635 : 0 : entity.vf = repr_port;
3636 : :
3637 : 0 : rc = sfc_repr_create(sa->eth_dev, &entity, sa->mae.switch_domain_id,
3638 : 0 : encp->enc_mac_pdu_max, &mport_sel);
3639 [ # # ]: 0 : if (rc != 0) {
3640 : 0 : sfc_err(sa,
3641 : : "failed to create representor for controller %u port %u repr_port %u: %s",
3642 : : controller, port, repr_port, rte_strerror(-rc));
3643 : 0 : return rc;
3644 : : }
3645 : :
3646 : : return 0;
3647 : : }
3648 : :
3649 : : static int
3650 : 0 : sfc_eth_dev_create_repr_port(struct sfc_adapter *sa,
3651 : : const struct rte_eth_devargs *eth_da,
3652 : : efx_pcie_interface_t controller,
3653 : : uint16_t port)
3654 : : {
3655 : : int first_error = 0;
3656 : : uint16_t i;
3657 : : int rc;
3658 : :
3659 [ # # ]: 0 : if (eth_da->type == RTE_ETH_REPRESENTOR_PF) {
3660 : 0 : return sfc_eth_dev_create_repr(sa, controller, port,
3661 : : EFX_PCI_VF_INVALID,
3662 : : eth_da->type);
3663 : : }
3664 : :
3665 [ # # ]: 0 : for (i = 0; i < eth_da->nb_representor_ports; i++) {
3666 : 0 : rc = sfc_eth_dev_create_repr(sa, controller, port,
3667 : 0 : eth_da->representor_ports[i],
3668 : 0 : eth_da->type);
3669 [ # # ]: 0 : if (rc != 0 && first_error == 0)
3670 : : first_error = rc;
3671 : : }
3672 : :
3673 : : return first_error;
3674 : : }
3675 : :
3676 : : static int
3677 : 0 : sfc_eth_dev_create_repr_controller(struct sfc_adapter *sa,
3678 : : const struct rte_eth_devargs *eth_da,
3679 : : efx_pcie_interface_t controller)
3680 : : {
3681 : : const efx_nic_cfg_t *encp;
3682 : : int first_error = 0;
3683 : : uint16_t default_port;
3684 : : uint16_t i;
3685 : : int rc;
3686 : :
3687 [ # # ]: 0 : if (eth_da->nb_ports == 0) {
3688 : 0 : encp = efx_nic_cfg_get(sa->nic);
3689 [ # # ]: 0 : default_port = encp->enc_intf == controller ? encp->enc_pf : 0;
3690 : 0 : return sfc_eth_dev_create_repr_port(sa, eth_da, controller,
3691 : : default_port);
3692 : : }
3693 : :
3694 [ # # ]: 0 : for (i = 0; i < eth_da->nb_ports; i++) {
3695 : 0 : rc = sfc_eth_dev_create_repr_port(sa, eth_da, controller,
3696 : 0 : eth_da->ports[i]);
3697 [ # # ]: 0 : if (rc != 0 && first_error == 0)
3698 : : first_error = rc;
3699 : : }
3700 : :
3701 : : return first_error;
3702 : : }
3703 : :
3704 : : static int
3705 [ # # # # ]: 0 : sfc_eth_dev_create_representors(struct rte_eth_dev *dev,
3706 : : const struct rte_eth_devargs *eth_da)
3707 : : {
3708 : : efx_pcie_interface_t intf;
3709 : : const efx_nic_cfg_t *encp;
3710 : : struct sfc_adapter *sa;
3711 : : uint16_t switch_domain_id;
3712 : : uint16_t i;
3713 : : int rc;
3714 : :
3715 : : sa = sfc_adapter_by_eth_dev(dev);
3716 : 0 : switch_domain_id = sa->mae.switch_domain_id;
3717 : :
3718 [ # # # # ]: 0 : switch (eth_da->type) {
3719 : : case RTE_ETH_REPRESENTOR_NONE:
3720 : : return 0;
3721 : : case RTE_ETH_REPRESENTOR_PF:
3722 : : case RTE_ETH_REPRESENTOR_VF:
3723 : : break;
3724 : 0 : case RTE_ETH_REPRESENTOR_SF:
3725 : 0 : sfc_err(sa, "SF representors are not supported");
3726 : 0 : return -ENOTSUP;
3727 : 0 : default:
3728 : 0 : sfc_err(sa, "unknown representor type: %d",
3729 : : eth_da->type);
3730 : 0 : return -ENOTSUP;
3731 : : }
3732 : :
3733 [ # # ]: 0 : if (!sa->switchdev) {
3734 : 0 : sfc_err(sa, "cannot create representors in non-switchdev mode");
3735 : 0 : return -EINVAL;
3736 : : }
3737 : :
3738 [ # # ]: 0 : if (!sfc_repr_available(sfc_sa2shared(sa))) {
3739 : 0 : sfc_err(sa, "cannot create representors: unsupported");
3740 : :
3741 : 0 : return -ENOTSUP;
3742 : : }
3743 : :
3744 : : /*
3745 : : * This is needed to construct the DPDK controller -> EFX interface
3746 : : * mapping.
3747 : : */
3748 : 0 : sfc_adapter_lock(sa);
3749 : 0 : rc = sfc_process_mport_journal(sa);
3750 : : sfc_adapter_unlock(sa);
3751 [ # # ]: 0 : if (rc != 0) {
3752 : : SFC_ASSERT(rc > 0);
3753 : 0 : return -rc;
3754 : : }
3755 : :
3756 [ # # ]: 0 : if (eth_da->nb_mh_controllers > 0) {
3757 [ # # ]: 0 : for (i = 0; i < eth_da->nb_mh_controllers; i++) {
3758 : 0 : rc = sfc_mae_switch_domain_get_intf(switch_domain_id,
3759 : 0 : eth_da->mh_controllers[i],
3760 : : &intf);
3761 [ # # ]: 0 : if (rc != 0) {
3762 : 0 : sfc_err(sa, "failed to get representor");
3763 : 0 : continue;
3764 : : }
3765 : 0 : sfc_eth_dev_create_repr_controller(sa, eth_da, intf);
3766 : : }
3767 : : } else {
3768 : 0 : encp = efx_nic_cfg_get(sa->nic);
3769 : 0 : sfc_eth_dev_create_repr_controller(sa, eth_da, encp->enc_intf);
3770 : : }
3771 : :
3772 : : return 0;
3773 : : }
3774 : :
3775 : 0 : static int sfc_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
3776 : : struct rte_pci_device *pci_dev)
3777 : : {
3778 : : struct sfc_ethdev_init_data init_data;
3779 : : struct rte_eth_devargs eth_da;
3780 : : struct rte_eth_dev *dev;
3781 : : bool dev_created;
3782 : : int rc;
3783 : :
3784 [ # # ]: 0 : if (pci_dev->device.devargs != NULL) {
3785 : 0 : rc = sfc_parse_rte_devargs(pci_dev->device.devargs->args,
3786 : : ð_da);
3787 [ # # ]: 0 : if (rc != 0)
3788 : : return rc;
3789 : : } else {
3790 : : memset(ð_da, 0, sizeof(eth_da));
3791 : : }
3792 : :
3793 : : /* If no VF representors specified, check for PF ones */
3794 [ # # ]: 0 : if (eth_da.nb_representor_ports > 0)
3795 : 0 : init_data.nb_representors = eth_da.nb_representor_ports;
3796 : : else
3797 : 0 : init_data.nb_representors = eth_da.nb_ports;
3798 : :
3799 [ # # # # ]: 0 : if (init_data.nb_representors > 0 &&
3800 : 0 : rte_eal_process_type() != RTE_PROC_PRIMARY) {
3801 : 0 : SFC_GENERIC_LOG(ERR,
3802 : : "Create representors from secondary process not supported, dev '%s'",
3803 : : pci_dev->device.name);
3804 : 0 : return -ENOTSUP;
3805 : : }
3806 : :
3807 : : /*
3808 : : * Driver supports RTE_PCI_DRV_PROBE_AGAIN. Hence create device only
3809 : : * if it does not already exist. Re-probing an existing device is
3810 : : * expected to allow additional representors to be configured.
3811 : : */
3812 : 0 : rc = sfc_eth_dev_find_or_create(pci_dev, &init_data, &dev,
3813 : : &dev_created);
3814 [ # # ]: 0 : if (rc != 0)
3815 : : return rc;
3816 : :
3817 [ # # # # ]: 0 : if (dev_created && rte_eal_process_type() == RTE_PROC_PRIMARY) {
3818 : 0 : struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
3819 : : struct sfc_adapter_shared *sas =
3820 : : sfc_adapter_shared_by_eth_dev(dev);
3821 : :
3822 : : /*
3823 : : * Pre-fill the dev info cache for the secondary
3824 : : * process. The port has been registered at this
3825 : : * point, allowing use of the public API.
3826 : : */
3827 : 0 : rc = rte_eth_dev_info_get(dev->data->port_id,
3828 : : &sas->dev_info_cache);
3829 [ # # ]: 0 : if (rc == 0) {
3830 : 0 : sas->dev_info_cache.device = NULL;
3831 : 0 : rte_atomic_store_explicit(&sas->dev_info_cache_is_valid,
3832 : : true, rte_memory_order_release);
3833 : : } else {
3834 : 0 : sfc_warn(sa, "failed to cache dev info for the secondary process");
3835 : : }
3836 : : }
3837 : :
3838 : 0 : rc = sfc_eth_dev_create_representors(dev, ð_da);
3839 [ # # ]: 0 : if (rc != 0) {
3840 [ # # ]: 0 : if (dev_created)
3841 : 0 : (void)rte_eth_dev_destroy(dev, sfc_eth_dev_uninit);
3842 : :
3843 : 0 : return rc;
3844 : : }
3845 : :
3846 : : return 0;
3847 : : }
3848 : :
3849 : 0 : static int sfc_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
3850 : : {
3851 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, sfc_eth_dev_uninit);
3852 : : }
3853 : :
3854 : : static struct rte_pci_driver sfc_efx_pmd = {
3855 : : .id_table = pci_id_sfc_efx_map,
3856 : : .drv_flags =
3857 : : RTE_PCI_DRV_INTR_LSC |
3858 : : RTE_PCI_DRV_NEED_MAPPING |
3859 : : RTE_PCI_DRV_PROBE_AGAIN,
3860 : : .probe = sfc_eth_dev_pci_probe,
3861 : : .remove = sfc_eth_dev_pci_remove,
3862 : : };
3863 : :
3864 : 302 : RTE_PMD_REGISTER_PCI(net_sfc_efx, sfc_efx_pmd);
3865 : : RTE_PMD_REGISTER_PCI_TABLE(net_sfc_efx, pci_id_sfc_efx_map);
3866 : : RTE_PMD_REGISTER_KMOD_DEP(net_sfc_efx, "* igb_uio | uio_pci_generic | vfio-pci");
3867 : : RTE_PMD_REGISTER_PARAM_STRING(net_sfc_efx,
3868 : : SFC_KVARG_SWITCH_MODE "=" SFC_KVARG_VALUES_SWITCH_MODE " "
3869 : : SFC_KVARG_RX_DATAPATH "=" SFC_KVARG_VALUES_RX_DATAPATH " "
3870 : : SFC_KVARG_TX_DATAPATH "=" SFC_KVARG_VALUES_TX_DATAPATH " "
3871 : : SFC_KVARG_PERF_PROFILE "=" SFC_KVARG_VALUES_PERF_PROFILE " "
3872 : : SFC_KVARG_FW_VARIANT "=" SFC_KVARG_VALUES_FW_VARIANT " "
3873 : : SFC_KVARG_RXD_WAIT_TIMEOUT_NS "=<long> "
3874 : : SFC_KVARG_STATS_UPDATE_PERIOD_MS "=<long>");
3875 [ - + ]: 302 : RTE_LOG_REGISTER_SUFFIX(sfc_logtype_driver, driver, NOTICE);
|