cmd_cint.c (10382B)
1 /* 2 * 3 * 4 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 5 * 6 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 7 */ 8 #include <sdk_config.h> 9 #include <shared/bsl.h> 10 int cmd_cint_c_not_empty; 11 12 #ifdef INCLUDE_LIB_CINT 13 14 15 #if !defined(__KERNEL__) 16 #include <stdlib.h> 17 #endif 18 19 #include "cint_sdk_atomics.h" 20 #include <cint_interpreter.h> 21 #include <appl/diag/autocli.h> 22 #include <appl/diag/cmd_cint.h> 23 #include <sal/core/alloc.h> 24 #include <sal/core/libc.h> 25 #include <sal/appl/io.h> 26 #include <appl/diag/shell.h> 27 #include <appl/diag/parse.h> 28 #include <cint_porting.h> 29 #include <cint_logger.h> 30 #include <soc/defs.h> 31 #ifdef INCLUDE_LIB_C_UNIT 32 #include <appl/c_unit/c_unit_framework.h> 33 #include "c_unit_data.h" 34 #endif 35 36 char cmd_cint_usage[] = "cint usage goes here\n"; 37 38 /* bcm_cint_data.c */ 39 extern cint_data_t bcm_cint_data; 40 /* imacsec_cint_t */ 41 #if defined(INCLUDE_PLP_IMACSEC) 42 extern cint_data_t phymod_imacsec_apis_cint_data; 43 #endif 44 /* sal_cint_data.c */ 45 extern cint_data_t sal_cint_data; 46 47 /* properties.c */ 48 extern void soc_cint_property_vars_init(void); 49 50 51 /* soc_cint_data.c */ 52 extern cint_data_t soc_cint_data; 53 54 #ifdef BCM_DFE_SUPPORT 55 extern cint_data_t dfe_cint_data; 56 extern cint_data_t dfe_defines_cint_data; 57 extern cint_data_t dfe_implementation_defines_cint_data; 58 59 #endif 60 61 extern cint_data_t diag_cint_data; 62 #if defined(_ARAD_TEST_SWDB) && defined(BCM_PETRA_SUPPORT) 63 extern cint_data_t arad_mcdb_cint_data; 64 #endif 65 66 #ifdef BCM_PETRA_SUPPORT 67 extern cint_data_t dpp_cint_data; 68 extern cint_data_t dpp_defines_cint_data; 69 extern cint_data_t dpp_implementation_defines_cint_data; 70 extern cint_data_t dpp_signals_cint_data; 71 #endif 72 73 #if defined(BCM_DFE_SUPPORT) || defined(BCM_PETRA_SUPPORT) 74 extern cint_data_t source_routed_cint_data; 75 #endif 76 #ifdef BCM_SAND_SUPPORT 77 extern cint_data_t dpp_diag_cint_data; 78 #endif 79 80 #ifdef BCM_DNX_SUPPORT 81 extern cint_data_t dnx_defines_cint_data; 82 extern cint_data_t dnx_implementation_defines_cint_data; 83 extern cint_data_t dpp_signals_cint_data; 84 extern cint_data_t dnx_cint_dbal; 85 #if defined(INCLUDE_KBP) 86 extern cint_data_t dnx_cint_kbp; 87 #endif 88 extern cint_data_t dnx_cint_alloc; 89 extern cint_data_t dnx_cint_applets; 90 extern cint_data_t pemladrv_cint_data; 91 #if defined(ADAPTER_SERVER_MODE) 92 extern cint_data_t adapter_cint_data; 93 #endif 94 #endif 95 96 #if defined(BCM_DNX_SUPPORT) || defined(BCM_DNXF_SUPPORT) 97 extern cint_data_t dnxc_cint_data; 98 #endif 99 100 #if defined(BCM_DNX_SUPPORT) 101 extern cint_data_t dnx_cint_data; 102 #endif 103 104 #ifdef BCM_DNXF_SUPPORT 105 extern cint_data_t dnxf_cint_data; 106 #endif 107 108 #if defined(PHYMOD_SUPPORT) 109 extern cint_data_t phymod_cint_data; 110 extern cint_data_t phymod_diagnostics_cint_data; 111 extern cint_data_t phymod_access_cint_data; 112 #endif 113 114 #if defined(FALCON_PHYMOD_TIER1_SUPPORT) 115 extern cint_data_t falcon_phymod_tier1_cint_data; 116 #endif 117 #if defined(EAGLE_PHYMOD_TIER1_SUPPORT) 118 extern cint_data_t eagle_phymod_tier1_cint_data; 119 #endif 120 #if defined(BLACKHAWK_PHYMOD_TIER1_SUPPORT) 121 extern cint_data_t blackhawk_phymod_tier1_cint_data; 122 #endif 123 124 #if defined (PHYMOD_EPDM_APIS_SUPPORT) 125 extern cint_data_t phymod_epdm_apis_cint_data; 126 #endif 127 128 129 #if defined(PORTMOD_SUPPORT) 130 extern cint_data_t portmod_cint_data; 131 #endif 132 133 #if defined(CPRIMOD_SUPPORT) 134 extern cint_data_t cprimod_cint_data; 135 #endif 136 137 138 #if defined(CPRI_DIAG_SUPPORT) 139 extern cint_data_t cpri_diag_cint_data; 140 #endif 141 142 /* Custom functions */ 143 int bshell(int unit, char* cmd) 144 { 145 return sh_process_command(unit, cmd); 146 } 147 CINT_FWRAPPER_CREATE_RP2(int,int,0,0, 148 bshell, 149 int,int,unit,0,0, 150 char*,char,cmd,1,0); 151 152 static int 153 rcload_file_noargs(int unit, char* file) { 154 return sh_rcload_file( 155 unit, 156 NULL, 157 file, 158 0); 159 } 160 161 CINT_FWRAPPER_CREATE_RP2(int,int,0,0, 162 rcload_file_noargs, 163 int,int,unit,0,0, 164 char*,char,cmd,1,0); 165 166 static cint_function_t __cint_cmd_functions[] = 167 { 168 CINT_FWRAPPER_ENTRY(bshell), 169 CINT_FWRAPPER_ENTRY(rcload_file_noargs), 170 CINT_ENTRY_LAST 171 }; 172 173 static cint_constants_t __cint_cmd_constants[] = 174 { 175 { "TRUE", 1 }, 176 { "FALSE", 0 }, 177 { NULL } 178 }; 179 180 cint_data_t cmd_cint_data = 181 { 182 NULL, 183 __cint_cmd_functions, 184 NULL, 185 NULL, 186 NULL, 187 __cint_cmd_constants, 188 NULL 189 }; 190 191 192 static int 193 __cint_sdk_data_init(void) 194 { 195 cint_interpreter_add_atomics(cint_sdk_atomics); 196 cint_interpreter_add_data(&cint_sdk_data, NULL); 197 #ifdef INCLUDE_LIB_C_UNIT 198 cint_interpreter_add_data(&c_unit_data, NULL); 199 #endif 200 cint_interpreter_add_data(&bcm_cint_data, NULL); 201 #if defined(INCLUDE_PLP_IMACSEC) 202 cint_interpreter_add_data(&phymod_imacsec_apis_cint_data, NULL); 203 #endif 204 cint_interpreter_add_data(&sal_cint_data, NULL); 205 cint_interpreter_add_data(&soc_cint_data, NULL); 206 cint_interpreter_add_data(&diag_cint_data, NULL); 207 #if defined(BCM_DFE_SUPPORT) || defined (BCM_PETRA_SUPPORT) 208 cint_interpreter_add_data(&source_routed_cint_data, NULL); 209 #endif 210 #ifdef BCM_SAND_SUPPORT 211 cint_interpreter_add_data(&dpp_diag_cint_data, NULL); 212 #endif 213 #if defined(_ARAD_TEST_SWDB) && defined(BCM_PETRA_SUPPORT) 214 cint_interpreter_add_data(&arad_mcdb_cint_data, NULL); 215 #endif 216 #ifdef BCM_PETRA_SUPPORT 217 cint_interpreter_add_data(&dpp_cint_data, NULL); 218 cint_interpreter_add_data(&dpp_defines_cint_data, NULL); 219 cint_interpreter_add_data(&dpp_implementation_defines_cint_data, NULL); 220 cint_interpreter_add_data(&dpp_signals_cint_data, NULL); 221 #endif 222 #ifdef BCM_DFE_SUPPORT 223 cint_interpreter_add_data(&dfe_cint_data, NULL); 224 cint_interpreter_add_data(&dfe_defines_cint_data, NULL); 225 cint_interpreter_add_data(&dfe_implementation_defines_cint_data, NULL); 226 #endif 227 #ifdef BCM_DNX_SUPPORT 228 cint_interpreter_add_data(&dpp_signals_cint_data, NULL); 229 cint_interpreter_add_data(&pemladrv_cint_data, NULL); 230 cint_interpreter_add_data(&dnx_cint_dbal, NULL); 231 #if defined(INCLUDE_KBP) 232 cint_interpreter_add_data(&dnx_cint_kbp, NULL); 233 #endif 234 cint_interpreter_add_data(&dnx_cint_applets, NULL); 235 cint_interpreter_add_data(&dnx_cint_alloc, NULL); 236 #if defined(ADAPTER_SERVER_MODE) 237 cint_interpreter_add_data(&adapter_cint_data, NULL); 238 #endif 239 #endif 240 241 #if defined(BCM_DNX_SUPPORT) || defined(BCM_DNXF_SUPPORT) 242 cint_interpreter_add_data(&dnxc_cint_data, NULL); 243 #endif 244 245 #if defined(BCM_DNX_SUPPORT) 246 cint_interpreter_add_data(&dnx_cint_data, NULL); 247 #endif 248 249 #ifdef BCM_DNXF_SUPPORT 250 cint_interpreter_add_data(&dnxf_cint_data, NULL); 251 #endif 252 253 #if defined(PHYMOD_SUPPORT) 254 cint_interpreter_add_data(&phymod_cint_data, NULL); 255 cint_interpreter_add_data(&phymod_diagnostics_cint_data, NULL); 256 cint_interpreter_add_data(&phymod_access_cint_data, NULL); 257 #endif 258 #if defined(FALCON_PHYMOD_TIER1_SUPPORT) 259 cint_interpreter_add_data(&falcon_phymod_tier1_cint_data, NULL); 260 #endif 261 #if defined(EAGLE_PHYMOD_TIER1_SUPPORT) 262 cint_interpreter_add_data(&eagle_phymod_tier1_cint_data, NULL); 263 #endif 264 #if defined(BLACKHAWK_PHYMOD_TIER1_SUPPORT) 265 cint_interpreter_add_data(&blackhawk_phymod_tier1_cint_data, NULL); 266 #endif 267 #if defined (PHYMOD_EPDM_APIS_SUPPORT) 268 cint_interpreter_add_data(&phymod_epdm_apis_cint_data, NULL); 269 #endif 270 #if defined(PORTMOD_SUPPORT) 271 cint_interpreter_add_data(&portmod_cint_data, NULL); 272 #endif 273 #if defined(CPRIMOD_SUPPORT) 274 cint_interpreter_add_data(&cprimod_cint_data, NULL); 275 #endif 276 277 #if defined(CPRI_DIAG_SUPPORT) 278 cint_interpreter_add_data(&cpri_diag_cint_data, NULL); 279 #endif 280 281 282 cint_interpreter_add_data(&cmd_cint_data, NULL); 283 soc_cint_property_vars_init(); 284 return 0; 285 } 286 287 static int 288 __cint_event_handler(void* cookie, cint_interpreter_event_t event) 289 { 290 switch(event) 291 { 292 case cintEventReset: 293 { 294 /* 295 * Interpreter has reset. Re-register our data 296 */ 297 __cint_sdk_data_init(); 298 break; 299 } 300 default: 301 { 302 /* Nothing */ 303 break; 304 } 305 } 306 return 0; 307 } 308 309 static void 310 __cint_init_path(void) 311 { 312 char *path; 313 #if !defined(__KERNEL__) 314 path = getenv("CINT_INCLUDE_PATH"); 315 #else 316 path = NULL; 317 #endif 318 319 if (path) { 320 cint_interpreter_include_set(path); 321 } 322 } 323 324 /* fatal error interface to lexer - abort to diag shell */ 325 void cmd_cint_fatal_error(char *msg) 326 { 327 sal_printf("%s",msg); 328 sh_ctrl_c_take(); 329 } 330 331 int 332 cmd_cint_initialize(void) 333 { 334 static int init = 0; 335 if(init == 0) { 336 cint_interpreter_init(); 337 cint_interpreter_event_register(__cint_event_handler, NULL); 338 __cint_init_path(); 339 __cint_sdk_data_init(); 340 #ifdef INCLUDE_LIB_C_UNIT 341 c_unit_initialize(c_unit_context_set); 342 #endif 343 #if CINT_CONFIG_INCLUDE_CINT_LOGGER == 1 344 cint_logger_cint_init(); 345 #endif 346 init = 1; 347 } 348 return 0; 349 } 350 351 #define CMD_CINT_ARG_MAX 16 352 353 cmd_result_t 354 cmd_cint(int unit, args_t* a) 355 { 356 char* s; 357 int cmp; 358 int argc = 0; 359 char* argv[CMD_CINT_ARG_MAX]; 360 361 cmd_cint_initialize(); 362 363 s = ARG_CUR(a); 364 if(s) { 365 cmp = sal_strcmp(s, "allow_file_info"); 366 if(!cmp) { 367 argv[argc] = ARG_GET(a); 368 argc++; 369 } 370 } 371 372 if(ARG_CUR(a)) { 373 /* Load file */ 374 FILE* fp; 375 s = ARG_GET(a); 376 377 if((fp = sal_fopen(s, "r")) != NULL) { 378 379 sal_memset(&argv[argc], 0, 380 (sizeof(argv)-(argc*sizeof(char *)))); 381 while( (s = ARG_GET(a)) ) { 382 if (argc < CMD_CINT_ARG_MAX) { 383 argv[argc] = s; 384 } 385 argc++; 386 } 387 388 if ( argc <= CMD_CINT_ARG_MAX ) { 389 cint_interpreter_parse(fp, NULL, argc, argv); 390 } 391 else { 392 cli_out("error: cannot pass more than 16 " 393 "arguments, excluding the filename.\n"); 394 } 395 sal_fclose(fp); 396 } 397 else { 398 cli_out("error: could not open file '%s'\n", s); 399 } 400 } 401 else { 402 cli_out("Entering C Interpreter. Type 'exit;' to quit.\n\n"); 403 cint_interpreter_parse(NULL, "cint> ", argc, argv); 404 } 405 return 0; 406 } 407 408 409 #endif /* INCLUDE_LIB_CINT */