1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2016, The Linux Foundation. All rights reserved.
5 #include <linux/ethtool.h>
10 static const char * const emac_ethtool_stat_strings
[] = {
64 #define EMAC_STATS_LEN ARRAY_SIZE(emac_ethtool_stat_strings)
66 static u32
emac_get_msglevel(struct net_device
*netdev
)
68 struct emac_adapter
*adpt
= netdev_priv(netdev
);
70 return adpt
->msg_enable
;
73 static void emac_set_msglevel(struct net_device
*netdev
, u32 data
)
75 struct emac_adapter
*adpt
= netdev_priv(netdev
);
77 adpt
->msg_enable
= data
;
80 static int emac_get_sset_count(struct net_device
*netdev
, int sset
)
83 case ETH_SS_PRIV_FLAGS
:
86 return EMAC_STATS_LEN
;
92 static void emac_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*data
)
97 case ETH_SS_PRIV_FLAGS
:
98 strcpy(data
, "single-pause-mode");
102 for (i
= 0; i
< EMAC_STATS_LEN
; i
++) {
103 strlcpy(data
, emac_ethtool_stat_strings
[i
],
105 data
+= ETH_GSTRING_LEN
;
111 static void emac_get_ethtool_stats(struct net_device
*netdev
,
112 struct ethtool_stats
*stats
,
115 struct emac_adapter
*adpt
= netdev_priv(netdev
);
117 spin_lock(&adpt
->stats
.lock
);
119 emac_update_hw_stats(adpt
);
120 memcpy(data
, &adpt
->stats
, EMAC_STATS_LEN
* sizeof(u64
));
122 spin_unlock(&adpt
->stats
.lock
);
125 static int emac_nway_reset(struct net_device
*netdev
)
127 struct phy_device
*phydev
= netdev
->phydev
;
132 return genphy_restart_aneg(phydev
);
135 static void emac_get_ringparam(struct net_device
*netdev
,
136 struct ethtool_ringparam
*ring
)
138 struct emac_adapter
*adpt
= netdev_priv(netdev
);
140 ring
->rx_max_pending
= EMAC_MAX_RX_DESCS
;
141 ring
->tx_max_pending
= EMAC_MAX_TX_DESCS
;
142 ring
->rx_pending
= adpt
->rx_desc_cnt
;
143 ring
->tx_pending
= adpt
->tx_desc_cnt
;
146 static int emac_set_ringparam(struct net_device
*netdev
,
147 struct ethtool_ringparam
*ring
)
149 struct emac_adapter
*adpt
= netdev_priv(netdev
);
151 /* We don't have separate queues/rings for small/large frames, so
152 * reject any attempt to specify those values separately.
154 if (ring
->rx_mini_pending
|| ring
->rx_jumbo_pending
)
158 clamp_val(ring
->tx_pending
, EMAC_MIN_TX_DESCS
, EMAC_MAX_TX_DESCS
);
161 clamp_val(ring
->rx_pending
, EMAC_MIN_RX_DESCS
, EMAC_MAX_RX_DESCS
);
163 if (netif_running(netdev
))
164 return emac_reinit_locked(adpt
);
169 static void emac_get_pauseparam(struct net_device
*netdev
,
170 struct ethtool_pauseparam
*pause
)
172 struct emac_adapter
*adpt
= netdev_priv(netdev
);
174 pause
->autoneg
= adpt
->automatic
? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
175 pause
->rx_pause
= adpt
->rx_flow_control
? 1 : 0;
176 pause
->tx_pause
= adpt
->tx_flow_control
? 1 : 0;
179 static int emac_set_pauseparam(struct net_device
*netdev
,
180 struct ethtool_pauseparam
*pause
)
182 struct emac_adapter
*adpt
= netdev_priv(netdev
);
184 adpt
->automatic
= pause
->autoneg
== AUTONEG_ENABLE
;
185 adpt
->rx_flow_control
= pause
->rx_pause
!= 0;
186 adpt
->tx_flow_control
= pause
->tx_pause
!= 0;
188 if (netif_running(netdev
))
189 return emac_reinit_locked(adpt
);
194 /* Selected registers that might want to track during runtime. */
195 static const u16 emac_regs
[] = {
203 EMAC_CORE_HW_VERSION
,
207 /* Every time emac_regs[] above is changed, increase this version number. */
208 #define EMAC_REGS_VERSION 0
210 #define EMAC_MAX_REG_SIZE ARRAY_SIZE(emac_regs)
212 static void emac_get_regs(struct net_device
*netdev
,
213 struct ethtool_regs
*regs
, void *buff
)
215 struct emac_adapter
*adpt
= netdev_priv(netdev
);
219 regs
->version
= EMAC_REGS_VERSION
;
220 regs
->len
= EMAC_MAX_REG_SIZE
* sizeof(u32
);
222 for (i
= 0; i
< EMAC_MAX_REG_SIZE
; i
++)
223 val
[i
] = readl(adpt
->base
+ emac_regs
[i
]);
226 static int emac_get_regs_len(struct net_device
*netdev
)
228 return EMAC_MAX_REG_SIZE
* sizeof(u32
);
231 #define EMAC_PRIV_ENABLE_SINGLE_PAUSE BIT(0)
233 static int emac_set_priv_flags(struct net_device
*netdev
, u32 flags
)
235 struct emac_adapter
*adpt
= netdev_priv(netdev
);
237 adpt
->single_pause_mode
= !!(flags
& EMAC_PRIV_ENABLE_SINGLE_PAUSE
);
239 if (netif_running(netdev
))
240 return emac_reinit_locked(adpt
);
245 static u32
emac_get_priv_flags(struct net_device
*netdev
)
247 struct emac_adapter
*adpt
= netdev_priv(netdev
);
249 return adpt
->single_pause_mode
? EMAC_PRIV_ENABLE_SINGLE_PAUSE
: 0;
252 static const struct ethtool_ops emac_ethtool_ops
= {
253 .get_link_ksettings
= phy_ethtool_get_link_ksettings
,
254 .set_link_ksettings
= phy_ethtool_set_link_ksettings
,
256 .get_msglevel
= emac_get_msglevel
,
257 .set_msglevel
= emac_set_msglevel
,
259 .get_sset_count
= emac_get_sset_count
,
260 .get_strings
= emac_get_strings
,
261 .get_ethtool_stats
= emac_get_ethtool_stats
,
263 .get_ringparam
= emac_get_ringparam
,
264 .set_ringparam
= emac_set_ringparam
,
266 .get_pauseparam
= emac_get_pauseparam
,
267 .set_pauseparam
= emac_set_pauseparam
,
269 .nway_reset
= emac_nway_reset
,
271 .get_link
= ethtool_op_get_link
,
273 .get_regs_len
= emac_get_regs_len
,
274 .get_regs
= emac_get_regs
,
276 .set_priv_flags
= emac_set_priv_flags
,
277 .get_priv_flags
= emac_get_priv_flags
,
280 void emac_set_ethtool_ops(struct net_device
*netdev
)
282 netdev
->ethtool_ops
= &emac_ethtool_ops
;