fw_qos.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies.
  4. * All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #include <linux/export.h>
  35. #include "fw_qos.h"
  36. #include "fw.h"
  37. enum {
  38. /* allocate vpp opcode modifiers */
  39. MLX4_ALLOCATE_VPP_ALLOCATE = 0x0,
  40. MLX4_ALLOCATE_VPP_QUERY = 0x1
  41. };
  42. enum {
  43. /* set vport qos opcode modifiers */
  44. MLX4_SET_VPORT_QOS_SET = 0x0,
  45. MLX4_SET_VPORT_QOS_QUERY = 0x1
  46. };
  47. struct mlx4_set_port_prio2tc_context {
  48. u8 prio2tc[4];
  49. };
  50. struct mlx4_port_scheduler_tc_cfg_be {
  51. __be16 pg;
  52. __be16 bw_precentage;
  53. __be16 max_bw_units; /* 3-100Mbps, 4-1Gbps, other values - reserved */
  54. __be16 max_bw_value;
  55. };
  56. struct mlx4_set_port_scheduler_context {
  57. struct mlx4_port_scheduler_tc_cfg_be tc[MLX4_NUM_TC];
  58. };
  59. /* Granular Qos (per VF) section */
  60. struct mlx4_alloc_vpp_param {
  61. __be32 availible_vpp;
  62. __be32 vpp_p_up[MLX4_NUM_UP];
  63. };
  64. struct mlx4_prio_qos_param {
  65. __be32 bw_share;
  66. __be32 max_avg_bw;
  67. __be32 reserved;
  68. __be32 enable;
  69. __be32 reserved1[4];
  70. };
  71. struct mlx4_set_vport_context {
  72. __be32 reserved[8];
  73. struct mlx4_prio_qos_param qos_p_up[MLX4_NUM_UP];
  74. };
  75. int mlx4_SET_PORT_PRIO2TC(struct mlx4_dev *dev, u8 port, u8 *prio2tc)
  76. {
  77. struct mlx4_cmd_mailbox *mailbox;
  78. struct mlx4_set_port_prio2tc_context *context;
  79. int err;
  80. u32 in_mod;
  81. int i;
  82. mailbox = mlx4_alloc_cmd_mailbox(dev);
  83. if (IS_ERR(mailbox))
  84. return PTR_ERR(mailbox);
  85. context = mailbox->buf;
  86. for (i = 0; i < MLX4_NUM_UP; i += 2)
  87. context->prio2tc[i >> 1] = prio2tc[i] << 4 | prio2tc[i + 1];
  88. in_mod = MLX4_SET_PORT_PRIO2TC << 8 | port;
  89. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  90. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  91. mlx4_free_cmd_mailbox(dev, mailbox);
  92. return err;
  93. }
  94. EXPORT_SYMBOL(mlx4_SET_PORT_PRIO2TC);
  95. int mlx4_SET_PORT_SCHEDULER(struct mlx4_dev *dev, u8 port, u8 *tc_tx_bw,
  96. u8 *pg, u16 *ratelimit)
  97. {
  98. struct mlx4_cmd_mailbox *mailbox;
  99. struct mlx4_set_port_scheduler_context *context;
  100. int err;
  101. u32 in_mod;
  102. int i;
  103. mailbox = mlx4_alloc_cmd_mailbox(dev);
  104. if (IS_ERR(mailbox))
  105. return PTR_ERR(mailbox);
  106. context = mailbox->buf;
  107. for (i = 0; i < MLX4_NUM_TC; i++) {
  108. struct mlx4_port_scheduler_tc_cfg_be *tc = &context->tc[i];
  109. u16 r;
  110. if (ratelimit && ratelimit[i]) {
  111. if (ratelimit[i] <= MLX4_MAX_100M_UNITS_VAL) {
  112. r = ratelimit[i];
  113. tc->max_bw_units =
  114. htons(MLX4_RATELIMIT_100M_UNITS);
  115. } else {
  116. r = ratelimit[i] / 10;
  117. tc->max_bw_units =
  118. htons(MLX4_RATELIMIT_1G_UNITS);
  119. }
  120. tc->max_bw_value = htons(r);
  121. } else {
  122. tc->max_bw_value = htons(MLX4_RATELIMIT_DEFAULT);
  123. tc->max_bw_units = htons(MLX4_RATELIMIT_1G_UNITS);
  124. }
  125. tc->pg = htons(pg[i]);
  126. tc->bw_precentage = htons(tc_tx_bw[i]);
  127. }
  128. in_mod = MLX4_SET_PORT_SCHEDULER << 8 | port;
  129. err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
  130. MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
  131. mlx4_free_cmd_mailbox(dev, mailbox);
  132. return err;
  133. }
  134. EXPORT_SYMBOL(mlx4_SET_PORT_SCHEDULER);
  135. int mlx4_ALLOCATE_VPP_get(struct mlx4_dev *dev, u8 port,
  136. u16 *availible_vpp, u8 *vpp_p_up)
  137. {
  138. int i;
  139. int err;
  140. struct mlx4_cmd_mailbox *mailbox;
  141. struct mlx4_alloc_vpp_param *out_param;
  142. mailbox = mlx4_alloc_cmd_mailbox(dev);
  143. if (IS_ERR(mailbox))
  144. return PTR_ERR(mailbox);
  145. out_param = mailbox->buf;
  146. err = mlx4_cmd_box(dev, 0, mailbox->dma, port,
  147. MLX4_ALLOCATE_VPP_QUERY,
  148. MLX4_CMD_ALLOCATE_VPP,
  149. MLX4_CMD_TIME_CLASS_A,
  150. MLX4_CMD_NATIVE);
  151. if (err)
  152. goto out;
  153. /* Total number of supported VPPs */
  154. *availible_vpp = (u16)be32_to_cpu(out_param->availible_vpp);
  155. for (i = 0; i < MLX4_NUM_UP; i++)
  156. vpp_p_up[i] = (u8)be32_to_cpu(out_param->vpp_p_up[i]);
  157. out:
  158. mlx4_free_cmd_mailbox(dev, mailbox);
  159. return err;
  160. }
  161. EXPORT_SYMBOL(mlx4_ALLOCATE_VPP_get);
  162. int mlx4_ALLOCATE_VPP_set(struct mlx4_dev *dev, u8 port, u8 *vpp_p_up)
  163. {
  164. int i;
  165. int err;
  166. struct mlx4_cmd_mailbox *mailbox;
  167. struct mlx4_alloc_vpp_param *in_param;
  168. mailbox = mlx4_alloc_cmd_mailbox(dev);
  169. if (IS_ERR(mailbox))
  170. return PTR_ERR(mailbox);
  171. in_param = mailbox->buf;
  172. for (i = 0; i < MLX4_NUM_UP; i++)
  173. in_param->vpp_p_up[i] = cpu_to_be32(vpp_p_up[i]);
  174. err = mlx4_cmd(dev, mailbox->dma, port,
  175. MLX4_ALLOCATE_VPP_ALLOCATE,
  176. MLX4_CMD_ALLOCATE_VPP,
  177. MLX4_CMD_TIME_CLASS_A,
  178. MLX4_CMD_NATIVE);
  179. mlx4_free_cmd_mailbox(dev, mailbox);
  180. return err;
  181. }
  182. EXPORT_SYMBOL(mlx4_ALLOCATE_VPP_set);
  183. int mlx4_SET_VPORT_QOS_get(struct mlx4_dev *dev, u8 port, u8 vport,
  184. struct mlx4_vport_qos_param *out_param)
  185. {
  186. int i;
  187. int err;
  188. struct mlx4_cmd_mailbox *mailbox;
  189. struct mlx4_set_vport_context *ctx;
  190. mailbox = mlx4_alloc_cmd_mailbox(dev);
  191. if (IS_ERR(mailbox))
  192. return PTR_ERR(mailbox);
  193. ctx = mailbox->buf;
  194. err = mlx4_cmd_box(dev, 0, mailbox->dma, (vport << 8) | port,
  195. MLX4_SET_VPORT_QOS_QUERY,
  196. MLX4_CMD_SET_VPORT_QOS,
  197. MLX4_CMD_TIME_CLASS_A,
  198. MLX4_CMD_NATIVE);
  199. if (err)
  200. goto out;
  201. for (i = 0; i < MLX4_NUM_UP; i++) {
  202. out_param[i].bw_share = be32_to_cpu(ctx->qos_p_up[i].bw_share);
  203. out_param[i].max_avg_bw =
  204. be32_to_cpu(ctx->qos_p_up[i].max_avg_bw);
  205. out_param[i].enable =
  206. !!(be32_to_cpu(ctx->qos_p_up[i].enable) & 31);
  207. }
  208. out:
  209. mlx4_free_cmd_mailbox(dev, mailbox);
  210. return err;
  211. }
  212. EXPORT_SYMBOL(mlx4_SET_VPORT_QOS_get);
  213. int mlx4_SET_VPORT_QOS_set(struct mlx4_dev *dev, u8 port, u8 vport,
  214. struct mlx4_vport_qos_param *in_param)
  215. {
  216. int i;
  217. int err;
  218. struct mlx4_cmd_mailbox *mailbox;
  219. struct mlx4_set_vport_context *ctx;
  220. mailbox = mlx4_alloc_cmd_mailbox(dev);
  221. if (IS_ERR(mailbox))
  222. return PTR_ERR(mailbox);
  223. ctx = mailbox->buf;
  224. for (i = 0; i < MLX4_NUM_UP; i++) {
  225. ctx->qos_p_up[i].bw_share = cpu_to_be32(in_param[i].bw_share);
  226. ctx->qos_p_up[i].max_avg_bw =
  227. cpu_to_be32(in_param[i].max_avg_bw);
  228. ctx->qos_p_up[i].enable =
  229. cpu_to_be32(in_param[i].enable << 31);
  230. }
  231. err = mlx4_cmd(dev, mailbox->dma, (vport << 8) | port,
  232. MLX4_SET_VPORT_QOS_SET,
  233. MLX4_CMD_SET_VPORT_QOS,
  234. MLX4_CMD_TIME_CLASS_A,
  235. MLX4_CMD_NATIVE);
  236. mlx4_free_cmd_mailbox(dev, mailbox);
  237. return err;
  238. }
  239. EXPORT_SYMBOL(mlx4_SET_VPORT_QOS_set);