Commit 768cc8ee authored by Pawel Wodkowski's avatar Pawel Wodkowski Committed by Jim Harris
Browse files

setup.sh: enhance output from setup, reset and status



Unify output of setup driver binding. Each line will print PCI BDF,
vendor and device id.

  $export PCI_BLACKLIST="0000:00:04.0 0000:00:04.1"
  $./scripts/setup.sh
  0000:0b:00.0 (8086 0953): nvme -> vfio-pci
  0000:00:04.1 (8086 0e20): Skipping un-whitelisted I/OAT device
  ...
  0000:00:04.1 (8086 0e21): Skipping un-whitelisted I/OAT device
  ...

Print log when desired driver is already bound:

  $./scripts/setup.sh
  0000:0b:00.0 (8086 0953): Already using the vfio-pci driver
  ...

'status' command prints vendor and device:

  ./scripts/setup.sh status
  ...
  NVMe devices
  BDF		Vendor	Device	NUMA	Driver		Device name
  0000:0b:00.0	8086	0953	0	vfio-pci		-

  I/OAT DMA
  BDF		Vendor	Device	NUMA	Driver
  0000:00:04.0	8086	0e20	0	ioatdma
  0000:80:04.0	8086	0e20	1	vfio-pci
  0000:00:04.1	8086	0e21	0	ioatdma
  0000:80:04.1	8086	0e21	1	vfio-pci
  0000:00:04.2	8086	0e22	0	vfio-pci
  0000:80:04.2	8086	0e22	1	vfio-pci
  ...

As we are here replace legacy Bash subshell invocation ` ` with $( ) in
some places.

Change-Id: I76b533c7580dadeb3d592c084778b8f9869c6d17
Signed-off-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/443218


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
parent eccf5491
Loading
Loading
Loading
Loading
+39 −21
Original line number Diff line number Diff line
@@ -96,6 +96,14 @@ function pci_can_bind() {
	return 1
}

function pci_dev_echo() {
	local bdf="$1"
	local vendor="$(cat /sys/bus/pci/devices/$bdf/vendor)"
	local device="$(cat /sys/bus/pci/devices/$bdf/device)"
	shift
	echo "$bdf (${vendor#0x} ${device#0x}): $@"
}

