xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * AMD 10Gb Ethernet driver
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This file is available to you under your choice of the following two
5*4882a593Smuzhiyun  * licenses:
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * License 1: GPLv2
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * This file is free software; you may copy, redistribute and/or modify
12*4882a593Smuzhiyun  * it under the terms of the GNU General Public License as published by
13*4882a593Smuzhiyun  * the Free Software Foundation, either version 2 of the License, or (at
14*4882a593Smuzhiyun  * your option) any later version.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * This file is distributed in the hope that it will be useful, but
17*4882a593Smuzhiyun  * WITHOUT ANY WARRANTY; without even the implied warranty of
18*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19*4882a593Smuzhiyun  * General Public License for more details.
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  * You should have received a copy of the GNU General Public License
22*4882a593Smuzhiyun  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * This file incorporates work covered by the following copyright and
25*4882a593Smuzhiyun  * permission notice:
26*4882a593Smuzhiyun  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
27*4882a593Smuzhiyun  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28*4882a593Smuzhiyun  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
29*4882a593Smuzhiyun  *     and you.
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  *     The Software IS NOT an item of Licensed Software or Licensed Product
32*4882a593Smuzhiyun  *     under any End User Software License Agreement or Agreement for Licensed
33*4882a593Smuzhiyun  *     Product with Synopsys or any supplement thereto.  Permission is hereby
34*4882a593Smuzhiyun  *     granted, free of charge, to any person obtaining a copy of this software
35*4882a593Smuzhiyun  *     annotated with this license and the Software, to deal in the Software
36*4882a593Smuzhiyun  *     without restriction, including without limitation the rights to use,
37*4882a593Smuzhiyun  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38*4882a593Smuzhiyun  *     of the Software, and to permit persons to whom the Software is furnished
39*4882a593Smuzhiyun  *     to do so, subject to the following conditions:
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  *     The above copyright notice and this permission notice shall be included
42*4882a593Smuzhiyun  *     in all copies or substantial portions of the Software.
43*4882a593Smuzhiyun  *
44*4882a593Smuzhiyun  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45*4882a593Smuzhiyun  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46*4882a593Smuzhiyun  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47*4882a593Smuzhiyun  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48*4882a593Smuzhiyun  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49*4882a593Smuzhiyun  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50*4882a593Smuzhiyun  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51*4882a593Smuzhiyun  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52*4882a593Smuzhiyun  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53*4882a593Smuzhiyun  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54*4882a593Smuzhiyun  *     THE POSSIBILITY OF SUCH DAMAGE.
55*4882a593Smuzhiyun  *
56*4882a593Smuzhiyun  *
57*4882a593Smuzhiyun  * License 2: Modified BSD
58*4882a593Smuzhiyun  *
59*4882a593Smuzhiyun  * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
60*4882a593Smuzhiyun  * All rights reserved.
61*4882a593Smuzhiyun  *
62*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
63*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions are met:
64*4882a593Smuzhiyun  *     * Redistributions of source code must retain the above copyright
65*4882a593Smuzhiyun  *       notice, this list of conditions and the following disclaimer.
66*4882a593Smuzhiyun  *     * Redistributions in binary form must reproduce the above copyright
67*4882a593Smuzhiyun  *       notice, this list of conditions and the following disclaimer in the
68*4882a593Smuzhiyun  *       documentation and/or other materials provided with the distribution.
69*4882a593Smuzhiyun  *     * Neither the name of Advanced Micro Devices, Inc. nor the
70*4882a593Smuzhiyun  *       names of its contributors may be used to endorse or promote products
71*4882a593Smuzhiyun  *       derived from this software without specific prior written permission.
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74*4882a593Smuzhiyun  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75*4882a593Smuzhiyun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76*4882a593Smuzhiyun  * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
77*4882a593Smuzhiyun  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78*4882a593Smuzhiyun  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79*4882a593Smuzhiyun  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80*4882a593Smuzhiyun  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82*4882a593Smuzhiyun  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83*4882a593Smuzhiyun  *
84*4882a593Smuzhiyun  * This file incorporates work covered by the following copyright and
85*4882a593Smuzhiyun  * permission notice:
86*4882a593Smuzhiyun  *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
87*4882a593Smuzhiyun  *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
88*4882a593Smuzhiyun  *     Inc. unless otherwise expressly agreed to in writing between Synopsys
89*4882a593Smuzhiyun  *     and you.
90*4882a593Smuzhiyun  *
91*4882a593Smuzhiyun  *     The Software IS NOT an item of Licensed Software or Licensed Product
92*4882a593Smuzhiyun  *     under any End User Software License Agreement or Agreement for Licensed
93*4882a593Smuzhiyun  *     Product with Synopsys or any supplement thereto.  Permission is hereby
94*4882a593Smuzhiyun  *     granted, free of charge, to any person obtaining a copy of this software
95*4882a593Smuzhiyun  *     annotated with this license and the Software, to deal in the Software
96*4882a593Smuzhiyun  *     without restriction, including without limitation the rights to use,
97*4882a593Smuzhiyun  *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98*4882a593Smuzhiyun  *     of the Software, and to permit persons to whom the Software is furnished
99*4882a593Smuzhiyun  *     to do so, subject to the following conditions:
100*4882a593Smuzhiyun  *
101*4882a593Smuzhiyun  *     The above copyright notice and this permission notice shall be included
102*4882a593Smuzhiyun  *     in all copies or substantial portions of the Software.
103*4882a593Smuzhiyun  *
104*4882a593Smuzhiyun  *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
105*4882a593Smuzhiyun  *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
106*4882a593Smuzhiyun  *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
107*4882a593Smuzhiyun  *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
108*4882a593Smuzhiyun  *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109*4882a593Smuzhiyun  *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110*4882a593Smuzhiyun  *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
111*4882a593Smuzhiyun  *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
112*4882a593Smuzhiyun  *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
113*4882a593Smuzhiyun  *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
114*4882a593Smuzhiyun  *     THE POSSIBILITY OF SUCH DAMAGE.
115*4882a593Smuzhiyun  */
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #include <linux/spinlock.h>
118*4882a593Smuzhiyun #include <linux/phy.h>
119*4882a593Smuzhiyun #include <linux/net_tstamp.h>
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun #include "xgbe.h"
122*4882a593Smuzhiyun #include "xgbe-common.h"
123*4882a593Smuzhiyun 
124*4882a593Smuzhiyun struct xgbe_stats {
125*4882a593Smuzhiyun 	char stat_string[ETH_GSTRING_LEN];
126*4882a593Smuzhiyun 	int stat_size;
127*4882a593Smuzhiyun 	int stat_offset;
128*4882a593Smuzhiyun };
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun #define XGMAC_MMC_STAT(_string, _var)				\
131*4882a593Smuzhiyun 	{ _string,						\
132*4882a593Smuzhiyun 	  sizeof_field(struct xgbe_mmc_stats, _var),		\
133*4882a593Smuzhiyun 	  offsetof(struct xgbe_prv_data, mmc_stats._var),	\
134*4882a593Smuzhiyun 	}
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun #define XGMAC_EXT_STAT(_string, _var)				\
137*4882a593Smuzhiyun 	{ _string,						\
138*4882a593Smuzhiyun 	  sizeof_field(struct xgbe_ext_stats, _var),		\
139*4882a593Smuzhiyun 	  offsetof(struct xgbe_prv_data, ext_stats._var),	\
140*4882a593Smuzhiyun 	}
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun static const struct xgbe_stats xgbe_gstring_stats[] = {
143*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_bytes", txoctetcount_gb),
144*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_packets", txframecount_gb),
145*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb),
146*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb),
147*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb),
148*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g),
149*4882a593Smuzhiyun 	XGMAC_EXT_STAT("tx_vxlan_packets", tx_vxlan_packets),
150*4882a593Smuzhiyun 	XGMAC_EXT_STAT("tx_tso_packets", tx_tso_packets),
151*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb),
152*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb),
153*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb),
154*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb),
155*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb),
156*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb),
157*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror),
158*4882a593Smuzhiyun 	XGMAC_MMC_STAT("tx_pause_frames", txpauseframes),
159*4882a593Smuzhiyun 
160*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb),
161*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_packets", rxframecount_gb),
162*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g),
163*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g),
164*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g),
165*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb),
166*4882a593Smuzhiyun 	XGMAC_EXT_STAT("rx_vxlan_packets", rx_vxlan_packets),
167*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb),
168*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb),
169*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb),
170*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb),
171*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb),
172*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb),
173*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g),
174*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g),
175*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_crc_errors", rxcrcerror),
176*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror),
177*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror),
178*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_length_errors", rxlengtherror),
179*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype),
180*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow),
181*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror),
182*4882a593Smuzhiyun 	XGMAC_EXT_STAT("rx_csum_errors", rx_csum_errors),
183*4882a593Smuzhiyun 	XGMAC_EXT_STAT("rx_vxlan_csum_errors", rx_vxlan_csum_errors),
184*4882a593Smuzhiyun 	XGMAC_MMC_STAT("rx_pause_frames", rxpauseframes),
185*4882a593Smuzhiyun 	XGMAC_EXT_STAT("rx_split_header_packets", rx_split_header_packets),
186*4882a593Smuzhiyun 	XGMAC_EXT_STAT("rx_buffer_unavailable", rx_buffer_unavailable),
187*4882a593Smuzhiyun };
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun #define XGBE_STATS_COUNT	ARRAY_SIZE(xgbe_gstring_stats)
190*4882a593Smuzhiyun 
xgbe_get_strings(struct net_device * netdev,u32 stringset,u8 * data)191*4882a593Smuzhiyun static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
192*4882a593Smuzhiyun {
193*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
194*4882a593Smuzhiyun 	int i;
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun 	switch (stringset) {
197*4882a593Smuzhiyun 	case ETH_SS_STATS:
198*4882a593Smuzhiyun 		for (i = 0; i < XGBE_STATS_COUNT; i++) {
199*4882a593Smuzhiyun 			memcpy(data, xgbe_gstring_stats[i].stat_string,
200*4882a593Smuzhiyun 			       ETH_GSTRING_LEN);
201*4882a593Smuzhiyun 			data += ETH_GSTRING_LEN;
202*4882a593Smuzhiyun 		}
203*4882a593Smuzhiyun 		for (i = 0; i < pdata->tx_ring_count; i++) {
204*4882a593Smuzhiyun 			sprintf(data, "txq_%u_packets", i);
205*4882a593Smuzhiyun 			data += ETH_GSTRING_LEN;
206*4882a593Smuzhiyun 			sprintf(data, "txq_%u_bytes", i);
207*4882a593Smuzhiyun 			data += ETH_GSTRING_LEN;
208*4882a593Smuzhiyun 		}
209*4882a593Smuzhiyun 		for (i = 0; i < pdata->rx_ring_count; i++) {
210*4882a593Smuzhiyun 			sprintf(data, "rxq_%u_packets", i);
211*4882a593Smuzhiyun 			data += ETH_GSTRING_LEN;
212*4882a593Smuzhiyun 			sprintf(data, "rxq_%u_bytes", i);
213*4882a593Smuzhiyun 			data += ETH_GSTRING_LEN;
214*4882a593Smuzhiyun 		}
215*4882a593Smuzhiyun 		break;
216*4882a593Smuzhiyun 	}
217*4882a593Smuzhiyun }
218*4882a593Smuzhiyun 
xgbe_get_ethtool_stats(struct net_device * netdev,struct ethtool_stats * stats,u64 * data)219*4882a593Smuzhiyun static void xgbe_get_ethtool_stats(struct net_device *netdev,
220*4882a593Smuzhiyun 				   struct ethtool_stats *stats, u64 *data)
221*4882a593Smuzhiyun {
222*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
223*4882a593Smuzhiyun 	u8 *stat;
224*4882a593Smuzhiyun 	int i;
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun 	pdata->hw_if.read_mmc_stats(pdata);
227*4882a593Smuzhiyun 	for (i = 0; i < XGBE_STATS_COUNT; i++) {
228*4882a593Smuzhiyun 		stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
229*4882a593Smuzhiyun 		*data++ = *(u64 *)stat;
230*4882a593Smuzhiyun 	}
231*4882a593Smuzhiyun 	for (i = 0; i < pdata->tx_ring_count; i++) {
232*4882a593Smuzhiyun 		*data++ = pdata->ext_stats.txq_packets[i];
233*4882a593Smuzhiyun 		*data++ = pdata->ext_stats.txq_bytes[i];
234*4882a593Smuzhiyun 	}
235*4882a593Smuzhiyun 	for (i = 0; i < pdata->rx_ring_count; i++) {
236*4882a593Smuzhiyun 		*data++ = pdata->ext_stats.rxq_packets[i];
237*4882a593Smuzhiyun 		*data++ = pdata->ext_stats.rxq_bytes[i];
238*4882a593Smuzhiyun 	}
239*4882a593Smuzhiyun }
240*4882a593Smuzhiyun 
xgbe_get_sset_count(struct net_device * netdev,int stringset)241*4882a593Smuzhiyun static int xgbe_get_sset_count(struct net_device *netdev, int stringset)
242*4882a593Smuzhiyun {
243*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
244*4882a593Smuzhiyun 	int ret;
245*4882a593Smuzhiyun 
246*4882a593Smuzhiyun 	switch (stringset) {
247*4882a593Smuzhiyun 	case ETH_SS_STATS:
248*4882a593Smuzhiyun 		ret = XGBE_STATS_COUNT +
249*4882a593Smuzhiyun 		      (pdata->tx_ring_count * 2) +
250*4882a593Smuzhiyun 		      (pdata->rx_ring_count * 2);
251*4882a593Smuzhiyun 		break;
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun 	default:
254*4882a593Smuzhiyun 		ret = -EOPNOTSUPP;
255*4882a593Smuzhiyun 	}
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun 	return ret;
258*4882a593Smuzhiyun }
259*4882a593Smuzhiyun 
xgbe_get_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * pause)260*4882a593Smuzhiyun static void xgbe_get_pauseparam(struct net_device *netdev,
261*4882a593Smuzhiyun 				struct ethtool_pauseparam *pause)
262*4882a593Smuzhiyun {
263*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun 	pause->autoneg = pdata->phy.pause_autoneg;
266*4882a593Smuzhiyun 	pause->tx_pause = pdata->phy.tx_pause;
267*4882a593Smuzhiyun 	pause->rx_pause = pdata->phy.rx_pause;
268*4882a593Smuzhiyun }
269*4882a593Smuzhiyun 
xgbe_set_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * pause)270*4882a593Smuzhiyun static int xgbe_set_pauseparam(struct net_device *netdev,
271*4882a593Smuzhiyun 			       struct ethtool_pauseparam *pause)
272*4882a593Smuzhiyun {
273*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
274*4882a593Smuzhiyun 	struct ethtool_link_ksettings *lks = &pdata->phy.lks;
275*4882a593Smuzhiyun 	int ret = 0;
276*4882a593Smuzhiyun 
277*4882a593Smuzhiyun 	if (pause->autoneg && (pdata->phy.autoneg != AUTONEG_ENABLE)) {
278*4882a593Smuzhiyun 		netdev_err(netdev,
279*4882a593Smuzhiyun 			   "autoneg disabled, pause autoneg not available\n");
280*4882a593Smuzhiyun 		return -EINVAL;
281*4882a593Smuzhiyun 	}
282*4882a593Smuzhiyun 
283*4882a593Smuzhiyun 	pdata->phy.pause_autoneg = pause->autoneg;
284*4882a593Smuzhiyun 	pdata->phy.tx_pause = pause->tx_pause;
285*4882a593Smuzhiyun 	pdata->phy.rx_pause = pause->rx_pause;
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun 	XGBE_CLR_ADV(lks, Pause);
288*4882a593Smuzhiyun 	XGBE_CLR_ADV(lks, Asym_Pause);
289*4882a593Smuzhiyun 
290*4882a593Smuzhiyun 	if (pause->rx_pause) {
291*4882a593Smuzhiyun 		XGBE_SET_ADV(lks, Pause);
292*4882a593Smuzhiyun 		XGBE_SET_ADV(lks, Asym_Pause);
293*4882a593Smuzhiyun 	}
294*4882a593Smuzhiyun 
295*4882a593Smuzhiyun 	if (pause->tx_pause) {
296*4882a593Smuzhiyun 		/* Equivalent to XOR of Asym_Pause */
297*4882a593Smuzhiyun 		if (XGBE_ADV(lks, Asym_Pause))
298*4882a593Smuzhiyun 			XGBE_CLR_ADV(lks, Asym_Pause);
299*4882a593Smuzhiyun 		else
300*4882a593Smuzhiyun 			XGBE_SET_ADV(lks, Asym_Pause);
301*4882a593Smuzhiyun 	}
302*4882a593Smuzhiyun 
303*4882a593Smuzhiyun 	if (netif_running(netdev))
304*4882a593Smuzhiyun 		ret = pdata->phy_if.phy_config_aneg(pdata);
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun 	return ret;
307*4882a593Smuzhiyun }
308*4882a593Smuzhiyun 
xgbe_get_link_ksettings(struct net_device * netdev,struct ethtool_link_ksettings * cmd)309*4882a593Smuzhiyun static int xgbe_get_link_ksettings(struct net_device *netdev,
310*4882a593Smuzhiyun 				   struct ethtool_link_ksettings *cmd)
311*4882a593Smuzhiyun {
312*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
313*4882a593Smuzhiyun 	struct ethtool_link_ksettings *lks = &pdata->phy.lks;
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun 	cmd->base.phy_address = pdata->phy.address;
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun 	cmd->base.autoneg = pdata->phy.autoneg;
318*4882a593Smuzhiyun 	cmd->base.speed = pdata->phy.speed;
319*4882a593Smuzhiyun 	cmd->base.duplex = pdata->phy.duplex;
320*4882a593Smuzhiyun 
321*4882a593Smuzhiyun 	cmd->base.port = PORT_NONE;
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun 	XGBE_LM_COPY(cmd, supported, lks, supported);
324*4882a593Smuzhiyun 	XGBE_LM_COPY(cmd, advertising, lks, advertising);
325*4882a593Smuzhiyun 	XGBE_LM_COPY(cmd, lp_advertising, lks, lp_advertising);
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	return 0;
328*4882a593Smuzhiyun }
329*4882a593Smuzhiyun 
xgbe_set_link_ksettings(struct net_device * netdev,const struct ethtool_link_ksettings * cmd)330*4882a593Smuzhiyun static int xgbe_set_link_ksettings(struct net_device *netdev,
331*4882a593Smuzhiyun 				   const struct ethtool_link_ksettings *cmd)
332*4882a593Smuzhiyun {
333*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
334*4882a593Smuzhiyun 	struct ethtool_link_ksettings *lks = &pdata->phy.lks;
335*4882a593Smuzhiyun 	__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
336*4882a593Smuzhiyun 	u32 speed;
337*4882a593Smuzhiyun 	int ret;
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun 	speed = cmd->base.speed;
340*4882a593Smuzhiyun 
341*4882a593Smuzhiyun 	if (cmd->base.phy_address != pdata->phy.address) {
342*4882a593Smuzhiyun 		netdev_err(netdev, "invalid phy address %hhu\n",
343*4882a593Smuzhiyun 			   cmd->base.phy_address);
344*4882a593Smuzhiyun 		return -EINVAL;
345*4882a593Smuzhiyun 	}
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun 	if ((cmd->base.autoneg != AUTONEG_ENABLE) &&
348*4882a593Smuzhiyun 	    (cmd->base.autoneg != AUTONEG_DISABLE)) {
349*4882a593Smuzhiyun 		netdev_err(netdev, "unsupported autoneg %hhu\n",
350*4882a593Smuzhiyun 			   cmd->base.autoneg);
351*4882a593Smuzhiyun 		return -EINVAL;
352*4882a593Smuzhiyun 	}
353*4882a593Smuzhiyun 
354*4882a593Smuzhiyun 	if (cmd->base.autoneg == AUTONEG_DISABLE) {
355*4882a593Smuzhiyun 		if (!pdata->phy_if.phy_valid_speed(pdata, speed)) {
356*4882a593Smuzhiyun 			netdev_err(netdev, "unsupported speed %u\n", speed);
357*4882a593Smuzhiyun 			return -EINVAL;
358*4882a593Smuzhiyun 		}
359*4882a593Smuzhiyun 
360*4882a593Smuzhiyun 		if (cmd->base.duplex != DUPLEX_FULL) {
361*4882a593Smuzhiyun 			netdev_err(netdev, "unsupported duplex %hhu\n",
362*4882a593Smuzhiyun 				   cmd->base.duplex);
363*4882a593Smuzhiyun 			return -EINVAL;
364*4882a593Smuzhiyun 		}
365*4882a593Smuzhiyun 	}
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun 	netif_dbg(pdata, link, netdev,
368*4882a593Smuzhiyun 		  "requested advertisement 0x%*pb, phy supported 0x%*pb\n",
369*4882a593Smuzhiyun 		  __ETHTOOL_LINK_MODE_MASK_NBITS, cmd->link_modes.advertising,
370*4882a593Smuzhiyun 		  __ETHTOOL_LINK_MODE_MASK_NBITS, lks->link_modes.supported);
371*4882a593Smuzhiyun 
372*4882a593Smuzhiyun 	bitmap_and(advertising,
373*4882a593Smuzhiyun 		   cmd->link_modes.advertising, lks->link_modes.supported,
374*4882a593Smuzhiyun 		   __ETHTOOL_LINK_MODE_MASK_NBITS);
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 	if ((cmd->base.autoneg == AUTONEG_ENABLE) &&
377*4882a593Smuzhiyun 	    bitmap_empty(advertising, __ETHTOOL_LINK_MODE_MASK_NBITS)) {
378*4882a593Smuzhiyun 		netdev_err(netdev,
379*4882a593Smuzhiyun 			   "unsupported requested advertisement\n");
380*4882a593Smuzhiyun 		return -EINVAL;
381*4882a593Smuzhiyun 	}
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun 	ret = 0;
384*4882a593Smuzhiyun 	pdata->phy.autoneg = cmd->base.autoneg;
385*4882a593Smuzhiyun 	pdata->phy.speed = speed;
386*4882a593Smuzhiyun 	pdata->phy.duplex = cmd->base.duplex;
387*4882a593Smuzhiyun 	bitmap_copy(lks->link_modes.advertising, advertising,
388*4882a593Smuzhiyun 		    __ETHTOOL_LINK_MODE_MASK_NBITS);
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun 	if (cmd->base.autoneg == AUTONEG_ENABLE)
391*4882a593Smuzhiyun 		XGBE_SET_ADV(lks, Autoneg);
392*4882a593Smuzhiyun 	else
393*4882a593Smuzhiyun 		XGBE_CLR_ADV(lks, Autoneg);
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun 	if (netif_running(netdev))
396*4882a593Smuzhiyun 		ret = pdata->phy_if.phy_config_aneg(pdata);
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun 	return ret;
399*4882a593Smuzhiyun }
400*4882a593Smuzhiyun 
xgbe_get_drvinfo(struct net_device * netdev,struct ethtool_drvinfo * drvinfo)401*4882a593Smuzhiyun static void xgbe_get_drvinfo(struct net_device *netdev,
402*4882a593Smuzhiyun 			     struct ethtool_drvinfo *drvinfo)
403*4882a593Smuzhiyun {
404*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
405*4882a593Smuzhiyun 	struct xgbe_hw_features *hw_feat = &pdata->hw_feat;
406*4882a593Smuzhiyun 
407*4882a593Smuzhiyun 	strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver));
408*4882a593Smuzhiyun 	strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
409*4882a593Smuzhiyun 		sizeof(drvinfo->bus_info));
410*4882a593Smuzhiyun 	snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d",
411*4882a593Smuzhiyun 		 XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
412*4882a593Smuzhiyun 		 XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
413*4882a593Smuzhiyun 		 XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
414*4882a593Smuzhiyun }
415*4882a593Smuzhiyun 
xgbe_get_msglevel(struct net_device * netdev)416*4882a593Smuzhiyun static u32 xgbe_get_msglevel(struct net_device *netdev)
417*4882a593Smuzhiyun {
418*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
419*4882a593Smuzhiyun 
420*4882a593Smuzhiyun 	return pdata->msg_enable;
421*4882a593Smuzhiyun }
422*4882a593Smuzhiyun 
xgbe_set_msglevel(struct net_device * netdev,u32 msglevel)423*4882a593Smuzhiyun static void xgbe_set_msglevel(struct net_device *netdev, u32 msglevel)
424*4882a593Smuzhiyun {
425*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun 	pdata->msg_enable = msglevel;
428*4882a593Smuzhiyun }
429*4882a593Smuzhiyun 
xgbe_get_coalesce(struct net_device * netdev,struct ethtool_coalesce * ec)430*4882a593Smuzhiyun static int xgbe_get_coalesce(struct net_device *netdev,
431*4882a593Smuzhiyun 			     struct ethtool_coalesce *ec)
432*4882a593Smuzhiyun {
433*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun 	memset(ec, 0, sizeof(struct ethtool_coalesce));
436*4882a593Smuzhiyun 
437*4882a593Smuzhiyun 	ec->rx_coalesce_usecs = pdata->rx_usecs;
438*4882a593Smuzhiyun 	ec->rx_max_coalesced_frames = pdata->rx_frames;
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun 	ec->tx_max_coalesced_frames = pdata->tx_frames;
441*4882a593Smuzhiyun 
442*4882a593Smuzhiyun 	return 0;
443*4882a593Smuzhiyun }
444*4882a593Smuzhiyun 
xgbe_set_coalesce(struct net_device * netdev,struct ethtool_coalesce * ec)445*4882a593Smuzhiyun static int xgbe_set_coalesce(struct net_device *netdev,
446*4882a593Smuzhiyun 			     struct ethtool_coalesce *ec)
447*4882a593Smuzhiyun {
448*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
449*4882a593Smuzhiyun 	struct xgbe_hw_if *hw_if = &pdata->hw_if;
450*4882a593Smuzhiyun 	unsigned int rx_frames, rx_riwt, rx_usecs;
451*4882a593Smuzhiyun 	unsigned int tx_frames;
452*4882a593Smuzhiyun 
453*4882a593Smuzhiyun 	rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs);
454*4882a593Smuzhiyun 	rx_usecs = ec->rx_coalesce_usecs;
455*4882a593Smuzhiyun 	rx_frames = ec->rx_max_coalesced_frames;
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun 	/* Use smallest possible value if conversion resulted in zero */
458*4882a593Smuzhiyun 	if (rx_usecs && !rx_riwt)
459*4882a593Smuzhiyun 		rx_riwt = 1;
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun 	/* Check the bounds of values for Rx */
462*4882a593Smuzhiyun 	if (rx_riwt > XGMAC_MAX_DMA_RIWT) {
463*4882a593Smuzhiyun 		netdev_err(netdev, "rx-usec is limited to %d usecs\n",
464*4882a593Smuzhiyun 			   hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT));
465*4882a593Smuzhiyun 		return -EINVAL;
466*4882a593Smuzhiyun 	}
467*4882a593Smuzhiyun 	if (rx_frames > pdata->rx_desc_count) {
468*4882a593Smuzhiyun 		netdev_err(netdev, "rx-frames is limited to %d frames\n",
469*4882a593Smuzhiyun 			   pdata->rx_desc_count);
470*4882a593Smuzhiyun 		return -EINVAL;
471*4882a593Smuzhiyun 	}
472*4882a593Smuzhiyun 
473*4882a593Smuzhiyun 	tx_frames = ec->tx_max_coalesced_frames;
474*4882a593Smuzhiyun 
475*4882a593Smuzhiyun 	/* Check the bounds of values for Tx */
476*4882a593Smuzhiyun 	if (tx_frames > pdata->tx_desc_count) {
477*4882a593Smuzhiyun 		netdev_err(netdev, "tx-frames is limited to %d frames\n",
478*4882a593Smuzhiyun 			   pdata->tx_desc_count);
479*4882a593Smuzhiyun 		return -EINVAL;
480*4882a593Smuzhiyun 	}
481*4882a593Smuzhiyun 
482*4882a593Smuzhiyun 	pdata->rx_riwt = rx_riwt;
483*4882a593Smuzhiyun 	pdata->rx_usecs = rx_usecs;
484*4882a593Smuzhiyun 	pdata->rx_frames = rx_frames;
485*4882a593Smuzhiyun 	hw_if->config_rx_coalesce(pdata);
486*4882a593Smuzhiyun 
487*4882a593Smuzhiyun 	pdata->tx_frames = tx_frames;
488*4882a593Smuzhiyun 	hw_if->config_tx_coalesce(pdata);
489*4882a593Smuzhiyun 
490*4882a593Smuzhiyun 	return 0;
491*4882a593Smuzhiyun }
492*4882a593Smuzhiyun 
xgbe_get_rxnfc(struct net_device * netdev,struct ethtool_rxnfc * rxnfc,u32 * rule_locs)493*4882a593Smuzhiyun static int xgbe_get_rxnfc(struct net_device *netdev,
494*4882a593Smuzhiyun 			  struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
495*4882a593Smuzhiyun {
496*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
497*4882a593Smuzhiyun 
498*4882a593Smuzhiyun 	switch (rxnfc->cmd) {
499*4882a593Smuzhiyun 	case ETHTOOL_GRXRINGS:
500*4882a593Smuzhiyun 		rxnfc->data = pdata->rx_ring_count;
501*4882a593Smuzhiyun 		break;
502*4882a593Smuzhiyun 	default:
503*4882a593Smuzhiyun 		return -EOPNOTSUPP;
504*4882a593Smuzhiyun 	}
505*4882a593Smuzhiyun 
506*4882a593Smuzhiyun 	return 0;
507*4882a593Smuzhiyun }
508*4882a593Smuzhiyun 
xgbe_get_rxfh_key_size(struct net_device * netdev)509*4882a593Smuzhiyun static u32 xgbe_get_rxfh_key_size(struct net_device *netdev)
510*4882a593Smuzhiyun {
511*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun 	return sizeof(pdata->rss_key);
514*4882a593Smuzhiyun }
515*4882a593Smuzhiyun 
xgbe_get_rxfh_indir_size(struct net_device * netdev)516*4882a593Smuzhiyun static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
517*4882a593Smuzhiyun {
518*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
519*4882a593Smuzhiyun 
520*4882a593Smuzhiyun 	return ARRAY_SIZE(pdata->rss_table);
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun 
xgbe_get_rxfh(struct net_device * netdev,u32 * indir,u8 * key,u8 * hfunc)523*4882a593Smuzhiyun static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
524*4882a593Smuzhiyun 			 u8 *hfunc)
525*4882a593Smuzhiyun {
526*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
527*4882a593Smuzhiyun 	unsigned int i;
528*4882a593Smuzhiyun 
529*4882a593Smuzhiyun 	if (indir) {
530*4882a593Smuzhiyun 		for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
531*4882a593Smuzhiyun 			indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
532*4882a593Smuzhiyun 						  MAC_RSSDR, DMCH);
533*4882a593Smuzhiyun 	}
534*4882a593Smuzhiyun 
535*4882a593Smuzhiyun 	if (key)
536*4882a593Smuzhiyun 		memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
537*4882a593Smuzhiyun 
538*4882a593Smuzhiyun 	if (hfunc)
539*4882a593Smuzhiyun 		*hfunc = ETH_RSS_HASH_TOP;
540*4882a593Smuzhiyun 
541*4882a593Smuzhiyun 	return 0;
542*4882a593Smuzhiyun }
543*4882a593Smuzhiyun 
xgbe_set_rxfh(struct net_device * netdev,const u32 * indir,const u8 * key,const u8 hfunc)544*4882a593Smuzhiyun static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
545*4882a593Smuzhiyun 			 const u8 *key, const u8 hfunc)
546*4882a593Smuzhiyun {
547*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
548*4882a593Smuzhiyun 	struct xgbe_hw_if *hw_if = &pdata->hw_if;
549*4882a593Smuzhiyun 	unsigned int ret;
550*4882a593Smuzhiyun 
551*4882a593Smuzhiyun 	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) {
552*4882a593Smuzhiyun 		netdev_err(netdev, "unsupported hash function\n");
553*4882a593Smuzhiyun 		return -EOPNOTSUPP;
554*4882a593Smuzhiyun 	}
555*4882a593Smuzhiyun 
556*4882a593Smuzhiyun 	if (indir) {
557*4882a593Smuzhiyun 		ret = hw_if->set_rss_lookup_table(pdata, indir);
558*4882a593Smuzhiyun 		if (ret)
559*4882a593Smuzhiyun 			return ret;
560*4882a593Smuzhiyun 	}
561*4882a593Smuzhiyun 
562*4882a593Smuzhiyun 	if (key) {
563*4882a593Smuzhiyun 		ret = hw_if->set_rss_hash_key(pdata, key);
564*4882a593Smuzhiyun 		if (ret)
565*4882a593Smuzhiyun 			return ret;
566*4882a593Smuzhiyun 	}
567*4882a593Smuzhiyun 
568*4882a593Smuzhiyun 	return 0;
569*4882a593Smuzhiyun }
570*4882a593Smuzhiyun 
xgbe_get_ts_info(struct net_device * netdev,struct ethtool_ts_info * ts_info)571*4882a593Smuzhiyun static int xgbe_get_ts_info(struct net_device *netdev,
572*4882a593Smuzhiyun 			    struct ethtool_ts_info *ts_info)
573*4882a593Smuzhiyun {
574*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
575*4882a593Smuzhiyun 
576*4882a593Smuzhiyun 	ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
577*4882a593Smuzhiyun 				   SOF_TIMESTAMPING_RX_SOFTWARE |
578*4882a593Smuzhiyun 				   SOF_TIMESTAMPING_SOFTWARE |
579*4882a593Smuzhiyun 				   SOF_TIMESTAMPING_TX_HARDWARE |
580*4882a593Smuzhiyun 				   SOF_TIMESTAMPING_RX_HARDWARE |
581*4882a593Smuzhiyun 				   SOF_TIMESTAMPING_RAW_HARDWARE;
582*4882a593Smuzhiyun 
583*4882a593Smuzhiyun 	if (pdata->ptp_clock)
584*4882a593Smuzhiyun 		ts_info->phc_index = ptp_clock_index(pdata->ptp_clock);
585*4882a593Smuzhiyun 	else
586*4882a593Smuzhiyun 		ts_info->phc_index = -1;
587*4882a593Smuzhiyun 
588*4882a593Smuzhiyun 	ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
589*4882a593Smuzhiyun 	ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
590*4882a593Smuzhiyun 			      (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
591*4882a593Smuzhiyun 			      (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
592*4882a593Smuzhiyun 			      (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
593*4882a593Smuzhiyun 			      (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
594*4882a593Smuzhiyun 			      (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
595*4882a593Smuzhiyun 			      (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
596*4882a593Smuzhiyun 			      (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
597*4882a593Smuzhiyun 			      (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
598*4882a593Smuzhiyun 			      (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
599*4882a593Smuzhiyun 			      (1 << HWTSTAMP_FILTER_ALL);
600*4882a593Smuzhiyun 
601*4882a593Smuzhiyun 	return 0;
602*4882a593Smuzhiyun }
603*4882a593Smuzhiyun 
xgbe_get_module_info(struct net_device * netdev,struct ethtool_modinfo * modinfo)604*4882a593Smuzhiyun static int xgbe_get_module_info(struct net_device *netdev,
605*4882a593Smuzhiyun 				struct ethtool_modinfo *modinfo)
606*4882a593Smuzhiyun {
607*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
608*4882a593Smuzhiyun 
609*4882a593Smuzhiyun 	return pdata->phy_if.module_info(pdata, modinfo);
610*4882a593Smuzhiyun }
611*4882a593Smuzhiyun 
xgbe_get_module_eeprom(struct net_device * netdev,struct ethtool_eeprom * eeprom,u8 * data)612*4882a593Smuzhiyun static int xgbe_get_module_eeprom(struct net_device *netdev,
613*4882a593Smuzhiyun 				  struct ethtool_eeprom *eeprom, u8 *data)
614*4882a593Smuzhiyun {
615*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
616*4882a593Smuzhiyun 
617*4882a593Smuzhiyun 	return pdata->phy_if.module_eeprom(pdata, eeprom, data);
618*4882a593Smuzhiyun }
619*4882a593Smuzhiyun 
xgbe_get_ringparam(struct net_device * netdev,struct ethtool_ringparam * ringparam)620*4882a593Smuzhiyun static void xgbe_get_ringparam(struct net_device *netdev,
621*4882a593Smuzhiyun 			       struct ethtool_ringparam *ringparam)
622*4882a593Smuzhiyun {
623*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
624*4882a593Smuzhiyun 
625*4882a593Smuzhiyun 	ringparam->rx_max_pending = XGBE_RX_DESC_CNT_MAX;
626*4882a593Smuzhiyun 	ringparam->tx_max_pending = XGBE_TX_DESC_CNT_MAX;
627*4882a593Smuzhiyun 	ringparam->rx_pending = pdata->rx_desc_count;
628*4882a593Smuzhiyun 	ringparam->tx_pending = pdata->tx_desc_count;
629*4882a593Smuzhiyun }
630*4882a593Smuzhiyun 
xgbe_set_ringparam(struct net_device * netdev,struct ethtool_ringparam * ringparam)631*4882a593Smuzhiyun static int xgbe_set_ringparam(struct net_device *netdev,
632*4882a593Smuzhiyun 			      struct ethtool_ringparam *ringparam)
633*4882a593Smuzhiyun {
634*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
635*4882a593Smuzhiyun 	unsigned int rx, tx;
636*4882a593Smuzhiyun 
637*4882a593Smuzhiyun 	if (ringparam->rx_mini_pending || ringparam->rx_jumbo_pending) {
638*4882a593Smuzhiyun 		netdev_err(netdev, "unsupported ring parameter\n");
639*4882a593Smuzhiyun 		return -EINVAL;
640*4882a593Smuzhiyun 	}
641*4882a593Smuzhiyun 
642*4882a593Smuzhiyun 	if ((ringparam->rx_pending < XGBE_RX_DESC_CNT_MIN) ||
643*4882a593Smuzhiyun 	    (ringparam->rx_pending > XGBE_RX_DESC_CNT_MAX)) {
644*4882a593Smuzhiyun 		netdev_err(netdev,
645*4882a593Smuzhiyun 			   "rx ring parameter must be between %u and %u\n",
646*4882a593Smuzhiyun 			   XGBE_RX_DESC_CNT_MIN, XGBE_RX_DESC_CNT_MAX);
647*4882a593Smuzhiyun 		return -EINVAL;
648*4882a593Smuzhiyun 	}
649*4882a593Smuzhiyun 
650*4882a593Smuzhiyun 	if ((ringparam->tx_pending < XGBE_TX_DESC_CNT_MIN) ||
651*4882a593Smuzhiyun 	    (ringparam->tx_pending > XGBE_TX_DESC_CNT_MAX)) {
652*4882a593Smuzhiyun 		netdev_err(netdev,
653*4882a593Smuzhiyun 			   "tx ring parameter must be between %u and %u\n",
654*4882a593Smuzhiyun 			   XGBE_TX_DESC_CNT_MIN, XGBE_TX_DESC_CNT_MAX);
655*4882a593Smuzhiyun 		return -EINVAL;
656*4882a593Smuzhiyun 	}
657*4882a593Smuzhiyun 
658*4882a593Smuzhiyun 	rx = __rounddown_pow_of_two(ringparam->rx_pending);
659*4882a593Smuzhiyun 	if (rx != ringparam->rx_pending)
660*4882a593Smuzhiyun 		netdev_notice(netdev,
661*4882a593Smuzhiyun 			      "rx ring parameter rounded to power of two: %u\n",
662*4882a593Smuzhiyun 			      rx);
663*4882a593Smuzhiyun 
664*4882a593Smuzhiyun 	tx = __rounddown_pow_of_two(ringparam->tx_pending);
665*4882a593Smuzhiyun 	if (tx != ringparam->tx_pending)
666*4882a593Smuzhiyun 		netdev_notice(netdev,
667*4882a593Smuzhiyun 			      "tx ring parameter rounded to power of two: %u\n",
668*4882a593Smuzhiyun 			      tx);
669*4882a593Smuzhiyun 
670*4882a593Smuzhiyun 	if ((rx == pdata->rx_desc_count) &&
671*4882a593Smuzhiyun 	    (tx == pdata->tx_desc_count))
672*4882a593Smuzhiyun 		goto out;
673*4882a593Smuzhiyun 
674*4882a593Smuzhiyun 	pdata->rx_desc_count = rx;
675*4882a593Smuzhiyun 	pdata->tx_desc_count = tx;
676*4882a593Smuzhiyun 
677*4882a593Smuzhiyun 	xgbe_restart_dev(pdata);
678*4882a593Smuzhiyun 
679*4882a593Smuzhiyun out:
680*4882a593Smuzhiyun 	return 0;
681*4882a593Smuzhiyun }
682*4882a593Smuzhiyun 
xgbe_get_channels(struct net_device * netdev,struct ethtool_channels * channels)683*4882a593Smuzhiyun static void xgbe_get_channels(struct net_device *netdev,
684*4882a593Smuzhiyun 			      struct ethtool_channels *channels)
685*4882a593Smuzhiyun {
686*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
687*4882a593Smuzhiyun 	unsigned int rx, tx, combined;
688*4882a593Smuzhiyun 
689*4882a593Smuzhiyun 	/* Calculate maximums allowed:
690*4882a593Smuzhiyun 	 *   - Take into account the number of available IRQs
691*4882a593Smuzhiyun 	 *   - Do not take into account the number of online CPUs so that
692*4882a593Smuzhiyun 	 *     the user can over-subscribe if desired
693*4882a593Smuzhiyun 	 *   - Tx is additionally limited by the number of hardware queues
694*4882a593Smuzhiyun 	 */
695*4882a593Smuzhiyun 	rx = min(pdata->hw_feat.rx_ch_cnt, pdata->rx_max_channel_count);
696*4882a593Smuzhiyun 	rx = min(rx, pdata->channel_irq_count);
697*4882a593Smuzhiyun 	tx = min(pdata->hw_feat.tx_ch_cnt, pdata->tx_max_channel_count);
698*4882a593Smuzhiyun 	tx = min(tx, pdata->channel_irq_count);
699*4882a593Smuzhiyun 	tx = min(tx, pdata->tx_max_q_count);
700*4882a593Smuzhiyun 
701*4882a593Smuzhiyun 	combined = min(rx, tx);
702*4882a593Smuzhiyun 
703*4882a593Smuzhiyun 	channels->max_combined = combined;
704*4882a593Smuzhiyun 	channels->max_rx = rx ? rx - 1 : 0;
705*4882a593Smuzhiyun 	channels->max_tx = tx ? tx - 1 : 0;
706*4882a593Smuzhiyun 
707*4882a593Smuzhiyun 	/* Get current settings based on device state */
708*4882a593Smuzhiyun 	rx = pdata->new_rx_ring_count ? : pdata->rx_ring_count;
709*4882a593Smuzhiyun 	tx = pdata->new_tx_ring_count ? : pdata->tx_ring_count;
710*4882a593Smuzhiyun 
711*4882a593Smuzhiyun 	combined = min(rx, tx);
712*4882a593Smuzhiyun 	rx -= combined;
713*4882a593Smuzhiyun 	tx -= combined;
714*4882a593Smuzhiyun 
715*4882a593Smuzhiyun 	channels->combined_count = combined;
716*4882a593Smuzhiyun 	channels->rx_count = rx;
717*4882a593Smuzhiyun 	channels->tx_count = tx;
718*4882a593Smuzhiyun }
719*4882a593Smuzhiyun 
xgbe_print_set_channels_input(struct net_device * netdev,struct ethtool_channels * channels)720*4882a593Smuzhiyun static void xgbe_print_set_channels_input(struct net_device *netdev,
721*4882a593Smuzhiyun 					  struct ethtool_channels *channels)
722*4882a593Smuzhiyun {
723*4882a593Smuzhiyun 	netdev_err(netdev, "channel inputs: combined=%u, rx-only=%u, tx-only=%u\n",
724*4882a593Smuzhiyun 		   channels->combined_count, channels->rx_count,
725*4882a593Smuzhiyun 		   channels->tx_count);
726*4882a593Smuzhiyun }
727*4882a593Smuzhiyun 
xgbe_set_channels(struct net_device * netdev,struct ethtool_channels * channels)728*4882a593Smuzhiyun static int xgbe_set_channels(struct net_device *netdev,
729*4882a593Smuzhiyun 			     struct ethtool_channels *channels)
730*4882a593Smuzhiyun {
731*4882a593Smuzhiyun 	struct xgbe_prv_data *pdata = netdev_priv(netdev);
732*4882a593Smuzhiyun 	unsigned int rx, rx_curr, tx, tx_curr, combined;
733*4882a593Smuzhiyun 
734*4882a593Smuzhiyun 	/* Calculate maximums allowed:
735*4882a593Smuzhiyun 	 *   - Take into account the number of available IRQs
736*4882a593Smuzhiyun 	 *   - Do not take into account the number of online CPUs so that
737*4882a593Smuzhiyun 	 *     the user can over-subscribe if desired
738*4882a593Smuzhiyun 	 *   - Tx is additionally limited by the number of hardware queues
739*4882a593Smuzhiyun 	 */
740*4882a593Smuzhiyun 	rx = min(pdata->hw_feat.rx_ch_cnt, pdata->rx_max_channel_count);
741*4882a593Smuzhiyun 	rx = min(rx, pdata->channel_irq_count);
742*4882a593Smuzhiyun 	tx = min(pdata->hw_feat.tx_ch_cnt, pdata->tx_max_channel_count);
743*4882a593Smuzhiyun 	tx = min(tx, pdata->tx_max_q_count);
744*4882a593Smuzhiyun 	tx = min(tx, pdata->channel_irq_count);
745*4882a593Smuzhiyun 
746*4882a593Smuzhiyun 	combined = min(rx, tx);
747*4882a593Smuzhiyun 
748*4882a593Smuzhiyun 	/* Should not be setting other count */
749*4882a593Smuzhiyun 	if (channels->other_count) {
750*4882a593Smuzhiyun 		netdev_err(netdev,
751*4882a593Smuzhiyun 			   "other channel count must be zero\n");
752*4882a593Smuzhiyun 		return -EINVAL;
753*4882a593Smuzhiyun 	}
754*4882a593Smuzhiyun 
755*4882a593Smuzhiyun 	/* Require at least one Combined (Rx and Tx) channel */
756*4882a593Smuzhiyun 	if (!channels->combined_count) {
757*4882a593Smuzhiyun 		netdev_err(netdev,
758*4882a593Smuzhiyun 			   "at least one combined Rx/Tx channel is required\n");
759*4882a593Smuzhiyun 		xgbe_print_set_channels_input(netdev, channels);
760*4882a593Smuzhiyun 		return -EINVAL;
761*4882a593Smuzhiyun 	}
762*4882a593Smuzhiyun 
763*4882a593Smuzhiyun 	/* Check combined channels */
764*4882a593Smuzhiyun 	if (channels->combined_count > combined) {
765*4882a593Smuzhiyun 		netdev_err(netdev,
766*4882a593Smuzhiyun 			   "combined channel count cannot exceed %u\n",
767*4882a593Smuzhiyun 			   combined);
768*4882a593Smuzhiyun 		xgbe_print_set_channels_input(netdev, channels);
769*4882a593Smuzhiyun 		return -EINVAL;
770*4882a593Smuzhiyun 	}
771*4882a593Smuzhiyun 
772*4882a593Smuzhiyun 	/* Can have some Rx-only or Tx-only channels, but not both */
773*4882a593Smuzhiyun 	if (channels->rx_count && channels->tx_count) {
774*4882a593Smuzhiyun 		netdev_err(netdev,
775*4882a593Smuzhiyun 			   "cannot specify both Rx-only and Tx-only channels\n");
776*4882a593Smuzhiyun 		xgbe_print_set_channels_input(netdev, channels);
777*4882a593Smuzhiyun 		return -EINVAL;
778*4882a593Smuzhiyun 	}
779*4882a593Smuzhiyun 
780*4882a593Smuzhiyun 	/* Check that we don't exceed the maximum number of channels */
781*4882a593Smuzhiyun 	if ((channels->combined_count + channels->rx_count) > rx) {
782*4882a593Smuzhiyun 		netdev_err(netdev,
783*4882a593Smuzhiyun 			   "total Rx channels (%u) requested exceeds maximum available (%u)\n",
784*4882a593Smuzhiyun 			   channels->combined_count + channels->rx_count, rx);
785*4882a593Smuzhiyun 		xgbe_print_set_channels_input(netdev, channels);
786*4882a593Smuzhiyun 		return -EINVAL;
787*4882a593Smuzhiyun 	}
788*4882a593Smuzhiyun 
789*4882a593Smuzhiyun 	if ((channels->combined_count + channels->tx_count) > tx) {
790*4882a593Smuzhiyun 		netdev_err(netdev,
791*4882a593Smuzhiyun 			   "total Tx channels (%u) requested exceeds maximum available (%u)\n",
792*4882a593Smuzhiyun 			   channels->combined_count + channels->tx_count, tx);
793*4882a593Smuzhiyun 		xgbe_print_set_channels_input(netdev, channels);
794*4882a593Smuzhiyun 		return -EINVAL;
795*4882a593Smuzhiyun 	}
796*4882a593Smuzhiyun 
797*4882a593Smuzhiyun 	rx = channels->combined_count + channels->rx_count;
798*4882a593Smuzhiyun 	tx = channels->combined_count + channels->tx_count;
799*4882a593Smuzhiyun 
800*4882a593Smuzhiyun 	rx_curr = pdata->new_rx_ring_count ? : pdata->rx_ring_count;
801*4882a593Smuzhiyun 	tx_curr = pdata->new_tx_ring_count ? : pdata->tx_ring_count;
802*4882a593Smuzhiyun 
803*4882a593Smuzhiyun 	if ((rx == rx_curr) && (tx == tx_curr))
804*4882a593Smuzhiyun 		goto out;
805*4882a593Smuzhiyun 
806*4882a593Smuzhiyun 	pdata->new_rx_ring_count = rx;
807*4882a593Smuzhiyun 	pdata->new_tx_ring_count = tx;
808*4882a593Smuzhiyun 
809*4882a593Smuzhiyun 	xgbe_full_restart_dev(pdata);
810*4882a593Smuzhiyun 
811*4882a593Smuzhiyun out:
812*4882a593Smuzhiyun 	return 0;
813*4882a593Smuzhiyun }
814*4882a593Smuzhiyun 
815*4882a593Smuzhiyun static const struct ethtool_ops xgbe_ethtool_ops = {
816*4882a593Smuzhiyun 	.supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS |
817*4882a593Smuzhiyun 				     ETHTOOL_COALESCE_MAX_FRAMES,
818*4882a593Smuzhiyun 	.get_drvinfo = xgbe_get_drvinfo,
819*4882a593Smuzhiyun 	.get_msglevel = xgbe_get_msglevel,
820*4882a593Smuzhiyun 	.set_msglevel = xgbe_set_msglevel,
821*4882a593Smuzhiyun 	.get_link = ethtool_op_get_link,
822*4882a593Smuzhiyun 	.get_coalesce = xgbe_get_coalesce,
823*4882a593Smuzhiyun 	.set_coalesce = xgbe_set_coalesce,
824*4882a593Smuzhiyun 	.get_pauseparam = xgbe_get_pauseparam,
825*4882a593Smuzhiyun 	.set_pauseparam = xgbe_set_pauseparam,
826*4882a593Smuzhiyun 	.get_strings = xgbe_get_strings,
827*4882a593Smuzhiyun 	.get_ethtool_stats = xgbe_get_ethtool_stats,
828*4882a593Smuzhiyun 	.get_sset_count = xgbe_get_sset_count,
829*4882a593Smuzhiyun 	.get_rxnfc = xgbe_get_rxnfc,
830*4882a593Smuzhiyun 	.get_rxfh_key_size = xgbe_get_rxfh_key_size,
831*4882a593Smuzhiyun 	.get_rxfh_indir_size = xgbe_get_rxfh_indir_size,
832*4882a593Smuzhiyun 	.get_rxfh = xgbe_get_rxfh,
833*4882a593Smuzhiyun 	.set_rxfh = xgbe_set_rxfh,
834*4882a593Smuzhiyun 	.get_ts_info = xgbe_get_ts_info,
835*4882a593Smuzhiyun 	.get_link_ksettings = xgbe_get_link_ksettings,
836*4882a593Smuzhiyun 	.set_link_ksettings = xgbe_set_link_ksettings,
837*4882a593Smuzhiyun 	.get_module_info = xgbe_get_module_info,
838*4882a593Smuzhiyun 	.get_module_eeprom = xgbe_get_module_eeprom,
839*4882a593Smuzhiyun 	.get_ringparam = xgbe_get_ringparam,
840*4882a593Smuzhiyun 	.set_ringparam = xgbe_set_ringparam,
841*4882a593Smuzhiyun 	.get_channels = xgbe_get_channels,
842*4882a593Smuzhiyun 	.set_channels = xgbe_set_channels,
843*4882a593Smuzhiyun };
844*4882a593Smuzhiyun 
xgbe_get_ethtool_ops(void)845*4882a593Smuzhiyun const struct ethtool_ops *xgbe_get_ethtool_ops(void)
846*4882a593Smuzhiyun {
847*4882a593Smuzhiyun 	return &xgbe_ethtool_ops;
848*4882a593Smuzhiyun }
849