-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqat_setup.sh
executable file
·152 lines (127 loc) · 5.1 KB
/
qat_setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env bash
shopt -s nullglob
rootdir=$(readlink -f $(dirname $0))/..
igb_driverdir=$rootdir/dpdk/build-tmp/kernel/linux/igb_uio/
allowed_drivers=("igb_uio" "uio_pci_generic")
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[@]}"
}
# This script requires an igb_uio kernel module binary located at $igb_driverdir/igb_uio.ko
# Please also note that this script is not intended to be comprehensive or production quality.
# It supports configuring a single card (the Intel QAT 8970) for use with the SPDK
bad_driver=true
driver_to_bind=uio_pci_generic
num_vfs=16
qat_pci_bdfs=($(lspci -Dd:37c8 | awk '{print $1}'))
if [ ${#qat_pci_bdfs[@]} -eq 0 ]; then
echo "No QAT devices found. Exiting"
exit 0
fi
if [ -n "$1" ]; then
driver_to_bind=$1
fi
for driver in "${allowed_drivers[@]}"; do
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
reload_intel_qat
# try starting the qat service. If this doesn't work, just treat it as a warning for now.
if ! service qat_service start; then
echo "failed to start the qat service. Something may be wrong with your 01.org driver."
fi
# configure virtual functions for the QAT cards.
for qat_bdf in "${qat_pci_bdfs[@]}"; do
if [[ ! -e /sys/bus/pci/drivers/c6xx/$qat_bdf/sriov_numvfs ]]; then
echo "($qat_bdf) sriov_numvfs interface missing, is SR-IOV enabled?"
continue
fi
echo "$num_vfs" > /sys/bus/pci/drivers/c6xx/$qat_bdf/sriov_numvfs
num_vfs_set=$(cat /sys/bus/pci/drivers/c6xx/$qat_bdf/sriov_numvfs)
if ((num_vfs != num_vfs_set)); then
echo "Number of VFs set to $num_vfs_set, expected $num_vfs"
else
echo "$qat_bdf set to $num_vfs VFs"
fi
done
# Confirm we have all of the virtual functions we asked for.
qat_vf_bdfs=($(lspci -Dd:37c9 | awk '{print $1}'))
if ((${#qat_vf_bdfs[@]} != ${#qat_pci_bdfs[@]} * num_vfs)); then
echo "Failed to prepare the VFs. Aborting"
exit 1
fi
# Unbind old driver if necessary.
for vf in "${qat_vf_bdfs[@]}"; do
old_driver=$(basename $(readlink -f /sys/bus/pci/devices/${vf}/driver))
if [ $old_driver != "driver" ]; then
echo "unbinding driver $old_driver from qat VF at BDF $vf"
echo -n $vf > /sys/bus/pci/drivers/$old_driver/unbind
fi
done
modprobe uio
# Insert the dpdk uio kernel module.
if [ $driver_to_bind == "igb_uio" ]; then
if ! lsmod | grep -q igb_uio; then
if ! insmod $igb_driverdir/igb_uio.ko; then
echo "Unable to insert the igb_uio kernel module. Aborting."
exit 1
fi
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
echo -n "8086 37c9" > /sys/bus/pci/drivers/$driver_to_bind/new_id
for vf in "${qat_vf_bdfs[@]}"; do
if ! ls -l /sys/bus/pci/devices/$vf/driver | grep -q $driver_to_bind; then
echo "unable to bind the driver to the device at bdf $vf"
if [ "$driver_to_bind" == "uio_pci_generic" ]; then
echo "Your kernel's uio_pci_generic module does not support binding to virtual functions."
echo "It likely is missing Linux git commit ID acec09e67 which is needed to bind"
echo "uio_pci_generic to virtual functions which have no legacy interrupt vector."
echo "Please build DPDK kernel module for igb_uio and re-run this script specifying the igb_uio driver."
fi
exit 1
fi
done
echo "Properly configured the qat device with driver $driver_to_bind."