en_ethtool.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  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 <linux/mlx4/driver.h>
  37. #include <linux/in.h>
  38. #include <net/ip.h>
  39. #include "mlx4_en.h"
  40. #include "en_port.h"
  41. #define EN_ETHTOOL_QP_ATTACH (1ull << 63)
  42. #define EN_ETHTOOL_SHORT_MASK cpu_to_be16(0xffff)
  43. #define EN_ETHTOOL_WORD_MASK cpu_to_be32(0xffffffff)
  44. static int mlx4_en_moderation_update(struct mlx4_en_priv *priv)
  45. {
  46. int i;
  47. int err = 0;
  48. for (i = 0; i < priv->tx_ring_num; i++) {
  49. priv->tx_cq[i].moder_cnt = priv->tx_frames;
  50. priv->tx_cq[i].moder_time = priv->tx_usecs;
  51. err = mlx4_en_set_cq_moder(priv, &priv->tx_cq[i]);
  52. if (err)
  53. return err;
  54. }
  55. if (priv->adaptive_rx_coal)
  56. return 0;
  57. for (i = 0; i < priv->rx_ring_num; i++) {
  58. priv->rx_cq[i].moder_cnt = priv->rx_frames;
  59. priv->rx_cq[i].moder_time = priv->rx_usecs;
  60. priv->last_moder_time[i] = MLX4_EN_AUTO_CONF;
  61. err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]);
  62. if (err)
  63. return err;
  64. }
  65. return err;
  66. }
  67. static void
  68. mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
  69. {
  70. struct mlx4_en_priv *priv = netdev_priv(dev);
  71. struct mlx4_en_dev *mdev = priv->mdev;
  72. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  73. strlcpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")",
  74. sizeof(drvinfo->version));
  75. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
  76. "%d.%d.%d",
  77. (u16) (mdev->dev->caps.fw_ver >> 32),
  78. (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff),
  79. (u16) (mdev->dev->caps.fw_ver & 0xffff));
  80. strlcpy(drvinfo->bus_info, pci_name(mdev->dev->pdev),
  81. sizeof(drvinfo->bus_info));
  82. drvinfo->n_stats = 0;
  83. drvinfo->regdump_len = 0;
  84. drvinfo->eedump_len = 0;
  85. }
  86. static const char main_strings[][ETH_GSTRING_LEN] = {
  87. "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
  88. "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
  89. "rx_length_errors", "rx_over_errors", "rx_crc_errors",
  90. "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
  91. "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
  92. "tx_heartbeat_errors", "tx_window_errors",
  93. /* port statistics */
  94. "tso_packets",
  95. "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed",
  96. "rx_csum_good", "rx_csum_none", "tx_chksum_offload",
  97. /* packet statistics */
  98. "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3",
  99. "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0",
  100. "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5",
  101. "tx_prio_6", "tx_prio_7",
  102. };
  103. #define NUM_MAIN_STATS 21
  104. #define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
  105. static const char mlx4_en_test_names[][ETH_GSTRING_LEN]= {
  106. "Interrupt Test",
  107. "Link Test",
  108. "Speed Test",
  109. "Register Test",
  110. "Loopback Test",
  111. };
  112. static u32 mlx4_en_get_msglevel(struct net_device *dev)
  113. {
  114. return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
  115. }
  116. static void mlx4_en_set_msglevel(struct net_device *dev, u32 val)
  117. {
  118. ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val;
  119. }
  120. static void mlx4_en_get_wol(struct net_device *netdev,
  121. struct ethtool_wolinfo *wol)
  122. {
  123. struct mlx4_en_priv *priv = netdev_priv(netdev);
  124. int err = 0;
  125. u64 config = 0;
  126. u64 mask;
  127. if ((priv->port < 1) || (priv->port > 2)) {
  128. en_err(priv, "Failed to get WoL information\n");
  129. return;
  130. }
  131. mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 :
  132. MLX4_DEV_CAP_FLAG_WOL_PORT2;
  133. if (!(priv->mdev->dev->caps.flags & mask)) {
  134. wol->supported = 0;
  135. wol->wolopts = 0;
  136. return;
  137. }
  138. err = mlx4_wol_read(priv->mdev->dev, &config, priv->port);
  139. if (err) {
  140. en_err(priv, "Failed to get WoL information\n");
  141. return;
  142. }
  143. if (config & MLX4_EN_WOL_MAGIC)
  144. wol->supported = WAKE_MAGIC;
  145. else
  146. wol->supported = 0;
  147. if (config & MLX4_EN_WOL_ENABLED)
  148. wol->wolopts = WAKE_MAGIC;
  149. else
  150. wol->wolopts = 0;
  151. }
  152. static int mlx4_en_set_wol(struct net_device *netdev,
  153. struct ethtool_wolinfo *wol)
  154. {
  155. struct mlx4_en_priv *priv = netdev_priv(netdev);
  156. u64 config = 0;
  157. int err = 0;
  158. u64 mask;
  159. if ((priv->port < 1) || (priv->port > 2))
  160. return -EOPNOTSUPP;
  161. mask = (priv->port == 1) ? MLX4_DEV_CAP_FLAG_WOL_PORT1 :
  162. MLX4_DEV_CAP_FLAG_WOL_PORT2;
  163. if (!(priv->mdev->dev->caps.flags & mask))
  164. return -EOPNOTSUPP;
  165. if (wol->supported & ~WAKE_MAGIC)
  166. return -EINVAL;
  167. err = mlx4_wol_read(priv->mdev->dev, &config, priv->port);
  168. if (err) {
  169. en_err(priv, "Failed to get WoL info, unable to modify\n");
  170. return err;
  171. }
  172. if (wol->wolopts & WAKE_MAGIC) {
  173. config |= MLX4_EN_WOL_DO_MODIFY | MLX4_EN_WOL_ENABLED |
  174. MLX4_EN_WOL_MAGIC;
  175. } else {
  176. config &= ~(MLX4_EN_WOL_ENABLED | MLX4_EN_WOL_MAGIC);
  177. config |= MLX4_EN_WOL_DO_MODIFY;
  178. }
  179. err = mlx4_wol_write(priv->mdev->dev, config, priv->port);
  180. if (err)
  181. en_err(priv, "Failed to set WoL information\n");
  182. return err;
  183. }
  184. static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
  185. {
  186. struct mlx4_en_priv *priv = netdev_priv(dev);
  187. int bit_count = hweight64(priv->stats_bitmap);
  188. switch (sset) {
  189. case ETH_SS_STATS:
  190. return (priv->stats_bitmap ? bit_count : NUM_ALL_STATS) +
  191. (priv->tx_ring_num + priv->rx_ring_num) * 2;
  192. case ETH_SS_TEST:
  193. return MLX4_EN_NUM_SELF_TEST - !(priv->mdev->dev->caps.flags
  194. & MLX4_DEV_CAP_FLAG_UC_LOOPBACK) * 2;
  195. default:
  196. return -EOPNOTSUPP;
  197. }
  198. }
  199. static void mlx4_en_get_ethtool_stats(struct net_device *dev,
  200. struct ethtool_stats *stats, uint64_t *data)
  201. {
  202. struct mlx4_en_priv *priv = netdev_priv(dev);
  203. int index = 0;
  204. int i, j = 0;
  205. spin_lock_bh(&priv->stats_lock);
  206. if (!(priv->stats_bitmap)) {
  207. for (i = 0; i < NUM_MAIN_STATS; i++)
  208. data[index++] =
  209. ((unsigned long *) &priv->stats)[i];
  210. for (i = 0; i < NUM_PORT_STATS; i++)
  211. data[index++] =
  212. ((unsigned long *) &priv->port_stats)[i];
  213. for (i = 0; i < NUM_PKT_STATS; i++)
  214. data[index++] =
  215. ((unsigned long *) &priv->pkstats)[i];
  216. } else {
  217. for (i = 0; i < NUM_MAIN_STATS; i++) {
  218. if ((priv->stats_bitmap >> j) & 1)
  219. data[index++] =
  220. ((unsigned long *) &priv->stats)[i];
  221. j++;
  222. }
  223. for (i = 0; i < NUM_PORT_STATS; i++) {
  224. if ((priv->stats_bitmap >> j) & 1)
  225. data[index++] =
  226. ((unsigned long *) &priv->port_stats)[i];
  227. j++;
  228. }
  229. }
  230. for (i = 0; i < priv->tx_ring_num; i++) {
  231. data[index++] = priv->tx_ring[i].packets;
  232. data[index++] = priv->tx_ring[i].bytes;
  233. }
  234. for (i = 0; i < priv->rx_ring_num; i++) {
  235. data[index++] = priv->rx_ring[i].packets;
  236. data[index++] = priv->rx_ring[i].bytes;
  237. }
  238. spin_unlock_bh(&priv->stats_lock);
  239. }
  240. static void mlx4_en_self_test(struct net_device *dev,
  241. struct ethtool_test *etest, u64 *buf)
  242. {
  243. mlx4_en_ex_selftest(dev, &etest->flags, buf);
  244. }
  245. static void mlx4_en_get_strings(struct net_device *dev,
  246. uint32_t stringset, uint8_t *data)
  247. {
  248. struct mlx4_en_priv *priv = netdev_priv(dev);
  249. int index = 0;
  250. int i;
  251. switch (stringset) {
  252. case ETH_SS_TEST:
  253. for (i = 0; i < MLX4_EN_NUM_SELF_TEST - 2; i++)
  254. strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
  255. if (priv->mdev->dev->caps.flags & MLX4_DEV_CAP_FLAG_UC_LOOPBACK)
  256. for (; i < MLX4_EN_NUM_SELF_TEST; i++)
  257. strcpy(data + i * ETH_GSTRING_LEN, mlx4_en_test_names[i]);
  258. break;
  259. case ETH_SS_STATS:
  260. /* Add main counters */
  261. if (!priv->stats_bitmap) {
  262. for (i = 0; i < NUM_MAIN_STATS; i++)
  263. strcpy(data + (index++) * ETH_GSTRING_LEN,
  264. main_strings[i]);
  265. for (i = 0; i < NUM_PORT_STATS; i++)
  266. strcpy(data + (index++) * ETH_GSTRING_LEN,
  267. main_strings[i +
  268. NUM_MAIN_STATS]);
  269. for (i = 0; i < NUM_PKT_STATS; i++)
  270. strcpy(data + (index++) * ETH_GSTRING_LEN,
  271. main_strings[i +
  272. NUM_MAIN_STATS +
  273. NUM_PORT_STATS]);
  274. } else
  275. for (i = 0; i < NUM_MAIN_STATS + NUM_PORT_STATS; i++) {
  276. if ((priv->stats_bitmap >> i) & 1) {
  277. strcpy(data +
  278. (index++) * ETH_GSTRING_LEN,
  279. main_strings[i]);
  280. }
  281. if (!(priv->stats_bitmap >> i))
  282. break;
  283. }
  284. for (i = 0; i < priv->tx_ring_num; i++) {
  285. sprintf(data + (index++) * ETH_GSTRING_LEN,
  286. "tx%d_packets", i);
  287. sprintf(data + (index++) * ETH_GSTRING_LEN,
  288. "tx%d_bytes", i);
  289. }
  290. for (i = 0; i < priv->rx_ring_num; i++) {
  291. sprintf(data + (index++) * ETH_GSTRING_LEN,
  292. "rx%d_packets", i);
  293. sprintf(data + (index++) * ETH_GSTRING_LEN,
  294. "rx%d_bytes", i);
  295. }
  296. break;
  297. }
  298. }
  299. static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  300. {
  301. struct mlx4_en_priv *priv = netdev_priv(dev);
  302. int trans_type;
  303. cmd->autoneg = AUTONEG_DISABLE;
  304. cmd->supported = SUPPORTED_10000baseT_Full;
  305. cmd->advertising = ADVERTISED_10000baseT_Full;
  306. if (mlx4_en_QUERY_PORT(priv->mdev, priv->port))
  307. return -ENOMEM;
  308. trans_type = priv->port_state.transciver;
  309. if (netif_carrier_ok(dev)) {
  310. ethtool_cmd_speed_set(cmd, priv->port_state.link_speed);
  311. cmd->duplex = DUPLEX_FULL;
  312. } else {
  313. ethtool_cmd_speed_set(cmd, -1);
  314. cmd->duplex = -1;
  315. }
  316. if (trans_type > 0 && trans_type <= 0xC) {
  317. cmd->port = PORT_FIBRE;
  318. cmd->transceiver = XCVR_EXTERNAL;
  319. cmd->supported |= SUPPORTED_FIBRE;
  320. cmd->advertising |= ADVERTISED_FIBRE;
  321. } else if (trans_type == 0x80 || trans_type == 0) {
  322. cmd->port = PORT_TP;
  323. cmd->transceiver = XCVR_INTERNAL;
  324. cmd->supported |= SUPPORTED_TP;
  325. cmd->advertising |= ADVERTISED_TP;
  326. } else {
  327. cmd->port = -1;
  328. cmd->transceiver = -1;
  329. }
  330. return 0;
  331. }
  332. static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  333. {
  334. if ((cmd->autoneg == AUTONEG_ENABLE) ||
  335. (ethtool_cmd_speed(cmd) != SPEED_10000) ||
  336. (cmd->duplex != DUPLEX_FULL))
  337. return -EINVAL;
  338. /* Nothing to change */
  339. return 0;
  340. }
  341. static int mlx4_en_get_coalesce(struct net_device *dev,
  342. struct ethtool_coalesce *coal)
  343. {
  344. struct mlx4_en_priv *priv = netdev_priv(dev);
  345. coal->tx_coalesce_usecs = priv->tx_usecs;
  346. coal->tx_max_coalesced_frames = priv->tx_frames;
  347. coal->rx_coalesce_usecs = priv->rx_usecs;
  348. coal->rx_max_coalesced_frames = priv->rx_frames;
  349. coal->pkt_rate_low = priv->pkt_rate_low;
  350. coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
  351. coal->pkt_rate_high = priv->pkt_rate_high;
  352. coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
  353. coal->rate_sample_interval = priv->sample_interval;
  354. coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
  355. return 0;
  356. }
  357. static int mlx4_en_set_coalesce(struct net_device *dev,
  358. struct ethtool_coalesce *coal)
  359. {
  360. struct mlx4_en_priv *priv = netdev_priv(dev);
  361. priv->rx_frames = (coal->rx_max_coalesced_frames ==
  362. MLX4_EN_AUTO_CONF) ?
  363. MLX4_EN_RX_COAL_TARGET :
  364. coal->rx_max_coalesced_frames;
  365. priv->rx_usecs = (coal->rx_coalesce_usecs ==
  366. MLX4_EN_AUTO_CONF) ?
  367. MLX4_EN_RX_COAL_TIME :
  368. coal->rx_coalesce_usecs;
  369. /* Setting TX coalescing parameters */
  370. if (coal->tx_coalesce_usecs != priv->tx_usecs ||
  371. coal->tx_max_coalesced_frames != priv->tx_frames) {
  372. priv->tx_usecs = coal->tx_coalesce_usecs;
  373. priv->tx_frames = coal->tx_max_coalesced_frames;
  374. }
  375. /* Set adaptive coalescing params */
  376. priv->pkt_rate_low = coal->pkt_rate_low;
  377. priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
  378. priv->pkt_rate_high = coal->pkt_rate_high;
  379. priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
  380. priv->sample_interval = coal->rate_sample_interval;
  381. priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
  382. return mlx4_en_moderation_update(priv);
  383. }
  384. static int mlx4_en_set_pauseparam(struct net_device *dev,
  385. struct ethtool_pauseparam *pause)
  386. {
  387. struct mlx4_en_priv *priv = netdev_priv(dev);
  388. struct mlx4_en_dev *mdev = priv->mdev;
  389. int err;
  390. priv->prof->tx_pause = pause->tx_pause != 0;
  391. priv->prof->rx_pause = pause->rx_pause != 0;
  392. err = mlx4_SET_PORT_general(mdev->dev, priv->port,
  393. priv->rx_skb_size + ETH_FCS_LEN,
  394. priv->prof->tx_pause,
  395. priv->prof->tx_ppp,
  396. priv->prof->rx_pause,
  397. priv->prof->rx_ppp);
  398. if (err)
  399. en_err(priv, "Failed setting pause params\n");
  400. return err;
  401. }
  402. static void mlx4_en_get_pauseparam(struct net_device *dev,
  403. struct ethtool_pauseparam *pause)
  404. {
  405. struct mlx4_en_priv *priv = netdev_priv(dev);
  406. pause->tx_pause = priv->prof->tx_pause;
  407. pause->rx_pause = priv->prof->rx_pause;
  408. }
  409. static int mlx4_en_set_ringparam(struct net_device *dev,
  410. struct ethtool_ringparam *param)
  411. {
  412. struct mlx4_en_priv *priv = netdev_priv(dev);
  413. struct mlx4_en_dev *mdev = priv->mdev;
  414. u32 rx_size, tx_size;
  415. int port_up = 0;
  416. int err = 0;
  417. if (param->rx_jumbo_pending || param->rx_mini_pending)
  418. return -EINVAL;
  419. rx_size = roundup_pow_of_two(param->rx_pending);
  420. rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE);
  421. rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE);
  422. tx_size = roundup_pow_of_two(param->tx_pending);
  423. tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE);
  424. tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE);
  425. if (rx_size == (priv->port_up ? priv->rx_ring[0].actual_size :
  426. priv->rx_ring[0].size) &&
  427. tx_size == priv->tx_ring[0].size)
  428. return 0;
  429. mutex_lock(&mdev->state_lock);
  430. if (priv->port_up) {
  431. port_up = 1;
  432. mlx4_en_stop_port(dev, 1);
  433. }
  434. mlx4_en_free_resources(priv);
  435. priv->prof->tx_ring_size = tx_size;
  436. priv->prof->rx_ring_size = rx_size;
  437. err = mlx4_en_alloc_resources(priv);
  438. if (err) {
  439. en_err(priv, "Failed reallocating port resources\n");
  440. goto out;
  441. }
  442. if (port_up) {
  443. err = mlx4_en_start_port(dev);
  444. if (err)
  445. en_err(priv, "Failed starting port\n");
  446. }
  447. err = mlx4_en_moderation_update(priv);
  448. out:
  449. mutex_unlock(&mdev->state_lock);
  450. return err;
  451. }
  452. static void mlx4_en_get_ringparam(struct net_device *dev,
  453. struct ethtool_ringparam *param)
  454. {
  455. struct mlx4_en_priv *priv = netdev_priv(dev);
  456. memset(param, 0, sizeof(*param));
  457. param->rx_max_pending = MLX4_EN_MAX_RX_SIZE;
  458. param->tx_max_pending = MLX4_EN_MAX_TX_SIZE;
  459. param->rx_pending = priv->port_up ?
  460. priv->rx_ring[0].actual_size : priv->rx_ring[0].size;
  461. param->tx_pending = priv->tx_ring[0].size;
  462. }
  463. static u32 mlx4_en_get_rxfh_indir_size(struct net_device *dev)
  464. {
  465. struct mlx4_en_priv *priv = netdev_priv(dev);
  466. return priv->rx_ring_num;
  467. }
  468. static int mlx4_en_get_rxfh_indir(struct net_device *dev, u32 *ring_index)
  469. {
  470. struct mlx4_en_priv *priv = netdev_priv(dev);
  471. struct mlx4_en_rss_map *rss_map = &priv->rss_map;
  472. int rss_rings;
  473. size_t n = priv->rx_ring_num;
  474. int err = 0;
  475. rss_rings = priv->prof->rss_rings ?: priv->rx_ring_num;
  476. while (n--) {
  477. ring_index[n] = rss_map->qps[n % rss_rings].qpn -
  478. rss_map->base_qpn;
  479. }
  480. return err;
  481. }
  482. static int mlx4_en_set_rxfh_indir(struct net_device *dev,
  483. const u32 *ring_index)
  484. {
  485. struct mlx4_en_priv *priv = netdev_priv(dev);
  486. struct mlx4_en_dev *mdev = priv->mdev;
  487. int port_up = 0;
  488. int err = 0;
  489. int i;
  490. int rss_rings = 0;
  491. /* Calculate RSS table size and make sure flows are spread evenly
  492. * between rings
  493. */
  494. for (i = 0; i < priv->rx_ring_num; i++) {
  495. if (i > 0 && !ring_index[i] && !rss_rings)
  496. rss_rings = i;
  497. if (ring_index[i] != (i % (rss_rings ?: priv->rx_ring_num)))
  498. return -EINVAL;
  499. }
  500. if (!rss_rings)
  501. rss_rings = priv->rx_ring_num;
  502. /* RSS table size must be an order of 2 */
  503. if (!is_power_of_2(rss_rings))
  504. return -EINVAL;
  505. mutex_lock(&mdev->state_lock);
  506. if (priv->port_up) {
  507. port_up = 1;
  508. mlx4_en_stop_port(dev, 1);
  509. }
  510. priv->prof->rss_rings = rss_rings;
  511. if (port_up) {
  512. err = mlx4_en_start_port(dev);
  513. if (err)
  514. en_err(priv, "Failed starting port\n");
  515. }
  516. mutex_unlock(&mdev->state_lock);
  517. return err;
  518. }
  519. #define all_zeros_or_all_ones(field) \
  520. ((field) == 0 || (field) == (__force typeof(field))-1)
  521. static int mlx4_en_validate_flow(struct net_device *dev,
  522. struct ethtool_rxnfc *cmd)
  523. {
  524. struct ethtool_usrip4_spec *l3_mask;
  525. struct ethtool_tcpip4_spec *l4_mask;
  526. struct ethhdr *eth_mask;
  527. if (cmd->fs.location >= MAX_NUM_OF_FS_RULES)
  528. return -EINVAL;
  529. if (cmd->fs.flow_type & FLOW_MAC_EXT) {
  530. /* dest mac mask must be ff:ff:ff:ff:ff:ff */
  531. if (!is_broadcast_ether_addr(cmd->fs.m_ext.h_dest))
  532. return -EINVAL;
  533. }
  534. switch (cmd->fs.flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
  535. case TCP_V4_FLOW:
  536. case UDP_V4_FLOW:
  537. if (cmd->fs.m_u.tcp_ip4_spec.tos)
  538. return -EINVAL;
  539. l4_mask = &cmd->fs.m_u.tcp_ip4_spec;
  540. /* don't allow mask which isn't all 0 or 1 */
  541. if (!all_zeros_or_all_ones(l4_mask->ip4src) ||
  542. !all_zeros_or_all_ones(l4_mask->ip4dst) ||
  543. !all_zeros_or_all_ones(l4_mask->psrc) ||
  544. !all_zeros_or_all_ones(l4_mask->pdst))
  545. return -EINVAL;
  546. break;
  547. case IP_USER_FLOW:
  548. l3_mask = &cmd->fs.m_u.usr_ip4_spec;
  549. if (l3_mask->l4_4_bytes || l3_mask->tos || l3_mask->proto ||
  550. cmd->fs.h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4 ||
  551. (!l3_mask->ip4src && !l3_mask->ip4dst) ||
  552. !all_zeros_or_all_ones(l3_mask->ip4src) ||
  553. !all_zeros_or_all_ones(l3_mask->ip4dst))
  554. return -EINVAL;
  555. break;
  556. case ETHER_FLOW:
  557. eth_mask = &cmd->fs.m_u.ether_spec;
  558. /* source mac mask must not be set */
  559. if (!is_zero_ether_addr(eth_mask->h_source))
  560. return -EINVAL;
  561. /* dest mac mask must be ff:ff:ff:ff:ff:ff */
  562. if (!is_broadcast_ether_addr(eth_mask->h_dest))
  563. return -EINVAL;
  564. if (!all_zeros_or_all_ones(eth_mask->h_proto))
  565. return -EINVAL;
  566. break;
  567. default:
  568. return -EINVAL;
  569. }
  570. if ((cmd->fs.flow_type & FLOW_EXT)) {
  571. if (cmd->fs.m_ext.vlan_etype ||
  572. !((cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK)) ==
  573. 0 ||
  574. (cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK)) ==
  575. cpu_to_be16(VLAN_VID_MASK)))
  576. return -EINVAL;
  577. if (cmd->fs.m_ext.vlan_tci) {
  578. if (be16_to_cpu(cmd->fs.h_ext.vlan_tci) >= VLAN_N_VID)
  579. return -EINVAL;
  580. }
  581. }
  582. return 0;
  583. }
  584. static int mlx4_en_ethtool_add_mac_rule(struct ethtool_rxnfc *cmd,
  585. struct list_head *rule_list_h,
  586. struct mlx4_spec_list *spec_l2,
  587. unsigned char *mac)
  588. {
  589. int err = 0;
  590. __be64 mac_msk = cpu_to_be64(MLX4_MAC_MASK << 16);
  591. spec_l2->id = MLX4_NET_TRANS_RULE_ID_ETH;
  592. memcpy(spec_l2->eth.dst_mac_msk, &mac_msk, ETH_ALEN);
  593. memcpy(spec_l2->eth.dst_mac, mac, ETH_ALEN);
  594. if ((cmd->fs.flow_type & FLOW_EXT) &&
  595. (cmd->fs.m_ext.vlan_tci & cpu_to_be16(VLAN_VID_MASK))) {
  596. spec_l2->eth.vlan_id = cmd->fs.h_ext.vlan_tci;
  597. spec_l2->eth.vlan_id_msk = cpu_to_be16(VLAN_VID_MASK);
  598. }
  599. list_add_tail(&spec_l2->list, rule_list_h);
  600. return err;
  601. }
  602. static int mlx4_en_ethtool_add_mac_rule_by_ipv4(struct mlx4_en_priv *priv,
  603. struct ethtool_rxnfc *cmd,
  604. struct list_head *rule_list_h,
  605. struct mlx4_spec_list *spec_l2,
  606. __be32 ipv4_dst)
  607. {
  608. #ifdef CONFIG_INET
  609. __be64 be_mac = 0;
  610. unsigned char mac[ETH_ALEN];
  611. if (!ipv4_is_multicast(ipv4_dst)) {
  612. if (cmd->fs.flow_type & FLOW_MAC_EXT) {
  613. memcpy(&mac, cmd->fs.h_ext.h_dest, ETH_ALEN);
  614. } else {
  615. be_mac = cpu_to_be64((priv->mac & MLX4_MAC_MASK) << 16);
  616. memcpy(&mac, &be_mac, ETH_ALEN);
  617. }
  618. } else {
  619. ip_eth_mc_map(ipv4_dst, mac);
  620. }
  621. return mlx4_en_ethtool_add_mac_rule(cmd, rule_list_h, spec_l2, &mac[0]);
  622. #else
  623. return -EINVAL;
  624. #endif
  625. }
  626. static int add_ip_rule(struct mlx4_en_priv *priv,
  627. struct ethtool_rxnfc *cmd,
  628. struct list_head *list_h)
  629. {
  630. int err;
  631. struct mlx4_spec_list *spec_l2 = NULL;
  632. struct mlx4_spec_list *spec_l3 = NULL;
  633. struct ethtool_usrip4_spec *l3_mask = &cmd->fs.m_u.usr_ip4_spec;
  634. spec_l3 = kzalloc(sizeof(*spec_l3), GFP_KERNEL);
  635. spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
  636. if (!spec_l2 || !spec_l3) {
  637. en_err(priv, "Fail to alloc ethtool rule.\n");
  638. err = -ENOMEM;
  639. goto free_spec;
  640. }
  641. err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h, spec_l2,
  642. cmd->fs.h_u.
  643. usr_ip4_spec.ip4dst);
  644. if (err)
  645. goto free_spec;
  646. spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4;
  647. spec_l3->ipv4.src_ip = cmd->fs.h_u.usr_ip4_spec.ip4src;
  648. if (l3_mask->ip4src)
  649. spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK;
  650. spec_l3->ipv4.dst_ip = cmd->fs.h_u.usr_ip4_spec.ip4dst;
  651. if (l3_mask->ip4dst)
  652. spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK;
  653. list_add_tail(&spec_l3->list, list_h);
  654. return 0;
  655. free_spec:
  656. kfree(spec_l2);
  657. kfree(spec_l3);
  658. return err;
  659. }
  660. static int add_tcp_udp_rule(struct mlx4_en_priv *priv,
  661. struct ethtool_rxnfc *cmd,
  662. struct list_head *list_h, int proto)
  663. {
  664. int err;
  665. struct mlx4_spec_list *spec_l2 = NULL;
  666. struct mlx4_spec_list *spec_l3 = NULL;
  667. struct mlx4_spec_list *spec_l4 = NULL;
  668. struct ethtool_tcpip4_spec *l4_mask = &cmd->fs.m_u.tcp_ip4_spec;
  669. spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
  670. spec_l3 = kzalloc(sizeof(*spec_l3), GFP_KERNEL);
  671. spec_l4 = kzalloc(sizeof(*spec_l4), GFP_KERNEL);
  672. if (!spec_l2 || !spec_l3 || !spec_l4) {
  673. en_err(priv, "Fail to alloc ethtool rule.\n");
  674. err = -ENOMEM;
  675. goto free_spec;
  676. }
  677. spec_l3->id = MLX4_NET_TRANS_RULE_ID_IPV4;
  678. if (proto == TCP_V4_FLOW) {
  679. err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h,
  680. spec_l2,
  681. cmd->fs.h_u.
  682. tcp_ip4_spec.ip4dst);
  683. if (err)
  684. goto free_spec;
  685. spec_l4->id = MLX4_NET_TRANS_RULE_ID_TCP;
  686. spec_l3->ipv4.src_ip = cmd->fs.h_u.tcp_ip4_spec.ip4src;
  687. spec_l3->ipv4.dst_ip = cmd->fs.h_u.tcp_ip4_spec.ip4dst;
  688. spec_l4->tcp_udp.src_port = cmd->fs.h_u.tcp_ip4_spec.psrc;
  689. spec_l4->tcp_udp.dst_port = cmd->fs.h_u.tcp_ip4_spec.pdst;
  690. } else {
  691. err = mlx4_en_ethtool_add_mac_rule_by_ipv4(priv, cmd, list_h,
  692. spec_l2,
  693. cmd->fs.h_u.
  694. udp_ip4_spec.ip4dst);
  695. if (err)
  696. goto free_spec;
  697. spec_l4->id = MLX4_NET_TRANS_RULE_ID_UDP;
  698. spec_l3->ipv4.src_ip = cmd->fs.h_u.udp_ip4_spec.ip4src;
  699. spec_l3->ipv4.dst_ip = cmd->fs.h_u.udp_ip4_spec.ip4dst;
  700. spec_l4->tcp_udp.src_port = cmd->fs.h_u.udp_ip4_spec.psrc;
  701. spec_l4->tcp_udp.dst_port = cmd->fs.h_u.udp_ip4_spec.pdst;
  702. }
  703. if (l4_mask->ip4src)
  704. spec_l3->ipv4.src_ip_msk = EN_ETHTOOL_WORD_MASK;
  705. if (l4_mask->ip4dst)
  706. spec_l3->ipv4.dst_ip_msk = EN_ETHTOOL_WORD_MASK;
  707. if (l4_mask->psrc)
  708. spec_l4->tcp_udp.src_port_msk = EN_ETHTOOL_SHORT_MASK;
  709. if (l4_mask->pdst)
  710. spec_l4->tcp_udp.dst_port_msk = EN_ETHTOOL_SHORT_MASK;
  711. list_add_tail(&spec_l3->list, list_h);
  712. list_add_tail(&spec_l4->list, list_h);
  713. return 0;
  714. free_spec:
  715. kfree(spec_l2);
  716. kfree(spec_l3);
  717. kfree(spec_l4);
  718. return err;
  719. }
  720. static int mlx4_en_ethtool_to_net_trans_rule(struct net_device *dev,
  721. struct ethtool_rxnfc *cmd,
  722. struct list_head *rule_list_h)
  723. {
  724. int err;
  725. struct ethhdr *eth_spec;
  726. struct mlx4_spec_list *spec_l2;
  727. struct mlx4_en_priv *priv = netdev_priv(dev);
  728. err = mlx4_en_validate_flow(dev, cmd);
  729. if (err)
  730. return err;
  731. switch (cmd->fs.flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
  732. case ETHER_FLOW:
  733. spec_l2 = kzalloc(sizeof(*spec_l2), GFP_KERNEL);
  734. if (!spec_l2)
  735. return -ENOMEM;
  736. eth_spec = &cmd->fs.h_u.ether_spec;
  737. mlx4_en_ethtool_add_mac_rule(cmd, rule_list_h, spec_l2,
  738. &eth_spec->h_dest[0]);
  739. spec_l2->eth.ether_type = eth_spec->h_proto;
  740. if (eth_spec->h_proto)
  741. spec_l2->eth.ether_type_enable = 1;
  742. break;
  743. case IP_USER_FLOW:
  744. err = add_ip_rule(priv, cmd, rule_list_h);
  745. break;
  746. case TCP_V4_FLOW:
  747. err = add_tcp_udp_rule(priv, cmd, rule_list_h, TCP_V4_FLOW);
  748. break;
  749. case UDP_V4_FLOW:
  750. err = add_tcp_udp_rule(priv, cmd, rule_list_h, UDP_V4_FLOW);
  751. break;
  752. }
  753. return err;
  754. }
  755. static int mlx4_en_flow_replace(struct net_device *dev,
  756. struct ethtool_rxnfc *cmd)
  757. {
  758. int err;
  759. struct mlx4_en_priv *priv = netdev_priv(dev);
  760. struct ethtool_flow_id *loc_rule;
  761. struct mlx4_spec_list *spec, *tmp_spec;
  762. u32 qpn;
  763. u64 reg_id;
  764. struct mlx4_net_trans_rule rule = {
  765. .queue_mode = MLX4_NET_TRANS_Q_FIFO,
  766. .exclusive = 0,
  767. .allow_loopback = 1,
  768. .promisc_mode = MLX4_FS_PROMISC_NONE,
  769. };
  770. rule.port = priv->port;
  771. rule.priority = MLX4_DOMAIN_ETHTOOL | cmd->fs.location;
  772. INIT_LIST_HEAD(&rule.list);
  773. /* Allow direct QP attaches if the EN_ETHTOOL_QP_ATTACH flag is set */
  774. if (cmd->fs.ring_cookie == RX_CLS_FLOW_DISC)
  775. qpn = priv->drop_qp.qpn;
  776. else if (cmd->fs.ring_cookie & EN_ETHTOOL_QP_ATTACH) {
  777. qpn = cmd->fs.ring_cookie & (EN_ETHTOOL_QP_ATTACH - 1);
  778. } else {
  779. if (cmd->fs.ring_cookie >= priv->rx_ring_num) {
  780. en_warn(priv, "rxnfc: RX ring (%llu) doesn't exist.\n",
  781. cmd->fs.ring_cookie);
  782. return -EINVAL;
  783. }
  784. qpn = priv->rss_map.qps[cmd->fs.ring_cookie].qpn;
  785. if (!qpn) {
  786. en_warn(priv, "rxnfc: RX ring (%llu) is inactive.\n",
  787. cmd->fs.ring_cookie);
  788. return -EINVAL;
  789. }
  790. }
  791. rule.qpn = qpn;
  792. err = mlx4_en_ethtool_to_net_trans_rule(dev, cmd, &rule.list);
  793. if (err)
  794. goto out_free_list;
  795. loc_rule = &priv->ethtool_rules[cmd->fs.location];
  796. if (loc_rule->id) {
  797. err = mlx4_flow_detach(priv->mdev->dev, loc_rule->id);
  798. if (err) {
  799. en_err(priv, "Fail to detach network rule at location %d. registration id = %llx\n",
  800. cmd->fs.location, loc_rule->id);
  801. goto out_free_list;
  802. }
  803. loc_rule->id = 0;
  804. memset(&loc_rule->flow_spec, 0,
  805. sizeof(struct ethtool_rx_flow_spec));
  806. list_del(&loc_rule->list);
  807. }
  808. err = mlx4_flow_attach(priv->mdev->dev, &rule, &reg_id);
  809. if (err) {
  810. en_err(priv, "Fail to attach network rule at location %d.\n",
  811. cmd->fs.location);
  812. goto out_free_list;
  813. }
  814. loc_rule->id = reg_id;
  815. memcpy(&loc_rule->flow_spec, &cmd->fs,
  816. sizeof(struct ethtool_rx_flow_spec));
  817. list_add_tail(&loc_rule->list, &priv->ethtool_list);
  818. out_free_list:
  819. list_for_each_entry_safe(spec, tmp_spec, &rule.list, list) {
  820. list_del(&spec->list);
  821. kfree(spec);
  822. }
  823. return err;
  824. }
  825. static int mlx4_en_flow_detach(struct net_device *dev,
  826. struct ethtool_rxnfc *cmd)
  827. {
  828. int err = 0;
  829. struct ethtool_flow_id *rule;
  830. struct mlx4_en_priv *priv = netdev_priv(dev);
  831. if (cmd->fs.location >= MAX_NUM_OF_FS_RULES)
  832. return -EINVAL;
  833. rule = &priv->ethtool_rules[cmd->fs.location];
  834. if (!rule->id) {
  835. err = -ENOENT;
  836. goto out;
  837. }
  838. err = mlx4_flow_detach(priv->mdev->dev, rule->id);
  839. if (err) {
  840. en_err(priv, "Fail to detach network rule at location %d. registration id = 0x%llx\n",
  841. cmd->fs.location, rule->id);
  842. goto out;
  843. }
  844. rule->id = 0;
  845. memset(&rule->flow_spec, 0, sizeof(struct ethtool_rx_flow_spec));
  846. list_del(&rule->list);
  847. out:
  848. return err;
  849. }
  850. static int mlx4_en_get_flow(struct net_device *dev, struct ethtool_rxnfc *cmd,
  851. int loc)
  852. {
  853. int err = 0;
  854. struct ethtool_flow_id *rule;
  855. struct mlx4_en_priv *priv = netdev_priv(dev);
  856. if (loc < 0 || loc >= MAX_NUM_OF_FS_RULES)
  857. return -EINVAL;
  858. rule = &priv->ethtool_rules[loc];
  859. if (rule->id)
  860. memcpy(&cmd->fs, &rule->flow_spec,
  861. sizeof(struct ethtool_rx_flow_spec));
  862. else
  863. err = -ENOENT;
  864. return err;
  865. }
  866. static int mlx4_en_get_num_flows(struct mlx4_en_priv *priv)
  867. {
  868. int i, res = 0;
  869. for (i = 0; i < MAX_NUM_OF_FS_RULES; i++) {
  870. if (priv->ethtool_rules[i].id)
  871. res++;
  872. }
  873. return res;
  874. }
  875. static int mlx4_en_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
  876. u32 *rule_locs)
  877. {
  878. struct mlx4_en_priv *priv = netdev_priv(dev);
  879. struct mlx4_en_dev *mdev = priv->mdev;
  880. int err = 0;
  881. int i = 0, priority = 0;
  882. if ((cmd->cmd == ETHTOOL_GRXCLSRLCNT ||
  883. cmd->cmd == ETHTOOL_GRXCLSRULE ||
  884. cmd->cmd == ETHTOOL_GRXCLSRLALL) &&
  885. (mdev->dev->caps.steering_mode !=
  886. MLX4_STEERING_MODE_DEVICE_MANAGED || !priv->port_up))
  887. return -EINVAL;
  888. switch (cmd->cmd) {
  889. case ETHTOOL_GRXRINGS:
  890. cmd->data = priv->rx_ring_num;
  891. break;
  892. case ETHTOOL_GRXCLSRLCNT:
  893. cmd->rule_cnt = mlx4_en_get_num_flows(priv);
  894. break;
  895. case ETHTOOL_GRXCLSRULE:
  896. err = mlx4_en_get_flow(dev, cmd, cmd->fs.location);
  897. break;
  898. case ETHTOOL_GRXCLSRLALL:
  899. while ((!err || err == -ENOENT) && priority < cmd->rule_cnt) {
  900. err = mlx4_en_get_flow(dev, cmd, i);
  901. if (!err)
  902. rule_locs[priority++] = i;
  903. i++;
  904. }
  905. err = 0;
  906. break;
  907. default:
  908. err = -EOPNOTSUPP;
  909. break;
  910. }
  911. return err;
  912. }
  913. static int mlx4_en_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
  914. {
  915. int err = 0;
  916. struct mlx4_en_priv *priv = netdev_priv(dev);
  917. struct mlx4_en_dev *mdev = priv->mdev;
  918. if (mdev->dev->caps.steering_mode !=
  919. MLX4_STEERING_MODE_DEVICE_MANAGED || !priv->port_up)
  920. return -EINVAL;
  921. switch (cmd->cmd) {
  922. case ETHTOOL_SRXCLSRLINS:
  923. err = mlx4_en_flow_replace(dev, cmd);
  924. break;
  925. case ETHTOOL_SRXCLSRLDEL:
  926. err = mlx4_en_flow_detach(dev, cmd);
  927. break;
  928. default:
  929. en_warn(priv, "Unsupported ethtool command. (%d)\n", cmd->cmd);
  930. return -EINVAL;
  931. }
  932. return err;
  933. }
  934. static void mlx4_en_get_channels(struct net_device *dev,
  935. struct ethtool_channels *channel)
  936. {
  937. struct mlx4_en_priv *priv = netdev_priv(dev);
  938. memset(channel, 0, sizeof(*channel));
  939. channel->max_rx = MAX_RX_RINGS;
  940. channel->max_tx = MLX4_EN_MAX_TX_RING_P_UP;
  941. channel->rx_count = priv->rx_ring_num;
  942. channel->tx_count = priv->tx_ring_num / MLX4_EN_NUM_UP;
  943. }
  944. static int mlx4_en_set_channels(struct net_device *dev,
  945. struct ethtool_channels *channel)
  946. {
  947. struct mlx4_en_priv *priv = netdev_priv(dev);
  948. struct mlx4_en_dev *mdev = priv->mdev;
  949. int port_up;
  950. int err = 0;
  951. if (channel->other_count || channel->combined_count ||
  952. channel->tx_count > MLX4_EN_MAX_TX_RING_P_UP ||
  953. channel->rx_count > MAX_RX_RINGS ||
  954. !channel->tx_count || !channel->rx_count)
  955. return -EINVAL;
  956. mutex_lock(&mdev->state_lock);
  957. if (priv->port_up) {
  958. port_up = 1;
  959. mlx4_en_stop_port(dev, 1);
  960. }
  961. mlx4_en_free_resources(priv);
  962. priv->num_tx_rings_p_up = channel->tx_count;
  963. priv->tx_ring_num = channel->tx_count * MLX4_EN_NUM_UP;
  964. priv->rx_ring_num = channel->rx_count;
  965. err = mlx4_en_alloc_resources(priv);
  966. if (err) {
  967. en_err(priv, "Failed reallocating port resources\n");
  968. goto out;
  969. }
  970. netif_set_real_num_tx_queues(dev, priv->tx_ring_num);
  971. netif_set_real_num_rx_queues(dev, priv->rx_ring_num);
  972. mlx4_en_setup_tc(dev, MLX4_EN_NUM_UP);
  973. en_warn(priv, "Using %d TX rings\n", priv->tx_ring_num);
  974. en_warn(priv, "Using %d RX rings\n", priv->rx_ring_num);
  975. if (port_up) {
  976. err = mlx4_en_start_port(dev);
  977. if (err)
  978. en_err(priv, "Failed starting port\n");
  979. }
  980. err = mlx4_en_moderation_update(priv);
  981. out:
  982. mutex_unlock(&mdev->state_lock);
  983. return err;
  984. }
  985. const struct ethtool_ops mlx4_en_ethtool_ops = {
  986. .get_drvinfo = mlx4_en_get_drvinfo,
  987. .get_settings = mlx4_en_get_settings,
  988. .set_settings = mlx4_en_set_settings,
  989. .get_link = ethtool_op_get_link,
  990. .get_strings = mlx4_en_get_strings,
  991. .get_sset_count = mlx4_en_get_sset_count,
  992. .get_ethtool_stats = mlx4_en_get_ethtool_stats,
  993. .self_test = mlx4_en_self_test,
  994. .get_wol = mlx4_en_get_wol,
  995. .set_wol = mlx4_en_set_wol,
  996. .get_msglevel = mlx4_en_get_msglevel,
  997. .set_msglevel = mlx4_en_set_msglevel,
  998. .get_coalesce = mlx4_en_get_coalesce,
  999. .set_coalesce = mlx4_en_set_coalesce,
  1000. .get_pauseparam = mlx4_en_get_pauseparam,
  1001. .set_pauseparam = mlx4_en_set_pauseparam,
  1002. .get_ringparam = mlx4_en_get_ringparam,
  1003. .set_ringparam = mlx4_en_set_ringparam,
  1004. .get_rxnfc = mlx4_en_get_rxnfc,
  1005. .set_rxnfc = mlx4_en_set_rxnfc,
  1006. .get_rxfh_indir_size = mlx4_en_get_rxfh_indir_size,
  1007. .get_rxfh_indir = mlx4_en_get_rxfh_indir,
  1008. .set_rxfh_indir = mlx4_en_set_rxfh_indir,
  1009. .get_channels = mlx4_en_get_channels,
  1010. .set_channels = mlx4_en_set_channels,
  1011. };