hns_ethtool.c 32 KB

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