* [PATCH net-next] net: dsa: mt7530: Add support for EEE features
@ 2021-04-09 22:53 René van Dorst
2021-04-10 5:25 ` DENG Qingfang
0 siblings, 1 reply; 3+ messages in thread
From: René van Dorst @ 2021-04-09 22:53 UTC (permalink / raw)
To: David S. Miller, Andrew Lunn, Florian Fainelli, Heiner Kallweit,
Jakub Kicinski, Landen Chao, Matthias Brugger, Russell King,
Sean Wang, Vivien Didelot, Vladimir Oltean, linux-mediatek,
netdev
Cc: Sergio Paracuellos, Frank Wunderlich, DENG Qingfang,
René van Dorst
This patch adds EEE support.
Signed-off-by: René van Dorst <opensource@vdorst.com>
---
drivers/net/dsa/mt7530.c | 50 ++++++++++++++++++++++++++++++++++++++++
drivers/net/dsa/mt7530.h | 16 ++++++++++++-
2 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index 2bd1bab71497..daa87b0baa65 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -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[] = {
diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h
index ec36ea5dfd57..02f983df26bc 100644
--- a/drivers/net/dsa/mt7530.h
+++ b/drivers/net/dsa/mt7530.h
@@ -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*/
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: dsa: mt7530: Add support for EEE features
2021-04-09 22:53 [PATCH net-next] net: dsa: mt7530: Add support for EEE features René van Dorst
@ 2021-04-10 5:25 ` DENG Qingfang
2021-04-12 6:57 ` René van Dorst
0 siblings, 1 reply; 3+ messages in thread
From: DENG Qingfang @ 2021-04-10 5:25 UTC (permalink / raw)
To: René van Dorst
Cc: David S. Miller, Andrew Lunn, Florian Fainelli, Heiner Kallweit,
Jakub Kicinski, Landen Chao, Matthias Brugger, Russell King,
Sean Wang, Vivien Didelot, Vladimir Oltean,
moderated list:ARM/Mediatek SoC support, netdev,
Sergio Paracuellos, Frank Wunderlich
Hi René,
On Sat, Apr 10, 2021 at 6:54 AM René van Dorst <opensource@vdorst.com> wrote:
> --- a/drivers/net/dsa/mt7530.c
> +++ b/drivers/net/dsa/mt7530.c
> @@ -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.
> }
>
> 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);
eee_enabled and eee_active will be set in phy_ethtool_get_eee, no need
to set them here.
> + }
> +
> + 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;
> +}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: dsa: mt7530: Add support for EEE features
2021-04-10 5:25 ` DENG Qingfang
@ 2021-04-12 6:57 ` René van Dorst
0 siblings, 0 replies; 3+ messages in thread
From: René van Dorst @ 2021-04-12 6:57 UTC (permalink / raw)
To: DENG Qingfang
Cc: David S. Miller, Andrew Lunn, Florian Fainelli, Heiner Kallweit,
Jakub Kicinski, Landen Chao, Matthias Brugger, Russell King,
Sean Wang, Vivien Didelot, Vladimir Oltean,
moderated list:ARM/Mediatek SoC support, netdev,
Sergio Paracuellos, Frank Wunderlich
Quoting DENG Qingfang <dqfext@gmail.com>:
Hi Qingfang,
Thanks for the review.
> Hi René,
>
> On Sat, Apr 10, 2021 at 6:54 AM René van Dorst <opensource@vdorst.com> wrote:
>> --- a/drivers/net/dsa/mt7530.c
>> +++ b/drivers/net/dsa/mt7530.c
>> @@ -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.
>
>> }
>>
>> 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);
>
> eee_enabled and eee_active will be set in phy_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.
>
>> + }
>> +
>> + 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;
>> +}
Greats,
René
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-04-12 6:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-09 22:53 [PATCH net-next] net: dsa: mt7530: Add support for EEE features René van Dorst
2021-04-10 5:25 ` DENG Qingfang
2021-04-12 6:57 ` René van Dorst
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).