1 // SPDX-License-Identifier: GPL-2.0+
2 // Copyright (c) 2016-2017 Hisilicon Limited.
4 #include <linux/etherdevice.h>
5 #include <linux/string.h>
10 #include "hns3_ethtool.h"
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), \
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),
45 #define HNS3_TXQ_STATS_COUNT ARRAY_SIZE(hns3_txq_stats)
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),
66 #define HNS3_PRIV_FLAGS_LEN ARRAY_SIZE(hns3_priv_flags)
68 #define HNS3_RXQ_STATS_COUNT ARRAY_SIZE(hns3_rxq_stats)
70 #define HNS3_TQP_STATS_COUNT (HNS3_TXQ_STATS_COUNT + HNS3_RXQ_STATS_COUNT)
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
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
82 static int hns3_lp_setup(struct net_device *ndev, enum hnae3_loop loop, bool en)
84 struct hnae3_handle *h = hns3_get_handle(ndev);
85 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
88 if (!h->ae_algo->ops->set_loopback ||
89 !h->ae_algo->ops->set_promisc_mode)
93 case HNAE3_LOOP_SERIAL_SERDES:
94 case HNAE3_LOOP_PARALLEL_SERDES:
97 case HNAE3_LOOP_EXTERNAL:
98 ret = h->ae_algo->ops->set_loopback(h, loop, en);
105 if (ret || ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V2)
109 h->ae_algo->ops->set_promisc_mode(h, true, true);
111 /* recover promisc mode before loopback test */
112 hns3_request_update_promisc_mode(h);
117 static int hns3_lp_up(struct net_device *ndev, enum hnae3_loop loop_mode)
119 struct hnae3_handle *h = hns3_get_handle(ndev);
122 ret = hns3_nic_reset_all_ring(h);
126 ret = hns3_lp_setup(ndev, loop_mode, true);
127 usleep_range(HNS3_NIC_LB_SETUP_USEC, HNS3_NIC_LB_SETUP_USEC * 2);
132 static int hns3_lp_down(struct net_device *ndev, enum hnae3_loop loop_mode)
136 ret = hns3_lp_setup(ndev, loop_mode, false);
138 netdev_err(ndev, "lb_setup return error: %d\n", ret);
142 usleep_range(HNS3_NIC_LB_SETUP_USEC, HNS3_NIC_LB_SETUP_USEC * 2);
147 static void hns3_lp_setup_skb(struct sk_buff *skb)
149 #define HNS3_NIC_LB_DST_MAC_ADDR 0x1f
151 struct net_device *ndev = skb->dev;
152 struct hnae3_handle *handle;
153 struct hnae3_ae_dev *ae_dev;
154 unsigned char *packet;
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);
162 memcpy(ethh->h_dest, ndev->dev_addr, ETH_ALEN);
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.
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);
177 for (i = 0; i < HNS3_NIC_LB_TEST_PACKET_SIZE; i++)
178 packet[i] = (unsigned char)(i & 0xff);
181 static void hns3_lb_check_skb_data(struct hns3_enet_ring *ring,
184 struct hns3_enet_tqp_vector *tqp_vector = ring->tqp_vector;
185 unsigned char *packet = skb->data;
186 u32 len = skb_headlen(skb);
189 len = min_t(u32, len, HNS3_NIC_LB_TEST_PACKET_SIZE);
191 for (i = 0; i < len; i++)
192 if (packet[i] != (unsigned char)(i & 0xff))
195 /* The packet is correctly received */
196 if (i == HNS3_NIC_LB_TEST_PACKET_SIZE)
197 tqp_vector->rx_group.total_packets++;
199 print_hex_dump(KERN_ERR, "selftest:", DUMP_PREFIX_OFFSET, 16, 1,
200 skb->data, len, true);
202 dev_kfree_skb_any(skb);
205 static u32 hns3_lb_check_rx_ring(struct hns3_nic_priv *priv, u32 budget)
207 struct hnae3_handle *h = priv->ae_handle;
208 struct hnae3_knic_private_info *kinfo;
209 u32 i, rcv_good_pkt_total = 0;
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;
217 rx_group = &ring->tqp_vector->rx_group;
218 pre_rx_pkt = rx_group->total_packets;
221 hns3_clean_rx_ring(ring, budget, hns3_lb_check_skb_data);
224 rcv_good_pkt_total += (rx_group->total_packets - pre_rx_pkt);
225 rx_group->total_packets = pre_rx_pkt;
227 return rcv_good_pkt_total;
230 static void hns3_lb_clear_tx_ring(struct hns3_nic_priv *priv, u32 start_ringid,
231 u32 end_ringid, u32 budget)
235 for (i = start_ringid; i <= end_ringid; i++) {
236 struct hns3_enet_ring *ring = &priv->ring[i];
238 hns3_clean_tx_ring(ring, 0);
243 * hns3_lp_run_test - run loopback test
245 * @mode: loopback type
247 * Return: %0 for success or a NIC loopback test error code on failure
249 static int hns3_lp_run_test(struct net_device *ndev, enum hnae3_loop mode)
251 struct hns3_nic_priv *priv = netdev_priv(ndev);
256 skb = alloc_skb(HNS3_NIC_LB_TEST_PACKET_SIZE + ETH_HLEN + NET_IP_ALIGN,
259 return HNS3_NIC_LB_TEST_NO_MEM_ERR;
262 hns3_lp_setup_skb(skb);
263 skb->queue_mapping = HNS3_NIC_LB_TEST_RING_ID;
266 for (i = 0; i < HNS3_NIC_LB_TEST_PKT_NUM; i++) {
270 tx_ret = hns3_nic_net_xmit(skb, ndev);
271 if (tx_ret == NETDEV_TX_OK) {
275 netdev_err(ndev, "hns3_lb_run_test xmit failed: %d\n",
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);
286 /* Allow 200 milliseconds for packets to go from Tx to Rx */
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);
297 hns3_lb_clear_tx_ring(priv, HNS3_NIC_LB_TEST_RING_ID,
298 HNS3_NIC_LB_TEST_RING_ID,
299 HNS3_NIC_LB_TEST_PKT_NUM);
305 static void hns3_set_selftest_param(struct hnae3_handle *h, int (*st_param)[2])
307 st_param[HNAE3_LOOP_EXTERNAL][0] = HNAE3_LOOP_EXTERNAL;
308 st_param[HNAE3_LOOP_EXTERNAL][1] =
309 h->flags & HNAE3_SUPPORT_EXTERNAL_LOOPBACK;
311 st_param[HNAE3_LOOP_APP][0] = HNAE3_LOOP_APP;
312 st_param[HNAE3_LOOP_APP][1] =
313 h->flags & HNAE3_SUPPORT_APP_LOOPBACK;
315 st_param[HNAE3_LOOP_SERIAL_SERDES][0] = HNAE3_LOOP_SERIAL_SERDES;
316 st_param[HNAE3_LOOP_SERIAL_SERDES][1] =
317 h->flags & HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK;
319 st_param[HNAE3_LOOP_PARALLEL_SERDES][0] =
320 HNAE3_LOOP_PARALLEL_SERDES;
321 st_param[HNAE3_LOOP_PARALLEL_SERDES][1] =
322 h->flags & HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK;
324 st_param[HNAE3_LOOP_PHY][0] = HNAE3_LOOP_PHY;
325 st_param[HNAE3_LOOP_PHY][1] =
326 h->flags & HNAE3_SUPPORT_PHY_LOOPBACK;
329 static void hns3_selftest_prepare(struct net_device *ndev, bool if_running)
331 struct hns3_nic_priv *priv = netdev_priv(ndev);
332 struct hnae3_handle *h = priv->ae_handle;
335 ndev->netdev_ops->ndo_stop(ndev);
337 #if IS_ENABLED(CONFIG_VLAN_8021Q)
338 /* Disable the vlan filter for selftest does not support it */
339 if (h->ae_algo->ops->enable_vlan_filter &&
340 ndev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
341 h->ae_algo->ops->enable_vlan_filter(h, false);
344 /* Tell firmware to stop mac autoneg before loopback test start,
345 * otherwise loopback test may be failed when the port is still
348 if (h->ae_algo->ops->halt_autoneg)
349 h->ae_algo->ops->halt_autoneg(h, true);
351 set_bit(HNS3_NIC_STATE_TESTING, &priv->state);
354 static void hns3_selftest_restore(struct net_device *ndev, bool if_running)
356 struct hns3_nic_priv *priv = netdev_priv(ndev);
357 struct hnae3_handle *h = priv->ae_handle;
359 clear_bit(HNS3_NIC_STATE_TESTING, &priv->state);
361 if (h->ae_algo->ops->halt_autoneg)
362 h->ae_algo->ops->halt_autoneg(h, false);
364 #if IS_ENABLED(CONFIG_VLAN_8021Q)
365 if (h->ae_algo->ops->enable_vlan_filter &&
366 ndev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
367 h->ae_algo->ops->enable_vlan_filter(h, true);
371 ndev->netdev_ops->ndo_open(ndev);
374 static void hns3_do_selftest(struct net_device *ndev, int (*st_param)[2],
375 struct ethtool_test *eth_test, u64 *data)
377 int test_index = HNAE3_LOOP_APP;
380 for (i = HNAE3_LOOP_APP; i < HNAE3_LOOP_NONE; i++) {
381 enum hnae3_loop loop_type = (enum hnae3_loop)st_param[i][0];
386 data[test_index] = hns3_lp_up(ndev, loop_type);
387 if (!data[test_index])
388 data[test_index] = hns3_lp_run_test(ndev, loop_type);
390 hns3_lp_down(ndev, loop_type);
392 if (data[test_index])
393 eth_test->flags |= ETH_TEST_FL_FAILED;
399 static void hns3_do_external_lb(struct net_device *ndev,
400 struct ethtool_test *eth_test, u64 *data)
402 data[HNAE3_LOOP_EXTERNAL] = hns3_lp_up(ndev, HNAE3_LOOP_EXTERNAL);
403 if (!data[HNAE3_LOOP_EXTERNAL])
404 data[HNAE3_LOOP_EXTERNAL] = hns3_lp_run_test(ndev, HNAE3_LOOP_EXTERNAL);
405 hns3_lp_down(ndev, HNAE3_LOOP_EXTERNAL);
407 if (data[HNAE3_LOOP_EXTERNAL])
408 eth_test->flags |= ETH_TEST_FL_FAILED;
410 eth_test->flags |= ETH_TEST_FL_EXTERNAL_LB_DONE;
414 * hns3_self_test - self test
416 * @eth_test: test cmd
419 static void hns3_self_test(struct net_device *ndev,
420 struct ethtool_test *eth_test, u64 *data)
422 struct hns3_nic_priv *priv = netdev_priv(ndev);
423 struct hnae3_handle *h = priv->ae_handle;
424 int st_param[HNAE3_LOOP_NONE][2];
425 bool if_running = netif_running(ndev);
427 if (hns3_nic_resetting(ndev)) {
428 netdev_err(ndev, "dev resetting!");
432 if (!(eth_test->flags & ETH_TEST_FL_OFFLINE))
435 if (netif_msg_ifdown(h))
436 netdev_info(ndev, "self test start\n");
438 hns3_set_selftest_param(h, st_param);
440 /* external loopback test requires that the link is up and the duplex is
441 * full, do external test first to reduce the whole test time
443 if (eth_test->flags & ETH_TEST_FL_EXTERNAL_LB) {
444 hns3_external_lb_prepare(ndev, if_running);
445 hns3_do_external_lb(ndev, eth_test, data);
446 hns3_external_lb_restore(ndev, if_running);
449 hns3_selftest_prepare(ndev, if_running);
450 hns3_do_selftest(ndev, st_param, eth_test, data);
451 hns3_selftest_restore(ndev, if_running);
453 if (netif_msg_ifdown(h))
454 netdev_info(ndev, "self test end\n");
457 static void hns3_update_limit_promisc_mode(struct net_device *netdev,
460 struct hnae3_handle *handle = hns3_get_handle(netdev);
463 set_bit(HNAE3_PFLAG_LIMIT_PROMISC, &handle->priv_flags);
465 clear_bit(HNAE3_PFLAG_LIMIT_PROMISC, &handle->priv_flags);
467 hns3_request_update_promisc_mode(handle);
470 static const struct hns3_pflag_desc hns3_priv_flags[HNAE3_PFLAG_MAX] = {
471 { "limit_promisc", hns3_update_limit_promisc_mode }
474 static int hns3_get_sset_count(struct net_device *netdev, int stringset)
476 struct hnae3_handle *h = hns3_get_handle(netdev);
477 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
479 if (!ops->get_sset_count)
484 return ((HNS3_TQP_STATS_COUNT * h->kinfo.num_tqps) +
485 ops->get_sset_count(h, stringset));
488 return ops->get_sset_count(h, stringset);
490 case ETH_SS_PRIV_FLAGS:
491 return HNAE3_PFLAG_MAX;
498 static void *hns3_update_strings(u8 *data, const struct hns3_stats *stats,
499 u32 stat_count, u32 num_tqps, const char *prefix)
501 #define MAX_PREFIX_SIZE (6 + 4)
506 for (i = 0; i < num_tqps; i++) {
507 for (j = 0; j < stat_count; j++) {
508 data[ETH_GSTRING_LEN - 1] = '\0';
510 /* first, prepend the prefix string */
511 n1 = scnprintf(data, MAX_PREFIX_SIZE, "%s%u_",
513 size_left = (ETH_GSTRING_LEN - 1) - n1;
515 /* now, concatenate the stats string to it */
516 strncat(data, stats[j].stats_string, size_left);
517 data += ETH_GSTRING_LEN;
524 static u8 *hns3_get_strings_tqps(struct hnae3_handle *handle, u8 *data)
526 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
527 const char tx_prefix[] = "txq";
528 const char rx_prefix[] = "rxq";
530 /* get strings for Tx */
531 data = hns3_update_strings(data, hns3_txq_stats, HNS3_TXQ_STATS_COUNT,
532 kinfo->num_tqps, tx_prefix);
534 /* get strings for Rx */
535 data = hns3_update_strings(data, hns3_rxq_stats, HNS3_RXQ_STATS_COUNT,
536 kinfo->num_tqps, rx_prefix);
541 static void hns3_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
543 struct hnae3_handle *h = hns3_get_handle(netdev);
544 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
545 char *buff = (char *)data;
548 if (!ops->get_strings)
553 buff = hns3_get_strings_tqps(h, buff);
554 ops->get_strings(h, stringset, (u8 *)buff);
557 ops->get_strings(h, stringset, data);
559 case ETH_SS_PRIV_FLAGS:
560 for (i = 0; i < HNS3_PRIV_FLAGS_LEN; i++) {
561 snprintf(buff, ETH_GSTRING_LEN, "%s",
562 hns3_priv_flags[i].name);
563 buff += ETH_GSTRING_LEN;
571 static u64 *hns3_get_stats_tqps(struct hnae3_handle *handle, u64 *data)
573 struct hns3_nic_priv *nic_priv = (struct hns3_nic_priv *)handle->priv;
574 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
575 struct hns3_enet_ring *ring;
579 /* get stats for Tx */
580 for (i = 0; i < kinfo->num_tqps; i++) {
581 ring = &nic_priv->ring[i];
582 for (j = 0; j < HNS3_TXQ_STATS_COUNT; j++) {
583 stat = (u8 *)ring + hns3_txq_stats[j].stats_offset;
584 *data++ = *(u64 *)stat;
588 /* get stats for Rx */
589 for (i = 0; i < kinfo->num_tqps; i++) {
590 ring = &nic_priv->ring[i + kinfo->num_tqps];
591 for (j = 0; j < HNS3_RXQ_STATS_COUNT; j++) {
592 stat = (u8 *)ring + hns3_rxq_stats[j].stats_offset;
593 *data++ = *(u64 *)stat;
600 /* hns3_get_stats - get detail statistics.
601 * @netdev: net device
602 * @stats: statistics info.
603 * @data: statistics data.
605 static void hns3_get_stats(struct net_device *netdev,
606 struct ethtool_stats *stats, u64 *data)
608 struct hnae3_handle *h = hns3_get_handle(netdev);
611 if (hns3_nic_resetting(netdev)) {
612 netdev_err(netdev, "dev resetting, could not get stats\n");
616 if (!h->ae_algo->ops->get_stats || !h->ae_algo->ops->update_stats) {
617 netdev_err(netdev, "could not get any statistics\n");
621 h->ae_algo->ops->update_stats(h, &netdev->stats);
623 /* get per-queue stats */
624 p = hns3_get_stats_tqps(h, p);
626 /* get MAC & other misc hardware stats */
627 h->ae_algo->ops->get_stats(h, p);
630 static void hns3_get_drvinfo(struct net_device *netdev,
631 struct ethtool_drvinfo *drvinfo)
633 struct hns3_nic_priv *priv = netdev_priv(netdev);
634 struct hnae3_handle *h = priv->ae_handle;
637 if (!h->ae_algo->ops->get_fw_version) {
638 netdev_err(netdev, "could not get fw version!\n");
642 strncpy(drvinfo->driver, dev_driver_string(&h->pdev->dev),
643 sizeof(drvinfo->driver));
644 drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
646 strncpy(drvinfo->bus_info, pci_name(h->pdev),
647 sizeof(drvinfo->bus_info));
648 drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';
650 fw_version = priv->ae_handle->ae_algo->ops->get_fw_version(h);
652 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
654 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE3_MASK,
655 HNAE3_FW_VERSION_BYTE3_SHIFT),
656 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE2_MASK,
657 HNAE3_FW_VERSION_BYTE2_SHIFT),
658 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE1_MASK,
659 HNAE3_FW_VERSION_BYTE1_SHIFT),
660 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE0_MASK,
661 HNAE3_FW_VERSION_BYTE0_SHIFT));
664 static u32 hns3_get_link(struct net_device *netdev)
666 struct hnae3_handle *h = hns3_get_handle(netdev);
668 if (h->ae_algo->ops->get_status)
669 return h->ae_algo->ops->get_status(h);
674 static void hns3_get_ringparam(struct net_device *netdev,
675 struct ethtool_ringparam *param,
676 struct kernel_ethtool_ringparam *kernel_param,
677 struct netlink_ext_ack *extack)
679 struct hns3_nic_priv *priv = netdev_priv(netdev);
680 struct hnae3_handle *h = priv->ae_handle;
681 int rx_queue_index = h->kinfo.num_tqps;
683 if (hns3_nic_resetting(netdev) || !priv->ring) {
684 netdev_err(netdev, "failed to get ringparam value, due to dev resetting or uninited\n");
688 param->tx_max_pending = HNS3_RING_MAX_PENDING;
689 param->rx_max_pending = HNS3_RING_MAX_PENDING;
691 param->tx_pending = priv->ring[0].desc_num;
692 param->rx_pending = priv->ring[rx_queue_index].desc_num;
693 kernel_param->rx_buf_len = priv->ring[rx_queue_index].buf_size;
694 kernel_param->tx_push = test_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE,
698 static void hns3_get_pauseparam(struct net_device *netdev,
699 struct ethtool_pauseparam *param)
701 struct hnae3_handle *h = hns3_get_handle(netdev);
702 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
704 if (!test_bit(HNAE3_DEV_SUPPORT_PAUSE_B, ae_dev->caps))
707 if (h->ae_algo->ops->get_pauseparam)
708 h->ae_algo->ops->get_pauseparam(h, ¶m->autoneg,
709 ¶m->rx_pause, ¶m->tx_pause);
712 static int hns3_set_pauseparam(struct net_device *netdev,
713 struct ethtool_pauseparam *param)
715 struct hnae3_handle *h = hns3_get_handle(netdev);
716 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
718 if (!test_bit(HNAE3_DEV_SUPPORT_PAUSE_B, ae_dev->caps))
721 netif_dbg(h, drv, netdev,
722 "set pauseparam: autoneg=%u, rx:%u, tx:%u\n",
723 param->autoneg, param->rx_pause, param->tx_pause);
725 if (h->ae_algo->ops->set_pauseparam)
726 return h->ae_algo->ops->set_pauseparam(h, param->autoneg,
732 static void hns3_get_ksettings(struct hnae3_handle *h,
733 struct ethtool_link_ksettings *cmd)
735 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
737 /* 1.auto_neg & speed & duplex from cmd */
738 if (ops->get_ksettings_an_result)
739 ops->get_ksettings_an_result(h,
745 /* 2.get link mode */
746 if (ops->get_link_mode)
747 ops->get_link_mode(h,
748 cmd->link_modes.supported,
749 cmd->link_modes.advertising);
751 /* 3.mdix_ctrl&mdix get from phy reg */
752 if (ops->get_mdix_mode)
753 ops->get_mdix_mode(h, &cmd->base.eth_tp_mdix_ctrl,
754 &cmd->base.eth_tp_mdix);
757 static int hns3_get_link_ksettings(struct net_device *netdev,
758 struct ethtool_link_ksettings *cmd)
760 struct hnae3_handle *h = hns3_get_handle(netdev);
761 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
762 const struct hnae3_ae_ops *ops;
767 ops = h->ae_algo->ops;
768 if (ops->get_media_type)
769 ops->get_media_type(h, &media_type, &module_type);
773 switch (media_type) {
774 case HNAE3_MEDIA_TYPE_NONE:
775 cmd->base.port = PORT_NONE;
776 hns3_get_ksettings(h, cmd);
778 case HNAE3_MEDIA_TYPE_FIBER:
779 if (module_type == HNAE3_MODULE_TYPE_CR)
780 cmd->base.port = PORT_DA;
782 cmd->base.port = PORT_FIBRE;
784 hns3_get_ksettings(h, cmd);
786 case HNAE3_MEDIA_TYPE_BACKPLANE:
787 cmd->base.port = PORT_NONE;
788 hns3_get_ksettings(h, cmd);
790 case HNAE3_MEDIA_TYPE_COPPER:
791 cmd->base.port = PORT_TP;
792 if (test_bit(HNAE3_DEV_SUPPORT_PHY_IMP_B, ae_dev->caps) &&
793 ops->get_phy_link_ksettings)
794 ops->get_phy_link_ksettings(h, cmd);
795 else if (!netdev->phydev)
796 hns3_get_ksettings(h, cmd);
798 phy_ethtool_ksettings_get(netdev->phydev, cmd);
802 netdev_warn(netdev, "Unknown media type");
807 cmd->base.mdio_support = ETH_MDIO_SUPPORTS_C22;
809 link_stat = hns3_get_link(netdev);
811 cmd->base.speed = SPEED_UNKNOWN;
812 cmd->base.duplex = DUPLEX_UNKNOWN;
818 static int hns3_check_ksettings_param(const struct net_device *netdev,
819 const struct ethtool_link_ksettings *cmd)
821 struct hnae3_handle *handle = hns3_get_handle(netdev);
822 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
823 u8 module_type = HNAE3_MODULE_TYPE_UNKNOWN;
824 u8 media_type = HNAE3_MEDIA_TYPE_UNKNOWN;
831 /* hw doesn't support use specified speed and duplex to negotiate,
832 * unnecessary to check them when autoneg on.
834 if (cmd->base.autoneg)
837 if (ops->get_ksettings_an_result) {
838 ops->get_ksettings_an_result(handle, &autoneg, &speed, &duplex, &lane_num);
839 if (cmd->base.autoneg == autoneg && cmd->base.speed == speed &&
840 cmd->base.duplex == duplex && cmd->lanes == lane_num)
844 if (ops->get_media_type)
845 ops->get_media_type(handle, &media_type, &module_type);
847 if (cmd->base.duplex == DUPLEX_HALF &&
848 media_type != HNAE3_MEDIA_TYPE_COPPER) {
850 "only copper port supports half duplex!");
854 if (ops->check_port_speed) {
855 ret = ops->check_port_speed(handle, cmd->base.speed);
857 netdev_err(netdev, "unsupported speed\n");
865 static int hns3_set_link_ksettings(struct net_device *netdev,
866 const struct ethtool_link_ksettings *cmd)
868 struct hnae3_handle *handle = hns3_get_handle(netdev);
869 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
870 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
873 /* Chip don't support this mode. */
874 if (cmd->base.speed == SPEED_1000 && cmd->base.duplex == DUPLEX_HALF)
877 if (cmd->lanes && !hnae3_ae_dev_lane_num_supported(ae_dev))
880 netif_dbg(handle, drv, netdev,
881 "set link(%s): autoneg=%u, speed=%u, duplex=%u, lanes=%u\n",
882 netdev->phydev ? "phy" : "mac",
883 cmd->base.autoneg, cmd->base.speed, cmd->base.duplex,
886 /* Only support ksettings_set for netdev with phy attached for now */
887 if (netdev->phydev) {
888 if (cmd->base.speed == SPEED_1000 &&
889 cmd->base.autoneg == AUTONEG_DISABLE)
892 return phy_ethtool_ksettings_set(netdev->phydev, cmd);
893 } else if (test_bit(HNAE3_DEV_SUPPORT_PHY_IMP_B, ae_dev->caps) &&
894 ops->set_phy_link_ksettings) {
895 return ops->set_phy_link_ksettings(handle, cmd);
898 if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2)
901 ret = hns3_check_ksettings_param(netdev, cmd);
905 if (ops->set_autoneg) {
906 ret = ops->set_autoneg(handle, cmd->base.autoneg);
911 /* hw doesn't support use specified speed and duplex to negotiate,
912 * ignore them when autoneg on.
914 if (cmd->base.autoneg) {
916 "autoneg is on, ignore the speed and duplex\n");
920 if (ops->cfg_mac_speed_dup_h)
921 ret = ops->cfg_mac_speed_dup_h(handle, cmd->base.speed,
922 cmd->base.duplex, (u8)(cmd->lanes));
927 static u32 hns3_get_rss_key_size(struct net_device *netdev)
929 struct hnae3_handle *h = hns3_get_handle(netdev);
931 if (!h->ae_algo->ops->get_rss_key_size)
934 return h->ae_algo->ops->get_rss_key_size(h);
937 static u32 hns3_get_rss_indir_size(struct net_device *netdev)
939 struct hnae3_handle *h = hns3_get_handle(netdev);
940 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
942 return ae_dev->dev_specs.rss_ind_tbl_size;
945 static int hns3_get_rss(struct net_device *netdev, u32 *indir, u8 *key,
948 struct hnae3_handle *h = hns3_get_handle(netdev);
950 if (!h->ae_algo->ops->get_rss)
953 return h->ae_algo->ops->get_rss(h, indir, key, hfunc);
956 static int hns3_set_rss(struct net_device *netdev, const u32 *indir,
957 const u8 *key, const u8 hfunc)
959 struct hnae3_handle *h = hns3_get_handle(netdev);
960 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
962 if (!h->ae_algo->ops->set_rss)
965 if ((ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 &&
966 hfunc != ETH_RSS_HASH_TOP) || (hfunc != ETH_RSS_HASH_NO_CHANGE &&
967 hfunc != ETH_RSS_HASH_TOP && hfunc != ETH_RSS_HASH_XOR)) {
968 netdev_err(netdev, "hash func not supported\n");
974 "set rss failed for indir is empty\n");
978 return h->ae_algo->ops->set_rss(h, indir, key, hfunc);
981 static int hns3_get_rxnfc(struct net_device *netdev,
982 struct ethtool_rxnfc *cmd,
985 struct hnae3_handle *h = hns3_get_handle(netdev);
988 case ETHTOOL_GRXRINGS:
989 cmd->data = h->kinfo.num_tqps;
992 if (h->ae_algo->ops->get_rss_tuple)
993 return h->ae_algo->ops->get_rss_tuple(h, cmd);
995 case ETHTOOL_GRXCLSRLCNT:
996 if (h->ae_algo->ops->get_fd_rule_cnt)
997 return h->ae_algo->ops->get_fd_rule_cnt(h, cmd);
999 case ETHTOOL_GRXCLSRULE:
1000 if (h->ae_algo->ops->get_fd_rule_info)
1001 return h->ae_algo->ops->get_fd_rule_info(h, cmd);
1003 case ETHTOOL_GRXCLSRLALL:
1004 if (h->ae_algo->ops->get_fd_all_rules)
1005 return h->ae_algo->ops->get_fd_all_rules(h, cmd,
1013 static const struct hns3_reset_type_map hns3_reset_type[] = {
1014 {ETH_RESET_MGMT, HNAE3_IMP_RESET},
1015 {ETH_RESET_ALL, HNAE3_GLOBAL_RESET},
1016 {ETH_RESET_DEDICATED, HNAE3_FUNC_RESET},
1019 static const struct hns3_reset_type_map hns3vf_reset_type[] = {
1020 {ETH_RESET_DEDICATED, HNAE3_VF_FUNC_RESET},
1023 static int hns3_set_reset(struct net_device *netdev, u32 *flags)
1025 enum hnae3_reset_type rst_type = HNAE3_NONE_RESET;
1026 struct hnae3_handle *h = hns3_get_handle(netdev);
1027 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
1028 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
1029 const struct hns3_reset_type_map *rst_type_map;
1030 enum ethtool_reset_flags rst_flags;
1033 if (ops->ae_dev_resetting && ops->ae_dev_resetting(h))
1036 if (!ops->set_default_reset_request || !ops->reset_event)
1039 if (h->flags & HNAE3_SUPPORT_VF) {
1040 rst_type_map = hns3vf_reset_type;
1041 size = ARRAY_SIZE(hns3vf_reset_type);
1043 rst_type_map = hns3_reset_type;
1044 size = ARRAY_SIZE(hns3_reset_type);
1047 for (i = 0; i < size; i++) {
1048 if (rst_type_map[i].rst_flags == *flags) {
1049 rst_type = rst_type_map[i].rst_type;
1050 rst_flags = rst_type_map[i].rst_flags;
1055 if (rst_type == HNAE3_NONE_RESET ||
1056 (rst_type == HNAE3_IMP_RESET &&
1057 ae_dev->dev_version <= HNAE3_DEVICE_VERSION_V2))
1060 netdev_info(netdev, "Setting reset type %d\n", rst_type);
1062 ops->set_default_reset_request(ae_dev, rst_type);
1064 ops->reset_event(h->pdev, h);
1066 *flags &= ~rst_flags;
1071 static void hns3_change_all_ring_bd_num(struct hns3_nic_priv *priv,
1072 u32 tx_desc_num, u32 rx_desc_num)
1074 struct hnae3_handle *h = priv->ae_handle;
1077 h->kinfo.num_tx_desc = tx_desc_num;
1078 h->kinfo.num_rx_desc = rx_desc_num;
1080 for (i = 0; i < h->kinfo.num_tqps; i++) {
1081 priv->ring[i].desc_num = tx_desc_num;
1082 priv->ring[i + h->kinfo.num_tqps].desc_num = rx_desc_num;
1086 static struct hns3_enet_ring *hns3_backup_ringparam(struct hns3_nic_priv *priv)
1088 struct hnae3_handle *handle = priv->ae_handle;
1089 struct hns3_enet_ring *tmp_rings;
1092 tmp_rings = kcalloc(handle->kinfo.num_tqps * 2,
1093 sizeof(struct hns3_enet_ring), GFP_KERNEL);
1097 for (i = 0; i < handle->kinfo.num_tqps * 2; i++) {
1098 memcpy(&tmp_rings[i], &priv->ring[i],
1099 sizeof(struct hns3_enet_ring));
1100 tmp_rings[i].skb = NULL;
1106 static int hns3_check_ringparam(struct net_device *ndev,
1107 struct ethtool_ringparam *param,
1108 struct kernel_ethtool_ringparam *kernel_param)
1110 #define RX_BUF_LEN_2K 2048
1111 #define RX_BUF_LEN_4K 4096
1113 struct hns3_nic_priv *priv = netdev_priv(ndev);
1115 if (hns3_nic_resetting(ndev) || !priv->ring) {
1116 netdev_err(ndev, "failed to set ringparam value, due to dev resetting or uninited\n");
1121 if (param->rx_mini_pending || param->rx_jumbo_pending)
1124 if (kernel_param->rx_buf_len != RX_BUF_LEN_2K &&
1125 kernel_param->rx_buf_len != RX_BUF_LEN_4K) {
1126 netdev_err(ndev, "Rx buf len only support 2048 and 4096\n");
1130 if (param->tx_pending > HNS3_RING_MAX_PENDING ||
1131 param->tx_pending < HNS3_RING_MIN_PENDING ||
1132 param->rx_pending > HNS3_RING_MAX_PENDING ||
1133 param->rx_pending < HNS3_RING_MIN_PENDING) {
1134 netdev_err(ndev, "Queue depth out of range [%d-%d]\n",
1135 HNS3_RING_MIN_PENDING, HNS3_RING_MAX_PENDING);
1143 hns3_is_ringparam_changed(struct net_device *ndev,
1144 struct ethtool_ringparam *param,
1145 struct kernel_ethtool_ringparam *kernel_param,
1146 struct hns3_ring_param *old_ringparam,
1147 struct hns3_ring_param *new_ringparam)
1149 struct hns3_nic_priv *priv = netdev_priv(ndev);
1150 struct hnae3_handle *h = priv->ae_handle;
1151 u16 queue_num = h->kinfo.num_tqps;
1153 new_ringparam->tx_desc_num = ALIGN(param->tx_pending,
1154 HNS3_RING_BD_MULTIPLE);
1155 new_ringparam->rx_desc_num = ALIGN(param->rx_pending,
1156 HNS3_RING_BD_MULTIPLE);
1157 old_ringparam->tx_desc_num = priv->ring[0].desc_num;
1158 old_ringparam->rx_desc_num = priv->ring[queue_num].desc_num;
1159 old_ringparam->rx_buf_len = priv->ring[queue_num].buf_size;
1160 new_ringparam->rx_buf_len = kernel_param->rx_buf_len;
1162 if (old_ringparam->tx_desc_num == new_ringparam->tx_desc_num &&
1163 old_ringparam->rx_desc_num == new_ringparam->rx_desc_num &&
1164 old_ringparam->rx_buf_len == new_ringparam->rx_buf_len) {
1165 netdev_info(ndev, "descriptor number and rx buffer length not changed\n");
1172 static int hns3_change_rx_buf_len(struct net_device *ndev, u32 rx_buf_len)
1174 struct hns3_nic_priv *priv = netdev_priv(ndev);
1175 struct hnae3_handle *h = priv->ae_handle;
1178 h->kinfo.rx_buf_len = rx_buf_len;
1180 for (i = 0; i < h->kinfo.num_tqps; i++) {
1181 h->kinfo.tqp[i]->buf_size = rx_buf_len;
1182 priv->ring[i + h->kinfo.num_tqps].buf_size = rx_buf_len;
1188 static int hns3_set_tx_push(struct net_device *netdev, u32 tx_push)
1190 struct hns3_nic_priv *priv = netdev_priv(netdev);
1191 struct hnae3_handle *h = hns3_get_handle(netdev);
1192 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(h->pdev);
1193 u32 old_state = test_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state);
1195 if (!test_bit(HNAE3_DEV_SUPPORT_TX_PUSH_B, ae_dev->caps) && tx_push)
1198 if (tx_push == old_state)
1201 netdev_dbg(netdev, "Changing tx push from %s to %s\n",
1202 old_state ? "on" : "off", tx_push ? "on" : "off");
1205 set_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state);
1207 clear_bit(HNS3_NIC_STATE_TX_PUSH_ENABLE, &priv->state);
1212 static int hns3_set_ringparam(struct net_device *ndev,
1213 struct ethtool_ringparam *param,
1214 struct kernel_ethtool_ringparam *kernel_param,
1215 struct netlink_ext_ack *extack)
1217 struct hns3_ring_param old_ringparam, new_ringparam;
1218 struct hns3_nic_priv *priv = netdev_priv(ndev);
1219 struct hnae3_handle *h = priv->ae_handle;
1220 struct hns3_enet_ring *tmp_rings;
1221 bool if_running = netif_running(ndev);
1224 ret = hns3_check_ringparam(ndev, param, kernel_param);
1228 ret = hns3_set_tx_push(ndev, kernel_param->tx_push);
1232 if (!hns3_is_ringparam_changed(ndev, param, kernel_param,
1233 &old_ringparam, &new_ringparam))
1236 tmp_rings = hns3_backup_ringparam(priv);
1238 netdev_err(ndev, "backup ring param failed by allocating memory fail\n");
1243 "Changing Tx/Rx ring depth from %u/%u to %u/%u, Changing rx buffer len from %u to %u\n",
1244 old_ringparam.tx_desc_num, old_ringparam.rx_desc_num,
1245 new_ringparam.tx_desc_num, new_ringparam.rx_desc_num,
1246 old_ringparam.rx_buf_len, new_ringparam.rx_buf_len);
1249 ndev->netdev_ops->ndo_stop(ndev);
1251 hns3_change_all_ring_bd_num(priv, new_ringparam.tx_desc_num,
1252 new_ringparam.rx_desc_num);
1253 hns3_change_rx_buf_len(ndev, new_ringparam.rx_buf_len);
1254 ret = hns3_init_all_ring(priv);
1256 netdev_err(ndev, "set ringparam fail, revert to old value(%d)\n",
1259 hns3_change_rx_buf_len(ndev, old_ringparam.rx_buf_len);
1260 hns3_change_all_ring_bd_num(priv, old_ringparam.tx_desc_num,
1261 old_ringparam.rx_desc_num);
1262 for (i = 0; i < h->kinfo.num_tqps * 2; i++)
1263 memcpy(&priv->ring[i], &tmp_rings[i],
1264 sizeof(struct hns3_enet_ring));
1266 for (i = 0; i < h->kinfo.num_tqps * 2; i++)
1267 hns3_fini_ring(&tmp_rings[i]);
1273 ret = ndev->netdev_ops->ndo_open(ndev);
1278 static int hns3_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1280 struct hnae3_handle *h = hns3_get_handle(netdev);
1284 if (h->ae_algo->ops->set_rss_tuple)
1285 return h->ae_algo->ops->set_rss_tuple(h, cmd);
1287 case ETHTOOL_SRXCLSRLINS:
1288 if (h->ae_algo->ops->add_fd_entry)
1289 return h->ae_algo->ops->add_fd_entry(h, cmd);
1291 case ETHTOOL_SRXCLSRLDEL:
1292 if (h->ae_algo->ops->del_fd_entry)
1293 return h->ae_algo->ops->del_fd_entry(h, cmd);
1300 static int hns3_nway_reset(struct net_device *netdev)
1302 struct hnae3_handle *handle = hns3_get_handle(netdev);
1303 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1304 struct phy_device *phy = netdev->phydev;
1307 if (!netif_running(netdev))
1310 if (hns3_nic_resetting(netdev)) {
1311 netdev_err(netdev, "dev resetting!");
1315 if (!ops->get_autoneg || !ops->restart_autoneg)
1318 autoneg = ops->get_autoneg(handle);
1319 if (autoneg != AUTONEG_ENABLE) {
1321 "Autoneg is off, don't support to restart it\n");
1325 netif_dbg(handle, drv, netdev,
1326 "nway reset (using %s)\n", phy ? "phy" : "mac");
1329 return genphy_restart_aneg(phy);
1331 return ops->restart_autoneg(handle);
1334 static void hns3_get_channels(struct net_device *netdev,
1335 struct ethtool_channels *ch)
1337 struct hnae3_handle *h = hns3_get_handle(netdev);
1339 if (h->ae_algo->ops->get_channels)
1340 h->ae_algo->ops->get_channels(h, ch);
1343 static int hns3_get_coalesce(struct net_device *netdev,
1344 struct ethtool_coalesce *cmd,
1345 struct kernel_ethtool_coalesce *kernel_coal,
1346 struct netlink_ext_ack *extack)
1348 struct hns3_nic_priv *priv = netdev_priv(netdev);
1349 struct hns3_enet_coalesce *tx_coal = &priv->tx_coal;
1350 struct hns3_enet_coalesce *rx_coal = &priv->rx_coal;
1351 struct hnae3_handle *h = priv->ae_handle;
1353 if (hns3_nic_resetting(netdev))
1356 cmd->use_adaptive_tx_coalesce = tx_coal->adapt_enable;
1357 cmd->use_adaptive_rx_coalesce = rx_coal->adapt_enable;
1359 cmd->tx_coalesce_usecs = tx_coal->int_gl;
1360 cmd->rx_coalesce_usecs = rx_coal->int_gl;
1362 cmd->tx_coalesce_usecs_high = h->kinfo.int_rl_setting;
1363 cmd->rx_coalesce_usecs_high = h->kinfo.int_rl_setting;
1365 cmd->tx_max_coalesced_frames = tx_coal->int_ql;
1366 cmd->rx_max_coalesced_frames = rx_coal->int_ql;
1368 kernel_coal->use_cqe_mode_tx = (priv->tx_cqe_mode ==
1369 DIM_CQ_PERIOD_MODE_START_FROM_CQE);
1370 kernel_coal->use_cqe_mode_rx = (priv->rx_cqe_mode ==
1371 DIM_CQ_PERIOD_MODE_START_FROM_CQE);
1376 static int hns3_check_gl_coalesce_para(struct net_device *netdev,
1377 struct ethtool_coalesce *cmd)
1379 struct hnae3_handle *handle = hns3_get_handle(netdev);
1380 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1383 if (cmd->rx_coalesce_usecs > ae_dev->dev_specs.max_int_gl) {
1385 "invalid rx-usecs value, rx-usecs range is 0-%u\n",
1386 ae_dev->dev_specs.max_int_gl);
1390 if (cmd->tx_coalesce_usecs > ae_dev->dev_specs.max_int_gl) {
1392 "invalid tx-usecs value, tx-usecs range is 0-%u\n",
1393 ae_dev->dev_specs.max_int_gl);
1397 /* device version above V3(include V3), GL uses 1us unit,
1398 * so the round down is not needed.
1400 if (ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V3)
1403 rx_gl = hns3_gl_round_down(cmd->rx_coalesce_usecs);
1404 if (rx_gl != cmd->rx_coalesce_usecs) {
1406 "rx_usecs(%u) rounded down to %u, because it must be multiple of 2.\n",
1407 cmd->rx_coalesce_usecs, rx_gl);
1410 tx_gl = hns3_gl_round_down(cmd->tx_coalesce_usecs);
1411 if (tx_gl != cmd->tx_coalesce_usecs) {
1413 "tx_usecs(%u) rounded down to %u, because it must be multiple of 2.\n",
1414 cmd->tx_coalesce_usecs, tx_gl);
1420 static int hns3_check_rl_coalesce_para(struct net_device *netdev,
1421 struct ethtool_coalesce *cmd)
1425 if (cmd->tx_coalesce_usecs_high != cmd->rx_coalesce_usecs_high) {
1427 "tx_usecs_high must be same as rx_usecs_high.\n");
1431 if (cmd->rx_coalesce_usecs_high > HNS3_INT_RL_MAX) {
1433 "Invalid usecs_high value, usecs_high range is 0-%d\n",
1438 rl = hns3_rl_round_down(cmd->rx_coalesce_usecs_high);
1439 if (rl != cmd->rx_coalesce_usecs_high) {
1441 "usecs_high(%u) rounded down to %u, because it must be multiple of 4.\n",
1442 cmd->rx_coalesce_usecs_high, rl);
1448 static int hns3_check_ql_coalesce_param(struct net_device *netdev,
1449 struct ethtool_coalesce *cmd)
1451 struct hnae3_handle *handle = hns3_get_handle(netdev);
1452 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1454 if ((cmd->tx_max_coalesced_frames || cmd->rx_max_coalesced_frames) &&
1455 !ae_dev->dev_specs.int_ql_max) {
1456 netdev_err(netdev, "coalesced frames is not supported\n");
1460 if (cmd->tx_max_coalesced_frames > ae_dev->dev_specs.int_ql_max ||
1461 cmd->rx_max_coalesced_frames > ae_dev->dev_specs.int_ql_max) {
1463 "invalid coalesced_frames value, range is 0-%u\n",
1464 ae_dev->dev_specs.int_ql_max);
1472 hns3_check_cqe_coalesce_param(struct net_device *netdev,
1473 struct kernel_ethtool_coalesce *kernel_coal)
1475 struct hnae3_handle *handle = hns3_get_handle(netdev);
1476 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1478 if ((kernel_coal->use_cqe_mode_tx || kernel_coal->use_cqe_mode_rx) &&
1479 !hnae3_ae_dev_cq_supported(ae_dev)) {
1480 netdev_err(netdev, "coalesced cqe mode is not supported\n");
1488 hns3_check_coalesce_para(struct net_device *netdev,
1489 struct ethtool_coalesce *cmd,
1490 struct kernel_ethtool_coalesce *kernel_coal)
1494 ret = hns3_check_cqe_coalesce_param(netdev, kernel_coal);
1498 ret = hns3_check_gl_coalesce_para(netdev, cmd);
1501 "Check gl coalesce param fail. ret = %d\n", ret);
1505 ret = hns3_check_rl_coalesce_para(netdev, cmd);
1508 "Check rl coalesce param fail. ret = %d\n", ret);
1512 return hns3_check_ql_coalesce_param(netdev, cmd);
1515 static void hns3_set_coalesce_per_queue(struct net_device *netdev,
1516 struct ethtool_coalesce *cmd,
1519 struct hns3_enet_tqp_vector *tx_vector, *rx_vector;
1520 struct hns3_nic_priv *priv = netdev_priv(netdev);
1521 struct hnae3_handle *h = priv->ae_handle;
1522 int queue_num = h->kinfo.num_tqps;
1524 tx_vector = priv->ring[queue].tqp_vector;
1525 rx_vector = priv->ring[queue_num + queue].tqp_vector;
1527 tx_vector->tx_group.coal.adapt_enable =
1528 cmd->use_adaptive_tx_coalesce;
1529 rx_vector->rx_group.coal.adapt_enable =
1530 cmd->use_adaptive_rx_coalesce;
1532 tx_vector->tx_group.coal.int_gl = cmd->tx_coalesce_usecs;
1533 rx_vector->rx_group.coal.int_gl = cmd->rx_coalesce_usecs;
1535 tx_vector->tx_group.coal.int_ql = cmd->tx_max_coalesced_frames;
1536 rx_vector->rx_group.coal.int_ql = cmd->rx_max_coalesced_frames;
1538 hns3_set_vector_coalesce_tx_gl(tx_vector,
1539 tx_vector->tx_group.coal.int_gl);
1540 hns3_set_vector_coalesce_rx_gl(rx_vector,
1541 rx_vector->rx_group.coal.int_gl);
1543 hns3_set_vector_coalesce_rl(tx_vector, h->kinfo.int_rl_setting);
1544 hns3_set_vector_coalesce_rl(rx_vector, h->kinfo.int_rl_setting);
1546 if (tx_vector->tx_group.coal.ql_enable)
1547 hns3_set_vector_coalesce_tx_ql(tx_vector,
1548 tx_vector->tx_group.coal.int_ql);
1549 if (rx_vector->rx_group.coal.ql_enable)
1550 hns3_set_vector_coalesce_rx_ql(rx_vector,
1551 rx_vector->rx_group.coal.int_ql);
1554 static int hns3_set_coalesce(struct net_device *netdev,
1555 struct ethtool_coalesce *cmd,
1556 struct kernel_ethtool_coalesce *kernel_coal,
1557 struct netlink_ext_ack *extack)
1559 struct hnae3_handle *h = hns3_get_handle(netdev);
1560 struct hns3_nic_priv *priv = netdev_priv(netdev);
1561 struct hns3_enet_coalesce *tx_coal = &priv->tx_coal;
1562 struct hns3_enet_coalesce *rx_coal = &priv->rx_coal;
1563 u16 queue_num = h->kinfo.num_tqps;
1564 enum dim_cq_period_mode tx_mode;
1565 enum dim_cq_period_mode rx_mode;
1569 if (hns3_nic_resetting(netdev))
1572 ret = hns3_check_coalesce_para(netdev, cmd, kernel_coal);
1576 h->kinfo.int_rl_setting =
1577 hns3_rl_round_down(cmd->rx_coalesce_usecs_high);
1579 tx_coal->adapt_enable = cmd->use_adaptive_tx_coalesce;
1580 rx_coal->adapt_enable = cmd->use_adaptive_rx_coalesce;
1582 tx_coal->int_gl = cmd->tx_coalesce_usecs;
1583 rx_coal->int_gl = cmd->rx_coalesce_usecs;
1585 tx_coal->int_ql = cmd->tx_max_coalesced_frames;
1586 rx_coal->int_ql = cmd->rx_max_coalesced_frames;
1588 for (i = 0; i < queue_num; i++)
1589 hns3_set_coalesce_per_queue(netdev, cmd, i);
1591 tx_mode = kernel_coal->use_cqe_mode_tx ?
1592 DIM_CQ_PERIOD_MODE_START_FROM_CQE :
1593 DIM_CQ_PERIOD_MODE_START_FROM_EQE;
1594 rx_mode = kernel_coal->use_cqe_mode_rx ?
1595 DIM_CQ_PERIOD_MODE_START_FROM_CQE :
1596 DIM_CQ_PERIOD_MODE_START_FROM_EQE;
1597 hns3_cq_period_mode_init(priv, tx_mode, rx_mode);
1602 static int hns3_get_regs_len(struct net_device *netdev)
1604 struct hnae3_handle *h = hns3_get_handle(netdev);
1606 if (!h->ae_algo->ops->get_regs_len)
1609 return h->ae_algo->ops->get_regs_len(h);
1612 static void hns3_get_regs(struct net_device *netdev,
1613 struct ethtool_regs *cmd, void *data)
1615 struct hnae3_handle *h = hns3_get_handle(netdev);
1617 if (!h->ae_algo->ops->get_regs)
1620 h->ae_algo->ops->get_regs(h, &cmd->version, data);
1623 static int hns3_set_phys_id(struct net_device *netdev,
1624 enum ethtool_phys_id_state state)
1626 struct hnae3_handle *h = hns3_get_handle(netdev);
1628 if (!h->ae_algo->ops->set_led_id)
1631 return h->ae_algo->ops->set_led_id(h, state);
1634 static u32 hns3_get_msglevel(struct net_device *netdev)
1636 struct hnae3_handle *h = hns3_get_handle(netdev);
1638 return h->msg_enable;
1641 static void hns3_set_msglevel(struct net_device *netdev, u32 msg_level)
1643 struct hnae3_handle *h = hns3_get_handle(netdev);
1645 h->msg_enable = msg_level;
1648 static void hns3_get_fec_stats(struct net_device *netdev,
1649 struct ethtool_fec_stats *fec_stats)
1651 struct hnae3_handle *handle = hns3_get_handle(netdev);
1652 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1653 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1655 if (!hnae3_ae_dev_fec_stats_supported(ae_dev) || !ops->get_fec_stats)
1658 ops->get_fec_stats(handle, fec_stats);
1661 /* Translate local fec value into ethtool value. */
1662 static unsigned int loc_to_eth_fec(u8 loc_fec)
1666 if (loc_fec & BIT(HNAE3_FEC_AUTO))
1667 eth_fec |= ETHTOOL_FEC_AUTO;
1668 if (loc_fec & BIT(HNAE3_FEC_RS))
1669 eth_fec |= ETHTOOL_FEC_RS;
1670 if (loc_fec & BIT(HNAE3_FEC_LLRS))
1671 eth_fec |= ETHTOOL_FEC_LLRS;
1672 if (loc_fec & BIT(HNAE3_FEC_BASER))
1673 eth_fec |= ETHTOOL_FEC_BASER;
1674 if (loc_fec & BIT(HNAE3_FEC_NONE))
1675 eth_fec |= ETHTOOL_FEC_OFF;
1680 /* Translate ethtool fec value into local value. */
1681 static unsigned int eth_to_loc_fec(unsigned int eth_fec)
1685 if (eth_fec & ETHTOOL_FEC_OFF)
1686 loc_fec |= BIT(HNAE3_FEC_NONE);
1687 if (eth_fec & ETHTOOL_FEC_AUTO)
1688 loc_fec |= BIT(HNAE3_FEC_AUTO);
1689 if (eth_fec & ETHTOOL_FEC_RS)
1690 loc_fec |= BIT(HNAE3_FEC_RS);
1691 if (eth_fec & ETHTOOL_FEC_LLRS)
1692 loc_fec |= BIT(HNAE3_FEC_LLRS);
1693 if (eth_fec & ETHTOOL_FEC_BASER)
1694 loc_fec |= BIT(HNAE3_FEC_BASER);
1699 static int hns3_get_fecparam(struct net_device *netdev,
1700 struct ethtool_fecparam *fec)
1702 struct hnae3_handle *handle = hns3_get_handle(netdev);
1703 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1704 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1708 if (!test_bit(HNAE3_DEV_SUPPORT_FEC_B, ae_dev->caps))
1714 ops->get_fec(handle, &fec_ability, &fec_mode);
1716 fec->fec = loc_to_eth_fec(fec_ability);
1717 fec->active_fec = loc_to_eth_fec(fec_mode);
1718 if (!fec->active_fec)
1719 fec->active_fec = ETHTOOL_FEC_OFF;
1724 static int hns3_set_fecparam(struct net_device *netdev,
1725 struct ethtool_fecparam *fec)
1727 struct hnae3_handle *handle = hns3_get_handle(netdev);
1728 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1729 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1732 if (!test_bit(HNAE3_DEV_SUPPORT_FEC_B, ae_dev->caps))
1737 fec_mode = eth_to_loc_fec(fec->fec);
1739 netif_dbg(handle, drv, netdev, "set fecparam: mode=%u\n", fec_mode);
1741 return ops->set_fec(handle, fec_mode);
1744 static int hns3_get_module_info(struct net_device *netdev,
1745 struct ethtool_modinfo *modinfo)
1747 #define HNS3_SFF_8636_V1_3 0x03
1749 struct hnae3_handle *handle = hns3_get_handle(netdev);
1750 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1751 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1752 struct hns3_sfp_type sfp_type;
1755 if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 ||
1756 !ops->get_module_eeprom)
1759 memset(&sfp_type, 0, sizeof(sfp_type));
1760 ret = ops->get_module_eeprom(handle, 0, sizeof(sfp_type) / sizeof(u8),
1765 switch (sfp_type.type) {
1766 case SFF8024_ID_SFP:
1767 modinfo->type = ETH_MODULE_SFF_8472;
1768 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1770 case SFF8024_ID_QSFP_8438:
1771 modinfo->type = ETH_MODULE_SFF_8436;
1772 modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
1774 case SFF8024_ID_QSFP_8436_8636:
1775 if (sfp_type.ext_type < HNS3_SFF_8636_V1_3) {
1776 modinfo->type = ETH_MODULE_SFF_8436;
1777 modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
1779 modinfo->type = ETH_MODULE_SFF_8636;
1780 modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
1783 case SFF8024_ID_QSFP28_8636:
1784 modinfo->type = ETH_MODULE_SFF_8636;
1785 modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
1788 netdev_err(netdev, "Optical module unknown: %#x\n",
1796 static int hns3_get_module_eeprom(struct net_device *netdev,
1797 struct ethtool_eeprom *ee, u8 *data)
1799 struct hnae3_handle *handle = hns3_get_handle(netdev);
1800 struct hnae3_ae_dev *ae_dev = pci_get_drvdata(handle->pdev);
1801 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1803 if (ae_dev->dev_version < HNAE3_DEVICE_VERSION_V2 ||
1804 !ops->get_module_eeprom)
1810 memset(data, 0, ee->len);
1812 return ops->get_module_eeprom(handle, ee->offset, ee->len, data);
1815 static u32 hns3_get_priv_flags(struct net_device *netdev)
1817 struct hnae3_handle *handle = hns3_get_handle(netdev);
1819 return handle->priv_flags;
1822 static int hns3_check_priv_flags(struct hnae3_handle *h, u32 changed)
1826 for (i = 0; i < HNAE3_PFLAG_MAX; i++)
1827 if ((changed & BIT(i)) && !test_bit(i, &h->supported_pflags)) {
1828 netdev_err(h->netdev, "%s is unsupported\n",
1829 hns3_priv_flags[i].name);
1836 static int hns3_set_priv_flags(struct net_device *netdev, u32 pflags)
1838 struct hnae3_handle *handle = hns3_get_handle(netdev);
1839 u32 changed = pflags ^ handle->priv_flags;
1843 ret = hns3_check_priv_flags(handle, changed);
1847 for (i = 0; i < HNAE3_PFLAG_MAX; i++) {
1848 if (changed & BIT(i)) {
1849 bool enable = !(handle->priv_flags & BIT(i));
1852 handle->priv_flags |= BIT(i);
1854 handle->priv_flags &= ~BIT(i);
1855 hns3_priv_flags[i].handler(netdev, enable);
1862 static int hns3_get_tunable(struct net_device *netdev,
1863 const struct ethtool_tunable *tuna,
1866 struct hns3_nic_priv *priv = netdev_priv(netdev);
1867 struct hnae3_handle *h = priv->ae_handle;
1871 case ETHTOOL_TX_COPYBREAK:
1872 /* all the tx rings have the same tx_copybreak */
1873 *(u32 *)data = priv->tx_copybreak;
1875 case ETHTOOL_RX_COPYBREAK:
1876 *(u32 *)data = priv->rx_copybreak;
1878 case ETHTOOL_TX_COPYBREAK_BUF_SIZE:
1879 *(u32 *)data = h->kinfo.tx_spare_buf_size;
1889 static int hns3_set_tx_spare_buf_size(struct net_device *netdev,
1892 struct hns3_nic_priv *priv = netdev_priv(netdev);
1893 struct hnae3_handle *h = priv->ae_handle;
1896 h->kinfo.tx_spare_buf_size = data;
1898 ret = hns3_reset_notify(h, HNAE3_DOWN_CLIENT);
1902 ret = hns3_reset_notify(h, HNAE3_UNINIT_CLIENT);
1906 ret = hns3_reset_notify(h, HNAE3_INIT_CLIENT);
1910 ret = hns3_reset_notify(h, HNAE3_UP_CLIENT);
1912 hns3_reset_notify(h, HNAE3_UNINIT_CLIENT);
1917 static int hns3_set_tunable(struct net_device *netdev,
1918 const struct ethtool_tunable *tuna,
1921 struct hns3_nic_priv *priv = netdev_priv(netdev);
1922 u32 old_tx_spare_buf_size, new_tx_spare_buf_size;
1923 struct hnae3_handle *h = priv->ae_handle;
1926 if (hns3_nic_resetting(netdev) || !priv->ring) {
1927 netdev_err(netdev, "failed to set tunable value, dev resetting!");
1932 case ETHTOOL_TX_COPYBREAK:
1933 priv->tx_copybreak = *(u32 *)data;
1935 for (i = 0; i < h->kinfo.num_tqps; i++)
1936 priv->ring[i].tx_copybreak = priv->tx_copybreak;
1939 case ETHTOOL_RX_COPYBREAK:
1940 priv->rx_copybreak = *(u32 *)data;
1942 for (i = h->kinfo.num_tqps; i < h->kinfo.num_tqps * 2; i++)
1943 priv->ring[i].rx_copybreak = priv->rx_copybreak;
1946 case ETHTOOL_TX_COPYBREAK_BUF_SIZE:
1947 old_tx_spare_buf_size = h->kinfo.tx_spare_buf_size;
1948 new_tx_spare_buf_size = *(u32 *)data;
1949 netdev_info(netdev, "request to set tx spare buf size from %u to %u\n",
1950 old_tx_spare_buf_size, new_tx_spare_buf_size);
1951 ret = hns3_set_tx_spare_buf_size(netdev, new_tx_spare_buf_size);
1953 (!priv->ring->tx_spare && new_tx_spare_buf_size != 0)) {
1956 netdev_warn(netdev, "change tx spare buf size fail, revert to old value\n");
1957 ret1 = hns3_set_tx_spare_buf_size(netdev,
1958 old_tx_spare_buf_size);
1960 netdev_err(netdev, "revert to old tx spare buf size fail\n");
1967 if (!priv->ring->tx_spare)
1968 netdev_info(netdev, "the active tx spare buf size is 0, disable tx spare buffer\n");
1970 netdev_info(netdev, "the active tx spare buf size is %u, due to page order\n",
1971 priv->ring->tx_spare->len);
1982 #define HNS3_ETHTOOL_COALESCE (ETHTOOL_COALESCE_USECS | \
1983 ETHTOOL_COALESCE_USE_ADAPTIVE | \
1984 ETHTOOL_COALESCE_RX_USECS_HIGH | \
1985 ETHTOOL_COALESCE_TX_USECS_HIGH | \
1986 ETHTOOL_COALESCE_MAX_FRAMES | \
1987 ETHTOOL_COALESCE_USE_CQE)
1989 #define HNS3_ETHTOOL_RING (ETHTOOL_RING_USE_RX_BUF_LEN | \
1990 ETHTOOL_RING_USE_TX_PUSH)
1992 static int hns3_get_ts_info(struct net_device *netdev,
1993 struct ethtool_ts_info *info)
1995 struct hnae3_handle *handle = hns3_get_handle(netdev);
1997 if (handle->ae_algo->ops->get_ts_info)
1998 return handle->ae_algo->ops->get_ts_info(handle, info);
2000 return ethtool_op_get_ts_info(netdev, info);
2003 static const struct hns3_ethtool_link_ext_state_mapping
2004 hns3_link_ext_state_map[] = {
2005 {1, ETHTOOL_LINK_EXT_STATE_AUTONEG,
2006 ETHTOOL_LINK_EXT_SUBSTATE_AN_NO_HCD},
2007 {2, ETHTOOL_LINK_EXT_STATE_AUTONEG,
2008 ETHTOOL_LINK_EXT_SUBSTATE_AN_ACK_NOT_RECEIVED},
2010 {256, ETHTOOL_LINK_EXT_STATE_LINK_TRAINING_FAILURE,
2011 ETHTOOL_LINK_EXT_SUBSTATE_LT_KR_LINK_INHIBIT_TIMEOUT},
2012 {257, ETHTOOL_LINK_EXT_STATE_LINK_TRAINING_FAILURE,
2013 ETHTOOL_LINK_EXT_SUBSTATE_LT_KR_LINK_PARTNER_DID_NOT_SET_RECEIVER_READY},
2014 {512, ETHTOOL_LINK_EXT_STATE_LINK_TRAINING_FAILURE,
2015 ETHTOOL_LINK_EXT_SUBSTATE_LT_REMOTE_FAULT},
2017 {513, ETHTOOL_LINK_EXT_STATE_LINK_LOGICAL_MISMATCH,
2018 ETHTOOL_LINK_EXT_SUBSTATE_LLM_PCS_DID_NOT_ACQUIRE_BLOCK_LOCK},
2019 {514, ETHTOOL_LINK_EXT_STATE_LINK_LOGICAL_MISMATCH,
2020 ETHTOOL_LINK_EXT_SUBSTATE_LLM_FC_FEC_IS_NOT_LOCKED},
2021 {515, ETHTOOL_LINK_EXT_STATE_LINK_LOGICAL_MISMATCH,
2022 ETHTOOL_LINK_EXT_SUBSTATE_LLM_RS_FEC_IS_NOT_LOCKED},
2024 {768, ETHTOOL_LINK_EXT_STATE_BAD_SIGNAL_INTEGRITY,
2025 ETHTOOL_LINK_EXT_SUBSTATE_BSI_LARGE_NUMBER_OF_PHYSICAL_ERRORS},
2026 {769, ETHTOOL_LINK_EXT_STATE_BAD_SIGNAL_INTEGRITY,
2027 ETHTOOL_LINK_EXT_SUBSTATE_BSI_SERDES_REFERENCE_CLOCK_LOST},
2028 {770, ETHTOOL_LINK_EXT_STATE_BAD_SIGNAL_INTEGRITY,
2029 ETHTOOL_LINK_EXT_SUBSTATE_BSI_SERDES_ALOS},
2031 {1024, ETHTOOL_LINK_EXT_STATE_NO_CABLE, 0},
2032 {1025, ETHTOOL_LINK_EXT_STATE_CABLE_ISSUE,
2033 ETHTOOL_LINK_EXT_SUBSTATE_CI_UNSUPPORTED_CABLE},
2035 {1026, ETHTOOL_LINK_EXT_STATE_EEPROM_ISSUE, 0},
2038 static int hns3_get_link_ext_state(struct net_device *netdev,
2039 struct ethtool_link_ext_state_info *info)
2041 const struct hns3_ethtool_link_ext_state_mapping *map;
2042 struct hnae3_handle *h = hns3_get_handle(netdev);
2046 if (netif_carrier_ok(netdev))
2049 if (!h->ae_algo->ops->get_link_diagnosis_info)
2052 ret = h->ae_algo->ops->get_link_diagnosis_info(h, &status_code);
2056 for (i = 0; i < ARRAY_SIZE(hns3_link_ext_state_map); i++) {
2057 map = &hns3_link_ext_state_map[i];
2058 if (map->status_code == status_code) {
2059 info->link_ext_state = map->link_ext_state;
2060 info->__link_ext_substate = map->link_ext_substate;
2068 static const struct ethtool_ops hns3vf_ethtool_ops = {
2069 .supported_coalesce_params = HNS3_ETHTOOL_COALESCE,
2070 .supported_ring_params = HNS3_ETHTOOL_RING,
2071 .get_drvinfo = hns3_get_drvinfo,
2072 .get_ringparam = hns3_get_ringparam,
2073 .set_ringparam = hns3_set_ringparam,
2074 .get_strings = hns3_get_strings,
2075 .get_ethtool_stats = hns3_get_stats,
2076 .get_sset_count = hns3_get_sset_count,
2077 .get_rxnfc = hns3_get_rxnfc,
2078 .set_rxnfc = hns3_set_rxnfc,
2079 .get_rxfh_key_size = hns3_get_rss_key_size,
2080 .get_rxfh_indir_size = hns3_get_rss_indir_size,
2081 .get_rxfh = hns3_get_rss,
2082 .set_rxfh = hns3_set_rss,
2083 .get_link_ksettings = hns3_get_link_ksettings,
2084 .get_channels = hns3_get_channels,
2085 .set_channels = hns3_set_channels,
2086 .get_coalesce = hns3_get_coalesce,
2087 .set_coalesce = hns3_set_coalesce,
2088 .get_regs_len = hns3_get_regs_len,
2089 .get_regs = hns3_get_regs,
2090 .get_link = hns3_get_link,
2091 .get_msglevel = hns3_get_msglevel,
2092 .set_msglevel = hns3_set_msglevel,
2093 .get_priv_flags = hns3_get_priv_flags,
2094 .set_priv_flags = hns3_set_priv_flags,
2095 .get_tunable = hns3_get_tunable,
2096 .set_tunable = hns3_set_tunable,
2097 .reset = hns3_set_reset,
2100 static const struct ethtool_ops hns3_ethtool_ops = {
2101 .supported_coalesce_params = HNS3_ETHTOOL_COALESCE,
2102 .supported_ring_params = HNS3_ETHTOOL_RING,
2103 .cap_link_lanes_supported = true,
2104 .self_test = hns3_self_test,
2105 .get_drvinfo = hns3_get_drvinfo,
2106 .get_link = hns3_get_link,
2107 .get_ringparam = hns3_get_ringparam,
2108 .set_ringparam = hns3_set_ringparam,
2109 .get_pauseparam = hns3_get_pauseparam,
2110 .set_pauseparam = hns3_set_pauseparam,
2111 .get_strings = hns3_get_strings,
2112 .get_ethtool_stats = hns3_get_stats,
2113 .get_sset_count = hns3_get_sset_count,
2114 .get_rxnfc = hns3_get_rxnfc,
2115 .set_rxnfc = hns3_set_rxnfc,
2116 .get_rxfh_key_size = hns3_get_rss_key_size,
2117 .get_rxfh_indir_size = hns3_get_rss_indir_size,
2118 .get_rxfh = hns3_get_rss,
2119 .set_rxfh = hns3_set_rss,
2120 .get_link_ksettings = hns3_get_link_ksettings,
2121 .set_link_ksettings = hns3_set_link_ksettings,
2122 .nway_reset = hns3_nway_reset,
2123 .get_channels = hns3_get_channels,
2124 .set_channels = hns3_set_channels,
2125 .get_coalesce = hns3_get_coalesce,
2126 .set_coalesce = hns3_set_coalesce,
2127 .get_regs_len = hns3_get_regs_len,
2128 .get_regs = hns3_get_regs,
2129 .set_phys_id = hns3_set_phys_id,
2130 .get_msglevel = hns3_get_msglevel,
2131 .set_msglevel = hns3_set_msglevel,
2132 .get_fecparam = hns3_get_fecparam,
2133 .set_fecparam = hns3_set_fecparam,
2134 .get_fec_stats = hns3_get_fec_stats,
2135 .get_module_info = hns3_get_module_info,
2136 .get_module_eeprom = hns3_get_module_eeprom,
2137 .get_priv_flags = hns3_get_priv_flags,
2138 .set_priv_flags = hns3_set_priv_flags,
2139 .get_ts_info = hns3_get_ts_info,
2140 .get_tunable = hns3_get_tunable,
2141 .set_tunable = hns3_set_tunable,
2142 .reset = hns3_set_reset,
2143 .get_link_ext_state = hns3_get_link_ext_state,
2146 void hns3_ethtool_set_ops(struct net_device *netdev)
2148 struct hnae3_handle *h = hns3_get_handle(netdev);
2150 if (h->flags & HNAE3_SUPPORT_VF)
2151 netdev->ethtool_ops = &hns3vf_ethtool_ops;
2153 netdev->ethtool_ops = &hns3_ethtool_ops;