LCOV - code coverage report
Current view: top level - drivers/net/sfc - sfc_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 2 1370 0.1 %
Date: 2024-12-01 18:57:19 Functions: 2 88 2.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 716 0.1 %

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

Generated by: LCOV version 1.14