GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / net / ethernet / hisilicon / hns / hns_ethtool.c
1 /*
2  * Copyright (c) 2014-2015 Hisilicon Limited.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  */
9
10 #include <linux/etherdevice.h>
11 #include <linux/interrupt.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include "hns_enet.h"
15
16 #define HNS_PHY_PAGE_MDIX       0
17 #define HNS_PHY_PAGE_LED        3
18 #define HNS_PHY_PAGE_COPPER     0
19
20 #define HNS_PHY_PAGE_REG        22      /* Page Selection Reg. */
21 #define HNS_PHY_CSC_REG         16      /* Copper Specific Control Register */
22 #define HNS_PHY_CSS_REG         17      /* Copper Specific Status Register */
23 #define HNS_LED_FC_REG          16      /* LED Function Control Reg. */
24 #define HNS_LED_PC_REG          17      /* LED Polarity Control Reg. */
25
26 #define HNS_LED_FORCE_ON        9
27 #define HNS_LED_FORCE_OFF       8
28
29 #define HNS_CHIP_VERSION 660
30 #define HNS_NET_STATS_CNT 26
31
32 #define PHY_MDIX_CTRL_S         (5)
33 #define PHY_MDIX_CTRL_M         (3 << PHY_MDIX_CTRL_S)
34
35 #define PHY_MDIX_STATUS_B       (6)
36 #define PHY_SPEED_DUP_RESOLVE_B (11)
37
38 /**
39  *hns_nic_get_link - get current link status
40  *@net_dev: net_device
41  *retuen 0 - success , negative --fail
42  */
43 static u32 hns_nic_get_link(struct net_device *net_dev)
44 {
45         struct hns_nic_priv *priv = netdev_priv(net_dev);
46         u32 link_stat = priv->link;
47         struct hnae_handle *h;
48
49         h = priv->ae_handle;
50
51         if (net_dev->phydev) {
52                 if (!genphy_read_status(net_dev->phydev))
53                         link_stat = net_dev->phydev->link;
54                 else
55                         link_stat = 0;
56         }
57
58         if (h->dev && h->dev->ops && h->dev->ops->get_status)
59                 link_stat = link_stat && h->dev->ops->get_status(h);
60         else
61                 link_stat = 0;
62
63         return link_stat;
64 }
65
66 static void hns_get_mdix_mode(struct net_device *net_dev,
67                               struct ethtool_link_ksettings *cmd)
68 {
69         int mdix_ctrl, mdix, retval, is_resolved;
70         struct phy_device *phy_dev = net_dev->phydev;
71
72         if (!phy_dev || !phy_dev->mdio.bus) {
73                 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_INVALID;
74                 cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID;
75                 return;
76         }
77
78         phy_write(phy_dev, HNS_PHY_PAGE_REG, HNS_PHY_PAGE_MDIX);
79
80         retval = phy_read(phy_dev, HNS_PHY_CSC_REG);
81         mdix_ctrl = hnae_get_field(retval, PHY_MDIX_CTRL_M, PHY_MDIX_CTRL_S);
82
83         retval = phy_read(phy_dev, HNS_PHY_CSS_REG);
84         mdix = hnae_get_bit(retval, PHY_MDIX_STATUS_B);
85         is_resolved = hnae_get_bit(retval, PHY_SPEED_DUP_RESOLVE_B);
86
87         phy_write(phy_dev, HNS_PHY_PAGE_REG, HNS_PHY_PAGE_COPPER);
88
89         switch (mdix_ctrl) {
90         case 0x0:
91                 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI;
92                 break;
93         case 0x1:
94                 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_X;
95                 break;
96         case 0x3:
97                 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_AUTO;
98                 break;
99         default:
100                 cmd->base.eth_tp_mdix_ctrl = ETH_TP_MDI_INVALID;
101                 break;
102         }
103
104         if (!is_resolved)
105                 cmd->base.eth_tp_mdix = ETH_TP_MDI_INVALID;
106         else if (mdix)
107                 cmd->base.eth_tp_mdix = ETH_TP_MDI_X;
108         else
109                 cmd->base.eth_tp_mdix = ETH_TP_MDI;
110 }
111
112 /**
113  *hns_nic_get_link_ksettings - implement ethtool get link ksettings
114  *@net_dev: net_device
115  *@cmd: ethtool_link_ksettings
116  *retuen 0 - success , negative --fail
117  */
118 static int hns_nic_get_link_ksettings(struct net_device *net_dev,
119                                       struct ethtool_link_ksettings *cmd)
120 {
121         struct hns_nic_priv *priv = netdev_priv(net_dev);
122         struct hnae_handle *h;
123         u32 link_stat;
124         int ret;
125         u8 duplex;
126         u16 speed;
127         u32 supported, advertising;
128
129         if (!priv || !priv->ae_handle)
130                 return -ESRCH;
131
132         h = priv->ae_handle;
133         if (!h->dev || !h->dev->ops || !h->dev->ops->get_info)
134                 return -ESRCH;
135
136         ret = h->dev->ops->get_info(h, NULL, &speed, &duplex);
137         if (ret < 0) {
138                 netdev_err(net_dev, "%s get_info error!\n", __func__);
139                 return -EINVAL;
140         }
141
142         ethtool_convert_link_mode_to_legacy_u32(&supported,
143                                                 cmd->link_modes.supported);
144         ethtool_convert_link_mode_to_legacy_u32(&advertising,
145                                                 cmd->link_modes.advertising);
146
147         /* When there is no phy, autoneg is off. */
148         cmd->base.autoneg = false;
149         cmd->base.speed = speed;
150         cmd->base.duplex = duplex;
151
152         if (net_dev->phydev)
153                 phy_ethtool_ksettings_get(net_dev->phydev, cmd);
154
155         link_stat = hns_nic_get_link(net_dev);
156         if (!link_stat) {
157                 cmd->base.speed = (u32)SPEED_UNKNOWN;
158                 cmd->base.duplex = DUPLEX_UNKNOWN;
159         }
160
161         if (cmd->base.autoneg)
162                 advertising |= ADVERTISED_Autoneg;
163
164         supported |= h->if_support;
165         if (h->phy_if == PHY_INTERFACE_MODE_SGMII) {
166                 supported |= SUPPORTED_TP;
167                 advertising |= ADVERTISED_1000baseT_Full;
168         } else if (h->phy_if == PHY_INTERFACE_MODE_XGMII) {
169                 supported |= SUPPORTED_FIBRE;
170                 advertising |= ADVERTISED_10000baseKR_Full;
171         }
172
173         switch (h->media_type) {
174         case HNAE_MEDIA_TYPE_FIBER:
175                 cmd->base.port = PORT_FIBRE;
176                 break;
177         case HNAE_MEDIA_TYPE_COPPER:
178                 cmd->base.port = PORT_TP;
179                 break;
180         case HNAE_MEDIA_TYPE_UNKNOWN:
181         default:
182                 break;
183         }
184
185         if (!(AE_IS_VER1(priv->enet_ver) && h->port_type == HNAE_PORT_DEBUG))
186                 supported |= SUPPORTED_Pause;
187
188         ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported,
189                                                 supported);
190         ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising,
191                                                 advertising);
192
193         cmd->base.mdio_support = ETH_MDIO_SUPPORTS_C45 | ETH_MDIO_SUPPORTS_C22;
194         hns_get_mdix_mode(net_dev, cmd);
195
196         return 0;
197 }
198
199 /**
200  *hns_nic_set_link_settings - implement ethtool set link ksettings
201  *@net_dev: net_device
202  *@cmd: ethtool_link_ksettings
203  *retuen 0 - success , negative --fail
204  */
205 static int hns_nic_set_link_ksettings(struct net_device *net_dev,
206                                       const struct ethtool_link_ksettings *cmd)
207 {
208         struct hns_nic_priv *priv = netdev_priv(net_dev);
209         struct hnae_handle *h;
210         u32 speed;
211
212         if (!netif_running(net_dev))
213                 return -ESRCH;
214
215         if (!priv || !priv->ae_handle || !priv->ae_handle->dev ||
216             !priv->ae_handle->dev->ops)
217                 return -ENODEV;
218
219         h = priv->ae_handle;
220         speed = cmd->base.speed;
221
222         if (h->phy_if == PHY_INTERFACE_MODE_XGMII) {
223                 if (cmd->base.autoneg == AUTONEG_ENABLE ||
224                     speed != SPEED_10000 ||
225                     cmd->base.duplex != DUPLEX_FULL)
226                         return -EINVAL;
227         } else if (h->phy_if == PHY_INTERFACE_MODE_SGMII) {
228                 if (!net_dev->phydev && cmd->base.autoneg == AUTONEG_ENABLE)
229                         return -EINVAL;
230
231                 if (speed == SPEED_1000 && cmd->base.duplex == DUPLEX_HALF)
232                         return -EINVAL;
233                 if (net_dev->phydev)
234                         return phy_ethtool_ksettings_set(net_dev->phydev, cmd);
235
236                 if ((speed != SPEED_10 && speed != SPEED_100 &&
237                      speed != SPEED_1000) || (cmd->base.duplex != DUPLEX_HALF &&
238                      cmd->base.duplex != DUPLEX_FULL))
239                         return -EINVAL;
240         } else {
241                 netdev_err(net_dev, "Not supported!");
242                 return -ENOTSUPP;
243         }
244
245         if (h->dev->ops->adjust_link) {
246                 netif_carrier_off(net_dev);
247                 h->dev->ops->adjust_link(h, (int)speed, cmd->base.duplex);
248                 netif_carrier_on(net_dev);
249                 return 0;
250         }
251
252         netdev_err(net_dev, "Not supported!");
253         return -ENOTSUPP;
254 }
255
256 static const char hns_nic_test_strs[][ETH_GSTRING_LEN] = {
257         "Mac    Loopback test",
258         "Serdes Loopback test",
259         "Phy    Loopback test"
260 };
261
262 static int hns_nic_config_phy_loopback(struct phy_device *phy_dev, u8 en)
263 {
264         int err;
265
266         if (en) {
267                 /* Doing phy loopback in offline state, phy resuming is
268                  * needed to power up the device.
269                  */
270                 err = phy_resume(phy_dev);
271                 if (err)
272                         goto out;
273
274                 err = phy_loopback(phy_dev, true);
275         } else {
276                 err = phy_loopback(phy_dev, false);
277                 if (err)
278                         goto out;
279
280                 err = phy_suspend(phy_dev);
281         }
282
283 out:
284         return err;
285 }
286
287 static int __lb_setup(struct net_device *ndev,
288                       enum hnae_loop loop)
289 {
290         int ret = 0;
291         struct hns_nic_priv *priv = netdev_priv(ndev);
292         struct phy_device *phy_dev = ndev->phydev;
293         struct hnae_handle *h = priv->ae_handle;
294
295         switch (loop) {
296         case MAC_INTERNALLOOP_PHY:
297                 ret = hns_nic_config_phy_loopback(phy_dev, 0x1);
298                 if (!ret)
299                         ret = h->dev->ops->set_loopback(h, loop, 0x1);
300                 break;
301         case MAC_INTERNALLOOP_MAC:
302                 if ((h->dev->ops->set_loopback) &&
303                     (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII))
304                         ret = h->dev->ops->set_loopback(h, loop, 0x1);
305                 break;
306         case MAC_INTERNALLOOP_SERDES:
307                 if (h->dev->ops->set_loopback)
308                         ret = h->dev->ops->set_loopback(h, loop, 0x1);
309                 break;
310         case MAC_LOOP_PHY_NONE:
311                 ret = hns_nic_config_phy_loopback(phy_dev, 0x0);
312         case MAC_LOOP_NONE:
313                 if (!ret && h->dev->ops->set_loopback) {
314                         if (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII)
315                                 ret = h->dev->ops->set_loopback(h,
316                                         MAC_INTERNALLOOP_MAC, 0x0);
317
318                         if (!ret)
319                                 ret = h->dev->ops->set_loopback(h,
320                                         MAC_INTERNALLOOP_SERDES, 0x0);
321                 }
322                 break;
323         default:
324                 ret = -EINVAL;
325                 break;
326         }
327
328         if (!ret) {
329                 if (loop == MAC_LOOP_NONE)
330                         h->dev->ops->set_promisc_mode(
331                                 h, ndev->flags & IFF_PROMISC);
332                 else
333                         h->dev->ops->set_promisc_mode(h, 1);
334         }
335         return ret;
336 }
337
338 static int __lb_up(struct net_device *ndev,
339                    enum hnae_loop loop_mode)
340 {
341 #define NIC_LB_TEST_WAIT_PHY_LINK_TIME 300
342         struct hns_nic_priv *priv = netdev_priv(ndev);
343         struct hnae_handle *h = priv->ae_handle;
344         int speed, duplex;
345         int ret;
346
347         hns_nic_net_reset(ndev);
348
349         ret = __lb_setup(ndev, loop_mode);
350         if (ret)
351                 return ret;
352
353         msleep(200);
354
355         ret = h->dev->ops->start ? h->dev->ops->start(h) : 0;
356         if (ret)
357                 return ret;
358
359         /* link adjust duplex*/
360         if (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII)
361                 speed = 1000;
362         else
363                 speed = 10000;
364         duplex = 1;
365
366         h->dev->ops->adjust_link(h, speed, duplex);
367
368         /* wait adjust link done and phy ready */
369         msleep(NIC_LB_TEST_WAIT_PHY_LINK_TIME);
370
371         return 0;
372 }
373
374 static void __lb_other_process(struct hns_nic_ring_data *ring_data,
375                                struct sk_buff *skb)
376 {
377         struct net_device *ndev;
378         struct hns_nic_priv *priv;
379         struct hnae_ring *ring;
380         struct netdev_queue *dev_queue;
381         struct sk_buff *new_skb;
382         unsigned int frame_size;
383         int check_ok;
384         u32 i;
385         char buff[33]; /* 32B data and the last character '\0' */
386
387         if (!ring_data) { /* Just for doing create frame*/
388                 ndev = skb->dev;
389                 priv = netdev_priv(ndev);
390
391                 frame_size = skb->len;
392                 memset(skb->data, 0xFF, frame_size);
393                 if ((!AE_IS_VER1(priv->enet_ver)) &&
394                     (priv->ae_handle->port_type == HNAE_PORT_SERVICE)) {
395                         memcpy(skb->data, ndev->dev_addr, 6);
396                         skb->data[5] += 0x1f;
397                 }
398
399                 frame_size &= ~1ul;
400                 memset(&skb->data[frame_size / 2], 0xAA, frame_size / 2 - 1);
401                 memset(&skb->data[frame_size / 2 + 10], 0xBE,
402                        frame_size / 2 - 11);
403                 memset(&skb->data[frame_size / 2 + 12], 0xAF,
404                        frame_size / 2 - 13);
405                 return;
406         }
407
408         ring = ring_data->ring;
409         ndev = ring_data->napi.dev;
410         if (is_tx_ring(ring)) { /* for tx queue reset*/
411                 dev_queue = netdev_get_tx_queue(ndev, ring_data->queue_index);
412                 netdev_tx_reset_queue(dev_queue);
413                 return;
414         }
415
416         frame_size = skb->len;
417         frame_size &= ~1ul;
418         /* for mutl buffer*/
419         new_skb = skb_copy(skb, GFP_ATOMIC);
420         dev_kfree_skb_any(skb);
421         if (!new_skb) {
422                 netdev_err(ndev, "skb alloc failed\n");
423                 return;
424         }
425         skb = new_skb;
426
427         check_ok = 0;
428         if (*(skb->data + 10) == 0xFF) { /* for rx check frame*/
429                 if ((*(skb->data + frame_size / 2 + 10) == 0xBE) &&
430                     (*(skb->data + frame_size / 2 + 12) == 0xAF))
431                         check_ok = 1;
432         }
433
434         if (check_ok) {
435                 ndev->stats.rx_packets++;
436                 ndev->stats.rx_bytes += skb->len;
437         } else {
438                 ndev->stats.rx_frame_errors++;
439                 for (i = 0; i < skb->len; i++) {
440                         snprintf(buff + i % 16 * 2, 3, /* tailing \0*/
441                                  "%02x", *(skb->data + i));
442                         if ((i % 16 == 15) || (i == skb->len - 1))
443                                 pr_info("%s\n", buff);
444                 }
445         }
446         dev_kfree_skb_any(skb);
447 }
448
449 static int __lb_clean_rings(struct hns_nic_priv *priv,
450                             int ringid0, int ringid1, int budget)
451 {
452         int i, ret;
453         struct hns_nic_ring_data *ring_data;
454         struct net_device *ndev = priv->netdev;
455         unsigned long rx_packets = ndev->stats.rx_packets;
456         unsigned long rx_bytes = ndev->stats.rx_bytes;
457         unsigned long rx_frame_errors = ndev->stats.rx_frame_errors;
458
459         for (i = ringid0; i <= ringid1; i++) {
460                 ring_data = &priv->ring_data[i];
461                 (void)ring_data->poll_one(ring_data,
462                                           budget, __lb_other_process);
463         }
464         ret = (int)(ndev->stats.rx_packets - rx_packets);
465         ndev->stats.rx_packets = rx_packets;
466         ndev->stats.rx_bytes = rx_bytes;
467         ndev->stats.rx_frame_errors = rx_frame_errors;
468         return ret;
469 }
470
471 /**
472  * nic_run_loopback_test -  run loopback test
473  * @nic_dev: net device
474  * @loopback_type: loopback type
475  */
476 static int __lb_run_test(struct net_device *ndev,
477                          enum hnae_loop loop_mode)
478 {
479 #define NIC_LB_TEST_PKT_NUM_PER_CYCLE 1
480 #define NIC_LB_TEST_RING_ID 0
481 #define NIC_LB_TEST_FRAME_SIZE 128
482 /* nic loopback test err  */
483 #define NIC_LB_TEST_NO_MEM_ERR 1
484 #define NIC_LB_TEST_TX_CNT_ERR 2
485 #define NIC_LB_TEST_RX_CNT_ERR 3
486 #define NIC_LB_TEST_RX_PKG_ERR 4
487         struct hns_nic_priv *priv = netdev_priv(ndev);
488         struct hnae_handle *h = priv->ae_handle;
489         int i, j, lc, good_cnt, ret_val = 0;
490         unsigned int size;
491         netdev_tx_t tx_ret_val;
492         struct sk_buff *skb;
493
494         size = NIC_LB_TEST_FRAME_SIZE;
495         /* allocate test skb */
496         skb = alloc_skb(size, GFP_KERNEL);
497         if (!skb)
498                 return NIC_LB_TEST_NO_MEM_ERR;
499
500         /* place data into test skb */
501         (void)skb_put(skb, size);
502         skb->dev = ndev;
503         __lb_other_process(NULL, skb);
504         skb->queue_mapping = NIC_LB_TEST_RING_ID;
505
506         lc = 1;
507         for (j = 0; j < lc; j++) {
508                 /* reset count of good packets */
509                 good_cnt = 0;
510                 /* place 64 packets on the transmit queue*/
511                 for (i = 0; i < NIC_LB_TEST_PKT_NUM_PER_CYCLE; i++) {
512                         (void)skb_get(skb);
513
514                         tx_ret_val = (netdev_tx_t)hns_nic_net_xmit_hw(
515                                 ndev, skb,
516                                 &tx_ring_data(priv, skb->queue_mapping));
517                         if (tx_ret_val == NETDEV_TX_OK)
518                                 good_cnt++;
519                         else
520                                 break;
521                 }
522                 if (good_cnt != NIC_LB_TEST_PKT_NUM_PER_CYCLE) {
523                         ret_val = NIC_LB_TEST_TX_CNT_ERR;
524                         dev_err(priv->dev, "%s sent fail, cnt=0x%x, budget=0x%x\n",
525                                 hns_nic_test_strs[loop_mode], good_cnt,
526                                 NIC_LB_TEST_PKT_NUM_PER_CYCLE);
527                         break;
528                 }
529
530                 /* allow 100 milliseconds for packets to go from Tx to Rx */
531                 msleep(100);
532
533                 good_cnt = __lb_clean_rings(priv,
534                                             h->q_num, h->q_num * 2 - 1,
535                                             NIC_LB_TEST_PKT_NUM_PER_CYCLE);
536                 if (good_cnt != NIC_LB_TEST_PKT_NUM_PER_CYCLE) {
537                         ret_val = NIC_LB_TEST_RX_CNT_ERR;
538                         dev_err(priv->dev, "%s recv fail, cnt=0x%x, budget=0x%x\n",
539                                 hns_nic_test_strs[loop_mode], good_cnt,
540                                 NIC_LB_TEST_PKT_NUM_PER_CYCLE);
541                         break;
542                 }
543                 (void)__lb_clean_rings(priv,
544                                        NIC_LB_TEST_RING_ID, NIC_LB_TEST_RING_ID,
545                                        NIC_LB_TEST_PKT_NUM_PER_CYCLE);
546         }
547
548         /* free the original skb */
549         kfree_skb(skb);
550
551         return ret_val;
552 }
553
554 static int __lb_down(struct net_device *ndev, enum hnae_loop loop)
555 {
556         struct hns_nic_priv *priv = netdev_priv(ndev);
557         struct hnae_handle *h = priv->ae_handle;
558         int ret;
559
560         if (loop == MAC_INTERNALLOOP_PHY)
561                 ret = __lb_setup(ndev, MAC_LOOP_PHY_NONE);
562         else
563                 ret = __lb_setup(ndev, MAC_LOOP_NONE);
564         if (ret)
565                 netdev_err(ndev, "%s: __lb_setup return error(%d)!\n",
566                            __func__,
567                            ret);
568
569         if (h->dev->ops->stop)
570                 h->dev->ops->stop(h);
571
572         usleep_range(10000, 20000);
573         (void)__lb_clean_rings(priv, 0, h->q_num - 1, 256);
574
575         hns_nic_net_reset(ndev);
576
577         return 0;
578 }
579
580 /**
581  * hns_nic_self_test - self test
582  * @dev: net device
583  * @eth_test: test cmd
584  * @data: test result
585  */
586 static void hns_nic_self_test(struct net_device *ndev,
587                               struct ethtool_test *eth_test, u64 *data)
588 {
589         struct hns_nic_priv *priv = netdev_priv(ndev);
590         bool if_running = netif_running(ndev);
591 #define SELF_TEST_TPYE_NUM 3
592         int st_param[SELF_TEST_TPYE_NUM][2];
593         int i;
594         int test_index = 0;
595
596         st_param[0][0] = MAC_INTERNALLOOP_MAC; /* XGE not supported lb */
597         st_param[0][1] = (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII);
598         st_param[1][0] = MAC_INTERNALLOOP_SERDES;
599         st_param[1][1] = 1; /*serdes must exist*/
600         st_param[2][0] = MAC_INTERNALLOOP_PHY; /* only supporte phy node*/
601         st_param[2][1] = ((!!(priv->ae_handle->phy_dev)) &&
602                 (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII));
603
604         if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
605                 set_bit(NIC_STATE_TESTING, &priv->state);
606
607                 if (if_running)
608                         dev_close(ndev);
609
610                 for (i = 0; i < SELF_TEST_TPYE_NUM; i++) {
611                         if (!st_param[i][1])
612                                 continue;       /* NEXT testing */
613
614                         data[test_index] = __lb_up(ndev,
615                                 (enum hnae_loop)st_param[i][0]);
616                         if (!data[test_index]) {
617                                 data[test_index] = __lb_run_test(
618                                         ndev, (enum hnae_loop)st_param[i][0]);
619                                 (void)__lb_down(ndev,
620                                                 (enum hnae_loop)st_param[i][0]);
621                         }
622
623                         if (data[test_index])
624                                 eth_test->flags |= ETH_TEST_FL_FAILED;
625
626                         test_index++;
627                 }
628
629                 hns_nic_net_reset(priv->netdev);
630
631                 clear_bit(NIC_STATE_TESTING, &priv->state);
632
633                 if (if_running)
634                         (void)dev_open(ndev);
635         }
636         /* Online tests aren't run; pass by default */
637
638         (void)msleep_interruptible(4 * 1000);
639 }
640
641 /**
642  * hns_nic_get_drvinfo - get net driver info
643  * @dev: net device
644  * @drvinfo: driver info
645  */
646 static void hns_nic_get_drvinfo(struct net_device *net_dev,
647                                 struct ethtool_drvinfo *drvinfo)
648 {
649         struct hns_nic_priv *priv = netdev_priv(net_dev);
650
651         strncpy(drvinfo->version, HNAE_DRIVER_VERSION,
652                 sizeof(drvinfo->version));
653         drvinfo->version[sizeof(drvinfo->version) - 1] = '\0';
654
655         strncpy(drvinfo->driver, HNAE_DRIVER_NAME, sizeof(drvinfo->driver));
656         drvinfo->driver[sizeof(drvinfo->driver) - 1] = '\0';
657
658         strncpy(drvinfo->bus_info, priv->dev->bus->name,
659                 sizeof(drvinfo->bus_info));
660         drvinfo->bus_info[ETHTOOL_BUSINFO_LEN - 1] = '\0';
661
662         strncpy(drvinfo->fw_version, "N/A", ETHTOOL_FWVERS_LEN);
663         drvinfo->eedump_len = 0;
664 }
665
666 /**
667  * hns_get_ringparam - get ring parameter
668  * @dev: net device
669  * @param: ethtool parameter
670  */
671 void hns_get_ringparam(struct net_device *net_dev,
672                        struct ethtool_ringparam *param)
673 {
674         struct hns_nic_priv *priv = netdev_priv(net_dev);
675         struct hnae_ae_ops *ops;
676         struct hnae_queue *queue;
677         u32 uplimit = 0;
678
679         queue = priv->ae_handle->qs[0];
680         ops = priv->ae_handle->dev->ops;
681
682         if (ops->get_ring_bdnum_limit)
683                 ops->get_ring_bdnum_limit(queue, &uplimit);
684
685         param->rx_max_pending = uplimit;
686         param->tx_max_pending = uplimit;
687         param->rx_pending = queue->rx_ring.desc_num;
688         param->tx_pending = queue->tx_ring.desc_num;
689 }
690
691 /**
692  * hns_get_pauseparam - get pause parameter
693  * @dev: net device
694  * @param: pause parameter
695  */
696 static void hns_get_pauseparam(struct net_device *net_dev,
697                                struct ethtool_pauseparam *param)
698 {
699         struct hns_nic_priv *priv = netdev_priv(net_dev);
700         struct hnae_ae_ops *ops;
701
702         ops = priv->ae_handle->dev->ops;
703
704         if (ops->get_pauseparam)
705                 ops->get_pauseparam(priv->ae_handle, &param->autoneg,
706                                             &param->rx_pause, &param->tx_pause);
707 }
708
709 /**
710  * hns_set_pauseparam - set pause parameter
711  * @dev: net device
712  * @param: pause parameter
713  *
714  * Return 0 on success, negative on failure
715  */
716 static int hns_set_pauseparam(struct net_device *net_dev,
717                               struct ethtool_pauseparam *param)
718 {
719         struct hns_nic_priv *priv = netdev_priv(net_dev);
720         struct hnae_handle *h;
721         struct hnae_ae_ops *ops;
722
723         h = priv->ae_handle;
724         ops = h->dev->ops;
725
726         if (!ops->set_pauseparam)
727                 return -ESRCH;
728
729         return ops->set_pauseparam(priv->ae_handle, param->autoneg,
730                                    param->rx_pause, param->tx_pause);
731 }
732
733 /**
734  * hns_get_coalesce - get coalesce info.
735  * @dev: net device
736  * @ec: coalesce info.
737  *
738  * Return 0 on success, negative on failure.
739  */
740 static int hns_get_coalesce(struct net_device *net_dev,
741                             struct ethtool_coalesce *ec)
742 {
743         struct hns_nic_priv *priv = netdev_priv(net_dev);
744         struct hnae_ae_ops *ops;
745
746         ops = priv->ae_handle->dev->ops;
747
748         ec->use_adaptive_rx_coalesce = priv->ae_handle->coal_adapt_en;
749         ec->use_adaptive_tx_coalesce = priv->ae_handle->coal_adapt_en;
750
751         if ((!ops->get_coalesce_usecs) ||
752             (!ops->get_max_coalesced_frames))
753                 return -ESRCH;
754
755         ops->get_coalesce_usecs(priv->ae_handle,
756                                         &ec->tx_coalesce_usecs,
757                                         &ec->rx_coalesce_usecs);
758
759         ops->get_max_coalesced_frames(
760                 priv->ae_handle,
761                 &ec->tx_max_coalesced_frames,
762                 &ec->rx_max_coalesced_frames);
763
764         ops->get_coalesce_range(priv->ae_handle,
765                                 &ec->tx_max_coalesced_frames_low,
766                                 &ec->rx_max_coalesced_frames_low,
767                                 &ec->tx_max_coalesced_frames_high,
768                                 &ec->rx_max_coalesced_frames_high,
769                                 &ec->tx_coalesce_usecs_low,
770                                 &ec->rx_coalesce_usecs_low,
771                                 &ec->tx_coalesce_usecs_high,
772                                 &ec->rx_coalesce_usecs_high);
773
774         return 0;
775 }
776
777 /**
778  * hns_set_coalesce - set coalesce info.
779  * @dev: net device
780  * @ec: coalesce info.
781  *
782  * Return 0 on success, negative on failure.
783  */
784 static int hns_set_coalesce(struct net_device *net_dev,
785                             struct ethtool_coalesce *ec)
786 {
787         struct hns_nic_priv *priv = netdev_priv(net_dev);
788         struct hnae_ae_ops *ops;
789         int rc1, rc2;
790
791         ops = priv->ae_handle->dev->ops;
792
793         if (ec->tx_coalesce_usecs != ec->rx_coalesce_usecs)
794                 return -EINVAL;
795
796         if ((!ops->set_coalesce_usecs) ||
797             (!ops->set_coalesce_frames))
798                 return -ESRCH;
799
800         if (ec->use_adaptive_rx_coalesce != priv->ae_handle->coal_adapt_en)
801                 priv->ae_handle->coal_adapt_en = ec->use_adaptive_rx_coalesce;
802
803         rc1 = ops->set_coalesce_usecs(priv->ae_handle,
804                                       ec->rx_coalesce_usecs);
805
806         rc2 = ops->set_coalesce_frames(priv->ae_handle,
807                                        ec->tx_max_coalesced_frames,
808                                        ec->rx_max_coalesced_frames);
809
810         if (rc1 || rc2)
811                 return -EINVAL;
812
813         return 0;
814 }
815
816 /**
817  * hns_get_channels - get channel info.
818  * @dev: net device
819  * @ch: channel info.
820  */
821 void hns_get_channels(struct net_device *net_dev, struct ethtool_channels *ch)
822 {
823         struct hns_nic_priv *priv = netdev_priv(net_dev);
824
825         ch->max_rx = priv->ae_handle->q_num;
826         ch->max_tx = priv->ae_handle->q_num;
827
828         ch->rx_count = priv->ae_handle->q_num;
829         ch->tx_count = priv->ae_handle->q_num;
830 }
831
832 /**
833  * get_ethtool_stats - get detail statistics.
834  * @dev: net device
835  * @stats: statistics info.
836  * @data: statistics data.
837  */
838 void hns_get_ethtool_stats(struct net_device *netdev,
839                            struct ethtool_stats *stats, u64 *data)
840 {
841         u64 *p = data;
842         struct hns_nic_priv *priv = netdev_priv(netdev);
843         struct hnae_handle *h = priv->ae_handle;
844         const struct rtnl_link_stats64 *net_stats;
845         struct rtnl_link_stats64 temp;
846
847         if (!h->dev->ops->get_stats || !h->dev->ops->update_stats) {
848                 netdev_err(netdev, "get_stats or update_stats is null!\n");
849                 return;
850         }
851
852         h->dev->ops->update_stats(h, &netdev->stats);
853
854         net_stats = dev_get_stats(netdev, &temp);
855
856         /* get netdev statistics */
857         p[0] = net_stats->rx_packets;
858         p[1] = net_stats->tx_packets;
859         p[2] = net_stats->rx_bytes;
860         p[3] = net_stats->tx_bytes;
861         p[4] = net_stats->rx_errors;
862         p[5] = net_stats->tx_errors;
863         p[6] = net_stats->rx_dropped;
864         p[7] = net_stats->tx_dropped;
865         p[8] = net_stats->multicast;
866         p[9] = net_stats->collisions;
867         p[10] = net_stats->rx_over_errors;
868         p[11] = net_stats->rx_crc_errors;
869         p[12] = net_stats->rx_frame_errors;
870         p[13] = net_stats->rx_fifo_errors;
871         p[14] = net_stats->rx_missed_errors;
872         p[15] = net_stats->tx_aborted_errors;
873         p[16] = net_stats->tx_carrier_errors;
874         p[17] = net_stats->tx_fifo_errors;
875         p[18] = net_stats->tx_heartbeat_errors;
876         p[19] = net_stats->rx_length_errors;
877         p[20] = net_stats->tx_window_errors;
878         p[21] = net_stats->rx_compressed;
879         p[22] = net_stats->tx_compressed;
880
881         p[23] = netdev->rx_dropped.counter;
882         p[24] = netdev->tx_dropped.counter;
883
884         p[25] = priv->tx_timeout_count;
885
886         /* get driver statistics */
887         h->dev->ops->get_stats(h, &p[26]);
888 }
889
890 /**
891  * get_strings: Return a set of strings that describe the requested objects
892  * @dev: net device
893  * @stats: string set ID.
894  * @data: objects data.
895  */
896 void hns_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
897 {
898         struct hns_nic_priv *priv = netdev_priv(netdev);
899         struct hnae_handle *h = priv->ae_handle;
900         char *buff = (char *)data;
901
902         if (!h->dev->ops->get_strings) {
903                 netdev_err(netdev, "h->dev->ops->get_strings is null!\n");
904                 return;
905         }
906
907         if (stringset == ETH_SS_TEST) {
908                 if (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII) {
909                         memcpy(buff, hns_nic_test_strs[MAC_INTERNALLOOP_MAC],
910                                ETH_GSTRING_LEN);
911                         buff += ETH_GSTRING_LEN;
912                 }
913                 memcpy(buff, hns_nic_test_strs[MAC_INTERNALLOOP_SERDES],
914                        ETH_GSTRING_LEN);
915                 buff += ETH_GSTRING_LEN;
916                 if ((netdev->phydev) && (!netdev->phydev->is_c45))
917                         memcpy(buff, hns_nic_test_strs[MAC_INTERNALLOOP_PHY],
918                                ETH_GSTRING_LEN);
919
920         } else {
921                 snprintf(buff, ETH_GSTRING_LEN, "rx_packets");
922                 buff = buff + ETH_GSTRING_LEN;
923                 snprintf(buff, ETH_GSTRING_LEN, "tx_packets");
924                 buff = buff + ETH_GSTRING_LEN;
925                 snprintf(buff, ETH_GSTRING_LEN, "rx_bytes");
926                 buff = buff + ETH_GSTRING_LEN;
927                 snprintf(buff, ETH_GSTRING_LEN, "tx_bytes");
928                 buff = buff + ETH_GSTRING_LEN;
929                 snprintf(buff, ETH_GSTRING_LEN, "rx_errors");
930                 buff = buff + ETH_GSTRING_LEN;
931                 snprintf(buff, ETH_GSTRING_LEN, "tx_errors");
932                 buff = buff + ETH_GSTRING_LEN;
933                 snprintf(buff, ETH_GSTRING_LEN, "rx_dropped");
934                 buff = buff + ETH_GSTRING_LEN;
935                 snprintf(buff, ETH_GSTRING_LEN, "tx_dropped");
936                 buff = buff + ETH_GSTRING_LEN;
937                 snprintf(buff, ETH_GSTRING_LEN, "multicast");
938                 buff = buff + ETH_GSTRING_LEN;
939                 snprintf(buff, ETH_GSTRING_LEN, "collisions");
940                 buff = buff + ETH_GSTRING_LEN;
941                 snprintf(buff, ETH_GSTRING_LEN, "rx_over_errors");
942                 buff = buff + ETH_GSTRING_LEN;
943                 snprintf(buff, ETH_GSTRING_LEN, "rx_crc_errors");
944                 buff = buff + ETH_GSTRING_LEN;
945                 snprintf(buff, ETH_GSTRING_LEN, "rx_frame_errors");
946                 buff = buff + ETH_GSTRING_LEN;
947                 snprintf(buff, ETH_GSTRING_LEN, "rx_fifo_errors");
948                 buff = buff + ETH_GSTRING_LEN;
949                 snprintf(buff, ETH_GSTRING_LEN, "rx_missed_errors");
950                 buff = buff + ETH_GSTRING_LEN;
951                 snprintf(buff, ETH_GSTRING_LEN, "tx_aborted_errors");
952                 buff = buff + ETH_GSTRING_LEN;
953                 snprintf(buff, ETH_GSTRING_LEN, "tx_carrier_errors");
954                 buff = buff + ETH_GSTRING_LEN;
955                 snprintf(buff, ETH_GSTRING_LEN, "tx_fifo_errors");
956                 buff = buff + ETH_GSTRING_LEN;
957                 snprintf(buff, ETH_GSTRING_LEN, "tx_heartbeat_errors");
958                 buff = buff + ETH_GSTRING_LEN;
959                 snprintf(buff, ETH_GSTRING_LEN, "rx_length_errors");
960                 buff = buff + ETH_GSTRING_LEN;
961                 snprintf(buff, ETH_GSTRING_LEN, "tx_window_errors");
962                 buff = buff + ETH_GSTRING_LEN;
963                 snprintf(buff, ETH_GSTRING_LEN, "rx_compressed");
964                 buff = buff + ETH_GSTRING_LEN;
965                 snprintf(buff, ETH_GSTRING_LEN, "tx_compressed");
966                 buff = buff + ETH_GSTRING_LEN;
967                 snprintf(buff, ETH_GSTRING_LEN, "netdev_rx_dropped");
968                 buff = buff + ETH_GSTRING_LEN;
969                 snprintf(buff, ETH_GSTRING_LEN, "netdev_tx_dropped");
970                 buff = buff + ETH_GSTRING_LEN;
971
972                 snprintf(buff, ETH_GSTRING_LEN, "netdev_tx_timeout");
973                 buff = buff + ETH_GSTRING_LEN;
974
975                 h->dev->ops->get_strings(h, stringset, (u8 *)buff);
976         }
977 }
978
979 /**
980  * nic_get_sset_count - get string set count witch returned by nic_get_strings.
981  * @dev: net device
982  * @stringset: string set index, 0: self test string; 1: statistics string.
983  *
984  * Return string set count.
985  */
986 int hns_get_sset_count(struct net_device *netdev, int stringset)
987 {
988         struct hns_nic_priv *priv = netdev_priv(netdev);
989         struct hnae_handle *h = priv->ae_handle;
990         struct hnae_ae_ops *ops = h->dev->ops;
991
992         if (!ops->get_sset_count) {
993                 netdev_err(netdev, "get_sset_count is null!\n");
994                 return -EOPNOTSUPP;
995         }
996         if (stringset == ETH_SS_TEST) {
997                 u32 cnt = (sizeof(hns_nic_test_strs) / ETH_GSTRING_LEN);
998
999                 if (priv->ae_handle->phy_if == PHY_INTERFACE_MODE_XGMII)
1000                         cnt--;
1001
1002                 if ((!netdev->phydev) || (netdev->phydev->is_c45))
1003                         cnt--;
1004
1005                 return cnt;
1006         } else if (stringset == ETH_SS_STATS) {
1007                 return (HNS_NET_STATS_CNT + ops->get_sset_count(h, stringset));
1008         } else {
1009                 return -EOPNOTSUPP;
1010         }
1011 }
1012
1013 /**
1014  * hns_phy_led_set - set phy LED status.
1015  * @dev: net device
1016  * @value: LED state.
1017  *
1018  * Return 0 on success, negative on failure.
1019  */
1020 int hns_phy_led_set(struct net_device *netdev, int value)
1021 {
1022         int retval;
1023         struct phy_device *phy_dev = netdev->phydev;
1024
1025         retval = phy_write(phy_dev, HNS_PHY_PAGE_REG, HNS_PHY_PAGE_LED);
1026         retval |= phy_write(phy_dev, HNS_LED_FC_REG, value);
1027         retval |= phy_write(phy_dev, HNS_PHY_PAGE_REG, HNS_PHY_PAGE_COPPER);
1028         if (retval) {
1029                 netdev_err(netdev, "mdiobus_write fail !\n");
1030                 return retval;
1031         }
1032         return 0;
1033 }
1034
1035 /**
1036  * nic_set_phys_id - set phy identify LED.
1037  * @dev: net device
1038  * @state: LED state.
1039  *
1040  * Return 0 on success, negative on failure.
1041  */
1042 int hns_set_phys_id(struct net_device *netdev, enum ethtool_phys_id_state state)
1043 {
1044         struct hns_nic_priv *priv = netdev_priv(netdev);
1045         struct hnae_handle *h = priv->ae_handle;
1046         struct phy_device *phy_dev = netdev->phydev;
1047         int ret;
1048
1049         if (phy_dev)
1050                 switch (state) {
1051                 case ETHTOOL_ID_ACTIVE:
1052                         ret = phy_write(phy_dev, HNS_PHY_PAGE_REG,
1053                                         HNS_PHY_PAGE_LED);
1054                         if (ret)
1055                                 return ret;
1056
1057                         priv->phy_led_val = phy_read(phy_dev, HNS_LED_FC_REG);
1058
1059                         ret = phy_write(phy_dev, HNS_PHY_PAGE_REG,
1060                                         HNS_PHY_PAGE_COPPER);
1061                         if (ret)
1062                                 return ret;
1063                         return 2;
1064                 case ETHTOOL_ID_ON:
1065                         ret = hns_phy_led_set(netdev, HNS_LED_FORCE_ON);
1066                         if (ret)
1067                                 return ret;
1068                         break;
1069                 case ETHTOOL_ID_OFF:
1070                         ret = hns_phy_led_set(netdev, HNS_LED_FORCE_OFF);
1071                         if (ret)
1072                                 return ret;
1073                         break;
1074                 case ETHTOOL_ID_INACTIVE:
1075                         ret = phy_write(phy_dev, HNS_PHY_PAGE_REG,
1076                                         HNS_PHY_PAGE_LED);
1077                         if (ret)
1078                                 return ret;
1079
1080                         ret = phy_write(phy_dev, HNS_LED_FC_REG,
1081                                         priv->phy_led_val);
1082                         if (ret)
1083                                 return ret;
1084
1085                         ret = phy_write(phy_dev, HNS_PHY_PAGE_REG,
1086                                         HNS_PHY_PAGE_COPPER);
1087                         if (ret)
1088                                 return ret;
1089                         break;
1090                 default:
1091                         return -EINVAL;
1092                 }
1093         else
1094                 switch (state) {
1095                 case ETHTOOL_ID_ACTIVE:
1096                         return h->dev->ops->set_led_id(h, HNAE_LED_ACTIVE);
1097                 case ETHTOOL_ID_ON:
1098                         return h->dev->ops->set_led_id(h, HNAE_LED_ON);
1099                 case ETHTOOL_ID_OFF:
1100                         return h->dev->ops->set_led_id(h, HNAE_LED_OFF);
1101                 case ETHTOOL_ID_INACTIVE:
1102                         return h->dev->ops->set_led_id(h, HNAE_LED_INACTIVE);
1103                 default:
1104                         return -EINVAL;
1105                 }
1106
1107         return 0;
1108 }
1109
1110 /**
1111  * hns_get_regs - get net device register
1112  * @dev: net device
1113  * @cmd: ethtool cmd
1114  * @date: register data
1115  */
1116 void hns_get_regs(struct net_device *net_dev, struct ethtool_regs *cmd,
1117                   void *data)
1118 {
1119         struct hns_nic_priv *priv = netdev_priv(net_dev);
1120         struct hnae_ae_ops *ops;
1121
1122         ops = priv->ae_handle->dev->ops;
1123
1124         cmd->version = HNS_CHIP_VERSION;
1125         if (!ops->get_regs) {
1126                 netdev_err(net_dev, "ops->get_regs is null!\n");
1127                 return;
1128         }
1129         ops->get_regs(priv->ae_handle, data);
1130 }
1131
1132 /**
1133  * nic_get_regs_len - get total register len.
1134  * @dev: net device
1135  *
1136  * Return total register len.
1137  */
1138 static int hns_get_regs_len(struct net_device *net_dev)
1139 {
1140         u32 reg_num;
1141         struct hns_nic_priv *priv = netdev_priv(net_dev);
1142         struct hnae_ae_ops *ops;
1143
1144         ops = priv->ae_handle->dev->ops;
1145         if (!ops->get_regs_len) {
1146                 netdev_err(net_dev, "ops->get_regs_len is null!\n");
1147                 return -EOPNOTSUPP;
1148         }
1149
1150         reg_num = ops->get_regs_len(priv->ae_handle);
1151         if (reg_num > 0)
1152                 return reg_num * sizeof(u32);
1153         else
1154                 return reg_num; /* error code */
1155 }
1156
1157 /**
1158  * hns_nic_nway_reset - nway reset
1159  * @dev: net device
1160  *
1161  * Return 0 on success, negative on failure
1162  */
1163 static int hns_nic_nway_reset(struct net_device *netdev)
1164 {
1165         struct phy_device *phy = netdev->phydev;
1166
1167         if (!netif_running(netdev))
1168                 return 0;
1169
1170         if (!phy)
1171                 return -EOPNOTSUPP;
1172
1173         if (phy->autoneg != AUTONEG_ENABLE)
1174                 return -EINVAL;
1175
1176         return genphy_restart_aneg(phy);
1177 }
1178
1179 static u32
1180 hns_get_rss_key_size(struct net_device *netdev)
1181 {
1182         struct hns_nic_priv *priv = netdev_priv(netdev);
1183         struct hnae_ae_ops *ops;
1184
1185         if (AE_IS_VER1(priv->enet_ver)) {
1186                 netdev_err(netdev,
1187                            "RSS feature is not supported on this hardware\n");
1188                 return 0;
1189         }
1190
1191         ops = priv->ae_handle->dev->ops;
1192         return ops->get_rss_key_size(priv->ae_handle);
1193 }
1194
1195 static u32
1196 hns_get_rss_indir_size(struct net_device *netdev)
1197 {
1198         struct hns_nic_priv *priv = netdev_priv(netdev);
1199         struct hnae_ae_ops *ops;
1200
1201         if (AE_IS_VER1(priv->enet_ver)) {
1202                 netdev_err(netdev,
1203                            "RSS feature is not supported on this hardware\n");
1204                 return 0;
1205         }
1206
1207         ops = priv->ae_handle->dev->ops;
1208         return ops->get_rss_indir_size(priv->ae_handle);
1209 }
1210
1211 static int
1212 hns_get_rss(struct net_device *netdev, u32 *indir, u8 *key, u8 *hfunc)
1213 {
1214         struct hns_nic_priv *priv = netdev_priv(netdev);
1215         struct hnae_ae_ops *ops;
1216
1217         if (AE_IS_VER1(priv->enet_ver)) {
1218                 netdev_err(netdev,
1219                            "RSS feature is not supported on this hardware\n");
1220                 return -EOPNOTSUPP;
1221         }
1222
1223         ops = priv->ae_handle->dev->ops;
1224
1225         if (!indir)
1226                 return 0;
1227
1228         return ops->get_rss(priv->ae_handle, indir, key, hfunc);
1229 }
1230
1231 static int
1232 hns_set_rss(struct net_device *netdev, const u32 *indir, const u8 *key,
1233             const u8 hfunc)
1234 {
1235         struct hns_nic_priv *priv = netdev_priv(netdev);
1236         struct hnae_ae_ops *ops;
1237
1238         if (AE_IS_VER1(priv->enet_ver)) {
1239                 netdev_err(netdev,
1240                            "RSS feature is not supported on this hardware\n");
1241                 return -EOPNOTSUPP;
1242         }
1243
1244         ops = priv->ae_handle->dev->ops;
1245
1246         if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) {
1247                 netdev_err(netdev, "Invalid hfunc!\n");
1248                 return -EOPNOTSUPP;
1249         }
1250
1251         return ops->set_rss(priv->ae_handle, indir, key, hfunc);
1252 }
1253
1254 static int hns_get_rxnfc(struct net_device *netdev,
1255                          struct ethtool_rxnfc *cmd,
1256                          u32 *rule_locs)
1257 {
1258         struct hns_nic_priv *priv = netdev_priv(netdev);
1259
1260         switch (cmd->cmd) {
1261         case ETHTOOL_GRXRINGS:
1262                 cmd->data = priv->ae_handle->q_num;
1263                 break;
1264         default:
1265                 return -EOPNOTSUPP;
1266         }
1267
1268         return 0;
1269 }
1270
1271 static const struct ethtool_ops hns_ethtool_ops = {
1272         .get_drvinfo = hns_nic_get_drvinfo,
1273         .get_link  = hns_nic_get_link,
1274         .get_ringparam = hns_get_ringparam,
1275         .get_pauseparam = hns_get_pauseparam,
1276         .set_pauseparam = hns_set_pauseparam,
1277         .get_coalesce = hns_get_coalesce,
1278         .set_coalesce = hns_set_coalesce,
1279         .get_channels = hns_get_channels,
1280         .self_test = hns_nic_self_test,
1281         .get_strings = hns_get_strings,
1282         .get_sset_count = hns_get_sset_count,
1283         .get_ethtool_stats = hns_get_ethtool_stats,
1284         .set_phys_id = hns_set_phys_id,
1285         .get_regs_len = hns_get_regs_len,
1286         .get_regs = hns_get_regs,
1287         .nway_reset = hns_nic_nway_reset,
1288         .get_rxfh_key_size = hns_get_rss_key_size,
1289         .get_rxfh_indir_size = hns_get_rss_indir_size,
1290         .get_rxfh = hns_get_rss,
1291         .set_rxfh = hns_set_rss,
1292         .get_rxnfc = hns_get_rxnfc,
1293         .get_link_ksettings  = hns_nic_get_link_ksettings,
1294         .set_link_ksettings  = hns_nic_set_link_ksettings,
1295 };
1296
1297 void hns_ethtool_set_ops(struct net_device *ndev)
1298 {
1299         ndev->ethtool_ops = &hns_ethtool_ops;
1300 }