en_params.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /*
  2. * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. #include <linux/kernel.h>
  34. #include <linux/ethtool.h>
  35. #include <linux/netdevice.h>
  36. #include "mlx4_en.h"
  37. #include "en_port.h"
  38. #define MLX4_EN_PARM_INT(X, def_val, desc) \
  39. static unsigned int X = def_val;\
  40. module_param(X , uint, 0444); \
  41. MODULE_PARM_DESC(X, desc);
  42. /*
  43. * Device scope module parameters
  44. */
  45. /* Use a XOR rathern than Toeplitz hash function for RSS */
  46. MLX4_EN_PARM_INT(rss_xor, 0, "Use XOR hash function for RSS");
  47. /* RSS hash type mask - default to <saddr, daddr, sport, dport> */
  48. MLX4_EN_PARM_INT(rss_mask, 0xf, "RSS hash type bitmask");
  49. /* Number of LRO sessions per Rx ring (rounded up to a power of two) */
  50. MLX4_EN_PARM_INT(num_lro, MLX4_EN_MAX_LRO_DESCRIPTORS,
  51. "Number of LRO sessions per ring or disabled (0)");
  52. /* Priority pausing */
  53. MLX4_EN_PARM_INT(pfctx, 0, "Priority based Flow Control policy on TX[7:0]."
  54. " Per priority bit mask");
  55. MLX4_EN_PARM_INT(pfcrx, 0, "Priority based Flow Control policy on RX[7:0]."
  56. " Per priority bit mask");
  57. MLX4_EN_PARM_INT(rx_ring_num1, 0, "Number or Rx rings for port 1 (0 = #cores)");
  58. MLX4_EN_PARM_INT(rx_ring_num2, 0, "Number or Rx rings for port 2 (0 = #cores)");
  59. MLX4_EN_PARM_INT(tx_ring_size1, MLX4_EN_AUTO_CONF, "Tx ring size for port 1");
  60. MLX4_EN_PARM_INT(tx_ring_size2, MLX4_EN_AUTO_CONF, "Tx ring size for port 2");
  61. MLX4_EN_PARM_INT(rx_ring_size1, MLX4_EN_AUTO_CONF, "Rx ring size for port 1");
  62. MLX4_EN_PARM_INT(rx_ring_size2, MLX4_EN_AUTO_CONF, "Rx ring size for port 2");
  63. int mlx4_en_get_profile(struct mlx4_en_dev *mdev)
  64. {
  65. struct mlx4_en_profile *params = &mdev->profile;
  66. int i;
  67. params->rss_xor = (rss_xor != 0);
  68. params->rss_mask = rss_mask & 0x1f;
  69. params->num_lro = min_t(int, num_lro , MLX4_EN_MAX_LRO_DESCRIPTORS);
  70. for (i = 1; i <= MLX4_MAX_PORTS; i++) {
  71. params->prof[i].rx_pause = 1;
  72. params->prof[i].rx_ppp = pfcrx;
  73. params->prof[i].tx_pause = 1;
  74. params->prof[i].tx_ppp = pfctx;
  75. }
  76. if (pfcrx || pfctx) {
  77. params->prof[1].tx_ring_num = MLX4_EN_TX_RING_NUM;
  78. params->prof[2].tx_ring_num = MLX4_EN_TX_RING_NUM;
  79. } else {
  80. params->prof[1].tx_ring_num = 1;
  81. params->prof[2].tx_ring_num = 1;
  82. }
  83. params->prof[1].rx_ring_num = min_t(int, rx_ring_num1, MAX_RX_RINGS);
  84. params->prof[2].rx_ring_num = min_t(int, rx_ring_num2, MAX_RX_RINGS);
  85. if (tx_ring_size1 == MLX4_EN_AUTO_CONF)
  86. tx_ring_size1 = MLX4_EN_DEF_TX_RING_SIZE;
  87. params->prof[1].tx_ring_size =
  88. (tx_ring_size1 < MLX4_EN_MIN_TX_SIZE) ?
  89. MLX4_EN_MIN_TX_SIZE : roundup_pow_of_two(tx_ring_size1);
  90. if (tx_ring_size2 == MLX4_EN_AUTO_CONF)
  91. tx_ring_size2 = MLX4_EN_DEF_TX_RING_SIZE;
  92. params->prof[2].tx_ring_size =
  93. (tx_ring_size2 < MLX4_EN_MIN_TX_SIZE) ?
  94. MLX4_EN_MIN_TX_SIZE : roundup_pow_of_two(tx_ring_size2);
  95. if (rx_ring_size1 == MLX4_EN_AUTO_CONF)
  96. rx_ring_size1 = MLX4_EN_DEF_RX_RING_SIZE;
  97. params->prof[1].rx_ring_size =
  98. (rx_ring_size1 < MLX4_EN_MIN_RX_SIZE) ?
  99. MLX4_EN_MIN_RX_SIZE : roundup_pow_of_two(rx_ring_size1);
  100. if (rx_ring_size2 == MLX4_EN_AUTO_CONF)
  101. rx_ring_size2 = MLX4_EN_DEF_RX_RING_SIZE;
  102. params->prof[2].rx_ring_size =
  103. (rx_ring_size2 < MLX4_EN_MIN_RX_SIZE) ?
  104. MLX4_EN_MIN_RX_SIZE : roundup_pow_of_two(rx_ring_size2);
  105. return 0;
  106. }
  107. /*
  108. * Ethtool support
  109. */
  110. static void mlx4_en_update_lro_stats(struct mlx4_en_priv *priv)
  111. {
  112. int i;
  113. priv->port_stats.lro_aggregated = 0;
  114. priv->port_stats.lro_flushed = 0;
  115. priv->port_stats.lro_no_desc = 0;
  116. for (i = 0; i < priv->rx_ring_num; i++) {
  117. priv->port_stats.lro_aggregated += priv->rx_ring[i].lro.stats.aggregated;
  118. priv->port_stats.lro_flushed += priv->rx_ring[i].lro.stats.flushed;
  119. priv->port_stats.lro_no_desc += priv->rx_ring[i].lro.stats.no_desc;
  120. }
  121. }
  122. static void
  123. mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
  124. {
  125. struct mlx4_en_priv *priv = netdev_priv(dev);
  126. struct mlx4_en_dev *mdev = priv->mdev;
  127. sprintf(drvinfo->driver, DRV_NAME " (%s)", mdev->dev->board_id);
  128. strncpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")", 32);
  129. sprintf(drvinfo->fw_version, "%d.%d.%d",
  130. (u16) (mdev->dev->caps.fw_ver >> 32),
  131. (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff),
  132. (u16) (mdev->dev->caps.fw_ver & 0xffff));
  133. strncpy(drvinfo->bus_info, pci_name(mdev->dev->pdev), 32);
  134. drvinfo->n_stats = 0;
  135. drvinfo->regdump_len = 0;
  136. drvinfo->eedump_len = 0;
  137. }
  138. static u32 mlx4_en_get_tso(struct net_device *dev)
  139. {
  140. return (dev->features & NETIF_F_TSO) != 0;
  141. }
  142. static int mlx4_en_set_tso(struct net_device *dev, u32 data)
  143. {
  144. struct mlx4_en_priv *priv = netdev_priv(dev);
  145. if (data) {
  146. if (!priv->mdev->LSO_support)
  147. return -EPERM;
  148. dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
  149. } else
  150. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
  151. return 0;
  152. }
  153. static u32 mlx4_en_get_rx_csum(struct net_device *dev)
  154. {
  155. struct mlx4_en_priv *priv = netdev_priv(dev);
  156. return priv->rx_csum;
  157. }
  158. static int mlx4_en_set_rx_csum(struct net_device *dev, u32 data)
  159. {
  160. struct mlx4_en_priv *priv = netdev_priv(dev);
  161. priv->rx_csum = (data != 0);
  162. return 0;
  163. }
  164. static const char main_strings[][ETH_GSTRING_LEN] = {
  165. "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
  166. "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
  167. "rx_length_errors", "rx_over_errors", "rx_crc_errors",
  168. "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
  169. "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
  170. "tx_heartbeat_errors", "tx_window_errors",
  171. /* port statistics */
  172. "lro_aggregated", "lro_flushed", "lro_no_desc", "tso_packets",
  173. "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed",
  174. "rx_csum_good", "rx_csum_none", "tx_chksum_offload",
  175. /* packet statistics */
  176. "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3",
  177. "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0",
  178. "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5",
  179. "tx_prio_6", "tx_prio_7",
  180. };
  181. #define NUM_MAIN_STATS 21
  182. #define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
  183. static u32 mlx4_en_get_msglevel(struct net_device *dev)
  184. {
  185. return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
  186. }
  187. static void mlx4_en_set_msglevel(struct net_device *dev, u32 val)
  188. {
  189. ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val;
  190. }
  191. static void mlx4_en_get_wol(struct net_device *netdev,
  192. struct ethtool_wolinfo *wol)
  193. {
  194. wol->supported = 0;
  195. wol->wolopts = 0;
  196. return;
  197. }
  198. static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
  199. {
  200. struct mlx4_en_priv *priv = netdev_priv(dev);
  201. if (sset != ETH_SS_STATS)
  202. return -EOPNOTSUPP;
  203. return NUM_ALL_STATS + (priv->tx_ring_num + priv->rx_ring_num) * 2;
  204. }
  205. static void mlx4_en_get_ethtool_stats(struct net_device *dev,
  206. struct ethtool_stats *stats, uint64_t *data)
  207. {
  208. struct mlx4_en_priv *priv = netdev_priv(dev);
  209. int index = 0;
  210. int i;
  211. spin_lock_bh(&priv->stats_lock);
  212. mlx4_en_update_lro_stats(priv);
  213. for (i = 0; i < NUM_MAIN_STATS; i++)
  214. data[index++] = ((unsigned long *) &priv->stats)[i];
  215. for (i = 0; i < NUM_PORT_STATS; i++)
  216. data[index++] = ((unsigned long *) &priv->port_stats)[i];
  217. for (i = 0; i < priv->tx_ring_num; i++) {
  218. data[index++] = priv->tx_ring[i].packets;
  219. data[index++] = priv->tx_ring[i].bytes;
  220. }
  221. for (i = 0; i < priv->rx_ring_num; i++) {
  222. data[index++] = priv->rx_ring[i].packets;
  223. data[index++] = priv->rx_ring[i].bytes;
  224. }
  225. for (i = 0; i < NUM_PKT_STATS; i++)
  226. data[index++] = ((unsigned long *) &priv->pkstats)[i];
  227. spin_unlock_bh(&priv->stats_lock);
  228. }
  229. static void mlx4_en_get_strings(struct net_device *dev,
  230. uint32_t stringset, uint8_t *data)
  231. {
  232. struct mlx4_en_priv *priv = netdev_priv(dev);
  233. int index = 0;
  234. int i;
  235. if (stringset != ETH_SS_STATS)
  236. return;
  237. /* Add main counters */
  238. for (i = 0; i < NUM_MAIN_STATS; i++)
  239. strcpy(data + (index++) * ETH_GSTRING_LEN, main_strings[i]);
  240. for (i = 0; i < NUM_PORT_STATS; i++)
  241. strcpy(data + (index++) * ETH_GSTRING_LEN,
  242. main_strings[i + NUM_MAIN_STATS]);
  243. for (i = 0; i < priv->tx_ring_num; i++) {
  244. sprintf(data + (index++) * ETH_GSTRING_LEN,
  245. "tx%d_packets", i);
  246. sprintf(data + (index++) * ETH_GSTRING_LEN,
  247. "tx%d_bytes", i);
  248. }
  249. for (i = 0; i < priv->rx_ring_num; i++) {
  250. sprintf(data + (index++) * ETH_GSTRING_LEN,
  251. "rx%d_packets", i);
  252. sprintf(data + (index++) * ETH_GSTRING_LEN,
  253. "rx%d_bytes", i);
  254. }
  255. for (i = 0; i < NUM_PKT_STATS; i++)
  256. strcpy(data + (index++) * ETH_GSTRING_LEN,
  257. main_strings[i + NUM_MAIN_STATS + NUM_PORT_STATS]);
  258. }
  259. static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  260. {
  261. cmd->autoneg = AUTONEG_DISABLE;
  262. cmd->supported = SUPPORTED_10000baseT_Full;
  263. cmd->advertising = SUPPORTED_10000baseT_Full;
  264. if (netif_carrier_ok(dev)) {
  265. cmd->speed = SPEED_10000;
  266. cmd->duplex = DUPLEX_FULL;
  267. } else {
  268. cmd->speed = -1;
  269. cmd->duplex = -1;
  270. }
  271. return 0;
  272. }
  273. static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  274. {
  275. if ((cmd->autoneg == AUTONEG_ENABLE) ||
  276. (cmd->speed != SPEED_10000) || (cmd->duplex != DUPLEX_FULL))
  277. return -EINVAL;
  278. /* Nothing to change */
  279. return 0;
  280. }
  281. static int mlx4_en_get_coalesce(struct net_device *dev,
  282. struct ethtool_coalesce *coal)
  283. {
  284. struct mlx4_en_priv *priv = netdev_priv(dev);
  285. coal->tx_coalesce_usecs = 0;
  286. coal->tx_max_coalesced_frames = 0;
  287. coal->rx_coalesce_usecs = priv->rx_usecs;
  288. coal->rx_max_coalesced_frames = priv->rx_frames;
  289. coal->pkt_rate_low = priv->pkt_rate_low;
  290. coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
  291. coal->pkt_rate_high = priv->pkt_rate_high;
  292. coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
  293. coal->rate_sample_interval = priv->sample_interval;
  294. coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
  295. return 0;
  296. }
  297. static int mlx4_en_set_coalesce(struct net_device *dev,
  298. struct ethtool_coalesce *coal)
  299. {
  300. struct mlx4_en_priv *priv = netdev_priv(dev);
  301. int err, i;
  302. priv->rx_frames = (coal->rx_max_coalesced_frames ==
  303. MLX4_EN_AUTO_CONF) ?
  304. MLX4_EN_RX_COAL_TARGET /
  305. priv->dev->mtu + 1 :
  306. coal->rx_max_coalesced_frames;
  307. priv->rx_usecs = (coal->rx_coalesce_usecs ==
  308. MLX4_EN_AUTO_CONF) ?
  309. MLX4_EN_RX_COAL_TIME :
  310. coal->rx_coalesce_usecs;
  311. /* Set adaptive coalescing params */
  312. priv->pkt_rate_low = coal->pkt_rate_low;
  313. priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
  314. priv->pkt_rate_high = coal->pkt_rate_high;
  315. priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
  316. priv->sample_interval = coal->rate_sample_interval;
  317. priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
  318. priv->last_moder_time = MLX4_EN_AUTO_CONF;
  319. if (priv->adaptive_rx_coal)
  320. return 0;
  321. for (i = 0; i < priv->rx_ring_num; i++) {
  322. priv->rx_cq[i].moder_cnt = priv->rx_frames;
  323. priv->rx_cq[i].moder_time = priv->rx_usecs;
  324. err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]);
  325. if (err)
  326. return err;
  327. }
  328. return 0;
  329. }
  330. static int mlx4_en_set_pauseparam(struct net_device *dev,
  331. struct ethtool_pauseparam *pause)
  332. {
  333. struct mlx4_en_priv *priv = netdev_priv(dev);
  334. struct mlx4_en_dev *mdev = priv->mdev;
  335. int err;
  336. priv->prof->tx_pause = pause->tx_pause != 0;
  337. priv->prof->rx_pause = pause->rx_pause != 0;
  338. err = mlx4_SET_PORT_general(mdev->dev, priv->port,
  339. priv->rx_skb_size + ETH_FCS_LEN,
  340. priv->prof->tx_pause,
  341. priv->prof->tx_ppp,
  342. priv->prof->rx_pause,
  343. priv->prof->rx_ppp);
  344. if (err)
  345. mlx4_err(mdev, "Failed setting pause params to\n");
  346. return err;
  347. }
  348. static void mlx4_en_get_pauseparam(struct net_device *dev,
  349. struct ethtool_pauseparam *pause)
  350. {
  351. struct mlx4_en_priv *priv = netdev_priv(dev);
  352. pause->tx_pause = priv->prof->tx_pause;
  353. pause->rx_pause = priv->prof->rx_pause;
  354. }
  355. static void mlx4_en_get_ringparam(struct net_device *dev,
  356. struct ethtool_ringparam *param)
  357. {
  358. struct mlx4_en_priv *priv = netdev_priv(dev);
  359. struct mlx4_en_dev *mdev = priv->mdev;
  360. memset(param, 0, sizeof(*param));
  361. param->rx_max_pending = mdev->dev->caps.max_rq_sg;
  362. param->tx_max_pending = mdev->dev->caps.max_sq_sg;
  363. param->rx_pending = mdev->profile.prof[priv->port].rx_ring_size;
  364. param->tx_pending = mdev->profile.prof[priv->port].tx_ring_size;
  365. }
  366. const struct ethtool_ops mlx4_en_ethtool_ops = {
  367. .get_drvinfo = mlx4_en_get_drvinfo,
  368. .get_settings = mlx4_en_get_settings,
  369. .set_settings = mlx4_en_set_settings,
  370. #ifdef NETIF_F_TSO
  371. .get_tso = mlx4_en_get_tso,
  372. .set_tso = mlx4_en_set_tso,
  373. #endif
  374. .get_sg = ethtool_op_get_sg,
  375. .set_sg = ethtool_op_set_sg,
  376. .get_link = ethtool_op_get_link,
  377. .get_rx_csum = mlx4_en_get_rx_csum,
  378. .set_rx_csum = mlx4_en_set_rx_csum,
  379. .get_tx_csum = ethtool_op_get_tx_csum,
  380. .set_tx_csum = ethtool_op_set_tx_ipv6_csum,
  381. .get_strings = mlx4_en_get_strings,
  382. .get_sset_count = mlx4_en_get_sset_count,
  383. .get_ethtool_stats = mlx4_en_get_ethtool_stats,
  384. .get_wol = mlx4_en_get_wol,
  385. .get_msglevel = mlx4_en_get_msglevel,
  386. .set_msglevel = mlx4_en_set_msglevel,
  387. .get_coalesce = mlx4_en_get_coalesce,
  388. .set_coalesce = mlx4_en_set_coalesce,
  389. .get_pauseparam = mlx4_en_get_pauseparam,
  390. .set_pauseparam = mlx4_en_set_pauseparam,
  391. .get_ringparam = mlx4_en_get_ringparam,
  392. .get_flags = ethtool_op_get_flags,
  393. .set_flags = ethtool_op_set_flags,
  394. };