en_port.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset)
  117. {
  118. struct mlx4_en_stat_out_mbox *mlx4_en_stats;
  119. struct mlx4_en_priv *priv = netdev_priv(mdev->pndev[port]);
  120. struct net_device_stats *stats = &priv->stats;
  121. struct mlx4_cmd_mailbox *mailbox;
  122. u64 in_mod = reset << 8 | port;
  123. int err;
  124. int i;
  125. mailbox = mlx4_alloc_cmd_mailbox(mdev->dev);
  126. if (IS_ERR(mailbox))
  127. return PTR_ERR(mailbox);
  128. err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, in_mod, 0,
  129. MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B,
  130. MLX4_CMD_WRAPPED);
  131. if (err)
  132. goto out;
  133. mlx4_en_stats = mailbox->buf;
  134. spin_lock_bh(&priv->stats_lock);
  135. stats->rx_packets = 0;
  136. stats->rx_bytes = 0;
  137. priv->port_stats.rx_chksum_good = 0;
  138. priv->port_stats.rx_chksum_none = 0;
  139. priv->port_stats.rx_chksum_complete = 0;
  140. for (i = 0; i < priv->rx_ring_num; i++) {
  141. stats->rx_packets += priv->rx_ring[i]->packets;
  142. stats->rx_bytes += priv->rx_ring[i]->bytes;
  143. priv->port_stats.rx_chksum_good += priv->rx_ring[i]->csum_ok;
  144. priv->port_stats.rx_chksum_none += priv->rx_ring[i]->csum_none;
  145. priv->port_stats.rx_chksum_complete += priv->rx_ring[i]->csum_complete;
  146. }
  147. stats->tx_packets = 0;
  148. stats->tx_bytes = 0;
  149. priv->port_stats.tx_chksum_offload = 0;
  150. priv->port_stats.queue_stopped = 0;
  151. priv->port_stats.wake_queue = 0;
  152. priv->port_stats.tso_packets = 0;
  153. priv->port_stats.xmit_more = 0;
  154. for (i = 0; i < priv->tx_ring_num; i++) {
  155. const struct mlx4_en_tx_ring *ring = priv->tx_ring[i];
  156. stats->tx_packets += ring->packets;
  157. stats->tx_bytes += ring->bytes;
  158. priv->port_stats.tx_chksum_offload += ring->tx_csum;
  159. priv->port_stats.queue_stopped += ring->queue_stopped;
  160. priv->port_stats.wake_queue += ring->wake_queue;
  161. priv->port_stats.tso_packets += ring->tso_packets;
  162. priv->port_stats.xmit_more += ring->xmit_more;
  163. }
  164. stats->rx_errors = be64_to_cpu(mlx4_en_stats->PCS) +
  165. be32_to_cpu(mlx4_en_stats->RdropLength) +
  166. be32_to_cpu(mlx4_en_stats->RJBBR) +
  167. be32_to_cpu(mlx4_en_stats->RCRC) +
  168. be32_to_cpu(mlx4_en_stats->RRUNT);
  169. stats->tx_errors = be32_to_cpu(mlx4_en_stats->TDROP);
  170. stats->multicast = be64_to_cpu(mlx4_en_stats->MCAST_prio_0) +
  171. be64_to_cpu(mlx4_en_stats->MCAST_prio_1) +
  172. be64_to_cpu(mlx4_en_stats->MCAST_prio_2) +
  173. be64_to_cpu(mlx4_en_stats->MCAST_prio_3) +
  174. be64_to_cpu(mlx4_en_stats->MCAST_prio_4) +
  175. be64_to_cpu(mlx4_en_stats->MCAST_prio_5) +
  176. be64_to_cpu(mlx4_en_stats->MCAST_prio_6) +
  177. be64_to_cpu(mlx4_en_stats->MCAST_prio_7) +
  178. be64_to_cpu(mlx4_en_stats->MCAST_novlan);
  179. stats->collisions = 0;
  180. stats->rx_length_errors = be32_to_cpu(mlx4_en_stats->RdropLength);
  181. stats->rx_over_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
  182. stats->rx_crc_errors = be32_to_cpu(mlx4_en_stats->RCRC);
  183. stats->rx_frame_errors = 0;
  184. stats->rx_fifo_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
  185. stats->rx_missed_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
  186. stats->tx_aborted_errors = 0;
  187. stats->tx_carrier_errors = 0;
  188. stats->tx_fifo_errors = 0;
  189. stats->tx_heartbeat_errors = 0;
  190. stats->tx_window_errors = 0;
  191. priv->pkstats.broadcast =
  192. be64_to_cpu(mlx4_en_stats->RBCAST_prio_0) +
  193. be64_to_cpu(mlx4_en_stats->RBCAST_prio_1) +
  194. be64_to_cpu(mlx4_en_stats->RBCAST_prio_2) +
  195. be64_to_cpu(mlx4_en_stats->RBCAST_prio_3) +
  196. be64_to_cpu(mlx4_en_stats->RBCAST_prio_4) +
  197. be64_to_cpu(mlx4_en_stats->RBCAST_prio_5) +
  198. be64_to_cpu(mlx4_en_stats->RBCAST_prio_6) +
  199. be64_to_cpu(mlx4_en_stats->RBCAST_prio_7) +
  200. be64_to_cpu(mlx4_en_stats->RBCAST_novlan);
  201. priv->pkstats.rx_prio[0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_0);
  202. priv->pkstats.rx_prio[1] = be64_to_cpu(mlx4_en_stats->RTOT_prio_1);
  203. priv->pkstats.rx_prio[2] = be64_to_cpu(mlx4_en_stats->RTOT_prio_2);
  204. priv->pkstats.rx_prio[3] = be64_to_cpu(mlx4_en_stats->RTOT_prio_3);
  205. priv->pkstats.rx_prio[4] = be64_to_cpu(mlx4_en_stats->RTOT_prio_4);
  206. priv->pkstats.rx_prio[5] = be64_to_cpu(mlx4_en_stats->RTOT_prio_5);
  207. priv->pkstats.rx_prio[6] = be64_to_cpu(mlx4_en_stats->RTOT_prio_6);
  208. priv->pkstats.rx_prio[7] = be64_to_cpu(mlx4_en_stats->RTOT_prio_7);
  209. priv->pkstats.tx_prio[0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_0);
  210. priv->pkstats.tx_prio[1] = be64_to_cpu(mlx4_en_stats->TTOT_prio_1);
  211. priv->pkstats.tx_prio[2] = be64_to_cpu(mlx4_en_stats->TTOT_prio_2);
  212. priv->pkstats.tx_prio[3] = be64_to_cpu(mlx4_en_stats->TTOT_prio_3);
  213. priv->pkstats.tx_prio[4] = be64_to_cpu(mlx4_en_stats->TTOT_prio_4);
  214. priv->pkstats.tx_prio[5] = be64_to_cpu(mlx4_en_stats->TTOT_prio_5);
  215. priv->pkstats.tx_prio[6] = be64_to_cpu(mlx4_en_stats->TTOT_prio_6);
  216. priv->pkstats.tx_prio[7] = be64_to_cpu(mlx4_en_stats->TTOT_prio_7);
  217. spin_unlock_bh(&priv->stats_lock);
  218. out:
  219. mlx4_free_cmd_mailbox(mdev->dev, mailbox);
  220. return err;
  221. }