Commit ad32c7b8 authored by Pawel Wodkowski's avatar Pawel Wodkowski Committed by Darek Stojaczyk
Browse files

scripts/common.sh: use PCI blacklist and whitelist



iter_pci_dev_id abd iter_pci_dev_id functions should
not return BDF for devices that are not ment to be used
in tests.

Note that not all tests are ready for this change as they
discover functions on its own. Lets this changed in
separate patch.

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


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
parent 5de43a75
Loading
Loading
Loading
Loading
+29 −5
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
# if PCI_BLACKLIST is empty assume device is NOT blacklistened
# Params:
# $1 - PCI BDF
function pci_can_bind() {
function pci_can_use() {
	local i

	# The '\ ' part is important
@@ -28,7 +28,8 @@ function pci_can_bind() {
	return 1
}

function iter_pci_class_code() {
# This function will ignore PCI PCI_WHITELIST and PCI_BLACKLIST
function iter_all_pci_class_code() {
	local class="$(printf %02x $((0x$1)))"
	local subclass="$(printf %02x $((0x$2)))"
	local progif="$(printf %02x $((0x$3)))"
@@ -45,7 +46,7 @@ function iter_pci_class_code() {
				'{if (cc ~ $2) print $1}' | tr -d '"'
		fi
	elif hash pciconf &>/dev/null; then
		addr=($(pciconf -l | grep -i "class=0x${class}${subclass}${progif}" | \
		local addr=($(pciconf -l | grep -i "class=0x${class}${subclass}${progif}" | \
			cut -d$'\t' -f1 | sed -e 's/^[a-zA-Z0-9_]*@pci//g' | tr ':' ' '))
		printf "%04x:%02x:%02x:%x\n" ${addr[0]} ${addr[1]} ${addr[2]} ${addr[3]}
	else
@@ -54,7 +55,8 @@ function iter_pci_class_code() {
	fi
}

function iter_pci_dev_id() {
# This function will ignore PCI PCI_WHITELIST and PCI_BLACKLIST
function iter_all_pci_dev_id() {
	local ven_id="$(printf %04x $((0x$1)))"
	local dev_id="$(printf %04x $((0x$2)))"

@@ -62,7 +64,7 @@ function iter_pci_dev_id() {
		lspci -mm -n -D | awk -v ven="\"$ven_id\"" -v dev="\"${dev_id}\"" -F " " \
			'{if (ven ~ $3 && dev ~ $4) print $1}' | tr -d '"'
	elif hash pciconf &>/dev/null; then
		addr=($(pciconf -l | grep -i "chip=0x${dev_id}${ven_id}" | \
		local addr=($(pciconf -l | grep -i "chip=0x${dev_id}${ven_id}" | \
			cut -d$'\t' -f1 | sed -e 's/^[a-zA-Z0-9_]*@pci//g' | tr ':' ' '))
		printf "%04x:%02x:%02x:%x\n" ${addr[0]} ${addr[1]} ${addr[2]} ${addr[3]}
	else
@@ -70,3 +72,25 @@ function iter_pci_dev_id() {
		exit 1
	fi
}

function iter_pci_dev_id() {
	local bdf=""

	for bdf in $(iter_all_pci_dev_id "$@"); do
		if pci_can_use "$bdf"; then
			echo "$bdf"
		fi
	done
}

# This function will filter out PCI devices using PCI_WHITELIST and PCI_BLACKLIST
# See function pci_can_use()
function iter_pci_class_code() {
	local bdf=""

	for bdf in $(iter_all_pci_class_code "$@"); do
		if pci_can_use "$bdf"; then
			echo "$bdf"
		fi
	done
}
+15 −15
Original line number Diff line number Diff line
@@ -179,10 +179,10 @@ function configure_linux_pci {

	# NVMe
	modprobe $driver_name
	for bdf in $(iter_pci_class_code 01 08 02); do
	for bdf in $(iter_all_pci_class_code 01 08 02); do
		blkname=''
		get_nvme_name_from_bdf "$bdf" blkname
		if ! pci_can_bind $bdf; then
		if ! pci_can_use $bdf; then
			pci_dev_echo "$bdf" "Skipping un-whitelisted NVMe controller $blkname"
			continue
		fi
@@ -205,8 +205,8 @@ function configure_linux_pci {
	| awk -F"x" '{print $2}' > $TMP

	for dev_id in `cat $TMP`; do
		for bdf in $(iter_pci_dev_id 8086 $dev_id); do
			if ! pci_can_bind $bdf; then
		for bdf in $(iter_all_pci_dev_id 8086 $dev_id); do
			if ! pci_can_use $bdf; then
				pci_dev_echo "$bdf" "Skipping un-whitelisted I/OAT device"
				continue
			fi
@@ -223,8 +223,8 @@ function configure_linux_pci {
	| awk -F"x" '{print $2}' > $TMP

	for dev_id in `cat $TMP`; do
		for bdf in $(iter_pci_dev_id 1af4 $dev_id); do
			if ! pci_can_bind $bdf; then
		for bdf in $(iter_all_pci_dev_id 1af4 $dev_id); do
			if ! pci_can_use $bdf; then
				pci_dev_echo "$bdf" "Skipping un-whitelisted Virtio device at $bdf"
				continue
			fi
@@ -361,8 +361,8 @@ function reset_linux_pci {
	check_for_driver nvme
	driver_loaded=$?
	set -e
	for bdf in $(iter_pci_class_code 01 08 02); do
		if ! pci_can_bind $bdf; then
	for bdf in $(iter_all_pci_class_code 01 08 02); do
		if ! pci_can_use $bdf; then
			pci_dev_echo "$bdf" "Skipping un-whitelisted NVMe controller $blkname"
			continue
		fi
@@ -384,8 +384,8 @@ function reset_linux_pci {
	driver_loaded=$?
	set -e
	for dev_id in `cat $TMP`; do
		for bdf in $(iter_pci_dev_id 8086 $dev_id); do
			if ! pci_can_bind $bdf; then
		for bdf in $(iter_all_pci_dev_id 8086 $dev_id); do
			if ! pci_can_use $bdf; then
				pci_dev_echo "$bdf" "Skipping un-whitelisted I/OAT device"
				continue
			fi
@@ -410,8 +410,8 @@ function reset_linux_pci {
	#  underscore vs. dash right in the virtio_scsi name.
	modprobe virtio-pci || true
	for dev_id in `cat $TMP`; do
		for bdf in $(iter_pci_dev_id 1af4 $dev_id); do
			if ! pci_can_bind $bdf; then
		for bdf in $(iter_all_pci_dev_id 1af4 $dev_id); do
			if ! pci_can_use $bdf; then
				pci_dev_echo "$bdf" "Skipping un-whitelisted Virtio device at"
				continue
			fi
@@ -465,7 +465,7 @@ function status_linux {
	echo "NVMe devices"

	echo -e "BDF\t\tVendor\tDevice\tNUMA\tDriver\t\tDevice name"
	for bdf in $(iter_pci_class_code 01 08 02); do
	for bdf in $(iter_all_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)
		device=$(cat /sys/bus/pci/devices/$bdf/device)
@@ -486,7 +486,7 @@ function status_linux {
	| awk -F"x" '{print $2}'`
	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
		for bdf in $(iter_all_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)
			device=$(cat /sys/bus/pci/devices/$bdf/device)
@@ -503,7 +503,7 @@ function status_linux {
	| awk -F"x" '{print $2}'`
	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
		for bdf in $(iter_all_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)
			device=$(cat /sys/bus/pci/devices/$bdf/device)