en_ethtool.c 32 KB

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