dport.c (14711B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 */ 7 8 #include <sal/core/libc.h> 9 10 #include <soc/drv.h> 11 #include <soc/cm.h> 12 #include <soc/debug.h> 13 #include <soc/error.h> 14 #include <soc/dport.h> 15 #ifdef BCM_HURRICANE3_SUPPORT 16 #include <soc/wolfhound2.h> 17 #endif 18 /* 19 * Static port maps are arrays of physical port numbers. 20 * The array index is the dport number. 21 */ 22 23 static soc_port_t bcm5665_dport_map[] = { 24 28, 25 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* 1-10 */ 26 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, /* 11-20 */ 27 20, 21, 22, 23, 32, 33, 34, 35, 36, 37, /* 21-30 */ 28 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, /* 31-40 */ 29 48, 49, 50, 51, 52, 53, 54, 55, 24, 25, /* 41-50 */ 30 26, 27, 56 31 }; 32 33 static soc_port_t bcm56524_dport_map[] = { 34 0, 35 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, /* 1-10 */ 36 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, /* 11-20 */ 37 50, 51, 52, 53, -1, -1, -1, -1, 1, -1, /* 21-30 */ 38 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 31-40 */ 39 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 41-50 */ 40 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 51-60 */ 41 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 61-70 */ 42 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 71-80 */ 43 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 81-90 */ 44 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 91-100 */ 45 /* HG/XE ports start at 101 */ 46 26, 27, 28, 29 47 }; 48 49 static soc_port_t bcm56526_dport_map[] = { 50 0, 51 2, 3, 4, 5, 6, 7, 8, 9, 38, 39, /* 1-10 */ 52 40, 41, 10, 11, 12, 13, 14, 15, 16, 17, /* 11-20 */ 53 18, 19, 20, 21, 22, 23, 24, 25, 1, -1, /* 21-30 */ 54 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 31-40 */ 55 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 41-50 */ 56 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 51-60 */ 57 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 61-70 */ 58 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 71-80 */ 59 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 81-90 */ 60 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 91-100 */ 61 /* HG/XE ports start at 101 */ 62 46, 50, 26, 27, 28, 29 63 }; 64 65 static soc_port_t bcm56624_dport_map[] = { 66 0, 67 2, 3, 4, 5, 6, 7, 18, 19, 8, 9, /* 1-10 */ 68 10, 11, 12, 13, 20, 21, 14, 15, 16, 17, /* 11-20 */ 69 22, 23, 24, 25, 37, 38, 39, 40, 26, 32, /* 21-30 */ 70 33, 34, 41, 42, 48, 49, 50, 51, 52, 53, /* 31-40 */ 71 35, 36, 46, 47, 27, 43, 44, 45, 1, -1, /* 41-50 */ 72 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 51-60 */ 73 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 61-70 */ 74 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 71-80 */ 75 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 81-90 */ 76 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 91-100 */ 77 /* HG/XE ports start at 101 */ 78 28, 29, 30, 31 79 }; 80 81 static soc_port_t bcm56626_dport_map[] = { 82 0, 83 2, 3, 4, 5, 6, 7, 18, 19, 8, 9, /* 1-10 */ 84 10, 11, 12, 13, 20, 21, 14, 15, 16, 17, /* 11-20 */ 85 22, 23, 24, 25, 1, -1, -1, -1, -1, -1, /* 21-30 */ 86 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 31-40 */ 87 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 41-50 */ 88 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 51-60 */ 89 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 61-70 */ 90 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 71-80 */ 91 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 81-90 */ 92 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 91-100 */ 93 /* HG/XE ports start at 101 */ 94 26, 27, 28, 29, 30, 31 95 }; 96 97 static soc_port_t bcm56628_dport_map[] = { 98 0, 99 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 1-10 */ 100 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 11-20 */ 101 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 21-30 */ 102 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 31-40 */ 103 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 41-50 */ 104 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 51-60 */ 105 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 61-70 */ 106 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 71-80 */ 107 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 81-90 */ 108 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 91-100 */ 109 /* HG/XE ports start at 101 */ 110 2, 14, 26, 27, 28, 29, 30, 31 111 }; 112 113 static soc_port_t bcm56629_dport_map[] = { 114 0, 115 8, 9, 10, 11, 12, 13, 20, 21, 22, 23, /* 1-10 */ 116 24, 25, 37, 38, 39, 40, 41, 42, 48, 49, /* 11-20 */ 117 50, 51, 52, 53, 1, -1, -1, -1, -1, -1, /* 21-30 */ 118 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 31-40 */ 119 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 41-50 */ 120 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 51-60 */ 121 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 61-70 */ 122 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 71-80 */ 123 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 81-90 */ 124 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 91-100 */ 125 /* HG/XE ports start at 101 */ 126 2, 14, 26, 27, 28, 29, 30, 31 127 }; 128 129 static soc_port_t bcm56629_40ge_dport_map[] = { 130 0, 131 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, /* 1-10 */ 132 14, 15, 16, 17, 20, 21, 22, 23, 24, 25, /* 11-20 */ 133 26, 32, 33, 34, 37, 38, 39, 40, 41, 42, /* 21-30 */ 134 27, 43, 44, 45, 48, 49, 50, 51, 52, 53, /* 31-40 */ 135 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 41-50 */ 136 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 51-60 */ 137 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 61-70 */ 138 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 71-80 */ 139 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 81-90 */ 140 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 91-100 */ 141 /* HG/XE ports start at 101 */ 142 28, 29, 30, 31 143 }; 144 145 static soc_port_t bcm56680_dport_map[] = { 146 0, 147 2, 3, 4, 5, 6, 7, 18, 19, 14, 15, /* 1-10 */ 148 16, 17, 26, 32, 33, 34, 35, 36, 46, 47, /* 11-20 */ 149 27, 43, 44, 45, 1, -1, -1, -1, -1, -1, /* 21-30 */ 150 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 31-40 */ 151 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 41-50 */ 152 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 51-60 */ 153 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 61-70 */ 154 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 71-80 */ 155 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 81-90 */ 156 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 91-100 */ 157 /* HG/XE ports start at 101 */ 158 28, 29, 30, 31 159 }; 160 161 static soc_port_t bcm56620_dport_map[] = { 162 0, 163 2, 3, 4, 5, 6, 7, 18, 19, 14, 15, /* 1-10 */ 164 16, 17, 26, 32, 33, 34, 35, 36, 46, 47, /* 11-20 */ 165 27, 43, 44, 45, -1, -1, -1, -1, -1, -1, /* 21-30 */ 166 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 31-40 */ 167 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 41-50 */ 168 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 51-60 */ 169 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 61-70 */ 170 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 71-80 */ 171 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 81-90 */ 172 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 91-100 */ 173 /* HG/XE ports start at 101 */ 174 28, 29, 30, 31 175 }; 176 177 static soc_port_t bcm56634_dport_map[] = { 178 0, 179 30, 31, 32, 33, 34, 35, 36, 37, 2, 3, /* 1-10 */ 180 4, 5, 6, 7, 8, 9, 38, 39, 40, 41, /* 11-20 */ 181 10, 11, 12, 13, 14, 15, 16, 17, 42, 43, /* 21-30 */ 182 44, 45, 18, 19, 20, 21, 22, 23, 24, 25, /* 31-40 */ 183 46, 47, 48, 49, 50, 51, 52, 53, 1, -1, /* 41-50 */ 184 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 51-60 */ 185 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 61-70 */ 186 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 71-80 */ 187 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 81-90 */ 188 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 91-100 */ 189 /* HG/XE ports start at 101 */ 190 26, 27, 28, 29 191 }; 192 193 static soc_port_t bcm56636_dport_map[] = { 194 0, 195 30, 31, 32, 33, 34, 35, 36, 37, 2, 3, /* 1-10 */ 196 4, 5, 6, 7, 8, 9, 38, 39, 40, 41, /* 11-20 */ 197 10, 11, 12, 13, 1, 43, 44, 45, 51, 52, /* 21-30 */ 198 53, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 31-40 */ 199 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 41-50 */ 200 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 51-60 */ 201 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 61-70 */ 202 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 71-80 */ 203 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 81-90 */ 204 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 91-100 */ 205 /* HG/XE ports start at 101 */ 206 42, 50, 26, 27, 28, 29 207 }; 208 209 static soc_port_t bcm5339x_dport_map[] = { 210 0, 211 -1, 2, -1, -1, -1, 6, -1, -1, -1, 10, /* 1-10 */ 212 -1, -1, -1, 14, -1, -1, -1, 18, -1, -1, /* 11-20 */ 213 22, 21, 23, 24, 25, 26, 27, 28, 29, -1, /* 21-30 */ 214 -1, -1, -1 215 }; 216 217 static soc_port_t bcm56160_dport_map[] = { 218 0, 219 2, 3, 4, 5, 13, 12, 11, 10, 9, 8, /* 1-10 */ 220 7, 6, 18, 19, 20, 21, 22, 23, 24, 25, /* 11-20 */ 221 14, 15, 16, 17, 26, 27, 28, 29, 30, 31 /* 21-30 */ 222 }; 223 224 static soc_port_t bcm56160_non_gphy_dport_map[] = { 225 0, 226 2, 3, 4, 5, 6, 7, 8, 9, 18, 19, /* 1-10 */ 227 20, 21, 22, 23, 24, 25, 10, 11, 12, 13, /* 11-20 */ 228 14, 15, 16, 17, 26, 27, 28, 29, 30, 31 /* 21-30 */ 229 }; 230 231 static soc_port_t bcm56162_dport_map[] = { 232 0, 233 9, 8, 7, 6, 5, 4, 3, 2, 18, 19, /* 1-10 */ 234 20, 21, 22, 23, 24, 25, 10, 11, 12, 13, /* 11-20 */ 235 14, 15, 16, 17, 26, 27, 28, 29, 30, 31 /* 21-30 */ 236 }; 237 238 239 STATIC int 240 _soc_esw_dport_map_array(int unit, soc_port_t *ports, int size) 241 { 242 int idx; 243 244 for (idx = 0; idx < size; idx++) { 245 if (ports[idx] >= 0) { 246 soc_dport_map_port(unit, idx, ports[idx]); 247 } 248 } 249 return 0; 250 } 251 252 #define MAP_ARRAY(_u,_m) _soc_esw_dport_map_array(_u,_m,COUNTOF(_m)) 253 254 int 255 soc_esw_dport_init(int unit) 256 { 257 uint16 dev_id; 258 uint8 rev_id; 259 int idx, port, dport, port_offset; 260 int hu2_config_id = 0; 261 262 hu2_config_id = soc_property_get(unit, spn_BCM5615X_CONFIG, 0); 263 264 /* Cache the configuration settings */ 265 SOC_DPORT_MAP_FLAGS(unit) = 0; 266 if (soc_property_get(unit, spn_DPORT_MAP_ENABLE, TRUE)) { 267 SOC_DPORT_MAP_FLAGS(unit) |= SOC_DPORT_MAP_F_ENABLE; 268 } 269 if (soc_property_get(unit, spn_DPORT_MAP_INDEXED, TRUE)) { 270 SOC_DPORT_MAP_FLAGS(unit) |= SOC_DPORT_MAP_F_INDEXED; 271 } 272 273 for (idx = 0; idx < COUNTOF(SOC_DPORT_MAP(unit)); idx++) { 274 SOC_DPORT_MAP(unit)[idx] = -1; 275 } 276 277 soc_cm_get_id(unit, &dev_id, &rev_id); 278 279 switch (dev_id) { 280 case BCM5665_DEVICE_ID: 281 MAP_ARRAY(unit, bcm5665_dport_map); 282 break; 283 case BCM56524_DEVICE_ID: 284 MAP_ARRAY(unit, bcm56524_dport_map); 285 break; 286 case BCM56526_DEVICE_ID: 287 MAP_ARRAY(unit, bcm56526_dport_map); 288 break; 289 case BCM56620_DEVICE_ID: 290 MAP_ARRAY(unit, bcm56620_dport_map); 291 break; 292 case BCM56624_DEVICE_ID: 293 MAP_ARRAY(unit, bcm56624_dport_map); 294 break; 295 case BCM56629_DEVICE_ID: 296 if (soc_feature(unit, soc_feature_xgport_one_xe_six_ge)) { 297 if (soc_property_get(unit, spn_BCM56629_40GE, 0)) { 298 MAP_ARRAY(unit, bcm56629_40ge_dport_map); 299 } else { 300 MAP_ARRAY(unit, bcm56629_dport_map); 301 } 302 break; 303 } 304 /* Fall through - BCM56629_A0 uses BCM56626 port layout */ 305 case BCM56626_DEVICE_ID: 306 MAP_ARRAY(unit, bcm56626_dport_map); 307 break; 308 case BCM56628_DEVICE_ID: 309 MAP_ARRAY(unit, bcm56628_dport_map); 310 break; 311 case BCM56680_DEVICE_ID: 312 case BCM56684_DEVICE_ID: 313 MAP_ARRAY(unit, bcm56680_dport_map); 314 break; 315 case BCM56634_DEVICE_ID: 316 case BCM56538_DEVICE_ID: 317 MAP_ARRAY(unit, bcm56634_dport_map); 318 if (soc_feature(unit, soc_feature_internal_loopback)) { 319 SOC_PBMP_ITER(PBMP_LB(unit), port) { 320 SOC_DPORT_MAP(unit)[port] = port; 321 } 322 SOC_PBMP_ITER(PBMP_MMU(unit), port) { 323 SOC_DPORT_MAP(unit)[port] = port; 324 } 325 } 326 break; 327 case BCM56636_DEVICE_ID: 328 MAP_ARRAY(unit, bcm56636_dport_map); 329 if (soc_feature(unit, soc_feature_internal_loopback)) { 330 SOC_PBMP_ITER(PBMP_LB(unit), port) { 331 SOC_DPORT_MAP(unit)[port] = port; 332 } 333 SOC_PBMP_ITER(PBMP_MMU(unit), port) { 334 SOC_DPORT_MAP(unit)[port] = port; 335 } 336 } 337 break; 338 339 case BCM56160_DEVICE_ID: 340 case BCM53440_DEVICE_ID: 341 if (soc_feature(unit, soc_feature_gphy)) { 342 MAP_ARRAY(unit, bcm56160_dport_map); 343 } else { 344 MAP_ARRAY(unit, bcm56160_non_gphy_dport_map); 345 } 346 break; 347 case BCM56162_DEVICE_ID: 348 case BCM56163_DEVICE_ID: 349 case BCM56164_DEVICE_ID: 350 case BCM56166_DEVICE_ID: 351 case BCM53443_DEVICE_ID: 352 case BCM53442_DEVICE_ID: 353 case BCM53434_DEVICE_ID: 354 if (soc_feature(unit, soc_feature_gphy)) { 355 MAP_ARRAY(unit, bcm56162_dport_map); 356 } else { 357 MAP_ARRAY(unit, bcm56160_non_gphy_dport_map); 358 } 359 break; 360 case BCM53393_DEVICE_ID: 361 MAP_ARRAY(unit, bcm5339x_dport_map); 362 break; 363 case BCM53394_DEVICE_ID: 364 if ((hu2_config_id == 0) || (hu2_config_id == 1)) { 365 MAP_ARRAY(unit, bcm5339x_dport_map); 366 break; 367 } 368 /* fall through */ 369 default: 370 port_offset = (CMIC_PORT(unit) == 0) ? 0 : 1; 371 PBMP_ALL_ITER(unit, port) { 372 /* coverity[overrun-local : FALSE] */ 373 SOC_DPORT_MAP(unit)[port + port_offset] = port; 374 } 375 SOC_PBMP_ITER(PBMP_MMU(unit), port) { 376 /* coverity[overrun-local : FALSE] */ 377 SOC_DPORT_MAP(unit)[port + port_offset] = port; 378 } 379 break; 380 } 381 382 #ifdef BCM_HURRICANE3_SUPPORT 383 if (soc_feature(unit, soc_feature_wh2)) { 384 (void)soc_wolfhound2_dport_init(unit); 385 } 386 #endif /* BCM_HURRICANE3_SUPPORT */ 387 PBMP_ALL_ITER(unit, port) { 388 dport = soc_property_port_get(unit, port, spn_DPORT_MAP_PORT, -1); 389 if (dport >= 0) { 390 soc_dport_map_port(unit, dport, port); 391 } 392 } 393 SOC_PBMP_ITER(PBMP_MMU(unit), port) { 394 dport = soc_property_port_get(unit, port, spn_DPORT_MAP_PORT, -1); 395 if (dport >= 0) { 396 soc_dport_map_port(unit, dport, port); 397 } 398 } 399 400 return soc_dport_map_update(unit); 401 } 402