Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: stmmac: qcom-ethqos: remove MAC_CTRL_REG modification

When operating in "SGMII" mode (Cisco SGMII or 2500BASE-X), qcom-ethqos
modifies the MAC control register in its ethqos_configure_sgmii()
function, which is only called from one path:

stmmac_mac_link_up()
+- reads MAC_CTRL_REG
+- masks out priv->hw->link.speed_mask
+- sets bits according to speed (2500, 1000, 100, 10) from priv->hw.link.speed*
+- ethqos_fix_mac_speed()
| +- qcom_ethqos_set_sgmii_loopback(false)
| +- ethqos_update_link_clk(speed)
| `- ethqos_configure(speed)
| `- ethqos_configure_sgmii(speed)
| +- reads MAC_CTRL_REG,
| +- configures PS/FES bits according to speed
| `- writes MAC_CTRL_REG as the last operation
+- sets duplex bit(s)
+- stmmac_mac_flow_ctrl()
+- writes MAC_CTRL_REG if changed from original read
...

As can be seen, the modification of the control register that
stmmac_mac_link_up() overwrites the changes that ethqos_fix_mac_speed()
does to the register. This makes ethqos_configure_sgmii()'s
modification questionable at best.

Analysing the values written, GMAC4 sets the speed bits as:
speed_mask = GMAC_CONFIG_FES | GMAC_CONFIG_PS
speed2500 = GMAC_CONFIG_FES B14=1 B15=0
speed1000 = 0 B14=0 B15=0
speed100 = GMAC_CONFIG_FES | GMAC_CONFIG_PS B14=1 B15=1
speed10 = GMAC_CONFIG_PS B14=0 B15=1

Whereas ethqos_configure_sgmii():
2500: clears ETHQOS_MAC_CTRL_PORT_SEL B14=X B15=0
1000: clears ETHQOS_MAC_CTRL_PORT_SEL B14=X B15=0
100: sets ETHQOS_MAC_CTRL_PORT_SEL | B14=1 B15=1
ETHQOS_MAC_CTRL_SPEED_MODE
10: sets ETHQOS_MAC_CTRL_PORT_SEL B14=0 B15=1
clears ETHQOS_MAC_CTRL_SPEED_MODE

Thus, they appear to be doing very similar, with the exception of the
FES bit (bit 14) for 1G and 2.5G speeds.

Given that stmmac_mac_link_up() will write the MAC_CTRL_REG after
ethqos_configure_sgmii(), remove the unnecessary update in the
glue driver's ethqos_configure_sgmii() method, simplifying the code.

Konrad states:

Without any additional knowledge, the register description says:

2500: B14=1 B15=0
1000: B14=0 B15=0
100: B14=1 B15=1
10: B14=0 B15=1

Tested-by: Mohd Ayaan Anwar <mohd.anwar@oss.qualcomm.com>
Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Link: https://patch.msgid.link/E1vEPlg-0000000CFHY-282A@rmk-PC.armlinux.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Russell King (Oracle) and committed by
Jakub Kicinski
9b443e58 ab5b7680

+1 -15
+1 -15
drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
··· 76 76 #define RGMII_CONFIG2_DATA_DIVIDE_CLK_SEL BIT(6) 77 77 #define RGMII_CONFIG2_TX_CLK_PHASE_SHIFT_EN BIT(5) 78 78 79 - /* MAC_CTRL_REG bits */ 80 - #define ETHQOS_MAC_CTRL_SPEED_MODE BIT(14) 81 - #define ETHQOS_MAC_CTRL_PORT_SEL BIT(15) 82 - 83 79 /* EMAC_WRAPPER_SGMII_PHY_CNTRL1 bits */ 84 80 #define SGMII_PHY_CNTRL1_SGMII_TX_TO_RX_LOOPBACK_EN BIT(3) 85 81 ··· 628 632 { 629 633 struct net_device *dev = platform_get_drvdata(ethqos->pdev); 630 634 struct stmmac_priv *priv = netdev_priv(dev); 631 - int val; 632 - 633 - val = readl(ethqos->mac_base + MAC_CTRL_REG); 634 635 635 636 switch (speed) { 636 637 case SPEED_2500: 637 - val &= ~ETHQOS_MAC_CTRL_PORT_SEL; 638 638 rgmii_updatel(ethqos, RGMII_CONFIG2_RGMII_CLK_SEL_CFG, 639 639 RGMII_CONFIG2_RGMII_CLK_SEL_CFG, 640 640 RGMII_IO_MACRO_CONFIG2); ··· 638 646 ethqos_pcs_set_inband(priv, false); 639 647 break; 640 648 case SPEED_1000: 641 - val &= ~ETHQOS_MAC_CTRL_PORT_SEL; 642 649 rgmii_updatel(ethqos, RGMII_CONFIG2_RGMII_CLK_SEL_CFG, 643 650 RGMII_CONFIG2_RGMII_CLK_SEL_CFG, 644 651 RGMII_IO_MACRO_CONFIG2); ··· 645 654 ethqos_pcs_set_inband(priv, true); 646 655 break; 647 656 case SPEED_100: 648 - val |= ETHQOS_MAC_CTRL_PORT_SEL | ETHQOS_MAC_CTRL_SPEED_MODE; 649 657 ethqos_set_serdes_speed(ethqos, SPEED_1000); 650 658 ethqos_pcs_set_inband(priv, true); 651 659 break; 652 660 case SPEED_10: 653 - val |= ETHQOS_MAC_CTRL_PORT_SEL; 654 - val &= ~ETHQOS_MAC_CTRL_SPEED_MODE; 655 661 rgmii_updatel(ethqos, RGMII_CONFIG_SGMII_CLK_DVDR, 656 662 FIELD_PREP(RGMII_CONFIG_SGMII_CLK_DVDR, 657 663 SGMII_10M_RX_CLK_DVDR), ··· 658 670 break; 659 671 } 660 672 661 - writel(val, ethqos->mac_base + MAC_CTRL_REG); 662 - 663 - return val; 673 + return 0; 664 674 } 665 675 666 676 static int ethqos_configure(struct qcom_ethqos *ethqos, int speed)