en_ethtool.c 35 KB

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