blob: b24a78c3980095c3220f86d19754544beabc84a7 [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 *
9 * Copyright (c) 2014 Advanced Micro Devices, Inc.
10 *
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 *
59 * Copyright (c) 2014 Advanced Micro Devices, Inc.
60 * 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, Thomasc5aa9e32014-06-05 09:15:06 -0500182};
Lendacky, Thomasa2ea14d2014-09-03 12:14:33 -0500183
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500184#define XGBE_STATS_COUNT ARRAY_SIZE(xgbe_gstring_stats)
185
186static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
187{
188 int i;
189
190 DBGPR("-->%s\n", __func__);
191
192 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 }
199 break;
200 }
201
202 DBGPR("<--%s\n", __func__);
203}
204
205static void xgbe_get_ethtool_stats(struct net_device *netdev,
206 struct ethtool_stats *stats, u64 *data)
207{
208 struct xgbe_prv_data *pdata = netdev_priv(netdev);
209 u8 *stat;
210 int i;
211
212 DBGPR("-->%s\n", __func__);
213
214 pdata->hw_if.read_mmc_stats(pdata);
215 for (i = 0; i < XGBE_STATS_COUNT; i++) {
216 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
217 *data++ = *(u64 *)stat;
218 }
219
220 DBGPR("<--%s\n", __func__);
221}
222
223static int xgbe_get_sset_count(struct net_device *netdev, int stringset)
224{
225 int ret;
226
227 DBGPR("-->%s\n", __func__);
228
229 switch (stringset) {
230 case ETH_SS_STATS:
231 ret = XGBE_STATS_COUNT;
232 break;
233
234 default:
235 ret = -EOPNOTSUPP;
236 }
237
238 DBGPR("<--%s\n", __func__);
239
240 return ret;
241}
242
243static void xgbe_get_pauseparam(struct net_device *netdev,
244 struct ethtool_pauseparam *pause)
245{
246 struct xgbe_prv_data *pdata = netdev_priv(netdev);
247
248 DBGPR("-->xgbe_get_pauseparam\n");
249
250 pause->autoneg = pdata->pause_autoneg;
251 pause->tx_pause = pdata->tx_pause;
252 pause->rx_pause = pdata->rx_pause;
253
254 DBGPR("<--xgbe_get_pauseparam\n");
255}
256
257static int xgbe_set_pauseparam(struct net_device *netdev,
258 struct ethtool_pauseparam *pause)
259{
260 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500261 int ret = 0;
262
263 DBGPR("-->xgbe_set_pauseparam\n");
264
265 DBGPR(" autoneg = %d, tx_pause = %d, rx_pause = %d\n",
266 pause->autoneg, pause->tx_pause, pause->rx_pause);
267
268 pdata->pause_autoneg = pause->autoneg;
269 if (pause->autoneg) {
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500270 pdata->phy.advertising |= ADVERTISED_Pause;
271 pdata->phy.advertising |= ADVERTISED_Asym_Pause;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500272
273 } else {
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500274 pdata->phy.advertising &= ~ADVERTISED_Pause;
275 pdata->phy.advertising &= ~ADVERTISED_Asym_Pause;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500276
277 pdata->tx_pause = pause->tx_pause;
278 pdata->rx_pause = pause->rx_pause;
279 }
280
281 if (netif_running(netdev))
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500282 ret = pdata->phy_if.phy_config_aneg(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500283
284 DBGPR("<--xgbe_set_pauseparam\n");
285
286 return ret;
287}
288
289static int xgbe_get_settings(struct net_device *netdev,
290 struct ethtool_cmd *cmd)
291{
292 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500293
294 DBGPR("-->xgbe_get_settings\n");
295
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500296 cmd->phy_address = pdata->phy.address;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500297
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500298 cmd->supported = pdata->phy.supported;
299 cmd->advertising = pdata->phy.advertising;
300 cmd->lp_advertising = pdata->phy.lp_advertising;
301
302 cmd->autoneg = pdata->phy.autoneg;
303 ethtool_cmd_speed_set(cmd, pdata->phy.speed);
304 cmd->duplex = pdata->phy.duplex;
305
306 cmd->port = PORT_NONE;
307 cmd->transceiver = XCVR_INTERNAL;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500308
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500309 DBGPR("<--xgbe_get_settings\n");
310
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500311 return 0;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500312}
313
314static int xgbe_set_settings(struct net_device *netdev,
315 struct ethtool_cmd *cmd)
316{
317 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500318 u32 speed;
319 int ret;
320
321 DBGPR("-->xgbe_set_settings\n");
322
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500323 speed = ethtool_cmd_speed(cmd);
324
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500325 if (cmd->phy_address != pdata->phy.address)
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500326 return -EINVAL;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500327
328 if ((cmd->autoneg != AUTONEG_ENABLE) &&
329 (cmd->autoneg != AUTONEG_DISABLE))
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500330 return -EINVAL;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500331
Lendacky, Thomasf0476042014-07-29 08:57:25 -0500332 if (cmd->autoneg == AUTONEG_DISABLE) {
333 switch (speed) {
334 case SPEED_10000:
335 case SPEED_2500:
336 case SPEED_1000:
337 break;
338 default:
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500339 return -EINVAL;
Lendacky, Thomasf0476042014-07-29 08:57:25 -0500340 }
341
342 if (cmd->duplex != DUPLEX_FULL)
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500343 return -EINVAL;
Lendacky, Thomasf0476042014-07-29 08:57:25 -0500344 }
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500345
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500346 cmd->advertising &= pdata->phy.supported;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500347 if ((cmd->autoneg == AUTONEG_ENABLE) && !cmd->advertising)
Lendacky, Thomas8c43a2c2014-08-01 11:56:29 -0500348 return -EINVAL;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500349
350 ret = 0;
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500351 pdata->phy.autoneg = cmd->autoneg;
352 pdata->phy.speed = speed;
353 pdata->phy.duplex = cmd->duplex;
354 pdata->phy.advertising = cmd->advertising;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500355
356 if (cmd->autoneg == AUTONEG_ENABLE)
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500357 pdata->phy.advertising |= ADVERTISED_Autoneg;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500358 else
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500359 pdata->phy.advertising &= ~ADVERTISED_Autoneg;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500360
361 if (netif_running(netdev))
Lendacky, Thomas7c12aa02015-05-14 11:44:15 -0500362 ret = pdata->phy_if.phy_config_aneg(pdata);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500363
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500364 DBGPR("<--xgbe_set_settings\n");
365
366 return ret;
367}
368
369static void xgbe_get_drvinfo(struct net_device *netdev,
370 struct ethtool_drvinfo *drvinfo)
371{
372 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -0500373 struct xgbe_hw_features *hw_feat = &pdata->hw_feat;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500374
375 strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver));
376 strlcpy(drvinfo->version, XGBE_DRV_VERSION, sizeof(drvinfo->version));
377 strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
378 sizeof(drvinfo->bus_info));
379 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d",
Lendacky, Thomasa9a4a2d2014-08-29 13:16:50 -0500380 XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
381 XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
382 XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500383 drvinfo->n_stats = XGBE_STATS_COUNT;
384}
385
386static int xgbe_get_coalesce(struct net_device *netdev,
387 struct ethtool_coalesce *ec)
388{
389 struct xgbe_prv_data *pdata = netdev_priv(netdev);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500390
391 DBGPR("-->xgbe_get_coalesce\n");
392
393 memset(ec, 0, sizeof(struct ethtool_coalesce));
394
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500395 ec->rx_coalesce_usecs = pdata->rx_usecs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500396 ec->rx_max_coalesced_frames = pdata->rx_frames;
397
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500398 ec->tx_max_coalesced_frames = pdata->tx_frames;
399
400 DBGPR("<--xgbe_get_coalesce\n");
401
402 return 0;
403}
404
405static int xgbe_set_coalesce(struct net_device *netdev,
406 struct ethtool_coalesce *ec)
407{
408 struct xgbe_prv_data *pdata = netdev_priv(netdev);
409 struct xgbe_hw_if *hw_if = &pdata->hw_if;
410 unsigned int rx_frames, rx_riwt, rx_usecs;
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -0500411 unsigned int tx_frames;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500412
413 DBGPR("-->xgbe_set_coalesce\n");
414
415 /* Check for not supported parameters */
416 if ((ec->rx_coalesce_usecs_irq) ||
417 (ec->rx_max_coalesced_frames_irq) ||
Lendacky, Thomasc635eaa2015-03-20 11:50:28 -0500418 (ec->tx_coalesce_usecs) ||
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500419 (ec->tx_coalesce_usecs_irq) ||
420 (ec->tx_max_coalesced_frames_irq) ||
421 (ec->stats_block_coalesce_usecs) ||
422 (ec->use_adaptive_rx_coalesce) ||
423 (ec->use_adaptive_tx_coalesce) ||
424 (ec->pkt_rate_low) ||
425 (ec->rx_coalesce_usecs_low) ||
426 (ec->rx_max_coalesced_frames_low) ||
427 (ec->tx_coalesce_usecs_low) ||
428 (ec->tx_max_coalesced_frames_low) ||
429 (ec->pkt_rate_high) ||
430 (ec->rx_coalesce_usecs_high) ||
431 (ec->rx_max_coalesced_frames_high) ||
432 (ec->tx_coalesce_usecs_high) ||
433 (ec->tx_max_coalesced_frames_high) ||
434 (ec->rate_sample_interval))
435 return -EOPNOTSUPP;
436
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500437 rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs);
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500438 rx_usecs = ec->rx_coalesce_usecs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500439 rx_frames = ec->rx_max_coalesced_frames;
440
441 /* Use smallest possible value if conversion resulted in zero */
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500442 if (rx_usecs && !rx_riwt)
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500443 rx_riwt = 1;
444
445 /* Check the bounds of values for Rx */
446 if (rx_riwt > XGMAC_MAX_DMA_RIWT) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500447 netdev_alert(netdev, "rx-usec is limited to %d usecs\n",
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500448 hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT));
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500449 return -EINVAL;
450 }
Lendacky, Thomas4780b7c2014-11-04 16:06:26 -0600451 if (rx_frames > pdata->rx_desc_count) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500452 netdev_alert(netdev, "rx-frames is limited to %d frames\n",
Lendacky, Thomas4780b7c2014-11-04 16:06:26 -0600453 pdata->rx_desc_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500454 return -EINVAL;
455 }
456
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500457 tx_frames = ec->tx_max_coalesced_frames;
458
459 /* Check the bounds of values for Tx */
Lendacky, Thomas4780b7c2014-11-04 16:06:26 -0600460 if (tx_frames > pdata->tx_desc_count) {
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500461 netdev_alert(netdev, "tx-frames is limited to %d frames\n",
Lendacky, Thomas4780b7c2014-11-04 16:06:26 -0600462 pdata->tx_desc_count);
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500463 return -EINVAL;
464 }
465
466 pdata->rx_riwt = rx_riwt;
Lendacky, Thomas4a57ebc2015-03-20 11:50:34 -0500467 pdata->rx_usecs = rx_usecs;
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500468 pdata->rx_frames = rx_frames;
469 hw_if->config_rx_coalesce(pdata);
470
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500471 pdata->tx_frames = tx_frames;
472 hw_if->config_tx_coalesce(pdata);
473
474 DBGPR("<--xgbe_set_coalesce\n");
475
476 return 0;
477}
478
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600479static int xgbe_get_rxnfc(struct net_device *netdev,
480 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
481{
482 struct xgbe_prv_data *pdata = netdev_priv(netdev);
483
484 switch (rxnfc->cmd) {
485 case ETHTOOL_GRXRINGS:
486 rxnfc->data = pdata->rx_ring_count;
487 break;
488 default:
489 return -EOPNOTSUPP;
490 }
491
492 return 0;
493}
494
495static u32 xgbe_get_rxfh_key_size(struct net_device *netdev)
496{
497 struct xgbe_prv_data *pdata = netdev_priv(netdev);
498
499 return sizeof(pdata->rss_key);
500}
501
502static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
503{
504 struct xgbe_prv_data *pdata = netdev_priv(netdev);
505
506 return ARRAY_SIZE(pdata->rss_table);
507}
508
Eyal Perry892311f2014-12-02 18:12:10 +0200509static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
510 u8 *hfunc)
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600511{
512 struct xgbe_prv_data *pdata = netdev_priv(netdev);
513 unsigned int i;
514
515 if (indir) {
516 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
517 indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
518 MAC_RSSDR, DMCH);
519 }
520
521 if (key)
522 memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
523
Eyal Perry892311f2014-12-02 18:12:10 +0200524 if (hfunc)
525 *hfunc = ETH_RSS_HASH_TOP;
526
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600527 return 0;
528}
529
530static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
Eyal Perry892311f2014-12-02 18:12:10 +0200531 const u8 *key, const u8 hfunc)
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600532{
533 struct xgbe_prv_data *pdata = netdev_priv(netdev);
534 struct xgbe_hw_if *hw_if = &pdata->hw_if;
535 unsigned int ret;
536
Eyal Perry892311f2014-12-02 18:12:10 +0200537 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
538 return -EOPNOTSUPP;
539
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600540 if (indir) {
541 ret = hw_if->set_rss_lookup_table(pdata, indir);
542 if (ret)
543 return ret;
544 }
545
546 if (key) {
547 ret = hw_if->set_rss_hash_key(pdata, key);
548 if (ret)
549 return ret;
550 }
551
552 return 0;
553}
554
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500555static int xgbe_get_ts_info(struct net_device *netdev,
556 struct ethtool_ts_info *ts_info)
557{
558 struct xgbe_prv_data *pdata = netdev_priv(netdev);
559
560 ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
561 SOF_TIMESTAMPING_RX_SOFTWARE |
562 SOF_TIMESTAMPING_SOFTWARE |
563 SOF_TIMESTAMPING_TX_HARDWARE |
564 SOF_TIMESTAMPING_RX_HARDWARE |
565 SOF_TIMESTAMPING_RAW_HARDWARE;
566
567 if (pdata->ptp_clock)
568 ts_info->phc_index = ptp_clock_index(pdata->ptp_clock);
569 else
570 ts_info->phc_index = -1;
571
572 ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
573 ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
574 (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
575 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
576 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
577 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
578 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
579 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
580 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
581 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
582 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
583 (1 << HWTSTAMP_FILTER_ALL);
584
585 return 0;
586}
587
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500588static const struct ethtool_ops xgbe_ethtool_ops = {
589 .get_settings = xgbe_get_settings,
590 .set_settings = xgbe_set_settings,
591 .get_drvinfo = xgbe_get_drvinfo,
592 .get_link = ethtool_op_get_link,
593 .get_coalesce = xgbe_get_coalesce,
594 .set_coalesce = xgbe_set_coalesce,
595 .get_pauseparam = xgbe_get_pauseparam,
596 .set_pauseparam = xgbe_set_pauseparam,
597 .get_strings = xgbe_get_strings,
598 .get_ethtool_stats = xgbe_get_ethtool_stats,
599 .get_sset_count = xgbe_get_sset_count,
Lendacky, Thomasf6ac8622014-11-04 16:07:23 -0600600 .get_rxnfc = xgbe_get_rxnfc,
601 .get_rxfh_key_size = xgbe_get_rxfh_key_size,
602 .get_rxfh_indir_size = xgbe_get_rxfh_indir_size,
603 .get_rxfh = xgbe_get_rxfh,
604 .set_rxfh = xgbe_set_rxfh,
Lendacky, Thomas23e4eef2014-07-29 08:57:19 -0500605 .get_ts_info = xgbe_get_ts_info,
Lendacky, Thomasc5aa9e32014-06-05 09:15:06 -0500606};
607
608struct ethtool_ops *xgbe_get_ethtool_ops(void)
609{
610 return (struct ethtool_ops *)&xgbe_ethtool_ops;
611}