1e5b845dcSCatherine Sullivan // SPDX-License-Identifier: (GPL-2.0 OR MIT)
2e5b845dcSCatherine Sullivan /* Google virtual Ethernet (gve) driver
3e5b845dcSCatherine Sullivan  *
41f6228e4SBailey Forrest  * Copyright (C) 2015-2021 Google, Inc.
5e5b845dcSCatherine Sullivan  */
6e5b845dcSCatherine Sullivan 
7cc69837fSJakub Kicinski #include <linux/ethtool.h>
8e5b845dcSCatherine Sullivan #include <linux/rtnetlink.h>
9e5b845dcSCatherine Sullivan #include "gve.h"
1024aeb56fSKuo Zhao #include "gve_adminq.h"
116081ac20STao Liu #include "gve_dqo.h"
12e5b845dcSCatherine Sullivan 
gve_get_drvinfo(struct net_device * netdev,struct ethtool_drvinfo * info)13e5b845dcSCatherine Sullivan static void gve_get_drvinfo(struct net_device *netdev,
14e5b845dcSCatherine Sullivan 			    struct ethtool_drvinfo *info)
15e5b845dcSCatherine Sullivan {
16e5b845dcSCatherine Sullivan 	struct gve_priv *priv = netdev_priv(netdev);
17e5b845dcSCatherine Sullivan 
18*9d0aba98SJunfeng Guo 	strscpy(info->driver, gve_driver_name, sizeof(info->driver));
19c32773c9SDaode Huang 	strscpy(info->version, gve_version_str, sizeof(info->version));
20c32773c9SDaode Huang 	strscpy(info->bus_info, pci_name(priv->pdev), sizeof(info->bus_info));
21e5b845dcSCatherine Sullivan }
22e5b845dcSCatherine Sullivan 
gve_set_msglevel(struct net_device * netdev,u32 value)23e5b845dcSCatherine Sullivan static void gve_set_msglevel(struct net_device *netdev, u32 value)
24e5b845dcSCatherine Sullivan {
25e5b845dcSCatherine Sullivan 	struct gve_priv *priv = netdev_priv(netdev);
26e5b845dcSCatherine Sullivan 
27e5b845dcSCatherine Sullivan 	priv->msg_enable = value;
28e5b845dcSCatherine Sullivan }
29e5b845dcSCatherine Sullivan 
gve_get_msglevel(struct net_device * netdev)30e5b845dcSCatherine Sullivan static u32 gve_get_msglevel(struct net_device *netdev)
31e5b845dcSCatherine Sullivan {
32e5b845dcSCatherine Sullivan 	struct gve_priv *priv = netdev_priv(netdev);
33e5b845dcSCatherine Sullivan 
34e5b845dcSCatherine Sullivan 	return priv->msg_enable;
35e5b845dcSCatherine Sullivan }
36e5b845dcSCatherine Sullivan 
3775eaae15SPraveen Kaligineedi /* For the following stats column string names, make sure the order
3875eaae15SPraveen Kaligineedi  * matches how it is filled in the code. For xdp_aborted, xdp_drop,
3975eaae15SPraveen Kaligineedi  * xdp_pass, xdp_tx, xdp_redirect, make sure it also matches the order
4075eaae15SPraveen Kaligineedi  * as declared in enum xdp_action inside file uapi/linux/bpf.h .
4175eaae15SPraveen Kaligineedi  */
42e5b845dcSCatherine Sullivan static const char gve_gstrings_main_stats[][ETH_GSTRING_LEN] = {
43e5b845dcSCatherine Sullivan 	"rx_packets", "tx_packets", "rx_bytes", "tx_bytes",
44e5b845dcSCatherine Sullivan 	"rx_dropped", "tx_dropped", "tx_timeouts",
45433e274bSKuo Zhao 	"rx_skb_alloc_fail", "rx_buf_alloc_fail", "rx_desc_err_dropped_pkt",
46433e274bSKuo Zhao 	"interface_up_cnt", "interface_down_cnt", "reset_cnt",
4724aeb56fSKuo Zhao 	"page_alloc_fail", "dma_mapping_error", "stats_report_trigger_cnt",
48433e274bSKuo Zhao };
49433e274bSKuo Zhao 
50433e274bSKuo Zhao static const char gve_gstrings_rx_stats[][ETH_GSTRING_LEN] = {
512c919835SJordan Kim 	"rx_posted_desc[%u]", "rx_completed_desc[%u]", "rx_consumed_desc[%u]", "rx_bytes[%u]",
5237149e93SDavid Awogbemila 	"rx_cont_packet_cnt[%u]", "rx_frag_flip_cnt[%u]", "rx_frag_copy_cnt[%u]",
5382fd151dSShailend Chand 	"rx_frag_alloc_cnt[%u]",
54433e274bSKuo Zhao 	"rx_dropped_pkt[%u]", "rx_copybreak_pkt[%u]", "rx_copied_pkt[%u]",
552f523dc3SDavid Awogbemila 	"rx_queue_drop_cnt[%u]", "rx_no_buffers_posted[%u]",
562f523dc3SDavid Awogbemila 	"rx_drops_packet_over_mru[%u]", "rx_drops_invalid_checksum[%u]",
5775eaae15SPraveen Kaligineedi 	"rx_xdp_aborted[%u]", "rx_xdp_drop[%u]", "rx_xdp_pass[%u]",
5875eaae15SPraveen Kaligineedi 	"rx_xdp_tx[%u]", "rx_xdp_redirect[%u]",
5939a7f4aaSPraveen Kaligineedi 	"rx_xdp_tx_errors[%u]", "rx_xdp_redirect_errors[%u]", "rx_xdp_alloc_fails[%u]",
60433e274bSKuo Zhao };
61433e274bSKuo Zhao 
62433e274bSKuo Zhao static const char gve_gstrings_tx_stats[][ETH_GSTRING_LEN] = {
632c919835SJordan Kim 	"tx_posted_desc[%u]", "tx_completed_desc[%u]", "tx_consumed_desc[%u]", "tx_bytes[%u]",
64433e274bSKuo Zhao 	"tx_wake[%u]", "tx_stop[%u]", "tx_event_counter[%u]",
65fd8e4032SPraveen Kaligineedi 	"tx_dma_mapping_error[%u]", "tx_xsk_wakeup[%u]",
66fd8e4032SPraveen Kaligineedi 	"tx_xsk_done[%u]", "tx_xsk_sent[%u]", "tx_xdp_xmit[%u]", "tx_xdp_xmit_errors[%u]"
67433e274bSKuo Zhao };
68433e274bSKuo Zhao 
69433e274bSKuo Zhao static const char gve_gstrings_adminq_stats[][ETH_GSTRING_LEN] = {
70433e274bSKuo Zhao 	"adminq_prod_cnt", "adminq_cmd_fail", "adminq_timeouts",
71433e274bSKuo Zhao 	"adminq_describe_device_cnt", "adminq_cfg_device_resources_cnt",
72433e274bSKuo Zhao 	"adminq_register_page_list_cnt", "adminq_unregister_page_list_cnt",
73433e274bSKuo Zhao 	"adminq_create_tx_queue_cnt", "adminq_create_rx_queue_cnt",
74433e274bSKuo Zhao 	"adminq_destroy_tx_queue_cnt", "adminq_destroy_rx_queue_cnt",
75433e274bSKuo Zhao 	"adminq_dcfg_device_resources_cnt", "adminq_set_driver_parameter_cnt",
767e074d5aSDavid Awogbemila 	"adminq_report_stats_cnt", "adminq_report_link_speed_cnt"
7724aeb56fSKuo Zhao };
7824aeb56fSKuo Zhao 
7924aeb56fSKuo Zhao static const char gve_gstrings_priv_flags[][ETH_GSTRING_LEN] = {
8024aeb56fSKuo Zhao 	"report-stats",
81e5b845dcSCatherine Sullivan };
82e5b845dcSCatherine Sullivan 
83e5b845dcSCatherine Sullivan #define GVE_MAIN_STATS_LEN  ARRAY_SIZE(gve_gstrings_main_stats)
84433e274bSKuo Zhao #define GVE_ADMINQ_STATS_LEN  ARRAY_SIZE(gve_gstrings_adminq_stats)
85433e274bSKuo Zhao #define NUM_GVE_TX_CNTS	ARRAY_SIZE(gve_gstrings_tx_stats)
86433e274bSKuo Zhao #define NUM_GVE_RX_CNTS	ARRAY_SIZE(gve_gstrings_rx_stats)
8724aeb56fSKuo Zhao #define GVE_PRIV_FLAGS_STR_LEN ARRAY_SIZE(gve_gstrings_priv_flags)
88e5b845dcSCatherine Sullivan 
gve_get_strings(struct net_device * netdev,u32 stringset,u8 * data)89e5b845dcSCatherine Sullivan static void gve_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
90e5b845dcSCatherine Sullivan {
91e5b845dcSCatherine Sullivan 	struct gve_priv *priv = netdev_priv(netdev);
92e5b845dcSCatherine Sullivan 	char *s = (char *)data;
932e80aeaeSPraveen Kaligineedi 	int num_tx_queues;
94433e274bSKuo Zhao 	int i, j;
95e5b845dcSCatherine Sullivan 
962e80aeaeSPraveen Kaligineedi 	num_tx_queues = gve_num_tx_queues(priv);
9724aeb56fSKuo Zhao 	switch (stringset) {
9824aeb56fSKuo Zhao 	case ETH_SS_STATS:
99e5b845dcSCatherine Sullivan 		memcpy(s, *gve_gstrings_main_stats,
100e5b845dcSCatherine Sullivan 		       sizeof(gve_gstrings_main_stats));
101e5b845dcSCatherine Sullivan 		s += sizeof(gve_gstrings_main_stats);
10224aeb56fSKuo Zhao 
103e5b845dcSCatherine Sullivan 		for (i = 0; i < priv->rx_cfg.num_queues; i++) {
104433e274bSKuo Zhao 			for (j = 0; j < NUM_GVE_RX_CNTS; j++) {
10524aeb56fSKuo Zhao 				snprintf(s, ETH_GSTRING_LEN,
10624aeb56fSKuo Zhao 					 gve_gstrings_rx_stats[j], i);
107e5b845dcSCatherine Sullivan 				s += ETH_GSTRING_LEN;
108433e274bSKuo Zhao 			}
109e5b845dcSCatherine Sullivan 		}
11024aeb56fSKuo Zhao 
1112e80aeaeSPraveen Kaligineedi 		for (i = 0; i < num_tx_queues; i++) {
112433e274bSKuo Zhao 			for (j = 0; j < NUM_GVE_TX_CNTS; j++) {
11324aeb56fSKuo Zhao 				snprintf(s, ETH_GSTRING_LEN,
11424aeb56fSKuo Zhao 					 gve_gstrings_tx_stats[j], i);
115e5b845dcSCatherine Sullivan 				s += ETH_GSTRING_LEN;
116e5b845dcSCatherine Sullivan 			}
117e5b845dcSCatherine Sullivan 		}
118e5b845dcSCatherine Sullivan 
119433e274bSKuo Zhao 		memcpy(s, *gve_gstrings_adminq_stats,
120433e274bSKuo Zhao 		       sizeof(gve_gstrings_adminq_stats));
121433e274bSKuo Zhao 		s += sizeof(gve_gstrings_adminq_stats);
12224aeb56fSKuo Zhao 		break;
12324aeb56fSKuo Zhao 
12424aeb56fSKuo Zhao 	case ETH_SS_PRIV_FLAGS:
12524aeb56fSKuo Zhao 		memcpy(s, *gve_gstrings_priv_flags,
12624aeb56fSKuo Zhao 		       sizeof(gve_gstrings_priv_flags));
12724aeb56fSKuo Zhao 		s += sizeof(gve_gstrings_priv_flags);
12824aeb56fSKuo Zhao 		break;
12924aeb56fSKuo Zhao 
13024aeb56fSKuo Zhao 	default:
13124aeb56fSKuo Zhao 		break;
13224aeb56fSKuo Zhao 	}
133433e274bSKuo Zhao }
134433e274bSKuo Zhao 
gve_get_sset_count(struct net_device * netdev,int sset)135e5b845dcSCatherine Sullivan static int gve_get_sset_count(struct net_device *netdev, int sset)
136e5b845dcSCatherine Sullivan {
137e5b845dcSCatherine Sullivan 	struct gve_priv *priv = netdev_priv(netdev);
1382e80aeaeSPraveen Kaligineedi 	int num_tx_queues;
139e5b845dcSCatherine Sullivan 
1402e80aeaeSPraveen Kaligineedi 	num_tx_queues = gve_num_tx_queues(priv);
141e5b845dcSCatherine Sullivan 	switch (sset) {
142e5b845dcSCatherine Sullivan 	case ETH_SS_STATS:
143433e274bSKuo Zhao 		return GVE_MAIN_STATS_LEN + GVE_ADMINQ_STATS_LEN +
144e5b845dcSCatherine Sullivan 		       (priv->rx_cfg.num_queues * NUM_GVE_RX_CNTS) +
1452e80aeaeSPraveen Kaligineedi 		       (num_tx_queues * NUM_GVE_TX_CNTS);
14624aeb56fSKuo Zhao 	case ETH_SS_PRIV_FLAGS:
14724aeb56fSKuo Zhao 		return GVE_PRIV_FLAGS_STR_LEN;
148e5b845dcSCatherine Sullivan 	default:
149e5b845dcSCatherine Sullivan 		return -EOPNOTSUPP;
150e5b845dcSCatherine Sullivan 	}
151e5b845dcSCatherine Sullivan }
152e5b845dcSCatherine Sullivan 
153e5b845dcSCatherine Sullivan static void
gve_get_ethtool_stats(struct net_device * netdev,struct ethtool_stats * stats,u64 * data)154e5b845dcSCatherine Sullivan gve_get_ethtool_stats(struct net_device *netdev,
155e5b845dcSCatherine Sullivan 		      struct ethtool_stats *stats, u64 *data)
156e5b845dcSCatherine Sullivan {
1572c919835SJordan Kim 	u64 tmp_rx_pkts, tmp_rx_bytes, tmp_rx_skb_alloc_fail,
1582c919835SJordan Kim 		tmp_rx_buf_alloc_fail, tmp_rx_desc_err_dropped_pkt,
1592c919835SJordan Kim 		tmp_tx_pkts, tmp_tx_bytes;
160433e274bSKuo Zhao 	u64 rx_buf_alloc_fail, rx_desc_err_dropped_pkt, rx_pkts,
1612c919835SJordan Kim 		rx_skb_alloc_fail, rx_bytes, tx_pkts, tx_bytes, tx_dropped;
1622f523dc3SDavid Awogbemila 	int stats_idx, base_stats_idx, max_stats_idx;
1632f523dc3SDavid Awogbemila 	struct stats *report_stats;
1642f523dc3SDavid Awogbemila 	int *rx_qid_to_stats_idx;
1652f523dc3SDavid Awogbemila 	int *tx_qid_to_stats_idx;
166433e274bSKuo Zhao 	struct gve_priv *priv;
1672f523dc3SDavid Awogbemila 	bool skip_nic_stats;
168e5b845dcSCatherine Sullivan 	unsigned int start;
1692e80aeaeSPraveen Kaligineedi 	int num_tx_queues;
170e5b845dcSCatherine Sullivan 	int ring;
1712f523dc3SDavid Awogbemila 	int i, j;
172e5b845dcSCatherine Sullivan 
173e5b845dcSCatherine Sullivan 	ASSERT_RTNL();
174e5b845dcSCatherine Sullivan 
175433e274bSKuo Zhao 	priv = netdev_priv(netdev);
1762e80aeaeSPraveen Kaligineedi 	num_tx_queues = gve_num_tx_queues(priv);
1772f523dc3SDavid Awogbemila 	report_stats = priv->stats_report->stats;
1782f523dc3SDavid Awogbemila 	rx_qid_to_stats_idx = kmalloc_array(priv->rx_cfg.num_queues,
1792f523dc3SDavid Awogbemila 					    sizeof(int), GFP_KERNEL);
1802f523dc3SDavid Awogbemila 	if (!rx_qid_to_stats_idx)
1812f523dc3SDavid Awogbemila 		return;
1822e80aeaeSPraveen Kaligineedi 	tx_qid_to_stats_idx = kmalloc_array(num_tx_queues,
1832f523dc3SDavid Awogbemila 					    sizeof(int), GFP_KERNEL);
1842f523dc3SDavid Awogbemila 	if (!tx_qid_to_stats_idx) {
1852f523dc3SDavid Awogbemila 		kfree(rx_qid_to_stats_idx);
1862f523dc3SDavid Awogbemila 		return;
1872f523dc3SDavid Awogbemila 	}
188433e274bSKuo Zhao 	for (rx_pkts = 0, rx_bytes = 0, rx_skb_alloc_fail = 0,
189433e274bSKuo Zhao 	     rx_buf_alloc_fail = 0, rx_desc_err_dropped_pkt = 0, ring = 0;
190e5b845dcSCatherine Sullivan 	     ring < priv->rx_cfg.num_queues; ring++) {
191e5b845dcSCatherine Sullivan 		if (priv->rx) {
192e5b845dcSCatherine Sullivan 			do {
193433e274bSKuo Zhao 				struct gve_rx_ring *rx = &priv->rx[ring];
194433e274bSKuo Zhao 
1953c13ce74SCatherine Sullivan 				start =
196068c38adSThomas Gleixner 				  u64_stats_fetch_begin(&priv->rx[ring].statss);
197433e274bSKuo Zhao 				tmp_rx_pkts = rx->rpackets;
198433e274bSKuo Zhao 				tmp_rx_bytes = rx->rbytes;
199433e274bSKuo Zhao 				tmp_rx_skb_alloc_fail = rx->rx_skb_alloc_fail;
200433e274bSKuo Zhao 				tmp_rx_buf_alloc_fail = rx->rx_buf_alloc_fail;
201433e274bSKuo Zhao 				tmp_rx_desc_err_dropped_pkt =
202433e274bSKuo Zhao 					rx->rx_desc_err_dropped_pkt;
203068c38adSThomas Gleixner 			} while (u64_stats_fetch_retry(&priv->rx[ring].statss,
204e5b845dcSCatherine Sullivan 						       start));
205433e274bSKuo Zhao 			rx_pkts += tmp_rx_pkts;
206433e274bSKuo Zhao 			rx_bytes += tmp_rx_bytes;
207433e274bSKuo Zhao 			rx_skb_alloc_fail += tmp_rx_skb_alloc_fail;
208433e274bSKuo Zhao 			rx_buf_alloc_fail += tmp_rx_buf_alloc_fail;
209433e274bSKuo Zhao 			rx_desc_err_dropped_pkt += tmp_rx_desc_err_dropped_pkt;
210e5b845dcSCatherine Sullivan 		}
211e5b845dcSCatherine Sullivan 	}
2122c919835SJordan Kim 	for (tx_pkts = 0, tx_bytes = 0, tx_dropped = 0, ring = 0;
2132e80aeaeSPraveen Kaligineedi 	     ring < num_tx_queues; ring++) {
214e5b845dcSCatherine Sullivan 		if (priv->tx) {
215e5b845dcSCatherine Sullivan 			do {
2163c13ce74SCatherine Sullivan 				start =
217068c38adSThomas Gleixner 				  u64_stats_fetch_begin(&priv->tx[ring].statss);
218433e274bSKuo Zhao 				tmp_tx_pkts = priv->tx[ring].pkt_done;
219433e274bSKuo Zhao 				tmp_tx_bytes = priv->tx[ring].bytes_done;
220068c38adSThomas Gleixner 			} while (u64_stats_fetch_retry(&priv->tx[ring].statss,
221e5b845dcSCatherine Sullivan 						       start));
222433e274bSKuo Zhao 			tx_pkts += tmp_tx_pkts;
223433e274bSKuo Zhao 			tx_bytes += tmp_tx_bytes;
2242c919835SJordan Kim 			tx_dropped += priv->tx[ring].dropped_pkt;
225e5b845dcSCatherine Sullivan 		}
226e5b845dcSCatherine Sullivan 	}
227e5b845dcSCatherine Sullivan 
228e5b845dcSCatherine Sullivan 	i = 0;
229e5b845dcSCatherine Sullivan 	data[i++] = rx_pkts;
230e5b845dcSCatherine Sullivan 	data[i++] = tx_pkts;
231e5b845dcSCatherine Sullivan 	data[i++] = rx_bytes;
232e5b845dcSCatherine Sullivan 	data[i++] = tx_bytes;
233433e274bSKuo Zhao 	/* total rx dropped packets */
234433e274bSKuo Zhao 	data[i++] = rx_skb_alloc_fail + rx_buf_alloc_fail +
235433e274bSKuo Zhao 		    rx_desc_err_dropped_pkt;
2362c919835SJordan Kim 	data[i++] = tx_dropped;
237e5b845dcSCatherine Sullivan 	data[i++] = priv->tx_timeo_cnt;
238433e274bSKuo Zhao 	data[i++] = rx_skb_alloc_fail;
239433e274bSKuo Zhao 	data[i++] = rx_buf_alloc_fail;
240433e274bSKuo Zhao 	data[i++] = rx_desc_err_dropped_pkt;
241433e274bSKuo Zhao 	data[i++] = priv->interface_up_cnt;
242433e274bSKuo Zhao 	data[i++] = priv->interface_down_cnt;
243433e274bSKuo Zhao 	data[i++] = priv->reset_cnt;
244433e274bSKuo Zhao 	data[i++] = priv->page_alloc_fail;
245433e274bSKuo Zhao 	data[i++] = priv->dma_mapping_error;
24624aeb56fSKuo Zhao 	data[i++] = priv->stats_report_trigger_cnt;
247e5b845dcSCatherine Sullivan 	i = GVE_MAIN_STATS_LEN;
248e5b845dcSCatherine Sullivan 
2492f523dc3SDavid Awogbemila 	/* For rx cross-reporting stats, start from nic rx stats in report */
2502e80aeaeSPraveen Kaligineedi 	base_stats_idx = GVE_TX_STATS_REPORT_NUM * num_tx_queues +
2512f523dc3SDavid Awogbemila 		GVE_RX_STATS_REPORT_NUM * priv->rx_cfg.num_queues;
2522f523dc3SDavid Awogbemila 	max_stats_idx = NIC_RX_STATS_REPORT_NUM * priv->rx_cfg.num_queues +
2532f523dc3SDavid Awogbemila 		base_stats_idx;
2542f523dc3SDavid Awogbemila 	/* Preprocess the stats report for rx, map queue id to start index */
2552f523dc3SDavid Awogbemila 	skip_nic_stats = false;
2562f523dc3SDavid Awogbemila 	for (stats_idx = base_stats_idx; stats_idx < max_stats_idx;
2572f523dc3SDavid Awogbemila 		stats_idx += NIC_RX_STATS_REPORT_NUM) {
2582f523dc3SDavid Awogbemila 		u32 stat_name = be32_to_cpu(report_stats[stats_idx].stat_name);
2592f523dc3SDavid Awogbemila 		u32 queue_id = be32_to_cpu(report_stats[stats_idx].queue_id);
2602f523dc3SDavid Awogbemila 
2612f523dc3SDavid Awogbemila 		if (stat_name == 0) {
2622f523dc3SDavid Awogbemila 			/* no stats written by NIC yet */
2632f523dc3SDavid Awogbemila 			skip_nic_stats = true;
2642f523dc3SDavid Awogbemila 			break;
2652f523dc3SDavid Awogbemila 		}
2662f523dc3SDavid Awogbemila 		rx_qid_to_stats_idx[queue_id] = stats_idx;
2672f523dc3SDavid Awogbemila 	}
268e5b845dcSCatherine Sullivan 	/* walk RX rings */
269e5b845dcSCatherine Sullivan 	if (priv->rx) {
270e5b845dcSCatherine Sullivan 		for (ring = 0; ring < priv->rx_cfg.num_queues; ring++) {
271e5b845dcSCatherine Sullivan 			struct gve_rx_ring *rx = &priv->rx[ring];
272e5b845dcSCatherine Sullivan 
273438b43bdSCatherine Sullivan 			data[i++] = rx->fill_cnt;
274433e274bSKuo Zhao 			data[i++] = rx->cnt;
2752c919835SJordan Kim 			data[i++] = rx->fill_cnt - rx->cnt;
276433e274bSKuo Zhao 			do {
277433e274bSKuo Zhao 				start =
278068c38adSThomas Gleixner 				  u64_stats_fetch_begin(&priv->rx[ring].statss);
279433e274bSKuo Zhao 				tmp_rx_bytes = rx->rbytes;
280433e274bSKuo Zhao 				tmp_rx_skb_alloc_fail = rx->rx_skb_alloc_fail;
281433e274bSKuo Zhao 				tmp_rx_buf_alloc_fail = rx->rx_buf_alloc_fail;
282433e274bSKuo Zhao 				tmp_rx_desc_err_dropped_pkt =
283433e274bSKuo Zhao 					rx->rx_desc_err_dropped_pkt;
284068c38adSThomas Gleixner 			} while (u64_stats_fetch_retry(&priv->rx[ring].statss,
285433e274bSKuo Zhao 						       start));
286433e274bSKuo Zhao 			data[i++] = tmp_rx_bytes;
28737149e93SDavid Awogbemila 			data[i++] = rx->rx_cont_packet_cnt;
28837149e93SDavid Awogbemila 			data[i++] = rx->rx_frag_flip_cnt;
28937149e93SDavid Awogbemila 			data[i++] = rx->rx_frag_copy_cnt;
29082fd151dSShailend Chand 			data[i++] = rx->rx_frag_alloc_cnt;
291433e274bSKuo Zhao 			/* rx dropped packets */
292433e274bSKuo Zhao 			data[i++] = tmp_rx_skb_alloc_fail +
293433e274bSKuo Zhao 				tmp_rx_buf_alloc_fail +
294433e274bSKuo Zhao 				tmp_rx_desc_err_dropped_pkt;
295433e274bSKuo Zhao 			data[i++] = rx->rx_copybreak_pkt;
296433e274bSKuo Zhao 			data[i++] = rx->rx_copied_pkt;
2972f523dc3SDavid Awogbemila 			/* stats from NIC */
2982f523dc3SDavid Awogbemila 			if (skip_nic_stats) {
2992f523dc3SDavid Awogbemila 				/* skip NIC rx stats */
3002f523dc3SDavid Awogbemila 				i += NIC_RX_STATS_REPORT_NUM;
30175eaae15SPraveen Kaligineedi 			} else {
30275eaae15SPraveen Kaligineedi 				stats_idx = rx_qid_to_stats_idx[ring];
3032f523dc3SDavid Awogbemila 				for (j = 0; j < NIC_RX_STATS_REPORT_NUM; j++) {
3042f523dc3SDavid Awogbemila 					u64 value =
30575eaae15SPraveen Kaligineedi 						be64_to_cpu(report_stats[stats_idx + j].value);
3062f523dc3SDavid Awogbemila 
3072f523dc3SDavid Awogbemila 					data[i++] = value;
3082f523dc3SDavid Awogbemila 				}
309e5b845dcSCatherine Sullivan 			}
31075eaae15SPraveen Kaligineedi 			/* XDP rx counters */
31175eaae15SPraveen Kaligineedi 			do {
31275eaae15SPraveen Kaligineedi 				start =	u64_stats_fetch_begin(&priv->rx[ring].statss);
31375eaae15SPraveen Kaligineedi 				for (j = 0; j < GVE_XDP_ACTIONS; j++)
31475eaae15SPraveen Kaligineedi 					data[i + j] = rx->xdp_actions[j];
31575eaae15SPraveen Kaligineedi 				data[i + j++] = rx->xdp_tx_errors;
31675eaae15SPraveen Kaligineedi 				data[i + j++] = rx->xdp_redirect_errors;
31739a7f4aaSPraveen Kaligineedi 				data[i + j++] = rx->xdp_alloc_fails;
31875eaae15SPraveen Kaligineedi 			} while (u64_stats_fetch_retry(&priv->rx[ring].statss,
31975eaae15SPraveen Kaligineedi 						       start));
32039a7f4aaSPraveen Kaligineedi 			i += GVE_XDP_ACTIONS + 3; /* XDP rx counters */
32175eaae15SPraveen Kaligineedi 		}
322e5b845dcSCatherine Sullivan 	} else {
323e5b845dcSCatherine Sullivan 		i += priv->rx_cfg.num_queues * NUM_GVE_RX_CNTS;
324e5b845dcSCatherine Sullivan 	}
3252f523dc3SDavid Awogbemila 
3262f523dc3SDavid Awogbemila 	/* For tx cross-reporting stats, start from nic tx stats in report */
3272f523dc3SDavid Awogbemila 	base_stats_idx = max_stats_idx;
3282e80aeaeSPraveen Kaligineedi 	max_stats_idx = NIC_TX_STATS_REPORT_NUM * num_tx_queues +
3292f523dc3SDavid Awogbemila 		max_stats_idx;
3302f523dc3SDavid Awogbemila 	/* Preprocess the stats report for tx, map queue id to start index */
3312f523dc3SDavid Awogbemila 	skip_nic_stats = false;
3322f523dc3SDavid Awogbemila 	for (stats_idx = base_stats_idx; stats_idx < max_stats_idx;
3332f523dc3SDavid Awogbemila 		stats_idx += NIC_TX_STATS_REPORT_NUM) {
3342f523dc3SDavid Awogbemila 		u32 stat_name = be32_to_cpu(report_stats[stats_idx].stat_name);
3352f523dc3SDavid Awogbemila 		u32 queue_id = be32_to_cpu(report_stats[stats_idx].queue_id);
3362f523dc3SDavid Awogbemila 
3372f523dc3SDavid Awogbemila 		if (stat_name == 0) {
3382f523dc3SDavid Awogbemila 			/* no stats written by NIC yet */
3392f523dc3SDavid Awogbemila 			skip_nic_stats = true;
3402f523dc3SDavid Awogbemila 			break;
3412f523dc3SDavid Awogbemila 		}
3422f523dc3SDavid Awogbemila 		tx_qid_to_stats_idx[queue_id] = stats_idx;
3432f523dc3SDavid Awogbemila 	}
344e5b845dcSCatherine Sullivan 	/* walk TX rings */
345e5b845dcSCatherine Sullivan 	if (priv->tx) {
3462e80aeaeSPraveen Kaligineedi 		for (ring = 0; ring < num_tx_queues; ring++) {
347e5b845dcSCatherine Sullivan 			struct gve_tx_ring *tx = &priv->tx[ring];
348e5b845dcSCatherine Sullivan 
3495e8c5adfSBailey Forrest 			if (gve_is_gqi(priv)) {
350e5b845dcSCatherine Sullivan 				data[i++] = tx->req;
351e5b845dcSCatherine Sullivan 				data[i++] = tx->done;
3522c919835SJordan Kim 				data[i++] = tx->req - tx->done;
3535e8c5adfSBailey Forrest 			} else {
3545e8c5adfSBailey Forrest 				/* DQO doesn't currently support
3555e8c5adfSBailey Forrest 				 * posted/completed descriptor counts;
3565e8c5adfSBailey Forrest 				 */
3575e8c5adfSBailey Forrest 				data[i++] = 0;
3585e8c5adfSBailey Forrest 				data[i++] = 0;
3592c919835SJordan Kim 				data[i++] = tx->dqo_tx.tail - tx->dqo_tx.head;
3605e8c5adfSBailey Forrest 			}
361433e274bSKuo Zhao 			do {
362433e274bSKuo Zhao 				start =
363068c38adSThomas Gleixner 				  u64_stats_fetch_begin(&priv->tx[ring].statss);
364433e274bSKuo Zhao 				tmp_tx_bytes = tx->bytes_done;
365068c38adSThomas Gleixner 			} while (u64_stats_fetch_retry(&priv->tx[ring].statss,
366433e274bSKuo Zhao 						       start));
367433e274bSKuo Zhao 			data[i++] = tmp_tx_bytes;
368e5b845dcSCatherine Sullivan 			data[i++] = tx->wake_queue;
369e5b845dcSCatherine Sullivan 			data[i++] = tx->stop_queue;
37061d72c7eSTao Liu 			data[i++] = gve_tx_load_event_counter(priv, tx);
3716f007c64SCatherine Sullivan 			data[i++] = tx->dma_mapping_error;
3722f523dc3SDavid Awogbemila 			/* stats from NIC */
3732f523dc3SDavid Awogbemila 			if (skip_nic_stats) {
3742f523dc3SDavid Awogbemila 				/* skip NIC tx stats */
3752f523dc3SDavid Awogbemila 				i += NIC_TX_STATS_REPORT_NUM;
37639a7f4aaSPraveen Kaligineedi 			} else {
37739a7f4aaSPraveen Kaligineedi 				stats_idx = tx_qid_to_stats_idx[ring];
3782f523dc3SDavid Awogbemila 				for (j = 0; j < NIC_TX_STATS_REPORT_NUM; j++) {
3792f523dc3SDavid Awogbemila 					u64 value =
38039a7f4aaSPraveen Kaligineedi 						be64_to_cpu(report_stats[stats_idx + j].value);
3812f523dc3SDavid Awogbemila 					data[i++] = value;
3822f523dc3SDavid Awogbemila 				}
383e5b845dcSCatherine Sullivan 			}
384fd8e4032SPraveen Kaligineedi 			/* XDP xsk counters */
385fd8e4032SPraveen Kaligineedi 			data[i++] = tx->xdp_xsk_wakeup;
386fd8e4032SPraveen Kaligineedi 			data[i++] = tx->xdp_xsk_done;
38739a7f4aaSPraveen Kaligineedi 			do {
38839a7f4aaSPraveen Kaligineedi 				start = u64_stats_fetch_begin(&priv->tx[ring].statss);
389fd8e4032SPraveen Kaligineedi 				data[i] = tx->xdp_xsk_sent;
390fd8e4032SPraveen Kaligineedi 				data[i + 1] = tx->xdp_xmit;
391fd8e4032SPraveen Kaligineedi 				data[i + 2] = tx->xdp_xmit_errors;
39239a7f4aaSPraveen Kaligineedi 			} while (u64_stats_fetch_retry(&priv->tx[ring].statss,
39339a7f4aaSPraveen Kaligineedi 						       start));
394fd8e4032SPraveen Kaligineedi 			i += 3; /* XDP tx counters */
39539a7f4aaSPraveen Kaligineedi 		}
396e5b845dcSCatherine Sullivan 	} else {
3972e80aeaeSPraveen Kaligineedi 		i += num_tx_queues * NUM_GVE_TX_CNTS;
398e5b845dcSCatherine Sullivan 	}
3992f523dc3SDavid Awogbemila 
4002f523dc3SDavid Awogbemila 	kfree(rx_qid_to_stats_idx);
4012f523dc3SDavid Awogbemila 	kfree(tx_qid_to_stats_idx);
402433e274bSKuo Zhao 	/* AQ Stats */
403433e274bSKuo Zhao 	data[i++] = priv->adminq_prod_cnt;
404433e274bSKuo Zhao 	data[i++] = priv->adminq_cmd_fail;
405433e274bSKuo Zhao 	data[i++] = priv->adminq_timeouts;
406433e274bSKuo Zhao 	data[i++] = priv->adminq_describe_device_cnt;
407433e274bSKuo Zhao 	data[i++] = priv->adminq_cfg_device_resources_cnt;
408433e274bSKuo Zhao 	data[i++] = priv->adminq_register_page_list_cnt;
409433e274bSKuo Zhao 	data[i++] = priv->adminq_unregister_page_list_cnt;
410433e274bSKuo Zhao 	data[i++] = priv->adminq_create_tx_queue_cnt;
411433e274bSKuo Zhao 	data[i++] = priv->adminq_create_rx_queue_cnt;
412433e274bSKuo Zhao 	data[i++] = priv->adminq_destroy_tx_queue_cnt;
413433e274bSKuo Zhao 	data[i++] = priv->adminq_destroy_rx_queue_cnt;
414433e274bSKuo Zhao 	data[i++] = priv->adminq_dcfg_device_resources_cnt;
415433e274bSKuo Zhao 	data[i++] = priv->adminq_set_driver_parameter_cnt;
41624aeb56fSKuo Zhao 	data[i++] = priv->adminq_report_stats_cnt;
4177e074d5aSDavid Awogbemila 	data[i++] = priv->adminq_report_link_speed_cnt;
418e5b845dcSCatherine Sullivan }
419e5b845dcSCatherine Sullivan 
gve_get_channels(struct net_device * netdev,struct ethtool_channels * cmd)420e5b845dcSCatherine Sullivan static void gve_get_channels(struct net_device *netdev,
421e5b845dcSCatherine Sullivan 			     struct ethtool_channels *cmd)
422e5b845dcSCatherine Sullivan {
423e5b845dcSCatherine Sullivan 	struct gve_priv *priv = netdev_priv(netdev);
424e5b845dcSCatherine Sullivan 
425e5b845dcSCatherine Sullivan 	cmd->max_rx = priv->rx_cfg.max_queues;
426e5b845dcSCatherine Sullivan 	cmd->max_tx = priv->tx_cfg.max_queues;
427e5b845dcSCatherine Sullivan 	cmd->max_other = 0;
428e5b845dcSCatherine Sullivan 	cmd->max_combined = 0;
429e5b845dcSCatherine Sullivan 	cmd->rx_count = priv->rx_cfg.num_queues;
430e5b845dcSCatherine Sullivan 	cmd->tx_count = priv->tx_cfg.num_queues;
431e5b845dcSCatherine Sullivan 	cmd->other_count = 0;
432e5b845dcSCatherine Sullivan 	cmd->combined_count = 0;
433e5b845dcSCatherine Sullivan }
434e5b845dcSCatherine Sullivan 
gve_set_channels(struct net_device * netdev,struct ethtool_channels * cmd)435e5b845dcSCatherine Sullivan static int gve_set_channels(struct net_device *netdev,
436e5b845dcSCatherine Sullivan 			    struct ethtool_channels *cmd)
437e5b845dcSCatherine Sullivan {
438e5b845dcSCatherine Sullivan 	struct gve_priv *priv = netdev_priv(netdev);
439e5b845dcSCatherine Sullivan 	struct gve_queue_config new_tx_cfg = priv->tx_cfg;
440e5b845dcSCatherine Sullivan 	struct gve_queue_config new_rx_cfg = priv->rx_cfg;
441e5b845dcSCatherine Sullivan 	struct ethtool_channels old_settings;
442e5b845dcSCatherine Sullivan 	int new_tx = cmd->tx_count;
443e5b845dcSCatherine Sullivan 	int new_rx = cmd->rx_count;
444e5b845dcSCatherine Sullivan 
445e5b845dcSCatherine Sullivan 	gve_get_channels(netdev, &old_settings);
446e5b845dcSCatherine Sullivan 
447f67435b5SDaode Huang 	/* Changing combined is not allowed */
448e5b845dcSCatherine Sullivan 	if (cmd->combined_count != old_settings.combined_count)
449e5b845dcSCatherine Sullivan 		return -EINVAL;
450e5b845dcSCatherine Sullivan 
451e5b845dcSCatherine Sullivan 	if (!new_rx || !new_tx)
452e5b845dcSCatherine Sullivan 		return -EINVAL;
453e5b845dcSCatherine Sullivan 
45475eaae15SPraveen Kaligineedi 	if (priv->num_xdp_queues &&
45575eaae15SPraveen Kaligineedi 	    (new_tx != new_rx || (2 * new_tx > priv->tx_cfg.max_queues))) {
45675eaae15SPraveen Kaligineedi 		dev_err(&priv->pdev->dev, "XDP load failed: The number of configured RX queues should be equal to the number of configured TX queues and the number of configured RX/TX queues should be less than or equal to half the maximum number of RX/TX queues");
45775eaae15SPraveen Kaligineedi 		return -EINVAL;
45875eaae15SPraveen Kaligineedi 	}
45975eaae15SPraveen Kaligineedi 
460e5b845dcSCatherine Sullivan 	if (!netif_carrier_ok(netdev)) {
461e5b845dcSCatherine Sullivan 		priv->tx_cfg.num_queues = new_tx;
462e5b845dcSCatherine Sullivan 		priv->rx_cfg.num_queues = new_rx;
463e5b845dcSCatherine Sullivan 		return 0;
464e5b845dcSCatherine Sullivan 	}
465e5b845dcSCatherine Sullivan 
466e5b845dcSCatherine Sullivan 	new_tx_cfg.num_queues = new_tx;
467e5b845dcSCatherine Sullivan 	new_rx_cfg.num_queues = new_rx;
468e5b845dcSCatherine Sullivan 
469e5b845dcSCatherine Sullivan 	return gve_adjust_queues(priv, new_rx_cfg, new_tx_cfg);
470e5b845dcSCatherine Sullivan }
471e5b845dcSCatherine Sullivan 
gve_get_ringparam(struct net_device * netdev,struct ethtool_ringparam * cmd,struct kernel_ethtool_ringparam * kernel_cmd,struct netlink_ext_ack * extack)472e5b845dcSCatherine Sullivan static void gve_get_ringparam(struct net_device *netdev,
47374624944SHao Chen 			      struct ethtool_ringparam *cmd,
47474624944SHao Chen 			      struct kernel_ethtool_ringparam *kernel_cmd,
47574624944SHao Chen 			      struct netlink_ext_ack *extack)
476e5b845dcSCatherine Sullivan {
477e5b845dcSCatherine Sullivan 	struct gve_priv *priv = netdev_priv(netdev);
478e5b845dcSCatherine Sullivan 
479e5b845dcSCatherine Sullivan 	cmd->rx_max_pending = priv->rx_desc_cnt;
480e5b845dcSCatherine Sullivan 	cmd->tx_max_pending = priv->tx_desc_cnt;
481e5b845dcSCatherine Sullivan 	cmd->rx_pending = priv->rx_desc_cnt;
482e5b845dcSCatherine Sullivan 	cmd->tx_pending = priv->tx_desc_cnt;
483e5b845dcSCatherine Sullivan }
484e5b845dcSCatherine Sullivan 
gve_user_reset(struct net_device * netdev,u32 * flags)485e5b845dcSCatherine Sullivan static int gve_user_reset(struct net_device *netdev, u32 *flags)
486e5b845dcSCatherine Sullivan {
487e5b845dcSCatherine Sullivan 	struct gve_priv *priv = netdev_priv(netdev);
488e5b845dcSCatherine Sullivan 
489e5b845dcSCatherine Sullivan 	if (*flags == ETH_RESET_ALL) {
490e5b845dcSCatherine Sullivan 		*flags = 0;
491e5b845dcSCatherine Sullivan 		return gve_reset(priv, true);
492e5b845dcSCatherine Sullivan 	}
493e5b845dcSCatherine Sullivan 
494e5b845dcSCatherine Sullivan 	return -EOPNOTSUPP;
495e5b845dcSCatherine Sullivan }
496e5b845dcSCatherine Sullivan 
gve_get_tunable(struct net_device * netdev,const struct ethtool_tunable * etuna,void * value)497d5f7543cSKuo Zhao static int gve_get_tunable(struct net_device *netdev,
498d5f7543cSKuo Zhao 			   const struct ethtool_tunable *etuna, void *value)
499d5f7543cSKuo Zhao {
500d5f7543cSKuo Zhao 	struct gve_priv *priv = netdev_priv(netdev);
501d5f7543cSKuo Zhao 
502d5f7543cSKuo Zhao 	switch (etuna->id) {
503d5f7543cSKuo Zhao 	case ETHTOOL_RX_COPYBREAK:
504d5f7543cSKuo Zhao 		*(u32 *)value = priv->rx_copybreak;
505d5f7543cSKuo Zhao 		return 0;
506d5f7543cSKuo Zhao 	default:
507d5f7543cSKuo Zhao 		return -EOPNOTSUPP;
508d5f7543cSKuo Zhao 	}
509d5f7543cSKuo Zhao }
510d5f7543cSKuo Zhao 
gve_set_tunable(struct net_device * netdev,const struct ethtool_tunable * etuna,const void * value)511d5f7543cSKuo Zhao static int gve_set_tunable(struct net_device *netdev,
512433e274bSKuo Zhao 			   const struct ethtool_tunable *etuna,
513433e274bSKuo Zhao 			   const void *value)
514d5f7543cSKuo Zhao {
515d5f7543cSKuo Zhao 	struct gve_priv *priv = netdev_priv(netdev);
516d5f7543cSKuo Zhao 	u32 len;
517d5f7543cSKuo Zhao 
518d5f7543cSKuo Zhao 	switch (etuna->id) {
519d5f7543cSKuo Zhao 	case ETHTOOL_RX_COPYBREAK:
5201f6228e4SBailey Forrest 	{
5211f6228e4SBailey Forrest 		u32 max_copybreak = gve_is_gqi(priv) ?
5221f6228e4SBailey Forrest 			(PAGE_SIZE / 2) : priv->data_buffer_size_dqo;
5231f6228e4SBailey Forrest 
524d5f7543cSKuo Zhao 		len = *(u32 *)value;
5251f6228e4SBailey Forrest 		if (len > max_copybreak)
526d5f7543cSKuo Zhao 			return -EINVAL;
527d5f7543cSKuo Zhao 		priv->rx_copybreak = len;
528d5f7543cSKuo Zhao 		return 0;
5291f6228e4SBailey Forrest 	}
530d5f7543cSKuo Zhao 	default:
531d5f7543cSKuo Zhao 		return -EOPNOTSUPP;
532d5f7543cSKuo Zhao 	}
533d5f7543cSKuo Zhao }
534d5f7543cSKuo Zhao 
gve_get_priv_flags(struct net_device * netdev)53524aeb56fSKuo Zhao static u32 gve_get_priv_flags(struct net_device *netdev)
53624aeb56fSKuo Zhao {
53724aeb56fSKuo Zhao 	struct gve_priv *priv = netdev_priv(netdev);
53824aeb56fSKuo Zhao 	u32 ret_flags = 0;
53924aeb56fSKuo Zhao 
54024aeb56fSKuo Zhao 	/* Only 1 flag exists currently: report-stats (BIT(O)), so set that flag. */
54124aeb56fSKuo Zhao 	if (priv->ethtool_flags & BIT(0))
54224aeb56fSKuo Zhao 		ret_flags |= BIT(0);
54324aeb56fSKuo Zhao 	return ret_flags;
54424aeb56fSKuo Zhao }
54524aeb56fSKuo Zhao 
gve_set_priv_flags(struct net_device * netdev,u32 flags)54624aeb56fSKuo Zhao static int gve_set_priv_flags(struct net_device *netdev, u32 flags)
54724aeb56fSKuo Zhao {
54824aeb56fSKuo Zhao 	struct gve_priv *priv = netdev_priv(netdev);
54924aeb56fSKuo Zhao 	u64 ori_flags, new_flags;
5502e80aeaeSPraveen Kaligineedi 	int num_tx_queues;
55124aeb56fSKuo Zhao 
5522e80aeaeSPraveen Kaligineedi 	num_tx_queues = gve_num_tx_queues(priv);
55324aeb56fSKuo Zhao 	ori_flags = READ_ONCE(priv->ethtool_flags);
55424aeb56fSKuo Zhao 	new_flags = ori_flags;
55524aeb56fSKuo Zhao 
55624aeb56fSKuo Zhao 	/* Only one priv flag exists: report-stats (BIT(0))*/
55724aeb56fSKuo Zhao 	if (flags & BIT(0))
55824aeb56fSKuo Zhao 		new_flags |= BIT(0);
55924aeb56fSKuo Zhao 	else
56024aeb56fSKuo Zhao 		new_flags &= ~(BIT(0));
56124aeb56fSKuo Zhao 	priv->ethtool_flags = new_flags;
56224aeb56fSKuo Zhao 	/* start report-stats timer when user turns report stats on. */
56324aeb56fSKuo Zhao 	if (flags & BIT(0)) {
56424aeb56fSKuo Zhao 		mod_timer(&priv->stats_report_timer,
56524aeb56fSKuo Zhao 			  round_jiffies(jiffies +
56624aeb56fSKuo Zhao 					msecs_to_jiffies(priv->stats_report_timer_period)));
56724aeb56fSKuo Zhao 	}
56824aeb56fSKuo Zhao 	/* Zero off gve stats when report-stats turned off and */
56924aeb56fSKuo Zhao 	/* delete report stats timer. */
57024aeb56fSKuo Zhao 	if (!(flags & BIT(0)) && (ori_flags & BIT(0))) {
57124aeb56fSKuo Zhao 		int tx_stats_num = GVE_TX_STATS_REPORT_NUM *
5722e80aeaeSPraveen Kaligineedi 			num_tx_queues;
57324aeb56fSKuo Zhao 		int rx_stats_num = GVE_RX_STATS_REPORT_NUM *
57424aeb56fSKuo Zhao 			priv->rx_cfg.num_queues;
57524aeb56fSKuo Zhao 
57624aeb56fSKuo Zhao 		memset(priv->stats_report->stats, 0, (tx_stats_num + rx_stats_num) *
57724aeb56fSKuo Zhao 				   sizeof(struct stats));
57824aeb56fSKuo Zhao 		del_timer_sync(&priv->stats_report_timer);
57924aeb56fSKuo Zhao 	}
58024aeb56fSKuo Zhao 	return 0;
58124aeb56fSKuo Zhao }
58224aeb56fSKuo Zhao 
gve_get_link_ksettings(struct net_device * netdev,struct ethtool_link_ksettings * cmd)5837e074d5aSDavid Awogbemila static int gve_get_link_ksettings(struct net_device *netdev,
5847e074d5aSDavid Awogbemila 				  struct ethtool_link_ksettings *cmd)
5857e074d5aSDavid Awogbemila {
5867e074d5aSDavid Awogbemila 	struct gve_priv *priv = netdev_priv(netdev);
58768c3e4fcSJoshua Washington 	int err = 0;
58868c3e4fcSJoshua Washington 
58968c3e4fcSJoshua Washington 	if (priv->link_speed == 0)
59068c3e4fcSJoshua Washington 		err = gve_adminq_report_link_speed(priv);
5917e074d5aSDavid Awogbemila 
5927e074d5aSDavid Awogbemila 	cmd->base.speed = priv->link_speed;
5930503efeaSJunfeng Guo 
5940503efeaSJunfeng Guo 	cmd->base.duplex = DUPLEX_FULL;
5950503efeaSJunfeng Guo 
5967e074d5aSDavid Awogbemila 	return err;
5977e074d5aSDavid Awogbemila }
5987e074d5aSDavid Awogbemila 
gve_get_coalesce(struct net_device * netdev,struct ethtool_coalesce * ec,struct kernel_ethtool_coalesce * kernel_ec,struct netlink_ext_ack * extack)5996081ac20STao Liu static int gve_get_coalesce(struct net_device *netdev,
6006081ac20STao Liu 			    struct ethtool_coalesce *ec,
6016081ac20STao Liu 			    struct kernel_ethtool_coalesce *kernel_ec,
6026081ac20STao Liu 			    struct netlink_ext_ack *extack)
6036081ac20STao Liu {
6046081ac20STao Liu 	struct gve_priv *priv = netdev_priv(netdev);
6056081ac20STao Liu 
6066081ac20STao Liu 	if (gve_is_gqi(priv))
6076081ac20STao Liu 		return -EOPNOTSUPP;
6086081ac20STao Liu 	ec->tx_coalesce_usecs = priv->tx_coalesce_usecs;
6096081ac20STao Liu 	ec->rx_coalesce_usecs = priv->rx_coalesce_usecs;
6106081ac20STao Liu 
6116081ac20STao Liu 	return 0;
6126081ac20STao Liu }
6136081ac20STao Liu 
gve_set_coalesce(struct net_device * netdev,struct ethtool_coalesce * ec,struct kernel_ethtool_coalesce * kernel_ec,struct netlink_ext_ack * extack)6146081ac20STao Liu static int gve_set_coalesce(struct net_device *netdev,
6156081ac20STao Liu 			    struct ethtool_coalesce *ec,
6166081ac20STao Liu 			    struct kernel_ethtool_coalesce *kernel_ec,
6176081ac20STao Liu 			    struct netlink_ext_ack *extack)
6186081ac20STao Liu {
6196081ac20STao Liu 	struct gve_priv *priv = netdev_priv(netdev);
6206081ac20STao Liu 	u32 tx_usecs_orig = priv->tx_coalesce_usecs;
6216081ac20STao Liu 	u32 rx_usecs_orig = priv->rx_coalesce_usecs;
6226081ac20STao Liu 	int idx;
6236081ac20STao Liu 
6246081ac20STao Liu 	if (gve_is_gqi(priv))
6256081ac20STao Liu 		return -EOPNOTSUPP;
6266081ac20STao Liu 
6276081ac20STao Liu 	if (ec->tx_coalesce_usecs > GVE_MAX_ITR_INTERVAL_DQO ||
6286081ac20STao Liu 	    ec->rx_coalesce_usecs > GVE_MAX_ITR_INTERVAL_DQO)
6296081ac20STao Liu 		return -EINVAL;
6306081ac20STao Liu 	priv->tx_coalesce_usecs = ec->tx_coalesce_usecs;
6316081ac20STao Liu 	priv->rx_coalesce_usecs = ec->rx_coalesce_usecs;
6326081ac20STao Liu 
6336081ac20STao Liu 	if (tx_usecs_orig != priv->tx_coalesce_usecs) {
6346081ac20STao Liu 		for (idx = 0; idx < priv->tx_cfg.num_queues; idx++) {
6356081ac20STao Liu 			int ntfy_idx = gve_tx_idx_to_ntfy(priv, idx);
6366081ac20STao Liu 			struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx];
6376081ac20STao Liu 
6386081ac20STao Liu 			gve_set_itr_coalesce_usecs_dqo(priv, block,
6396081ac20STao Liu 						       priv->tx_coalesce_usecs);
6406081ac20STao Liu 		}
6416081ac20STao Liu 	}
6426081ac20STao Liu 
6436081ac20STao Liu 	if (rx_usecs_orig != priv->rx_coalesce_usecs) {
6446081ac20STao Liu 		for (idx = 0; idx < priv->rx_cfg.num_queues; idx++) {
6456081ac20STao Liu 			int ntfy_idx = gve_rx_idx_to_ntfy(priv, idx);
6466081ac20STao Liu 			struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx];
6476081ac20STao Liu 
6486081ac20STao Liu 			gve_set_itr_coalesce_usecs_dqo(priv, block,
6496081ac20STao Liu 						       priv->rx_coalesce_usecs);
6506081ac20STao Liu 		}
6516081ac20STao Liu 	}
6526081ac20STao Liu 
6536081ac20STao Liu 	return 0;
6546081ac20STao Liu }
6556081ac20STao Liu 
656e5b845dcSCatherine Sullivan const struct ethtool_ops gve_ethtool_ops = {
6576081ac20STao Liu 	.supported_coalesce_params = ETHTOOL_COALESCE_USECS,
658e5b845dcSCatherine Sullivan 	.get_drvinfo = gve_get_drvinfo,
659e5b845dcSCatherine Sullivan 	.get_strings = gve_get_strings,
660e5b845dcSCatherine Sullivan 	.get_sset_count = gve_get_sset_count,
661e5b845dcSCatherine Sullivan 	.get_ethtool_stats = gve_get_ethtool_stats,
662e5b845dcSCatherine Sullivan 	.set_msglevel = gve_set_msglevel,
663e5b845dcSCatherine Sullivan 	.get_msglevel = gve_get_msglevel,
664e5b845dcSCatherine Sullivan 	.set_channels = gve_set_channels,
665e5b845dcSCatherine Sullivan 	.get_channels = gve_get_channels,
666e5b845dcSCatherine Sullivan 	.get_link = ethtool_op_get_link,
6676081ac20STao Liu 	.get_coalesce = gve_get_coalesce,
6686081ac20STao Liu 	.set_coalesce = gve_set_coalesce,
669e5b845dcSCatherine Sullivan 	.get_ringparam = gve_get_ringparam,
670e5b845dcSCatherine Sullivan 	.reset = gve_user_reset,
671d5f7543cSKuo Zhao 	.get_tunable = gve_get_tunable,
672d5f7543cSKuo Zhao 	.set_tunable = gve_set_tunable,
67324aeb56fSKuo Zhao 	.get_priv_flags = gve_get_priv_flags,
67424aeb56fSKuo Zhao 	.set_priv_flags = gve_set_priv_flags,
6757e074d5aSDavid Awogbemila 	.get_link_ksettings = gve_get_link_ksettings
676e5b845dcSCatherine Sullivan };
677