blob: 5ce3440b99c77ec439163f25a6f217f998e85c52 [file] [log] [blame]
Ido Shamay12a889c2015-04-02 16:31:10 +03001/*
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
35#include <linux/export.h>
36#include "fw_qos.h"
Ido Shamay7e95bb92015-04-02 16:31:11 +030037#include "fw.h"
38
39enum {
40 /* allocate vpp opcode modifiers */
41 MLX4_ALLOCATE_VPP_ALLOCATE = 0x0,
42 MLX4_ALLOCATE_VPP_QUERY = 0x1
43};
Ido Shamay12a889c2015-04-02 16:31:10 +030044
45struct mlx4_set_port_prio2tc_context {
46 u8 prio2tc[4];
47};
48
49struct mlx4_port_scheduler_tc_cfg_be {
50 __be16 pg;
51 __be16 bw_precentage;
52 __be16 max_bw_units; /* 3-100Mbps, 4-1Gbps, other values - reserved */
53 __be16 max_bw_value;
54};
55
56struct mlx4_set_port_scheduler_context {
57 struct mlx4_port_scheduler_tc_cfg_be tc[MLX4_NUM_TC];
58};
59
Ido Shamay7e95bb92015-04-02 16:31:11 +030060/* Granular Qos (per VF) section */
61struct mlx4_alloc_vpp_param {
62 __be32 availible_vpp;
63 __be32 vpp_p_up[MLX4_NUM_UP];
64};
65
Ido Shamay12a889c2015-04-02 16:31:10 +030066int mlx4_SET_PORT_PRIO2TC(struct mlx4_dev *dev, u8 port, u8 *prio2tc)
67{
68 struct mlx4_cmd_mailbox *mailbox;
69 struct mlx4_set_port_prio2tc_context *context;
70 int err;
71 u32 in_mod;
72 int i;
73
74 mailbox = mlx4_alloc_cmd_mailbox(dev);
75 if (IS_ERR(mailbox))
76 return PTR_ERR(mailbox);
77
78 context = mailbox->buf;
79
80 for (i = 0; i < MLX4_NUM_UP; i += 2)
81 context->prio2tc[i >> 1] = prio2tc[i] << 4 | prio2tc[i + 1];
82
83 in_mod = MLX4_SET_PORT_PRIO2TC << 8 | port;
84 err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
85 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
86
87 mlx4_free_cmd_mailbox(dev, mailbox);
88 return err;
89}
90EXPORT_SYMBOL(mlx4_SET_PORT_PRIO2TC);
91
92int mlx4_SET_PORT_SCHEDULER(struct mlx4_dev *dev, u8 port, u8 *tc_tx_bw,
93 u8 *pg, u16 *ratelimit)
94{
95 struct mlx4_cmd_mailbox *mailbox;
96 struct mlx4_set_port_scheduler_context *context;
97 int err;
98 u32 in_mod;
99 int i;
100
101 mailbox = mlx4_alloc_cmd_mailbox(dev);
102 if (IS_ERR(mailbox))
103 return PTR_ERR(mailbox);
104
105 context = mailbox->buf;
106
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
111 if (ratelimit && ratelimit[i]) {
112 if (ratelimit[i] <= MLX4_MAX_100M_UNITS_VAL) {
113 r = ratelimit[i];
114 tc->max_bw_units =
115 htons(MLX4_RATELIMIT_100M_UNITS);
116 } else {
117 r = ratelimit[i] / 10;
118 tc->max_bw_units =
119 htons(MLX4_RATELIMIT_1G_UNITS);
120 }
121 tc->max_bw_value = htons(r);
122 } else {
123 tc->max_bw_value = htons(MLX4_RATELIMIT_DEFAULT);
124 tc->max_bw_units = htons(MLX4_RATELIMIT_1G_UNITS);
125 }
126
127 tc->pg = htons(pg[i]);
128 tc->bw_precentage = htons(tc_tx_bw[i]);
129 }
130
131 in_mod = MLX4_SET_PORT_SCHEDULER << 8 | port;
132 err = mlx4_cmd(dev, mailbox->dma, in_mod, 1, MLX4_CMD_SET_PORT,
133 MLX4_CMD_TIME_CLASS_B, MLX4_CMD_NATIVE);
134
135 mlx4_free_cmd_mailbox(dev, mailbox);
136 return err;
137}
138EXPORT_SYMBOL(mlx4_SET_PORT_SCHEDULER);
Ido Shamay7e95bb92015-04-02 16:31:11 +0300139
140int mlx4_ALLOCATE_VPP_get(struct mlx4_dev *dev, u8 port,
141 u16 *availible_vpp, u8 *vpp_p_up)
142{
143 int i;
144 int err;
145 struct mlx4_cmd_mailbox *mailbox;
146 struct mlx4_alloc_vpp_param *out_param;
147
148 mailbox = mlx4_alloc_cmd_mailbox(dev);
149 if (IS_ERR(mailbox))
150 return PTR_ERR(mailbox);
151
152 out_param = mailbox->buf;
153
154 err = mlx4_cmd_box(dev, 0, mailbox->dma, port,
155 MLX4_ALLOCATE_VPP_QUERY,
156 MLX4_CMD_ALLOCATE_VPP,
157 MLX4_CMD_TIME_CLASS_A,
158 MLX4_CMD_NATIVE);
159 if (err)
160 goto out;
161
162 /* Total number of supported VPPs */
163 *availible_vpp = (u16)be32_to_cpu(out_param->availible_vpp);
164
165 for (i = 0; i < MLX4_NUM_UP; i++)
166 vpp_p_up[i] = (u8)be32_to_cpu(out_param->vpp_p_up[i]);
167
168out:
169 mlx4_free_cmd_mailbox(dev, mailbox);
170
171 return err;
172}
173EXPORT_SYMBOL(mlx4_ALLOCATE_VPP_get);
174
175int mlx4_ALLOCATE_VPP_set(struct mlx4_dev *dev, u8 port, u8 *vpp_p_up)
176{
177 int i;
178 int err;
179 struct mlx4_cmd_mailbox *mailbox;
180 struct mlx4_alloc_vpp_param *in_param;
181
182 mailbox = mlx4_alloc_cmd_mailbox(dev);
183 if (IS_ERR(mailbox))
184 return PTR_ERR(mailbox);
185
186 in_param = mailbox->buf;
187
188 for (i = 0; i < MLX4_NUM_UP; i++)
189 in_param->vpp_p_up[i] = cpu_to_be32(vpp_p_up[i]);
190
191 err = mlx4_cmd(dev, mailbox->dma, port,
192 MLX4_ALLOCATE_VPP_ALLOCATE,
193 MLX4_CMD_ALLOCATE_VPP,
194 MLX4_CMD_TIME_CLASS_A,
195 MLX4_CMD_NATIVE);
196
197 mlx4_free_cmd_mailbox(dev, mailbox);
198 return err;
199}
200EXPORT_SYMBOL(mlx4_ALLOCATE_VPP_set);