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