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("dropped", sw_err_cnt),
31 HNS3_TQP_STAT("seg_pkt_cnt", seg_pkt_cnt),
32 HNS3_TQP_STAT("packets", tx_pkts),
33 HNS3_TQP_STAT("bytes", tx_bytes),
34 HNS3_TQP_STAT("more", tx_more),
35 HNS3_TQP_STAT("wake", restart_queue),
36 HNS3_TQP_STAT("busy", tx_busy),
37 HNS3_TQP_STAT("copy", tx_copy),
38 HNS3_TQP_STAT("vlan_err", tx_vlan_err),
39 HNS3_TQP_STAT("l4_proto_err", tx_l4_proto_err),
40 HNS3_TQP_STAT("l2l3l4_err", tx_l2l3l4_err),
41 HNS3_TQP_STAT("tso_err", tx_tso_err),
44 #define HNS3_TXQ_STATS_COUNT ARRAY_SIZE(hns3_txq_stats)
46 static const struct hns3_stats hns3_rxq_stats[] = {
47 /* Rx per-queue statistics */
48 HNS3_TQP_STAT("dropped", sw_err_cnt),
49 HNS3_TQP_STAT("seg_pkt_cnt", seg_pkt_cnt),
50 HNS3_TQP_STAT("packets", rx_pkts),
51 HNS3_TQP_STAT("bytes", rx_bytes),
52 HNS3_TQP_STAT("errors", rx_err_cnt),
53 HNS3_TQP_STAT("reuse_pg_cnt", reuse_pg_cnt),
54 HNS3_TQP_STAT("err_pkt_len", err_pkt_len),
55 HNS3_TQP_STAT("err_bd_num", err_bd_num),
56 HNS3_TQP_STAT("l2_err", l2_err),
57 HNS3_TQP_STAT("l3l4_csum_err", l3l4_csum_err),
58 HNS3_TQP_STAT("multicast", rx_multicast),
59 HNS3_TQP_STAT("non_reuse_pg", non_reuse_pg),
62 #define HNS3_RXQ_STATS_COUNT ARRAY_SIZE(hns3_rxq_stats)
64 #define HNS3_TQP_STATS_COUNT (HNS3_TXQ_STATS_COUNT + HNS3_RXQ_STATS_COUNT)
66 #define HNS3_SELF_TEST_TYPE_NUM 4
67 #define HNS3_NIC_LB_TEST_PKT_NUM 1
68 #define HNS3_NIC_LB_TEST_RING_ID 0
69 #define HNS3_NIC_LB_TEST_PACKET_SIZE 128
70 #define HNS3_NIC_LB_SETUP_USEC 10000
72 /* Nic loopback test err */
73 #define HNS3_NIC_LB_TEST_NO_MEM_ERR 1
74 #define HNS3_NIC_LB_TEST_TX_CNT_ERR 2
75 #define HNS3_NIC_LB_TEST_RX_CNT_ERR 3
77 static int hns3_lp_setup(struct net_device *ndev, enum hnae3_loop loop, bool en)
79 struct hnae3_handle *h = hns3_get_handle(ndev);
80 bool vlan_filter_enable;
83 if (!h->ae_algo->ops->set_loopback ||
84 !h->ae_algo->ops->set_promisc_mode)
88 case HNAE3_LOOP_SERIAL_SERDES:
89 case HNAE3_LOOP_PARALLEL_SERDES:
92 ret = h->ae_algo->ops->set_loopback(h, loop, en);
99 if (ret || h->pdev->revision >= 0x21)
103 h->ae_algo->ops->set_promisc_mode(h, true, true);
105 /* recover promisc mode before loopback test */
106 hns3_request_update_promisc_mode(h);
107 vlan_filter_enable = ndev->flags & IFF_PROMISC ? false : true;
108 hns3_enable_vlan_filter(ndev, vlan_filter_enable);
114 static int hns3_lp_up(struct net_device *ndev, enum hnae3_loop loop_mode)
116 struct hnae3_handle *h = hns3_get_handle(ndev);
119 ret = hns3_nic_reset_all_ring(h);
123 ret = hns3_lp_setup(ndev, loop_mode, true);
124 usleep_range(HNS3_NIC_LB_SETUP_USEC, HNS3_NIC_LB_SETUP_USEC * 2);
129 static int hns3_lp_down(struct net_device *ndev, enum hnae3_loop loop_mode)
133 ret = hns3_lp_setup(ndev, loop_mode, false);
135 netdev_err(ndev, "lb_setup return error: %d\n", ret);
139 usleep_range(HNS3_NIC_LB_SETUP_USEC, HNS3_NIC_LB_SETUP_USEC * 2);
144 static void hns3_lp_setup_skb(struct sk_buff *skb)
146 #define HNS3_NIC_LB_DST_MAC_ADDR 0x1f
148 struct net_device *ndev = skb->dev;
149 struct hnae3_handle *handle;
150 unsigned char *packet;
154 skb_reserve(skb, NET_IP_ALIGN);
155 ethh = skb_put(skb, sizeof(struct ethhdr));
156 packet = skb_put(skb, HNS3_NIC_LB_TEST_PACKET_SIZE);
158 memcpy(ethh->h_dest, ndev->dev_addr, ETH_ALEN);
160 /* The dst mac addr of loopback packet is the same as the host'
161 * mac addr, the SSU component may loop back the packet to host
162 * before the packet reaches mac or serdes, which will defect
163 * the purpose of mac or serdes selftest.
165 handle = hns3_get_handle(ndev);
166 if (handle->pdev->revision == 0x20)
167 ethh->h_dest[5] += HNS3_NIC_LB_DST_MAC_ADDR;
168 eth_zero_addr(ethh->h_source);
169 ethh->h_proto = htons(ETH_P_ARP);
170 skb_reset_mac_header(skb);
172 for (i = 0; i < HNS3_NIC_LB_TEST_PACKET_SIZE; i++)
173 packet[i] = (unsigned char)(i & 0xff);
176 static void hns3_lb_check_skb_data(struct hns3_enet_ring *ring,
179 struct hns3_enet_tqp_vector *tqp_vector = ring->tqp_vector;
180 unsigned char *packet = skb->data;
181 u32 len = skb_headlen(skb);
184 len = min_t(u32, len, HNS3_NIC_LB_TEST_PACKET_SIZE);
186 for (i = 0; i < len; i++)
187 if (packet[i] != (unsigned char)(i & 0xff))
190 /* The packet is correctly received */
191 if (i == HNS3_NIC_LB_TEST_PACKET_SIZE)
192 tqp_vector->rx_group.total_packets++;
194 print_hex_dump(KERN_ERR, "selftest:", DUMP_PREFIX_OFFSET, 16, 1,
195 skb->data, len, true);
197 dev_kfree_skb_any(skb);
200 static u32 hns3_lb_check_rx_ring(struct hns3_nic_priv *priv, u32 budget)
202 struct hnae3_handle *h = priv->ae_handle;
203 struct hnae3_knic_private_info *kinfo;
204 u32 i, rcv_good_pkt_total = 0;
207 for (i = kinfo->num_tqps; i < kinfo->num_tqps * 2; i++) {
208 struct hns3_enet_ring *ring = &priv->ring[i];
209 struct hns3_enet_ring_group *rx_group;
212 rx_group = &ring->tqp_vector->rx_group;
213 pre_rx_pkt = rx_group->total_packets;
216 hns3_clean_rx_ring(ring, budget, hns3_lb_check_skb_data);
219 rcv_good_pkt_total += (rx_group->total_packets - pre_rx_pkt);
220 rx_group->total_packets = pre_rx_pkt;
222 return rcv_good_pkt_total;
225 static void hns3_lb_clear_tx_ring(struct hns3_nic_priv *priv, u32 start_ringid,
226 u32 end_ringid, u32 budget)
230 for (i = start_ringid; i <= end_ringid; i++) {
231 struct hns3_enet_ring *ring = &priv->ring[i];
233 hns3_clean_tx_ring(ring);
238 * hns3_lp_run_test - run loopback test
240 * @mode: loopback type
242 static int hns3_lp_run_test(struct net_device *ndev, enum hnae3_loop mode)
244 struct hns3_nic_priv *priv = netdev_priv(ndev);
249 skb = alloc_skb(HNS3_NIC_LB_TEST_PACKET_SIZE + ETH_HLEN + NET_IP_ALIGN,
252 return HNS3_NIC_LB_TEST_NO_MEM_ERR;
255 hns3_lp_setup_skb(skb);
256 skb->queue_mapping = HNS3_NIC_LB_TEST_RING_ID;
259 for (i = 0; i < HNS3_NIC_LB_TEST_PKT_NUM; i++) {
263 tx_ret = hns3_nic_net_xmit(skb, ndev);
264 if (tx_ret == NETDEV_TX_OK) {
268 netdev_err(ndev, "hns3_lb_run_test xmit failed: %d\n",
272 if (good_cnt != HNS3_NIC_LB_TEST_PKT_NUM) {
273 ret_val = HNS3_NIC_LB_TEST_TX_CNT_ERR;
274 netdev_err(ndev, "mode %d sent fail, cnt=0x%x, budget=0x%x\n",
275 mode, good_cnt, HNS3_NIC_LB_TEST_PKT_NUM);
279 /* Allow 200 milliseconds for packets to go from Tx to Rx */
282 good_cnt = hns3_lb_check_rx_ring(priv, HNS3_NIC_LB_TEST_PKT_NUM);
283 if (good_cnt != HNS3_NIC_LB_TEST_PKT_NUM) {
284 ret_val = HNS3_NIC_LB_TEST_RX_CNT_ERR;
285 netdev_err(ndev, "mode %d recv fail, cnt=0x%x, budget=0x%x\n",
286 mode, good_cnt, HNS3_NIC_LB_TEST_PKT_NUM);
290 hns3_lb_clear_tx_ring(priv, HNS3_NIC_LB_TEST_RING_ID,
291 HNS3_NIC_LB_TEST_RING_ID,
292 HNS3_NIC_LB_TEST_PKT_NUM);
299 * hns3_nic_self_test - self test
301 * @eth_test: test cmd
304 static void hns3_self_test(struct net_device *ndev,
305 struct ethtool_test *eth_test, u64 *data)
307 struct hns3_nic_priv *priv = netdev_priv(ndev);
308 struct hnae3_handle *h = priv->ae_handle;
309 int st_param[HNS3_SELF_TEST_TYPE_NUM][2];
310 bool if_running = netif_running(ndev);
311 #if IS_ENABLED(CONFIG_VLAN_8021Q)
312 bool dis_vlan_filter;
317 if (hns3_nic_resetting(ndev)) {
318 netdev_err(ndev, "dev resetting!");
322 /* Only do offline selftest, or pass by default */
323 if (eth_test->flags != ETH_TEST_FL_OFFLINE)
326 netif_dbg(h, drv, ndev, "self test start");
328 st_param[HNAE3_LOOP_APP][0] = HNAE3_LOOP_APP;
329 st_param[HNAE3_LOOP_APP][1] =
330 h->flags & HNAE3_SUPPORT_APP_LOOPBACK;
332 st_param[HNAE3_LOOP_SERIAL_SERDES][0] = HNAE3_LOOP_SERIAL_SERDES;
333 st_param[HNAE3_LOOP_SERIAL_SERDES][1] =
334 h->flags & HNAE3_SUPPORT_SERDES_SERIAL_LOOPBACK;
336 st_param[HNAE3_LOOP_PARALLEL_SERDES][0] =
337 HNAE3_LOOP_PARALLEL_SERDES;
338 st_param[HNAE3_LOOP_PARALLEL_SERDES][1] =
339 h->flags & HNAE3_SUPPORT_SERDES_PARALLEL_LOOPBACK;
341 st_param[HNAE3_LOOP_PHY][0] = HNAE3_LOOP_PHY;
342 st_param[HNAE3_LOOP_PHY][1] =
343 h->flags & HNAE3_SUPPORT_PHY_LOOPBACK;
346 ndev->netdev_ops->ndo_stop(ndev);
348 #if IS_ENABLED(CONFIG_VLAN_8021Q)
349 /* Disable the vlan filter for selftest does not support it */
350 dis_vlan_filter = (ndev->features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
351 h->ae_algo->ops->enable_vlan_filter;
353 h->ae_algo->ops->enable_vlan_filter(h, false);
356 /* Tell firmware to stop mac autoneg before loopback test start,
357 * otherwise loopback test may be failed when the port is still
360 if (h->ae_algo->ops->halt_autoneg)
361 h->ae_algo->ops->halt_autoneg(h, true);
363 set_bit(HNS3_NIC_STATE_TESTING, &priv->state);
365 for (i = 0; i < HNS3_SELF_TEST_TYPE_NUM; i++) {
366 enum hnae3_loop loop_type = (enum hnae3_loop)st_param[i][0];
371 data[test_index] = hns3_lp_up(ndev, loop_type);
372 if (!data[test_index])
373 data[test_index] = hns3_lp_run_test(ndev, loop_type);
375 hns3_lp_down(ndev, loop_type);
377 if (data[test_index])
378 eth_test->flags |= ETH_TEST_FL_FAILED;
383 clear_bit(HNS3_NIC_STATE_TESTING, &priv->state);
385 if (h->ae_algo->ops->halt_autoneg)
386 h->ae_algo->ops->halt_autoneg(h, false);
388 #if IS_ENABLED(CONFIG_VLAN_8021Q)
390 h->ae_algo->ops->enable_vlan_filter(h, true);
394 ndev->netdev_ops->ndo_open(ndev);
396 netif_dbg(h, drv, ndev, "self test end\n");
399 static int hns3_get_sset_count(struct net_device *netdev, int stringset)
401 struct hnae3_handle *h = hns3_get_handle(netdev);
402 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
404 if (!ops->get_sset_count)
409 return ((HNS3_TQP_STATS_COUNT * h->kinfo.num_tqps) +
410 ops->get_sset_count(h, stringset));
413 return ops->get_sset_count(h, stringset);
420 static void *hns3_update_strings(u8 *data, const struct hns3_stats *stats,
421 u32 stat_count, u32 num_tqps, const char *prefix)
423 #define MAX_PREFIX_SIZE (6 + 4)
428 for (i = 0; i < num_tqps; i++) {
429 for (j = 0; j < stat_count; j++) {
430 data[ETH_GSTRING_LEN - 1] = '\0';
432 /* first, prepend the prefix string */
433 n1 = scnprintf(data, MAX_PREFIX_SIZE, "%s%d_",
435 size_left = (ETH_GSTRING_LEN - 1) - n1;
437 /* now, concatenate the stats string to it */
438 strncat(data, stats[j].stats_string, size_left);
439 data += ETH_GSTRING_LEN;
446 static u8 *hns3_get_strings_tqps(struct hnae3_handle *handle, u8 *data)
448 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
449 const char tx_prefix[] = "txq";
450 const char rx_prefix[] = "rxq";
452 /* get strings for Tx */
453 data = hns3_update_strings(data, hns3_txq_stats, HNS3_TXQ_STATS_COUNT,
454 kinfo->num_tqps, tx_prefix);
456 /* get strings for Rx */
457 data = hns3_update_strings(data, hns3_rxq_stats, HNS3_RXQ_STATS_COUNT,
458 kinfo->num_tqps, rx_prefix);
463 static void hns3_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
465 struct hnae3_handle *h = hns3_get_handle(netdev);
466 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
467 char *buff = (char *)data;
469 if (!ops->get_strings)
474 buff = hns3_get_strings_tqps(h, buff);
475 ops->get_strings(h, stringset, (u8 *)buff);
478 ops->get_strings(h, stringset, data);
485 static u64 *hns3_get_stats_tqps(struct hnae3_handle *handle, u64 *data)
487 struct hns3_nic_priv *nic_priv = (struct hns3_nic_priv *)handle->priv;
488 struct hnae3_knic_private_info *kinfo = &handle->kinfo;
489 struct hns3_enet_ring *ring;
493 /* get stats for Tx */
494 for (i = 0; i < kinfo->num_tqps; i++) {
495 ring = &nic_priv->ring[i];
496 for (j = 0; j < HNS3_TXQ_STATS_COUNT; j++) {
497 stat = (u8 *)ring + hns3_txq_stats[j].stats_offset;
498 *data++ = *(u64 *)stat;
502 /* get stats for Rx */
503 for (i = 0; i < kinfo->num_tqps; i++) {
504 ring = &nic_priv->ring[i + kinfo->num_tqps];
505 for (j = 0; j < HNS3_RXQ_STATS_COUNT; j++) {
506 stat = (u8 *)ring + hns3_rxq_stats[j].stats_offset;
507 *data++ = *(u64 *)stat;
514 /* hns3_get_stats - get detail statistics.
515 * @netdev: net device
516 * @stats: statistics info.
517 * @data: statistics data.
519 static void hns3_get_stats(struct net_device *netdev,
520 struct ethtool_stats *stats, u64 *data)
522 struct hnae3_handle *h = hns3_get_handle(netdev);
525 if (hns3_nic_resetting(netdev)) {
526 netdev_err(netdev, "dev resetting, could not get stats\n");
530 if (!h->ae_algo->ops->get_stats || !h->ae_algo->ops->update_stats) {
531 netdev_err(netdev, "could not get any statistics\n");
535 h->ae_algo->ops->update_stats(h, &netdev->stats);
537 /* get per-queue stats */
538 p = hns3_get_stats_tqps(h, p);
540 /* get MAC & other misc hardware stats */
541 h->ae_algo->ops->get_stats(h, p);
544 static void hns3_get_drvinfo(struct net_device *netdev,
545 struct ethtool_drvinfo *drvinfo)
547 struct hns3_nic_priv *priv = netdev_priv(netdev);
548 struct hnae3_handle *h = priv->ae_handle;
551 if (!h->ae_algo->ops->get_fw_version) {
552 netdev_err(netdev, "could not get fw version!\n");
556 strncpy(drvinfo->driver, h->pdev->driver->name,
557 sizeof(drvinfo->driver));
558 drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
560 strncpy(drvinfo->bus_info, pci_name(h->pdev),
561 sizeof(drvinfo->bus_info));
562 drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';
564 fw_version = priv->ae_handle->ae_algo->ops->get_fw_version(h);
566 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
568 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE3_MASK,
569 HNAE3_FW_VERSION_BYTE3_SHIFT),
570 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE2_MASK,
571 HNAE3_FW_VERSION_BYTE2_SHIFT),
572 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE1_MASK,
573 HNAE3_FW_VERSION_BYTE1_SHIFT),
574 hnae3_get_field(fw_version, HNAE3_FW_VERSION_BYTE0_MASK,
575 HNAE3_FW_VERSION_BYTE0_SHIFT));
578 static u32 hns3_get_link(struct net_device *netdev)
580 struct hnae3_handle *h = hns3_get_handle(netdev);
582 if (h->ae_algo->ops->get_status)
583 return h->ae_algo->ops->get_status(h);
588 static void hns3_get_ringparam(struct net_device *netdev,
589 struct ethtool_ringparam *param)
591 struct hns3_nic_priv *priv = netdev_priv(netdev);
592 struct hnae3_handle *h = priv->ae_handle;
593 int queue_num = h->kinfo.num_tqps;
595 if (hns3_nic_resetting(netdev)) {
596 netdev_err(netdev, "dev resetting!");
600 param->tx_max_pending = HNS3_RING_MAX_PENDING;
601 param->rx_max_pending = HNS3_RING_MAX_PENDING;
603 param->tx_pending = priv->ring[0].desc_num;
604 param->rx_pending = priv->ring[queue_num].desc_num;
607 static void hns3_get_pauseparam(struct net_device *netdev,
608 struct ethtool_pauseparam *param)
610 struct hnae3_handle *h = hns3_get_handle(netdev);
612 if (h->ae_algo->ops->get_pauseparam)
613 h->ae_algo->ops->get_pauseparam(h, ¶m->autoneg,
614 ¶m->rx_pause, ¶m->tx_pause);
617 static int hns3_set_pauseparam(struct net_device *netdev,
618 struct ethtool_pauseparam *param)
620 struct hnae3_handle *h = hns3_get_handle(netdev);
622 netif_dbg(h, drv, netdev,
623 "set pauseparam: autoneg=%u, rx:%u, tx:%u\n",
624 param->autoneg, param->rx_pause, param->tx_pause);
626 if (h->ae_algo->ops->set_pauseparam)
627 return h->ae_algo->ops->set_pauseparam(h, param->autoneg,
633 static void hns3_get_ksettings(struct hnae3_handle *h,
634 struct ethtool_link_ksettings *cmd)
636 const struct hnae3_ae_ops *ops = h->ae_algo->ops;
638 /* 1.auto_neg & speed & duplex from cmd */
639 if (ops->get_ksettings_an_result)
640 ops->get_ksettings_an_result(h,
645 /* 2.get link mode */
646 if (ops->get_link_mode)
647 ops->get_link_mode(h,
648 cmd->link_modes.supported,
649 cmd->link_modes.advertising);
651 /* 3.mdix_ctrl&mdix get from phy reg */
652 if (ops->get_mdix_mode)
653 ops->get_mdix_mode(h, &cmd->base.eth_tp_mdix_ctrl,
654 &cmd->base.eth_tp_mdix);
657 static int hns3_get_link_ksettings(struct net_device *netdev,
658 struct ethtool_link_ksettings *cmd)
660 struct hnae3_handle *h = hns3_get_handle(netdev);
661 const struct hnae3_ae_ops *ops;
666 ops = h->ae_algo->ops;
667 if (ops->get_media_type)
668 ops->get_media_type(h, &media_type, &module_type);
672 switch (media_type) {
673 case HNAE3_MEDIA_TYPE_NONE:
674 cmd->base.port = PORT_NONE;
675 hns3_get_ksettings(h, cmd);
677 case HNAE3_MEDIA_TYPE_FIBER:
678 if (module_type == HNAE3_MODULE_TYPE_CR)
679 cmd->base.port = PORT_DA;
681 cmd->base.port = PORT_FIBRE;
683 hns3_get_ksettings(h, cmd);
685 case HNAE3_MEDIA_TYPE_BACKPLANE:
686 cmd->base.port = PORT_NONE;
687 hns3_get_ksettings(h, cmd);
689 case HNAE3_MEDIA_TYPE_COPPER:
690 cmd->base.port = PORT_TP;
692 hns3_get_ksettings(h, cmd);
694 phy_ethtool_ksettings_get(netdev->phydev, cmd);
698 netdev_warn(netdev, "Unknown media type");
703 cmd->base.mdio_support = ETH_MDIO_SUPPORTS_C22;
705 link_stat = hns3_get_link(netdev);
707 cmd->base.speed = SPEED_UNKNOWN;
708 cmd->base.duplex = DUPLEX_UNKNOWN;
714 static int hns3_check_ksettings_param(const struct net_device *netdev,
715 const struct ethtool_link_ksettings *cmd)
717 struct hnae3_handle *handle = hns3_get_handle(netdev);
718 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
719 u8 module_type = HNAE3_MODULE_TYPE_UNKNOWN;
720 u8 media_type = HNAE3_MEDIA_TYPE_UNKNOWN;
726 /* hw doesn't support use specified speed and duplex to negotiate,
727 * unnecessary to check them when autoneg on.
729 if (cmd->base.autoneg)
732 if (ops->get_ksettings_an_result) {
733 ops->get_ksettings_an_result(handle, &autoneg, &speed, &duplex);
734 if (cmd->base.autoneg == autoneg && cmd->base.speed == speed &&
735 cmd->base.duplex == duplex)
739 if (ops->get_media_type)
740 ops->get_media_type(handle, &media_type, &module_type);
742 if (cmd->base.duplex == DUPLEX_HALF &&
743 media_type != HNAE3_MEDIA_TYPE_COPPER) {
745 "only copper port supports half duplex!");
749 if (ops->check_port_speed) {
750 ret = ops->check_port_speed(handle, cmd->base.speed);
752 netdev_err(netdev, "unsupported speed\n");
760 static int hns3_set_link_ksettings(struct net_device *netdev,
761 const struct ethtool_link_ksettings *cmd)
763 struct hnae3_handle *handle = hns3_get_handle(netdev);
764 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
767 /* Chip don't support this mode. */
768 if (cmd->base.speed == SPEED_1000 && cmd->base.duplex == DUPLEX_HALF)
771 netif_dbg(handle, drv, netdev,
772 "set link(%s): autoneg=%u, speed=%u, duplex=%u\n",
773 netdev->phydev ? "phy" : "mac",
774 cmd->base.autoneg, cmd->base.speed, cmd->base.duplex);
776 /* Only support ksettings_set for netdev with phy attached for now */
777 if (netdev->phydev) {
778 if (cmd->base.speed == SPEED_1000 &&
779 cmd->base.autoneg == AUTONEG_DISABLE)
782 return phy_ethtool_ksettings_set(netdev->phydev, cmd);
785 if (handle->pdev->revision == 0x20)
788 ret = hns3_check_ksettings_param(netdev, cmd);
792 if (ops->set_autoneg) {
793 ret = ops->set_autoneg(handle, cmd->base.autoneg);
798 /* hw doesn't support use specified speed and duplex to negotiate,
799 * ignore them when autoneg on.
801 if (cmd->base.autoneg) {
803 "autoneg is on, ignore the speed and duplex\n");
807 if (ops->cfg_mac_speed_dup_h)
808 ret = ops->cfg_mac_speed_dup_h(handle, cmd->base.speed,
814 static u32 hns3_get_rss_key_size(struct net_device *netdev)
816 struct hnae3_handle *h = hns3_get_handle(netdev);
818 if (!h->ae_algo->ops->get_rss_key_size)
821 return h->ae_algo->ops->get_rss_key_size(h);
824 static u32 hns3_get_rss_indir_size(struct net_device *netdev)
826 struct hnae3_handle *h = hns3_get_handle(netdev);
828 if (!h->ae_algo->ops->get_rss_indir_size)
831 return h->ae_algo->ops->get_rss_indir_size(h);
834 static int hns3_get_rss(struct net_device *netdev, u32 *indir, u8 *key,
837 struct hnae3_handle *h = hns3_get_handle(netdev);
839 if (!h->ae_algo->ops->get_rss)
842 return h->ae_algo->ops->get_rss(h, indir, key, hfunc);
845 static int hns3_set_rss(struct net_device *netdev, const u32 *indir,
846 const u8 *key, const u8 hfunc)
848 struct hnae3_handle *h = hns3_get_handle(netdev);
850 if (!h->ae_algo->ops->set_rss)
853 if ((h->pdev->revision == 0x20 &&
854 hfunc != ETH_RSS_HASH_TOP) || (hfunc != ETH_RSS_HASH_NO_CHANGE &&
855 hfunc != ETH_RSS_HASH_TOP && hfunc != ETH_RSS_HASH_XOR)) {
856 netdev_err(netdev, "hash func not supported\n");
862 "set rss failed for indir is empty\n");
866 return h->ae_algo->ops->set_rss(h, indir, key, hfunc);
869 static int hns3_get_rxnfc(struct net_device *netdev,
870 struct ethtool_rxnfc *cmd,
873 struct hnae3_handle *h = hns3_get_handle(netdev);
876 case ETHTOOL_GRXRINGS:
877 cmd->data = h->kinfo.num_tqps;
880 if (h->ae_algo->ops->get_rss_tuple)
881 return h->ae_algo->ops->get_rss_tuple(h, cmd);
883 case ETHTOOL_GRXCLSRLCNT:
884 if (h->ae_algo->ops->get_fd_rule_cnt)
885 return h->ae_algo->ops->get_fd_rule_cnt(h, cmd);
887 case ETHTOOL_GRXCLSRULE:
888 if (h->ae_algo->ops->get_fd_rule_info)
889 return h->ae_algo->ops->get_fd_rule_info(h, cmd);
891 case ETHTOOL_GRXCLSRLALL:
892 if (h->ae_algo->ops->get_fd_all_rules)
893 return h->ae_algo->ops->get_fd_all_rules(h, cmd,
901 static void hns3_change_all_ring_bd_num(struct hns3_nic_priv *priv,
902 u32 tx_desc_num, u32 rx_desc_num)
904 struct hnae3_handle *h = priv->ae_handle;
907 h->kinfo.num_tx_desc = tx_desc_num;
908 h->kinfo.num_rx_desc = rx_desc_num;
910 for (i = 0; i < h->kinfo.num_tqps; i++) {
911 priv->ring[i].desc_num = tx_desc_num;
912 priv->ring[i + h->kinfo.num_tqps].desc_num = rx_desc_num;
916 static struct hns3_enet_ring *hns3_backup_ringparam(struct hns3_nic_priv *priv)
918 struct hnae3_handle *handle = priv->ae_handle;
919 struct hns3_enet_ring *tmp_rings;
922 tmp_rings = kcalloc(handle->kinfo.num_tqps * 2,
923 sizeof(struct hns3_enet_ring), GFP_KERNEL);
927 for (i = 0; i < handle->kinfo.num_tqps * 2; i++) {
928 memcpy(&tmp_rings[i], &priv->ring[i],
929 sizeof(struct hns3_enet_ring));
930 tmp_rings[i].skb = NULL;
936 static int hns3_check_ringparam(struct net_device *ndev,
937 struct ethtool_ringparam *param)
939 if (hns3_nic_resetting(ndev))
942 if (param->rx_mini_pending || param->rx_jumbo_pending)
945 if (param->tx_pending > HNS3_RING_MAX_PENDING ||
946 param->tx_pending < HNS3_RING_MIN_PENDING ||
947 param->rx_pending > HNS3_RING_MAX_PENDING ||
948 param->rx_pending < HNS3_RING_MIN_PENDING) {
949 netdev_err(ndev, "Queue depth out of range [%d-%d]\n",
950 HNS3_RING_MIN_PENDING, HNS3_RING_MAX_PENDING);
957 static int hns3_set_ringparam(struct net_device *ndev,
958 struct ethtool_ringparam *param)
960 struct hns3_nic_priv *priv = netdev_priv(ndev);
961 struct hnae3_handle *h = priv->ae_handle;
962 struct hns3_enet_ring *tmp_rings;
963 bool if_running = netif_running(ndev);
964 u32 old_tx_desc_num, new_tx_desc_num;
965 u32 old_rx_desc_num, new_rx_desc_num;
966 u16 queue_num = h->kinfo.num_tqps;
969 ret = hns3_check_ringparam(ndev, param);
973 /* Hardware requires that its descriptors must be multiple of eight */
974 new_tx_desc_num = ALIGN(param->tx_pending, HNS3_RING_BD_MULTIPLE);
975 new_rx_desc_num = ALIGN(param->rx_pending, HNS3_RING_BD_MULTIPLE);
976 old_tx_desc_num = priv->ring[0].desc_num;
977 old_rx_desc_num = priv->ring[queue_num].desc_num;
978 if (old_tx_desc_num == new_tx_desc_num &&
979 old_rx_desc_num == new_rx_desc_num)
982 tmp_rings = hns3_backup_ringparam(priv);
985 "backup ring param failed by allocating memory fail\n");
990 "Changing Tx/Rx ring depth from %u/%u to %u/%u\n",
991 old_tx_desc_num, old_rx_desc_num,
992 new_tx_desc_num, new_rx_desc_num);
995 ndev->netdev_ops->ndo_stop(ndev);
997 hns3_change_all_ring_bd_num(priv, new_tx_desc_num, new_rx_desc_num);
998 ret = hns3_init_all_ring(priv);
1000 netdev_err(ndev, "Change bd num fail, revert to old value(%d)\n",
1003 hns3_change_all_ring_bd_num(priv, old_tx_desc_num,
1005 for (i = 0; i < h->kinfo.num_tqps * 2; i++)
1006 memcpy(&priv->ring[i], &tmp_rings[i],
1007 sizeof(struct hns3_enet_ring));
1009 for (i = 0; i < h->kinfo.num_tqps * 2; i++)
1010 hns3_fini_ring(&tmp_rings[i]);
1016 ret = ndev->netdev_ops->ndo_open(ndev);
1021 static int hns3_set_rxnfc(struct net_device *netdev, struct ethtool_rxnfc *cmd)
1023 struct hnae3_handle *h = hns3_get_handle(netdev);
1027 if (h->ae_algo->ops->set_rss_tuple)
1028 return h->ae_algo->ops->set_rss_tuple(h, cmd);
1030 case ETHTOOL_SRXCLSRLINS:
1031 if (h->ae_algo->ops->add_fd_entry)
1032 return h->ae_algo->ops->add_fd_entry(h, cmd);
1034 case ETHTOOL_SRXCLSRLDEL:
1035 if (h->ae_algo->ops->del_fd_entry)
1036 return h->ae_algo->ops->del_fd_entry(h, cmd);
1043 static int hns3_nway_reset(struct net_device *netdev)
1045 struct hnae3_handle *handle = hns3_get_handle(netdev);
1046 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1047 struct phy_device *phy = netdev->phydev;
1050 if (!netif_running(netdev))
1053 if (hns3_nic_resetting(netdev)) {
1054 netdev_err(netdev, "dev resetting!");
1058 if (!ops->get_autoneg || !ops->restart_autoneg)
1061 autoneg = ops->get_autoneg(handle);
1062 if (autoneg != AUTONEG_ENABLE) {
1064 "Autoneg is off, don't support to restart it\n");
1068 netif_dbg(handle, drv, netdev,
1069 "nway reset (using %s)\n", phy ? "phy" : "mac");
1072 return genphy_restart_aneg(phy);
1074 if (handle->pdev->revision == 0x20)
1077 return ops->restart_autoneg(handle);
1080 static void hns3_get_channels(struct net_device *netdev,
1081 struct ethtool_channels *ch)
1083 struct hnae3_handle *h = hns3_get_handle(netdev);
1085 if (h->ae_algo->ops->get_channels)
1086 h->ae_algo->ops->get_channels(h, ch);
1089 static int hns3_get_coalesce_per_queue(struct net_device *netdev, u32 queue,
1090 struct ethtool_coalesce *cmd)
1092 struct hns3_enet_tqp_vector *tx_vector, *rx_vector;
1093 struct hns3_nic_priv *priv = netdev_priv(netdev);
1094 struct hnae3_handle *h = priv->ae_handle;
1095 u16 queue_num = h->kinfo.num_tqps;
1097 if (hns3_nic_resetting(netdev))
1100 if (queue >= queue_num) {
1102 "Invalid queue value %u! Queue max id=%u\n",
1103 queue, queue_num - 1);
1107 tx_vector = priv->ring[queue].tqp_vector;
1108 rx_vector = priv->ring[queue_num + queue].tqp_vector;
1110 cmd->use_adaptive_tx_coalesce =
1111 tx_vector->tx_group.coal.gl_adapt_enable;
1112 cmd->use_adaptive_rx_coalesce =
1113 rx_vector->rx_group.coal.gl_adapt_enable;
1115 cmd->tx_coalesce_usecs = tx_vector->tx_group.coal.int_gl;
1116 cmd->rx_coalesce_usecs = rx_vector->rx_group.coal.int_gl;
1118 cmd->tx_coalesce_usecs_high = h->kinfo.int_rl_setting;
1119 cmd->rx_coalesce_usecs_high = h->kinfo.int_rl_setting;
1124 static int hns3_get_coalesce(struct net_device *netdev,
1125 struct ethtool_coalesce *cmd)
1127 return hns3_get_coalesce_per_queue(netdev, 0, cmd);
1130 static int hns3_check_gl_coalesce_para(struct net_device *netdev,
1131 struct ethtool_coalesce *cmd)
1135 if (cmd->rx_coalesce_usecs > HNS3_INT_GL_MAX) {
1137 "Invalid rx-usecs value, rx-usecs range is 0-%d\n",
1142 if (cmd->tx_coalesce_usecs > HNS3_INT_GL_MAX) {
1144 "Invalid tx-usecs value, tx-usecs range is 0-%d\n",
1149 rx_gl = hns3_gl_round_down(cmd->rx_coalesce_usecs);
1150 if (rx_gl != cmd->rx_coalesce_usecs) {
1152 "rx_usecs(%u) rounded down to %u, because it must be multiple of 2.\n",
1153 cmd->rx_coalesce_usecs, rx_gl);
1156 tx_gl = hns3_gl_round_down(cmd->tx_coalesce_usecs);
1157 if (tx_gl != cmd->tx_coalesce_usecs) {
1159 "tx_usecs(%u) rounded down to %u, because it must be multiple of 2.\n",
1160 cmd->tx_coalesce_usecs, tx_gl);
1166 static int hns3_check_rl_coalesce_para(struct net_device *netdev,
1167 struct ethtool_coalesce *cmd)
1171 if (cmd->tx_coalesce_usecs_high != cmd->rx_coalesce_usecs_high) {
1173 "tx_usecs_high must be same as rx_usecs_high.\n");
1177 if (cmd->rx_coalesce_usecs_high > HNS3_INT_RL_MAX) {
1179 "Invalid usecs_high value, usecs_high range is 0-%d\n",
1184 rl = hns3_rl_round_down(cmd->rx_coalesce_usecs_high);
1185 if (rl != cmd->rx_coalesce_usecs_high) {
1187 "usecs_high(%u) rounded down to %u, because it must be multiple of 4.\n",
1188 cmd->rx_coalesce_usecs_high, rl);
1194 static int hns3_check_coalesce_para(struct net_device *netdev,
1195 struct ethtool_coalesce *cmd)
1199 ret = hns3_check_gl_coalesce_para(netdev, cmd);
1202 "Check gl coalesce param fail. ret = %d\n", ret);
1206 ret = hns3_check_rl_coalesce_para(netdev, cmd);
1209 "Check rl coalesce param fail. ret = %d\n", ret);
1213 if (cmd->use_adaptive_tx_coalesce == 1 ||
1214 cmd->use_adaptive_rx_coalesce == 1) {
1216 "adaptive-tx=%u and adaptive-rx=%u, tx_usecs or rx_usecs will changed dynamically.\n",
1217 cmd->use_adaptive_tx_coalesce,
1218 cmd->use_adaptive_rx_coalesce);
1224 static void hns3_set_coalesce_per_queue(struct net_device *netdev,
1225 struct ethtool_coalesce *cmd,
1228 struct hns3_enet_tqp_vector *tx_vector, *rx_vector;
1229 struct hns3_nic_priv *priv = netdev_priv(netdev);
1230 struct hnae3_handle *h = priv->ae_handle;
1231 int queue_num = h->kinfo.num_tqps;
1233 tx_vector = priv->ring[queue].tqp_vector;
1234 rx_vector = priv->ring[queue_num + queue].tqp_vector;
1236 tx_vector->tx_group.coal.gl_adapt_enable =
1237 cmd->use_adaptive_tx_coalesce;
1238 rx_vector->rx_group.coal.gl_adapt_enable =
1239 cmd->use_adaptive_rx_coalesce;
1241 tx_vector->tx_group.coal.int_gl = cmd->tx_coalesce_usecs;
1242 rx_vector->rx_group.coal.int_gl = cmd->rx_coalesce_usecs;
1244 hns3_set_vector_coalesce_tx_gl(tx_vector,
1245 tx_vector->tx_group.coal.int_gl);
1246 hns3_set_vector_coalesce_rx_gl(rx_vector,
1247 rx_vector->rx_group.coal.int_gl);
1249 hns3_set_vector_coalesce_rl(tx_vector, h->kinfo.int_rl_setting);
1250 hns3_set_vector_coalesce_rl(rx_vector, h->kinfo.int_rl_setting);
1253 static int hns3_set_coalesce(struct net_device *netdev,
1254 struct ethtool_coalesce *cmd)
1256 struct hnae3_handle *h = hns3_get_handle(netdev);
1257 u16 queue_num = h->kinfo.num_tqps;
1261 if (hns3_nic_resetting(netdev))
1264 ret = hns3_check_coalesce_para(netdev, cmd);
1268 h->kinfo.int_rl_setting =
1269 hns3_rl_round_down(cmd->rx_coalesce_usecs_high);
1271 for (i = 0; i < queue_num; i++)
1272 hns3_set_coalesce_per_queue(netdev, cmd, i);
1277 static int hns3_get_regs_len(struct net_device *netdev)
1279 struct hnae3_handle *h = hns3_get_handle(netdev);
1281 if (!h->ae_algo->ops->get_regs_len)
1284 return h->ae_algo->ops->get_regs_len(h);
1287 static void hns3_get_regs(struct net_device *netdev,
1288 struct ethtool_regs *cmd, void *data)
1290 struct hnae3_handle *h = hns3_get_handle(netdev);
1292 if (!h->ae_algo->ops->get_regs)
1295 h->ae_algo->ops->get_regs(h, &cmd->version, data);
1298 static int hns3_set_phys_id(struct net_device *netdev,
1299 enum ethtool_phys_id_state state)
1301 struct hnae3_handle *h = hns3_get_handle(netdev);
1303 if (!h->ae_algo->ops->set_led_id)
1306 return h->ae_algo->ops->set_led_id(h, state);
1309 static u32 hns3_get_msglevel(struct net_device *netdev)
1311 struct hnae3_handle *h = hns3_get_handle(netdev);
1313 return h->msg_enable;
1316 static void hns3_set_msglevel(struct net_device *netdev, u32 msg_level)
1318 struct hnae3_handle *h = hns3_get_handle(netdev);
1320 h->msg_enable = msg_level;
1323 /* Translate local fec value into ethtool value. */
1324 static unsigned int loc_to_eth_fec(u8 loc_fec)
1328 if (loc_fec & BIT(HNAE3_FEC_AUTO))
1329 eth_fec |= ETHTOOL_FEC_AUTO;
1330 if (loc_fec & BIT(HNAE3_FEC_RS))
1331 eth_fec |= ETHTOOL_FEC_RS;
1332 if (loc_fec & BIT(HNAE3_FEC_BASER))
1333 eth_fec |= ETHTOOL_FEC_BASER;
1335 /* if nothing is set, then FEC is off */
1337 eth_fec = ETHTOOL_FEC_OFF;
1342 /* Translate ethtool fec value into local value. */
1343 static unsigned int eth_to_loc_fec(unsigned int eth_fec)
1347 if (eth_fec & ETHTOOL_FEC_OFF)
1350 if (eth_fec & ETHTOOL_FEC_AUTO)
1351 loc_fec |= BIT(HNAE3_FEC_AUTO);
1352 if (eth_fec & ETHTOOL_FEC_RS)
1353 loc_fec |= BIT(HNAE3_FEC_RS);
1354 if (eth_fec & ETHTOOL_FEC_BASER)
1355 loc_fec |= BIT(HNAE3_FEC_BASER);
1360 static int hns3_get_fecparam(struct net_device *netdev,
1361 struct ethtool_fecparam *fec)
1363 struct hnae3_handle *handle = hns3_get_handle(netdev);
1364 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1368 if (handle->pdev->revision == 0x20)
1374 ops->get_fec(handle, &fec_ability, &fec_mode);
1376 fec->fec = loc_to_eth_fec(fec_ability);
1377 fec->active_fec = loc_to_eth_fec(fec_mode);
1382 static int hns3_set_fecparam(struct net_device *netdev,
1383 struct ethtool_fecparam *fec)
1385 struct hnae3_handle *handle = hns3_get_handle(netdev);
1386 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1389 if (handle->pdev->revision == 0x20)
1394 fec_mode = eth_to_loc_fec(fec->fec);
1396 netif_dbg(handle, drv, netdev, "set fecparam: mode=%u\n", fec_mode);
1398 return ops->set_fec(handle, fec_mode);
1401 static int hns3_get_module_info(struct net_device *netdev,
1402 struct ethtool_modinfo *modinfo)
1404 #define HNS3_SFF_8636_V1_3 0x03
1406 struct hnae3_handle *handle = hns3_get_handle(netdev);
1407 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1408 struct hns3_sfp_type sfp_type;
1411 if (handle->pdev->revision == 0x20 || !ops->get_module_eeprom)
1414 memset(&sfp_type, 0, sizeof(sfp_type));
1415 ret = ops->get_module_eeprom(handle, 0, sizeof(sfp_type) / sizeof(u8),
1420 switch (sfp_type.type) {
1421 case SFF8024_ID_SFP:
1422 modinfo->type = ETH_MODULE_SFF_8472;
1423 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1425 case SFF8024_ID_QSFP_8438:
1426 modinfo->type = ETH_MODULE_SFF_8436;
1427 modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
1429 case SFF8024_ID_QSFP_8436_8636:
1430 if (sfp_type.ext_type < HNS3_SFF_8636_V1_3) {
1431 modinfo->type = ETH_MODULE_SFF_8436;
1432 modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
1434 modinfo->type = ETH_MODULE_SFF_8636;
1435 modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
1438 case SFF8024_ID_QSFP28_8636:
1439 modinfo->type = ETH_MODULE_SFF_8636;
1440 modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
1443 netdev_err(netdev, "Optical module unknown: %#x\n",
1451 static int hns3_get_module_eeprom(struct net_device *netdev,
1452 struct ethtool_eeprom *ee, u8 *data)
1454 struct hnae3_handle *handle = hns3_get_handle(netdev);
1455 const struct hnae3_ae_ops *ops = handle->ae_algo->ops;
1457 if (handle->pdev->revision == 0x20 || !ops->get_module_eeprom)
1463 memset(data, 0, ee->len);
1465 return ops->get_module_eeprom(handle, ee->offset, ee->len, data);
1468 #define HNS3_ETHTOOL_COALESCE (ETHTOOL_COALESCE_USECS | \
1469 ETHTOOL_COALESCE_USE_ADAPTIVE | \
1470 ETHTOOL_COALESCE_RX_USECS_HIGH | \
1471 ETHTOOL_COALESCE_TX_USECS_HIGH)
1473 static const struct ethtool_ops hns3vf_ethtool_ops = {
1474 .supported_coalesce_params = HNS3_ETHTOOL_COALESCE,
1475 .get_drvinfo = hns3_get_drvinfo,
1476 .get_ringparam = hns3_get_ringparam,
1477 .set_ringparam = hns3_set_ringparam,
1478 .get_strings = hns3_get_strings,
1479 .get_ethtool_stats = hns3_get_stats,
1480 .get_sset_count = hns3_get_sset_count,
1481 .get_rxnfc = hns3_get_rxnfc,
1482 .set_rxnfc = hns3_set_rxnfc,
1483 .get_rxfh_key_size = hns3_get_rss_key_size,
1484 .get_rxfh_indir_size = hns3_get_rss_indir_size,
1485 .get_rxfh = hns3_get_rss,
1486 .set_rxfh = hns3_set_rss,
1487 .get_link_ksettings = hns3_get_link_ksettings,
1488 .get_channels = hns3_get_channels,
1489 .set_channels = hns3_set_channels,
1490 .get_coalesce = hns3_get_coalesce,
1491 .set_coalesce = hns3_set_coalesce,
1492 .get_regs_len = hns3_get_regs_len,
1493 .get_regs = hns3_get_regs,
1494 .get_link = hns3_get_link,
1495 .get_msglevel = hns3_get_msglevel,
1496 .set_msglevel = hns3_set_msglevel,
1499 static const struct ethtool_ops hns3_ethtool_ops = {
1500 .supported_coalesce_params = HNS3_ETHTOOL_COALESCE,
1501 .self_test = hns3_self_test,
1502 .get_drvinfo = hns3_get_drvinfo,
1503 .get_link = hns3_get_link,
1504 .get_ringparam = hns3_get_ringparam,
1505 .set_ringparam = hns3_set_ringparam,
1506 .get_pauseparam = hns3_get_pauseparam,
1507 .set_pauseparam = hns3_set_pauseparam,
1508 .get_strings = hns3_get_strings,
1509 .get_ethtool_stats = hns3_get_stats,
1510 .get_sset_count = hns3_get_sset_count,
1511 .get_rxnfc = hns3_get_rxnfc,
1512 .set_rxnfc = hns3_set_rxnfc,
1513 .get_rxfh_key_size = hns3_get_rss_key_size,
1514 .get_rxfh_indir_size = hns3_get_rss_indir_size,
1515 .get_rxfh = hns3_get_rss,
1516 .set_rxfh = hns3_set_rss,
1517 .get_link_ksettings = hns3_get_link_ksettings,
1518 .set_link_ksettings = hns3_set_link_ksettings,
1519 .nway_reset = hns3_nway_reset,
1520 .get_channels = hns3_get_channels,
1521 .set_channels = hns3_set_channels,
1522 .get_coalesce = hns3_get_coalesce,
1523 .set_coalesce = hns3_set_coalesce,
1524 .get_regs_len = hns3_get_regs_len,
1525 .get_regs = hns3_get_regs,
1526 .set_phys_id = hns3_set_phys_id,
1527 .get_msglevel = hns3_get_msglevel,
1528 .set_msglevel = hns3_set_msglevel,
1529 .get_fecparam = hns3_get_fecparam,
1530 .set_fecparam = hns3_set_fecparam,
1531 .get_module_info = hns3_get_module_info,
1532 .get_module_eeprom = hns3_get_module_eeprom,
1535 void hns3_ethtool_set_ops(struct net_device *netdev)
1537 struct hnae3_handle *h = hns3_get_handle(netdev);
1539 if (h->flags & HNAE3_SUPPORT_VF)
1540 netdev->ethtool_ops = &hns3vf_ethtool_ops;
1542 netdev->ethtool_ops = &hns3_ethtool_ops;