en_ethtool.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. #include <linux/kernel.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/netdevice.h>
  36. #include "mlx4_en.h"
  37. #include "en_port.h"
  38. static void
  39. mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
  40. {
  41. struct mlx4_en_priv *priv = netdev_priv(dev);
  42. struct mlx4_en_dev *mdev = priv->mdev;
  43. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  44. strlcpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")",
  45. sizeof(drvinfo->version));
  46. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
  47. "%d.%d.%d",
  48. (u16) (mdev->dev->caps.fw_ver >> 32),
  49. (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff),
  50. (u16) (mdev->dev->caps.fw_ver & 0xffff));
  51. strlcpy(drvinfo->bus_info, pci_name(mdev->dev->pdev),
  52. sizeof(drvinfo->bus_info));
  53. drvinfo->n_stats = 0;
  54. drvinfo->regdump_len = 0;
  55. drvinfo->eedump_len = 0;
  56. }
  57. static const char main_strings[][ETH_GSTRING_LEN] = {
  58. "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
  59. "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
  60. "rx_length_errors", "rx_over_errors", "rx_crc_errors",
  61. "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
  62. "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
  63. "tx_heartbeat_errors", "tx_window_errors",
  64. /* port statistics */
  65. "tso_packets",
  66. "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed",
  67. "rx_csum_good", "rx_csum_none", "tx_chksum_offload",
  68. /* packet statistics */
  69. "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3",
  70. "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0",
  71. "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5",
  72. "tx_prio_6", "tx_prio_7",
  73. };
  74. #define NUM_MAIN_STATS 21
  75. #define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
  76. static const char mlx4_en_test_names[][ETH_GSTRING_LEN]= {
  77. "Interrupt Test",
  78. "Link Test",
  79. "Speed Test",
  80. "Register Test",
  81. "Loopback Test",
  82. };
  83. static u32 mlx4_en_get_msglevel(struct net_device *dev)
  84. {
  85. return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
  86. }
  87. static void mlx4_en_set_msglevel(struct net_device *dev, u32 val)
  88. {
  89. ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val;
  90. }
  91. static void mlx4_en_get_wol(struct net_device *netdev,
  92. struct ethtool_wolinfo *wol)
  93. {
  94. struct mlx4_en_priv *priv = netdev_priv(netdev);
  95. int err = 0;
  96. u64 config = 0;
  97. u64 mask;
  98. if ((priv->port < 1) || (priv->port > 2)) {
  99. en_err(priv, "Failed to get WoL information\n");
  100. return;
  101. }
  102. mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 :
  103. MLX4_DEV_CAP_FLAG_WOL_PORT2;
  104. if (!(priv->mdev->dev->caps.flags & mask)) {
  105. wol->supported = 0;
  106. wol->wolopts = 0;
  107. return;
  108. }
  109. err = mlx4_wol_read(priv->mdev->dev, &config, priv->port);
  110. if (err) {
  111. en_err(priv, "Failed to get WoL information\n");
  112. return;
  113. }
  114. if (config & MLX4_EN_WOL_MAGIC)
  115. wol->supported = WAKE_MAGIC;
  116. else
  117. wol->supported = 0;
  118. if (config & MLX4_EN_WOL_ENABLED)
  119. wol->wolopts = WAKE_MAGIC;
  120. else
  121. wol->wolopts = 0;
  122. }
  123. static int mlx4_en_set_wol(struct net_device *netdev,
  124. struct ethtool_wolinfo *wol)
  125. {
  126. struct mlx4_en_priv *priv = netdev_priv(netdev);
  127. u64 config = 0;
  128. int err = 0;
  129. u64 mask;
  130. if ((priv->port < 1) || (priv->port > 2))
  131. return -EOPNOTSUPP;
  132. mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 :
  133. MLX4_DEV_CAP_FLAG_WOL_PORT2;
  134. if (!(priv->mdev->dev->caps.flags & mask))
  135. return -EOPNOTSUPP;
  136. if (wol->supported & ~WAKE_MAGIC)
  137. return -EINVAL;
  138. err = mlx4_wol_read(priv->mdev->dev, &config, priv->port);
  139. if (err) {
  140. en_err(priv, "Failed to get WoL info, unable to modify\n");
  141. return err;
  142. }
  143. if (wol->wolopts & WAKE_MAGIC) {
  144. config |= MLX4_EN_WOL_DO_MODIFY | MLX4_EN_WOL_ENABLED |
  145. MLX4_EN_WOL_MAGIC;
  146. } else {
  147. config &= ~(MLX4_EN_WOL_ENABLED | MLX4_EN_WOL_MAGIC);
  148. config |= MLX4_EN_WOL_DO_MODIFY;
  149. }
  150. err = mlx4_wol_write(priv->mdev->dev, config, priv->port);
  151. if (err)
  152. en_err(priv, "Failed to set WoL information\n");
  153. return err;
  154. }
  155. static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
  156. {
  157. struct mlx4_en_priv *priv = netdev_priv(dev);
  158. int bit_count = hweight64(priv->stats_bitmap);
  159. switch (sset) {
  160. case ETH_SS_STATS:
  161. return (priv->stats_bitmap ? bit_count : NUM_ALL_STATS) +
  162. (priv->tx_ring_num + priv->rx_ring_num) * 2;
  163. case ETH_SS_TEST:
  164. return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.flags
  165. & MLX4_DEV_CAP_FLAG_UC_LOOPBACK) * 2;
  166. default:
  167. return -EOPNOTSUPP;
  168. }
  169. }
  170. static void mlx4_en_get_ethtool_stats(struct net_device *dev,
  171. struct ethtool_stats *stats, uint64_t *data)
  172. {
  173. struct mlx4_en_priv *priv = netdev_priv(dev);
  174. int index = 0;
  175. int i, j = 0;
  176. spin_lock_bh(&priv->stats_lock);
  177. if (!(priv->stats_bitmap)) {
  178. for (i = 0; i < NUM_MAIN_STATS; i++)
  179. data[index++] =
  180. ((unsigned long *) &priv->stats)[i];
  181. for (i = 0; i < NUM_PORT_STATS; i++)
  182. data[index++] =
  183. ((unsigned long *) &priv->port_stats)[i];
  184. for (i = 0; i < NUM_PKT_STATS; i++)
  185. data[index++] =
  186. ((unsigned long *) &priv->pkstats)[i];
  187. } else {
  188. for (i = 0; i < NUM_MAIN_STATS; i++) {
  189. if ((priv->stats_bitmap >> j) & 1)
  190. data[index++] =
  191. ((unsigned long *) &priv->stats)[i];
  192. j++;
  193. }
  194. for (i = 0; i < NUM_PORT_STATS; i++) {
  195. if ((priv->stats_bitmap >> j) & 1)
  196. data[index++] =
  197. ((unsigned long *) &priv->port_stats)[i];
  198. j++;
  199. }
  200. }
  201. for (i = 0; i < priv->tx_ring_num; i++) {
  202. data[index++] = priv->tx_ring[i].packets;
  203. data[index++] = priv->tx_ring[i].bytes;
  204. }
  205. for (i = 0; i < priv->rx_ring_num; i++) {
  206. data[index++] = priv->rx_ring[i].packets;
  207. data[index++] = priv->rx_ring[i].bytes;
  208. }
  209. spin_unlock_bh(&priv->stats_lock);
  210. }
  211. static void mlx4_en_self_test(struct net_device *dev,
  212. struct ethtool_test *etest, u64 *buf)
  213. {
  214. mlx4_en_ex_selftest(dev, &etest->flags, buf);
  215. }
  216. static void mlx4_en_get_strings(struct net_device *dev,
  217. uint32_t stringset, uint8_t *data)
  218. {
  219. struct mlx4_en_priv *priv = netdev_priv(dev);
  220. int index = 0;
  221. int i;
  222. switch (stringset) {
  223. case ETH_SS_TEST:
  224. for (i = 0; i < MLX4_EN_NUM_SELF_TEST - 2; i++)
  225. strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
  226. if (priv->mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_UC_LOOPBACK)
  227. for (; i < MLX4_EN_NUM_SELF_TEST; i++)
  228. strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
  229. break;
  230. case ETH_SS_STATS:
  231. /* Add main counters */
  232. if (!priv->stats_bitmap) {
  233. for (i = 0; i < NUM_MAIN_STATS; i++)
  234. strcpy(data + (index++) * ETH_GSTRING_LEN,
  235. main_strings[i]);
  236. for (i = 0; i < NUM_PORT_STATS; i++)
  237. strcpy(data + (index++) * ETH_GSTRING_LEN,
  238. main_strings[i +
  239. NUM_MAIN_STATS]);
  240. for (i = 0; i < NUM_PKT_STATS; i++)
  241. strcpy(data + (index++) * ETH_GSTRING_LEN,
  242. main_strings[i +
  243. NUM_MAIN_STATS +
  244. NUM_PORT_STATS]);
  245. } else
  246. for (i = 0; i < NUM_MAIN_STATS + NUM_PORT_STATS; i++) {
  247. if ((priv->stats_bitmap >> i) & 1) {
  248. strcpy(data +
  249. (index++) * ETH_GSTRING_LEN,
  250. main_strings[i]);
  251. }
  252. if (!(priv->stats_bitmap >> i))
  253. break;
  254. }
  255. for (i = 0; i < priv->tx_ring_num; i++) {
  256. sprintf(data + (index++) * ETH_GSTRING_LEN,
  257. "tx%d_packets", i);
  258. sprintf(data + (index++) * ETH_GSTRING_LEN,
  259. "tx%d_bytes", i);
  260. }
  261. for (i = 0; i < priv->rx_ring_num; i++) {
  262. sprintf(data + (index++) * ETH_GSTRING_LEN,
  263. "rx%d_packets", i);
  264. sprintf(data + (index++) * ETH_GSTRING_LEN,
  265. "rx%d_bytes", i);
  266. }
  267. break;
  268. }
  269. }
  270. static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  271. {
  272. struct mlx4_en_priv *priv = netdev_priv(dev);
  273. int trans_type;
  274. cmd->autoneg = AUTONEG_DISABLE;
  275. cmd->supported = SUPPORTED_10000baseT_Full;
  276. cmd->advertising = ADVERTISED_10000baseT_Full;
  277. if (mlx4_en_QUERY_PORT(priv->mdev, priv->port))
  278. return -ENOMEM;
  279. trans_type = priv->port_state.transciver;
  280. if (netif_carrier_ok(dev)) {
  281. ethtool_cmd_speed_set(cmd, priv->port_state.link_speed);
  282. cmd->duplex = DUPLEX_FULL;
  283. } else {
  284. ethtool_cmd_speed_set(cmd, -1);
  285. cmd->duplex = -1;
  286. }
  287. if (trans_type > 0 && trans_type <= 0xC) {
  288. cmd->port = PORT_FIBRE;
  289. cmd->transceiver = XCVR_EXTERNAL;
  290. cmd->supported |= SUPPORTED_FIBRE;
  291. cmd->advertising |= ADVERTISED_FIBRE;
  292. } else if (trans_type == 0x80 || trans_type == 0) {
  293. cmd->port = PORT_TP;
  294. cmd->transceiver = XCVR_INTERNAL;
  295. cmd->supported |= SUPPORTED_TP;
  296. cmd->advertising |= ADVERTISED_TP;
  297. } else {
  298. cmd->port = -1;
  299. cmd->transceiver = -1;
  300. }
  301. return 0;
  302. }
  303. static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  304. {
  305. if ((cmd->autoneg == AUTONEG_ENABLE) ||
  306. (ethtool_cmd_speed(cmd) != SPEED_10000) ||
  307. (cmd->duplex != DUPLEX_FULL))
  308. return -EINVAL;
  309. /* Nothing to change */
  310. return 0;
  311. }
  312. static int mlx4_en_get_coalesce(struct net_device *dev,
  313. struct ethtool_coalesce *coal)
  314. {
  315. struct mlx4_en_priv *priv = netdev_priv(dev);
  316. coal->tx_coalesce_usecs = priv->tx_usecs;
  317. coal->tx_max_coalesced_frames = priv->tx_frames;
  318. coal->rx_coalesce_usecs = priv->rx_usecs;
  319. coal->rx_max_coalesced_frames = priv->rx_frames;
  320. coal->pkt_rate_low = priv->pkt_rate_low;
  321. coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
  322. coal->pkt_rate_high = priv->pkt_rate_high;
  323. coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
  324. coal->rate_sample_interval = priv->sample_interval;
  325. coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
  326. return 0;
  327. }
  328. static int mlx4_en_set_coalesce(struct net_device *dev,
  329. struct ethtool_coalesce *coal)
  330. {
  331. struct mlx4_en_priv *priv = netdev_priv(dev);
  332. int err, i;
  333. priv->rx_frames = (coal->rx_max_coalesced_frames ==
  334. MLX4_EN_AUTO_CONF) ?
  335. MLX4_EN_RX_COAL_TARGET :
  336. coal->rx_max_coalesced_frames;
  337. priv->rx_usecs = (coal->rx_coalesce_usecs ==
  338. MLX4_EN_AUTO_CONF) ?
  339. MLX4_EN_RX_COAL_TIME :
  340. coal->rx_coalesce_usecs;
  341. /* Setting TX coalescing parameters */
  342. if (coal->tx_coalesce_usecs != priv->tx_usecs ||
  343. coal->tx_max_coalesced_frames != priv->tx_frames) {
  344. priv->tx_usecs = coal->tx_coalesce_usecs;
  345. priv->tx_frames = coal->tx_max_coalesced_frames;
  346. for (i = 0; i < priv->tx_ring_num; i++) {
  347. priv->tx_cq[i].moder_cnt = priv->tx_frames;
  348. priv->tx_cq[i].moder_time = priv->tx_usecs;
  349. if (mlx4_en_set_cq_moder(priv, &priv->tx_cq[i])) {
  350. en_warn(priv, "Failed changing moderation "
  351. "for TX cq %d\n", i);
  352. }
  353. }
  354. }
  355. /* Set adaptive coalescing params */
  356. priv->pkt_rate_low = coal->pkt_rate_low;
  357. priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
  358. priv->pkt_rate_high = coal->pkt_rate_high;
  359. priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
  360. priv->sample_interval = coal->rate_sample_interval;
  361. priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
  362. if (priv->adaptive_rx_coal)
  363. return 0;
  364. for (i = 0; i < priv->rx_ring_num; i++) {
  365. priv->rx_cq[i].moder_cnt = priv->rx_frames;
  366. priv->rx_cq[i].moder_time = priv->rx_usecs;
  367. priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
  368. err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]);
  369. if (err)
  370. return err;
  371. }
  372. return 0;
  373. }
  374. static int mlx4_en_set_pauseparam(struct net_device *dev,
  375. struct ethtool_pauseparam *pause)
  376. {
  377. struct mlx4_en_priv *priv = netdev_priv(dev);
  378. struct mlx4_en_dev *mdev = priv->mdev;
  379. int err;
  380. priv->prof->tx_pause = pause->tx_pause != 0;
  381. priv->prof->rx_pause = pause->rx_pause != 0;
  382. err = mlx4_SET_PORT_general(mdev->dev, priv->port,
  383. priv->rx_skb_size + ETH_FCS_LEN,
  384. priv->prof->tx_pause,
  385. priv->prof->tx_ppp,
  386. priv->prof->rx_pause,
  387. priv->prof->rx_ppp);
  388. if (err)
  389. en_err(priv, "Failed setting pause params\n");
  390. return err;
  391. }
  392. static void mlx4_en_get_pauseparam(struct net_device *dev,
  393. struct ethtool_pauseparam *pause)
  394. {
  395. struct mlx4_en_priv *priv = netdev_priv(dev);
  396. pause->tx_pause = priv->prof->tx_pause;
  397. pause->rx_pause = priv->prof->rx_pause;
  398. }
  399. static int mlx4_en_set_ringparam(struct net_device *dev,
  400. struct ethtool_ringparam *param)
  401. {
  402. struct mlx4_en_priv *priv = netdev_priv(dev);
  403. struct mlx4_en_dev *mdev = priv->mdev;
  404. u32 rx_size, tx_size;
  405. int port_up = 0;
  406. int err = 0;
  407. int i;
  408. if (param->rx_jumbo_pending || param->rx_mini_pending)
  409. return -EINVAL;
  410. rx_size = roundup_pow_of_two(param->rx_pending);
  411. rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE);
  412. rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE);
  413. tx_size = roundup_pow_of_two(param->tx_pending);
  414. tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE);
  415. tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE);
  416. if (rx_size == (priv->port_up ? priv->rx_ring[0].actual_size :
  417. priv->rx_ring[0].size) &&
  418. tx_size == priv->tx_ring[0].size)
  419. return 0;
  420. mutex_lock(&mdev->state_lock);
  421. if (priv->port_up) {
  422. port_up = 1;
  423. mlx4_en_stop_port(dev);
  424. }
  425. mlx4_en_free_resources(priv);
  426. priv->prof->tx_ring_size = tx_size;
  427. priv->prof->rx_ring_size = rx_size;
  428. err = mlx4_en_alloc_resources(priv);
  429. if (err) {
  430. en_err(priv, "Failed reallocating port resources\n");
  431. goto out;
  432. }
  433. if (port_up) {
  434. err = mlx4_en_start_port(dev);
  435. if (err)
  436. en_err(priv, "Failed starting port\n");
  437. }
  438. for (i = 0; i < priv->rx_ring_num; i++) {
  439. priv->rx_cq[i].moder_cnt = priv->rx_frames;
  440. priv->rx_cq[i].moder_time = priv->rx_usecs;
  441. priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
  442. err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]);
  443. if (err)
  444. goto out;
  445. }
  446. out:
  447. mutex_unlock(&mdev->state_lock);
  448. return err;
  449. }
  450. static void mlx4_en_get_ringparam(struct net_device *dev,
  451. struct ethtool_ringparam *param)
  452. {
  453. struct mlx4_en_priv *priv = netdev_priv(dev);
  454. memset(param, 0, sizeof(*param));
  455. param->rx_max_pending = MLX4_EN_MAX_RX_SIZE;
  456. param->tx_max_pending = MLX4_EN_MAX_TX_SIZE;
  457. param->rx_pending = priv->port_up ?
  458. priv->rx_ring[0].actual_size : priv->rx_ring[0].size;
  459. param->tx_pending = priv->tx_ring[0].size;
  460. }
  461. static u32 mlx4_en_get_rxfh_indir_size(struct net_device *dev)
  462. {
  463. struct mlx4_en_priv *priv = netdev_priv(dev);
  464. return priv->rx_ring_num;
  465. }
  466. static int mlx4_en_get_rxfh_indir(struct net_device *dev, u32 *ring_index)
  467. {
  468. struct mlx4_en_priv *priv = netdev_priv(dev);
  469. struct mlx4_en_rss_map *rss_map = &priv->rss_map;
  470. int rss_rings;
  471. size_t n = priv->rx_ring_num;
  472. int err = 0;
  473. rss_rings = priv->prof->rss_rings ?: priv->rx_ring_num;
  474. while (n--) {
  475. ring_index[n] = rss_map->qps[n % rss_rings].qpn -
  476. rss_map->base_qpn;
  477. }
  478. return err;
  479. }
  480. static int mlx4_en_set_rxfh_indir(struct net_device *dev,
  481. const u32 *ring_index)
  482. {
  483. struct mlx4_en_priv *priv = netdev_priv(dev);
  484. struct mlx4_en_dev *mdev = priv->mdev;
  485. int port_up = 0;
  486. int err = 0;
  487. int i;
  488. int rss_rings = 0;
  489. /* Calculate RSS table size and make sure flows are spread evenly
  490. * between rings
  491. */
  492. for (i = 0; i < priv->rx_ring_num; i++) {
  493. if (i > 0 && !ring_index[i] && !rss_rings)
  494. rss_rings = i;
  495. if (ring_index[i] != (i % (rss_rings ?: priv->rx_ring_num)))
  496. return -EINVAL;
  497. }
  498. if (!rss_rings)
  499. rss_rings = priv->rx_ring_num;
  500. /* RSS table size must be an order of 2 */
  501. if (!is_power_of_2(rss_rings))
  502. return -EINVAL;
  503. mutex_lock(&mdev->state_lock);
  504. if (priv->port_up) {
  505. port_up = 1;
  506. mlx4_en_stop_port(dev);
  507. }
  508. priv->prof->rss_rings = rss_rings;
  509. if (port_up) {
  510. err = mlx4_en_start_port(dev);
  511. if (err)
  512. en_err(priv, "Failed starting port\n");
  513. }
  514. mutex_unlock(&mdev->state_lock);
  515. return err;
  516. }
  517. static int mlx4_en_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
  518. u32 *rule_locs)
  519. {
  520. struct mlx4_en_priv *priv = netdev_priv(dev);
  521. int err = 0;
  522. switch (cmd->cmd) {
  523. case ETHTOOL_GRXRINGS:
  524. cmd->data = priv->rx_ring_num;
  525. break;
  526. default:
  527. err = -EOPNOTSUPP;
  528. break;
  529. }
  530. return err;
  531. }
  532. const struct ethtool_ops mlx4_en_ethtool_ops = {
  533. .get_drvinfo = mlx4_en_get_drvinfo,
  534. .get_settings = mlx4_en_get_settings,
  535. .set_settings = mlx4_en_set_settings,
  536. .get_link = ethtool_op_get_link,
  537. .get_strings = mlx4_en_get_strings,
  538. .get_sset_count = mlx4_en_get_sset_count,
  539. .get_ethtool_stats = mlx4_en_get_ethtool_stats,
  540. .self_test = mlx4_en_self_test,
  541. .get_wol = mlx4_en_get_wol,
  542. .set_wol = mlx4_en_set_wol,
  543. .get_msglevel = mlx4_en_get_msglevel,
  544. .set_msglevel = mlx4_en_set_msglevel,
  545. .get_coalesce = mlx4_en_get_coalesce,
  546. .set_coalesce = mlx4_en_set_coalesce,
  547. .get_pauseparam = mlx4_en_get_pauseparam,
  548. .set_pauseparam = mlx4_en_set_pauseparam,
  549. .get_ringparam = mlx4_en_get_ringparam,
  550. .set_ringparam = mlx4_en_set_ringparam,
  551. .get_rxnfc = mlx4_en_get_rxnfc,
  552. .get_rxfh_indir_size = mlx4_en_get_rxfh_indir_size,
  553. .get_rxfh_indir = mlx4_en_get_rxfh_indir,
  554. .set_rxfh_indir = mlx4_en_set_rxfh_indir,
  555. };