xref: /linux/tools/testing/selftests/powerpc/eeh/eeh-basic.sh (revision d0034a7a4ac7fae708146ac0059b9c47a1543f0d)
185d86c8aSOliver O'Halloran#!/bin/sh
285d86c8aSOliver O'Halloran# SPDX-License-Identifier: GPL-2.0-only
385d86c8aSOliver O'Halloran
485d86c8aSOliver O'Halloran. ./eeh-functions.sh
585d86c8aSOliver O'Halloran
6*db82f709SOliver O'Halloraneeh_test_prep # NB: may exit
785d86c8aSOliver O'Halloran
885d86c8aSOliver O'Halloranpre_lspci=`mktemp`
985d86c8aSOliver O'Halloranlspci > $pre_lspci
1085d86c8aSOliver O'Halloran
1185d86c8aSOliver O'Halloran# record the devices that we break in here. Assuming everything
1285d86c8aSOliver O'Halloran# goes to plan we should get them back once the recover process
1385d86c8aSOliver O'Halloran# is finished.
1485d86c8aSOliver O'Hallorandevices=""
1585d86c8aSOliver O'Halloran
1685d86c8aSOliver O'Halloran# Build up a list of candidate devices.
1785d86c8aSOliver O'Halloranfor dev in `ls -1 /sys/bus/pci/devices/ | grep '\.0$'` ; do
18*db82f709SOliver O'Halloran	if ! eeh_can_break $dev ; then
1985d86c8aSOliver O'Halloran		continue;
2085d86c8aSOliver O'Halloran	fi
2185d86c8aSOliver O'Halloran
22*db82f709SOliver O'Halloran	# Skip VFs for now since we don't have a reliable way to break them.
2385d86c8aSOliver O'Halloran	if [ -e "/sys/bus/pci/devices/$dev/physfn" ] ; then
2485d86c8aSOliver O'Halloran		echo "$dev, Skipped: virtfn"
2585d86c8aSOliver O'Halloran		continue;
2685d86c8aSOliver O'Halloran	fi
2785d86c8aSOliver O'Halloran
2885d86c8aSOliver O'Halloran	echo "$dev, Added"
2985d86c8aSOliver O'Halloran
3085d86c8aSOliver O'Halloran	# Add to this list of device to check
3185d86c8aSOliver O'Halloran	devices="$devices $dev"
3285d86c8aSOliver O'Hallorandone
3385d86c8aSOliver O'Halloran
3485d86c8aSOliver O'Hallorandev_count="$(echo $devices | wc -w)"
3585d86c8aSOliver O'Halloranecho "Found ${dev_count} breakable devices..."
3685d86c8aSOliver O'Halloran
3785d86c8aSOliver O'Halloranfailed=0
3885d86c8aSOliver O'Halloranfor dev in $devices ; do
3985d86c8aSOliver O'Halloran	echo "Breaking $dev..."
4085d86c8aSOliver O'Halloran
4185d86c8aSOliver O'Halloran	if ! pe_ok $dev ; then
4285d86c8aSOliver O'Halloran		echo "Skipping $dev, Initial PE state is not ok"
4385d86c8aSOliver O'Halloran		failed="$((failed + 1))"
4485d86c8aSOliver O'Halloran		continue;
4585d86c8aSOliver O'Halloran	fi
4685d86c8aSOliver O'Halloran
4785d86c8aSOliver O'Halloran	if ! eeh_one_dev $dev ; then
4885d86c8aSOliver O'Halloran		failed="$((failed + 1))"
4985d86c8aSOliver O'Halloran	fi
5085d86c8aSOliver O'Hallorandone
5185d86c8aSOliver O'Halloran
5285d86c8aSOliver O'Halloranecho "$failed devices failed to recover ($dev_count tested)"
5385d86c8aSOliver O'Halloranlspci | diff -u $pre_lspci -
5485d86c8aSOliver O'Halloranrm -f $pre_lspci
5585d86c8aSOliver O'Halloran
563db38057SPo-Hsu Lintest "$failed" -eq 0
57996f9e0fSOliver O'Halloranexit $?
58