Shell to setup the nic driver interfaces. This script is given a list of PCI addresses, and will unbind the current running linux driver and bind the pci-vfio driver there instead. Also enable user permission for vfio groups... Must be run as root. When sourced, also sets the ODP_PKTIO_IF<n> environment variables. For instance, syntax is: source pktio_setup_nic 0000:23:00.0 0000:23:00.1 The usage of this script is still manual. It is meant to be called in the future pktio_run_nic script in the future.
Signed-off-by: Christophe Milard <christophe.mil...@linaro.org> --- platform/linux-generic/test/pktio/pktio_setup_nic | 105 ++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100755 platform/linux-generic/test/pktio/pktio_setup_nic diff --git a/platform/linux-generic/test/pktio/pktio_setup_nic b/platform/linux-generic/test/pktio/pktio_setup_nic new file mode 100755 index 0000000..640930c --- /dev/null +++ b/platform/linux-generic/test/pktio/pktio_setup_nic @@ -0,0 +1,105 @@ +#!/bin/bash +#this script must be run as root (modprobe etc...) + +setup_vfio() { + user=$1 + shift + + #iommu should be running for the following to work: + #on intel, put kernel boot option "intel_iommu=on" + + #read the PCI group it belongs to: + grp=`readlink /sys/bus/pci/devices/${target}/iommu_group ` + grp=`echo ${grp} | grep -o '[^/]*$'` + echo target ${target} is in group: ${grp} + + modprobe vfio-pci + + #collect the PCI vendor:ID of the selected device: + addr=`lspci -n -mm -s ${target} | cut -d' ' -f3-4 | sed -e's/"//g'` + + #unbind the current driver: + echo ${target} > /sys/bus/pci/devices/${target}/driver/unbind + + #and bind it to the vfio-pci driver + #Binding the device to the vfio-pci driver creates the VFIO group + #character devices for this group: + + echo ${addr} > /sys/bus/pci/drivers/vfio-pci/new_id + + #Now we need to look at what other devices are in the group to free + #it for use by VFIO: + + #check manually that no other devices are in the same group: + #If more than the PCI bridge is listed here, remove these + #devices manually from the group. + #ls -l /sys/bus/pci/devices/${target}/iommu_group/devices + + #give user access to the group: + chown $user:$user /dev/vfio/${grp} + #to ba able to map the config space??? not possible via vfio!?? + chmod a+rw /sys/bus/pci/devices/${target}/config +} + +usage() { + prog=$1 + echo -e "$prog [user=<user>] <pci_address> [<pci_address>*]" + echo -e "\t for instance: $prog 0000:23:00.0 0000:23:00.1" + echo -e "\t or $prog user=donaldduck 0000:23:00.0 0000:23:00.1" + echo -e "\t the script will attempt to sudo if not root." + echo -e "\t Environment variables ODP_PKTIO_IF<n> are set if sourced." + echo -e "It is assumed that the differents devices belongs to different " + echo -e "vfio groups." + echo +} + +############################### MAIN ######################### + +#collect the name of the program being run +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + prog=${BASH_SOURCE[0]} + sourced=yes +else + sourced=no + prog=$0 +fi + + +#help? +if [[ "x$1" = "x-h" || "x$1" = "x--help" || "x$1" = "x" ]]; then + usage $prog + if [[ "$sourced" = yes ]]; then + return 0 + else + exit 0 + fi +fi + +#check if first arg is user=<user> (with no space): +#default to current user if no user given +first_arg=$1 +if [[ ${first_arg:0:5} = 'user=' ]]; then + user=$(echo $first_arg| cut -d'=' -f 2) + shift +else + user=$(whoami) +fi + +##root? : do real setup: +index=0 +if [[ "$(id -u)" = "0" ]]; then + for target in $*; do + echo "setting up ${target}" + setup_vfio $user ${target} + export ODP_PKTIO_IF${index}="pmd:${target}" + export ODP_WAIT_FOR_NETWORK=1 + ((index++)) + done +else #try to sudo + sudo $prog "user=$user" $* + for target in $*; do + export ODP_PKTIO_IF${index}="pmd:${target}" + export ODP_WAIT_FOR_NETWORK=1 + ((index++)) + done +fi -- 2.1.4 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp