Skip to content

Commit c9e19ea

Browse files
committed
Merge branch 'stmmac-rework-speed-selection'
Corentin Labbe says: ==================== net-next: stmmac: rework the speed selection 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. My first try was to create an adjust_link() in stmmac_ops but it duplicate some code The current solution is to have direct value for 10/100/1000 and a mask for them. The first 4 patchs fix some minor problem found in stmmac_adjust_link() and reported by Florian Fainelli in my previous serie. The last patch is the real work. This series is tested on cubieboard2 (dwmac1000) and opipc (dwmac-sun8i). Changes since v3: - Added the patch #4 "Convert old_link to bool" as suggested by Joe Perches - Changed the speedmask Changes since v2: - Use true/false for new_state in patch #1 ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 26d732b + ca84dfb commit c9e19ea

File tree

6 files changed

+57
-58
lines changed

6 files changed

+57
-58
lines changed

drivers/net/ethernet/stmicro/stmmac/common.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,11 @@ extern const struct stmmac_hwtimestamp stmmac_ptp;
549549
extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;
550550

551551
struct mac_link {
552-
int port;
553-
int duplex;
554-
int speed;
552+
u32 speed_mask;
553+
u32 speed10;
554+
u32 speed100;
555+
u32 speed1000;
556+
u32 duplex;
555557
};
556558

