xref: /openbmc/linux/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c (revision c595db6d7c8bcf87ef42204391fa890e5950e566)
14fa9c49fSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
27ac6653aSJeff Kirsher /*******************************************************************************
37ac6653aSJeff Kirsher   STMMAC Ethtool support
47ac6653aSJeff Kirsher 
57ac6653aSJeff Kirsher   Copyright (C) 2007-2009  STMicroelectronics Ltd
67ac6653aSJeff Kirsher 
77ac6653aSJeff Kirsher 
87ac6653aSJeff Kirsher   Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
97ac6653aSJeff Kirsher *******************************************************************************/
107ac6653aSJeff Kirsher 
117ac6653aSJeff Kirsher #include <linux/etherdevice.h>
127ac6653aSJeff Kirsher #include <linux/ethtool.h>
137ac6653aSJeff Kirsher #include <linux/interrupt.h>
147ac6653aSJeff Kirsher #include <linux/mii.h>
1574371272SJose Abreu #include <linux/phylink.h>
16891434b1SRayagond Kokatanur #include <linux/net_tstamp.h>
177ac6653aSJeff Kirsher #include <asm/io.h>
187ac6653aSJeff Kirsher 
197ac6653aSJeff Kirsher #include "stmmac.h"
207ac6653aSJeff Kirsher #include "dwmac_dma.h"
21bfc56530SJose Abreu #include "dwxgmac2.h"
227ac6653aSJeff Kirsher 
2377b0d361SThor Thayer #define REG_SPACE_SIZE	0x1060
247af037c3SCamel Guo #define GMAC4_REG_SPACE_SIZE	0x116C
257ac6653aSJeff Kirsher #define MAC100_ETHTOOL_NAME	"st_mac100"
267ac6653aSJeff Kirsher #define GMAC_ETHTOOL_NAME	"st_gmac"
27bfc56530SJose Abreu #define XGMAC_ETHTOOL_NAME	"st_xgmac"
287ac6653aSJeff Kirsher 
297af037c3SCamel Guo /* Same as DMA_CHAN_BASE_ADDR defined in dwmac4_dma.h
307af037c3SCamel Guo  *
317af037c3SCamel Guo  * It is here because dwmac_dma.h and dwmac4_dam.h can not be included at the
327af037c3SCamel Guo  * same time due to the conflicting macro names.
337af037c3SCamel Guo  */
347af037c3SCamel Guo #define GMAC4_DMA_CHAN_BASE_ADDR  0x00001100
357af037c3SCamel Guo 
36f4458b92SThor Thayer #define ETHTOOL_DMA_OFFSET	55
37f4458b92SThor Thayer 
387ac6653aSJeff Kirsher struct stmmac_stats {
397ac6653aSJeff Kirsher 	char stat_string[ETH_GSTRING_LEN];
407ac6653aSJeff Kirsher 	int sizeof_stat;
417ac6653aSJeff Kirsher 	int stat_offset;
427ac6653aSJeff Kirsher };
437ac6653aSJeff Kirsher 
447ac6653aSJeff Kirsher #define STMMAC_STAT(m)	\
45c593642cSPankaj Bharadiya 	{ #m, sizeof_field(struct stmmac_extra_stats, m),	\
467ac6653aSJeff Kirsher 	offsetof(struct stmmac_priv, xstats.m)}
477ac6653aSJeff Kirsher 
487ac6653aSJeff Kirsher static const struct stmmac_stats stmmac_gstrings_stats[] = {
491cc5a735SGiuseppe CAVALLARO 	/* Transmit errors */
507ac6653aSJeff Kirsher 	STMMAC_STAT(tx_underflow),
517ac6653aSJeff Kirsher 	STMMAC_STAT(tx_carrier),
527ac6653aSJeff Kirsher 	STMMAC_STAT(tx_losscarrier),
533c20f72fSGiuseppe CAVALLARO 	STMMAC_STAT(vlan_tag),
547ac6653aSJeff Kirsher 	STMMAC_STAT(tx_deferred),
557ac6653aSJeff Kirsher 	STMMAC_STAT(tx_vlan),
567ac6653aSJeff Kirsher 	STMMAC_STAT(tx_jabber),
577ac6653aSJeff Kirsher 	STMMAC_STAT(tx_frame_flushed),
587ac6653aSJeff Kirsher 	STMMAC_STAT(tx_payload_error),
597ac6653aSJeff Kirsher 	STMMAC_STAT(tx_ip_header_error),
601cc5a735SGiuseppe CAVALLARO 	/* Receive errors */
617ac6653aSJeff Kirsher 	STMMAC_STAT(rx_desc),
623c20f72fSGiuseppe CAVALLARO 	STMMAC_STAT(sa_filter_fail),
633c20f72fSGiuseppe CAVALLARO 	STMMAC_STAT(overflow_error),
643c20f72fSGiuseppe CAVALLARO 	STMMAC_STAT(ipc_csum_error),
657ac6653aSJeff Kirsher 	STMMAC_STAT(rx_collision),
66e0a76606SLABBE Corentin 	STMMAC_STAT(rx_crc_errors),
671cc5a735SGiuseppe CAVALLARO 	STMMAC_STAT(dribbling_bit),
687ac6653aSJeff Kirsher 	STMMAC_STAT(rx_length),
697ac6653aSJeff Kirsher 	STMMAC_STAT(rx_mii),
707ac6653aSJeff Kirsher 	STMMAC_STAT(rx_multicast),
717ac6653aSJeff Kirsher 	STMMAC_STAT(rx_gmac_overflow),
727ac6653aSJeff Kirsher 	STMMAC_STAT(rx_watchdog),
737ac6653aSJeff Kirsher 	STMMAC_STAT(da_rx_filter_fail),
747ac6653aSJeff Kirsher 	STMMAC_STAT(sa_rx_filter_fail),
757ac6653aSJeff Kirsher 	STMMAC_STAT(rx_missed_cntr),
767ac6653aSJeff Kirsher 	STMMAC_STAT(rx_overflow_cntr),
771cc5a735SGiuseppe CAVALLARO 	STMMAC_STAT(rx_vlan),
78b5418e13SJose Abreu 	STMMAC_STAT(rx_split_hdr_pkt_n),
7962a2ab93SGiuseppe CAVALLARO 	/* Tx/Rx IRQ error info */
807ac6653aSJeff Kirsher 	STMMAC_STAT(tx_undeflow_irq),
817ac6653aSJeff Kirsher 	STMMAC_STAT(tx_process_stopped_irq),
827ac6653aSJeff Kirsher 	STMMAC_STAT(tx_jabber_irq),
837ac6653aSJeff Kirsher 	STMMAC_STAT(rx_overflow_irq),
847ac6653aSJeff Kirsher 	STMMAC_STAT(rx_buf_unav_irq),
857ac6653aSJeff Kirsher 	STMMAC_STAT(rx_process_stopped_irq),
867ac6653aSJeff Kirsher 	STMMAC_STAT(rx_watchdog_irq),
877ac6653aSJeff Kirsher 	STMMAC_STAT(tx_early_irq),
887ac6653aSJeff Kirsher 	STMMAC_STAT(fatal_bus_error_irq),
8962a2ab93SGiuseppe CAVALLARO 	/* Tx/Rx IRQ Events */
9062a2ab93SGiuseppe CAVALLARO 	STMMAC_STAT(rx_early_irq),
917ac6653aSJeff Kirsher 	STMMAC_STAT(threshold),
9262a2ab93SGiuseppe CAVALLARO 	STMMAC_STAT(irq_receive_pmt_irq_n),
9362a2ab93SGiuseppe CAVALLARO 	/* MMC info */
94d765955dSGiuseppe CAVALLARO 	STMMAC_STAT(mmc_tx_irq_n),
95d765955dSGiuseppe CAVALLARO 	STMMAC_STAT(mmc_rx_irq_n),
96d765955dSGiuseppe CAVALLARO 	STMMAC_STAT(mmc_rx_csum_offload_irq_n),
9762a2ab93SGiuseppe CAVALLARO 	/* EEE */
98d765955dSGiuseppe CAVALLARO 	STMMAC_STAT(irq_tx_path_in_lpi_mode_n),
99d765955dSGiuseppe CAVALLARO 	STMMAC_STAT(irq_tx_path_exit_lpi_mode_n),
100d765955dSGiuseppe CAVALLARO 	STMMAC_STAT(irq_rx_path_in_lpi_mode_n),
101d765955dSGiuseppe CAVALLARO 	STMMAC_STAT(irq_rx_path_exit_lpi_mode_n),
102d765955dSGiuseppe CAVALLARO 	STMMAC_STAT(phy_eee_wakeup_error_n),
103c24602efSGiuseppe CAVALLARO 	/* Extended RDES status */
104c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(ip_hdr_err),
105c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(ip_payload_err),
106c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(ip_csum_bypassed),
107c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(ipv4_pkt_rcvd),
108c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(ipv6_pkt_rcvd),
109ee112c12SGiuseppe CAVALLARO 	STMMAC_STAT(no_ptp_rx_msg_type_ext),
110ee112c12SGiuseppe CAVALLARO 	STMMAC_STAT(ptp_rx_msg_type_sync),
111ee112c12SGiuseppe CAVALLARO 	STMMAC_STAT(ptp_rx_msg_type_follow_up),
112ee112c12SGiuseppe CAVALLARO 	STMMAC_STAT(ptp_rx_msg_type_delay_req),
113ee112c12SGiuseppe CAVALLARO 	STMMAC_STAT(ptp_rx_msg_type_delay_resp),
114ee112c12SGiuseppe CAVALLARO 	STMMAC_STAT(ptp_rx_msg_type_pdelay_req),
115ee112c12SGiuseppe CAVALLARO 	STMMAC_STAT(ptp_rx_msg_type_pdelay_resp),
116ee112c12SGiuseppe CAVALLARO 	STMMAC_STAT(ptp_rx_msg_type_pdelay_follow_up),
117ee112c12SGiuseppe CAVALLARO 	STMMAC_STAT(ptp_rx_msg_type_announce),
118ee112c12SGiuseppe CAVALLARO 	STMMAC_STAT(ptp_rx_msg_type_management),
119ee112c12SGiuseppe CAVALLARO 	STMMAC_STAT(ptp_rx_msg_pkt_reserved_type),
120c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(ptp_frame_type),
121c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(ptp_ver),
122c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(timestamp_dropped),
123c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(av_pkt_rcvd),
124c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(av_tagged_pkt_rcvd),
125c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(vlan_tag_priority_val),
126c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(l3_filter_match),
127c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(l4_filter_match),
128c24602efSGiuseppe CAVALLARO 	STMMAC_STAT(l3_l4_filter_no_match),
1290982a0f6SGiuseppe CAVALLARO 	/* PCS */
1300982a0f6SGiuseppe CAVALLARO 	STMMAC_STAT(irq_pcs_ane_n),
1310982a0f6SGiuseppe CAVALLARO 	STMMAC_STAT(irq_pcs_link_n),
1320982a0f6SGiuseppe CAVALLARO 	STMMAC_STAT(irq_rgmii_n),
1332f7a791cSGiuseppe CAVALLARO 	/* DEBUG */
1342f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_tx_status_fifo_full),
1352f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_tx_fifo_not_empty),
1362f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mmtl_fifo_ctrl),
1372f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_tx_fifo_read_ctrl_write),
1382f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_tx_fifo_read_ctrl_wait),
1392f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_tx_fifo_read_ctrl_read),
1402f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_tx_fifo_read_ctrl_idle),
1412f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mac_tx_in_pause),
1422f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mac_tx_frame_ctrl_xfer),
1432f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mac_tx_frame_ctrl_idle),
1442f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mac_tx_frame_ctrl_wait),
1452f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mac_tx_frame_ctrl_pause),
1462f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mac_gmii_tx_proto_engine),
1472f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_rx_fifo_fill_level_full),
1482f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_rx_fifo_fill_above_thresh),
1492f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_rx_fifo_fill_below_thresh),
1502f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_rx_fifo_fill_level_empty),
1512f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_rx_fifo_read_ctrl_flush),
1522f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_rx_fifo_read_ctrl_read_data),
1532f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_rx_fifo_read_ctrl_status),
1542f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_rx_fifo_read_ctrl_idle),
1552f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mtl_rx_fifo_ctrl_active),
1562f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mac_rx_frame_ctrl_fifo),
1572f7a791cSGiuseppe CAVALLARO 	STMMAC_STAT(mac_gmii_rx_proto_engine),
1589f298959SOng Boon Leong 	/* EST */
1599f298959SOng Boon Leong 	STMMAC_STAT(mtl_est_cgce),
1609f298959SOng Boon Leong 	STMMAC_STAT(mtl_est_hlbs),
1619f298959SOng Boon Leong 	STMMAC_STAT(mtl_est_hlbf),
1629f298959SOng Boon Leong 	STMMAC_STAT(mtl_est_btre),
1639f298959SOng Boon Leong 	STMMAC_STAT(mtl_est_btrlm),
1647ac6653aSJeff Kirsher };
1657ac6653aSJeff Kirsher #define STMMAC_STATS_LEN ARRAY_SIZE(stmmac_gstrings_stats)
1667ac6653aSJeff Kirsher 
167133466c3SJisheng Zhang /* statistics collected in queue which will be summed up for all TX or RX
168133466c3SJisheng Zhang  * queues, or summed up for both TX and RX queues(napi_poll, normal_irq_n).
169133466c3SJisheng Zhang  */
170133466c3SJisheng Zhang static const char stmmac_qstats_string[][ETH_GSTRING_LEN] = {
171133466c3SJisheng Zhang 	"rx_pkt_n",
172133466c3SJisheng Zhang 	"rx_normal_irq_n",
173133466c3SJisheng Zhang 	"tx_pkt_n",
174133466c3SJisheng Zhang 	"tx_normal_irq_n",
175133466c3SJisheng Zhang 	"tx_clean",
176133466c3SJisheng Zhang 	"tx_set_ic_bit",
177133466c3SJisheng Zhang 	"tx_tso_frames",
178133466c3SJisheng Zhang 	"tx_tso_nfrags",
179133466c3SJisheng Zhang 	"normal_irq_n",
180133466c3SJisheng Zhang 	"napi_poll",
181133466c3SJisheng Zhang };
182133466c3SJisheng Zhang #define STMMAC_QSTATS ARRAY_SIZE(stmmac_qstats_string)
183133466c3SJisheng Zhang 
1841c901a46SGiuseppe CAVALLARO /* HW MAC Management counters (if supported) */
1851c901a46SGiuseppe CAVALLARO #define STMMAC_MMC_STAT(m)	\
186c593642cSPankaj Bharadiya 	{ #m, sizeof_field(struct stmmac_counters, m),	\
1871c901a46SGiuseppe CAVALLARO 	offsetof(struct stmmac_priv, mmc.m)}
1881c901a46SGiuseppe CAVALLARO 
18938fe7a93SGiuseppe CAVALLARO static const struct stmmac_stats stmmac_mmc[] = {
1901c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_octetcount_gb),
1911c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_framecount_gb),
1921c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_broadcastframe_g),
1931c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_multicastframe_g),
1941c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_64_octets_gb),
1951c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_65_to_127_octets_gb),
1961c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_128_to_255_octets_gb),
1971c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_256_to_511_octets_gb),
1981c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_512_to_1023_octets_gb),
1991c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_1024_to_max_octets_gb),
2001c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_unicast_gb),
2011c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_multicast_gb),
2021c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_broadcast_gb),
2031c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_underflow_error),
2041c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_singlecol_g),
2051c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_multicol_g),
2061c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_deferred),
2071c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_latecol),
2081c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_exesscol),
2091c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_carrier_error),
2101c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_octetcount_g),
2111c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_framecount_g),
2121c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_excessdef),
2131c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_pause_frame),
2141c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_tx_vlan_frame_g),
2151c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_framecount_gb),
2161c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_octetcount_gb),
2171c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_octetcount_g),
2181c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_broadcastframe_g),
2191c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_multicastframe_g),
2202b78d348SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_crc_error),
2211c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_align_error),
2221c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_run_error),
2231c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_jabber_error),
2241c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_undersize_g),
2251c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_oversize_g),
2261c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_64_octets_gb),
2271c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_65_to_127_octets_gb),
2281c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_128_to_255_octets_gb),
2291c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_256_to_511_octets_gb),
2301c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_512_to_1023_octets_gb),
2311c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_1024_to_max_octets_gb),
2321c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_unicast_g),
2331c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_length_error),
2341c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_autofrangetype),
2351c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_pause_frames),
2361c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_fifo_overflow),
2371c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_vlan_frames_gb),
2381c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_watchdog_error),
2391c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipc_intr_mask),
2401c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipc_intr),
2411c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv4_gd),
2421c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv4_hderr),
2431c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv4_nopay),
2441c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv4_frag),
2451c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv4_udsbl),
2461c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv4_gd_octets),
2471c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv4_hderr_octets),
2481c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv4_nopay_octets),
2491c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv4_frag_octets),
2501c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv4_udsbl_octets),
2511c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv6_gd_octets),
2521c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv6_hderr_octets),
2531c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv6_nopay_octets),
2541c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv6_gd),
2551c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv6_hderr),
2561c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_ipv6_nopay),
2571c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_udp_gd),
2581c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_udp_err),
2591c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_tcp_gd),
2601c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_tcp_err),
2611c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_icmp_gd),
2621c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_icmp_err),
2631c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_udp_gd_octets),
2641c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_udp_err_octets),
2651c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_tcp_gd_octets),
2661c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_tcp_err_octets),
2671c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_icmp_gd_octets),
2681c901a46SGiuseppe CAVALLARO 	STMMAC_MMC_STAT(mmc_rx_icmp_err_octets),
269b6cdf09fSJose Abreu 	STMMAC_MMC_STAT(mmc_tx_fpe_fragment_cntr),
270b6cdf09fSJose Abreu 	STMMAC_MMC_STAT(mmc_tx_hold_req_cntr),
271b6cdf09fSJose Abreu 	STMMAC_MMC_STAT(mmc_rx_packet_assembly_err_cntr),
272b6cdf09fSJose Abreu 	STMMAC_MMC_STAT(mmc_rx_packet_smd_err_cntr),
273b6cdf09fSJose Abreu 	STMMAC_MMC_STAT(mmc_rx_packet_assembly_ok_cntr),
274b6cdf09fSJose Abreu 	STMMAC_MMC_STAT(mmc_rx_fpe_fragment_cntr),
2751c901a46SGiuseppe CAVALLARO };
27638fe7a93SGiuseppe CAVALLARO #define STMMAC_MMC_STATS_LEN ARRAY_SIZE(stmmac_mmc)
2771c901a46SGiuseppe CAVALLARO 
27868e9c5deSVijayakannan Ayyathurai static const char stmmac_qstats_tx_string[][ETH_GSTRING_LEN] = {
27968e9c5deSVijayakannan Ayyathurai 	"tx_pkt_n",
280af9bf701SVijayakannan Ayyathurai 	"tx_irq_n",
28168e9c5deSVijayakannan Ayyathurai #define STMMAC_TXQ_STATS ARRAY_SIZE(stmmac_qstats_tx_string)
28268e9c5deSVijayakannan Ayyathurai };
28368e9c5deSVijayakannan Ayyathurai 
28468e9c5deSVijayakannan Ayyathurai static const char stmmac_qstats_rx_string[][ETH_GSTRING_LEN] = {
28568e9c5deSVijayakannan Ayyathurai 	"rx_pkt_n",
286af9bf701SVijayakannan Ayyathurai 	"rx_irq_n",
28768e9c5deSVijayakannan Ayyathurai #define STMMAC_RXQ_STATS ARRAY_SIZE(stmmac_qstats_rx_string)
28868e9c5deSVijayakannan Ayyathurai };
28968e9c5deSVijayakannan Ayyathurai 
stmmac_ethtool_getdrvinfo(struct net_device * dev,struct ethtool_drvinfo * info)2907ac6653aSJeff Kirsher static void stmmac_ethtool_getdrvinfo(struct net_device *dev,
2917ac6653aSJeff Kirsher 				      struct ethtool_drvinfo *info)
2927ac6653aSJeff Kirsher {
2937ac6653aSJeff Kirsher 	struct stmmac_priv *priv = netdev_priv(dev);
2947ac6653aSJeff Kirsher 
2957cc99fd2SNiklas Cassel 	if (priv->plat->has_gmac || priv->plat->has_gmac4)
296f029c781SWolfram Sang 		strscpy(info->driver, GMAC_ETHTOOL_NAME, sizeof(info->driver));
297bfc56530SJose Abreu 	else if (priv->plat->has_xgmac)
298f029c781SWolfram Sang 		strscpy(info->driver, XGMAC_ETHTOOL_NAME, sizeof(info->driver));
2991c901a46SGiuseppe CAVALLARO 	else
300f029c781SWolfram Sang 		strscpy(info->driver, MAC100_ETHTOOL_NAME,
30133a5ba14SRick Jones 			sizeof(info->driver));
3027ac6653aSJeff Kirsher 
30320e07e2cSWong Vee Khee 	if (priv->plat->pdev) {
304f029c781SWolfram Sang 		strscpy(info->bus_info, pci_name(priv->plat->pdev),
30520e07e2cSWong Vee Khee 			sizeof(info->bus_info));
30620e07e2cSWong Vee Khee 	}
3077ac6653aSJeff Kirsher }
3087ac6653aSJeff Kirsher 
stmmac_ethtool_get_link_ksettings(struct net_device * dev,struct ethtool_link_ksettings * cmd)3091685e785SPhilippe Reynes static int stmmac_ethtool_get_link_ksettings(struct net_device *dev,
3101685e785SPhilippe Reynes 					     struct ethtool_link_ksettings *cmd)
3117ac6653aSJeff Kirsher {
3127ac6653aSJeff Kirsher 	struct stmmac_priv *priv = netdev_priv(dev);
313e58bb43fSGiuseppe CAVALLARO 
3143a7517c5SSneh Shah 	if (!(priv->plat->flags & STMMAC_FLAG_HAS_INTEGRATED_PCS) &&
3153a7517c5SSneh Shah 	    (priv->hw->pcs & STMMAC_PCS_RGMII ||
3163a7517c5SSneh Shah 	     priv->hw->pcs & STMMAC_PCS_SGMII)) {
317e58bb43fSGiuseppe CAVALLARO 		struct rgmii_adv adv;
3181685e785SPhilippe Reynes 		u32 supported, advertising, lp_advertising;
319e58bb43fSGiuseppe CAVALLARO 
320e58bb43fSGiuseppe CAVALLARO 		if (!priv->xstats.pcs_link) {
3211685e785SPhilippe Reynes 			cmd->base.speed = SPEED_UNKNOWN;
3221685e785SPhilippe Reynes 			cmd->base.duplex = DUPLEX_UNKNOWN;
323e58bb43fSGiuseppe CAVALLARO 			return 0;
324e58bb43fSGiuseppe CAVALLARO 		}
3251685e785SPhilippe Reynes 		cmd->base.duplex = priv->xstats.pcs_duplex;
326e58bb43fSGiuseppe CAVALLARO 
3271685e785SPhilippe Reynes 		cmd->base.speed = priv->xstats.pcs_speed;
328e58bb43fSGiuseppe CAVALLARO 
329e58bb43fSGiuseppe CAVALLARO 		/* Get and convert ADV/LP_ADV from the HW AN registers */
330c10d4c82SJose Abreu 		if (stmmac_pcs_get_adv_lp(priv, priv->ioaddr, &adv))
331e58bb43fSGiuseppe CAVALLARO 			return -EOPNOTSUPP;	/* should never happen indeed */
332e58bb43fSGiuseppe CAVALLARO 
333e58bb43fSGiuseppe CAVALLARO 		/* Encoding of PSE bits is defined in 802.3z, 37.2.1.4 */
334e58bb43fSGiuseppe CAVALLARO 
3351685e785SPhilippe Reynes 		ethtool_convert_link_mode_to_legacy_u32(
3361685e785SPhilippe Reynes 			&supported, cmd->link_modes.supported);
3371685e785SPhilippe Reynes 		ethtool_convert_link_mode_to_legacy_u32(
3381685e785SPhilippe Reynes 			&advertising, cmd->link_modes.advertising);
3391685e785SPhilippe Reynes 		ethtool_convert_link_mode_to_legacy_u32(
3401685e785SPhilippe Reynes 			&lp_advertising, cmd->link_modes.lp_advertising);
3411685e785SPhilippe Reynes 
342e58bb43fSGiuseppe CAVALLARO 		if (adv.pause & STMMAC_PCS_PAUSE)
3431685e785SPhilippe Reynes 			advertising |= ADVERTISED_Pause;
344e58bb43fSGiuseppe CAVALLARO 		if (adv.pause & STMMAC_PCS_ASYM_PAUSE)
3451685e785SPhilippe Reynes 			advertising |= ADVERTISED_Asym_Pause;
346e58bb43fSGiuseppe CAVALLARO 		if (adv.lp_pause & STMMAC_PCS_PAUSE)
3471685e785SPhilippe Reynes 			lp_advertising |= ADVERTISED_Pause;
348e58bb43fSGiuseppe CAVALLARO 		if (adv.lp_pause & STMMAC_PCS_ASYM_PAUSE)
3491685e785SPhilippe Reynes 			lp_advertising |= ADVERTISED_Asym_Pause;
350e58bb43fSGiuseppe CAVALLARO 
351e58bb43fSGiuseppe CAVALLARO 		/* Reg49[3] always set because ANE is always supported */
3521685e785SPhilippe Reynes 		cmd->base.autoneg = ADVERTISED_Autoneg;
3531685e785SPhilippe Reynes 		supported |= SUPPORTED_Autoneg;
3541685e785SPhilippe Reynes 		advertising |= ADVERTISED_Autoneg;
3551685e785SPhilippe Reynes 		lp_advertising |= ADVERTISED_Autoneg;
356e58bb43fSGiuseppe CAVALLARO 
357e58bb43fSGiuseppe CAVALLARO 		if (adv.duplex) {
3581685e785SPhilippe Reynes 			supported |= (SUPPORTED_1000baseT_Full |
359e58bb43fSGiuseppe CAVALLARO 				      SUPPORTED_100baseT_Full |
360e58bb43fSGiuseppe CAVALLARO 				      SUPPORTED_10baseT_Full);
3611685e785SPhilippe Reynes 			advertising |= (ADVERTISED_1000baseT_Full |
362e58bb43fSGiuseppe CAVALLARO 					ADVERTISED_100baseT_Full |
363e58bb43fSGiuseppe CAVALLARO 					ADVERTISED_10baseT_Full);
364e58bb43fSGiuseppe CAVALLARO 		} else {
3651685e785SPhilippe Reynes 			supported |= (SUPPORTED_1000baseT_Half |
366e58bb43fSGiuseppe CAVALLARO 				      SUPPORTED_100baseT_Half |
367e58bb43fSGiuseppe CAVALLARO 				      SUPPORTED_10baseT_Half);
3681685e785SPhilippe Reynes 			advertising |= (ADVERTISED_1000baseT_Half |
369e58bb43fSGiuseppe CAVALLARO 					ADVERTISED_100baseT_Half |
370e58bb43fSGiuseppe CAVALLARO 					ADVERTISED_10baseT_Half);
371e58bb43fSGiuseppe CAVALLARO 		}
372e58bb43fSGiuseppe CAVALLARO 		if (adv.lp_duplex)
3731685e785SPhilippe Reynes 			lp_advertising |= (ADVERTISED_1000baseT_Full |
374e58bb43fSGiuseppe CAVALLARO 					   ADVERTISED_100baseT_Full |
375e58bb43fSGiuseppe CAVALLARO 					   ADVERTISED_10baseT_Full);
376e58bb43fSGiuseppe CAVALLARO 		else
3771685e785SPhilippe Reynes 			lp_advertising |= (ADVERTISED_1000baseT_Half |
378e58bb43fSGiuseppe CAVALLARO 					   ADVERTISED_100baseT_Half |
379e58bb43fSGiuseppe CAVALLARO 					   ADVERTISED_10baseT_Half);
3801685e785SPhilippe Reynes 		cmd->base.port = PORT_OTHER;
3811685e785SPhilippe Reynes 
3821685e785SPhilippe Reynes 		ethtool_convert_legacy_u32_to_link_mode(
3831685e785SPhilippe Reynes 			cmd->link_modes.supported, supported);
3841685e785SPhilippe Reynes 		ethtool_convert_legacy_u32_to_link_mode(
3851685e785SPhilippe Reynes 			cmd->link_modes.advertising, advertising);
3861685e785SPhilippe Reynes 		ethtool_convert_legacy_u32_to_link_mode(
3871685e785SPhilippe Reynes 			cmd->link_modes.lp_advertising, lp_advertising);
388e58bb43fSGiuseppe CAVALLARO 
389e58bb43fSGiuseppe CAVALLARO 		return 0;
390e58bb43fSGiuseppe CAVALLARO 	}
391e58bb43fSGiuseppe CAVALLARO 
39274371272SJose Abreu 	return phylink_ethtool_ksettings_get(priv->phylink, cmd);
3937ac6653aSJeff Kirsher }
3947ac6653aSJeff Kirsher 
3951685e785SPhilippe Reynes static int
stmmac_ethtool_set_link_ksettings(struct net_device * dev,const struct ethtool_link_ksettings * cmd)3961685e785SPhilippe Reynes stmmac_ethtool_set_link_ksettings(struct net_device *dev,
3971685e785SPhilippe Reynes 				  const struct ethtool_link_ksettings *cmd)
3987ac6653aSJeff Kirsher {
3997ac6653aSJeff Kirsher 	struct stmmac_priv *priv = netdev_priv(dev);
4007ac6653aSJeff Kirsher 
4013a7517c5SSneh Shah 	if (!(priv->plat->flags & STMMAC_FLAG_HAS_INTEGRATED_PCS) &&
4023a7517c5SSneh Shah 	    (priv->hw->pcs & STMMAC_PCS_RGMII ||
4033a7517c5SSneh Shah 	     priv->hw->pcs & STMMAC_PCS_SGMII)) {
404e58bb43fSGiuseppe CAVALLARO 		/* Only support ANE */
4051685e785SPhilippe Reynes 		if (cmd->base.autoneg != AUTONEG_ENABLE)
406e58bb43fSGiuseppe CAVALLARO 			return -EINVAL;
407e58bb43fSGiuseppe CAVALLARO 
40829555fa3SThierry Reding 		mutex_lock(&priv->lock);
409c10d4c82SJose Abreu 		stmmac_pcs_ctrl_ane(priv, priv->ioaddr, 1, priv->hw->ps, 0);
41029555fa3SThierry Reding 		mutex_unlock(&priv->lock);
411e58bb43fSGiuseppe CAVALLARO 
412e58bb43fSGiuseppe CAVALLARO 		return 0;
413e58bb43fSGiuseppe CAVALLARO 	}
414e58bb43fSGiuseppe CAVALLARO 
41574371272SJose Abreu 	return phylink_ethtool_ksettings_set(priv->phylink, cmd);
4167ac6653aSJeff Kirsher }
4177ac6653aSJeff Kirsher 
stmmac_ethtool_getmsglevel(struct net_device * dev)4187ac6653aSJeff Kirsher static u32 stmmac_ethtool_getmsglevel(struct net_device *dev)
4197ac6653aSJeff Kirsher {
4207ac6653aSJeff Kirsher 	struct stmmac_priv *priv = netdev_priv(dev);
4217ac6653aSJeff Kirsher 	return priv->msg_enable;
4227ac6653aSJeff Kirsher }
4237ac6653aSJeff Kirsher 
stmmac_ethtool_setmsglevel(struct net_device * dev,u32 level)4247ac6653aSJeff Kirsher static void stmmac_ethtool_setmsglevel(struct net_device *dev, u32 level)
4257ac6653aSJeff Kirsher {
4267ac6653aSJeff Kirsher 	struct stmmac_priv *priv = netdev_priv(dev);
4277ac6653aSJeff Kirsher 	priv->msg_enable = level;
4287ac6653aSJeff Kirsher 
4297ac6653aSJeff Kirsher }
4307ac6653aSJeff Kirsher 
stmmac_check_if_running(struct net_device * dev)4317ac6653aSJeff Kirsher static int stmmac_check_if_running(struct net_device *dev)
4327ac6653aSJeff Kirsher {
4337ac6653aSJeff Kirsher 	if (!netif_running(dev))
4347ac6653aSJeff Kirsher 		return -EBUSY;
4357ac6653aSJeff Kirsher 	return 0;
4367ac6653aSJeff Kirsher }
4377ac6653aSJeff Kirsher 
stmmac_ethtool_get_regs_len(struct net_device * dev)4387ac6653aSJeff Kirsher static int stmmac_ethtool_get_regs_len(struct net_device *dev)
4397ac6653aSJeff Kirsher {
440bfc56530SJose Abreu 	struct stmmac_priv *priv = netdev_priv(dev);
441bfc56530SJose Abreu 
442bfc56530SJose Abreu 	if (priv->plat->has_xgmac)
443bfc56530SJose Abreu 		return XGMAC_REGSIZE * 4;
4447af037c3SCamel Guo 	else if (priv->plat->has_gmac4)
4457af037c3SCamel Guo 		return GMAC4_REG_SPACE_SIZE;
4467ac6653aSJeff Kirsher 	return REG_SPACE_SIZE;
4477ac6653aSJeff Kirsher }
4487ac6653aSJeff Kirsher 
stmmac_ethtool_gregs(struct net_device * dev,struct ethtool_regs * regs,void * space)4497ac6653aSJeff Kirsher static void stmmac_ethtool_gregs(struct net_device *dev,
4507ac6653aSJeff Kirsher 			  struct ethtool_regs *regs, void *space)
4517ac6653aSJeff Kirsher {
4527ac6653aSJeff Kirsher 	struct stmmac_priv *priv = netdev_priv(dev);
453bfc56530SJose Abreu 	u32 *reg_space = (u32 *) space;
4547ac6653aSJeff Kirsher 
455c10d4c82SJose Abreu 	stmmac_dump_mac_regs(priv, priv->hw, reg_space);
456a4e887faSJose Abreu 	stmmac_dump_dma_regs(priv, priv->ioaddr, reg_space);
457bfc56530SJose Abreu 
458f4458b92SThor Thayer 	/* Copy DMA registers to where ethtool expects them */
4597af037c3SCamel Guo 	if (priv->plat->has_gmac4) {
4607af037c3SCamel Guo 		/* GMAC4 dumps its DMA registers at its DMA_CHAN_BASE_ADDR */
4617af037c3SCamel Guo 		memcpy(&reg_space[ETHTOOL_DMA_OFFSET],
4627af037c3SCamel Guo 		       &reg_space[GMAC4_DMA_CHAN_BASE_ADDR / 4],
4637af037c3SCamel Guo 		       NUM_DWMAC4_DMA_REGS * 4);
4647af037c3SCamel Guo 	} else if (!priv->plat->has_xgmac) {
465bfc56530SJose Abreu 		memcpy(&reg_space[ETHTOOL_DMA_OFFSET],
466bfc56530SJose Abreu 		       &reg_space[DMA_BUS_MODE / 4],
467f4458b92SThor Thayer 		       NUM_DWMAC1000_DMA_REGS * 4);
4687ac6653aSJeff Kirsher 	}
469bfc56530SJose Abreu }
4707ac6653aSJeff Kirsher 
stmmac_nway_reset(struct net_device * dev)47174371272SJose Abreu static int stmmac_nway_reset(struct net_device *dev)
47274371272SJose Abreu {
47374371272SJose Abreu 	struct stmmac_priv *priv = netdev_priv(dev);
47474371272SJose Abreu 
47574371272SJose Abreu 	return phylink_ethtool_nway_reset(priv->phylink);
47674371272SJose Abreu }
47774371272SJose Abreu 
stmmac_get_ringparam(struct net_device * netdev,struct ethtool_ringparam * ring,struct kernel_ethtool_ringparam * kernel_ring,struct netlink_ext_ack * extack)478aa042f60SSong, Yoong Siang static void stmmac_get_ringparam(struct net_device *netdev,
47974624944SHao Chen 				 struct ethtool_ringparam *ring,
48074624944SHao Chen 				 struct kernel_ethtool_ringparam *kernel_ring,
48174624944SHao Chen 				 struct netlink_ext_ack *extack)
482aa042f60SSong, Yoong Siang {
483aa042f60SSong, Yoong Siang 	struct stmmac_priv *priv = netdev_priv(netdev);
484aa042f60SSong, Yoong Siang 
485aa042f60SSong, Yoong Siang 	ring->rx_max_pending = DMA_MAX_RX_SIZE;
486aa042f60SSong, Yoong Siang 	ring->tx_max_pending = DMA_MAX_TX_SIZE;
4878531c808SChristian Marangi 	ring->rx_pending = priv->dma_conf.dma_rx_size;
4888531c808SChristian Marangi 	ring->tx_pending = priv->dma_conf.dma_tx_size;
489aa042f60SSong, Yoong Siang }
490aa042f60SSong, Yoong Siang 
stmmac_set_ringparam(struct net_device * netdev,struct ethtool_ringparam * ring,struct kernel_ethtool_ringparam * kernel_ring,struct netlink_ext_ack * extack)491aa042f60SSong, Yoong Siang static int stmmac_set_ringparam(struct net_device *netdev,
49274624944SHao Chen 				struct ethtool_ringparam *ring,
49374624944SHao Chen 				struct kernel_ethtool_ringparam *kernel_ring,
49474624944SHao Chen 				struct netlink_ext_ack *extack)
495aa042f60SSong, Yoong Siang {
496aa042f60SSong, Yoong Siang 	if (ring->rx_mini_pending || ring->rx_jumbo_pending ||
497aa042f60SSong, Yoong Siang 	    ring->rx_pending < DMA_MIN_RX_SIZE ||
498aa042f60SSong, Yoong Siang 	    ring->rx_pending > DMA_MAX_RX_SIZE ||
499aa042f60SSong, Yoong Siang 	    !is_power_of_2(ring->rx_pending) ||
500aa042f60SSong, Yoong Siang 	    ring->tx_pending < DMA_MIN_TX_SIZE ||
501aa042f60SSong, Yoong Siang 	    ring->tx_pending > DMA_MAX_TX_SIZE ||
502aa042f60SSong, Yoong Siang 	    !is_power_of_2(ring->tx_pending))
503aa042f60SSong, Yoong Siang 		return -EINVAL;
504aa042f60SSong, Yoong Siang 
505aa042f60SSong, Yoong Siang 	return stmmac_reinit_ringparam(netdev, ring->rx_pending,
506aa042f60SSong, Yoong Siang 				       ring->tx_pending);
507aa042f60SSong, Yoong Siang }
508aa042f60SSong, Yoong Siang 
5097ac6653aSJeff Kirsher static void
stmmac_get_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * pause)5107ac6653aSJeff Kirsher stmmac_get_pauseparam(struct net_device *netdev,
5117ac6653aSJeff Kirsher 		      struct ethtool_pauseparam *pause)
5127ac6653aSJeff Kirsher {
5137ac6653aSJeff Kirsher 	struct stmmac_priv *priv = netdev_priv(netdev);
514c10d4c82SJose Abreu 	struct rgmii_adv adv_lp;
5157ac6653aSJeff Kirsher 
516c10d4c82SJose Abreu 	if (priv->hw->pcs && !stmmac_pcs_get_adv_lp(priv, priv->ioaddr, &adv_lp)) {
51770523e63SGiuseppe CAVALLARO 		pause->autoneg = 1;
51870523e63SGiuseppe CAVALLARO 		if (!adv_lp.pause)
51970523e63SGiuseppe CAVALLARO 			return;
52070523e63SGiuseppe CAVALLARO 	} else {
52174371272SJose Abreu 		phylink_ethtool_get_pauseparam(priv->phylink, pause);
52270523e63SGiuseppe CAVALLARO 	}
5237ac6653aSJeff Kirsher }
5247ac6653aSJeff Kirsher 
5257ac6653aSJeff Kirsher static int
stmmac_set_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * pause)5267ac6653aSJeff Kirsher stmmac_set_pauseparam(struct net_device *netdev,
5277ac6653aSJeff Kirsher 		      struct ethtool_pauseparam *pause)
5287ac6653aSJeff Kirsher {
5297ac6653aSJeff Kirsher 	struct stmmac_priv *priv = netdev_priv(netdev);
53070523e63SGiuseppe CAVALLARO 	struct rgmii_adv adv_lp;
53170523e63SGiuseppe CAVALLARO 
532c10d4c82SJose Abreu 	if (priv->hw->pcs && !stmmac_pcs_get_adv_lp(priv, priv->ioaddr, &adv_lp)) {
53370523e63SGiuseppe CAVALLARO 		pause->autoneg = 1;
53470523e63SGiuseppe CAVALLARO 		if (!adv_lp.pause)
535e58bb43fSGiuseppe CAVALLARO 			return -EOPNOTSUPP;
53670523e63SGiuseppe CAVALLARO 		return 0;
53774371272SJose Abreu 	} else {
53874371272SJose Abreu 		return phylink_ethtool_set_pauseparam(priv->phylink, pause);
53974371272SJose Abreu 	}
5407ac6653aSJeff Kirsher }
5417ac6653aSJeff Kirsher 
stmmac_get_rx_normal_irq_n(struct stmmac_priv * priv,int q)542*9680b2abSPetr Tesarik static u64 stmmac_get_rx_normal_irq_n(struct stmmac_priv *priv, int q)
543*9680b2abSPetr Tesarik {
544*9680b2abSPetr Tesarik 	u64 total;
545*9680b2abSPetr Tesarik 	int cpu;
546*9680b2abSPetr Tesarik 
547*9680b2abSPetr Tesarik 	total = 0;
548*9680b2abSPetr Tesarik 	for_each_possible_cpu(cpu) {
549*9680b2abSPetr Tesarik 		struct stmmac_pcpu_stats *pcpu;
550*9680b2abSPetr Tesarik 		unsigned int start;
551*9680b2abSPetr Tesarik 		u64 irq_n;
552*9680b2abSPetr Tesarik 
553*9680b2abSPetr Tesarik 		pcpu = per_cpu_ptr(priv->xstats.pcpu_stats, cpu);
554*9680b2abSPetr Tesarik 		do {
555*9680b2abSPetr Tesarik 			start = u64_stats_fetch_begin(&pcpu->syncp);
556*9680b2abSPetr Tesarik 			irq_n = u64_stats_read(&pcpu->rx_normal_irq_n[q]);
557*9680b2abSPetr Tesarik 		} while (u64_stats_fetch_retry(&pcpu->syncp, start));
558*9680b2abSPetr Tesarik 		total += irq_n;
559*9680b2abSPetr Tesarik 	}
560*9680b2abSPetr Tesarik 	return total;
561*9680b2abSPetr Tesarik }
562*9680b2abSPetr Tesarik 
stmmac_get_tx_normal_irq_n(struct stmmac_priv * priv,int q)563*9680b2abSPetr Tesarik static u64 stmmac_get_tx_normal_irq_n(struct stmmac_priv *priv, int q)
564*9680b2abSPetr Tesarik {
565*9680b2abSPetr Tesarik 	u64 total;
566*9680b2abSPetr Tesarik 	int cpu;
567*9680b2abSPetr Tesarik 
568*9680b2abSPetr Tesarik 	total = 0;
569*9680b2abSPetr Tesarik 	for_each_possible_cpu(cpu) {
570*9680b2abSPetr Tesarik 		struct stmmac_pcpu_stats *pcpu;
571*9680b2abSPetr Tesarik 		unsigned int start;
572*9680b2abSPetr Tesarik 		u64 irq_n;
573*9680b2abSPetr Tesarik 
574*9680b2abSPetr Tesarik 		pcpu = per_cpu_ptr(priv->xstats.pcpu_stats, cpu);
575*9680b2abSPetr Tesarik 		do {
576*9680b2abSPetr Tesarik 			start = u64_stats_fetch_begin(&pcpu->syncp);
577*9680b2abSPetr Tesarik 			irq_n = u64_stats_read(&pcpu->tx_normal_irq_n[q]);
578*9680b2abSPetr Tesarik 		} while (u64_stats_fetch_retry(&pcpu->syncp, start));
579*9680b2abSPetr Tesarik 		total += irq_n;
580*9680b2abSPetr Tesarik 	}
581*9680b2abSPetr Tesarik 	return total;
582*9680b2abSPetr Tesarik }
583*9680b2abSPetr Tesarik 
stmmac_get_per_qstats(struct stmmac_priv * priv,u64 * data)58468e9c5deSVijayakannan Ayyathurai static void stmmac_get_per_qstats(struct stmmac_priv *priv, u64 *data)
58568e9c5deSVijayakannan Ayyathurai {
58668e9c5deSVijayakannan Ayyathurai 	u32 tx_cnt = priv->plat->tx_queues_to_use;
58768e9c5deSVijayakannan Ayyathurai 	u32 rx_cnt = priv->plat->rx_queues_to_use;
588133466c3SJisheng Zhang 	unsigned int start;
589*9680b2abSPetr Tesarik 	int q;
59068e9c5deSVijayakannan Ayyathurai 
59168e9c5deSVijayakannan Ayyathurai 	for (q = 0; q < tx_cnt; q++) {
5928070274bSJisheng Zhang 		struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[q];
593*9680b2abSPetr Tesarik 		u64 pkt_n;
594133466c3SJisheng Zhang 
595133466c3SJisheng Zhang 		do {
596*9680b2abSPetr Tesarik 			start = u64_stats_fetch_begin(&txq_stats->napi_syncp);
597*9680b2abSPetr Tesarik 			pkt_n = u64_stats_read(&txq_stats->napi.tx_pkt_n);
598*9680b2abSPetr Tesarik 		} while (u64_stats_fetch_retry(&txq_stats->napi_syncp, start));
599133466c3SJisheng Zhang 
600*9680b2abSPetr Tesarik 		*data++ = pkt_n;
601*9680b2abSPetr Tesarik 		*data++ = stmmac_get_tx_normal_irq_n(priv, q);
60268e9c5deSVijayakannan Ayyathurai 	}
603133466c3SJisheng Zhang 
60468e9c5deSVijayakannan Ayyathurai 	for (q = 0; q < rx_cnt; q++) {
6058070274bSJisheng Zhang 		struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[q];
606*9680b2abSPetr Tesarik 		u64 pkt_n;
607133466c3SJisheng Zhang 
608133466c3SJisheng Zhang 		do {
609*9680b2abSPetr Tesarik 			start = u64_stats_fetch_begin(&rxq_stats->napi_syncp);
610*9680b2abSPetr Tesarik 			pkt_n = u64_stats_read(&rxq_stats->napi.rx_pkt_n);
611*9680b2abSPetr Tesarik 		} while (u64_stats_fetch_retry(&rxq_stats->napi_syncp, start));
612133466c3SJisheng Zhang 
613*9680b2abSPetr Tesarik 		*data++ = pkt_n;
614*9680b2abSPetr Tesarik 		*data++ = stmmac_get_rx_normal_irq_n(priv, q);
61568e9c5deSVijayakannan Ayyathurai 	}
61668e9c5deSVijayakannan Ayyathurai }
61768e9c5deSVijayakannan Ayyathurai 
stmmac_get_ethtool_stats(struct net_device * dev,struct ethtool_stats * dummy,u64 * data)6187ac6653aSJeff Kirsher static void stmmac_get_ethtool_stats(struct net_device *dev,
6197ac6653aSJeff Kirsher 				 struct ethtool_stats *dummy, u64 *data)
6207ac6653aSJeff Kirsher {
6217ac6653aSJeff Kirsher 	struct stmmac_priv *priv = netdev_priv(dev);
622ad5a87d7SJoao Pinto 	u32 rx_queues_count = priv->plat->rx_queues_to_use;
623ad5a87d7SJoao Pinto 	u32 tx_queues_count = priv->plat->tx_queues_to_use;
624133466c3SJisheng Zhang 	u64 napi_poll = 0, normal_irq_n = 0;
625133466c3SJisheng Zhang 	int i, j = 0, pos, ret;
6268bf993a5SJose Abreu 	unsigned long count;
627133466c3SJisheng Zhang 	unsigned int start;
6287ac6653aSJeff Kirsher 
629c10d4c82SJose Abreu 	if (priv->dma_cap.asp) {
6308bf993a5SJose Abreu 		for (i = 0; i < STMMAC_SAFETY_FEAT_SIZE; i++) {
631c10d4c82SJose Abreu 			if (!stmmac_safety_feat_dump(priv, &priv->sstats, i,
632c10d4c82SJose Abreu 						&count, NULL))
6338bf993a5SJose Abreu 				data[j++] = count;
6348bf993a5SJose Abreu 		}
6358bf993a5SJose Abreu 	}
6368bf993a5SJose Abreu 
6371c901a46SGiuseppe CAVALLARO 	/* Update the DMA HW counters for dwmac10/100 */
638133466c3SJisheng Zhang 	ret = stmmac_dma_diagnostic_fr(priv, &priv->xstats, priv->ioaddr);
639a4e887faSJose Abreu 	if (ret) {
6401c901a46SGiuseppe CAVALLARO 		/* If supported, for new GMAC chips expose the MMC counters */
64138fe7a93SGiuseppe CAVALLARO 		if (priv->dma_cap.rmon) {
6423b1dd2c5SJose Abreu 			stmmac_mmc_read(priv, priv->mmcaddr, &priv->mmc);
6437ac6653aSJeff Kirsher 
6441c901a46SGiuseppe CAVALLARO 			for (i = 0; i < STMMAC_MMC_STATS_LEN; i++) {
64538fe7a93SGiuseppe CAVALLARO 				char *p;
64638fe7a93SGiuseppe CAVALLARO 				p = (char *)priv + stmmac_mmc[i].stat_offset;
6471c901a46SGiuseppe CAVALLARO 
64838fe7a93SGiuseppe CAVALLARO 				data[j++] = (stmmac_mmc[i].sizeof_stat ==
64938fe7a93SGiuseppe CAVALLARO 					     sizeof(u64)) ? (*(u64 *)p) :
65038fe7a93SGiuseppe CAVALLARO 					     (*(u32 *)p);
65138fe7a93SGiuseppe CAVALLARO 			}
6521c901a46SGiuseppe CAVALLARO 		}
653d765955dSGiuseppe CAVALLARO 		if (priv->eee_enabled) {
65474371272SJose Abreu 			int val = phylink_get_eee_err(priv->phylink);
655d765955dSGiuseppe CAVALLARO 			if (val)
656d765955dSGiuseppe CAVALLARO 				priv->xstats.phy_eee_wakeup_error_n = val;
657d765955dSGiuseppe CAVALLARO 		}
6582f7a791cSGiuseppe CAVALLARO 
659c10d4c82SJose Abreu 		if (priv->synopsys_id >= DWMAC_CORE_3_50)
660c10d4c82SJose Abreu 			stmmac_mac_debug(priv, priv->ioaddr,
661ad5a87d7SJoao Pinto 					(void *)&priv->xstats,
662ad5a87d7SJoao Pinto 					rx_queues_count, tx_queues_count);
6631c901a46SGiuseppe CAVALLARO 	}
6647ac6653aSJeff Kirsher 	for (i = 0; i < STMMAC_STATS_LEN; i++) {
6657ac6653aSJeff Kirsher 		char *p = (char *)priv + stmmac_gstrings_stats[i].stat_offset;
6661c901a46SGiuseppe CAVALLARO 		data[j++] = (stmmac_gstrings_stats[i].sizeof_stat ==
6677ac6653aSJeff Kirsher 			     sizeof(u64)) ? (*(u64 *)p) : (*(u32 *)p);
6687ac6653aSJeff Kirsher 	}
669133466c3SJisheng Zhang 
670133466c3SJisheng Zhang 	pos = j;
671133466c3SJisheng Zhang 	for (i = 0; i < rx_queues_count; i++) {
6728070274bSJisheng Zhang 		struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[i];
673*9680b2abSPetr Tesarik 		struct stmmac_napi_rx_stats snapshot;
674*9680b2abSPetr Tesarik 		u64 n_irq;
675133466c3SJisheng Zhang 
676133466c3SJisheng Zhang 		j = pos;
677133466c3SJisheng Zhang 		do {
678*9680b2abSPetr Tesarik 			start = u64_stats_fetch_begin(&rxq_stats->napi_syncp);
679*9680b2abSPetr Tesarik 			snapshot = rxq_stats->napi;
680*9680b2abSPetr Tesarik 		} while (u64_stats_fetch_retry(&rxq_stats->napi_syncp, start));
681133466c3SJisheng Zhang 
682*9680b2abSPetr Tesarik 		data[j++] += u64_stats_read(&snapshot.rx_pkt_n);
683*9680b2abSPetr Tesarik 		n_irq = stmmac_get_rx_normal_irq_n(priv, i);
684*9680b2abSPetr Tesarik 		data[j++] += n_irq;
685*9680b2abSPetr Tesarik 		normal_irq_n += n_irq;
686*9680b2abSPetr Tesarik 		napi_poll += u64_stats_read(&snapshot.poll);
687133466c3SJisheng Zhang 	}
688133466c3SJisheng Zhang 
689133466c3SJisheng Zhang 	pos = j;
690133466c3SJisheng Zhang 	for (i = 0; i < tx_queues_count; i++) {
6918070274bSJisheng Zhang 		struct stmmac_txq_stats *txq_stats = &priv->xstats.txq_stats[i];
692*9680b2abSPetr Tesarik 		struct stmmac_napi_tx_stats napi_snapshot;
693*9680b2abSPetr Tesarik 		struct stmmac_q_tx_stats q_snapshot;
694*9680b2abSPetr Tesarik 		u64 n_irq;
695133466c3SJisheng Zhang 
696133466c3SJisheng Zhang 		j = pos;
697133466c3SJisheng Zhang 		do {
698*9680b2abSPetr Tesarik 			start = u64_stats_fetch_begin(&txq_stats->q_syncp);
699*9680b2abSPetr Tesarik 			q_snapshot = txq_stats->q;
700*9680b2abSPetr Tesarik 		} while (u64_stats_fetch_retry(&txq_stats->q_syncp, start));
701*9680b2abSPetr Tesarik 		do {
702*9680b2abSPetr Tesarik 			start = u64_stats_fetch_begin(&txq_stats->napi_syncp);
703*9680b2abSPetr Tesarik 			napi_snapshot = txq_stats->napi;
704*9680b2abSPetr Tesarik 		} while (u64_stats_fetch_retry(&txq_stats->napi_syncp, start));
705133466c3SJisheng Zhang 
706*9680b2abSPetr Tesarik 		data[j++] += u64_stats_read(&napi_snapshot.tx_pkt_n);
707*9680b2abSPetr Tesarik 		n_irq = stmmac_get_tx_normal_irq_n(priv, i);
708*9680b2abSPetr Tesarik 		data[j++] += n_irq;
709*9680b2abSPetr Tesarik 		normal_irq_n += n_irq;
710*9680b2abSPetr Tesarik 		data[j++] += u64_stats_read(&napi_snapshot.tx_clean);
711*9680b2abSPetr Tesarik 		data[j++] += u64_stats_read(&q_snapshot.tx_set_ic_bit) +
712*9680b2abSPetr Tesarik 			u64_stats_read(&napi_snapshot.tx_set_ic_bit);
713*9680b2abSPetr Tesarik 		data[j++] += u64_stats_read(&q_snapshot.tx_tso_frames);
714*9680b2abSPetr Tesarik 		data[j++] += u64_stats_read(&q_snapshot.tx_tso_nfrags);
715*9680b2abSPetr Tesarik 		napi_poll += u64_stats_read(&napi_snapshot.poll);
716133466c3SJisheng Zhang 	}
717133466c3SJisheng Zhang 	normal_irq_n += priv->xstats.rx_early_irq;
718133466c3SJisheng Zhang 	data[j++] = normal_irq_n;
719133466c3SJisheng Zhang 	data[j++] = napi_poll;
720133466c3SJisheng Zhang 
72168e9c5deSVijayakannan Ayyathurai 	stmmac_get_per_qstats(priv, &data[j]);
7227ac6653aSJeff Kirsher }
7237ac6653aSJeff Kirsher 
stmmac_get_sset_count(struct net_device * netdev,int sset)7247ac6653aSJeff Kirsher static int stmmac_get_sset_count(struct net_device *netdev, int sset)
7257ac6653aSJeff Kirsher {
7261c901a46SGiuseppe CAVALLARO 	struct stmmac_priv *priv = netdev_priv(netdev);
72768e9c5deSVijayakannan Ayyathurai 	u32 tx_cnt = priv->plat->tx_queues_to_use;
72868e9c5deSVijayakannan Ayyathurai 	u32 rx_cnt = priv->plat->rx_queues_to_use;
7298bf993a5SJose Abreu 	int i, len, safety_len = 0;
7301c901a46SGiuseppe CAVALLARO 
7317ac6653aSJeff Kirsher 	switch (sset) {
7327ac6653aSJeff Kirsher 	case ETH_SS_STATS:
733133466c3SJisheng Zhang 		len = STMMAC_STATS_LEN + STMMAC_QSTATS +
73468e9c5deSVijayakannan Ayyathurai 		      STMMAC_TXQ_STATS * tx_cnt +
73568e9c5deSVijayakannan Ayyathurai 		      STMMAC_RXQ_STATS * rx_cnt;
7361c901a46SGiuseppe CAVALLARO 
73738fe7a93SGiuseppe CAVALLARO 		if (priv->dma_cap.rmon)
7381c901a46SGiuseppe CAVALLARO 			len += STMMAC_MMC_STATS_LEN;
739c10d4c82SJose Abreu 		if (priv->dma_cap.asp) {
7408bf993a5SJose Abreu 			for (i = 0; i < STMMAC_SAFETY_FEAT_SIZE; i++) {
741c10d4c82SJose Abreu 				if (!stmmac_safety_feat_dump(priv,
742c10d4c82SJose Abreu 							&priv->sstats, i,
743c10d4c82SJose Abreu 							NULL, NULL))
7448bf993a5SJose Abreu 					safety_len++;
7458bf993a5SJose Abreu 			}
7468bf993a5SJose Abreu 
7478bf993a5SJose Abreu 			len += safety_len;
7488bf993a5SJose Abreu 		}
7491c901a46SGiuseppe CAVALLARO 
7501c901a46SGiuseppe CAVALLARO 		return len;
751091810dbSJose Abreu 	case ETH_SS_TEST:
752091810dbSJose Abreu 		return stmmac_selftest_get_count(priv);
7537ac6653aSJeff Kirsher 	default:
7547ac6653aSJeff Kirsher 		return -EOPNOTSUPP;
7557ac6653aSJeff Kirsher 	}
7567ac6653aSJeff Kirsher }
7577ac6653aSJeff Kirsher 
stmmac_get_qstats_string(struct stmmac_priv * priv,u8 * data)75868e9c5deSVijayakannan Ayyathurai static void stmmac_get_qstats_string(struct stmmac_priv *priv, u8 *data)
75968e9c5deSVijayakannan Ayyathurai {
76068e9c5deSVijayakannan Ayyathurai 	u32 tx_cnt = priv->plat->tx_queues_to_use;
76168e9c5deSVijayakannan Ayyathurai 	u32 rx_cnt = priv->plat->rx_queues_to_use;
76268e9c5deSVijayakannan Ayyathurai 	int q, stat;
76368e9c5deSVijayakannan Ayyathurai 
76468e9c5deSVijayakannan Ayyathurai 	for (q = 0; q < tx_cnt; q++) {
76568e9c5deSVijayakannan Ayyathurai 		for (stat = 0; stat < STMMAC_TXQ_STATS; stat++) {
76668e9c5deSVijayakannan Ayyathurai 			snprintf(data, ETH_GSTRING_LEN, "q%d_%s", q,
76768e9c5deSVijayakannan Ayyathurai 				 stmmac_qstats_tx_string[stat]);
76868e9c5deSVijayakannan Ayyathurai 			data += ETH_GSTRING_LEN;
76968e9c5deSVijayakannan Ayyathurai 		}
77068e9c5deSVijayakannan Ayyathurai 	}
77168e9c5deSVijayakannan Ayyathurai 	for (q = 0; q < rx_cnt; q++) {
77268e9c5deSVijayakannan Ayyathurai 		for (stat = 0; stat < STMMAC_RXQ_STATS; stat++) {
77368e9c5deSVijayakannan Ayyathurai 			snprintf(data, ETH_GSTRING_LEN, "q%d_%s", q,
77468e9c5deSVijayakannan Ayyathurai 				 stmmac_qstats_rx_string[stat]);
77568e9c5deSVijayakannan Ayyathurai 			data += ETH_GSTRING_LEN;
77668e9c5deSVijayakannan Ayyathurai 		}
77768e9c5deSVijayakannan Ayyathurai 	}
77868e9c5deSVijayakannan Ayyathurai }
77968e9c5deSVijayakannan Ayyathurai 
stmmac_get_strings(struct net_device * dev,u32 stringset,u8 * data)7807ac6653aSJeff Kirsher static void stmmac_get_strings(struct net_device *dev, u32 stringset, u8 *data)
7817ac6653aSJeff Kirsher {
7827ac6653aSJeff Kirsher 	int i;
7837ac6653aSJeff Kirsher 	u8 *p = data;
7841c901a46SGiuseppe CAVALLARO 	struct stmmac_priv *priv = netdev_priv(dev);
7857ac6653aSJeff Kirsher 
7867ac6653aSJeff Kirsher 	switch (stringset) {
7877ac6653aSJeff Kirsher 	case ETH_SS_STATS:
788c10d4c82SJose Abreu 		if (priv->dma_cap.asp) {
7898bf993a5SJose Abreu 			for (i = 0; i < STMMAC_SAFETY_FEAT_SIZE; i++) {
790c10d4c82SJose Abreu 				const char *desc;
791c10d4c82SJose Abreu 				if (!stmmac_safety_feat_dump(priv,
792c10d4c82SJose Abreu 							&priv->sstats, i,
793c10d4c82SJose Abreu 							NULL, &desc)) {
7948bf993a5SJose Abreu 					memcpy(p, desc, ETH_GSTRING_LEN);
7958bf993a5SJose Abreu 					p += ETH_GSTRING_LEN;
7968bf993a5SJose Abreu 				}
7978bf993a5SJose Abreu 			}
7988bf993a5SJose Abreu 		}
79938fe7a93SGiuseppe CAVALLARO 		if (priv->dma_cap.rmon)
8001c901a46SGiuseppe CAVALLARO 			for (i = 0; i < STMMAC_MMC_STATS_LEN; i++) {
80138fe7a93SGiuseppe CAVALLARO 				memcpy(p, stmmac_mmc[i].stat_string,
8021c901a46SGiuseppe CAVALLARO 				       ETH_GSTRING_LEN);
8031c901a46SGiuseppe CAVALLARO 				p += ETH_GSTRING_LEN;
8041c901a46SGiuseppe CAVALLARO 			}
8057ac6653aSJeff Kirsher 		for (i = 0; i < STMMAC_STATS_LEN; i++) {
806133466c3SJisheng Zhang 			memcpy(p, stmmac_gstrings_stats[i].stat_string, ETH_GSTRING_LEN);
807133466c3SJisheng Zhang 			p += ETH_GSTRING_LEN;
808133466c3SJisheng Zhang 		}
809133466c3SJisheng Zhang 		for (i = 0; i < STMMAC_QSTATS; i++) {
810133466c3SJisheng Zhang 			memcpy(p, stmmac_qstats_string[i], ETH_GSTRING_LEN);
8117ac6653aSJeff Kirsher 			p += ETH_GSTRING_LEN;
8127ac6653aSJeff Kirsher 		}
81368e9c5deSVijayakannan Ayyathurai 		stmmac_get_qstats_string(priv, p);
8147ac6653aSJeff Kirsher 		break;
815091810dbSJose Abreu 	case ETH_SS_TEST:
816091810dbSJose Abreu 		stmmac_selftest_get_strings(priv, p);
817091810dbSJose Abreu 		break;
8187ac6653aSJeff Kirsher 	default:
8197ac6653aSJeff Kirsher 		WARN_ON(1);
8207ac6653aSJeff Kirsher 		break;
8217ac6653aSJeff Kirsher 	}
8227ac6653aSJeff Kirsher }
8237ac6653aSJeff Kirsher 
8247ac6653aSJeff Kirsher /* Currently only support WOL through Magic packet. */
stmmac_get_wol(struct net_device * dev,struct ethtool_wolinfo * wol)8257ac6653aSJeff Kirsher static void stmmac_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
8267ac6653aSJeff Kirsher {
8277ac6653aSJeff Kirsher 	struct stmmac_priv *priv = netdev_priv(dev);
8287ac6653aSJeff Kirsher 
8291d8e5b0fSJisheng Zhang 	if (!priv->plat->pmt)
8301d8e5b0fSJisheng Zhang 		return phylink_ethtool_get_wol(priv->phylink, wol);
8311d8e5b0fSJisheng Zhang 
83229555fa3SThierry Reding 	mutex_lock(&priv->lock);
8337ac6653aSJeff Kirsher 	if (device_can_wakeup(priv->device)) {
8347ac6653aSJeff Kirsher 		wol->supported = WAKE_MAGIC | WAKE_UCAST;
8351057d685SJisheng Zhang 		if (priv->hw_cap_support && !priv->dma_cap.pmt_magic_frame)
8361057d685SJisheng Zhang 			wol->supported &= ~WAKE_MAGIC;
8377ac6653aSJeff Kirsher 		wol->wolopts = priv->wolopts;
8387ac6653aSJeff Kirsher 	}
83929555fa3SThierry Reding 	mutex_unlock(&priv->lock);
8407ac6653aSJeff Kirsher }
8417ac6653aSJeff Kirsher 
stmmac_set_wol(struct net_device * dev,struct ethtool_wolinfo * wol)8427ac6653aSJeff Kirsher static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
8437ac6653aSJeff Kirsher {
8447ac6653aSJeff Kirsher 	struct stmmac_priv *priv = netdev_priv(dev);
8457ac6653aSJeff Kirsher 	u32 support = WAKE_MAGIC | WAKE_UCAST;
8467ac6653aSJeff Kirsher 
8472f45f7a1SJisheng Zhang 	if (!device_can_wakeup(priv->device))
8482f45f7a1SJisheng Zhang 		return -EOPNOTSUPP;
8492f45f7a1SJisheng Zhang 
8501d8e5b0fSJisheng Zhang 	if (!priv->plat->pmt) {
8511d8e5b0fSJisheng Zhang 		int ret = phylink_ethtool_set_wol(priv->phylink, wol);
8521d8e5b0fSJisheng Zhang 
8531d8e5b0fSJisheng Zhang 		if (!ret)
85401f4d47aSJisheng Zhang 			device_set_wakeup_enable(priv->device, !!wol->wolopts);
8551d8e5b0fSJisheng Zhang 		return ret;
8561d8e5b0fSJisheng Zhang 	}
8571d8e5b0fSJisheng Zhang 
85819e30c14SGiuseppe CAVALLARO 	/* By default almost all GMAC devices support the WoL via
85919e30c14SGiuseppe CAVALLARO 	 * magic frame but we can disable it if the HW capability
86019e30c14SGiuseppe CAVALLARO 	 * register shows no support for pmt_magic_frame. */
86119e30c14SGiuseppe CAVALLARO 	if ((priv->hw_cap_support) && (!priv->dma_cap.pmt_magic_frame))
86219e30c14SGiuseppe CAVALLARO 		wol->wolopts &= ~WAKE_MAGIC;
86319e30c14SGiuseppe CAVALLARO 
8647ac6653aSJeff Kirsher 	if (wol->wolopts & ~support)
8657ac6653aSJeff Kirsher 		return -EINVAL;
8667ac6653aSJeff Kirsher 
8677ac6653aSJeff Kirsher 	if (wol->wolopts) {
8687ac6653aSJeff Kirsher 		pr_info("stmmac: wakeup enable\n");
8697ac6653aSJeff Kirsher 		device_set_wakeup_enable(priv->device, 1);
870fed034d2SQiang Ma 		/* Avoid unbalanced enable_irq_wake calls */
871fed034d2SQiang Ma 		if (priv->wol_irq_disabled)
8723172d3afSDeepak Sikri 			enable_irq_wake(priv->wol_irq);
873fed034d2SQiang Ma 		priv->wol_irq_disabled = false;
8747ac6653aSJeff Kirsher 	} else {
8757ac6653aSJeff Kirsher 		device_set_wakeup_enable(priv->device, 0);
876fed034d2SQiang Ma 		/* Avoid unbalanced disable_irq_wake calls */
877fed034d2SQiang Ma 		if (!priv->wol_irq_disabled)
8783172d3afSDeepak Sikri 			disable_irq_wake(priv->wol_irq);
879fed034d2SQiang Ma 		priv->wol_irq_disabled = true;
8807ac6653aSJeff Kirsher 	}
8817ac6653aSJeff Kirsher 
88229555fa3SThierry Reding 	mutex_lock(&priv->lock);
8837ac6653aSJeff Kirsher 	priv->wolopts = wol->wolopts;
88429555fa3SThierry Reding 	mutex_unlock(&priv->lock);
8857ac6653aSJeff Kirsher 
8867ac6653aSJeff Kirsher 	return 0;
8877ac6653aSJeff Kirsher }
8887ac6653aSJeff Kirsher 
stmmac_ethtool_op_get_eee(struct net_device * dev,struct ethtool_eee * edata)889d765955dSGiuseppe CAVALLARO static int stmmac_ethtool_op_get_eee(struct net_device *dev,
890d765955dSGiuseppe CAVALLARO 				     struct ethtool_eee *edata)
891d765955dSGiuseppe CAVALLARO {
892d765955dSGiuseppe CAVALLARO 	struct stmmac_priv *priv = netdev_priv(dev);
893d765955dSGiuseppe CAVALLARO 
894d765955dSGiuseppe CAVALLARO 	if (!priv->dma_cap.eee)
895d765955dSGiuseppe CAVALLARO 		return -EOPNOTSUPP;
896d765955dSGiuseppe CAVALLARO 
897d765955dSGiuseppe CAVALLARO 	edata->eee_enabled = priv->eee_enabled;
898d765955dSGiuseppe CAVALLARO 	edata->eee_active = priv->eee_active;
899d765955dSGiuseppe CAVALLARO 	edata->tx_lpi_timer = priv->tx_lpi_timer;
900388e201dSVineetha G. Jaya Kumaran 	edata->tx_lpi_enabled = priv->tx_lpi_enabled;
901d765955dSGiuseppe CAVALLARO 
90274371272SJose Abreu 	return phylink_ethtool_get_eee(priv->phylink, edata);
903d765955dSGiuseppe CAVALLARO }
904d765955dSGiuseppe CAVALLARO 
stmmac_ethtool_op_set_eee(struct net_device * dev,struct ethtool_eee * edata)905d765955dSGiuseppe CAVALLARO static int stmmac_ethtool_op_set_eee(struct net_device *dev,
906d765955dSGiuseppe CAVALLARO 				     struct ethtool_eee *edata)
907d765955dSGiuseppe CAVALLARO {
908d765955dSGiuseppe CAVALLARO 	struct stmmac_priv *priv = netdev_priv(dev);
9098a7493e5SJose Abreu 	int ret;
910d765955dSGiuseppe CAVALLARO 
9117241c5a6SVoon Weifeng 	if (!priv->dma_cap.eee)
912d765955dSGiuseppe CAVALLARO 		return -EOPNOTSUPP;
9137241c5a6SVoon Weifeng 
914388e201dSVineetha G. Jaya Kumaran 	if (priv->tx_lpi_enabled != edata->tx_lpi_enabled)
915388e201dSVineetha G. Jaya Kumaran 		netdev_warn(priv->dev,
916388e201dSVineetha G. Jaya Kumaran 			    "Setting EEE tx-lpi is not supported\n");
917388e201dSVineetha G. Jaya Kumaran 
9187241c5a6SVoon Weifeng 	if (!edata->eee_enabled)
9197241c5a6SVoon Weifeng 		stmmac_disable_eee_mode(priv);
920d765955dSGiuseppe CAVALLARO 
92174371272SJose Abreu 	ret = phylink_ethtool_set_eee(priv->phylink, edata);
9228a7493e5SJose Abreu 	if (ret)
9238a7493e5SJose Abreu 		return ret;
9248a7493e5SJose Abreu 
925388e201dSVineetha G. Jaya Kumaran 	if (edata->eee_enabled &&
926388e201dSVineetha G. Jaya Kumaran 	    priv->tx_lpi_timer != edata->tx_lpi_timer) {
9278a7493e5SJose Abreu 		priv->tx_lpi_timer = edata->tx_lpi_timer;
928388e201dSVineetha G. Jaya Kumaran 		stmmac_eee_init(priv);
929388e201dSVineetha G. Jaya Kumaran 	}
930388e201dSVineetha G. Jaya Kumaran 
9318a7493e5SJose Abreu 	return 0;
932d765955dSGiuseppe CAVALLARO }
933d765955dSGiuseppe CAVALLARO 
stmmac_usec2riwt(u32 usec,struct stmmac_priv * priv)93448f44da4SGiuseppe CAVALLARO static u32 stmmac_usec2riwt(u32 usec, struct stmmac_priv *priv)
93548f44da4SGiuseppe CAVALLARO {
936f573c0b9Sjpinto 	unsigned long clk = clk_get_rate(priv->plat->stmmac_clk);
93748f44da4SGiuseppe CAVALLARO 
9384ec5302fSJose Abreu 	if (!clk) {
9394ec5302fSJose Abreu 		clk = priv->plat->clk_ref_rate;
94048f44da4SGiuseppe CAVALLARO 		if (!clk)
94148f44da4SGiuseppe CAVALLARO 			return 0;
9424ec5302fSJose Abreu 	}
94348f44da4SGiuseppe CAVALLARO 
94448f44da4SGiuseppe CAVALLARO 	return (usec * (clk / 1000000)) / 256;
94548f44da4SGiuseppe CAVALLARO }
94648f44da4SGiuseppe CAVALLARO 
stmmac_riwt2usec(u32 riwt,struct stmmac_priv * priv)94748f44da4SGiuseppe CAVALLARO static u32 stmmac_riwt2usec(u32 riwt, struct stmmac_priv *priv)
94848f44da4SGiuseppe CAVALLARO {
949f573c0b9Sjpinto 	unsigned long clk = clk_get_rate(priv->plat->stmmac_clk);
95048f44da4SGiuseppe CAVALLARO 
9514ec5302fSJose Abreu 	if (!clk) {
9524ec5302fSJose Abreu 		clk = priv->plat->clk_ref_rate;
95348f44da4SGiuseppe CAVALLARO 		if (!clk)
95448f44da4SGiuseppe CAVALLARO 			return 0;
9554ec5302fSJose Abreu 	}
95648f44da4SGiuseppe CAVALLARO 
95748f44da4SGiuseppe CAVALLARO 	return (riwt * 256) / (clk / 1000000);
95848f44da4SGiuseppe CAVALLARO }
95948f44da4SGiuseppe CAVALLARO 
__stmmac_get_coalesce(struct net_device * dev,struct ethtool_coalesce * ec,int queue)960db2f2842SOng Boon Leong static int __stmmac_get_coalesce(struct net_device *dev,
961db2f2842SOng Boon Leong 				 struct ethtool_coalesce *ec,
962db2f2842SOng Boon Leong 				 int queue)
96348f44da4SGiuseppe CAVALLARO {
96448f44da4SGiuseppe CAVALLARO 	struct stmmac_priv *priv = netdev_priv(dev);
965db2f2842SOng Boon Leong 	u32 max_cnt;
966db2f2842SOng Boon Leong 	u32 rx_cnt;
967db2f2842SOng Boon Leong 	u32 tx_cnt;
96848f44da4SGiuseppe CAVALLARO 
969db2f2842SOng Boon Leong 	rx_cnt = priv->plat->rx_queues_to_use;
970db2f2842SOng Boon Leong 	tx_cnt = priv->plat->tx_queues_to_use;
971db2f2842SOng Boon Leong 	max_cnt = max(rx_cnt, tx_cnt);
97248f44da4SGiuseppe CAVALLARO 
973db2f2842SOng Boon Leong 	if (queue < 0)
974db2f2842SOng Boon Leong 		queue = 0;
975db2f2842SOng Boon Leong 	else if (queue >= max_cnt)
976db2f2842SOng Boon Leong 		return -EINVAL;
977db2f2842SOng Boon Leong 
978db2f2842SOng Boon Leong 	if (queue < tx_cnt) {
979db2f2842SOng Boon Leong 		ec->tx_coalesce_usecs = priv->tx_coal_timer[queue];
980db2f2842SOng Boon Leong 		ec->tx_max_coalesced_frames = priv->tx_coal_frames[queue];
981db2f2842SOng Boon Leong 	} else {
982db2f2842SOng Boon Leong 		ec->tx_coalesce_usecs = 0;
983db2f2842SOng Boon Leong 		ec->tx_max_coalesced_frames = 0;
984db2f2842SOng Boon Leong 	}
985db2f2842SOng Boon Leong 
986db2f2842SOng Boon Leong 	if (priv->use_riwt && queue < rx_cnt) {
987db2f2842SOng Boon Leong 		ec->rx_max_coalesced_frames = priv->rx_coal_frames[queue];
988db2f2842SOng Boon Leong 		ec->rx_coalesce_usecs = stmmac_riwt2usec(priv->rx_riwt[queue],
989db2f2842SOng Boon Leong 							 priv);
990db2f2842SOng Boon Leong 	} else {
991db2f2842SOng Boon Leong 		ec->rx_max_coalesced_frames = 0;
992db2f2842SOng Boon Leong 		ec->rx_coalesce_usecs = 0;
993d429b66eSJose Abreu 	}
99448f44da4SGiuseppe CAVALLARO 
99548f44da4SGiuseppe CAVALLARO 	return 0;
99648f44da4SGiuseppe CAVALLARO }
99748f44da4SGiuseppe CAVALLARO 
stmmac_get_coalesce(struct net_device * dev,struct ethtool_coalesce * ec,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)998db2f2842SOng Boon Leong static int stmmac_get_coalesce(struct net_device *dev,
999f3ccfda1SYufeng Mo 			       struct ethtool_coalesce *ec,
1000f3ccfda1SYufeng Mo 			       struct kernel_ethtool_coalesce *kernel_coal,
1001f3ccfda1SYufeng Mo 			       struct netlink_ext_ack *extack)
100248f44da4SGiuseppe CAVALLARO {
1003db2f2842SOng Boon Leong 	return __stmmac_get_coalesce(dev, ec, -1);
1004db2f2842SOng Boon Leong }
1005db2f2842SOng Boon Leong 
stmmac_get_per_queue_coalesce(struct net_device * dev,u32 queue,struct ethtool_coalesce * ec)1006db2f2842SOng Boon Leong static int stmmac_get_per_queue_coalesce(struct net_device *dev, u32 queue,
1007db2f2842SOng Boon Leong 					 struct ethtool_coalesce *ec)
1008db2f2842SOng Boon Leong {
1009db2f2842SOng Boon Leong 	return __stmmac_get_coalesce(dev, ec, queue);
1010db2f2842SOng Boon Leong }
1011db2f2842SOng Boon Leong 
__stmmac_set_coalesce(struct net_device * dev,struct ethtool_coalesce * ec,int queue)1012db2f2842SOng Boon Leong static int __stmmac_set_coalesce(struct net_device *dev,
1013db2f2842SOng Boon Leong 				 struct ethtool_coalesce *ec,
1014db2f2842SOng Boon Leong 				 int queue)
1015db2f2842SOng Boon Leong {
101648f44da4SGiuseppe CAVALLARO 	struct stmmac_priv *priv = netdev_priv(dev);
1017db2f2842SOng Boon Leong 	bool all_queues = false;
101848f44da4SGiuseppe CAVALLARO 	unsigned int rx_riwt;
1019db2f2842SOng Boon Leong 	u32 max_cnt;
1020db2f2842SOng Boon Leong 	u32 rx_cnt;
1021db2f2842SOng Boon Leong 	u32 tx_cnt;
1022db2f2842SOng Boon Leong 
1023db2f2842SOng Boon Leong 	rx_cnt = priv->plat->rx_queues_to_use;
1024db2f2842SOng Boon Leong 	tx_cnt = priv->plat->tx_queues_to_use;
1025db2f2842SOng Boon Leong 	max_cnt = max(rx_cnt, tx_cnt);
1026db2f2842SOng Boon Leong 
1027db2f2842SOng Boon Leong 	if (queue < 0)
1028db2f2842SOng Boon Leong 		all_queues = true;
1029db2f2842SOng Boon Leong 	else if (queue >= max_cnt)
1030db2f2842SOng Boon Leong 		return -EINVAL;
103148f44da4SGiuseppe CAVALLARO 
10328f9e5b5dSJose Abreu 	if (priv->use_riwt && (ec->rx_coalesce_usecs > 0)) {
10338f9e5b5dSJose Abreu 		rx_riwt = stmmac_usec2riwt(ec->rx_coalesce_usecs, priv);
10348f9e5b5dSJose Abreu 
10358f9e5b5dSJose Abreu 		if ((rx_riwt > MAX_DMA_RIWT) || (rx_riwt < MIN_DMA_RIWT))
103648f44da4SGiuseppe CAVALLARO 			return -EINVAL;
103748f44da4SGiuseppe CAVALLARO 
1038db2f2842SOng Boon Leong 		if (all_queues) {
1039db2f2842SOng Boon Leong 			int i;
1040db2f2842SOng Boon Leong 
1041db2f2842SOng Boon Leong 			for (i = 0; i < rx_cnt; i++) {
1042db2f2842SOng Boon Leong 				priv->rx_riwt[i] = rx_riwt;
1043db2f2842SOng Boon Leong 				stmmac_rx_watchdog(priv, priv->ioaddr,
1044db2f2842SOng Boon Leong 						   rx_riwt, i);
1045db2f2842SOng Boon Leong 				priv->rx_coal_frames[i] =
1046db2f2842SOng Boon Leong 					ec->rx_max_coalesced_frames;
1047db2f2842SOng Boon Leong 			}
1048db2f2842SOng Boon Leong 		} else if (queue < rx_cnt) {
1049db2f2842SOng Boon Leong 			priv->rx_riwt[queue] = rx_riwt;
1050db2f2842SOng Boon Leong 			stmmac_rx_watchdog(priv, priv->ioaddr,
1051db2f2842SOng Boon Leong 					   rx_riwt, queue);
1052db2f2842SOng Boon Leong 			priv->rx_coal_frames[queue] =
1053db2f2842SOng Boon Leong 				ec->rx_max_coalesced_frames;
1054db2f2842SOng Boon Leong 		}
10558f9e5b5dSJose Abreu 	}
10568f9e5b5dSJose Abreu 
105748f44da4SGiuseppe CAVALLARO 	if ((ec->tx_coalesce_usecs == 0) &&
105848f44da4SGiuseppe CAVALLARO 	    (ec->tx_max_coalesced_frames == 0))
105948f44da4SGiuseppe CAVALLARO 		return -EINVAL;
106048f44da4SGiuseppe CAVALLARO 
10619b8d16cfSGiuseppe CAVALLARO 	if ((ec->tx_coalesce_usecs > STMMAC_MAX_COAL_TX_TICK) ||
106248f44da4SGiuseppe CAVALLARO 	    (ec->tx_max_coalesced_frames > STMMAC_TX_MAX_FRAMES))
106348f44da4SGiuseppe CAVALLARO 		return -EINVAL;
106448f44da4SGiuseppe CAVALLARO 
1065db2f2842SOng Boon Leong 	if (all_queues) {
1066db2f2842SOng Boon Leong 		int i;
1067db2f2842SOng Boon Leong 
1068db2f2842SOng Boon Leong 		for (i = 0; i < tx_cnt; i++) {
1069db2f2842SOng Boon Leong 			priv->tx_coal_frames[i] =
1070db2f2842SOng Boon Leong 				ec->tx_max_coalesced_frames;
1071db2f2842SOng Boon Leong 			priv->tx_coal_timer[i] =
1072db2f2842SOng Boon Leong 				ec->tx_coalesce_usecs;
1073db2f2842SOng Boon Leong 		}
1074db2f2842SOng Boon Leong 	} else if (queue < tx_cnt) {
1075db2f2842SOng Boon Leong 		priv->tx_coal_frames[queue] =
1076db2f2842SOng Boon Leong 			ec->tx_max_coalesced_frames;
1077db2f2842SOng Boon Leong 		priv->tx_coal_timer[queue] =
1078db2f2842SOng Boon Leong 			ec->tx_coalesce_usecs;
1079db2f2842SOng Boon Leong 	}
1080db2f2842SOng Boon Leong 
108148f44da4SGiuseppe CAVALLARO 	return 0;
108248f44da4SGiuseppe CAVALLARO }
108348f44da4SGiuseppe CAVALLARO 
stmmac_set_coalesce(struct net_device * dev,struct ethtool_coalesce * ec,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)1084db2f2842SOng Boon Leong static int stmmac_set_coalesce(struct net_device *dev,
1085f3ccfda1SYufeng Mo 			       struct ethtool_coalesce *ec,
1086f3ccfda1SYufeng Mo 			       struct kernel_ethtool_coalesce *kernel_coal,
1087f3ccfda1SYufeng Mo 			       struct netlink_ext_ack *extack)
1088db2f2842SOng Boon Leong {
1089db2f2842SOng Boon Leong 	return __stmmac_set_coalesce(dev, ec, -1);
1090db2f2842SOng Boon Leong }
1091db2f2842SOng Boon Leong 
stmmac_set_per_queue_coalesce(struct net_device * dev,u32 queue,struct ethtool_coalesce * ec)1092db2f2842SOng Boon Leong static int stmmac_set_per_queue_coalesce(struct net_device *dev, u32 queue,
1093db2f2842SOng Boon Leong 					 struct ethtool_coalesce *ec)
1094db2f2842SOng Boon Leong {
1095db2f2842SOng Boon Leong 	return __stmmac_set_coalesce(dev, ec, queue);
1096db2f2842SOng Boon Leong }
1097db2f2842SOng Boon Leong 
stmmac_get_rxnfc(struct net_device * dev,struct ethtool_rxnfc * rxnfc,u32 * rule_locs)109876067459SJose Abreu static int stmmac_get_rxnfc(struct net_device *dev,
109976067459SJose Abreu 			    struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
110076067459SJose Abreu {
110176067459SJose Abreu 	struct stmmac_priv *priv = netdev_priv(dev);
110276067459SJose Abreu 
110376067459SJose Abreu 	switch (rxnfc->cmd) {
110476067459SJose Abreu 	case ETHTOOL_GRXRINGS:
110576067459SJose Abreu 		rxnfc->data = priv->plat->rx_queues_to_use;
110676067459SJose Abreu 		break;
110776067459SJose Abreu 	default:
110876067459SJose Abreu 		return -EOPNOTSUPP;
110976067459SJose Abreu 	}
111076067459SJose Abreu 
111176067459SJose Abreu 	return 0;
111276067459SJose Abreu }
111376067459SJose Abreu 
stmmac_get_rxfh_key_size(struct net_device * dev)111476067459SJose Abreu static u32 stmmac_get_rxfh_key_size(struct net_device *dev)
111576067459SJose Abreu {
111676067459SJose Abreu 	struct stmmac_priv *priv = netdev_priv(dev);
111776067459SJose Abreu 
111876067459SJose Abreu 	return sizeof(priv->rss.key);
111976067459SJose Abreu }
112076067459SJose Abreu 
stmmac_get_rxfh_indir_size(struct net_device * dev)112176067459SJose Abreu static u32 stmmac_get_rxfh_indir_size(struct net_device *dev)
112276067459SJose Abreu {
112376067459SJose Abreu 	struct stmmac_priv *priv = netdev_priv(dev);
112476067459SJose Abreu 
112576067459SJose Abreu 	return ARRAY_SIZE(priv->rss.table);
112676067459SJose Abreu }
112776067459SJose Abreu 
stmmac_get_rxfh(struct net_device * dev,u32 * indir,u8 * key,u8 * hfunc)112876067459SJose Abreu static int stmmac_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
112976067459SJose Abreu 			   u8 *hfunc)
113076067459SJose Abreu {
113176067459SJose Abreu 	struct stmmac_priv *priv = netdev_priv(dev);
113276067459SJose Abreu 	int i;
113376067459SJose Abreu 
113476067459SJose Abreu 	if (indir) {
113576067459SJose Abreu 		for (i = 0; i < ARRAY_SIZE(priv->rss.table); i++)
113676067459SJose Abreu 			indir[i] = priv->rss.table[i];
113776067459SJose Abreu 	}
113876067459SJose Abreu 
113976067459SJose Abreu 	if (key)
114076067459SJose Abreu 		memcpy(key, priv->rss.key, sizeof(priv->rss.key));
114176067459SJose Abreu 	if (hfunc)
114276067459SJose Abreu 		*hfunc = ETH_RSS_HASH_TOP;
114376067459SJose Abreu 
114476067459SJose Abreu 	return 0;
114576067459SJose Abreu }
114676067459SJose Abreu 
stmmac_set_rxfh(struct net_device * dev,const u32 * indir,const u8 * key,const u8 hfunc)114776067459SJose Abreu static int stmmac_set_rxfh(struct net_device *dev, const u32 *indir,
114876067459SJose Abreu 			   const u8 *key, const u8 hfunc)
114976067459SJose Abreu {
115076067459SJose Abreu 	struct stmmac_priv *priv = netdev_priv(dev);
115176067459SJose Abreu 	int i;
115276067459SJose Abreu 
115376067459SJose Abreu 	if ((hfunc != ETH_RSS_HASH_NO_CHANGE) && (hfunc != ETH_RSS_HASH_TOP))
115476067459SJose Abreu 		return -EOPNOTSUPP;
115576067459SJose Abreu 
115676067459SJose Abreu 	if (indir) {
115776067459SJose Abreu 		for (i = 0; i < ARRAY_SIZE(priv->rss.table); i++)
115876067459SJose Abreu 			priv->rss.table[i] = indir[i];
115976067459SJose Abreu 	}
116076067459SJose Abreu 
116176067459SJose Abreu 	if (key)
116276067459SJose Abreu 		memcpy(priv->rss.key, key, sizeof(priv->rss.key));
116376067459SJose Abreu 
116476067459SJose Abreu 	return stmmac_rss_configure(priv, priv->hw, &priv->rss,
116576067459SJose Abreu 				    priv->plat->rx_queues_to_use);
116676067459SJose Abreu }
116776067459SJose Abreu 
stmmac_get_channels(struct net_device * dev,struct ethtool_channels * chan)11680366f7e0SOng Boon Leong static void stmmac_get_channels(struct net_device *dev,
11690366f7e0SOng Boon Leong 				struct ethtool_channels *chan)
11700366f7e0SOng Boon Leong {
11710366f7e0SOng Boon Leong 	struct stmmac_priv *priv = netdev_priv(dev);
11720366f7e0SOng Boon Leong 
11730366f7e0SOng Boon Leong 	chan->rx_count = priv->plat->rx_queues_to_use;
11740366f7e0SOng Boon Leong 	chan->tx_count = priv->plat->tx_queues_to_use;
11750366f7e0SOng Boon Leong 	chan->max_rx = priv->dma_cap.number_rx_queues;
11760366f7e0SOng Boon Leong 	chan->max_tx = priv->dma_cap.number_tx_queues;
11770366f7e0SOng Boon Leong }
11780366f7e0SOng Boon Leong 
stmmac_set_channels(struct net_device * dev,struct ethtool_channels * chan)11790366f7e0SOng Boon Leong static int stmmac_set_channels(struct net_device *dev,
11800366f7e0SOng Boon Leong 			       struct ethtool_channels *chan)
11810366f7e0SOng Boon Leong {
11820366f7e0SOng Boon Leong 	struct stmmac_priv *priv = netdev_priv(dev);
11830366f7e0SOng Boon Leong 
11840366f7e0SOng Boon Leong 	if (chan->rx_count > priv->dma_cap.number_rx_queues ||
11850366f7e0SOng Boon Leong 	    chan->tx_count > priv->dma_cap.number_tx_queues ||
11860366f7e0SOng Boon Leong 	    !chan->rx_count || !chan->tx_count)
11870366f7e0SOng Boon Leong 		return -EINVAL;
11880366f7e0SOng Boon Leong 
11890366f7e0SOng Boon Leong 	return stmmac_reinit_queues(dev, chan->rx_count, chan->tx_count);
11900366f7e0SOng Boon Leong }
11910366f7e0SOng Boon Leong 
stmmac_get_ts_info(struct net_device * dev,struct ethtool_ts_info * info)1192891434b1SRayagond Kokatanur static int stmmac_get_ts_info(struct net_device *dev,
1193891434b1SRayagond Kokatanur 			      struct ethtool_ts_info *info)
1194891434b1SRayagond Kokatanur {
1195891434b1SRayagond Kokatanur 	struct stmmac_priv *priv = netdev_priv(dev);
1196891434b1SRayagond Kokatanur 
1197e6dbe1ebSPhil Reid 	if ((priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) {
1198891434b1SRayagond Kokatanur 
1199e6dbe1ebSPhil Reid 		info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
1200e6dbe1ebSPhil Reid 					SOF_TIMESTAMPING_TX_HARDWARE |
1201e6dbe1ebSPhil Reid 					SOF_TIMESTAMPING_RX_SOFTWARE |
1202891434b1SRayagond Kokatanur 					SOF_TIMESTAMPING_RX_HARDWARE |
1203e6dbe1ebSPhil Reid 					SOF_TIMESTAMPING_SOFTWARE |
1204891434b1SRayagond Kokatanur 					SOF_TIMESTAMPING_RAW_HARDWARE;
1205891434b1SRayagond Kokatanur 
120692ba6888SRayagond Kokatanur 		if (priv->ptp_clock)
120792ba6888SRayagond Kokatanur 			info->phc_index = ptp_clock_index(priv->ptp_clock);
120892ba6888SRayagond Kokatanur 
1209891434b1SRayagond Kokatanur 		info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
1210891434b1SRayagond Kokatanur 
1211891434b1SRayagond Kokatanur 		info->rx_filters = ((1 << HWTSTAMP_FILTER_NONE) |
1212891434b1SRayagond Kokatanur 				    (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
1213891434b1SRayagond Kokatanur 				    (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
1214891434b1SRayagond Kokatanur 				    (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
1215891434b1SRayagond Kokatanur 				    (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
1216891434b1SRayagond Kokatanur 				    (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
1217891434b1SRayagond Kokatanur 				    (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
1218891434b1SRayagond Kokatanur 				    (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
1219891434b1SRayagond Kokatanur 				    (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
1220891434b1SRayagond Kokatanur 				    (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
1221891434b1SRayagond Kokatanur 				    (1 << HWTSTAMP_FILTER_ALL));
1222891434b1SRayagond Kokatanur 		return 0;
1223891434b1SRayagond Kokatanur 	} else
1224891434b1SRayagond Kokatanur 		return ethtool_op_get_ts_info(dev, info);
1225891434b1SRayagond Kokatanur }
1226891434b1SRayagond Kokatanur 
stmmac_get_tunable(struct net_device * dev,const struct ethtool_tunable * tuna,void * data)122722ad3838SGiuseppe Cavallaro static int stmmac_get_tunable(struct net_device *dev,
122822ad3838SGiuseppe Cavallaro 			      const struct ethtool_tunable *tuna, void *data)
122922ad3838SGiuseppe Cavallaro {
123022ad3838SGiuseppe Cavallaro 	struct stmmac_priv *priv = netdev_priv(dev);
123122ad3838SGiuseppe Cavallaro 	int ret = 0;
123222ad3838SGiuseppe Cavallaro 
123322ad3838SGiuseppe Cavallaro 	switch (tuna->id) {
123422ad3838SGiuseppe Cavallaro 	case ETHTOOL_RX_COPYBREAK:
123522ad3838SGiuseppe Cavallaro 		*(u32 *)data = priv->rx_copybreak;
123622ad3838SGiuseppe Cavallaro 		break;
123722ad3838SGiuseppe Cavallaro 	default:
123822ad3838SGiuseppe Cavallaro 		ret = -EINVAL;
123922ad3838SGiuseppe Cavallaro 		break;
124022ad3838SGiuseppe Cavallaro 	}
124122ad3838SGiuseppe Cavallaro 
124222ad3838SGiuseppe Cavallaro 	return ret;
124322ad3838SGiuseppe Cavallaro }
124422ad3838SGiuseppe Cavallaro 
stmmac_set_tunable(struct net_device * dev,const struct ethtool_tunable * tuna,const void * data)124522ad3838SGiuseppe Cavallaro static int stmmac_set_tunable(struct net_device *dev,
124622ad3838SGiuseppe Cavallaro 			      const struct ethtool_tunable *tuna,
124722ad3838SGiuseppe Cavallaro 			      const void *data)
124822ad3838SGiuseppe Cavallaro {
124922ad3838SGiuseppe Cavallaro 	struct stmmac_priv *priv = netdev_priv(dev);
125022ad3838SGiuseppe Cavallaro 	int ret = 0;
125122ad3838SGiuseppe Cavallaro 
125222ad3838SGiuseppe Cavallaro 	switch (tuna->id) {
125322ad3838SGiuseppe Cavallaro 	case ETHTOOL_RX_COPYBREAK:
125422ad3838SGiuseppe Cavallaro 		priv->rx_copybreak = *(u32 *)data;
125522ad3838SGiuseppe Cavallaro 		break;
125622ad3838SGiuseppe Cavallaro 	default:
125722ad3838SGiuseppe Cavallaro 		ret = -EINVAL;
125822ad3838SGiuseppe Cavallaro 		break;
125922ad3838SGiuseppe Cavallaro 	}
126022ad3838SGiuseppe Cavallaro 
126122ad3838SGiuseppe Cavallaro 	return ret;
126222ad3838SGiuseppe Cavallaro }
126322ad3838SGiuseppe Cavallaro 
12649b07be4bSstephen hemminger static const struct ethtool_ops stmmac_ethtool_ops = {
1265d0ee0e62SJakub Kicinski 	.supported_coalesce_params = ETHTOOL_COALESCE_USECS |
1266d0ee0e62SJakub Kicinski 				     ETHTOOL_COALESCE_MAX_FRAMES,
12677ac6653aSJeff Kirsher 	.begin = stmmac_check_if_running,
12687ac6653aSJeff Kirsher 	.get_drvinfo = stmmac_ethtool_getdrvinfo,
12697ac6653aSJeff Kirsher 	.get_msglevel = stmmac_ethtool_getmsglevel,
12707ac6653aSJeff Kirsher 	.set_msglevel = stmmac_ethtool_setmsglevel,
12717ac6653aSJeff Kirsher 	.get_regs = stmmac_ethtool_gregs,
12727ac6653aSJeff Kirsher 	.get_regs_len = stmmac_ethtool_get_regs_len,
12737ac6653aSJeff Kirsher 	.get_link = ethtool_op_get_link,
127474371272SJose Abreu 	.nway_reset = stmmac_nway_reset,
1275aa042f60SSong, Yoong Siang 	.get_ringparam = stmmac_get_ringparam,
1276aa042f60SSong, Yoong Siang 	.set_ringparam = stmmac_set_ringparam,
12777ac6653aSJeff Kirsher 	.get_pauseparam = stmmac_get_pauseparam,
12787ac6653aSJeff Kirsher 	.set_pauseparam = stmmac_set_pauseparam,
1279091810dbSJose Abreu 	.self_test = stmmac_selftest_run,
12807ac6653aSJeff Kirsher 	.get_ethtool_stats = stmmac_get_ethtool_stats,
12817ac6653aSJeff Kirsher 	.get_strings = stmmac_get_strings,
12827ac6653aSJeff Kirsher 	.get_wol = stmmac_get_wol,
12837ac6653aSJeff Kirsher 	.set_wol = stmmac_set_wol,
1284d765955dSGiuseppe CAVALLARO 	.get_eee = stmmac_ethtool_op_get_eee,
1285d765955dSGiuseppe CAVALLARO 	.set_eee = stmmac_ethtool_op_set_eee,
12867ac6653aSJeff Kirsher 	.get_sset_count	= stmmac_get_sset_count,
128776067459SJose Abreu 	.get_rxnfc = stmmac_get_rxnfc,
128876067459SJose Abreu 	.get_rxfh_key_size = stmmac_get_rxfh_key_size,
128976067459SJose Abreu 	.get_rxfh_indir_size = stmmac_get_rxfh_indir_size,
129076067459SJose Abreu 	.get_rxfh = stmmac_get_rxfh,
129176067459SJose Abreu 	.set_rxfh = stmmac_set_rxfh,
1292891434b1SRayagond Kokatanur 	.get_ts_info = stmmac_get_ts_info,
129348f44da4SGiuseppe CAVALLARO 	.get_coalesce = stmmac_get_coalesce,
129448f44da4SGiuseppe CAVALLARO 	.set_coalesce = stmmac_set_coalesce,
1295db2f2842SOng Boon Leong 	.get_per_queue_coalesce = stmmac_get_per_queue_coalesce,
1296db2f2842SOng Boon Leong 	.set_per_queue_coalesce = stmmac_set_per_queue_coalesce,
12970366f7e0SOng Boon Leong 	.get_channels = stmmac_get_channels,
12980366f7e0SOng Boon Leong 	.set_channels = stmmac_set_channels,
129922ad3838SGiuseppe Cavallaro 	.get_tunable = stmmac_get_tunable,
130022ad3838SGiuseppe Cavallaro 	.set_tunable = stmmac_set_tunable,
13011685e785SPhilippe Reynes 	.get_link_ksettings = stmmac_ethtool_get_link_ksettings,
13021685e785SPhilippe Reynes 	.set_link_ksettings = stmmac_ethtool_set_link_ksettings,
13037ac6653aSJeff Kirsher };
13047ac6653aSJeff Kirsher 
stmmac_set_ethtool_ops(struct net_device * netdev)13057ac6653aSJeff Kirsher void stmmac_set_ethtool_ops(struct net_device *netdev)
13067ac6653aSJeff Kirsher {
13077ad24ea4SWilfried Klaebe 	netdev->ethtool_ops = &stmmac_ethtool_ops;
13087ac6653aSJeff Kirsher }
1309