1 /*******************************************************************************
4 Copyright (C) 2007-2009 STMicroelectronics Ltd
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
23 *******************************************************************************/
25 #include <linux/etherdevice.h>
26 #include <linux/ethtool.h>
27 #include <linux/interrupt.h>
28 #include <linux/mii.h>
29 #include <linux/phy.h>
32 #include "dwmac_dma.h"
34 #define REG_SPACE_SIZE 0x1054
35 #define MAC100_ETHTOOL_NAME "st_mac100"
36 #define GMAC_ETHTOOL_NAME "st_gmac"
39 char stat_string
[ETH_GSTRING_LEN
];
44 #define STMMAC_STAT(m) \
45 { #m, FIELD_SIZEOF(struct stmmac_extra_stats, m), \
46 offsetof(struct stmmac_priv, xstats.m)}
48 static const struct stmmac_stats stmmac_gstrings_stats
[] = {
49 STMMAC_STAT(tx_underflow
),
50 STMMAC_STAT(tx_carrier
),
51 STMMAC_STAT(tx_losscarrier
),
52 STMMAC_STAT(tx_heartbeat
),
53 STMMAC_STAT(tx_deferred
),
56 STMMAC_STAT(tx_jabber
),
57 STMMAC_STAT(tx_frame_flushed
),
58 STMMAC_STAT(tx_payload_error
),
59 STMMAC_STAT(tx_ip_header_error
),
61 STMMAC_STAT(rx_partial
),
63 STMMAC_STAT(rx_toolong
),
64 STMMAC_STAT(rx_collision
),
66 STMMAC_STAT(rx_length
),
68 STMMAC_STAT(rx_multicast
),
69 STMMAC_STAT(rx_gmac_overflow
),
70 STMMAC_STAT(rx_watchdog
),
71 STMMAC_STAT(da_rx_filter_fail
),
72 STMMAC_STAT(sa_rx_filter_fail
),
73 STMMAC_STAT(rx_missed_cntr
),
74 STMMAC_STAT(rx_overflow_cntr
),
75 STMMAC_STAT(tx_undeflow_irq
),
76 STMMAC_STAT(tx_process_stopped_irq
),
77 STMMAC_STAT(tx_jabber_irq
),
78 STMMAC_STAT(rx_overflow_irq
),
79 STMMAC_STAT(rx_buf_unav_irq
),
80 STMMAC_STAT(rx_process_stopped_irq
),
81 STMMAC_STAT(rx_watchdog_irq
),
82 STMMAC_STAT(tx_early_irq
),
83 STMMAC_STAT(fatal_bus_error_irq
),
84 STMMAC_STAT(threshold
),
85 STMMAC_STAT(tx_pkt_n
),
86 STMMAC_STAT(rx_pkt_n
),
88 STMMAC_STAT(sched_timer_n
),
89 STMMAC_STAT(normal_irq_n
),
91 #define STMMAC_STATS_LEN ARRAY_SIZE(stmmac_gstrings_stats)
93 static void stmmac_ethtool_getdrvinfo(struct net_device
*dev
,
94 struct ethtool_drvinfo
*info
)
96 struct stmmac_priv
*priv
= netdev_priv(dev
);
98 if (!priv
->plat
->has_gmac
)
99 strcpy(info
->driver
, MAC100_ETHTOOL_NAME
);
101 strcpy(info
->driver
, GMAC_ETHTOOL_NAME
);
103 strcpy(info
->version
, DRV_MODULE_VERSION
);
104 info
->fw_version
[0] = '\0';
105 info
->n_stats
= STMMAC_STATS_LEN
;
108 static int stmmac_ethtool_getsettings(struct net_device
*dev
,
109 struct ethtool_cmd
*cmd
)
111 struct stmmac_priv
*priv
= netdev_priv(dev
);
112 struct phy_device
*phy
= priv
->phydev
;
115 pr_err("%s: %s: PHY is not registered\n",
116 __func__
, dev
->name
);
119 if (!netif_running(dev
)) {
120 pr_err("%s: interface is disabled: we cannot track "
121 "link speed / duplex setting\n", dev
->name
);
124 cmd
->transceiver
= XCVR_INTERNAL
;
125 spin_lock_irq(&priv
->lock
);
126 rc
= phy_ethtool_gset(phy
, cmd
);
127 spin_unlock_irq(&priv
->lock
);
131 static int stmmac_ethtool_setsettings(struct net_device
*dev
,
132 struct ethtool_cmd
*cmd
)
134 struct stmmac_priv
*priv
= netdev_priv(dev
);
135 struct phy_device
*phy
= priv
->phydev
;
138 spin_lock(&priv
->lock
);
139 rc
= phy_ethtool_sset(phy
, cmd
);
140 spin_unlock(&priv
->lock
);
145 static u32
stmmac_ethtool_getmsglevel(struct net_device
*dev
)
147 struct stmmac_priv
*priv
= netdev_priv(dev
);
148 return priv
->msg_enable
;
151 static void stmmac_ethtool_setmsglevel(struct net_device
*dev
, u32 level
)
153 struct stmmac_priv
*priv
= netdev_priv(dev
);
154 priv
->msg_enable
= level
;
158 static int stmmac_check_if_running(struct net_device
*dev
)
160 if (!netif_running(dev
))
165 static int stmmac_ethtool_get_regs_len(struct net_device
*dev
)
167 return REG_SPACE_SIZE
;
170 static void stmmac_ethtool_gregs(struct net_device
*dev
,
171 struct ethtool_regs
*regs
, void *space
)
174 u32
*reg_space
= (u32
*) space
;
176 struct stmmac_priv
*priv
= netdev_priv(dev
);
178 memset(reg_space
, 0x0, REG_SPACE_SIZE
);
180 if (!priv
->plat
->has_gmac
) {
182 for (i
= 0; i
< 12; i
++)
183 reg_space
[i
] = readl(priv
->ioaddr
+ (i
* 4));
185 for (i
= 0; i
< 9; i
++)
187 readl(priv
->ioaddr
+ (DMA_BUS_MODE
+ (i
* 4)));
188 reg_space
[22] = readl(priv
->ioaddr
+ DMA_CUR_TX_BUF_ADDR
);
189 reg_space
[23] = readl(priv
->ioaddr
+ DMA_CUR_RX_BUF_ADDR
);
192 for (i
= 0; i
< 55; i
++)
193 reg_space
[i
] = readl(priv
->ioaddr
+ (i
* 4));
195 for (i
= 0; i
< 22; i
++)
197 readl(priv
->ioaddr
+ (DMA_BUS_MODE
+ (i
* 4)));
202 stmmac_get_pauseparam(struct net_device
*netdev
,
203 struct ethtool_pauseparam
*pause
)
205 struct stmmac_priv
*priv
= netdev_priv(netdev
);
207 spin_lock(&priv
->lock
);
211 pause
->autoneg
= priv
->phydev
->autoneg
;
213 if (priv
->flow_ctrl
& FLOW_RX
)
215 if (priv
->flow_ctrl
& FLOW_TX
)
218 spin_unlock(&priv
->lock
);
222 stmmac_set_pauseparam(struct net_device
*netdev
,
223 struct ethtool_pauseparam
*pause
)
225 struct stmmac_priv
*priv
= netdev_priv(netdev
);
226 struct phy_device
*phy
= priv
->phydev
;
227 int new_pause
= FLOW_OFF
;
230 spin_lock(&priv
->lock
);
233 new_pause
|= FLOW_RX
;
235 new_pause
|= FLOW_TX
;
237 priv
->flow_ctrl
= new_pause
;
238 phy
->autoneg
= pause
->autoneg
;
241 if (netif_running(netdev
))
242 ret
= phy_start_aneg(phy
);
244 priv
->hw
->mac
->flow_ctrl(priv
->ioaddr
, phy
->duplex
,
245 priv
->flow_ctrl
, priv
->pause
);
246 spin_unlock(&priv
->lock
);
250 static void stmmac_get_ethtool_stats(struct net_device
*dev
,
251 struct ethtool_stats
*dummy
, u64
*data
)
253 struct stmmac_priv
*priv
= netdev_priv(dev
);
256 /* Update HW stats if supported */
257 priv
->hw
->dma
->dma_diagnostic_fr(&dev
->stats
, (void *) &priv
->xstats
,
260 for (i
= 0; i
< STMMAC_STATS_LEN
; i
++) {
261 char *p
= (char *)priv
+ stmmac_gstrings_stats
[i
].stat_offset
;
262 data
[i
] = (stmmac_gstrings_stats
[i
].sizeof_stat
==
263 sizeof(u64
)) ? (*(u64
*)p
) : (*(u32
*)p
);
267 static int stmmac_get_sset_count(struct net_device
*netdev
, int sset
)
271 return STMMAC_STATS_LEN
;
277 static void stmmac_get_strings(struct net_device
*dev
, u32 stringset
, u8
*data
)
284 for (i
= 0; i
< STMMAC_STATS_LEN
; i
++) {
285 memcpy(p
, stmmac_gstrings_stats
[i
].stat_string
,
287 p
+= ETH_GSTRING_LEN
;
296 /* Currently only support WOL through Magic packet. */
297 static void stmmac_get_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
299 struct stmmac_priv
*priv
= netdev_priv(dev
);
301 spin_lock_irq(&priv
->lock
);
302 if (device_can_wakeup(priv
->device
)) {
303 wol
->supported
= WAKE_MAGIC
| WAKE_UCAST
;
304 wol
->wolopts
= priv
->wolopts
;
306 spin_unlock_irq(&priv
->lock
);
309 static int stmmac_set_wol(struct net_device
*dev
, struct ethtool_wolinfo
*wol
)
311 struct stmmac_priv
*priv
= netdev_priv(dev
);
312 u32 support
= WAKE_MAGIC
| WAKE_UCAST
;
314 if (!device_can_wakeup(priv
->device
))
317 if (wol
->wolopts
& ~support
)
321 pr_info("stmmac: wakeup enable\n");
322 device_set_wakeup_enable(priv
->device
, 1);
323 enable_irq_wake(dev
->irq
);
325 device_set_wakeup_enable(priv
->device
, 0);
326 disable_irq_wake(dev
->irq
);
329 spin_lock_irq(&priv
->lock
);
330 priv
->wolopts
= wol
->wolopts
;
331 spin_unlock_irq(&priv
->lock
);
336 static struct ethtool_ops stmmac_ethtool_ops
= {
337 .begin
= stmmac_check_if_running
,
338 .get_drvinfo
= stmmac_ethtool_getdrvinfo
,
339 .get_settings
= stmmac_ethtool_getsettings
,
340 .set_settings
= stmmac_ethtool_setsettings
,
341 .get_msglevel
= stmmac_ethtool_getmsglevel
,
342 .set_msglevel
= stmmac_ethtool_setmsglevel
,
343 .get_regs
= stmmac_ethtool_gregs
,
344 .get_regs_len
= stmmac_ethtool_get_regs_len
,
345 .get_link
= ethtool_op_get_link
,
346 .get_pauseparam
= stmmac_get_pauseparam
,
347 .set_pauseparam
= stmmac_set_pauseparam
,
348 .get_ethtool_stats
= stmmac_get_ethtool_stats
,
349 .get_strings
= stmmac_get_strings
,
350 .get_wol
= stmmac_get_wol
,
351 .set_wol
= stmmac_set_wol
,
352 .get_sset_count
= stmmac_get_sset_count
,
355 void stmmac_set_ethtool_ops(struct net_device
*netdev
)
357 SET_ETHTOOL_OPS(netdev
, &stmmac_ethtool_ops
);