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: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/c/443767 (master)
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/447148
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Tested-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Pawel Wodkowski 2019-02-07 13:31:06 +01:00 committed by Darek Stojaczyk
parent 29ae45877a
commit 1bf4f98311
2 changed files with 55 additions and 31 deletions

View File

@ -6,7 +6,7 @@
# if PCI_BLACKLIST is empty assume device is NOT blacklistened # if PCI_BLACKLIST is empty assume device is NOT blacklistened
# Params: # Params:
# $1 - PCI BDF # $1 - PCI BDF
function pci_can_bind() { function pci_can_use() {
local i local i
# The '\ ' part is important # The '\ ' part is important
@ -28,7 +28,8 @@ function pci_can_bind() {
return 1 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 class="$(printf %02x $((0x$1)))"
local subclass="$(printf %02x $((0x$2)))" local subclass="$(printf %02x $((0x$2)))"
local progif="$(printf %02x $((0x$3)))" local progif="$(printf %02x $((0x$3)))"
@ -45,7 +46,25 @@ function iter_pci_class_code() {
'{if (cc ~ $2) print $1}' | tr -d '"' '{if (cc ~ $2) print $1}' | tr -d '"'
fi fi
elif hash pciconf &>/dev/null; then 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
echo "Missing PCI enumeration utility"
exit 1
fi
}
# 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)))"
if hash lspci &>/dev/null; then
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
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 ':' ' ')) 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]} printf "%04x:%02x:%02x:%x\n" ${addr[0]} ${addr[1]} ${addr[2]} ${addr[3]}
else else
@ -55,18 +74,23 @@ function iter_pci_class_code() {
} }
function iter_pci_dev_id() { function iter_pci_dev_id() {
local ven_id="$(printf %04x $((0x$1)))" local bdf=""
local dev_id="$(printf %04x $((0x$2)))"
if hash lspci &>/dev/null; then for bdf in $(iter_all_pci_dev_id "$@"); do
lspci -mm -n -D | awk -v ven="\"$ven_id\"" -v dev="\"${dev_id}\"" -F " " \ if pci_can_use "$bdf"; then
'{if (ven ~ $3 && dev ~ $4) print $1}' | tr -d '"' echo "$bdf"
elif hash pciconf &>/dev/null; then
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
echo "Missing PCI enumeration utility"
exit 1
fi 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
} }

View File

@ -178,10 +178,10 @@ function configure_linux_pci {
# NVMe # NVMe
modprobe $driver_name 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='' blkname=''
get_nvme_name_from_bdf "$bdf" 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" pci_dev_echo "$bdf" "Skipping un-whitelisted NVMe controller $blkname"
continue continue
fi fi
@ -204,8 +204,8 @@ function configure_linux_pci {
| awk -F"x" '{print $2}' > $TMP | awk -F"x" '{print $2}' > $TMP
for dev_id in `cat $TMP`; do for dev_id in `cat $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
if ! pci_can_bind $bdf; then if ! pci_can_use $bdf; then
pci_dev_echo "$bdf" "Skipping un-whitelisted I/OAT device" pci_dev_echo "$bdf" "Skipping un-whitelisted I/OAT device"
continue continue
fi fi
@ -222,8 +222,8 @@ function configure_linux_pci {
| awk -F"x" '{print $2}' > $TMP | awk -F"x" '{print $2}' > $TMP
for dev_id in `cat $TMP`; do for dev_id in `cat $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
if ! pci_can_bind $bdf; then if ! pci_can_use $bdf; then
pci_dev_echo "$bdf" "Skipping un-whitelisted Virtio device at $bdf" pci_dev_echo "$bdf" "Skipping un-whitelisted Virtio device at $bdf"
continue continue
fi fi
@ -360,8 +360,8 @@ function reset_linux_pci {
check_for_driver nvme 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_all_pci_class_code 01 08 02); do
if ! pci_can_bind $bdf; then if ! pci_can_use $bdf; then
pci_dev_echo "$bdf" "Skipping un-whitelisted NVMe controller $blkname" pci_dev_echo "$bdf" "Skipping un-whitelisted NVMe controller $blkname"
continue continue
fi fi
@ -383,8 +383,8 @@ function reset_linux_pci {
driver_loaded=$? driver_loaded=$?
set -e set -e
for dev_id in `cat $TMP`; do for dev_id in `cat $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
if ! pci_can_bind $bdf; then if ! pci_can_use $bdf; then
pci_dev_echo "$bdf" "Skipping un-whitelisted I/OAT device" pci_dev_echo "$bdf" "Skipping un-whitelisted I/OAT device"
continue continue
fi fi
@ -409,8 +409,8 @@ function reset_linux_pci {
# underscore vs. dash right in the virtio_scsi name. # underscore vs. dash right in the virtio_scsi name.
modprobe virtio-pci || true modprobe virtio-pci || true
for dev_id in `cat $TMP`; do for dev_id in `cat $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
if ! pci_can_bind $bdf; then if ! pci_can_use $bdf; then
pci_dev_echo "$bdf" "Skipping un-whitelisted Virtio device at" pci_dev_echo "$bdf" "Skipping un-whitelisted Virtio device at"
continue continue
fi fi
@ -464,7 +464,7 @@ function status_linux {
echo "NVMe devices" echo "NVMe devices"
echo -e "BDF\t\tVendor\tDevice\tNUMA\tDriver\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 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}') driver=$(grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}')
node=$(cat /sys/bus/pci/devices/$bdf/numa_node) node=$(cat /sys/bus/pci/devices/$bdf/numa_node)
device=$(cat /sys/bus/pci/devices/$bdf/device) device=$(cat /sys/bus/pci/devices/$bdf/device)
@ -485,7 +485,7 @@ function status_linux {
| awk -F"x" '{print $2}'` | awk -F"x" '{print $2}'`
echo -e "BDF\t\tVendor\tDevice\tNUMA\tDriver" echo -e "BDF\t\tVendor\tDevice\tNUMA\tDriver"
for dev_id in $TMP; do 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}') driver=$(grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}')
node=$(cat /sys/bus/pci/devices/$bdf/numa_node) node=$(cat /sys/bus/pci/devices/$bdf/numa_node)
device=$(cat /sys/bus/pci/devices/$bdf/device) device=$(cat /sys/bus/pci/devices/$bdf/device)
@ -502,7 +502,7 @@ function status_linux {
| awk -F"x" '{print $2}'` | awk -F"x" '{print $2}'`
echo -e "BDF\t\tVendor\tDevice\tNUMA\tDriver\t\tDevice name" echo -e "BDF\t\tVendor\tDevice\tNUMA\tDriver\t\tDevice name"
for dev_id in $TMP; do 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}') driver=$(grep DRIVER /sys/bus/pci/devices/$bdf/uevent |awk -F"=" '{print $2}')
node=$(cat /sys/bus/pci/devices/$bdf/numa_node) node=$(cat /sys/bus/pci/devices/$bdf/numa_node)
device=$(cat /sys/bus/pci/devices/$bdf/device) device=$(cat /sys/bus/pci/devices/$bdf/device)