en_port.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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/if_vlan.h>
  34. #include <linux/mlx4/device.h>
  35. #include <linux/mlx4/cmd.h>
  36. #include "en_port.h"
  37. #include "mlx4_en.h"
  38. int mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, struct mlx4_en_priv *priv)
  39. {
  40. struct mlx4_cmd_mailbox *mailbox;
  41. struct mlx4_set_vlan_fltr_mbox *filter;
  42. int i;
  43. int j;
  44. int index = 0;
  45. u32 entry;
  46. int err = 0;
  47. mailbox = mlx4_alloc_cmd_mailbox(dev);
  48. if (IS_ERR(mailbox))
  49. return PTR_ERR(mailbox);
  50. filter = mailbox->buf;
  51. for (i = VLAN_FLTR_SIZE - 1; i >= 0; i--) {
  52. entry = 0;
  53. for (j = 0; j < 32; j++)
  54. if (test_bit(index++, priv->active_vlans))
  55. entry |= 1 << j;
  56. filter->entry[i] = cpu_to_be32(entry);
  57. }
  58. err = mlx4_cmd(dev, mailbox->dma, priv->port, 0, MLX4_CMD_SET_VLAN_FLTR,
  59. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
  60. mlx4_free_cmd_mailbox(dev, mailbox);
  61. return err;
  62. }
  63. int mlx4_en_QUERY_PORT(struct mlx4_en_dev *mdev, u8 port)
  64. {
  65. struct mlx4_en_query_port_context *qport_context;
  66. struct mlx4_en_priv *priv = netdev_priv(mdev->pndev[port]);
  67. struct mlx4_en_port_state *state = &priv->port_state;
  68. struct mlx4_cmd_mailbox *mailbox;
  69. int err;
  70. mailbox = mlx4_alloc_cmd_mailbox(mdev->dev);
  71. if (IS_ERR(mailbox))
  72. return PTR_ERR(mailbox);
  73. err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, port, 0,
  74. MLX4_CMD_QUERY_PORT, MLX4_CMD_TIME_CLASS_B,
  75. MLX4_CMD_WRAPPED);
  76. if (err)
  77. goto out;
  78. qport_context = mailbox->buf;
  79. /* This command is always accessed from Ethtool context
  80. * already synchronized, no need in locking */
  81. state->link_state = !!(qport_context->link_up & MLX4_EN_LINK_UP_MASK);
  82. switch (qport_context->link_speed & MLX4_EN_SPEED_MASK) {
  83. case MLX4_EN_100M_SPEED:
  84. state->link_speed = SPEED_100;
  85. break;
  86. case MLX4_EN_1G_SPEED:
  87. state->link_speed = SPEED_1000;
  88. break;
  89. case MLX4_EN_10G_SPEED_XAUI:
  90. case MLX4_EN_10G_SPEED_XFI:
  91. state->link_speed = SPEED_10000;
  92. break;
  93. case MLX4_EN_20G_SPEED:
  94. state->link_speed = SPEED_20000;
  95. break;
  96. case MLX4_EN_40G_SPEED:
  97. state->link_speed = SPEED_40000;
  98. break;
  99. case MLX4_EN_56G_SPEED:
  100. state->link_speed = SPEED_56000;
  101. break;
  102. default:
  103. state->link_speed = -1;
  104. break;
  105. }
  106. state->transceiver = qport_context->transceiver;
  107. state->flags = 0; /* Reset and recalculate the port flags */
  108. state->flags |= (qport_context->link_up & MLX4_EN_ANC_MASK) ?
  109. MLX4_EN_PORT_ANC : 0;
  110. state->flags |= (qport_context->autoneg & MLX4_EN_AUTONEG_MASK) ?
  111. MLX4_EN_PORT_ANE : 0;
  112. out:
  113. mlx4_free_cmd_mailbox(mdev->dev, mailbox);
  114. return err;
  115. }
  116. /* Each counter set is located in struct mlx4_en_stat_out_mbox
  117. * with a const offset between its prio components.
  118. * This function runs over a counter set and sum all of it's prio components.
  119. */
  120. static unsigned long en_stats_adder(__be64 *start, __be64 *next, int num)
  121. {
  122. __be64 *curr = start;
  123. unsigned long ret = 0;
  124. int i;
  125. int offset = next - start;
  126. for (i = 0; i < num; i++) {
  127. ret += be64_to_cpu(*curr);
  128. curr += offset;
  129. }
  130. return ret;
  131. }
  132. int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset)
  133. {
  134. struct mlx4_counter tmp_counter_stats;
  135. struct mlx4_en_stat_out_mbox *mlx4_en_stats;
  136. struct mlx4_en_stat_out_flow_control_mbox *flowstats;
  137. struct mlx4_en_priv *priv = netdev_priv(mdev->pndev[port]);
  138. struct net_device_stats *stats = &priv->stats;
  139. struct mlx4_cmd_mailbox *mailbox;
  140. u64 in_mod = reset << 8 | port;
  141. int err;
  142. int i, counter_index;
  143. mailbox = mlx4_alloc_cmd_mailbox(mdev->dev);
  144. if (IS_ERR(mailbox))
  145. return PTR_ERR(mailbox);
  146. err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, in_mod, 0,
  147. MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B,
  148. MLX4_CMD_WRAPPED);
  149. if (err)
  150. goto out;
  151. mlx4_en_stats = mailbox->buf;
  152. spin_lock_bh(&priv->stats_lock);
  153. stats->rx_packets = 0;
  154. stats->rx_bytes = 0;
  155. priv->port_stats.rx_chksum_good = 0;
  156. priv->port_stats.rx_chksum_none = 0;
  157. priv->port_stats.rx_chksum_complete = 0;
  158. for (i = 0; i < priv->rx_ring_num; i++) {
  159. stats->rx_packets += priv->rx_ring[i]->packets;
  160. stats->rx_bytes += priv->rx_ring[i]->bytes;
  161. priv->port_stats.rx_chksum_good += priv->rx_ring[i]->csum_ok;
  162. priv->port_stats.rx_chksum_none += priv->rx_ring[i]->csum_none;
  163. priv->port_stats.rx_chksum_complete += priv->rx_ring[i]->csum_complete;
  164. }
  165. stats->tx_packets = 0;
  166. stats->tx_bytes = 0;
  167. priv->port_stats.tx_chksum_offload = 0;
  168. priv->port_stats.queue_stopped = 0;
  169. priv->port_stats.wake_queue = 0;
  170. priv->port_stats.tso_packets = 0;
  171. priv->port_stats.xmit_more = 0;
  172. for (i = 0; i < priv->tx_ring_num; i++) {
  173. const struct mlx4_en_tx_ring *ring = priv->tx_ring[i];
  174. stats->tx_packets += ring->packets;
  175. stats->tx_bytes += ring->bytes;
  176. priv->port_stats.tx_chksum_offload += ring->tx_csum;
  177. priv->port_stats.queue_stopped += ring->queue_stopped;
  178. priv->port_stats.wake_queue += ring->wake_queue;
  179. priv->port_stats.tso_packets += ring->tso_packets;
  180. priv->port_stats.xmit_more += ring->xmit_more;
  181. }
  182. if (mlx4_is_master(mdev->dev)) {
  183. stats->rx_packets = en_stats_adder(&mlx4_en_stats->RTOT_prio_0,
  184. &mlx4_en_stats->RTOT_prio_1,
  185. NUM_PRIORITIES);
  186. stats->tx_packets = en_stats_adder(&mlx4_en_stats->TTOT_prio_0,
  187. &mlx4_en_stats->TTOT_prio_1,
  188. NUM_PRIORITIES);
  189. stats->rx_bytes = en_stats_adder(&mlx4_en_stats->ROCT_prio_0,
  190. &mlx4_en_stats->ROCT_prio_1,
  191. NUM_PRIORITIES);
  192. stats->tx_bytes = en_stats_adder(&mlx4_en_stats->TOCT_prio_0,
  193. &mlx4_en_stats->TOCT_prio_1,
  194. NUM_PRIORITIES);
  195. }
  196. /* net device stats */
  197. stats->rx_errors = be64_to_cpu(mlx4_en_stats->PCS) +
  198. be32_to_cpu(mlx4_en_stats->RJBBR) +
  199. be32_to_cpu(mlx4_en_stats->RCRC) +
  200. be32_to_cpu(mlx4_en_stats->RRUNT) +
  201. be64_to_cpu(mlx4_en_stats->RInRangeLengthErr) +
  202. be64_to_cpu(mlx4_en_stats->ROutRangeLengthErr) +
  203. be32_to_cpu(mlx4_en_stats->RSHORT) +
  204. en_stats_adder(&mlx4_en_stats->RGIANT_prio_0,
  205. &mlx4_en_stats->RGIANT_prio_1,
  206. NUM_PRIORITIES);
  207. stats->tx_errors = en_stats_adder(&mlx4_en_stats->TGIANT_prio_0,
  208. &mlx4_en_stats->TGIANT_prio_1,
  209. NUM_PRIORITIES);
  210. stats->multicast = en_stats_adder(&mlx4_en_stats->MCAST_prio_0,
  211. &mlx4_en_stats->MCAST_prio_1,
  212. NUM_PRIORITIES);
  213. stats->collisions = 0;
  214. stats->rx_dropped = be32_to_cpu(mlx4_en_stats->RDROP);
  215. stats->rx_length_errors = be32_to_cpu(mlx4_en_stats->RdropLength);
  216. stats->rx_over_errors = 0;
  217. stats->rx_crc_errors = be32_to_cpu(mlx4_en_stats->RCRC);
  218. stats->rx_frame_errors = 0;
  219. stats->rx_fifo_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
  220. stats->rx_missed_errors = 0;
  221. stats->tx_aborted_errors = 0;
  222. stats->tx_carrier_errors = 0;
  223. stats->tx_fifo_errors = 0;
  224. stats->tx_heartbeat_errors = 0;
  225. stats->tx_window_errors = 0;
  226. stats->tx_dropped = be32_to_cpu(mlx4_en_stats->TDROP);
  227. /* RX stats */
  228. priv->pkstats.rx_multicast_packets = stats->multicast;
  229. priv->pkstats.rx_broadcast_packets =
  230. en_stats_adder(&mlx4_en_stats->RBCAST_prio_0,
  231. &mlx4_en_stats->RBCAST_prio_1,
  232. NUM_PRIORITIES);
  233. priv->pkstats.rx_jabbers = be32_to_cpu(mlx4_en_stats->RJBBR);
  234. priv->pkstats.rx_in_range_length_error =
  235. be64_to_cpu(mlx4_en_stats->RInRangeLengthErr);
  236. priv->pkstats.rx_out_range_length_error =
  237. be64_to_cpu(mlx4_en_stats->ROutRangeLengthErr);
  238. /* Tx stats */
  239. priv->pkstats.tx_multicast_packets =
  240. en_stats_adder(&mlx4_en_stats->TMCAST_prio_0,
  241. &mlx4_en_stats->TMCAST_prio_1,
  242. NUM_PRIORITIES);
  243. priv->pkstats.tx_broadcast_packets =
  244. en_stats_adder(&mlx4_en_stats->TBCAST_prio_0,
  245. &mlx4_en_stats->TBCAST_prio_1,
  246. NUM_PRIORITIES);
  247. priv->pkstats.rx_prio[0][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_0);
  248. priv->pkstats.rx_prio[0][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_0);
  249. priv->pkstats.rx_prio[1][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_1);
  250. priv->pkstats.rx_prio[1][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_1);
  251. priv->pkstats.rx_prio[2][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_2);
  252. priv->pkstats.rx_prio[2][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_2);
  253. priv->pkstats.rx_prio[3][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_3);
  254. priv->pkstats.rx_prio[3][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_3);
  255. priv->pkstats.rx_prio[4][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_4);
  256. priv->pkstats.rx_prio[4][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_4);
  257. priv->pkstats.rx_prio[5][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_5);
  258. priv->pkstats.rx_prio[5][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_5);
  259. priv->pkstats.rx_prio[6][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_6);
  260. priv->pkstats.rx_prio[6][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_6);
  261. priv->pkstats.rx_prio[7][0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_7);
  262. priv->pkstats.rx_prio[7][1] = be64_to_cpu(mlx4_en_stats->ROCT_prio_7);
  263. priv->pkstats.rx_prio[8][0] = be64_to_cpu(mlx4_en_stats->RTOT_novlan);
  264. priv->pkstats.rx_prio[8][1] = be64_to_cpu(mlx4_en_stats->ROCT_novlan);
  265. priv->pkstats.tx_prio[0][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_0);
  266. priv->pkstats.tx_prio[0][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_0);
  267. priv->pkstats.tx_prio[1][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_1);
  268. priv->pkstats.tx_prio[1][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_1);
  269. priv->pkstats.tx_prio[2][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_2);
  270. priv->pkstats.tx_prio[2][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_2);
  271. priv->pkstats.tx_prio[3][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_3);
  272. priv->pkstats.tx_prio[3][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_3);
  273. priv->pkstats.tx_prio[4][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_4);
  274. priv->pkstats.tx_prio[4][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_4);
  275. priv->pkstats.tx_prio[5][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_5);
  276. priv->pkstats.tx_prio[5][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_5);
  277. priv->pkstats.tx_prio[6][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_6);
  278. priv->pkstats.tx_prio[6][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_6);
  279. priv->pkstats.tx_prio[7][0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_7);
  280. priv->pkstats.tx_prio[7][1] = be64_to_cpu(mlx4_en_stats->TOCT_prio_7);
  281. priv->pkstats.tx_prio[8][0] = be64_to_cpu(mlx4_en_stats->TTOT_novlan);
  282. priv->pkstats.tx_prio[8][1] = be64_to_cpu(mlx4_en_stats->TOCT_novlan);
  283. spin_unlock_bh(&priv->stats_lock);
  284. memset(&tmp_counter_stats, 0, sizeof(tmp_counter_stats));
  285. counter_index = mlx4_get_default_counter_index(mdev->dev, port);
  286. err = mlx4_get_counter_stats(mdev->dev, counter_index,
  287. &tmp_counter_stats, reset);
  288. /* 0xffs indicates invalid value */
  289. memset(mailbox->buf, 0xff, sizeof(*flowstats) * MLX4_NUM_PRIORITIES);
  290. if (mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FLOWSTATS_EN) {
  291. memset(mailbox->buf, 0,
  292. sizeof(*flowstats) * MLX4_NUM_PRIORITIES);
  293. err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma,
  294. in_mod | MLX4_DUMP_ETH_STATS_FLOW_CONTROL,
  295. 0, MLX4_CMD_DUMP_ETH_STATS,
  296. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_WRAPPED);
  297. if (err)
  298. goto out;
  299. }
  300. flowstats = mailbox->buf;
  301. spin_lock_bh(&priv->stats_lock);
  302. if (tmp_counter_stats.counter_mode == 0) {
  303. priv->pf_stats.rx_bytes = be64_to_cpu(tmp_counter_stats.rx_bytes);
  304. priv->pf_stats.tx_bytes = be64_to_cpu(tmp_counter_stats.tx_bytes);
  305. priv->pf_stats.rx_packets = be64_to_cpu(tmp_counter_stats.rx_frames);
  306. priv->pf_stats.tx_packets = be64_to_cpu(tmp_counter_stats.tx_frames);
  307. }
  308. for (i = 0; i < MLX4_NUM_PRIORITIES; i++) {
  309. priv->rx_priority_flowstats[i].rx_pause =
  310. be64_to_cpu(flowstats[i].rx_pause);
  311. priv->rx_priority_flowstats[i].rx_pause_duration =
  312. be64_to_cpu(flowstats[i].rx_pause_duration);
  313. priv->rx_priority_flowstats[i].rx_pause_transition =
  314. be64_to_cpu(flowstats[i].rx_pause_transition);
  315. priv->tx_priority_flowstats[i].tx_pause =
  316. be64_to_cpu(flowstats[i].tx_pause);
  317. priv->tx_priority_flowstats[i].tx_pause_duration =
  318. be64_to_cpu(flowstats[i].tx_pause_duration);
  319. priv->tx_priority_flowstats[i].tx_pause_transition =
  320. be64_to_cpu(flowstats[i].tx_pause_transition);
  321. }
  322. /* if pfc is not in use, all priorities counters have the same value */
  323. priv->rx_flowstats.rx_pause =
  324. be64_to_cpu(flowstats[0].rx_pause);
  325. priv->rx_flowstats.rx_pause_duration =
  326. be64_to_cpu(flowstats[0].rx_pause_duration);
  327. priv->rx_flowstats.rx_pause_transition =
  328. be64_to_cpu(flowstats[0].rx_pause_transition);
  329. priv->tx_flowstats.tx_pause =
  330. be64_to_cpu(flowstats[0].tx_pause);
  331. priv->tx_flowstats.tx_pause_duration =
  332. be64_to_cpu(flowstats[0].tx_pause_duration);
  333. priv->tx_flowstats.tx_pause_transition =
  334. be64_to_cpu(flowstats[0].tx_pause_transition);
  335. spin_unlock_bh(&priv->stats_lock);
  336. out:
  337. mlx4_free_cmd_mailbox(mdev->dev, mailbox);
  338. return err;
  339. }