blob: 3480ff5c7ed6a7b8828c559e055a6154dd15cc7e [file] [log] [blame]
Catherine Sullivane5b845dc2019-07-01 15:57:55 -07001// SPDX-License-Identifier: (GPL-2.0 OR MIT)
2/* Google virtual Ethernet (gve) driver
3 *
Jeroen de Borst6f3bc482024-06-25 00:12:31 +00004 * Copyright (C) 2015-2024 Google LLC
Catherine Sullivane5b845dc2019-07-01 15:57:55 -07005 */
6
7#include <linux/rtnetlink.h>
8#include "gve.h"
Kuo Zhao24aeb562020-09-11 10:38:47 -07009#include "gve_adminq.h"
Tao Liu6081ac22021-12-15 16:46:52 -080010#include "gve_dqo.h"
Shailend Chandaf9bcf92024-05-01 23:25:47 +000011#include "gve_utils.h"
Catherine Sullivane5b845dc2019-07-01 15:57:55 -070012
13static void gve_get_drvinfo(struct net_device *netdev,
14 struct ethtool_drvinfo *info)
15{
16 struct gve_priv *priv = netdev_priv(netdev);
17
Junfeng Guo9d0aba92023-07-08 11:14:51 +080018 strscpy(info->driver, gve_driver_name, sizeof(info->driver));
Daode Huangc32773c2021-03-25 15:56:31 +080019 strscpy(info->version, gve_version_str, sizeof(info->version));
20 strscpy(info->bus_info, pci_name(priv->pdev), sizeof(info->bus_info));
Catherine Sullivane5b845dc2019-07-01 15:57:55 -070021}
22
23static void gve_set_msglevel(struct net_device *netdev, u32 value)
24{
25 struct gve_priv *priv = netdev_priv(netdev);
26
27 priv->msg_enable = value;
28}
29
30static u32 gve_get_msglevel(struct net_device *netdev)
31{
32 struct gve_priv *priv = netdev_priv(netdev);
33
34 return priv->msg_enable;
35}
36
Praveen Kaligineedi75eaae12023-03-15 16:33:10 -070037/* For the following stats column string names, make sure the order
38 * matches how it is filled in the code. For xdp_aborted, xdp_drop,
39 * xdp_pass, xdp_tx, xdp_redirect, make sure it also matches the order
40 * as declared in enum xdp_action inside file uapi/linux/bpf.h .
41 */
Catherine Sullivane5b845dc2019-07-01 15:57:55 -070042static const char gve_gstrings_main_stats[][ETH_GSTRING_LEN] = {
Jeroen de Borst056a7092024-02-29 13:22:36 -080043 "rx_packets", "rx_hsplit_pkt", "tx_packets", "rx_bytes",
44 "tx_bytes", "rx_dropped", "tx_dropped", "tx_timeouts",
Kuo Zhao433e2742020-09-11 10:38:45 -070045 "rx_skb_alloc_fail", "rx_buf_alloc_fail", "rx_desc_err_dropped_pkt",
Jeroen de Borst056a7092024-02-29 13:22:36 -080046 "rx_hsplit_unsplit_pkt",
Kuo Zhao433e2742020-09-11 10:38:45 -070047 "interface_up_cnt", "interface_down_cnt", "reset_cnt",
Kuo Zhao24aeb562020-09-11 10:38:47 -070048 "page_alloc_fail", "dma_mapping_error", "stats_report_trigger_cnt",
Kuo Zhao433e2742020-09-11 10:38:45 -070049};
50
51static const char gve_gstrings_rx_stats[][ETH_GSTRING_LEN] = {
Jeroen de Borst056a7092024-02-29 13:22:36 -080052 "rx_posted_desc[%u]", "rx_completed_desc[%u]", "rx_consumed_desc[%u]",
53 "rx_bytes[%u]", "rx_hsplit_bytes[%u]", "rx_cont_packet_cnt[%u]",
54 "rx_frag_flip_cnt[%u]", "rx_frag_copy_cnt[%u]", "rx_frag_alloc_cnt[%u]",
Kuo Zhao433e2742020-09-11 10:38:45 -070055 "rx_dropped_pkt[%u]", "rx_copybreak_pkt[%u]", "rx_copied_pkt[%u]",
David Awogbemila2f523dc2020-09-11 10:38:48 -070056 "rx_queue_drop_cnt[%u]", "rx_no_buffers_posted[%u]",
57 "rx_drops_packet_over_mru[%u]", "rx_drops_invalid_checksum[%u]",
Praveen Kaligineedi75eaae12023-03-15 16:33:10 -070058 "rx_xdp_aborted[%u]", "rx_xdp_drop[%u]", "rx_xdp_pass[%u]",
59 "rx_xdp_tx[%u]", "rx_xdp_redirect[%u]",
Praveen Kaligineedi39a7f4a2023-03-15 16:33:11 -070060 "rx_xdp_tx_errors[%u]", "rx_xdp_redirect_errors[%u]", "rx_xdp_alloc_fails[%u]",
Kuo Zhao433e2742020-09-11 10:38:45 -070061};
62
63static const char gve_gstrings_tx_stats[][ETH_GSTRING_LEN] = {
Jordan Kim2c919832021-12-15 16:46:51 -080064 "tx_posted_desc[%u]", "tx_completed_desc[%u]", "tx_consumed_desc[%u]", "tx_bytes[%u]",
Kuo Zhao433e2742020-09-11 10:38:45 -070065 "tx_wake[%u]", "tx_stop[%u]", "tx_event_counter[%u]",
Praveen Kaligineedifd8e4032023-03-15 16:33:12 -070066 "tx_dma_mapping_error[%u]", "tx_xsk_wakeup[%u]",
67 "tx_xsk_done[%u]", "tx_xsk_sent[%u]", "tx_xdp_xmit[%u]", "tx_xdp_xmit_errors[%u]"
Kuo Zhao433e2742020-09-11 10:38:45 -070068};
69
70static const char gve_gstrings_adminq_stats[][ETH_GSTRING_LEN] = {
71 "adminq_prod_cnt", "adminq_cmd_fail", "adminq_timeouts",
72 "adminq_describe_device_cnt", "adminq_cfg_device_resources_cnt",
73 "adminq_register_page_list_cnt", "adminq_unregister_page_list_cnt",
74 "adminq_create_tx_queue_cnt", "adminq_create_rx_queue_cnt",
75 "adminq_destroy_tx_queue_cnt", "adminq_destroy_rx_queue_cnt",
76 "adminq_dcfg_device_resources_cnt", "adminq_set_driver_parameter_cnt",
Jeroen de Borst57718b62024-06-25 00:12:30 +000077 "adminq_report_stats_cnt", "adminq_report_link_speed_cnt", "adminq_get_ptype_map_cnt",
78 "adminq_query_flow_rules", "adminq_cfg_flow_rule",
Kuo Zhao24aeb562020-09-11 10:38:47 -070079};
80
81static const char gve_gstrings_priv_flags[][ETH_GSTRING_LEN] = {
82 "report-stats",
Catherine Sullivane5b845dc2019-07-01 15:57:55 -070083};
84
85#define GVE_MAIN_STATS_LEN ARRAY_SIZE(gve_gstrings_main_stats)
Kuo Zhao433e2742020-09-11 10:38:45 -070086#define GVE_ADMINQ_STATS_LEN ARRAY_SIZE(gve_gstrings_adminq_stats)
87#define NUM_GVE_TX_CNTS ARRAY_SIZE(gve_gstrings_tx_stats)
88#define NUM_GVE_RX_CNTS ARRAY_SIZE(gve_gstrings_rx_stats)
Kuo Zhao24aeb562020-09-11 10:38:47 -070089#define GVE_PRIV_FLAGS_STR_LEN ARRAY_SIZE(gve_gstrings_priv_flags)
Catherine Sullivane5b845dc2019-07-01 15:57:55 -070090
91static void gve_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
92{
93 struct gve_priv *priv = netdev_priv(netdev);
Simon Hormanba8bcb02024-05-08 09:32:20 +010094 u8 *s = (char *)data;
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -070095 int num_tx_queues;
Kuo Zhao433e2742020-09-11 10:38:45 -070096 int i, j;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -070097
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -070098 num_tx_queues = gve_num_tx_queues(priv);
Kuo Zhao24aeb562020-09-11 10:38:47 -070099 switch (stringset) {
100 case ETH_SS_STATS:
Simon Hormanba8bcb02024-05-08 09:32:20 +0100101 for (i = 0; i < ARRAY_SIZE(gve_gstrings_main_stats); i++)
102 ethtool_puts(&s, gve_gstrings_main_stats[i]);
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700103
Simon Hormanba8bcb02024-05-08 09:32:20 +0100104 for (i = 0; i < priv->rx_cfg.num_queues; i++)
105 for (j = 0; j < NUM_GVE_RX_CNTS; j++)
106 ethtool_sprintf(&s, gve_gstrings_rx_stats[j],
107 i);
Kuo Zhao433e2742020-09-11 10:38:45 -0700108
Simon Hormanba8bcb02024-05-08 09:32:20 +0100109 for (i = 0; i < num_tx_queues; i++)
110 for (j = 0; j < NUM_GVE_TX_CNTS; j++)
111 ethtool_sprintf(&s, gve_gstrings_tx_stats[j],
112 i);
Kuo Zhao24aeb562020-09-11 10:38:47 -0700113
Simon Hormanba8bcb02024-05-08 09:32:20 +0100114 for (i = 0; i < ARRAY_SIZE(gve_gstrings_adminq_stats); i++)
115 ethtool_puts(&s, gve_gstrings_adminq_stats[i]);
116
Kuo Zhao24aeb562020-09-11 10:38:47 -0700117 break;
118
119 case ETH_SS_PRIV_FLAGS:
Simon Hormanba8bcb02024-05-08 09:32:20 +0100120 for (i = 0; i < ARRAY_SIZE(gve_gstrings_priv_flags); i++)
121 ethtool_puts(&s, gve_gstrings_priv_flags[i]);
Kuo Zhao24aeb562020-09-11 10:38:47 -0700122 break;
123
124 default:
125 break;
126 }
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700127}
128
129static int gve_get_sset_count(struct net_device *netdev, int sset)
130{
131 struct gve_priv *priv = netdev_priv(netdev);
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700132 int num_tx_queues;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700133
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700134 num_tx_queues = gve_num_tx_queues(priv);
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700135 switch (sset) {
136 case ETH_SS_STATS:
Kuo Zhao433e2742020-09-11 10:38:45 -0700137 return GVE_MAIN_STATS_LEN + GVE_ADMINQ_STATS_LEN +
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700138 (priv->rx_cfg.num_queues * NUM_GVE_RX_CNTS) +
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700139 (num_tx_queues * NUM_GVE_TX_CNTS);
Kuo Zhao24aeb562020-09-11 10:38:47 -0700140 case ETH_SS_PRIV_FLAGS:
141 return GVE_PRIV_FLAGS_STR_LEN;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700142 default:
143 return -EOPNOTSUPP;
144 }
145}
146
147static void
148gve_get_ethtool_stats(struct net_device *netdev,
149 struct ethtool_stats *stats, u64 *data)
150{
Jeroen de Borst056a7092024-02-29 13:22:36 -0800151 u64 tmp_rx_pkts, tmp_rx_hsplit_pkt, tmp_rx_bytes, tmp_rx_hsplit_bytes,
152 tmp_rx_skb_alloc_fail, tmp_rx_buf_alloc_fail,
153 tmp_rx_desc_err_dropped_pkt, tmp_rx_hsplit_unsplit_pkt,
Jordan Kim2c919832021-12-15 16:46:51 -0800154 tmp_tx_pkts, tmp_tx_bytes;
Jeroen de Borst056a7092024-02-29 13:22:36 -0800155 u64 rx_buf_alloc_fail, rx_desc_err_dropped_pkt, rx_hsplit_unsplit_pkt,
156 rx_pkts, rx_hsplit_pkt, rx_skb_alloc_fail, rx_bytes, tx_pkts, tx_bytes,
157 tx_dropped;
David Awogbemila2f523dc2020-09-11 10:38:48 -0700158 int stats_idx, base_stats_idx, max_stats_idx;
159 struct stats *report_stats;
160 int *rx_qid_to_stats_idx;
161 int *tx_qid_to_stats_idx;
Shailend Chandaf9bcf92024-05-01 23:25:47 +0000162 int num_stopped_rxqs = 0;
163 int num_stopped_txqs = 0;
Kuo Zhao433e2742020-09-11 10:38:45 -0700164 struct gve_priv *priv;
David Awogbemila2f523dc2020-09-11 10:38:48 -0700165 bool skip_nic_stats;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700166 unsigned int start;
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700167 int num_tx_queues;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700168 int ring;
David Awogbemila2f523dc2020-09-11 10:38:48 -0700169 int i, j;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700170
171 ASSERT_RTNL();
172
Kuo Zhao433e2742020-09-11 10:38:45 -0700173 priv = netdev_priv(netdev);
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700174 num_tx_queues = gve_num_tx_queues(priv);
David Awogbemila2f523dc2020-09-11 10:38:48 -0700175 report_stats = priv->stats_report->stats;
176 rx_qid_to_stats_idx = kmalloc_array(priv->rx_cfg.num_queues,
177 sizeof(int), GFP_KERNEL);
178 if (!rx_qid_to_stats_idx)
179 return;
Shailend Chandaf9bcf92024-05-01 23:25:47 +0000180 for (ring = 0; ring < priv->rx_cfg.num_queues; ring++) {
181 rx_qid_to_stats_idx[ring] = -1;
182 if (!gve_rx_was_added_to_block(priv, ring))
183 num_stopped_rxqs++;
184 }
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700185 tx_qid_to_stats_idx = kmalloc_array(num_tx_queues,
David Awogbemila2f523dc2020-09-11 10:38:48 -0700186 sizeof(int), GFP_KERNEL);
187 if (!tx_qid_to_stats_idx) {
188 kfree(rx_qid_to_stats_idx);
189 return;
190 }
Shailend Chandaf9bcf92024-05-01 23:25:47 +0000191 for (ring = 0; ring < num_tx_queues; ring++) {
192 tx_qid_to_stats_idx[ring] = -1;
193 if (!gve_tx_was_added_to_block(priv, ring))
194 num_stopped_txqs++;
195 }
196
Jeroen de Borst056a7092024-02-29 13:22:36 -0800197 for (rx_pkts = 0, rx_bytes = 0, rx_hsplit_pkt = 0,
198 rx_skb_alloc_fail = 0, rx_buf_alloc_fail = 0,
199 rx_desc_err_dropped_pkt = 0, rx_hsplit_unsplit_pkt = 0,
200 ring = 0;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700201 ring < priv->rx_cfg.num_queues; ring++) {
202 if (priv->rx) {
203 do {
Kuo Zhao433e2742020-09-11 10:38:45 -0700204 struct gve_rx_ring *rx = &priv->rx[ring];
205
Catherine Sullivan3c13ce72019-07-02 15:46:57 -0700206 start =
Thomas Gleixner068c38a2022-10-26 15:22:14 +0200207 u64_stats_fetch_begin(&priv->rx[ring].statss);
Kuo Zhao433e2742020-09-11 10:38:45 -0700208 tmp_rx_pkts = rx->rpackets;
Jeroen de Borst056a7092024-02-29 13:22:36 -0800209 tmp_rx_hsplit_pkt = rx->rx_hsplit_pkt;
Kuo Zhao433e2742020-09-11 10:38:45 -0700210 tmp_rx_bytes = rx->rbytes;
211 tmp_rx_skb_alloc_fail = rx->rx_skb_alloc_fail;
212 tmp_rx_buf_alloc_fail = rx->rx_buf_alloc_fail;
213 tmp_rx_desc_err_dropped_pkt =
214 rx->rx_desc_err_dropped_pkt;
Jeroen de Borst056a7092024-02-29 13:22:36 -0800215 tmp_rx_hsplit_unsplit_pkt =
216 rx->rx_hsplit_unsplit_pkt;
Thomas Gleixner068c38a2022-10-26 15:22:14 +0200217 } while (u64_stats_fetch_retry(&priv->rx[ring].statss,
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700218 start));
Kuo Zhao433e2742020-09-11 10:38:45 -0700219 rx_pkts += tmp_rx_pkts;
Jeroen de Borst056a7092024-02-29 13:22:36 -0800220 rx_hsplit_pkt += tmp_rx_hsplit_pkt;
Kuo Zhao433e2742020-09-11 10:38:45 -0700221 rx_bytes += tmp_rx_bytes;
222 rx_skb_alloc_fail += tmp_rx_skb_alloc_fail;
223 rx_buf_alloc_fail += tmp_rx_buf_alloc_fail;
224 rx_desc_err_dropped_pkt += tmp_rx_desc_err_dropped_pkt;
Jeroen de Borst056a7092024-02-29 13:22:36 -0800225 rx_hsplit_unsplit_pkt += tmp_rx_hsplit_unsplit_pkt;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700226 }
227 }
Jordan Kim2c919832021-12-15 16:46:51 -0800228 for (tx_pkts = 0, tx_bytes = 0, tx_dropped = 0, ring = 0;
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700229 ring < num_tx_queues; ring++) {
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700230 if (priv->tx) {
231 do {
Catherine Sullivan3c13ce72019-07-02 15:46:57 -0700232 start =
Thomas Gleixner068c38a2022-10-26 15:22:14 +0200233 u64_stats_fetch_begin(&priv->tx[ring].statss);
Kuo Zhao433e2742020-09-11 10:38:45 -0700234 tmp_tx_pkts = priv->tx[ring].pkt_done;
235 tmp_tx_bytes = priv->tx[ring].bytes_done;
Thomas Gleixner068c38a2022-10-26 15:22:14 +0200236 } while (u64_stats_fetch_retry(&priv->tx[ring].statss,
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700237 start));
Kuo Zhao433e2742020-09-11 10:38:45 -0700238 tx_pkts += tmp_tx_pkts;
239 tx_bytes += tmp_tx_bytes;
Jordan Kim2c919832021-12-15 16:46:51 -0800240 tx_dropped += priv->tx[ring].dropped_pkt;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700241 }
242 }
243
244 i = 0;
245 data[i++] = rx_pkts;
Jeroen de Borst056a7092024-02-29 13:22:36 -0800246 data[i++] = rx_hsplit_pkt;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700247 data[i++] = tx_pkts;
248 data[i++] = rx_bytes;
249 data[i++] = tx_bytes;
Kuo Zhao433e2742020-09-11 10:38:45 -0700250 /* total rx dropped packets */
251 data[i++] = rx_skb_alloc_fail + rx_buf_alloc_fail +
252 rx_desc_err_dropped_pkt;
Jordan Kim2c919832021-12-15 16:46:51 -0800253 data[i++] = tx_dropped;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700254 data[i++] = priv->tx_timeo_cnt;
Kuo Zhao433e2742020-09-11 10:38:45 -0700255 data[i++] = rx_skb_alloc_fail;
256 data[i++] = rx_buf_alloc_fail;
257 data[i++] = rx_desc_err_dropped_pkt;
Jeroen de Borst056a7092024-02-29 13:22:36 -0800258 data[i++] = rx_hsplit_unsplit_pkt;
Kuo Zhao433e2742020-09-11 10:38:45 -0700259 data[i++] = priv->interface_up_cnt;
260 data[i++] = priv->interface_down_cnt;
261 data[i++] = priv->reset_cnt;
262 data[i++] = priv->page_alloc_fail;
263 data[i++] = priv->dma_mapping_error;
Kuo Zhao24aeb562020-09-11 10:38:47 -0700264 data[i++] = priv->stats_report_trigger_cnt;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700265 i = GVE_MAIN_STATS_LEN;
266
David Awogbemila2f523dc2020-09-11 10:38:48 -0700267 /* For rx cross-reporting stats, start from nic rx stats in report */
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700268 base_stats_idx = GVE_TX_STATS_REPORT_NUM * num_tx_queues +
David Awogbemila2f523dc2020-09-11 10:38:48 -0700269 GVE_RX_STATS_REPORT_NUM * priv->rx_cfg.num_queues;
Shailend Chandaf9bcf92024-05-01 23:25:47 +0000270 /* The boundary between driver stats and NIC stats shifts if there are
271 * stopped queues.
272 */
273 base_stats_idx += NIC_RX_STATS_REPORT_NUM * num_stopped_rxqs +
274 NIC_TX_STATS_REPORT_NUM * num_stopped_txqs;
275 max_stats_idx = NIC_RX_STATS_REPORT_NUM *
276 (priv->rx_cfg.num_queues - num_stopped_rxqs) +
David Awogbemila2f523dc2020-09-11 10:38:48 -0700277 base_stats_idx;
278 /* Preprocess the stats report for rx, map queue id to start index */
279 skip_nic_stats = false;
280 for (stats_idx = base_stats_idx; stats_idx < max_stats_idx;
281 stats_idx += NIC_RX_STATS_REPORT_NUM) {
282 u32 stat_name = be32_to_cpu(report_stats[stats_idx].stat_name);
283 u32 queue_id = be32_to_cpu(report_stats[stats_idx].queue_id);
284
285 if (stat_name == 0) {
286 /* no stats written by NIC yet */
287 skip_nic_stats = true;
288 break;
289 }
Shailend Chandaf9bcf92024-05-01 23:25:47 +0000290 if (queue_id < 0 || queue_id >= priv->rx_cfg.num_queues) {
291 net_err_ratelimited("Invalid rxq id in NIC stats\n");
292 continue;
293 }
David Awogbemila2f523dc2020-09-11 10:38:48 -0700294 rx_qid_to_stats_idx[queue_id] = stats_idx;
295 }
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700296 /* walk RX rings */
297 if (priv->rx) {
298 for (ring = 0; ring < priv->rx_cfg.num_queues; ring++) {
299 struct gve_rx_ring *rx = &priv->rx[ring];
300
Catherine Sullivan438b43b2019-08-01 16:07:31 -0700301 data[i++] = rx->fill_cnt;
Kuo Zhao433e2742020-09-11 10:38:45 -0700302 data[i++] = rx->cnt;
Jordan Kim2c919832021-12-15 16:46:51 -0800303 data[i++] = rx->fill_cnt - rx->cnt;
Kuo Zhao433e2742020-09-11 10:38:45 -0700304 do {
305 start =
Thomas Gleixner068c38a2022-10-26 15:22:14 +0200306 u64_stats_fetch_begin(&priv->rx[ring].statss);
Kuo Zhao433e2742020-09-11 10:38:45 -0700307 tmp_rx_bytes = rx->rbytes;
Jeroen de Borst056a7092024-02-29 13:22:36 -0800308 tmp_rx_hsplit_bytes = rx->rx_hsplit_bytes;
Kuo Zhao433e2742020-09-11 10:38:45 -0700309 tmp_rx_skb_alloc_fail = rx->rx_skb_alloc_fail;
310 tmp_rx_buf_alloc_fail = rx->rx_buf_alloc_fail;
311 tmp_rx_desc_err_dropped_pkt =
312 rx->rx_desc_err_dropped_pkt;
Thomas Gleixner068c38a2022-10-26 15:22:14 +0200313 } while (u64_stats_fetch_retry(&priv->rx[ring].statss,
Kuo Zhao433e2742020-09-11 10:38:45 -0700314 start));
315 data[i++] = tmp_rx_bytes;
Jeroen de Borst056a7092024-02-29 13:22:36 -0800316 data[i++] = tmp_rx_hsplit_bytes;
David Awogbemila37149e92021-10-24 11:42:37 -0700317 data[i++] = rx->rx_cont_packet_cnt;
318 data[i++] = rx->rx_frag_flip_cnt;
319 data[i++] = rx->rx_frag_copy_cnt;
Shailend Chand82fd1512022-10-29 09:53:22 -0700320 data[i++] = rx->rx_frag_alloc_cnt;
Kuo Zhao433e2742020-09-11 10:38:45 -0700321 /* rx dropped packets */
322 data[i++] = tmp_rx_skb_alloc_fail +
323 tmp_rx_buf_alloc_fail +
324 tmp_rx_desc_err_dropped_pkt;
325 data[i++] = rx->rx_copybreak_pkt;
326 data[i++] = rx->rx_copied_pkt;
David Awogbemila2f523dc2020-09-11 10:38:48 -0700327 /* stats from NIC */
Shailend Chandaf9bcf92024-05-01 23:25:47 +0000328 stats_idx = rx_qid_to_stats_idx[ring];
329 if (skip_nic_stats || stats_idx < 0) {
David Awogbemila2f523dc2020-09-11 10:38:48 -0700330 /* skip NIC rx stats */
331 i += NIC_RX_STATS_REPORT_NUM;
Praveen Kaligineedi75eaae12023-03-15 16:33:10 -0700332 } else {
Praveen Kaligineedi75eaae12023-03-15 16:33:10 -0700333 for (j = 0; j < NIC_RX_STATS_REPORT_NUM; j++) {
334 u64 value =
335 be64_to_cpu(report_stats[stats_idx + j].value);
David Awogbemila2f523dc2020-09-11 10:38:48 -0700336
Praveen Kaligineedi75eaae12023-03-15 16:33:10 -0700337 data[i++] = value;
338 }
David Awogbemila2f523dc2020-09-11 10:38:48 -0700339 }
Praveen Kaligineedi75eaae12023-03-15 16:33:10 -0700340 /* XDP rx counters */
341 do {
342 start = u64_stats_fetch_begin(&priv->rx[ring].statss);
343 for (j = 0; j < GVE_XDP_ACTIONS; j++)
344 data[i + j] = rx->xdp_actions[j];
345 data[i + j++] = rx->xdp_tx_errors;
346 data[i + j++] = rx->xdp_redirect_errors;
Praveen Kaligineedi39a7f4a2023-03-15 16:33:11 -0700347 data[i + j++] = rx->xdp_alloc_fails;
Praveen Kaligineedi75eaae12023-03-15 16:33:10 -0700348 } while (u64_stats_fetch_retry(&priv->rx[ring].statss,
349 start));
Praveen Kaligineedi39a7f4a2023-03-15 16:33:11 -0700350 i += GVE_XDP_ACTIONS + 3; /* XDP rx counters */
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700351 }
352 } else {
353 i += priv->rx_cfg.num_queues * NUM_GVE_RX_CNTS;
354 }
David Awogbemila2f523dc2020-09-11 10:38:48 -0700355
356 /* For tx cross-reporting stats, start from nic tx stats in report */
357 base_stats_idx = max_stats_idx;
Shailend Chandaf9bcf92024-05-01 23:25:47 +0000358 max_stats_idx = NIC_TX_STATS_REPORT_NUM *
359 (num_tx_queues - num_stopped_txqs) +
David Awogbemila2f523dc2020-09-11 10:38:48 -0700360 max_stats_idx;
361 /* Preprocess the stats report for tx, map queue id to start index */
362 skip_nic_stats = false;
363 for (stats_idx = base_stats_idx; stats_idx < max_stats_idx;
364 stats_idx += NIC_TX_STATS_REPORT_NUM) {
365 u32 stat_name = be32_to_cpu(report_stats[stats_idx].stat_name);
366 u32 queue_id = be32_to_cpu(report_stats[stats_idx].queue_id);
367
368 if (stat_name == 0) {
369 /* no stats written by NIC yet */
370 skip_nic_stats = true;
371 break;
372 }
Shailend Chandaf9bcf92024-05-01 23:25:47 +0000373 if (queue_id < 0 || queue_id >= num_tx_queues) {
374 net_err_ratelimited("Invalid txq id in NIC stats\n");
375 continue;
376 }
David Awogbemila2f523dc2020-09-11 10:38:48 -0700377 tx_qid_to_stats_idx[queue_id] = stats_idx;
378 }
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700379 /* walk TX rings */
380 if (priv->tx) {
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700381 for (ring = 0; ring < num_tx_queues; ring++) {
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700382 struct gve_tx_ring *tx = &priv->tx[ring];
383
Bailey Forrest5e8c5ad2021-06-24 11:06:28 -0700384 if (gve_is_gqi(priv)) {
385 data[i++] = tx->req;
386 data[i++] = tx->done;
Jordan Kim2c919832021-12-15 16:46:51 -0800387 data[i++] = tx->req - tx->done;
Bailey Forrest5e8c5ad2021-06-24 11:06:28 -0700388 } else {
389 /* DQO doesn't currently support
390 * posted/completed descriptor counts;
391 */
392 data[i++] = 0;
393 data[i++] = 0;
Jordan Kim2c919832021-12-15 16:46:51 -0800394 data[i++] = tx->dqo_tx.tail - tx->dqo_tx.head;
Bailey Forrest5e8c5ad2021-06-24 11:06:28 -0700395 }
Kuo Zhao433e2742020-09-11 10:38:45 -0700396 do {
397 start =
Thomas Gleixner068c38a2022-10-26 15:22:14 +0200398 u64_stats_fetch_begin(&priv->tx[ring].statss);
Kuo Zhao433e2742020-09-11 10:38:45 -0700399 tmp_tx_bytes = tx->bytes_done;
Thomas Gleixner068c38a2022-10-26 15:22:14 +0200400 } while (u64_stats_fetch_retry(&priv->tx[ring].statss,
Kuo Zhao433e2742020-09-11 10:38:45 -0700401 start));
402 data[i++] = tmp_tx_bytes;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700403 data[i++] = tx->wake_queue;
404 data[i++] = tx->stop_queue;
Tao Liu61d72c7e2021-10-11 08:36:46 -0700405 data[i++] = gve_tx_load_event_counter(priv, tx);
Catherine Sullivan6f007c62020-12-07 14:45:26 -0800406 data[i++] = tx->dma_mapping_error;
David Awogbemila2f523dc2020-09-11 10:38:48 -0700407 /* stats from NIC */
Shailend Chandaf9bcf92024-05-01 23:25:47 +0000408 stats_idx = tx_qid_to_stats_idx[ring];
409 if (skip_nic_stats || stats_idx < 0) {
David Awogbemila2f523dc2020-09-11 10:38:48 -0700410 /* skip NIC tx stats */
411 i += NIC_TX_STATS_REPORT_NUM;
Praveen Kaligineedi39a7f4a2023-03-15 16:33:11 -0700412 } else {
Praveen Kaligineedi39a7f4a2023-03-15 16:33:11 -0700413 for (j = 0; j < NIC_TX_STATS_REPORT_NUM; j++) {
414 u64 value =
415 be64_to_cpu(report_stats[stats_idx + j].value);
416 data[i++] = value;
417 }
David Awogbemila2f523dc2020-09-11 10:38:48 -0700418 }
Praveen Kaligineedifd8e4032023-03-15 16:33:12 -0700419 /* XDP xsk counters */
420 data[i++] = tx->xdp_xsk_wakeup;
421 data[i++] = tx->xdp_xsk_done;
Praveen Kaligineedi39a7f4a2023-03-15 16:33:11 -0700422 do {
423 start = u64_stats_fetch_begin(&priv->tx[ring].statss);
Praveen Kaligineedifd8e4032023-03-15 16:33:12 -0700424 data[i] = tx->xdp_xsk_sent;
425 data[i + 1] = tx->xdp_xmit;
426 data[i + 2] = tx->xdp_xmit_errors;
Praveen Kaligineedi39a7f4a2023-03-15 16:33:11 -0700427 } while (u64_stats_fetch_retry(&priv->tx[ring].statss,
428 start));
Praveen Kaligineedifd8e4032023-03-15 16:33:12 -0700429 i += 3; /* XDP tx counters */
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700430 }
431 } else {
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700432 i += num_tx_queues * NUM_GVE_TX_CNTS;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700433 }
David Awogbemila2f523dc2020-09-11 10:38:48 -0700434
435 kfree(rx_qid_to_stats_idx);
436 kfree(tx_qid_to_stats_idx);
Kuo Zhao433e2742020-09-11 10:38:45 -0700437 /* AQ Stats */
438 data[i++] = priv->adminq_prod_cnt;
439 data[i++] = priv->adminq_cmd_fail;
440 data[i++] = priv->adminq_timeouts;
441 data[i++] = priv->adminq_describe_device_cnt;
442 data[i++] = priv->adminq_cfg_device_resources_cnt;
443 data[i++] = priv->adminq_register_page_list_cnt;
444 data[i++] = priv->adminq_unregister_page_list_cnt;
445 data[i++] = priv->adminq_create_tx_queue_cnt;
446 data[i++] = priv->adminq_create_rx_queue_cnt;
447 data[i++] = priv->adminq_destroy_tx_queue_cnt;
448 data[i++] = priv->adminq_destroy_rx_queue_cnt;
449 data[i++] = priv->adminq_dcfg_device_resources_cnt;
450 data[i++] = priv->adminq_set_driver_parameter_cnt;
Kuo Zhao24aeb562020-09-11 10:38:47 -0700451 data[i++] = priv->adminq_report_stats_cnt;
David Awogbemila7e074d52020-09-11 10:38:51 -0700452 data[i++] = priv->adminq_report_link_speed_cnt;
John Fraker3bcbc672024-03-25 15:33:08 -0700453 data[i++] = priv->adminq_get_ptype_map_cnt;
Jeroen de Borst57718b62024-06-25 00:12:30 +0000454 data[i++] = priv->adminq_query_flow_rules_cnt;
455 data[i++] = priv->adminq_cfg_flow_rule_cnt;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700456}
457
458static void gve_get_channels(struct net_device *netdev,
459 struct ethtool_channels *cmd)
460{
461 struct gve_priv *priv = netdev_priv(netdev);
462
463 cmd->max_rx = priv->rx_cfg.max_queues;
464 cmd->max_tx = priv->tx_cfg.max_queues;
465 cmd->max_other = 0;
466 cmd->max_combined = 0;
467 cmd->rx_count = priv->rx_cfg.num_queues;
468 cmd->tx_count = priv->tx_cfg.num_queues;
469 cmd->other_count = 0;
470 cmd->combined_count = 0;
471}
472
473static int gve_set_channels(struct net_device *netdev,
474 struct ethtool_channels *cmd)
475{
476 struct gve_priv *priv = netdev_priv(netdev);
477 struct gve_queue_config new_tx_cfg = priv->tx_cfg;
478 struct gve_queue_config new_rx_cfg = priv->rx_cfg;
479 struct ethtool_channels old_settings;
480 int new_tx = cmd->tx_count;
481 int new_rx = cmd->rx_count;
482
483 gve_get_channels(netdev, &old_settings);
484
Daode Huangf67435b2021-03-25 15:56:32 +0800485 /* Changing combined is not allowed */
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700486 if (cmd->combined_count != old_settings.combined_count)
487 return -EINVAL;
488
489 if (!new_rx || !new_tx)
490 return -EINVAL;
491
Praveen Kaligineedi75eaae12023-03-15 16:33:10 -0700492 if (priv->num_xdp_queues &&
493 (new_tx != new_rx || (2 * new_tx > priv->tx_cfg.max_queues))) {
494 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");
495 return -EINVAL;
496 }
497
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700498 if (!netif_carrier_ok(netdev)) {
499 priv->tx_cfg.num_queues = new_tx;
500 priv->rx_cfg.num_queues = new_rx;
501 return 0;
502 }
503
504 new_tx_cfg.num_queues = new_tx;
505 new_rx_cfg.num_queues = new_rx;
506
507 return gve_adjust_queues(priv, new_rx_cfg, new_tx_cfg);
508}
509
510static void gve_get_ringparam(struct net_device *netdev,
Hao Chen74624942021-11-18 20:12:43 +0800511 struct ethtool_ringparam *cmd,
512 struct kernel_ethtool_ringparam *kernel_cmd,
513 struct netlink_ext_ack *extack)
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700514{
515 struct gve_priv *priv = netdev_priv(netdev);
516
Harshitha Ramamurthy834f9452024-04-01 23:45:30 +0000517 cmd->rx_max_pending = priv->max_rx_desc_cnt;
518 cmd->tx_max_pending = priv->max_tx_desc_cnt;
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700519 cmd->rx_pending = priv->rx_desc_cnt;
520 cmd->tx_pending = priv->tx_desc_cnt;
Jeroen de Borst5e37d822024-02-29 13:22:35 -0800521
522 if (!gve_header_split_supported(priv))
523 kernel_cmd->tcp_data_split = ETHTOOL_TCP_DATA_SPLIT_UNKNOWN;
524 else if (priv->header_split_enabled)
525 kernel_cmd->tcp_data_split = ETHTOOL_TCP_DATA_SPLIT_ENABLED;
526 else
527 kernel_cmd->tcp_data_split = ETHTOOL_TCP_DATA_SPLIT_DISABLED;
528}
529
Harshitha Ramamurthy834f9452024-04-01 23:45:30 +0000530static int gve_adjust_ring_sizes(struct gve_priv *priv,
531 u16 new_tx_desc_cnt,
532 u16 new_rx_desc_cnt)
533{
534 struct gve_tx_alloc_rings_cfg tx_alloc_cfg = {0};
535 struct gve_rx_alloc_rings_cfg rx_alloc_cfg = {0};
Harshitha Ramamurthy834f9452024-04-01 23:45:30 +0000536 int err;
537
538 /* get current queue configuration */
Shailend Chandee242842024-05-01 23:25:48 +0000539 gve_get_curr_alloc_cfgs(priv, &tx_alloc_cfg, &rx_alloc_cfg);
Harshitha Ramamurthy834f9452024-04-01 23:45:30 +0000540
541 /* copy over the new ring_size from ethtool */
542 tx_alloc_cfg.ring_size = new_tx_desc_cnt;
543 rx_alloc_cfg.ring_size = new_rx_desc_cnt;
544
Harshitha Ramamurthy834f9452024-04-01 23:45:30 +0000545 if (netif_running(priv->dev)) {
Shailend Chandee242842024-05-01 23:25:48 +0000546 err = gve_adjust_config(priv, &tx_alloc_cfg, &rx_alloc_cfg);
Harshitha Ramamurthy834f9452024-04-01 23:45:30 +0000547 if (err)
548 return err;
549 }
550
551 /* Set new ring_size for the next up */
552 priv->tx_desc_cnt = new_tx_desc_cnt;
553 priv->rx_desc_cnt = new_rx_desc_cnt;
554
555 return 0;
556}
557
558static int gve_validate_req_ring_size(struct gve_priv *priv, u16 new_tx_desc_cnt,
559 u16 new_rx_desc_cnt)
560{
561 /* check for valid range */
562 if (new_tx_desc_cnt < priv->min_tx_desc_cnt ||
563 new_tx_desc_cnt > priv->max_tx_desc_cnt ||
564 new_rx_desc_cnt < priv->min_rx_desc_cnt ||
565 new_rx_desc_cnt > priv->max_rx_desc_cnt) {
566 dev_err(&priv->pdev->dev, "Requested descriptor count out of range\n");
567 return -EINVAL;
568 }
569
570 if (!is_power_of_2(new_tx_desc_cnt) || !is_power_of_2(new_rx_desc_cnt)) {
571 dev_err(&priv->pdev->dev, "Requested descriptor count has to be a power of 2\n");
572 return -EINVAL;
573 }
574 return 0;
575}
576
Jeroen de Borst5e37d822024-02-29 13:22:35 -0800577static int gve_set_ringparam(struct net_device *netdev,
578 struct ethtool_ringparam *cmd,
579 struct kernel_ethtool_ringparam *kernel_cmd,
580 struct netlink_ext_ack *extack)
581{
582 struct gve_priv *priv = netdev_priv(netdev);
Harshitha Ramamurthy834f9452024-04-01 23:45:30 +0000583 u16 new_tx_cnt, new_rx_cnt;
584 int err;
Jeroen de Borst5e37d822024-02-29 13:22:35 -0800585
Harshitha Ramamurthy834f9452024-04-01 23:45:30 +0000586 err = gve_set_hsplit_config(priv, kernel_cmd->tcp_data_split);
587 if (err)
588 return err;
589
590 if (cmd->tx_pending == priv->tx_desc_cnt && cmd->rx_pending == priv->rx_desc_cnt)
591 return 0;
592
593 if (!priv->modify_ring_size_enabled) {
594 dev_err(&priv->pdev->dev, "Modify ring size is not supported.\n");
Jeroen de Borst5e37d822024-02-29 13:22:35 -0800595 return -EOPNOTSUPP;
596 }
597
Harshitha Ramamurthy834f9452024-04-01 23:45:30 +0000598 new_tx_cnt = cmd->tx_pending;
599 new_rx_cnt = cmd->rx_pending;
600
601 if (gve_validate_req_ring_size(priv, new_tx_cnt, new_rx_cnt))
602 return -EINVAL;
603
604 return gve_adjust_ring_sizes(priv, new_tx_cnt, new_rx_cnt);
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700605}
606
607static int gve_user_reset(struct net_device *netdev, u32 *flags)
608{
609 struct gve_priv *priv = netdev_priv(netdev);
610
611 if (*flags == ETH_RESET_ALL) {
612 *flags = 0;
613 return gve_reset(priv, true);
614 }
615
616 return -EOPNOTSUPP;
617}
618
Kuo Zhaod5f75432020-09-11 10:38:44 -0700619static int gve_get_tunable(struct net_device *netdev,
620 const struct ethtool_tunable *etuna, void *value)
621{
622 struct gve_priv *priv = netdev_priv(netdev);
623
624 switch (etuna->id) {
625 case ETHTOOL_RX_COPYBREAK:
626 *(u32 *)value = priv->rx_copybreak;
627 return 0;
628 default:
629 return -EOPNOTSUPP;
630 }
631}
632
633static int gve_set_tunable(struct net_device *netdev,
Kuo Zhao433e2742020-09-11 10:38:45 -0700634 const struct ethtool_tunable *etuna,
635 const void *value)
Kuo Zhaod5f75432020-09-11 10:38:44 -0700636{
637 struct gve_priv *priv = netdev_priv(netdev);
638 u32 len;
639
640 switch (etuna->id) {
641 case ETHTOOL_RX_COPYBREAK:
Bailey Forrest1f6228e2021-06-24 11:06:27 -0700642 {
643 u32 max_copybreak = gve_is_gqi(priv) ?
John Frakerda7d4b42023-11-27 16:26:48 -0800644 GVE_DEFAULT_RX_BUFFER_SIZE : priv->data_buffer_size_dqo;
Bailey Forrest1f6228e2021-06-24 11:06:27 -0700645
Kuo Zhaod5f75432020-09-11 10:38:44 -0700646 len = *(u32 *)value;
Bailey Forrest1f6228e2021-06-24 11:06:27 -0700647 if (len > max_copybreak)
Kuo Zhaod5f75432020-09-11 10:38:44 -0700648 return -EINVAL;
649 priv->rx_copybreak = len;
650 return 0;
Bailey Forrest1f6228e2021-06-24 11:06:27 -0700651 }
Kuo Zhaod5f75432020-09-11 10:38:44 -0700652 default:
653 return -EOPNOTSUPP;
654 }
655}
656
Kuo Zhao24aeb562020-09-11 10:38:47 -0700657static u32 gve_get_priv_flags(struct net_device *netdev)
658{
659 struct gve_priv *priv = netdev_priv(netdev);
660 u32 ret_flags = 0;
661
662 /* Only 1 flag exists currently: report-stats (BIT(O)), so set that flag. */
663 if (priv->ethtool_flags & BIT(0))
664 ret_flags |= BIT(0);
665 return ret_flags;
666}
667
668static int gve_set_priv_flags(struct net_device *netdev, u32 flags)
669{
670 struct gve_priv *priv = netdev_priv(netdev);
671 u64 ori_flags, new_flags;
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700672 int num_tx_queues;
Kuo Zhao24aeb562020-09-11 10:38:47 -0700673
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700674 num_tx_queues = gve_num_tx_queues(priv);
Kuo Zhao24aeb562020-09-11 10:38:47 -0700675 ori_flags = READ_ONCE(priv->ethtool_flags);
676 new_flags = ori_flags;
677
678 /* Only one priv flag exists: report-stats (BIT(0))*/
679 if (flags & BIT(0))
680 new_flags |= BIT(0);
681 else
682 new_flags &= ~(BIT(0));
683 priv->ethtool_flags = new_flags;
684 /* start report-stats timer when user turns report stats on. */
685 if (flags & BIT(0)) {
686 mod_timer(&priv->stats_report_timer,
687 round_jiffies(jiffies +
688 msecs_to_jiffies(priv->stats_report_timer_period)));
689 }
690 /* Zero off gve stats when report-stats turned off and */
691 /* delete report stats timer. */
692 if (!(flags & BIT(0)) && (ori_flags & BIT(0))) {
693 int tx_stats_num = GVE_TX_STATS_REPORT_NUM *
Praveen Kaligineedi2e80aea2023-03-15 16:33:08 -0700694 num_tx_queues;
Kuo Zhao24aeb562020-09-11 10:38:47 -0700695 int rx_stats_num = GVE_RX_STATS_REPORT_NUM *
696 priv->rx_cfg.num_queues;
697
698 memset(priv->stats_report->stats, 0, (tx_stats_num + rx_stats_num) *
699 sizeof(struct stats));
700 del_timer_sync(&priv->stats_report_timer);
701 }
702 return 0;
703}
704
David Awogbemila7e074d52020-09-11 10:38:51 -0700705static int gve_get_link_ksettings(struct net_device *netdev,
706 struct ethtool_link_ksettings *cmd)
707{
708 struct gve_priv *priv = netdev_priv(netdev);
Joshua Washington68c3e4f2023-03-21 10:23:32 -0700709 int err = 0;
710
711 if (priv->link_speed == 0)
712 err = gve_adminq_report_link_speed(priv);
David Awogbemila7e074d52020-09-11 10:38:51 -0700713
714 cmd->base.speed = priv->link_speed;
Junfeng Guo0503efe2023-07-06 12:41:28 +0800715
716 cmd->base.duplex = DUPLEX_FULL;
717
David Awogbemila7e074d52020-09-11 10:38:51 -0700718 return err;
719}
720
Tao Liu6081ac22021-12-15 16:46:52 -0800721static int gve_get_coalesce(struct net_device *netdev,
722 struct ethtool_coalesce *ec,
723 struct kernel_ethtool_coalesce *kernel_ec,
724 struct netlink_ext_ack *extack)
725{
726 struct gve_priv *priv = netdev_priv(netdev);
727
728 if (gve_is_gqi(priv))
729 return -EOPNOTSUPP;
730 ec->tx_coalesce_usecs = priv->tx_coalesce_usecs;
731 ec->rx_coalesce_usecs = priv->rx_coalesce_usecs;
732
733 return 0;
734}
735
736static int gve_set_coalesce(struct net_device *netdev,
737 struct ethtool_coalesce *ec,
738 struct kernel_ethtool_coalesce *kernel_ec,
739 struct netlink_ext_ack *extack)
740{
741 struct gve_priv *priv = netdev_priv(netdev);
742 u32 tx_usecs_orig = priv->tx_coalesce_usecs;
743 u32 rx_usecs_orig = priv->rx_coalesce_usecs;
744 int idx;
745
746 if (gve_is_gqi(priv))
747 return -EOPNOTSUPP;
748
749 if (ec->tx_coalesce_usecs > GVE_MAX_ITR_INTERVAL_DQO ||
750 ec->rx_coalesce_usecs > GVE_MAX_ITR_INTERVAL_DQO)
751 return -EINVAL;
752 priv->tx_coalesce_usecs = ec->tx_coalesce_usecs;
753 priv->rx_coalesce_usecs = ec->rx_coalesce_usecs;
754
755 if (tx_usecs_orig != priv->tx_coalesce_usecs) {
756 for (idx = 0; idx < priv->tx_cfg.num_queues; idx++) {
757 int ntfy_idx = gve_tx_idx_to_ntfy(priv, idx);
758 struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx];
759
760 gve_set_itr_coalesce_usecs_dqo(priv, block,
761 priv->tx_coalesce_usecs);
762 }
763 }
764
765 if (rx_usecs_orig != priv->rx_coalesce_usecs) {
766 for (idx = 0; idx < priv->rx_cfg.num_queues; idx++) {
767 int ntfy_idx = gve_rx_idx_to_ntfy(priv, idx);
768 struct gve_notify_block *block = &priv->ntfy_blocks[ntfy_idx];
769
770 gve_set_itr_coalesce_usecs_dqo(priv, block,
771 priv->rx_coalesce_usecs);
772 }
773 }
774
775 return 0;
776}
777
Jeroen de Borst6f3bc482024-06-25 00:12:31 +0000778static int gve_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
779{
780 struct gve_priv *priv = netdev_priv(netdev);
781 int err = 0;
782
783 if (!(netdev->features & NETIF_F_NTUPLE))
784 return -EOPNOTSUPP;
785
786 switch (cmd->cmd) {
787 case ETHTOOL_SRXCLSRLINS:
788 err = gve_add_flow_rule(priv, cmd);
789 break;
790 case ETHTOOL_SRXCLSRLDEL:
791 err = gve_del_flow_rule(priv, cmd);
792 break;
793 case ETHTOOL_SRXFH:
794 err = -EOPNOTSUPP;
795 break;
796 default:
797 err = -EOPNOTSUPP;
798 break;
799 }
800
801 return err;
802}
803
804static int gve_get_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd, u32 *rule_locs)
805{
806 struct gve_priv *priv = netdev_priv(netdev);
807 int err = 0;
808
809 switch (cmd->cmd) {
810 case ETHTOOL_GRXRINGS:
811 cmd->data = priv->rx_cfg.num_queues;
812 break;
813 case ETHTOOL_GRXCLSRLCNT:
814 if (!priv->max_flow_rules)
815 return -EOPNOTSUPP;
816
817 err = gve_adminq_query_flow_rules(priv, GVE_FLOW_RULE_QUERY_STATS, 0);
818 if (err)
819 return err;
820
821 cmd->rule_cnt = priv->num_flow_rules;
822 cmd->data = priv->max_flow_rules;
823 break;
824 case ETHTOOL_GRXCLSRULE:
825 err = gve_get_flow_rule_entry(priv, cmd);
826 break;
827 case ETHTOOL_GRXCLSRLALL:
828 err = gve_get_flow_rule_ids(priv, cmd, (u32 *)rule_locs);
829 break;
830 case ETHTOOL_GRXFH:
831 err = -EOPNOTSUPP;
832 break;
833 default:
834 err = -EOPNOTSUPP;
835 break;
836 }
837
838 return err;
839}
840
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700841const struct ethtool_ops gve_ethtool_ops = {
Tao Liu6081ac22021-12-15 16:46:52 -0800842 .supported_coalesce_params = ETHTOOL_COALESCE_USECS,
Jeroen de Borst5e37d822024-02-29 13:22:35 -0800843 .supported_ring_params = ETHTOOL_RING_USE_TCP_DATA_SPLIT,
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700844 .get_drvinfo = gve_get_drvinfo,
845 .get_strings = gve_get_strings,
846 .get_sset_count = gve_get_sset_count,
847 .get_ethtool_stats = gve_get_ethtool_stats,
848 .set_msglevel = gve_set_msglevel,
849 .get_msglevel = gve_get_msglevel,
850 .set_channels = gve_set_channels,
851 .get_channels = gve_get_channels,
Jeroen de Borst6f3bc482024-06-25 00:12:31 +0000852 .set_rxnfc = gve_set_rxnfc,
853 .get_rxnfc = gve_get_rxnfc,
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700854 .get_link = ethtool_op_get_link,
Tao Liu6081ac22021-12-15 16:46:52 -0800855 .get_coalesce = gve_get_coalesce,
856 .set_coalesce = gve_set_coalesce,
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700857 .get_ringparam = gve_get_ringparam,
Jeroen de Borst5e37d822024-02-29 13:22:35 -0800858 .set_ringparam = gve_set_ringparam,
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700859 .reset = gve_user_reset,
Kuo Zhaod5f75432020-09-11 10:38:44 -0700860 .get_tunable = gve_get_tunable,
861 .set_tunable = gve_set_tunable,
Kuo Zhao24aeb562020-09-11 10:38:47 -0700862 .get_priv_flags = gve_get_priv_flags,
863 .set_priv_flags = gve_set_priv_flags,
John Fraker4ca78e62024-04-11 22:32:29 -0700864 .get_link_ksettings = gve_get_link_ksettings,
865 .get_ts_info = ethtool_op_get_ts_info,
Catherine Sullivane5b845dc2019-07-01 15:57:55 -0700866};