falcon_tsc_functions.h (19268B)
1 /**************************************************************************** 2 * File Name : falcon_tsc_functions.h 3 * Created On : 29/04/2013 4 * Created By : Kiran Divakar 5 * Description: Header file with API functions for Serdes IPs 6 * 7 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 8 * 9 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 10 * No portions of this material may be reproduced in any form without 11 * the written permission of: 12 * 13 * Broadcom Corporation 14 * 5300 California Avenue 15 * Irvine, CA 92617 16 * 17 * All information contained in this document is Broadcom Corporation 18 * company private proprietary, and trade secret. 19 *//** 20 * @file 21 * Protoypes of all API functions for engineering use 22 *//*************************************************************************/ 23 24 25 26 #ifndef FALCON_TSC_API_FUNCTIONS_H 27 #define FALCON_TSC_API_FUNCTIONS_H 28 #include <phymod/phymod.h> 29 30 /* include all .h files, even though some are redundant */ 31 32 #include "falcon_tsc_usr_includes.h" 33 34 #include "falcon_tsc_ipconfig.h" 35 #include "falcon_tsc_dependencies.h" 36 #include "falcon_tsc_interface.h" 37 #include "falcon_tsc_debug_functions.h" 38 #include "falcon_tsc_common.h" 39 #include "falcon_api_uc_common.h" 40 #include "common/srds_api_uc_common.h" 41 42 #include "falcon_tsc_field_access.h" 43 #include "falcon_tsc_enum.h" 44 #include "common/srds_api_err_code.h" 45 #include "falcon_tsc_internal.h" 46 47 48 49 50 /** 51 * Error-trapping macro. 52 * 53 * In other then SerDes-team post-silicon evaluation builds, simply yields 54 * the error code supplied as an argument, without further action. 55 */ 56 #define _error(err_code) _print_err_msg(err_code) 57 58 /**@}*/ 59 60 61 62 /************************************************************************//** 63 * @name Error-Code Storage Addresses. 64 * 65 * Used by error-checking expression-wrapper macros. Expands to the address 66 * where the macros are meant to store the error codes on which they operate, 67 * which depends on the target core and type of executable image being built. 68 * 69 * These are defined well ahead of the error-checking macros themselves to 70 * facilitate definition of RAM- and register-access macros generally used 71 * in their argyments. 72 *//*************************************************************************/ 73 /**@{*/ 74 75 76 /** 77 * Error-code storage address. 78 * 79 * This is a standard API build that directs error-checking expression-wrapper 80 * macros to use a block-local error codes for efficient. local optimization. 81 */ 82 #define __ERR &__err 83 84 /**@}*/ 85 86 87 88 /************************************************************************//** 89 * @name Register Access Macro Inclusions 90 * 91 * All cores provide access to hardware control/status registers. 92 *//*************************************************************************/ 93 /**@{*/ 94 95 96 97 /** 98 * This build includes register access macros for the FALCON/TSC core. 99 */ 100 #include "falcon_tsc_fields.h" 101 102 103 104 105 /**@}*/ 106 107 108 109 /************************************************************************//** 110 * @name RAM Access Macro Inclusions 111 * 112 * Some cores also provide access to firmware control/status RAM variables. 113 *//*************************************************************************/ 114 /**@{*/ 115 116 /** 117 * This build includes macros to access Falcon and/or Falcon2 microcode RAM 118 * variables. 119 */ 120 #include "falcon_api_uc_vars_rdwr_defns.h" 121 122 /**@}*/ 123 124 125 126 /************************************************************************//** 127 * @name Direct RAM Access 128 * 129 * Cores/chips with a built-in microcontroller afford direct, memory-mapped 130 * access to the firmware control/status RAM variables. 131 *//*************************************************************************/ 132 /**@{*/ 133 134 /** Base of core variable block, FALCON/FALCON2 variant. */ 135 #define CORE_VAR_RAM_BASE (0x400) 136 /** Base of lane variable block, FALCON/FALCON2 variant. */ 137 #define LANE_VAR_RAM_BASE (0x420) 138 /** Size of lane variable block, FALCON/FALCON2 variant. */ 139 #define LANE_VAR_RAM_SIZE (0x130) 140 #define CORE_VAR_RAM_SIZE (0x40) 141 142 /**@}*/ 143 144 145 146 /************************************************************************//** 147 * @name Diagnostic Sampling 148 *//*************************************************************************/ 149 /**@{*/ 150 151 #ifdef STANDALONE_EVENT 152 #define DIAG_MAX_SAMPLES (64) 153 #else 154 /** 155 * Diagnostic sample set size, FALCON/FALCON2 variant. 156 * 157 * Applies to collections of BER measurements, eye margins, etc. 158 */ 159 #define DIAG_MAX_SAMPLES (64) 160 161 #endif 162 163 /**@}*/ 164 165 166 167 /************************************************************************//** 168 * @name Error-Checking Expression Wrappers 169 * 170 * These macros simplify checking and forwarding of error codes returned 171 * either directly or indirectly in the context of functions that themselves 172 * return error codes directly or indirectly. 173 * 174 * All expand to unterminated statements and dereference `__ERR' (defined as 175 * a macro in the same header) to access either private, block-internal error 176 * codes (`__err') or a common error-code cache (e.g. `global_err_code' in 177 * SerDes team post-silicon evaluation builds). 178 * 179 * Neither `__err' nor `__ERR' should be used directly outside the API; and 180 * their names may change to comply with the C Language standard reservation 181 * of identifiers beginning with `__' for use by compiler implementers. 182 * 183 * Great care is taken to ensure not only that error returns are checked but 184 * that use of an error-code cache (as in SerDes team post-silicon evaluation 185 * builds) does not cause "unused variable" warnings. 186 *//*************************************************************************/ 187 /**@{*/ 188 189 /** 190 * Error-check a function call, returning error codes returned. 191 * 192 * Evaluates an expression (typically function call), stores its value into 193 * `*(__ERR)' and returns it from a containing function if it is unequal to 194 * `ERR_CODE_NONE'. 195 * 196 * EFUN() is intended for use in functions returning error codes directly to 197 * check calls to functions also returning error codes directly, e.g.: 198 * 199 * err_code_t foo(...) // remaining arguments elided 200 * { 201 * // ... 202 * EFUN(wrc_core_s_rstb(0x0)); 203 * // ... 204 * return ERR_CODE_NONE; 205 * } 206 */ 207 208 #define EFUN(expr) \ 209 do { \ 210 err_code_t __err; \ 211 *(__ERR) = (expr); \ 212 if (*(__ERR) != ERR_CODE_NONE) \ 213 return _error(*(__ERR)); \ 214 (void)__err; \ 215 } while (0) 216 217 /** 218 * Error-check a statement, returning error codes forwarded. 219 * 220 * Evaluates an expression (typically unterminated statement) that may modify 221 * `*(__ERR)' and returns it from a containing function if it is unequal to 222 * `ERR_CODE_NONE'. 223 * 224 * ESTM() is intended for use in functions returning error codes directly to 225 * check calls to functions returning error codes indirectly, e.g.: 226 * 227 * err_code_t foo(...) // remaining arguments elided 228 * { 229 * uint8_t rst; 230 * // ... 231 * ESTM(rst = rdc_core_s_rstb()); 232 * // ... 233 * return ERR_CODE_NONE; 234 * } 235 */ 236 237 #define ESTM(expr) \ 238 do { \ 239 err_code_t __err; \ 240 *(__ERR) = ERR_CODE_NONE; \ 241 (expr); \ 242 if (*(__ERR) != ERR_CODE_NONE) \ 243 return _error(*(__ERR)); \ 244 (void)__err; \ 245 } while (0) 246 247 /** 248 * Error-check a function call, defaulting when forwarding error codes 249 * returned. 250 * 251 * In a function taking an argument `err_code_t *err_code_p' in lieu of 252 * returning an error code directly, evaluates an expression (typically 253 * function call), stores its value into `*(__ERR)', combines this (bitwise 254 * inclusive ore) into `*(err_code_p)', and returns a default value if either 255 * `*(__ERR)' or `*(err_code_p)' is not `ERR_CODE_NONE'. 256 * 257 * EPFUN2() is intended for use in functions returning error codes indirectly 258 * to check calls to functions returning error codes directly, e.g.: 259 * 260 * uint8_t foo(err_code_t *err_code_p, ...) // remaining arguments elided 261 * { 262 * uint8_t result = 0x0; 263 * // ... 264 * EPFUN2(wrc_core_s_rstb(0x0), 0x1); 265 * // ... 266 * return result; 267 * } 268 */ 269 270 #define EPFUN2(expr, on_err) \ 271 do { \ 272 err_code_t __err; \ 273 *(__ERR) = (expr); \ 274 *(err_code_p) |= *(__ERR); \ 275 if ((*(err_code_p) != ERR_CODE_NONE) \ 276 || (*(__ERR) != ERR_CODE_NONE)) \ 277 return (on_err); \ 278 (void)__err; \ 279 } while (0) 280 281 /** 282 * Error-check a statement, defaulting when forwarding error codes forwarded. 283 * 284 * In a function taking an argument `err_code_t *err_code_p' in lieu of 285 * returning an error code directly, evaluates an expression (typically 286 * unterminated statement), stores its value into `*(__ERR)', combines this 287 * (bitwise inclusive ore) into `*(err_code_p)', and returns a default value 288 * if either `*(__ERR)' or `*(err_code_p)' is not `ERR_CODE_NONE'. 289 * 290 * EPSTM2() is intended for use in functions returning error codes indirectly 291 * to check calls to functions also returning error codes indirectly, e.g.: 292 * 293 * uint8_t foo(err_code_t *err_code_p, ...) // remaining arguments elided 294 * { 295 * uint8_t result; 296 * // ... 297 * EPSTM(result = rdc_core_s_rstb(), 0x1); 298 * // ... 299 * return result; 300 * } 301 */ 302 303 #define EPSTM2(expr, on_err) \ 304 do { \ 305 err_code_t __err; \ 306 *(__ERR) = ERR_CODE_NONE; \ 307 (expr); \ 308 *(err_code_p) |= *(__ERR); \ 309 if ((*(err_code_p ) != ERR_CODE_NONE) \ 310 || (*(__ERR) != ERR_CODE_NONE)) \ 311 return (on_err); \ 312 (void)__err; \ 313 } while (0) 314 315 /** 316 * Error-check a function call, defaulting to zero when forwarding error codes 317 * returned. 318 * 319 * Supplies a default value of zero to EPFUN2() to reduce clutter in the most 320 * common case. 321 * 322 * EPFUN() is intended for use in functions returning error codes indirectly 323 * to check calls to functions returning error codes directly, e.g.: 324 * 325 * uint8_t foo(err_code_t *err_code_p, ...) // remaining arguments elided 326 * { 327 * uint8_t result; // determined below, detail elided 328 * // ... 329 * EPFUN(wrc_core_s_rstb(0x0)); 330 * // ... 331 * return result; 332 * } 333 */ 334 335 #define EPFUN(expr) EPFUN2((expr), 0) 336 337 /** 338 * Error-check a statement, defaulting to zero when forwarding error codes 339 * forwarded. 340 * 341 * Supplies a default value of zero to EPSTM2() to reduce clutter in the most 342 * common case. 343 * 344 * EPSTM() is intended for use in functions returning error codes indirectly 345 * to check calls to functions also returning error codes indirectly, e.g.: 346 * 347 * uint8_t foo(err_code_t *err_code_p, ...) // remaining arguments elided 348 * { 349 * uint8_t result; 350 * // ... 351 * EPSTM(result = rdc_core_s_rstb()); 352 * // ... 353 * return result; 354 * } 355 */ 356 357 #define EPSTM(expr) EPSTM2((expr), 0) 358 359 /** 360 * Invoke a function with automatic return of error on NULL result. 361 * 362 * ENULL() is intended for use in functions returning error codes directly to 363 * check calls to functions returning pointers, e.g.: 364 * 365 * err_code_t foo(...) // remaining arguments elided 366 * { 367 * // ... 368 * ENULL(strchr("foo", 'q')); 369 * // ... 370 * return ERR_CODE_NONE; 371 * } 372 */ 373 #define ENULL(expr) \ 374 EFUN((((void*)0 != (expr)) ? ERR_CODE_NONE : ERR_CODE_BAD_PTR_OR_INVALID_INPUT)) 375 376 /** 377 * Invoke a function with automatic forward of error on NULL result. 378 * 379 * EPNULL() is intended for use in functions returning error codes indirectly 380 * to check calls to functions returning pointers, e.g.: 381 * 382 * uint8_t foo(err_code_t *err_code_p, ...) // remaining arguments elided 383 * { 384 * uint8_t result; // determined below, detail elided 385 * // ... 386 * EPNULL(strchr(foo, 'q')); 387 * // ... 388 * return result; 389 * } 390 */ 391 #define EPNULL(expr) \ 392 EPFUN((((void*)0 != (expr)) ? ERR_CODE_NONE : ERR_CODE_BAD_PTR_OR_INVALID_INPUT)) 393 394 /** 395 * Invoke USR_PRINTF(()) with non-error-code-generating arguments. 396 * 397 * Note that the single argument is a parenthesized argument list to be 398 * passed to USR_PRINTF(()). 399 * 400 * EFUN_PRINTF(()) is intended for use in functions returning error codes 401 * directly, with an argument list the elements of which do not generate 402 * error codes of any kind, e.g.: 403 * 404 * err_code_t foo(...) // remaining arguments elided 405 * { 406 * // ... 407 * EFUN_PRINTF(("%u", 1)); 408 * // ... 409 * return ERR_CODE_NONE; 410 * } 411 */ 412 #define EFUN_PRINTF(paren_arg_list) USR_PRINTF(paren_arg_list) 413 414 /** 415 * Invoke USR_PRINTF(()) with error-code-generating arguments that would 416 * otherwise be handled by ESTM(). 417 * 418 * Note that the single argument is a parenthesized argument list to be 419 * passed to USR_PRINTF(()). 420 * 421 * EFUN_PRINTF(()) is intended for use in functions returning error codes 422 * directly, with an argument list the elements of which may generate error 423 * codes indirectly, e.g.: 424 * 425 * err_code_t foo(...) // remaining arguments elided 426 * { 427 * // ... 428 * ESTM_PRINTF(("%u", rdc_core_s_rstb())); 429 * // ... 430 * return ERR_CODE_NONE; 431 * } 432 */ 433 #define ESTM_PRINTF(paren_arg_list) \ 434 do { \ 435 err_code_t __err; \ 436 *(__ERR) = ERR_CODE_NONE; \ 437 USR_PRINTF(paren_arg_list); \ 438 if (*(__ERR) != ERR_CODE_NONE) \ 439 return _error(*(__ERR)); \ 440 (void)__err; \ 441 } while (0) 442 443 /** 444 * Invoke possibly-remapped 'memset()' and, if it returns NULL, force an 445 * error return. 446 * 447 * Ordinarily, standard implementations of 'memset' will return NULL only if 448 * passed a NULL destination address, and *may already* have overwritten an 449 * inappropriate address range before returning: nevertheless, a specialized 450 * implementation could use a NULL return to indicate other failures. In 451 * either case, execution should not be allowed to proceed on NULL return. 452 */ 453 #define ENULL_MEMSET(mem, val, num) ENULL((USR_MEMSET((mem), (val), (num)))) 454 455 /** 456 * Invoke possibly-remapped 'memset()' and, if it returns NULL, force an 457 * error to be forwarded. 458 * 459 * Ordinarily, standard implementations of 'memset' will return NULL only if 460 * passed a NULL destination address, and *may already* have overwritten an 461 * inappropriate address range before returning: nevertheless, a specialized 462 * implementation could use a NULL return to indicate other failures. In 463 * either case, execution should not be allowed to proceed on NULL return. 464 */ 465 #define EPNULL_MEMSET(mem, val, num) EPNULL((USR_MEMSET((mem), (val), (num)))) 466 467 /** 468 * Invoke possibly-remapped 'strcpy()' and, if it returns NULL, force an 469 * error return. 470 * 471 * Ordinarily, standard implementations of 'strcpy' will return NULL only if 472 * passed a NULL destination address, and *may already* have overwritten an 473 * inappropriate address range before returning: nevertheless, a specialized 474 * implementation could use a NULL return to indicate other failures. In 475 * either case, execution should not be allowed to proceed on NULL return. 476 */ 477 #define ENULL_STRCPY(dst, src) ENULL((USR_STRCPY((dst), (src)))) 478 479 /** 480 * Invoke possibly-remapped 'strcpy()' and, if it returns NULL, force an 481 * error to be forwarded. 482 * 483 * Ordinarily, standard implementations of 'strcpy' will return NULL only if 484 * passed a NULL destination address, and *may already* have overwritten an 485 * inappropriate address range before returning: nevertheless, a specialized 486 * implementation could use a NULL return to indicate other failures. In 487 * either case, execution should not be allowed to proceed on NULL return. 488 */ 489 #define EPNULL_STRCPY(dst, src) EPNULL((USR_STRCPY((dst), (src)))) 490 491 /** 492 * Invoke possibly-remapped 'strcpy()' and, if it returns NULL, force an 493 * error return. 494 * 495 * Ordinarily, standard implementations of 'strncpy' will return NULL only if 496 * passed a NULL destination address, and *may already* have overwritten an 497 * inappropriate address range before returning: nevertheless, a specialized 498 * implementation could use a NULL return to indicate other failures. In 499 * either case, execution should not be allowed to proceed on NULL return. 500 */ 501 #define ENULL_STRNCAT(dst, src, size) ENULL((USR_STRNCAT((dst), (src), (size)))) 502 503 /** 504 * Invoke possibly-remapped 'strcpy()' and, if it returns NULL, force an 505 * error to be forwarded. 506 * 507 * Ordinarily, standard implementations of 'strncpy' will return NULL only if 508 * passed a NULL destination address, and *may already* have overwritten an 509 * inappropriate address range before returning: nevertheless, a specialized 510 * implementation could use a NULL return to indicate other failures. In 511 * either case, execution should not be allowed to proceed on NULL return. 512 */ 513 #define EPNULL_STRNCAT(dst, src, size) EPNULL((USR_STRNCAT((dst), (src), (size)))) 514 515 /**@}*/ 516 517 /************************************************************************//** 518 * @name Display Utility Macros 519 *//*************************************************************************/ 520 /**@{*/ 521 522 /** Display a signed integer variable. */ 523 #define DISP(x) ESTM_PRINTF(("%s = %d\n", # x, x)) 524 525 /** Display an unsigned integer variable. */ 526 #define DISPU(x) ESTM_PRINTF(("%s = %u\n", # x, x)) 527 528 /** Display a floating point variable. */ 529 #define DISPF(x) ESTM_PRINTF(("%s = %f\n", # x, x)) 530 531 /** Display an integer variable in hex. */ 532 #define DISPX(x) ESTM_PRINTF(("%s = %x\n", # x, x)) 533 534 /** Read and display the value of a lane register field in decimal. */ 535 #define DISP_REG(x) ESTM_PRINTF(("%s = %d\n", # x, rd_ ## x ## ())) 536 537 /** Read and display the value of a lane register field in hex. */ 538 #define DISP_REGX(x) ESTM_PRINTF(("%s = %x\n", # x, rd_ ## x ## ())) 539 540 /** Read and display the value of a core register field in hex. */ 541 #define DISP_REGC(x) ESTM_PRINTF(("%s = %x\n", # x, rdc_ ## x ## ())) 542 543 /** Display a single member of a lane struct. */ 544 #define DISP_LN_VARS(name, param, format) \ 545 do { \ 546 ESTM_PRINTF(("%-16s\t", name)); \ 547 for (i = 0; i < num_lanes; i++) { \ 548 ESTM_PRINTF((format, (lane_st[i].param))); \ 549 } \ 550 EFUN_PRINTF(("\n")); \ 551 } while (0) 552 553 /** Display two members of a lane struct. */ 554 #define DISP_LNQ_VARS(name, param1, param2, format) \ 555 do { \ 556 ESTM_PRINTF(("%-16s\t", name)); \ 557 for (i = 0; i < num_lanes; i++) { \ 558 ESTM_PRINTF((format, (lane_st[i].param1), (lane_st[i].param2))); \ 559 } \ 560 EFUN_PRINTF(("\n")); \ 561 } while (0) 562 563 /**@}*/ 564 565 /************************************************************************//** 566 * @name Arithmetic Utility Macros 567 *//*************************************************************************/ 568 /**@{*/ 569 570 /** 571 * Clockwise difference between phase counters. 572 */ 573 #define dist_cw(a, b) (((a) <= (b)) ? ((b) - (a)) : ((uint16_t)256 - (a) + (b))) 574 575 /** 576 * Counter-clockwise difference between phase counters 577 */ 578 #define dist_ccw(a, b) (((a) >= (b)) ? ((a) - (b)) : ((uint16_t)256 + (a) - (b))) 579 580 /** 581 * Lesser of two expressions. 582 * 583 * @warning 584 * 585 * May evaluate the selected expression twice. 586 */ 587 #define _min(a, b) (((a) > (b)) ? (b) : (a)) 588 589 /** 590 * Greater of two expressions. 591 * 592 * @warning 593 * 594 * May evaluate the selected expression twice. 595 */ 596 #define _max(a, b) (((a) > (b)) ? (a) : (b)) 597 598 /** 599 * Absolute value of an expression. 600 * 601 * @warning 602 * 603 * May evaluate the given expression twice. 604 */ 605 #define _abs(a) (((a) > 0) ? (a) : (-(a))) 606 607 /**@}*/ 608 #endif