function linux_bind_driver() {
	bdf="$1"
	driver_name="$2"
@@ -106,6 +114,7 @@ function linux_bind_driver() {
		old_driver_name=$(basename $(readlink /sys/bus/pci/devices/$bdf/driver))

		if [ "$driver_name" = "$old_driver_name" ]; then
			pci_dev_echo "$bdf" "Already using the $old_driver_name driver"
			return 0
		fi

@@ -113,7 +122,7 @@ function linux_bind_driver() {
		echo "$bdf" > "/sys/bus/pci/devices/$bdf/driver/unbind"
	fi

	echo "$bdf ($ven_dev_id): $old_driver_name -> $driver_name"
	pci_dev_echo "$bdf" "$old_driver_name -> $driver_name"

	echo "$ven_dev_id" > "/sys/bus/pci/drivers/$driver_name/new_id" 2> /dev/null || true
	echo "$bdf" > "/sys/bus/pci/drivers/$driver_name/bind" 2> /dev/null || true
@@ -192,7 +201,7 @@ function configure_linux_pci {
		blkname=''
		get_nvme_name_from_bdf "$bdf" blkname
		if ! pci_can_bind $bdf; then
			echo "Skipping un-whitelisted NVMe controller $blkname ($bdf)"
			pci_dev_echo "$bdf" "Skipping un-whitelisted NVMe controller $blkname"
			continue
		fi
		if [ "$blkname" != "" ]; then
@@ -203,7 +212,7 @@ function configure_linux_pci {
		if [ "$mountpoints" = "0" ]; then
			linux_bind_driver "$bdf" "$driver_name"
		else
			echo Active mountpoints on /dev/$blkname, so not binding PCI dev $bdf
			pci_dev_echo "$bdf" "Active mountpoints on /dev/$blkname, so not binding PCI dev"
		fi
	done

@@ -216,7 +225,7 @@ function configure_linux_pci {
	for dev_id in `cat $TMP`; do
		for bdf in $(iter_pci_dev_id 8086 $dev_id); do
			if ! pci_can_bind $bdf; then
				echo "Skipping un-whitelisted I/OAT device at $bdf"
				pci_dev_echo "$bdf" "Skipping un-whitelisted I/OAT device"
				continue
			fi

@@ -234,14 +243,14 @@ function configure_linux_pci {
	for dev_id in `cat $TMP`; do
		for bdf in $(iter_pci_dev_id 1af4 $dev_id); do
			if ! pci_can_bind $bdf; then
				echo "Skipping un-whitelisted Virtio device at $bdf"
				pci_dev_echo "$bdf" "Skipping un-whitelisted Virtio device at $bdf"
				continue
			fi
			blknames=''
			get_virtio_names_from_bdf "$bdf" blknames
			for blkname in $blknames; do
				if [ "$(lsblk /dev/$blkname --output MOUNTPOINT -n | wc -w)" != "0" ]; then
					echo Active mountpoints on /dev/$blkname, so not binding PCI dev $bdf
					pci_dev_echo "$bdf" "Active mountpoints on /dev/$blkname, so not binding"
					continue 2
				fi
			done
@@ -372,7 +381,7 @@ function reset_linux_pci {
	set -e
	for bdf in $(iter_pci_class_code 01 08 02); do
		if ! pci_can_bind $bdf; then
			echo "Skipping un-whitelisted NVMe controller $blkname ($bdf)"
			pci_dev_echo "$bdf" "Skipping un-whitelisted NVMe controller $blkname"
			continue
		fi
		if [ $driver_loaded -ne 0 ]; then
@@ -395,7 +404,7 @@ function reset_linux_pci {
	for dev_id in `cat $TMP`; do
		for bdf in $(iter_pci_dev_id 8086 $dev_id); do
			if ! pci_can_bind $bdf; then
				echo "Skipping un-whitelisted I/OAT device at $bdf"
				pci_dev_echo "$bdf" "Skipping un-whitelisted I/OAT device"
				continue
			fi
			if [ $driver_loaded -ne 0 ]; then
@@ -421,7 +430,7 @@ function reset_linux_pci {
	for dev_id in `cat $TMP`; do
		for bdf in $(iter_pci_dev_id 1af4 $dev_id); do
			if ! pci_can_bind $bdf; then
				echo "Skipping un-whitelisted Virtio device at $bdf"
				pci_dev_echo "$bdf" "Skipping un-whitelisted Virtio device at"
				continue
			fi
			linux_bind_driver "$bdf" virtio-pci
@@ -470,47 +479,56 @@ function status_linux {
		printf "%-6s %10s %8s / %6s\n" $node $huge_size $free_pages $all_pages
	fi

	echo ""
	echo "NVMe devices"

	echo -e "BDF\t\tNuma Node\tDriver name\t\tDevice name"
	echo -e "BDF\t\tVendor\tDevice\tNUMA\tDriver\t\tDevice name"
	for bdf in $(iter_pci_class_code 01 08 02); do
		driver=`grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}'`
		node=`cat /sys/bus/pci/devices/$bdf/numa_node`;
		driver=$(grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}')
		node=$(cat /sys/bus/pci/devices/$bdf/numa_node)
		device=$(cat /sys/bus/pci/devices/$bdf/device)
		vendor=$(cat /sys/bus/pci/devices/$bdf/vendor)
		if [ "$driver" = "nvme" -a -d /sys/bus/pci/devices/$bdf/nvme ]; then
			name="\t"`ls /sys/bus/pci/devices/$bdf/nvme`;
		else
			name="-";
		fi
		echo -e "$bdf\t$node\t\t$driver\t\t$name";
		echo -e "$bdf\t${vendor#0x}\t${device#0x}\t$node\t$driver\t\t$name";
	done

	echo ""
	echo "I/OAT DMA"

	#collect all the device_id info of ioat devices.
	TMP=`grep "PCI_DEVICE_ID_INTEL_IOAT" $rootdir/include/spdk/pci_ids.h \
	| awk -F"x" '{print $2}'`
	echo -e "BDF\t\tNuma Node\tDriver Name"
	echo -e "BDF\t\tVendor\tDevice\tNUMA\tDriver"
	for dev_id in $TMP; do
		for bdf in $(iter_pci_dev_id 8086 $dev_id); do
			driver=`grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}'`
			node=`cat /sys/bus/pci/devices/$bdf/numa_node`;
			echo -e "$bdf\t$node\t\t$driver"
			driver=$(grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}')
			node=$(cat /sys/bus/pci/devices/$bdf/numa_node)
			device=$(cat /sys/bus/pci/devices/$bdf/device)
			vendor=$(cat /sys/bus/pci/devices/$bdf/vendor)
			echo -e "$bdf\t${vendor#0x}\t${device#0x}\t$node\t$driver"
		done
	done

	echo ""
	echo "virtio"

	#collect all the device_id info of virtio devices.
	TMP=`grep "PCI_DEVICE_ID_VIRTIO" $rootdir/include/spdk/pci_ids.h \
	| awk -F"x" '{print $2}'`
	echo -e "BDF\t\tNuma Node\tDriver Name\t\tDevice Name"
	echo -e "BDF\t\tVendor\tDevice\tNUMA\tDriver\t\tDevice name"
	for dev_id in $TMP; do
		for bdf in $(iter_pci_dev_id 1af4 $dev_id); do
			driver=`grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}'`
			node=`cat /sys/bus/pci/devices/$bdf/numa_node`;
			driver=$(grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}')
			node=$(cat /sys/bus/pci/devices/$bdf/numa_node)
			device=$(cat /sys/bus/pci/devices/$bdf/device)
			vendor=$(cat /sys/bus/pci/devices/$bdf/vendor)
			blknames=''
			get_virtio_names_from_bdf "$bdf" blknames
			echo -e "$bdf\t$node\t\t$driver\t\t$blknames"
			echo -e "$bdf\t${vendor#0x}\t${device#0x}\t$node\t\t$driver\t\t$blknames"
		done
	done
}