18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * AMD 10Gb Ethernet driver
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This file is available to you under your choice of the following two
58c2ecf20Sopenharmony_ci * licenses:
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * License 1: GPLv2
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * This file is free software; you may copy, redistribute and/or modify
128c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
138c2ecf20Sopenharmony_ci * the Free Software Foundation, either version 2 of the License, or (at
148c2ecf20Sopenharmony_ci * your option) any later version.
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci * This file is distributed in the hope that it will be useful, but
178c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
188c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
198c2ecf20Sopenharmony_ci * General Public License for more details.
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License
228c2ecf20Sopenharmony_ci * along with this program.  If not, see <http://www.gnu.org/licenses/>.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * This file incorporates work covered by the following copyright and
258c2ecf20Sopenharmony_ci * permission notice:
268c2ecf20Sopenharmony_ci *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
278c2ecf20Sopenharmony_ci *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
288c2ecf20Sopenharmony_ci *     Inc. unless otherwise expressly agreed to in writing between Synopsys
298c2ecf20Sopenharmony_ci *     and you.
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci *     The Software IS NOT an item of Licensed Software or Licensed Product
328c2ecf20Sopenharmony_ci *     under any End User Software License Agreement or Agreement for Licensed
338c2ecf20Sopenharmony_ci *     Product with Synopsys or any supplement thereto.  Permission is hereby
348c2ecf20Sopenharmony_ci *     granted, free of charge, to any person obtaining a copy of this software
358c2ecf20Sopenharmony_ci *     annotated with this license and the Software, to deal in the Software
368c2ecf20Sopenharmony_ci *     without restriction, including without limitation the rights to use,
378c2ecf20Sopenharmony_ci *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
388c2ecf20Sopenharmony_ci *     of the Software, and to permit persons to whom the Software is furnished
398c2ecf20Sopenharmony_ci *     to do so, subject to the following conditions:
408c2ecf20Sopenharmony_ci *
418c2ecf20Sopenharmony_ci *     The above copyright notice and this permission notice shall be included
428c2ecf20Sopenharmony_ci *     in all copies or substantial portions of the Software.
438c2ecf20Sopenharmony_ci *
448c2ecf20Sopenharmony_ci *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
458c2ecf20Sopenharmony_ci *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
468c2ecf20Sopenharmony_ci *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
478c2ecf20Sopenharmony_ci *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
488c2ecf20Sopenharmony_ci *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
498c2ecf20Sopenharmony_ci *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
508c2ecf20Sopenharmony_ci *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
518c2ecf20Sopenharmony_ci *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
528c2ecf20Sopenharmony_ci *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
538c2ecf20Sopenharmony_ci *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
548c2ecf20Sopenharmony_ci *     THE POSSIBILITY OF SUCH DAMAGE.
558c2ecf20Sopenharmony_ci *
568c2ecf20Sopenharmony_ci *
578c2ecf20Sopenharmony_ci * License 2: Modified BSD
588c2ecf20Sopenharmony_ci *
598c2ecf20Sopenharmony_ci * Copyright (c) 2014-2016 Advanced Micro Devices, Inc.
608c2ecf20Sopenharmony_ci * All rights reserved.
618c2ecf20Sopenharmony_ci *
628c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
638c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met:
648c2ecf20Sopenharmony_ci *     * Redistributions of source code must retain the above copyright
658c2ecf20Sopenharmony_ci *       notice, this list of conditions and the following disclaimer.
668c2ecf20Sopenharmony_ci *     * Redistributions in binary form must reproduce the above copyright
678c2ecf20Sopenharmony_ci *       notice, this list of conditions and the following disclaimer in the
688c2ecf20Sopenharmony_ci *       documentation and/or other materials provided with the distribution.
698c2ecf20Sopenharmony_ci *     * Neither the name of Advanced Micro Devices, Inc. nor the
708c2ecf20Sopenharmony_ci *       names of its contributors may be used to endorse or promote products
718c2ecf20Sopenharmony_ci *       derived from this software without specific prior written permission.
728c2ecf20Sopenharmony_ci *
738c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
748c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
758c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
768c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
778c2ecf20Sopenharmony_ci * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
788c2ecf20Sopenharmony_ci * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
798c2ecf20Sopenharmony_ci * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
808c2ecf20Sopenharmony_ci * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
818c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
828c2ecf20Sopenharmony_ci * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
838c2ecf20Sopenharmony_ci *
848c2ecf20Sopenharmony_ci * This file incorporates work covered by the following copyright and
858c2ecf20Sopenharmony_ci * permission notice:
868c2ecf20Sopenharmony_ci *     The Synopsys DWC ETHER XGMAC Software Driver and documentation
878c2ecf20Sopenharmony_ci *     (hereinafter "Software") is an unsupported proprietary work of Synopsys,
888c2ecf20Sopenharmony_ci *     Inc. unless otherwise expressly agreed to in writing between Synopsys
898c2ecf20Sopenharmony_ci *     and you.
908c2ecf20Sopenharmony_ci *
918c2ecf20Sopenharmony_ci *     The Software IS NOT an item of Licensed Software or Licensed Product
928c2ecf20Sopenharmony_ci *     under any End User Software License Agreement or Agreement for Licensed
938c2ecf20Sopenharmony_ci *     Product with Synopsys or any supplement thereto.  Permission is hereby
948c2ecf20Sopenharmony_ci *     granted, free of charge, to any person obtaining a copy of this software
958c2ecf20Sopenharmony_ci *     annotated with this license and the Software, to deal in the Software
968c2ecf20Sopenharmony_ci *     without restriction, including without limitation the rights to use,
978c2ecf20Sopenharmony_ci *     copy, modify, merge, publish, distribute, sublicense, and/or sell copies
988c2ecf20Sopenharmony_ci *     of the Software, and to permit persons to whom the Software is furnished
998c2ecf20Sopenharmony_ci *     to do so, subject to the following conditions:
1008c2ecf20Sopenharmony_ci *
1018c2ecf20Sopenharmony_ci *     The above copyright notice and this permission notice shall be included
1028c2ecf20Sopenharmony_ci *     in all copies or substantial portions of the Software.
1038c2ecf20Sopenharmony_ci *
1048c2ecf20Sopenharmony_ci *     THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
1058c2ecf20Sopenharmony_ci *     BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1068c2ecf20Sopenharmony_ci *     TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
1078c2ecf20Sopenharmony_ci *     PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
1088c2ecf20Sopenharmony_ci *     BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1098c2ecf20Sopenharmony_ci *     CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1108c2ecf20Sopenharmony_ci *     SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1118c2ecf20Sopenharmony_ci *     INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1128c2ecf20Sopenharmony_ci *     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1138c2ecf20Sopenharmony_ci *     ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
1148c2ecf20Sopenharmony_ci *     THE POSSIBILITY OF SUCH DAMAGE.
1158c2ecf20Sopenharmony_ci */
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
1188c2ecf20Sopenharmony_ci#include <linux/phy.h>
1198c2ecf20Sopenharmony_ci#include <linux/net_tstamp.h>
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci#include "xgbe.h"
1228c2ecf20Sopenharmony_ci#include "xgbe-common.h"
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_cistruct xgbe_stats {
1258c2ecf20Sopenharmony_ci	char stat_string[ETH_GSTRING_LEN];
1268c2ecf20Sopenharmony_ci	int stat_size;
1278c2ecf20Sopenharmony_ci	int stat_offset;
1288c2ecf20Sopenharmony_ci};
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci#define XGMAC_MMC_STAT(_string, _var)				\
1318c2ecf20Sopenharmony_ci	{ _string,						\
1328c2ecf20Sopenharmony_ci	  sizeof_field(struct xgbe_mmc_stats, _var),		\
1338c2ecf20Sopenharmony_ci	  offsetof(struct xgbe_prv_data, mmc_stats._var),	\
1348c2ecf20Sopenharmony_ci	}
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci#define XGMAC_EXT_STAT(_string, _var)				\
1378c2ecf20Sopenharmony_ci	{ _string,						\
1388c2ecf20Sopenharmony_ci	  sizeof_field(struct xgbe_ext_stats, _var),		\
1398c2ecf20Sopenharmony_ci	  offsetof(struct xgbe_prv_data, ext_stats._var),	\
1408c2ecf20Sopenharmony_ci	}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_cistatic const struct xgbe_stats xgbe_gstring_stats[] = {
1438c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_bytes", txoctetcount_gb),
1448c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_packets", txframecount_gb),
1458c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb),
1468c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb),
1478c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb),
1488c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g),
1498c2ecf20Sopenharmony_ci	XGMAC_EXT_STAT("tx_vxlan_packets", tx_vxlan_packets),
1508c2ecf20Sopenharmony_ci	XGMAC_EXT_STAT("tx_tso_packets", tx_tso_packets),
1518c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb),
1528c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb),
1538c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb),
1548c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb),
1558c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb),
1568c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb),
1578c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror),
1588c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("tx_pause_frames", txpauseframes),
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb),
1618c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_packets", rxframecount_gb),
1628c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g),
1638c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g),
1648c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g),
1658c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb),
1668c2ecf20Sopenharmony_ci	XGMAC_EXT_STAT("rx_vxlan_packets", rx_vxlan_packets),
1678c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb),
1688c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb),
1698c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb),
1708c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb),
1718c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb),
1728c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb),
1738c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g),
1748c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g),
1758c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_crc_errors", rxcrcerror),
1768c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror),
1778c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror),
1788c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_length_errors", rxlengtherror),
1798c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype),
1808c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow),
1818c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror),
1828c2ecf20Sopenharmony_ci	XGMAC_EXT_STAT("rx_csum_errors", rx_csum_errors),
1838c2ecf20Sopenharmony_ci	XGMAC_EXT_STAT("rx_vxlan_csum_errors", rx_vxlan_csum_errors),
1848c2ecf20Sopenharmony_ci	XGMAC_MMC_STAT("rx_pause_frames", rxpauseframes),
1858c2ecf20Sopenharmony_ci	XGMAC_EXT_STAT("rx_split_header_packets", rx_split_header_packets),
1868c2ecf20Sopenharmony_ci	XGMAC_EXT_STAT("rx_buffer_unavailable", rx_buffer_unavailable),
1878c2ecf20Sopenharmony_ci};
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci#define XGBE_STATS_COUNT	ARRAY_SIZE(xgbe_gstring_stats)
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_cistatic void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
1928c2ecf20Sopenharmony_ci{
1938c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
1948c2ecf20Sopenharmony_ci	int i;
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci	switch (stringset) {
1978c2ecf20Sopenharmony_ci	case ETH_SS_STATS:
1988c2ecf20Sopenharmony_ci		for (i = 0; i < XGBE_STATS_COUNT; i++) {
1998c2ecf20Sopenharmony_ci			memcpy(data, xgbe_gstring_stats[i].stat_string,
2008c2ecf20Sopenharmony_ci			       ETH_GSTRING_LEN);
2018c2ecf20Sopenharmony_ci			data += ETH_GSTRING_LEN;
2028c2ecf20Sopenharmony_ci		}
2038c2ecf20Sopenharmony_ci		for (i = 0; i < pdata->tx_ring_count; i++) {
2048c2ecf20Sopenharmony_ci			sprintf(data, "txq_%u_packets", i);
2058c2ecf20Sopenharmony_ci			data += ETH_GSTRING_LEN;
2068c2ecf20Sopenharmony_ci			sprintf(data, "txq_%u_bytes", i);
2078c2ecf20Sopenharmony_ci			data += ETH_GSTRING_LEN;
2088c2ecf20Sopenharmony_ci		}
2098c2ecf20Sopenharmony_ci		for (i = 0; i < pdata->rx_ring_count; i++) {
2108c2ecf20Sopenharmony_ci			sprintf(data, "rxq_%u_packets", i);
2118c2ecf20Sopenharmony_ci			data += ETH_GSTRING_LEN;
2128c2ecf20Sopenharmony_ci			sprintf(data, "rxq_%u_bytes", i);
2138c2ecf20Sopenharmony_ci			data += ETH_GSTRING_LEN;
2148c2ecf20Sopenharmony_ci		}
2158c2ecf20Sopenharmony_ci		break;
2168c2ecf20Sopenharmony_ci	}
2178c2ecf20Sopenharmony_ci}
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistatic void xgbe_get_ethtool_stats(struct net_device *netdev,
2208c2ecf20Sopenharmony_ci				   struct ethtool_stats *stats, u64 *data)
2218c2ecf20Sopenharmony_ci{
2228c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
2238c2ecf20Sopenharmony_ci	u8 *stat;
2248c2ecf20Sopenharmony_ci	int i;
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	pdata->hw_if.read_mmc_stats(pdata);
2278c2ecf20Sopenharmony_ci	for (i = 0; i < XGBE_STATS_COUNT; i++) {
2288c2ecf20Sopenharmony_ci		stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
2298c2ecf20Sopenharmony_ci		*data++ = *(u64 *)stat;
2308c2ecf20Sopenharmony_ci	}
2318c2ecf20Sopenharmony_ci	for (i = 0; i < pdata->tx_ring_count; i++) {
2328c2ecf20Sopenharmony_ci		*data++ = pdata->ext_stats.txq_packets[i];
2338c2ecf20Sopenharmony_ci		*data++ = pdata->ext_stats.txq_bytes[i];
2348c2ecf20Sopenharmony_ci	}
2358c2ecf20Sopenharmony_ci	for (i = 0; i < pdata->rx_ring_count; i++) {
2368c2ecf20Sopenharmony_ci		*data++ = pdata->ext_stats.rxq_packets[i];
2378c2ecf20Sopenharmony_ci		*data++ = pdata->ext_stats.rxq_bytes[i];
2388c2ecf20Sopenharmony_ci	}
2398c2ecf20Sopenharmony_ci}
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistatic int xgbe_get_sset_count(struct net_device *netdev, int stringset)
2428c2ecf20Sopenharmony_ci{
2438c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
2448c2ecf20Sopenharmony_ci	int ret;
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci	switch (stringset) {
2478c2ecf20Sopenharmony_ci	case ETH_SS_STATS:
2488c2ecf20Sopenharmony_ci		ret = XGBE_STATS_COUNT +
2498c2ecf20Sopenharmony_ci		      (pdata->tx_ring_count * 2) +
2508c2ecf20Sopenharmony_ci		      (pdata->rx_ring_count * 2);
2518c2ecf20Sopenharmony_ci		break;
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci	default:
2548c2ecf20Sopenharmony_ci		ret = -EOPNOTSUPP;
2558c2ecf20Sopenharmony_ci	}
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci	return ret;
2588c2ecf20Sopenharmony_ci}
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cistatic void xgbe_get_pauseparam(struct net_device *netdev,
2618c2ecf20Sopenharmony_ci				struct ethtool_pauseparam *pause)
2628c2ecf20Sopenharmony_ci{
2638c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	pause->autoneg = pdata->phy.pause_autoneg;
2668c2ecf20Sopenharmony_ci	pause->tx_pause = pdata->phy.tx_pause;
2678c2ecf20Sopenharmony_ci	pause->rx_pause = pdata->phy.rx_pause;
2688c2ecf20Sopenharmony_ci}
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_cistatic int xgbe_set_pauseparam(struct net_device *netdev,
2718c2ecf20Sopenharmony_ci			       struct ethtool_pauseparam *pause)
2728c2ecf20Sopenharmony_ci{
2738c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
2748c2ecf20Sopenharmony_ci	struct ethtool_link_ksettings *lks = &pdata->phy.lks;
2758c2ecf20Sopenharmony_ci	int ret = 0;
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	if (pause->autoneg && (pdata->phy.autoneg != AUTONEG_ENABLE)) {
2788c2ecf20Sopenharmony_ci		netdev_err(netdev,
2798c2ecf20Sopenharmony_ci			   "autoneg disabled, pause autoneg not available\n");
2808c2ecf20Sopenharmony_ci		return -EINVAL;
2818c2ecf20Sopenharmony_ci	}
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	pdata->phy.pause_autoneg = pause->autoneg;
2848c2ecf20Sopenharmony_ci	pdata->phy.tx_pause = pause->tx_pause;
2858c2ecf20Sopenharmony_ci	pdata->phy.rx_pause = pause->rx_pause;
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci	XGBE_CLR_ADV(lks, Pause);
2888c2ecf20Sopenharmony_ci	XGBE_CLR_ADV(lks, Asym_Pause);
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	if (pause->rx_pause) {
2918c2ecf20Sopenharmony_ci		XGBE_SET_ADV(lks, Pause);
2928c2ecf20Sopenharmony_ci		XGBE_SET_ADV(lks, Asym_Pause);
2938c2ecf20Sopenharmony_ci	}
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci	if (pause->tx_pause) {
2968c2ecf20Sopenharmony_ci		/* Equivalent to XOR of Asym_Pause */
2978c2ecf20Sopenharmony_ci		if (XGBE_ADV(lks, Asym_Pause))
2988c2ecf20Sopenharmony_ci			XGBE_CLR_ADV(lks, Asym_Pause);
2998c2ecf20Sopenharmony_ci		else
3008c2ecf20Sopenharmony_ci			XGBE_SET_ADV(lks, Asym_Pause);
3018c2ecf20Sopenharmony_ci	}
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	if (netif_running(netdev))
3048c2ecf20Sopenharmony_ci		ret = pdata->phy_if.phy_config_aneg(pdata);
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_ci	return ret;
3078c2ecf20Sopenharmony_ci}
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_cistatic int xgbe_get_link_ksettings(struct net_device *netdev,
3108c2ecf20Sopenharmony_ci				   struct ethtool_link_ksettings *cmd)
3118c2ecf20Sopenharmony_ci{
3128c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
3138c2ecf20Sopenharmony_ci	struct ethtool_link_ksettings *lks = &pdata->phy.lks;
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	cmd->base.phy_address = pdata->phy.address;
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci	if (netif_carrier_ok(netdev)) {
3188c2ecf20Sopenharmony_ci		cmd->base.speed = pdata->phy.speed;
3198c2ecf20Sopenharmony_ci		cmd->base.duplex = pdata->phy.duplex;
3208c2ecf20Sopenharmony_ci	} else {
3218c2ecf20Sopenharmony_ci		cmd->base.speed = SPEED_UNKNOWN;
3228c2ecf20Sopenharmony_ci		cmd->base.duplex = DUPLEX_UNKNOWN;
3238c2ecf20Sopenharmony_ci	}
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	cmd->base.autoneg = pdata->phy.autoneg;
3268c2ecf20Sopenharmony_ci	cmd->base.port = PORT_NONE;
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	XGBE_LM_COPY(cmd, supported, lks, supported);
3298c2ecf20Sopenharmony_ci	XGBE_LM_COPY(cmd, advertising, lks, advertising);
3308c2ecf20Sopenharmony_ci	XGBE_LM_COPY(cmd, lp_advertising, lks, lp_advertising);
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	return 0;
3338c2ecf20Sopenharmony_ci}
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_cistatic int xgbe_set_link_ksettings(struct net_device *netdev,
3368c2ecf20Sopenharmony_ci				   const struct ethtool_link_ksettings *cmd)
3378c2ecf20Sopenharmony_ci{
3388c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
3398c2ecf20Sopenharmony_ci	struct ethtool_link_ksettings *lks = &pdata->phy.lks;
3408c2ecf20Sopenharmony_ci	__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
3418c2ecf20Sopenharmony_ci	u32 speed;
3428c2ecf20Sopenharmony_ci	int ret;
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci	speed = cmd->base.speed;
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci	if (cmd->base.phy_address != pdata->phy.address) {
3478c2ecf20Sopenharmony_ci		netdev_err(netdev, "invalid phy address %hhu\n",
3488c2ecf20Sopenharmony_ci			   cmd->base.phy_address);
3498c2ecf20Sopenharmony_ci		return -EINVAL;
3508c2ecf20Sopenharmony_ci	}
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	if ((cmd->base.autoneg != AUTONEG_ENABLE) &&
3538c2ecf20Sopenharmony_ci	    (cmd->base.autoneg != AUTONEG_DISABLE)) {
3548c2ecf20Sopenharmony_ci		netdev_err(netdev, "unsupported autoneg %hhu\n",
3558c2ecf20Sopenharmony_ci			   cmd->base.autoneg);
3568c2ecf20Sopenharmony_ci		return -EINVAL;
3578c2ecf20Sopenharmony_ci	}
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci	if (cmd->base.autoneg == AUTONEG_DISABLE) {
3608c2ecf20Sopenharmony_ci		if (!pdata->phy_if.phy_valid_speed(pdata, speed)) {
3618c2ecf20Sopenharmony_ci			netdev_err(netdev, "unsupported speed %u\n", speed);
3628c2ecf20Sopenharmony_ci			return -EINVAL;
3638c2ecf20Sopenharmony_ci		}
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci		if (cmd->base.duplex != DUPLEX_FULL) {
3668c2ecf20Sopenharmony_ci			netdev_err(netdev, "unsupported duplex %hhu\n",
3678c2ecf20Sopenharmony_ci				   cmd->base.duplex);
3688c2ecf20Sopenharmony_ci			return -EINVAL;
3698c2ecf20Sopenharmony_ci		}
3708c2ecf20Sopenharmony_ci	}
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ci	netif_dbg(pdata, link, netdev,
3738c2ecf20Sopenharmony_ci		  "requested advertisement 0x%*pb, phy supported 0x%*pb\n",
3748c2ecf20Sopenharmony_ci		  __ETHTOOL_LINK_MODE_MASK_NBITS, cmd->link_modes.advertising,
3758c2ecf20Sopenharmony_ci		  __ETHTOOL_LINK_MODE_MASK_NBITS, lks->link_modes.supported);
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	bitmap_and(advertising,
3788c2ecf20Sopenharmony_ci		   cmd->link_modes.advertising, lks->link_modes.supported,
3798c2ecf20Sopenharmony_ci		   __ETHTOOL_LINK_MODE_MASK_NBITS);
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci	if ((cmd->base.autoneg == AUTONEG_ENABLE) &&
3828c2ecf20Sopenharmony_ci	    bitmap_empty(advertising, __ETHTOOL_LINK_MODE_MASK_NBITS)) {
3838c2ecf20Sopenharmony_ci		netdev_err(netdev,
3848c2ecf20Sopenharmony_ci			   "unsupported requested advertisement\n");
3858c2ecf20Sopenharmony_ci		return -EINVAL;
3868c2ecf20Sopenharmony_ci	}
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	ret = 0;
3898c2ecf20Sopenharmony_ci	pdata->phy.autoneg = cmd->base.autoneg;
3908c2ecf20Sopenharmony_ci	pdata->phy.speed = speed;
3918c2ecf20Sopenharmony_ci	pdata->phy.duplex = cmd->base.duplex;
3928c2ecf20Sopenharmony_ci	bitmap_copy(lks->link_modes.advertising, advertising,
3938c2ecf20Sopenharmony_ci		    __ETHTOOL_LINK_MODE_MASK_NBITS);
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci	if (cmd->base.autoneg == AUTONEG_ENABLE)
3968c2ecf20Sopenharmony_ci		XGBE_SET_ADV(lks, Autoneg);
3978c2ecf20Sopenharmony_ci	else
3988c2ecf20Sopenharmony_ci		XGBE_CLR_ADV(lks, Autoneg);
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	if (netif_running(netdev))
4018c2ecf20Sopenharmony_ci		ret = pdata->phy_if.phy_config_aneg(pdata);
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	return ret;
4048c2ecf20Sopenharmony_ci}
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_cistatic void xgbe_get_drvinfo(struct net_device *netdev,
4078c2ecf20Sopenharmony_ci			     struct ethtool_drvinfo *drvinfo)
4088c2ecf20Sopenharmony_ci{
4098c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
4108c2ecf20Sopenharmony_ci	struct xgbe_hw_features *hw_feat = &pdata->hw_feat;
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver));
4138c2ecf20Sopenharmony_ci	strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
4148c2ecf20Sopenharmony_ci		sizeof(drvinfo->bus_info));
4158c2ecf20Sopenharmony_ci	snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d",
4168c2ecf20Sopenharmony_ci		 XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
4178c2ecf20Sopenharmony_ci		 XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
4188c2ecf20Sopenharmony_ci		 XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
4198c2ecf20Sopenharmony_ci}
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_cistatic u32 xgbe_get_msglevel(struct net_device *netdev)
4228c2ecf20Sopenharmony_ci{
4238c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_ci	return pdata->msg_enable;
4268c2ecf20Sopenharmony_ci}
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_cistatic void xgbe_set_msglevel(struct net_device *netdev, u32 msglevel)
4298c2ecf20Sopenharmony_ci{
4308c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ci	pdata->msg_enable = msglevel;
4338c2ecf20Sopenharmony_ci}
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_cistatic int xgbe_get_coalesce(struct net_device *netdev,
4368c2ecf20Sopenharmony_ci			     struct ethtool_coalesce *ec)
4378c2ecf20Sopenharmony_ci{
4388c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci	memset(ec, 0, sizeof(struct ethtool_coalesce));
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci	ec->rx_coalesce_usecs = pdata->rx_usecs;
4438c2ecf20Sopenharmony_ci	ec->rx_max_coalesced_frames = pdata->rx_frames;
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	ec->tx_max_coalesced_frames = pdata->tx_frames;
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci	return 0;
4488c2ecf20Sopenharmony_ci}
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_cistatic int xgbe_set_coalesce(struct net_device *netdev,
4518c2ecf20Sopenharmony_ci			     struct ethtool_coalesce *ec)
4528c2ecf20Sopenharmony_ci{
4538c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
4548c2ecf20Sopenharmony_ci	struct xgbe_hw_if *hw_if = &pdata->hw_if;
4558c2ecf20Sopenharmony_ci	unsigned int rx_frames, rx_riwt, rx_usecs;
4568c2ecf20Sopenharmony_ci	unsigned int tx_frames;
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci	rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs);
4598c2ecf20Sopenharmony_ci	rx_usecs = ec->rx_coalesce_usecs;
4608c2ecf20Sopenharmony_ci	rx_frames = ec->rx_max_coalesced_frames;
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_ci	/* Use smallest possible value if conversion resulted in zero */
4638c2ecf20Sopenharmony_ci	if (rx_usecs && !rx_riwt)
4648c2ecf20Sopenharmony_ci		rx_riwt = 1;
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ci	/* Check the bounds of values for Rx */
4678c2ecf20Sopenharmony_ci	if (rx_riwt > XGMAC_MAX_DMA_RIWT) {
4688c2ecf20Sopenharmony_ci		netdev_err(netdev, "rx-usec is limited to %d usecs\n",
4698c2ecf20Sopenharmony_ci			   hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT));
4708c2ecf20Sopenharmony_ci		return -EINVAL;
4718c2ecf20Sopenharmony_ci	}
4728c2ecf20Sopenharmony_ci	if (rx_frames > pdata->rx_desc_count) {
4738c2ecf20Sopenharmony_ci		netdev_err(netdev, "rx-frames is limited to %d frames\n",
4748c2ecf20Sopenharmony_ci			   pdata->rx_desc_count);
4758c2ecf20Sopenharmony_ci		return -EINVAL;
4768c2ecf20Sopenharmony_ci	}
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_ci	tx_frames = ec->tx_max_coalesced_frames;
4798c2ecf20Sopenharmony_ci
4808c2ecf20Sopenharmony_ci	/* Check the bounds of values for Tx */
4818c2ecf20Sopenharmony_ci	if (tx_frames > pdata->tx_desc_count) {
4828c2ecf20Sopenharmony_ci		netdev_err(netdev, "tx-frames is limited to %d frames\n",
4838c2ecf20Sopenharmony_ci			   pdata->tx_desc_count);
4848c2ecf20Sopenharmony_ci		return -EINVAL;
4858c2ecf20Sopenharmony_ci	}
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci	pdata->rx_riwt = rx_riwt;
4888c2ecf20Sopenharmony_ci	pdata->rx_usecs = rx_usecs;
4898c2ecf20Sopenharmony_ci	pdata->rx_frames = rx_frames;
4908c2ecf20Sopenharmony_ci	hw_if->config_rx_coalesce(pdata);
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci	pdata->tx_frames = tx_frames;
4938c2ecf20Sopenharmony_ci	hw_if->config_tx_coalesce(pdata);
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_ci	return 0;
4968c2ecf20Sopenharmony_ci}
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_cistatic int xgbe_get_rxnfc(struct net_device *netdev,
4998c2ecf20Sopenharmony_ci			  struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
5008c2ecf20Sopenharmony_ci{
5018c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci	switch (rxnfc->cmd) {
5048c2ecf20Sopenharmony_ci	case ETHTOOL_GRXRINGS:
5058c2ecf20Sopenharmony_ci		rxnfc->data = pdata->rx_ring_count;
5068c2ecf20Sopenharmony_ci		break;
5078c2ecf20Sopenharmony_ci	default:
5088c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
5098c2ecf20Sopenharmony_ci	}
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci	return 0;
5128c2ecf20Sopenharmony_ci}
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_cistatic u32 xgbe_get_rxfh_key_size(struct net_device *netdev)
5158c2ecf20Sopenharmony_ci{
5168c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci	return sizeof(pdata->rss_key);
5198c2ecf20Sopenharmony_ci}
5208c2ecf20Sopenharmony_ci
5218c2ecf20Sopenharmony_cistatic u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
5228c2ecf20Sopenharmony_ci{
5238c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
5248c2ecf20Sopenharmony_ci
5258c2ecf20Sopenharmony_ci	return ARRAY_SIZE(pdata->rss_table);
5268c2ecf20Sopenharmony_ci}
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_cistatic int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
5298c2ecf20Sopenharmony_ci			 u8 *hfunc)
5308c2ecf20Sopenharmony_ci{
5318c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
5328c2ecf20Sopenharmony_ci	unsigned int i;
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_ci	if (indir) {
5358c2ecf20Sopenharmony_ci		for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
5368c2ecf20Sopenharmony_ci			indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
5378c2ecf20Sopenharmony_ci						  MAC_RSSDR, DMCH);
5388c2ecf20Sopenharmony_ci	}
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_ci	if (key)
5418c2ecf20Sopenharmony_ci		memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_ci	if (hfunc)
5448c2ecf20Sopenharmony_ci		*hfunc = ETH_RSS_HASH_TOP;
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_ci	return 0;
5478c2ecf20Sopenharmony_ci}
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_cistatic int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
5508c2ecf20Sopenharmony_ci			 const u8 *key, const u8 hfunc)
5518c2ecf20Sopenharmony_ci{
5528c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
5538c2ecf20Sopenharmony_ci	struct xgbe_hw_if *hw_if = &pdata->hw_if;
5548c2ecf20Sopenharmony_ci	unsigned int ret;
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_ci	if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) {
5578c2ecf20Sopenharmony_ci		netdev_err(netdev, "unsupported hash function\n");
5588c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
5598c2ecf20Sopenharmony_ci	}
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci	if (indir) {
5628c2ecf20Sopenharmony_ci		ret = hw_if->set_rss_lookup_table(pdata, indir);
5638c2ecf20Sopenharmony_ci		if (ret)
5648c2ecf20Sopenharmony_ci			return ret;
5658c2ecf20Sopenharmony_ci	}
5668c2ecf20Sopenharmony_ci
5678c2ecf20Sopenharmony_ci	if (key) {
5688c2ecf20Sopenharmony_ci		ret = hw_if->set_rss_hash_key(pdata, key);
5698c2ecf20Sopenharmony_ci		if (ret)
5708c2ecf20Sopenharmony_ci			return ret;
5718c2ecf20Sopenharmony_ci	}
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci	return 0;
5748c2ecf20Sopenharmony_ci}
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_cistatic int xgbe_get_ts_info(struct net_device *netdev,
5778c2ecf20Sopenharmony_ci			    struct ethtool_ts_info *ts_info)
5788c2ecf20Sopenharmony_ci{
5798c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_ci	ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
5828c2ecf20Sopenharmony_ci				   SOF_TIMESTAMPING_RX_SOFTWARE |
5838c2ecf20Sopenharmony_ci				   SOF_TIMESTAMPING_SOFTWARE |
5848c2ecf20Sopenharmony_ci				   SOF_TIMESTAMPING_TX_HARDWARE |
5858c2ecf20Sopenharmony_ci				   SOF_TIMESTAMPING_RX_HARDWARE |
5868c2ecf20Sopenharmony_ci				   SOF_TIMESTAMPING_RAW_HARDWARE;
5878c2ecf20Sopenharmony_ci
5888c2ecf20Sopenharmony_ci	if (pdata->ptp_clock)
5898c2ecf20Sopenharmony_ci		ts_info->phc_index = ptp_clock_index(pdata->ptp_clock);
5908c2ecf20Sopenharmony_ci	else
5918c2ecf20Sopenharmony_ci		ts_info->phc_index = -1;
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci	ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
5948c2ecf20Sopenharmony_ci	ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
5958c2ecf20Sopenharmony_ci			      (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
5968c2ecf20Sopenharmony_ci			      (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
5978c2ecf20Sopenharmony_ci			      (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
5988c2ecf20Sopenharmony_ci			      (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
5998c2ecf20Sopenharmony_ci			      (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
6008c2ecf20Sopenharmony_ci			      (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
6018c2ecf20Sopenharmony_ci			      (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
6028c2ecf20Sopenharmony_ci			      (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
6038c2ecf20Sopenharmony_ci			      (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
6048c2ecf20Sopenharmony_ci			      (1 << HWTSTAMP_FILTER_ALL);
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_ci	return 0;
6078c2ecf20Sopenharmony_ci}
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_cistatic int xgbe_get_module_info(struct net_device *netdev,
6108c2ecf20Sopenharmony_ci				struct ethtool_modinfo *modinfo)
6118c2ecf20Sopenharmony_ci{
6128c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
6138c2ecf20Sopenharmony_ci
6148c2ecf20Sopenharmony_ci	return pdata->phy_if.module_info(pdata, modinfo);
6158c2ecf20Sopenharmony_ci}
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_cistatic int xgbe_get_module_eeprom(struct net_device *netdev,
6188c2ecf20Sopenharmony_ci				  struct ethtool_eeprom *eeprom, u8 *data)
6198c2ecf20Sopenharmony_ci{
6208c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
6218c2ecf20Sopenharmony_ci
6228c2ecf20Sopenharmony_ci	return pdata->phy_if.module_eeprom(pdata, eeprom, data);
6238c2ecf20Sopenharmony_ci}
6248c2ecf20Sopenharmony_ci
6258c2ecf20Sopenharmony_cistatic void xgbe_get_ringparam(struct net_device *netdev,
6268c2ecf20Sopenharmony_ci			       struct ethtool_ringparam *ringparam)
6278c2ecf20Sopenharmony_ci{
6288c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_ci	ringparam->rx_max_pending = XGBE_RX_DESC_CNT_MAX;
6318c2ecf20Sopenharmony_ci	ringparam->tx_max_pending = XGBE_TX_DESC_CNT_MAX;
6328c2ecf20Sopenharmony_ci	ringparam->rx_pending = pdata->rx_desc_count;
6338c2ecf20Sopenharmony_ci	ringparam->tx_pending = pdata->tx_desc_count;
6348c2ecf20Sopenharmony_ci}
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_cistatic int xgbe_set_ringparam(struct net_device *netdev,
6378c2ecf20Sopenharmony_ci			      struct ethtool_ringparam *ringparam)
6388c2ecf20Sopenharmony_ci{
6398c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
6408c2ecf20Sopenharmony_ci	unsigned int rx, tx;
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci	if (ringparam->rx_mini_pending || ringparam->rx_jumbo_pending) {
6438c2ecf20Sopenharmony_ci		netdev_err(netdev, "unsupported ring parameter\n");
6448c2ecf20Sopenharmony_ci		return -EINVAL;
6458c2ecf20Sopenharmony_ci	}
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci	if ((ringparam->rx_pending < XGBE_RX_DESC_CNT_MIN) ||
6488c2ecf20Sopenharmony_ci	    (ringparam->rx_pending > XGBE_RX_DESC_CNT_MAX)) {
6498c2ecf20Sopenharmony_ci		netdev_err(netdev,
6508c2ecf20Sopenharmony_ci			   "rx ring parameter must be between %u and %u\n",
6518c2ecf20Sopenharmony_ci			   XGBE_RX_DESC_CNT_MIN, XGBE_RX_DESC_CNT_MAX);
6528c2ecf20Sopenharmony_ci		return -EINVAL;
6538c2ecf20Sopenharmony_ci	}
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci	if ((ringparam->tx_pending < XGBE_TX_DESC_CNT_MIN) ||
6568c2ecf20Sopenharmony_ci	    (ringparam->tx_pending > XGBE_TX_DESC_CNT_MAX)) {
6578c2ecf20Sopenharmony_ci		netdev_err(netdev,
6588c2ecf20Sopenharmony_ci			   "tx ring parameter must be between %u and %u\n",
6598c2ecf20Sopenharmony_ci			   XGBE_TX_DESC_CNT_MIN, XGBE_TX_DESC_CNT_MAX);
6608c2ecf20Sopenharmony_ci		return -EINVAL;
6618c2ecf20Sopenharmony_ci	}
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_ci	rx = __rounddown_pow_of_two(ringparam->rx_pending);
6648c2ecf20Sopenharmony_ci	if (rx != ringparam->rx_pending)
6658c2ecf20Sopenharmony_ci		netdev_notice(netdev,
6668c2ecf20Sopenharmony_ci			      "rx ring parameter rounded to power of two: %u\n",
6678c2ecf20Sopenharmony_ci			      rx);
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_ci	tx = __rounddown_pow_of_two(ringparam->tx_pending);
6708c2ecf20Sopenharmony_ci	if (tx != ringparam->tx_pending)
6718c2ecf20Sopenharmony_ci		netdev_notice(netdev,
6728c2ecf20Sopenharmony_ci			      "tx ring parameter rounded to power of two: %u\n",
6738c2ecf20Sopenharmony_ci			      tx);
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_ci	if ((rx == pdata->rx_desc_count) &&
6768c2ecf20Sopenharmony_ci	    (tx == pdata->tx_desc_count))
6778c2ecf20Sopenharmony_ci		goto out;
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_ci	pdata->rx_desc_count = rx;
6808c2ecf20Sopenharmony_ci	pdata->tx_desc_count = tx;
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ci	xgbe_restart_dev(pdata);
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ciout:
6858c2ecf20Sopenharmony_ci	return 0;
6868c2ecf20Sopenharmony_ci}
6878c2ecf20Sopenharmony_ci
6888c2ecf20Sopenharmony_cistatic void xgbe_get_channels(struct net_device *netdev,
6898c2ecf20Sopenharmony_ci			      struct ethtool_channels *channels)
6908c2ecf20Sopenharmony_ci{
6918c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
6928c2ecf20Sopenharmony_ci	unsigned int rx, tx, combined;
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	/* Calculate maximums allowed:
6958c2ecf20Sopenharmony_ci	 *   - Take into account the number of available IRQs
6968c2ecf20Sopenharmony_ci	 *   - Do not take into account the number of online CPUs so that
6978c2ecf20Sopenharmony_ci	 *     the user can over-subscribe if desired
6988c2ecf20Sopenharmony_ci	 *   - Tx is additionally limited by the number of hardware queues
6998c2ecf20Sopenharmony_ci	 */
7008c2ecf20Sopenharmony_ci	rx = min(pdata->hw_feat.rx_ch_cnt, pdata->rx_max_channel_count);
7018c2ecf20Sopenharmony_ci	rx = min(rx, pdata->channel_irq_count);
7028c2ecf20Sopenharmony_ci	tx = min(pdata->hw_feat.tx_ch_cnt, pdata->tx_max_channel_count);
7038c2ecf20Sopenharmony_ci	tx = min(tx, pdata->channel_irq_count);
7048c2ecf20Sopenharmony_ci	tx = min(tx, pdata->tx_max_q_count);
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_ci	combined = min(rx, tx);
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci	channels->max_combined = combined;
7098c2ecf20Sopenharmony_ci	channels->max_rx = rx ? rx - 1 : 0;
7108c2ecf20Sopenharmony_ci	channels->max_tx = tx ? tx - 1 : 0;
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci	/* Get current settings based on device state */
7138c2ecf20Sopenharmony_ci	rx = pdata->new_rx_ring_count ? : pdata->rx_ring_count;
7148c2ecf20Sopenharmony_ci	tx = pdata->new_tx_ring_count ? : pdata->tx_ring_count;
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ci	combined = min(rx, tx);
7178c2ecf20Sopenharmony_ci	rx -= combined;
7188c2ecf20Sopenharmony_ci	tx -= combined;
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_ci	channels->combined_count = combined;
7218c2ecf20Sopenharmony_ci	channels->rx_count = rx;
7228c2ecf20Sopenharmony_ci	channels->tx_count = tx;
7238c2ecf20Sopenharmony_ci}
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_cistatic void xgbe_print_set_channels_input(struct net_device *netdev,
7268c2ecf20Sopenharmony_ci					  struct ethtool_channels *channels)
7278c2ecf20Sopenharmony_ci{
7288c2ecf20Sopenharmony_ci	netdev_err(netdev, "channel inputs: combined=%u, rx-only=%u, tx-only=%u\n",
7298c2ecf20Sopenharmony_ci		   channels->combined_count, channels->rx_count,
7308c2ecf20Sopenharmony_ci		   channels->tx_count);
7318c2ecf20Sopenharmony_ci}
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_cistatic int xgbe_set_channels(struct net_device *netdev,
7348c2ecf20Sopenharmony_ci			     struct ethtool_channels *channels)
7358c2ecf20Sopenharmony_ci{
7368c2ecf20Sopenharmony_ci	struct xgbe_prv_data *pdata = netdev_priv(netdev);
7378c2ecf20Sopenharmony_ci	unsigned int rx, rx_curr, tx, tx_curr, combined;
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ci	/* Calculate maximums allowed:
7408c2ecf20Sopenharmony_ci	 *   - Take into account the number of available IRQs
7418c2ecf20Sopenharmony_ci	 *   - Do not take into account the number of online CPUs so that
7428c2ecf20Sopenharmony_ci	 *     the user can over-subscribe if desired
7438c2ecf20Sopenharmony_ci	 *   - Tx is additionally limited by the number of hardware queues
7448c2ecf20Sopenharmony_ci	 */
7458c2ecf20Sopenharmony_ci	rx = min(pdata->hw_feat.rx_ch_cnt, pdata->rx_max_channel_count);
7468c2ecf20Sopenharmony_ci	rx = min(rx, pdata->channel_irq_count);
7478c2ecf20Sopenharmony_ci	tx = min(pdata->hw_feat.tx_ch_cnt, pdata->tx_max_channel_count);
7488c2ecf20Sopenharmony_ci	tx = min(tx, pdata->tx_max_q_count);
7498c2ecf20Sopenharmony_ci	tx = min(tx, pdata->channel_irq_count);
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_ci	combined = min(rx, tx);
7528c2ecf20Sopenharmony_ci
7538c2ecf20Sopenharmony_ci	/* Should not be setting other count */
7548c2ecf20Sopenharmony_ci	if (channels->other_count) {
7558c2ecf20Sopenharmony_ci		netdev_err(netdev,
7568c2ecf20Sopenharmony_ci			   "other channel count must be zero\n");
7578c2ecf20Sopenharmony_ci		return -EINVAL;
7588c2ecf20Sopenharmony_ci	}
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_ci	/* Require at least one Combined (Rx and Tx) channel */
7618c2ecf20Sopenharmony_ci	if (!channels->combined_count) {
7628c2ecf20Sopenharmony_ci		netdev_err(netdev,
7638c2ecf20Sopenharmony_ci			   "at least one combined Rx/Tx channel is required\n");
7648c2ecf20Sopenharmony_ci		xgbe_print_set_channels_input(netdev, channels);
7658c2ecf20Sopenharmony_ci		return -EINVAL;
7668c2ecf20Sopenharmony_ci	}
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_ci	/* Check combined channels */
7698c2ecf20Sopenharmony_ci	if (channels->combined_count > combined) {
7708c2ecf20Sopenharmony_ci		netdev_err(netdev,
7718c2ecf20Sopenharmony_ci			   "combined channel count cannot exceed %u\n",
7728c2ecf20Sopenharmony_ci			   combined);
7738c2ecf20Sopenharmony_ci		xgbe_print_set_channels_input(netdev, channels);
7748c2ecf20Sopenharmony_ci		return -EINVAL;
7758c2ecf20Sopenharmony_ci	}
7768c2ecf20Sopenharmony_ci
7778c2ecf20Sopenharmony_ci	/* Can have some Rx-only or Tx-only channels, but not both */
7788c2ecf20Sopenharmony_ci	if (channels->rx_count && channels->tx_count) {
7798c2ecf20Sopenharmony_ci		netdev_err(netdev,
7808c2ecf20Sopenharmony_ci			   "cannot specify both Rx-only and Tx-only channels\n");
7818c2ecf20Sopenharmony_ci		xgbe_print_set_channels_input(netdev, channels);
7828c2ecf20Sopenharmony_ci		return -EINVAL;
7838c2ecf20Sopenharmony_ci	}
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci	/* Check that we don't exceed the maximum number of channels */
7868c2ecf20Sopenharmony_ci	if ((channels->combined_count + channels->rx_count) > rx) {
7878c2ecf20Sopenharmony_ci		netdev_err(netdev,
7888c2ecf20Sopenharmony_ci			   "total Rx channels (%u) requested exceeds maximum available (%u)\n",
7898c2ecf20Sopenharmony_ci			   channels->combined_count + channels->rx_count, rx);
7908c2ecf20Sopenharmony_ci		xgbe_print_set_channels_input(netdev, channels);
7918c2ecf20Sopenharmony_ci		return -EINVAL;
7928c2ecf20Sopenharmony_ci	}
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_ci	if ((channels->combined_count + channels->tx_count) > tx) {
7958c2ecf20Sopenharmony_ci		netdev_err(netdev,
7968c2ecf20Sopenharmony_ci			   "total Tx channels (%u) requested exceeds maximum available (%u)\n",
7978c2ecf20Sopenharmony_ci			   channels->combined_count + channels->tx_count, tx);
7988c2ecf20Sopenharmony_ci		xgbe_print_set_channels_input(netdev, channels);
7998c2ecf20Sopenharmony_ci		return -EINVAL;
8008c2ecf20Sopenharmony_ci	}
8018c2ecf20Sopenharmony_ci
8028c2ecf20Sopenharmony_ci	rx = channels->combined_count + channels->rx_count;
8038c2ecf20Sopenharmony_ci	tx = channels->combined_count + channels->tx_count;
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	rx_curr = pdata->new_rx_ring_count ? : pdata->rx_ring_count;
8068c2ecf20Sopenharmony_ci	tx_curr = pdata->new_tx_ring_count ? : pdata->tx_ring_count;
8078c2ecf20Sopenharmony_ci
8088c2ecf20Sopenharmony_ci	if ((rx == rx_curr) && (tx == tx_curr))
8098c2ecf20Sopenharmony_ci		goto out;
8108c2ecf20Sopenharmony_ci
8118c2ecf20Sopenharmony_ci	pdata->new_rx_ring_count = rx;
8128c2ecf20Sopenharmony_ci	pdata->new_tx_ring_count = tx;
8138c2ecf20Sopenharmony_ci
8148c2ecf20Sopenharmony_ci	xgbe_full_restart_dev(pdata);
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ciout:
8178c2ecf20Sopenharmony_ci	return 0;
8188c2ecf20Sopenharmony_ci}
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_cistatic const struct ethtool_ops xgbe_ethtool_ops = {
8218c2ecf20Sopenharmony_ci	.supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS |
8228c2ecf20Sopenharmony_ci				     ETHTOOL_COALESCE_MAX_FRAMES,
8238c2ecf20Sopenharmony_ci	.get_drvinfo = xgbe_get_drvinfo,
8248c2ecf20Sopenharmony_ci	.get_msglevel = xgbe_get_msglevel,
8258c2ecf20Sopenharmony_ci	.set_msglevel = xgbe_set_msglevel,
8268c2ecf20Sopenharmony_ci	.get_link = ethtool_op_get_link,
8278c2ecf20Sopenharmony_ci	.get_coalesce = xgbe_get_coalesce,
8288c2ecf20Sopenharmony_ci	.set_coalesce = xgbe_set_coalesce,
8298c2ecf20Sopenharmony_ci	.get_pauseparam = xgbe_get_pauseparam,
8308c2ecf20Sopenharmony_ci	.set_pauseparam = xgbe_set_pauseparam,
8318c2ecf20Sopenharmony_ci	.get_strings = xgbe_get_strings,
8328c2ecf20Sopenharmony_ci	.get_ethtool_stats = xgbe_get_ethtool_stats,
8338c2ecf20Sopenharmony_ci	.get_sset_count = xgbe_get_sset_count,
8348c2ecf20Sopenharmony_ci	.get_rxnfc = xgbe_get_rxnfc,
8358c2ecf20Sopenharmony_ci	.get_rxfh_key_size = xgbe_get_rxfh_key_size,
8368c2ecf20Sopenharmony_ci	.get_rxfh_indir_size = xgbe_get_rxfh_indir_size,
8378c2ecf20Sopenharmony_ci	.get_rxfh = xgbe_get_rxfh,
8388c2ecf20Sopenharmony_ci	.set_rxfh = xgbe_set_rxfh,
8398c2ecf20Sopenharmony_ci	.get_ts_info = xgbe_get_ts_info,
8408c2ecf20Sopenharmony_ci	.get_link_ksettings = xgbe_get_link_ksettings,
8418c2ecf20Sopenharmony_ci	.set_link_ksettings = xgbe_set_link_ksettings,
8428c2ecf20Sopenharmony_ci	.get_module_info = xgbe_get_module_info,
8438c2ecf20Sopenharmony_ci	.get_module_eeprom = xgbe_get_module_eeprom,
8448c2ecf20Sopenharmony_ci	.get_ringparam = xgbe_get_ringparam,
8458c2ecf20Sopenharmony_ci	.set_ringparam = xgbe_set_ringparam,
8468c2ecf20Sopenharmony_ci	.get_channels = xgbe_get_channels,
8478c2ecf20Sopenharmony_ci	.set_channels = xgbe_set_channels,
8488c2ecf20Sopenharmony_ci};
8498c2ecf20Sopenharmony_ci
8508c2ecf20Sopenharmony_ciconst struct ethtool_ops *xgbe_get_ethtool_ops(void)
8518c2ecf20Sopenharmony_ci{
8528c2ecf20Sopenharmony_ci	return &xgbe_ethtool_ops;
8538c2ecf20Sopenharmony_ci}
854