2020-07-13 16:15:09 -05:00
|
|
|
#! /bin/bash
|
|
|
|
## Check the platform PCIe device presence and status
|
|
|
|
|
|
|
|
VERBOSE="no"
|
|
|
|
RESULTS="PCIe Device Checking All Test"
|
|
|
|
EXPECTED="PCIe Device Checking All Test ----------->>> PASSED"
|
|
|
|
MAX_WAIT_SECONDS=15
|
|
|
|
|
|
|
|
function debug()
|
|
|
|
{
|
|
|
|
/usr/bin/logger "$0 : $1"
|
|
|
|
if [[ x"${VERBOSE}" == x"yes" ]]; then
|
|
|
|
echo "$(date) $0: $1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_and_rescan_pcie_devices()
|
|
|
|
{
|
2021-02-04 14:14:08 -06:00
|
|
|
PCIE_CHK_CMD='sudo pcieutil check | grep "$RESULTS"'
|
2020-07-13 16:15:09 -05:00
|
|
|
PLATFORM=$(sonic-cfggen -H -v DEVICE_METADATA.localhost.platform)
|
|
|
|
|
2021-02-21 10:27:37 -06:00
|
|
|
if [ ! -f /usr/share/sonic/device/$PLATFORM/pcie.yaml ]; then
|
2021-02-04 14:14:08 -06:00
|
|
|
debug "pcie.yaml does not exist! Can't check PCIe status!"
|
2020-07-13 16:15:09 -05:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
|
|
|
begin=$SECONDS
|
|
|
|
end=$((begin + MAX_WAIT_SECONDS))
|
|
|
|
rescan_time=$((MAX_WAIT_SECONDS/2))
|
|
|
|
rescan_time=$((begin + rescan_time))
|
|
|
|
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
now=$SECONDS
|
|
|
|
if [[ $now -gt $end ]]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
2020-09-15 17:21:31 -05:00
|
|
|
if [ "$(eval $PCIE_CHK_CMD)" = "$EXPECTED" ]; then
|
|
|
|
redis-cli -n 6 HSET "PCIE_DEVICES" "status" "PASSED"
|
2020-07-13 16:15:09 -05:00
|
|
|
debug "PCIe check passed"
|
|
|
|
exit
|
|
|
|
else
|
|
|
|
debug "sleep 0.1 seconds"
|
|
|
|
sleep 0.1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $now -gt $rescan_time ]; then
|
|
|
|
debug "PCIe check failed, try pci bus rescan"
|
|
|
|
echo 1 > /sys/bus/pci/rescan
|
|
|
|
rescan_time=$end
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
|
|
|
debug "PCIe check failed"
|
2020-09-15 17:21:31 -05:00
|
|
|
redis-cli -n 6 HSET "PCIE_DEVICES" "status" "FAILED"
|
2020-07-13 16:15:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
check_and_rescan_pcie_devices
|