Goglides Dev 🌱

Balkrishna Pandey
Balkrishna Pandey

Posted on

How to Check SRIOV NIC Card and Map Network Interface Name which is using it?

Anyone who doesn't know about Single Root I/O Virtualization (SR-IOV), it is a technology that enables sharing a single physical network interface controller (NIC) among multiple virtual machines (VMs) while providing each VM with a dedicated and isolated virtual function (VF).

Recently, a vendor reached out to me with some questions about the network interface cards (NICs), which has SR-IOV capabilities, on the worker nodes of a system. Specifically, they wanted to know,

  • The drivers running on each NIC, along with their complete versions.
  • the hardware model of the NICs, along with their minor version
  • and the correct firmware version.

This information was essential for the vendor to ensure compatibility and optimal performance of their products with the NICs on the system.

You can easily identify these information using ethtool. The major challenge was identifying SR-IOV interface.

If you're also looking for ways to obtain this information, there are several commands that you can use to get the details of the NICs on your system. This article will discuss using lspci, and ethtool Linux commands to obtain the necessary information about your system's NICs with SR-IOV capabilities.

If you know better way please comment below.

Step 1: Check SR-IOV Support using lspci -vvv

The first step is to verify if your NIC card supports SR-IOV. You can use the lspci command with the -vvv option to display detailed information about the device. To list information only for SR-IOV-supported devices, here's an awk command that will look for the string "SR-IOV" within the device section and print the entire section if it is found:

lspci -vv | awk '/^[[:xdigit:]]{2}:/ {device=$0} /SR-IOV/ {print device; found=1} END {if (!found) print "SR-IOV not found."}'
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • lspci -vv produces the output that we're processing.
  • The first pattern /^[[:xdigit:]]{2}:/ matches lines that start with a hexadecimal number followed by a colon. These lines contain the device name and will be stored in the variable device.
  • The second pattern, /SR-IOV/, matches lines containing the " SR-IOV " string. When this pattern is matched, we print the contents of the device variable, which includes the entire device section.
  • Finally, the END block checks if the string "SR-IOV" was found in any device section. If not, it prints a message indicating "SR-IOV not found."

Here is the output of the above command looks like,

01:00.0 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
01:00.1 Ethernet controller: Intel Corporation I350 Gigabit Network Connection (rev 01)
0e:00.0 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
0e:00.1 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
81:00.0 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
81:00.1 Ethernet controller: Intel Corporation 82599ES 10-Gigabit SFI/SFP+ Network Connection (rev 01)
Enter fullscreen mode Exit fullscreen mode

If you want just to find device id you can adjust your awk as follows,

lspci -vv | awk '/^[[:xdigit:]]{2}:/ {device=$1} /SR-IOV/ {print device; found=1} END {if (!found) print "SR-IOV not found."}'
Enter fullscreen mode Exit fullscreen mode

Output:

01:00.0
01:00.1
0e:00.0
0e:00.1
81:00.0
81:00.1
Enter fullscreen mode Exit fullscreen mode

Now you can see more information by passing this device ID to the lspci command as follows,

lspci -vv | awk '/^[[:xdigit:]]{2}:/ {device=$1} /SR-IOV/ {print device; found=1} END {if (!found) print "SR-IOV not found."}' | xargs -I {} lspci -vvv -s {}
Enter fullscreen mode Exit fullscreen mode

The xargs command is used to pass the output of one command as an argument to another command. In this case, xargs takes the output of the awk command (which contains the device ID with SR-IOV support) and passes it as an argument to the lspci command to get more detailed information about that specific device.
The -I {} option tells xargs to use{} as a placeholder for the argument passed from the previous command.
So the overall command can be broken down into the following steps:

  1. lspci -vv: This command lists all PCI devices in verbose mode.
  2. awk '/^[[:xdigit:]]{2}:/ {device=$1} /SR-IOV/ {print device; found=1} END {if (!found) print "SR-IOV not found."}': This command processes the output of lspci -vv using awk to find the device ID of the device that has SR-IOV support. It then prints the device ID if it finds SR-IOV, or prints "SR-IOV not found" if it doesn't find SR-IOV.
  3. xargs -I {} lspci -vvv -s {}: This command takes the device ID output by awk and passes it as an argument to lspci -vvv -s {}, which provides more detailed information about the device with that ID.

Step 2: Identify the Network Interface Name using ethtool -i

Once you have identified the device that supports SR-IOV, you can use the ethtool command to identify the network interface name that uses the SR-IOV-enabled NIC card. The following command will display the details of the network interface:

ethtool -i <interface_name>
Enter fullscreen mode Exit fullscreen mode

Replace <interface_name> with the name of your network interface. This command will provide you with the network interface's driver name, firmware version, and bus information.
Here is one example,

ethtool -i enp14s0f1
driver: ixgbe
version: 4.18.0-305.65.1.el8_4.x86_64
firmware-version: 0x800008a4
expansion-rom-version: 
bus-info: 0000:0e:00.1
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: yes
Enter fullscreen mode Exit fullscreen mode

Since there are many physical and virtual interfaces, comparing them manually can be quite challenging. However, the ethtool -i command displays information about the driver and firmware for the interface, as well as the PCI bus information for the interface, including the PCI device ID. These details are also present in the lspci output. You can use the grep command to extract the necessary information.
The output of this command will look something like this:

bus-info: 0000:0e:00.1
driver: ixgbe
Enter fullscreen mode Exit fullscreen mode

The bus-info field contains the PCI bus information, including the device ID, and the driver field specifies the driver name. By comparing the output of the ethtool -i command with the lspci output, you can identify the interfaces that correspond to the PCI devices that support SR-IOV.

So I used the following script to identify all interfaces,

for i in `ls /sys/class/net/`; do echo $i; sudo ethtool -i $i ; echo "------"; done | egrep 'ixgbe|igbng f' -B1 -A10
Enter fullscreen mode Exit fullscreen mode

Here your ixgbe|igb value comes from the following scripts.

lspci -vv | awk '/^[[:xdigit:]]{2}:/ {device=$1} /SR-IOV/ {print device; found=1} END {if (!found) print "SR-IOV not found."}' | xargs -I {} lspci -vvv -s {} | grep "Kernel driverin use" | uniq 
Enter fullscreen mode Exit fullscreen mode

Note:
"If you're an Ansible user and prefer automation for network configuration, you may want to check out the work of my good friend and colleague, Karim Latouche. He has created an excellent script that automates the configuration of SR-IOV VF interfaces. You can find the script on GitHub."

Top comments (0)