Skip to content

Commit

Permalink
Adapt link name script for reuse native NIC port
Browse files Browse the repository at this point in the history
Uplink rep NIC port won't be re-created when goes to switchdev mode,
rename native NIC port when driver loads.

Signed-off-by: Bodong Wang <[email protected]>
Signed-off-by: Vladimir Sokolovsky <[email protected]>
  • Loading branch information
vladsokolovsky committed Jun 25, 2020
1 parent caf305e commit 161c13c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
11 changes: 9 additions & 2 deletions kernel-boot/82-net-setup-link.rules
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
SUBSYSTEM=="net", ACTION=="add", ATTR{phys_switch_id}!="", ATTR{phys_port_name}!="", \
IMPORT{program}="/lib/udev/vf-net-link-name.sh $attr{phys_switch_id} $attr{phys_port_name}" \
NAME="$env{NAME}", RUN+="/sbin/ethtool -L $env{NAME} combined 4"
IMPORT{program}="/lib/udev/vf-net-link-name.sh $attr{phys_port_name} $attr{phys_switch_id}" \
NAME="$env{NAME}", GOTO="net_setup_skip_link_name"

SUBSYSTEM=="net", ACTION=="add", ATTR{phys_port_name}!="", \
IMPORT{program}="/lib/udev/vf-net-link-name.sh $attr{phys_port_name}" \
NAME="$env{NAME}"

LABEL="net_setup_skip_link_name"
RUN+="/sbin/ethtool -L $env{NAME} combined 4"
16 changes: 11 additions & 5 deletions kernel-boot/vf-net-link-name.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/bash

SWID=$1
SWID=$2
# might be pf0vf1 so only get vf number
PORT=${2##*f}
PORT_NAME=$2
PORT=${1##*f}
PORT_NAME=$1

# need the PATH for BF ARM lspci to work
PATH=/bin:/sbin:/usr/bin:/usr/sbin

is_bf=`lspci -s 00:00.0 2> /dev/null | grep -wq "PCI bridge: Mellanox Technologies" && echo 1 || echo 0`
if [ $is_bf -eq 1 ]; then
echo NAME=`echo ${2} | sed -e "s/vf-1/hpf/;s/\(pf[[:digit:]]\+\)p.*/\1m0/"`
echo NAME=`echo ${1} | sed -e "s/\(pf[[:digit:]]\+\)$/\1hpf/"`
exit 0
fi

Expand All @@ -25,6 +25,10 @@ if [ -n "$ID_NET_NAME_PATH" ]; then
exit
fi

if [ -z "$SWID" ]; then
exit 0
fi

# for SF mdev devices
function get_sf_rep_name() {
b=`udevadm info -q property -p /sys/bus/pci/devices/$1/net/* | grep "ID_PATH=" | cut -d- -f2 | cut -d: -f2`
Expand Down Expand Up @@ -85,7 +89,9 @@ function get_pci_port_name() {

# for vf rep get parent slot/path.
parent_phys_port_name=${PORT_NAME%vf*}
parent_phys_port_name=${parent_phys_port_name//f}
parent_phys_port_name=${parent_phys_port_name//pf}
((parent_phys_port_name&=0x7))
parent_phys_port_name="p$parent_phys_port_name"
# try at most two times
for cnt in {1..2}; do
for pci in `ls -l /sys/class/net/*/device | cut -d "/" -f9-`; do
Expand Down

0 comments on commit 161c13c

Please sign in to comment.