1 // SPDX-License-Identifier: GPL-2.0+
2 // Copyright (c) 2016-2017 Hisilicon Limited.
4 #include <linux/etherdevice.h>
5 #include <linux/string.h>
12 char stats_string[ETH_GSTRING_LEN];
16 struct hns3_sfp_type {
21 /* tqp related stats */
22 #define HNS3_TQP_STAT(_string, _member) { \
23 .stats_string = _string, \
24 .stats_offset = offsetof(struct hns3_enet_ring, stats) +\
25 offsetof(struct ring_stats, _member), \
28 static const struct hns3_stats hns3_txq_stats[] = {
29 /* Tx per-queue statistics */
30 HNS3_TQP_STAT("io_err_cnt", io_err_cnt),
31 HNS3_TQP_STAT("dropped", sw_err_cnt),
32 HNS3_TQP_STAT("seg_pkt_cnt", seg_pkt_cnt),
33 HNS3_TQP_STAT("packets", tx_pkts),
34 HNS3_TQP_STAT("bytes", tx_bytes),
35 HNS3_TQP_STAT("errors", tx_err_cnt),
36 HNS3_TQP_STAT("wake", restart_queue),
37 HNS3_TQP_STAT("busy", tx_busy),
38 HNS3_TQP_STAT("copy", tx_copy),
39 HNS3_TQP_STAT("vlan_err", tx_vlan_err),
40 HNS3_TQP_STAT("l4_proto_err", tx_l4_proto_err),
41 HNS3_TQP_STAT("l2l3l4_err", tx_l2l3l4_err),
42 HNS3_TQP_STAT("tso_err", tx_tso_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("io_err_cnt", io_err_cnt),
50 HNS3_TQP_STAT("dropped", sw_err_cnt),
51 HNS3_TQP_STAT("seg_pkt_cnt", seg_pkt_cnt),
52 HNS3_TQP_STAT("packets", rx_pkts),
53 HNS3_TQP_STAT("bytes", rx_bytes),
54 HNS3_TQP_STAT("errors", rx_err_cnt),
55 HNS3_TQP_STAT("reuse_pg_cnt", reuse_pg_cnt),
56 HNS3_TQP_STAT("err_pkt_len", err_pkt_len),
57 HNS3_TQP_STAT("err_bd_num", err_bd_num),
58 HNS3_TQP_STAT("l2_err", l2_err),
59 HNS3_TQP_STAT("l3l4_csum_err", l3l4_csum_err),
60 HNS3_TQP_STAT("multicast", rx_multicast),
61 HNS3_TQP_STAT("non_reuse_pg", non_reuse_pg),
64 #define HNS3_RXQ_STATS_COUNT ARRAY_SIZE(hns3_rxq_stats)
66 #define HNS3_TQP_STATS_COUNT (HNS3_TXQ_STATS_COUNT + HNS3_RXQ_STATS_COUNT)
68 #define HNS3_SELF_TEST_TYPE_NUM 4
69 #define HNS3_NIC_LB_TEST_PKT_NUM 1
70 #define HNS3_NIC_LB_TEST_RING_ID 0
71 #define HNS3_NIC_LB_TEST_PACKET_SIZE 128
72 #define HNS3_NIC_LB_SETUP_USEC 10000
74 /* Nic loopback test err */
75 #define HNS3_NIC_LB_TEST_NO_MEM_ERR 1
76 #define HNS3_NIC_LB_TEST_TX_CNT_ERR 2
77 #define HNS3_NIC_LB_TEST_RX_CNT_ERR 3
79 static int hns3_lp_setup(struct net_device *ndev, enum hnae3_loop loop, bool en)
81 struct hnae3_handle *h = hns3_get_handle(ndev);
82 bool vlan_filter_enable;
85 if (!h->ae_algo->ops->set_loopback ||
86 !h->ae_algo->ops->set_promisc_mode)
90 case HNAE3_LOOP_SERIAL_SERDES:
91 case HNAE3_LOOP_PARALLEL_SERDES:
94 ret = h->ae_algo->ops->set_loopback(h, loop, en);
101 if (ret || h->pdev->revision >= 0x21)
105 h->ae_algo->ops->set_promisc_mode(h, true, true);
107 /* recover promisc mode before loopback test */
108 hns3_request_update_promisc_mode(h);
109 vlan_filter_enable = ndev->flags & IFF_PROMISC ? false : true;
110 hns3_enable_vlan_filter(ndev, vlan_filter_enable);
116 static int hns3_lp_up(struct net_device *ndev, enum hnae3_loop loop_mode)
118 struct hnae3_handle *h = hns3_get_handle(ndev);
121 ret = hns3_nic_reset_all_ring(h);
125 ret = hns3_lp_setup(ndev, loop_mode, true);
126 usleep_range(HNS3_NIC_LB_SETUP_USEC, HNS3_NIC_LB_SETUP_USEC * 2);
131 static int hns3_lp_down(struct net_device *ndev, enum hnae3_loop loop_mode)
135 ret = hns3_lp_setup(ndev, loop_mode, false);
137 netdev_err(ndev, "lb_setup return error: %d\n", ret);
141 usleep_range(HNS3_NIC_LB_SETUP_USEC, HNS3_NIC_LB_SETUP_USEC * 2);
146 static void hns3_lp_setup_skb(struct sk_buff *skb)
148 #define HNS3_NIC_LB_DST_MAC_ADDR 0x1f
150 struct net_device *ndev = skb->dev;
151 struct hnae3_handle *handle;
152 unsigned char *packet;
156 skb_reserve(skb, NET_IP_ALIGN);
157 ethh = skb_put(skb, sizeof(struct ethhdr));
158 packet = skb_put(skb, HNS3_NIC_LB_TEST_PACKET_SIZE);
160 memcpy(ethh->h_dest, ndev->dev_addr, ETH_ALEN);
162 /* The dst mac addr of loopback packet is the same as the host'
163 * mac addr, the SSU component may loop back the packet to host
164 * before the packet reaches mac or serdes, which will defect
165 * the purpose of mac or serdes selftest.
167 handle = hns3_get_handle(ndev);
168 if (handle->pdev->revision == 0x20)
169 ethh->h_dest[5] += HNS3_NIC_LB_DST_MAC_ADDR;
170 eth_zero_addr(ethh->h_source);
171 ethh->h_proto = htons(ETH_P_ARP);
172 skb_reset_mac_header(skb);
174 for (i = 0; i < HNS3_NIC_LB_TEST_PACKET_SIZE; i++)
175 packet[i] = (unsigned char)(i & 0xff);
178 static void hns3_lb_check_skb_data(struct hns3_enet_ring *ring,
181 struct hns3_enet_tqp_vector *tqp_vector = ring->tqp_vector;
182 unsigned char *packet = skb->data;
183 u32 len = skb_headlen(skb);
186 len = min_t(u32, len, HNS3_NIC_LB_TEST_PACKET_SIZE);
188 for (i = 0; i < len; i++)
189 if (packet[i] != (unsigned char)(i & 0xff))
192 /* The packet is correctly received */
193 if (i == HNS3_NIC_LB_TEST_PACKET_SIZE)
194 tqp_vector->rx_group.total_packets++;
196 print_hex_dump(KERN_ERR, "selftest:", DUMP_PREFIX_OFFSET, 16, 1,
197 skb->data, len, true);
199 dev_kfree_skb_any(skb);
202 static u32 hns3_lb_check_rx_ring(struct hns3_nic_priv *priv, u32 budget)
204 struct hnae3_handle *h = priv->ae_handle;
205 struct hnae3_knic_private_info *kinfo;
206 u32 i, rcv_good_pkt_total = 0;
209 for (i = kinfo->num_tqps; i < kinfo->num_tqps * 2; i++) {
210 struct hns3_enet_ring *ring = &priv->ring[i];
211 struct hns3_enet_ring_group *rx_group;
214 rx_group = &ring->tqp_vector->rx_group;
215 pre_rx_pkt = rx_group->total_packets;
218 hns3_clean_rx_ring(ring, budget, hns3_lb_check_skb_data);
221 rcv_good_pkt_total += (rx_group->total_packets - pre_rx_pkt);
222 rx_group->total_packets = pre_rx_pkt;
224 return rcv_good_pkt_total;
227 static void hns3_lb_clear_tx_ring(struct hns3_nic_priv *priv, u32 start_ringid,
228 u32 end_ringid, u32 budget)
232 for (i = start_ringid; i <= end_ringid; i++) {
233 struct hns3_enet_ring *ring = &priv->ring[i];
235 hns3_clean_tx_ring(ring);
240 * hns3_lp_run_test - run loopback test
242 * @mode: loopback type
244 static int hns3_lp_run_test(struct net_device *ndev, enum hnae3_loop mode)
246 struct hns3_nic_priv *priv = netdev_priv(ndev);
251 skb = alloc_skb(HNS3_NIC_LB_TEST_PACKET_SIZE + ETH_HLEN + NET_IP_ALIGN,
254 return HNS3_NIC_LB_TEST_NO_MEM_ERR;
257 hns3_lp_setup_skb(skb);
258 skb->queue_mapping = HNS3_NIC_LB_TEST_RING_ID;
261 for (i = 0; i < HNS3_NIC_LB_TEST_PKT_NUM; i++) {
265 tx_ret = hns3_nic_net_xmit(skb, ndev);
266 if (tx_ret == NETDEV_TX_OK) {
270 netdev_err(ndev, "hns3_lb_run_test xmit failed: %d\n",
274 if (good_cnt != HNS3_NIC_LB_TEST_PKT_NUM) {
275 ret_val = HNS3_NIC_LB_TEST_TX_CNT_ERR;
276 netdev_err(ndev, "mode %d sent fail, cnt=0x%x, budget=0x%x\n",
277 mode, good_cnt, HNS3_NIC_LB_TEST_PKT_NUM);
281 /* Allow 200 milliseconds for packets to go from Tx to Rx */
284 good_cnt = hns3_lb_check_rx_ring(priv, HNS3_NIC_LB_TEST_PKT_NUM);
285 if (good_cnt != HNS3_NIC_LB_TEST_PKT_NUM) {
286 ret_val = HNS3_NIC_LB_TEST_RX_CNT_ERR;
287 netdev_err(ndev, "mode %d recv fail, cnt=0x%x, budget=0x%x\n",
288 mode, good_cnt, HNS3_NIC_LB_TEST_PKT_NUM);
292 hns3_lb_clear_tx_ring(priv, HNS3_NIC_LB_TEST_RING_ID,
293 HNS3_NIC_LB_TEST_RING_ID,
294 HNS3_NIC_LB_TEST_PKT_NUM);
301 * hns3_nic_self_test - self test
303 * @eth_test: test cmd
306 static void hns3_self_test(struct net_device *ndev,
307 struct ethtool_test *eth_test, u64 *data)
309 struct hns3_nic_priv *priv = netdev_priv(ndev);
310 struct hnae3_handle *h = priv->ae_handle;
311 int st_param[HNS3_SELF_TEST_TYPE_NUM][2];
312 bool if_running = netif_running(ndev);
313 #if IS_ENABLED(CONFIG_VLAN_8021Q)
314 bool dis_vlan_filter;
319 if (hns3_nic_resetting(ndev)) {
320 netdev_err(ndev, "dev resetting!");
324 /* Only do offline selftest, or pass by default */
325 if (eth_test->flags != ETH_TEST_FL_OFFLINE)
328 netif_dbg(h, drv, ndev, "self test start");
330 st_param[HNAE3_LOOP_APP][0] = HNAE3_LOOP_APP;
331 st_param[HNAE3_LOOP_APP][1] =
332 h->flags & HNAE3_SUPPORT_APP_LOOPBACK;
334 st_param[HNAE3_LOOP_SERIAL_SERDES][0] = HNAE3_LOOP_SERIAL_SERDES;
335 st_param[HNAE3_LOOP_SERIAL_SERDES][1] =
336 h->flags & HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK;
338 st_param[HNAE3_LOOP_PARALLEL_SERDES][0] =
339 HNAE3_LOOP_PARALLEL_SERDES;
340 st_param[HNAE3_LOOP_PARALLEL_SERDES][1] =
341 h->flags & HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK;
343 st_param[HNAE3_LOOP_PHY][0] = HNAE3_LOOP_PHY;
344 st_param[HNAE3_LOOP_PHY][1] =
345 h->flags & HNAE3_SUPPORT_PHY_LOOPBACK;
348 ndev->netdev_ops->ndo_stop(ndev);
350 #if IS_ENABLED(CONFIG_VLAN_8021Q)
351 /* Disable the vlan filter for selftest does not support it */
352 dis_vlan_filter = (ndev->features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
353 h->ae_algo->ops->enable_vlan_filter;
355 h->ae_algo->ops->enable_vlan_filter(h, false);
358 /* Tell firmware to stop mac autoneg before loopback test start,
359 * otherwise loopback test may be failed when the port is still
362 if (h->ae_algo->ops->halt_autoneg)
363 h->ae_algo->ops->halt_autoneg(h, true);
365 set_bit(HNS3_NIC_STATE_TESTING, &priv->state);
367 for (i = 0; i < HNS3_SELF_TEST_TYPE_NUM; i++) {
368 enum hnae3_loop loop_type = (enum hnae3_loop)st_param[i][0];
373 data[test_index] = hns3_lp_up(ndev, loop_type);
374 if (!data[test_index])
375 data[test_index] = hns3_lp_run_test(ndev, loop_type);
377 hns3_lp_down(ndev, loop_type);
379 if (data[test_index])
380 eth_test->flags |= ETH_TEST_FL_FAILED;
385 clear_bit(HNS3_NIC_STATE_TESTING, &priv->state);
387 if (h->ae_algo->ops->halt_autoneg)
388 h->ae_algo->ops->halt_autoneg(h, false);
390 #if IS_ENABLED(CONFIG_VLAN_8021Q)
392 h->ae_algo->ops->enable_vlan_filter(h, true);
396 ndev->netdev_ops->ndo_open(ndev);
398 netif_dbg(h, drv, ndev, "self test end\n");
401 static int hns3_get_sset_count(struct net_device *netdev, int stringset)
403 struct hnae3_handle *h = hns3_get_handle(netdev);
404 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
406 if (!ops->get_sset_count)
411 return ((HNS3_TQP_STATS_COUNT * h->kinfo.num_tqps) +
412 ops->get_sset_count(h, stringset));
415 return ops->get_sset_count(h, stringset);
422 static void *hns3_update_strings(u8 *data, const struct hns3_stats *stats,
423 u32 stat_count, u32 num_tqps, const char *prefix)
425 #define MAX_PREFIX_SIZE (6 + 4)
430 for (i = 0; i < num_tqps; i++) {
431 for (j = 0; j < stat_count; j++) {
432 data[ETH_GSTRING_LEN - 1] = '\0';
434 /* first, prepend the prefix string */
435 n1 = scnprintf(data, MAX_PREFIX_SIZE, "%s%d_",
437 size_left = (ETH_GSTRING_LEN - 1) - n1;
439 /* now, concatenate the stats string to it */
440 strncat(data, stats[j].stats_string, size_left);
441 data += ETH_GSTRING_LEN;
448 static u8 *hns3_get_strings_tqps(struct hnae3_handle *handle, u8 *data)
450 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
451 const char tx_prefix[] = "txq";
452 const char rx_prefix[] = "rxq";
454 /* get strings for Tx */
455 data = hns3_update_strings(data, hns3_txq_stats, HNS3_TXQ_STATS_COUNT,
456 kinfo->num_tqps, tx_prefix);
458 /* get strings for Rx */
459 data = hns3_update_strings(data, hns3_rxq_stats, HNS3_RXQ_STATS_COUNT,
460 kinfo->num_tqps, rx_prefix);
465 static void hns3_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
467 struct hnae3_handle *h = hns3_get_handle(netdev);
468 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
469 char *buff = (char *)data;
471 if (!ops->get_strings)
476 buff = hns3_get_strings_tqps(h, buff);
477 ops->get_strings(h, stringset, (u8 *)buff);
480 ops->get_strings(h, stringset, data);
487 static u64 *hns3_get_stats_tqps(struct hnae3_handle *handle, u64 *data)
489 struct hns3_nic_priv *nic_priv = (struct hns3_nic_priv *)handle->priv;
490 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
491 struct hns3_enet_ring *ring;
495 /* get stats for Tx */
496 for (i = 0; i < kinfo->num_tqps; i++) {
497 ring = &nic_priv->ring[i];
498 for (j = 0; j < HNS3_TXQ_STATS_COUNT; j++) {
499 stat = (u8 *)ring + hns3_txq_stats[j].stats_offset;
500 *data++ = *(u64 *)stat;
504 /* get stats for Rx */
505 for (i = 0; i < kinfo->num_tqps; i++) {
506 ring = &nic_priv->ring[i + kinfo->num_tqps];
507 for (j = 0; j < HNS3_RXQ_STATS_COUNT; j++) {
508 stat = (u8 *)ring + hns3_rxq_stats[j].stats_offset;
509 *data++ = *(u64 *)stat;
516 /* hns3_get_stats - get detail statistics.
517 * @netdev: net device
518 * @stats: statistics info.
519 * @data: statistics data.
521 static void hns3_get_stats(struct net_device *netdev,
522 struct ethtool_stats *stats, u64 *data)
524 struct hnae3_handle *h = hns3_get_handle(netdev);
527 if (hns3_nic_resetting(netdev)) {
528 netdev_err(netdev, "dev resetting, could not get stats\n");
532 if (!h->ae_algo->ops->get_stats || !h->ae_algo->ops->update_stats) {
533 netdev_err(netdev, "could not get any statistics\n");
537 h->ae_algo->ops->update_stats(h, &netdev->stats);
539 /* get per-queue stats */
540 p = hns3_get_stats_tqps(h, p);
542 /* get MAC & other misc hardware stats */
543 h->ae_algo->ops->get_stats(h, p);
546 static void hns3_get_drvinfo(struct net_device *netdev,
547 struct ethtool_drvinfo *drvinfo)
549 struct hns3_nic_priv *priv = netdev_priv(netdev);
550 struct hnae3_handle *h = priv->ae_handle;
553 if (!h->ae_algo->ops->get_fw_version) {
554 netdev_err(netdev, "could not get fw version!\n");
558 strncpy(drvinfo->driver, h->pdev->driver->name,
559 sizeof(drvinfo->driver));
560 drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
562 strncpy(drvinfo->bus_info, pci_name(h->pdev),
563 sizeof(drvinfo->bus_info));
564 drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';
566 fw_version = priv->ae_handle->ae_algo->ops->get_fw_version(h);
568 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
570 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE3_MASK,
571 HNAE3_FW_VERSION_BYTE3_SHIFT),
572 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE2_MASK,
573 HNAE3_FW_VERSION_BYTE2_SHIFT),
574 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE1_MASK,
575 HNAE3_FW_VERSION_BYTE1_SHIFT),
576 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE0_MASK,
577 HNAE3_FW_VERSION_BYTE0_SHIFT));
580 static u32 hns3_get_link(struct net_device *netdev)
582 struct hnae3_handle *h = hns3_get_handle(netdev);
584 if (h->ae_algo->ops->get_status)
585 return h->ae_algo->ops->get_status(h);
590 static void hns3_get_ringparam(struct net_device *netdev,
591 struct ethtool_ringparam *param)
593 struct hns3_nic_priv *priv = netdev_priv(netdev);
594 struct hnae3_handle *h = priv->ae_handle;
595 int queue_num = h->kinfo.num_tqps;
597 if (hns3_nic_resetting(netdev)) {
598 netdev_err(netdev, "dev resetting!");
602 param->tx_max_pending = HNS3_RING_MAX_PENDING;
603 param->rx_max_pending = HNS3_RING_MAX_PENDING;
605 param->tx_pending = priv->ring[0].desc_num;
606 param->rx_pending = priv->ring[queue_num].desc_num;
609 static void hns3_get_pauseparam(struct net_device *netdev,
610 struct ethtool_pauseparam *param)
612 struct hnae3_handle *h = hns3_get_handle(netdev);
614 if (h->ae_algo->ops->get_pauseparam)
615 h->ae_algo->ops->get_pauseparam(h, ¶m->autoneg,
616 ¶m->rx_pause, ¶m->tx_pause);
619 static int hns3_set_pauseparam(struct net_device *netdev,
620 struct ethtool_pauseparam *param)
622 struct hnae3_handle *h = hns3_get_handle(netdev);
624 netif_dbg(h, drv, netdev,
625 "set pauseparam: autoneg=%u, rx:%u, tx:%u\n",
626 param->autoneg, param->rx_pause, param->tx_pause);
628 if (h->ae_algo->ops->set_pauseparam)
629 return h->ae_algo->ops->set_pauseparam(h, param->autoneg,
635 static void hns3_get_ksettings(struct hnae3_handle *h,
636 struct ethtool_link_ksettings *cmd)
638 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
640 /* 1.auto_neg & speed & duplex from cmd */
641 if (ops->get_ksettings_an_result)
642 ops->get_ksettings_an_result(h,
647 /* 2.get link mode */
648 if (ops->get_link_mode)
649 ops->get_link_mode(h,
650 cmd->link_modes.supported,
651 cmd->link_modes.advertising);
653 /* 3.mdix_ctrl&mdix get from phy reg */
654 if (ops->get_mdix_mode)
655 ops->get_mdix_mode(h, &cmd->base.eth_tp_mdix_ctrl,
656 &cmd->base.eth_tp_mdix);
659 static int hns3_get_link_ksettings(struct net_device *netdev,
660 struct ethtool_link_ksettings *cmd)
662 struct hnae3_handle *h = hns3_get_handle(netdev);
663 const struct hnae3_ae_ops *ops;
668 ops = h->ae_algo->ops;
669 if (ops->get_media_type)
670 ops->get_media_type(h, &media_type, &module_type);
674 switch (media_type) {
675 case HNAE3_MEDIA_TYPE_NONE:
676 cmd->base.port = PORT_NONE;
677 hns3_get_ksettings(h, cmd);
679 case HNAE3_MEDIA_TYPE_FIBER:
680 if (module_type == HNAE3_MODULE_TYPE_CR)
681 cmd->base.port = PORT_DA;
683 cmd->base.port = PORT_FIBRE;
685 hns3_get_ksettings(h, cmd);
687 case HNAE3_MEDIA_TYPE_BACKPLANE:
688 cmd->base.port = PORT_NONE;
689 hns3_get_ksettings(h, cmd);
691 case HNAE3_MEDIA_TYPE_COPPER:
692 cmd->base.port = PORT_TP;
694 hns3_get_ksettings(h, cmd);
696 phy_ethtool_ksettings_get(netdev->phydev, cmd);
700 netdev_warn(netdev, "Unknown media type");
705 cmd->base.mdio_support = ETH_MDIO_SUPPORTS_C22;
707 link_stat = hns3_get_link(netdev);
709 cmd->base.speed = SPEED_UNKNOWN;
710 cmd->base.duplex = DUPLEX_UNKNOWN;
716 static int hns3_check_ksettings_param(const struct net_device *netdev,
717 const struct ethtool_link_ksettings *cmd)
719 struct hnae3_handle *handle = hns3_get_handle(netdev);
720 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
721 u8 module_type = HNAE3_MODULE_TYPE_UNKNOWN;
722 u8 media_type = HNAE3_MEDIA_TYPE_UNKNOWN;
728 /* hw doesn't support use specified speed and duplex to negotiate,
729 * unnecessary to check them when autoneg on.
731 if (cmd->base.autoneg)
734 if (ops->get_ksettings_an_result) {
735 ops->get_ksettings_an_result(handle, &autoneg, &speed, &duplex);
736 if (cmd->base.autoneg == autoneg && cmd->base.speed == speed &&
737 cmd->base.duplex == duplex)
741 if (ops->get_media_type)
742 ops->get_media_type(handle, &media_type, &module_type);
744 if (cmd->base.duplex == DUPLEX_HALF &&
745 media_type != HNAE3_MEDIA_TYPE_COPPER) {
747 "only copper port supports half duplex!");
751 if (ops->check_port_speed) {
752 ret = ops->check_port_speed(handle, cmd->base.speed);
754 netdev_err(netdev, "unsupported speed\n");
762 static int hns3_set_link_ksettings(struct net_device *netdev,
763 const struct ethtool_link_ksettings *cmd)
765 struct hnae3_handle *handle = hns3_get_handle(netdev);
766 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
769 /* Chip don't support this mode. */
770 if (cmd->base.speed == SPEED_1000 && cmd->base.duplex == DUPLEX_HALF)
773 netif_dbg(handle, drv, netdev,
774 "set link(%s): autoneg=%u, speed=%u, duplex=%u\n",
775 netdev->phydev ? "phy" : "mac",
776 cmd->base.autoneg, cmd->base.speed, cmd->base.duplex);
778 /* Only support ksettings_set for netdev with phy attached for now */
779 if (netdev->phydev) {
780 if (cmd->base.speed == SPEED_1000 &&
781 cmd->base.autoneg == AUTONEG_DISABLE)
784 return phy_ethtool_ksettings_set(netdev->phydev, cmd);
787 if (handle->pdev->revision == 0x20)
790 ret = hns3_check_ksettings_param(netdev, cmd);
794 if (ops->set_autoneg) {
795 ret = ops->set_autoneg(handle, cmd->base.autoneg);
800 /* hw doesn't support use specified speed and duplex to negotiate,
801 * ignore them when autoneg on.
803 if (cmd->base.autoneg) {
805 "autoneg is on, ignore the speed and duplex\n");
809 if (ops->cfg_mac_speed_dup_h)
810 ret = ops->cfg_mac_speed_dup_h(handle, cmd->base.speed,
816 static u32 hns3_get_rss_key_size(struct net_device *netdev)
818 struct hnae3_handle *h = hns3_get_handle(netdev);
820 if (!h->ae_algo->ops->get_rss_key_size)
823 return h->ae_algo->ops->get_rss_key_size(h);
826 static u32 hns3_get_rss_indir_size(struct net_device *netdev)
828 struct hnae3_handle *h = hns3_get_handle(netdev);
830 if (!h->ae_algo->ops->get_rss_indir_size)
833 return h->ae_algo->ops->get_rss_indir_size(h);
836 static int hns3_get_rss(struct net_device *netdev, u32 *indir, u8 *key,
839 struct hnae3_handle *h = hns3_get_handle(netdev);
841 if (!h->ae_algo->ops->get_rss)
844 return h->ae_algo->ops->get_rss(h, indir, key, hfunc);
847 static int hns3_set_rss(struct net_device *netdev, const u32 *indir,
848 const u8 *key, const u8 hfunc)
850 struct hnae3_handle *h = hns3_get_handle(netdev);
852 if (!h->ae_algo->ops->set_rss)
855 if ((h->pdev->revision == 0x20 &&
856 hfunc != ETH_RSS_HASH_TOP) || (hfunc != ETH_RSS_HASH_NO_CHANGE &&
857 hfunc != ETH_RSS_HASH_TOP && hfunc != ETH_RSS_HASH_XOR)) {
858 netdev_err(netdev, "hash func not supported\n");
864 "set rss failed for indir is empty\n");
868 return h->ae_algo->ops->set_rss(h, indir, key, hfunc);
871 static int hns3_get_rxnfc(struct net_device *netdev,
872 struct ethtool_rxnfc *cmd,
875 struct hnae3_handle *h = hns3_get_handle(netdev);
878 case ETHTOOL_GRXRINGS:
879 cmd->data = h->kinfo.num_tqps;
882 if (h->ae_algo->ops->get_rss_tuple)
883 return h->ae_algo->ops->get_rss_tuple(h, cmd);
885 case ETHTOOL_GRXCLSRLCNT:
886 if (h->ae_algo->ops->get_fd_rule_cnt)
887 return h->ae_algo->ops->get_fd_rule_cnt(h, cmd);
889 case ETHTOOL_GRXCLSRULE:
890 if (h->ae_algo->ops->get_fd_rule_info)
891 return h->ae_algo->ops->get_fd_rule_info(h, cmd);
893 case ETHTOOL_GRXCLSRLALL:
894 if (h->ae_algo->ops->get_fd_all_rules)
895 return h->ae_algo->ops->get_fd_all_rules(h, cmd,
903 static void hns3_change_all_ring_bd_num(struct hns3_nic_priv *priv,
904 u32 tx_desc_num, u32 rx_desc_num)
906 struct hnae3_handle *h = priv->ae_handle;
909 h->kinfo.num_tx_desc = tx_desc_num;
910 h->kinfo.num_rx_desc = rx_desc_num;
912 for (i = 0; i < h->kinfo.num_tqps; i++) {
913 priv->ring[i].desc_num = tx_desc_num;
914 priv->ring[i + h->kinfo.num_tqps].desc_num = rx_desc_num;
918 static struct hns3_enet_ring *hns3_backup_ringparam(struct hns3_nic_priv *priv)
920 struct hnae3_handle *handle = priv->ae_handle;
921 struct hns3_enet_ring *tmp_rings;
924 tmp_rings = kcalloc(handle->kinfo.num_tqps * 2,
925 sizeof(struct hns3_enet_ring), GFP_KERNEL);
929 for (i = 0; i < handle->kinfo.num_tqps * 2; i++) {
930 memcpy(&tmp_rings[i], &priv->ring[i],
931 sizeof(struct hns3_enet_ring));
932 tmp_rings[i].skb = NULL;
938 static int hns3_check_ringparam(struct net_device *ndev,
939 struct ethtool_ringparam *param)
941 if (hns3_nic_resetting(ndev))
944 if (param->rx_mini_pending || param->rx_jumbo_pending)
947 if (param->tx_pending > HNS3_RING_MAX_PENDING ||
948 param->tx_pending < HNS3_RING_MIN_PENDING ||
949 param->rx_pending > HNS3_RING_MAX_PENDING ||
950 param->rx_pending < HNS3_RING_MIN_PENDING) {
951 netdev_err(ndev, "Queue depth out of range [%d-%d]\n",
952 HNS3_RING_MIN_PENDING, HNS3_RING_MAX_PENDING);
959 static int hns3_set_ringparam(struct net_device *ndev,
960 struct ethtool_ringparam *param)
962 struct hns3_nic_priv *priv = netdev_priv(ndev);
963 struct hnae3_handle *h = priv->ae_handle;
964 struct hns3_enet_ring *tmp_rings;
965 bool if_running = netif_running(ndev);
966 u32 old_tx_desc_num, new_tx_desc_num;
967 u32 old_rx_desc_num, new_rx_desc_num;
968 u16 queue_num = h->kinfo.num_tqps;
971 ret = hns3_check_ringparam(ndev, param);
975 /* Hardware requires that its descriptors must be multiple of eight */
976 new_tx_desc_num = ALIGN(param->tx_pending, HNS3_RING_BD_MULTIPLE);
977 new_rx_desc_num = ALIGN(param->rx_pending, HNS3_RING_BD_MULTIPLE);
978 old_tx_desc_num = priv->ring[0].desc_num;
979 old_rx_desc_num = priv->ring[queue_num].desc_num;
980 if (old_tx_desc_num == new_tx_desc_num &&
981 old_rx_desc_num == new_rx_desc_num)
984 tmp_rings = hns3_backup_ringparam(priv);
987 "backup ring param failed by allocating memory fail\n");
992 "Changing Tx/Rx ring depth from %u/%u to %u/%u\n",
993 old_tx_desc_num, old_rx_desc_num,
994 new_tx_desc_num, new_rx_desc_num);
997 ndev->netdev_ops->ndo_stop(ndev);
999 hns3_change_all_ring_bd_num(priv, new_tx_desc_num, new_rx_desc_num);
1000 ret = hns3_init_all_ring(priv);
1002 netdev_err(ndev, "Change bd num fail, revert to old value(%d)\n",
1005 hns3_change_all_ring_bd_num(priv, old_tx_desc_num,
1007 for (i = 0; i < h->kinfo.num_tqps * 2; i++)
1008 memcpy(&priv->ring[i], &tmp_rings[i],
1009 sizeof(struct hns3_enet_ring));
1011 for (i = 0; i < h->kinfo.num_tqps * 2; i++)
1012 hns3_fini_ring(&tmp_rings[i]);
1018 ret = ndev->netdev_ops->ndo_open(ndev);
1023 static int hns3_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1025 struct hnae3_handle *h = hns3_get_handle(netdev);
1029 if (h->ae_algo->ops->set_rss_tuple)
1030 return h->ae_algo->ops->set_rss_tuple(h, cmd);
1032 case ETHTOOL_SRXCLSRLINS:
1033 if (h->ae_algo->ops->add_fd_entry)
1034 return h->ae_algo->ops->add_fd_entry(h, cmd);
1036 case ETHTOOL_SRXCLSRLDEL:
1037 if (h->ae_algo->ops->del_fd_entry)
1038 return h->ae_algo->ops->del_fd_entry(h, cmd);
1045 static int hns3_nway_reset(struct net_device *netdev)
1047 struct hnae3_handle *handle = hns3_get_handle(netdev);
1048 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1049 struct phy_device *phy = netdev->phydev;
1052 if (!netif_running(netdev))
1055 if (hns3_nic_resetting(netdev)) {
1056 netdev_err(netdev, "dev resetting!");
1060 if (!ops->get_autoneg || !ops->restart_autoneg)
1063 autoneg = ops->get_autoneg(handle);
1064 if (autoneg != AUTONEG_ENABLE) {
1066 "Autoneg is off, don't support to restart it\n");
1070 netif_dbg(handle, drv, netdev,
1071 "nway reset (using %s)\n", phy ? "phy" : "mac");
1074 return genphy_restart_aneg(phy);
1076 if (handle->pdev->revision == 0x20)
1079 return ops->restart_autoneg(handle);
1082 static void hns3_get_channels(struct net_device *netdev,
1083 struct ethtool_channels *ch)
1085 struct hnae3_handle *h = hns3_get_handle(netdev);
1087 if (h->ae_algo->ops->get_channels)
1088 h->ae_algo->ops->get_channels(h, ch);
1091 static int hns3_get_coalesce_per_queue(struct net_device *netdev, u32 queue,
1092 struct ethtool_coalesce *cmd)
1094 struct hns3_enet_tqp_vector *tx_vector, *rx_vector;
1095 struct hns3_nic_priv *priv = netdev_priv(netdev);
1096 struct hnae3_handle *h = priv->ae_handle;
1097 u16 queue_num = h->kinfo.num_tqps;
1099 if (hns3_nic_resetting(netdev))
1102 if (queue >= queue_num) {
1104 "Invalid queue value %u! Queue max id=%u\n",
1105 queue, queue_num - 1);
1109 tx_vector = priv->ring[queue].tqp_vector;
1110 rx_vector = priv->ring[queue_num + queue].tqp_vector;
1112 cmd->use_adaptive_tx_coalesce =
1113 tx_vector->tx_group.coal.gl_adapt_enable;
1114 cmd->use_adaptive_rx_coalesce =
1115 rx_vector->rx_group.coal.gl_adapt_enable;
1117 cmd->tx_coalesce_usecs = tx_vector->tx_group.coal.int_gl;
1118 cmd->rx_coalesce_usecs = rx_vector->rx_group.coal.int_gl;
1120 cmd->tx_coalesce_usecs_high = h->kinfo.int_rl_setting;
1121 cmd->rx_coalesce_usecs_high = h->kinfo.int_rl_setting;
1126 static int hns3_get_coalesce(struct net_device *netdev,
1127 struct ethtool_coalesce *cmd)
1129 return hns3_get_coalesce_per_queue(netdev, 0, cmd);
1132 static int hns3_check_gl_coalesce_para(struct net_device *netdev,
1133 struct ethtool_coalesce *cmd)
1137 if (cmd->rx_coalesce_usecs > HNS3_INT_GL_MAX) {
1139 "Invalid rx-usecs value, rx-usecs range is 0-%d\n",
1144 if (cmd->tx_coalesce_usecs > HNS3_INT_GL_MAX) {
1146 "Invalid tx-usecs value, tx-usecs range is 0-%d\n",
1151 rx_gl = hns3_gl_round_down(cmd->rx_coalesce_usecs);
1152 if (rx_gl != cmd->rx_coalesce_usecs) {
1154 "rx_usecs(%u) rounded down to %u, because it must be multiple of 2.\n",
1155 cmd->rx_coalesce_usecs, rx_gl);
1158 tx_gl = hns3_gl_round_down(cmd->tx_coalesce_usecs);
1159 if (tx_gl != cmd->tx_coalesce_usecs) {
1161 "tx_usecs(%u) rounded down to %u, because it must be multiple of 2.\n",
1162 cmd->tx_coalesce_usecs, tx_gl);
1168 static int hns3_check_rl_coalesce_para(struct net_device *netdev,
1169 struct ethtool_coalesce *cmd)
1173 if (cmd->tx_coalesce_usecs_high != cmd->rx_coalesce_usecs_high) {
1175 "tx_usecs_high must be same as rx_usecs_high.\n");
1179 if (cmd->rx_coalesce_usecs_high > HNS3_INT_RL_MAX) {
1181 "Invalid usecs_high value, usecs_high range is 0-%d\n",
1186 rl = hns3_rl_round_down(cmd->rx_coalesce_usecs_high);
1187 if (rl != cmd->rx_coalesce_usecs_high) {
1189 "usecs_high(%u) rounded down to %u, because it must be multiple of 4.\n",
1190 cmd->rx_coalesce_usecs_high, rl);
1196 static int hns3_check_coalesce_para(struct net_device *netdev,
1197 struct ethtool_coalesce *cmd)
1201 ret = hns3_check_gl_coalesce_para(netdev, cmd);
1204 "Check gl coalesce param fail. ret = %d\n", ret);
1208 ret = hns3_check_rl_coalesce_para(netdev, cmd);
1211 "Check rl coalesce param fail. ret = %d\n", ret);
1215 if (cmd->use_adaptive_tx_coalesce == 1 ||
1216 cmd->use_adaptive_rx_coalesce == 1) {
1218 "adaptive-tx=%u and adaptive-rx=%u, tx_usecs or rx_usecs will changed dynamically.\n",
1219 cmd->use_adaptive_tx_coalesce,
1220 cmd->use_adaptive_rx_coalesce);
1226 static void hns3_set_coalesce_per_queue(struct net_device *netdev,
1227 struct ethtool_coalesce *cmd,
1230 struct hns3_enet_tqp_vector *tx_vector, *rx_vector;
1231 struct hns3_nic_priv *priv = netdev_priv(netdev);
1232 struct hnae3_handle *h = priv->ae_handle;
1233 int queue_num = h->kinfo.num_tqps;
1235 tx_vector = priv->ring[queue].tqp_vector;
1236 rx_vector = priv->ring[queue_num + queue].tqp_vector;
1238 tx_vector->tx_group.coal.gl_adapt_enable =
1239 cmd->use_adaptive_tx_coalesce;
1240 rx_vector->rx_group.coal.gl_adapt_enable =
1241 cmd->use_adaptive_rx_coalesce;
1243 tx_vector->tx_group.coal.int_gl = cmd->tx_coalesce_usecs;
1244 rx_vector->rx_group.coal.int_gl = cmd->rx_coalesce_usecs;
1246 hns3_set_vector_coalesce_tx_gl(tx_vector,
1247 tx_vector->tx_group.coal.int_gl);
1248 hns3_set_vector_coalesce_rx_gl(rx_vector,
1249 rx_vector->rx_group.coal.int_gl);
1251 hns3_set_vector_coalesce_rl(tx_vector, h->kinfo.int_rl_setting);
1252 hns3_set_vector_coalesce_rl(rx_vector, h->kinfo.int_rl_setting);
1255 static int hns3_set_coalesce(struct net_device *netdev,
1256 struct ethtool_coalesce *cmd)
1258 struct hnae3_handle *h = hns3_get_handle(netdev);
1259 u16 queue_num = h->kinfo.num_tqps;
1263 if (hns3_nic_resetting(netdev))
1266 ret = hns3_check_coalesce_para(netdev, cmd);
1270 h->kinfo.int_rl_setting =
1271 hns3_rl_round_down(cmd->rx_coalesce_usecs_high);
1273 for (i = 0; i < queue_num; i++)
1274 hns3_set_coalesce_per_queue(netdev, cmd, i);
1279 static int hns3_get_regs_len(struct net_device *netdev)
1281 struct hnae3_handle *h = hns3_get_handle(netdev);
1283 if (!h->ae_algo->ops->get_regs_len)
1286 return h->ae_algo->ops->get_regs_len(h);
1289 static void hns3_get_regs(struct net_device *netdev,
1290 struct ethtool_regs *cmd, void *data)
1292 struct hnae3_handle *h = hns3_get_handle(netdev);
1294 if (!h->ae_algo->ops->get_regs)
1297 h->ae_algo->ops->get_regs(h, &cmd->version, data);
1300 static int hns3_set_phys_id(struct net_device *netdev,
1301 enum ethtool_phys_id_state state)
1303 struct hnae3_handle *h = hns3_get_handle(netdev);
1305 if (!h->ae_algo->ops->set_led_id)
1308 return h->ae_algo->ops->set_led_id(h, state);
1311 static u32 hns3_get_msglevel(struct net_device *netdev)
1313 struct hnae3_handle *h = hns3_get_handle(netdev);
1315 return h->msg_enable;
1318 static void hns3_set_msglevel(struct net_device *netdev, u32 msg_level)
1320 struct hnae3_handle *h = hns3_get_handle(netdev);
1322 h->msg_enable = msg_level;
1325 /* Translate local fec value into ethtool value. */
1326 static unsigned int loc_to_eth_fec(u8 loc_fec)
1330 if (loc_fec & BIT(HNAE3_FEC_AUTO))
1331 eth_fec |= ETHTOOL_FEC_AUTO;
1332 if (loc_fec & BIT(HNAE3_FEC_RS))
1333 eth_fec |= ETHTOOL_FEC_RS;
1334 if (loc_fec & BIT(HNAE3_FEC_BASER))
1335 eth_fec |= ETHTOOL_FEC_BASER;
1337 /* if nothing is set, then FEC is off */
1339 eth_fec = ETHTOOL_FEC_OFF;
1344 /* Translate ethtool fec value into local value. */
1345 static unsigned int eth_to_loc_fec(unsigned int eth_fec)
1349 if (eth_fec & ETHTOOL_FEC_OFF)
1352 if (eth_fec & ETHTOOL_FEC_AUTO)
1353 loc_fec |= BIT(HNAE3_FEC_AUTO);
1354 if (eth_fec & ETHTOOL_FEC_RS)
1355 loc_fec |= BIT(HNAE3_FEC_RS);
1356 if (eth_fec & ETHTOOL_FEC_BASER)
1357 loc_fec |= BIT(HNAE3_FEC_BASER);
1362 static int hns3_get_fecparam(struct net_device *netdev,
1363 struct ethtool_fecparam *fec)
1365 struct hnae3_handle *handle = hns3_get_handle(netdev);
1366 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1370 if (handle->pdev->revision == 0x20)
1376 ops->get_fec(handle, &fec_ability, &fec_mode);
1378 fec->fec = loc_to_eth_fec(fec_ability);
1379 fec->active_fec = loc_to_eth_fec(fec_mode);
1384 static int hns3_set_fecparam(struct net_device *netdev,
1385 struct ethtool_fecparam *fec)
1387 struct hnae3_handle *handle = hns3_get_handle(netdev);
1388 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1391 if (handle->pdev->revision == 0x20)
1396 fec_mode = eth_to_loc_fec(fec->fec);
1398 netif_dbg(handle, drv, netdev, "set fecparam: mode=%u\n", fec_mode);
1400 return ops->set_fec(handle, fec_mode);
1403 static int hns3_get_module_info(struct net_device *netdev,
1404 struct ethtool_modinfo *modinfo)
1406 #define HNS3_SFF_8636_V1_3 0x03
1408 struct hnae3_handle *handle = hns3_get_handle(netdev);
1409 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1410 struct hns3_sfp_type sfp_type;
1413 if (handle->pdev->revision == 0x20 || !ops->get_module_eeprom)
1416 memset(&sfp_type, 0, sizeof(sfp_type));
1417 ret = ops->get_module_eeprom(handle, 0, sizeof(sfp_type) / sizeof(u8),
1422 switch (sfp_type.type) {
1423 case SFF8024_ID_SFP:
1424 modinfo->type = ETH_MODULE_SFF_8472;
1425 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1427 case SFF8024_ID_QSFP_8438:
1428 modinfo->type = ETH_MODULE_SFF_8436;
1429 modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
1431 case SFF8024_ID_QSFP_8436_8636:
1432 if (sfp_type.ext_type < HNS3_SFF_8636_V1_3) {
1433 modinfo->type = ETH_MODULE_SFF_8436;
1434 modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
1436 modinfo->type = ETH_MODULE_SFF_8636;
1437 modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
1440 case SFF8024_ID_QSFP28_8636:
1441 modinfo->type = ETH_MODULE_SFF_8636;
1442 modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
1445 netdev_err(netdev, "Optical module unknown: %#x\n",
1453 static int hns3_get_module_eeprom(struct net_device *netdev,
1454 struct ethtool_eeprom *ee, u8 *data)
1456 struct hnae3_handle *handle = hns3_get_handle(netdev);
1457 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1459 if (handle->pdev->revision == 0x20 || !ops->get_module_eeprom)
1465 memset(data, 0, ee->len);
1467 return ops->get_module_eeprom(handle, ee->offset, ee->len, data);
1470 #define HNS3_ETHTOOL_COALESCE (ETHTOOL_COALESCE_USECS | \
1471 ETHTOOL_COALESCE_USE_ADAPTIVE | \
1472 ETHTOOL_COALESCE_RX_USECS_HIGH | \
1473 ETHTOOL_COALESCE_TX_USECS_HIGH)
1475 static const struct ethtool_ops hns3vf_ethtool_ops = {
1476 .supported_coalesce_params = HNS3_ETHTOOL_COALESCE,
1477 .get_drvinfo = hns3_get_drvinfo,
1478 .get_ringparam = hns3_get_ringparam,
1479 .set_ringparam = hns3_set_ringparam,
1480 .get_strings = hns3_get_strings,
1481 .get_ethtool_stats = hns3_get_stats,
1482 .get_sset_count = hns3_get_sset_count,
1483 .get_rxnfc = hns3_get_rxnfc,
1484 .set_rxnfc = hns3_set_rxnfc,
1485 .get_rxfh_key_size = hns3_get_rss_key_size,
1486 .get_rxfh_indir_size = hns3_get_rss_indir_size,
1487 .get_rxfh = hns3_get_rss,
1488 .set_rxfh = hns3_set_rss,
1489 .get_link_ksettings = hns3_get_link_ksettings,
1490 .get_channels = hns3_get_channels,
1491 .set_channels = hns3_set_channels,
1492 .get_coalesce = hns3_get_coalesce,
1493 .set_coalesce = hns3_set_coalesce,
1494 .get_regs_len = hns3_get_regs_len,
1495 .get_regs = hns3_get_regs,
1496 .get_link = hns3_get_link,
1497 .get_msglevel = hns3_get_msglevel,
1498 .set_msglevel = hns3_set_msglevel,
1501 static const struct ethtool_ops hns3_ethtool_ops = {
1502 .supported_coalesce_params = HNS3_ETHTOOL_COALESCE,
1503 .self_test = hns3_self_test,
1504 .get_drvinfo = hns3_get_drvinfo,
1505 .get_link = hns3_get_link,
1506 .get_ringparam = hns3_get_ringparam,
1507 .set_ringparam = hns3_set_ringparam,
1508 .get_pauseparam = hns3_get_pauseparam,
1509 .set_pauseparam = hns3_set_pauseparam,
1510 .get_strings = hns3_get_strings,
1511 .get_ethtool_stats = hns3_get_stats,
1512 .get_sset_count = hns3_get_sset_count,
1513 .get_rxnfc = hns3_get_rxnfc,
1514 .set_rxnfc = hns3_set_rxnfc,
1515 .get_rxfh_key_size = hns3_get_rss_key_size,
1516 .get_rxfh_indir_size = hns3_get_rss_indir_size,
1517 .get_rxfh = hns3_get_rss,
1518 .set_rxfh = hns3_set_rss,
1519 .get_link_ksettings = hns3_get_link_ksettings,
1520 .set_link_ksettings = hns3_set_link_ksettings,
1521 .nway_reset = hns3_nway_reset,
1522 .get_channels = hns3_get_channels,
1523 .set_channels = hns3_set_channels,
1524 .get_coalesce = hns3_get_coalesce,
1525 .set_coalesce = hns3_set_coalesce,
1526 .get_regs_len = hns3_get_regs_len,
1527 .get_regs = hns3_get_regs,
1528 .set_phys_id = hns3_set_phys_id,
1529 .get_msglevel = hns3_get_msglevel,
1530 .set_msglevel = hns3_set_msglevel,
1531 .get_fecparam = hns3_get_fecparam,
1532 .set_fecparam = hns3_set_fecparam,
1533 .get_module_info = hns3_get_module_info,
1534 .get_module_eeprom = hns3_get_module_eeprom,
1537 void hns3_ethtool_set_ops(struct net_device *netdev)
1539 struct hnae3_handle *h = hns3_get_handle(netdev);
1541 if (h->flags & HNAE3_SUPPORT_VF)
1542 netdev->ethtool_ops = &hns3vf_ethtool_ops;
1544 netdev->ethtool_ops = &hns3_ethtool_ops;