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

net: mtk_eth_soc: partially convert to phylink_pcs

Partially convert mtk_eth_soc to phylink_pcs, moving the configuration,
link up and AN restart over. However, it seems mac_pcs_get_state()
doesn't actually get the state from the PCS, so we can't convert that
over without a better understanding of the hardware.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Russell King (Oracle) and committed by
Jakub Kicinski
14a44ab0 901f3fbe

+53 -58
+21 -28
drivers/net/ethernet/mediatek/mtk_eth_soc.c
··· 263 263 mtk_w32(eth, val, TRGMII_TCK_CTRL); 264 264 } 265 265 266 + static struct phylink_pcs *mtk_mac_select_pcs(struct phylink_config *config, 267 + phy_interface_t interface) 268 + { 269 + struct mtk_mac *mac = container_of(config, struct mtk_mac, 270 + phylink_config); 271 + struct mtk_eth *eth = mac->hw; 272 + unsigned int sid; 273 + 274 + if (interface == PHY_INTERFACE_MODE_SGMII || 275 + phy_interface_mode_is_8023z(interface)) { 276 + sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ? 277 + 0 : mac->id; 278 + 279 + return mtk_sgmii_select_pcs(eth->sgmii, sid); 280 + } 281 + 282 + return NULL; 283 + } 284 + 266 285 static void mtk_mac_config(struct phylink_config *config, unsigned int mode, 267 286 const struct phylink_link_state *state) 268 287 { ··· 289 270 phylink_config); 290 271 struct mtk_eth *eth = mac->hw; 291 272 int val, ge_mode, err = 0; 292 - u32 sid, i; 273 + u32 i; 293 274 294 275 /* MT76x8 has no hardware settings between for the MAC */ 295 276 if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628) && ··· 410 391 SYSCFG0_SGMII_MASK, 411 392 ~(u32)SYSCFG0_SGMII_MASK); 412 393 413 - /* Decide how GMAC and SGMIISYS be mapped */ 414 - sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ? 415 - 0 : mac->id; 416 - 417 - /* Setup SGMIISYS with the determined property */ 418 - err = mtk_sgmii_config(eth->sgmii, sid, mode, state->interface); 419 - if (err) 420 - goto init_err; 421 - 422 394 /* Save the syscfg0 value for mac_finish */ 423 395 mac->syscfg0 = val; 424 396 } else if (phylink_autoneg_inband(mode)) { ··· 489 479 state->pause |= MLO_PAUSE_TX; 490 480 } 491 481 492 - static void mtk_mac_an_restart(struct phylink_config *config) 493 - { 494 - struct mtk_mac *mac = container_of(config, struct mtk_mac, 495 - phylink_config); 496 - 497 - mtk_sgmii_restart_an(mac->hw, mac->id); 498 - } 499 - 500 482 static void mtk_mac_link_down(struct phylink_config *config, unsigned int mode, 501 483 phy_interface_t interface) 502 484 { ··· 508 506 struct mtk_mac *mac = container_of(config, struct mtk_mac, 509 507 phylink_config); 510 508 u32 mcr; 511 - 512 - if (phy_interface_mode_is_8023z(interface)) { 513 - struct mtk_eth *eth = mac->hw; 514 - 515 - /* Decide how GMAC and SGMIISYS be mapped */ 516 - int sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ? 517 - 0 : mac->id; 518 - mtk_sgmii_link_up(eth->sgmii, sid, speed, duplex); 519 - } 520 509 521 510 mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id)); 522 511 mcr &= ~(MAC_MCR_SPEED_100 | MAC_MCR_SPEED_1000 | ··· 541 548 542 549 static const struct phylink_mac_ops mtk_phylink_ops = { 543 550 .validate = phylink_generic_validate, 551 + .mac_select_pcs = mtk_mac_select_pcs, 544 552 .mac_pcs_get_state = mtk_mac_pcs_get_state, 545 - .mac_an_restart = mtk_mac_an_restart, 546 553 .mac_config = mtk_mac_config, 547 554 .mac_finish = mtk_mac_finish, 548 555 .mac_link_down = mtk_mac_link_down,
+3 -4
drivers/net/ethernet/mediatek/mtk_eth_soc.h
··· 874 874 * @regmap: The register map pointing at the range used to setup 875 875 * SGMII modes 876 876 * @ana_rgc3: The offset refers to register ANA_RGC3 related to regmap 877 + * @pcs: Phylink PCS structure 877 878 */ 878 879 struct mtk_pcs { 879 880 struct regmap *regmap; 880 881 u32 ana_rgc3; 882 + struct phylink_pcs pcs; 881 883 }; 882 884 883 885 /* struct mtk_sgmii - This is the structure holding sgmii regmap and its ··· 1022 1020 void mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg); 1023 1021 u32 mtk_r32(struct mtk_eth *eth, unsigned reg); 1024 1022 1023 + struct phylink_pcs *mtk_sgmii_select_pcs(struct mtk_sgmii *ss, int id); 1025 1024 int mtk_sgmii_init(struct mtk_sgmii *ss, struct device_node *np, 1026 1025 u32 ana_rgc3); 1027 - int mtk_sgmii_config(struct mtk_sgmii *ss, int id, unsigned int mode, 1028 - phy_interface_t interface); 1029 - void mtk_sgmii_link_up(struct mtk_sgmii *ss, int id, int speed, int duplex); 1030 - void mtk_sgmii_restart_an(struct mtk_eth *eth, int mac_id); 1031 1026 1032 1027 int mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id); 1033 1028 int mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id);
+29 -26
drivers/net/ethernet/mediatek/mtk_sgmii.c
··· 14 14 15 15 #include "mtk_eth_soc.h" 16 16 17 + static struct mtk_pcs *pcs_to_mtk_pcs(struct phylink_pcs *pcs) 18 + { 19 + return container_of(pcs, struct mtk_pcs, pcs); 20 + } 21 + 17 22 /* For SGMII interface mode */ 18 23 static int mtk_pcs_setup_mode_an(struct mtk_pcs *mpcs) 19 24 { 20 25 unsigned int val; 21 - 22 - if (!mpcs->regmap) 23 - return -EINVAL; 24 26 25 27 /* Setup the link timer and QPHY power up inside SGMIISYS */ 26 28 regmap_write(mpcs->regmap, SGMSYS_PCS_LINK_TIMER, ··· 52 50 { 53 51 unsigned int val; 54 52 55 - if (!mpcs->regmap) 56 - return -EINVAL; 57 - 58 53 regmap_read(mpcs->regmap, mpcs->ana_rgc3, &val); 59 54 val &= ~RG_PHY_SPEED_MASK; 60 55 if (interface == PHY_INTERFACE_MODE_2500BASEX) ··· 77 78 return 0; 78 79 } 79 80 80 - int mtk_sgmii_config(struct mtk_sgmii *ss, int id, unsigned int mode, 81 - phy_interface_t interface) 81 + static int mtk_pcs_config(struct phylink_pcs *pcs, unsigned int mode, 82 + phy_interface_t interface, 83 + const unsigned long *advertising, 84 + bool permit_pause_to_mac) 82 85 { 83 - struct mtk_pcs *mpcs = &ss->pcs[id]; 86 + struct mtk_pcs *mpcs = pcs_to_mtk_pcs(pcs); 84 87 int err = 0; 85 88 86 89 /* Setup SGMIISYS with the determined property */ ··· 94 93 return err; 95 94 } 96 95 97 - static void mtk_pcs_restart_an(struct mtk_pcs *mpcs) 96 + static void mtk_pcs_restart_an(struct phylink_pcs *pcs) 98 97 { 98 + struct mtk_pcs *mpcs = pcs_to_mtk_pcs(pcs); 99 99 unsigned int val; 100 - 101 - if (!mpcs->regmap) 102 - return; 103 100 104 101 regmap_read(mpcs->regmap, SGMSYS_PCS_CONTROL_1, &val); 105 102 val |= SGMII_AN_RESTART; 106 103 regmap_write(mpcs->regmap, SGMSYS_PCS_CONTROL_1, val); 107 104 } 108 105 109 - static void mtk_pcs_link_up(struct mtk_pcs *mpcs, int speed, int duplex) 106 + static void mtk_pcs_link_up(struct phylink_pcs *pcs, unsigned int mode, 107 + phy_interface_t interface, int speed, int duplex) 110 108 { 109 + struct mtk_pcs *mpcs = pcs_to_mtk_pcs(pcs); 111 110 unsigned int val; 111 + 112 + if (!phy_interface_mode_is_8023z(interface)) 113 + return; 112 114 113 115 /* SGMII force duplex setting */ 114 116 regmap_read(mpcs->regmap, SGMSYS_SGMII_MODE, &val); ··· 122 118 regmap_write(mpcs->regmap, SGMSYS_SGMII_MODE, val); 123 119 } 124 120 125 - /* For 1000BASE-X and 2500BASE-X interface modes */ 126 - void mtk_sgmii_link_up(struct mtk_sgmii *ss, int id, int speed, int duplex) 127 - { 128 - mtk_pcs_link_up(&ss->pcs[id], speed, duplex); 129 - } 121 + static const struct phylink_pcs_ops mtk_pcs_ops = { 122 + .pcs_config = mtk_pcs_config, 123 + .pcs_an_restart = mtk_pcs_restart_an, 124 + .pcs_link_up = mtk_pcs_link_up, 125 + }; 130 126 131 127 int mtk_sgmii_init(struct mtk_sgmii *ss, struct device_node *r, u32 ana_rgc3) 132 128 { ··· 143 139 of_node_put(np); 144 140 if (IS_ERR(ss->pcs[i].regmap)) 145 141 return PTR_ERR(ss->pcs[i].regmap); 142 + 143 + ss->pcs[i].pcs.ops = &mtk_pcs_ops; 146 144 } 147 145 148 146 return 0; 149 147 } 150 148 151 - void mtk_sgmii_restart_an(struct mtk_eth *eth, int mac_id) 149 + struct phylink_pcs *mtk_sgmii_select_pcs(struct mtk_sgmii *ss, int id) 152 150 { 153 - unsigned int sid; 151 + if (!ss->pcs[id].regmap) 152 + return NULL; 154 153 155 - /* Decide how GMAC and SGMIISYS be mapped */ 156 - sid = (MTK_HAS_CAPS(eth->soc->caps, MTK_SHARED_SGMII)) ? 157 - 0 : mac_id; 158 - 159 - mtk_pcs_restart_an(&eth->sgmii->pcs[sid]); 154 + return &ss->pcs[id].pcs; 160 155 }