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