net: add rte prefix to ether structures
[dpdk.git] / drivers / net / sfc / sfc_port.c
index fd267e1..8de5f0c 100644 (file)
@@ -87,6 +87,18 @@ sfc_port_update_mac_stats(struct sfc_adapter *sa)
        return 0;
 }
 
+static void
+sfc_port_reset_sw_stats(struct sfc_adapter *sa)
+{
+       struct sfc_port *port = &sa->port;
+
+       /*
+        * Reset diff stats explicitly since check which does not allow
+        * the statistics to grow backward could deny it.
+        */
+       port->ipackets = 0;
+}
+
 int
 sfc_port_reset_mac_stats(struct sfc_adapter *sa)
 {
@@ -95,6 +107,8 @@ sfc_port_reset_mac_stats(struct sfc_adapter *sa)
 
        rte_spinlock_lock(&port->mac_stats_lock);
        rc = efx_mac_stats_clear(sa->nic);
+       if (rc == 0)
+               sfc_port_reset_sw_stats(sa);
        rte_spinlock_unlock(&port->mac_stats_lock);
 
        return rc;
@@ -121,6 +135,28 @@ sfc_port_init_dev_link(struct sfc_adapter *sa)
        return 0;
 }
 
+#if EFSYS_OPT_LOOPBACK
+
+static efx_link_mode_t
+sfc_port_phy_caps_to_max_link_speed(uint32_t phy_caps)
+{
+       if (phy_caps & (1u << EFX_PHY_CAP_100000FDX))
+               return EFX_LINK_100000FDX;
+       if (phy_caps & (1u << EFX_PHY_CAP_50000FDX))
+               return EFX_LINK_50000FDX;
+       if (phy_caps & (1u << EFX_PHY_CAP_40000FDX))
+               return EFX_LINK_40000FDX;
+       if (phy_caps & (1u << EFX_PHY_CAP_25000FDX))
+               return EFX_LINK_25000FDX;
+       if (phy_caps & (1u << EFX_PHY_CAP_10000FDX))
+               return EFX_LINK_10000FDX;
+       if (phy_caps & (1u << EFX_PHY_CAP_1000FDX))
+               return EFX_LINK_1000FDX;
+       return EFX_LINK_UNKNOWN;
+}
+
+#endif
+
 int
 sfc_port_start(struct sfc_adapter *sa)
 {
@@ -143,6 +179,21 @@ sfc_port_start(struct sfc_adapter *sa)
        if (rc != 0)
                goto fail_port_init;
 
+#if EFSYS_OPT_LOOPBACK
+       if (sa->eth_dev->data->dev_conf.lpbk_mode != 0) {
+               efx_link_mode_t link_mode;
+
+               link_mode =
+                       sfc_port_phy_caps_to_max_link_speed(port->phy_adv_cap);
+               sfc_log_init(sa, "set loopback link_mode=%u type=%u", link_mode,
+                            sa->eth_dev->data->dev_conf.lpbk_mode);
+               rc = efx_port_loopback_set(sa->nic, link_mode,
+                       sa->eth_dev->data->dev_conf.lpbk_mode);
+               if (rc != 0)
+                       goto fail_loopback_set;
+       }
+#endif
+
        sfc_log_init(sa, "set flow control to %#x autoneg=%u",
                     port->flow_ctrl, port->flow_ctrl_autoneg);
        rc = efx_mac_fcntl_set(sa->nic, port->flow_ctrl,
@@ -155,6 +206,16 @@ sfc_port_start(struct sfc_adapter *sa)
        SFC_ASSERT((port->phy_adv_cap & phy_pause_caps) == 0);
        phy_adv_cap = port->phy_adv_cap | (phy_adv_cap & phy_pause_caps);
 
+       /*
+        * No controls for FEC yet. Use default FEC mode.
+        * I.e. advertise everything supported (*_FEC=1), but do not request
+        * anything explicitly (*_FEC_REQUESTED=0).
+        */
+       phy_adv_cap |= port->phy_adv_cap_mask &
+               (1u << EFX_PHY_CAP_BASER_FEC |
+                1u << EFX_PHY_CAP_RS_FEC |
+                1u << EFX_PHY_CAP_25G_BASER_FEC);
+
        sfc_log_init(sa, "set phy adv caps to %#x", phy_adv_cap);
        rc = efx_phy_adv_cap_set(sa->nic, phy_adv_cap);
        if (rc != 0)
@@ -165,8 +226,8 @@ sfc_port_start(struct sfc_adapter *sa)
        if (rc != 0)
                goto fail_mac_pdu_set;
 
-       if (!port->isolated) {
-               struct ether_addr *addr = &port->default_mac_addr;
+       if (!sfc_sa2shared(sa)->isolated) {
+               struct rte_ether_addr *addr = &port->default_mac_addr;
 
                sfc_log_init(sa, "set MAC address");
                rc = efx_mac_addr_set(sa->nic, addr->addr_bytes);
@@ -268,6 +329,9 @@ fail_mac_addr_set:
 fail_mac_pdu_set:
 fail_phy_adv_cap_set:
 fail_mac_fcntl_set:
+#if EFSYS_OPT_LOOPBACK
+fail_loopback_set:
+#endif
        efx_port_fini(sa->nic);
 
 fail_port_init:
@@ -322,7 +386,7 @@ sfc_port_attach(struct sfc_adapter *sa)
 {
        struct sfc_port *port = &sa->port;
        const efx_nic_cfg_t *encp = efx_nic_cfg_get(sa->nic);
-       const struct ether_addr *from;
+       const struct rte_ether_addr *from;
        uint32_t mac_nstats;
        size_t mac_stats_size;
        long kvarg_stats_update_period_ms;
@@ -337,7 +401,7 @@ sfc_port_attach(struct sfc_adapter *sa)
        port->flow_ctrl_autoneg = B_TRUE;
 
        RTE_BUILD_BUG_ON(sizeof(encp->enc_mac_addr) != sizeof(*from));
-       from = (const struct ether_addr *)(encp->enc_mac_addr);
+       from = (const struct rte_ether_addr *)(encp->enc_mac_addr);
        ether_addr_copy(from, &port->default_mac_addr);
 
        port->max_mcast_addrs = EFX_MAC_MULTICAST_LIST_MAX;