카테고리 없음

SR-IOV NIC PF/VF 정보 조회

zzerog 2021. 7. 8. 13:03
728x90

실행 결과

$ sudo ./nic.sh 
================================================================================
[PF]: NIC        numa     pci_id          vendor:device        driver    # of VF
================================================================================
      p7p1     1        0000:86:00.0    8086:158B            i40e      8
      p7p2     1        0000:86:00.1    8086:158B            i40e      0
================================================================================
================================================================================
[VF]:  PF            VF_idx     pci_id          vendor:device     driver
================================================================================
         p7p1 ( 8)
                     vf#0       0000:86:02.0    8086:154C           iavf
                     vf#1       0000:86:02.1    8086:154C           iavf
                     vf#2       0000:86:02.2    8086:154C           iavf
                     vf#3       0000:86:02.3    8086:154C           iavf
                     vf#4       0000:86:02.4    8086:154C           iavf
                     vf#5       0000:86:02.5    8086:154C           iavf
                     vf#6       0000:86:02.6    8086:154C           iavf
                     vf#7       0000:86:02.7    8086:154C           iavf
         p7p2 ( 0)
================================================================================

스크립트

#!/bin/bash

pfmax=0
vfmax=0

device=()
numa=()
pci=()
vendor=()
driver=()

#######################################
# Get device/numa information and save to device Array
##

idx=0
for i in `lshw -c network -businfo | egrep "[0-9]+G" | cut -d " " -f 3`
do
    device[$idx]=$i
    numa[$idx]=`cat /sys/class/net/"${device[$idx]}"/device/numa_node`
    #echo "$idx: ${device[$idx]}- ${numa[$idx]}"
    ((idx++))
    ((pfmax++))
done


#######################################
## Get PF's pci information and save to pci array
##
idx=0

while [ $idx -lt $pfmax ]
do
    pci[$idx]=`cat /sys/class/net/"${device[$idx]}"/device/uevent | grep PCI_SLOT_NAME | cut -d "=" -f 2`
    #echo "$idx: ${pci[$idx]}"
    ((idx++))
done

#######################################
## Get PF's vendor/device information and save to vendor array
##
idx=0

while [ $idx -lt $pfmax ]
do
    vendor[$idx]=`cat /sys/class/net/"${device[$idx]}"/device/uevent | grep PCI_ID | cut -d "=" -f 2`
    #echo "$idx: ${pci[$idx]}"
    ((idx++))
done

#######################################
## Get PF's driver information and save to vendor array
##
idx=0

while [ $idx -lt $pfmax ]
do
    driver[$idx]=`cat /sys/class/net/"${device[$idx]}"/device/uevent | grep DRIVER | cut -d "=" -f 2`
    #echo "$idx: ${pci[$idx]}"
    ((idx++))
done


#######################################
## Get number of VF per each PF and save numVF array
##
idx=0

while [ $idx -lt $pfmax ]
do
    numVF[$idx]=`cat /sys/class/net/"${device[$idx]}"/device/sriov_numvfs`
    vfmax=`expr $vfmax + ${numVF[$idx]}`
    ((idx++))
done
    #echo "$vfmax"


#######################################
## Print PF Information to Screen
##
echo "================================================================================"
echo "[PF]: NIC        numa     pci_id          vendor:device        driver    # of VF"
echo "================================================================================"
for ((i=0;i<$pfmax;i++))
do
#    echo "      ${device[$i]}     ${numa[$i]}           `lspci -nn | grep -i eth | grep "${pci[$i]}"`"
    echo "      ${device[$i]}     ${numa[$i]}        ${pci[$i]}    ${vendor[$i]}            ${driver[$i]}      ${numVF[$i]}"

done
echo "================================================================================"



#########################################################################################
vfdevice=()
vfpci=()
vfvendor=()
vfdriver=()



#######################################
# Get VF's device information and save to device Array
##
idx=0


#for i in `lshw -c network -businfo | egrep -i "illegal|Virtual" | cut -d " " -f 3`
#do
#    vfdevice[$idx]=$i
#    echo "$idx: ${vfdevice[$idx]}"
#    ((idx++))
#done

#######################################
# Get VF's pci_id information and save to pci Array
##
idx=0


for i in `lshw -c network -businfo | egrep -i "illegal|Virtual" | cut -d " " -f 1 | cut -d "@" -f 2`
do
    vfpci[$idx]=$i
