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

net: ethernet: mtk_eth_soc: add support for MT7988 internal 2.5G PHY

The MediaTek MT7988 SoC comes with an single built-in Ethernet PHY for
2500Base-T/1000Base-T/100Base-TX/10Base-T link partners in addition to
the built-in 1GE switch. The built-in PHY only supports full duplex.

Add muxes allowing to select GMAC2->2.5G PHY path and add basic support
for XGMAC as the built-in 2.5G PHY is internally connected via XGMII.
The XGMAC features will also be used by 5GBase-R, 10GBase-R and USXGMII
SerDes modes which are going to be added once support for standalone PCS
drivers is in place.

In order to make use of the built-in 2.5G PHY the appropriate PHY driver
as well as (proprietary) PHY firmware has to be present as well.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Link: https://patch.msgid.link/9072cefbff6db969720672ec98ed5cef65e8218c.1745715380.git.daniel@makrotopia.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Daniel Golle and committed by
Jakub Kicinski
51cf06dd 7a4f15ca

+203 -16
+43
drivers/net/ethernet/mediatek/mtk_eth_path.c
··· 31 31 return "gmac2_rgmii"; 32 32 case MTK_ETH_PATH_GMAC2_SGMII: 33 33 return "gmac2_sgmii"; 34 + case MTK_ETH_PATH_GMAC2_2P5GPHY: 35 + return "gmac2_2p5gphy"; 34 36 case MTK_ETH_PATH_GMAC2_GEPHY: 35 37 return "gmac2_gephy"; 36 38 case MTK_ETH_PATH_GDM1_ESW: ··· 129 127 return 0; 130 128 } 131 129 130 + static int set_mux_gmac2_to_2p5gphy(struct mtk_eth *eth, u64 path) 131 + { 132 + int ret; 133 + 134 + if (path == MTK_ETH_PATH_GMAC2_2P5GPHY) { 135 + ret = regmap_clear_bits(eth->ethsys, ETHSYS_SYSCFG0, 136 + SYSCFG0_SGMII_GMAC2_V2); 137 + if (ret) 138 + return ret; 139 + 140 + /* Setup mux to 2p5g PHY */ 141 + ret = regmap_clear_bits(eth->infra, TOP_MISC_NETSYS_PCS_MUX, 142 + MUX_G2_USXGMII_SEL); 143 + if (ret) 144 + return ret; 145 + 146 + dev_dbg(eth->dev, "path %s in %s updated\n", 147 + mtk_eth_path_name(path), __func__); 148 + } 149 + 150 + return 0; 151 + } 152 + 132 153 static int set_mux_gmac1_gmac2_to_sgmii_rgmii(struct mtk_eth *eth, u64 path) 133 154 { 134 155 unsigned int val = 0; ··· 235 210 .cap_bit = MTK_ETH_MUX_U3_GMAC2_TO_QPHY, 236 211 .set_path = set_mux_u3_gmac2_to_qphy, 237 212 }, { 213 + .name = "mux_gmac2_to_2p5gphy", 214 + .cap_bit = MTK_ETH_MUX_GMAC2_TO_2P5GPHY, 215 + .set_path = set_mux_gmac2_to_2p5gphy, 216 + }, { 238 217 .name = "mux_gmac1_gmac2_to_sgmii_rgmii", 239 218 .cap_bit = MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII, 240 219 .set_path = set_mux_gmac1_gmac2_to_sgmii_rgmii, ··· 284 255 285 256 path = (mac_id == 0) ? MTK_ETH_PATH_GMAC1_SGMII : 286 257 MTK_ETH_PATH_GMAC2_SGMII; 258 + 259 + /* Setup proper MUXes along the path */ 260 + return mtk_eth_mux_setup(eth, path); 261 + } 262 + 263 + int mtk_gmac_2p5gphy_path_setup(struct mtk_eth *eth, int mac_id) 264 + { 265 + u64 path = 0; 266 + 267 + if (mac_id == MTK_GMAC2_ID) 268 + path = MTK_ETH_PATH_GMAC2_2P5GPHY; 269 + 270 + if (!path) 271 + return -EINVAL; 287 272 288 273 /* Setup proper MUXes along the path */ 289 274 return mtk_eth_mux_setup(eth, path);
+106 -13
drivers/net/ethernet/mediatek/mtk_eth_soc.c
··· 503 503 static void mtk_setup_bridge_switch(struct mtk_eth *eth) 504 504 { 505 505 /* Force Port1 XGMAC Link Up */ 506 - mtk_m32(eth, 0, MTK_XGMAC_FORCE_LINK(MTK_GMAC1_ID), 506 + mtk_m32(eth, 0, MTK_XGMAC_FORCE_MODE(MTK_GMAC1_ID), 507 507 MTK_XGMAC_STS(MTK_GMAC1_ID)); 508 508 509 509 /* Adjust GSW bridge IPG to 11 */ ··· 530 530 } 531 531 532 532 return NULL; 533 + } 534 + 535 + static int mtk_mac_prepare(struct phylink_config *config, unsigned int mode, 536 + phy_interface_t iface) 537 + { 538 + struct mtk_mac *mac = container_of(config, struct mtk_mac, 539 + phylink_config); 540 + struct mtk_eth *eth = mac->hw; 541 + 542 + if (mtk_interface_mode_is_xgmii(eth, iface) && 543 + mac->id != MTK_GMAC1_ID) { 544 + mtk_m32(mac->hw, XMAC_MCR_TRX_DISABLE, 545 + XMAC_MCR_TRX_DISABLE, MTK_XMAC_MCR(mac->id)); 546 + 547 + mtk_m32(mac->hw, MTK_XGMAC_FORCE_MODE(mac->id) | 548 + MTK_XGMAC_FORCE_LINK(mac->id), 549 + MTK_XGMAC_FORCE_MODE(mac->id), MTK_XGMAC_STS(mac->id)); 550 + } 551 + 552 + return 0; 533 553 } 534 554 535 555 static void mtk_mac_config(struct phylink_config *config, unsigned int mode, ··· 593 573 } 594 574 break; 595 575 case PHY_INTERFACE_MODE_INTERNAL: 576 + if (mac->id == MTK_GMAC2_ID && 577 + MTK_HAS_CAPS(eth->soc->caps, MTK_2P5GPHY)) { 578 + err = mtk_gmac_2p5gphy_path_setup(eth, mac->id); 579 + if (err) 580 + goto init_err; 581 + } 596 582 break; 597 583 default: 598 584 goto err_phy; ··· 670 644 } 671 645 672 646 /* Setup gmac */ 673 - if (mtk_is_netsys_v3_or_greater(eth) && 674 - mac->interface == PHY_INTERFACE_MODE_INTERNAL) { 647 + if (mtk_interface_mode_is_xgmii(eth, state->interface)) { 675 648 mtk_w32(mac->hw, MTK_GDMA_XGDM_SEL, MTK_GDMA_EG_CTRL(mac->id)); 676 649 mtk_w32(mac->hw, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(mac->id)); 677 650 678 - mtk_setup_bridge_switch(eth); 651 + if (mac->id == MTK_GMAC1_ID) 652 + mtk_setup_bridge_switch(eth); 679 653 } 680 654 681 655 return; ··· 722 696 { 723 697 struct mtk_mac *mac = container_of(config, struct mtk_mac, 724 698 phylink_config); 725 - u32 mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id)); 726 699 727 - mcr &= ~(MAC_MCR_TX_EN | MAC_MCR_RX_EN | MAC_MCR_FORCE_LINK); 728 - mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id)); 700 + if (!mtk_interface_mode_is_xgmii(mac->hw, interface)) { 701 + /* GMAC modes */ 702 + mtk_m32(mac->hw, 703 + MAC_MCR_TX_EN | MAC_MCR_RX_EN | MAC_MCR_FORCE_LINK, 0, 704 + MTK_MAC_MCR(mac->id)); 705 + } else if (mac->id != MTK_GMAC1_ID) { 706 + /* XGMAC except for built-in switch */ 707 + mtk_m32(mac->hw, XMAC_MCR_TRX_DISABLE, XMAC_MCR_TRX_DISABLE, 708 + MTK_XMAC_MCR(mac->id)); 709 + mtk_m32(mac->hw, MTK_XGMAC_FORCE_LINK(mac->id), 0, 710 + MTK_XGMAC_STS(mac->id)); 711 + } 729 712 } 730 713 731 714 static void mtk_set_queue_speed(struct mtk_eth *eth, unsigned int idx, ··· 806 771 mtk_w32(eth, val, soc->reg_map->qdma.qtx_sch + ofs); 807 772 } 808 773 809 - static void mtk_mac_link_up(struct phylink_config *config, 810 - struct phy_device *phy, 811 - unsigned int mode, phy_interface_t interface, 812 - int speed, int duplex, bool tx_pause, bool rx_pause) 774 + static void mtk_gdm_mac_link_up(struct mtk_mac *mac, 775 + struct phy_device *phy, 776 + unsigned int mode, phy_interface_t interface, 777 + int speed, int duplex, bool tx_pause, 778 + bool rx_pause) 813 779 { 814 - struct mtk_mac *mac = container_of(config, struct mtk_mac, 815 - phylink_config); 816 780 u32 mcr; 817 781 818 782 mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id)); ··· 845 811 mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id)); 846 812 } 847 813 814 + static void mtk_xgdm_mac_link_up(struct mtk_mac *mac, 815 + struct phy_device *phy, 816 + unsigned int mode, phy_interface_t interface, 817 + int speed, int duplex, bool tx_pause, 818 + bool rx_pause) 819 + { 820 + u32 mcr; 821 + 822 + if (mac->id == MTK_GMAC1_ID) 823 + return; 824 + 825 + /* Eliminate the interference(before link-up) caused by PHY noise */ 826 + mtk_m32(mac->hw, XMAC_LOGIC_RST, 0, MTK_XMAC_LOGIC_RST(mac->id)); 827 + mdelay(20); 828 + mtk_m32(mac->hw, XMAC_GLB_CNTCLR, XMAC_GLB_CNTCLR, 829 + MTK_XMAC_CNT_CTRL(mac->id)); 830 + 831 + mtk_m32(mac->hw, MTK_XGMAC_FORCE_LINK(mac->id), 832 + MTK_XGMAC_FORCE_LINK(mac->id), MTK_XGMAC_STS(mac->id)); 833 + 834 + mcr = mtk_r32(mac->hw, MTK_XMAC_MCR(mac->id)); 835 + mcr &= ~(XMAC_MCR_FORCE_TX_FC | XMAC_MCR_FORCE_RX_FC | 836 + XMAC_MCR_TRX_DISABLE); 837 + /* Configure pause modes - 838 + * phylink will avoid these for half duplex 839 + */ 840 + if (tx_pause) 841 + mcr |= XMAC_MCR_FORCE_TX_FC; 842 + if (rx_pause) 843 + mcr |= XMAC_MCR_FORCE_RX_FC; 844 + 845 + mtk_w32(mac->hw, mcr, MTK_XMAC_MCR(mac->id)); 846 + } 847 + 848 + static void mtk_mac_link_up(struct phylink_config *config, 849 + struct phy_device *phy, 850 + unsigned int mode, phy_interface_t interface, 851 + int speed, int duplex, bool tx_pause, bool rx_pause) 852 + { 853 + struct mtk_mac *mac = container_of(config, struct mtk_mac, 854 + phylink_config); 855 + 856 + if (mtk_interface_mode_is_xgmii(mac->hw, interface)) 857 + mtk_xgdm_mac_link_up(mac, phy, mode, interface, speed, duplex, 858 + tx_pause, rx_pause); 859 + else 860 + mtk_gdm_mac_link_up(mac, phy, mode, interface, speed, duplex, 861 + tx_pause, rx_pause); 862 + } 863 + 848 864 static void mtk_mac_disable_tx_lpi(struct phylink_config *config) 849 865 { 850 866 struct mtk_mac *mac = container_of(config, struct mtk_mac, ··· 911 827 phylink_config); 912 828 struct mtk_eth *eth = mac->hw; 913 829 u32 val; 830 + 831 + if (mtk_interface_mode_is_xgmii(eth, mac->interface)) 832 + return -EOPNOTSUPP; 914 833 915 834 /* Tx idle timer in ms */ 916 835 timer = DIV_ROUND_UP(timer, 1000); ··· 945 858 } 946 859 947 860 static const struct phylink_mac_ops mtk_phylink_ops = { 861 + .mac_prepare = mtk_mac_prepare, 948 862 .mac_select_pcs = mtk_mac_select_pcs, 949 863 .mac_config = mtk_mac_config, 950 864 .mac_finish = mtk_mac_finish, ··· 4850 4762 } 4851 4763 4852 4764 mac->phylink = phylink; 4765 + 4766 + if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_2P5GPHY) && 4767 + id == MTK_GMAC2_ID) 4768 + __set_bit(PHY_INTERFACE_MODE_INTERNAL, 4769 + mac->phylink_config.supported_interfaces); 4853 4770 4854 4771 SET_NETDEV_DEV(eth->netdev[id], eth->dev); 4855 4772 eth->netdev[id]->watchdog_timeo = 5 * HZ;
+54 -3
drivers/net/ethernet/mediatek/mtk_eth_soc.h
··· 431 431 432 432 /* XMAC status registers */ 433 433 #define MTK_XGMAC_STS(x) (((x) == MTK_GMAC3_ID) ? 0x1001C : 0x1000C) 434 - #define MTK_XGMAC_FORCE_LINK(x) (((x) == MTK_GMAC2_ID) ? BIT(31) : BIT(15)) 434 + #define MTK_XGMAC_FORCE_MODE(x) (((x) == MTK_GMAC2_ID) ? BIT(31) : BIT(15)) 435 + #define MTK_XGMAC_FORCE_LINK(x) (((x) == MTK_GMAC2_ID) ? BIT(27) : BIT(11)) 435 436 #define MTK_USXGMII_PCS_LINK BIT(8) 436 437 #define MTK_XGMAC_RX_FC BIT(5) 437 438 #define MTK_XGMAC_TX_FC BIT(4) ··· 525 524 #define INTF_MODE_RGMII_1000 (TRGMII_MODE | TRGMII_CENTRAL_ALIGNED) 526 525 #define INTF_MODE_RGMII_10_100 0 527 526 527 + /* XFI Mac control registers */ 528 + #define MTK_XMAC_BASE(x) (0x12000 + (((x) - 1) * 0x1000)) 529 + #define MTK_XMAC_MCR(x) (MTK_XMAC_BASE(x)) 530 + #define XMAC_MCR_TRX_DISABLE 0xf 531 + #define XMAC_MCR_FORCE_TX_FC BIT(5) 532 + #define XMAC_MCR_FORCE_RX_FC BIT(4) 533 + 534 + /* XFI Mac logic reset registers */ 535 + #define MTK_XMAC_LOGIC_RST(x) (MTK_XMAC_BASE(x) + 0x10) 536 + #define XMAC_LOGIC_RST BIT(0) 537 + 538 + /* XFI Mac count global control */ 539 + #define MTK_XMAC_CNT_CTRL(x) (MTK_XMAC_BASE(x) + 0x100) 540 + #define XMAC_GLB_CNTCLR BIT(0) 541 + 528 542 /* GPIO port control registers for GMAC 2*/ 529 543 #define GPIO_OD33_CTRL8 0x4c0 530 544 #define GPIO_BIAS_CTRL 0xed0 ··· 603 587 #define GEPHY_MAC_SEL BIT(1) 604 588 605 589 /* Top misc registers */ 590 + #define TOP_MISC_NETSYS_PCS_MUX 0x0 591 + #define NETSYS_PCS_MUX_MASK GENMASK(1, 0) 592 + #define MUX_G2_USXGMII_SEL BIT(1) 593 + 606 594 #define USB_PHY_SWITCH_REG 0x218 607 595 #define QPHY_SEL_MASK GENMASK(1, 0) 608 596 #define SGMII_QPHY_SEL 0x2 ··· 971 951 MTK_RGMII_BIT = 0, 972 952 MTK_TRGMII_BIT, 973 953 MTK_SGMII_BIT, 954 + MTK_2P5GPHY_BIT, 974 955 MTK_ESW_BIT, 975 956 MTK_GEPHY_BIT, 976 957 MTK_MUX_BIT, ··· 992 971 MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT, 993 972 MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT, 994 973 MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT, 974 + MTK_ETH_MUX_GMAC2_TO_2P5GPHY_BIT, 995 975 MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT, 996 976 MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT, 997 977 ··· 1002 980 MTK_ETH_PATH_GMAC1_SGMII_BIT, 1003 981 MTK_ETH_PATH_GMAC2_RGMII_BIT, 1004 982 MTK_ETH_PATH_GMAC2_SGMII_BIT, 983 + MTK_ETH_PATH_GMAC2_2P5GPHY_BIT, 1005 984 MTK_ETH_PATH_GMAC2_GEPHY_BIT, 1006 985 MTK_ETH_PATH_GDM1_ESW_BIT, 1007 986 }; ··· 1011 988 #define MTK_RGMII BIT_ULL(MTK_RGMII_BIT) 1012 989 #define MTK_TRGMII BIT_ULL(MTK_TRGMII_BIT) 1013 990 #define MTK_SGMII BIT_ULL(MTK_SGMII_BIT) 991 + #define MTK_2P5GPHY BIT_ULL(MTK_2P5GPHY_BIT) 1014 992 #define MTK_ESW BIT_ULL(MTK_ESW_BIT) 1015 993 #define MTK_GEPHY BIT_ULL(MTK_GEPHY_BIT) 1016 994 #define MTK_MUX BIT_ULL(MTK_MUX_BIT) ··· 1034 1010 BIT_ULL(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT) 1035 1011 #define MTK_ETH_MUX_U3_GMAC2_TO_QPHY \ 1036 1012 BIT_ULL(MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT) 1013 + #define MTK_ETH_MUX_GMAC2_TO_2P5GPHY \ 1014 + BIT_ULL(MTK_ETH_MUX_GMAC2_TO_2P5GPHY_BIT) 1037 1015 #define MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \ 1038 1016 BIT_ULL(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT) 1039 1017 #define MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII \ ··· 1047 1021 #define MTK_ETH_PATH_GMAC1_SGMII BIT_ULL(MTK_ETH_PATH_GMAC1_SGMII_BIT) 1048 1022 #define MTK_ETH_PATH_GMAC2_RGMII BIT_ULL(MTK_ETH_PATH_GMAC2_RGMII_BIT) 1049 1023 #define MTK_ETH_PATH_GMAC2_SGMII BIT_ULL(MTK_ETH_PATH_GMAC2_SGMII_BIT) 1024 + #define MTK_ETH_PATH_GMAC2_2P5GPHY BIT_ULL(MTK_ETH_PATH_GMAC2_2P5GPHY_BIT) 1050 1025 #define MTK_ETH_PATH_GMAC2_GEPHY BIT_ULL(MTK_ETH_PATH_GMAC2_GEPHY_BIT) 1051 1026 #define MTK_ETH_PATH_GDM1_ESW BIT_ULL(MTK_ETH_PATH_GDM1_ESW_BIT) 1052 1027 ··· 1057 1030 #define MTK_GMAC2_RGMII (MTK_ETH_PATH_GMAC2_RGMII | MTK_RGMII) 1058 1031 #define MTK_GMAC2_SGMII (MTK_ETH_PATH_GMAC2_SGMII | MTK_SGMII) 1059 1032 #define MTK_GMAC2_GEPHY (MTK_ETH_PATH_GMAC2_GEPHY | MTK_GEPHY) 1033 + #define MTK_GMAC2_2P5GPHY (MTK_ETH_PATH_GMAC2_2P5GPHY | MTK_2P5GPHY) 1060 1034 #define MTK_GDM1_ESW (MTK_ETH_PATH_GDM1_ESW | MTK_ESW) 1061 1035 1062 1036 /* MUXes present on SoCs */ ··· 1076 1048 #define MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \ 1077 1049 (MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_MUX | \ 1078 1050 MTK_SHARED_SGMII) 1051 + 1052 + /* 2: GMAC2 -> 2P5GPHY */ 1053 + #define MTK_MUX_GMAC2_TO_2P5GPHY \ 1054 + (MTK_ETH_MUX_GMAC2_TO_2P5GPHY | MTK_MUX | MTK_INFRA) 1079 1055 1080 1056 /* 0: GMACx -> GEPHY, 1: GMACx -> SGMII where x is 1 or 2 */ 1081 1057 #define MTK_MUX_GMAC12_TO_GEPHY_SGMII \ ··· 1116 1084 MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA | \ 1117 1085 MTK_RSTCTRL_PPE1 | MTK_SRAM) 1118 1086 1119 - #define MT7988_CAPS (MTK_36BIT_DMA | MTK_GDM1_ESW | MTK_QDMA | \ 1120 - MTK_RSTCTRL_PPE1 | MTK_RSTCTRL_PPE2 | MTK_SRAM) 1087 + #define MT7988_CAPS (MTK_36BIT_DMA | MTK_GDM1_ESW | MTK_GMAC2_2P5GPHY | \ 1088 + MTK_MUX_GMAC2_TO_2P5GPHY | MTK_QDMA | MTK_RSTCTRL_PPE1 | \ 1089 + MTK_RSTCTRL_PPE2 | MTK_SRAM) 1121 1090 1122 1091 struct mtk_tx_dma_desc_info { 1123 1092 dma_addr_t addr; ··· 1470 1437 return MTK_FOE_IB2_MULTICAST; 1471 1438 } 1472 1439 1440 + static inline bool mtk_interface_mode_is_xgmii(struct mtk_eth *eth, 1441 + phy_interface_t interface) 1442 + { 1443 + if (!mtk_is_netsys_v3_or_greater(eth)) 1444 + return false; 1445 + 1446 + switch (interface) { 1447 + case PHY_INTERFACE_MODE_INTERNAL: 1448 + case PHY_INTERFACE_MODE_USXGMII: 1449 + case PHY_INTERFACE_MODE_10GBASER: 1450 + case PHY_INTERFACE_MODE_5GBASER: 1451 + return true; 1452 + default: 1453 + return false; 1454 + } 1455 + } 1456 + 1473 1457 /* read the hardware status register */ 1474 1458 void mtk_stats_update_mac(struct mtk_mac *mac); 1475 1459 ··· 1495 1445 u32 mtk_m32(struct mtk_eth *eth, u32 mask, u32 set, unsigned int reg); 1496 1446 1497 1447 int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id); 1448 + int mtk_gmac_2p5gphy_path_setup(struct mtk_eth *eth, int mac_id); 1498 1449 int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id); 1499 1450 int mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id); 1500 1451