blob: c326e586bc1c51881feec2eece5474eda39689bd [file] [log] [blame]
Jiri Pirko56ade8f2015-10-16 14:01:37 +02001/*
2 * drivers/net/ethernet/mellanox/mlxsw/spectrum_buffers.c
3 * Copyright (c) 2015 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com>
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the names of the copyright holders nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * Alternatively, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") version 2 as published by the Free
20 * Software Foundation.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <linux/kernel.h>
36#include <linux/types.h>
Ido Schimmeldd6cb0f2016-04-06 17:10:01 +020037#include <linux/dcbnl.h>
Ido Schimmelff6551e2016-04-06 17:10:03 +020038#include <linux/if_ether.h>
Jiri Pirko56ade8f2015-10-16 14:01:37 +020039
40#include "spectrum.h"
41#include "core.h"
42#include "port.h"
43#include "reg.h"
44
Jiri Pirko94266e32016-04-14 18:19:16 +020045static int mlxsw_sp_sb_pr_write(struct mlxsw_sp *mlxsw_sp, u8 pool,
46 enum mlxsw_reg_sbxx_dir dir,
47 enum mlxsw_reg_sbpr_mode mode, u32 size)
48{
49 char sbpr_pl[MLXSW_REG_SBPR_LEN];
50
51 mlxsw_reg_sbpr_pack(sbpr_pl, pool, dir, mode, size);
52 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbpr), sbpr_pl);
53}
54
55static int mlxsw_sp_sb_cm_write(struct mlxsw_sp *mlxsw_sp, u8 local_port,
56 u8 pg_buff, enum mlxsw_reg_sbxx_dir dir,
57 u32 min_buff, u32 max_buff, u8 pool)
58{
59 char sbcm_pl[MLXSW_REG_SBCM_LEN];
60
61 mlxsw_reg_sbcm_pack(sbcm_pl, local_port, pg_buff, dir,
62 min_buff, max_buff, pool);
63 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbcm), sbcm_pl);
64}
65
66static int mlxsw_sp_sb_pm_write(struct mlxsw_sp *mlxsw_sp, u8 local_port,
67 u8 pool, enum mlxsw_reg_sbxx_dir dir,
68 u32 min_buff, u32 max_buff)
69{
70 char sbpm_pl[MLXSW_REG_SBPM_LEN];
71
72 mlxsw_reg_sbpm_pack(sbpm_pl, local_port, pool, dir, min_buff, max_buff);
73 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbpm), sbpm_pl);
74}
75
Jiri Pirkob11c3b42016-04-14 18:19:17 +020076static const u16 mlxsw_sp_pbs[] = {
77 2 * MLXSW_SP_BYTES_TO_CELLS(ETH_FRAME_LEN),
78 0,
79 0,
80 0,
81 0,
82 0,
83 0,
84 0,
85 0, /* Unused */
86 2 * MLXSW_SP_BYTES_TO_CELLS(MLXSW_PORT_MAX_MTU),
Jiri Pirko56ade8f2015-10-16 14:01:37 +020087};
88
89#define MLXSW_SP_PBS_LEN ARRAY_SIZE(mlxsw_sp_pbs)
90
91static int mlxsw_sp_port_pb_init(struct mlxsw_sp_port *mlxsw_sp_port)
92{
93 char pbmc_pl[MLXSW_REG_PBMC_LEN];
94 int i;
95
96 mlxsw_reg_pbmc_pack(pbmc_pl, mlxsw_sp_port->local_port,
97 0xffff, 0xffff / 2);
98 for (i = 0; i < MLXSW_SP_PBS_LEN; i++) {
Jiri Pirkob11c3b42016-04-14 18:19:17 +020099 if (i == 8)
100 continue;
101 mlxsw_reg_pbmc_lossy_buffer_pack(pbmc_pl, i, mlxsw_sp_pbs[i]);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200102 }
Ido Schimmeld6b7c132016-04-06 17:10:05 +0200103 mlxsw_reg_pbmc_lossy_buffer_pack(pbmc_pl,
104 MLXSW_REG_PBMC_PORT_SHARED_BUF_IDX, 0);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200105 return mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core,
106 MLXSW_REG(pbmc), pbmc_pl);
107}
108
Ido Schimmeldd6cb0f2016-04-06 17:10:01 +0200109static int mlxsw_sp_port_pb_prio_init(struct mlxsw_sp_port *mlxsw_sp_port)
110{
111 char pptb_pl[MLXSW_REG_PPTB_LEN];
112 int i;
113
114 mlxsw_reg_pptb_pack(pptb_pl, mlxsw_sp_port->local_port);
115 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
116 mlxsw_reg_pptb_prio_to_buff_set(pptb_pl, i, 0);
117 return mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core, MLXSW_REG(pptb),
118 pptb_pl);
119}
120
121static int mlxsw_sp_port_headroom_init(struct mlxsw_sp_port *mlxsw_sp_port)
122{
123 int err;
124
125 err = mlxsw_sp_port_pb_init(mlxsw_sp_port);
126 if (err)
127 return err;
128 return mlxsw_sp_port_pb_prio_init(mlxsw_sp_port);
129}
130
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200131struct mlxsw_sp_sb_pool {
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200132 enum mlxsw_reg_sbpr_mode mode;
133 u32 size;
134};
135
136#define MLXSW_SP_SB_POOL_INGRESS_SIZE \
Ido Schimmel1a198442016-04-06 17:10:02 +0200137 (15000000 - (2 * 20000 * MLXSW_PORT_MAX_PORTS))
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200138#define MLXSW_SP_SB_POOL_EGRESS_SIZE \
Ido Schimmel1a198442016-04-06 17:10:02 +0200139 (14000000 - (8 * 1500 * MLXSW_PORT_MAX_PORTS))
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200140
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200141#define MLXSW_SP_SB_POOL(_mode, _size) \
142 { \
143 .mode = _mode, \
144 .size = _size, \
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200145 }
146
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200147static const struct mlxsw_sp_sb_pool mlxsw_sp_sb_pools_ingress[] = {
148 MLXSW_SP_SB_POOL(MLXSW_REG_SBPR_MODE_DYNAMIC,
149 MLXSW_SP_BYTES_TO_CELLS(MLXSW_SP_SB_POOL_INGRESS_SIZE)),
150 MLXSW_SP_SB_POOL(MLXSW_REG_SBPR_MODE_DYNAMIC, 0),
151 MLXSW_SP_SB_POOL(MLXSW_REG_SBPR_MODE_DYNAMIC, 0),
152 MLXSW_SP_SB_POOL(MLXSW_REG_SBPR_MODE_DYNAMIC, 0),
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200153};
154
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200155#define MLXSW_SP_SB_POOLS_INGRESS_LEN ARRAY_SIZE(mlxsw_sp_sb_pools_ingress)
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200156
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200157static const struct mlxsw_sp_sb_pool mlxsw_sp_sb_pools_egress[] = {
158 MLXSW_SP_SB_POOL(MLXSW_REG_SBPR_MODE_DYNAMIC,
159 MLXSW_SP_BYTES_TO_CELLS(MLXSW_SP_SB_POOL_EGRESS_SIZE)),
160 MLXSW_SP_SB_POOL(MLXSW_REG_SBPR_MODE_DYNAMIC, 0),
161 MLXSW_SP_SB_POOL(MLXSW_REG_SBPR_MODE_DYNAMIC, 0),
162 MLXSW_SP_SB_POOL(MLXSW_REG_SBPR_MODE_DYNAMIC,
163 MLXSW_SP_BYTES_TO_CELLS(MLXSW_SP_SB_POOL_EGRESS_SIZE)),
164};
165
166#define MLXSW_SP_SB_POOLS_EGRESS_LEN ARRAY_SIZE(mlxsw_sp_sb_pools_egress)
167
168static int __mlxsw_sp_sb_pools_init(struct mlxsw_sp *mlxsw_sp,
169 enum mlxsw_reg_sbxx_dir dir,
170 const struct mlxsw_sp_sb_pool *pools,
171 size_t pools_len)
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200172{
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200173 int i;
174 int err;
175
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200176 for (i = 0; i < pools_len; i++) {
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200177 const struct mlxsw_sp_sb_pool *pool;
178
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200179 pool = &pools[i];
180 err = mlxsw_sp_sb_pr_write(mlxsw_sp, i, dir,
Jiri Pirko94266e32016-04-14 18:19:16 +0200181 pool->mode, pool->size);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200182 if (err)
183 return err;
184 }
185 return 0;
186}
187
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200188static int mlxsw_sp_sb_pools_init(struct mlxsw_sp *mlxsw_sp)
189{
190 int err;
191
192 err = __mlxsw_sp_sb_pools_init(mlxsw_sp, MLXSW_REG_SBXX_DIR_INGRESS,
193 mlxsw_sp_sb_pools_ingress,
194 MLXSW_SP_SB_POOLS_INGRESS_LEN);
195 if (err)
196 return err;
197 return __mlxsw_sp_sb_pools_init(mlxsw_sp, MLXSW_REG_SBXX_DIR_EGRESS,
198 mlxsw_sp_sb_pools_egress,
199 MLXSW_SP_SB_POOLS_EGRESS_LEN);
200}
201
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200202struct mlxsw_sp_sb_cm {
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200203 u32 min_buff;
204 u32 max_buff;
205 u8 pool;
206};
207
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200208#define MLXSW_SP_SB_CM(_min_buff, _max_buff, _pool) \
209 { \
210 .min_buff = _min_buff, \
211 .max_buff = _max_buff, \
212 .pool = _pool, \
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200213 }
214
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200215static const struct mlxsw_sp_sb_cm mlxsw_sp_sb_cms_ingress[] = {
216 MLXSW_SP_SB_CM(MLXSW_SP_BYTES_TO_CELLS(10000), 8, 0),
217 MLXSW_SP_SB_CM(0, 0, 0),
218 MLXSW_SP_SB_CM(0, 0, 0),
219 MLXSW_SP_SB_CM(0, 0, 0),
220 MLXSW_SP_SB_CM(0, 0, 0),
221 MLXSW_SP_SB_CM(0, 0, 0),
222 MLXSW_SP_SB_CM(0, 0, 0),
223 MLXSW_SP_SB_CM(0, 0, 0),
224 MLXSW_SP_SB_CM(0, 0, 0), /* dummy, this PG does not exist */
225 MLXSW_SP_SB_CM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200226};
227
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200228#define MLXSW_SP_SB_CMS_INGRESS_LEN ARRAY_SIZE(mlxsw_sp_sb_cms_ingress)
229
230static const struct mlxsw_sp_sb_cm mlxsw_sp_sb_cms_egress[] = {
231 MLXSW_SP_SB_CM(MLXSW_SP_BYTES_TO_CELLS(1500), 9, 0),
232 MLXSW_SP_SB_CM(MLXSW_SP_BYTES_TO_CELLS(1500), 9, 0),
233 MLXSW_SP_SB_CM(MLXSW_SP_BYTES_TO_CELLS(1500), 9, 0),
234 MLXSW_SP_SB_CM(MLXSW_SP_BYTES_TO_CELLS(1500), 9, 0),
235 MLXSW_SP_SB_CM(MLXSW_SP_BYTES_TO_CELLS(1500), 9, 0),
236 MLXSW_SP_SB_CM(MLXSW_SP_BYTES_TO_CELLS(1500), 9, 0),
237 MLXSW_SP_SB_CM(MLXSW_SP_BYTES_TO_CELLS(1500), 9, 0),
238 MLXSW_SP_SB_CM(MLXSW_SP_BYTES_TO_CELLS(1500), 9, 0),
239 MLXSW_SP_SB_CM(0, 0, 0),
240 MLXSW_SP_SB_CM(0, 0, 0),
241 MLXSW_SP_SB_CM(0, 0, 0),
242 MLXSW_SP_SB_CM(0, 0, 0),
243 MLXSW_SP_SB_CM(0, 0, 0),
244 MLXSW_SP_SB_CM(0, 0, 0),
245 MLXSW_SP_SB_CM(0, 0, 0),
246 MLXSW_SP_SB_CM(0, 0, 0),
247 MLXSW_SP_SB_CM(1, 0xff, 0),
248};
249
250#define MLXSW_SP_SB_CMS_EGRESS_LEN ARRAY_SIZE(mlxsw_sp_sb_cms_egress)
251
252#define MLXSW_SP_CPU_PORT_SB_CM MLXSW_SP_SB_CM(104, 2, 3)
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200253
254static const struct mlxsw_sp_sb_cm mlxsw_sp_cpu_port_sb_cms[] = {
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200255 MLXSW_SP_CPU_PORT_SB_CM,
256 MLXSW_SP_CPU_PORT_SB_CM,
257 MLXSW_SP_CPU_PORT_SB_CM,
258 MLXSW_SP_CPU_PORT_SB_CM,
259 MLXSW_SP_CPU_PORT_SB_CM,
260 MLXSW_SP_CPU_PORT_SB_CM,
261 MLXSW_SP_CPU_PORT_SB_CM,
262 MLXSW_SP_CPU_PORT_SB_CM,
263 MLXSW_SP_CPU_PORT_SB_CM,
264 MLXSW_SP_CPU_PORT_SB_CM,
265 MLXSW_SP_CPU_PORT_SB_CM,
266 MLXSW_SP_CPU_PORT_SB_CM,
267 MLXSW_SP_CPU_PORT_SB_CM,
268 MLXSW_SP_CPU_PORT_SB_CM,
269 MLXSW_SP_CPU_PORT_SB_CM,
270 MLXSW_SP_CPU_PORT_SB_CM,
271 MLXSW_SP_CPU_PORT_SB_CM,
272 MLXSW_SP_CPU_PORT_SB_CM,
273 MLXSW_SP_CPU_PORT_SB_CM,
274 MLXSW_SP_CPU_PORT_SB_CM,
275 MLXSW_SP_CPU_PORT_SB_CM,
276 MLXSW_SP_CPU_PORT_SB_CM,
277 MLXSW_SP_CPU_PORT_SB_CM,
278 MLXSW_SP_CPU_PORT_SB_CM,
279 MLXSW_SP_CPU_PORT_SB_CM,
280 MLXSW_SP_CPU_PORT_SB_CM,
281 MLXSW_SP_CPU_PORT_SB_CM,
282 MLXSW_SP_CPU_PORT_SB_CM,
283 MLXSW_SP_CPU_PORT_SB_CM,
284 MLXSW_SP_CPU_PORT_SB_CM,
285 MLXSW_SP_CPU_PORT_SB_CM,
286 MLXSW_SP_CPU_PORT_SB_CM,
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200287};
288
289#define MLXSW_SP_CPU_PORT_SB_MCS_LEN \
290 ARRAY_SIZE(mlxsw_sp_cpu_port_sb_cms)
291
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200292static int __mlxsw_sp_sb_cms_init(struct mlxsw_sp *mlxsw_sp, u8 local_port,
293 enum mlxsw_reg_sbxx_dir dir,
294 const struct mlxsw_sp_sb_cm *cms,
295 size_t cms_len)
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200296{
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200297 int i;
298 int err;
299
300 for (i = 0; i < cms_len; i++) {
301 const struct mlxsw_sp_sb_cm *cm;
302
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200303 if (i == 8 && dir == MLXSW_REG_SBXX_DIR_INGRESS)
304 continue; /* PG number 8 does not exist, skip it */
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200305 cm = &cms[i];
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200306 err = mlxsw_sp_sb_cm_write(mlxsw_sp, local_port, i, dir,
307 cm->min_buff, cm->max_buff,
308 cm->pool);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200309 if (err)
310 return err;
311 }
312 return 0;
313}
314
315static int mlxsw_sp_port_sb_cms_init(struct mlxsw_sp_port *mlxsw_sp_port)
316{
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200317 int err;
318
319 err = __mlxsw_sp_sb_cms_init(mlxsw_sp_port->mlxsw_sp,
320 mlxsw_sp_port->local_port,
321 MLXSW_REG_SBXX_DIR_INGRESS,
322 mlxsw_sp_sb_cms_ingress,
323 MLXSW_SP_SB_CMS_INGRESS_LEN);
324 if (err)
325 return err;
326 return __mlxsw_sp_sb_cms_init(mlxsw_sp_port->mlxsw_sp,
327 mlxsw_sp_port->local_port,
328 MLXSW_REG_SBXX_DIR_EGRESS,
329 mlxsw_sp_sb_cms_egress,
330 MLXSW_SP_SB_CMS_EGRESS_LEN);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200331}
332
333static int mlxsw_sp_cpu_port_sb_cms_init(struct mlxsw_sp *mlxsw_sp)
334{
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200335 return __mlxsw_sp_sb_cms_init(mlxsw_sp, 0, MLXSW_REG_SBXX_DIR_EGRESS,
336 mlxsw_sp_cpu_port_sb_cms,
337 MLXSW_SP_CPU_PORT_SB_MCS_LEN);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200338}
339
340struct mlxsw_sp_sb_pm {
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200341 u32 min_buff;
342 u32 max_buff;
343};
344
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200345#define MLXSW_SP_SB_PM(_min_buff, _max_buff) \
346 { \
347 .min_buff = _min_buff, \
348 .max_buff = _max_buff, \
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200349 }
350
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200351static const struct mlxsw_sp_sb_pm mlxsw_sp_sb_pms_ingress[] = {
352 MLXSW_SP_SB_PM(0, 0xff),
353 MLXSW_SP_SB_PM(0, 0),
354 MLXSW_SP_SB_PM(0, 0),
355 MLXSW_SP_SB_PM(0, 0),
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200356};
357
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200358#define MLXSW_SP_SB_PMS_INGRESS_LEN ARRAY_SIZE(mlxsw_sp_sb_pms_ingress)
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200359
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200360static const struct mlxsw_sp_sb_pm mlxsw_sp_sb_pms_egress[] = {
361 MLXSW_SP_SB_PM(0, 7),
362 MLXSW_SP_SB_PM(0, 0),
363 MLXSW_SP_SB_PM(0, 0),
364 MLXSW_SP_SB_PM(0, 0),
365};
366
367#define MLXSW_SP_SB_PMS_EGRESS_LEN ARRAY_SIZE(mlxsw_sp_sb_pms_egress)
368
369static int __mlxsw_sp_port_sb_pms_init(struct mlxsw_sp *mlxsw_sp, u8 local_port,
370 enum mlxsw_reg_sbxx_dir dir,
371 const struct mlxsw_sp_sb_pm *pms,
372 size_t pms_len)
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200373{
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200374 int i;
375 int err;
376
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200377 for (i = 0; i < pms_len; i++) {
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200378 const struct mlxsw_sp_sb_pm *pm;
379
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200380 pm = &pms[i];
381 err = mlxsw_sp_sb_pm_write(mlxsw_sp, local_port, i, dir,
Jiri Pirko94266e32016-04-14 18:19:16 +0200382 pm->min_buff, pm->max_buff);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200383 if (err)
384 return err;
385 }
386 return 0;
387}
388
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200389static int mlxsw_sp_port_sb_pms_init(struct mlxsw_sp_port *mlxsw_sp_port)
390{
391 int err;
392
393 err = __mlxsw_sp_port_sb_pms_init(mlxsw_sp_port->mlxsw_sp,
394 mlxsw_sp_port->local_port,
395 MLXSW_REG_SBXX_DIR_INGRESS,
396 mlxsw_sp_sb_pms_ingress,
397 MLXSW_SP_SB_PMS_INGRESS_LEN);
398 if (err)
399 return err;
400 return __mlxsw_sp_port_sb_pms_init(mlxsw_sp_port->mlxsw_sp,
401 mlxsw_sp_port->local_port,
402 MLXSW_REG_SBXX_DIR_EGRESS,
403 mlxsw_sp_sb_pms_egress,
404 MLXSW_SP_SB_PMS_EGRESS_LEN);
405}
406
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200407struct mlxsw_sp_sb_mm {
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200408 u32 min_buff;
409 u32 max_buff;
410 u8 pool;
411};
412
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200413#define MLXSW_SP_SB_MM(_min_buff, _max_buff, _pool) \
414 { \
415 .min_buff = _min_buff, \
416 .max_buff = _max_buff, \
417 .pool = _pool, \
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200418 }
419
420static const struct mlxsw_sp_sb_mm mlxsw_sp_sb_mms[] = {
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200421 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
422 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
423 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
424 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
425 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
426 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
427 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
428 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
429 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
430 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
431 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
432 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
433 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
434 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
435 MLXSW_SP_SB_MM(MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0),
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200436};
437
438#define MLXSW_SP_SB_MMS_LEN ARRAY_SIZE(mlxsw_sp_sb_mms)
439
440static int mlxsw_sp_sb_mms_init(struct mlxsw_sp *mlxsw_sp)
441{
442 char sbmm_pl[MLXSW_REG_SBMM_LEN];
443 int i;
444 int err;
445
446 for (i = 0; i < MLXSW_SP_SB_MMS_LEN; i++) {
447 const struct mlxsw_sp_sb_mm *mc;
448
449 mc = &mlxsw_sp_sb_mms[i];
Jiri Pirkob11c3b42016-04-14 18:19:17 +0200450 mlxsw_reg_sbmm_pack(sbmm_pl, i, mc->min_buff,
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200451 mc->max_buff, mc->pool);
452 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbmm), sbmm_pl);
453 if (err)
454 return err;
455 }
456 return 0;
457}
458
459int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp)
460{
461 int err;
462
463 err = mlxsw_sp_sb_pools_init(mlxsw_sp);
464 if (err)
465 return err;
466 err = mlxsw_sp_cpu_port_sb_cms_init(mlxsw_sp);
467 if (err)
468 return err;
469 err = mlxsw_sp_sb_mms_init(mlxsw_sp);
470
471 return err;
472}
473
474int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port)
475{
476 int err;
477
Ido Schimmeldd6cb0f2016-04-06 17:10:01 +0200478 err = mlxsw_sp_port_headroom_init(mlxsw_sp_port);
Jiri Pirko56ade8f2015-10-16 14:01:37 +0200479 if (err)
480 return err;
481 err = mlxsw_sp_port_sb_cms_init(mlxsw_sp_port);
482 if (err)
483 return err;
484 err = mlxsw_sp_port_sb_pms_init(mlxsw_sp_port);
485
486 return err;
487}