New upstream version 17.11.4
[deb_dpdk.git] / drivers / net / sfc / sfc_ethdev.c
index bdb4c46..1b160b5 100644 (file)
@@ -33,6 +33,7 @@
 #include <rte_ethdev.h>
 #include <rte_ethdev_pci.h>
 #include <rte_pci.h>
+#include <rte_bus_pci.h>
 #include <rte_errno.h>
 
 #include "efx.h"
@@ -107,7 +108,7 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 
        sfc_log_init(sa, "entry");
 
-       dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device);
+       dev_info->pci_dev = RTE_ETH_DEV_TO_PCI(dev);
        dev_info->max_rx_pktlen = EFX_MAC_PDU_MAX;
 
        /* Autonegotiation may be disabled */
@@ -145,10 +146,16 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        if (~sa->dp_tx->features & SFC_DP_TX_FEAT_MULTI_SEG)
                dev_info->default_txconf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS;
 
+       if (~sa->dp_tx->features & SFC_DP_TX_FEAT_MULTI_POOL)
+               dev_info->default_txconf.txq_flags |= ETH_TXQ_FLAGS_NOMULTMEMP;
+
+       if (~sa->dp_tx->features & SFC_DP_TX_FEAT_REFCNT)
+               dev_info->default_txconf.txq_flags |= ETH_TXQ_FLAGS_NOREFCOUNT;
+
 #if EFSYS_OPT_RX_SCALE
        if (sa->rss_support != EFX_RX_SCALE_UNAVAILABLE) {
                dev_info->reta_size = EFX_RSS_TBL_SIZE;
-               dev_info->hash_key_size = SFC_RSS_KEY_SIZE;
+               dev_info->hash_key_size = EFX_RSS_KEY_SIZE;
                dev_info->flow_type_rss_offloads = SFC_RSS_OFFLOADS;
        }
 #endif
