xref: /dpdk/drivers/net/sfc/sfc_ethdev.c (revision fb7ad441d43d4152cb7bde992a1136c20d9166e9)
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 <rte_dev.h>
11 #include <ethdev_driver.h>
12 #include <ethdev_pci.h>
13 #include <rte_pci.h>
14 #include <rte_bus_pci.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_dp.h"
30 #include "sfc_dp_rx.h"
31 
32 uint32_t sfc_logtype_driver;
33 
34 static struct sfc_dp_list sfc_dp_head =
35 	TAILQ_HEAD_INITIALIZER(sfc_dp_head);
36 
37 
38 static void sfc_eth_dev_clear_ops(struct rte_eth_dev *dev);
39 
40 
41 static int
42 sfc_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
43 {
44 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
45 	efx_nic_fw_info_t enfi;
46 	int ret;
47 	int rc;
48 
49 	/*
50 	 * Return value of the callback is likely supposed to be
51 	 * equal to or greater than 0, nevertheless, if an error
52 	 * occurs, it will be desirable to pass it to the caller
53 	 */
54 	if ((fw_version == NULL) || (fw_size == 0))
55 		return -EINVAL;
56 
57 	rc = efx_nic_get_fw_version(sa->nic, &enfi);
58 	if (rc != 0)
59 		return -rc;
60 
61 	ret = snprintf(fw_version, fw_size,
62 		       "%" PRIu16 ".%" PRIu16 ".%" PRIu16 ".%" PRIu16,
63 		       enfi.enfi_mc_fw_version[0], enfi.enfi_mc_fw_version[1],
64 		       enfi.enfi_mc_fw_version[2], enfi.enfi_mc_fw_version[3]);
65 	if (ret < 0)
66 		return ret;
67 
68 	if (enfi.enfi_dpcpu_fw_ids_valid) {
69 		size_t dpcpu_fw_ids_offset = MIN(fw_size - 1, (size_t)ret);
70 		int ret_extra;
71 
72 		ret_extra = snprintf(fw_version + dpcpu_fw_ids_offset,
73 				     fw_size - dpcpu_fw_ids_offset,
74 				     " rx%" PRIx16 " tx%" PRIx16,
75 				     enfi.enfi_rx_dpcpu_fw_id,
76 				     enfi.enfi_tx_dpcpu_fw_id);
77 		if (ret_extra < 0)
78 			return ret_extra;
79 
80 		ret += ret_extra;
81 	}
82 
83 	if (fw_size < (size_t)(++ret))
84 		return ret;
85 	else
86 		return 0;
87 }
88 
89 static int
90 sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
91 {
92 	const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
93 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
94 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
95 	struct sfc_rss *rss = &sas->rss;
96 	struct sfc_mae *mae = &sa->mae;
97 	uint64_t txq_offloads_def = 0;
98 
99 	sfc_log_init(sa, "entry");
100 
101 	dev_info->min_mtu = RTE_ETHER_MIN_MTU;
102 	dev_info->max_mtu = EFX_MAC_SDU_MAX;
103 
104 	dev_info->max_rx_pktlen = EFX_MAC_PDU_MAX;
105 
106 	dev_info->max_vfs = sa->sriov.num_vfs;
107 
108 	/* Autonegotiation may be disabled */
109 	dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
110 	if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_1000FDX))
111 		dev_info->speed_capa |= ETH_LINK_SPEED_1G;
112 	if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_10000FDX))
113 		dev_info->speed_capa |= ETH_LINK_SPEED_10G;
114 	if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_25000FDX))
115 		dev_info->speed_capa |= ETH_LINK_SPEED_25G;
116 	if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_40000FDX))
117 		dev_info->speed_capa |= ETH_LINK_SPEED_40G;
118 	if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_50000FDX))
119 		dev_info->speed_capa |= ETH_LINK_SPEED_50G;
120 	if (sa->port.phy_adv_cap_mask & (1u << EFX_PHY_CAP_100000FDX))
121 		dev_info->speed_capa |= ETH_LINK_SPEED_100G;
122 
123 	dev_info->max_rx_queues = sa->rxq_max;
124 	dev_info->max_tx_queues = sa->txq_max;
125 
126 	/* By default packets are dropped if no descriptors are available */
127 	dev_info->default_rxconf.rx_drop_en = 1;
128 
129 	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 	dev_info->rx_offload_capa = sfc_rx_get_dev_offload_caps(sa) |
137 				    dev_info->rx_queue_offload_capa;
138 
139 	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 	dev_info->tx_offload_capa = sfc_tx_get_dev_offload_caps(sa) |
147 				    dev_info->tx_queue_offload_capa;
148 
149 	if (dev_info->tx_offload_capa & DEV_TX_OFFLOAD_MBUF_FAST_FREE)
150 		txq_offloads_def |= DEV_TX_OFFLOAD_MBUF_FAST_FREE;
151 
152 	dev_info->default_txconf.offloads |= txq_offloads_def;
153 
154 	if (rss->context_type != EFX_RX_SCALE_UNAVAILABLE) {
155 		uint64_t rte_hf = 0;
156 		unsigned int i;
157 
158 		for (i = 0; i < rss->hf_map_nb_entries; ++i)
159 			rte_hf |= rss->hf_map[i].rte;
160 
161 		dev_info->reta_size = EFX_RSS_TBL_SIZE;
162 		dev_info->hash_key_size = EFX_RSS_KEY_SIZE;
163 		dev_info->flow_type_rss_offloads = rte_hf;
164 	}
165 
166 	/* Initialize to hardware limits */
167 	dev_info->rx_desc_lim.nb_max = sa->rxq_max_entries;
168 	dev_info->rx_desc_lim.nb_min = sa->rxq_min_entries;
169 	/* The RXQ hardware requires that the descriptor count is a power
170 	 * of 2, but rx_desc_lim cannot properly describe that constraint.
171 	 */
172 	dev_info->rx_desc_lim.nb_align = sa->rxq_min_entries;
173 
174 	/* Initialize to hardware limits */
175 	dev_info->tx_desc_lim.nb_max = sa->txq_max_entries;
176 	dev_info->tx_desc_lim.nb_min = sa->txq_min_entries;
177 	/*
178 	 * The TXQ hardware requires that the descriptor count is a power
179 	 * of 2, but tx_desc_lim cannot properly describe that constraint
180 	 */
181 	dev_info->tx_desc_lim.nb_align = sa->txq_min_entries;
182 
183 	if (sap->dp_rx->get_dev_info != NULL)
184 		sap->dp_rx->get_dev_info(dev_info);
185 	if (sap->dp_tx->get_dev_info != NULL)
186 		sap->dp_tx->get_dev_info(dev_info);
187 
188 	dev_info->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
189 			     RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
190 
191 	if (mae->status == SFC_MAE_STATUS_SUPPORTED) {
192 		dev_info->switch_info.name = dev->device->driver->name;
193 		dev_info->switch_info.domain_id = mae->switch_domain_id;
194 		dev_info->switch_info.port_id = mae->switch_port_id;
195 	}
196 
197 	return 0;
198 }
199 
200 static const uint32_t *
201 sfc_dev_supported_ptypes_get(struct rte_eth_dev *dev)
202 {
203 	const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
204 
205 	return sap->dp_rx->supported_ptypes_get(sap->shared->tunnel_encaps);
206 }
207 
208 static int
209 sfc_dev_configure(struct rte_eth_dev *dev)
210 {
211 	struct rte_eth_dev_data *dev_data = dev->data;
212 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
213 	int rc;
214 
215 	sfc_log_init(sa, "entry n_rxq=%u n_txq=%u",
216 		     dev_data->nb_rx_queues, dev_data->nb_tx_queues);
217 
218 	sfc_adapter_lock(sa);
219 	switch (sa->state) {
220 	case SFC_ADAPTER_CONFIGURED:
221 		/* FALLTHROUGH */
222 	case SFC_ADAPTER_INITIALIZED:
223 		rc = sfc_configure(sa);
224 		break;
225 	default:
226 		sfc_err(sa, "unexpected adapter state %u to configure",
227 			sa->state);
228 		rc = EINVAL;
229 		break;
230 	}
231 	sfc_adapter_unlock(sa);
232 
233 	sfc_log_init(sa, "done %d", rc);
234 	SFC_ASSERT(rc >= 0);
235 	return -rc;
236 }
237 
238 static int
239 sfc_dev_start(struct rte_eth_dev *dev)
240 {
241 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
242 	int rc;
243 
244 	sfc_log_init(sa, "entry");
245 
246 	sfc_adapter_lock(sa);
247 	rc = sfc_start(sa);
248 	sfc_adapter_unlock(sa);
249 
250 	sfc_log_init(sa, "done %d", rc);
251 	SFC_ASSERT(rc >= 0);
252 	return -rc;
253 }
254 
255 static int
256 sfc_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
257 {
258 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
259 	struct rte_eth_link current_link;
260 	int ret;
261 
262 	sfc_log_init(sa, "entry");
263 
264 	if (sa->state != SFC_ADAPTER_STARTED) {
265 		sfc_port_link_mode_to_info(EFX_LINK_UNKNOWN, &current_link);
266 	} else if (wait_to_complete) {
267 		efx_link_mode_t link_mode;
268 
269 		if (efx_port_poll(sa->nic, &link_mode) != 0)
270 			link_mode = EFX_LINK_UNKNOWN;
271 		sfc_port_link_mode_to_info(link_mode, &current_link);
272 
273 	} else {
274 		sfc_ev_mgmt_qpoll(sa);
275 		rte_eth_linkstatus_get(dev, &current_link);
276 	}
277 
278 	ret = rte_eth_linkstatus_set(dev, &current_link);
279 	if (ret == 0)
280 		sfc_notice(sa, "Link status is %s",
281 			   current_link.link_status ? "UP" : "DOWN");
282 
283 	return ret;
284 }
285 
286 static int
287 sfc_dev_stop(struct rte_eth_dev *dev)
288 {
289 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
290 
291 	sfc_log_init(sa, "entry");
292 
293 	sfc_adapter_lock(sa);
294 	sfc_stop(sa);
295 	sfc_adapter_unlock(sa);
296 
297 	sfc_log_init(sa, "done");
298 
299 	return 0;
300 }
301 
302 static int
303 sfc_dev_set_link_up(struct rte_eth_dev *dev)
304 {
305 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
306 	int rc;
307 
308 	sfc_log_init(sa, "entry");
309 
310 	sfc_adapter_lock(sa);
311 	rc = sfc_start(sa);
312 	sfc_adapter_unlock(sa);
313 
314 	SFC_ASSERT(rc >= 0);
315 	return -rc;
316 }
317 
318 static int
319 sfc_dev_set_link_down(struct rte_eth_dev *dev)
320 {
321 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
322 
323 	sfc_log_init(sa, "entry");
324 
325 	sfc_adapter_lock(sa);
326 	sfc_stop(sa);
327 	sfc_adapter_unlock(sa);
328 
329 	return 0;
330 }
331 
332 static void
333 sfc_eth_dev_secondary_clear_ops(struct rte_eth_dev *dev)
334 {
335 	free(dev->process_private);
336 	rte_eth_dev_release_port(dev);
337 }
338 
339 static int
340 sfc_dev_close(struct rte_eth_dev *dev)
341 {
342 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
343 
344 	sfc_log_init(sa, "entry");
345 
346 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
347 		sfc_eth_dev_secondary_clear_ops(dev);
348 		return 0;
349 	}
350 
351 	sfc_adapter_lock(sa);
352 	switch (sa->state) {
353 	case SFC_ADAPTER_STARTED:
354 		sfc_stop(sa);
355 		SFC_ASSERT(sa->state == SFC_ADAPTER_CONFIGURED);
356 		/* FALLTHROUGH */
357 	case SFC_ADAPTER_CONFIGURED:
358 		sfc_close(sa);
359 		SFC_ASSERT(sa->state == SFC_ADAPTER_INITIALIZED);
360 		/* FALLTHROUGH */
361 	case SFC_ADAPTER_INITIALIZED:
362 		break;
363 	default:
364 		sfc_err(sa, "unexpected adapter state %u on close", sa->state);
365 		break;
366 	}
367 
368 	/*
369 	 * Cleanup all resources.
370 	 * Rollback primary process sfc_eth_dev_init() below.
371 	 */
372 
373 	sfc_eth_dev_clear_ops(dev);
374 
375 	sfc_detach(sa);
376 	sfc_unprobe(sa);
377 
378 	sfc_kvargs_cleanup(sa);
379 
380 	sfc_adapter_unlock(sa);
381 	sfc_adapter_lock_fini(sa);
382 
383 	sfc_log_init(sa, "done");
384 
385 	/* Required for logging, so cleanup last */
386 	sa->eth_dev = NULL;
387 
388 	free(sa);
389 
390 	return 0;
391 }
392 
393 static int
394 sfc_dev_filter_set(struct rte_eth_dev *dev, enum sfc_dev_filter_mode mode,
395 		   boolean_t enabled)
396 {
397 	struct sfc_port *port;
398 	boolean_t *toggle;
399 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
400 	boolean_t allmulti = (mode == SFC_DEV_FILTER_MODE_ALLMULTI);
401 	const char *desc = (allmulti) ? "all-multi" : "promiscuous";
402 	int rc = 0;
403 
404 	sfc_adapter_lock(sa);
405 
406 	port = &sa->port;
407 	toggle = (allmulti) ? (&port->allmulti) : (&port->promisc);
408 
409 	if (*toggle != enabled) {
410 		*toggle = enabled;
411 
412 		if (sfc_sa2shared(sa)->isolated) {
413 			sfc_warn(sa, "isolated mode is active on the port");
414 			sfc_warn(sa, "the change is to be applied on the next "
415 				     "start provided that isolated mode is "
416 				     "disabled prior the next start");
417 		} else if ((sa->state == SFC_ADAPTER_STARTED) &&
418 			   ((rc = sfc_set_rx_mode(sa)) != 0)) {
419 			*toggle = !(enabled);
420 			sfc_warn(sa, "Failed to %s %s mode, rc = %d",
421 				 ((enabled) ? "enable" : "disable"), desc, rc);
422 
423 			/*
424 			 * For promiscuous and all-multicast filters a
425 			 * permission failure should be reported as an
426 			 * unsupported filter.
427 			 */
428 			if (rc == EPERM)
429 				rc = ENOTSUP;
430 		}
431 	}
432 
433 	sfc_adapter_unlock(sa);
434 	return rc;
435 }
436 
437 static int
438 sfc_dev_promisc_enable(struct rte_eth_dev *dev)
439 {
440 	int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_TRUE);
441 
442 	SFC_ASSERT(rc >= 0);
443 	return -rc;
444 }
445 
446 static int
447 sfc_dev_promisc_disable(struct rte_eth_dev *dev)
448 {
449 	int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_PROMISC, B_FALSE);
450 
451 	SFC_ASSERT(rc >= 0);
452 	return -rc;
453 }
454 
455 static int
456 sfc_dev_allmulti_enable(struct rte_eth_dev *dev)
457 {
458 	int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_TRUE);
459 
460 	SFC_ASSERT(rc >= 0);
461 	return -rc;
462 }
463 
464 static int
465 sfc_dev_allmulti_disable(struct rte_eth_dev *dev)
466 {
467 	int rc = sfc_dev_filter_set(dev, SFC_DEV_FILTER_MODE_ALLMULTI, B_FALSE);
468 
469 	SFC_ASSERT(rc >= 0);
470 	return -rc;
471 }
472 
473 static int
474 sfc_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
475 		   uint16_t nb_rx_desc, unsigned int socket_id,
476 		   const struct rte_eth_rxconf *rx_conf,
477 		   struct rte_mempool *mb_pool)
478 {
479 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
480 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
481 	int rc;
482 
483 	sfc_log_init(sa, "RxQ=%u nb_rx_desc=%u socket_id=%u",
484 		     rx_queue_id, nb_rx_desc, socket_id);
485 
486 	sfc_adapter_lock(sa);
487 
488 	rc = sfc_rx_qinit(sa, rx_queue_id, nb_rx_desc, socket_id,
489 			  rx_conf, mb_pool);
490 	if (rc != 0)
491 		goto fail_rx_qinit;
492 
493 	dev->data->rx_queues[rx_queue_id] = sas->rxq_info[rx_queue_id].dp;
494 
495 	sfc_adapter_unlock(sa);
496 
497 	return 0;
498 
499 fail_rx_qinit:
500 	sfc_adapter_unlock(sa);
501 	SFC_ASSERT(rc > 0);
502 	return -rc;
503 }
504 
505 static void
506 sfc_rx_queue_release(void *queue)
507 {
508 	struct sfc_dp_rxq *dp_rxq = queue;
509 	struct sfc_rxq *rxq;
510 	struct sfc_adapter *sa;
511 	unsigned int sw_index;
512 
513 	if (dp_rxq == NULL)
514 		return;
515 
516 	rxq = sfc_rxq_by_dp_rxq(dp_rxq);
517 	sa = rxq->evq->sa;
518 	sfc_adapter_lock(sa);
519 
520 	sw_index = dp_rxq->dpq.queue_id;
521 
522 	sfc_log_init(sa, "RxQ=%u", sw_index);
523 
524 	sfc_rx_qfini(sa, sw_index);
525 
526 	sfc_adapter_unlock(sa);
527 }
528 
529 static int
530 sfc_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
531 		   uint16_t nb_tx_desc, unsigned int socket_id,
532 		   const struct rte_eth_txconf *tx_conf)
533 {
534 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
535 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
536 	int rc;
537 
538 	sfc_log_init(sa, "TxQ = %u, nb_tx_desc = %u, socket_id = %u",
539 		     tx_queue_id, nb_tx_desc, socket_id);
540 
541 	sfc_adapter_lock(sa);
542 
543 	rc = sfc_tx_qinit(sa, tx_queue_id, nb_tx_desc, socket_id, tx_conf);
544 	if (rc != 0)
545 		goto fail_tx_qinit;
546 
547 	dev->data->tx_queues[tx_queue_id] = sas->txq_info[tx_queue_id].dp;
548 
549 	sfc_adapter_unlock(sa);
550 	return 0;
551 
552 fail_tx_qinit:
553 	sfc_adapter_unlock(sa);
554 	SFC_ASSERT(rc > 0);
555 	return -rc;
556 }
557 
558 static void
559 sfc_tx_queue_release(void *queue)
560 {
561 	struct sfc_dp_txq *dp_txq = queue;
562 	struct sfc_txq *txq;
563 	unsigned int sw_index;
564 	struct sfc_adapter *sa;
565 
566 	if (dp_txq == NULL)
567 		return;
568 
569 	txq = sfc_txq_by_dp_txq(dp_txq);
570 	sw_index = dp_txq->dpq.queue_id;
571 
572 	SFC_ASSERT(txq->evq != NULL);
573 	sa = txq->evq->sa;
574 
575 	sfc_log_init(sa, "TxQ = %u", sw_index);
576 
577 	sfc_adapter_lock(sa);
578 
579 	sfc_tx_qfini(sa, sw_index);
580 
581 	sfc_adapter_unlock(sa);
582 }
583 
584 /*
585  * Some statistics are computed as A - B where A and B each increase
586  * monotonically with some hardware counter(s) and the counters are read
587  * asynchronously.
588  *
589  * If packet X is counted in A, but not counted in B yet, computed value is
590  * greater than real.
591  *
592  * If packet X is not counted in A at the moment of reading the counter,
593  * but counted in B at the moment of reading the counter, computed value
594  * is less than real.
595  *
596  * However, counter which grows backward is worse evil than slightly wrong
597  * value. So, let's try to guarantee that it never happens except may be
598  * the case when the MAC stats are zeroed as a result of a NIC reset.
599  */
600 static void
601 sfc_update_diff_stat(uint64_t *stat, uint64_t newval)
602 {
603 	if ((int64_t)(newval - *stat) > 0 || newval == 0)
604 		*stat = newval;
605 }
606 
607 static int
608 sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
609 {
610 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
611 	struct sfc_port *port = &sa->port;
612 	uint64_t *mac_stats;
613 	int ret;
614 
615 	rte_spinlock_lock(&port->mac_stats_lock);
616 
617 	ret = sfc_port_update_mac_stats(sa);
618 	if (ret != 0)
619 		goto unlock;
620 
621 	mac_stats = port->mac_stats_buf;
622 
623 	if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask,
624 				   EFX_MAC_VADAPTER_RX_UNICAST_PACKETS)) {
625 		stats->ipackets =
626 			mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_PACKETS] +
627 			mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_PACKETS] +
628 			mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_PACKETS];
629 		stats->opackets =
630 			mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_PACKETS] +
631 			mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_PACKETS] +
632 			mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_PACKETS];
633 		stats->ibytes =
634 			mac_stats[EFX_MAC_VADAPTER_RX_UNICAST_BYTES] +
635 			mac_stats[EFX_MAC_VADAPTER_RX_MULTICAST_BYTES] +
636 			mac_stats[EFX_MAC_VADAPTER_RX_BROADCAST_BYTES];
637 		stats->obytes =
638 			mac_stats[EFX_MAC_VADAPTER_TX_UNICAST_BYTES] +
639 			mac_stats[EFX_MAC_VADAPTER_TX_MULTICAST_BYTES] +
640 			mac_stats[EFX_MAC_VADAPTER_TX_BROADCAST_BYTES];
641 		stats->imissed = mac_stats[EFX_MAC_VADAPTER_RX_BAD_PACKETS];
642 		stats->oerrors = mac_stats[EFX_MAC_VADAPTER_TX_BAD_PACKETS];
643 
644 		/* CRC is included in these stats, but shouldn't be */
645 		stats->ibytes -= stats->ipackets * RTE_ETHER_CRC_LEN;
646 		stats->obytes -= stats->opackets * RTE_ETHER_CRC_LEN;
647 	} else {
648 		stats->opackets = mac_stats[EFX_MAC_TX_PKTS];
649 		stats->ibytes = mac_stats[EFX_MAC_RX_OCTETS];
650 		stats->obytes = mac_stats[EFX_MAC_TX_OCTETS];
651 
652 		/* CRC is included in these stats, but shouldn't be */
653 		stats->ibytes -= mac_stats[EFX_MAC_RX_PKTS] * RTE_ETHER_CRC_LEN;
654 		stats->obytes -= mac_stats[EFX_MAC_TX_PKTS] * RTE_ETHER_CRC_LEN;
655 
656 		/*
657 		 * Take into account stats which are whenever supported
658 		 * on EF10. If some stat is not supported by current
659 		 * firmware variant or HW revision, it is guaranteed
660 		 * to be zero in mac_stats.
661 		 */
662 		stats->imissed =
663 			mac_stats[EFX_MAC_RX_NODESC_DROP_CNT] +
664 			mac_stats[EFX_MAC_PM_TRUNC_BB_OVERFLOW] +
665 			mac_stats[EFX_MAC_PM_DISCARD_BB_OVERFLOW] +
666 			mac_stats[EFX_MAC_PM_TRUNC_VFIFO_FULL] +
667 			mac_stats[EFX_MAC_PM_DISCARD_VFIFO_FULL] +
668 			mac_stats[EFX_MAC_PM_TRUNC_QBB] +
669 			mac_stats[EFX_MAC_PM_DISCARD_QBB] +
670 			mac_stats[EFX_MAC_PM_DISCARD_MAPPING] +
671 			mac_stats[EFX_MAC_RXDP_Q_DISABLED_PKTS] +
672 			mac_stats[EFX_MAC_RXDP_DI_DROPPED_PKTS];
673 		stats->ierrors =
674 			mac_stats[EFX_MAC_RX_FCS_ERRORS] +
675 			mac_stats[EFX_MAC_RX_ALIGN_ERRORS] +
676 			mac_stats[EFX_MAC_RX_JABBER_PKTS];
677 		/* no oerrors counters supported on EF10 */
678 
679 		/* Exclude missed, errors and pauses from Rx packets */
680 		sfc_update_diff_stat(&port->ipackets,
681 			mac_stats[EFX_MAC_RX_PKTS] -
682 			mac_stats[EFX_MAC_RX_PAUSE_PKTS] -
683 			stats->imissed - stats->ierrors);
684 		stats->ipackets = port->ipackets;
685 	}
686 
687 unlock:
688 	rte_spinlock_unlock(&port->mac_stats_lock);
689 	SFC_ASSERT(ret >= 0);
690 	return -ret;
691 }
692 
693 static int
694 sfc_stats_reset(struct rte_eth_dev *dev)
695 {
696 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
697 	struct sfc_port *port = &sa->port;
698 	int rc;
699 
700 	if (sa->state != SFC_ADAPTER_STARTED) {
701 		/*
702 		 * The operation cannot be done if port is not started; it
703 		 * will be scheduled to be done during the next port start
704 		 */
705 		port->mac_stats_reset_pending = B_TRUE;
706 		return 0;
707 	}
708 
709 	rc = sfc_port_reset_mac_stats(sa);
710 	if (rc != 0)
711 		sfc_err(sa, "failed to reset statistics (rc = %d)", rc);
712 
713 	SFC_ASSERT(rc >= 0);
714 	return -rc;
715 }
716 
717 static int
718 sfc_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
719 	       unsigned int xstats_count)
720 {
721 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
722 	struct sfc_port *port = &sa->port;
723 	uint64_t *mac_stats;
724 	int rc;
725 	unsigned int i;
726 	int nstats = 0;
727 
728 	rte_spinlock_lock(&port->mac_stats_lock);
729 
730 	rc = sfc_port_update_mac_stats(sa);
731 	if (rc != 0) {
732 		SFC_ASSERT(rc > 0);
733 		nstats = -rc;
734 		goto unlock;
735 	}
736 
737 	mac_stats = port->mac_stats_buf;
738 
739 	for (i = 0; i < EFX_MAC_NSTATS; ++i) {
740 		if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) {
741 			if (xstats != NULL && nstats < (int)xstats_count) {
742 				xstats[nstats].id = nstats;
743 				xstats[nstats].value = mac_stats[i];
744 			}
745 			nstats++;
746 		}
747 	}
748 
749 unlock:
750 	rte_spinlock_unlock(&port->mac_stats_lock);
751 
752 	return nstats;
753 }
754 
755 static int
756 sfc_xstats_get_names(struct rte_eth_dev *dev,
757 		     struct rte_eth_xstat_name *xstats_names,
758 		     unsigned int xstats_count)
759 {
760 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
761 	struct sfc_port *port = &sa->port;
762 	unsigned int i;
763 	unsigned int nstats = 0;
764 
765 	for (i = 0; i < EFX_MAC_NSTATS; ++i) {
766 		if (EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i)) {
767 			if (xstats_names != NULL && nstats < xstats_count)
768 				strlcpy(xstats_names[nstats].name,
769 					efx_mac_stat_name(sa->nic, i),
770 					sizeof(xstats_names[0].name));
771 			nstats++;
772 		}
773 	}
774 
775 	return nstats;
776 }
777 
778 static int
779 sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
780 		     uint64_t *values, unsigned int n)
781 {
782 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
783 	struct sfc_port *port = &sa->port;
784 	uint64_t *mac_stats;
785 	unsigned int nb_supported = 0;
786 	unsigned int nb_written = 0;
787 	unsigned int i;
788 	int ret;
789 	int rc;
790 
791 	if (unlikely(values == NULL) ||
792 	    unlikely((ids == NULL) && (n < port->mac_stats_nb_supported)))
793 		return port->mac_stats_nb_supported;
794 
795 	rte_spinlock_lock(&port->mac_stats_lock);
796 
797 	rc = sfc_port_update_mac_stats(sa);
798 	if (rc != 0) {
799 		SFC_ASSERT(rc > 0);
800 		ret = -rc;
801 		goto unlock;
802 	}
803 
804 	mac_stats = port->mac_stats_buf;
805 
806 	for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < n); ++i) {
807 		if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
808 			continue;
809 
810 		if ((ids == NULL) || (ids[nb_written] == nb_supported))
811 			values[nb_written++] = mac_stats[i];
812 
813 		++nb_supported;
814 	}
815 
816 	ret = nb_written;
817 
818 unlock:
819 	rte_spinlock_unlock(&port->mac_stats_lock);
820 
821 	return ret;
822 }
823 
824 static int
825 sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
826 			   struct rte_eth_xstat_name *xstats_names,
827 			   const uint64_t *ids, unsigned int size)
828 {
829 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
830 	struct sfc_port *port = &sa->port;
831 	unsigned int nb_supported = 0;
832 	unsigned int nb_written = 0;
833 	unsigned int i;
834 
835 	if (unlikely(xstats_names == NULL) ||
836 	    unlikely((ids == NULL) && (size < port->mac_stats_nb_supported)))
837 		return port->mac_stats_nb_supported;
838 
839 	for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < size); ++i) {
840 		if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
841 			continue;
842 
843 		if ((ids == NULL) || (ids[nb_written] == nb_supported)) {
844 			char *name = xstats_names[nb_written++].name;
845 
846 			strlcpy(name, efx_mac_stat_name(sa->nic, i),
847 				sizeof(xstats_names[0].name));
848 		}
849 
850 		++nb_supported;
851 	}
852 
853 	return nb_written;
854 }
855 
856 static int
857 sfc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
858 {
859 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
860 	unsigned int wanted_fc, link_fc;
861 
862 	memset(fc_conf, 0, sizeof(*fc_conf));
863 
864 	sfc_adapter_lock(sa);
865 
866 	if (sa->state == SFC_ADAPTER_STARTED)
867 		efx_mac_fcntl_get(sa->nic, &wanted_fc, &link_fc);
868 	else
869 		link_fc = sa->port.flow_ctrl;
870 
871 	switch (link_fc) {
872 	case 0:
873 		fc_conf->mode = RTE_FC_NONE;
874 		break;
875 	case EFX_FCNTL_RESPOND:
876 		fc_conf->mode = RTE_FC_RX_PAUSE;
877 		break;
878 	case EFX_FCNTL_GENERATE:
879 		fc_conf->mode = RTE_FC_TX_PAUSE;
880 		break;
881 	case (EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE):
882 		fc_conf->mode = RTE_FC_FULL;
883 		break;
884 	default:
885 		sfc_err(sa, "%s: unexpected flow control value %#x",
886 			__func__, link_fc);
887 	}
888 
889 	fc_conf->autoneg = sa->port.flow_ctrl_autoneg;
890 
891 	sfc_adapter_unlock(sa);
892 
893 	return 0;
894 }
895 
896 static int
897 sfc_flow_ctrl_set(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
898 {
899 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
900 	struct sfc_port *port = &sa->port;
901 	unsigned int fcntl;
902 	int rc;
903 
904 	if (fc_conf->high_water != 0 || fc_conf->low_water != 0 ||
905 	    fc_conf->pause_time != 0 || fc_conf->send_xon != 0 ||
906 	    fc_conf->mac_ctrl_frame_fwd != 0) {
907 		sfc_err(sa, "unsupported flow control settings specified");
908 		rc = EINVAL;
909 		goto fail_inval;
910 	}
911 
912 	switch (fc_conf->mode) {
913 	case RTE_FC_NONE:
914 		fcntl = 0;
915 		break;
916 	case RTE_FC_RX_PAUSE:
917 		fcntl = EFX_FCNTL_RESPOND;
918 		break;
919 	case RTE_FC_TX_PAUSE:
920 		fcntl = EFX_FCNTL_GENERATE;
921 		break;
922 	case RTE_FC_FULL:
923 		fcntl = EFX_FCNTL_RESPOND | EFX_FCNTL_GENERATE;
924 		break;
925 	default:
926 		rc = EINVAL;
927 		goto fail_inval;
928 	}
929 
930 	sfc_adapter_lock(sa);
931 
932 	if (sa->state == SFC_ADAPTER_STARTED) {
933 		rc = efx_mac_fcntl_set(sa->nic, fcntl, fc_conf->autoneg);
934 		if (rc != 0)
935 			goto fail_mac_fcntl_set;
936 	}
937 
938 	port->flow_ctrl = fcntl;
939 	port->flow_ctrl_autoneg = fc_conf->autoneg;
940 
941 	sfc_adapter_unlock(sa);
942 
943 	return 0;
944 
945 fail_mac_fcntl_set:
946 	sfc_adapter_unlock(sa);
947 fail_inval:
948 	SFC_ASSERT(rc > 0);
949 	return -rc;
950 }
951 
952 static int
953 sfc_check_scatter_on_all_rx_queues(struct sfc_adapter *sa, size_t pdu)
954 {
955 	struct sfc_adapter_shared * const sas = sfc_sa2shared(sa);
956 	const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
957 	boolean_t scatter_enabled;
958 	const char *error;
959 	unsigned int i;
960 
961 	for (i = 0; i < sas->rxq_count; i++) {
962 		if ((sas->rxq_info[i].state & SFC_RXQ_INITIALIZED) == 0)
963 			continue;
964 
965 		scatter_enabled = (sas->rxq_info[i].type_flags &
966 				   EFX_RXQ_FLAG_SCATTER);
967 
968 		if (!sfc_rx_check_scatter(pdu, sa->rxq_ctrl[i].buf_size,
969 					  encp->enc_rx_prefix_size,
970 					  scatter_enabled,
971 					  encp->enc_rx_scatter_max, &error)) {
972 			sfc_err(sa, "MTU check for RxQ %u failed: %s", i,
973 				error);
974 			return EINVAL;
975 		}
976 	}
977 
978 	return 0;
979 }
980 
981 static int
982 sfc_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
983 {
984 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
985 	size_t pdu = EFX_MAC_PDU(mtu);
986 	size_t old_pdu;
987 	int rc;
988 
989 	sfc_log_init(sa, "mtu=%u", mtu);
990 
991 	rc = EINVAL;
992 	if (pdu < EFX_MAC_PDU_MIN) {
993 		sfc_err(sa, "too small MTU %u (PDU size %u less than min %u)",
994 			(unsigned int)mtu, (unsigned int)pdu,
995 			EFX_MAC_PDU_MIN);
996 		goto fail_inval;
997 	}
998 	if (pdu > EFX_MAC_PDU_MAX) {
999 		sfc_err(sa, "too big MTU %u (PDU size %u greater than max %u)",
1000 			(unsigned int)mtu, (unsigned int)pdu,
1001 			(unsigned int)EFX_MAC_PDU_MAX);
1002 		goto fail_inval;
1003 	}
1004 
1005 	sfc_adapter_lock(sa);
1006 
1007 	rc = sfc_check_scatter_on_all_rx_queues(sa, pdu);
1008 	if (rc != 0)
1009 		goto fail_check_scatter;
1010 
1011 	if (pdu != sa->port.pdu) {
1012 		if (sa->state == SFC_ADAPTER_STARTED) {
1013 			sfc_stop(sa);
1014 
1015 			old_pdu = sa->port.pdu;
1016 			sa->port.pdu = pdu;
1017 			rc = sfc_start(sa);
1018 			if (rc != 0)
1019 				goto fail_start;
1020 		} else {
1021 			sa->port.pdu = pdu;
1022 		}
1023 	}
1024 
1025 	/*
1026 	 * The driver does not use it, but other PMDs update jumbo frame
1027 	 * flag and max_rx_pkt_len when MTU is set.
1028 	 */
1029 	if (mtu > RTE_ETHER_MTU) {
1030 		struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
1031 		rxmode->offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1032 	}
1033 
1034 	dev->data->dev_conf.rxmode.max_rx_pkt_len = sa->port.pdu;
1035 
1036 	sfc_adapter_unlock(sa);
1037 
1038 	sfc_log_init(sa, "done");
1039 	return 0;
1040 
1041 fail_start:
1042 	sa->port.pdu = old_pdu;
1043 	if (sfc_start(sa) != 0)
1044 		sfc_err(sa, "cannot start with neither new (%u) nor old (%u) "
1045 			"PDU max size - port is stopped",
1046 			(unsigned int)pdu, (unsigned int)old_pdu);
1047 
1048 fail_check_scatter:
1049 	sfc_adapter_unlock(sa);
1050 
1051 fail_inval:
1052 	sfc_log_init(sa, "failed %d", rc);
1053 	SFC_ASSERT(rc > 0);
1054 	return -rc;
1055 }
1056 static int
1057 sfc_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
1058 {
1059 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1060 	const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
1061 	struct sfc_port *port = &sa->port;
1062 	struct rte_ether_addr *old_addr = &dev->data->mac_addrs[0];
1063 	int rc = 0;
1064 
1065 	sfc_adapter_lock(sa);
1066 
1067 	if (rte_is_same_ether_addr(mac_addr, &port->default_mac_addr))
1068 		goto unlock;
1069 
1070 	/*
1071 	 * Copy the address to the device private data so that
1072 	 * it could be recalled in the case of adapter restart.
1073 	 */
1074 	rte_ether_addr_copy(mac_addr, &port->default_mac_addr);
1075 
1076 	/*
1077 	 * Neither of the two following checks can return
1078 	 * an error. The new MAC address is preserved in
1079 	 * the device private data and can be activated
1080 	 * on the next port start if the user prevents
1081 	 * isolated mode from being enabled.
1082 	 */
1083 	if (sfc_sa2shared(sa)->isolated) {
1084 		sfc_warn(sa, "isolated mode is active on the port");
1085 		sfc_warn(sa, "will not set MAC address");
1086 		goto unlock;
1087 	}
1088 
1089 	if (sa->state != SFC_ADAPTER_STARTED) {
1090 		sfc_notice(sa, "the port is not started");
1091 		sfc_notice(sa, "the new MAC address will be set on port start");
1092 
1093 		goto unlock;
1094 	}
1095 
1096 	if (encp->enc_allow_set_mac_with_installed_filters) {
1097 		rc = efx_mac_addr_set(sa->nic, mac_addr->addr_bytes);
1098 		if (rc != 0) {
1099 			sfc_err(sa, "cannot set MAC address (rc = %u)", rc);
1100 			goto unlock;
1101 		}
1102 
1103 		/*
1104 		 * Changing the MAC address by means of MCDI request
1105 		 * has no effect on received traffic, therefore
1106 		 * we also need to update unicast filters
1107 		 */
1108 		rc = sfc_set_rx_mode_unchecked(sa);
1109 		if (rc != 0) {
1110 			sfc_err(sa, "cannot set filter (rc = %u)", rc);
1111 			/* Rollback the old address */
1112 			(void)efx_mac_addr_set(sa->nic, old_addr->addr_bytes);
1113 			(void)sfc_set_rx_mode_unchecked(sa);
1114 		}
1115 	} else {
1116 		sfc_warn(sa, "cannot set MAC address with filters installed");
1117 		sfc_warn(sa, "adapter will be restarted to pick the new MAC");
1118 		sfc_warn(sa, "(some traffic may be dropped)");
1119 
1120 		/*
1121 		 * Since setting MAC address with filters installed is not
1122 		 * allowed on the adapter, the new MAC address will be set
1123 		 * by means of adapter restart. sfc_start() shall retrieve
1124 		 * the new address from the device private data and set it.
1125 		 */
1126 		sfc_stop(sa);
1127 		rc = sfc_start(sa);
1128 		if (rc != 0)
1129 			sfc_err(sa, "cannot restart adapter (rc = %u)", rc);
1130 	}
1131 
1132 unlock:
1133 	if (rc != 0)
1134 		rte_ether_addr_copy(old_addr, &port->default_mac_addr);
1135 
1136 	sfc_adapter_unlock(sa);
1137 
1138 	SFC_ASSERT(rc >= 0);
1139 	return -rc;
1140 }
1141 
1142 
1143 static int
1144 sfc_set_mc_addr_list(struct rte_eth_dev *dev,
1145 		struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr)
1146 {
1147 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1148 	struct sfc_port *port = &sa->port;
1149 	uint8_t *mc_addrs = port->mcast_addrs;
1150 	int rc;
1151 	unsigned int i;
1152 
1153 	if (sfc_sa2shared(sa)->isolated) {
1154 		sfc_err(sa, "isolated mode is active on the port");
1155 		sfc_err(sa, "will not set multicast address list");
1156 		return -ENOTSUP;
1157 	}
1158 
1159 	if (mc_addrs == NULL)
1160 		return -ENOBUFS;
1161 
1162 	if (nb_mc_addr > port->max_mcast_addrs) {
1163 		sfc_err(sa, "too many multicast addresses: %u > %u",
1164 			 nb_mc_addr, port->max_mcast_addrs);
1165 		return -EINVAL;
1166 	}
1167 
1168 	for (i = 0; i < nb_mc_addr; ++i) {
1169 		rte_memcpy(mc_addrs, mc_addr_set[i].addr_bytes,
1170 				 EFX_MAC_ADDR_LEN);
1171 		mc_addrs += EFX_MAC_ADDR_LEN;
1172 	}
1173 
1174 	port->nb_mcast_addrs = nb_mc_addr;
1175 
1176 	if (sa->state != SFC_ADAPTER_STARTED)
1177 		return 0;
1178 
1179 	rc = efx_mac_multicast_list_set(sa->nic, port->mcast_addrs,
1180 					port->nb_mcast_addrs);
1181 	if (rc != 0)
1182 		sfc_err(sa, "cannot set multicast address list (rc = %u)", rc);
1183 
1184 	SFC_ASSERT(rc >= 0);
1185 	return -rc;
1186 }
1187 
1188 /*
1189  * The function is used by the secondary process as well. It must not
1190  * use any process-local pointers from the adapter data.
1191  */
1192 static void
1193 sfc_rx_queue_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
1194 		      struct rte_eth_rxq_info *qinfo)
1195 {
1196 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1197 	struct sfc_rxq_info *rxq_info;
1198 
1199 	SFC_ASSERT(rx_queue_id < sas->rxq_count);
1200 
1201 	rxq_info = &sas->rxq_info[rx_queue_id];
1202 
1203 	qinfo->mp = rxq_info->refill_mb_pool;
1204 	qinfo->conf.rx_free_thresh = rxq_info->refill_threshold;
1205 	qinfo->conf.rx_drop_en = 1;
1206 	qinfo->conf.rx_deferred_start = rxq_info->deferred_start;
1207 	qinfo->conf.offloads = dev->data->dev_conf.rxmode.offloads;
1208 	if (rxq_info->type_flags & EFX_RXQ_FLAG_SCATTER) {
1209 		qinfo->conf.offloads |= DEV_RX_OFFLOAD_SCATTER;
1210 		qinfo->scattered_rx = 1;
1211 	}
1212 	qinfo->nb_desc = rxq_info->entries;
1213 }
1214 
1215 /*
1216  * The function is used by the secondary process as well. It must not
1217  * use any process-local pointers from the adapter data.
1218  */
1219 static void
1220 sfc_tx_queue_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
1221 		      struct rte_eth_txq_info *qinfo)
1222 {
1223 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1224 	struct sfc_txq_info *txq_info;
1225 
1226 	SFC_ASSERT(tx_queue_id < sas->txq_count);
1227 
1228 	txq_info = &sas->txq_info[tx_queue_id];
1229 
1230 	memset(qinfo, 0, sizeof(*qinfo));
1231 
1232 	qinfo->conf.offloads = txq_info->offloads;
1233 	qinfo->conf.tx_free_thresh = txq_info->free_thresh;
1234 	qinfo->conf.tx_deferred_start = txq_info->deferred_start;
1235 	qinfo->nb_desc = txq_info->entries;
1236 }
1237 
1238 /*
1239  * The function is used by the secondary process as well. It must not
1240  * use any process-local pointers from the adapter data.
1241  */
1242 static uint32_t
1243 sfc_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1244 {
1245 	const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1246 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1247 	struct sfc_rxq_info *rxq_info;
1248 
1249 	SFC_ASSERT(rx_queue_id < sas->rxq_count);
1250 	rxq_info = &sas->rxq_info[rx_queue_id];
1251 
1252 	if ((rxq_info->state & SFC_RXQ_STARTED) == 0)
1253 		return 0;
1254 
1255 	return sap->dp_rx->qdesc_npending(rxq_info->dp);
1256 }
1257 
1258 /*
1259  * The function is used by the secondary process as well. It must not
1260  * use any process-local pointers from the adapter data.
1261  */
1262 static int
1263 sfc_rx_descriptor_done(void *queue, uint16_t offset)
1264 {
1265 	struct sfc_dp_rxq *dp_rxq = queue;
1266 	const struct sfc_dp_rx *dp_rx;
1267 
1268 	dp_rx = sfc_dp_rx_by_dp_rxq(dp_rxq);
1269 
1270 	return offset < dp_rx->qdesc_npending(dp_rxq);
1271 }
1272 
1273 /*
1274  * The function is used by the secondary process as well. It must not
1275  * use any process-local pointers from the adapter data.
1276  */
1277 static int
1278 sfc_rx_descriptor_status(void *queue, uint16_t offset)
1279 {
1280 	struct sfc_dp_rxq *dp_rxq = queue;
1281 	const struct sfc_dp_rx *dp_rx;
1282 
1283 	dp_rx = sfc_dp_rx_by_dp_rxq(dp_rxq);
1284 
1285 	return dp_rx->qdesc_status(dp_rxq, offset);
1286 }
1287 
1288 /*
1289  * The function is used by the secondary process as well. It must not
1290  * use any process-local pointers from the adapter data.
1291  */
1292 static int
1293 sfc_tx_descriptor_status(void *queue, uint16_t offset)
1294 {
1295 	struct sfc_dp_txq *dp_txq = queue;
1296 	const struct sfc_dp_tx *dp_tx;
1297 
1298 	dp_tx = sfc_dp_tx_by_dp_txq(dp_txq);
1299 
1300 	return dp_tx->qdesc_status(dp_txq, offset);
1301 }
1302 
1303 static int
1304 sfc_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1305 {
1306 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1307 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1308 	int rc;
1309 
1310 	sfc_log_init(sa, "RxQ=%u", rx_queue_id);
1311 
1312 	sfc_adapter_lock(sa);
1313 
1314 	rc = EINVAL;
1315 	if (sa->state != SFC_ADAPTER_STARTED)
1316 		goto fail_not_started;
1317 
1318 	if (sas->rxq_info[rx_queue_id].state != SFC_RXQ_INITIALIZED)
1319 		goto fail_not_setup;
1320 
1321 	rc = sfc_rx_qstart(sa, rx_queue_id);
1322 	if (rc != 0)
1323 		goto fail_rx_qstart;
1324 
1325 	sas->rxq_info[rx_queue_id].deferred_started = B_TRUE;
1326 
1327 	sfc_adapter_unlock(sa);
1328 
1329 	return 0;
1330 
1331 fail_rx_qstart:
1332 fail_not_setup:
1333 fail_not_started:
1334 	sfc_adapter_unlock(sa);
1335 	SFC_ASSERT(rc > 0);
1336 	return -rc;
1337 }
1338 
1339 static int
1340 sfc_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
1341 {
1342 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1343 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1344 
1345 	sfc_log_init(sa, "RxQ=%u", rx_queue_id);
1346 
1347 	sfc_adapter_lock(sa);
1348 	sfc_rx_qstop(sa, rx_queue_id);
1349 
1350 	sas->rxq_info[rx_queue_id].deferred_started = B_FALSE;
1351 
1352 	sfc_adapter_unlock(sa);
1353 
1354 	return 0;
1355 }
1356 
1357 static int
1358 sfc_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1359 {
1360 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1361 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1362 	int rc;
1363 
1364 	sfc_log_init(sa, "TxQ = %u", tx_queue_id);
1365 
1366 	sfc_adapter_lock(sa);
1367 
1368 	rc = EINVAL;
1369 	if (sa->state != SFC_ADAPTER_STARTED)
1370 		goto fail_not_started;
1371 
1372 	if (sas->txq_info[tx_queue_id].state != SFC_TXQ_INITIALIZED)
1373 		goto fail_not_setup;
1374 
1375 	rc = sfc_tx_qstart(sa, tx_queue_id);
1376 	if (rc != 0)
1377 		goto fail_tx_qstart;
1378 
1379 	sas->txq_info[tx_queue_id].deferred_started = B_TRUE;
1380 
1381 	sfc_adapter_unlock(sa);
1382 	return 0;
1383 
1384 fail_tx_qstart:
1385 
1386 fail_not_setup:
1387 fail_not_started:
1388 	sfc_adapter_unlock(sa);
1389 	SFC_ASSERT(rc > 0);
1390 	return -rc;
1391 }
1392 
1393 static int
1394 sfc_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
1395 {
1396 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1397 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1398 
1399 	sfc_log_init(sa, "TxQ = %u", tx_queue_id);
1400 
1401 	sfc_adapter_lock(sa);
1402 
1403 	sfc_tx_qstop(sa, tx_queue_id);
1404 
1405 	sas->txq_info[tx_queue_id].deferred_started = B_FALSE;
1406 
1407 	sfc_adapter_unlock(sa);
1408 	return 0;
1409 }
1410 
1411 static efx_tunnel_protocol_t
1412 sfc_tunnel_rte_type_to_efx_udp_proto(enum rte_eth_tunnel_type rte_type)
1413 {
1414 	switch (rte_type) {
1415 	case RTE_TUNNEL_TYPE_VXLAN:
1416 		return EFX_TUNNEL_PROTOCOL_VXLAN;
1417 	case RTE_TUNNEL_TYPE_GENEVE:
1418 		return EFX_TUNNEL_PROTOCOL_GENEVE;
1419 	default:
1420 		return EFX_TUNNEL_NPROTOS;
1421 	}
1422 }
1423 
1424 enum sfc_udp_tunnel_op_e {
1425 	SFC_UDP_TUNNEL_ADD_PORT,
1426 	SFC_UDP_TUNNEL_DEL_PORT,
1427 };
1428 
1429 static int
1430 sfc_dev_udp_tunnel_op(struct rte_eth_dev *dev,
1431 		      struct rte_eth_udp_tunnel *tunnel_udp,
1432 		      enum sfc_udp_tunnel_op_e op)
1433 {
1434 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1435 	efx_tunnel_protocol_t tunnel_proto;
1436 	int rc;
1437 
1438 	sfc_log_init(sa, "%s udp_port=%u prot_type=%u",
1439 		     (op == SFC_UDP_TUNNEL_ADD_PORT) ? "add" :
1440 		     (op == SFC_UDP_TUNNEL_DEL_PORT) ? "delete" : "unknown",
1441 		     tunnel_udp->udp_port, tunnel_udp->prot_type);
1442 
1443 	tunnel_proto =
1444 		sfc_tunnel_rte_type_to_efx_udp_proto(tunnel_udp->prot_type);
1445 	if (tunnel_proto >= EFX_TUNNEL_NPROTOS) {
1446 		rc = ENOTSUP;
1447 		goto fail_bad_proto;
1448 	}
1449 
1450 	sfc_adapter_lock(sa);
1451 
1452 	switch (op) {
1453 	case SFC_UDP_TUNNEL_ADD_PORT:
1454 		rc = efx_tunnel_config_udp_add(sa->nic,
1455 					       tunnel_udp->udp_port,
1456 					       tunnel_proto);
1457 		break;
1458 	case SFC_UDP_TUNNEL_DEL_PORT:
1459 		rc = efx_tunnel_config_udp_remove(sa->nic,
1460 						  tunnel_udp->udp_port,
1461 						  tunnel_proto);
1462 		break;
1463 	default:
1464 		rc = EINVAL;
1465 		goto fail_bad_op;
1466 	}
1467 
1468 	if (rc != 0)
1469 		goto fail_op;
1470 
1471 	if (sa->state == SFC_ADAPTER_STARTED) {
1472 		rc = efx_tunnel_reconfigure(sa->nic);
1473 		if (rc == EAGAIN) {
1474 			/*
1475 			 * Configuration is accepted by FW and MC reboot
1476 			 * is initiated to apply the changes. MC reboot
1477 			 * will be handled in a usual way (MC reboot
1478 			 * event on management event queue and adapter
1479 			 * restart).
1480 			 */
1481 			rc = 0;
1482 		} else if (rc != 0) {
1483 			goto fail_reconfigure;
1484 		}
1485 	}
1486 
1487 	sfc_adapter_unlock(sa);
1488 	return 0;
1489 
1490 fail_reconfigure:
1491 	/* Remove/restore entry since the change makes the trouble */
1492 	switch (op) {
1493 	case SFC_UDP_TUNNEL_ADD_PORT:
1494 		(void)efx_tunnel_config_udp_remove(sa->nic,
1495 						   tunnel_udp->udp_port,
1496 						   tunnel_proto);
1497 		break;
1498 	case SFC_UDP_TUNNEL_DEL_PORT:
1499 		(void)efx_tunnel_config_udp_add(sa->nic,
1500 						tunnel_udp->udp_port,
1501 						tunnel_proto);
1502 		break;
1503 	}
1504 
1505 fail_op:
1506 fail_bad_op:
1507 	sfc_adapter_unlock(sa);
1508 
1509 fail_bad_proto:
1510 	SFC_ASSERT(rc > 0);
1511 	return -rc;
1512 }
1513 
1514 static int
1515 sfc_dev_udp_tunnel_port_add(struct rte_eth_dev *dev,
1516 			    struct rte_eth_udp_tunnel *tunnel_udp)
1517 {
1518 	return sfc_dev_udp_tunnel_op(dev, tunnel_udp, SFC_UDP_TUNNEL_ADD_PORT);
1519 }
1520 
1521 static int
1522 sfc_dev_udp_tunnel_port_del(struct rte_eth_dev *dev,
1523 			    struct rte_eth_udp_tunnel *tunnel_udp)
1524 {
1525 	return sfc_dev_udp_tunnel_op(dev, tunnel_udp, SFC_UDP_TUNNEL_DEL_PORT);
1526 }
1527 
1528 /*
1529  * The function is used by the secondary process as well. It must not
1530  * use any process-local pointers from the adapter data.
1531  */
1532 static int
1533 sfc_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
1534 			  struct rte_eth_rss_conf *rss_conf)
1535 {
1536 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1537 	struct sfc_rss *rss = &sas->rss;
1538 
1539 	if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE)
1540 		return -ENOTSUP;
1541 
1542 	/*
1543 	 * Mapping of hash configuration between RTE and EFX is not one-to-one,
1544 	 * hence, conversion is done here to derive a correct set of ETH_RSS
1545 	 * flags which corresponds to the active EFX configuration stored
1546 	 * locally in 'sfc_adapter' and kept up-to-date
1547 	 */
1548 	rss_conf->rss_hf = sfc_rx_hf_efx_to_rte(rss, rss->hash_types);
1549 	rss_conf->rss_key_len = EFX_RSS_KEY_SIZE;
1550 	if (rss_conf->rss_key != NULL)
1551 		rte_memcpy(rss_conf->rss_key, rss->key, EFX_RSS_KEY_SIZE);
1552 
1553 	return 0;
1554 }
1555 
1556 static int
1557 sfc_dev_rss_hash_update(struct rte_eth_dev *dev,
1558 			struct rte_eth_rss_conf *rss_conf)
1559 {
1560 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1561 	struct sfc_rss *rss = &sfc_sa2shared(sa)->rss;
1562 	unsigned int efx_hash_types;
1563 	uint32_t contexts[] = {EFX_RSS_CONTEXT_DEFAULT, rss->dummy_rss_context};
1564 	unsigned int n_contexts;
1565 	unsigned int mode_i = 0;
1566 	unsigned int key_i = 0;
1567 	unsigned int i = 0;
1568 	int rc = 0;
1569 
1570 	n_contexts = rss->dummy_rss_context == EFX_RSS_CONTEXT_DEFAULT ? 1 : 2;
1571 
1572 	if (sfc_sa2shared(sa)->isolated)
1573 		return -ENOTSUP;
1574 
1575 	if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE) {
1576 		sfc_err(sa, "RSS is not available");
1577 		return -ENOTSUP;
1578 	}
1579 
1580 	if (rss->channels == 0) {
1581 		sfc_err(sa, "RSS is not configured");
1582 		return -EINVAL;
1583 	}
1584 
1585 	if ((rss_conf->rss_key != NULL) &&
1586 	    (rss_conf->rss_key_len != sizeof(rss->key))) {
1587 		sfc_err(sa, "RSS key size is wrong (should be %zu)",
1588 			sizeof(rss->key));
1589 		return -EINVAL;
1590 	}
1591 
1592 	sfc_adapter_lock(sa);
1593 
1594 	rc = sfc_rx_hf_rte_to_efx(sa, rss_conf->rss_hf, &efx_hash_types);
1595 	if (rc != 0)
1596 		goto fail_rx_hf_rte_to_efx;
1597 
1598 	for (mode_i = 0; mode_i < n_contexts; mode_i++) {
1599 		rc = efx_rx_scale_mode_set(sa->nic, contexts[mode_i],
1600 					   rss->hash_alg, efx_hash_types,
1601 					   B_TRUE);
1602 		if (rc != 0)
1603 			goto fail_scale_mode_set;
1604 	}
1605 
1606 	if (rss_conf->rss_key != NULL) {
1607 		if (sa->state == SFC_ADAPTER_STARTED) {
1608 			for (key_i = 0; key_i < n_contexts; key_i++) {
1609 				rc = efx_rx_scale_key_set(sa->nic,
1610 							  contexts[key_i],
1611 							  rss_conf->rss_key,
1612 							  sizeof(rss->key));
1613 				if (rc != 0)
1614 					goto fail_scale_key_set;
1615 			}
1616 		}
1617 
1618 		rte_memcpy(rss->key, rss_conf->rss_key, sizeof(rss->key));
1619 	}
1620 
1621 	rss->hash_types = efx_hash_types;
1622 
1623 	sfc_adapter_unlock(sa);
1624 
1625 	return 0;
1626 
1627 fail_scale_key_set:
1628 	for (i = 0; i < key_i; i++) {
1629 		if (efx_rx_scale_key_set(sa->nic, contexts[i], rss->key,
1630 					 sizeof(rss->key)) != 0)
1631 			sfc_err(sa, "failed to restore RSS key");
1632 	}
1633 
1634 fail_scale_mode_set:
1635 	for (i = 0; i < mode_i; i++) {
1636 		if (efx_rx_scale_mode_set(sa->nic, contexts[i],
1637 					  EFX_RX_HASHALG_TOEPLITZ,
1638 					  rss->hash_types, B_TRUE) != 0)
1639 			sfc_err(sa, "failed to restore RSS mode");
1640 	}
1641 
1642 fail_rx_hf_rte_to_efx:
1643 	sfc_adapter_unlock(sa);
1644 	return -rc;
1645 }
1646 
1647 /*
1648  * The function is used by the secondary process as well. It must not
1649  * use any process-local pointers from the adapter data.
1650  */
1651 static int
1652 sfc_dev_rss_reta_query(struct rte_eth_dev *dev,
1653 		       struct rte_eth_rss_reta_entry64 *reta_conf,
1654 		       uint16_t reta_size)
1655 {
1656 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1657 	struct sfc_rss *rss = &sas->rss;
1658 	int entry;
1659 
1660 	if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE || sas->isolated)
1661 		return -ENOTSUP;
1662 
1663 	if (rss->channels == 0)
1664 		return -EINVAL;
1665 
1666 	if (reta_size != EFX_RSS_TBL_SIZE)
1667 		return -EINVAL;
1668 
1669 	for (entry = 0; entry < reta_size; entry++) {
1670 		int grp = entry / RTE_RETA_GROUP_SIZE;
1671 		int grp_idx = entry % RTE_RETA_GROUP_SIZE;
1672 
1673 		if ((reta_conf[grp].mask >> grp_idx) & 1)
1674 			reta_conf[grp].reta[grp_idx] = rss->tbl[entry];
1675 	}
1676 
1677 	return 0;
1678 }
1679 
1680 static int
1681 sfc_dev_rss_reta_update(struct rte_eth_dev *dev,
1682 			struct rte_eth_rss_reta_entry64 *reta_conf,
1683 			uint16_t reta_size)
1684 {
1685 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1686 	struct sfc_rss *rss = &sfc_sa2shared(sa)->rss;
1687 	unsigned int *rss_tbl_new;
1688 	uint16_t entry;
1689 	int rc = 0;
1690 
1691 
1692 	if (sfc_sa2shared(sa)->isolated)
1693 		return -ENOTSUP;
1694 
1695 	if (rss->context_type != EFX_RX_SCALE_EXCLUSIVE) {
1696 		sfc_err(sa, "RSS is not available");
1697 		return -ENOTSUP;
1698 	}
1699 
1700 	if (rss->channels == 0) {
1701 		sfc_err(sa, "RSS is not configured");
1702 		return -EINVAL;
1703 	}
1704 
1705 	if (reta_size != EFX_RSS_TBL_SIZE) {
1706 		sfc_err(sa, "RETA size is wrong (should be %u)",
1707 			EFX_RSS_TBL_SIZE);
1708 		return -EINVAL;
1709 	}
1710 
1711 	rss_tbl_new = rte_zmalloc("rss_tbl_new", sizeof(rss->tbl), 0);
1712 	if (rss_tbl_new == NULL)
1713 		return -ENOMEM;
1714 
1715 	sfc_adapter_lock(sa);
1716 
1717 	rte_memcpy(rss_tbl_new, rss->tbl, sizeof(rss->tbl));
1718 
1719 	for (entry = 0; entry < reta_size; entry++) {
1720 		int grp_idx = entry % RTE_RETA_GROUP_SIZE;
1721 		struct rte_eth_rss_reta_entry64 *grp;
1722 
1723 		grp = &reta_conf[entry / RTE_RETA_GROUP_SIZE];
1724 
1725 		if (grp->mask & (1ull << grp_idx)) {
1726 			if (grp->reta[grp_idx] >= rss->channels) {
1727 				rc = EINVAL;
1728 				goto bad_reta_entry;
1729 			}
1730 			rss_tbl_new[entry] = grp->reta[grp_idx];
1731 		}
1732 	}
1733 
1734 	if (sa->state == SFC_ADAPTER_STARTED) {
1735 		rc = efx_rx_scale_tbl_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
1736 					  rss_tbl_new, EFX_RSS_TBL_SIZE);
1737 		if (rc != 0)
1738 			goto fail_scale_tbl_set;
1739 	}
1740 
1741 	rte_memcpy(rss->tbl, rss_tbl_new, sizeof(rss->tbl));
1742 
1743 fail_scale_tbl_set:
1744 bad_reta_entry:
1745 	sfc_adapter_unlock(sa);
1746 
1747 	rte_free(rss_tbl_new);
1748 
1749 	SFC_ASSERT(rc >= 0);
1750 	return -rc;
1751 }
1752 
1753 static int
1754 sfc_dev_flow_ops_get(struct rte_eth_dev *dev __rte_unused,
1755 		     const struct rte_flow_ops **ops)
1756 {
1757 	*ops = &sfc_flow_ops;
1758 	return 0;
1759 }
1760 
1761 static int
1762 sfc_pool_ops_supported(struct rte_eth_dev *dev, const char *pool)
1763 {
1764 	const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1765 
1766 	/*
1767 	 * If Rx datapath does not provide callback to check mempool,
1768 	 * all pools are supported.
1769 	 */
1770 	if (sap->dp_rx->pool_ops_supported == NULL)
1771 		return 1;
1772 
1773 	return sap->dp_rx->pool_ops_supported(pool);
1774 }
1775 
1776 static int
1777 sfc_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1778 {
1779 	const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1780 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1781 	struct sfc_rxq_info *rxq_info;
1782 
1783 	SFC_ASSERT(queue_id < sas->rxq_count);
1784 	rxq_info = &sas->rxq_info[queue_id];
1785 
1786 	return sap->dp_rx->intr_enable(rxq_info->dp);
1787 }
1788 
1789 static int
1790 sfc_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1791 {
1792 	const struct sfc_adapter_priv *sap = sfc_adapter_priv_by_eth_dev(dev);
1793 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1794 	struct sfc_rxq_info *rxq_info;
1795 
1796 	SFC_ASSERT(queue_id < sas->rxq_count);
1797 	rxq_info = &sas->rxq_info[queue_id];
1798 
1799 	return sap->dp_rx->intr_disable(rxq_info->dp);
1800 }
1801 
1802 static const struct eth_dev_ops sfc_eth_dev_ops = {
1803 	.dev_configure			= sfc_dev_configure,
1804 	.dev_start			= sfc_dev_start,
1805 	.dev_stop			= sfc_dev_stop,
1806 	.dev_set_link_up		= sfc_dev_set_link_up,
1807 	.dev_set_link_down		= sfc_dev_set_link_down,
1808 	.dev_close			= sfc_dev_close,
1809 	.promiscuous_enable		= sfc_dev_promisc_enable,
1810 	.promiscuous_disable		= sfc_dev_promisc_disable,
1811 	.allmulticast_enable		= sfc_dev_allmulti_enable,
1812 	.allmulticast_disable		= sfc_dev_allmulti_disable,
1813 	.link_update			= sfc_dev_link_update,
1814 	.stats_get			= sfc_stats_get,
1815 	.stats_reset			= sfc_stats_reset,
1816 	.xstats_get			= sfc_xstats_get,
1817 	.xstats_reset			= sfc_stats_reset,
1818 	.xstats_get_names		= sfc_xstats_get_names,
1819 	.dev_infos_get			= sfc_dev_infos_get,
1820 	.dev_supported_ptypes_get	= sfc_dev_supported_ptypes_get,
1821 	.mtu_set			= sfc_dev_set_mtu,
1822 	.rx_queue_start			= sfc_rx_queue_start,
1823 	.rx_queue_stop			= sfc_rx_queue_stop,
1824 	.tx_queue_start			= sfc_tx_queue_start,
1825 	.tx_queue_stop			= sfc_tx_queue_stop,
1826 	.rx_queue_setup			= sfc_rx_queue_setup,
1827 	.rx_queue_release		= sfc_rx_queue_release,
1828 	.rx_queue_intr_enable		= sfc_rx_queue_intr_enable,
1829 	.rx_queue_intr_disable		= sfc_rx_queue_intr_disable,
1830 	.tx_queue_setup			= sfc_tx_queue_setup,
1831 	.tx_queue_release		= sfc_tx_queue_release,
1832 	.flow_ctrl_get			= sfc_flow_ctrl_get,
1833 	.flow_ctrl_set			= sfc_flow_ctrl_set,
1834 	.mac_addr_set			= sfc_mac_addr_set,
1835 	.udp_tunnel_port_add		= sfc_dev_udp_tunnel_port_add,
1836 	.udp_tunnel_port_del		= sfc_dev_udp_tunnel_port_del,
1837 	.reta_update			= sfc_dev_rss_reta_update,
1838 	.reta_query			= sfc_dev_rss_reta_query,
1839 	.rss_hash_update		= sfc_dev_rss_hash_update,
1840 	.rss_hash_conf_get		= sfc_dev_rss_hash_conf_get,
1841 	.flow_ops_get			= sfc_dev_flow_ops_get,
1842 	.set_mc_addr_list		= sfc_set_mc_addr_list,
1843 	.rxq_info_get			= sfc_rx_queue_info_get,
1844 	.txq_info_get			= sfc_tx_queue_info_get,
1845 	.fw_version_get			= sfc_fw_version_get,
1846 	.xstats_get_by_id		= sfc_xstats_get_by_id,
1847 	.xstats_get_names_by_id		= sfc_xstats_get_names_by_id,
1848 	.pool_ops_supported		= sfc_pool_ops_supported,
1849 };
1850 
1851 /**
1852  * Duplicate a string in potentially shared memory required for
1853  * multi-process support.
1854  *
1855  * strdup() allocates from process-local heap/memory.
1856  */
1857 static char *
1858 sfc_strdup(const char *str)
1859 {
1860 	size_t size;
1861 	char *copy;
1862 
1863 	if (str == NULL)
1864 		return NULL;
1865 
1866 	size = strlen(str) + 1;
1867 	copy = rte_malloc(__func__, size, 0);
1868 	if (copy != NULL)
1869 		rte_memcpy(copy, str, size);
1870 
1871 	return copy;
1872 }
1873 
1874 static int
1875 sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
1876 {
1877 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
1878 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
1879 	const struct sfc_dp_rx *dp_rx;
1880 	const struct sfc_dp_tx *dp_tx;
1881 	const efx_nic_cfg_t *encp;
1882 	unsigned int avail_caps = 0;
1883 	const char *rx_name = NULL;
1884 	const char *tx_name = NULL;
1885 	int rc;
1886 
1887 	switch (sa->family) {
1888 	case EFX_FAMILY_HUNTINGTON:
1889 	case EFX_FAMILY_MEDFORD:
1890 	case EFX_FAMILY_MEDFORD2:
1891 		avail_caps |= SFC_DP_HW_FW_CAP_EF10;
1892 		avail_caps |= SFC_DP_HW_FW_CAP_RX_EFX;
1893 		avail_caps |= SFC_DP_HW_FW_CAP_TX_EFX;
1894 		break;
1895 	case EFX_FAMILY_RIVERHEAD:
1896 		avail_caps |= SFC_DP_HW_FW_CAP_EF100;
1897 		break;
1898 	default:
1899 		break;
1900 	}
1901 
1902 	encp = efx_nic_cfg_get(sa->nic);
1903 	if (encp->enc_rx_es_super_buffer_supported)
1904 		avail_caps |= SFC_DP_HW_FW_CAP_RX_ES_SUPER_BUFFER;
1905 
1906 	rc = sfc_kvargs_process(sa, SFC_KVARG_RX_DATAPATH,
1907 				sfc_kvarg_string_handler, &rx_name);
1908 	if (rc != 0)
1909 		goto fail_kvarg_rx_datapath;
1910 
1911 	if (rx_name != NULL) {
1912 		dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, rx_name);
1913 		if (dp_rx == NULL) {
1914 			sfc_err(sa, "Rx datapath %s not found", rx_name);
1915 			rc = ENOENT;
1916 			goto fail_dp_rx;
1917 		}
1918 		if (!sfc_dp_match_hw_fw_caps(&dp_rx->dp, avail_caps)) {
1919 			sfc_err(sa,
1920 				"Insufficient Hw/FW capabilities to use Rx datapath %s",
1921 				rx_name);
1922 			rc = EINVAL;
1923 			goto fail_dp_rx_caps;
1924 		}
1925 	} else {
1926 		dp_rx = sfc_dp_find_rx_by_caps(&sfc_dp_head, avail_caps);
1927 		if (dp_rx == NULL) {
1928 			sfc_err(sa, "Rx datapath by caps %#x not found",
1929 				avail_caps);
1930 			rc = ENOENT;
1931 			goto fail_dp_rx;
1932 		}
1933 	}
1934 
1935 	sas->dp_rx_name = sfc_strdup(dp_rx->dp.name);
1936 	if (sas->dp_rx_name == NULL) {
1937 		rc = ENOMEM;
1938 		goto fail_dp_rx_name;
1939 	}
1940 
1941 	sfc_notice(sa, "use %s Rx datapath", sas->dp_rx_name);
1942 
1943 	rc = sfc_kvargs_process(sa, SFC_KVARG_TX_DATAPATH,
1944 				sfc_kvarg_string_handler, &tx_name);
1945 	if (rc != 0)
1946 		goto fail_kvarg_tx_datapath;
1947 
1948 	if (tx_name != NULL) {
1949 		dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, tx_name);
1950 		if (dp_tx == NULL) {
1951 			sfc_err(sa, "Tx datapath %s not found", tx_name);
1952 			rc = ENOENT;
1953 			goto fail_dp_tx;
1954 		}
1955 		if (!sfc_dp_match_hw_fw_caps(&dp_tx->dp, avail_caps)) {
1956 			sfc_err(sa,
1957 				"Insufficient Hw/FW capabilities to use Tx datapath %s",
1958 				tx_name);
1959 			rc = EINVAL;
1960 			goto fail_dp_tx_caps;
1961 		}
1962 	} else {
1963 		dp_tx = sfc_dp_find_tx_by_caps(&sfc_dp_head, avail_caps);
1964 		if (dp_tx == NULL) {
1965 			sfc_err(sa, "Tx datapath by caps %#x not found",
1966 				avail_caps);
1967 			rc = ENOENT;
1968 			goto fail_dp_tx;
1969 		}
1970 	}
1971 
1972 	sas->dp_tx_name = sfc_strdup(dp_tx->dp.name);
1973 	if (sas->dp_tx_name == NULL) {
1974 		rc = ENOMEM;
1975 		goto fail_dp_tx_name;
1976 	}
1977 
1978 	sfc_notice(sa, "use %s Tx datapath", sas->dp_tx_name);
1979 
1980 	sa->priv.dp_rx = dp_rx;
1981 	sa->priv.dp_tx = dp_tx;
1982 
1983 	dev->rx_pkt_burst = dp_rx->pkt_burst;
1984 	dev->tx_pkt_prepare = dp_tx->pkt_prepare;
1985 	dev->tx_pkt_burst = dp_tx->pkt_burst;
1986 
1987 	dev->rx_queue_count = sfc_rx_queue_count;
1988 	dev->rx_descriptor_done = sfc_rx_descriptor_done;
1989 	dev->rx_descriptor_status = sfc_rx_descriptor_status;
1990 	dev->tx_descriptor_status = sfc_tx_descriptor_status;
1991 	dev->dev_ops = &sfc_eth_dev_ops;
1992 
1993 	return 0;
1994 
1995 fail_dp_tx_name:
1996 fail_dp_tx_caps:
1997 fail_dp_tx:
1998 fail_kvarg_tx_datapath:
1999 	rte_free(sas->dp_rx_name);
2000 	sas->dp_rx_name = NULL;
2001 
2002 fail_dp_rx_name:
2003 fail_dp_rx_caps:
2004 fail_dp_rx:
2005 fail_kvarg_rx_datapath:
2006 	return rc;
2007 }
2008 
2009 static void
2010 sfc_eth_dev_clear_ops(struct rte_eth_dev *dev)
2011 {
2012 	struct sfc_adapter *sa = sfc_adapter_by_eth_dev(dev);
2013 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2014 
2015 	dev->dev_ops = NULL;
2016 	dev->tx_pkt_prepare = NULL;
2017 	dev->rx_pkt_burst = NULL;
2018 	dev->tx_pkt_burst = NULL;
2019 
2020 	rte_free(sas->dp_tx_name);
2021 	sas->dp_tx_name = NULL;
2022 	sa->priv.dp_tx = NULL;
2023 
2024 	rte_free(sas->dp_rx_name);
2025 	sas->dp_rx_name = NULL;
2026 	sa->priv.dp_rx = NULL;
2027 }
2028 
2029 static const struct eth_dev_ops sfc_eth_dev_secondary_ops = {
2030 	.dev_supported_ptypes_get	= sfc_dev_supported_ptypes_get,
2031 	.reta_query			= sfc_dev_rss_reta_query,
2032 	.rss_hash_conf_get		= sfc_dev_rss_hash_conf_get,
2033 	.rxq_info_get			= sfc_rx_queue_info_get,
2034 	.txq_info_get			= sfc_tx_queue_info_get,
2035 };
2036 
2037 static int
2038 sfc_eth_dev_secondary_init(struct rte_eth_dev *dev, uint32_t logtype_main)
2039 {
2040 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2041 	struct sfc_adapter_priv *sap;
2042 	const struct sfc_dp_rx *dp_rx;
2043 	const struct sfc_dp_tx *dp_tx;
2044 	int rc;
2045 
2046 	/*
2047 	 * Allocate process private data from heap, since it should not
2048 	 * be located in shared memory allocated using rte_malloc() API.
2049 	 */
2050 	sap = calloc(1, sizeof(*sap));
2051 	if (sap == NULL) {
2052 		rc = ENOMEM;
2053 		goto fail_alloc_priv;
2054 	}
2055 
2056 	sap->logtype_main = logtype_main;
2057 
2058 	dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, sas->dp_rx_name);
2059 	if (dp_rx == NULL) {
2060 		SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2061 			"cannot find %s Rx datapath", sas->dp_rx_name);
2062 		rc = ENOENT;
2063 		goto fail_dp_rx;
2064 	}
2065 	if (~dp_rx->features & SFC_DP_RX_FEAT_MULTI_PROCESS) {
2066 		SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2067 			"%s Rx datapath does not support multi-process",
2068 			sas->dp_rx_name);
2069 		rc = EINVAL;
2070 		goto fail_dp_rx_multi_process;
2071 	}
2072 
2073 	dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, sas->dp_tx_name);
2074 	if (dp_tx == NULL) {
2075 		SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2076 			"cannot find %s Tx datapath", sas->dp_tx_name);
2077 		rc = ENOENT;
2078 		goto fail_dp_tx;
2079 	}
2080 	if (~dp_tx->features & SFC_DP_TX_FEAT_MULTI_PROCESS) {
2081 		SFC_LOG(sas, RTE_LOG_ERR, logtype_main,
2082 			"%s Tx datapath does not support multi-process",
2083 			sas->dp_tx_name);
2084 		rc = EINVAL;
2085 		goto fail_dp_tx_multi_process;
2086 	}
2087 
2088 	sap->dp_rx = dp_rx;
2089 	sap->dp_tx = dp_tx;
2090 
2091 	dev->process_private = sap;
2092 	dev->rx_pkt_burst = dp_rx->pkt_burst;
2093 	dev->tx_pkt_prepare = dp_tx->pkt_prepare;
2094 	dev->tx_pkt_burst = dp_tx->pkt_burst;
2095 	dev->rx_queue_count = sfc_rx_queue_count;
2096 	dev->rx_descriptor_done = sfc_rx_descriptor_done;
2097 	dev->rx_descriptor_status = sfc_rx_descriptor_status;
2098 	dev->tx_descriptor_status = sfc_tx_descriptor_status;
2099 	dev->dev_ops = &sfc_eth_dev_secondary_ops;
2100 
2101 	return 0;
2102 
2103 fail_dp_tx_multi_process:
2104 fail_dp_tx:
2105 fail_dp_rx_multi_process:
2106 fail_dp_rx:
2107 	free(sap);
2108 
2109 fail_alloc_priv:
2110 	return rc;
2111 }
2112 
2113 static void
2114 sfc_register_dp(void)
2115 {
2116 	/* Register once */
2117 	if (TAILQ_EMPTY(&sfc_dp_head)) {
2118 		/* Prefer EF10 datapath */
2119 		sfc_dp_register(&sfc_dp_head, &sfc_ef100_rx.dp);
2120 		sfc_dp_register(&sfc_dp_head, &sfc_ef10_essb_rx.dp);
2121 		sfc_dp_register(&sfc_dp_head, &sfc_ef10_rx.dp);
2122 		sfc_dp_register(&sfc_dp_head, &sfc_efx_rx.dp);
2123 
2124 		sfc_dp_register(&sfc_dp_head, &sfc_ef100_tx.dp);
2125 		sfc_dp_register(&sfc_dp_head, &sfc_ef10_tx.dp);
2126 		sfc_dp_register(&sfc_dp_head, &sfc_efx_tx.dp);
2127 		sfc_dp_register(&sfc_dp_head, &sfc_ef10_simple_tx.dp);
2128 	}
2129 }
2130 
2131 static int
2132 sfc_eth_dev_init(struct rte_eth_dev *dev)
2133 {
2134 	struct sfc_adapter_shared *sas = sfc_adapter_shared_by_eth_dev(dev);
2135 	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
2136 	uint32_t logtype_main;
2137 	struct sfc_adapter *sa;
2138 	int rc;
2139 	const efx_nic_cfg_t *encp;
2140 	const struct rte_ether_addr *from;
2141 	int ret;
2142 
2143 	if (sfc_efx_dev_class_get(pci_dev->device.devargs) !=
2144 			SFC_EFX_DEV_CLASS_NET) {
2145 		SFC_GENERIC_LOG(DEBUG,
2146 			"Incompatible device class: skip probing, should be probed by other sfc driver.");
2147 		return 1;
2148 	}
2149 
2150 	sfc_register_dp();
2151 
2152 	logtype_main = sfc_register_logtype(&pci_dev->addr,
2153 					    SFC_LOGTYPE_MAIN_STR,
2154 					    RTE_LOG_NOTICE);
2155 
2156 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2157 		return -sfc_eth_dev_secondary_init(dev, logtype_main);
2158 
2159 	/* Required for logging */
2160 	ret = snprintf(sas->log_prefix, sizeof(sas->log_prefix),
2161 			"PMD: sfc_efx " PCI_PRI_FMT " #%" PRIu16 ": ",
2162 			pci_dev->addr.domain, pci_dev->addr.bus,
2163 			pci_dev->addr.devid, pci_dev->addr.function,
2164 			dev->data->port_id);
2165 	if (ret < 0 || ret >= (int)sizeof(sas->log_prefix)) {
2166 		SFC_GENERIC_LOG(ERR,
2167 			"reserved log prefix is too short for " PCI_PRI_FMT,
2168 			pci_dev->addr.domain, pci_dev->addr.bus,
2169 			pci_dev->addr.devid, pci_dev->addr.function);
2170 		return -EINVAL;
2171 	}
2172 	sas->pci_addr = pci_dev->addr;
2173 	sas->port_id = dev->data->port_id;
2174 
2175 	/*
2176 	 * Allocate process private data from heap, since it should not
2177 	 * be located in shared memory allocated using rte_malloc() API.
2178 	 */
2179 	sa = calloc(1, sizeof(*sa));
2180 	if (sa == NULL) {
2181 		rc = ENOMEM;
2182 		goto fail_alloc_sa;
2183 	}
2184 
2185 	dev->process_private = sa;
2186 
2187 	/* Required for logging */
2188 	sa->priv.shared = sas;
2189 	sa->priv.logtype_main = logtype_main;
2190 
2191 	sa->eth_dev = dev;
2192 
2193 	/* Copy PCI device info to the dev->data */
2194 	rte_eth_copy_pci_info(dev, pci_dev);
2195 	dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
2196 	dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
2197 
2198 	rc = sfc_kvargs_parse(sa);
2199 	if (rc != 0)
2200 		goto fail_kvargs_parse;
2201 
2202 	sfc_log_init(sa, "entry");
2203 
2204 	dev->data->mac_addrs = rte_zmalloc("sfc", RTE_ETHER_ADDR_LEN, 0);
2205 	if (dev->data->mac_addrs == NULL) {
2206 		rc = ENOMEM;
2207 		goto fail_mac_addrs;
2208 	}
2209 
2210 	sfc_adapter_lock_init(sa);
2211 	sfc_adapter_lock(sa);
2212 
2213 	sfc_log_init(sa, "probing");
2214 	rc = sfc_probe(sa);
2215 	if (rc != 0)
2216 		goto fail_probe;
2217 
2218 	sfc_log_init(sa, "set device ops");
2219 	rc = sfc_eth_dev_set_ops(dev);
2220 	if (rc != 0)
2221 		goto fail_set_ops;
2222 
2223 	sfc_log_init(sa, "attaching");
2224 	rc = sfc_attach(sa);
2225 	if (rc != 0)
2226 		goto fail_attach;
2227 
2228 	encp = efx_nic_cfg_get(sa->nic);
2229 
2230 	/*
2231 	 * The arguments are really reverse order in comparison to
2232 	 * Linux kernel. Copy from NIC config to Ethernet device data.
2233 	 */
2234 	from = (const struct rte_ether_addr *)(encp->enc_mac_addr);
2235 	rte_ether_addr_copy(from, &dev->data->mac_addrs[0]);
2236 
2237 	sfc_adapter_unlock(sa);
2238 
2239 	sfc_log_init(sa, "done");
2240 	return 0;
2241 
2242 fail_attach:
2243 	sfc_eth_dev_clear_ops(dev);
2244 
2245 fail_set_ops:
2246 	sfc_unprobe(sa);
2247 
2248 fail_probe:
2249 	sfc_adapter_unlock(sa);
2250 	sfc_adapter_lock_fini(sa);
2251 	rte_free(dev->data->mac_addrs);
2252 	dev->data->mac_addrs = NULL;
2253 
2254 fail_mac_addrs:
2255 	sfc_kvargs_cleanup(sa);
2256 
2257 fail_kvargs_parse:
2258 	sfc_log_init(sa, "failed %d", rc);
2259 	dev->process_private = NULL;
2260 	free(sa);
2261 
2262 fail_alloc_sa:
2263 	SFC_ASSERT(rc > 0);
2264 	return -rc;
2265 }
2266 
2267 static int
2268 sfc_eth_dev_uninit(struct rte_eth_dev *dev)
2269 {
2270 	sfc_dev_close(dev);
2271 
2272 	return 0;
2273 }
2274 
2275 static const struct rte_pci_id pci_id_sfc_efx_map[] = {
2276 	{ RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_FARMINGDALE) },
2277 	{ RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_FARMINGDALE_VF) },
2278 	{ RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_GREENPORT) },
2279 	{ RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_GREENPORT_VF) },
2280 	{ RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD) },
2281 	{ RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD_VF) },
2282 	{ RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD2) },
2283 	{ RTE_PCI_DEVICE(EFX_PCI_VENID_SFC, EFX_PCI_DEVID_MEDFORD2_VF) },
2284 	{ RTE_PCI_DEVICE(EFX_PCI_VENID_XILINX, EFX_PCI_DEVID_RIVERHEAD) },
2285 	{ .vendor_id = 0 /* sentinel */ }
2286 };
2287 
2288 static int sfc_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2289 	struct rte_pci_device *pci_dev)
2290 {
2291 	return rte_eth_dev_pci_generic_probe(pci_dev,
2292 		sizeof(struct sfc_adapter_shared), sfc_eth_dev_init);
2293 }
2294 
2295 static int sfc_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
2296 {
2297 	return rte_eth_dev_pci_generic_remove(pci_dev, sfc_eth_dev_uninit);
2298 }
2299 
2300 static struct rte_pci_driver sfc_efx_pmd = {
2301 	.id_table = pci_id_sfc_efx_map,
2302 	.drv_flags =
2303 		RTE_PCI_DRV_INTR_LSC |
2304 		RTE_PCI_DRV_NEED_MAPPING,
2305 	.probe = sfc_eth_dev_pci_probe,
2306 	.remove = sfc_eth_dev_pci_remove,
2307 };
2308 
2309 RTE_PMD_REGISTER_PCI(net_sfc_efx, sfc_efx_pmd);
2310 RTE_PMD_REGISTER_PCI_TABLE(net_sfc_efx, pci_id_sfc_efx_map);
2311 RTE_PMD_REGISTER_KMOD_DEP(net_sfc_efx, "* igb_uio | uio_pci_generic | vfio-pci");
2312 RTE_PMD_REGISTER_PARAM_STRING(net_sfc_efx,
2313 	SFC_KVARG_RX_DATAPATH "=" SFC_KVARG_VALUES_RX_DATAPATH " "
2314 	SFC_KVARG_TX_DATAPATH "=" SFC_KVARG_VALUES_TX_DATAPATH " "
2315 	SFC_KVARG_PERF_PROFILE "=" SFC_KVARG_VALUES_PERF_PROFILE " "
2316 	SFC_KVARG_FW_VARIANT "=" SFC_KVARG_VALUES_FW_VARIANT " "
2317 	SFC_KVARG_RXD_WAIT_TIMEOUT_NS "=<long> "
2318 	SFC_KVARG_STATS_UPDATE_PERIOD_MS "=<long>");
2319 
2320 RTE_INIT(sfc_driver_register_logtype)
2321 {
2322 	int ret;
2323 
2324 	ret = rte_log_register_type_and_pick_level(SFC_LOGTYPE_PREFIX "driver",
2325 						   RTE_LOG_NOTICE);
2326 	sfc_logtype_driver = (ret < 0) ? RTE_LOGTYPE_PMD : ret;
2327 }
2328