main.c (13495B)
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: main.c 8 * Purpose: PE Mode utility code 9 */ 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 #include <string.h> 14 #include <unistd.h> 15 #include "bcm_xmod_pe_api.h" 16 17 extern int bcm_xmod_debug_cmd(int unit, int module, int cmd, void *txbuf, int txlen, int *rsp, void *rxbuf, int rxlen); 18 extern int bcm_reset_cpu(int unit, int module); 19 #ifdef PEMODE_BCM_BUILD 20 extern FILE * sal_fopen(char *file, char *mode); 21 extern int sal_fclose(FILE *fp); 22 extern int sal_fread(void *buf, int size, int num, FILE *fp); 23 extern int sal_feof(FILE *fp); 24 extern int sal_fsize(FILE *fp); 25 extern void *sal_alloc(unsigned int sz, char *s); 26 extern void sal_free(void *addr); 27 char *flname = "BCM8806x_pe"; 28 #endif /* PEMODE_BCM_BUILD */ 29 int bcm_xmod_db_test(int unit, int module); 30 int bcm_xmod_db_lb(int unit, int module, int lb_port, int lb, int en); 31 int bcm_xmod_db_stats(int unit, int module, int pe_port); 32 int bcm_xmod_db_insert_tag(int unit, int module, int pe_port); 33 34 void 35 display_usage(void) { 36 printf( "Usage: pe_app <test>\n"); 37 printf( " 1 - FW download test\n"); 38 printf( " 2 - PE Init(mod[0/2], mode[1/2], 10g, ltup, tlpe0, ltpe1, ltpe2, ltpe3)\n"); 39 printf( " 3 - PE Port Status Get(mod[0/2])\n"); 40 printf( " 4 - PE Port Statistics Get(mod[0/2], clear)\n"); 41 printf( " 5 - PE FW Ver Get(mod[0/2])\n"); 42 printf( " 6 - PE Device Rev ID\n"); 43 printf( " 7 - PE Die Temp\n"); 44 printf( " 8 - XMOD Debug Test Cmd(mod[0/2])\n"); 45 printf( " 9 - XMOD Debug Loopback Cmd(mod[0/2], gport[0,4,5,6,7], lb, enable)\n"); 46 printf( " 10 - Resest CPUs\n"); 47 printf( " 11 - FW Print port stats(mod[0/2], gport[0,4,5,6,7])\n"); 48 printf( " 12 - FW Check insert tag(mod[0/2], port[0-3])\n"); 49 printf( " 13 - TSC Reg Access(port[0-3], sys[0/1], r/w[0/1], reg(32b), val(16b))\n"); 50 printf( " 14 - SBUS Access(port[0-3], reg(32b), cmd(32b), ring[0-2], val(32b))\n"); 51 printf( " 15 - AXI Reg Access(r/w[0/1], reg(32b), val(32b))\n"); 52 printf( " 16 - TOP Reg Access(r/w[0/1], reg(32b), val(32b))\n"); 53 printf( " 17 - Eyescan(port[0-3], sys[0/1])\n"); 54 printf( " 18 - DSC Dump(port[0-3], sys[0/1])\n"); 55 printf( " 19 - PRBS(port[0-3], sys[0/1], action[0-2], dir[0-2], poly[0-6], invert[0/1])\n"); 56 printf( "Parameters:\n"); 57 printf( " mod - Module: 0-First Module(default); 2-Second Module\n"); 58 printf( " mode - Mode: 1-1x4(50G up port, default); 2-1x2(25G up port)\n"); 59 printf( " 10g - Force up port link speed to 10G\n"); 60 printf( " ltup - Set Link Training on up port\n"); 61 printf( " ltpe(x) - Set Link Training on pe(x) port\n"); 62 printf( " port - 0-port0; 1-port1; 2-port2; 3-port3\n"); 63 printf( " gport - 0-LS port0; 4-SS port0; 5-SS port1; 6-SS port2; 7-SS port3\n"); 64 printf( " sys - System: 0-Line Side(up port); 1-System Side(server port)\n"); 65 printf( " r/w - 0-Read; 1-Write\n"); 66 printf( " ring - 0-MIG0; 1-MIG1; 2-TOP\n"); 67 printf( " action - 0-Set; 1-Get; 2-Clear\n"); 68 printf( " dir - 0-RX/TX; 1-RX; 2-TX\n"); 69 printf( " poly - 0-Poly7; 1-Poly9; 2-Poly11; 3-Poly15; 4-Poly23; 5-Poly31; 6-Poly58\n"); 70 printf( " invert - 0-NoInvert; 1-Invert\n"); 71 } 72 73 74 #ifdef INCLUDE_MAIN 75 int main() { 76 pe_app(0,0,0,0); 77 return 0; 78 } 79 #endif 80 81 82 int 83 pe_app(int testnum, int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7) 84 { 85 xmod_pe_config_t config; 86 xmod_pe_status_t status; 87 xmod_pe_port_stats_t stats; 88 xmod_pe_fw_ver_t ver; 89 int rc; 90 int unit, module, rev_id, temp; 91 int pe_port; 92 #ifdef PEMODE_BCM_BUILD 93 FILE *fp; 94 #endif /* PEMODE_BCM_BUILD */ 95 void *fl_data; 96 int fl_len; 97 int value; 98 uint32 value32; 99 uint32 data32[4]; 100 101 printf("pe_app() testnum: %d arg0 0x%x, arg1 0x%x, arg2 0x%x, arg3 0x%x, arg4 0x%x, arg5 0x%x, arg6 0x%x, arg7 0x%x\n", 102 testnum, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7); 103 104 bcm_initialize(); 105 unit = 0; 106 module = 0; 107 108 switch (testnum) { 109 case 1: 110 printf("test %d\n", testnum); 111 fl_data = NULL; 112 fl_len = 0; 113 #ifdef PEMODE_BCM_BUILD 114 if ((fp = sal_fopen(flname, "rb")) == NULL) { 115 printf("%s() cannot read file: %s\n", __FUNCTION__, flname); 116 break; 117 } 118 fl_len = sal_fsize(fp); 119 printf("%s() file %s length: %d\n", __FUNCTION__, flname, fl_len); 120 /* need to close/open to reset fp to beg file to read data*/ 121 sal_fclose(fp); 122 if ((fp = sal_fopen(flname, "rb")) == NULL) { 123 printf("%s() cannot read file: %s\n", __FUNCTION__, flname); 124 break; 125 } 126 fl_data = sal_alloc(fl_len, __FILE__); 127 if (fl_data == NULL) { 128 printf("%s() cannot alloc memory\n", __FUNCTION__); 129 sal_fclose(fp); 130 break; 131 } 132 rc = sal_fread(fl_data, 1, fl_len, fp); 133 sal_fclose(fp); 134 if (rc != fl_len) { 135 printf("%s() only read %d of %d bytes\n", __FUNCTION__, rc, fl_len); 136 break; 137 } 138 printf("%s() fl_data 0x%p fl_len %d\n", __FUNCTION__, fl_data, fl_len); 139 #endif /* PEMODE_BCM_BUILD */ 140 rc = bcm_firmware_download(unit, module, fl_data, fl_len); 141 if (rc!=0) { 142 printf("%s() bcm_firmware_download() error %d\n", __FUNCTION__, rc); 143 } 144 #ifdef PEMODE_BCM_BUILD 145 sal_free(fl_data); 146 #endif /* PEMODE_BCM_BUILD */ 147 break; 148 case 2: 149 printf("test %d\n", testnum); 150 if (arg0!=0 && arg0!=2) { 151 printf("%s() ERROR, invalid arg0 %d\n", __FUNCTION__, arg0); 152 break; 153 } 154 if (arg1!=1 && arg1!=2) { 155 arg1=XMOD_PE_MODE_4_PORTS; 156 } 157 module = arg0; 158 config.mode = arg1; 159 config.tag = XMOD_PE_TAG_BR; 160 config.pfc = 1; 161 config.line10g = arg2; 162 config.tagid[0] = 0x11; 163 config.tagid[1] = 0x22; 164 config.tagid[2] = 0x33; 165 config.tagid[3] = 0x44; 166 config.lt_up_port = arg3; 167 config.lt_pe_port[0] = arg4; 168 config.lt_pe_port[1] = arg5; 169 config.lt_pe_port[2] = arg6; 170 config.lt_pe_port[3] = arg7; 171 rc = bcm_xmod_pe_init(unit, module, &config); 172 if (rc!=0) { 173 printf("%s() bcm_xmod_pe_init() error %d\n", __FUNCTION__, rc); 174 } 175 break; 176 case 3: 177 printf("test %d\n", testnum); 178 if (arg0!=0 && arg0!=2) { 179 printf("%s() ERROR, invalid arg0 %d\n", __FUNCTION__, arg0); 180 break; 181 } 182 module = arg0; 183 rc = bcm_xmod_pe_status_get(unit, module, &status); 184 if (rc!=0) { 185 printf("%s() bcm_xmod_pe_status_get() error %d\n", __FUNCTION__, rc); 186 } 187 break; 188 case 4: 189 printf("test %d\n", testnum); 190 if (arg0!=0 && arg0!=2) { 191 printf("%s() ERROR, invalid arg0 %d\n", __FUNCTION__, arg0); 192 break; 193 } 194 module = arg0; 195 for (pe_port=0; pe_port<=4; pe_port++) { 196 printf("%s() calling bcm_xmod_pe_port_stats_get(%d)\n", __FUNCTION__, pe_port); 197 rc = bcm_xmod_pe_port_stats_get(unit, module, pe_port, &stats, arg1); 198 if (rc!=0) { 199 printf("%s() bcm_xmod_pe_port_stats_get() error %d\n", __FUNCTION__, rc); 200 } 201 } 202 break; 203 case 5: 204 printf("test %d\n", testnum); 205 if (arg0!=0 && arg0!=2) { 206 printf("%s() ERROR, invalid arg0 %d\n", __FUNCTION__, arg0); 207 break; 208 } 209 module = arg0; 210 rc = bcm_xmod_pe_fw_ver_get(unit, module, &ver); 211 if (rc!=0) { 212 printf("%s() bcm_xmod_pe_fw_ver_get() error %d\n", __FUNCTION__, rc); 213 } 214 break; 215 case 6: 216 printf("test %d\n", testnum); 217 rc = bcm_device_rev_id(unit, module, &rev_id); 218 if (rc!=0) { 219 printf("%s() bcm_device_rev_id() error %d\n", __FUNCTION__, rc); 220 } 221 printf("%s() rev_id %d\n", __FUNCTION__, rev_id); 222 break; 223 case 7: 224 printf("test %d\n", testnum); 225 rc = bcm_device_die_temp(unit, module, &temp); 226 if (rc!=0) { 227 printf("%s() bcm_device_die_temp() error %d\n", __FUNCTION__, rc); 228 } 229 printf("%s() die temp %d\n", __FUNCTION__, temp); 230 break; 231 case 8: 232 printf("test %d\n", testnum); 233 if (arg0!=0 && arg0!=2) { 234 printf("%s() ERROR, invalid arg0 %d\n", __FUNCTION__, arg0); 235 break; 236 } 237 module = arg0; 238 bcm_xmod_db_test(unit, module); 239 break; 240 case 9: 241 printf("test %d\n", testnum); 242 if (arg0!=0 && arg0!=2) { 243 printf("%s() ERROR, invalid arg0 %d\n", __FUNCTION__, arg0); 244 break; 245 } 246 module = arg0; 247 bcm_xmod_db_lb(unit, module, arg1, arg2, arg3); 248 break; 249 case 10: 250 printf("test %d\n", testnum); 251 bcm_reset_cpu(unit, module); 252 break; 253 case 11: 254 printf("test %d\n", testnum); 255 if (arg0!=0 && arg0!=2) { 256 printf("%s() ERROR, invalid arg0 %d\n", __FUNCTION__, arg0); 257 break; 258 } 259 module = arg0; 260 bcm_xmod_db_stats(unit, module, arg1); 261 break; 262 case 12: 263 printf("test %d\n", testnum); 264 if (arg0!=0 && arg0!=2) { 265 printf("%s() ERROR, invalid arg0 %d\n", __FUNCTION__, arg0); 266 break; 267 } 268 module = arg0; 269 bcm_xmod_db_insert_tag(unit, module, arg1); 270 break; 271 case 13: 272 printf("test %d\n", testnum); 273 value=arg4; 274 bcm_tsc_reg_access(unit, arg0, arg1, arg2, arg3, &value); 275 break; 276 case 14: 277 printf("test %d\n", testnum); 278 data32[0]=arg4; 279 data32[1]=arg5; 280 data32[2]=arg6; 281 data32[3]=arg7; 282 bcm_sbus_access(unit, arg0, arg1, arg2, arg3, data32); 283 break; 284 case 15: 285 printf("test %d\n", testnum); 286 value32=arg2; 287 bcm_axi_reg_access(unit, module, arg0, arg1, &value32); 288 break; 289 case 16: 290 printf("test %d\n", testnum); 291 value32=arg2; 292 bcm_top_reg_access(unit, module, arg0, arg1, &value32); 293 break; 294 case 17: 295 printf("test %d\n", testnum); 296 bcm_eyescan(unit, arg0, arg1); 297 break; 298 case 18: 299 printf("test %d\n", testnum); 300 bcm_dscdump(unit, arg0, arg1); 301 break; 302 case 19: 303 printf("test %d\n", testnum); 304 bcm_prbs(unit, arg0, arg1, arg2, arg3, arg4, arg5); 305 break; 306 default: 307 display_usage(); 308 break; 309 } 310 return 0; 311 } 312 313 314 int 315 bcm_xmod_db_test(int unit, int module) 316 { 317 int idx; 318 int rsp; 319 int rc; 320 uint8 txbuf[32]; 321 uint8 rxbuf[32]; 322 323 printf("%s() uint %d, module %d\n", __FUNCTION__, unit, module); 324 325 /* init buffers */ 326 for (idx=0; idx<32; idx++) { 327 txbuf[idx]=0x20+idx; 328 rxbuf[idx]=0; 329 } 330 331 rc = bcm_xmod_debug_cmd(unit, module, 0, (void*)txbuf, 32, &rsp, (void*)rxbuf, 32); 332 if (rc) { 333 printf("ERROR %d\n", rc); 334 } else { 335 printf("rsp (%d): RX DATA:", rsp); 336 for (idx=0; idx<32; idx++) { 337 printf("%02x ", rxbuf[idx]); 338 } 339 printf("\n"); 340 } 341 342 return rc; 343 } 344 345 346 int 347 bcm_xmod_db_lb(int unit, int module, int lb_port, int lb, int en) 348 { 349 int rsp; 350 int rc; 351 uint8 txbuf[32]; 352 353 printf("%s() uint %d, module %d\n", __FUNCTION__, unit, module); 354 355 /* init buffers */ 356 txbuf[0]=lb_port; /* port */ 357 txbuf[1]=lb; /* LB - xmodLoopbackRemotePCS */ 358 txbuf[2]=en; /* enable */ 359 360 rc = bcm_xmod_debug_cmd(unit, module, 1, (void*)txbuf, 3, &rsp, NULL, 0); 361 if (rc) { 362 printf("ERROR %d\n", rc); 363 } 364 365 return rc; 366 } 367 368 369 int 370 bcm_xmod_db_stats(int unit, int module, int pe_port) 371 { 372 int rsp; 373 int rc; 374 uint8 txbuf[32]; 375 376 printf("%s() uint %d, module %d\n", __FUNCTION__, unit, module); 377 378 /* init buffers */ 379 txbuf[0]=pe_port; /* port */ 380 381 rc = bcm_xmod_debug_cmd(unit, module, 2, (void*)txbuf, 1, &rsp, NULL, 0); 382 if (rc) { 383 printf("ERROR %d\n", rc); 384 } 385 386 return rc; 387 } 388 389 390 int 391 bcm_xmod_db_insert_tag(int unit, int module, int pe_port) 392 { 393 int rsp; 394 int rc; 395 uint8 txbuf[32]; 396 397 printf("%s() uint %d, module %d\n", __FUNCTION__, unit, module); 398 399 /* init buffers */ 400 txbuf[0]=pe_port; /* port */ 401 402 rc = bcm_xmod_debug_cmd(unit, module, 3, (void*)txbuf, 1, &rsp, NULL, 0); 403 if (rc) { 404 printf("ERROR %d\n", rc); 405 } 406 407 return rc; 408 } 409 410