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