1 @@ -3386,9 +3906,10 @@ static void mvneta_mac_an_restart(struct 2 gmac_an & ~MVNETA_GMAC_INBAND_RESTART_AN); 3 } 4 5 -static void mvneta_mac_config(struct net_device *ndev, unsigned int mode, 6 - const struct phylink_link_state *state) 7 +static void mvneta_mac_config(struct phylink_config *config, unsigned int mode, 8 + const struct phylink_link_state *state) 9 { 10 + struct net_device *ndev = to_net_dev(config->dev); 11 struct mvneta_port *pp = netdev_priv(ndev); 12 u32 new_ctrl0, gmac_ctrl0 = mvreg_read(pp, MVNETA_GMAC_CTRL_0); 13 u32 new_ctrl2, gmac_ctrl2 = mvreg_read(pp, MVNETA_GMAC_CTRL_2); 14 @@ -3403,20 +3924,11 @@ static void mvneta_mac_config(struct net 15 new_clk = gmac_clk & ~MVNETA_GMAC_1MS_CLOCK_ENABLE; 16 new_an = gmac_an & ~(MVNETA_GMAC_INBAND_AN_ENABLE | 17 MVNETA_GMAC_INBAND_RESTART_AN | 18 - MVNETA_GMAC_CONFIG_MII_SPEED | 19 - MVNETA_GMAC_CONFIG_GMII_SPEED | 20 MVNETA_GMAC_AN_SPEED_EN | 21 MVNETA_GMAC_ADVERT_SYM_FLOW_CTRL | 22 - MVNETA_GMAC_CONFIG_FLOW_CTRL | 23 MVNETA_GMAC_AN_FLOW_CTRL_EN | 24 - MVNETA_GMAC_CONFIG_FULL_DUPLEX | 25 MVNETA_GMAC_AN_DUPLEX_EN); 26 27 - if (phylink_test(state->advertising, Pause)) 28 - new_an |= MVNETA_GMAC_ADVERT_SYM_FLOW_CTRL; 29 - if (state->pause & MLO_PAUSE_TXRX_MASK) 30 - new_an |= MVNETA_GMAC_CONFIG_FLOW_CTRL; 31 - 32 /* Even though it might look weird, when we're configured in 33 * SGMII or QSGMII mode, the RGMII bit needs to be set. 34 */ 35 @@ -3427,30 +3939,32 @@ static void mvneta_mac_config(struct net 36 phy_interface_mode_is_8023z(state->interface)) 37 new_ctrl2 |= MVNETA_GMAC2_PCS_ENABLE; 38 39 + if (phylink_test(state->advertising, Pause)) 40 + new_an |= MVNETA_GMAC_ADVERT_SYM_FLOW_CTRL; 41 + 42 if (!phylink_autoneg_inband(mode)) { 43 - /* Phy or fixed speed */ 44 - if (state->duplex) 45 - new_an |= MVNETA_GMAC_CONFIG_FULL_DUPLEX; 46 - 47 - if (state->speed == SPEED_1000) 48 - new_an |= MVNETA_GMAC_CONFIG_GMII_SPEED; 49 - else if (state->speed == SPEED_100) 50 - new_an |= MVNETA_GMAC_CONFIG_MII_SPEED; 51 + /* Phy or fixed speed - nothing to do, leave the 52 + * configured speed, duplex and flow control as-is. 53 + */ 54 } else if (state->interface == PHY_INTERFACE_MODE_SGMII) { 55 /* SGMII mode receives the state from the PHY */ 56 new_ctrl2 |= MVNETA_GMAC2_INBAND_AN_ENABLE; 57 - new_clk |= MVNETA_GMAC_1MS_CLOCK_ENABLE; 58 + new_clk = MVNETA_GMAC_1MS_CLOCK_ENABLE; 59 new_an = (new_an & ~(MVNETA_GMAC_FORCE_LINK_DOWN | 60 - MVNETA_GMAC_FORCE_LINK_PASS)) | 61 + MVNETA_GMAC_FORCE_LINK_PASS | 62 + MVNETA_GMAC_CONFIG_MII_SPEED | 63 + MVNETA_GMAC_CONFIG_GMII_SPEED | 64 + MVNETA_GMAC_CONFIG_FULL_DUPLEX)) | 65 MVNETA_GMAC_INBAND_AN_ENABLE | 66 MVNETA_GMAC_AN_SPEED_EN | 67 MVNETA_GMAC_AN_DUPLEX_EN; 68 } else { 69 /* 802.3z negotiation - only 1000base-X */ 70 new_ctrl0 |= MVNETA_GMAC0_PORT_1000BASE_X; 71 - new_clk |= MVNETA_GMAC_1MS_CLOCK_ENABLE; 72 + new_clk = MVNETA_GMAC_1MS_CLOCK_ENABLE; 73 new_an = (new_an & ~(MVNETA_GMAC_FORCE_LINK_DOWN | 74 - MVNETA_GMAC_FORCE_LINK_PASS)) | 75 + MVNETA_GMAC_FORCE_LINK_PASS | 76 + MVNETA_GMAC_CONFIG_MII_SPEED)) | 77 MVNETA_GMAC_INBAND_AN_ENABLE | 78 MVNETA_GMAC_CONFIG_GMII_SPEED | 79 /* The MAC only supports FD mode */ 80 @@ -3460,9 +3974,14 @@ static void mvneta_mac_config(struct net 81 new_an |= MVNETA_GMAC_AN_FLOW_CTRL_EN; 82 } 83 84 + /* Set the 1ms clock divisor */ 85 + if (new_clk == MVNETA_GMAC_1MS_CLOCK_ENABLE) 86 + new_clk |= clk_get_rate(pp->clk) / 1000; 87 + 88 /* Armada 370 documentation says we can only change the port mode 89 * and in-band enable when the link is down, so force it down 90 - * while making these changes. We also do this for GMAC_CTRL2 */ 91 + * while making these changes. We also do this for GMAC_CTRL2 92 + */ 93 if ((new_ctrl0 ^ gmac_ctrl0) & MVNETA_GMAC0_PORT_1000BASE_X || 94 (new_ctrl2 ^ gmac_ctrl2) & MVNETA_GMAC2_INBAND_AN_ENABLE || 95 (new_an ^ gmac_an) & MVNETA_GMAC_INBAND_AN_ENABLE) { 96 @@ -3471,14 +3990,18 @@ static void mvneta_mac_config(struct net 97 MVNETA_GMAC_FORCE_LINK_DOWN); 98 } 99 100 + 101 /* When at 2.5G, the link partner can send frames with shortened 102 * preambles. 103 */ 104 if (state->interface == PHY_INTERFACE_MODE_2500BASEX) 105 new_ctrl4 |= MVNETA_GMAC4_SHORT_PREAMBLE_ENABLE; 106 107 - if (pp->phy_interface != state->interface) 108 - mvneta_config_interface(pp, state->interface); 109 + if (pp->phy_interface != state->interface) { 110 + if (pp->comphy) 111 + WARN_ON(phy_power_off(pp->comphy)); 112 + WARN_ON(mvneta_config_interface(pp, state->interface)); 113 + } 114 115 if (new_ctrl0 != gmac_ctrl0) 116 mvreg_write(pp, MVNETA_GMAC_CTRL_0, new_ctrl0); 117 @@ -3510,9 +4033,10 @@ static void mvneta_set_eee(struct mvneta 118 mvreg_write(pp, MVNETA_LPI_CTRL_1, lpi_ctl1); 119 } 120