Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
Stefan Roese | 790978b | 2022-04-07 09:11:44 +0200 | [diff] [blame] | 3 | * Copyright (C) 2020-2022 Marvell International Ltd. |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 4 | * |
| 5 | * Helper Functions for the Configuration Framework |
| 6 | */ |
| 7 | |
| 8 | #include <log.h> |
| 9 | #include <linux/delay.h> |
| 10 | |
| 11 | #include <mach/cvmx-regs.h> |
| 12 | #include <mach/cvmx-csr.h> |
| 13 | #include <mach/cvmx-bootmem.h> |
| 14 | #include <mach/octeon-model.h> |
| 15 | #include <mach/cvmx-fuse.h> |
| 16 | #include <mach/octeon-feature.h> |
| 17 | #include <mach/cvmx-qlm.h> |
| 18 | #include <mach/octeon_qlm.h> |
| 19 | #include <mach/cvmx-pcie.h> |
| 20 | #include <mach/cvmx-coremask.h> |
| 21 | |
| 22 | #include <mach/cvmx-agl-defs.h> |
| 23 | #include <mach/cvmx-bgxx-defs.h> |
| 24 | #include <mach/cvmx-gmxx-defs.h> |
| 25 | #include <mach/cvmx-ipd-defs.h> |
| 26 | #include <mach/cvmx-pki-defs.h> |
| 27 | |
| 28 | #include <mach/cvmx-helper.h> |
| 29 | #include <mach/cvmx-helper-board.h> |
| 30 | #include <mach/cvmx-helper-fdt.h> |
| 31 | #include <mach/cvmx-helper-bgx.h> |
| 32 | #include <mach/cvmx-helper-cfg.h> |
| 33 | #include <mach/cvmx-helper-util.h> |
| 34 | #include <mach/cvmx-helper-pki.h> |
| 35 | |
| 36 | #include <mach/cvmx-global-resources.h> |
| 37 | #include <mach/cvmx-pko-internal-ports-range.h> |
| 38 | #include <mach/cvmx-ilk.h> |
| 39 | #include <mach/cvmx-pip.h> |
| 40 | |
| 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
| 43 | int cvmx_npi_max_pknds; |
| 44 | static bool port_cfg_data_initialized; |
| 45 | |
| 46 | struct cvmx_cfg_port_param cvmx_cfg_port[CVMX_MAX_NODES][CVMX_HELPER_MAX_IFACE] |
| 47 | [CVMX_HELPER_CFG_MAX_PORT_PER_IFACE]; |
| 48 | /* |
| 49 | * Indexed by the pko_port number |
| 50 | */ |
| 51 | static int __cvmx_cfg_pko_highest_queue; |
| 52 | struct cvmx_cfg_pko_port_param |
| 53 | cvmx_pko_queue_table[CVMX_HELPER_CFG_MAX_PKO_PORT] = { |
| 54 | [0 ... CVMX_HELPER_CFG_MAX_PKO_PORT - 1] = { |
| 55 | CVMX_HELPER_CFG_INVALID_VALUE, |
| 56 | CVMX_HELPER_CFG_INVALID_VALUE |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | cvmx_user_static_pko_queue_config_t |
| 61 | __cvmx_pko_queue_static_config[CVMX_MAX_NODES]; |
| 62 | |
| 63 | struct cvmx_cfg_pko_port_map |
| 64 | cvmx_cfg_pko_port_map[CVMX_HELPER_CFG_MAX_PKO_PORT] = { |
| 65 | [0 ... CVMX_HELPER_CFG_MAX_PKO_PORT - 1] = { |
| 66 | CVMX_HELPER_CFG_INVALID_VALUE, |
| 67 | CVMX_HELPER_CFG_INVALID_VALUE, |
| 68 | CVMX_HELPER_CFG_INVALID_VALUE |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | /* |
| 73 | * This array assists translation from ipd_port to pko_port. |
| 74 | * The ``16'' is the rounded value for the 3rd 4-bit value of |
| 75 | * ipd_port, used to differentiate ``interfaces.'' |
| 76 | */ |
| 77 | static struct cvmx_cfg_pko_port_pair |
| 78 | ipd2pko_port_cache[16][CVMX_HELPER_CFG_MAX_PORT_PER_IFACE] = { |
| 79 | [0 ... 15] = { |
| 80 | [0 ... CVMX_HELPER_CFG_MAX_PORT_PER_IFACE - 1] = { |
| 81 | CVMX_HELPER_CFG_INVALID_VALUE, |
| 82 | CVMX_HELPER_CFG_INVALID_VALUE |
| 83 | } |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | /* |
| 88 | * Options |
| 89 | * |
| 90 | * Each array-elem's initial value is also the option's default value. |
| 91 | */ |
| 92 | static u64 cvmx_cfg_opts[CVMX_HELPER_CFG_OPT_MAX] = { |
| 93 | [0 ... CVMX_HELPER_CFG_OPT_MAX - 1] = 1 |
| 94 | }; |
| 95 | |
| 96 | /* |
| 97 | * MISC |
| 98 | */ |
| 99 | |
| 100 | static int cvmx_cfg_max_pko_engines; /* # of PKO DMA engines allocated */ |
| 101 | static int cvmx_pko_queue_alloc(u64 port, int count); |
| 102 | static void cvmx_init_port_cfg(void); |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 103 | |
| 104 | int __cvmx_helper_cfg_pknd(int xiface, int index) |
| 105 | { |
| 106 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 107 | int pkind; |
| 108 | |
| 109 | if (!port_cfg_data_initialized) |
| 110 | cvmx_init_port_cfg(); |
| 111 | |
| 112 | /* |
| 113 | * Only 8 PKNDs are assigned to ILK channels. The channels are wrapped |
| 114 | * if more than 8 channels are configured, fix the index accordingly. |
| 115 | */ |
| 116 | if (OCTEON_IS_MODEL(OCTEON_CN78XX)) { |
| 117 | if (cvmx_helper_interface_get_mode(xiface) == |
| 118 | CVMX_HELPER_INTERFACE_MODE_ILK) |
| 119 | index %= 8; |
| 120 | } |
| 121 | |
| 122 | pkind = cvmx_cfg_port[xi.node][xi.interface][index].ccpp_pknd; |
| 123 | return pkind; |
| 124 | } |
| 125 | |
| 126 | int __cvmx_helper_cfg_bpid(int xiface, int index) |
| 127 | { |
| 128 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 129 | |
| 130 | if (!port_cfg_data_initialized) |
| 131 | cvmx_init_port_cfg(); |
| 132 | |
| 133 | /* |
| 134 | * Only 8 BIDs are assigned to ILK channels. The channels are wrapped |
| 135 | * if more than 8 channels are configured, fix the index accordingly. |
| 136 | */ |
| 137 | if (OCTEON_IS_MODEL(OCTEON_CN78XX)) { |
| 138 | if (cvmx_helper_interface_get_mode(xiface) == |
| 139 | CVMX_HELPER_INTERFACE_MODE_ILK) |
| 140 | index %= 8; |
| 141 | } |
| 142 | |
| 143 | return cvmx_cfg_port[xi.node][xi.interface][index].ccpp_bpid; |
| 144 | } |
| 145 | |
| 146 | int __cvmx_helper_cfg_pko_port_base(int xiface, int index) |
| 147 | { |
| 148 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 149 | |
| 150 | if (!port_cfg_data_initialized) |
| 151 | cvmx_init_port_cfg(); |
| 152 | |
| 153 | return cvmx_cfg_port[xi.node][xi.interface][index].ccpp_pko_port_base; |
| 154 | } |
| 155 | |
| 156 | int __cvmx_helper_cfg_pko_port_num(int xiface, int index) |
| 157 | { |
| 158 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 159 | |
| 160 | if (!port_cfg_data_initialized) |
| 161 | cvmx_init_port_cfg(); |
| 162 | |
| 163 | return cvmx_cfg_port[xi.node][xi.interface][index].ccpp_pko_num_ports; |
| 164 | } |
| 165 | |
| 166 | int __cvmx_helper_cfg_pko_queue_num(int pko_port) |
| 167 | { |
| 168 | return cvmx_pko_queue_table[pko_port].ccppp_num_queues; |
| 169 | } |
| 170 | |
| 171 | int __cvmx_helper_cfg_pko_queue_base(int pko_port) |
| 172 | { |
| 173 | return cvmx_pko_queue_table[pko_port].ccppp_queue_base; |
| 174 | } |
| 175 | |
| 176 | int __cvmx_helper_cfg_pko_max_queue(void) |
| 177 | { |
| 178 | return __cvmx_cfg_pko_highest_queue; |
| 179 | } |
| 180 | |
| 181 | int __cvmx_helper_cfg_pko_max_engine(void) |
| 182 | { |
| 183 | return cvmx_cfg_max_pko_engines; |
| 184 | } |
| 185 | |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 186 | uint64_t cvmx_helper_cfg_opt_get(cvmx_helper_cfg_option_t opt) |
| 187 | { |
| 188 | if (opt >= CVMX_HELPER_CFG_OPT_MAX) |
| 189 | return (uint64_t)CVMX_HELPER_CFG_INVALID_VALUE; |
| 190 | |
| 191 | return cvmx_cfg_opts[opt]; |
| 192 | } |
| 193 | |
| 194 | /* |
| 195 | * initialize the queue allocation list. the existing static allocation result |
| 196 | * is used as a starting point to ensure backward compatibility. |
| 197 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 198 | * Return: 0 on success |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 199 | * -1 on failure |
| 200 | */ |
| 201 | int cvmx_pko_queue_grp_alloc(u64 start, uint64_t end, uint64_t count) |
| 202 | { |
| 203 | u64 port; |
| 204 | int ret_val; |
| 205 | |
| 206 | for (port = start; port < end; port++) { |
| 207 | ret_val = cvmx_pko_queue_alloc(port, count); |
| 208 | if (ret_val == -1) { |
| 209 | printf("ERROR: %sL Failed to allocate queue for port=%d count=%d\n", |
| 210 | __func__, (int)port, (int)count); |
| 211 | return ret_val; |
| 212 | } |
| 213 | } |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | int cvmx_pko_queue_init_from_cvmx_config_non_pknd(void) |
| 218 | { |
| 219 | int ret_val = -1; |
| 220 | u64 count, start, end; |
| 221 | |
| 222 | start = 0; |
| 223 | end = __cvmx_pko_queue_static_config[0].non_pknd.pko_ports_per_interface[0]; |
| 224 | count = __cvmx_pko_queue_static_config[0].non_pknd.pko_queues_per_port_interface[0]; |
| 225 | cvmx_pko_queue_grp_alloc(start, end, count); |
| 226 | |
| 227 | start = 16; |
| 228 | end = start + __cvmx_pko_queue_static_config[0].non_pknd.pko_ports_per_interface[1]; |
| 229 | count = __cvmx_pko_queue_static_config[0].non_pknd.pko_queues_per_port_interface[1]; |
| 230 | ret_val = cvmx_pko_queue_grp_alloc(start, end, count); |
| 231 | if (ret_val != 0) |
| 232 | return -1; |
| 233 | |
| 234 | if (OCTEON_IS_MODEL(OCTEON_CN70XX)) { |
| 235 | /* Interface 4: AGL, PKO port 24 only, DPI 32-35 */ |
| 236 | start = 24; |
| 237 | end = start + 1; |
| 238 | count = __cvmx_pko_queue_static_config[0].non_pknd.pko_queues_per_port_interface[4]; |
| 239 | ret_val = cvmx_pko_queue_grp_alloc(start, end, count); |
| 240 | |
| 241 | if (ret_val != 0) |
| 242 | return -1; |
| 243 | end = 32; /* DPI first PKO poty */ |
| 244 | } |
| 245 | |
| 246 | start = end; |
| 247 | end = 36; |
| 248 | count = __cvmx_pko_queue_static_config[0].non_pknd.pko_queues_per_port_pci; |
| 249 | cvmx_pko_queue_grp_alloc(start, end, count); |
| 250 | if (ret_val != 0) |
| 251 | return -1; |
| 252 | |
| 253 | start = end; |
| 254 | end = 40; |
| 255 | count = __cvmx_pko_queue_static_config[0].non_pknd.pko_queues_per_port_loop; |
| 256 | cvmx_pko_queue_grp_alloc(start, end, count); |
| 257 | if (ret_val != 0) |
| 258 | return -1; |
| 259 | |
| 260 | start = end; |
| 261 | end = 42; |
| 262 | count = __cvmx_pko_queue_static_config[0].non_pknd.pko_queues_per_port_srio[0]; |
| 263 | cvmx_pko_queue_grp_alloc(start, end, count); |
| 264 | if (ret_val != 0) |
| 265 | return -1; |
| 266 | |
| 267 | start = end; |
| 268 | end = 44; |
| 269 | count = __cvmx_pko_queue_static_config[0].non_pknd.pko_queues_per_port_srio[1]; |
| 270 | cvmx_pko_queue_grp_alloc(start, end, count); |
| 271 | if (ret_val != 0) |
| 272 | return -1; |
| 273 | |
| 274 | start = end; |
| 275 | end = 46; |
| 276 | count = __cvmx_pko_queue_static_config[0].non_pknd.pko_queues_per_port_srio[2]; |
| 277 | cvmx_pko_queue_grp_alloc(start, end, count); |
| 278 | if (ret_val != 0) |
| 279 | return -1; |
| 280 | |
| 281 | start = end; |
| 282 | end = 48; |
| 283 | count = __cvmx_pko_queue_static_config[0].non_pknd.pko_queues_per_port_srio[3]; |
| 284 | cvmx_pko_queue_grp_alloc(start, end, count); |
| 285 | if (ret_val != 0) |
| 286 | return -1; |
| 287 | return 0; |
| 288 | } |
| 289 | |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 290 | static int queue_range_init; |
| 291 | |
| 292 | int init_cvmx_pko_que_range(void) |
| 293 | { |
| 294 | int rv = 0; |
| 295 | |
| 296 | if (queue_range_init) |
| 297 | return 0; |
| 298 | queue_range_init = 1; |
| 299 | rv = cvmx_create_global_resource_range(CVMX_GR_TAG_PKO_QUEUES, |
| 300 | CVMX_HELPER_CFG_MAX_PKO_QUEUES); |
| 301 | if (rv != 0) |
| 302 | printf("ERROR: %s: Failed to initialize pko queues range\n", __func__); |
| 303 | |
| 304 | return rv; |
| 305 | } |
| 306 | |
| 307 | /* |
| 308 | * get a block of "count" queues for "port" |
| 309 | * |
| 310 | * @param port the port for which the queues are requested |
| 311 | * @param count the number of queues requested |
| 312 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 313 | * Return: 0 on success |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 314 | * -1 on failure |
| 315 | */ |
| 316 | static int cvmx_pko_queue_alloc(u64 port, int count) |
| 317 | { |
| 318 | int ret_val = -1; |
| 319 | int highest_queue; |
| 320 | |
| 321 | init_cvmx_pko_que_range(); |
| 322 | |
| 323 | if (cvmx_pko_queue_table[port].ccppp_num_queues == count) |
| 324 | return cvmx_pko_queue_table[port].ccppp_queue_base; |
| 325 | |
| 326 | if (cvmx_pko_queue_table[port].ccppp_num_queues > 0) { |
| 327 | printf("WARNING: %s port=%d already %d queues\n", |
| 328 | __func__, (int)port, |
| 329 | (int)cvmx_pko_queue_table[port].ccppp_num_queues); |
| 330 | return -1; |
| 331 | } |
| 332 | |
| 333 | if (port >= CVMX_HELPER_CFG_MAX_PKO_QUEUES) { |
| 334 | printf("ERROR: %s port=%d > %d\n", __func__, (int)port, |
| 335 | CVMX_HELPER_CFG_MAX_PKO_QUEUES); |
| 336 | return -1; |
| 337 | } |
| 338 | |
| 339 | ret_val = cvmx_allocate_global_resource_range(CVMX_GR_TAG_PKO_QUEUES, |
| 340 | port, count, 1); |
| 341 | |
| 342 | debug("%s: pko_e_port=%i q_base=%i q_count=%i\n", |
| 343 | __func__, (int)port, ret_val, (int)count); |
| 344 | |
| 345 | if (ret_val == -1) |
| 346 | return ret_val; |
| 347 | cvmx_pko_queue_table[port].ccppp_queue_base = ret_val; |
| 348 | cvmx_pko_queue_table[port].ccppp_num_queues = count; |
| 349 | |
| 350 | highest_queue = ret_val + count - 1; |
| 351 | if (highest_queue > __cvmx_cfg_pko_highest_queue) |
| 352 | __cvmx_cfg_pko_highest_queue = highest_queue; |
| 353 | return 0; |
| 354 | } |
| 355 | |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 356 | /* |
| 357 | * initialize cvmx_cfg_pko_port_map |
| 358 | */ |
| 359 | void cvmx_helper_cfg_init_pko_port_map(void) |
| 360 | { |
| 361 | int i, j, k; |
| 362 | int pko_eid; |
| 363 | int pko_port_base, pko_port_max; |
| 364 | cvmx_helper_interface_mode_t mode; |
| 365 | |
| 366 | if (!port_cfg_data_initialized) |
| 367 | cvmx_init_port_cfg(); |
| 368 | /* |
| 369 | * one pko_eid is allocated to each port except for ILK, NPI, and |
| 370 | * LOOP. Each of the three has one eid. |
| 371 | */ |
| 372 | pko_eid = 0; |
| 373 | for (i = 0; i < cvmx_helper_get_number_of_interfaces(); i++) { |
| 374 | mode = cvmx_helper_interface_get_mode(i); |
| 375 | for (j = 0; j < cvmx_helper_interface_enumerate(i); j++) { |
| 376 | pko_port_base = cvmx_cfg_port[0][i][j].ccpp_pko_port_base; |
| 377 | pko_port_max = pko_port_base + cvmx_cfg_port[0][i][j].ccpp_pko_num_ports; |
| 378 | if (!octeon_has_feature(OCTEON_FEATURE_PKO3)) { |
| 379 | cvmx_helper_cfg_assert(pko_port_base != |
| 380 | CVMX_HELPER_CFG_INVALID_VALUE); |
| 381 | cvmx_helper_cfg_assert(pko_port_max >= pko_port_base); |
| 382 | } |
| 383 | for (k = pko_port_base; k < pko_port_max; k++) { |
| 384 | cvmx_cfg_pko_port_map[k].ccppl_interface = i; |
| 385 | cvmx_cfg_pko_port_map[k].ccppl_index = j; |
| 386 | cvmx_cfg_pko_port_map[k].ccppl_eid = pko_eid; |
| 387 | } |
| 388 | |
| 389 | if (!(mode == CVMX_HELPER_INTERFACE_MODE_NPI || |
| 390 | mode == CVMX_HELPER_INTERFACE_MODE_LOOP || |
| 391 | mode == CVMX_HELPER_INTERFACE_MODE_ILK)) |
| 392 | pko_eid++; |
| 393 | } |
| 394 | |
| 395 | if (mode == CVMX_HELPER_INTERFACE_MODE_NPI || |
| 396 | mode == CVMX_HELPER_INTERFACE_MODE_LOOP || |
| 397 | mode == CVMX_HELPER_INTERFACE_MODE_ILK) |
| 398 | pko_eid++; |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * Legal pko_eids [0, 0x13] should not be exhausted. |
| 403 | */ |
| 404 | if (!octeon_has_feature(OCTEON_FEATURE_PKO3)) |
| 405 | cvmx_helper_cfg_assert(pko_eid <= 0x14); |
| 406 | |
| 407 | cvmx_cfg_max_pko_engines = pko_eid; |
| 408 | } |
| 409 | |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 410 | int __cvmx_helper_cfg_pko_port_interface(int pko_port) |
| 411 | { |
| 412 | return cvmx_cfg_pko_port_map[pko_port].ccppl_interface; |
| 413 | } |
| 414 | |
| 415 | int __cvmx_helper_cfg_pko_port_index(int pko_port) |
| 416 | { |
| 417 | return cvmx_cfg_pko_port_map[pko_port].ccppl_index; |
| 418 | } |
| 419 | |
| 420 | int __cvmx_helper_cfg_pko_port_eid(int pko_port) |
| 421 | { |
| 422 | return cvmx_cfg_pko_port_map[pko_port].ccppl_eid; |
| 423 | } |
| 424 | |
| 425 | #define IPD2PKO_CACHE_Y(ipd_port) (ipd_port) >> 8 |
| 426 | #define IPD2PKO_CACHE_X(ipd_port) (ipd_port) & 0xff |
| 427 | |
| 428 | static inline int __cvmx_helper_cfg_ipd2pko_cachex(int ipd_port) |
| 429 | { |
| 430 | int ipd_x = IPD2PKO_CACHE_X(ipd_port); |
| 431 | |
| 432 | if (ipd_port & 0x800) |
| 433 | ipd_x = (ipd_x >> 4) & 3; |
| 434 | return ipd_x; |
| 435 | } |
| 436 | |
| 437 | /* |
| 438 | * ipd_port to pko_port translation cache |
| 439 | */ |
| 440 | int __cvmx_helper_cfg_init_ipd2pko_cache(void) |
| 441 | { |
| 442 | int i, j, n; |
| 443 | int ipd_y, ipd_x, ipd_port; |
| 444 | |
| 445 | for (i = 0; i < cvmx_helper_get_number_of_interfaces(); i++) { |
| 446 | n = cvmx_helper_interface_enumerate(i); |
| 447 | |
| 448 | for (j = 0; j < n; j++) { |
| 449 | ipd_port = cvmx_helper_get_ipd_port(i, j); |
| 450 | ipd_y = IPD2PKO_CACHE_Y(ipd_port); |
| 451 | ipd_x = __cvmx_helper_cfg_ipd2pko_cachex(ipd_port); |
| 452 | ipd2pko_port_cache[ipd_y][ipd_x] = (struct cvmx_cfg_pko_port_pair){ |
| 453 | __cvmx_helper_cfg_pko_port_base(i, j), |
| 454 | __cvmx_helper_cfg_pko_port_num(i, j) |
| 455 | }; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | return 0; |
| 460 | } |
| 461 | |
| 462 | int cvmx_helper_cfg_ipd2pko_port_base(int ipd_port) |
| 463 | { |
| 464 | int ipd_y, ipd_x; |
| 465 | |
| 466 | /* Internal PKO ports are not present in PKO3 */ |
| 467 | if (octeon_has_feature(OCTEON_FEATURE_PKI)) |
| 468 | return ipd_port; |
| 469 | |
| 470 | ipd_y = IPD2PKO_CACHE_Y(ipd_port); |
| 471 | ipd_x = __cvmx_helper_cfg_ipd2pko_cachex(ipd_port); |
| 472 | |
| 473 | return ipd2pko_port_cache[ipd_y][ipd_x].ccppp_base_port; |
| 474 | } |
| 475 | |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 476 | /** |
| 477 | * Return the number of queues to be assigned to this pko_port |
| 478 | * |
| 479 | * @param pko_port |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 480 | * Return: the number of queues for this pko_port |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 481 | * |
| 482 | */ |
| 483 | static int cvmx_helper_cfg_dft_nqueues(int pko_port) |
| 484 | { |
| 485 | cvmx_helper_interface_mode_t mode; |
| 486 | int interface; |
| 487 | int n; |
| 488 | int ret; |
| 489 | |
| 490 | interface = __cvmx_helper_cfg_pko_port_interface(pko_port); |
| 491 | mode = cvmx_helper_interface_get_mode(interface); |
| 492 | |
| 493 | n = NUM_ELEMENTS(__cvmx_pko_queue_static_config[0].pknd.pko_cfg_iface); |
| 494 | |
| 495 | if (mode == CVMX_HELPER_INTERFACE_MODE_LOOP) { |
| 496 | ret = __cvmx_pko_queue_static_config[0].pknd.pko_cfg_loop.queues_per_port; |
| 497 | } else if (mode == CVMX_HELPER_INTERFACE_MODE_NPI) { |
| 498 | ret = __cvmx_pko_queue_static_config[0].pknd.pko_cfg_npi.queues_per_port; |
| 499 | } |
| 500 | |
| 501 | else if ((interface >= 0) && (interface < n)) { |
| 502 | ret = __cvmx_pko_queue_static_config[0].pknd.pko_cfg_iface[interface].queues_per_port; |
| 503 | } else { |
| 504 | /* Should never be called */ |
| 505 | ret = 1; |
| 506 | } |
| 507 | /* Override for sanity in case of empty static config table */ |
| 508 | if (ret == 0) |
| 509 | ret = 1; |
| 510 | return ret; |
| 511 | } |
| 512 | |
| 513 | static int cvmx_helper_cfg_init_pko_iports_and_queues_using_static_config(void) |
| 514 | { |
| 515 | int pko_port_base = 0; |
| 516 | int cvmx_cfg_default_pko_nports = 1; |
| 517 | int i, j, n, k; |
| 518 | int rv = 0; |
| 519 | |
| 520 | if (!port_cfg_data_initialized) |
| 521 | cvmx_init_port_cfg(); |
| 522 | |
| 523 | /* When not using config file, each port is assigned one internal pko port*/ |
| 524 | for (i = 0; i < cvmx_helper_get_number_of_interfaces(); i++) { |
| 525 | n = cvmx_helper_interface_enumerate(i); |
| 526 | for (j = 0; j < n; j++) { |
| 527 | cvmx_cfg_port[0][i][j].ccpp_pko_port_base = pko_port_base; |
| 528 | cvmx_cfg_port[0][i][j].ccpp_pko_num_ports = cvmx_cfg_default_pko_nports; |
| 529 | /* |
| 530 | * Initialize interface early here so that the |
| 531 | * cvmx_helper_cfg_dft_nqueues() below |
| 532 | * can get the interface number corresponding to the |
| 533 | * pko port |
| 534 | */ |
| 535 | for (k = pko_port_base; k < pko_port_base + cvmx_cfg_default_pko_nports; |
| 536 | k++) { |
| 537 | cvmx_cfg_pko_port_map[k].ccppl_interface = i; |
| 538 | } |
| 539 | pko_port_base += cvmx_cfg_default_pko_nports; |
| 540 | } |
| 541 | } |
| 542 | cvmx_helper_cfg_assert(pko_port_base <= CVMX_HELPER_CFG_MAX_PKO_PORT); |
| 543 | |
| 544 | /* Assigning queues per pko */ |
| 545 | for (i = 0; i < pko_port_base; i++) { |
| 546 | int base; |
| 547 | |
| 548 | n = cvmx_helper_cfg_dft_nqueues(i); |
| 549 | base = cvmx_pko_queue_alloc(i, n); |
| 550 | if (base == -1) { |
| 551 | printf("ERROR: %s: failed to alloc %d queues for pko port=%d\n", __func__, |
| 552 | n, i); |
| 553 | rv = -1; |
| 554 | } |
| 555 | } |
| 556 | return rv; |
| 557 | } |
| 558 | |
| 559 | /** |
| 560 | * Returns if port is valid for a given interface |
| 561 | * |
| 562 | * @param xiface interface to check |
| 563 | * @param index port index in the interface |
| 564 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 565 | * Return: status of the port present or not. |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 566 | */ |
| 567 | int cvmx_helper_is_port_valid(int xiface, int index) |
| 568 | { |
| 569 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 570 | |
| 571 | if (!port_cfg_data_initialized) |
| 572 | cvmx_init_port_cfg(); |
| 573 | return cvmx_cfg_port[xi.node][xi.interface][index].valid; |
| 574 | } |
| 575 | |
| 576 | void cvmx_helper_set_port_valid(int xiface, int index, bool valid) |
| 577 | { |
| 578 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 579 | |
| 580 | if (!port_cfg_data_initialized) |
| 581 | cvmx_init_port_cfg(); |
| 582 | cvmx_cfg_port[xi.node][xi.interface][index].valid = valid; |
| 583 | } |
| 584 | |
| 585 | void cvmx_helper_set_mac_phy_mode(int xiface, int index, bool valid) |
| 586 | { |
| 587 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 588 | |
| 589 | if (!port_cfg_data_initialized) |
| 590 | cvmx_init_port_cfg(); |
| 591 | cvmx_cfg_port[xi.node][xi.interface][index].sgmii_phy_mode = valid; |
| 592 | } |
| 593 | |
| 594 | bool cvmx_helper_get_mac_phy_mode(int xiface, int index) |
| 595 | { |
| 596 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 597 | |
| 598 | if (!port_cfg_data_initialized) |
| 599 | cvmx_init_port_cfg(); |
| 600 | return cvmx_cfg_port[xi.node][xi.interface][index].sgmii_phy_mode; |
| 601 | } |
| 602 | |
| 603 | void cvmx_helper_set_1000x_mode(int xiface, int index, bool valid) |
| 604 | { |
| 605 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 606 | |
| 607 | if (!port_cfg_data_initialized) |
| 608 | cvmx_init_port_cfg(); |
| 609 | cvmx_cfg_port[xi.node][xi.interface][index].sgmii_1000x_mode = valid; |
| 610 | } |
| 611 | |
| 612 | bool cvmx_helper_get_1000x_mode(int xiface, int index) |
| 613 | { |
| 614 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 615 | |
| 616 | if (!port_cfg_data_initialized) |
| 617 | cvmx_init_port_cfg(); |
| 618 | return cvmx_cfg_port[xi.node][xi.interface][index].sgmii_1000x_mode; |
| 619 | } |
| 620 | |
| 621 | void cvmx_helper_set_agl_rx_clock_delay_bypass(int xiface, int index, bool valid) |
| 622 | { |
| 623 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 624 | |
| 625 | if (!port_cfg_data_initialized) |
| 626 | cvmx_init_port_cfg(); |
| 627 | cvmx_cfg_port[xi.node][xi.interface][index].agl_rx_clk_delay_bypass = valid; |
| 628 | } |
| 629 | |
| 630 | bool cvmx_helper_get_agl_rx_clock_delay_bypass(int xiface, int index) |
| 631 | { |
| 632 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 633 | |
| 634 | if (!port_cfg_data_initialized) |
| 635 | cvmx_init_port_cfg(); |
| 636 | return cvmx_cfg_port[xi.node][xi.interface][index].agl_rx_clk_delay_bypass; |
| 637 | } |
| 638 | |
| 639 | void cvmx_helper_set_agl_rx_clock_skew(int xiface, int index, uint8_t value) |
| 640 | { |
| 641 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 642 | |
| 643 | if (!port_cfg_data_initialized) |
| 644 | cvmx_init_port_cfg(); |
| 645 | cvmx_cfg_port[xi.node][xi.interface][index].agl_rx_clk_skew = value; |
| 646 | } |
| 647 | |
| 648 | uint8_t cvmx_helper_get_agl_rx_clock_skew(int xiface, int index) |
| 649 | { |
| 650 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 651 | |
| 652 | if (!port_cfg_data_initialized) |
| 653 | cvmx_init_port_cfg(); |
| 654 | return cvmx_cfg_port[xi.node][xi.interface][index].agl_rx_clk_skew; |
| 655 | } |
| 656 | |
| 657 | void cvmx_helper_set_agl_refclk_sel(int xiface, int index, uint8_t value) |
| 658 | { |
| 659 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 660 | |
| 661 | if (!port_cfg_data_initialized) |
| 662 | cvmx_init_port_cfg(); |
| 663 | cvmx_cfg_port[xi.node][xi.interface][index].agl_refclk_sel = value; |
| 664 | } |
| 665 | |
| 666 | uint8_t cvmx_helper_get_agl_refclk_sel(int xiface, int index) |
| 667 | { |
| 668 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 669 | |
| 670 | if (!port_cfg_data_initialized) |
| 671 | cvmx_init_port_cfg(); |
| 672 | return cvmx_cfg_port[xi.node][xi.interface][index].agl_refclk_sel; |
| 673 | } |
| 674 | |
| 675 | void cvmx_helper_set_port_force_link_up(int xiface, int index, bool value) |
| 676 | { |
| 677 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 678 | |
| 679 | if (!port_cfg_data_initialized) |
| 680 | cvmx_init_port_cfg(); |
| 681 | cvmx_cfg_port[xi.node][xi.interface][index].force_link_up = value; |
| 682 | } |
| 683 | |
| 684 | bool cvmx_helper_get_port_force_link_up(int xiface, int index) |
| 685 | { |
| 686 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 687 | |
| 688 | if (!port_cfg_data_initialized) |
| 689 | cvmx_init_port_cfg(); |
| 690 | return cvmx_cfg_port[xi.node][xi.interface][index].force_link_up; |
| 691 | } |
| 692 | |
| 693 | void cvmx_helper_set_port_phy_present(int xiface, int index, bool value) |
| 694 | { |
| 695 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 696 | |
| 697 | if (!port_cfg_data_initialized) |
| 698 | cvmx_init_port_cfg(); |
| 699 | cvmx_cfg_port[xi.node][xi.interface][index].phy_present = value; |
| 700 | } |
| 701 | |
| 702 | bool cvmx_helper_get_port_phy_present(int xiface, int index) |
| 703 | { |
| 704 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 705 | |
| 706 | if (!port_cfg_data_initialized) |
| 707 | cvmx_init_port_cfg(); |
| 708 | return cvmx_cfg_port[xi.node][xi.interface][index].phy_present; |
| 709 | } |
| 710 | |
| 711 | int __cvmx_helper_init_port_valid(void) |
| 712 | { |
| 713 | int i, j, node; |
| 714 | bool valid; |
| 715 | static void *fdt_addr; |
| 716 | int rc; |
| 717 | struct cvmx_coremask pcm; |
| 718 | |
| 719 | octeon_get_available_coremask(&pcm); |
| 720 | |
| 721 | if (fdt_addr == 0) |
| 722 | fdt_addr = __cvmx_phys_addr_to_ptr((u64)gd->fdt_blob, 128 * 1024); |
| 723 | |
| 724 | if (!port_cfg_data_initialized) |
| 725 | cvmx_init_port_cfg(); |
| 726 | if (octeon_has_feature(OCTEON_FEATURE_BGX)) { |
| 727 | rc = __cvmx_helper_parse_bgx_dt(fdt_addr); |
| 728 | if (!rc) |
| 729 | rc = __cvmx_fdt_parse_vsc7224(fdt_addr); |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 730 | if (!rc && octeon_has_feature(OCTEON_FEATURE_BGX_XCV)) |
| 731 | rc = __cvmx_helper_parse_bgx_rgmii_dt(fdt_addr); |
| 732 | |
| 733 | /* Some ports are not in sequence, the device tree does not |
| 734 | * clear them. |
| 735 | * |
| 736 | * Also clear any ports that are not defined in the device tree. |
| 737 | * Apply this to each node. |
| 738 | */ |
| 739 | for (node = 0; node < CVMX_MAX_NODES; node++) { |
| 740 | if (!cvmx_coremask_get64_node(&pcm, node)) |
| 741 | continue; |
| 742 | for (i = 0; i < CVMX_HELPER_MAX_GMX; i++) { |
| 743 | int j; |
| 744 | int xiface = cvmx_helper_node_interface_to_xiface(node, i); |
| 745 | |
| 746 | for (j = 0; j < cvmx_helper_interface_enumerate(i); j++) { |
| 747 | cvmx_bgxx_cmrx_config_t cmr_config; |
| 748 | |
| 749 | cmr_config.u64 = |
| 750 | csr_rd_node(node, CVMX_BGXX_CMRX_CONFIG(j, i)); |
| 751 | if ((cmr_config.s.lane_to_sds == 0xe4 && |
| 752 | cmr_config.s.lmac_type != 4 && |
| 753 | cmr_config.s.lmac_type != 1 && |
| 754 | cmr_config.s.lmac_type != 5) || |
| 755 | ((cvmx_helper_get_port_fdt_node_offset(xiface, j) == |
| 756 | CVMX_HELPER_CFG_INVALID_VALUE))) |
| 757 | cvmx_helper_set_port_valid(xiface, j, false); |
| 758 | } |
| 759 | } |
| 760 | } |
| 761 | return rc; |
| 762 | } |
| 763 | |
| 764 | /* TODO: Update this to behave more like 78XX */ |
| 765 | for (i = 0; i < cvmx_helper_get_number_of_interfaces(); i++) { |
| 766 | int n = cvmx_helper_interface_enumerate(i); |
| 767 | |
| 768 | for (j = 0; j < n; j++) { |
| 769 | int ipd_port = cvmx_helper_get_ipd_port(i, j); |
| 770 | |
| 771 | valid = (__cvmx_helper_board_get_port_from_dt(fdt_addr, ipd_port) == 1); |
| 772 | cvmx_helper_set_port_valid(i, j, valid); |
| 773 | } |
| 774 | } |
| 775 | return 0; |
| 776 | } |
| 777 | |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 778 | /* |
| 779 | * This call is made from Linux octeon_ethernet driver |
| 780 | * to setup the PKO with a specific queue count and |
| 781 | * internal port count configuration. |
| 782 | */ |
| 783 | int cvmx_pko_alloc_iport_and_queues(int interface, int port, int port_cnt, int queue_cnt) |
| 784 | { |
| 785 | int rv, p, port_start, cnt; |
| 786 | |
Stefan Roese | 790978b | 2022-04-07 09:11:44 +0200 | [diff] [blame] | 787 | debug("%s: intf %d/%d pcnt %d qcnt %d\n", __func__, interface, port, port_cnt, |
| 788 | queue_cnt); |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 789 | |
| 790 | if (!port_cfg_data_initialized) |
| 791 | cvmx_init_port_cfg(); |
| 792 | if (octeon_has_feature(OCTEON_FEATURE_PKND)) { |
| 793 | rv = cvmx_pko_internal_ports_alloc(interface, port, port_cnt); |
| 794 | if (rv < 0) { |
| 795 | printf("ERROR: %s: failed to allocate internal ports forinterface=%d port=%d cnt=%d\n", |
| 796 | __func__, interface, port, port_cnt); |
| 797 | return -1; |
| 798 | } |
| 799 | port_start = __cvmx_helper_cfg_pko_port_base(interface, port); |
| 800 | cnt = __cvmx_helper_cfg_pko_port_num(interface, port); |
| 801 | } else { |
| 802 | port_start = cvmx_helper_get_ipd_port(interface, port); |
| 803 | cnt = 1; |
| 804 | } |
| 805 | |
| 806 | for (p = port_start; p < port_start + cnt; p++) { |
| 807 | rv = cvmx_pko_queue_alloc(p, queue_cnt); |
| 808 | if (rv < 0) { |
| 809 | printf("ERROR: %s: failed to allocate queues for port=%d cnt=%d\n", |
| 810 | __func__, p, queue_cnt); |
| 811 | return -1; |
| 812 | } |
| 813 | } |
| 814 | return 0; |
| 815 | } |
| 816 | |
| 817 | static void cvmx_init_port_cfg(void) |
| 818 | { |
| 819 | int node, i, j; |
| 820 | |
| 821 | if (port_cfg_data_initialized) |
| 822 | return; |
| 823 | |
| 824 | for (node = 0; node < CVMX_MAX_NODES; node++) { |
| 825 | for (i = 0; i < CVMX_HELPER_MAX_IFACE; i++) { |
| 826 | for (j = 0; j < CVMX_HELPER_CFG_MAX_PORT_PER_IFACE; j++) { |
| 827 | struct cvmx_cfg_port_param *pcfg; |
| 828 | struct cvmx_srio_port_param *sr; |
| 829 | |
| 830 | pcfg = &cvmx_cfg_port[node][i][j]; |
Stefan Roese | 790978b | 2022-04-07 09:11:44 +0200 | [diff] [blame] | 831 | |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 832 | memset(pcfg, 0, sizeof(*pcfg)); |
| 833 | |
| 834 | pcfg->port_fdt_node = CVMX_HELPER_CFG_INVALID_VALUE; |
| 835 | pcfg->phy_fdt_node = CVMX_HELPER_CFG_INVALID_VALUE; |
| 836 | pcfg->phy_info = NULL; |
| 837 | pcfg->ccpp_pknd = CVMX_HELPER_CFG_INVALID_VALUE; |
| 838 | pcfg->ccpp_bpid = CVMX_HELPER_CFG_INVALID_VALUE; |
| 839 | pcfg->ccpp_pko_port_base = CVMX_HELPER_CFG_INVALID_VALUE; |
| 840 | pcfg->ccpp_pko_num_ports = CVMX_HELPER_CFG_INVALID_VALUE; |
| 841 | pcfg->agl_rx_clk_skew = 0; |
| 842 | pcfg->valid = true; |
| 843 | pcfg->sgmii_phy_mode = false; |
| 844 | pcfg->sgmii_1000x_mode = false; |
| 845 | pcfg->agl_rx_clk_delay_bypass = false; |
| 846 | pcfg->force_link_up = false; |
| 847 | pcfg->disable_an = false; |
| 848 | pcfg->link_down_pwr_dn = false; |
| 849 | pcfg->phy_present = false; |
| 850 | pcfg->tx_clk_delay_bypass = false; |
| 851 | pcfg->rgmii_tx_clk_delay = 0; |
| 852 | pcfg->enable_fec = false; |
| 853 | sr = &pcfg->srio_short; |
| 854 | sr->srio_rx_ctle_agc_override = false; |
| 855 | sr->srio_rx_ctle_zero = 0x6; |
| 856 | sr->srio_rx_agc_pre_ctle = 0x5; |
| 857 | sr->srio_rx_agc_post_ctle = 0x4; |
| 858 | sr->srio_tx_swing_override = false; |
| 859 | sr->srio_tx_swing = 0x7; |
| 860 | sr->srio_tx_premptap_override = false; |
| 861 | sr->srio_tx_premptap_pre = 0; |
| 862 | sr->srio_tx_premptap_post = 0xF; |
| 863 | sr->srio_tx_gain_override = false; |
| 864 | sr->srio_tx_gain = 0x3; |
| 865 | sr->srio_tx_vboost_override = 0; |
| 866 | sr->srio_tx_vboost = true; |
| 867 | sr = &pcfg->srio_long; |
| 868 | sr->srio_rx_ctle_agc_override = false; |
| 869 | sr->srio_rx_ctle_zero = 0x6; |
| 870 | sr->srio_rx_agc_pre_ctle = 0x5; |
| 871 | sr->srio_rx_agc_post_ctle = 0x4; |
| 872 | sr->srio_tx_swing_override = false; |
| 873 | sr->srio_tx_swing = 0x7; |
| 874 | sr->srio_tx_premptap_override = false; |
| 875 | sr->srio_tx_premptap_pre = 0; |
| 876 | sr->srio_tx_premptap_post = 0xF; |
| 877 | sr->srio_tx_gain_override = false; |
| 878 | sr->srio_tx_gain = 0x3; |
| 879 | sr->srio_tx_vboost_override = 0; |
| 880 | sr->srio_tx_vboost = true; |
| 881 | pcfg->agl_refclk_sel = 0; |
| 882 | pcfg->sfp_of_offset = -1; |
| 883 | pcfg->vsc7224_chan = NULL; |
| 884 | } |
| 885 | } |
| 886 | } |
| 887 | port_cfg_data_initialized = true; |
| 888 | } |
| 889 | |
| 890 | int __cvmx_helper_init_port_config_data(int node) |
| 891 | { |
| 892 | int rv = 0; |
| 893 | int i, j, n; |
| 894 | int num_interfaces, interface; |
| 895 | int pknd = 0, bpid = 0; |
| 896 | const int use_static_config = 1; |
| 897 | |
Stefan Roese | 790978b | 2022-04-07 09:11:44 +0200 | [diff] [blame] | 898 | debug("%s:\n", __func__); |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 899 | |
| 900 | if (!port_cfg_data_initialized) |
| 901 | cvmx_init_port_cfg(); |
| 902 | |
| 903 | if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) { |
| 904 | /* PKO3: only needs BPID, PKND to be setup, |
| 905 | * while the rest of PKO3 init is done in cvmx-helper-pko3.c |
| 906 | */ |
| 907 | pknd = 0; |
| 908 | bpid = 0; |
| 909 | for (i = 0; i < cvmx_helper_get_number_of_interfaces(); i++) { |
| 910 | int xiface = cvmx_helper_node_interface_to_xiface(node, i); |
| 911 | |
| 912 | n = cvmx_helper_interface_enumerate(xiface); |
| 913 | /* |
| 914 | * Assign 8 pknds to ILK interface, these pknds will be |
| 915 | * distributed among the channels configured |
| 916 | */ |
| 917 | if (cvmx_helper_interface_get_mode(xiface) == |
| 918 | CVMX_HELPER_INTERFACE_MODE_ILK) { |
| 919 | if (n > 8) |
| 920 | n = 8; |
| 921 | } |
| 922 | if (cvmx_helper_interface_get_mode(xiface) != |
| 923 | CVMX_HELPER_INTERFACE_MODE_NPI) { |
| 924 | for (j = 0; j < n; j++) { |
| 925 | struct cvmx_cfg_port_param *pcfg; |
| 926 | |
| 927 | pcfg = &cvmx_cfg_port[node][i][j]; |
| 928 | pcfg->ccpp_pknd = pknd++; |
| 929 | pcfg->ccpp_bpid = bpid++; |
| 930 | } |
| 931 | } else { |
| 932 | for (j = 0; j < n; j++) { |
| 933 | if (j == n / cvmx_npi_max_pknds) { |
| 934 | pknd++; |
| 935 | bpid++; |
| 936 | } |
| 937 | cvmx_cfg_port[node][i][j].ccpp_pknd = pknd; |
| 938 | cvmx_cfg_port[node][i][j].ccpp_bpid = bpid; |
| 939 | } |
| 940 | pknd++; |
| 941 | bpid++; |
| 942 | } |
| 943 | } /* for i=0 */ |
| 944 | cvmx_helper_cfg_assert(pknd <= CVMX_HELPER_CFG_MAX_PIP_PKND); |
| 945 | cvmx_helper_cfg_assert(bpid <= CVMX_HELPER_CFG_MAX_PIP_BPID); |
| 946 | } else if (octeon_has_feature(OCTEON_FEATURE_PKND)) { |
| 947 | if (use_static_config) |
| 948 | cvmx_helper_cfg_init_pko_iports_and_queues_using_static_config(); |
| 949 | |
| 950 | /* Initialize pknd and bpid */ |
| 951 | for (i = 0; i < cvmx_helper_get_number_of_interfaces(); i++) { |
| 952 | n = cvmx_helper_interface_enumerate(i); |
| 953 | for (j = 0; j < n; j++) { |
| 954 | cvmx_cfg_port[0][i][j].ccpp_pknd = pknd++; |
| 955 | cvmx_cfg_port[0][i][j].ccpp_bpid = bpid++; |
| 956 | } |
| 957 | } |
| 958 | cvmx_helper_cfg_assert(pknd <= CVMX_HELPER_CFG_MAX_PIP_PKND); |
| 959 | cvmx_helper_cfg_assert(bpid <= CVMX_HELPER_CFG_MAX_PIP_BPID); |
| 960 | } else { |
| 961 | if (use_static_config) |
| 962 | cvmx_pko_queue_init_from_cvmx_config_non_pknd(); |
| 963 | } |
| 964 | |
| 965 | /* Remainder not used for PKO3 */ |
| 966 | if (octeon_has_feature(OCTEON_FEATURE_CN78XX_WQE)) |
| 967 | return 0; |
| 968 | |
| 969 | /* init ports, queues which are not initialized */ |
| 970 | num_interfaces = cvmx_helper_get_number_of_interfaces(); |
| 971 | for (interface = 0; interface < num_interfaces; interface++) { |
| 972 | int num_ports = __cvmx_helper_early_ports_on_interface(interface); |
| 973 | int port, port_base, queue; |
| 974 | |
| 975 | for (port = 0; port < num_ports; port++) { |
| 976 | bool init_req = false; |
| 977 | |
| 978 | if (octeon_has_feature(OCTEON_FEATURE_PKND)) { |
| 979 | port_base = __cvmx_helper_cfg_pko_port_base(interface, port); |
| 980 | if (port_base == CVMX_HELPER_CFG_INVALID_VALUE) |
| 981 | init_req = true; |
| 982 | } else { |
| 983 | port_base = cvmx_helper_get_ipd_port(interface, port); |
| 984 | queue = __cvmx_helper_cfg_pko_queue_base(port_base); |
| 985 | if (queue == CVMX_HELPER_CFG_INVALID_VALUE) |
| 986 | init_req = true; |
| 987 | } |
| 988 | |
| 989 | if (init_req) { |
| 990 | rv = cvmx_pko_alloc_iport_and_queues(interface, port, 1, 1); |
| 991 | if (rv < 0) { |
| 992 | debug("cvm_pko_alloc_iport_and_queues failed.\n"); |
| 993 | return rv; |
| 994 | } |
| 995 | } |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | if (octeon_has_feature(OCTEON_FEATURE_PKND)) { |
| 1000 | cvmx_helper_cfg_init_pko_port_map(); |
| 1001 | __cvmx_helper_cfg_init_ipd2pko_cache(); |
| 1002 | } |
| 1003 | |
Stefan Roese | 790978b | 2022-04-07 09:11:44 +0200 | [diff] [blame] | 1004 | #ifdef DEBUG |
| 1005 | cvmx_helper_cfg_show_cfg(); |
| 1006 | cvmx_pko_queue_show(); |
| 1007 | #endif |
| 1008 | |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1009 | return rv; |
| 1010 | } |
| 1011 | |
| 1012 | /** |
| 1013 | * @INTERNAL |
| 1014 | * Store the FDT node offset in the device tree of a port |
| 1015 | * |
| 1016 | * @param xiface node and interface |
| 1017 | * @param index port index |
| 1018 | * @param node_offset node offset to store |
| 1019 | */ |
| 1020 | void cvmx_helper_set_port_fdt_node_offset(int xiface, int index, int node_offset) |
| 1021 | { |
| 1022 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1023 | |
| 1024 | if (!port_cfg_data_initialized) |
| 1025 | cvmx_init_port_cfg(); |
| 1026 | cvmx_cfg_port[xi.node][xi.interface][index].port_fdt_node = node_offset; |
| 1027 | } |
| 1028 | |
| 1029 | /** |
| 1030 | * @INTERNAL |
| 1031 | * Return the FDT node offset in the device tree of a port |
| 1032 | * |
| 1033 | * @param xiface node and interface |
| 1034 | * @param index port index |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 1035 | * Return: node offset of port or -1 if invalid |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1036 | */ |
| 1037 | int cvmx_helper_get_port_fdt_node_offset(int xiface, int index) |
| 1038 | { |
| 1039 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1040 | |
| 1041 | if (!port_cfg_data_initialized) |
| 1042 | cvmx_init_port_cfg(); |
| 1043 | return cvmx_cfg_port[xi.node][xi.interface][index].port_fdt_node; |
| 1044 | } |
| 1045 | |
| 1046 | /** |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1047 | * @INTERNAL |
| 1048 | * Store the FDT node offset in the device tree of a phy |
| 1049 | * |
| 1050 | * @param xiface node and interface |
| 1051 | * @param index port index |
| 1052 | * @param node_offset node offset to store |
| 1053 | */ |
| 1054 | void cvmx_helper_set_phy_fdt_node_offset(int xiface, int index, int node_offset) |
| 1055 | { |
| 1056 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1057 | |
| 1058 | if (!port_cfg_data_initialized) |
| 1059 | cvmx_init_port_cfg(); |
| 1060 | cvmx_cfg_port[xi.node][xi.interface][index].phy_fdt_node = node_offset; |
| 1061 | } |
| 1062 | |
| 1063 | /** |
| 1064 | * @INTERNAL |
| 1065 | * Return the FDT node offset in the device tree of a phy |
| 1066 | * |
| 1067 | * @param xiface node and interface |
| 1068 | * @param index port index |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 1069 | * Return: node offset of phy or -1 if invalid |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1070 | */ |
| 1071 | int cvmx_helper_get_phy_fdt_node_offset(int xiface, int index) |
| 1072 | { |
| 1073 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1074 | |
| 1075 | if (!port_cfg_data_initialized) |
| 1076 | cvmx_init_port_cfg(); |
| 1077 | return cvmx_cfg_port[xi.node][xi.interface][index].phy_fdt_node; |
| 1078 | } |
| 1079 | |
| 1080 | /** |
| 1081 | * @INTERNAL |
| 1082 | * Override default autonegotiation for a port |
| 1083 | * |
| 1084 | * @param xiface node and interface |
| 1085 | * @param index port index |
| 1086 | * @param enable true to enable autonegotiation, false to force full |
| 1087 | * duplex, full speed. |
| 1088 | */ |
| 1089 | void cvmx_helper_set_port_autonegotiation(int xiface, int index, bool enable) |
| 1090 | { |
| 1091 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1092 | |
| 1093 | if (!port_cfg_data_initialized) |
| 1094 | cvmx_init_port_cfg(); |
| 1095 | cvmx_cfg_port[xi.node][xi.interface][index].disable_an = !enable; |
| 1096 | } |
| 1097 | |
| 1098 | /** |
| 1099 | * @INTERNAL |
| 1100 | * Returns if autonegotiation is enabled or not. |
| 1101 | * |
| 1102 | * @param xiface node and interface |
| 1103 | * @param index port index |
| 1104 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 1105 | * Return: 0 if autonegotiation is disabled, 1 if enabled. |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1106 | */ |
| 1107 | bool cvmx_helper_get_port_autonegotiation(int xiface, int index) |
| 1108 | { |
| 1109 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1110 | |
| 1111 | if (!port_cfg_data_initialized) |
| 1112 | cvmx_init_port_cfg(); |
| 1113 | return !cvmx_cfg_port[xi.node][xi.interface][index].disable_an; |
| 1114 | } |
| 1115 | |
| 1116 | /** |
| 1117 | * @INTERNAL |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1118 | * Returns if forward error correction is enabled or not. |
| 1119 | * |
| 1120 | * @param xiface node and interface |
| 1121 | * @param index port index |
| 1122 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 1123 | * Return: false if fec is disabled, true if enabled. |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1124 | */ |
| 1125 | bool cvmx_helper_get_port_fec(int xiface, int index) |
| 1126 | { |
| 1127 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1128 | |
| 1129 | if (!port_cfg_data_initialized) |
| 1130 | cvmx_init_port_cfg(); |
| 1131 | return cvmx_cfg_port[xi.node][xi.interface][index].enable_fec; |
| 1132 | } |
| 1133 | |
| 1134 | /** |
| 1135 | * @INTERNAL |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1136 | * Sets the PHY info data structure |
| 1137 | * |
| 1138 | * @param xiface node and interface |
| 1139 | * @param index port index |
| 1140 | * @param[in] phy_info phy information data structure pointer |
| 1141 | */ |
| 1142 | void cvmx_helper_set_port_phy_info(int xiface, int index, struct cvmx_phy_info *phy_info) |
| 1143 | { |
| 1144 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1145 | |
| 1146 | if (!port_cfg_data_initialized) |
| 1147 | cvmx_init_port_cfg(); |
| 1148 | cvmx_cfg_port[xi.node][xi.interface][index].phy_info = phy_info; |
| 1149 | } |
| 1150 | |
| 1151 | /** |
| 1152 | * @INTERNAL |
| 1153 | * Returns the PHY information data structure for a port |
| 1154 | * |
| 1155 | * @param xiface node and interface |
| 1156 | * @param index port index |
| 1157 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 1158 | * Return: pointer to PHY information data structure or NULL if not set |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1159 | */ |
| 1160 | struct cvmx_phy_info *cvmx_helper_get_port_phy_info(int xiface, int index) |
| 1161 | { |
| 1162 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1163 | |
| 1164 | if (!port_cfg_data_initialized) |
| 1165 | cvmx_init_port_cfg(); |
| 1166 | return cvmx_cfg_port[xi.node][xi.interface][index].phy_info; |
| 1167 | } |
| 1168 | |
| 1169 | /** |
| 1170 | * @INTERNAL |
| 1171 | * Returns a pointer to the PHY LED configuration (if local GPIOs drive them) |
| 1172 | * |
| 1173 | * @param xiface node and interface |
| 1174 | * @param index portindex |
| 1175 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 1176 | * Return: pointer to the PHY LED information data structure or NULL if not |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1177 | * present |
| 1178 | */ |
| 1179 | struct cvmx_phy_gpio_leds *cvmx_helper_get_port_phy_leds(int xiface, int index) |
| 1180 | { |
| 1181 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1182 | |
| 1183 | if (!port_cfg_data_initialized) |
| 1184 | cvmx_init_port_cfg(); |
| 1185 | return cvmx_cfg_port[xi.node][xi.interface][index].gpio_leds; |
| 1186 | } |
| 1187 | |
| 1188 | /** |
| 1189 | * @INTERNAL |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1190 | * Disables RGMII TX clock bypass and sets delay value |
| 1191 | * |
| 1192 | * @param xiface node and interface |
| 1193 | * @param index portindex |
| 1194 | * @param bypass Set true to enable the clock bypass and false |
| 1195 | * to sync clock and data synchronously. |
| 1196 | * Default is false. |
| 1197 | * @param clk_delay Delay value to skew TXC from TXD |
| 1198 | */ |
| 1199 | void cvmx_helper_cfg_set_rgmii_tx_clk_delay(int xiface, int index, bool bypass, int clk_delay) |
| 1200 | { |
| 1201 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1202 | |
| 1203 | if (!port_cfg_data_initialized) |
| 1204 | cvmx_init_port_cfg(); |
| 1205 | cvmx_cfg_port[xi.node][xi.interface][index].tx_clk_delay_bypass = bypass; |
| 1206 | cvmx_cfg_port[xi.node][xi.interface][index].rgmii_tx_clk_delay = clk_delay; |
| 1207 | } |
| 1208 | |
| 1209 | /** |
| 1210 | * @INTERNAL |
| 1211 | * Gets RGMII TX clock bypass and delay value |
| 1212 | * |
| 1213 | * @param xiface node and interface |
| 1214 | * @param index portindex |
| 1215 | * @param bypass Set true to enable the clock bypass and false |
| 1216 | * to sync clock and data synchronously. |
| 1217 | * Default is false. |
| 1218 | * @param clk_delay Delay value to skew TXC from TXD, default is 0. |
| 1219 | */ |
| 1220 | void cvmx_helper_cfg_get_rgmii_tx_clk_delay(int xiface, int index, bool *bypass, int *clk_delay) |
| 1221 | { |
| 1222 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1223 | |
| 1224 | if (!port_cfg_data_initialized) |
| 1225 | cvmx_init_port_cfg(); |
| 1226 | *bypass = cvmx_cfg_port[xi.node][xi.interface][index].tx_clk_delay_bypass; |
| 1227 | |
| 1228 | *clk_delay = cvmx_cfg_port[xi.node][xi.interface][index].rgmii_tx_clk_delay; |
| 1229 | } |
| 1230 | |
| 1231 | /** |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1232 | * Sets the Microsemi VSC7224 channel info data structure |
| 1233 | * |
| 1234 | * @param xiface node and interface |
| 1235 | * @param index port index |
| 1236 | * @param[in] vsc7224_info Microsemi VSC7224 data structure |
| 1237 | */ |
| 1238 | void cvmx_helper_cfg_set_vsc7224_chan_info(int xiface, int index, |
| 1239 | struct cvmx_vsc7224_chan *vsc7224_chan_info) |
| 1240 | { |
| 1241 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1242 | |
| 1243 | if (!port_cfg_data_initialized) |
| 1244 | cvmx_init_port_cfg(); |
| 1245 | cvmx_cfg_port[xi.node][xi.interface][index].vsc7224_chan = vsc7224_chan_info; |
| 1246 | } |
| 1247 | |
| 1248 | /** |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1249 | * Gets the SFP data associated with a port |
| 1250 | * |
| 1251 | * @param xiface node and interface |
| 1252 | * @param index port index |
| 1253 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 1254 | * Return: pointer to SFP data structure or NULL if none |
Aaron Williams | c691f4d | 2020-12-11 17:05:58 +0100 | [diff] [blame] | 1255 | */ |
| 1256 | struct cvmx_fdt_sfp_info *cvmx_helper_cfg_get_sfp_info(int xiface, int index) |
| 1257 | { |
| 1258 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1259 | |
| 1260 | if (!port_cfg_data_initialized) |
| 1261 | cvmx_init_port_cfg(); |
| 1262 | return cvmx_cfg_port[xi.node][xi.interface][index].sfp_info; |
| 1263 | } |
| 1264 | |
| 1265 | /** |
| 1266 | * Sets the SFP data associated with a port |
| 1267 | * |
| 1268 | * @param xiface node and interface |
| 1269 | * @param index port index |
| 1270 | * @param[in] sfp_info port SFP data or NULL for none |
| 1271 | */ |
| 1272 | void cvmx_helper_cfg_set_sfp_info(int xiface, int index, struct cvmx_fdt_sfp_info *sfp_info) |
| 1273 | { |
| 1274 | struct cvmx_xiface xi = cvmx_helper_xiface_to_node_interface(xiface); |
| 1275 | |
| 1276 | if (!port_cfg_data_initialized) |
| 1277 | cvmx_init_port_cfg(); |
| 1278 | cvmx_cfg_port[xi.node][xi.interface][index].sfp_info = sfp_info; |
| 1279 | } |