blob: 46c959b994a79fe31e6df62fcf69564237026c2c [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{
189 int i;
190
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500191 switch (stringset) {
192 case ETH_SS_STATS:
193 for (i = 0; i < XGBE_STATS_COUNT; i++) {
194 memcpy(data, xgbe_gstring_stats[i].stat_string,
195 ETH_GSTRING_LEN);
196 data += ETH_GSTRING_LEN;
197 }
198 break;
199 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500200}
201
202static void xgbe_get_ethtool_stats(struct net_device *netdev,
203 struct ethtool_stats *stats, u64 *data)
204{
205 struct xgbe_prv_data *pdata = netdev_priv(netdev);
206 u8 *stat;
207 int i;
208
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500209 pdata->hw_if.read_mmc_stats(pdata);
210 for (i = 0; i < XGBE_STATS_COUNT; i++) {
211 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
212 *data++ = *(u64 *)stat;
213 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500214}
215
216static int xgbe_get_sset_count(struct net_device *netdev, int stringset)
217{
218 int ret;
219
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500220 switch (stringset) {
221 case ETH_SS_STATS:
222 ret = XGBE_STATS_COUNT;
223 break;
224
225 default:
226 ret = -EOPNOTSUPP;
227 }
228
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500229 return ret;
230}
231
232static void xgbe_get_pauseparam(struct net_device *netdev,
233 struct ethtool_pauseparam *pause)
234{
235 struct xgbe_prv_data *pdata = netdev_priv(netdev);
236
Lendacky, Thomasc1ce2f72015-05-14 11:44:27 -0500237 pause->autoneg = pdata->phy.pause_autoneg;
238 pause->tx_pause = pdata->phy.tx_pause;
239 pause->rx_pause = pdata->phy.rx_pause;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500240}
241
242static int xgbe_set_pauseparam(struct net_device *netdev,
243 struct ethtool_pauseparam *pause)
244{
245 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500246 int ret = 0;
247
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500248 if (pause->autoneg && (pdata->phy.autoneg != AUTONEG_ENABLE)) {
249 netdev_err(netdev,
250 "autoneg disabled, pause autoneg not avialable\n");
Lendacky, Thomasc1ce2f72015-05-14 11:44:27 -0500251 return -EINVAL;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500252 }
Lendacky, Thomasc1ce2f72015-05-14 11:44:27 -0500253
254 pdata->phy.pause_autoneg = pause->autoneg;
255 pdata->phy.tx_pause = pause->tx_pause;
256 pdata->phy.rx_pause = pause->rx_pause;
257
258 pdata->phy.advertising &= ~ADVERTISED_Pause;
259 pdata->phy.advertising &= ~ADVERTISED_Asym_Pause;
260
261 if (pause->rx_pause) {
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500262 pdata->phy.advertising |= ADVERTISED_Pause;
263 pdata->phy.advertising |= ADVERTISED_Asym_Pause;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500264 }
265
Lendacky, Thomasc1ce2f72015-05-14 11:44:27 -0500266 if (pause->tx_pause)
267 pdata->phy.advertising ^= ADVERTISED_Asym_Pause;
268
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500269 if (netif_running(netdev))
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500270 ret = pdata->phy_if.phy_config_aneg(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500271
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500272 return ret;
273}
274
275static int xgbe_get_settings(struct net_device *netdev,
276 struct ethtool_cmd *cmd)
277{
278 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500279
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500280 cmd->phy_address = pdata->phy.address;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500281
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500282 cmd->supported = pdata->phy.supported;
283 cmd->advertising = pdata->phy.advertising;
284 cmd->lp_advertising = pdata->phy.lp_advertising;
285
286 cmd->autoneg = pdata->phy.autoneg;
287 ethtool_cmd_speed_set(cmd, pdata->phy.speed);
288 cmd->duplex = pdata->phy.duplex;
289
290 cmd->port = PORT_NONE;
291 cmd->transceiver = XCVR_INTERNAL;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500292
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500293 return 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500294}
295
296static int xgbe_set_settings(struct net_device *netdev,
297 struct ethtool_cmd *cmd)
298{
299 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500300 u32 speed;
301 int ret;
302
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500303 speed = ethtool_cmd_speed(cmd);
304
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500305 if (cmd->phy_address != pdata->phy.address) {
306 netdev_err(netdev, "invalid phy address %hhu\n",
307 cmd->phy_address);
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500308 return -EINVAL;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500309 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500310
311 if ((cmd->autoneg != AUTONEG_ENABLE) &&
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500312 (cmd->autoneg != AUTONEG_DISABLE)) {
313 netdev_err(netdev, "unsupported autoneg %hhu\n",
314 cmd->autoneg);
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500315 return -EINVAL;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500316 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500317
Lendacky, Thomasf0476042014-07-29 08:57:25 -0500318 if (cmd->autoneg == AUTONEG_DISABLE) {
Lendacky, Thomase57f7a32016-11-03 13:18:27 -0500319 if (!pdata->phy_if.phy_valid_speed(pdata, speed)) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500320 netdev_err(netdev, "unsupported speed %u\n", speed);
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500321 return -EINVAL;
Lendacky, Thomasf0476042014-07-29 08:57:25 -0500322 }
323
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500324 if (cmd->duplex != DUPLEX_FULL) {
325 netdev_err(netdev, "unsupported duplex %hhu\n",
326 cmd->duplex);
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500327 return -EINVAL;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500328 }
Lendacky, Thomasf0476042014-07-29 08:57:25 -0500329 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500330
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500331 netif_dbg(pdata, link, netdev,
332 "requested advertisement %#x, phy supported %#x\n",
333 cmd->advertising, pdata->phy.supported);
334
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500335 cmd->advertising &= pdata->phy.supported;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500336 if ((cmd->autoneg == AUTONEG_ENABLE) && !cmd->advertising) {
337 netdev_err(netdev,
338 "unsupported requested advertisement\n");
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500339 return -EINVAL;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500340 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500341
342 ret = 0;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500343 pdata->phy.autoneg = cmd->autoneg;
344 pdata->phy.speed = speed;
345 pdata->phy.duplex = cmd->duplex;
346 pdata->phy.advertising = cmd->advertising;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500347
348 if (cmd->autoneg == AUTONEG_ENABLE)
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500349 pdata->phy.advertising |= ADVERTISED_Autoneg;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500350 else
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500351 pdata->phy.advertising &= ~ADVERTISED_Autoneg;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500352
353 if (netif_running(netdev))
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500354 ret = pdata->phy_if.phy_config_aneg(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500355
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500356 return ret;
357}
358
359static void xgbe_get_drvinfo(struct net_device *netdev,
360 struct ethtool_drvinfo *drvinfo)
361{
362 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -0500363 struct xgbe_hw_features *hw_feat = &pdata->hw_feat;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500364
365 strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver));
366 strlcpy(drvinfo->version, XGBE_DRV_VERSION, sizeof(drvinfo->version));
367 strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
368 sizeof(drvinfo->bus_info));
369 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d",
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -0500370 XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
371 XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
372 XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500373}
374
Lendacky, Thomas349fb2d72015-09-30 08:52:51 -0500375static u32 xgbe_get_msglevel(struct net_device *netdev)
376{
377 struct xgbe_prv_data *pdata = netdev_priv(netdev);
378
379 return pdata->msg_enable;
380}
381
382static void xgbe_set_msglevel(struct net_device *netdev, u32 msglevel)
383{
384 struct xgbe_prv_data *pdata = netdev_priv(netdev);
385
386 pdata->msg_enable = msglevel;
387}
388
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500389static int xgbe_get_coalesce(struct net_device *netdev,
390 struct ethtool_coalesce *ec)
391{
392 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500393
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500394 memset(ec, 0, sizeof(struct ethtool_coalesce));
395
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500396 ec->rx_coalesce_usecs = pdata->rx_usecs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500397 ec->rx_max_coalesced_frames = pdata->rx_frames;
398
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500399 ec->tx_max_coalesced_frames = pdata->tx_frames;
400
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500401 return 0;
402}
403
404static int xgbe_set_coalesce(struct net_device *netdev,
405 struct ethtool_coalesce *ec)
406{
407 struct xgbe_prv_data *pdata = netdev_priv(netdev);
408 struct xgbe_hw_if *hw_if = &pdata->hw_if;
409 unsigned int rx_frames, rx_riwt, rx_usecs;
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -0500410 unsigned int tx_frames;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500411
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500412 /* Check for not supported parameters */
413 if ((ec->rx_coalesce_usecs_irq) ||
414 (ec->rx_max_coalesced_frames_irq) ||
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -0500415 (ec->tx_coalesce_usecs) ||
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500416 (ec->tx_coalesce_usecs_irq) ||
417 (ec->tx_max_coalesced_frames_irq) ||
418 (ec->stats_block_coalesce_usecs) ||
419 (ec->use_adaptive_rx_coalesce) ||
420 (ec->use_adaptive_tx_coalesce) ||
421 (ec->pkt_rate_low) ||
422 (ec->rx_coalesce_usecs_low) ||
423 (ec->rx_max_coalesced_frames_low) ||
424 (ec->tx_coalesce_usecs_low) ||
425 (ec->tx_max_coalesced_frames_low) ||
426 (ec->pkt_rate_high) ||
427 (ec->rx_coalesce_usecs_high) ||
428 (ec->rx_max_coalesced_frames_high) ||
429 (ec->tx_coalesce_usecs_high) ||
430 (ec->tx_max_coalesced_frames_high) ||
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500431 (ec->rate_sample_interval)) {
432 netdev_err(netdev, "unsupported coalescing parameter\n");
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500433 return -EOPNOTSUPP;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500434 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500435
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500436 rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs);
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500437 rx_usecs = ec->rx_coalesce_usecs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500438 rx_frames = ec->rx_max_coalesced_frames;
439
440 /* Use smallest possible value if conversion resulted in zero */
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500441 if (rx_usecs && !rx_riwt)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500442 rx_riwt = 1;
443
444 /* Check the bounds of values for Rx */
445 if (rx_riwt > XGMAC_MAX_DMA_RIWT) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500446 netdev_err(netdev, "rx-usec is limited to %d usecs\n",
447 hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500448 return -EINVAL;
449 }
Lendacky, Thomas4780b7c2014-11-04 16:06:26 -0600450 if (rx_frames > pdata->rx_desc_count) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500451 netdev_err(netdev, "rx-frames is limited to %d frames\n",
452 pdata->rx_desc_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500453 return -EINVAL;
454 }
455
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500456 tx_frames = ec->tx_max_coalesced_frames;
457
458 /* Check the bounds of values for Tx */
Lendacky, Thomas4780b7c2014-11-04 16:06:26 -0600459 if (tx_frames > pdata->tx_desc_count) {
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500460 netdev_err(netdev, "tx-frames is limited to %d frames\n",
461 pdata->tx_desc_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500462 return -EINVAL;
463 }
464
465 pdata->rx_riwt = rx_riwt;
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500466 pdata->rx_usecs = rx_usecs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500467 pdata->rx_frames = rx_frames;
468 hw_if->config_rx_coalesce(pdata);
469
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500470 pdata->tx_frames = tx_frames;
471 hw_if->config_tx_coalesce(pdata);
472
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500473 return 0;
474}
475
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600476static int xgbe_get_rxnfc(struct net_device *netdev,
477 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
478{
479 struct xgbe_prv_data *pdata = netdev_priv(netdev);
480
481 switch (rxnfc->cmd) {
482 case ETHTOOL_GRXRINGS:
483 rxnfc->data = pdata->rx_ring_count;
484 break;
485 default:
486 return -EOPNOTSUPP;
487 }
488
489 return 0;
490}
491
492static u32 xgbe_get_rxfh_key_size(struct net_device *netdev)
493{
494 struct xgbe_prv_data *pdata = netdev_priv(netdev);
495
496 return sizeof(pdata->rss_key);
497}
498
499static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
500{
501 struct xgbe_prv_data *pdata = netdev_priv(netdev);
502
503 return ARRAY_SIZE(pdata->rss_table);
504}
505
Eyal Perry892311f2014-12-02 18:12:10 +0200506static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
507 u8 *hfunc)
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600508{
509 struct xgbe_prv_data *pdata = netdev_priv(netdev);
510 unsigned int i;
511
512 if (indir) {
513 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
514 indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
515 MAC_RSSDR, DMCH);
516 }
517
518 if (key)
519 memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
520
Eyal Perry892311f2014-12-02 18:12:10 +0200521 if (hfunc)
522 *hfunc = ETH_RSS_HASH_TOP;
523
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600524 return 0;
525}
526
527static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
Eyal Perry892311f2014-12-02 18:12:10 +0200528 const u8 *key, const u8 hfunc)
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600529{
530 struct xgbe_prv_data *pdata = netdev_priv(netdev);
531 struct xgbe_hw_if *hw_if = &pdata->hw_if;
532 unsigned int ret;
533
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500534 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) {
535 netdev_err(netdev, "unsupported hash function\n");
Eyal Perry892311f2014-12-02 18:12:10 +0200536 return -EOPNOTSUPP;
Lendacky, Thomase5dd8b82015-09-30 08:52:57 -0500537 }
Eyal Perry892311f2014-12-02 18:12:10 +0200538
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600539 if (indir) {
540 ret = hw_if->set_rss_lookup_table(pdata, indir);
541 if (ret)
542 return ret;
543 }
544
545 if (key) {
546 ret = hw_if->set_rss_hash_key(pdata, key);
547 if (ret)
548 return ret;
549 }
550
551 return 0;
552}
553
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500554static int xgbe_get_ts_info(struct net_device *netdev,
555 struct ethtool_ts_info *ts_info)
556{
557 struct xgbe_prv_data *pdata = netdev_priv(netdev);
558
559 ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
560 SOF_TIMESTAMPING_RX_SOFTWARE |
561 SOF_TIMESTAMPING_SOFTWARE |
562 SOF_TIMESTAMPING_TX_HARDWARE |
563 SOF_TIMESTAMPING_RX_HARDWARE |
564 SOF_TIMESTAMPING_RAW_HARDWARE;
565
566 if (pdata->ptp_clock)
567 ts_info->phc_index = ptp_clock_index(pdata->ptp_clock);
568 else
569 ts_info->phc_index = -1;
570
571 ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
572 ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
573 (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
574 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
575 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
576 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
577 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
578 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
579 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
580 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
581 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
582 (1 << HWTSTAMP_FILTER_ALL);
583
584 return 0;
585}
586
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500587static const struct ethtool_ops xgbe_ethtool_ops = {
588 .get_settings = xgbe_get_settings,
589 .set_settings = xgbe_set_settings,
590 .get_drvinfo = xgbe_get_drvinfo,
Lendacky, Thomas349fb2d72015-09-30 08:52:51 -0500591 .get_msglevel = xgbe_get_msglevel,
592 .set_msglevel = xgbe_set_msglevel,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500593 .get_link = ethtool_op_get_link,
594 .get_coalesce = xgbe_get_coalesce,
595 .set_coalesce = xgbe_set_coalesce,
596 .get_pauseparam = xgbe_get_pauseparam,
597 .set_pauseparam = xgbe_set_pauseparam,
598 .get_strings = xgbe_get_strings,
599 .get_ethtool_stats = xgbe_get_ethtool_stats,
600 .get_sset_count = xgbe_get_sset_count,
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600601 .get_rxnfc = xgbe_get_rxnfc,
602 .get_rxfh_key_size = xgbe_get_rxfh_key_size,
603 .get_rxfh_indir_size = xgbe_get_rxfh_indir_size,
604 .get_rxfh = xgbe_get_rxfh,
605 .set_rxfh = xgbe_set_rxfh,
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500606 .get_ts_info = xgbe_get_ts_info,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500607};
608
stephen hemmingerce0b15d2016-08-31 08:57:36 -0700609const struct ethtool_ops *xgbe_get_ethtool_ops(void)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500610{
stephen hemmingerce0b15d2016-08-31 08:57:36 -0700611 return &xgbe_ethtool_ops;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500612}