3 uio_drivers="igb_uio uio_pci_generic vfio-pci"
9 modalias=$(cat $selection/modalias)
10 native_drv=$(modprobe -R $modalias)
13 for drv in $native_drv $uio_drivers; do
14 if [ -e /sys/bus/pci/drivers/$drv ]; then
16 drv_desc=$(modinfo $drv | grep description: | sed -e 's/.*:[[:space:]]\+//' )
18 array+=("${drv_desc}")
21 dialog --backtitle "PCI NIC Bind Utility" \
23 --menu "Select kernel driver" 18 100 12 \
24 "${array[@]}" 2> $tmpfile
26 selection=$(cat $tmpfile)
28 if [ $retval -ne 0 ]; then
31 vd=$(cat /sys/bus/pci/devices/${addr}/vendor /sys/bus/pci/devices/${addr}/device)
32 echo $addr | tee /sys/bus/pci/devices/${addr}/driver/unbind > /dev/null 2> /dev/null
33 echo $vd | tee /sys/bus/pci/drivers/${selection}/new_id > /dev/null 2> /dev/null
34 echo $addr | tee /sys/bus/pci/drivers/${selection}/bind > /dev/null 2> /dev/null
37 function find_pci_slot() {
39 [ ! "$(ls -A /sys/bus/pci/slots )" ] && echo "No PCI slot data" && return
40 for slot in $(find /sys/bus/pci/slots/* -maxdepth 0 -exec basename {} \;); do
41 slot_addr=$(cat /sys/bus/pci/slots/$slot/address)
42 if [[ "${addr}" == *"${slot_addr}"* ]]; then
43 echo "PCI slot: ${slot}"
47 echo "Unknown PCI slot"
50 ! type -ap dialog > /dev/null && echo "Please install dialog (apt-get install dialog)" && exit
51 if [ $USER != "root" ] ; then
52 echo "Restarting script with sudo..."
57 cd /sys/bus/pci/devices
62 class=$(cat ${addr}/class)
63 if [ "$class" = "0x020000" ]; then
64 name=$(lspci -s $addr | sed -e 's/.*: //')
65 if [ -e "/sys/bus/pci/devices/$addr/driver" ]; then
66 drv=$(basename $(readlink -f /sys/bus/pci/devices/$addr/driver))
70 slot=$(find_pci_slot ${addr})
72 array+=("${drv}|${name}")
77 dialog --backtitle "PCI NIC Bind Utility" \
80 --column-separator '|' \
81 --menu "Select NIC" 18 100 12 \
82 "${array[@]}" 2> $tmpfile
85 selection=$(cat $tmpfile)
87 if [ $retval -ne 0 ]; then