staging: rtl8188eu: Replace function name in string with __func__
[linux/fpc-iii.git] / drivers / net / ethernet / qualcomm / emac / emac-ethtool.c
blobc8c6231b87f3305ae570d6c5277d91415ff696e8
1 /* Copyright (c) 2016, The Linux Foundation. All rights reserved.
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
13 #include <linux/ethtool.h>
14 #include <linux/phy.h>
16 #include "emac.h"
18 static const char * const emac_ethtool_stat_strings[] = {
19 "rx_ok",
20 "rx_bcast",
21 "rx_mcast",
22 "rx_pause",
23 "rx_ctrl",
24 "rx_fcs_err",
25 "rx_len_err",
26 "rx_byte_cnt",
27 "rx_runt",
28 "rx_frag",
29 "rx_sz_64",
30 "rx_sz_65_127",
31 "rx_sz_128_255",
32 "rx_sz_256_511",
33 "rx_sz_512_1023",
34 "rx_sz_1024_1518",
35 "rx_sz_1519_max",
36 "rx_sz_ov",
37 "rx_rxf_ov",
38 "rx_align_err",
39 "rx_bcast_byte_cnt",
40 "rx_mcast_byte_cnt",
41 "rx_err_addr",
42 "rx_crc_align",
43 "rx_jabbers",
44 "tx_ok",
45 "tx_bcast",
46 "tx_mcast",
47 "tx_pause",
48 "tx_exc_defer",
49 "tx_ctrl",
50 "tx_defer",
51 "tx_byte_cnt",
52 "tx_sz_64",
53 "tx_sz_65_127",
54 "tx_sz_128_255",
55 "tx_sz_256_511",
56 "tx_sz_512_1023",
57 "tx_sz_1024_1518",
58 "tx_sz_1519_max",
59 "tx_1_col",
60 "tx_2_col",
61 "tx_late_col",
62 "tx_abort_col",
63 "tx_underrun",
64 "tx_rd_eop",
65 "tx_len_err",
66 "tx_trunc",
67 "tx_bcast_byte",
68 "tx_mcast_byte",
69 "tx_col",
72 #define EMAC_STATS_LEN ARRAY_SIZE(emac_ethtool_stat_strings)
74 static u32 emac_get_msglevel(struct net_device *netdev)
76 struct emac_adapter *adpt = netdev_priv(netdev);
78 return adpt->msg_enable;
81 static void emac_set_msglevel(struct net_device *netdev, u32 data)
83 struct emac_adapter *adpt = netdev_priv(netdev);
85 adpt->msg_enable = data;
88 static int emac_get_sset_count(struct net_device *netdev, int sset)
90 switch (sset) {
91 case ETH_SS_PRIV_FLAGS:
92 return 1;
93 case ETH_SS_STATS:
94 return EMAC_STATS_LEN;
95 default:
96 return -EOPNOTSUPP;
100 static void emac_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
102 unsigned int i;
104 switch (stringset) {
105 case ETH_SS_PRIV_FLAGS:
106 strcpy(data, "single-pause-mode");
107 break;
109 case ETH_SS_STATS:
110 for (i = 0; i < EMAC_STATS_LEN; i++) {
111 strlcpy(data, emac_ethtool_stat_strings[i],
112 ETH_GSTRING_LEN);
113 data += ETH_GSTRING_LEN;
115 break;
119 static void emac_get_ethtool_stats(struct net_device *netdev,
120 struct ethtool_stats *stats,
121 u64 *data)
123 struct emac_adapter *adpt = netdev_priv(netdev);
125 spin_lock(&adpt->stats.lock);
127 emac_update_hw_stats(adpt);
128 memcpy(data, &adpt->stats, EMAC_STATS_LEN * sizeof(u64));
130 spin_unlock(&adpt->stats.lock);
133 static int emac_nway_reset(struct net_device *netdev)
135 struct phy_device *phydev = netdev->phydev;
137 if (!phydev)
138 return -ENODEV;
140 return genphy_restart_aneg(phydev);
143 static void emac_get_ringparam(struct net_device *netdev,
144 struct ethtool_ringparam *ring)
146 struct emac_adapter *adpt = netdev_priv(netdev);
148 ring->rx_max_pending = EMAC_MAX_RX_DESCS;
149 ring->tx_max_pending = EMAC_MAX_TX_DESCS;
150 ring->rx_pending = adpt->rx_desc_cnt;
151 ring->tx_pending = adpt->tx_desc_cnt;
154 static int emac_set_ringparam(struct net_device *netdev,
155 struct ethtool_ringparam *ring)
157 struct emac_adapter *adpt = netdev_priv(netdev);
159 /* We don't have separate queues/rings for small/large frames, so
160 * reject any attempt to specify those values separately.
162 if (ring->rx_mini_pending || ring->rx_jumbo_pending)
163 return -EINVAL;
165 adpt->tx_desc_cnt =
166 clamp_val(ring->tx_pending, EMAC_MIN_TX_DESCS, EMAC_MAX_TX_DESCS);
168 adpt->rx_desc_cnt =
169 clamp_val(ring->rx_pending, EMAC_MIN_RX_DESCS, EMAC_MAX_RX_DESCS);
171 if (netif_running(netdev))
172 return emac_reinit_locked(adpt);
174 return 0;
177 static void emac_get_pauseparam(struct net_device *netdev,
178 struct ethtool_pauseparam *pause)
180 struct emac_adapter *adpt = netdev_priv(netdev);
182 pause->autoneg = adpt->automatic ? AUTONEG_ENABLE : AUTONEG_DISABLE;
183 pause->rx_pause = adpt->rx_flow_control ? 1 : 0;
184 pause->tx_pause = adpt->tx_flow_control ? 1 : 0;
187 static int emac_set_pauseparam(struct net_device *netdev,
188 struct ethtool_pauseparam *pause)
190 struct emac_adapter *adpt = netdev_priv(netdev);
192 adpt->automatic = pause->autoneg == AUTONEG_ENABLE;
193 adpt->rx_flow_control = pause->rx_pause != 0;
194 adpt->tx_flow_control = pause->tx_pause != 0;
196 if (netif_running(netdev))
197 return emac_reinit_locked(adpt);
199 return 0;
202 /* Selected registers that might want to track during runtime. */
203 static const u16 emac_regs[] = {
204 EMAC_DMA_MAS_CTRL,
205 EMAC_MAC_CTRL,
206 EMAC_TXQ_CTRL_0,
207 EMAC_RXQ_CTRL_0,
208 EMAC_DMA_CTRL,
209 EMAC_INT_MASK,
210 EMAC_AXI_MAST_CTRL,
211 EMAC_CORE_HW_VERSION,
212 EMAC_MISC_CTRL,
215 /* Every time emac_regs[] above is changed, increase this version number. */
216 #define EMAC_REGS_VERSION 0
218 #define EMAC_MAX_REG_SIZE ARRAY_SIZE(emac_regs)
220 static void emac_get_regs(struct net_device *netdev,
221 struct ethtool_regs *regs, void *buff)
223 struct emac_adapter *adpt = netdev_priv(netdev);
224 u32 *val = buff;
225 unsigned int i;
227 regs->version = EMAC_REGS_VERSION;
228 regs->len = EMAC_MAX_REG_SIZE * sizeof(u32);
230 for (i = 0; i < EMAC_MAX_REG_SIZE; i++)
231 val[i] = readl(adpt->base + emac_regs[i]);
234 static int emac_get_regs_len(struct net_device *netdev)
236 return EMAC_MAX_REG_SIZE * sizeof(u32);
239 #define EMAC_PRIV_ENABLE_SINGLE_PAUSE BIT(0)
241 static int emac_set_priv_flags(struct net_device *netdev, u32 flags)
243 struct emac_adapter *adpt = netdev_priv(netdev);
245 adpt->single_pause_mode = !!(flags & EMAC_PRIV_ENABLE_SINGLE_PAUSE);
247 if (netif_running(netdev))
248 return emac_reinit_locked(adpt);
250 return 0;
253 static u32 emac_get_priv_flags(struct net_device *netdev)
255 struct emac_adapter *adpt = netdev_priv(netdev);
257 return adpt->single_pause_mode ? EMAC_PRIV_ENABLE_SINGLE_PAUSE : 0;
260 static const struct ethtool_ops emac_ethtool_ops = {
261 .get_link_ksettings = phy_ethtool_get_link_ksettings,
262 .set_link_ksettings = phy_ethtool_set_link_ksettings,
264 .get_msglevel = emac_get_msglevel,
265 .set_msglevel = emac_set_msglevel,
267 .get_sset_count = emac_get_sset_count,
268 .get_strings = emac_get_strings,
269 .get_ethtool_stats = emac_get_ethtool_stats,
271 .get_ringparam = emac_get_ringparam,
272 .set_ringparam = emac_set_ringparam,
274 .get_pauseparam = emac_get_pauseparam,
275 .set_pauseparam = emac_set_pauseparam,
277 .nway_reset = emac_nway_reset,
279 .get_link = ethtool_op_get_link,
281 .get_regs_len = emac_get_regs_len,
282 .get_regs = emac_get_regs,
284 .set_priv_flags = emac_set_priv_flags,
285 .get_priv_flags = emac_get_priv_flags,
288 void emac_set_ethtool_ops(struct net_device *netdev)
290 netdev->ethtool_ops = &emac_ethtool_ops;