#    echo "$idx: ${vfpci[$idx]}"
    ((idx++))
done



#######################################
## Get VF's vender:device information and save to vfvendor array
##

idx=0

while [ $idx -lt $vfmax ]
do
    aaa=`echo ${vfpci[$idx]} | cut -c 1-7`
    vfvendor[$idx]=`cat /sys/class/pci_bus/$aaa/device//"${vfpci[$idx]}"/uevent | grep PCI_ID | cut -d "=" -f 2`
#    echo "$idx: ${vfvendor[$idx]}"
    ((idx++))
done

#######################################
## Get VF's driver information and save to vfdriver array
##

idx=0

while [ $idx -lt $vfmax ]
do
    aaa=`echo ${vfpci[$idx]} | cut -c 1-7`
    vfdriver[$idx]=`cat /sys/class/pci_bus/$aaa/device//"${vfpci[$idx]}"/uevent | grep DRIVER | cut -d "=" -f 2`
#    echo "$idx: ${vfdriver[$idx]}"
    ((idx++))
done


#######################################
## Print VF Information to Screen
##

echo "================================================================================"
echo "[VF]:  PF            VF_idx     pci_id          vendor:device     driver"
echo "================================================================================"


k=0
i=0
for aa in "${device[@]}"
do
    printf " %12s (%2s)\n" $aa ${numVF[$i]}
    if [ "${numVF[$i]}" -eq "0" ]
    then
        ((i++))
        continue
    fi
    y=0
    while [ ${i} -le $vfmax ]
    do
        printf "                     vf#%-2s      %12s    %6s         %6s\n" $y   ${vfpci[$k]}   ${vfvendor[$k]}   ${vfdriver[$k]}
        ((y++))
        ((k++))
        if [ $y -eq ${numVF[$i]} ]
        then
            break;
        fi
    done
    ((i++))
done
echo "================================================================================"

실행 결과

$ ./sriov.sh 
Virtual Functions on Intel Corporation Ethernet Controller XXV710 for 25GbE SFP28. (p7p1):
PCI BDF         Interface
=======         =========
0000:86:02.0    p7p1_0
0000:86:02.1    p7p1_1
0000:86:02.2    p7p1_2
0000:86:02.3    p7p1_3
0000:86:02.4    p7p1_4
0000:86:02.5    p7p1_5
0000:86:02.6    p7p1_6
0000:86:02.7    p7p1_7

스크립트

#!/bin/bash

NIC_DIR="/sys/class/net"
for i in $( ls $NIC_DIR) ;
do
	if [ -d "${NIC_DIR}/$i/device" -a ! -L "${NIC_DIR}/$i/device/physfn" ]; then
		declare -a VF_PCI_BDF
		declare -a VF_INTERFACE
		k=0
		for j in $( ls "${NIC_DIR}/$i/device" ) ;
		do
			if [[ "$j" == "virtfn"* ]]; then
				VF_PCI=$( readlink "${NIC_DIR}/$i/device/$j" | cut -d '/' -f2 )
				VF_PCI_BDF[$k]=$VF_PCI
				#get the interface name for the VF at this PCI Address
				for iface in $( ls $NIC_DIR );
				do
					link_dir=$( readlink ${NIC_DIR}/$iface )
					if [[ "$link_dir" == *"$VF_PCI"* ]]; then
						VF_INTERFACE[$k]=$iface
					fi
				done
				((k++))
			fi
		done
		NUM_VFs=${#VF_PCI_BDF[@]}
		if [[ $NUM_VFs -gt 0 ]]; then
			#get the PF Device Description
			PF_PCI=$( readlink "${NIC_DIR}/$i/device" | cut -d '/' -f4 )
			PF_VENDOR=$( lspci -vmmks $PF_PCI | grep ^Vendor | cut -f2)
			PF_NAME=$( lspci -vmmks $PF_PCI | grep ^Device | cut -f2).
			echo "Virtual Functions on $PF_VENDOR $PF_NAME ($i):"
			echo -e "PCI BDF\t\tInterface"
			echo -e "=======\t\t========="
			for (( l = 0; l < $NUM_VFs; l++ )) ;
			do
				echo -e "${VF_PCI_BDF[$l]}\t${VF_INTERFACE[$l]}"
			done
			unset VF_PCI_BDF
			unset VF_INTERFACE
			echo " "
		fi
	fi
done
반응형