Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 1 | /* |
| 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 Schimmel | dd6cb0f | 2016-04-06 17:10:01 +0200 | [diff] [blame] | 37 | #include <linux/dcbnl.h> |
Ido Schimmel | ff6551e | 2016-04-06 17:10:03 +0200 | [diff] [blame] | 38 | #include <linux/if_ether.h> |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 39 | |
| 40 | #include "spectrum.h" |
| 41 | #include "core.h" |
| 42 | #include "port.h" |
| 43 | #include "reg.h" |
| 44 | |
| 45 | struct mlxsw_sp_pb { |
| 46 | u8 index; |
| 47 | u16 size; |
| 48 | }; |
| 49 | |
| 50 | #define MLXSW_SP_PB(_index, _size) \ |
| 51 | { \ |
| 52 | .index = _index, \ |
| 53 | .size = _size, \ |
| 54 | } |
| 55 | |
| 56 | static const struct mlxsw_sp_pb mlxsw_sp_pbs[] = { |
Ido Schimmel | ff6551e | 2016-04-06 17:10:03 +0200 | [diff] [blame] | 57 | MLXSW_SP_PB(0, 2 * MLXSW_SP_BYTES_TO_CELLS(ETH_FRAME_LEN)), |
| 58 | MLXSW_SP_PB(1, 0), |
| 59 | MLXSW_SP_PB(2, 0), |
| 60 | MLXSW_SP_PB(3, 0), |
| 61 | MLXSW_SP_PB(4, 0), |
| 62 | MLXSW_SP_PB(5, 0), |
| 63 | MLXSW_SP_PB(6, 0), |
| 64 | MLXSW_SP_PB(7, 0), |
| 65 | MLXSW_SP_PB(9, 2 * MLXSW_SP_BYTES_TO_CELLS(MLXSW_PORT_MAX_MTU)), |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | #define MLXSW_SP_PBS_LEN ARRAY_SIZE(mlxsw_sp_pbs) |
| 69 | |
| 70 | static int mlxsw_sp_port_pb_init(struct mlxsw_sp_port *mlxsw_sp_port) |
| 71 | { |
| 72 | char pbmc_pl[MLXSW_REG_PBMC_LEN]; |
| 73 | int i; |
| 74 | |
| 75 | mlxsw_reg_pbmc_pack(pbmc_pl, mlxsw_sp_port->local_port, |
| 76 | 0xffff, 0xffff / 2); |
| 77 | for (i = 0; i < MLXSW_SP_PBS_LEN; i++) { |
| 78 | const struct mlxsw_sp_pb *pb; |
| 79 | |
| 80 | pb = &mlxsw_sp_pbs[i]; |
| 81 | mlxsw_reg_pbmc_lossy_buffer_pack(pbmc_pl, pb->index, pb->size); |
| 82 | } |
Ido Schimmel | d6b7c13 | 2016-04-06 17:10:05 +0200 | [diff] [blame^] | 83 | mlxsw_reg_pbmc_lossy_buffer_pack(pbmc_pl, |
| 84 | MLXSW_REG_PBMC_PORT_SHARED_BUF_IDX, 0); |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 85 | return mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core, |
| 86 | MLXSW_REG(pbmc), pbmc_pl); |
| 87 | } |
| 88 | |
Ido Schimmel | dd6cb0f | 2016-04-06 17:10:01 +0200 | [diff] [blame] | 89 | static int mlxsw_sp_port_pb_prio_init(struct mlxsw_sp_port *mlxsw_sp_port) |
| 90 | { |
| 91 | char pptb_pl[MLXSW_REG_PPTB_LEN]; |
| 92 | int i; |
| 93 | |
| 94 | mlxsw_reg_pptb_pack(pptb_pl, mlxsw_sp_port->local_port); |
| 95 | for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) |
| 96 | mlxsw_reg_pptb_prio_to_buff_set(pptb_pl, i, 0); |
| 97 | return mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core, MLXSW_REG(pptb), |
| 98 | pptb_pl); |
| 99 | } |
| 100 | |
| 101 | static int mlxsw_sp_port_headroom_init(struct mlxsw_sp_port *mlxsw_sp_port) |
| 102 | { |
| 103 | int err; |
| 104 | |
| 105 | err = mlxsw_sp_port_pb_init(mlxsw_sp_port); |
| 106 | if (err) |
| 107 | return err; |
| 108 | return mlxsw_sp_port_pb_prio_init(mlxsw_sp_port); |
| 109 | } |
| 110 | |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 111 | struct mlxsw_sp_sb_pool { |
| 112 | u8 pool; |
| 113 | enum mlxsw_reg_sbpr_dir dir; |
| 114 | enum mlxsw_reg_sbpr_mode mode; |
| 115 | u32 size; |
| 116 | }; |
| 117 | |
| 118 | #define MLXSW_SP_SB_POOL_INGRESS_SIZE \ |
Ido Schimmel | 1a19844 | 2016-04-06 17:10:02 +0200 | [diff] [blame] | 119 | (15000000 - (2 * 20000 * MLXSW_PORT_MAX_PORTS)) |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 120 | #define MLXSW_SP_SB_POOL_EGRESS_SIZE \ |
Ido Schimmel | 1a19844 | 2016-04-06 17:10:02 +0200 | [diff] [blame] | 121 | (14000000 - (8 * 1500 * MLXSW_PORT_MAX_PORTS)) |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 122 | |
| 123 | #define MLXSW_SP_SB_POOL(_pool, _dir, _mode, _size) \ |
| 124 | { \ |
| 125 | .pool = _pool, \ |
| 126 | .dir = _dir, \ |
| 127 | .mode = _mode, \ |
| 128 | .size = _size, \ |
| 129 | } |
| 130 | |
| 131 | #define MLXSW_SP_SB_POOL_INGRESS(_pool, _size) \ |
| 132 | MLXSW_SP_SB_POOL(_pool, MLXSW_REG_SBPR_DIR_INGRESS, \ |
| 133 | MLXSW_REG_SBPR_MODE_DYNAMIC, _size) |
| 134 | |
| 135 | #define MLXSW_SP_SB_POOL_EGRESS(_pool, _size) \ |
| 136 | MLXSW_SP_SB_POOL(_pool, MLXSW_REG_SBPR_DIR_EGRESS, \ |
| 137 | MLXSW_REG_SBPR_MODE_DYNAMIC, _size) |
| 138 | |
| 139 | static const struct mlxsw_sp_sb_pool mlxsw_sp_sb_pools[] = { |
Ido Schimmel | 1a19844 | 2016-04-06 17:10:02 +0200 | [diff] [blame] | 140 | MLXSW_SP_SB_POOL_INGRESS(0, MLXSW_SP_BYTES_TO_CELLS(MLXSW_SP_SB_POOL_INGRESS_SIZE)), |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 141 | MLXSW_SP_SB_POOL_INGRESS(1, 0), |
| 142 | MLXSW_SP_SB_POOL_INGRESS(2, 0), |
| 143 | MLXSW_SP_SB_POOL_INGRESS(3, 0), |
Ido Schimmel | 1a19844 | 2016-04-06 17:10:02 +0200 | [diff] [blame] | 144 | MLXSW_SP_SB_POOL_EGRESS(0, MLXSW_SP_BYTES_TO_CELLS(MLXSW_SP_SB_POOL_EGRESS_SIZE)), |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 145 | MLXSW_SP_SB_POOL_EGRESS(1, 0), |
| 146 | MLXSW_SP_SB_POOL_EGRESS(2, 0), |
Ido Schimmel | 1a19844 | 2016-04-06 17:10:02 +0200 | [diff] [blame] | 147 | MLXSW_SP_SB_POOL_EGRESS(2, MLXSW_SP_BYTES_TO_CELLS(MLXSW_SP_SB_POOL_EGRESS_SIZE)), |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | #define MLXSW_SP_SB_POOLS_LEN ARRAY_SIZE(mlxsw_sp_sb_pools) |
| 151 | |
| 152 | static int mlxsw_sp_sb_pools_init(struct mlxsw_sp *mlxsw_sp) |
| 153 | { |
| 154 | char sbpr_pl[MLXSW_REG_SBPR_LEN]; |
| 155 | int i; |
| 156 | int err; |
| 157 | |
| 158 | for (i = 0; i < MLXSW_SP_SB_POOLS_LEN; i++) { |
| 159 | const struct mlxsw_sp_sb_pool *pool; |
| 160 | |
| 161 | pool = &mlxsw_sp_sb_pools[i]; |
| 162 | mlxsw_reg_sbpr_pack(sbpr_pl, pool->pool, pool->dir, |
| 163 | pool->mode, pool->size); |
| 164 | err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbpr), sbpr_pl); |
| 165 | if (err) |
| 166 | return err; |
| 167 | } |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | struct mlxsw_sp_sb_cm { |
| 172 | union { |
| 173 | u8 pg; |
| 174 | u8 tc; |
| 175 | } u; |
| 176 | enum mlxsw_reg_sbcm_dir dir; |
| 177 | u32 min_buff; |
| 178 | u32 max_buff; |
| 179 | u8 pool; |
| 180 | }; |
| 181 | |
| 182 | #define MLXSW_SP_SB_CM(_pg_tc, _dir, _min_buff, _max_buff, _pool) \ |
| 183 | { \ |
| 184 | .u.pg = _pg_tc, \ |
| 185 | .dir = _dir, \ |
| 186 | .min_buff = _min_buff, \ |
| 187 | .max_buff = _max_buff, \ |
| 188 | .pool = _pool, \ |
| 189 | } |
| 190 | |
| 191 | #define MLXSW_SP_SB_CM_INGRESS(_pg, _min_buff, _max_buff) \ |
| 192 | MLXSW_SP_SB_CM(_pg, MLXSW_REG_SBCM_DIR_INGRESS, \ |
| 193 | _min_buff, _max_buff, 0) |
| 194 | |
| 195 | #define MLXSW_SP_SB_CM_EGRESS(_tc, _min_buff, _max_buff) \ |
| 196 | MLXSW_SP_SB_CM(_tc, MLXSW_REG_SBCM_DIR_EGRESS, \ |
| 197 | _min_buff, _max_buff, 0) |
| 198 | |
| 199 | #define MLXSW_SP_CPU_PORT_SB_CM_EGRESS(_tc) \ |
| 200 | MLXSW_SP_SB_CM(_tc, MLXSW_REG_SBCM_DIR_EGRESS, 104, 2, 3) |
| 201 | |
| 202 | static const struct mlxsw_sp_sb_cm mlxsw_sp_sb_cms[] = { |
Ido Schimmel | 1a19844 | 2016-04-06 17:10:02 +0200 | [diff] [blame] | 203 | MLXSW_SP_SB_CM_INGRESS(0, MLXSW_SP_BYTES_TO_CELLS(10000), 8), |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 204 | MLXSW_SP_SB_CM_INGRESS(1, 0, 0), |
| 205 | MLXSW_SP_SB_CM_INGRESS(2, 0, 0), |
| 206 | MLXSW_SP_SB_CM_INGRESS(3, 0, 0), |
| 207 | MLXSW_SP_SB_CM_INGRESS(4, 0, 0), |
| 208 | MLXSW_SP_SB_CM_INGRESS(5, 0, 0), |
| 209 | MLXSW_SP_SB_CM_INGRESS(6, 0, 0), |
| 210 | MLXSW_SP_SB_CM_INGRESS(7, 0, 0), |
Ido Schimmel | 1a19844 | 2016-04-06 17:10:02 +0200 | [diff] [blame] | 211 | MLXSW_SP_SB_CM_INGRESS(9, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff), |
| 212 | MLXSW_SP_SB_CM_EGRESS(0, MLXSW_SP_BYTES_TO_CELLS(1500), 9), |
| 213 | MLXSW_SP_SB_CM_EGRESS(1, MLXSW_SP_BYTES_TO_CELLS(1500), 9), |
| 214 | MLXSW_SP_SB_CM_EGRESS(2, MLXSW_SP_BYTES_TO_CELLS(1500), 9), |
| 215 | MLXSW_SP_SB_CM_EGRESS(3, MLXSW_SP_BYTES_TO_CELLS(1500), 9), |
| 216 | MLXSW_SP_SB_CM_EGRESS(4, MLXSW_SP_BYTES_TO_CELLS(1500), 9), |
| 217 | MLXSW_SP_SB_CM_EGRESS(5, MLXSW_SP_BYTES_TO_CELLS(1500), 9), |
| 218 | MLXSW_SP_SB_CM_EGRESS(6, MLXSW_SP_BYTES_TO_CELLS(1500), 9), |
| 219 | MLXSW_SP_SB_CM_EGRESS(7, MLXSW_SP_BYTES_TO_CELLS(1500), 9), |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 220 | MLXSW_SP_SB_CM_EGRESS(8, 0, 0), |
| 221 | MLXSW_SP_SB_CM_EGRESS(9, 0, 0), |
| 222 | MLXSW_SP_SB_CM_EGRESS(10, 0, 0), |
| 223 | MLXSW_SP_SB_CM_EGRESS(11, 0, 0), |
| 224 | MLXSW_SP_SB_CM_EGRESS(12, 0, 0), |
| 225 | MLXSW_SP_SB_CM_EGRESS(13, 0, 0), |
| 226 | MLXSW_SP_SB_CM_EGRESS(14, 0, 0), |
| 227 | MLXSW_SP_SB_CM_EGRESS(15, 0, 0), |
| 228 | MLXSW_SP_SB_CM_EGRESS(16, 1, 0xff), |
| 229 | }; |
| 230 | |
| 231 | #define MLXSW_SP_SB_CMS_LEN ARRAY_SIZE(mlxsw_sp_sb_cms) |
| 232 | |
| 233 | static const struct mlxsw_sp_sb_cm mlxsw_sp_cpu_port_sb_cms[] = { |
| 234 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(0), |
| 235 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(1), |
| 236 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(2), |
| 237 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(3), |
| 238 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(4), |
| 239 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(5), |
| 240 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(6), |
| 241 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(7), |
| 242 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(8), |
| 243 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(9), |
| 244 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(10), |
| 245 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(11), |
| 246 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(12), |
| 247 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(13), |
| 248 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(14), |
| 249 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(15), |
| 250 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(16), |
| 251 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(17), |
| 252 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(18), |
| 253 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(19), |
| 254 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(20), |
| 255 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(21), |
| 256 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(22), |
| 257 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(23), |
| 258 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(24), |
| 259 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(25), |
| 260 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(26), |
| 261 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(27), |
| 262 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(28), |
| 263 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(29), |
| 264 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(30), |
| 265 | MLXSW_SP_CPU_PORT_SB_CM_EGRESS(31), |
| 266 | }; |
| 267 | |
| 268 | #define MLXSW_SP_CPU_PORT_SB_MCS_LEN \ |
| 269 | ARRAY_SIZE(mlxsw_sp_cpu_port_sb_cms) |
| 270 | |
| 271 | static int mlxsw_sp_sb_cms_init(struct mlxsw_sp *mlxsw_sp, u8 local_port, |
| 272 | const struct mlxsw_sp_sb_cm *cms, |
| 273 | size_t cms_len) |
| 274 | { |
| 275 | char sbcm_pl[MLXSW_REG_SBCM_LEN]; |
| 276 | int i; |
| 277 | int err; |
| 278 | |
| 279 | for (i = 0; i < cms_len; i++) { |
| 280 | const struct mlxsw_sp_sb_cm *cm; |
| 281 | |
| 282 | cm = &cms[i]; |
| 283 | mlxsw_reg_sbcm_pack(sbcm_pl, local_port, cm->u.pg, cm->dir, |
| 284 | cm->min_buff, cm->max_buff, cm->pool); |
| 285 | err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbcm), sbcm_pl); |
| 286 | if (err) |
| 287 | return err; |
| 288 | } |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | static int mlxsw_sp_port_sb_cms_init(struct mlxsw_sp_port *mlxsw_sp_port) |
| 293 | { |
| 294 | return mlxsw_sp_sb_cms_init(mlxsw_sp_port->mlxsw_sp, |
| 295 | mlxsw_sp_port->local_port, mlxsw_sp_sb_cms, |
| 296 | MLXSW_SP_SB_CMS_LEN); |
| 297 | } |
| 298 | |
| 299 | static int mlxsw_sp_cpu_port_sb_cms_init(struct mlxsw_sp *mlxsw_sp) |
| 300 | { |
| 301 | return mlxsw_sp_sb_cms_init(mlxsw_sp, 0, mlxsw_sp_cpu_port_sb_cms, |
| 302 | MLXSW_SP_CPU_PORT_SB_MCS_LEN); |
| 303 | } |
| 304 | |
| 305 | struct mlxsw_sp_sb_pm { |
| 306 | u8 pool; |
| 307 | enum mlxsw_reg_sbpm_dir dir; |
| 308 | u32 min_buff; |
| 309 | u32 max_buff; |
| 310 | }; |
| 311 | |
| 312 | #define MLXSW_SP_SB_PM(_pool, _dir, _min_buff, _max_buff) \ |
| 313 | { \ |
| 314 | .pool = _pool, \ |
| 315 | .dir = _dir, \ |
| 316 | .min_buff = _min_buff, \ |
| 317 | .max_buff = _max_buff, \ |
| 318 | } |
| 319 | |
| 320 | #define MLXSW_SP_SB_PM_INGRESS(_pool, _min_buff, _max_buff) \ |
| 321 | MLXSW_SP_SB_PM(_pool, MLXSW_REG_SBPM_DIR_INGRESS, \ |
| 322 | _min_buff, _max_buff) |
| 323 | |
| 324 | #define MLXSW_SP_SB_PM_EGRESS(_pool, _min_buff, _max_buff) \ |
| 325 | MLXSW_SP_SB_PM(_pool, MLXSW_REG_SBPM_DIR_EGRESS, \ |
| 326 | _min_buff, _max_buff) |
| 327 | |
| 328 | static const struct mlxsw_sp_sb_pm mlxsw_sp_sb_pms[] = { |
| 329 | MLXSW_SP_SB_PM_INGRESS(0, 0, 0xff), |
| 330 | MLXSW_SP_SB_PM_INGRESS(1, 0, 0), |
| 331 | MLXSW_SP_SB_PM_INGRESS(2, 0, 0), |
| 332 | MLXSW_SP_SB_PM_INGRESS(3, 0, 0), |
| 333 | MLXSW_SP_SB_PM_EGRESS(0, 0, 7), |
| 334 | MLXSW_SP_SB_PM_EGRESS(1, 0, 0), |
| 335 | MLXSW_SP_SB_PM_EGRESS(2, 0, 0), |
| 336 | MLXSW_SP_SB_PM_EGRESS(3, 0, 0), |
| 337 | }; |
| 338 | |
| 339 | #define MLXSW_SP_SB_PMS_LEN ARRAY_SIZE(mlxsw_sp_sb_pms) |
| 340 | |
| 341 | static int mlxsw_sp_port_sb_pms_init(struct mlxsw_sp_port *mlxsw_sp_port) |
| 342 | { |
| 343 | char sbpm_pl[MLXSW_REG_SBPM_LEN]; |
| 344 | int i; |
| 345 | int err; |
| 346 | |
| 347 | for (i = 0; i < MLXSW_SP_SB_PMS_LEN; i++) { |
| 348 | const struct mlxsw_sp_sb_pm *pm; |
| 349 | |
| 350 | pm = &mlxsw_sp_sb_pms[i]; |
| 351 | mlxsw_reg_sbpm_pack(sbpm_pl, mlxsw_sp_port->local_port, |
| 352 | pm->pool, pm->dir, |
| 353 | pm->min_buff, pm->max_buff); |
| 354 | err = mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core, |
| 355 | MLXSW_REG(sbpm), sbpm_pl); |
| 356 | if (err) |
| 357 | return err; |
| 358 | } |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | struct mlxsw_sp_sb_mm { |
| 363 | u8 prio; |
| 364 | u32 min_buff; |
| 365 | u32 max_buff; |
| 366 | u8 pool; |
| 367 | }; |
| 368 | |
| 369 | #define MLXSW_SP_SB_MM(_prio, _min_buff, _max_buff, _pool) \ |
| 370 | { \ |
| 371 | .prio = _prio, \ |
| 372 | .min_buff = _min_buff, \ |
| 373 | .max_buff = _max_buff, \ |
| 374 | .pool = _pool, \ |
| 375 | } |
| 376 | |
| 377 | static const struct mlxsw_sp_sb_mm mlxsw_sp_sb_mms[] = { |
Ido Schimmel | 1a19844 | 2016-04-06 17:10:02 +0200 | [diff] [blame] | 378 | MLXSW_SP_SB_MM(0, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 379 | MLXSW_SP_SB_MM(1, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 380 | MLXSW_SP_SB_MM(2, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 381 | MLXSW_SP_SB_MM(3, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 382 | MLXSW_SP_SB_MM(4, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 383 | MLXSW_SP_SB_MM(5, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 384 | MLXSW_SP_SB_MM(6, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 385 | MLXSW_SP_SB_MM(7, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 386 | MLXSW_SP_SB_MM(8, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 387 | MLXSW_SP_SB_MM(9, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 388 | MLXSW_SP_SB_MM(10, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 389 | MLXSW_SP_SB_MM(11, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 390 | MLXSW_SP_SB_MM(12, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 391 | MLXSW_SP_SB_MM(13, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
| 392 | MLXSW_SP_SB_MM(14, MLXSW_SP_BYTES_TO_CELLS(20000), 0xff, 0), |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 393 | }; |
| 394 | |
| 395 | #define MLXSW_SP_SB_MMS_LEN ARRAY_SIZE(mlxsw_sp_sb_mms) |
| 396 | |
| 397 | static int mlxsw_sp_sb_mms_init(struct mlxsw_sp *mlxsw_sp) |
| 398 | { |
| 399 | char sbmm_pl[MLXSW_REG_SBMM_LEN]; |
| 400 | int i; |
| 401 | int err; |
| 402 | |
| 403 | for (i = 0; i < MLXSW_SP_SB_MMS_LEN; i++) { |
| 404 | const struct mlxsw_sp_sb_mm *mc; |
| 405 | |
| 406 | mc = &mlxsw_sp_sb_mms[i]; |
| 407 | mlxsw_reg_sbmm_pack(sbmm_pl, mc->prio, mc->min_buff, |
| 408 | mc->max_buff, mc->pool); |
| 409 | err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbmm), sbmm_pl); |
| 410 | if (err) |
| 411 | return err; |
| 412 | } |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp) |
| 417 | { |
| 418 | int err; |
| 419 | |
| 420 | err = mlxsw_sp_sb_pools_init(mlxsw_sp); |
| 421 | if (err) |
| 422 | return err; |
| 423 | err = mlxsw_sp_cpu_port_sb_cms_init(mlxsw_sp); |
| 424 | if (err) |
| 425 | return err; |
| 426 | err = mlxsw_sp_sb_mms_init(mlxsw_sp); |
| 427 | |
| 428 | return err; |
| 429 | } |
| 430 | |
| 431 | int mlxsw_sp_port_buffers_init(struct mlxsw_sp_port *mlxsw_sp_port) |
| 432 | { |
| 433 | int err; |
| 434 | |
Ido Schimmel | dd6cb0f | 2016-04-06 17:10:01 +0200 | [diff] [blame] | 435 | err = mlxsw_sp_port_headroom_init(mlxsw_sp_port); |
Jiri Pirko | 56ade8f | 2015-10-16 14:01:37 +0200 | [diff] [blame] | 436 | if (err) |
| 437 | return err; |
| 438 | err = mlxsw_sp_port_sb_cms_init(mlxsw_sp_port); |
| 439 | if (err) |
| 440 | return err; |
| 441 | err = mlxsw_sp_port_sb_pms_init(mlxsw_sp_port); |
| 442 | |
| 443 | return err; |
| 444 | } |