-
Notifications
You must be signed in to change notification settings - Fork 114
/
switchdev-configuration-before-nm.sh.yaml
78 lines (67 loc) · 2.42 KB
/
switchdev-configuration-before-nm.sh.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
mode: 0755
overwrite: true
path: "/usr/local/bin/switchdev-configuration-before-nm.sh"
contents:
inline: |
#!/bin/bash
set -eux
input="/etc/sriov-operator/sriov_config.json"
UDEV_RULE_FILE='/etc/udev/rules.d/10-persistent-net.rules'
if [ ! -f $input ]; then
echo "File /etc/sriov-operator/sriov_config.json not exist."
exit
fi
which jq
append_to_file(){
content="$1"
file_name="$2"
if ! test -f "$file_name"
then
echo "$content" > "$file_name"
else
if ! grep -Fxq "$content" "$file_name"
then
echo "$content" >> "$file_name"
fi
fi
}
add_udev_rule_for_sriov_pf(){
pf_pci=$(grep PCI_SLOT_NAME /sys/class/net/$1/device/uevent | cut -d'=' -f2)
udev_data_line="SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?*\", KERNELS==\"$pf_pci\", NAME=\"$1\""
append_to_file "$udev_data_line" "$UDEV_RULE_FILE"
}
jq -c '.interfaces[]' ${input} | while read iface;do
num_vfs=$(echo $iface | jq '.numVfs' -r)
pci_addr=$(echo $iface | jq '.pciAddress' -r)
echo "Set $num_vfs VFs on device $pci_addr"
# create VFs
echo $num_vfs > /sys/bus/pci/devices/${pci_addr}/sriov_numvfs
done
# wait for vfs to be ready
sleep 5
jq -c '.interfaces[]' $input | while read iface;
do
eswitch_mode=$(echo $iface | jq '.eSwitchMode' -r)
if [[ "$eswitch_mode" == "switchdev" ]]; then
pci_addr=$(echo $iface | jq '.pciAddress' -r)
name=$(echo $iface | jq '.name' -r)
# Create udev rule to save PF name
add_udev_rule_for_sriov_pf $name
echo "Unload VF driver for $pci_addr"
VfDirs=$(ls /sys/bus/pci/devices/${pci_addr} | grep virtfn)
for VfDir in $VfDirs
do
VfPciAddr=$(basename "$( readlink -f /sys/bus/pci/devices/${pci_addr}/$VfDir )")
echo $VfPciAddr > /sys/bus/pci/drivers/mlx5_core/unbind || true
done
# set flow steering mode before entering switchdev mode
echo "Set flow steering mode to smfs"
devlink dev param set pci/${pci_addr} name flow_steering_mode value smfs cmode runtime
# set PF to switchdev mode
echo "Set eswitch mode to switchdev"
devlink dev eswitch set pci/${pci_addr} mode switchdev
ip link set ${name} up
# turn hw-tc-offload on
/usr/sbin/ethtool -K ${name} hw-tc-offload on
fi
done