openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

eagle_tsc_functions.h (19202B)


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