@@ -361,8 +368,13 @@ sfc_dev_filter_set(struct rte_eth_dev *dev, enum sfc_dev_filter_mode mode,
        if (*toggle != enabled) {
                *toggle = enabled;
 
-               if ((sa->state == SFC_ADAPTER_STARTED) &&
-                   (sfc_set_rx_mode(sa) != 0)) {
+               if (port->isolated) {
+                       sfc_warn(sa, "isolated mode is active on the port");
+                       sfc_warn(sa, "the change is to be applied on the next "
+                                    "start provided that isolated mode is "
+                                    "disabled prior the next start");
+               } else if ((sa->state == SFC_ADAPTER_STARTED) &&
+                          (sfc_set_rx_mode(sa) != 0)) {
                        *toggle = !(enabled);
                        sfc_warn(sa, "Failed to %s %s mode",
                                 ((enabled) ? "enable" : "disable"), desc);
@@ -510,16 +522,18 @@ sfc_tx_queue_release(void *queue)
        sfc_adapter_unlock(sa);
 }
 
-static void
+static int
 sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 {
        struct sfc_adapter *sa = dev->data->dev_private;
        struct sfc_port *port = &sa->port;
        uint64_t *mac_stats;
+       int ret;
 
        rte_spinlock_lock(&port->mac_stats_lock);
 
-       if (sfc_port_update_mac_stats(sa) != 0)
+       ret = sfc_port_update_mac_stats(sa);
+       if (ret != 0)
                goto unlock;
 
        mac_stats = port->mac_stats_buf;
@@ -576,6 +590,8 @@ sfc_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
 
 unlock:
        rte_spinlock_unlock(&port->mac_stats_lock);
+       SFC_ASSERT(ret >= 0);
+       return -ret;
 }
 
 static void
@@ -660,6 +676,85 @@ sfc_xstats_get_names(struct rte_eth_dev *dev,
        return nstats;
 }
 
+static int
+sfc_xstats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
+                    uint64_t *values, unsigned int n)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+       struct sfc_port *port = &sa->port;
+       uint64_t *mac_stats;
+       unsigned int nb_supported = 0;
+       unsigned int nb_written = 0;
+       unsigned int i;
+       int ret;
+       int rc;
+
+       if (unlikely(values == NULL) ||
+           unlikely((ids == NULL) && (n < port->mac_stats_nb_supported)))
+               return port->mac_stats_nb_supported;
+
+       rte_spinlock_lock(&port->mac_stats_lock);
+
+       rc = sfc_port_update_mac_stats(sa);
+       if (rc != 0) {
+               SFC_ASSERT(rc > 0);
+               ret = -rc;
+               goto unlock;
+       }
+
+       mac_stats = port->mac_stats_buf;
+
+       for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < n); ++i) {
+               if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
+                       continue;
+
+               if ((ids == NULL) || (ids[nb_written] == nb_supported))
+                       values[nb_written++] = mac_stats[i];
+
+               ++nb_supported;
+       }
+
+       ret = nb_written;
+
+unlock:
+       rte_spinlock_unlock(&port->mac_stats_lock);
+
+       return ret;
+}
+
+static int
+sfc_xstats_get_names_by_id(struct rte_eth_dev *dev,
+                          struct rte_eth_xstat_name *xstats_names,
+                          const uint64_t *ids, unsigned int size)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+       struct sfc_port *port = &sa->port;
+       unsigned int nb_supported = 0;
+       unsigned int nb_written = 0;
+       unsigned int i;
+
+       if (unlikely(xstats_names == NULL) ||
+           unlikely((ids == NULL) && (size < port->mac_stats_nb_supported)))
+               return port->mac_stats_nb_supported;
+
+       for (i = 0; (i < EFX_MAC_NSTATS) && (nb_written < size); ++i) {
+               if (!EFX_MAC_STAT_SUPPORTED(port->mac_stats_mask, i))
+                       continue;
+
+               if ((ids == NULL) || (ids[nb_written] == nb_supported)) {
+                       char *name = xstats_names[nb_written++].name;
+
+                       strncpy(name, efx_mac_stat_name(sa->nic, i),
+                               sizeof(xstats_names[0].name));
+                       name[sizeof(xstats_names[0].name) - 1] = '\0';
+               }
+
+               ++nb_supported;
+       }
+
+       return nb_written;
+}
+
 static int
 sfc_flow_ctrl_get(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
 {
@@ -826,10 +921,23 @@ sfc_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
 {
        struct sfc_adapter *sa = dev->data->dev_private;
        const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
+       struct sfc_port *port = &sa->port;
        int rc;
 
        sfc_adapter_lock(sa);
 
+       /*
+        * Copy the address to the device private data so that
+        * it could be recalled in the case of adapter restart.
+        */
+       ether_addr_copy(mac_addr, &port->default_mac_addr);
+
+       if (port->isolated) {
+               sfc_err(sa, "isolated mode is active on the port");
+               sfc_err(sa, "will not set MAC address");
+               goto unlock;
+       }
+
        if (sa->state != SFC_ADAPTER_STARTED) {
                sfc_info(sa, "the port is not started");
                sfc_info(sa, "the new MAC address will be set on port start");
@@ -859,9 +967,9 @@ sfc_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
 
                /*
                 * Since setting MAC address with filters installed is not
-                * allowed on the adapter, one needs to simply restart adapter
-                * so that the new MAC address will be taken from an outer
-                * storage and set flawlessly by means of sfc_start() call
+                * allowed on the adapter, the new MAC address will be set
+                * by means of adapter restart. sfc_start() shall retrieve
+                * the new address from the device private data and set it.
                 */
                sfc_stop(sa);
                rc = sfc_start(sa);
@@ -870,6 +978,13 @@ sfc_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
        }
 
 unlock:
+       /*
+        * In the case of failure sa->port->default_mac_addr does not
+        * need rollback since no error code is returned, and the upper
+        * API will anyway update the external MAC address storage.
+        * To be consistent with that new value it is better to keep
+        * the device private value the same.
+        */
        sfc_adapter_unlock(sa);
 }
 
@@ -884,6 +999,12 @@ sfc_set_mc_addr_list(struct rte_eth_dev *dev, struct ether_addr *mc_addr_set,
        int rc;
        unsigned int i;
 
+       if (port->isolated) {
+               sfc_err(sa, "isolated mode is active on the port");
+               sfc_err(sa, "will not set multicast address list");
+               return -ENOTSUP;
+       }
+
        if (mc_addrs == NULL)
                return -ENOBUFS;
 
@@ -894,7 +1015,7 @@ sfc_set_mc_addr_list(struct rte_eth_dev *dev, struct ether_addr *mc_addr_set,
        }
 
        for (i = 0; i < nb_mc_addr; ++i) {
-               (void)rte_memcpy(mc_addrs, mc_addr_set[i].addr_bytes,
+               rte_memcpy(mc_addrs, mc_addr_set[i].addr_bytes,
                                 EFX_MAC_ADDR_LEN);
                mc_addrs += EFX_MAC_ADDR_LEN;
        }
@@ -909,10 +1030,14 @@ sfc_set_mc_addr_list(struct rte_eth_dev *dev, struct ether_addr *mc_addr_set,
        if (rc != 0)
                sfc_err(sa, "cannot set multicast address list (rc = %u)", rc);
 
-       SFC_ASSERT(rc > 0);
+       SFC_ASSERT(rc >= 0);
        return -rc;
 }
 
+/*
+ * The function is used by the secondary process as well. It must not
+ * use any process-local pointers from the adapter data.
+ */
 static void
 sfc_rx_queue_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
                      struct rte_eth_rxq_info *qinfo)
@@ -939,6 +1064,10 @@ sfc_rx_queue_info_get(struct rte_eth_dev *dev, uint16_t rx_queue_id,
        sfc_adapter_unlock(sa);
 }
 
+/*
+ * The function is used by the secondary process as well. It must not
+ * use any process-local pointers from the adapter data.
+ */
 static void
 sfc_tx_queue_info_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
                      struct rte_eth_txq_info *qinfo)
@@ -981,6 +1110,24 @@ sfc_rx_descriptor_done(void *queue, uint16_t offset)
        return sfc_rx_qdesc_done(dp_rxq, offset);
 }
 
+static int
+sfc_rx_descriptor_status(void *queue, uint16_t offset)
+{
+       struct sfc_dp_rxq *dp_rxq = queue;
+       struct sfc_rxq *rxq = sfc_rxq_by_dp_rxq(dp_rxq);
+
+       return rxq->evq->sa->dp_rx->qdesc_status(dp_rxq, offset);
+}
+
+static int
+sfc_tx_descriptor_status(void *queue, uint16_t offset)
+{
+       struct sfc_dp_txq *dp_txq = queue;
+       struct sfc_txq *txq = sfc_txq_by_dp_txq(dp_txq);
+
+       return txq->evq->sa->dp_tx->qdesc_status(dp_txq, offset);
+}
+
 static int
 sfc_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
 {
@@ -1083,8 +1230,9 @@ sfc_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
                          struct rte_eth_rss_conf *rss_conf)
 {
        struct sfc_adapter *sa = dev->data->dev_private;
+       struct sfc_port *port = &sa->port;
 
-       if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE)
+       if ((sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) || port->isolated)
                return -ENOTSUP;
 
        if (sa->rss_channels == 0)
@@ -1099,9 +1247,9 @@ sfc_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
         * locally in 'sfc_adapter' and kept up-to-date
         */
        rss_conf->rss_hf = sfc_efx_to_rte_hash_type(sa->rss_hash_types);
-       rss_conf->rss_key_len = SFC_RSS_KEY_SIZE;
+       rss_conf->rss_key_len = EFX_RSS_KEY_SIZE;
        if (rss_conf->rss_key != NULL)
-               rte_memcpy(rss_conf->rss_key, sa->rss_key, SFC_RSS_KEY_SIZE);
+               rte_memcpy(rss_conf->rss_key, sa->rss_key, EFX_RSS_KEY_SIZE);
 
        sfc_adapter_unlock(sa);
 
@@ -1113,9 +1261,13 @@ sfc_dev_rss_hash_update(struct rte_eth_dev *dev,
                        struct rte_eth_rss_conf *rss_conf)
 {
        struct sfc_adapter *sa = dev->data->dev_private;
+       struct sfc_port *port = &sa->port;
        unsigned int efx_hash_types;
        int rc = 0;
 
+       if (port->isolated)
+               return -ENOTSUP;
+
        if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) {
                sfc_err(sa, "RSS is not available");
                return -ENOTSUP;
@@ -1142,14 +1294,17 @@ sfc_dev_rss_hash_update(struct rte_eth_dev *dev,
 
        efx_hash_types = sfc_rte_to_efx_hash_type(rss_conf->rss_hf);
 
-       rc = efx_rx_scale_mode_set(sa->nic, EFX_RX_HASHALG_TOEPLITZ,
+       rc = efx_rx_scale_mode_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
+                                  EFX_RX_HASHALG_TOEPLITZ,
                                   efx_hash_types, B_TRUE);
        if (rc != 0)
                goto fail_scale_mode_set;
 
        if (rss_conf->rss_key != NULL) {
                if (sa->state == SFC_ADAPTER_STARTED) {
-                       rc = efx_rx_scale_key_set(sa->nic, rss_conf->rss_key,
+                       rc = efx_rx_scale_key_set(sa->nic,
+                                                 EFX_RSS_CONTEXT_DEFAULT,
+                                                 rss_conf->rss_key,
                                                  sizeof(sa->rss_key));
                        if (rc != 0)
                                goto fail_scale_key_set;
@@ -1165,7 +1320,8 @@ sfc_dev_rss_hash_update(struct rte_eth_dev *dev,
        return 0;
 
 fail_scale_key_set:
-       if (efx_rx_scale_mode_set(sa->nic, EFX_RX_HASHALG_TOEPLITZ,
+       if (efx_rx_scale_mode_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
+                                 EFX_RX_HASHALG_TOEPLITZ,
                                  sa->rss_hash_types, B_TRUE) != 0)
                sfc_err(sa, "failed to restore RSS mode");
 
@@ -1180,9 +1336,10 @@ sfc_dev_rss_reta_query(struct rte_eth_dev *dev,
                       uint16_t reta_size)
 {
        struct sfc_adapter *sa = dev->data->dev_private;
+       struct sfc_port *port = &sa->port;
        int entry;
 
-       if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE)
+       if ((sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) || port->isolated)
                return -ENOTSUP;
 
        if (sa->rss_channels == 0)
@@ -1212,10 +1369,14 @@ sfc_dev_rss_reta_update(struct rte_eth_dev *dev,
                        uint16_t reta_size)
 {
        struct sfc_adapter *sa = dev->data->dev_private;
+       struct sfc_port *port = &sa->port;
        unsigned int *rss_tbl_new;
        uint16_t entry;
-       int rc;
+       int rc = 0;
+
 
+       if (port->isolated)
+               return -ENOTSUP;
 
        if (sa->rss_support != EFX_RX_SCALE_EXCLUSIVE) {
                sfc_err(sa, "RSS is not available");
@@ -1256,10 +1417,16 @@ sfc_dev_rss_reta_update(struct rte_eth_dev *dev,
                }
        }
 
-       rc = efx_rx_scale_tbl_set(sa->nic, rss_tbl_new, EFX_RSS_TBL_SIZE);
-       if (rc == 0)
-               rte_memcpy(sa->rss_tbl, rss_tbl_new, sizeof(sa->rss_tbl));
+       if (sa->state == SFC_ADAPTER_STARTED) {
+               rc = efx_rx_scale_tbl_set(sa->nic, EFX_RSS_CONTEXT_DEFAULT,
+                                         rss_tbl_new, EFX_RSS_TBL_SIZE);
+               if (rc != 0)
+                       goto fail_scale_tbl_set;
+       }
 
+       rte_memcpy(sa->rss_tbl, rss_tbl_new, sizeof(sa->rss_tbl));
+
+fail_scale_tbl_set:
 bad_reta_entry:
        sfc_adapter_unlock(sa);
 
@@ -1354,6 +1521,8 @@ static const struct eth_dev_ops sfc_eth_dev_ops = {
        .rx_queue_release               = sfc_rx_queue_release,
        .rx_queue_count                 = sfc_rx_queue_count,
        .rx_descriptor_done             = sfc_rx_descriptor_done,
+       .rx_descriptor_status           = sfc_rx_descriptor_status,
+       .tx_descriptor_status           = sfc_tx_descriptor_status,
        .tx_queue_setup                 = sfc_tx_queue_setup,
        .tx_queue_release               = sfc_tx_queue_release,
        .flow_ctrl_get                  = sfc_flow_ctrl_get,
@@ -1370,8 +1539,33 @@ static const struct eth_dev_ops sfc_eth_dev_ops = {
        .rxq_info_get                   = sfc_rx_queue_info_get,
        .txq_info_get                   = sfc_tx_queue_info_get,
        .fw_version_get                 = sfc_fw_version_get,
+       .xstats_get_by_id               = sfc_xstats_get_by_id,
+       .xstats_get_names_by_id         = sfc_xstats_get_names_by_id,
 };
 
+/**
+ * Duplicate a string in potentially shared memory required for
+ * multi-process support.
+ *
+ * strdup() allocates from process-local heap/memory.
+ */
+static char *
+sfc_strdup(const char *str)
+{
+       size_t size;
+       char *copy;
+
+       if (str == NULL)
+               return NULL;
+
+       size = strlen(str) + 1;
+       copy = rte_malloc(__func__, size, 0);
+       if (copy != NULL)
+               rte_memcpy(copy, str, size);
+
+       return copy;
+}
+
 static int
 sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
 {
@@ -1407,7 +1601,7 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
                                "Insufficient Hw/FW capabilities to use Rx datapath %s",
                                rx_name);
                        rc = EINVAL;
-                       goto fail_dp_rx;
+                       goto fail_dp_rx_caps;
                }
        } else {
                sa->dp_rx = sfc_dp_find_rx_by_caps(&sfc_dp_head, avail_caps);
@@ -1419,7 +1613,13 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
                }
        }
 
-       sfc_info(sa, "use %s Rx datapath", sa->dp_rx->dp.name);
+       sa->dp_rx_name = sfc_strdup(sa->dp_rx->dp.name);
+       if (sa->dp_rx_name == NULL) {
+               rc = ENOMEM;
+               goto fail_dp_rx_name;
+       }
+
+       sfc_info(sa, "use %s Rx datapath", sa->dp_rx_name);
 
        dev->rx_pkt_burst = sa->dp_rx->pkt_burst;
 
@@ -1440,7 +1640,7 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
                                "Insufficient Hw/FW capabilities to use Tx datapath %s",
                                tx_name);
                        rc = EINVAL;
-                       goto fail_dp_tx;
+                       goto fail_dp_tx_caps;
                }
        } else {
                sa->dp_tx = sfc_dp_find_tx_by_caps(&sfc_dp_head, avail_caps);
@@ -1452,7 +1652,13 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
                }
        }
 
-       sfc_info(sa, "use %s Tx datapath", sa->dp_tx->dp.name);
+       sa->dp_tx_name = sfc_strdup(sa->dp_tx->dp.name);
+       if (sa->dp_tx_name == NULL) {
+               rc = ENOMEM;
+               goto fail_dp_tx_name;
+       }
+
+       sfc_info(sa, "use %s Tx datapath", sa->dp_tx_name);
 
        dev->tx_pkt_burst = sa->dp_tx->pkt_burst;
 
@@ -1460,13 +1666,107 @@ sfc_eth_dev_set_ops(struct rte_eth_dev *dev)
 
        return 0;
 
+fail_dp_tx_name:
+fail_dp_tx_caps:
+       sa->dp_tx = NULL;
+
 fail_dp_tx:
 fail_kvarg_tx_datapath:
+       rte_free(sa->dp_rx_name);
+       sa->dp_rx_name = NULL;
+
+fail_dp_rx_name:
+fail_dp_rx_caps:
+       sa->dp_rx = NULL;
+
 fail_dp_rx:
 fail_kvarg_rx_datapath:
        return rc;
 }
 
+static void
+sfc_eth_dev_clear_ops(struct rte_eth_dev *dev)
+{
+       struct sfc_adapter *sa = dev->data->dev_private;
+
+       dev->dev_ops = NULL;
+       dev->rx_pkt_burst = NULL;
+       dev->tx_pkt_burst = NULL;
+
+       rte_free(sa->dp_tx_name);
+       sa->dp_tx_name = NULL;
+       sa->dp_tx = NULL;
+
+       rte_free(sa->dp_rx_name);
+       sa->dp_rx_name = NULL;
+       sa->dp_rx = NULL;
+}
+
+static const struct eth_dev_ops sfc_eth_dev_secondary_ops = {
+       .rxq_info_get                   = sfc_rx_queue_info_get,
+       .txq_info_get                   = sfc_tx_queue_info_get,
+};
+
+static int
+sfc_eth_dev_secondary_set_ops(struct rte_eth_dev *dev)
+{
+       /*
+        * Device private data has really many process-local pointers.
+        * Below code should be extremely careful to use data located
+        * in shared memory only.
+        */
+       struct sfc_adapter *sa = dev->data->dev_private;
+       const struct sfc_dp_rx *dp_rx;
+       const struct sfc_dp_tx *dp_tx;
+       int rc;
+
+       dp_rx = sfc_dp_find_rx_by_name(&sfc_dp_head, sa->dp_rx_name);
+       if (dp_rx == NULL) {
+               sfc_err(sa, "cannot find %s Rx datapath", sa->dp_tx_name);
+               rc = ENOENT;
+               goto fail_dp_rx;
+       }
+       if (~dp_rx->features & SFC_DP_RX_FEAT_MULTI_PROCESS) {
+               sfc_err(sa, "%s Rx datapath does not support multi-process",
+                       sa->dp_tx_name);
+               rc = EINVAL;
+               goto fail_dp_rx_multi_process;
+       }
+
+       dp_tx = sfc_dp_find_tx_by_name(&sfc_dp_head, sa->dp_tx_name);
+       if (dp_tx == NULL) {
+               sfc_err(sa, "cannot find %s Tx datapath", sa->dp_tx_name);
+               rc = ENOENT;
+               goto fail_dp_tx;
+       }
+       if (~dp_tx->features & SFC_DP_TX_FEAT_MULTI_PROCESS) {
+               sfc_err(sa, "%s Tx datapath does not support multi-process",
+                       sa->dp_tx_name);
+               rc = EINVAL;
+               goto fail_dp_tx_multi_process;
+       }
+
+       dev->rx_pkt_burst = dp_rx->pkt_burst;
+       dev->tx_pkt_burst = dp_tx->pkt_burst;
+       dev->dev_ops = &sfc_eth_dev_secondary_ops;
+
+       return 0;
+
+fail_dp_tx_multi_process:
+fail_dp_tx:
+fail_dp_rx_multi_process:
+fail_dp_rx:
+       return rc;
+}
+
+static void
+sfc_eth_dev_secondary_clear_ops(struct rte_eth_dev *dev)
+{
+       dev->dev_ops = NULL;
+       dev->tx_pkt_burst = NULL;
+       dev->rx_pkt_burst = NULL;
+}
+
 static void
 sfc_register_dp(void)
 {
@@ -1486,14 +1786,20 @@ static int
 sfc_eth_dev_init(struct rte_eth_dev *dev)
 {
        struct sfc_adapter *sa = dev->data->dev_private;
-       struct rte_pci_device *pci_dev = SFC_DEV_TO_PCI(dev);
+       struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
        int rc;
        const efx_nic_cfg_t *encp;
        const struct ether_addr *from;
 
        sfc_register_dp();
 
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+               return -sfc_eth_dev_secondary_set_ops(dev);
+
        /* Required for logging */
+       sa->pci_addr = pci_dev->addr;
+       sa->port_id = dev->data->port_id;
+
        sa->eth_dev = dev;
 
        /* Copy PCI device info to the dev->data */
@@ -1549,6 +1855,8 @@ sfc_eth_dev_init(struct rte_eth_dev *dev)
        return 0;
 
 fail_attach:
+       sfc_eth_dev_clear_ops(dev);
+
 fail_set_ops:
        sfc_unprobe(sa);
 
@@ -1571,22 +1879,26 @@ fail_kvargs_parse:
 static int
 sfc_eth_dev_uninit(struct rte_eth_dev *dev)
 {
-       struct sfc_adapter *sa = dev->data->dev_private;
+       struct sfc_adapter *sa;
+
+       if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
+               sfc_eth_dev_secondary_clear_ops(dev);
+               return 0;
+       }
 
+       sa = dev->data->dev_private;
        sfc_log_init(sa, "entry");
 
        sfc_adapter_lock(sa);
 
+       sfc_eth_dev_clear_ops(dev);
+
        sfc_detach(sa);
        sfc_unprobe(sa);
 
        rte_free(dev->data->mac_addrs);
        dev->data->mac_addrs = NULL;
 
-       dev->dev_ops = NULL;
-       dev->rx_pkt_burst = NULL;
-       dev->tx_pkt_burst = NULL;
-
        sfc_kvargs_cleanup(sa);
 
        sfc_adapter_unlock(sa);