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