1#!/usr/bin/env bash 2 3rootdir=$(readlink -f $(dirname $0))/.. 4igb_driverdir=$rootdir/dpdk/build/build/kernel/igb_uio/ 5allowed_drivers=("igb_uio" "uio_pci_generic") 6 7# This script requires an igb_uio kernel module binary located at $igb_driverdir/igb_uio.ko 8# Please also note that this script is not intended to be comprehensive or production quality. 9# It supports configuring a single card (the Intel QAT 8970) for use with the SPDK 10 11bad_driver=true 12driver_to_bind=uio_pci_generic 13num_vfs=16 14 15qat_pci_bdfs=( $(lspci -Dd:37c8 | awk '{print $1}') ) 16if [ ${#qat_pci_bdfs[@]} -eq 0 ]; then 17 echo "No QAT devices found. Exiting" 18 exit 0 19fi 20 21if [ -n "$1" ]; then 22 driver_to_bind=$1 23fi 24 25for driver in "${allowed_drivers[@]}"; do 26 if [ $driver == $driver_to_bind ]; then 27 bad_driver=false 28 fi 29done 30 31if $bad_driver; then 32 echo "Unrecognized driver. Please specify an accepted driver (listed below):" 33 echo "${allowed_drivers[@]}" 34 exit 1 35fi 36 37# try starting the qat service. If this doesn't work, just treat it as a warning for now. 38if ! service qat_service start; then 39 echo "failed to start the qat service. Something may be wrong with your 01.org driver." 40fi 41 42# configure virtual functions for the QAT cards. 43for qat_bdf in "${qat_pci_bdfs[@]}"; do 44 echo "$num_vfs" > /sys/bus/pci/drivers/c6xx/$qat_bdf/sriov_numvfs 45 num_vfs=$(cat /sys/bus/pci/drivers/c6xx/$qat_bdf/sriov_numvfs) 46 echo "$qat_bdf set to $num_vfs VFs" 47done 48 49# Confirm we have all of the virtual functions we asked for. 50 51qat_vf_bdfs=( $(lspci -Dd:37c9 | awk '{print $1}') ) 52if (( ${#qat_vf_bdfs[@]} != ${#qat_pci_bdfs[@]}*num_vfs )); then 53 echo "Failed to prepare the VFs. Aborting" 54 exit 1 55fi 56 57# Unbind old driver if necessary. 58for vf in "${qat_vf_bdfs[@]}"; do 59 old_driver=$(basename $(readlink -f /sys/bus/pci/devices/${vf}/driver)) 60 if [ $old_driver != "driver" ]; then 61 echo "unbinding driver $old_driver from qat VF at BDF $vf" 62 echo -n $vf > /sys/bus/pci/drivers/$old_driver/unbind 63 fi 64done 65 66modprobe uio 67 68# Insert the dpdk uio kernel module. 69if [ $driver_to_bind == "igb_uio" ]; then 70 if ! lsmod | grep -q igb_uio; then 71 if ! insmod $igb_driverdir/igb_uio.ko; then 72 echo "Unable to insert the igb_uio kernel module. Aborting." 73 exit 1 74 fi 75 fi 76elif [ "$driver_to_bind" == "uio_pci_generic" ]; then 77 modprobe uio_pci_generic 78else 79 echo "Unsure how to work with driver $driver_to_bind. Please configure it in qat_setup.sh" 80 exit 1 81fi 82 83echo -n "8086 37c9" > /sys/bus/pci/drivers/$driver_to_bind/new_id 84for vf in "${qat_vf_bdfs[@]}"; do 85 if ! ls -l /sys/bus/pci/devices/$vf/driver | grep -q $driver_to_bind; then 86 echo "unable to bind the driver to the device at bdf $vf" 87 if [ "$driver_to_bind" == "uio_pci_generic" ]; then 88 echo "Your kernel's uio_pci_generic module does not support binding to virtual functions." 89 echo "It likely is missing Linux git commit ID acec09e67 which is needed to bind" 90 echo "uio_pci_generic to virtual functions which have no legacy interrupt vector." 91 echo "Please rebuild spdk with --with-igb-uio-driver and re-run this script specifying the igb_uio driver." 92 fi 93 exit 1 94 fi 95done 96echo "Properly configured the qat device with driver $driver_to_bind." 97