Script D: Switchdev Mode with LAG Configuration
The following commands are used to create and bring up a VF in switchdev mode, and to configure LAG in active-backup mode. ice_lag DDP package can be downloaded from Git Repository and it can be found in this path: linux-firmware/intel/ice/ddp-lag). ===========================================================================================
#!/bin/bash set -x
#set -e
DEVLINK=devlink
PF1=ens2f0
PF1_PCI="pci/0000:17:00.0"
PF2=ens2f1
BR=br1
VF1_PCI=0000:17:01.0
VF1=ens2f0v0
VF1_MAC= ea:fe:27:fa:5d:a6
VF1_IP=172.31.123.11
MASK=24
VF1_PR=eth0
UL_PR=ens2f0
BOND=bond0
#1. Load bonding driver
modprobe bonding mode=active-backup miimon=100 max_bonds=1
or
ip link add $<BOND> type bond mode active-backup miimon 100
#2. Create a bridge
ip link add $<BR> type bridge
#3. Change the eswitch mode to switchdev and create a VF
devlink dev eswitch set $<PF1_PCI> mode switchdev
echo <num_of_VFs> > /sys/class/net/$<PF1>/device/sriov_numvfs
#4. Add the PF interfaces to bond
ip l s $<PF1> master $<BOND>
ip l s $<PF2> master $<BOND>
#5. Verify in the dmesg that the PF1 is the active one
dmesg -wH
#6. Add the bond interface to the bridge
ip link set $<BOND>master $<BR>
#7. Add the port representor to the bridge
ip l s $<VF_PR> master $<BR>
#8. Bring all the interfaces up
ip l s $<PF1> up
ip l s $<PF2> up
ip l s $<VF_PR> up
ip l s $<BOND>up
ip l s $<BR> up
#9. Configure IP address on the VF and send traffic to the VF
ip addr add $VF1_IP/$MASK dev $VF1
#10. Check the bonding mode and current active slave
cat /proc/net/bonding/$BOND
#11. To offload tc filters to the hardware hw-tc-offload must be enabled on the VFs Port Representor (VF_PR)
ethtool -K $PF1 hw-tc-offload on
ethtool -K $VF1_PR hw-tc-offload on
# Verify settings:
ethtool -k $PF1 | grep "hw-tc"
ethtool -k $VF1_PR | grep "hw-tc"
#12. Enable ingress qdisc on PF1 (Uplink port) and VF Port Representors
$TC qdisc add dev $PF1_ingress
$TC qdisc add dev $VF1 ingress
#13. Add filter with skip_sw to offload to hardware
$TC filter add dev $VF1_PR ingress protocol ip prio 1 flower src_mac $VF1_MAC dst_mac
$PEER_MAC skip_sw action mirred egress redirect dev $PF1
$TC filter add dev $PF1 ingress protocol ip prio 1 flower src_mac $PEER_MAC dst_mac
$VF1_MAC skip_sw action mirred egress redirect dev $VF1_PR
#14. Change active slave to second PF
ifenslave $BOND $PF2 -c
or
echo $PF2 > /sys/class/net/$BOND/bonding/active_slave
#15. Verify the active slave change in the dmesg and also in the bonding mode
cat /proc/net/bonding/$BOND
===========================================================================================