dnxcmn.h (12583B)
1 /** \file dnxcmn.h 2 * 3 * Common Utils for dnx only 4 */ 5 /* 6 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 7 * 8 * Copyright 2007-2020 Broadcom Inc. All rights reserved. 9 */ 10 #ifndef DNXCMN_H_INCLUDED 11 /* 12 * { 13 */ 14 #define DNXCMN_H_INCLUDED 15 16 #ifndef BCM_DNX_SUPPORT 17 #error "This file is for use by DNX (JR2) family only!" 18 #endif 19 /* 20 * Includes 21 * { 22 */ 23 #include <soc/dnx/dnx_data/auto_generated/dnx_data_device.h> 24 #include <soc/dnx/dbal/auto_generated/dbal_defines_fields.h> 25 #include <soc/dnx/dbal/auto_generated/dbal_defines_tables.h> 26 /* 27 * } 28 */ 29 30 /* 31 * MACROs 32 * { 33 */ 34 /** 35 * \brief - iterate over the relevant cores 36 * if core_id is BCM_CORE_ALL will iterate over all supported cores. 37 * Otherwise the iteration will be over the given core. 38 */ 39 #define DNXCMN_CORES_ITER(unit, core_id, core_index) \ 40 for(core_index = ((core_id == BCM_CORE_ALL) ? 0 : core_id);\ 41 core_index < ((core_id == BCM_CORE_ALL) ? dnx_data_device.general.nof_cores_get(unit) : (core_id + 1));\ 42 core_index++) 43 44 /** 45 * \brief - convert core id to index 46 * if core_id is BCM_CORE_ALL return 0 assuming cores are symmetrical. 47 */ 48 #define DNXCMN_CORE_ID2INDEX(unit, core_id) ((core_id == BCM_CORE_ALL) ? 0 : core_id) 49 50 /** 51 * \brief - validate core is legal 52 * if allow_all == true - validate that core is either valid core_id or BCM_CORE_ALL 53 * Otherwise - validate that core is valid core_id 54 */ 55 #define DNXCMN_CORE_VALIDATE(unit, core, allow_all) \ 56 if ((core >= dnx_data_device.general.nof_cores_get(unit) || (core < 0)) && (!(core == _SHR_CORE_ALL && allow_all)))\ 57 {\ 58 SHR_ERR_EXIT(_SHR_E_PARAM, "Invalid Core %d\n", core);\ 59 } 60 61 /** 62 * \brief - indicates whether chip has more than one core or not. 63 */ 64 #define DNXCMN_CHIP_IS_MULTI_CORE(unit) \ 65 (dnx_data_device.general.nof_cores_get(unit) > 1) 66 67 /** 68 * Get core clock frequency (supported units are Hz, KHz and MHz) 69 */ 70 #define DNXCMN_CORE_CLOCK_HZ_GET(unit) (dnx_data_device.general.core_clock_khz_get(unit) * 1000) 71 #define DNXCMN_CORE_CLOCK_KHZ_GET(unit) (dnx_data_device.general.core_clock_khz_get(unit)) 72 /* 73 * } 74 */ 75 76 /* 77 * TYPEDEFs 78 * { 79 */ 80 81 #define DNXCMN_TIMEOUT (20*1000) 82 #define DNXCMN_MIN_POLLS (100) 83 84 /* 85 * } 86 */ 87 88 /* 89 * TYPEDEFs 90 * { 91 */ 92 /** 93 * \brief - time units 94 */ 95 typedef enum 96 { 97 /** 98 * Invalid time unit 99 */ 100 DNXCMN_TIME_UNIT_INVALID = -1, 101 /** 102 * Second 103 */ 104 DNXCMN_TIME_UNIT_SEC = 0, 105 /** 106 * Mili Second 107 */ 108 DNXCMN_TIME_UNIT_MILISEC = 1, 109 /** 110 * Micro Second 111 */ 112 DNXCMN_TIME_UNIT_USEC = 2, 113 114 /** 115 * Nano Second 116 */ 117 DNXCMN_TIME_UNIT_NSEC = 3 118 } dnxcmn_time_unit_e; 119 120 /** 121 * Represet time which composed from amount of time and time units 122 */ 123 typedef struct 124 { 125 dnxcmn_time_unit_e time_units; 126 uint64 time; 127 } dnxcmn_time_t; 128 /** 129 * Enumeration of field types acceptable by dnx_dbal_gen_set/get 130 * See: 131 * dnx_dbal_gen_set() 132 * dnx_dbal_gen_get() 133 */ 134 typedef enum 135 { 136 FIRST_DNX_GEN_DBAL_FIELD = 0, 137 /** 138 * Field is of type uint32. 139 */ 140 GEN_DBAL_FIELD32 = FIRST_DNX_GEN_DBAL_FIELD, 141 /** 142 * Field is of type uint64. 143 */ 144 GEN_DBAL_FIELD64, 145 /** 146 * Field is an array. All array elements are of type uint32. 147 */ 148 GEN_DBAL_ARR32, 149 /** 150 * Field is a range. Only relevant for 'key' and only for 'set' operation. 151 */ 152 GEN_DBAL_RANGE32, 153 /** 154 * Field is the last, following all other fields and their parameters. 155 * Used for verification. 156 */ 157 GEN_DBAL_FIELD_LAST_MARK, 158 NUM_DNX_GEN_DBAL_FIELD 159 } dnx_gen_dbal_field_e; 160 /* 161 * } 162 */ 163 /* 164 * DBAL utils functions 165 * { 166 */ 167 168 /** 169 * \brief 170 * Carry out DBAL access (of 'get') on one specified table 171 * with one or more keys and with one or more fields. 172 * All fields must be of a type specified in 'dnx_gen_dbal_field_e'. 173 * In most cases, they would be of type 'uint32' for input and 174 * 'uint32 *' for output 175 * \param [in] unit - 176 * uint32. Identifier of HW platform. 177 * \param [in] dbal_table_id - 178 * dbal_tables_e. Identifier of the DBAL table to write to. 179 * For example: DBAL_TABLE_EGQ_SHAPER_GLOBAL_CONFIGURATION 180 * \param [in] num_keys - 181 * uint32. Number of keys required for access of this table. The code, 182 * below, will expect 'num_keys' triplets at the beginning of the variables 183 * list (va_arg_params) as follows: (Field Type, Key Id, Key Value). 184 * For example: 185 * GEN_DBAL_FIELD32, DBAL_FIELD_CORE_ID, core 186 * Note that all values are expected to be specified in in 'dnx_gen_dbal_field_e'. 187 * \param [in] num_fields - 188 * uint32. Number of fields required for access of this table. The code, 189 * below, will expect 'num_fields' quartet, following the 'num_keys' triplets on 190 * variables list (va_arg_params) as follows: 191 * (Field Type, Field Id, Field Instance, Pointer to Field Value). 192 * For example: 193 * GEN_DBAL_FIELD32, DBAL_FIELD_FQP_CALENDAR_SET_SEL, INST_SINGLE, ¤t_cal 194 * Notes: 195 * * For 'get' operation, all field values are expected be pointers to types 196 * specified in in 'dnx_gen_dbal_field_e'. 197 * In most cases, the field type would be 'uint32 *' 198 * * In most cases, the value of 'Field Instance' would be 'INST_SINGLE'. However, 199 * when the field is actually an array of fields, with index, this value would be 200 * the index. 201 * \return 202 * \retval Zero - On success 203 * \retval Error - Identifier as per shr_error_e 204 * \remark 205 * * The last field identifier, following the ekys and the variables, MUST be GEN_DBAL_FIELD_LAST_MARK. 206 * This is a verification tool. 207 * * In parameter 'va_arg_params' (represented by '...') - 208 * List of triplets followed by quartets as described above. Sum length of both lists 209 * is expected to be 210 * 'num_keys' + 'num_fields'. 211 * * If field type is GEN_DBAL_ARR32, then the 'field value' is expected to be 'uint32 *' 212 * which is a pointer to the array, in memory, which is to contain data as read from HW. 213 * User is expected to fill that area with '0' before calling this procedure. 214 * \see 215 * * dnx_egr_recycle_bandwidth_get 216 */ 217 shr_error_e dnx_dbal_gen_get( 218 uint32 unit, 219 dbal_tables_e dbal_table_id, 220 uint32 num_keys, 221 uint32 num_fields, 222 ...); 223 /** 224 * \brief 225 * Carry out DBAL access (of 'set') on one specified table 226 * with one or more keys and with one or more fields. 227 * All fields must be of a type specified in 'dnx_gen_dbal_field_e'. 228 * In most cases, they would be of type 'uint32' 229 * \param [in] unit - 230 * uint32. Identifier of HW platform. 231 * \param [in] dbal_table_id - 232 * dbal_tables_e. Identifier of the DBAL table to write to. 233 * For example: DBAL_TABLE_EGQ_SHAPER_GLOBAL_CONFIGURATION 234 * \param [in] num_keys - 235 * uint32. Number of keys required for access of this table. The code, 236 * below, will expect 'num_keys' triplets at the beginning of the variables 237 * list (va_arg_params) as follows: (Field Type, Key Id, Key Value). 238 * For example: 239 * GEN_DBAL_FIELD32, DBAL_FIELD_CORE_ID, core 240 * Note that all values are expected to be specified in in 'dnx_gen_dbal_field_e'. 241 * \param [in] num_fields - 242 * uint32. Number of fields required for access of this table. The code, 243 * below, will expect 'num_fields' quartet, following the 'num_keys' triplets on 244 * variables list (va_arg_params) as follows (but see notes below): 245 * (Field Type, Field Id, Field Instance, Field Value). 246 * For example: 247 * GEN_DBAL_FIELD32, DBAL_FIELD_FQP_CALENDAR_SET_SEL, INST_SINGLE, current_cal 248 * Notes: 249 * * For 'set' operation, all values are expected be specified in in 'dnx_gen_dbal_field_e'. 250 * In most cases, the type would be 'uint32' 251 * * In most cases, the value of 'Field Instance' would be 'INST_SINGLE'. However, 252 * when the field is actually an array of fields, with index, this value would be 253 * the index. 254 * * For 'set' operation, on the 'key' section, if the key is a 'range' then the 255 * number of following parameters is '4' (instead of the standard triplet) and the last 256 * two are the range. 257 * \return 258 * \retval Zero - On success 259 * \retval Error - Identifier as per shr_error_e 260 * \remark 261 * * The last field identifier, following the ekys and the variables, MUST be GEN_DBAL_FIELD_LAST_MARK. 262 * This is a verification tool. 263 * * In parameter 'va_arg_params' (represented by '...') - 264 * List of triplets followed by quartets as described above. Sum length of both lists 265 * is expected to be 266 * 'num_keys' + 'num_fields'. 267 * * If field type is GEN_DBAL_ARR32, then the 'field value' is expected to be 'uint32 *' 268 * which is a pointer to the array, in memory, which is to be written into HW. 269 * \see 270 * * dnx_egr_q_nif_cal_set 271 */ 272 shr_error_e dnx_dbal_gen_set( 273 uint32 unit, 274 dbal_tables_e dbal_table_id, 275 uint32 num_keys, 276 uint32 num_fields, 277 ...); 278 /* 279 * } 280 */ 281 282 /* 283 * TIME Functions 284 * { 285 */ 286 /** 287 * \brief - Convert time to required time_units 288 * The result will be round off 289 * 290 * \par DIRECT_INPUT: 291 * \param [in] unit - unit #. 292 * \param [in] time_src - time to convert 293 * \param [in] required_time_units - required time units 294 * \param [in] time_dest - destination of the converted tiem 295 * \par INDIRECT INPUT: 296 * * None 297 */ 298 shr_error_e dnxcmn_time_units_convert( 299 int unit, 300 dnxcmn_time_t * time_src, 301 dnxcmn_time_unit_e required_time_units, 302 dnxcmn_time_t * time_dest); 303 304 /** 305 * \brief - Convert device clock cycles to time (according to required time units) 306 * The result will be round down 307 * 308 * \par DIRECT_INPUT: 309 * \param [in] unit - unit #. 310 * \param [in] nof_clock_cycles - number of clock cycles to convert to time 311 * \param [in] required_time_unit - required time units 312 * \param [in] time - pointer to converted time (output) 313 * \par INDIRECT INPUT: 314 * * dnx_data_device (to get the core clock) 315 */ 316 shr_error_e dnxcmn_clock_cycles_to_time_get( 317 int unit, 318 uint32 nof_clock_cycles, 319 dnxcmn_time_unit_e required_time_unit, 320 dnxcmn_time_t * time); 321 322 /** 323 * \brief - Convert system reference clock cycles to time (according to required time units) 324 * The result will be round down 325 * 326 * \par DIRECT_INPUT: 327 * \param [in] unit - unit #. 328 * \param [in] nof_clock_cycles - number of clock cycles to convert to time 329 * \param [in] required_time_unit - required time units 330 * \param [in] time - pointer to converted time (output) 331 * \par INDIRECT INPUT: 332 * * dnx_data_device (to get the core clock) 333 */ 334 shr_error_e dnxcmn_system_ref_clock_cycles_to_time_get( 335 int unit, 336 uint32 nof_clock_cycles, 337 dnxcmn_time_unit_e required_time_unit, 338 dnxcmn_time_t * time); 339 340 /** 341 * \brief - Convert time to device clock cycles (according to specified time units) 342 * 343 * \par DIRECT_INPUT: 344 * \param [in] unit - unit #. 345 * \param [in] time - time to convert to clock cycles 346 * \param [in] nof_clock_cycles - pointer to converted number of clock cycles (output) 347 * \par INDIRECT INPUT: 348 * * dnx_data_device (to get the core clock) 349 */ 350 shr_error_e dnxcmn_time_to_clock_cycles_get( 351 int unit, 352 dnxcmn_time_t * time, 353 uint32 *nof_clock_cycles); 354 355 /** 356 * \brief - Convert time to system reference clock cycles (according to specified time units) 357 * 358 * \par DIRECT_INPUT: 359 * \param [in] unit - unit #. 360 * \param [in] time - time to convert to clock cycles 361 * \param [in] nof_clock_cycles - pointer to converted number of clock cycles (output) 362 * \par INDIRECT INPUT: 363 * * dnx_data_device (to get the core clock) 364 */ 365 shr_error_e dnxcmn_time_to_system_ref_clock_cycles_get( 366 int unit, 367 dnxcmn_time_t * time, 368 uint32 *nof_clock_cycles); 369 370 /** 371 * \brief - Doing polling till the result matches the expected, 372 * or we reach the time out 373 * 374 * \par DIRECT_INPUT: 375 * \param [in] unit - unit #. 376 * \param [in] time_out - time out value, maximal time for 377 * polling 378 * \param [in] min_polls - minimum polls 379 * \param [in] entry_handle_id - DBAL handle to the table, need to 380 * set Key field before passsing the handle 381 * \param [in] field - DBAL field name 382 * \param [in] expected_value - the expected value 383 */ 384 shr_error_e dnxcmn_polling( 385 int unit, 386 sal_usecs_t time_out, 387 int32 min_polls, 388 uint32 entry_handle_id, 389 dbal_fields_e field, 390 uint32 expected_value); 391 392 /* 393 * } 394 */ 395 #endif /* !DNXCMN_H_INCLUDED */