en_port.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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_MCAST_FLTR(struct mlx4_dev *dev, u8 port,
  39. u64 mac, u64 clear, u8 mode)
  40. {
  41. return mlx4_cmd(dev, (mac | (clear << 63)), port, mode,
  42. MLX4_CMD_SET_MCAST_FLTR, MLX4_CMD_TIME_CLASS_B);
  43. }
  44. int mlx4_SET_VLAN_FLTR(struct mlx4_dev *dev, u8 port, struct vlan_group *grp)
  45. {
  46. struct mlx4_cmd_mailbox *mailbox;
  47. struct mlx4_set_vlan_fltr_mbox *filter;
  48. int i;
  49. int j;
  50. int index = 0;
  51. u32 entry;
  52. int err = 0;
  53. mailbox = mlx4_alloc_cmd_mailbox(dev);
  54. if (IS_ERR(mailbox))
  55. return PTR_ERR(mailbox);
  56. filter = mailbox->buf;
  57. if (grp) {
  58. memset(filter, 0, sizeof *filter);
  59. for (i = VLAN_FLTR_SIZE - 1; i >= 0; i--) {
  60. entry = 0;
  61. for (j = 0; j < 32; j++)
  62. if (vlan_group_get_device(grp, index++))
  63. entry |= 1 << j;
  64. filter->entry[i] = cpu_to_be32(entry);
  65. }
  66. } else {
  67. /* When no vlans are configured we block all vlans */
  68. memset(filter, 0, sizeof(*filter));
  69. }
  70. err = mlx4_cmd(dev, mailbox->dma, port, 0, MLX4_CMD_SET_VLAN_FLTR,
  71. MLX4_CMD_TIME_CLASS_B);
  72. mlx4_free_cmd_mailbox(dev, mailbox);
  73. return err;
  74. }
  75. int mlx4_SET_PORT_general(struct mlx4_dev *dev, u8 port, int mtu,
  76. u8 pptx, u8 pfctx, u8 pprx, u8 pfcrx)
  77. {
  78. struct mlx4_cmd_mailbox *mailbox;
  79. struct mlx4_set_port_general_context *context;
  80. int err;
  81. u32 in_mod;
  82. mailbox = mlx4_alloc_cmd_mailbox(dev);
  83. if (IS_ERR(mailbox))
  84. return PTR_ERR(mailbox);
  85. context = mailbox->buf;
  86. memset(context, 0, sizeof *context);
  87. context->flags = SET_PORT_GEN_ALL_VALID;
  88. context->mtu = cpu_to_be16(mtu);
  89. context->pptx = (pptx * (!pfctx)) << 7;
  90. context->pfctx = pfctx;
  91. context->pprx = (pprx * (!pfcrx)) << 7;
  92. context->pfcrx = pfcrx;
  93. in_mod = MLX4_SET_PORT_GENERAL << 8 | port;
  94. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  95. MLX4_CMD_TIME_CLASS_B);
  96. mlx4_free_cmd_mailbox(dev, mailbox);
  97. return err;
  98. }
  99. int mlx4_SET_PORT_qpn_calc(struct mlx4_dev *dev, u8 port, u32 base_qpn,
  100. u8 promisc)
  101. {
  102. struct mlx4_cmd_mailbox *mailbox;
  103. struct mlx4_set_port_rqp_calc_context *context;
  104. int err;
  105. u32 in_mod;
  106. mailbox = mlx4_alloc_cmd_mailbox(dev);
  107. if (IS_ERR(mailbox))
  108. return PTR_ERR(mailbox);
  109. context = mailbox->buf;
  110. memset(context, 0, sizeof *context);
  111. context->base_qpn = cpu_to_be32(base_qpn);
  112. context->promisc = cpu_to_be32(promisc << SET_PORT_PROMISC_SHIFT | base_qpn);
  113. context->mcast = cpu_to_be32(1 << SET_PORT_PROMISC_SHIFT | base_qpn);
  114. context->intra_no_vlan = 0;
  115. context->no_vlan = MLX4_NO_VLAN_IDX;
  116. context->intra_vlan_miss = 0;
  117. context->vlan_miss = MLX4_VLAN_MISS_IDX;
  118. in_mod = MLX4_SET_PORT_RQP_CALC << 8 | port;
  119. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  120. MLX4_CMD_TIME_CLASS_B);
  121. mlx4_free_cmd_mailbox(dev, mailbox);
  122. return err;
  123. }
  124. int mlx4_en_DUMP_ETH_STATS(struct mlx4_en_dev *mdev, u8 port, u8 reset)
  125. {
  126. struct mlx4_en_stat_out_mbox *mlx4_en_stats;
  127. struct mlx4_en_priv *priv = netdev_priv(mdev->pndev[port]);
  128. struct net_device_stats *stats = &priv->stats;
  129. struct mlx4_cmd_mailbox *mailbox;
  130. u64 in_mod = reset << 8 | port;
  131. int err;
  132. mailbox = mlx4_alloc_cmd_mailbox(mdev->dev);
  133. if (IS_ERR(mailbox))
  134. return PTR_ERR(mailbox);
  135. memset(mailbox->buf, 0, sizeof(*mlx4_en_stats));
  136. err = mlx4_cmd_box(mdev->dev, 0, mailbox->dma, in_mod, 0,
  137. MLX4_CMD_DUMP_ETH_STATS, MLX4_CMD_TIME_CLASS_B);
  138. if (err)
  139. goto out;
  140. mlx4_en_stats = mailbox->buf;
  141. spin_lock_bh(&priv->stats_lock);
  142. stats->rx_packets = be32_to_cpu(mlx4_en_stats->RTOTFRMS) -
  143. be32_to_cpu(mlx4_en_stats->RDROP);
  144. stats->tx_packets = be64_to_cpu(mlx4_en_stats->TTOT_prio_0) +
  145. be64_to_cpu(mlx4_en_stats->TTOT_prio_1) +
  146. be64_to_cpu(mlx4_en_stats->TTOT_prio_2) +
  147. be64_to_cpu(mlx4_en_stats->TTOT_prio_3) +
  148. be64_to_cpu(mlx4_en_stats->TTOT_prio_4) +
  149. be64_to_cpu(mlx4_en_stats->TTOT_prio_5) +
  150. be64_to_cpu(mlx4_en_stats->TTOT_prio_6) +
  151. be64_to_cpu(mlx4_en_stats->TTOT_prio_7) +
  152. be64_to_cpu(mlx4_en_stats->TTOT_novlan) +
  153. be64_to_cpu(mlx4_en_stats->TTOT_loopbk);
  154. stats->rx_bytes = be64_to_cpu(mlx4_en_stats->ROCT_prio_0) +
  155. be64_to_cpu(mlx4_en_stats->ROCT_prio_1) +
  156. be64_to_cpu(mlx4_en_stats->ROCT_prio_2) +
  157. be64_to_cpu(mlx4_en_stats->ROCT_prio_3) +
  158. be64_to_cpu(mlx4_en_stats->ROCT_prio_4) +
  159. be64_to_cpu(mlx4_en_stats->ROCT_prio_5) +
  160. be64_to_cpu(mlx4_en_stats->ROCT_prio_6) +
  161. be64_to_cpu(mlx4_en_stats->ROCT_prio_7) +
  162. be64_to_cpu(mlx4_en_stats->ROCT_novlan);
  163. stats->tx_bytes = be64_to_cpu(mlx4_en_stats->TTTLOCT_prio_0) +
  164. be64_to_cpu(mlx4_en_stats->TTTLOCT_prio_1) +
  165. be64_to_cpu(mlx4_en_stats->TTTLOCT_prio_2) +
  166. be64_to_cpu(mlx4_en_stats->TTTLOCT_prio_3) +
  167. be64_to_cpu(mlx4_en_stats->TTTLOCT_prio_4) +
  168. be64_to_cpu(mlx4_en_stats->TTTLOCT_prio_5) +
  169. be64_to_cpu(mlx4_en_stats->TTTLOCT_prio_6) +
  170. be64_to_cpu(mlx4_en_stats->TTTLOCT_prio_7) +
  171. be64_to_cpu(mlx4_en_stats->TTTLOCT_novlan) +
  172. be64_to_cpu(mlx4_en_stats->TTTLOCT_loopbk);
  173. stats->rx_errors = be64_to_cpu(mlx4_en_stats->PCS) +
  174. be32_to_cpu(mlx4_en_stats->RdropLength) +
  175. be32_to_cpu(mlx4_en_stats->RJBBR) +
  176. be32_to_cpu(mlx4_en_stats->RCRC) +
  177. be32_to_cpu(mlx4_en_stats->RRUNT);
  178. stats->tx_errors = be32_to_cpu(mlx4_en_stats->TDROP);
  179. stats->multicast = be64_to_cpu(mlx4_en_stats->MCAST_prio_0) +
  180. be64_to_cpu(mlx4_en_stats->MCAST_prio_1) +
  181. be64_to_cpu(mlx4_en_stats->MCAST_prio_2) +
  182. be64_to_cpu(mlx4_en_stats->MCAST_prio_3) +
  183. be64_to_cpu(mlx4_en_stats->MCAST_prio_4) +
  184. be64_to_cpu(mlx4_en_stats->MCAST_prio_5) +
  185. be64_to_cpu(mlx4_en_stats->MCAST_prio_6) +
  186. be64_to_cpu(mlx4_en_stats->MCAST_prio_7) +
  187. be64_to_cpu(mlx4_en_stats->MCAST_novlan);
  188. stats->collisions = 0;
  189. stats->rx_length_errors = be32_to_cpu(mlx4_en_stats->RdropLength);
  190. stats->rx_over_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
  191. stats->rx_crc_errors = be32_to_cpu(mlx4_en_stats->RCRC);
  192. stats->rx_frame_errors = 0;
  193. stats->rx_fifo_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
  194. stats->rx_missed_errors = be32_to_cpu(mlx4_en_stats->RdropOvflw);
  195. stats->tx_aborted_errors = 0;
  196. stats->tx_carrier_errors = 0;
  197. stats->tx_fifo_errors = 0;
  198. stats->tx_heartbeat_errors = 0;
  199. stats->tx_window_errors = 0;
  200. priv->pkstats.broadcast =
  201. be64_to_cpu(mlx4_en_stats->RBCAST_prio_0) +
  202. be64_to_cpu(mlx4_en_stats->RBCAST_prio_1) +
  203. be64_to_cpu(mlx4_en_stats->RBCAST_prio_2) +
  204. be64_to_cpu(mlx4_en_stats->RBCAST_prio_3) +
  205. be64_to_cpu(mlx4_en_stats->RBCAST_prio_4) +
  206. be64_to_cpu(mlx4_en_stats->RBCAST_prio_5) +
  207. be64_to_cpu(mlx4_en_stats->RBCAST_prio_6) +
  208. be64_to_cpu(mlx4_en_stats->RBCAST_prio_7) +
  209. be64_to_cpu(mlx4_en_stats->RBCAST_novlan);
  210. priv->pkstats.rx_prio[0] = be64_to_cpu(mlx4_en_stats->RTOT_prio_0);
  211. priv->pkstats.rx_prio[1] = be64_to_cpu(mlx4_en_stats->RTOT_prio_1);
  212. priv->pkstats.rx_prio[2] = be64_to_cpu(mlx4_en_stats->RTOT_prio_2);
  213. priv->pkstats.rx_prio[3] = be64_to_cpu(mlx4_en_stats->RTOT_prio_3);
  214. priv->pkstats.rx_prio[4] = be64_to_cpu(mlx4_en_stats->RTOT_prio_4);
  215. priv->pkstats.rx_prio[5] = be64_to_cpu(mlx4_en_stats->RTOT_prio_5);
  216. priv->pkstats.rx_prio[6] = be64_to_cpu(mlx4_en_stats->RTOT_prio_6);
  217. priv->pkstats.rx_prio[7] = be64_to_cpu(mlx4_en_stats->RTOT_prio_7);
  218. priv->pkstats.tx_prio[0] = be64_to_cpu(mlx4_en_stats->TTOT_prio_0);
  219. priv->pkstats.tx_prio[1] = be64_to_cpu(mlx4_en_stats->TTOT_prio_1);
  220. priv->pkstats.tx_prio[2] = be64_to_cpu(mlx4_en_stats->TTOT_prio_2);
  221. priv->pkstats.tx_prio[3] = be64_to_cpu(mlx4_en_stats->TTOT_prio_3);
  222. priv->pkstats.tx_prio[4] = be64_to_cpu(mlx4_en_stats->TTOT_prio_4);
  223. priv->pkstats.tx_prio[5] = be64_to_cpu(mlx4_en_stats->TTOT_prio_5);
  224. priv->pkstats.tx_prio[6] = be64_to_cpu(mlx4_en_stats->TTOT_prio_6);
  225. priv->pkstats.tx_prio[7] = be64_to_cpu(mlx4_en_stats->TTOT_prio_7);
  226. spin_unlock_bh(&priv->stats_lock);
  227. out:
  228. mlx4_free_cmd_mailbox(mdev->dev, mailbox);
  229. return err;
  230. }