2019-03-06 20:51:46 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-12-17 12:58:55 -06:00
|
|
|
declare -r SYSLOG_LOGGER="/usr/bin/logger"
|
|
|
|
declare -r SYSLOG_IDENTIFIER="platform_wait"
|
|
|
|
declare -r SYSLOG_ERROR="error"
|
|
|
|
declare -r SYSLOG_NOTICE="notice"
|
|
|
|
declare -r SYSLOG_INFO="info"
|
|
|
|
|
|
|
|
declare -r HW_MGMT_CONFIG="/var/run/hw-management/config"
|
|
|
|
|
2023-11-16 20:01:06 -06:00
|
|
|
declare -r ASIC_INIT_DONE="${HW_MGMT_CONFIG}/asics_init_done"
|
|
|
|
declare -r NUM_ASICS="${HW_MGMT_CONFIG}/asic_num"
|
|
|
|
declare -r ASIC_CHIPUP_COMPLETED="${HW_MGMT_CONFIG}/asic_chipup_completed"
|
2019-12-17 12:58:55 -06:00
|
|
|
|
2019-03-06 20:51:46 -06:00
|
|
|
declare -r EXIT_SUCCESS="0"
|
|
|
|
declare -r EXIT_TIMEOUT="1"
|
|
|
|
|
2019-12-17 12:58:55 -06:00
|
|
|
function log_error() {
|
|
|
|
eval "${SYSLOG_LOGGER} -t ${SYSLOG_IDENTIFIER} -p ${SYSLOG_ERROR} $@"
|
|
|
|
}
|
2019-03-06 20:51:46 -06:00
|
|
|
|
2019-12-17 12:58:55 -06:00
|
|
|
function log_notice() {
|
|
|
|
eval "${SYSLOG_LOGGER} -t ${SYSLOG_IDENTIFIER} -p ${SYSLOG_NOTICE} $@"
|
|
|
|
}
|
|
|
|
|
|
|
|
function log_info() {
|
|
|
|
eval "${SYSLOG_LOGGER} -t ${SYSLOG_IDENTIFIER} -p ${SYSLOG_INFO} $@"
|
|
|
|
}
|
|
|
|
|
2023-11-16 20:01:06 -06:00
|
|
|
function wait_for_asic_chipup() {
|
2019-12-17 12:58:55 -06:00
|
|
|
|
2023-11-16 20:01:06 -06:00
|
|
|
local _ASIC_INIT="0"
|
|
|
|
local _ASIC_COUNT="0"
|
|
|
|
local _ASICS_CHIPUP="0"
|
2019-03-06 20:51:46 -06:00
|
|
|
|
|
|
|
local -i _WDOG_CNT="1"
|
|
|
|
local -ir _WDOG_MAX="300"
|
|
|
|
|
|
|
|
local -r _TIMEOUT="1s"
|
|
|
|
|
|
|
|
while [[ "${_WDOG_CNT}" -le "${_WDOG_MAX}" ]]; do
|
2023-11-16 20:01:06 -06:00
|
|
|
_ASIC_INIT="$(cat ${ASIC_INIT_DONE} 2>&1)"
|
|
|
|
_ASIC_COUNT="$(cat ${NUM_ASICS} 2>&1)"
|
|
|
|
_ASICS_CHIPUP="$(cat ${ASIC_CHIPUP_COMPLETED} 2>&1)"
|
2019-12-17 12:58:55 -06:00
|
|
|
|
2023-11-16 20:01:06 -06:00
|
|
|
if [[ "${_ASIC_INIT}" -eq 1 && "${_ASIC_COUNT}" -eq "${_ASICS_CHIPUP}" ]]; then
|
|
|
|
return "${EXIT_SUCCESS}"
|
2019-12-17 12:58:55 -06:00
|
|
|
fi
|
2019-03-06 20:51:46 -06:00
|
|
|
|
|
|
|
let "_WDOG_CNT++"
|
|
|
|
sleep "${_TIMEOUT}"
|
|
|
|
done
|
|
|
|
|
2023-11-16 20:01:06 -06:00
|
|
|
log_error "Mellanox ASIC is not ready: INIT: ${_ASIC_INIT}, NUM_ASIC: ${_ASIC_COUNT}, CHIPUP: ${_ASICS_CHIPUP} timeout...."
|
2019-03-06 20:51:46 -06:00
|
|
|
return "${EXIT_TIMEOUT}"
|
|
|
|
}
|
|
|
|
|
2023-11-16 20:01:06 -06:00
|
|
|
log_info "Wait for Mellanox ASIC to be ready"
|
2019-03-06 20:51:46 -06:00
|
|
|
|
2023-11-16 20:01:06 -06:00
|
|
|
wait_for_asic_chipup
|
2019-03-06 20:51:46 -06:00
|
|
|
EXIT_CODE="$?"
|
|
|
|
if [[ "${EXIT_CODE}" != "${EXIT_SUCCESS}" ]]; then
|
|
|
|
exit "${EXIT_CODE}"
|
|
|
|
fi
|
|
|
|
|
2023-11-16 20:01:06 -06:00
|
|
|
log_notice "Mellanox ASIC is ready"
|
2019-12-17 12:58:55 -06:00
|
|
|
|
2019-03-06 20:51:46 -06:00
|
|
|
exit "${EXIT_SUCCESS}"
|