1 From: Russell King <rmk+kernel@arm.linux.org.uk>
2 Date: Tue, 29 Sep 2015 15:17:39 +0100
3 Subject: [PATCH] net: mvneta: add EEE support
5 Add EEE support to mvneta. This allows us to enable the low power idle
6 support at MAC level if there is a PHY attached through phylink which
7 supports LPI. The appropriate ethtool support is provided to allow the
8 feature to be controlled, including ethtool statistics for EEE wakeup
11 Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
14 --- a/drivers/net/ethernet/marvell/mvneta.c
15 +++ b/drivers/net/ethernet/marvell/mvneta.c
17 #define MVNETA_TXQ_TOKEN_SIZE_REG(q) (0x3e40 + ((q) << 2))
18 #define MVNETA_TXQ_TOKEN_SIZE_MAX 0x7fffffff
20 +#define MVNETA_LPI_CTRL_0 0x2cc0
21 +#define MVNETA_LPI_CTRL_1 0x2cc4
22 +#define MVNETA_LPI_REQUEST_ENABLE BIT(0)
23 +#define MVNETA_LPI_CTRL_2 0x2cc8
24 +#define MVNETA_LPI_STATUS 0x2ccc
26 #define MVNETA_CAUSE_TXQ_SENT_DESC_ALL_MASK 0xff
28 /* Descriptor ring Macros */
30 #define MVNETA_RX_GET_BM_POOL_ID(rxd) \
31 (((rxd)->status & MVNETA_RXD_BM_POOL_MASK) >> MVNETA_RXD_BM_POOL_SHIFT)
34 + ETHTOOL_STAT_EEE_WAKEUP,
38 struct mvneta_statistic {
39 unsigned short offset;
41 @@ -325,6 +336,7 @@ struct mvneta_statistic {
47 static const struct mvneta_statistic mvneta_statistics[] = {
48 { 0x3000, T_REG_64, "good_octets_received", },
49 @@ -359,6 +371,7 @@ static const struct mvneta_statistic mvn
50 { 0x304c, T_REG_32, "broadcast_frames_sent", },
51 { 0x3054, T_REG_32, "fc_sent", },
52 { 0x300c, T_REG_32, "internal_mac_transmit_err", },
53 + { ETHTOOL_STAT_EEE_WAKEUP, T_SW, "eee_wakeup_errors", },
56 struct mvneta_pcpu_stats {
57 @@ -417,6 +430,10 @@ struct mvneta_port {
58 struct mvneta_bm_pool *pool_short;
63 + bool tx_lpi_enabled;
65 u64 ethtool_stats[ARRAY_SIZE(mvneta_statistics)];
67 u32 indir[MVNETA_RSS_LU_TABLE_SIZE];
68 @@ -3290,6 +3307,18 @@ static void mvneta_mac_config(struct net
69 mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, new_an);
72 +static void mvneta_set_eee(struct mvneta_port *pp, bool enable)
76 + lpi_ctl1 = mvreg_read(pp, MVNETA_LPI_CTRL_1);
78 + lpi_ctl1 |= MVNETA_LPI_REQUEST_ENABLE;
80 + lpi_ctl1 &= ~MVNETA_LPI_REQUEST_ENABLE;
81 + mvreg_write(pp, MVNETA_LPI_CTRL_1, lpi_ctl1);
84 static void mvneta_mac_link_down(struct net_device *ndev, unsigned int mode)
86 struct mvneta_port *pp = netdev_priv(ndev);
87 @@ -3303,6 +3332,9 @@ static void mvneta_mac_link_down(struct
88 val |= MVNETA_GMAC_FORCE_LINK_DOWN;
89 mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
92 + pp->eee_active = false;
93 + mvneta_set_eee(pp, false);
96 static void mvneta_mac_link_up(struct net_device *ndev, unsigned int mode,
97 @@ -3319,6 +3351,11 @@ static void mvneta_mac_link_up(struct ne
102 + if (phy && pp->eee_enabled) {
103 + pp->eee_active = phy_init_eee(phy, 0) >= 0;
104 + mvneta_set_eee(pp, pp->eee_active && pp->tx_lpi_enabled);
108 static const struct phylink_mac_ops mvneta_phylink_ops = {
109 @@ -3771,6 +3808,13 @@ static void mvneta_ethtool_update_stats(
110 high = readl_relaxed(base + s->offset + 4);
111 val = (u64)high << 32 | low;
114 + switch (s->offset) {
115 + case ETHTOOL_STAT_EEE_WAKEUP:
116 + val = phylink_get_eee_err(pp->phylink);
122 pp->ethtool_stats[i] += val;
123 @@ -3906,6 +3950,47 @@ static u16 mvneta_select_queue(struct ne
127 +static int mvneta_ethtool_get_eee(struct net_device *dev,
128 + struct ethtool_eee *eee)
130 + struct mvneta_port *pp = netdev_priv(dev);
133 + lpi_ctl0 = mvreg_read(pp, MVNETA_LPI_CTRL_0);
135 + eee->eee_enabled = pp->eee_enabled;
136 + eee->eee_active = pp->eee_active;
137 + eee->tx_lpi_enabled = pp->tx_lpi_enabled;
138 + eee->tx_lpi_timer = (lpi_ctl0) >> 8; // * scale;
140 + return phylink_ethtool_get_eee(pp->phylink, eee);
143 +static int mvneta_ethtool_set_eee(struct net_device *dev,
144 + struct ethtool_eee *eee)
146 + struct mvneta_port *pp = netdev_priv(dev);
149 + /* The Armada 37x documents do not give limits for this other than
150 + * it being an 8-bit register. */
151 + if (eee->tx_lpi_enabled &&
152 + (eee->tx_lpi_timer < 0 || eee->tx_lpi_timer > 255))
155 + lpi_ctl0 = mvreg_read(pp, MVNETA_LPI_CTRL_0);
156 + lpi_ctl0 &= ~(0xff << 8);
157 + lpi_ctl0 |= eee->tx_lpi_timer << 8;
158 + mvreg_write(pp, MVNETA_LPI_CTRL_0, lpi_ctl0);
160 + pp->eee_enabled = eee->eee_enabled;
161 + pp->tx_lpi_enabled = eee->tx_lpi_enabled;
163 + mvneta_set_eee(pp, eee->tx_lpi_enabled && eee->eee_enabled);
165 + return phylink_ethtool_set_eee(pp->phylink, eee);
168 static const struct net_device_ops mvneta_netdev_ops = {
169 .ndo_open = mvneta_open,
170 .ndo_stop = mvneta_stop,
171 @@ -3938,6 +4023,8 @@ const struct ethtool_ops mvneta_eth_tool
172 .set_rxfh = mvneta_ethtool_set_rxfh,
173 .get_link_ksettings = mvneta_ethtool_get_link_ksettings,
174 .set_link_ksettings = mvneta_ethtool_set_link_ksettings,
175 + .get_eee = mvneta_ethtool_get_eee,
176 + .set_eee = mvneta_ethtool_set_eee,