tsc_functions.h (10026B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: portphy.h 8 */ 9 10 #ifndef _TSC_FUNCTIONS_H_ 11 #define _TSC_FUNCTIONS_H_ 12 13 #include "types.h" 14 #include "error.h" 15 #include "bcm_utils.h" 16 #include "bcm_pe_fields.h" 17 #include "bcm_pe_api_uc_vars_rdwr_defns.h" 18 19 20 /** 21 * Error-check a function call, returning error codes returned. 22 * 23 * Evaluates an expression (typically function call), stores its value into 24 * `*(__ERR)' and returns it from a containing function if it is unequal to 25 * `SOC_E_NONE'. 26 * 27 * EFUN() is intended for use in functions returning error codes directly to 28 * check calls to functions also returning error codes directly, e.g.: 29 * 30 * int foo(...) // remaining arguments elided 31 * { 32 * // ... 33 * EFUN(wrc_core_s_rstb(0x0)); 34 * // ... 35 * return SOC_E_NONE; 36 * } 37 */ 38 39 #define EFUN(expr) \ 40 do { \ 41 int __err; \ 42 *(__ERR) = (expr); \ 43 if (*(__ERR) != SOC_E_NONE) \ 44 return (*(__ERR)); \ 45 (void)__err; \ 46 } while (0) 47 48 49 /** 50 * Error-check a statement, returning error codes forwarded. 51 * 52 * Evaluates an expression (typically unterminated statement) that may modify 53 * `*(__ERR)' and returns it from a containing function if it is unequal to 54 * `SOC_E_NONE'. 55 * 56 * ESTM() is intended for use in functions returning error codes directly to 57 * check calls to functions returning error codes indirectly, e.g.: 58 * 59 * err_code_t foo(...) // remaining arguments elided 60 * { 61 * uint8 rst; 62 * // ... 63 * ESTM(rst = rdc_core_s_rstb()); 64 * // ... 65 * return SOC_E_NONE; 66 * } 67 */ 68 69 #define ESTM(expr) \ 70 do { \ 71 int __err; \ 72 *(__ERR) = SOC_E_NONE; \ 73 (expr); \ 74 if (*(__ERR) != SOC_E_NONE) \ 75 return *(__ERR); \ 76 (void)__err; \ 77 } while (0) 78 79 80 /** 81 * Error-check a statement, defaulting when forwarding error codes forwarded. 82 * 83 * In a function taking an argument `int *err_code_p' in lieu of 84 * returning an error code directly, evaluates an expression (typically 85 * unterminated statement), stores its value into `*(__ERR)', combines this 86 * (bitwise inclusive ore) into `*(err_code_p)', and returns a default value 87 * if either `*(__ERR)' or `*(err_code_p)' is not `SOC_E_NONE'. 88 * 89 * EPSTM2() is intended for use in functions returning error codes indirectly 90 * to check calls to functions also returning error codes indirectly, e.g.: 91 * 92 * uint8 foo(int *err_code_p, ...) // remaining arguments elided 93 * { 94 * uint8 result; 95 * // ... 96 * EPSTM(result = rdc_core_s_rstb(), 0x1); 97 * // ... 98 * return result; 99 * } 100 */ 101 102 #define EPSTM2(expr, on_err) \ 103 do { \ 104 int __err; \ 105 *(__ERR) = SOC_E_NONE; \ 106 (expr); \ 107 *(err_code_p) |= *(__ERR); \ 108 if ((*(err_code_p ) != SOC_E_NONE) \ 109 || (*(__ERR) != SOC_E_NONE)) \ 110 return (on_err); \ 111 (void)__err; \ 112 } while (0) 113 114 115 /** 116 * Error-check a statement, defaulting to zero when forwarding error codes 117 * forwarded. 118 * 119 * Supplies a default value of zero to EPSTM2() to reduce clutter in the most 120 * common case. 121 * 122 * EPSTM() is intended for use in functions returning error codes indirectly 123 * to check calls to functions also returning error codes indirectly, e.g.: 124 * 125 * uint8 foo(int *err_code_p, ...) // remaining arguments elided 126 * { 127 * uint8 result; 128 * // ... 129 * EPSTM(result = rdc_core_s_rstb()); 130 * // ... 131 * return result; 132 * } 133 */ 134 135 #define EPSTM(expr) EPSTM2((expr), 0) 136 137 138 /** 139 * Error-check a function call, defaulting when forwarding error codes 140 * returned. 141 * 142 * In a function taking an argument `int *err_code_p' in lieu of 143 * returning an error code directly, evaluates an expression (typically 144 * function call), stores its value into `*(__ERR)', combines this (bitwise 145 * inclusive ore) into `*(err_code_p)', and returns a default value if either 146 * `*(__ERR)' or `*(err_code_p)' is not `SOC_E_NONE'. 147 * 148 * EPFUN2() is intended for use in functions returning error codes indirectly 149 * to check calls to functions returning error codes directly, e.g.: 150 * 151 * uint8 foo(int *err_code_p, ...) // remaining arguments elided 152 * { 153 * uint8 result = 0x0; 154 * // ... 155 * EPFUN2(wrc_core_s_rstb(0x0), 0x1); 156 * // ... 157 * return result; 158 * } 159 */ 160 161 #define EPFUN2(expr, on_err) \ 162 do { \ 163 int __err; \ 164 *(__ERR) = (expr); \ 165 *(err_code_p) |= *(__ERR); \ 166 if ((*(err_code_p) != SOC_E_NONE) \ 167 || (*(__ERR) != SOC_E_NONE)) \ 168 return (on_err); \ 169 (void)__err; \ 170 } while (0) 171 172 173 /** 174 * Error-check a function call, defaulting to zero when forwarding error codes 175 * returned. 176 * 177 * Supplies a default value of zero to EPFUN2() to reduce clutter in the most 178 * common case. 179 * 180 * EPFUN() is intended for use in functions returning error codes indirectly 181 * to check calls to functions returning error codes directly, e.g.: 182 * 183 * uint8 foo(int *err_code_p, ...) // remaining arguments elided 184 * { 185 * uint8 result; // determined below, detail elided 186 * // ... 187 * EPFUN(wrc_core_s_rstb(0x0)); 188 * // ... 189 * return result; 190 * } 191 */ 192 193 #define EPFUN(expr) EPFUN2((expr), 0) 194 195 /** 196 * Absolute value of an expression. 197 * 198 * @warning 199 * 200 * May evaluate the given expression twice. 201 */ 202 #define _abs(a) (((a) > 0) ? (a) : (-(a))) 203 204 /** SERDES_UC_DIAG_COMMANDS */ 205 #define CMD_UC_DIAG_DISABLE 3 206 #define CMD_UC_DIAG_PASSIVE 1 207 #define CMD_UC_DIAG_DENSITY 2 208 #define CMD_UC_DIAG_START_VSCAN_EYE 4 209 #define CMD_UC_DIAG_START_HSCAN_EYE 5 210 #define CMD_UC_DIAG_GET_EYE_SAMPLE 6 211 212 #define CMD_UC_DBG 4 213 #define CMD_UC_DBG_DIE_TEMP 0 214 #define CMD_DIAG_EN 5 215 #define CMD_READ_DIAG_DATA_WORD 18 216 #define CMD_UC_CTRL 1 217 #define CMD_UC_CTRL_STOP_GRACEFULLY 0 218 #define CMD_UC_CTRL_STOP_IMMEDIATE 1 219 #define CMD_UC_CTRL_RESUME 2 220 221 #define DSC_A_DSC_UC_CTRL 0xd03d 222 #define DSC_E_RX_PI_CNT_BIN_D 0xd075 223 #define DSC_E_RX_PI_CNT_BIN_P 0xd076 224 #define DSC_E_RX_PI_CNT_BIN_L 0xd077 225 #define DSC_E_RX_PI_CNT_BIN_PD 0xd070 226 #define DSC_E_RX_PI_CNT_BIN_LD 0xd071 227 #define TLB_RX_PRBS_CHK_ERR_CNT_MSB_STATUS 0xD16A 228 #define TLB_RX_PRBS_CHK_ERR_CNT_LSB_STATUS 0xD16B 229 230 #define CMD_EVENT_LOG_READ 15 231 #define CMD_EVENT_LOG_READ_START 0 232 #define CMD_EVENT_LOG_READ_NEXT 1 233 #define CMD_EVENT_LOG_READ_DONE 2 234 235 /************************************************************************//** 236 * Direct RAM Access 237 * memory-mapped access to the firmware control/status RAM variables. 238 *//*************************************************************************/ 239 #define CORE_VAR_RAM_BASE (0x400) 240 #define LANE_VAR_RAM_BASE (0x420) 241 #define LANE_VAR_RAM_SIZE (0x130) 242 #define CORE_VAR_RAM_SIZE (0x40) 243 244 /* PLL Lock and change Status Register define */ 245 #define PLL_STATUS_ADDR 0xD148 246 /* PMD Lock and change Status Register define */ 247 #define PMD_LOCK_STATUS_ADDR 0xD16C 248 /* Sigdet and change Status Register define */ 249 #define SIGDET_STATUS_ADDR 0xD0E8 250 251 extern int bcm_pe_pmd_uc_cmd (phy_ctrl_t *pa, uint8 cmd, uint8 supp_info, uint32 timeout_ms); 252 extern int bcm_pe_pmd_uc_diag_cmd (phy_ctrl_t *pa, uint8 control, uint32 timeout_ms); 253 extern int bcm_pe_pmd_uc_control (phy_ctrl_t *pa, uint8 control, uint32 timeout_ms); 254 extern uint16 _bcm_pe_pmd_rde_field (phy_ctrl_t *pa, uint16 addr, uint8 shift_left, uint8 shift_right, int *err_code_p); 255 extern int16 _bcm_pe_pmd_rde_field_signed (phy_ctrl_t *pa, uint16 addr, uint8 shift_left, uint8 shift_right, int *err_code_p); 256 extern uint8 _bcm_pe_pmd_rde_field_byte (phy_ctrl_t *pa, uint16 addr, uint8 shift_left, uint8 shift_right, int *err_code_p); 257 extern int8 _bcm_pe_pmd_rde_field_signed_byte (phy_ctrl_t *pa, uint16 addr, uint8 shift_left, uint8 shift_right, int *err_code_p); 258 extern int _bcm_pe_pmd_mwr_reg_byte (phy_ctrl_t *pa, uint16 addr, uint16 mask, uint8 lsb, uint8 val); 259 extern uint16 _bcm_pe_pmd_rde_reg (phy_ctrl_t *pa, uint16 addr, int *err_code_p); 260 extern int bcm_pe_pmd_rdt_reg(phy_ctrl_t *pa, uint16 address, uint16 *val); 261 extern uint16 bcm_pe_rdwl_uc_var (phy_ctrl_t *pa, int *err_code_p, uint16 addr); 262 extern int16 bcm_pe_rdwls_uc_var (phy_ctrl_t *pa, int *err_code_p, uint16 addr); 263 extern uint8 bcm_pe_rdbl_uc_var (phy_ctrl_t *pa, int *err_code_p, uint16 addr); 264 extern int8 bcm_pe_rdbls_uc_var (phy_ctrl_t *pa, int *err_code_p, uint16 addr); 265 extern uint8 bcm_pe_rdbc_uc_var (phy_ctrl_t *pa, int *err_code_p, uint8 addr); 266 extern uint16 bcm_pe_rdwc_uc_var (phy_ctrl_t *pa, int *err_code_p, uint8 addr); 267 extern int _bcm_pe_pll_lock_status (phy_ctrl_t *pa, uint8 *pll_lock, uint8 *pll_lock_chg); 268 extern int _bcm_pe_pmd_lock_status (phy_ctrl_t *pa, uint8 *pmd_lock, uint8 *pmd_lock_chg); 269 extern int bcm_pe_prbs_chk_lock_state (phy_ctrl_t *pa, uint8 *chk_lock); 270 extern int bcm_pe_prbs_err_count_ll (phy_ctrl_t *pa, uint32 *prbs_err_cnt); 271 extern int bcm_pe_set_pll(uint8 pll_index); 272 extern uint8 bcm_pe_get_pll(void); 273 extern uint8 bcm_pe_get_core(void); 274 extern int bcm_pe_stop_rx_adaptation (phy_ctrl_t *pa, uint8 enable); 275 extern uint8 bcm_pe_tsc_get_lane(phy_ctrl_t *pa); 276 277 #endif /* _TSC_FUNCTIONS_H_ */