net/sfc: support link speed and duplex settings
authorAndrew Rybchenko <arybchenko@solarflare.com>
Thu, 15 Dec 2016 12:50:59 +0000 (12:50 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 17 Jan 2017 18:40:50 +0000 (19:40 +0100)
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andrew Lee <alee@solarflare.com>
Reviewed-by: Robert Stonehouse <rstonehouse@solarflare.com>
doc/guides/nics/features/sfc_efx.ini
drivers/net/sfc/sfc.c
drivers/net/sfc/sfc.h
drivers/net/sfc/sfc_ethdev.c
drivers/net/sfc/sfc_port.c

index a845bfc..60ecca0 100644 (file)
@@ -4,6 +4,7 @@
 ; Refer to default.ini for the full list of available PMD features.
 ;
 [Features]
+Speed capabilities   = Y
 Link status          = Y
 Link status event    = Y
 MTU update           = Y
index 6b3dc48..f884a21 100644 (file)
@@ -85,6 +85,33 @@ sfc_dma_free(const struct sfc_adapter *sa, efsys_mem_t *esmp)
        memset(esmp, 0, sizeof(*esmp));
 }
 
+static uint32_t
+sfc_phy_cap_from_link_speeds(uint32_t speeds)
+{
+       uint32_t phy_caps = 0;
+
+       if (~speeds & ETH_LINK_SPEED_FIXED) {
+               phy_caps |= (1 << EFX_PHY_CAP_AN);
+               /*
+                * If no speeds are specified in the mask, any supported
+                * may be negotiated
+                */
+               if (speeds == ETH_LINK_SPEED_AUTONEG)
+                       phy_caps |=
+                               (1 << EFX_PHY_CAP_1000FDX) |
+                               (1 << EFX_PHY_CAP_10000FDX) |
+                               (1 << EFX_PHY_CAP_40000FDX);
+       }
+       if (speeds & ETH_LINK_SPEED_1G)
+               phy_caps |= (1 << EFX_PHY_CAP_1000FDX);
+       if (speeds & ETH_LINK_SPEED_10G)
+               phy_caps |= (1 << EFX_PHY_CAP_10000FDX);
+       if (speeds & ETH_LINK_SPEED_40G)
+               phy_caps |= (1 << EFX_PHY_CAP_40000FDX);
+
+       return phy_caps;
+}
+
 /*
  * Check requested device level configuration.
  * Receive and transmit configuration is checked in corresponding
@@ -96,8 +123,12 @@ sfc_check_conf(struct sfc_adapter *sa)
        const struct rte_eth_conf *conf = &sa->eth_dev->data->dev_conf;
        int rc = 0;
 
-       if (conf->link_speeds != ETH_LINK_SPEED_AUTONEG) {
-               sfc_err(sa, "Manual link speed/duplex choice not supported");
+       sa->port.phy_adv_cap =
+               sfc_phy_cap_from_link_speeds(conf->link_speeds) &
+               sa->port.phy_adv_cap_mask;
+       if ((sa->port.phy_adv_cap & ~(1 << EFX_PHY_CAP_AN)) == 0) {
+               sfc_err(sa, "No link speeds from mask %#x are supported",
+                       conf->link_speeds);
                rc = EINVAL;
        }
 
@@ -516,6 +547,9 @@ sfc_attach(struct sfc_adapter *sa)
        if (rc != 0)
                goto fail_intr_attach;
 
+       efx_phy_adv_cap_get(sa->nic, EFX_PHY_CAP_PERM,
+                           &sa->port.phy_adv_cap_mask);
+
        sfc_log_init(sa, "fini nic");
        efx_nic_fini(enp);
 
index 83c4430..c155bc4 100644 (file)
@@ -126,6 +126,9 @@ struct sfc_txq_info;
 struct sfc_port {
        unsigned int                    lsc_seq;
 
+       uint32_t                        phy_adv_cap_mask;
+       uint32_t                        phy_adv_cap;
+
        unsigned int                    flow_ctrl;
        boolean_t                       flow_ctrl_autoneg;
        size_t                          pdu;
index 98c26cc..7051f43 100644 (file)
@@ -52,6 +52,15 @@ sfc_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device);
        dev_info->max_rx_pktlen = EFX_MAC_PDU_MAX;
 
+       /* Autonegotiation may be disabled */
+       dev_info->speed_capa = ETH_LINK_SPEED_FIXED;
+       if (sa->port.phy_adv_cap_mask & EFX_PHY_CAP_1000FDX)
+               dev_info->speed_capa |= ETH_LINK_SPEED_1G;
+       if (sa->port.phy_adv_cap_mask & EFX_PHY_CAP_10000FDX)
+               dev_info->speed_capa |= ETH_LINK_SPEED_10G;
+       if (sa->port.phy_adv_cap_mask & EFX_PHY_CAP_40000FDX)
+               dev_info->speed_capa |= ETH_LINK_SPEED_40G;
+
        dev_info->max_rx_queues = sa->rxq_max;
        dev_info->max_tx_queues = sa->txq_max;
 
index ccc0854..1241af7 100644 (file)
@@ -86,6 +86,11 @@ sfc_port_start(struct sfc_adapter *sa)
        if (rc != 0)
                goto fail_mac_fcntl_set;
 
+       sfc_log_init(sa, "set phy adv caps to %#x", port->phy_adv_cap);
+       rc = efx_phy_adv_cap_set(sa->nic, port->phy_adv_cap);
+       if (rc != 0)
+               goto fail_phy_adv_cap_set;
+
        sfc_log_init(sa, "set MAC PDU %u", (unsigned int)port->pdu);
        rc = efx_mac_pdu_set(sa->nic, port->pdu);
        if (rc != 0)
@@ -131,6 +136,7 @@ fail_mac_stats_periodic:
 fail_mac_filter_set:
 fail_mac_addr_set:
 fail_mac_pdu_set:
+fail_phy_adv_cap_set:
 fail_mac_fcntl_set:
        efx_port_fini(sa->nic);