armcore.c (5662B)
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 * tr145 - ARM core test 8 * Test the ARM core(s) embedded in CMICM and IPROC switches 9 */ 10 11 #include <shared/bsl.h> 12 13 #include <sal/types.h> 14 #include <sal/core/boot.h> 15 #include <sal/appl/sal.h> 16 #include <appl/diag/system.h> 17 #include <appl/diag/parse.h> 18 #include <shared/bsl.h> 19 #include <soc/types.h> 20 #include <soc/debug.h> 21 #include <soc/shared/mos_msg_common.h> 22 #if defined(BCM_CMICM_SUPPORT) || defined(BCM_IPROC_SUPPORT) 23 #include <soc/uc_msg.h> 24 #endif 25 26 #include <bcm/error.h> 27 28 #include "testlist.h" 29 #include <appl/diag/system.h> 30 #include <appl/diag/progress.h> 31 32 #if defined(BCM_CMICM_SUPPORT) || defined(BCM_IPROC_SUPPORT) 33 34 /* Return codes for TEST_RUN calls */ 35 #define MOS_TEST_RC_OK 0 36 #define MOS_TEST_RC_FAILURE 0xffffffff 37 #define MOS_TEST_RC_INVALID 0xfffffffe 38 39 typedef struct arm_core_work_s { 40 int unit; /* unit number */ 41 int uc_num; /* core # to test */ 42 uint32 tests; /* bitmap of tests to perform */ 43 } arm_core_work_t; 44 45 static uint32 _arm_core_uc_msg_timeout_usecs = 10 * 1000 * 1000; /* 10sec */ 46 47 static arm_core_work_t *ac_work[SOC_MAX_NUM_DEVICES]; 48 49 static 50 int 51 arm_core_test_msg(arm_core_work_t *ac, int subclass, uint32 data_in, uint32 *data_out) 52 { 53 int rv; 54 mos_msg_data_t send, reply; 55 56 /* Build the message */ 57 sal_memset(&send, 0, sizeof(send)); 58 sal_memset(&reply, 0, sizeof(reply)); 59 send.s.mclass = MOS_MSG_CLASS_TEST; 60 send.s.subclass = subclass; 61 send.s.data = soc_htonl(data_in); 62 63 /* Send and receive */ 64 rv = soc_cmic_uc_msg_send_receive(ac->unit, ac->uc_num, &send, &reply, 65 _arm_core_uc_msg_timeout_usecs); 66 67 /* Check reply class, subclass */ 68 if (rv != SOC_E_NONE) { 69 test_error(ac->unit, "soc_cmic_uc_msg_send_receive failed (%d).\n", rv); 70 return rv; 71 } 72 if ((reply.s.mclass != send.s.mclass) || 73 (reply.s.subclass != send.s.subclass)) { 74 test_error(ac->unit, "unexpected message reply.\n"); 75 return SOC_E_INTERNAL; 76 } 77 78 /* return data */ 79 *data_out = soc_ntohl(reply.s.data); 80 return SOC_E_NONE; 81 } 82 83 int 84 arm_core_test(int u, args_t *args, void *pa) 85 { 86 arm_core_work_t *ac = (arm_core_work_t *)pa; 87 uint32 count; 88 int r; 89 int rv; 90 uint32 rc; 91 92 /* Start the test application */ 93 rv = soc_cmic_uc_appl_init(u, ac->uc_num, MOS_MSG_CLASS_TEST, 94 _arm_core_uc_msg_timeout_usecs, 95 0, 0, 96 NULL, NULL); 97 if (rv != SOC_E_NONE) { 98 test_error(u, "Error starting test appl (%d).\n", rv); 99 return -1; 100 } 101 102 rv = arm_core_test_msg(ac, MOS_MSG_SUBCLASS_TEST_COUNT, 0, &count); 103 if (rv != SOC_E_NONE) { 104 test_error(u, "Error communicating with test appl (%d).\n", rv); 105 return -1; 106 } 107 108 /* If no tests, error */ 109 if (!count) { 110 test_error(u, "uKernel image on core %d does not support test.\n", 111 ac->uc_num); 112 return -1; 113 } 114 115 progress_init(count, 1, 0); 116 for (r = 0; r < count; ) { 117 rv = arm_core_test_msg(ac, MOS_MSG_SUBCLASS_TEST_RUN, r, &rc); 118 if (rv != SOC_E_NONE) { 119 test_error(u, "Error communicating with test appl (%d).\n", rv); 120 return -1; 121 } 122 switch (rc) { 123 case MOS_TEST_RC_OK: 124 LOG_INFO(BSL_LS_APPL_TESTS, 125 (BSL_META_U(u, 126 "test %d PASS\n"), r)); 127 break; 128 case MOS_TEST_RC_FAILURE: 129 LOG_INFO(BSL_LS_APPL_TESTS, 130 (BSL_META_U(u, 131 "test %d FAIL\n"), r)); 132 break; 133 case MOS_TEST_RC_INVALID: 134 LOG_INFO(BSL_LS_APPL_TESTS, 135 (BSL_META_U(u, 136 "test %d SKIP\n"), r)); 137 break; 138 } 139 r += 1; 140 progress_report(1); 141 } 142 progress_done(); 143 return 0; 144 } 145 146 int 147 arm_core_test_init(int u, args_t *args, void **pa) 148 { 149 arm_core_work_t *ac; 150 parse_table_t pt; 151 152 if (!soc_feature(u, soc_feature_mcs) 153 && !soc_feature(u, soc_feature_iproc)) { 154 test_error(u, "ERROR: test only valid on mcs or iproc enabled devices\n"); 155 return -1; 156 } 157 158 if (ac_work[u] == NULL) { 159 ac_work[u] = sal_alloc(sizeof(arm_core_work_t), "arm_core_test"); 160 if (ac_work[u] == NULL) { 161 test_error(u, "ERROR: cannot allocate memory\n"); 162 return -1; 163 } 164 sal_memset(ac_work[u], 0, sizeof(arm_core_work_t)); 165 } 166 ac = ac_work[u]; 167 ac->unit = u; 168 169 parse_table_init(u, &pt); 170 parse_table_add(&pt, "uc", PQ_INT, (void *)0, &ac->uc_num, 171 NULL); 172 parse_table_add(&pt, "tests", PQ_INT, (void *)0xffffffff, &ac->tests, 173 NULL); 174 175 if (parse_arg_eq(args, &pt) < 0 || ARG_CNT(args) != 0) { 176 test_error(u, "%s: Invalid Option: %s\n", ARG_CMD(args), 177 ARG_CUR(args) ? ARG_CUR(args) : "*"); 178 } 179 parse_arg_eq_done(&pt); 180 181 *pa = (void *)ac; 182 183 return 0; 184 } 185 186 int 187 arm_core_test_done(int u, void *pa) 188 { 189 arm_core_work_t *ac = (arm_core_work_t *)pa; 190 191 if (NULL == ac) { 192 return(0); 193 } 194 195 sal_free(ac); 196 ac_work[u] = NULL; 197 return(0); 198 } 199 200 #endif