en_ethtool.c 32 KB

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