2 * AMD 10Gb Ethernet driver
4 * This file is available to you under your choice of the following two
9 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
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.
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.
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/>.
24 * This file incorporates work covered by the following copyright and
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
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:
41 * The above copyright notice and this permission notice shall be included
42 * in all copies or substantial portions of the Software.
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.
57 * License 2: Modified BSD
59 * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
60 * All rights reserved.
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.
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.
84 * This file incorporates work covered by the following copyright and
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
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:
101 * The above copyright notice and this permission notice shall be included
102 * in all copies or substantial portions of the Software.
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.
117 #include <linux/spinlock.h>
118 #include <linux/phy.h>
119 #include <linux/net_tstamp.h>
122 #include "xgbe-common.h"
125 char stat_string
[ETH_GSTRING_LEN
];
130 #define XGMAC_MMC_STAT(_string, _var) \
132 sizeof_field(struct xgbe_mmc_stats, _var), \
133 offsetof(struct xgbe_prv_data, mmc_stats._var), \
136 #define XGMAC_EXT_STAT(_string, _var) \
138 sizeof_field(struct xgbe_ext_stats, _var), \
139 offsetof(struct xgbe_prv_data, ext_stats._var), \
142 static 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
),
149 XGMAC_EXT_STAT("tx_vxlan_packets", tx_vxlan_packets
),
150 XGMAC_EXT_STAT("tx_tso_packets", tx_tso_packets
),
151 XGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb
),
152 XGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb
),
153 XGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb
),
154 XGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb
),
155 XGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb
),
156 XGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb
),
157 XGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror
),
158 XGMAC_MMC_STAT("tx_pause_frames", txpauseframes
),
160 XGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb
),
161 XGMAC_MMC_STAT("rx_packets", rxframecount_gb
),
162 XGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g
),
163 XGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g
),
164 XGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g
),
165 XGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb
),
166 XGMAC_EXT_STAT("rx_vxlan_packets", rx_vxlan_packets
),
167 XGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb
),
168 XGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb
),
169 XGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb
),
170 XGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb
),
171 XGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb
),
172 XGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb
),
173 XGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g
),
174 XGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g
),
175 XGMAC_MMC_STAT("rx_crc_errors", rxcrcerror
),
176 XGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror
),
177 XGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror
),
178 XGMAC_MMC_STAT("rx_length_errors", rxlengtherror
),
179 XGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype
),
180 XGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow
),
181 XGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror
),
182 XGMAC_EXT_STAT("rx_csum_errors", rx_csum_errors
),
183 XGMAC_EXT_STAT("rx_vxlan_csum_errors", rx_vxlan_csum_errors
),
184 XGMAC_MMC_STAT("rx_pause_frames", rxpauseframes
),
185 XGMAC_EXT_STAT("rx_split_header_packets", rx_split_header_packets
),
186 XGMAC_EXT_STAT("rx_buffer_unavailable", rx_buffer_unavailable
),
189 #define XGBE_STATS_COUNT ARRAY_SIZE(xgbe_gstring_stats)
191 static void xgbe_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*data
)
193 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
198 for (i
= 0; i
< XGBE_STATS_COUNT
; i
++) {
199 memcpy(data
, xgbe_gstring_stats
[i
].stat_string
,
201 data
+= ETH_GSTRING_LEN
;
203 for (i
= 0; i
< pdata
->tx_ring_count
; i
++) {
204 sprintf(data
, "txq_%u_packets", i
);
205 data
+= ETH_GSTRING_LEN
;
206 sprintf(data
, "txq_%u_bytes", i
);
207 data
+= ETH_GSTRING_LEN
;
209 for (i
= 0; i
< pdata
->rx_ring_count
; i
++) {
210 sprintf(data
, "rxq_%u_packets", i
);
211 data
+= ETH_GSTRING_LEN
;
212 sprintf(data
, "rxq_%u_bytes", i
);
213 data
+= ETH_GSTRING_LEN
;
219 static void xgbe_get_ethtool_stats(struct net_device
*netdev
,
220 struct ethtool_stats
*stats
, u64
*data
)
222 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
226 pdata
->hw_if
.read_mmc_stats(pdata
);
227 for (i
= 0; i
< XGBE_STATS_COUNT
; i
++) {
228 stat
= (u8
*)pdata
+ xgbe_gstring_stats
[i
].stat_offset
;
229 *data
++ = *(u64
*)stat
;
231 for (i
= 0; i
< pdata
->tx_ring_count
; i
++) {
232 *data
++ = pdata
->ext_stats
.txq_packets
[i
];
233 *data
++ = pdata
->ext_stats
.txq_bytes
[i
];
235 for (i
= 0; i
< pdata
->rx_ring_count
; i
++) {
236 *data
++ = pdata
->ext_stats
.rxq_packets
[i
];
237 *data
++ = pdata
->ext_stats
.rxq_bytes
[i
];
241 static int xgbe_get_sset_count(struct net_device
*netdev
, int stringset
)
243 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
248 ret
= XGBE_STATS_COUNT
+
249 (pdata
->tx_ring_count
* 2) +
250 (pdata
->rx_ring_count
* 2);
260 static void xgbe_get_pauseparam(struct net_device
*netdev
,
261 struct ethtool_pauseparam
*pause
)
263 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
265 pause
->autoneg
= pdata
->phy
.pause_autoneg
;
266 pause
->tx_pause
= pdata
->phy
.tx_pause
;
267 pause
->rx_pause
= pdata
->phy
.rx_pause
;
270 static int xgbe_set_pauseparam(struct net_device
*netdev
,
271 struct ethtool_pauseparam
*pause
)
273 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
274 struct ethtool_link_ksettings
*lks
= &pdata
->phy
.lks
;
277 if (pause
->autoneg
&& (pdata
->phy
.autoneg
!= AUTONEG_ENABLE
)) {
279 "autoneg disabled, pause autoneg not available\n");
283 pdata
->phy
.pause_autoneg
= pause
->autoneg
;
284 pdata
->phy
.tx_pause
= pause
->tx_pause
;
285 pdata
->phy
.rx_pause
= pause
->rx_pause
;
287 XGBE_CLR_ADV(lks
, Pause
);
288 XGBE_CLR_ADV(lks
, Asym_Pause
);
290 if (pause
->rx_pause
) {
291 XGBE_SET_ADV(lks
, Pause
);
292 XGBE_SET_ADV(lks
, Asym_Pause
);
295 if (pause
->tx_pause
) {
296 /* Equivalent to XOR of Asym_Pause */
297 if (XGBE_ADV(lks
, Asym_Pause
))
298 XGBE_CLR_ADV(lks
, Asym_Pause
);
300 XGBE_SET_ADV(lks
, Asym_Pause
);
303 if (netif_running(netdev
))
304 ret
= pdata
->phy_if
.phy_config_aneg(pdata
);
309 static int xgbe_get_link_ksettings(struct net_device
*netdev
,
310 struct ethtool_link_ksettings
*cmd
)
312 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
313 struct ethtool_link_ksettings
*lks
= &pdata
->phy
.lks
;
315 cmd
->base
.phy_address
= pdata
->phy
.address
;
317 cmd
->base
.autoneg
= pdata
->phy
.autoneg
;
318 cmd
->base
.speed
= pdata
->phy
.speed
;
319 cmd
->base
.duplex
= pdata
->phy
.duplex
;
321 cmd
->base
.port
= PORT_NONE
;
323 XGBE_LM_COPY(cmd
, supported
, lks
, supported
);
324 XGBE_LM_COPY(cmd
, advertising
, lks
, advertising
);
325 XGBE_LM_COPY(cmd
, lp_advertising
, lks
, lp_advertising
);
330 static int xgbe_set_link_ksettings(struct net_device
*netdev
,
331 const struct ethtool_link_ksettings
*cmd
)
333 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
334 struct ethtool_link_ksettings
*lks
= &pdata
->phy
.lks
;
335 __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising
);
339 speed
= cmd
->base
.speed
;
341 if (cmd
->base
.phy_address
!= pdata
->phy
.address
) {
342 netdev_err(netdev
, "invalid phy address %hhu\n",
343 cmd
->base
.phy_address
);
347 if ((cmd
->base
.autoneg
!= AUTONEG_ENABLE
) &&
348 (cmd
->base
.autoneg
!= AUTONEG_DISABLE
)) {
349 netdev_err(netdev
, "unsupported autoneg %hhu\n",
354 if (cmd
->base
.autoneg
== AUTONEG_DISABLE
) {
355 if (!pdata
->phy_if
.phy_valid_speed(pdata
, speed
)) {
356 netdev_err(netdev
, "unsupported speed %u\n", speed
);
360 if (cmd
->base
.duplex
!= DUPLEX_FULL
) {
361 netdev_err(netdev
, "unsupported duplex %hhu\n",
367 netif_dbg(pdata
, link
, netdev
,
368 "requested advertisement 0x%*pb, phy supported 0x%*pb\n",
369 __ETHTOOL_LINK_MODE_MASK_NBITS
, cmd
->link_modes
.advertising
,
370 __ETHTOOL_LINK_MODE_MASK_NBITS
, lks
->link_modes
.supported
);
372 bitmap_and(advertising
,
373 cmd
->link_modes
.advertising
, lks
->link_modes
.supported
,
374 __ETHTOOL_LINK_MODE_MASK_NBITS
);
376 if ((cmd
->base
.autoneg
== AUTONEG_ENABLE
) &&
377 bitmap_empty(advertising
, __ETHTOOL_LINK_MODE_MASK_NBITS
)) {
379 "unsupported requested advertisement\n");
384 pdata
->phy
.autoneg
= cmd
->base
.autoneg
;
385 pdata
->phy
.speed
= speed
;
386 pdata
->phy
.duplex
= cmd
->base
.duplex
;
387 bitmap_copy(lks
->link_modes
.advertising
, advertising
,
388 __ETHTOOL_LINK_MODE_MASK_NBITS
);
390 if (cmd
->base
.autoneg
== AUTONEG_ENABLE
)
391 XGBE_SET_ADV(lks
, Autoneg
);
393 XGBE_CLR_ADV(lks
, Autoneg
);
395 if (netif_running(netdev
))
396 ret
= pdata
->phy_if
.phy_config_aneg(pdata
);
401 static void xgbe_get_drvinfo(struct net_device
*netdev
,
402 struct ethtool_drvinfo
*drvinfo
)
404 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
405 struct xgbe_hw_features
*hw_feat
= &pdata
->hw_feat
;
407 strlcpy(drvinfo
->driver
, XGBE_DRV_NAME
, sizeof(drvinfo
->driver
));
408 strlcpy(drvinfo
->version
, XGBE_DRV_VERSION
, sizeof(drvinfo
->version
));
409 strlcpy(drvinfo
->bus_info
, dev_name(pdata
->dev
),
410 sizeof(drvinfo
->bus_info
));
411 snprintf(drvinfo
->fw_version
, sizeof(drvinfo
->fw_version
), "%d.%d.%d",
412 XGMAC_GET_BITS(hw_feat
->version
, MAC_VR
, USERVER
),
413 XGMAC_GET_BITS(hw_feat
->version
, MAC_VR
, DEVID
),
414 XGMAC_GET_BITS(hw_feat
->version
, MAC_VR
, SNPSVER
));
417 static u32
xgbe_get_msglevel(struct net_device
*netdev
)
419 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
421 return pdata
->msg_enable
;
424 static void xgbe_set_msglevel(struct net_device
*netdev
, u32 msglevel
)
426 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
428 pdata
->msg_enable
= msglevel
;
431 static int xgbe_get_coalesce(struct net_device
*netdev
,
432 struct ethtool_coalesce
*ec
)
434 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
436 memset(ec
, 0, sizeof(struct ethtool_coalesce
));
438 ec
->rx_coalesce_usecs
= pdata
->rx_usecs
;
439 ec
->rx_max_coalesced_frames
= pdata
->rx_frames
;
441 ec
->tx_max_coalesced_frames
= pdata
->tx_frames
;
446 static int xgbe_set_coalesce(struct net_device
*netdev
,
447 struct ethtool_coalesce
*ec
)
449 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
450 struct xgbe_hw_if
*hw_if
= &pdata
->hw_if
;
451 unsigned int rx_frames
, rx_riwt
, rx_usecs
;
452 unsigned int tx_frames
;
454 /* Check for not supported parameters */
455 if ((ec
->rx_coalesce_usecs_irq
) ||
456 (ec
->rx_max_coalesced_frames_irq
) ||
457 (ec
->tx_coalesce_usecs
) ||
458 (ec
->tx_coalesce_usecs_irq
) ||
459 (ec
->tx_max_coalesced_frames_irq
) ||
460 (ec
->stats_block_coalesce_usecs
) ||
461 (ec
->use_adaptive_rx_coalesce
) ||
462 (ec
->use_adaptive_tx_coalesce
) ||
463 (ec
->pkt_rate_low
) ||
464 (ec
->rx_coalesce_usecs_low
) ||
465 (ec
->rx_max_coalesced_frames_low
) ||
466 (ec
->tx_coalesce_usecs_low
) ||
467 (ec
->tx_max_coalesced_frames_low
) ||
468 (ec
->pkt_rate_high
) ||
469 (ec
->rx_coalesce_usecs_high
) ||
470 (ec
->rx_max_coalesced_frames_high
) ||
471 (ec
->tx_coalesce_usecs_high
) ||
472 (ec
->tx_max_coalesced_frames_high
) ||
473 (ec
->rate_sample_interval
)) {
474 netdev_err(netdev
, "unsupported coalescing parameter\n");
478 rx_riwt
= hw_if
->usec_to_riwt(pdata
, ec
->rx_coalesce_usecs
);
479 rx_usecs
= ec
->rx_coalesce_usecs
;
480 rx_frames
= ec
->rx_max_coalesced_frames
;
482 /* Use smallest possible value if conversion resulted in zero */
483 if (rx_usecs
&& !rx_riwt
)
486 /* Check the bounds of values for Rx */
487 if (rx_riwt
> XGMAC_MAX_DMA_RIWT
) {
488 netdev_err(netdev
, "rx-usec is limited to %d usecs\n",
489 hw_if
->riwt_to_usec(pdata
, XGMAC_MAX_DMA_RIWT
));
492 if (rx_frames
> pdata
->rx_desc_count
) {
493 netdev_err(netdev
, "rx-frames is limited to %d frames\n",
494 pdata
->rx_desc_count
);
498 tx_frames
= ec
->tx_max_coalesced_frames
;
500 /* Check the bounds of values for Tx */
501 if (tx_frames
> pdata
->tx_desc_count
) {
502 netdev_err(netdev
, "tx-frames is limited to %d frames\n",
503 pdata
->tx_desc_count
);
507 pdata
->rx_riwt
= rx_riwt
;
508 pdata
->rx_usecs
= rx_usecs
;
509 pdata
->rx_frames
= rx_frames
;
510 hw_if
->config_rx_coalesce(pdata
);
512 pdata
->tx_frames
= tx_frames
;
513 hw_if
->config_tx_coalesce(pdata
);
518 static int xgbe_get_rxnfc(struct net_device
*netdev
,
519 struct ethtool_rxnfc
*rxnfc
, u32
*rule_locs
)
521 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
523 switch (rxnfc
->cmd
) {
524 case ETHTOOL_GRXRINGS
:
525 rxnfc
->data
= pdata
->rx_ring_count
;
534 static u32
xgbe_get_rxfh_key_size(struct net_device
*netdev
)
536 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
538 return sizeof(pdata
->rss_key
);
541 static u32
xgbe_get_rxfh_indir_size(struct net_device
*netdev
)
543 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
545 return ARRAY_SIZE(pdata
->rss_table
);
548 static int xgbe_get_rxfh(struct net_device
*netdev
, u32
*indir
, u8
*key
,
551 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
555 for (i
= 0; i
< ARRAY_SIZE(pdata
->rss_table
); i
++)
556 indir
[i
] = XGMAC_GET_BITS(pdata
->rss_table
[i
],
561 memcpy(key
, pdata
->rss_key
, sizeof(pdata
->rss_key
));
564 *hfunc
= ETH_RSS_HASH_TOP
;
569 static int xgbe_set_rxfh(struct net_device
*netdev
, const u32
*indir
,
570 const u8
*key
, const u8 hfunc
)
572 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
573 struct xgbe_hw_if
*hw_if
= &pdata
->hw_if
;
576 if (hfunc
!= ETH_RSS_HASH_NO_CHANGE
&& hfunc
!= ETH_RSS_HASH_TOP
) {
577 netdev_err(netdev
, "unsupported hash function\n");
582 ret
= hw_if
->set_rss_lookup_table(pdata
, indir
);
588 ret
= hw_if
->set_rss_hash_key(pdata
, key
);
596 static int xgbe_get_ts_info(struct net_device
*netdev
,
597 struct ethtool_ts_info
*ts_info
)
599 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
601 ts_info
->so_timestamping
= SOF_TIMESTAMPING_TX_SOFTWARE
|
602 SOF_TIMESTAMPING_RX_SOFTWARE
|
603 SOF_TIMESTAMPING_SOFTWARE
|
604 SOF_TIMESTAMPING_TX_HARDWARE
|
605 SOF_TIMESTAMPING_RX_HARDWARE
|
606 SOF_TIMESTAMPING_RAW_HARDWARE
;
608 if (pdata
->ptp_clock
)
609 ts_info
->phc_index
= ptp_clock_index(pdata
->ptp_clock
);
611 ts_info
->phc_index
= -1;
613 ts_info
->tx_types
= (1 << HWTSTAMP_TX_OFF
) | (1 << HWTSTAMP_TX_ON
);
614 ts_info
->rx_filters
= (1 << HWTSTAMP_FILTER_NONE
) |
615 (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT
) |
616 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC
) |
617 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
) |
618 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT
) |
619 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC
) |
620 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
) |
621 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT
) |
622 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC
) |
623 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
) |
624 (1 << HWTSTAMP_FILTER_ALL
);
629 static int xgbe_get_module_info(struct net_device
*netdev
,
630 struct ethtool_modinfo
*modinfo
)
632 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
634 return pdata
->phy_if
.module_info(pdata
, modinfo
);
637 static int xgbe_get_module_eeprom(struct net_device
*netdev
,
638 struct ethtool_eeprom
*eeprom
, u8
*data
)
640 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
642 return pdata
->phy_if
.module_eeprom(pdata
, eeprom
, data
);
645 static void xgbe_get_ringparam(struct net_device
*netdev
,
646 struct ethtool_ringparam
*ringparam
)
648 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
650 ringparam
->rx_max_pending
= XGBE_RX_DESC_CNT_MAX
;
651 ringparam
->tx_max_pending
= XGBE_TX_DESC_CNT_MAX
;
652 ringparam
->rx_pending
= pdata
->rx_desc_count
;
653 ringparam
->tx_pending
= pdata
->tx_desc_count
;
656 static int xgbe_set_ringparam(struct net_device
*netdev
,
657 struct ethtool_ringparam
*ringparam
)
659 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
662 if (ringparam
->rx_mini_pending
|| ringparam
->rx_jumbo_pending
) {
663 netdev_err(netdev
, "unsupported ring parameter\n");
667 if ((ringparam
->rx_pending
< XGBE_RX_DESC_CNT_MIN
) ||
668 (ringparam
->rx_pending
> XGBE_RX_DESC_CNT_MAX
)) {
670 "rx ring parameter must be between %u and %u\n",
671 XGBE_RX_DESC_CNT_MIN
, XGBE_RX_DESC_CNT_MAX
);
675 if ((ringparam
->tx_pending
< XGBE_TX_DESC_CNT_MIN
) ||
676 (ringparam
->tx_pending
> XGBE_TX_DESC_CNT_MAX
)) {
678 "tx ring parameter must be between %u and %u\n",
679 XGBE_TX_DESC_CNT_MIN
, XGBE_TX_DESC_CNT_MAX
);
683 rx
= __rounddown_pow_of_two(ringparam
->rx_pending
);
684 if (rx
!= ringparam
->rx_pending
)
685 netdev_notice(netdev
,
686 "rx ring parameter rounded to power of two: %u\n",
689 tx
= __rounddown_pow_of_two(ringparam
->tx_pending
);
690 if (tx
!= ringparam
->tx_pending
)
691 netdev_notice(netdev
,
692 "tx ring parameter rounded to power of two: %u\n",
695 if ((rx
== pdata
->rx_desc_count
) &&
696 (tx
== pdata
->tx_desc_count
))
699 pdata
->rx_desc_count
= rx
;
700 pdata
->tx_desc_count
= tx
;
702 xgbe_restart_dev(pdata
);
708 static void xgbe_get_channels(struct net_device
*netdev
,
709 struct ethtool_channels
*channels
)
711 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
712 unsigned int rx
, tx
, combined
;
714 /* Calculate maximums allowed:
715 * - Take into account the number of available IRQs
716 * - Do not take into account the number of online CPUs so that
717 * the user can over-subscribe if desired
718 * - Tx is additionally limited by the number of hardware queues
720 rx
= min(pdata
->hw_feat
.rx_ch_cnt
, pdata
->rx_max_channel_count
);
721 rx
= min(rx
, pdata
->channel_irq_count
);
722 tx
= min(pdata
->hw_feat
.tx_ch_cnt
, pdata
->tx_max_channel_count
);
723 tx
= min(tx
, pdata
->channel_irq_count
);
724 tx
= min(tx
, pdata
->tx_max_q_count
);
726 combined
= min(rx
, tx
);
728 channels
->max_combined
= combined
;
729 channels
->max_rx
= rx
? rx
- 1 : 0;
730 channels
->max_tx
= tx
? tx
- 1 : 0;
732 /* Get current settings based on device state */
733 rx
= pdata
->new_rx_ring_count
? : pdata
->rx_ring_count
;
734 tx
= pdata
->new_tx_ring_count
? : pdata
->tx_ring_count
;
736 combined
= min(rx
, tx
);
740 channels
->combined_count
= combined
;
741 channels
->rx_count
= rx
;
742 channels
->tx_count
= tx
;
745 static void xgbe_print_set_channels_input(struct net_device
*netdev
,
746 struct ethtool_channels
*channels
)
748 netdev_err(netdev
, "channel inputs: combined=%u, rx-only=%u, tx-only=%u\n",
749 channels
->combined_count
, channels
->rx_count
,
753 static int xgbe_set_channels(struct net_device
*netdev
,
754 struct ethtool_channels
*channels
)
756 struct xgbe_prv_data
*pdata
= netdev_priv(netdev
);
757 unsigned int rx
, rx_curr
, tx
, tx_curr
, combined
;
759 /* Calculate maximums allowed:
760 * - Take into account the number of available IRQs
761 * - Do not take into account the number of online CPUs so that
762 * the user can over-subscribe if desired
763 * - Tx is additionally limited by the number of hardware queues
765 rx
= min(pdata
->hw_feat
.rx_ch_cnt
, pdata
->rx_max_channel_count
);
766 rx
= min(rx
, pdata
->channel_irq_count
);
767 tx
= min(pdata
->hw_feat
.tx_ch_cnt
, pdata
->tx_max_channel_count
);
768 tx
= min(tx
, pdata
->tx_max_q_count
);
769 tx
= min(tx
, pdata
->channel_irq_count
);
771 combined
= min(rx
, tx
);
773 /* Should not be setting other count */
774 if (channels
->other_count
) {
776 "other channel count must be zero\n");
780 /* Require at least one Combined (Rx and Tx) channel */
781 if (!channels
->combined_count
) {
783 "at least one combined Rx/Tx channel is required\n");
784 xgbe_print_set_channels_input(netdev
, channels
);
788 /* Check combined channels */
789 if (channels
->combined_count
> combined
) {
791 "combined channel count cannot exceed %u\n",
793 xgbe_print_set_channels_input(netdev
, channels
);
797 /* Can have some Rx-only or Tx-only channels, but not both */
798 if (channels
->rx_count
&& channels
->tx_count
) {
800 "cannot specify both Rx-only and Tx-only channels\n");
801 xgbe_print_set_channels_input(netdev
, channels
);
805 /* Check that we don't exceed the maximum number of channels */
806 if ((channels
->combined_count
+ channels
->rx_count
) > rx
) {
808 "total Rx channels (%u) requested exceeds maximum available (%u)\n",
809 channels
->combined_count
+ channels
->rx_count
, rx
);
810 xgbe_print_set_channels_input(netdev
, channels
);
814 if ((channels
->combined_count
+ channels
->tx_count
) > tx
) {
816 "total Tx channels (%u) requested exceeds maximum available (%u)\n",
817 channels
->combined_count
+ channels
->tx_count
, tx
);
818 xgbe_print_set_channels_input(netdev
, channels
);
822 rx
= channels
->combined_count
+ channels
->rx_count
;
823 tx
= channels
->combined_count
+ channels
->tx_count
;
825 rx_curr
= pdata
->new_rx_ring_count
? : pdata
->rx_ring_count
;
826 tx_curr
= pdata
->new_tx_ring_count
? : pdata
->tx_ring_count
;
828 if ((rx
== rx_curr
) && (tx
== tx_curr
))
831 pdata
->new_rx_ring_count
= rx
;
832 pdata
->new_tx_ring_count
= tx
;
834 xgbe_full_restart_dev(pdata
);
840 static const struct ethtool_ops xgbe_ethtool_ops
= {
841 .get_drvinfo
= xgbe_get_drvinfo
,
842 .get_msglevel
= xgbe_get_msglevel
,
843 .set_msglevel
= xgbe_set_msglevel
,
844 .get_link
= ethtool_op_get_link
,
845 .get_coalesce
= xgbe_get_coalesce
,
846 .set_coalesce
= xgbe_set_coalesce
,
847 .get_pauseparam
= xgbe_get_pauseparam
,
848 .set_pauseparam
= xgbe_set_pauseparam
,
849 .get_strings
= xgbe_get_strings
,
850 .get_ethtool_stats
= xgbe_get_ethtool_stats
,
851 .get_sset_count
= xgbe_get_sset_count
,
852 .get_rxnfc
= xgbe_get_rxnfc
,
853 .get_rxfh_key_size
= xgbe_get_rxfh_key_size
,
854 .get_rxfh_indir_size
= xgbe_get_rxfh_indir_size
,
855 .get_rxfh
= xgbe_get_rxfh
,
856 .set_rxfh
= xgbe_set_rxfh
,
857 .get_ts_info
= xgbe_get_ts_info
,
858 .get_link_ksettings
= xgbe_get_link_ksettings
,
859 .set_link_ksettings
= xgbe_set_link_ksettings
,
860 .get_module_info
= xgbe_get_module_info
,
861 .get_module_eeprom
= xgbe_get_module_eeprom
,
862 .get_ringparam
= xgbe_get_ringparam
,
863 .set_ringparam
= xgbe_set_ringparam
,
864 .get_channels
= xgbe_get_channels
,
865 .set_channels
= xgbe_set_channels
,
868 const struct ethtool_ops
*xgbe_get_ethtool_ops(void)
870 return &xgbe_ethtool_ops
;