557559
struct mii_regs {

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@ static void dwmac1000_core_init(struct mac_device_info *hw, int mtu)
4545
if (hw->ps) {
4646
value |= GMAC_CONTROL_TE;
4747

48-
if (hw->ps == SPEED_1000) {
49-
value &= ~GMAC_CONTROL_PS;
50-
} else {
51-
value |= GMAC_CONTROL_PS;
52-
53-
if (hw->ps == SPEED_10)
54-
value &= ~GMAC_CONTROL_FES;
55-
else
56-
value |= GMAC_CONTROL_FES;
48+
value &= ~hw->link.speed_mask;
49+
switch (hw->ps) {
50+
case SPEED_1000:
51+
value |= hw->link.speed1000;
52+
break;
53+
case SPEED_100:
54+
value |= hw->link.speed100;
55+
break;
56+
case SPEED_10:
57+
value |= hw->link.speed10;
58+
break;
5759
}
5860
}
5961

@@ -531,9 +533,11 @@ struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins,
531533
mac->mac = &dwmac1000_ops;
532534
mac->dma = &dwmac1000_dma_ops;
533535

534-
mac->link.port = GMAC_CONTROL_PS;
535536
mac->link.duplex = GMAC_CONTROL_DM;
536-
mac->link.speed = GMAC_CONTROL_FES;
537+
mac->link.speed10 = GMAC_CONTROL_PS;
538+
mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
539+
mac->link.speed1000 = 0;
540+
mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES;
537541
mac->mii.addr = GMAC_MII_ADDR;
538542
mac->mii.data = GMAC_MII_DATA;
539543
mac->mii.addr_shift = 11;

drivers/net/ethernet/stmicro/stmmac/dwmac100_core.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,11 @@ struct mac_device_info *dwmac100_setup(void __iomem *ioaddr, int *synopsys_id)
175175
mac->mac = &dwmac100_ops;
176176
mac->dma = &dwmac100_dma_ops;
177177

178-
mac->link.port = MAC_CONTROL_PS;
179178
mac->link.duplex = MAC_CONTROL_F;
180-
mac->link.speed = 0;
179+
mac->link.speed10 = 0;
180+
mac->link.speed100 = 0;
181+
mac->link.speed1000 = 0;
182+
mac->link.speed_mask = MAC_CONTROL_PS;
181183
mac->mii.addr = MAC_MII_ADDR;
182184
mac->mii.data = MAC_MII_DATA;
183185
mac->mii.addr_shift = 11;

drivers/net/ethernet/stmicro/stmmac/dwmac4_core.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ static void dwmac4_core_init(struct mac_device_info *hw, int mtu)
3535
if (hw->ps) {
3636
value |= GMAC_CONFIG_TE;
3737

38-
if (hw->ps == SPEED_1000) {
39-
value &= ~GMAC_CONFIG_PS;
40-
} else {
41-
value |= GMAC_CONFIG_PS;
42-
43-
if (hw->ps == SPEED_10)
44-
value &= ~GMAC_CONFIG_FES;
45-
else
46-
value |= GMAC_CONFIG_FES;
38+
value &= hw->link.speed_mask;
39+
switch (hw->ps) {
40+
case SPEED_1000:
41+
value |= hw->link.speed1000;
42+
break;
43+
case SPEED_100:
44+
value |= hw->link.speed100;
45+
break;
46+
case SPEED_10:
47+
value |= hw->link.speed10;
48+
break;
4749
}
4850
}
4951

@@ -747,9 +749,11 @@ struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
747749
if (mac->multicast_filter_bins)
748750
mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins);
749751

750-
mac->link.port = GMAC_CONFIG_PS;
751752
mac->link.duplex = GMAC_CONFIG_DM;
752-
mac->link.speed = GMAC_CONFIG_FES;
753+
mac->link.speed10 = GMAC_CONFIG_PS;
754+
mac->link.speed100 = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
755+
mac->link.speed1000 = 0;
756+
mac->link.speed_mask = GMAC_CONFIG_FES | GMAC_CONFIG_PS;
753757
mac->mii.addr = GMAC_MDIO_ADDR;
754758
mac->mii.data = GMAC_MDIO_DATA;
755759
mac->mii.addr_shift = 21;

drivers/net/ethernet/stmicro/stmmac/stmmac.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct stmmac_priv {
104104
/* TX Queue */
105105
struct stmmac_tx_queue tx_queue[MTL_MAX_TX_QUEUES];
106106

107-
int oldlink;
107+
bool oldlink;
108108
int speed;
109109
int oldduplex;
110110
unsigned int flow_ctrl;

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ static void stmmac_adjust_link(struct net_device *dev)
775775
struct stmmac_priv *priv = netdev_priv(dev);
776776
struct phy_device *phydev = dev->phydev;
777777
unsigned long flags;
778-
int new_state = 0;
778+
bool new_state = false;
779779

780780
if (!phydev)
781781
return;
@@ -788,8 +788,8 @@ static void stmmac_adjust_link(struct net_device *dev)
788788
/* Now we make sure that we can be in full duplex mode.
789789
* If not, we operate in half-duplex mode. */
790790
if (phydev->duplex != priv->oldduplex) {
791-
new_state = 1;
792-
if (!(phydev->duplex))
791+
new_state = true;
792+
if (!phydev->duplex)
793793
ctrl &= ~priv->hw->link.duplex;
794794
else
795795
ctrl |= priv->hw->link.duplex;
@@ -800,30 +800,17 @@ static void stmmac_adjust_link(struct net_device *dev)
800800
stmmac_mac_flow_ctrl(priv, phydev->duplex);
801801

802802
if (phydev->speed != priv->speed) {
803-
new_state = 1;
803+
new_state = true;
804+
ctrl &= ~priv->hw->link.speed_mask;
804805
switch (phydev->speed) {
805-
case 1000:
806-
if (priv->plat->has_gmac ||
807-
priv->plat->has_gmac4)
808-
ctrl &= ~priv->hw->link.port;
806+
case SPEED_1000:
807+
ctrl |= priv->hw->link.speed1000;
809808
break;
810-
case 100:
811-
if (priv->plat->has_gmac ||
812-
priv->plat->has_gmac4) {
813-
ctrl |= priv->hw->link.port;
814-
ctrl |= priv->hw->link.speed;
815-
} else {
816-
ctrl &= ~priv->hw->link.port;
817-
}
809+
case SPEED_100:
810+
ctrl |= priv->hw->link.speed100;
818811
break;
819-
case 10:
820-
if (priv->plat->has_gmac ||
821-
priv->plat->has_gmac4) {
822-
ctrl |= priv->hw->link.port;
823-
ctrl &= ~(priv->hw->link.speed);
824-
} else {
825-
ctrl &= ~priv->hw->link.port;
826-
}
812+
case SPEED_10:
813+
ctrl |= priv->hw->link.speed10;
827814
break;
828815
default:
829816
netif_warn(priv, link, priv->dev,
@@ -839,12 +826,12 @@ static void stmmac_adjust_link(struct net_device *dev)
839826
writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
840827

841828
if (!priv->oldlink) {
842-
new_state = 1;
843-
priv->oldlink = 1;
829+
new_state = true;
830+
priv->oldlink = true;
844831
}
845832
} else if (priv->oldlink) {
846-
new_state = 1;
847-
priv->oldlink = 0;
833+
new_state = true;
834+
priv->oldlink = false;
848835
priv->speed = SPEED_UNKNOWN;
849836
priv->oldduplex = DUPLEX_UNKNOWN;
850837
}
@@ -907,7 +894,7 @@ static int stmmac_init_phy(struct net_device *dev)
907894
char bus_id[MII_BUS_ID_SIZE];
908895
int interface = priv->plat->interface;
909896
int max_speed = priv->plat->max_speed;
910-
priv->oldlink = 0;
897+
priv->oldlink = false;
911898
priv->speed = SPEED_UNKNOWN;
912899
priv->oldduplex = DUPLEX_UNKNOWN;
913900

@@ -4291,7 +4278,7 @@ int stmmac_suspend(struct device *dev)
42914278
}
42924279
spin_unlock_irqrestore(&priv->lock, flags);
42934280

4294-
priv->oldlink = 0;
4281+
priv->oldlink = false;
42954282
priv->speed = SPEED_UNKNOWN;
42964283
priv->oldduplex = DUPLEX_UNKNOWN;
42974284
return 0;

0 commit comments

Comments
 (0)