2018-10-09 18:26:27 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-11-02 15:49:40 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# Copyright (C) 2018 Intel Corporation
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
2020-12-04 10:08:46 +00:00
|
|
|
shopt -s nullglob
|
2023-03-08 10:00:04 +00:00
|
|
|
set -e
|
2018-10-09 18:26:27 +00:00
|
|
|
|
|
|
|
rootdir=$(readlink -f $(dirname $0))/..
|
|
|
|
allowed_drivers=("igb_uio" "uio_pci_generic")
|
|
|
|
|
2020-12-04 10:08:46 +00:00
|
|
|
reload_intel_qat() {
|
|
|
|
# We need to make sure the out-of-tree intel_qat driver, provided via vm_setup.sh, is in
|
|
|
|
# use. Otherwise, some dependency modules loaded by qat_service may fail causing some
|
|
|
|
# disturbance later on during the tests - in particular, it's been seen that the adf_ctl
|
|
|
|
# was returning inconsistent data (wrong pci addresses), confusing the service into
|
|
|
|
# believing SR-IOV is not enabled.
|
|
|
|
|
|
|
|
# If this file doesn't exist, then either intel_qat is a kernel built-in or is not loaded.
|
|
|
|
# Nothing to do in such cases, qat_service will load the module for us.
|
|
|
|
[[ -e /sys/module/intel_qat/taint ]] || return 0
|
|
|
|
|
|
|
|
local t v
|
|
|
|
t=$(< /sys/module/intel_qat/taint)
|
|
|
|
v=$(< /sys/module/intel_qat/version)
|
|
|
|
|
|
|
|
# OE - out-of-tree, unsigned. By the very default, drivers built via vm_setup.sh are not
|
|
|
|
# signed.
|
|
|
|
[[ -z $t || $t != *"OE"* ]] || return 0
|
|
|
|
|
|
|
|
# Check the version of loaded module against the version of the same module as seen
|
|
|
|
# from .dep. perspective. if these are the same the most likely something is broken
|
|
|
|
# with the dependencies. We report a failure in such a case since reloading the module
|
|
|
|
# won't do any good anyway.
|
|
|
|
|
|
|
|
if [[ $(modinfo -F version intel_qat) == "$v" ]]; then
|
|
|
|
cat <<- WARN
|
|
|
|
Upstream intel_qat driver detected. Same version of the driver is seen
|
|
|
|
in modules dependencies: $v. This may mean QAT build didn't update
|
|
|
|
dependencies properly. QAT setup may fail, please, rebuild the QAT
|
|
|
|
driver.
|
|
|
|
WARN
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Ok, intel_qat is an upstream module, replace it with the out-of-tree one.
|
|
|
|
echo "Reloading intel_qat module"
|
|
|
|
|
|
|
|
local h=(/sys/module/intel_qat/holders/*)
|
|
|
|
h=("${h[@]##*/}")
|
|
|
|
|
|
|
|
modprobe -r "${h[@]}" intel_qat
|
|
|
|
# qat_service does that too, but be vigilant
|
|
|
|
modprobe -a intel_qat "${h[@]}"
|
|
|
|
}
|
|
|
|
|
2021-01-26 10:44:10 +00:00
|
|
|
# Please note that this script is not intended to be comprehensive or production quality.
|
2018-10-09 18:26:27 +00:00
|
|
|
# It supports configuring a single card (the Intel QAT 8970) for use with the SPDK
|
|
|
|
|
|
|
|
bad_driver=true
|
|
|
|
driver_to_bind=uio_pci_generic
|
|
|
|
|
2023-03-08 10:00:04 +00:00
|
|
|
reload_intel_qat
|
|
|
|
|
|
|
|
_qat_pci_bdfs=(
|
|
|
|
/sys/bus/pci/drivers/c6xx/0000*
|
|
|
|
/sys/bus/pci/drivers/dh895xcc/0000*
|
|
|
|
)
|
|
|
|
|
|
|
|
qat_pci_bdfs=("${_qat_pci_bdfs[@]#*drivers/}")
|
|
|
|
|
2018-10-09 18:26:27 +00:00
|
|
|
if [ ${#qat_pci_bdfs[@]} -eq 0 ]; then
|
|
|
|
echo "No QAT devices found. Exiting"
|
2021-10-21 09:40:42 +00:00
|
|
|
exit 1
|
2018-10-09 18:26:27 +00:00
|
|
|
fi
|
|
|
|
|
2019-07-25 13:01:09 +00:00
|
|
|
if [ -n "$1" ]; then
|
2018-10-09 18:26:27 +00:00
|
|
|
driver_to_bind=$1
|
|
|
|
fi
|
|
|
|
|
2019-11-25 11:21:54 +00:00
|
|
|
for driver in "${allowed_drivers[@]}"; do
|
2018-10-09 18:26:27 +00:00
|
|
|
if [ $driver == $driver_to_bind ]; then
|
|
|
|
bad_driver=false
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if $bad_driver; then
|
|
|
|
echo "Unrecognized driver. Please specify an accepted driver (listed below):"
|
|
|
|
echo "${allowed_drivers[@]}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-11-13 20:35:16 +00:00
|
|
|
# try starting the qat service. If this doesn't work, just treat it as a warning for now.
|
2020-03-31 11:49:27 +00:00
|
|
|
if ! service qat_service start; then
|
2018-11-13 20:35:16 +00:00
|
|
|
echo "failed to start the qat service. Something may be wrong with your 01.org driver."
|
2018-10-09 18:26:27 +00:00
|
|
|
fi
|
|
|
|
|
2023-03-08 10:00:04 +00:00
|
|
|
expected_num_vfs=0 set_num_vfs=0
|
2018-10-09 18:26:27 +00:00
|
|
|
# configure virtual functions for the QAT cards.
|
2019-11-25 11:21:54 +00:00
|
|
|
for qat_bdf in "${qat_pci_bdfs[@]}"; do
|
2023-03-08 10:00:04 +00:00
|
|
|
if [[ ! -e /sys/bus/pci/drivers/$qat_bdf/sriov_numvfs ]]; then
|
|
|
|
echo "(${qat_bdf##*/}) sriov_numvfs interface missing, is SR-IOV enabled?"
|
2020-12-02 11:48:18 +00:00
|
|
|
continue
|
|
|
|
fi
|
2023-03-08 10:00:04 +00:00
|
|
|
num_vfs=$(< "/sys/bus/pci/drivers/$qat_bdf/sriov_totalvfs")
|
|
|
|
echo "$num_vfs" > /sys/bus/pci/drivers/$qat_bdf/sriov_numvfs
|
|
|
|
num_vfs_set=$(< "/sys/bus/pci/drivers/$qat_bdf/sriov_numvfs")
|
2020-12-02 11:48:18 +00:00
|
|
|
if ((num_vfs != num_vfs_set)); then
|
|
|
|
echo "Number of VFs set to $num_vfs_set, expected $num_vfs"
|
|
|
|
else
|
2023-03-08 10:00:04 +00:00
|
|
|
echo "${qat_bdf##*/} set to $num_vfs VFs"
|
2020-12-02 11:48:18 +00:00
|
|
|
fi
|
2023-03-08 10:00:04 +00:00
|
|
|
((expected_num_vfs += num_vfs))
|
|
|
|
((set_num_vfs += num_vfs_set))
|
2018-10-09 18:26:27 +00:00
|
|
|
done
|
|
|
|
|
2023-03-08 10:00:04 +00:00
|
|
|
# Build VF list out of qat_pci_bdfs[@] by slapping /virtfn* to the path to know if we got'em all.
|
|
|
|
# shellcheck disable=SC2206 # <- intentional
|
|
|
|
qat_vf_bdfs=(${_qat_pci_bdfs[@]/%//virtfn*})
|
2018-10-09 18:26:27 +00:00
|
|
|
|
2023-03-08 10:00:04 +00:00
|
|
|
if ((expected_num_vfs != set_num_vfs || ${#qat_vf_bdfs[@]} != expected_num_vfs)); then
|
|
|
|
echo "Failed to prepare the VFs. Aborting" >&2
|
2018-10-09 18:26:27 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
modprobe uio
|
|
|
|
|
|
|
|
# Insert the dpdk uio kernel module.
|
|
|
|
if [ $driver_to_bind == "igb_uio" ]; then
|
2021-01-26 10:44:10 +00:00
|
|
|
if ! modprobe igb_uio; then
|
|
|
|
echo "Unable to insert the igb_uio kernel module. Aborting."
|
|
|
|
exit 1
|
2018-10-09 18:26:27 +00:00
|
|
|
fi
|
|
|
|
elif [ "$driver_to_bind" == "uio_pci_generic" ]; then
|
|
|
|
modprobe uio_pci_generic
|
|
|
|
else
|
|
|
|
echo "Unsure how to work with driver $driver_to_bind. Please configure it in qat_setup.sh"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-03-08 10:00:04 +00:00
|
|
|
# Unbind old driver if necessary.
|
2019-11-25 11:21:54 +00:00
|
|
|
for vf in "${qat_vf_bdfs[@]}"; do
|
2023-03-08 10:00:04 +00:00
|
|
|
vf=$(readlink -f "$vf")
|
|
|
|
if [[ -e $vf/driver ]]; then
|
|
|
|
old_driver=$(basename "$(readlink -f "$vf/driver")")
|
|
|
|
if [[ $old_driver != "$driver_to_bind" ]]; then
|
|
|
|
echo "unbinding driver $old_driver from qat VF at BDF ${vf##*/}"
|
|
|
|
echo "${vf##*/}" > "/sys/bus/pci/drivers/$old_driver/unbind"
|
2018-10-09 18:26:27 +00:00
|
|
|
fi
|
|
|
|
fi
|
2023-03-08 10:00:04 +00:00
|
|
|
echo "$driver_to_bind" > "$vf/driver_override"
|
|
|
|
echo "${vf##*/}" > /sys/bus/pci/drivers_probe
|
2018-10-09 18:26:27 +00:00
|
|
|
done
|
2023-03-08 10:00:04 +00:00
|
|
|
|
2018-10-09 18:26:27 +00:00
|
|
|
echo "Properly configured the qat device with driver $driver_to_bind."
|