PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/net/mlx4/en_ethtool.c

https://bitbucket.org/GT-P6200/samsung-kernel-p6200
C | 460 lines | 356 code | 67 blank | 37 comment | 52 complexity | 93a0a7b7cc834660d6d51e4a0d12a06a MD5 | raw file
  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. static void mlx4_en_update_lro_stats(struct mlx4_en_priv *priv)
  39. {
  40. int i;
  41. priv->port_stats.lro_aggregated = 0;
  42. priv->port_stats.lro_flushed = 0;
  43. priv->port_stats.lro_no_desc = 0;
  44. for (i = 0; i < priv->rx_ring_num; i++) {
  45. priv->port_stats.lro_aggregated += priv->rx_ring[i].lro.stats.aggregated;
  46. priv->port_stats.lro_flushed += priv->rx_ring[i].lro.stats.flushed;
  47. priv->port_stats.lro_no_desc += priv->rx_ring[i].lro.stats.no_desc;
  48. }
  49. }
  50. static void
  51. mlx4_en_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo)
  52. {
  53. struct mlx4_en_priv *priv = netdev_priv(dev);
  54. struct mlx4_en_dev *mdev = priv->mdev;
  55. sprintf(drvinfo->driver, DRV_NAME " (%s)", mdev->dev->board_id);
  56. strncpy(drvinfo->version, DRV_VERSION " (" DRV_RELDATE ")", 32);
  57. sprintf(drvinfo->fw_version, "%d.%d.%d",
  58. (u16) (mdev->dev->caps.fw_ver >> 32),
  59. (u16) ((mdev->dev->caps.fw_ver >> 16) & 0xffff),
  60. (u16) (mdev->dev->caps.fw_ver & 0xffff));
  61. strncpy(drvinfo->bus_info, pci_name(mdev->dev->pdev), 32);
  62. drvinfo->n_stats = 0;
  63. drvinfo->regdump_len = 0;
  64. drvinfo->eedump_len = 0;
  65. }
  66. static u32 mlx4_en_get_tso(struct net_device *dev)
  67. {
  68. return (dev->features & NETIF_F_TSO) != 0;
  69. }
  70. static int mlx4_en_set_tso(struct net_device *dev, u32 data)
  71. {
  72. struct mlx4_en_priv *priv = netdev_priv(dev);
  73. if (data) {
  74. if (!priv->mdev->LSO_support)
  75. return -EPERM;
  76. dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
  77. } else
  78. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
  79. return 0;
  80. }
  81. static u32 mlx4_en_get_rx_csum(struct net_device *dev)
  82. {
  83. struct mlx4_en_priv *priv = netdev_priv(dev);
  84. return priv->rx_csum;
  85. }
  86. static int mlx4_en_set_rx_csum(struct net_device *dev, u32 data)
  87. {
  88. struct mlx4_en_priv *priv = netdev_priv(dev);
  89. priv->rx_csum = (data != 0);
  90. return 0;
  91. }
  92. static const char main_strings[][ETH_GSTRING_LEN] = {
  93. "rx_packets", "tx_packets", "rx_bytes", "tx_bytes", "rx_errors",
  94. "tx_errors", "rx_dropped", "tx_dropped", "multicast", "collisions",
  95. "rx_length_errors", "rx_over_errors", "rx_crc_errors",
  96. "rx_frame_errors", "rx_fifo_errors", "rx_missed_errors",
  97. "tx_aborted_errors", "tx_carrier_errors", "tx_fifo_errors",
  98. "tx_heartbeat_errors", "tx_window_errors",
  99. /* port statistics */
  100. "lro_aggregated", "lro_flushed", "lro_no_desc", "tso_packets",
  101. "queue_stopped", "wake_queue", "tx_timeout", "rx_alloc_failed",
  102. "rx_csum_good", "rx_csum_none", "tx_chksum_offload",
  103. /* packet statistics */
  104. "broadcast", "rx_prio_0", "rx_prio_1", "rx_prio_2", "rx_prio_3",
  105. "rx_prio_4", "rx_prio_5", "rx_prio_6", "rx_prio_7", "tx_prio_0",
  106. "tx_prio_1", "tx_prio_2", "tx_prio_3", "tx_prio_4", "tx_prio_5",
  107. "tx_prio_6", "tx_prio_7",
  108. };
  109. #define NUM_MAIN_STATS 21
  110. #define NUM_ALL_STATS (NUM_MAIN_STATS + NUM_PORT_STATS + NUM_PKT_STATS + NUM_PERF_STATS)
  111. static u32 mlx4_en_get_msglevel(struct net_device *dev)
  112. {
  113. return ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable;
  114. }
  115. static void mlx4_en_set_msglevel(struct net_device *dev, u32 val)
  116. {
  117. ((struct mlx4_en_priv *) netdev_priv(dev))->msg_enable = val;
  118. }
  119. static void mlx4_en_get_wol(struct net_device *netdev,
  120. struct ethtool_wolinfo *wol)
  121. {
  122. wol->supported = 0;
  123. wol->wolopts = 0;
  124. }
  125. static int mlx4_en_get_sset_count(struct net_device *dev, int sset)
  126. {
  127. struct mlx4_en_priv *priv = netdev_priv(dev);
  128. if (sset != ETH_SS_STATS)
  129. return -EOPNOTSUPP;
  130. return NUM_ALL_STATS + (priv->tx_ring_num + priv->rx_ring_num) * 2;
  131. }
  132. static void mlx4_en_get_ethtool_stats(struct net_device *dev,
  133. struct ethtool_stats *stats, uint64_t *data)
  134. {
  135. struct mlx4_en_priv *priv = netdev_priv(dev);
  136. int index = 0;
  137. int i;
  138. spin_lock_bh(&priv->stats_lock);
  139. mlx4_en_update_lro_stats(priv);
  140. for (i = 0; i < NUM_MAIN_STATS; i++)
  141. data[index++] = ((unsigned long *) &priv->stats)[i];
  142. for (i = 0; i < NUM_PORT_STATS; i++)
  143. data[index++] = ((unsigned long *) &priv->port_stats)[i];
  144. for (i = 0; i < priv->tx_ring_num; i++) {
  145. data[index++] = priv->tx_ring[i].packets;
  146. data[index++] = priv->tx_ring[i].bytes;
  147. }
  148. for (i = 0; i < priv->rx_ring_num; i++) {
  149. data[index++] = priv->rx_ring[i].packets;
  150. data[index++] = priv->rx_ring[i].bytes;
  151. }
  152. for (i = 0; i < NUM_PKT_STATS; i++)
  153. data[index++] = ((unsigned long *) &priv->pkstats)[i];
  154. spin_unlock_bh(&priv->stats_lock);
  155. }
  156. static void mlx4_en_get_strings(struct net_device *dev,
  157. uint32_t stringset, uint8_t *data)
  158. {
  159. struct mlx4_en_priv *priv = netdev_priv(dev);
  160. int index = 0;
  161. int i;
  162. if (stringset != ETH_SS_STATS)
  163. return;
  164. /* Add main counters */
  165. for (i = 0; i < NUM_MAIN_STATS; i++)
  166. strcpy(data + (index++) * ETH_GSTRING_LEN, main_strings[i]);
  167. for (i = 0; i < NUM_PORT_STATS; i++)
  168. strcpy(data + (index++) * ETH_GSTRING_LEN,
  169. main_strings[i + NUM_MAIN_STATS]);
  170. for (i = 0; i < priv->tx_ring_num; i++) {
  171. sprintf(data + (index++) * ETH_GSTRING_LEN,
  172. "tx%d_packets", i);
  173. sprintf(data + (index++) * ETH_GSTRING_LEN,
  174. "tx%d_bytes", i);
  175. }
  176. for (i = 0; i < priv->rx_ring_num; i++) {
  177. sprintf(data + (index++) * ETH_GSTRING_LEN,
  178. "rx%d_packets", i);
  179. sprintf(data + (index++) * ETH_GSTRING_LEN,
  180. "rx%d_bytes", i);
  181. }
  182. for (i = 0; i < NUM_PKT_STATS; i++)
  183. strcpy(data + (index++) * ETH_GSTRING_LEN,
  184. main_strings[i + NUM_MAIN_STATS + NUM_PORT_STATS]);
  185. }
  186. static int mlx4_en_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  187. {
  188. cmd->autoneg = AUTONEG_DISABLE;
  189. cmd->supported = SUPPORTED_10000baseT_Full;
  190. cmd->advertising = ADVERTISED_1000baseT_Full;
  191. if (netif_carrier_ok(dev)) {
  192. cmd->speed = SPEED_10000;
  193. cmd->duplex = DUPLEX_FULL;
  194. } else {
  195. cmd->speed = -1;
  196. cmd->duplex = -1;
  197. }
  198. return 0;
  199. }
  200. static int mlx4_en_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  201. {
  202. if ((cmd->autoneg == AUTONEG_ENABLE) ||
  203. (cmd->speed != SPEED_10000) || (cmd->duplex != DUPLEX_FULL))
  204. return -EINVAL;
  205. /* Nothing to change */
  206. return 0;
  207. }
  208. static int mlx4_en_get_coalesce(struct net_device *dev,
  209. struct ethtool_coalesce *coal)
  210. {
  211. struct mlx4_en_priv *priv = netdev_priv(dev);
  212. coal->tx_coalesce_usecs = 0;
  213. coal->tx_max_coalesced_frames = 0;
  214. coal->rx_coalesce_usecs = priv->rx_usecs;
  215. coal->rx_max_coalesced_frames = priv->rx_frames;
  216. coal->pkt_rate_low = priv->pkt_rate_low;
  217. coal->rx_coalesce_usecs_low = priv->rx_usecs_low;
  218. coal->pkt_rate_high = priv->pkt_rate_high;
  219. coal->rx_coalesce_usecs_high = priv->rx_usecs_high;
  220. coal->rate_sample_interval = priv->sample_interval;
  221. coal->use_adaptive_rx_coalesce = priv->adaptive_rx_coal;
  222. return 0;
  223. }
  224. static int mlx4_en_set_coalesce(struct net_device *dev,
  225. struct ethtool_coalesce *coal)
  226. {
  227. struct mlx4_en_priv *priv = netdev_priv(dev);
  228. int err, i;
  229. priv->rx_frames = (coal->rx_max_coalesced_frames ==
  230. MLX4_EN_AUTO_CONF) ?
  231. MLX4_EN_RX_COAL_TARGET :
  232. coal->rx_max_coalesced_frames;
  233. priv->rx_usecs = (coal->rx_coalesce_usecs ==
  234. MLX4_EN_AUTO_CONF) ?
  235. MLX4_EN_RX_COAL_TIME :
  236. coal->rx_coalesce_usecs;
  237. /* Set adaptive coalescing params */
  238. priv->pkt_rate_low = coal->pkt_rate_low;
  239. priv->rx_usecs_low = coal->rx_coalesce_usecs_low;
  240. priv->pkt_rate_high = coal->pkt_rate_high;
  241. priv->rx_usecs_high = coal->rx_coalesce_usecs_high;
  242. priv->sample_interval = coal->rate_sample_interval;
  243. priv->adaptive_rx_coal = coal->use_adaptive_rx_coalesce;
  244. priv->last_moder_time = MLX4_EN_AUTO_CONF;
  245. if (priv->adaptive_rx_coal)
  246. return 0;
  247. for (i = 0; i < priv->rx_ring_num; i++) {
  248. priv->rx_cq[i].moder_cnt = priv->rx_frames;
  249. priv->rx_cq[i].moder_time = priv->rx_usecs;
  250. err = mlx4_en_set_cq_moder(priv, &priv->rx_cq[i]);
  251. if (err)
  252. return err;
  253. }
  254. return 0;
  255. }
  256. static int mlx4_en_set_pauseparam(struct net_device *dev,
  257. struct ethtool_pauseparam *pause)
  258. {
  259. struct mlx4_en_priv *priv = netdev_priv(dev);
  260. struct mlx4_en_dev *mdev = priv->mdev;
  261. int err;
  262. priv->prof->tx_pause = pause->tx_pause != 0;
  263. priv->prof->rx_pause = pause->rx_pause != 0;
  264. err = mlx4_SET_PORT_general(mdev->dev, priv->port,
  265. priv->rx_skb_size + ETH_FCS_LEN,
  266. priv->prof->tx_pause,
  267. priv->prof->tx_ppp,
  268. priv->prof->rx_pause,
  269. priv->prof->rx_ppp);
  270. if (err)
  271. en_err(priv, "Failed setting pause params\n");
  272. return err;
  273. }
  274. static void mlx4_en_get_pauseparam(struct net_device *dev,
  275. struct ethtool_pauseparam *pause)
  276. {
  277. struct mlx4_en_priv *priv = netdev_priv(dev);
  278. pause->tx_pause = priv->prof->tx_pause;
  279. pause->rx_pause = priv->prof->rx_pause;
  280. }
  281. static int mlx4_en_set_ringparam(struct net_device *dev,
  282. struct ethtool_ringparam *param)
  283. {
  284. struct mlx4_en_priv *priv = netdev_priv(dev);
  285. struct mlx4_en_dev *mdev = priv->mdev;
  286. u32 rx_size, tx_size;
  287. int port_up = 0;
  288. int err = 0;
  289. if (param->rx_jumbo_pending || param->rx_mini_pending)
  290. return -EINVAL;
  291. rx_size = roundup_pow_of_two(param->rx_pending);
  292. rx_size = max_t(u32, rx_size, MLX4_EN_MIN_RX_SIZE);
  293. rx_size = min_t(u32, rx_size, MLX4_EN_MAX_RX_SIZE);
  294. tx_size = roundup_pow_of_two(param->tx_pending);
  295. tx_size = max_t(u32, tx_size, MLX4_EN_MIN_TX_SIZE);
  296. tx_size = min_t(u32, tx_size, MLX4_EN_MAX_TX_SIZE);
  297. if (rx_size == priv->prof->rx_ring_size &&
  298. tx_size == priv->prof->tx_ring_size)
  299. return 0;
  300. mutex_lock(&mdev->state_lock);
  301. if (priv->port_up) {
  302. port_up = 1;
  303. mlx4_en_stop_port(dev);
  304. }
  305. mlx4_en_free_resources(priv);
  306. priv->prof->tx_ring_size = tx_size;
  307. priv->prof->rx_ring_size = rx_size;
  308. err = mlx4_en_alloc_resources(priv);
  309. if (err) {
  310. en_err(priv, "Failed reallocating port resources\n");
  311. goto out;
  312. }
  313. if (port_up) {
  314. err = mlx4_en_start_port(dev);
  315. if (err)
  316. en_err(priv, "Failed starting port\n");
  317. }
  318. out:
  319. mutex_unlock(&mdev->state_lock);
  320. return err;
  321. }
  322. static void mlx4_en_get_ringparam(struct net_device *dev,
  323. struct ethtool_ringparam *param)
  324. {
  325. struct mlx4_en_priv *priv = netdev_priv(dev);
  326. struct mlx4_en_dev *mdev = priv->mdev;
  327. memset(param, 0, sizeof(*param));
  328. param->rx_max_pending = MLX4_EN_MAX_RX_SIZE;
  329. param->tx_max_pending = MLX4_EN_MAX_TX_SIZE;
  330. param->rx_pending = mdev->profile.prof[priv->port].rx_ring_size;
  331. param->tx_pending = mdev->profile.prof[priv->port].tx_ring_size;
  332. }
  333. static int mlx4_ethtool_op_set_flags(struct net_device *dev, u32 data)
  334. {
  335. struct mlx4_en_priv *priv = netdev_priv(dev);
  336. struct mlx4_en_dev *mdev = priv->mdev;
  337. int rc = 0;
  338. int changed = 0;
  339. if (data & ~ETH_FLAG_LRO)
  340. return -EOPNOTSUPP;
  341. if (data & ETH_FLAG_LRO) {
  342. if (mdev->profile.num_lro == 0)
  343. return -EOPNOTSUPP;
  344. if (!(dev->features & NETIF_F_LRO))
  345. changed = 1;
  346. } else if (dev->features & NETIF_F_LRO) {
  347. changed = 1;
  348. }
  349. if (changed) {
  350. if (netif_running(dev)) {
  351. mutex_lock(&mdev->state_lock);
  352. mlx4_en_stop_port(dev);
  353. }
  354. dev->features ^= NETIF_F_LRO;
  355. if (netif_running(dev)) {
  356. rc = mlx4_en_start_port(dev);
  357. if (rc)
  358. en_err(priv, "Failed to restart port\n");
  359. mutex_unlock(&mdev->state_lock);
  360. }
  361. }
  362. return rc;
  363. }
  364. const struct ethtool_ops mlx4_en_ethtool_ops = {
  365. .get_drvinfo = mlx4_en_get_drvinfo,
  366. .get_settings = mlx4_en_get_settings,
  367. .set_settings = mlx4_en_set_settings,
  368. #ifdef NETIF_F_TSO
  369. .get_tso = mlx4_en_get_tso,
  370. .set_tso = mlx4_en_set_tso,
  371. #endif
  372. .get_sg = ethtool_op_get_sg,
  373. .set_sg = ethtool_op_set_sg,
  374. .get_link = ethtool_op_get_link,
  375. .get_rx_csum = mlx4_en_get_rx_csum,
  376. .set_rx_csum = mlx4_en_set_rx_csum,
  377. .get_tx_csum = ethtool_op_get_tx_csum,
  378. .set_tx_csum = ethtool_op_set_tx_ipv6_csum,
  379. .get_strings = mlx4_en_get_strings,
  380. .get_sset_count = mlx4_en_get_sset_count,
  381. .get_ethtool_stats = mlx4_en_get_ethtool_stats,
  382. .get_wol = mlx4_en_get_wol,
  383. .get_msglevel = mlx4_en_get_msglevel,
  384. .set_msglevel = mlx4_en_set_msglevel,
  385. .get_coalesce = mlx4_en_get_coalesce,
  386. .set_coalesce = mlx4_en_set_coalesce,
  387. .get_pauseparam = mlx4_en_get_pauseparam,
  388. .set_pauseparam = mlx4_en_set_pauseparam,
  389. .get_ringparam = mlx4_en_get_ringparam,
  390. .set_ringparam = mlx4_en_set_ringparam,
  391. .get_flags = ethtool_op_get_flags,
  392. .set_flags = mlx4_ethtool_op_set_flags,
  393. };