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