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 strscpy(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
,
137 struct kernel_ethtool_ringparam
*kernel_ring
,
138 struct netlink_ext_ack
*extack
)
140 struct emac_adapter
*adpt
= netdev_priv(netdev
);
142 ring
->rx_max_pending
= EMAC_MAX_RX_DESCS
;
143 ring
->tx_max_pending
= EMAC_MAX_TX_DESCS
;
144 ring
->rx_pending
= adpt
->rx_desc_cnt
;
145 ring
->tx_pending
= adpt
->tx_desc_cnt
;
148 static int emac_set_ringparam(struct net_device
*netdev
,
149 struct ethtool_ringparam
*ring
,
150 struct kernel_ethtool_ringparam
*kernel_ring
,
151 struct netlink_ext_ack
*extack
)
153 struct emac_adapter
*adpt
= netdev_priv(netdev
);
155 /* We don't have separate queues/rings for small/large frames, so
156 * reject any attempt to specify those values separately.
158 if (ring
->rx_mini_pending
|| ring
->rx_jumbo_pending
)
162 clamp_val(ring
->tx_pending
, EMAC_MIN_TX_DESCS
, EMAC_MAX_TX_DESCS
);
165 clamp_val(ring
->rx_pending
, EMAC_MIN_RX_DESCS
, EMAC_MAX_RX_DESCS
);
167 if (netif_running(netdev
))
168 return emac_reinit_locked(adpt
);
173 static void emac_get_pauseparam(struct net_device
*netdev
,
174 struct ethtool_pauseparam
*pause
)
176 struct emac_adapter
*adpt
= netdev_priv(netdev
);
178 pause
->autoneg
= adpt
->automatic
? AUTONEG_ENABLE
: AUTONEG_DISABLE
;
179 pause
->rx_pause
= adpt
->rx_flow_control
? 1 : 0;
180 pause
->tx_pause
= adpt
->tx_flow_control
? 1 : 0;
183 static int emac_set_pauseparam(struct net_device
*netdev
,
184 struct ethtool_pauseparam
*pause
)
186 struct emac_adapter
*adpt
= netdev_priv(netdev
);
188 adpt
->automatic
= pause
->autoneg
== AUTONEG_ENABLE
;
189 adpt
->rx_flow_control
= pause
->rx_pause
!= 0;
190 adpt
->tx_flow_control
= pause
->tx_pause
!= 0;
192 if (netif_running(netdev
))
193 return emac_reinit_locked(adpt
);
198 /* Selected registers that might want to track during runtime. */
199 static const u16 emac_regs
[] = {
207 EMAC_CORE_HW_VERSION
,
211 /* Every time emac_regs[] above is changed, increase this version number. */
212 #define EMAC_REGS_VERSION 0
214 #define EMAC_MAX_REG_SIZE ARRAY_SIZE(emac_regs)
216 static void emac_get_regs(struct net_device
*netdev
,
217 struct ethtool_regs
*regs
, void *buff
)
219 struct emac_adapter
*adpt
= netdev_priv(netdev
);
223 regs
->version
= EMAC_REGS_VERSION
;
224 regs
->len
= EMAC_MAX_REG_SIZE
* sizeof(u32
);
226 for (i
= 0; i
< EMAC_MAX_REG_SIZE
; i
++)
227 val
[i
] = readl(adpt
->base
+ emac_regs
[i
]);
230 static int emac_get_regs_len(struct net_device
*netdev
)
232 return EMAC_MAX_REG_SIZE
* sizeof(u32
);
235 #define EMAC_PRIV_ENABLE_SINGLE_PAUSE BIT(0)
237 static int emac_set_priv_flags(struct net_device
*netdev
, u32 flags
)
239 struct emac_adapter
*adpt
= netdev_priv(netdev
);
241 adpt
->single_pause_mode
= !!(flags
& EMAC_PRIV_ENABLE_SINGLE_PAUSE
);
243 if (netif_running(netdev
))
244 return emac_reinit_locked(adpt
);
249 static u32
emac_get_priv_flags(struct net_device
*netdev
)
251 struct emac_adapter
*adpt
= netdev_priv(netdev
);
253 return adpt
->single_pause_mode
? EMAC_PRIV_ENABLE_SINGLE_PAUSE
: 0;
256 static const struct ethtool_ops emac_ethtool_ops
= {
257 .get_link_ksettings
= phy_ethtool_get_link_ksettings
,
258 .set_link_ksettings
= phy_ethtool_set_link_ksettings
,
260 .get_msglevel
= emac_get_msglevel
,
261 .set_msglevel
= emac_set_msglevel
,
263 .get_sset_count
= emac_get_sset_count
,
264 .get_strings
= emac_get_strings
,
265 .get_ethtool_stats
= emac_get_ethtool_stats
,
267 .get_ringparam
= emac_get_ringparam
,
268 .set_ringparam
= emac_set_ringparam
,
270 .get_pauseparam
= emac_get_pauseparam
,
271 .set_pauseparam
= emac_set_pauseparam
,
273 .nway_reset
= emac_nway_reset
,
275 .get_link
= ethtool_op_get_link
,
277 .get_regs_len
= emac_get_regs_len
,
278 .get_regs
= emac_get_regs
,
280 .set_priv_flags
= emac_set_priv_flags
,
281 .get_priv_flags
= emac_get_priv_flags
,
284 void emac_set_ethtool_ops(struct net_device
*netdev
)
286 netdev
->ethtool_ops
= &emac_ethtool_ops
;