Skip to content

Commit 952d732

Browse files
LGA1150kuba-moo
authored andcommitted
net: ethernet: mediatek: add EEE support
Add EEE support to MediaTek SoC Ethernet. The register fields are similar to the ones in MT7531, except that the LPI threshold is in milliseconds. Signed-off-by: Qingfang Deng <[email protected]> Reviewed-by: Russell King (Oracle) <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 9faaaef commit 952d732

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,12 +815,60 @@ static void mtk_mac_link_up(struct phylink_config *config,
815815
mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
816816
}
817817

818+
static void mtk_mac_disable_tx_lpi(struct phylink_config *config)
819+
{
820+
struct mtk_mac *mac = container_of(config, struct mtk_mac,
821+
phylink_config);
822+
struct mtk_eth *eth = mac->hw;
823+
824+
mtk_m32(eth, MAC_MCR_EEE100M | MAC_MCR_EEE1G, 0, MTK_MAC_MCR(mac->id));
825+
}
826+
827+
static int mtk_mac_enable_tx_lpi(struct phylink_config *config, u32 timer,
828+
bool tx_clk_stop)
829+
{
830+
struct mtk_mac *mac = container_of(config, struct mtk_mac,
831+
phylink_config);
832+
struct mtk_eth *eth = mac->hw;
833+
u32 val;
834+
835+
/* Tx idle timer in ms */
836+
timer = DIV_ROUND_UP(timer, 1000);
837+
838+
/* If the timer is zero, then set LPI_MODE, which allows the
839+
* system to enter LPI mode immediately rather than waiting for
840+
* the LPI threshold.
841+
*/
842+
if (!timer)
843+
val = MAC_EEE_LPI_MODE;
844+
else if (FIELD_FIT(MAC_EEE_LPI_TXIDLE_THD, timer))
845+
val = FIELD_PREP(MAC_EEE_LPI_TXIDLE_THD, timer);
846+
else
847+
val = MAC_EEE_LPI_TXIDLE_THD;
848+
849+
if (tx_clk_stop)
850+
val |= MAC_EEE_CKG_TXIDLE;
851+
852+
/* PHY Wake-up time, this field does not have a reset value, so use the
853+
* reset value from MT7531 (36us for 100M and 17us for 1000M).
854+
*/
855+
val |= FIELD_PREP(MAC_EEE_WAKEUP_TIME_1000, 17) |
856+
FIELD_PREP(MAC_EEE_WAKEUP_TIME_100, 36);
857+
858+
mtk_w32(eth, val, MTK_MAC_EEECR(mac->id));
859+
mtk_m32(eth, 0, MAC_MCR_EEE100M | MAC_MCR_EEE1G, MTK_MAC_MCR(mac->id));
860+
861+
return 0;
862+
}
863+
818864
static const struct phylink_mac_ops mtk_phylink_ops = {
819865
.mac_select_pcs = mtk_mac_select_pcs,
820866
.mac_config = mtk_mac_config,
821867
.mac_finish = mtk_mac_finish,
822868
.mac_link_down = mtk_mac_link_down,
823869
.mac_link_up = mtk_mac_link_up,
870+
.mac_disable_tx_lpi = mtk_mac_disable_tx_lpi,
871+
.mac_enable_tx_lpi = mtk_mac_enable_tx_lpi,
824872
};
825873

826874
static int mtk_mdio_init(struct mtk_eth *eth)
@@ -4469,6 +4517,20 @@ static int mtk_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam
44694517
return phylink_ethtool_set_pauseparam(mac->phylink, pause);
44704518
}
44714519

4520+
static int mtk_get_eee(struct net_device *dev, struct ethtool_keee *eee)
4521+
{
4522+
struct mtk_mac *mac = netdev_priv(dev);
4523+
4524+
return phylink_ethtool_get_eee(mac->phylink, eee);
4525+
}
4526+
4527+
static int mtk_set_eee(struct net_device *dev, struct ethtool_keee *eee)
4528+
{
4529+
struct mtk_mac *mac = netdev_priv(dev);
4530+
4531+
return phylink_ethtool_set_eee(mac->phylink, eee);
4532+
}
4533+
44724534
static u16 mtk_select_queue(struct net_device *dev, struct sk_buff *skb,
44734535
struct net_device *sb_dev)
44744536
{
@@ -4501,6 +4563,8 @@ static const struct ethtool_ops mtk_ethtool_ops = {
45014563
.set_pauseparam = mtk_set_pauseparam,
45024564
.get_rxnfc = mtk_get_rxnfc,
45034565
.set_rxnfc = mtk_set_rxnfc,
4566+
.get_eee = mtk_get_eee,
4567+
.set_eee = mtk_set_eee,
45044568
};
45054569

45064570
static const struct net_device_ops mtk_netdev_ops = {
@@ -4610,6 +4674,9 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
46104674
mac->phylink_config.type = PHYLINK_NETDEV;
46114675
mac->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
46124676
MAC_10 | MAC_100 | MAC_1000 | MAC_2500FD;
4677+
mac->phylink_config.lpi_capabilities = MAC_100FD | MAC_1000FD |
4678+
MAC_2500FD;
4679+
mac->phylink_config.lpi_timer_default = 1000;
46134680

46144681
/* MT7623 gmac0 is now missing its speed-specific PLL configuration
46154682
* in its .mac_config method (since state->speed is not valid there.

drivers/net/ethernet/mediatek/mtk_eth_soc.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,8 @@
453453
#define MAC_MCR_RX_FIFO_CLR_DIS BIT(12)
454454
#define MAC_MCR_BACKOFF_EN BIT(9)
455455
#define MAC_MCR_BACKPR_EN BIT(8)
456+
#define MAC_MCR_EEE1G BIT(7)
457+
#define MAC_MCR_EEE100M BIT(6)
456458
#define MAC_MCR_FORCE_RX_FC BIT(5)
457459
#define MAC_MCR_FORCE_TX_FC BIT(4)
458460
#define MAC_MCR_SPEED_1000 BIT(3)
@@ -461,6 +463,15 @@
461463
#define MAC_MCR_FORCE_LINK BIT(0)
462464
#define MAC_MCR_FORCE_LINK_DOWN (MAC_MCR_FORCE_MODE)
463465

466+
/* Mac EEE control registers */
467+
#define MTK_MAC_EEECR(x) (0x10104 + (x * 0x100))
468+
#define MAC_EEE_WAKEUP_TIME_1000 GENMASK(31, 24)
469+
#define MAC_EEE_WAKEUP_TIME_100 GENMASK(23, 16)
470+
#define MAC_EEE_LPI_TXIDLE_THD GENMASK(15, 8)
471+
#define MAC_EEE_CKG_TXIDLE BIT(3)
472+
#define MAC_EEE_CKG_RXLPI BIT(2)
473+
#define MAC_EEE_LPI_MODE BIT(0)
474+
464475
/* Mac status registers */
465476
#define MTK_MAC_MSR(x) (0x10108 + (x * 0x100))
466477
#define MAC_MSR_EEE1G BIT(7)

0 commit comments

Comments
 (0)