4 # https://gerrit.akraino.org/r/#/c/icn/+/1359/1/deploy/kud-plugin-addons/device-plugins/sriov/driver/install_iavf_drivers.sh
6 nic_models=(X710 XL710 X722)
8 device_checkers=(is_not_used is_driver_match is_model_match)
10 function install_iavf_driver {
13 echo "Installing modules..."
14 echo "Installing i40evf blacklist file..."
15 mkdir -p "/etc/modprobe.d/"
16 echo "blacklist i40evf" > "/etc/modprobe.d/iavf-blacklist-i40evf.conf"
18 kver=`uname -a | awk '{print $3}'`
19 install_mod_dir=/lib/modules/$kver/updates/drivers/net/ethernet/intel/iavf/
20 echo "Installing driver in $install_mod_dir"
21 mkdir -p $install_mod_dir
22 cp iavf.ko $install_mod_dir
24 echo "Installing kernel module i40evf..."
29 echo "Enabling VF on interface $ifname..."
30 echo "/sys/class/net/$ifname/device/sriov_numvfs"
31 echo '8' > /sys/class/net/$ifname/device/sriov_numvfs
34 function is_not_used {
36 route_info=`ip route show | grep $ifname`
37 if [ -z "$route_info" ]; then
44 function is_driver_match {
46 driver=`cat /sys/class/net/$ifname/device/uevent | grep DRIVER | cut -f2 -d "="`
47 if [ ! -z "$driver" ]; then
48 for nic_driver in ${nic_drivers[@]}; do
49 if [ "$driver" = "$nic_driver" ]; then
57 function is_model_match {
59 pci_addr=`cat /sys/class/net/$ifname/device/uevent | grep PCI_SLOT_NAME | cut -f2 -d "=" | cut -f2,3 -d ":"`
60 if [ ! -z "$pci_addr" ]; then
61 for nic_model in ${nic_models[@]}; do
62 model_match=$(lspci | grep $pci_addr | grep $nic_model)
63 if [ ! -z "$model_match" ]; then
71 function get_sriov_ifname {
72 for net_device in /sys/class/net/*/ ; do
73 if [ -e $net_device/device/sriov_numvfs ] ; then
74 ifname=$(basename $net_device)
75 for device_checker in ${device_checkers[@]}; do
76 eval $device_checker $ifname
77 if [ "$?" = "0" ]; then
82 if [ ! -z "$ifname" ]; then
91 if [ $# -ne 1 ] ; then
92 ifname=$(get_sriov_ifname)
93 if [ -z "$ifname" ]; then
94 echo "Cannot find Nic with SRIOV support."
96 install_iavf_driver $ifname
100 if [ ! -e /sys/class/net/$ifname/device/sriov_numvfs ] ; then
101 echo "${ifname} is not a valid sriov interface"
103 install_iavf_driver $ifname