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

Generated by: LCOV version 1.14