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