Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions files/build_templates/pcie-check.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Start the pcie-check.service in 10 seconds after boot

[Timer]
OnBootSec=10sec
Unit=pcie-check.service

[Install]
WantedBy=timers.target
9 changes: 9 additions & 0 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,15 @@ sudo cp $IMAGE_CONFIGS/procdockerstatsd/procdockerstatsd.service $FILESYSTEM_ROO
echo "procdockerstatsd.service" | sudo tee -a $GENERATED_SERVICE_FILE
sudo cp $IMAGE_CONFIGS/procdockerstatsd/procdockerstatsd $FILESYSTEM_ROOT/usr/bin/

# Copy systemd timer configuration
sudo cp $BUILD_TEMPLATES/pcie-check.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
sudo LANG=C chroot $FILESYSTEM_ROOT systemctl enable pcie-check.timer

# Copy pcie-check service files
sudo cp $IMAGE_CONFIGS/pcie-check/pcie-check.service $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
echo "pcie-check.service" | sudo tee -a $GENERATED_SERVICE_FILE
sudo cp $IMAGE_CONFIGS/pcie-check/pcie-check.sh $FILESYSTEM_ROOT/usr/bin/

# Copy systemd timer configuration
# It implements delayed start of services
sudo cp $BUILD_TEMPLATES/process-reboot-cause.timer $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM
Expand Down
7 changes: 7 additions & 0 deletions files/image_config/pcie-check/pcie-check.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Unit]
Description=Check the PCIe device presence and status
After=rc.local.service

[Service]
Type=simple
ExecStart=/usr/bin/pcie-check.sh
58 changes: 58 additions & 0 deletions files/image_config/pcie-check/pcie-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#! /bin/bash
## Check the platform PCIe device presence and status

VERBOSE="no"
RESULTS="PCIe Device Checking All Test"
PCIE_CHK_CMD=`sudo pcieutil pcie-check |grep "$RESULTS"`
Copy link
Copy Markdown
Contributor

@padmanarayana padmanarayana Jun 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be done based on pcie_check_sysfs() like API rather than thru' CLI ?
This will also help in avoiding to check the CLI string output for EXPECTED.

EXPECTED="PCIe Device Checking All Test ----------->>> PASSED"
MAX_WAIT_TIMEOUT=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()
{
PLATFORM=`sonic-cfggen -H -v DEVICE_METADATA.localhost.platform`
if [ ! -f /usr/share/sonic/device/$PLATFORM/plugins/pcie.yaml ]; then
debug "pcie.yaml does not exist! can't check pcie status!"
exit
fi

begin=$SECONDS
end=`expr $begin + $MAX_WAIT_TIMEOUT`
rescan_time=$((MAX_WAIT_TIMEOUT/2))
rescan_time=`expr $begin + $rescan_time`

while true
do
now=$SECONDS
if [[ $now -gt $end ]]; then
break
fi

if [ "$PCIE_CHK_CMD" = "$EXPECTED" ]; then
redis-cli -n 6 SET "PCIE_STATUS|PCIE_DEVICES" "PASSED"
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here rescan is instantiated for all-devices. (sys/bus/pci/rescan). Rescan should be device specific.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed offline. For now, we will rescan the entire bus. Rescanning individual devices will be a future enhancement.

rescan_time=$end
fi

done
debug "PCIe check failed"
redis-cli -n 6 SET "PCIE_STATUS|PCIE_DEVICES" "FAILED"
}

check_and_rescan_pcie_devices