setup.sh: Add support for built-in modules

setup.sh uses lsmod to detect if a module is present but this does
not work when modules are built-in. We add a second check (on
/sys/module/<module>) and place the check in a function.

We also change the sense of driver_loaded so it is more sane and also
allows us to return different positive values depending on if the
driver is a module or built-in.

Change-Id: Iccc4dca212a6f04fb2ac9bd4768935f8b2bb240a
Signed-off-by: Stephen Bates <sbates@raithlin.com>
Reviewed-on: https://review.gerrithub.io/402178
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Stephen Bates 2018-03-01 18:43:20 -07:00 committed by Jim Harris
parent c1174e6895
commit e1817b60bb

View File

@ -49,6 +49,23 @@ function usage()
exit 0 exit 0
} }
# In monolithic kernels the lsmod won't work. So
# back that with a /sys/modules check. Return a different code for
# built-in vs module just in case we want that down the road.
function check_for_driver {
$(lsmod | grep $1 > /dev/null)
if [ $? -eq 0 ]; then
return 1
else
if [[ -d /sys/module/$1 ]]; then
return 2
else
return 0
fi
fi
return 0
}
function pci_can_bind() { function pci_can_bind() {
if [[ ${#PCI_WHITELIST[@]} == 0 ]]; then if [[ ${#PCI_WHITELIST[@]} == 0 ]]; then
#no whitelist specified, bind all devices #no whitelist specified, bind all devices
@ -275,7 +292,7 @@ function configure_linux {
function reset_linux_pci { function reset_linux_pci {
# NVMe # NVMe
set +e set +e
lsmod | grep nvme > /dev/null check_for_driver nvme
driver_loaded=$? driver_loaded=$?
set -e set -e
for bdf in $(iter_pci_class_code 01 08 02); do for bdf in $(iter_pci_class_code 01 08 02); do
@ -283,7 +300,7 @@ function reset_linux_pci {
echo "Skipping un-whitelisted NVMe controller $blkname ($bdf)" echo "Skipping un-whitelisted NVMe controller $blkname ($bdf)"
continue continue
fi fi
if [ $driver_loaded -eq 0 ]; then if [ $driver_loaded -ne 0 ]; then
linux_bind_driver "$bdf" nvme linux_bind_driver "$bdf" nvme
else else
linux_unbind_driver "$bdf" linux_unbind_driver "$bdf"
@ -297,7 +314,7 @@ function reset_linux_pci {
| awk -F"x" '{print $2}' > $TMP | awk -F"x" '{print $2}' > $TMP
set +e set +e
lsmod | grep ioatdma > /dev/null check_for_driver ioatdma
driver_loaded=$? driver_loaded=$?
set -e set -e
for dev_id in `cat $TMP`; do for dev_id in `cat $TMP`; do
@ -306,7 +323,7 @@ function reset_linux_pci {
echo "Skipping un-whitelisted I/OAT device at $bdf" echo "Skipping un-whitelisted I/OAT device at $bdf"
continue continue
fi fi
if [ $driver_loaded -eq 0 ]; then if [ $driver_loaded -ne 0 ]; then
linux_bind_driver "$bdf" ioatdma linux_bind_driver "$bdf" ioatdma
else else
linux_unbind_driver "$bdf" linux_unbind_driver "$bdf"