1 // SPDX-License-Identifier: GPL-2.0+
2 // Copyright (c) 2016-2017 Hisilicon Limited.
3
4 #include <linux/etherdevice.h>
5 #include <linux/string.h>
6 #include <linux/phy.h>
7 #include <linux/sfp.h>
8
9 #include "hns3_enet.h"
10 #include "hns3_ethtool.h"
11
12 /* tqp related stats */
13 #define HNS3_TQP_STAT(_string, _member) { \
14 .stats_string = _string, \
15 .stats_offset = offsetof(struct hns3_enet_ring, stats) +\
16 offsetof(struct ring_stats, _member), \
17 }
18
19 static const struct hns3_stats hns3_txq_stats[] = {
20 /* Tx per-queue statistics */
21 HNS3_TQP_STAT("dropped", sw_err_cnt),
22 HNS3_TQP_STAT("seg_pkt_cnt", seg_pkt_cnt),
23 HNS3_TQP_STAT("packets", tx_pkts),
24 HNS3_TQP_STAT("bytes", tx_bytes),
25 HNS3_TQP_STAT("more", tx_more),
26 HNS3_TQP_STAT("push", tx_push),
27 HNS3_TQP_STAT("mem_doorbell", tx_mem_doorbell),
28 HNS3_TQP_STAT("wake", restart_queue),
29 HNS3_TQP_STAT("busy", tx_busy),
30 HNS3_TQP_STAT("copy", tx_copy),
31 HNS3_TQP_STAT("vlan_err", tx_vlan_err),
32 HNS3_TQP_STAT("l4_proto_err", tx_l4_proto_err),
33 HNS3_TQP_STAT("l2l3l4_err", tx_l2l3l4_err),
34 HNS3_TQP_STAT("tso_err", tx_tso_err),
35 HNS3_TQP_STAT("over_max_recursion", over_max_recursion),
36 HNS3_TQP_STAT("hw_limitation", hw_limitation),
37 HNS3_TQP_STAT("bounce", tx_bounce),
38 HNS3_TQP_STAT("spare_full", tx_spare_full),
39 HNS3_TQP_STAT("copy_bits_err", copy_bits_err),
40 HNS3_TQP_STAT("sgl", tx_sgl),
41 HNS3_TQP_STAT("skb2sgl_err", skb2sgl_err),
42 HNS3_TQP_STAT("map_sg_err", map_sg_err),
43 };
44
45 #define HNS3_TXQ_STATS_COUNT ARRAY_SIZE(hns3_txq_stats)
46
47 static const struct hns3_stats hns3_rxq_stats[] = {
48 /* Rx per-queue statistics */
49 HNS3_TQP_STAT("dropped", sw_err_cnt),
50 HNS3_TQP_STAT("seg_pkt_cnt", seg_pkt_cnt),
51 HNS3_TQP_STAT("packets", rx_pkts),
52 HNS3_TQP_STAT("bytes", rx_bytes),
53 HNS3_TQP_STAT("errors", rx_err_cnt),
54 HNS3_TQP_STAT("reuse_pg_cnt", reuse_pg_cnt),
55 HNS3_TQP_STAT("err_pkt_len", err_pkt_len),
56 HNS3_TQP_STAT("err_bd_num", err_bd_num),
57 HNS3_TQP_STAT("l2_err", l2_err),
58 HNS3_TQP_STAT("l3l4_csum_err", l3l4_csum_err),
59 HNS3_TQP_STAT("csum_complete", csum_complete),
60 HNS3_TQP_STAT("multicast", rx_multicast),
61 HNS3_TQP_STAT("non_reuse_pg", non_reuse_pg),
62 HNS3_TQP_STAT("frag_alloc_err", frag_alloc_err),
63 HNS3_TQP_STAT("frag_alloc", frag_alloc),
64 };
65
66 #define HNS3_PRIV_FLAGS_LEN ARRAY_SIZE(hns3_priv_flags)
67
68 #define HNS3_RXQ_STATS_COUNT ARRAY_SIZE(hns3_rxq_stats)
69
70 #define HNS3_TQP_STATS_COUNT (HNS3_TXQ_STATS_COUNT + HNS3_RXQ_STATS_COUNT)
71
72 #define HNS3_NIC_LB_TEST_PKT_NUM 1
73 #define HNS3_NIC_LB_TEST_RING_ID 0
74 #define HNS3_NIC_LB_TEST_PACKET_SIZE 128
75 #define HNS3_NIC_LB_SETUP_USEC 10000
76
77 /* Nic loopback test err */
78 #define HNS3_NIC_LB_TEST_NO_MEM_ERR 1
79 #define HNS3_NIC_LB_TEST_TX_CNT_ERR 2
80 #define HNS3_NIC_LB_TEST_RX_CNT_ERR 3
81
hns3_lp_setup(struct net_device * ndev,enum hnae3_loop loop,bool en)82 static int hns3_lp_setup(struct net_device *ndev, enum hnae3_loop loop, bool en)
83 {
84 struct hnae3_handle *h = hns3_get_handle(ndev);
85 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
86 int ret;
87
88 if (!h->ae_algo->ops->set_loopback ||
89 !h->ae_algo->ops->set_promisc_mode)
90 return -EOPNOTSUPP;
91
92 switch (loop) {
93 case HNAE3_LOOP_SERIAL_SERDES:
94 case HNAE3_LOOP_PARALLEL_SERDES:
95 case HNAE3_LOOP_APP:
96 case HNAE3_LOOP_PHY:
97 case HNAE3_LOOP_EXTERNAL:
98 ret = h->ae_algo->ops->set_loopback(h, loop, en);
99 break;
100 default:
101 ret = -ENOTSUPP;
102 break;
103 }
104
105 if (ret || ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V2)
106 return ret;
107
108 if (en)
109 h->ae_algo->ops->set_promisc_mode(h, true, true);
110 else
111 /* recover promisc mode before loopback test */
112 hns3_request_update_promisc_mode(h);
113
114 return ret;
115 }
116
hns3_lp_up(struct net_device * ndev,enum hnae3_loop loop_mode)117 static int hns3_lp_up(struct net_device *ndev, enum hnae3_loop loop_mode)
118 {
119 struct hnae3_handle *h = hns3_get_handle(ndev);
120 int ret;
121
122 ret = hns3_nic_reset_all_ring(h);
123 if (ret)
124 return ret;
125
126 ret = hns3_lp_setup(ndev, loop_mode, true);
127 usleep_range(HNS3_NIC_LB_SETUP_USEC, HNS3_NIC_LB_SETUP_USEC * 2);
128
129 return ret;
130 }
131
hns3_lp_down(struct net_device * ndev,enum hnae3_loop loop_mode)132 static int hns3_lp_down(struct net_device *ndev, enum hnae3_loop loop_mode)
133 {
134 int ret;
135
136 ret = hns3_lp_setup(ndev, loop_mode, false);
137 if (ret) {
138 netdev_err(ndev, "lb_setup return error: %d\n", ret);
139 return ret;
140 }
141
142 usleep_range(HNS3_NIC_LB_SETUP_USEC, HNS3_NIC_LB_SETUP_USEC * 2);
143
144 return 0;
145 }
146
hns3_lp_setup_skb(struct sk_buff * skb)147 static void hns3_lp_setup_skb(struct sk_buff *skb)
148 {
149 #define HNS3_NIC_LB_DST_MAC_ADDR 0x1f
150
151 struct net_device *ndev = skb->dev;
152 struct hnae3_handle *handle;
153 struct hnae3_ae_dev *ae_dev;
154 unsigned char *packet;
155 struct ethhdr *ethh;
156 unsigned int i;
157
158 skb_reserve(skb, NET_IP_ALIGN);
159 ethh = skb_put(skb, sizeof(struct ethhdr));
160 packet = skb_put(skb, HNS3_NIC_LB_TEST_PACKET_SIZE);
161
162 memcpy(ethh->h_dest, ndev->dev_addr, ETH_ALEN);
163
164 /* The dst mac addr of loopback packet is the same as the host'
165 * mac addr, the SSU component may loop back the packet to host
166 * before the packet reaches mac or serdes, which will defect
167 * the purpose of mac or serdes selftest.
168 */
169 handle = hns3_get_handle(ndev);
170 ae_dev = pci_get_drvdata(handle->pdev);
171 if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2)
172 ethh->h_dest[5] += HNS3_NIC_LB_DST_MAC_ADDR;
173 eth_zero_addr(ethh->h_source);
174 ethh->h_proto = htons(ETH_P_ARP);
175 skb_reset_mac_header(skb);
176
177 for (i = 0; i < HNS3_NIC_LB_TEST_PACKET_SIZE; i++)
178 packet[i] = (unsigned char)(i & 0xff);
179 }
180
hns3_lb_check_skb_data(struct hns3_enet_ring * ring,struct sk_buff * skb)181 static void hns3_lb_check_skb_data(struct hns3_enet_ring *ring,
182 struct sk_buff *skb)
183 {
184 struct hns3_enet_tqp_vector *tqp_vector = ring->tqp_vector;
185 unsigned char *packet = skb->data;
186 u32 len = skb_headlen(skb);
187 u32 i;
188
189 len = min_t(u32, len, HNS3_NIC_LB_TEST_PACKET_SIZE);
190
191 for (i = 0; i < len; i++)
192 if (packet[i] != (unsigned char)(i & 0xff))
193 break;
194
195 /* The packet is correctly received */
196 if (i == HNS3_NIC_LB_TEST_PACKET_SIZE)
197 tqp_vector->rx_group.total_packets++;
198 else
199 print_hex_dump(KERN_ERR, "selftest:", DUMP_PREFIX_OFFSET, 16, 1,
200 skb->data, len, true);
201
202 dev_kfree_skb_any(skb);
203 }
204
hns3_lb_check_rx_ring(struct hns3_nic_priv * priv,u32 budget)205 static u32 hns3_lb_check_rx_ring(struct hns3_nic_priv *priv, u32 budget)
206 {
207 struct hnae3_handle *h = priv->ae_handle;
208 struct hnae3_knic_private_info *kinfo;
209 u32 i, rcv_good_pkt_total = 0;
210
211 kinfo = &h->kinfo;
212 for (i = kinfo->num_tqps; i < kinfo->num_tqps * 2; i++) {
213 struct hns3_enet_ring *ring = &priv->ring[i];
214 struct hns3_enet_ring_group *rx_group;
215 u64 pre_rx_pkt;
216
217 rx_group = &ring->tqp_vector->rx_group;
218 pre_rx_pkt = rx_group->total_packets;
219
220 preempt_disable();
221 hns3_clean_rx_ring(ring, budget, hns3_lb_check_skb_data);
222 preempt_enable();
223
224 rcv_good_pkt_total += (rx_group->total_packets - pre_rx_pkt);
225 rx_group->total_packets = pre_rx_pkt;
226 }
227 return rcv_good_pkt_total;
228 }
229
hns3_lb_clear_tx_ring(struct hns3_nic_priv * priv,u32 start_ringid,u32 end_ringid)230 static void hns3_lb_clear_tx_ring(struct hns3_nic_priv *priv, u32 start_ringid,
231 u32 end_ringid)
232 {
233 u32 i;
234
235 for (i = start_ringid; i <= end_ringid; i++) {
236 struct hns3_enet_ring *ring = &priv->ring[i];
237
238 hns3_clean_tx_ring(ring, 0);
239 }
240 }
241
242 /**
243 * hns3_lp_run_test - run loopback test
244 * @ndev: net device
245 * @mode: loopback type
246 *
247 * Return: %0 for success or a NIC loopback test error code on failure
248 */
hns3_lp_run_test(struct net_device * ndev,enum hnae3_loop mode)249 static int hns3_lp_run_test(struct net_device *ndev, enum hnae3_loop mode)
250 {
251 struct hns3_nic_priv *priv = netdev_priv(ndev);
252 struct sk_buff *skb;
253 u32 i, good_cnt;
254 int ret_val = 0;
255
256 skb = alloc_skb(HNS3_NIC_LB_TEST_PACKET_SIZE + ETH_HLEN + NET_IP_ALIGN,
257 GFP_KERNEL);
258 if (!skb)
259 return HNS3_NIC_LB_TEST_NO_MEM_ERR;
260
261 skb->dev = ndev;
262 hns3_lp_setup_skb(skb);
263 skb->queue_mapping = HNS3_NIC_LB_TEST_RING_ID;
264
265 good_cnt = 0;
266 for (i = 0; i < HNS3_NIC_LB_TEST_PKT_NUM; i++) {
267 netdev_tx_t tx_ret;
268
269 skb_get(skb);
270 tx_ret = hns3_nic_net_xmit(skb, ndev);
271 if (tx_ret == NETDEV_TX_OK) {
272 good_cnt++;
273 } else {
274 kfree_skb(skb);
275 netdev_err(ndev, "hns3_lb_run_test xmit failed: %d\n",
276 tx_ret);
277 }
278 }
279 if (good_cnt != HNS3_NIC_LB_TEST_PKT_NUM) {
280 ret_val = HNS3_NIC_LB_TEST_TX_CNT_ERR;
281 netdev_err(ndev, "mode %d sent fail, cnt=0x%x, budget=0x%x\n",
282 mode, good_cnt, HNS3_NIC_LB_TEST_PKT_NUM);
283 goto out;
284 }
285
286 /* Allow 200 milliseconds for packets to go from Tx to Rx */
287 msleep(200);
288
289 good_cnt = hns3_lb_check_rx_ring(priv, HNS3_NIC_LB_TEST_PKT_NUM);
290 if (good_cnt != HNS3_NIC_LB_TEST_PKT_NUM) {
291 ret_val = HNS3_NIC_LB_TEST_RX_CNT_ERR;
292 netdev_err(ndev, "mode %d recv fail, cnt=0x%x, budget=0x%x\n",
293 mode, good_cnt, HNS3_NIC_LB_TEST_PKT_NUM);
294 }
295
296 out:
297 hns3_lb_clear_tx_ring(priv, HNS3_NIC_LB_TEST_RING_ID,
298 HNS3_NIC_LB_TEST_RING_ID);
299
300 kfree_skb(skb);
301 return ret_val;
302 }
303
hns3_set_selftest_param(struct hnae3_handle * h,int (* st_param)[2])304 static void hns3_set_selftest_param(struct hnae3_handle *h, int (*st_param)[2])
305 {
306 st_param[HNAE3_LOOP_EXTERNAL][0] = HNAE3_LOOP_EXTERNAL;
307 st_param[HNAE3_LOOP_EXTERNAL][1] =
308 h->flags & HNAE3_SUPPORT_EXTERNAL_LOOPBACK;
309
310 st_param[HNAE3_LOOP_APP][0] = HNAE3_LOOP_APP;
311 st_param[HNAE3_LOOP_APP][1] =
312 h->flags & HNAE3_SUPPORT_APP_LOOPBACK;
313
314 st_param[HNAE3_LOOP_SERIAL_SERDES][0] = HNAE3_LOOP_SERIAL_SERDES;
315 st_param[HNAE3_LOOP_SERIAL_SERDES][1] =
316 h->flags & HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK;
317
318 st_param[HNAE3_LOOP_PARALLEL_SERDES][0] =
319 HNAE3_LOOP_PARALLEL_SERDES;
320 st_param[HNAE3_LOOP_PARALLEL_SERDES][1] =
321 h->flags & HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK;
322
323 st_param[HNAE3_LOOP_PHY][0] = HNAE3_LOOP_PHY;
324 st_param[HNAE3_LOOP_PHY][1] =
325 h->flags & HNAE3_SUPPORT_PHY_LOOPBACK;
326 }
327
hns3_selftest_prepare(struct net_device * ndev,bool if_running)328 static void hns3_selftest_prepare(struct net_device *ndev, bool if_running)
329 {
330 struct hns3_nic_priv *priv = netdev_priv(ndev);
331 struct hnae3_handle *h = priv->ae_handle;
332
333 if (if_running)
334 ndev->netdev_ops->ndo_stop(ndev);
335
336 #if IS_ENABLED(CONFIG_VLAN_8021Q)
337 /* Disable the vlan filter for selftest does not support it */
338 if (h->ae_algo->ops->enable_vlan_filter &&
339 ndev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
340 h->ae_algo->ops->enable_vlan_filter(h, false);
341 #endif
342
343 /* Tell firmware to stop mac autoneg before loopback test start,
344 * otherwise loopback test may be failed when the port is still
345 * negotiating.
346 */
347 if (h->ae_algo->ops->halt_autoneg)
348 h->ae_algo->ops->halt_autoneg(h, true);
349
350 set_bit(HNS3_NIC_STATE_TESTING, &priv->state);
351 }
352
hns3_selftest_restore(struct net_device * ndev,bool if_running)353 static void hns3_selftest_restore(struct net_device *ndev, bool if_running)
354 {
355 struct hns3_nic_priv *priv = netdev_priv(ndev);
356 struct hnae3_handle *h = priv->ae_handle;
357
358 clear_bit(HNS3_NIC_STATE_TESTING, &priv->state);
359
360 if (h->ae_algo->ops->halt_autoneg)
361 h->ae_algo->ops->halt_autoneg(h, false);
362
363 #if IS_ENABLED(CONFIG_VLAN_8021Q)
364 if (h->ae_algo->ops->enable_vlan_filter &&
365 ndev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
366 h->ae_algo->ops->enable_vlan_filter(h, true);
367 #endif
368
369 if (if_running)
370 ndev->netdev_ops->ndo_open(ndev);
371 }
372
hns3_do_selftest(struct net_device * ndev,int (* st_param)[2],struct ethtool_test * eth_test,u64 * data)373 static void hns3_do_selftest(struct net_device *ndev, int (*st_param)[2],
374 struct ethtool_test *eth_test, u64 *data)
375 {
376 int test_index = HNAE3_LOOP_APP;
377 u32 i;
378
379 for (i = HNAE3_LOOP_APP; i < HNAE3_LOOP_NONE; i++) {
380 enum hnae3_loop loop_type = (enum hnae3_loop)st_param[i][0];
381
382 if (!st_param[i][1])
383 continue;
384
385 data[test_index] = hns3_lp_up(ndev, loop_type);
386 if (!data[test_index])
387 data[test_index] = hns3_lp_run_test(ndev, loop_type);
388
389 hns3_lp_down(ndev, loop_type);
390
391 if (data[test_index])
392 eth_test->flags |= ETH_TEST_FL_FAILED;
393
394 test_index++;
395 }
396 }
397
hns3_do_external_lb(struct net_device * ndev,struct ethtool_test * eth_test,u64 * data)398 static void hns3_do_external_lb(struct net_device *ndev,
399 struct ethtool_test *eth_test, u64 *data)
400 {
401 data[HNAE3_LOOP_EXTERNAL] = hns3_lp_up(ndev, HNAE3_LOOP_EXTERNAL);
402 if (!data[HNAE3_LOOP_EXTERNAL])
403 data[HNAE3_LOOP_EXTERNAL] = hns3_lp_run_test(ndev, HNAE3_LOOP_EXTERNAL);
404 hns3_lp_down(ndev, HNAE3_LOOP_EXTERNAL);
405
406 if (data[HNAE3_LOOP_EXTERNAL])
407 eth_test->flags |= ETH_TEST_FL_FAILED;
408
409 eth_test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
410 }
411
412 /**
413 * hns3_self_test - self test
414 * @ndev: net device
415 * @eth_test: test cmd
416 * @data: test result
417 */
hns3_self_test(struct net_device * ndev,struct ethtool_test * eth_test,u64 * data)418 static void hns3_self_test(struct net_device *ndev,
419 struct ethtool_test *eth_test, u64 *data)
420 {
421 struct hns3_nic_priv *priv = netdev_priv(ndev);
422 struct hnae3_handle *h = priv->ae_handle;
423 int st_param[HNAE3_LOOP_NONE][2];
424 bool if_running = netif_running(ndev);
425
426 if (hns3_nic_resetting(ndev)) {
427 netdev_err(ndev, "dev resetting!");
428 return;
429 }
430
431 if (!(eth_test->flags & ETH_TEST_FL_OFFLINE))
432 return;
433
434 if (netif_msg_ifdown(h))
435 netdev_info(ndev, "self test start\n");
436
437 hns3_set_selftest_param(h, st_param);
438
439 /* external loopback test requires that the link is up and the duplex is
440 * full, do external test first to reduce the whole test time
441 */
442 if (eth_test->flags & ETH_TEST_FL_EXTERNAL_LB) {
443 hns3_external_lb_prepare(ndev, if_running);
444 hns3_do_external_lb(ndev, eth_test, data);
445 hns3_external_lb_restore(ndev, if_running);
446 }
447
448 hns3_selftest_prepare(ndev, if_running);
449 hns3_do_selftest(ndev, st_param, eth_test, data);
450 hns3_selftest_restore(ndev, if_running);
451
452 if (netif_msg_ifdown(h))
453 netdev_info(ndev, "self test end\n");
454 }
455
hns3_update_limit_promisc_mode(struct net_device * netdev,bool enable)456 static void hns3_update_limit_promisc_mode(struct net_device *netdev,
457 bool enable)
458 {
459 struct hnae3_handle *handle = hns3_get_handle(netdev);
460
461 if (enable)
462 set_bit(HNAE3_PFLAG_LIMIT_PROMISC, &handle->priv_flags);
463 else
464 clear_bit(HNAE3_PFLAG_LIMIT_PROMISC, &handle->priv_flags);
465
466 hns3_request_update_promisc_mode(handle);
467 }
468
469 static const struct hns3_pflag_desc hns3_priv_flags[HNAE3_PFLAG_MAX] = {
470 { "limit_promisc", hns3_update_limit_promisc_mode }
471 };
472
hns3_get_sset_count(struct net_device * netdev,int stringset)473 static int hns3_get_sset_count(struct net_device *netdev, int stringset)
474 {
475 struct hnae3_handle *h = hns3_get_handle(netdev);
476 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
477
478 if (!ops->get_sset_count)
479 return -EOPNOTSUPP;
480
481 switch (stringset) {
482 case ETH_SS_STATS:
483 return ((HNS3_TQP_STATS_COUNT * h->kinfo.num_tqps) +
484 ops->get_sset_count(h, stringset));
485
486 case ETH_SS_TEST:
487 return ops->get_sset_count(h, stringset);
488
489 case ETH_SS_PRIV_FLAGS:
490 return HNAE3_PFLAG_MAX;
491
492 default:
493 return -EOPNOTSUPP;
494 }
495 }
496
hns3_update_strings(u8 * data,const struct hns3_stats * stats,u32 stat_count,u32 num_tqps,const char * prefix)497 static void *hns3_update_strings(u8 *data, const struct hns3_stats *stats,
498 u32 stat_count, u32 num_tqps, const char *prefix)
499 {
500 #define MAX_PREFIX_SIZE (6 + 4)
501 u32 size_left;
502 u32 i, j;
503 u32 n1;
504
505 for (i = 0; i < num_tqps; i++) {
506 for (j = 0; j < stat_count; j++) {
507 data[ETH_GSTRING_LEN - 1] = '\0';
508
509 /* first, prepend the prefix string */
510 n1 = scnprintf(data, MAX_PREFIX_SIZE, "%s%u_",
511 prefix, i);
512 size_left = (ETH_GSTRING_LEN - 1) - n1;
513
514 /* now, concatenate the stats string to it */
515 strncat(data, stats[j].stats_string, size_left);
516 data += ETH_GSTRING_LEN;
517 }
518 }
519
520 return data;
521 }
522
hns3_get_strings_tqps(struct hnae3_handle * handle,u8 * data)523 static u8 *hns3_get_strings_tqps(struct hnae3_handle *handle, u8 *data)
524 {
525 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
526 const char tx_prefix[] = "txq";
527 const char rx_prefix[] = "rxq";
528
529 /* get strings for Tx */
530 data = hns3_update_strings(data, hns3_txq_stats, HNS3_TXQ_STATS_COUNT,
531 kinfo->num_tqps, tx_prefix);
532
533 /* get strings for Rx */
534 data = hns3_update_strings(data, hns3_rxq_stats, HNS3_RXQ_STATS_COUNT,
535 kinfo->num_tqps, rx_prefix);
536
537 return data;
538 }
539
hns3_get_strings(struct net_device * netdev,u32 stringset,u8 * data)540 static void hns3_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
541 {
542 struct hnae3_handle *h = hns3_get_handle(netdev);
543 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
544 char *buff = (char *)data;
545 int i;
546
547 if (!ops->get_strings)
548 return;
549
550 switch (stringset) {
551 case ETH_SS_STATS:
552 buff = hns3_get_strings_tqps(h, buff);
553 ops->get_strings(h, stringset, (u8 *)buff);
554 break;
555 case ETH_SS_TEST:
556 ops->get_strings(h, stringset, data);
557 break;
558 case ETH_SS_PRIV_FLAGS:
559 for (i = 0; i < HNS3_PRIV_FLAGS_LEN; i++) {
560 snprintf(buff, ETH_GSTRING_LEN, "%s",
561 hns3_priv_flags[i].name);
562 buff += ETH_GSTRING_LEN;
563 }
564 break;
565 default:
566 break;
567 }
568 }
569
hns3_get_stats_tqps(struct hnae3_handle * handle,u64 * data)570 static u64 *hns3_get_stats_tqps(struct hnae3_handle *handle, u64 *data)
571 {
572 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
573 struct hns3_nic_priv *nic_priv = handle->priv;
574 struct hns3_enet_ring *ring;
575 u8 *stat;
576 int i, j;
577
578 /* get stats for Tx */
579 for (i = 0; i < kinfo->num_tqps; i++) {
580 ring = &nic_priv->ring[i];
581 for (j = 0; j < HNS3_TXQ_STATS_COUNT; j++) {
582 stat = (u8 *)ring + hns3_txq_stats[j].stats_offset;
583 *data++ = *(u64 *)stat;
584 }
585 }
586
587 /* get stats for Rx */
588 for (i = 0; i < kinfo->num_tqps; i++) {
589 ring = &nic_priv->ring[i + kinfo->num_tqps];
590 for (j = 0; j < HNS3_RXQ_STATS_COUNT; j++) {
591 stat = (u8 *)ring + hns3_rxq_stats[j].stats_offset;
592 *data++ = *(u64 *)stat;
593 }
594 }
595
596 return data;
597 }
598
599 /* hns3_get_stats - get detail statistics.
600 * @netdev: net device
601 * @stats: statistics info.
602 * @data: statistics data.
603 */
hns3_get_stats(struct net_device * netdev,struct ethtool_stats * stats,u64 * data)604 static void hns3_get_stats(struct net_device *netdev,
605 struct ethtool_stats *stats, u64 *data)
606 {
607 struct hnae3_handle *h = hns3_get_handle(netdev);
608 u64 *p = data;
609
610 if (hns3_nic_resetting(netdev)) {
611 netdev_err(netdev, "dev resetting, could not get stats\n");
612 return;
613 }
614
615 if (!h->ae_algo->ops->get_stats || !h->ae_algo->ops->update_stats) {
616 netdev_err(netdev, "could not get any statistics\n");
617 return;
618 }
619
620 h->ae_algo->ops->update_stats(h);
621
622 /* get per-queue stats */
623 p = hns3_get_stats_tqps(h, p);
624
625 /* get MAC & other misc hardware stats */
626 h->ae_algo->ops->get_stats(h, p);
627 }
628
hns3_get_drvinfo(struct net_device * netdev,struct ethtool_drvinfo * drvinfo)629 static void hns3_get_drvinfo(struct net_device *netdev,
630 struct ethtool_drvinfo *drvinfo)
631 {
632 struct hns3_nic_priv *priv = netdev_priv(netdev);
633 struct hnae3_handle *h = priv->ae_handle;
634 u32 fw_version;
635
636 if (!h->ae_algo->ops->get_fw_version) {
637 netdev_err(netdev, "could not get fw version!\n");
638 return;
639 }
640
641 strscpy(drvinfo->driver, dev_driver_string(&h->pdev->dev),
642 sizeof(drvinfo->driver));
643
644 strscpy(drvinfo->bus_info, pci_name(h->pdev),
645 sizeof(drvinfo->bus_info));
646
647 fw_version = priv->ae_handle->ae_algo->ops->get_fw_version(h);
648
649 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
650 "%lu.%lu.%lu.%lu",
651 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE3_MASK,
652 HNAE3_FW_VERSION_BYTE3_SHIFT),
653 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE2_MASK,
654 HNAE3_FW_VERSION_BYTE2_SHIFT),
655 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE1_MASK,
656 HNAE3_FW_VERSION_BYTE1_SHIFT),
657 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE0_MASK,
658 HNAE3_FW_VERSION_BYTE0_SHIFT));
659 }
660
hns3_get_link(struct net_device * netdev)661 static u32 hns3_get_link(struct net_device *netdev)
662 {
663 struct hnae3_handle *h = hns3_get_handle(netdev);
664
665 if (h->ae_algo->ops->get_status)
666 return h->ae_algo->ops->get_status(h);
667 else
668 return 0;
669 }
670
hns3_get_ringparam(struct net_device * netdev,struct ethtool_ringparam * param,struct kernel_ethtool_ringparam * kernel_param,struct netlink_ext_ack * extack)671 static void hns3_get_ringparam(struct net_device *netdev,
672 struct ethtool_ringparam *param,
673 struct kernel_ethtool_ringparam *kernel_param,
674 struct netlink_ext_ack *extack)
675 {
676 struct hns3_nic_priv *priv = netdev_priv(netdev);
677 struct hnae3_handle *h = priv->ae_handle;
678 int rx_queue_index = h->kinfo.num_tqps;
679
680 if (hns3_nic_resetting(netdev) || !priv->ring) {
681 netdev_err(netdev, "failed to get ringparam value, due to dev resetting or uninited\n");
682 return;
683 }
684
685 param->tx_max_pending = HNS3_RING_MAX_PENDING;
686 param->rx_max_pending = HNS3_RING_MAX_PENDING;
687
688 param->tx_pending = priv->ring[0].desc_num;
689 param->rx_pending = priv->ring[rx_queue_index].desc_num;
690 kernel_param->rx_buf_len = priv->ring[rx_queue_index].buf_size;
691 kernel_param->tx_push = test_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE,
692 &priv->state);
693 }
694
hns3_get_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * param)695 static void hns3_get_pauseparam(struct net_device *netdev,
696 struct ethtool_pauseparam *param)
697 {
698 struct hnae3_handle *h = hns3_get_handle(netdev);
699 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
700
701 if (!test_bit(HNAE3_DEV_SUPPORT_PAUSE_B, ae_dev->caps))
702 return;
703
704 if (h->ae_algo->ops->get_pauseparam)
705 h->ae_algo->ops->get_pauseparam(h, ¶m->autoneg,
706 ¶m->rx_pause, ¶m->tx_pause);
707 }
708
hns3_set_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * param)709 static int hns3_set_pauseparam(struct net_device *netdev,
710 struct ethtool_pauseparam *param)
711 {
712 struct hnae3_handle *h = hns3_get_handle(netdev);
713 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
714
715 if (!test_bit(HNAE3_DEV_SUPPORT_PAUSE_B, ae_dev->caps))
716 return -EOPNOTSUPP;
717
718 netif_dbg(h, drv, netdev,
719 "set pauseparam: autoneg=%u, rx:%u, tx:%u\n",
720 param->autoneg, param->rx_pause, param->tx_pause);
721
722 if (h->ae_algo->ops->set_pauseparam)
723 return h->ae_algo->ops->set_pauseparam(h, param->autoneg,
724 param->rx_pause,
725 param->tx_pause);
726 return -EOPNOTSUPP;
727 }
728
hns3_get_ksettings(struct hnae3_handle * h,struct ethtool_link_ksettings * cmd)729 static void hns3_get_ksettings(struct hnae3_handle *h,
730 struct ethtool_link_ksettings *cmd)
731 {
732 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
733
734 /* 1.auto_neg & speed & duplex from cmd */
735 if (ops->get_ksettings_an_result)
736 ops->get_ksettings_an_result(h,
737 &cmd->base.autoneg,
738 &cmd->base.speed,
739 &cmd->base.duplex,
740 &cmd->lanes);
741
742 /* 2.get link mode */
743 if (ops->get_link_mode)
744 ops->get_link_mode(h,
745 cmd->link_modes.supported,
746 cmd->link_modes.advertising);
747
748 /* 3.mdix_ctrl&mdix get from phy reg */
749 if (ops->get_mdix_mode)
750 ops->get_mdix_mode(h, &cmd->base.eth_tp_mdix_ctrl,
751 &cmd->base.eth_tp_mdix);
752 }
753
hns3_get_link_ksettings(struct net_device * netdev,struct ethtool_link_ksettings * cmd)754 static int hns3_get_link_ksettings(struct net_device *netdev,
755 struct ethtool_link_ksettings *cmd)
756 {
757 struct hnae3_handle *h = hns3_get_handle(netdev);
758 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
759 const struct hnae3_ae_ops *ops;
760 u8 module_type;
761 u8 media_type;
762 u8 link_stat;
763
764 ops = h->ae_algo->ops;
765 if (ops->get_media_type)
766 ops->get_media_type(h, &media_type, &module_type);
767 else
768 return -EOPNOTSUPP;
769
770 switch (media_type) {
771 case HNAE3_MEDIA_TYPE_NONE:
772 cmd->base.port = PORT_NONE;
773 hns3_get_ksettings(h, cmd);
774 break;
775 case HNAE3_MEDIA_TYPE_FIBER:
776 if (module_type == HNAE3_MODULE_TYPE_UNKNOWN)
777 cmd->base.port = PORT_OTHER;
778 else if (module_type == HNAE3_MODULE_TYPE_CR)
779 cmd->base.port = PORT_DA;
780 else
781 cmd->base.port = PORT_FIBRE;
782
783 hns3_get_ksettings(h, cmd);
784 break;
785 case HNAE3_MEDIA_TYPE_BACKPLANE:
786 cmd->base.port = PORT_NONE;
787 hns3_get_ksettings(h, cmd);
788 break;
789 case HNAE3_MEDIA_TYPE_COPPER:
790 cmd->base.port = PORT_TP;
791 if (test_bit(HNAE3_DEV_SUPPORT_PHY_IMP_B, ae_dev->caps) &&
792 ops->get_phy_link_ksettings)
793 ops->get_phy_link_ksettings(h, cmd);
794 else if (!netdev->phydev)
795 hns3_get_ksettings(h, cmd);
796 else
797 phy_ethtool_ksettings_get(netdev->phydev, cmd);
798 break;
799 default:
800
801 netdev_warn(netdev, "Unknown media type");
802 return 0;
803 }
804
805 /* mdio_support */
806 cmd->base.mdio_support = ETH_MDIO_SUPPORTS_C22;
807
808 link_stat = hns3_get_link(netdev);
809 if (!link_stat) {
810 cmd->base.speed = SPEED_UNKNOWN;
811 cmd->base.duplex = DUPLEX_UNKNOWN;
812 }
813
814 return 0;
815 }
816
hns3_check_ksettings_param(const struct net_device * netdev,const struct ethtool_link_ksettings * cmd)817 static int hns3_check_ksettings_param(const struct net_device *netdev,
818 const struct ethtool_link_ksettings *cmd)
819 {
820 struct hnae3_handle *handle = hns3_get_handle(netdev);
821 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
822 u8 module_type = HNAE3_MODULE_TYPE_UNKNOWN;
823 u8 media_type = HNAE3_MEDIA_TYPE_UNKNOWN;
824 u32 lane_num;
825 u8 autoneg;
826 u32 speed;
827 u8 duplex;
828 int ret;
829
830 /* hw doesn't support use specified speed and duplex to negotiate,
831 * unnecessary to check them when autoneg on.
832 */
833 if (cmd->base.autoneg)
834 return 0;
835
836 if (ops->get_ksettings_an_result) {
837 ops->get_ksettings_an_result(handle, &autoneg, &speed, &duplex, &lane_num);
838 if (cmd->base.autoneg == autoneg && cmd->base.speed == speed &&
839 cmd->base.duplex == duplex && cmd->lanes == lane_num)
840 return 0;
841 }
842
843 if (ops->get_media_type)
844 ops->get_media_type(handle, &media_type, &module_type);
845
846 if (cmd->base.duplex == DUPLEX_HALF &&
847 media_type != HNAE3_MEDIA_TYPE_COPPER) {
848 netdev_err(netdev,
849 "only copper port supports half duplex!");
850 return -EINVAL;
851 }
852
853 if (ops->check_port_speed) {
854 ret = ops->check_port_speed(handle, cmd->base.speed);
855 if (ret) {
856 netdev_err(netdev, "unsupported speed\n");
857 return ret;
858 }
859 }
860
861 return 0;
862 }
863
hns3_set_link_ksettings(struct net_device * netdev,const struct ethtool_link_ksettings * cmd)864 static int hns3_set_link_ksettings(struct net_device *netdev,
865 const struct ethtool_link_ksettings *cmd)
866 {
867 struct hnae3_handle *handle = hns3_get_handle(netdev);
868 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
869 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
870 int ret;
871
872 /* Chip don't support this mode. */
873 if (cmd->base.speed == SPEED_1000 && cmd->base.duplex == DUPLEX_HALF)
874 return -EINVAL;
875
876 if (cmd->lanes && !hnae3_ae_dev_lane_num_supported(ae_dev))
877 return -EOPNOTSUPP;
878
879 netif_dbg(handle, drv, netdev,
880 "set link(%s): autoneg=%u, speed=%u, duplex=%u, lanes=%u\n",
881 netdev->phydev ? "phy" : "mac",
882 cmd->base.autoneg, cmd->base.speed, cmd->base.duplex,
883 cmd->lanes);
884
885 /* Only support ksettings_set for netdev with phy attached for now */
886 if (netdev->phydev) {
887 if (cmd->base.speed == SPEED_1000 &&
888 cmd->base.autoneg == AUTONEG_DISABLE)
889 return -EINVAL;
890
891 return phy_ethtool_ksettings_set(netdev->phydev, cmd);
892 } else if (test_bit(HNAE3_DEV_SUPPORT_PHY_IMP_B, ae_dev->caps) &&
893 ops->set_phy_link_ksettings) {
894 return ops->set_phy_link_ksettings(handle, cmd);
895 }
896
897 if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2)
898 return -EOPNOTSUPP;
899
900 ret = hns3_check_ksettings_param(netdev, cmd);
901 if (ret)
902 return ret;
903
904 if (ops->set_autoneg) {
905 ret = ops->set_autoneg(handle, cmd->base.autoneg);
906 if (ret)
907 return ret;
908 }
909
910 /* hw doesn't support use specified speed and duplex to negotiate,
911 * ignore them when autoneg on.
912 */
913 if (cmd->base.autoneg) {
914 netdev_info(netdev,
915 "autoneg is on, ignore the speed and duplex\n");
916 return 0;
917 }
918
919 if (ops->cfg_mac_speed_dup_h)
920 ret = ops->cfg_mac_speed_dup_h(handle, cmd->base.speed,
921 cmd->base.duplex, (u8)(cmd->lanes));
922
923 return ret;
924 }
925
hns3_get_rss_key_size(struct net_device * netdev)926 static u32 hns3_get_rss_key_size(struct net_device *netdev)
927 {
928 struct hnae3_handle *h = hns3_get_handle(netdev);
929
930 if (!h->ae_algo->ops->get_rss_key_size)
931 return 0;
932
933 return h->ae_algo->ops->get_rss_key_size(h);
934 }
935
hns3_get_rss_indir_size(struct net_device * netdev)936 static u32 hns3_get_rss_indir_size(struct net_device *netdev)
937 {
938 struct hnae3_handle *h = hns3_get_handle(netdev);
939 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
940
941 return ae_dev->dev_specs.rss_ind_tbl_size;
942 }
943
hns3_get_rss(struct net_device * netdev,struct ethtool_rxfh_param * rxfh)944 static int hns3_get_rss(struct net_device *netdev,
945 struct ethtool_rxfh_param *rxfh)
946 {
947 struct hnae3_handle *h = hns3_get_handle(netdev);
948
949 if (!h->ae_algo->ops->get_rss)
950 return -EOPNOTSUPP;
951
952 return h->ae_algo->ops->get_rss(h, rxfh->indir, rxfh->key,
953 &rxfh->hfunc);
954 }
955
hns3_set_rss(struct net_device * netdev,struct ethtool_rxfh_param * rxfh,struct netlink_ext_ack * extack)956 static int hns3_set_rss(struct net_device *netdev,
957 struct ethtool_rxfh_param *rxfh,
958 struct netlink_ext_ack *extack)
959 {
960 struct hnae3_handle *h = hns3_get_handle(netdev);
961 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
962
963 if (!h->ae_algo->ops->set_rss)
964 return -EOPNOTSUPP;
965
966 if ((ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 &&
967 rxfh->hfunc != ETH_RSS_HASH_TOP) ||
968 (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
969 rxfh->hfunc != ETH_RSS_HASH_TOP &&
970 rxfh->hfunc != ETH_RSS_HASH_XOR)) {
971 netdev_err(netdev, "hash func not supported\n");
972 return -EOPNOTSUPP;
973 }
974
975 if (!rxfh->indir) {
976 netdev_err(netdev,
977 "set rss failed for indir is empty\n");
978 return -EOPNOTSUPP;
979 }
980
981 return h->ae_algo->ops->set_rss(h, rxfh->indir, rxfh->key,
982 rxfh->hfunc);
983 }
984
hns3_get_rxnfc(struct net_device * netdev,struct ethtool_rxnfc * cmd,u32 * rule_locs)985 static int hns3_get_rxnfc(struct net_device *netdev,
986 struct ethtool_rxnfc *cmd,
987 u32 *rule_locs)
988 {
989 struct hnae3_handle *h = hns3_get_handle(netdev);
990
991 switch (cmd->cmd) {
992 case ETHTOOL_GRXRINGS:
993 cmd->data = h->kinfo.num_tqps;
994 return 0;
995 case ETHTOOL_GRXFH:
996 if (h->ae_algo->ops->get_rss_tuple)
997 return h->ae_algo->ops->get_rss_tuple(h, cmd);
998 return -EOPNOTSUPP;
999 case ETHTOOL_GRXCLSRLCNT:
1000 if (h->ae_algo->ops->get_fd_rule_cnt)
1001 return h->ae_algo->ops->get_fd_rule_cnt(h, cmd);
1002 return -EOPNOTSUPP;
1003 case ETHTOOL_GRXCLSRULE:
1004 if (h->ae_algo->ops->get_fd_rule_info)
1005 return h->ae_algo->ops->get_fd_rule_info(h, cmd);
1006 return -EOPNOTSUPP;
1007 case ETHTOOL_GRXCLSRLALL:
1008 if (h->ae_algo->ops->get_fd_all_rules)
1009 return h->ae_algo->ops->get_fd_all_rules(h, cmd,
1010 rule_locs);
1011 return -EOPNOTSUPP;
1012 default:
1013 return -EOPNOTSUPP;
1014 }
1015 }
1016
1017 static const struct hns3_reset_type_map hns3_reset_type[] = {
1018 {ETH_RESET_MGMT, HNAE3_IMP_RESET},
1019 {ETH_RESET_ALL, HNAE3_GLOBAL_RESET},
1020 {ETH_RESET_DEDICATED, HNAE3_FUNC_RESET},
1021 };
1022
1023 static const struct hns3_reset_type_map hns3vf_reset_type[] = {
1024 {ETH_RESET_DEDICATED, HNAE3_VF_FUNC_RESET},
1025 };
1026
hns3_set_reset(struct net_device * netdev,u32 * flags)1027 static int hns3_set_reset(struct net_device *netdev, u32 *flags)
1028 {
1029 enum hnae3_reset_type rst_type = HNAE3_NONE_RESET;
1030 struct hnae3_handle *h = hns3_get_handle(netdev);
1031 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
1032 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
1033 const struct hns3_reset_type_map *rst_type_map;
1034 enum ethtool_reset_flags rst_flags;
1035 u32 i, size;
1036
1037 if (ops->ae_dev_resetting && ops->ae_dev_resetting(h))
1038 return -EBUSY;
1039
1040 if (!ops->set_default_reset_request || !ops->reset_event)
1041 return -EOPNOTSUPP;
1042
1043 if (h->flags & HNAE3_SUPPORT_VF) {
1044 rst_type_map = hns3vf_reset_type;
1045 size = ARRAY_SIZE(hns3vf_reset_type);
1046 } else {
1047 rst_type_map = hns3_reset_type;
1048 size = ARRAY_SIZE(hns3_reset_type);
1049 }
1050
1051 for (i = 0; i < size; i++) {
1052 if (rst_type_map[i].rst_flags == *flags) {
1053 rst_type = rst_type_map[i].rst_type;
1054 rst_flags = rst_type_map[i].rst_flags;
1055 break;
1056 }
1057 }
1058
1059 if (rst_type == HNAE3_NONE_RESET ||
1060 (rst_type == HNAE3_IMP_RESET &&
1061 ae_dev->dev_version <= HNAE3_DEVICE_VERSION_V2))
1062 return -EOPNOTSUPP;
1063
1064 netdev_info(netdev, "Setting reset type %d\n", rst_type);
1065
1066 ops->set_default_reset_request(ae_dev, rst_type);
1067
1068 ops->reset_event(h->pdev, h);
1069
1070 *flags &= ~rst_flags;
1071
1072 return 0;
1073 }
1074
hns3_change_all_ring_bd_num(struct hns3_nic_priv * priv,u32 tx_desc_num,u32 rx_desc_num)1075 static void hns3_change_all_ring_bd_num(struct hns3_nic_priv *priv,
1076 u32 tx_desc_num, u32 rx_desc_num)
1077 {
1078 struct hnae3_handle *h = priv->ae_handle;
1079 int i;
1080
1081 h->kinfo.num_tx_desc = tx_desc_num;
1082 h->kinfo.num_rx_desc = rx_desc_num;
1083
1084 for (i = 0; i < h->kinfo.num_tqps; i++) {
1085 priv->ring[i].desc_num = tx_desc_num;
1086 priv->ring[i + h->kinfo.num_tqps].desc_num = rx_desc_num;
1087 }
1088 }
1089
hns3_backup_ringparam(struct hns3_nic_priv * priv)1090 static struct hns3_enet_ring *hns3_backup_ringparam(struct hns3_nic_priv *priv)
1091 {
1092 struct hnae3_handle *handle = priv->ae_handle;
1093 struct hns3_enet_ring *tmp_rings;
1094 int i;
1095
1096 tmp_rings = kcalloc(handle->kinfo.num_tqps * 2,
1097 sizeof(struct hns3_enet_ring), GFP_KERNEL);
1098 if (!tmp_rings)
1099 return NULL;
1100
1101 for (i = 0; i < handle->kinfo.num_tqps * 2; i++) {
1102 memcpy(&tmp_rings[i], &priv->ring[i],
1103 sizeof(struct hns3_enet_ring));
1104 tmp_rings[i].skb = NULL;
1105 }
1106
1107 return tmp_rings;
1108 }
1109
hns3_check_ringparam(struct net_device * ndev,struct ethtool_ringparam * param,struct kernel_ethtool_ringparam * kernel_param)1110 static int hns3_check_ringparam(struct net_device *ndev,
1111 struct ethtool_ringparam *param,
1112 struct kernel_ethtool_ringparam *kernel_param)
1113 {
1114 #define RX_BUF_LEN_2K 2048
1115 #define RX_BUF_LEN_4K 4096
1116
1117 struct hns3_nic_priv *priv = netdev_priv(ndev);
1118
1119 if (hns3_nic_resetting(ndev) || !priv->ring) {
1120 netdev_err(ndev, "failed to set ringparam value, due to dev resetting or uninited\n");
1121 return -EBUSY;
1122 }
1123
1124
1125 if (param->rx_mini_pending || param->rx_jumbo_pending)
1126 return -EINVAL;
1127
1128 if (kernel_param->rx_buf_len != RX_BUF_LEN_2K &&
1129 kernel_param->rx_buf_len != RX_BUF_LEN_4K) {
1130 netdev_err(ndev, "Rx buf len only support 2048 and 4096\n");
1131 return -EINVAL;
1132 }
1133
1134 if (param->tx_pending > HNS3_RING_MAX_PENDING ||
1135 param->tx_pending < HNS3_RING_MIN_PENDING ||
1136 param->rx_pending > HNS3_RING_MAX_PENDING ||
1137 param->rx_pending < HNS3_RING_MIN_PENDING) {
1138 netdev_err(ndev, "Queue depth out of range [%d-%d]\n",
1139 HNS3_RING_MIN_PENDING, HNS3_RING_MAX_PENDING);
1140 return -EINVAL;
1141 }
1142
1143 return 0;
1144 }
1145
1146 static bool
hns3_is_ringparam_changed(struct net_device * ndev,struct ethtool_ringparam * param,struct kernel_ethtool_ringparam * kernel_param,struct hns3_ring_param * old_ringparam,struct hns3_ring_param * new_ringparam)1147 hns3_is_ringparam_changed(struct net_device *ndev,
1148 struct ethtool_ringparam *param,
1149 struct kernel_ethtool_ringparam *kernel_param,
1150 struct hns3_ring_param *old_ringparam,
1151 struct hns3_ring_param *new_ringparam)
1152 {
1153 struct hns3_nic_priv *priv = netdev_priv(ndev);
1154 struct hnae3_handle *h = priv->ae_handle;
1155 u16 queue_num = h->kinfo.num_tqps;
1156
1157 new_ringparam->tx_desc_num = ALIGN(param->tx_pending,
1158 HNS3_RING_BD_MULTIPLE);
1159 new_ringparam->rx_desc_num = ALIGN(param->rx_pending,
1160 HNS3_RING_BD_MULTIPLE);
1161 old_ringparam->tx_desc_num = priv->ring[0].desc_num;
1162 old_ringparam->rx_desc_num = priv->ring[queue_num].desc_num;
1163 old_ringparam->rx_buf_len = priv->ring[queue_num].buf_size;
1164 new_ringparam->rx_buf_len = kernel_param->rx_buf_len;
1165
1166 if (old_ringparam->tx_desc_num == new_ringparam->tx_desc_num &&
1167 old_ringparam->rx_desc_num == new_ringparam->rx_desc_num &&
1168 old_ringparam->rx_buf_len == new_ringparam->rx_buf_len) {
1169 netdev_info(ndev, "descriptor number and rx buffer length not changed\n");
1170 return false;
1171 }
1172
1173 return true;
1174 }
1175
hns3_change_rx_buf_len(struct net_device * ndev,u32 rx_buf_len)1176 static int hns3_change_rx_buf_len(struct net_device *ndev, u32 rx_buf_len)
1177 {
1178 struct hns3_nic_priv *priv = netdev_priv(ndev);
1179 struct hnae3_handle *h = priv->ae_handle;
1180 int i;
1181
1182 h->kinfo.rx_buf_len = rx_buf_len;
1183
1184 for (i = 0; i < h->kinfo.num_tqps; i++) {
1185 h->kinfo.tqp[i]->buf_size = rx_buf_len;
1186 priv->ring[i + h->kinfo.num_tqps].buf_size = rx_buf_len;
1187 }
1188
1189 return 0;
1190 }
1191
hns3_set_tx_push(struct net_device * netdev,u32 tx_push)1192 static int hns3_set_tx_push(struct net_device *netdev, u32 tx_push)
1193 {
1194 struct hns3_nic_priv *priv = netdev_priv(netdev);
1195 struct hnae3_handle *h = hns3_get_handle(netdev);
1196 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
1197 u32 old_state = test_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state);
1198
1199 if (!test_bit(HNAE3_DEV_SUPPORT_TX_PUSH_B, ae_dev->caps) && tx_push)
1200 return -EOPNOTSUPP;
1201
1202 if (tx_push == old_state)
1203 return 0;
1204
1205 netdev_dbg(netdev, "Changing tx push from %s to %s\n",
1206 old_state ? "on" : "off", tx_push ? "on" : "off");
1207
1208 if (tx_push)
1209 set_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state);
1210 else
1211 clear_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state);
1212
1213 return 0;
1214 }
1215
hns3_set_ringparam(struct net_device * ndev,struct ethtool_ringparam * param,struct kernel_ethtool_ringparam * kernel_param,struct netlink_ext_ack * extack)1216 static int hns3_set_ringparam(struct net_device *ndev,
1217 struct ethtool_ringparam *param,
1218 struct kernel_ethtool_ringparam *kernel_param,
1219 struct netlink_ext_ack *extack)
1220 {
1221 struct hns3_ring_param old_ringparam, new_ringparam;
1222 struct hns3_nic_priv *priv = netdev_priv(ndev);
1223 struct hnae3_handle *h = priv->ae_handle;
1224 struct hns3_enet_ring *tmp_rings;
1225 bool if_running = netif_running(ndev);
1226 int ret, i;
1227
1228 ret = hns3_check_ringparam(ndev, param, kernel_param);
1229 if (ret)
1230 return ret;
1231
1232 ret = hns3_set_tx_push(ndev, kernel_param->tx_push);
1233 if (ret)
1234 return ret;
1235
1236 if (!hns3_is_ringparam_changed(ndev, param, kernel_param,
1237 &old_ringparam, &new_ringparam))
1238 return 0;
1239
1240 tmp_rings = hns3_backup_ringparam(priv);
1241 if (!tmp_rings) {
1242 netdev_err(ndev, "backup ring param failed by allocating memory fail\n");
1243 return -ENOMEM;
1244 }
1245
1246 netdev_info(ndev,
1247 "Changing Tx/Rx ring depth from %u/%u to %u/%u, Changing rx buffer len from %u to %u\n",
1248 old_ringparam.tx_desc_num, old_ringparam.rx_desc_num,
1249 new_ringparam.tx_desc_num, new_ringparam.rx_desc_num,
1250 old_ringparam.rx_buf_len, new_ringparam.rx_buf_len);
1251
1252 if (if_running)
1253 ndev->netdev_ops->ndo_stop(ndev);
1254
1255 hns3_change_all_ring_bd_num(priv, new_ringparam.tx_desc_num,
1256 new_ringparam.rx_desc_num);
1257 hns3_change_rx_buf_len(ndev, new_ringparam.rx_buf_len);
1258 ret = hns3_init_all_ring(priv);
1259 if (ret) {
1260 netdev_err(ndev, "set ringparam fail, revert to old value(%d)\n",
1261 ret);
1262
1263 hns3_change_rx_buf_len(ndev, old_ringparam.rx_buf_len);
1264 hns3_change_all_ring_bd_num(priv, old_ringparam.tx_desc_num,
1265 old_ringparam.rx_desc_num);
1266 for (i = 0; i < h->kinfo.num_tqps * 2; i++)
1267 memcpy(&priv->ring[i], &tmp_rings[i],
1268 sizeof(struct hns3_enet_ring));
1269 } else {
1270 for (i = 0; i < h->kinfo.num_tqps * 2; i++)
1271 hns3_fini_ring(&tmp_rings[i]);
1272 }
1273
1274 kfree(tmp_rings);
1275
1276 if (if_running)
1277 ret = ndev->netdev_ops->ndo_open(ndev);
1278
1279 return ret;
1280 }
1281
hns3_set_rxnfc(struct net_device * netdev,struct ethtool_rxnfc * cmd)1282 static int hns3_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1283 {
1284 struct hnae3_handle *h = hns3_get_handle(netdev);
1285
1286 switch (cmd->cmd) {
1287 case ETHTOOL_SRXFH:
1288 if (h->ae_algo->ops->set_rss_tuple)
1289 return h->ae_algo->ops->set_rss_tuple(h, cmd);
1290 return -EOPNOTSUPP;
1291 case ETHTOOL_SRXCLSRLINS:
1292 if (h->ae_algo->ops->add_fd_entry)
1293 return h->ae_algo->ops->add_fd_entry(h, cmd);
1294 return -EOPNOTSUPP;
1295 case ETHTOOL_SRXCLSRLDEL:
1296 if (h->ae_algo->ops->del_fd_entry)
1297 return h->ae_algo->ops->del_fd_entry(h, cmd);
1298 return -EOPNOTSUPP;
1299 default:
1300 return -EOPNOTSUPP;
1301 }
1302 }
1303
hns3_nway_reset(struct net_device * netdev)1304 static int hns3_nway_reset(struct net_device *netdev)
1305 {
1306 struct hnae3_handle *handle = hns3_get_handle(netdev);
1307 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1308 struct phy_device *phy = netdev->phydev;
1309 int autoneg;
1310
1311 if (!netif_running(netdev))
1312 return 0;
1313
1314 if (hns3_nic_resetting(netdev)) {
1315 netdev_err(netdev, "dev resetting!");
1316 return -EBUSY;
1317 }
1318
1319 if (!ops->get_autoneg || !ops->restart_autoneg)
1320 return -EOPNOTSUPP;
1321
1322 autoneg = ops->get_autoneg(handle);
1323 if (autoneg != AUTONEG_ENABLE) {
1324 netdev_err(netdev,
1325 "Autoneg is off, don't support to restart it\n");
1326 return -EINVAL;
1327 }
1328
1329 netif_dbg(handle, drv, netdev,
1330 "nway reset (using %s)\n", phy ? "phy" : "mac");
1331
1332 if (phy)
1333 return genphy_restart_aneg(phy);
1334
1335 return ops->restart_autoneg(handle);
1336 }
1337
hns3_get_channels(struct net_device * netdev,struct ethtool_channels * ch)1338 static void hns3_get_channels(struct net_device *netdev,
1339 struct ethtool_channels *ch)
1340 {
1341 struct hnae3_handle *h = hns3_get_handle(netdev);
1342
1343 if (h->ae_algo->ops->get_channels)
1344 h->ae_algo->ops->get_channels(h, ch);
1345 }
1346
hns3_get_coalesce(struct net_device * netdev,struct ethtool_coalesce * cmd,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)1347 static int hns3_get_coalesce(struct net_device *netdev,
1348 struct ethtool_coalesce *cmd,
1349 struct kernel_ethtool_coalesce *kernel_coal,
1350 struct netlink_ext_ack *extack)
1351 {
1352 struct hns3_nic_priv *priv = netdev_priv(netdev);
1353 struct hns3_enet_coalesce *tx_coal = &priv->tx_coal;
1354 struct hns3_enet_coalesce *rx_coal = &priv->rx_coal;
1355 struct hnae3_handle *h = priv->ae_handle;
1356
1357 if (hns3_nic_resetting(netdev))
1358 return -EBUSY;
1359
1360 cmd->use_adaptive_tx_coalesce = tx_coal->adapt_enable;
1361 cmd->use_adaptive_rx_coalesce = rx_coal->adapt_enable;
1362
1363 cmd->tx_coalesce_usecs = tx_coal->int_gl;
1364 cmd->rx_coalesce_usecs = rx_coal->int_gl;
1365
1366 cmd->tx_coalesce_usecs_high = h->kinfo.int_rl_setting;
1367 cmd->rx_coalesce_usecs_high = h->kinfo.int_rl_setting;
1368
1369 cmd->tx_max_coalesced_frames = tx_coal->int_ql;
1370 cmd->rx_max_coalesced_frames = rx_coal->int_ql;
1371
1372 kernel_coal->use_cqe_mode_tx = (priv->tx_cqe_mode ==
1373 DIM_CQ_PERIOD_MODE_START_FROM_CQE);
1374 kernel_coal->use_cqe_mode_rx = (priv->rx_cqe_mode ==
1375 DIM_CQ_PERIOD_MODE_START_FROM_CQE);
1376
1377 return 0;
1378 }
1379
hns3_check_gl_coalesce_para(struct net_device * netdev,struct ethtool_coalesce * cmd)1380 static int hns3_check_gl_coalesce_para(struct net_device *netdev,
1381 struct ethtool_coalesce *cmd)
1382 {
1383 struct hnae3_handle *handle = hns3_get_handle(netdev);
1384 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1385 u32 rx_gl, tx_gl;
1386
1387 if (cmd->rx_coalesce_usecs > ae_dev->dev_specs.max_int_gl) {
1388 netdev_err(netdev,
1389 "invalid rx-usecs value, rx-usecs range is 0-%u\n",
1390 ae_dev->dev_specs.max_int_gl);
1391 return -EINVAL;
1392 }
1393
1394 if (cmd->tx_coalesce_usecs > ae_dev->dev_specs.max_int_gl) {
1395 netdev_err(netdev,
1396 "invalid tx-usecs value, tx-usecs range is 0-%u\n",
1397 ae_dev->dev_specs.max_int_gl);
1398 return -EINVAL;
1399 }
1400
1401 /* device version above V3(include V3), GL uses 1us unit,
1402 * so the round down is not needed.
1403 */
1404 if (ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V3)
1405 return 0;
1406
1407 rx_gl = hns3_gl_round_down(cmd->rx_coalesce_usecs);
1408 if (rx_gl != cmd->rx_coalesce_usecs) {
1409 netdev_info(netdev,
1410 "rx_usecs(%u) rounded down to %u, because it must be multiple of 2.\n",
1411 cmd->rx_coalesce_usecs, rx_gl);
1412 }
1413
1414 tx_gl = hns3_gl_round_down(cmd->tx_coalesce_usecs);
1415 if (tx_gl != cmd->tx_coalesce_usecs) {
1416 netdev_info(netdev,
1417 "tx_usecs(%u) rounded down to %u, because it must be multiple of 2.\n",
1418 cmd->tx_coalesce_usecs, tx_gl);
1419 }
1420
1421 return 0;
1422 }
1423
hns3_check_rl_coalesce_para(struct net_device * netdev,struct ethtool_coalesce * cmd)1424 static int hns3_check_rl_coalesce_para(struct net_device *netdev,
1425 struct ethtool_coalesce *cmd)
1426 {
1427 u32 rl;
1428
1429 if (cmd->tx_coalesce_usecs_high != cmd->rx_coalesce_usecs_high) {
1430 netdev_err(netdev,
1431 "tx_usecs_high must be same as rx_usecs_high.\n");
1432 return -EINVAL;
1433 }
1434
1435 if (cmd->rx_coalesce_usecs_high > HNS3_INT_RL_MAX) {
1436 netdev_err(netdev,
1437 "Invalid usecs_high value, usecs_high range is 0-%d\n",
1438 HNS3_INT_RL_MAX);
1439 return -EINVAL;
1440 }
1441
1442 rl = hns3_rl_round_down(cmd->rx_coalesce_usecs_high);
1443 if (rl != cmd->rx_coalesce_usecs_high) {
1444 netdev_info(netdev,
1445 "usecs_high(%u) rounded down to %u, because it must be multiple of 4.\n",
1446 cmd->rx_coalesce_usecs_high, rl);
1447 }
1448
1449 return 0;
1450 }
1451
hns3_check_ql_coalesce_param(struct net_device * netdev,struct ethtool_coalesce * cmd)1452 static int hns3_check_ql_coalesce_param(struct net_device *netdev,
1453 struct ethtool_coalesce *cmd)
1454 {
1455 struct hnae3_handle *handle = hns3_get_handle(netdev);
1456 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1457
1458 if ((cmd->tx_max_coalesced_frames || cmd->rx_max_coalesced_frames) &&
1459 !ae_dev->dev_specs.int_ql_max) {
1460 netdev_err(netdev, "coalesced frames is not supported\n");
1461 return -EOPNOTSUPP;
1462 }
1463
1464 if (cmd->tx_max_coalesced_frames > ae_dev->dev_specs.int_ql_max ||
1465 cmd->rx_max_coalesced_frames > ae_dev->dev_specs.int_ql_max) {
1466 netdev_err(netdev,
1467 "invalid coalesced_frames value, range is 0-%u\n",
1468 ae_dev->dev_specs.int_ql_max);
1469 return -ERANGE;
1470 }
1471
1472 return 0;
1473 }
1474
1475 static int
hns3_check_cqe_coalesce_param(struct net_device * netdev,struct kernel_ethtool_coalesce * kernel_coal)1476 hns3_check_cqe_coalesce_param(struct net_device *netdev,
1477 struct kernel_ethtool_coalesce *kernel_coal)
1478 {
1479 struct hnae3_handle *handle = hns3_get_handle(netdev);
1480 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1481
1482 if ((kernel_coal->use_cqe_mode_tx || kernel_coal->use_cqe_mode_rx) &&
1483 !hnae3_ae_dev_cq_supported(ae_dev)) {
1484 netdev_err(netdev, "coalesced cqe mode is not supported\n");
1485 return -EOPNOTSUPP;
1486 }
1487
1488 return 0;
1489 }
1490
1491 static int
hns3_check_coalesce_para(struct net_device * netdev,struct ethtool_coalesce * cmd,struct kernel_ethtool_coalesce * kernel_coal)1492 hns3_check_coalesce_para(struct net_device *netdev,
1493 struct ethtool_coalesce *cmd,
1494 struct kernel_ethtool_coalesce *kernel_coal)
1495 {
1496 int ret;
1497
1498 ret = hns3_check_cqe_coalesce_param(netdev, kernel_coal);
1499 if (ret)
1500 return ret;
1501
1502 ret = hns3_check_gl_coalesce_para(netdev, cmd);
1503 if (ret) {
1504 netdev_err(netdev,
1505 "Check gl coalesce param fail. ret = %d\n", ret);
1506 return ret;
1507 }
1508
1509 ret = hns3_check_rl_coalesce_para(netdev, cmd);
1510 if (ret) {
1511 netdev_err(netdev,
1512 "Check rl coalesce param fail. ret = %d\n", ret);
1513 return ret;
1514 }
1515
1516 return hns3_check_ql_coalesce_param(netdev, cmd);
1517 }
1518
hns3_set_coalesce_per_queue(struct net_device * netdev,struct ethtool_coalesce * cmd,u32 queue)1519 static void hns3_set_coalesce_per_queue(struct net_device *netdev,
1520 struct ethtool_coalesce *cmd,
1521 u32 queue)
1522 {
1523 struct hns3_enet_tqp_vector *tx_vector, *rx_vector;
1524 struct hns3_nic_priv *priv = netdev_priv(netdev);
1525 struct hnae3_handle *h = priv->ae_handle;
1526 int queue_num = h->kinfo.num_tqps;
1527
1528 tx_vector = priv->ring[queue].tqp_vector;
1529 rx_vector = priv->ring[queue_num + queue].tqp_vector;
1530
1531 tx_vector->tx_group.coal.adapt_enable =
1532 cmd->use_adaptive_tx_coalesce;
1533 rx_vector->rx_group.coal.adapt_enable =
1534 cmd->use_adaptive_rx_coalesce;
1535
1536 tx_vector->tx_group.coal.int_gl = cmd->tx_coalesce_usecs;
1537 rx_vector->rx_group.coal.int_gl = cmd->rx_coalesce_usecs;
1538
1539 tx_vector->tx_group.coal.int_ql = cmd->tx_max_coalesced_frames;
1540 rx_vector->rx_group.coal.int_ql = cmd->rx_max_coalesced_frames;
1541
1542 hns3_set_vector_coalesce_tx_gl(tx_vector,
1543 tx_vector->tx_group.coal.int_gl);
1544 hns3_set_vector_coalesce_rx_gl(rx_vector,
1545 rx_vector->rx_group.coal.int_gl);
1546
1547 hns3_set_vector_coalesce_rl(tx_vector, h->kinfo.int_rl_setting);
1548 hns3_set_vector_coalesce_rl(rx_vector, h->kinfo.int_rl_setting);
1549
1550 if (tx_vector->tx_group.coal.ql_enable)
1551 hns3_set_vector_coalesce_tx_ql(tx_vector,
1552 tx_vector->tx_group.coal.int_ql);
1553 if (rx_vector->rx_group.coal.ql_enable)
1554 hns3_set_vector_coalesce_rx_ql(rx_vector,
1555 rx_vector->rx_group.coal.int_ql);
1556 }
1557
hns3_set_coalesce(struct net_device * netdev,struct ethtool_coalesce * cmd,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)1558 static int hns3_set_coalesce(struct net_device *netdev,
1559 struct ethtool_coalesce *cmd,
1560 struct kernel_ethtool_coalesce *kernel_coal,
1561 struct netlink_ext_ack *extack)
1562 {
1563 struct hnae3_handle *h = hns3_get_handle(netdev);
1564 struct hns3_nic_priv *priv = netdev_priv(netdev);
1565 struct hns3_enet_coalesce *tx_coal = &priv->tx_coal;
1566 struct hns3_enet_coalesce *rx_coal = &priv->rx_coal;
1567 u16 queue_num = h->kinfo.num_tqps;
1568 enum dim_cq_period_mode tx_mode;
1569 enum dim_cq_period_mode rx_mode;
1570 int ret;
1571 int i;
1572
1573 if (hns3_nic_resetting(netdev))
1574 return -EBUSY;
1575
1576 ret = hns3_check_coalesce_para(netdev, cmd, kernel_coal);
1577 if (ret)
1578 return ret;
1579
1580 h->kinfo.int_rl_setting =
1581 hns3_rl_round_down(cmd->rx_coalesce_usecs_high);
1582
1583 tx_coal->adapt_enable = cmd->use_adaptive_tx_coalesce;
1584 rx_coal->adapt_enable = cmd->use_adaptive_rx_coalesce;
1585
1586 tx_coal->int_gl = cmd->tx_coalesce_usecs;
1587 rx_coal->int_gl = cmd->rx_coalesce_usecs;
1588
1589 tx_coal->int_ql = cmd->tx_max_coalesced_frames;
1590 rx_coal->int_ql = cmd->rx_max_coalesced_frames;
1591
1592 for (i = 0; i < queue_num; i++)
1593 hns3_set_coalesce_per_queue(netdev, cmd, i);
1594
1595 tx_mode = kernel_coal->use_cqe_mode_tx ?
1596 DIM_CQ_PERIOD_MODE_START_FROM_CQE :
1597 DIM_CQ_PERIOD_MODE_START_FROM_EQE;
1598 rx_mode = kernel_coal->use_cqe_mode_rx ?
1599 DIM_CQ_PERIOD_MODE_START_FROM_CQE :
1600 DIM_CQ_PERIOD_MODE_START_FROM_EQE;
1601 hns3_cq_period_mode_init(priv, tx_mode, rx_mode);
1602
1603 return 0;
1604 }
1605
hns3_get_regs_len(struct net_device * netdev)1606 static int hns3_get_regs_len(struct net_device *netdev)
1607 {
1608 struct hnae3_handle *h = hns3_get_handle(netdev);
1609
1610 if (!h->ae_algo->ops->get_regs_len)
1611 return -EOPNOTSUPP;
1612
1613 return h->ae_algo->ops->get_regs_len(h);
1614 }
1615
hns3_get_regs(struct net_device * netdev,struct ethtool_regs * cmd,void * data)1616 static void hns3_get_regs(struct net_device *netdev,
1617 struct ethtool_regs *cmd, void *data)
1618 {
1619 struct hnae3_handle *h = hns3_get_handle(netdev);
1620
1621 if (!h->ae_algo->ops->get_regs)
1622 return;
1623
1624 h->ae_algo->ops->get_regs(h, &cmd->version, data);
1625 }
1626
hns3_set_phys_id(struct net_device * netdev,enum ethtool_phys_id_state state)1627 static int hns3_set_phys_id(struct net_device *netdev,
1628 enum ethtool_phys_id_state state)
1629 {
1630 struct hnae3_handle *h = hns3_get_handle(netdev);
1631
1632 if (!h->ae_algo->ops->set_led_id)
1633 return -EOPNOTSUPP;
1634
1635 return h->ae_algo->ops->set_led_id(h, state);
1636 }
1637
hns3_get_msglevel(struct net_device * netdev)1638 static u32 hns3_get_msglevel(struct net_device *netdev)
1639 {
1640 struct hnae3_handle *h = hns3_get_handle(netdev);
1641
1642 return h->msg_enable;
1643 }
1644
hns3_set_msglevel(struct net_device * netdev,u32 msg_level)1645 static void hns3_set_msglevel(struct net_device *netdev, u32 msg_level)
1646 {
1647 struct hnae3_handle *h = hns3_get_handle(netdev);
1648
1649 h->msg_enable = msg_level;
1650 }
1651
hns3_get_fec_stats(struct net_device * netdev,struct ethtool_fec_stats * fec_stats)1652 static void hns3_get_fec_stats(struct net_device *netdev,
1653 struct ethtool_fec_stats *fec_stats)
1654 {
1655 struct hnae3_handle *handle = hns3_get_handle(netdev);
1656 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1657 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1658
1659 if (!hnae3_ae_dev_fec_stats_supported(ae_dev) || !ops->get_fec_stats)
1660 return;
1661
1662 ops->get_fec_stats(handle, fec_stats);
1663 }
1664
1665 /* Translate local fec value into ethtool value. */
loc_to_eth_fec(u8 loc_fec)1666 static unsigned int loc_to_eth_fec(u8 loc_fec)
1667 {
1668 u32 eth_fec = 0;
1669
1670 if (loc_fec & BIT(HNAE3_FEC_AUTO))
1671 eth_fec |= ETHTOOL_FEC_AUTO;
1672 if (loc_fec & BIT(HNAE3_FEC_RS))
1673 eth_fec |= ETHTOOL_FEC_RS;
1674 if (loc_fec & BIT(HNAE3_FEC_LLRS))
1675 eth_fec |= ETHTOOL_FEC_LLRS;
1676 if (loc_fec & BIT(HNAE3_FEC_BASER))
1677 eth_fec |= ETHTOOL_FEC_BASER;
1678 if (loc_fec & BIT(HNAE3_FEC_NONE))
1679 eth_fec |= ETHTOOL_FEC_OFF;
1680
1681 return eth_fec;
1682 }
1683
1684 /* Translate ethtool fec value into local value. */
eth_to_loc_fec(unsigned int eth_fec)1685 static unsigned int eth_to_loc_fec(unsigned int eth_fec)
1686 {
1687 u32 loc_fec = 0;
1688
1689 if (eth_fec & ETHTOOL_FEC_OFF)
1690 loc_fec |= BIT(HNAE3_FEC_NONE);
1691 if (eth_fec & ETHTOOL_FEC_AUTO)
1692 loc_fec |= BIT(HNAE3_FEC_AUTO);
1693 if (eth_fec & ETHTOOL_FEC_RS)
1694 loc_fec |= BIT(HNAE3_FEC_RS);
1695 if (eth_fec & ETHTOOL_FEC_LLRS)
1696 loc_fec |= BIT(HNAE3_FEC_LLRS);
1697 if (eth_fec & ETHTOOL_FEC_BASER)
1698 loc_fec |= BIT(HNAE3_FEC_BASER);
1699
1700 return loc_fec;
1701 }
1702
hns3_get_fecparam(struct net_device * netdev,struct ethtool_fecparam * fec)1703 static int hns3_get_fecparam(struct net_device *netdev,
1704 struct ethtool_fecparam *fec)
1705 {
1706 struct hnae3_handle *handle = hns3_get_handle(netdev);
1707 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1708 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1709 u8 fec_ability;
1710 u8 fec_mode;
1711
1712 if (!test_bit(HNAE3_DEV_SUPPORT_FEC_B, ae_dev->caps))
1713 return -EOPNOTSUPP;
1714
1715 if (!ops->get_fec)
1716 return -EOPNOTSUPP;
1717
1718 ops->get_fec(handle, &fec_ability, &fec_mode);
1719
1720 fec->fec = loc_to_eth_fec(fec_ability);
1721 fec->active_fec = loc_to_eth_fec(fec_mode);
1722 if (!fec->active_fec)
1723 fec->active_fec = ETHTOOL_FEC_OFF;
1724
1725 return 0;
1726 }
1727
hns3_set_fecparam(struct net_device * netdev,struct ethtool_fecparam * fec)1728 static int hns3_set_fecparam(struct net_device *netdev,
1729 struct ethtool_fecparam *fec)
1730 {
1731 struct hnae3_handle *handle = hns3_get_handle(netdev);
1732 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1733 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1734 u32 fec_mode;
1735
1736 if (!test_bit(HNAE3_DEV_SUPPORT_FEC_B, ae_dev->caps))
1737 return -EOPNOTSUPP;
1738
1739 if (!ops->set_fec)
1740 return -EOPNOTSUPP;
1741 fec_mode = eth_to_loc_fec(fec->fec);
1742
1743 netif_dbg(handle, drv, netdev, "set fecparam: mode=%u\n", fec_mode);
1744
1745 return ops->set_fec(handle, fec_mode);
1746 }
1747
hns3_get_module_info(struct net_device * netdev,struct ethtool_modinfo * modinfo)1748 static int hns3_get_module_info(struct net_device *netdev,
1749 struct ethtool_modinfo *modinfo)
1750 {
1751 #define HNS3_SFF_8636_V1_3 0x03
1752
1753 struct hnae3_handle *handle = hns3_get_handle(netdev);
1754 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1755 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1756 struct hns3_sfp_type sfp_type;
1757 int ret;
1758
1759 if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 ||
1760 !ops->get_module_eeprom)
1761 return -EOPNOTSUPP;
1762
1763 memset(&sfp_type, 0, sizeof(sfp_type));
1764 ret = ops->get_module_eeprom(handle, 0, sizeof(sfp_type) / sizeof(u8),
1765 (u8 *)&sfp_type);
1766 if (ret)
1767 return ret;
1768
1769 switch (sfp_type.type) {
1770 case SFF8024_ID_SFP:
1771 modinfo->type = ETH_MODULE_SFF_8472;
1772 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1773 break;
1774 case SFF8024_ID_QSFP_8438:
1775 modinfo->type = ETH_MODULE_SFF_8436;
1776 modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
1777 break;
1778 case SFF8024_ID_QSFP_8436_8636:
1779 if (sfp_type.ext_type < HNS3_SFF_8636_V1_3) {
1780 modinfo->type = ETH_MODULE_SFF_8436;
1781 modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
1782 } else {
1783 modinfo->type = ETH_MODULE_SFF_8636;
1784 modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
1785 }
1786 break;
1787 case SFF8024_ID_QSFP28_8636:
1788 modinfo->type = ETH_MODULE_SFF_8636;
1789 modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
1790 break;
1791 default:
1792 netdev_err(netdev, "Optical module unknown: %#x\n",
1793 sfp_type.type);
1794 return -EINVAL;
1795 }
1796
1797 return 0;
1798 }
1799
hns3_get_module_eeprom(struct net_device * netdev,struct ethtool_eeprom * ee,u8 * data)1800 static int hns3_get_module_eeprom(struct net_device *netdev,
1801 struct ethtool_eeprom *ee, u8 *data)
1802 {
1803 struct hnae3_handle *handle = hns3_get_handle(netdev);
1804 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1805 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1806
1807 if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 ||
1808 !ops->get_module_eeprom)
1809 return -EOPNOTSUPP;
1810
1811 if (!ee->len)
1812 return -EINVAL;
1813
1814 memset(data, 0, ee->len);
1815
1816 return ops->get_module_eeprom(handle, ee->offset, ee->len, data);
1817 }
1818
hns3_get_priv_flags(struct net_device * netdev)1819 static u32 hns3_get_priv_flags(struct net_device *netdev)
1820 {
1821 struct hnae3_handle *handle = hns3_get_handle(netdev);
1822
1823 return handle->priv_flags;
1824 }
1825
hns3_check_priv_flags(struct hnae3_handle * h,u32 changed)1826 static int hns3_check_priv_flags(struct hnae3_handle *h, u32 changed)
1827 {
1828 u32 i;
1829
1830 for (i = 0; i < HNAE3_PFLAG_MAX; i++)
1831 if ((changed & BIT(i)) && !test_bit(i, &h->supported_pflags)) {
1832 netdev_err(h->netdev, "%s is unsupported\n",
1833 hns3_priv_flags[i].name);
1834 return -EOPNOTSUPP;
1835 }
1836
1837 return 0;
1838 }
1839
hns3_set_priv_flags(struct net_device * netdev,u32 pflags)1840 static int hns3_set_priv_flags(struct net_device *netdev, u32 pflags)
1841 {
1842 struct hnae3_handle *handle = hns3_get_handle(netdev);
1843 u32 changed = pflags ^ handle->priv_flags;
1844 int ret;
1845 u32 i;
1846
1847 ret = hns3_check_priv_flags(handle, changed);
1848 if (ret)
1849 return ret;
1850
1851 for (i = 0; i < HNAE3_PFLAG_MAX; i++) {
1852 if (changed & BIT(i)) {
1853 bool enable = !(handle->priv_flags & BIT(i));
1854
1855 if (enable)
1856 handle->priv_flags |= BIT(i);
1857 else
1858 handle->priv_flags &= ~BIT(i);
1859 hns3_priv_flags[i].handler(netdev, enable);
1860 }
1861 }
1862
1863 return 0;
1864 }
1865
hns3_get_tunable(struct net_device * netdev,const struct ethtool_tunable * tuna,void * data)1866 static int hns3_get_tunable(struct net_device *netdev,
1867 const struct ethtool_tunable *tuna,
1868 void *data)
1869 {
1870 struct hns3_nic_priv *priv = netdev_priv(netdev);
1871 struct hnae3_handle *h = priv->ae_handle;
1872 int ret = 0;
1873
1874 switch (tuna->id) {
1875 case ETHTOOL_TX_COPYBREAK:
1876 /* all the tx rings have the same tx_copybreak */
1877 *(u32 *)data = priv->tx_copybreak;
1878 break;
1879 case ETHTOOL_RX_COPYBREAK:
1880 *(u32 *)data = priv->rx_copybreak;
1881 break;
1882 case ETHTOOL_TX_COPYBREAK_BUF_SIZE:
1883 *(u32 *)data = h->kinfo.tx_spare_buf_size;
1884 break;
1885 default:
1886 ret = -EOPNOTSUPP;
1887 break;
1888 }
1889
1890 return ret;
1891 }
1892
hns3_set_tx_spare_buf_size(struct net_device * netdev,u32 data)1893 static int hns3_set_tx_spare_buf_size(struct net_device *netdev,
1894 u32 data)
1895 {
1896 struct hns3_nic_priv *priv = netdev_priv(netdev);
1897 struct hnae3_handle *h = priv->ae_handle;
1898 int ret;
1899
1900 h->kinfo.tx_spare_buf_size = data;
1901
1902 ret = hns3_reset_notify(h, HNAE3_DOWN_CLIENT);
1903 if (ret)
1904 return ret;
1905
1906 ret = hns3_reset_notify(h, HNAE3_UNINIT_CLIENT);
1907 if (ret)
1908 return ret;
1909
1910 ret = hns3_reset_notify(h, HNAE3_INIT_CLIENT);
1911 if (ret)
1912 return ret;
1913
1914 ret = hns3_reset_notify(h, HNAE3_UP_CLIENT);
1915 if (ret)
1916 hns3_reset_notify(h, HNAE3_UNINIT_CLIENT);
1917
1918 return ret;
1919 }
1920
hns3_set_tunable(struct net_device * netdev,const struct ethtool_tunable * tuna,const void * data)1921 static int hns3_set_tunable(struct net_device *netdev,
1922 const struct ethtool_tunable *tuna,
1923 const void *data)
1924 {
1925 struct hns3_nic_priv *priv = netdev_priv(netdev);
1926 u32 old_tx_spare_buf_size, new_tx_spare_buf_size;
1927 struct hnae3_handle *h = priv->ae_handle;
1928 int i, ret = 0;
1929
1930 if (hns3_nic_resetting(netdev) || !priv->ring) {
1931 netdev_err(netdev, "failed to set tunable value, dev resetting!");
1932 return -EBUSY;
1933 }
1934
1935 switch (tuna->id) {
1936 case ETHTOOL_TX_COPYBREAK:
1937 priv->tx_copybreak = *(u32 *)data;
1938
1939 for (i = 0; i < h->kinfo.num_tqps; i++)
1940 priv->ring[i].tx_copybreak = priv->tx_copybreak;
1941
1942 break;
1943 case ETHTOOL_RX_COPYBREAK:
1944 priv->rx_copybreak = *(u32 *)data;
1945
1946 for (i = h->kinfo.num_tqps; i < h->kinfo.num_tqps * 2; i++)
1947 priv->ring[i].rx_copybreak = priv->rx_copybreak;
1948
1949 break;
1950 case ETHTOOL_TX_COPYBREAK_BUF_SIZE:
1951 old_tx_spare_buf_size = h->kinfo.tx_spare_buf_size;
1952 new_tx_spare_buf_size = *(u32 *)data;
1953 netdev_info(netdev, "request to set tx spare buf size from %u to %u\n",
1954 old_tx_spare_buf_size, new_tx_spare_buf_size);
1955 ret = hns3_set_tx_spare_buf_size(netdev, new_tx_spare_buf_size);
1956 if (ret ||
1957 (!priv->ring->tx_spare && new_tx_spare_buf_size != 0)) {
1958 int ret1;
1959
1960 netdev_warn(netdev, "change tx spare buf size fail, revert to old value\n");
1961 ret1 = hns3_set_tx_spare_buf_size(netdev,
1962 old_tx_spare_buf_size);
1963 if (ret1) {
1964 netdev_err(netdev, "revert to old tx spare buf size fail\n");
1965 return ret1;
1966 }
1967
1968 return ret;
1969 }
1970
1971 if (!priv->ring->tx_spare)
1972 netdev_info(netdev, "the active tx spare buf size is 0, disable tx spare buffer\n");
1973 else
1974 netdev_info(netdev, "the active tx spare buf size is %u, due to page order\n",
1975 priv->ring->tx_spare->len);
1976
1977 break;
1978 default:
1979 ret = -EOPNOTSUPP;
1980 break;
1981 }
1982
1983 return ret;
1984 }
1985
1986 #define HNS3_ETHTOOL_COALESCE (ETHTOOL_COALESCE_USECS | \
1987 ETHTOOL_COALESCE_USE_ADAPTIVE | \
1988 ETHTOOL_COALESCE_RX_USECS_HIGH | \
1989 ETHTOOL_COALESCE_TX_USECS_HIGH | \
1990 ETHTOOL_COALESCE_MAX_FRAMES | \
1991 ETHTOOL_COALESCE_USE_CQE)
1992
1993 #define HNS3_ETHTOOL_RING (ETHTOOL_RING_USE_RX_BUF_LEN | \
1994 ETHTOOL_RING_USE_TX_PUSH)
1995
hns3_get_ts_info(struct net_device * netdev,struct ethtool_ts_info * info)1996 static int hns3_get_ts_info(struct net_device *netdev,
1997 struct ethtool_ts_info *info)
1998 {
1999 struct hnae3_handle *handle = hns3_get_handle(netdev);
2000
2001 if (handle->ae_algo->ops->get_ts_info)
2002 return handle->ae_algo->ops->get_ts_info(handle, info);
2003
2004 return ethtool_op_get_ts_info(netdev, info);
2005 }
2006
2007 static const struct hns3_ethtool_link_ext_state_mapping
2008 hns3_link_ext_state_map[] = {
2009 {1, ETHTOOL_LINK_EXT_STATE_AUTONEG,
2010 ETHTOOL_LINK_EXT_SUBSTATE_AN_NO_HCD},
2011 {2, ETHTOOL_LINK_EXT_STATE_AUTONEG,
2012 ETHTOOL_LINK_EXT_SUBSTATE_AN_ACK_NOT_RECEIVED},
2013
2014 {256, ETHTOOL_LINK_EXT_STATE_LINK_TRAINING_FAILURE,
2015 ETHTOOL_LINK_EXT_SUBSTATE_LT_KR_LINK_INHIBIT_TIMEOUT},
2016 {257, ETHTOOL_LINK_EXT_STATE_LINK_TRAINING_FAILURE,
2017 ETHTOOL_LINK_EXT_SUBSTATE_LT_KR_LINK_PARTNER_DID_NOT_SET_RECEIVER_READY},
2018 {512, ETHTOOL_LINK_EXT_STATE_LINK_TRAINING_FAILURE,
2019 ETHTOOL_LINK_EXT_SUBSTATE_LT_REMOTE_FAULT},
2020
2021 {513, ETHTOOL_LINK_EXT_STATE_LINK_LOGICAL_MISMATCH,
2022 ETHTOOL_LINK_EXT_SUBSTATE_LLM_PCS_DID_NOT_ACQUIRE_BLOCK_LOCK},
2023 {514, ETHTOOL_LINK_EXT_STATE_LINK_LOGICAL_MISMATCH,
2024 ETHTOOL_LINK_EXT_SUBSTATE_LLM_FC_FEC_IS_NOT_LOCKED},
2025 {515, ETHTOOL_LINK_EXT_STATE_LINK_LOGICAL_MISMATCH,
2026 ETHTOOL_LINK_EXT_SUBSTATE_LLM_RS_FEC_IS_NOT_LOCKED},
2027
2028 {768, ETHTOOL_LINK_EXT_STATE_BAD_SIGNAL_INTEGRITY,
2029 ETHTOOL_LINK_EXT_SUBSTATE_BSI_LARGE_NUMBER_OF_PHYSICAL_ERRORS},
2030 {769, ETHTOOL_LINK_EXT_STATE_BAD_SIGNAL_INTEGRITY,
2031 ETHTOOL_LINK_EXT_SUBSTATE_BSI_SERDES_REFERENCE_CLOCK_LOST},
2032 {770, ETHTOOL_LINK_EXT_STATE_BAD_SIGNAL_INTEGRITY,
2033 ETHTOOL_LINK_EXT_SUBSTATE_BSI_SERDES_ALOS},
2034
2035 {1024, ETHTOOL_LINK_EXT_STATE_NO_CABLE, 0},
2036 {1025, ETHTOOL_LINK_EXT_STATE_CABLE_ISSUE,
2037 ETHTOOL_LINK_EXT_SUBSTATE_CI_UNSUPPORTED_CABLE},
2038
2039 {1026, ETHTOOL_LINK_EXT_STATE_EEPROM_ISSUE, 0},
2040 };
2041
hns3_get_link_ext_state(struct net_device * netdev,struct ethtool_link_ext_state_info * info)2042 static int hns3_get_link_ext_state(struct net_device *netdev,
2043 struct ethtool_link_ext_state_info *info)
2044 {
2045 const struct hns3_ethtool_link_ext_state_mapping *map;
2046 struct hnae3_handle *h = hns3_get_handle(netdev);
2047 u32 status_code, i;
2048 int ret;
2049
2050 if (netif_carrier_ok(netdev))
2051 return -ENODATA;
2052
2053 if (!h->ae_algo->ops->get_link_diagnosis_info)
2054 return -EOPNOTSUPP;
2055
2056 ret = h->ae_algo->ops->get_link_diagnosis_info(h, &status_code);
2057 if (ret)
2058 return ret;
2059
2060 for (i = 0; i < ARRAY_SIZE(hns3_link_ext_state_map); i++) {
2061 map = &hns3_link_ext_state_map[i];
2062 if (map->status_code == status_code) {
2063 info->link_ext_state = map->link_ext_state;
2064 info->__link_ext_substate = map->link_ext_substate;
2065 return 0;
2066 }
2067 }
2068
2069 return -ENODATA;
2070 }
2071
hns3_get_wol(struct net_device * netdev,struct ethtool_wolinfo * wol)2072 static void hns3_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
2073 {
2074 struct hnae3_handle *handle = hns3_get_handle(netdev);
2075 const struct hnae3_ae_ops *ops = hns3_get_ops(handle);
2076 struct hnae3_ae_dev *ae_dev = hns3_get_ae_dev(handle);
2077
2078 if (!hnae3_ae_dev_wol_supported(ae_dev))
2079 return;
2080
2081 ops->get_wol(handle, wol);
2082 }
2083
hns3_set_wol(struct net_device * netdev,struct ethtool_wolinfo * wol)2084 static int hns3_set_wol(struct net_device *netdev,
2085 struct ethtool_wolinfo *wol)
2086 {
2087 struct hnae3_handle *handle = hns3_get_handle(netdev);
2088 const struct hnae3_ae_ops *ops = hns3_get_ops(handle);
2089 struct hnae3_ae_dev *ae_dev = hns3_get_ae_dev(handle);
2090
2091 if (!hnae3_ae_dev_wol_supported(ae_dev))
2092 return -EOPNOTSUPP;
2093
2094 return ops->set_wol(handle, wol);
2095 }
2096
2097 static const struct ethtool_ops hns3vf_ethtool_ops = {
2098 .supported_coalesce_params = HNS3_ETHTOOL_COALESCE,
2099 .supported_ring_params = HNS3_ETHTOOL_RING,
2100 .get_drvinfo = hns3_get_drvinfo,
2101 .get_ringparam = hns3_get_ringparam,
2102 .set_ringparam = hns3_set_ringparam,
2103 .get_strings = hns3_get_strings,
2104 .get_ethtool_stats = hns3_get_stats,
2105 .get_sset_count = hns3_get_sset_count,
2106 .get_rxnfc = hns3_get_rxnfc,
2107 .set_rxnfc = hns3_set_rxnfc,
2108 .get_rxfh_key_size = hns3_get_rss_key_size,
2109 .get_rxfh_indir_size = hns3_get_rss_indir_size,
2110 .get_rxfh = hns3_get_rss,
2111 .set_rxfh = hns3_set_rss,
2112 .get_link_ksettings = hns3_get_link_ksettings,
2113 .get_channels = hns3_get_channels,
2114 .set_channels = hns3_set_channels,
2115 .get_coalesce = hns3_get_coalesce,
2116 .set_coalesce = hns3_set_coalesce,
2117 .get_regs_len = hns3_get_regs_len,
2118 .get_regs = hns3_get_regs,
2119 .get_link = hns3_get_link,
2120 .get_msglevel = hns3_get_msglevel,
2121 .set_msglevel = hns3_set_msglevel,
2122 .get_priv_flags = hns3_get_priv_flags,
2123 .set_priv_flags = hns3_set_priv_flags,
2124 .get_tunable = hns3_get_tunable,
2125 .set_tunable = hns3_set_tunable,
2126 .reset = hns3_set_reset,
2127 };
2128
2129 static const struct ethtool_ops hns3_ethtool_ops = {
2130 .supported_coalesce_params = HNS3_ETHTOOL_COALESCE,
2131 .supported_ring_params = HNS3_ETHTOOL_RING,
2132 .cap_link_lanes_supported = true,
2133 .self_test = hns3_self_test,
2134 .get_drvinfo = hns3_get_drvinfo,
2135 .get_link = hns3_get_link,
2136 .get_ringparam = hns3_get_ringparam,
2137 .set_ringparam = hns3_set_ringparam,
2138 .get_pauseparam = hns3_get_pauseparam,
2139 .set_pauseparam = hns3_set_pauseparam,
2140 .get_strings = hns3_get_strings,
2141 .get_ethtool_stats = hns3_get_stats,
2142 .get_sset_count = hns3_get_sset_count,
2143 .get_rxnfc = hns3_get_rxnfc,
2144 .set_rxnfc = hns3_set_rxnfc,
2145 .get_rxfh_key_size = hns3_get_rss_key_size,
2146 .get_rxfh_indir_size = hns3_get_rss_indir_size,
2147 .get_rxfh = hns3_get_rss,
2148 .set_rxfh = hns3_set_rss,
2149 .get_link_ksettings = hns3_get_link_ksettings,
2150 .set_link_ksettings = hns3_set_link_ksettings,
2151 .nway_reset = hns3_nway_reset,
2152 .get_channels = hns3_get_channels,
2153 .set_channels = hns3_set_channels,
2154 .get_coalesce = hns3_get_coalesce,
2155 .set_coalesce = hns3_set_coalesce,
2156 .get_regs_len = hns3_get_regs_len,
2157 .get_regs = hns3_get_regs,
2158 .set_phys_id = hns3_set_phys_id,
2159 .get_msglevel = hns3_get_msglevel,
2160 .set_msglevel = hns3_set_msglevel,
2161 .get_fecparam = hns3_get_fecparam,
2162 .set_fecparam = hns3_set_fecparam,
2163 .get_fec_stats = hns3_get_fec_stats,
2164 .get_module_info = hns3_get_module_info,
2165 .get_module_eeprom = hns3_get_module_eeprom,
2166 .get_priv_flags = hns3_get_priv_flags,
2167 .set_priv_flags = hns3_set_priv_flags,
2168 .get_ts_info = hns3_get_ts_info,
2169 .get_tunable = hns3_get_tunable,
2170 .set_tunable = hns3_set_tunable,
2171 .reset = hns3_set_reset,
2172 .get_link_ext_state = hns3_get_link_ext_state,
2173 .get_wol = hns3_get_wol,
2174 .set_wol = hns3_set_wol,
2175 };
2176
hns3_ethtool_set_ops(struct net_device * netdev)2177 void hns3_ethtool_set_ops(struct net_device *netdev)
2178 {
2179 struct hnae3_handle *h = hns3_get_handle(netdev);
2180
2181 if (h->flags & HNAE3_SUPPORT_VF)
2182 netdev->ethtool_ops = &hns3vf_ethtool_ops;
2183 else
2184 netdev->ethtool_ops = &hns3_ethtool_ops;
2185 }
2186