net: dsa: mt7530: Add support for EEE features
Subsystems (5)
PATCH 1/1 net: dsa: mt7530: Add support for EEE features
This patch adds EEE support.
--- drivers/net/dsa/mt7530.c | 50 ++++++++++++++++++++++++++++++++++++++++ drivers/net/dsa/mt7530.h | 16 ++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-)
drivers/net/dsa/mt7530.c +50 -0
@@ -2568,6 +2568,11 @@ static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port, mcr |=PMCR_TX_FC_EN ;if (rx_pause) mcr |=PMCR_RX_FC_EN ; + +if (mode ==MLO_AN_PHY && phydev && + !(priv->eee_disabled &BIT (port)) && +phy_init_eee (phydev,0 ) >=0 ) + mcr |=PMCR_FORCE_EEE1G |PMCR_FORCE_EEE100 ; }mt7530_set (priv,MT7530_PMCR_P (port), mcr);
@@ -2800,6 +2805,49 @@ mt753x_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val)return priv->info->phy_write (ds, port, regnum, val); } +static int mt753x_get_mac_eee (struct dsa_switch *ds,int port, +struct ethtool_eee *e) +{ +struct mt7530_priv *priv = ds->priv; +u32 eeecr, pmsr; + + e->eee_enabled = !(priv->eee_disabled &BIT (port)); + +if (e->eee_enabled) { + eeecr =mt7530_read (priv,MT7530_PMEEECR_P (port)); + e->tx_lpi_enabled = !(eeecr &LPI_MODE_EN ); + e->tx_lpi_timer =GET_LPI_THRESH (eeecr); + pmsr =mt7530_read (priv,MT7530_PMSR_P (port)); + e->eee_active = e->eee_enabled && !!(pmsr &PMSR_EEE1G ); + } + +return 0 ; +} + +static int mt753x_set_mac_eee (struct dsa_switch *ds,int port, +struct ethtool_eee *e) +{ +struct mt7530_priv *priv = ds->priv; +u32 eeecr; + +if (e->eee_enabled) { +if (e->tx_lpi_timer >0xFFF ) +return -EINVAL ; + priv->eee_disabled &= ~BIT (port); + eeecr =mt7530_read (priv,MT7530_PMEEECR_P (port)); + eeecr &= ~(LPI_THRESH_MASK |LPI_MODE_EN ); +if (!e->tx_lpi_enabled) +/* Force LPI Mode without a delay */ + eeecr |=LPI_MODE_EN ; + eeecr |=SET_LPI_THRESH (e->tx_lpi_timer); +mt7530_write (priv,MT7530_PMEEECR_P (port), eeecr); + }else { + priv->eee_disabled |=BIT (port); + } + +return 0 ; +} +static const struct dsa_switch_ops mt7530_switch_ops = { .get_tag_protocol = mtk_get_tag_protocol, .setup = mt753x_setup,
@@ -2835,6 +2883,8 @@ static const struct dsa_switch_ops mt7530_switch_ops = { .phylink_mac_an_restart = mt753x_phylink_mac_an_restart, .phylink_mac_link_down = mt753x_phylink_mac_link_down, .phylink_mac_link_up = mt753x_phylink_mac_link_up, + .get_mac_eee = mt753x_get_mac_eee, + .set_mac_eee = mt753x_set_mac_eee, };static const struct mt753x_info mt753x_table[] = {
drivers/net/dsa/mt7530.h +15 -1
@@ -257,6 +257,8 @@ enum mt7530_vlan_port_attr {#define PMCR_RX_EN BIT(13)#define PMCR_BACKOFF_EN BIT(9)#define PMCR_BACKPR_EN BIT(8) +#define PMCR_FORCE_EEE1G BIT(7) +#define PMCR_FORCE_EEE100 BIT(6)#define PMCR_TX_FC_EN BIT(5)#define PMCR_RX_FC_EN BIT(4)#define PMCR_FORCE_SPEED_1000 BIT(3)
@@ -288,7 +290,17 @@ enum mt7530_vlan_port_attr { PMCR_TX_EN | PMCR_RX_EN | \ PMCR_TX_FC_EN | PMCR_RX_FC_EN | \ PMCR_FORCE_SPEED_1000 | \ - PMCR_FORCE_FDX | PMCR_FORCE_LNK) + PMCR_FORCE_FDX | PMCR_FORCE_LNK | \ + PMCR_FORCE_EEE1G | PMCR_FORCE_EEE100) + +#define MT7530_PMEEECR_P (x) (0x3004 + (x) * 0x100) +#define WAKEUP_TIME_1000 (x) (((x) & 0xFF) << 24) +#define WAKEUP_TIME_100 (x) (((x) & 0xFF) << 16) +#define LPI_THRESH_MASK GENMASK(15, 4) +#define LPI_THRESH_SHT 4 +#define SET_LPI_THRESH (x) (((x) << LPI_THRESH_SHT) & LPI_THRESH_MASK) +#define GET_LPI_THRESH (x) (((x) & LPI_THRESH_MASK) >> LPI_THRESH_SHT) +#define LPI_MODE_EN BIT(0)#define MT7530_PMSR_P (x) (0x3008 + (x) * 0x100)#define PMSR_EEE1G BIT(7)
@@ -761,6 +773,7 @@ struct mt753x_info {* registers * @p6_interface Holding the current port 6 interface * @p5_intf_sel: Holding the current port 5 interface select +* @eee_disabled: Holding the current eee user disabled bits */ struct mt7530_priv {struct device *dev;
@@ -778,6 +791,7 @@ struct mt7530_priv {unsigned int p5_intf_sel;u8 mirror_rx;u8 mirror_tx; +u8 eee_disabled;struct mt7530_port ports[MT7530_NUM_PORTS ];/* protect among processes for registers access*/
Signature · 1 line
2.30.2
Hi René,
drivers/net/dsa/mt7530.c static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port, · line 2575
Quoted 11 lines · René van Dorst
drivers/net/dsa/mt7530.c +5
-0@@ -2568,6 +2568,11 @@ static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port, mcr |=PMCR_TX_FC_EN ;if (rx_pause) mcr |=PMCR_RX_FC_EN ; + +if (mode ==MLO_AN_PHY && phydev && + !(priv->eee_disabled &BIT (port)) && +phy_init_eee (phydev,0 ) >=0 ) + mcr |=PMCR_FORCE_EEE1G |PMCR_FORCE_EEE100 ;
You should adjust this according to e->advertised.
Quoted 11 lines
drivers/net/dsa/mt7530.c +4
-0}mt7530_set (priv,MT7530_PMCR_P (port), mcr);@@ -2800,6 +2805,49 @@ mt753x_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val)return priv->info->phy_write (ds, port, regnum, val); } +static int mt753x_get_mac_eee (struct dsa_switch *ds,int port, +struct ethtool_eee *e) +{ +struct mt7530_priv *priv = ds->priv;
drivers/net/dsa/mt7530.c mt753x_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val) · line 2821
Quoted 10 lines
drivers/net/dsa/mt7530.c +10
-0+u32 eeecr, pmsr; + + e->eee_enabled = !(priv->eee_disabled &BIT (port)); + +if (e->eee_enabled) { + eeecr =mt7530_read (priv,MT7530_PMEEECR_P (port)); + e->tx_lpi_enabled = !(eeecr &LPI_MODE_EN ); + e->tx_lpi_timer =GET_LPI_THRESH (eeecr); + pmsr =mt7530_read (priv,MT7530_PMSR_P (port)); + e->eee_active = e->eee_enabled && !!(pmsr &PMSR_EEE1G );
eee_enabled and eee_active will be set in phy_ethtool_get_eee, no need to set them here.
Quoted 28 lines
drivers/net/dsa/mt7530.c +28
-0+ } + +return 0 ; +} + +static int mt753x_set_mac_eee (struct dsa_switch *ds,int port, +struct ethtool_eee *e) +{ +struct mt7530_priv *priv = ds->priv; +u32 eeecr; + +if (e->eee_enabled) { +if (e->tx_lpi_timer >0xFFF ) +return -EINVAL ; + priv->eee_disabled &= ~BIT (port); + eeecr =mt7530_read (priv,MT7530_PMEEECR_P (port)); + eeecr &= ~(LPI_THRESH_MASK |LPI_MODE_EN ); +if (!e->tx_lpi_enabled) +/* Force LPI Mode without a delay */ + eeecr |=LPI_MODE_EN ; + eeecr |=SET_LPI_THRESH (e->tx_lpi_timer); +mt7530_write (priv,MT7530_PMEEECR_P (port), eeecr); + }else { + priv->eee_disabled |=BIT (port); + } + +return 0 ; +}
Quoting DENG Qingfang <[email protected]>:
Hi Qingfang,
Thanks for the review.
Quoted 17 lines
Hi René,
drivers/net/dsa/mt7530.c static void · line 2576
Quoted 12 lines · René van Dorst
drivers/net/dsa/mt7530.c +5
-0@@ -2568,6 +2568,11 @@ static void mt753x_phylink_mac_link_up(struct dsa_switch *ds, int port, mcr |= PMCR_TX_FC_EN;if (rx_pause) mcr |=PMCR_RX_FC_EN ; + +if (mode ==MLO_AN_PHY && phydev && + !(priv->eee_disabled &BIT (port)) && +phy_init_eee (phydev,0 ) >=0 ) + mcr |=PMCR_FORCE_EEE1G |PMCR_FORCE_EEE100 ;You should adjust this according to
e->advertised.
I now better understand EEE part in phylink.
I refactor the code a lot and also tested with different port with various eee-broken-1000t and eee-broken-100tx set in the device tree.
Looking at mcr value, in all the cases the bit are set right.
Quoted 18 lines
Quoted 18 lines
drivers/net/dsa/mt7530.c +0
-0}mt7530_set(priv, MT7530_PMCR_P(port), mcr);drivers/net/dsa/mt7530.c +9
-0@@ -2800,6 +2805,49 @@ mt753x_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val)return priv->info->phy_write (ds, port, regnum, val); } +static int mt753x_get_mac_eee (struct dsa_switch *ds,int port, +struct ethtool_eee *e) +{ +struct mt7530_priv *priv = ds->priv; +u32 eeecr, pmsr; + + e->eee_enabled = !(priv->eee_disabled &BIT (port)); + +if (e->eee_enabled) {
Quoted 8 lines
drivers/net/dsa/mt7530.c mt753x_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val) · line 2821
Quoted 5 lines
drivers/net/dsa/mt7530.c +5
-0+ eeecr =mt7530_read (priv,MT7530_PMEEECR_P (port)); + e->tx_lpi_enabled = !(eeecr &LPI_MODE_EN ); + e->tx_lpi_timer =GET_LPI_THRESH (eeecr); + pmsr =mt7530_read (priv,MT7530_PMSR_P (port)); + e->eee_active = e->eee_enabled && !!(pmsr &PMSR_EEE1G );
eee_enabledandeee_activewill be set inphy_ethtool_get_eee, no need to set them here.
Thanks for pointing that out.
I refactor the code so it only set/report the LPI settings.
I already sended v2 with these changes.
Quoted 21 lines
Quoted 21 lines
drivers/net/dsa/mt7530.c +20
-0+ } + +return 0 ; +} + +static int mt753x_set_mac_eee (struct dsa_switch *ds,int port, +struct ethtool_eee *e) +{ +struct mt7530_priv *priv = ds->priv; +u32 eeecr; + +if (e->eee_enabled) { +if (e->tx_lpi_timer >0xFFF ) +return -EINVAL ; + priv->eee_disabled &= ~BIT (port); + eeecr =mt7530_read (priv,MT7530_PMEEECR_P (port)); + eeecr &= ~(LPI_THRESH_MASK |LPI_MODE_EN ); +if (!e->tx_lpi_enabled) +/* Force LPI Mode without a delay */ + eeecr |=LPI_MODE_EN ;
Quoted 8 lines
drivers/net/dsa/mt7530.c mt753x_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val) · line 2849
Quoted 8 lines
drivers/net/dsa/mt7530.c +8
-0+ eeecr |=SET_LPI_THRESH (e->tx_lpi_timer); +mt7530_write (priv,MT7530_PMEEECR_P (port), eeecr); + }else { + priv->eee_disabled |=BIT (port); + } + +return 0 ; +}
Greats,
René