amd-xgbe: Simplify calculation and setting of queue fifos
[deliverable/linux.git] / drivers / net / ethernet / amd / xgbe / xgbe-ethtool.c
CommitLineData
c5aa9e3b
LT
1/*
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>
23e4eef7 119#include <linux/net_tstamp.h>
c5aa9e3b
LT
120
121#include "xgbe.h"
122#include "xgbe-common.h"
123
c5aa9e3b
LT
124struct 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
5452b2df
LT
136#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
c5aa9e3b
LT
142static 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),
5452b2df 149 XGMAC_EXT_STAT("tx_tso_packets", tx_tso_packets),
c5aa9e3b
LT
150 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),
5452b2df 181 XGMAC_EXT_STAT("rx_split_header_packets", rx_split_header_packets),
c5aa9e3b 182};
a2ea14d7 183
c5aa9e3b
LT
184#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
c5aa9e3b
LT
190 switch (stringset) {
191 case ETH_SS_STATS:
192 for (i = 0; i < XGBE_STATS_COUNT; i++) {
193 memcpy(data, xgbe_gstring_stats[i].stat_string,
194 ETH_GSTRING_LEN);
195 data += ETH_GSTRING_LEN;
196 }
197 break;
198 }
c5aa9e3b
LT
199}
200
201static void xgbe_get_ethtool_stats(struct net_device *netdev,
202 struct ethtool_stats *stats, u64 *data)
203{
204 struct xgbe_prv_data *pdata = netdev_priv(netdev);
205 u8 *stat;
206 int i;
207
c5aa9e3b
LT
208 pdata->hw_if.read_mmc_stats(pdata);
209 for (i = 0; i < XGBE_STATS_COUNT; i++) {
210 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
211 *data++ = *(u64 *)stat;
212 }
c5aa9e3b
LT
213}
214
215static int xgbe_get_sset_count(struct net_device *netdev, int stringset)
216{
217 int ret;
218
c5aa9e3b
LT
219 switch (stringset) {
220 case ETH_SS_STATS:
221 ret = XGBE_STATS_COUNT;
222 break;
223
224 default:
225 ret = -EOPNOTSUPP;
226 }
227
c5aa9e3b
LT
228 return ret;
229}
230
231static void xgbe_get_pauseparam(struct net_device *netdev,
232 struct ethtool_pauseparam *pause)
233{
234 struct xgbe_prv_data *pdata = netdev_priv(netdev);
235
c1ce2f77
LT
236 pause->autoneg = pdata->phy.pause_autoneg;
237 pause->tx_pause = pdata->phy.tx_pause;
238 pause->rx_pause = pdata->phy.rx_pause;
c5aa9e3b
LT
239}
240
241static int xgbe_set_pauseparam(struct net_device *netdev,
242 struct ethtool_pauseparam *pause)
243{
244 struct xgbe_prv_data *pdata = netdev_priv(netdev);
c5aa9e3b
LT
245 int ret = 0;
246
e5dd8b81
LT
247 if (pause->autoneg && (pdata->phy.autoneg != AUTONEG_ENABLE)) {
248 netdev_err(netdev,
249 "autoneg disabled, pause autoneg not avialable\n");
c1ce2f77 250 return -EINVAL;
e5dd8b81 251 }
c1ce2f77
LT
252
253 pdata->phy.pause_autoneg = pause->autoneg;
254 pdata->phy.tx_pause = pause->tx_pause;
255 pdata->phy.rx_pause = pause->rx_pause;
c5aa9e3b 256
c1ce2f77
LT
257 pdata->phy.advertising &= ~ADVERTISED_Pause;
258 pdata->phy.advertising &= ~ADVERTISED_Asym_Pause;
c5aa9e3b 259
c1ce2f77
LT
260 if (pause->rx_pause) {
261 pdata->phy.advertising |= ADVERTISED_Pause;
262 pdata->phy.advertising |= ADVERTISED_Asym_Pause;
c5aa9e3b
LT
263 }
264
c1ce2f77
LT
265 if (pause->tx_pause)
266 pdata->phy.advertising ^= ADVERTISED_Asym_Pause;
267
c5aa9e3b 268 if (netif_running(netdev))
7c12aa08 269 ret = pdata->phy_if.phy_config_aneg(pdata);
c5aa9e3b 270
c5aa9e3b
LT
271 return ret;
272}
273
274static int xgbe_get_settings(struct net_device *netdev,
275 struct ethtool_cmd *cmd)
276{
277 struct xgbe_prv_data *pdata = netdev_priv(netdev);
c5aa9e3b 278
7c12aa08
LT
279 cmd->phy_address = pdata->phy.address;
280
281 cmd->supported = pdata->phy.supported;
282 cmd->advertising = pdata->phy.advertising;
283 cmd->lp_advertising = pdata->phy.lp_advertising;
284
285 cmd->autoneg = pdata->phy.autoneg;
286 ethtool_cmd_speed_set(cmd, pdata->phy.speed);
287 cmd->duplex = pdata->phy.duplex;
c5aa9e3b 288
7c12aa08
LT
289 cmd->port = PORT_NONE;
290 cmd->transceiver = XCVR_INTERNAL;
c5aa9e3b 291
7c12aa08 292 return 0;
c5aa9e3b
LT
293}
294
295static int xgbe_set_settings(struct net_device *netdev,
296 struct ethtool_cmd *cmd)
297{
298 struct xgbe_prv_data *pdata = netdev_priv(netdev);
c5aa9e3b
LT
299 u32 speed;
300 int ret;
301
c5aa9e3b
LT
302 speed = ethtool_cmd_speed(cmd);
303
e5dd8b81
LT
304 if (cmd->phy_address != pdata->phy.address) {
305 netdev_err(netdev, "invalid phy address %hhu\n",
306 cmd->phy_address);
8c43a2cc 307 return -EINVAL;
e5dd8b81 308 }
c5aa9e3b
LT
309
310 if ((cmd->autoneg != AUTONEG_ENABLE) &&
e5dd8b81
LT
311 (cmd->autoneg != AUTONEG_DISABLE)) {
312 netdev_err(netdev, "unsupported autoneg %hhu\n",
313 cmd->autoneg);
8c43a2cc 314 return -EINVAL;
e5dd8b81 315 }
c5aa9e3b 316
f047604a
LT
317 if (cmd->autoneg == AUTONEG_DISABLE) {
318 switch (speed) {
319 case SPEED_10000:
320 case SPEED_2500:
321 case SPEED_1000:
322 break;
323 default:
e5dd8b81 324 netdev_err(netdev, "unsupported speed %u\n", speed);
8c43a2cc 325 return -EINVAL;
f047604a
LT
326 }
327
e5dd8b81
LT
328 if (cmd->duplex != DUPLEX_FULL) {
329 netdev_err(netdev, "unsupported duplex %hhu\n",
330 cmd->duplex);
8c43a2cc 331 return -EINVAL;
e5dd8b81 332 }
f047604a 333 }
c5aa9e3b 334
e5dd8b81
LT
335 netif_dbg(pdata, link, netdev,
336 "requested advertisement %#x, phy supported %#x\n",
337 cmd->advertising, pdata->phy.supported);
338
7c12aa08 339 cmd->advertising &= pdata->phy.supported;
e5dd8b81
LT
340 if ((cmd->autoneg == AUTONEG_ENABLE) && !cmd->advertising) {
341 netdev_err(netdev,
342 "unsupported requested advertisement\n");
8c43a2cc 343 return -EINVAL;
e5dd8b81 344 }
c5aa9e3b
LT
345
346 ret = 0;
7c12aa08
LT
347 pdata->phy.autoneg = cmd->autoneg;
348 pdata->phy.speed = speed;
349 pdata->phy.duplex = cmd->duplex;
350 pdata->phy.advertising = cmd->advertising;
c5aa9e3b
LT
351
352 if (cmd->autoneg == AUTONEG_ENABLE)
7c12aa08 353 pdata->phy.advertising |= ADVERTISED_Autoneg;
c5aa9e3b 354 else
7c12aa08 355 pdata->phy.advertising &= ~ADVERTISED_Autoneg;
c5aa9e3b
LT
356
357 if (netif_running(netdev))
7c12aa08 358 ret = pdata->phy_if.phy_config_aneg(pdata);
c5aa9e3b 359
c5aa9e3b
LT
360 return ret;
361}
362
363static void xgbe_get_drvinfo(struct net_device *netdev,
364 struct ethtool_drvinfo *drvinfo)
365{
366 struct xgbe_prv_data *pdata = netdev_priv(netdev);
a9a4a2d9 367 struct xgbe_hw_features *hw_feat = &pdata->hw_feat;
c5aa9e3b
LT
368
369 strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver));
370 strlcpy(drvinfo->version, XGBE_DRV_VERSION, sizeof(drvinfo->version));
371 strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
372 sizeof(drvinfo->bus_info));
373 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d",
a9a4a2d9
LT
374 XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
375 XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
376 XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
c5aa9e3b
LT
377 drvinfo->n_stats = XGBE_STATS_COUNT;
378}
379
349fb2d7
LT
380static u32 xgbe_get_msglevel(struct net_device *netdev)
381{
382 struct xgbe_prv_data *pdata = netdev_priv(netdev);
383
384 return pdata->msg_enable;
385}
386
387static void xgbe_set_msglevel(struct net_device *netdev, u32 msglevel)
388{
389 struct xgbe_prv_data *pdata = netdev_priv(netdev);
390
391 pdata->msg_enable = msglevel;
392}
393
c5aa9e3b
LT
394static int xgbe_get_coalesce(struct net_device *netdev,
395 struct ethtool_coalesce *ec)
396{
397 struct xgbe_prv_data *pdata = netdev_priv(netdev);
c5aa9e3b 398
c5aa9e3b
LT
399 memset(ec, 0, sizeof(struct ethtool_coalesce));
400
4a57ebcc 401 ec->rx_coalesce_usecs = pdata->rx_usecs;
c5aa9e3b
LT
402 ec->rx_max_coalesced_frames = pdata->rx_frames;
403
c5aa9e3b
LT
404 ec->tx_max_coalesced_frames = pdata->tx_frames;
405
c5aa9e3b
LT
406 return 0;
407}
408
409static int xgbe_set_coalesce(struct net_device *netdev,
410 struct ethtool_coalesce *ec)
411{
412 struct xgbe_prv_data *pdata = netdev_priv(netdev);
413 struct xgbe_hw_if *hw_if = &pdata->hw_if;
414 unsigned int rx_frames, rx_riwt, rx_usecs;
c635eaac 415 unsigned int tx_frames;
c5aa9e3b 416
c5aa9e3b
LT
417 /* Check for not supported parameters */
418 if ((ec->rx_coalesce_usecs_irq) ||
419 (ec->rx_max_coalesced_frames_irq) ||
c635eaac 420 (ec->tx_coalesce_usecs) ||
c5aa9e3b
LT
421 (ec->tx_coalesce_usecs_irq) ||
422 (ec->tx_max_coalesced_frames_irq) ||
423 (ec->stats_block_coalesce_usecs) ||
424 (ec->use_adaptive_rx_coalesce) ||
425 (ec->use_adaptive_tx_coalesce) ||
426 (ec->pkt_rate_low) ||
427 (ec->rx_coalesce_usecs_low) ||
428 (ec->rx_max_coalesced_frames_low) ||
429 (ec->tx_coalesce_usecs_low) ||
430 (ec->tx_max_coalesced_frames_low) ||
431 (ec->pkt_rate_high) ||
432 (ec->rx_coalesce_usecs_high) ||
433 (ec->rx_max_coalesced_frames_high) ||
434 (ec->tx_coalesce_usecs_high) ||
435 (ec->tx_max_coalesced_frames_high) ||
e5dd8b81
LT
436 (ec->rate_sample_interval)) {
437 netdev_err(netdev, "unsupported coalescing parameter\n");
c5aa9e3b 438 return -EOPNOTSUPP;
e5dd8b81 439 }
c5aa9e3b 440
c5aa9e3b 441 rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs);
4a57ebcc 442 rx_usecs = ec->rx_coalesce_usecs;
c5aa9e3b
LT
443 rx_frames = ec->rx_max_coalesced_frames;
444
445 /* Use smallest possible value if conversion resulted in zero */
4a57ebcc 446 if (rx_usecs && !rx_riwt)
c5aa9e3b
LT
447 rx_riwt = 1;
448
449 /* Check the bounds of values for Rx */
450 if (rx_riwt > XGMAC_MAX_DMA_RIWT) {
e5dd8b81
LT
451 netdev_err(netdev, "rx-usec is limited to %d usecs\n",
452 hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT));
c5aa9e3b
LT
453 return -EINVAL;
454 }
4780b7ca 455 if (rx_frames > pdata->rx_desc_count) {
e5dd8b81
LT
456 netdev_err(netdev, "rx-frames is limited to %d frames\n",
457 pdata->rx_desc_count);
c5aa9e3b
LT
458 return -EINVAL;
459 }
460
c5aa9e3b
LT
461 tx_frames = ec->tx_max_coalesced_frames;
462
463 /* Check the bounds of values for Tx */
4780b7ca 464 if (tx_frames > pdata->tx_desc_count) {
e5dd8b81
LT
465 netdev_err(netdev, "tx-frames is limited to %d frames\n",
466 pdata->tx_desc_count);
c5aa9e3b
LT
467 return -EINVAL;
468 }
469
470 pdata->rx_riwt = rx_riwt;
4a57ebcc 471 pdata->rx_usecs = rx_usecs;
c5aa9e3b
LT
472 pdata->rx_frames = rx_frames;
473 hw_if->config_rx_coalesce(pdata);
474
c5aa9e3b
LT
475 pdata->tx_frames = tx_frames;
476 hw_if->config_tx_coalesce(pdata);
477
c5aa9e3b
LT
478 return 0;
479}
480
f6ac8628
LT
481static int xgbe_get_rxnfc(struct net_device *netdev,
482 struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
483{
484 struct xgbe_prv_data *pdata = netdev_priv(netdev);
485
486 switch (rxnfc->cmd) {
487 case ETHTOOL_GRXRINGS:
488 rxnfc->data = pdata->rx_ring_count;
489 break;
490 default:
491 return -EOPNOTSUPP;
492 }
493
494 return 0;
495}
496
497static u32 xgbe_get_rxfh_key_size(struct net_device *netdev)
498{
499 struct xgbe_prv_data *pdata = netdev_priv(netdev);
500
501 return sizeof(pdata->rss_key);
502}
503
504static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
505{
506 struct xgbe_prv_data *pdata = netdev_priv(netdev);
507
508 return ARRAY_SIZE(pdata->rss_table);
509}
510
892311f6
EP
511static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
512 u8 *hfunc)
f6ac8628
LT
513{
514 struct xgbe_prv_data *pdata = netdev_priv(netdev);
515 unsigned int i;
516
517 if (indir) {
518 for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
519 indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
520 MAC_RSSDR, DMCH);
521 }
522
523 if (key)
524 memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
525
892311f6
EP
526 if (hfunc)
527 *hfunc = ETH_RSS_HASH_TOP;
528
f6ac8628
LT
529 return 0;
530}
531
532static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
892311f6 533 const u8 *key, const u8 hfunc)
f6ac8628
LT
534{
535 struct xgbe_prv_data *pdata = netdev_priv(netdev);
536 struct xgbe_hw_if *hw_if = &pdata->hw_if;
537 unsigned int ret;
538
e5dd8b81
LT
539 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) {
540 netdev_err(netdev, "unsupported hash function\n");
892311f6 541 return -EOPNOTSUPP;
e5dd8b81 542 }
892311f6 543
f6ac8628
LT
544 if (indir) {
545 ret = hw_if->set_rss_lookup_table(pdata, indir);
546 if (ret)
547 return ret;
548 }
549
550 if (key) {
551 ret = hw_if->set_rss_hash_key(pdata, key);
552 if (ret)
553 return ret;
554 }
555
556 return 0;
557}
558
23e4eef7
LT
559static int xgbe_get_ts_info(struct net_device *netdev,
560 struct ethtool_ts_info *ts_info)
561{
562 struct xgbe_prv_data *pdata = netdev_priv(netdev);
563
564 ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
565 SOF_TIMESTAMPING_RX_SOFTWARE |
566 SOF_TIMESTAMPING_SOFTWARE |
567 SOF_TIMESTAMPING_TX_HARDWARE |
568 SOF_TIMESTAMPING_RX_HARDWARE |
569 SOF_TIMESTAMPING_RAW_HARDWARE;
570
571 if (pdata->ptp_clock)
572 ts_info->phc_index = ptp_clock_index(pdata->ptp_clock);
573 else
574 ts_info->phc_index = -1;
575
576 ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
577 ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
578 (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
579 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
580 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
581 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
582 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
583 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
584 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
585 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
586 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
587 (1 << HWTSTAMP_FILTER_ALL);
588
589 return 0;
590}
591
c5aa9e3b
LT
592static const struct ethtool_ops xgbe_ethtool_ops = {
593 .get_settings = xgbe_get_settings,
594 .set_settings = xgbe_set_settings,
595 .get_drvinfo = xgbe_get_drvinfo,
349fb2d7
LT
596 .get_msglevel = xgbe_get_msglevel,
597 .set_msglevel = xgbe_set_msglevel,
c5aa9e3b
LT
598 .get_link = ethtool_op_get_link,
599 .get_coalesce = xgbe_get_coalesce,
600 .set_coalesce = xgbe_set_coalesce,
601 .get_pauseparam = xgbe_get_pauseparam,
602 .set_pauseparam = xgbe_set_pauseparam,
603 .get_strings = xgbe_get_strings,
604 .get_ethtool_stats = xgbe_get_ethtool_stats,
605 .get_sset_count = xgbe_get_sset_count,
f6ac8628
LT
606 .get_rxnfc = xgbe_get_rxnfc,
607 .get_rxfh_key_size = xgbe_get_rxfh_key_size,
608 .get_rxfh_indir_size = xgbe_get_rxfh_indir_size,
609 .get_rxfh = xgbe_get_rxfh,
610 .set_rxfh = xgbe_set_rxfh,
23e4eef7 611 .get_ts_info = xgbe_get_ts_info,
c5aa9e3b
LT
612};
613
614struct ethtool_ops *xgbe_get_ethtool_ops(void)
615{
616 return (struct ethtool_ops *)&xgbe_ethtool_ops;
617}
This page took 0.13672 seconds and 5 git commands to generate.