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