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

phy8806x_tsc_functions.h (19289B)


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