From 102837283738d8ad6e0cd0a4f69406da46b7f4af Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 13 Oct 2017 08:32:39 -0700 Subject: [PATCH] setup.sh: for reset, just unbind if kernel driver is not loaded If the user did not have the ioatdma driver loaded for example, when running "setup.sh reset", we should not load ioatdma so that we can bind to it. Instead just unbind the devices from the uio/vfio driver. Signed-off-by: Jim Harris Change-Id: I953941eb4918105b97ad78987b47b33f4372ae01 Reviewed-on: https://review.gerrithub.io/382474 Reviewed-by: Daniel Verkamp Tested-by: SPDK Automated Test System Reviewed-by: Changpeng Liu --- scripts/setup.sh | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/scripts/setup.sh b/scripts/setup.sh index 419e782ba..1e14049e3 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -45,6 +45,21 @@ function linux_bind_driver() { fi } +function linux_unbind_driver() { + bdf="$1" + ven_dev_id=$(lspci -n -s $bdf | cut -d' ' -f3 | sed 's/:/ /') + + if ! [ -e "/sys/bus/pci/devices/$bdf/driver" ]; then + return 0 + fi + + old_driver_name=$(basename $(readlink /sys/bus/pci/devices/$bdf/driver)) + + echo "$ven_dev_id" > "/sys/bus/pci/devices/$bdf/driver/remove_id" 2> /dev/null || true + echo "$bdf" > "/sys/bus/pci/devices/$bdf/driver/unbind" + echo "$bdf ($ven_dev_id): $old_driver_name -> no driver" +} + function linux_hugetlbfs_mount() { mount | grep ' type hugetlbfs ' | awk '{ print $3 }' } @@ -130,9 +145,16 @@ function configure_linux { function reset_linux { # NVMe - modprobe nvme || true + set +e + lsmod | grep nvme > /dev/null + driver_loaded=$? + set -e for bdf in $(linux_iter_pci_class_code 0108); do - linux_bind_driver "$bdf" nvme + if [ $driver_loaded -eq 0 ]; then + linux_bind_driver "$bdf" nvme + else + linux_unbind_driver "$bdf" + fi done @@ -142,10 +164,17 @@ function reset_linux { grep "PCI_DEVICE_ID_INTEL_IOAT" $rootdir/include/spdk/pci_ids.h \ | awk -F"x" '{print $2}' > $TMP - modprobe ioatdma || true + set +e + lsmod | grep ioatdma > /dev/null + driver_loaded=$? + set -e for dev_id in `cat $TMP`; do for bdf in $(linux_iter_pci_dev_id 8086 $dev_id); do - linux_bind_driver "$bdf" ioatdma + if [ $driver_loaded -eq 0 ]; then + linux_bind_driver "$bdf" ioatdma + else + linux_unbind_driver "$bdf" + fi done done rm $TMP @@ -156,6 +185,10 @@ function reset_linux { grep "VIRTIO_PCI_DEVICEID_SCSI" $rootdir/lib/bdev/virtio/rte_virtio/virtio_pci.h \ | awk -F"x" '{print $2}' > $TMP + # TODO: check if virtio-pci is loaded first and just unbind if it is not loaded + # Requires some more investigation - for example, some kernels do not seem to have + # virtio-pci but just virtio_scsi instead. Also need to make sure we get the + # underscore vs. dash right in the virtio_scsi name. modprobe virtio-pci || true for dev_id in `cat $TMP`; do for bdf in $(linux_iter_pci_dev_id 1af4 $dev_id); do