blob: cea25acd5de2921a49e75cf6417dfe38313ec11a [file] [log] [blame]
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -05001/*
2 * AMD 10Gb Ethernet driver
3 *
4 * This file is available to you under your choice of the following two
5 * licenses:
6 *
7 * License 1: GPLv2
8 *
Lendacky, Thomas757e6aa2016-02-17 11:48:39 -06009 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -050010 *
11 * This file is free software; you may copy, redistribute and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or (at
14 * your option) any later version.
15 *
16 * This file is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * This file incorporates work covered by the following copyright and
25 * permission notice:
26 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
27 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
28 * Inc. unless otherwise expressly agreed to in writing between Synopsys
29 * and you.
30 *
31 * The Software IS NOT an item of Licensed Software or Licensed Product
32 * under any End User Software License Agreement or Agreement for Licensed
33 * Product with Synopsys or any supplement thereto. Permission is hereby
34 * granted, free of charge, to any person obtaining a copy of this software
35 * annotated with this license and the Software, to deal in the Software
36 * without restriction, including without limitation the rights to use,
37 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
38 * of the Software, and to permit persons to whom the Software is furnished
39 * to do so, subject to the following conditions:
40 *
41 * The above copyright notice and this permission notice shall be included
42 * in all copies or substantial portions of the Software.
43 *
44 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
45 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
48 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
49 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
50 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
54 * THE POSSIBILITY OF SUCH DAMAGE.
55 *
56 *
57 * License 2: Modified BSD
58 *
Lendacky, Thomas757e6aa2016-02-17 11:48:39 -060059 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -050060 * All rights reserved.
61 *
62 * Redistribution and use in source and binary forms, with or without
63 * modification, are permitted provided that the following conditions are met:
64 * * Redistributions of source code must retain the above copyright
65 * notice, this list of conditions and the following disclaimer.
66 * * Redistributions in binary form must reproduce the above copyright
67 * notice, this list of conditions and the following disclaimer in the
68 * documentation and/or other materials provided with the distribution.
69 * * Neither the name of Advanced Micro Devices, Inc. nor the
70 * names of its contributors may be used to endorse or promote products
71 * derived from this software without specific prior written permission.
72 *
73 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
74 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
75 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
76 * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
77 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83 *
84 * This file incorporates work covered by the following copyright and
85 * permission notice:
86 * The Synopsys DWC ETHER XGMAC Software Driver and documentation
87 * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
88 * Inc. unless otherwise expressly agreed to in writing between Synopsys
89 * and you.
90 *
91 * The Software IS NOT an item of Licensed Software or Licensed Product
92 * under any End User Software License Agreement or Agreement for Licensed
93 * Product with Synopsys or any supplement thereto. Permission is hereby
94 * granted, free of charge, to any person obtaining a copy of this software
95 * annotated with this license and the Software, to deal in the Software
96 * without restriction, including without limitation the rights to use,
97 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98 * of the Software, and to permit persons to whom the Software is furnished
99 * to do so, subject to the following conditions:
100 *
101 * The above copyright notice and this permission notice shall be included
102 * in all copies or substantial portions of the Software.
103 *
104 * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
105 * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
106 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
107 * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
108 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
109 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
110 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
111 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
112 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
113 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
114 * THE POSSIBILITY OF SUCH DAMAGE.
115 */
116
117#include <linux/spinlock.h>
118#include <linux/phy.h>
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500119#include <linux/net_tstamp.h>
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500120
121#include "xgbe.h"
122#include "xgbe-common.h"
123
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500124struct xgbe_stats {
125 char stat_string[ETH_GSTRING_LEN];
126 int stat_size;
127 int stat_offset;
128};
129
130#define XGMAC_MMC_STAT(_string, _var) \
131 { _string, \
132 FIELD_SIZEOF(struct xgbe_mmc_stats, _var), \
133 offsetof(struct xgbe_prv_data, mmc_stats._var), \
134 }
135
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -0500136#define XGMAC_EXT_STAT(_string, _var) \
137 { _string, \
138 FIELD_SIZEOF(struct xgbe_ext_stats, _var), \
139 offsetof(struct xgbe_prv_data, ext_stats._var), \
140 }
141
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500142static const struct xgbe_stats xgbe_gstring_stats[] = {
143 XGMAC_MMC_STAT("tx_bytes", txoctetcount_gb),
144 XGMAC_MMC_STAT("tx_packets", txframecount_gb),
145 XGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb),
146 XGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb),
147 XGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb),
148 XGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g),
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -0500149 XGMAC_EXT_STAT("tx_tso_packets", tx_tso_packets),
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500150 XGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb),
151 XGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb),
152 XGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb),
153 XGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb),
154 XGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb),
155 XGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb),
156 XGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror),
157 XGMAC_MMC_STAT("tx_pause_frames", txpauseframes),
158
159 XGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb),
160 XGMAC_MMC_STAT("rx_packets", rxframecount_gb),
161 XGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g),
162 XGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g),
163 XGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g),
164 XGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb),
165 XGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb),
166 XGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb),
167 XGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb),
168 XGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb),
169 XGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb),
170 XGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb),
171 XGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g),
172 XGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g),
173 XGMAC_MMC_STAT("rx_crc_errors", rxcrcerror),
174 XGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror),
175 XGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror),
176 XGMAC_MMC_STAT("rx_length_errors", rxlengtherror),
177 XGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype),
178 XGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow),
179 XGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror),
180 XGMAC_MMC_STAT("rx_pause_frames", rxpauseframes),
Lendacky, Thomas5452b2d2015-05-14 11:43:57 -0500181 XGMAC_EXT_STAT("rx_split_header_packets", rx_split_header_packets),
Lendacky, Thomas72c9ac42015-09-30 08:53:10 -0500182 XGMAC_EXT_STAT("rx_buffer_unavailable", rx_buffer_unavailable),
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500183};
Lendacky, Thomasa2ea14d2014-09-03 12:14:33 -0500184
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500185#define XGBE_STATS_COUNT ARRAY_SIZE(xgbe_gstring_stats)
186
187static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
188{
Lendacky, Thomas80a788c2017-08-18 09:03:35 -0500189 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500190 int i;
191
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500192 switch (stringset) {
193 case ETH_SS_STATS:
194 for (i = 0; i < XGBE_STATS_COUNT; i++) {
195 memcpy(data, xgbe_gstring_stats[i].stat_string,
196 ETH_GSTRING_LEN);
197 data += ETH_GSTRING_LEN;
198 }
Lendacky, Thomas80a788c2017-08-18 09:03:35 -0500199 for (i = 0; i < pdata->tx_ring_count; i++) {
200 sprintf(data, "txq_%u_packets", i);
201 data += ETH_GSTRING_LEN;
202 sprintf(data, "txq_%u_bytes", i);
203 data += ETH_GSTRING_LEN;
204 }
205 for (i = 0; i < pdata->rx_ring_count; i++) {
206 sprintf(data, "rxq_%u_packets", i);
207 data += ETH_GSTRING_LEN;
208 sprintf(data, "rxq_%u_bytes", i);
209 data += ETH_GSTRING_LEN;
210 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500211 break;
212 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500213}
214
215static void xgbe_get_ethtool_stats(struct net_device *netdev,
216 struct ethtool_stats *stats, u64 *data)
217{
218 struct xgbe_prv_data *pdata = netdev_priv(netdev);
219 u8 *stat;
220 int i;
221
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500222 pdata->hw_if.read_mmc_stats(pdata);
223 for (i = 0; i < XGBE_STATS_COUNT; i++) {
224 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
225 *data++ = *(u64 *)stat;
226 }
Lendacky, Thomas80a788c2017-08-18 09:03:35 -0500227 for (i = 0; i < pdata->tx_ring_count; i++) {
228 *data++ = pdata->ext_stats.txq_packets[i];
229 *data++ = pdata->ext_stats.txq_bytes[i];
230 }
231 for (i = 0; i < pdata->rx_ring_count; i++) {
232 *data++ = pdata->ext_stats.rxq_packets[i];
233 *data++ = pdata->ext_stats.rxq_bytes[i];
234 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500235}
236
237static int xgbe_get_sset_count(struct net_device *netdev, int stringset)
238{
Lendacky, Thomas80a788c2017-08-18 09:03:35 -0500239 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500240 int ret;
241
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500242 switch (stringset) {
243 case ETH_SS_STATS:
Lendacky, Thomas80a788c2017-08-18 09:03:35 -0500244 ret = XGBE_STATS_COUNT +
245 (pdata->tx_ring_count * 2) +
246 (pdata->rx_ring_count * 2);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500247 break;
248
249 default:
250 ret = -EOPNOTSUPP;
251 }
252
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500253 return ret;
254}
255
256static void xgbe_get_pauseparam(struct net_device *netdev,
257 struct ethtool_pauseparam *pause)
258{
259 struct xgbe_prv_data *pdata = netdev_priv(netdev);
260
Lendacky, Thomasc1ce2f72015-05-14 11:44:27 -0500261 pause->autoneg = pdata->phy.pause_autoneg;
262 pause->tx_pause = pdata->phy.tx_pause;
263 pause->rx_pause = pdata->phy.rx_pause;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500264}
265
266static int xgbe_set_pauseparam(struct net_device *netdev,
267 struct ethtool_pauseparam *pause)
268{
269 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500270 struct ethtool_link_ksettings *lks = &pdata->phy.lks;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500271 int ret = 0;
272
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500273 if (pause->autoneg && (pdata->phy.autoneg != AUTONEG_ENABLE)) {
274 netdev_err(netdev,
Colin Ian Kingbeef8512017-06-28 17:51:10 +0100275 "autoneg disabled, pause autoneg not available\n");
Lendacky, Thomasc1ce2f72015-05-14 11:44:27 -0500276 return -EINVAL;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500277 }
Lendacky, Thomasc1ce2f72015-05-14 11:44:27 -0500278
279 pdata->phy.pause_autoneg = pause->autoneg;
280 pdata->phy.tx_pause = pause->tx_pause;
281 pdata->phy.rx_pause = pause->rx_pause;
282
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500283 XGBE_CLR_ADV(lks, Pause);
284 XGBE_CLR_ADV(lks, Asym_Pause);
Lendacky, Thomasc1ce2f72015-05-14 11:44:27 -0500285
286 if (pause->rx_pause) {
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500287 XGBE_SET_ADV(lks, Pause);
288 XGBE_SET_ADV(lks, Asym_Pause);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500289 }
290
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500291 if (pause->tx_pause) {
292 /* Equivalent to XOR of Asym_Pause */
293 if (XGBE_ADV(lks, Asym_Pause))
294 XGBE_CLR_ADV(lks, Asym_Pause);
295 else
296 XGBE_SET_ADV(lks, Asym_Pause);
297 }
Lendacky, Thomasc1ce2f72015-05-14 11:44:27 -0500298
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500299 if (netif_running(netdev))
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500300 ret = pdata->phy_if.phy_config_aneg(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500301
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500302 return ret;
303}
304
Philippe Reynes90fdd042016-11-06 14:57:04 +0100305static int xgbe_get_link_ksettings(struct net_device *netdev,
306 struct ethtool_link_ksettings *cmd)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500307{
308 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500309 struct ethtool_link_ksettings *lks = &pdata->phy.lks;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500310
Philippe Reynes90fdd042016-11-06 14:57:04 +0100311 cmd->base.phy_address = pdata->phy.address;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500312
Philippe Reynes90fdd042016-11-06 14:57:04 +0100313 cmd->base.autoneg = pdata->phy.autoneg;
314 cmd->base.speed = pdata->phy.speed;
315 cmd->base.duplex = pdata->phy.duplex;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500316
Philippe Reynes90fdd042016-11-06 14:57:04 +0100317 cmd->base.port = PORT_NONE;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500318
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500319 XGBE_LM_COPY(cmd, supported, lks, supported);
320 XGBE_LM_COPY(cmd, advertising, lks, advertising);
321 XGBE_LM_COPY(cmd, lp_advertising, lks, lp_advertising);
322
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500323 return 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500324}
325
Philippe Reynes90fdd042016-11-06 14:57:04 +0100326static int xgbe_set_link_ksettings(struct net_device *netdev,
327 const struct ethtool_link_ksettings *cmd)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500328{
329 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500330 struct ethtool_link_ksettings *lks = &pdata->phy.lks;
331 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500332 u32 speed;
333 int ret;
334
Philippe Reynes90fdd042016-11-06 14:57:04 +0100335 speed = cmd->base.speed;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500336
Philippe Reynes90fdd042016-11-06 14:57:04 +0100337 if (cmd->base.phy_address != pdata->phy.address) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500338 netdev_err(netdev, "invalid phy address %hhu\n",
Philippe Reynes90fdd042016-11-06 14:57:04 +0100339 cmd->base.phy_address);
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500340 return -EINVAL;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500341 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500342
Philippe Reynes90fdd042016-11-06 14:57:04 +0100343 if ((cmd->base.autoneg != AUTONEG_ENABLE) &&
344 (cmd->base.autoneg != AUTONEG_DISABLE)) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500345 netdev_err(netdev, "unsupported autoneg %hhu\n",
Philippe Reynes90fdd042016-11-06 14:57:04 +0100346 cmd->base.autoneg);
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500347 return -EINVAL;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500348 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500349
Philippe Reynes90fdd042016-11-06 14:57:04 +0100350 if (cmd->base.autoneg == AUTONEG_DISABLE) {
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500351 if (!pdata->phy_if.phy_valid_speed(pdata, speed)) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500352 netdev_err(netdev, "unsupported speed %u\n", speed);
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500353 return -EINVAL;
Lendacky, Thomasf0476042014-07-29 08:57:25 -0500354 }
355
Philippe Reynes90fdd042016-11-06 14:57:04 +0100356 if (cmd->base.duplex != DUPLEX_FULL) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500357 netdev_err(netdev, "unsupported duplex %hhu\n",
Philippe Reynes90fdd042016-11-06 14:57:04 +0100358 cmd->base.duplex);
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500359 return -EINVAL;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500360 }
Lendacky, Thomasf0476042014-07-29 08:57:25 -0500361 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500362
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500363 netif_dbg(pdata, link, netdev,
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500364 "requested advertisement 0x%*pb, phy supported 0x%*pb\n",
365 __ETHTOOL_LINK_MODE_MASK_NBITS, cmd->link_modes.advertising,
366 __ETHTOOL_LINK_MODE_MASK_NBITS, lks->link_modes.supported);
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500367
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500368 bitmap_and(advertising,
369 cmd->link_modes.advertising, lks->link_modes.supported,
370 __ETHTOOL_LINK_MODE_MASK_NBITS);
371
372 if ((cmd->base.autoneg == AUTONEG_ENABLE) &&
373 bitmap_empty(advertising, __ETHTOOL_LINK_MODE_MASK_NBITS)) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500374 netdev_err(netdev,
375 "unsupported requested advertisement\n");
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500376 return -EINVAL;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500377 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500378
379 ret = 0;
Philippe Reynes90fdd042016-11-06 14:57:04 +0100380 pdata->phy.autoneg = cmd->base.autoneg;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500381 pdata->phy.speed = speed;
Philippe Reynes90fdd042016-11-06 14:57:04 +0100382 pdata->phy.duplex = cmd->base.duplex;
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500383 bitmap_copy(lks->link_modes.advertising, advertising,
384 __ETHTOOL_LINK_MODE_MASK_NBITS);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500385
Philippe Reynes90fdd042016-11-06 14:57:04 +0100386 if (cmd->base.autoneg == AUTONEG_ENABLE)
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500387 XGBE_SET_ADV(lks, Autoneg);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500388 else
Lendacky, Thomas85f9feb2017-08-18 09:03:55 -0500389 XGBE_CLR_ADV(lks, Autoneg);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500390
391 if (netif_running(netdev))
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500392 ret = pdata->phy_if.phy_config_aneg(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500393
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500394 return ret;
395}
396
397static void xgbe_get_drvinfo(struct net_device *netdev,
398 struct ethtool_drvinfo *drvinfo)
399{
400 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -0500401 struct xgbe_hw_features *hw_feat = &pdata->hw_feat;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500402
403 strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver));
404 strlcpy(drvinfo->version, XGBE_DRV_VERSION, sizeof(drvinfo->version));
405 strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
406 sizeof(drvinfo->bus_info));
407 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d",
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -0500408 XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
409 XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
410 XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500411}
412
Lendacky, Thomas349fb2d72015-09-30 08:52:51 -0500413static u32 xgbe_get_msglevel(struct net_device *netdev)
414{
415 struct xgbe_prv_data *pdata = netdev_priv(netdev);
416
417 return pdata->msg_enable;
418}
419
420static void xgbe_set_msglevel(struct net_device *netdev, u32 msglevel)
421{
422 struct xgbe_prv_data *pdata = netdev_priv(netdev);
423
424 pdata->msg_enable = msglevel;
425}
426
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500427static int xgbe_get_coalesce(struct net_device *netdev,
428 struct ethtool_coalesce *ec)
429{
430 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500431
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500432 memset(ec, 0, sizeof(struct ethtool_coalesce));
433
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500434 ec->rx_coalesce_usecs = pdata->rx_usecs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500435 ec->rx_max_coalesced_frames = pdata->rx_frames;
436
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500437 ec->tx_max_coalesced_frames = pdata->tx_frames;
438
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500439 return 0;
440}
441
442static int xgbe_set_coalesce(struct net_device *netdev,
443 struct ethtool_coalesce *ec)
444{
445 struct xgbe_prv_data *pdata = netdev_priv(netdev);
446 struct xgbe_hw_if *hw_if = &pdata->hw_if;
447 unsigned int rx_frames, rx_riwt, rx_usecs;
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -0500448 unsigned int tx_frames;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500449
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500450 /* Check for not supported parameters */
451 if ((ec->rx_coalesce_usecs_irq) ||
452 (ec->rx_max_coalesced_frames_irq) ||
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -0500453 (ec->tx_coalesce_usecs) ||
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500454 (ec->tx_coalesce_usecs_irq) ||
455 (ec->tx_max_coalesced_frames_irq) ||
456 (ec->stats_block_coalesce_usecs) ||
457 (ec->use_adaptive_rx_coalesce) ||
458 (ec->use_adaptive_tx_coalesce) ||
459 (ec->pkt_rate_low) ||
460 (ec->rx_coalesce_usecs_low) ||
461 (ec->rx_max_coalesced_frames_low) ||
462 (ec->tx_coalesce_usecs_low) ||
463 (ec->tx_max_coalesced_frames_low) ||
464 (ec->pkt_rate_high) ||
465 (ec->rx_coalesce_usecs_high) ||
466 (ec->rx_max_coalesced_frames_high) ||
467 (ec->tx_coalesce_usecs_high) ||
468 (ec->tx_max_coalesced_frames_high) ||
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500469 (ec->rate_sample_interval)) {
470 netdev_err(netdev, "unsupported coalescing parameter\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500471 return -EOPNOTSUPP;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500472 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500473
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500474 rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs);
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500475 rx_usecs = ec->rx_coalesce_usecs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500476 rx_frames = ec->rx_max_coalesced_frames;
477
478 /* Use smallest possible value if conversion resulted in zero */
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500479 if (rx_usecs && !rx_riwt)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500480 rx_riwt = 1;
481
482 /* Check the bounds of values for Rx */
483 if (rx_riwt > XGMAC_MAX_DMA_RIWT) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500484 netdev_err(netdev, "rx-usec is limited to %d usecs\n",
485 hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500486 return -EINVAL;
487 }
Lendacky, Thomas4780b7c2014-11-04 16:06:26 -0600488 if (rx_frames > pdata->rx_desc_count) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500489 netdev_err(netdev, "rx-frames is limited to %d frames\n",
490 pdata->rx_desc_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500491 return -EINVAL;
492 }
493
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500494 tx_frames = ec->tx_max_coalesced_frames;
495
496 /* Check the bounds of values for Tx */
Lendacky, Thomas4780b7c2014-11-04 16:06:26 -0600497 if (tx_frames > pdata->tx_desc_count) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500498 netdev_err(netdev, "tx-frames is limited to %d frames\n",
499 pdata->tx_desc_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500500 return -EINVAL;
501 }
502
503 pdata->rx_riwt = rx_riwt;
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500504 pdata->rx_usecs = rx_usecs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500505 pdata->rx_frames = rx_frames;
506 hw_if->config_rx_coalesce(pdata);
507
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500508 pdata->tx_frames = tx_frames;
509 hw_if->config_tx_coalesce(pdata);
510
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500511 return 0;
512}
513
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600514static int xgbe_get_rxnfc(struct net_device *netdev,
515 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
516{
517 struct xgbe_prv_data *pdata = netdev_priv(netdev);
518
519 switch (rxnfc->cmd) {
520 case ETHTOOL_GRXRINGS:
521 rxnfc->data = pdata->rx_ring_count;
522 break;
523 default:
524 return -EOPNOTSUPP;
525 }
526
527 return 0;
528}
529
530static u32 xgbe_get_rxfh_key_size(struct net_device *netdev)
531{
532 struct xgbe_prv_data *pdata = netdev_priv(netdev);
533
534 return sizeof(pdata->rss_key);
535}
536
537static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
538{
539 struct xgbe_prv_data *pdata = netdev_priv(netdev);
540
541 return ARRAY_SIZE(pdata->rss_table);
542}
543
Eyal Perry892311f2014-12-02 18:12:10 +0200544static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
545 u8 *hfunc)
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600546{
547 struct xgbe_prv_data *pdata = netdev_priv(netdev);
548 unsigned int i;
549
550 if (indir) {
551 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
552 indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
553 MAC_RSSDR, DMCH);
554 }
555
556 if (key)
557 memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
558
Eyal Perry892311f2014-12-02 18:12:10 +0200559 if (hfunc)
560 *hfunc = ETH_RSS_HASH_TOP;
561
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600562 return 0;
563}
564
565static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
Eyal Perry892311f2014-12-02 18:12:10 +0200566 const u8 *key, const u8 hfunc)
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600567{
568 struct xgbe_prv_data *pdata = netdev_priv(netdev);
569 struct xgbe_hw_if *hw_if = &pdata->hw_if;
570 unsigned int ret;
571
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500572 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) {
573 netdev_err(netdev, "unsupported hash function\n");
Eyal Perry892311f2014-12-02 18:12:10 +0200574 return -EOPNOTSUPP;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500575 }
Eyal Perry892311f2014-12-02 18:12:10 +0200576
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600577 if (indir) {
578 ret = hw_if->set_rss_lookup_table(pdata, indir);
579 if (ret)
580 return ret;
581 }
582
583 if (key) {
584 ret = hw_if->set_rss_hash_key(pdata, key);
585 if (ret)
586 return ret;
587 }
588
589 return 0;
590}
591
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500592static int xgbe_get_ts_info(struct net_device *netdev,
593 struct ethtool_ts_info *ts_info)
594{
595 struct xgbe_prv_data *pdata = netdev_priv(netdev);
596
597 ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
598 SOF_TIMESTAMPING_RX_SOFTWARE |
599 SOF_TIMESTAMPING_SOFTWARE |
600 SOF_TIMESTAMPING_TX_HARDWARE |
601 SOF_TIMESTAMPING_RX_HARDWARE |
602 SOF_TIMESTAMPING_RAW_HARDWARE;
603
604 if (pdata->ptp_clock)
605 ts_info->phc_index = ptp_clock_index(pdata->ptp_clock);
606 else
607 ts_info->phc_index = -1;
608
609 ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
610 ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
611 (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
612 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
613 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
614 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
615 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
616 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
617 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
618 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
619 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
620 (1 << HWTSTAMP_FILTER_ALL);
621
622 return 0;
623}
624
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500625static const struct ethtool_ops xgbe_ethtool_ops = {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500626 .get_drvinfo = xgbe_get_drvinfo,
Lendacky, Thomas349fb2d72015-09-30 08:52:51 -0500627 .get_msglevel = xgbe_get_msglevel,
628 .set_msglevel = xgbe_set_msglevel,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500629 .get_link = ethtool_op_get_link,
630 .get_coalesce = xgbe_get_coalesce,
631 .set_coalesce = xgbe_set_coalesce,
632 .get_pauseparam = xgbe_get_pauseparam,
633 .set_pauseparam = xgbe_set_pauseparam,
634 .get_strings = xgbe_get_strings,
635 .get_ethtool_stats = xgbe_get_ethtool_stats,
636 .get_sset_count = xgbe_get_sset_count,
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600637 .get_rxnfc = xgbe_get_rxnfc,
638 .get_rxfh_key_size = xgbe_get_rxfh_key_size,
639 .get_rxfh_indir_size = xgbe_get_rxfh_indir_size,
640 .get_rxfh = xgbe_get_rxfh,
641 .set_rxfh = xgbe_set_rxfh,
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500642 .get_ts_info = xgbe_get_ts_info,
Philippe Reynes90fdd042016-11-06 14:57:04 +0100643 .get_link_ksettings = xgbe_get_link_ksettings,
644 .set_link_ksettings = xgbe_set_link_ksettings,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500645};
646
stephen hemmingerce0b15d2016-08-31 08:57:36 -0700647const struct ethtool_ops *xgbe_get_ethtool_ops(void)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500648{
stephen hemmingerce0b15d2016-08-31 08:57:36 -0700649 return &xgbe_ethtool_ops;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500650}