net-next: stmmac: rework the speed selection
authorLABBE Corentin <clabbe.montjoie@gmail.com>
Wed, 24 May 2017 07:16:47 +0000 (09:16 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 25 May 2017 17:08:35 +0000 (13:08 -0400)
The current stmmac_adjust_link() part which handle speed have
some if (has_platform) code and my dwmac-sun8i will add more of them.

So we need to handle better speed selection.
Moreover the struct link member speed and port are hard to guess their
purpose. And their unique usage are to be combined for writing speed.

So this patch replace speed/port by simpler
speed10/speed100/speed1000/speed_mask variables.

In dwmac4_core_init and dwmac1000_core_init, port/speed value was used
directly without using the struct link. This patch convert also their
usage to speedxxx.

Signed-off-by: Corentin Labbe <clabbe.montjoie@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/stmicro/stmmac/common.h
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c
drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

index b7ce3fbb53757a4cb4dd7405e1683d0fc784870c..e82b4b70b7be3a4154c688daef01d4ea3918458c 100644 (file)
@@ -549,9 +549,11 @@ extern const struct stmmac_hwtimestamp stmmac_ptp;
 extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;
 
 struct mac_link {
-       int port;
-       int duplex;
-       int speed;
+       u32 speed_mask;
+       u32 speed10;
+       u32 speed100;
+       u32 speed1000;
+       u32 duplex;
 };
 
 struct mii_regs {
index f3d9305e5f706bc407c51a5d98af6a28b6404f42..8a86340ff2d348ebbaabe29f73b51a67060542fe 100644 (file)
@@ -45,15 +45,17 @@ static void dwmac1000_core_init(struct mac_device_info *hw, int mtu)
        if (hw->ps) {
                value |= GMAC_CONTROL_TE;
 
-               if (hw->ps == SPEED_1000) {
-                       value &= ~GMAC_CONTROL_PS;
-               } else {
-                       value |= GMAC_CONTROL_PS;
-
-                       if (hw->ps == SPEED_10)
-                               value &= ~GMAC_CONTROL_FES;
-                       else
-                               value |= GMAC_CONTROL_FES;
+               value &= ~hw->link.speed_mask;
+               switch (hw->ps) {
+               case SPEED_1000:
+                       value |= hw->link.speed1000;
+                       break;
+               case SPEED_100:
+                       value |= hw->link.speed100;
+                       break;
+               case SPEED_10:
+                       value |= hw->link.speed10;
+                       break;
                }
        }
 
@@ -531,9 +533,11 @@ struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins,
        mac->mac = &dwmac1000_ops;
        mac->dma = &dwmac1000_dma_ops;
 
-       mac->link.port = GMAC_CONTROL_PS;
        mac->link.duplex = GMAC_CONTROL_DM;
-       mac->link.speed = GMAC_CONTROL_FES;
+       mac->link.speed10 = GMAC_CONTROL_PS;
+       mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
+       mac->link.speed1000 = 0;
+       mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
        mac->mii.addr = GMAC_MII_ADDR;
        mac->mii.data = GMAC_MII_DATA;
        mac->mii.addr_shift = 11;
index 1b360910548473a486372835b3e167456528d508..8ef5173563134235903350167ca9d16b366881af 100644 (file)
@@ -175,9 +175,11 @@ struct mac_device_info *dwmac100_setup(void __iomem *ioaddr, int *synopsys_id)
        mac->mac = &dwmac100_ops;
        mac->dma = &dwmac100_dma_ops;
 
-       mac->link.port = MAC_CONTROL_PS;
        mac->link.duplex = MAC_CONTROL_F;
-       mac->link.speed = 0;
+       mac->link.speed10 = 0;
+       mac->link.speed100 = 0;
+       mac->link.speed1000 = 0;
+       mac->link.speed_mask = MAC_CONTROL_PS;
        mac->mii.addr = MAC_MII_ADDR;
        mac->mii.data = MAC_MII_DATA;
        mac->mii.addr_shift = 11;
index 48793f2e93075a9cabd57b3a4e0ee86765368bae..f233bf8b4ebb844d9b27ca8cf01947f066e5ba03 100644 (file)
@@ -35,15 +35,17 @@ static void dwmac4_core_init(struct mac_device_info *hw, int mtu)
        if (hw->ps) {
                value |= GMAC_CONFIG_TE;
 
-               if (hw->ps == SPEED_1000) {
-                       value &= ~GMAC_CONFIG_PS;
-               } else {
-                       value |= GMAC_CONFIG_PS;
-
-                       if (hw->ps == SPEED_10)
-                               value &= ~GMAC_CONFIG_FES;
-                       else
-                               value |= GMAC_CONFIG_FES;
+               value &= hw->link.speed_mask;
+               switch (hw->ps) {
+               case SPEED_1000:
+                       value |= hw->link.speed1000;
+                       break;
+               case SPEED_100:
+                       value |= hw->link.speed100;
+                       break;
+               case SPEED_10:
+                       value |= hw->link.speed10;
+                       break;
                }
        }
 
@@ -747,9 +749,11 @@ struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
        if (mac->multicast_filter_bins)
                mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
 
-       mac->link.port = GMAC_CONFIG_PS;
        mac->link.duplex = GMAC_CONFIG_DM;
-       mac->link.speed = GMAC_CONFIG_FES;
+       mac->link.speed10 = GMAC_CONFIG_PS;
+       mac->link.speed100 = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
+       mac->link.speed1000 = 0;
+       mac->link.speed_mask = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
        mac->mii.addr = GMAC_MDIO_ADDR;
        mac->mii.data = GMAC_MDIO_DATA;
        mac->mii.addr_shift = 21;
index 9ec138dc04f95aefa3fb8cbafb8888c56878ba34..f158273eab9b1a1e14b171a5dc3c09cca3635a29 100644 (file)
@@ -801,29 +801,16 @@ static void stmmac_adjust_link(struct net_device *dev)
 
                if (phydev->speed != priv->speed) {
                        new_state = true;
+                       ctrl &= ~priv->hw->link.speed_mask;
                        switch (phydev->speed) {
                        case SPEED_1000:
-                               if (priv->plat->has_gmac ||
-                                   priv->plat->has_gmac4)
-                                       ctrl &= ~priv->hw->link.port;
+                               ctrl |= priv->hw->link.speed1000;
                                break;
                        case SPEED_100:
-                               if (priv->plat->has_gmac ||
-                                   priv->plat->has_gmac4) {
-                                       ctrl |= priv->hw->link.port;
-                                       ctrl |= priv->hw->link.speed;
-                               } else {
-                                       ctrl &= ~priv->hw->link.port;
-                               }
+                               ctrl |= priv->hw->link.speed100;
                                break;
                        case SPEED_10:
-                               if (priv->plat->has_gmac ||
-                                   priv->plat->has_gmac4) {
-                                       ctrl |= priv->hw->link.port;
-                                       ctrl &= ~(priv->hw->link.speed);
-                               } else {
-                                       ctrl &= ~priv->hw->link.port;
-                               }
+                               ctrl |= priv->hw->link.speed10;
                                break;
                        default:
                                netif_warn(priv, link, priv->dev,