Path: blob/master/tools/testing/selftests/drivers/net/mlxsw/qos_pfc.sh
26292 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# This test injects a 10-MB burst of traffic with VLAN tag and 802.1p priority4# of 1. This stream is consistently prioritized as priority 1, is put to PG5# buffer 1, and scheduled at TC 1.6#7# - the stream first ingresses through $swp1, where it is forwarded to $swp38#9# - then it ingresses through $swp4. Here it is put to a lossless buffer and put10# to a small pool ("PFC pool"). The traffic is forwarded to $swp2, which is11# shaped, and thus the PFC pool eventually fills, therefore the headroom12# fills, and $swp3 is paused.13#14# - since $swp3 now can't send traffic, the traffic ingressing $swp1 is kept at15# a pool ("overflow pool"). The overflow pool needs to be large enough to16# contain the whole burst.17#18# - eventually the PFC pool gets some traffic out, headroom therefore gets some19# traffic to the pool, and $swp3 is unpaused again. This way the traffic is20# gradually forwarded from the overflow pool, through the PFC pool, out of21# $swp2, and eventually to $h2.22#23# - if PFC works, all lossless flow packets that ingress through $swp1 should24# also be seen ingressing $h2. If it doesn't, there will be drops due to25# discrepancy between the speeds of $swp1 and $h2.26#27# - it should all play out relatively quickly, so that SLL and HLL will not28# cause drops.29#30# +-----------------------+31# | H1 |32# | + $h1.111 |33# | | 192.0.2.33/28 |34# | | |35# | + $h1 |36# +---|-------------------+ +--------------------+37# | | |38# +---|----------------------|--------------------|---------------------------+39# | + $swp1 $swp3 + + $swp4 |40# | | iPOOL1 iPOOL0 | | iPOOL2 |41# | | ePOOL4 ePOOL5 | | ePOOL4 |42# | | PFC:enabled=1 | | PFC:enabled=1 |43# | +-|----------------------|-+ +-|------------------------+ |44# | | + $swp1.111 $swp3.111 + | | + $swp4.111 | |45# | | | | | |46# | | BR1 | | BR2 | |47# | | | | | |48# | | | | + $swp2.111 | |49# | +--------------------------+ +---------|----------------+ |50# | | |51# | iPOOL0: 500KB dynamic | |52# | iPOOL1: 10MB static | |53# | iPOOL2: 1MB static + $swp2 |54# | ePOOL4: 500KB dynamic | iPOOL0 |55# | ePOOL5: 10MB static | ePOOL6 |56# | ePOOL6: "infinite" static | 200Mbps shaper |57# +-------------------------------------------------------|-------------------+58# |59# +---|-------------------+60# | + $h2 H2 |61# | | |62# | + $h2.111 |63# | 192.0.2.34/28 |64# +-----------------------+65#66# iPOOL0+ePOOL4 is a helper pool for control traffic etc.67# iPOOL1+ePOOL5 are overflow pools.68# iPOOL2+ePOOL6 are PFC pools.6970ALL_TESTS="71ping_ipv472test_qos_pfc73"7475lib_dir=$(dirname $0)/../../../net/forwarding7677NUM_NETIFS=678source $lib_dir/lib.sh79source $lib_dir/devlink_lib.sh8081_1KB=100082_100KB=$((100 * _1KB))83_500KB=$((500 * _1KB))84_1MB=$((1000 * _1KB))85_10MB=$((10 * _1MB))8687h1_create()88{89simple_if_init $h190mtu_set $h1 100009192vlan_create $h1 111 v$h1 192.0.2.33/2893}9495h1_destroy()96{97vlan_destroy $h1 1119899mtu_restore $h1100simple_if_fini $h1101}102103h2_create()104{105simple_if_init $h2106mtu_set $h2 10000107108vlan_create $h2 111 v$h2 192.0.2.34/28109}110111h2_destroy()112{113vlan_destroy $h2 111114115mtu_restore $h2116simple_if_fini $h2117}118119switch_create()120{121local lanes_swp4122local pg1_size123124# pools125# -----126127devlink_pool_size_thtype_save 0128devlink_pool_size_thtype_save 4129devlink_pool_size_thtype_save 1130devlink_pool_size_thtype_save 5131devlink_pool_size_thtype_save 2132devlink_pool_size_thtype_save 6133134devlink_port_pool_th_save $swp1 1135devlink_port_pool_th_save $swp2 6136devlink_port_pool_th_save $swp3 5137devlink_port_pool_th_save $swp4 2138139devlink_tc_bind_pool_th_save $swp1 1 ingress140devlink_tc_bind_pool_th_save $swp2 1 egress141devlink_tc_bind_pool_th_save $swp3 1 egress142devlink_tc_bind_pool_th_save $swp4 1 ingress143144# Control traffic pools. Just reduce the size. Keep them dynamic so that145# we don't need to change all the uninteresting quotas.146devlink_pool_size_thtype_set 0 dynamic $_500KB147devlink_pool_size_thtype_set 4 dynamic $_500KB148149# Overflow pools.150devlink_pool_size_thtype_set 1 static $_10MB151devlink_pool_size_thtype_set 5 static $_10MB152153# PFC pools. As per the writ, the size of egress PFC pool should be154# infinice, but actually it just needs to be large enough to not matter155# in practice, so reuse the 10MB limit.156devlink_pool_size_thtype_set 2 static $_1MB157devlink_pool_size_thtype_set 6 static $_10MB158159# $swp1160# -----161162ip link set dev $swp1 up163mtu_set $swp1 10000164vlan_create $swp1 111165ip link set dev $swp1.111 type vlan ingress-qos-map 0:0 1:1166167devlink_port_pool_th_set $swp1 1 $_10MB168devlink_tc_bind_pool_th_set $swp1 1 ingress 1 $_10MB169170# Configure qdisc so that we can configure PG and therefore pool171# assignment.172tc qdisc replace dev $swp1 root handle 1: \173ets bands 8 strict 8 priomap 7 6174dcb buffer set dev $swp1 prio-buffer all:0 1:1175176# $swp2177# -----178179ip link set dev $swp2 up180mtu_set $swp2 10000181vlan_create $swp2 111182ip link set dev $swp2.111 type vlan egress-qos-map 0:0 1:1183184devlink_port_pool_th_set $swp2 6 $_10MB185devlink_tc_bind_pool_th_set $swp2 1 egress 6 $_10MB186187# prio 0->TC0 (band 7), 1->TC1 (band 6). TC1 is shaped.188tc qdisc replace dev $swp2 root handle 1: \189ets bands 8 strict 8 priomap 7 6190tc qdisc replace dev $swp2 parent 1:7 handle 17: \191tbf rate 200Mbit burst 131072 limit 1M192193# $swp3194# -----195196ip link set dev $swp3 up197mtu_set $swp3 10000198vlan_create $swp3 111199ip link set dev $swp3.111 type vlan egress-qos-map 0:0 1:1200201devlink_port_pool_th_set $swp3 5 $_10MB202devlink_tc_bind_pool_th_set $swp3 1 egress 5 $_10MB203204# prio 0->TC0 (band 7), 1->TC1 (band 6)205tc qdisc replace dev $swp3 root handle 1: \206ets bands 8 strict 8 priomap 7 6207208# Need to enable PFC so that PAUSE takes effect. Therefore need to put209# the lossless prio into a buffer of its own. Don't bother with buffer210# sizes though, there is not going to be any pressure in the "backward"211# direction.212dcb buffer set dev $swp3 prio-buffer all:0 1:1213dcb pfc set dev $swp3 prio-pfc all:off 1:on214215# $swp4216# -----217218ip link set dev $swp4 up219mtu_set $swp4 10000220vlan_create $swp4 111221ip link set dev $swp4.111 type vlan ingress-qos-map 0:0 1:1222223devlink_port_pool_th_set $swp4 2 $_1MB224devlink_tc_bind_pool_th_set $swp4 1 ingress 2 $_1MB225226# Configure qdisc so that we can hand-tune headroom.227tc qdisc replace dev $swp4 root handle 1: \228ets bands 8 strict 8 priomap 7 6229dcb buffer set dev $swp4 prio-buffer all:0 1:1230dcb pfc set dev $swp4 prio-pfc all:off 1:on231# PG0 will get autoconfigured to Xoff, give PG1 arbitrarily 100K, which232# is (-2*MTU) about 80K of delay provision.233pg1_size=$_100KB234235setup_wait_dev_with_timeout $swp4236237lanes_swp4=$(ethtool $swp4 | grep 'Lanes:')238lanes_swp4=${lanes_swp4#*"Lanes: "}239240# 8-lane ports use two buffers among which the configured buffer241# is split, so double the size to get twice (20K + 80K).242if [[ $lanes_swp4 -eq 8 ]]; then243pg1_size=$((pg1_size * 2))244fi245246dcb buffer set dev $swp4 buffer-size all:0 1:$pg1_size247248# bridges249# -------250251ip link add name br1 type bridge vlan_filtering 0252ip link set dev $swp1.111 master br1253ip link set dev $swp3.111 master br1254ip link set dev br1 up255256ip link add name br2 type bridge vlan_filtering 0257ip link set dev $swp2.111 master br2258ip link set dev $swp4.111 master br2259ip link set dev br2 up260}261262switch_destroy()263{264# Do this first so that we can reset the limits to values that are only265# valid for the original static / dynamic setting.266devlink_pool_size_thtype_restore 6267devlink_pool_size_thtype_restore 5268devlink_pool_size_thtype_restore 4269devlink_pool_size_thtype_restore 2270devlink_pool_size_thtype_restore 1271devlink_pool_size_thtype_restore 0272273# bridges274# -------275276ip link set dev br2 down277ip link set dev $swp4.111 nomaster278ip link set dev $swp2.111 nomaster279ip link del dev br2280281ip link set dev br1 down282ip link set dev $swp3.111 nomaster283ip link set dev $swp1.111 nomaster284ip link del dev br1285286# $swp4287# -----288289dcb buffer set dev $swp4 buffer-size all:0290dcb pfc set dev $swp4 prio-pfc all:off291dcb buffer set dev $swp4 prio-buffer all:0292tc qdisc del dev $swp4 root293294devlink_tc_bind_pool_th_restore $swp4 1 ingress295devlink_port_pool_th_restore $swp4 2296297vlan_destroy $swp4 111298mtu_restore $swp4299ip link set dev $swp4 down300301# $swp3302# -----303304dcb pfc set dev $swp3 prio-pfc all:off305dcb buffer set dev $swp3 prio-buffer all:0306tc qdisc del dev $swp3 root307308devlink_tc_bind_pool_th_restore $swp3 1 egress309devlink_port_pool_th_restore $swp3 5310311vlan_destroy $swp3 111312mtu_restore $swp3313ip link set dev $swp3 down314315# $swp2316# -----317318tc qdisc del dev $swp2 parent 1:7319tc qdisc del dev $swp2 root320321devlink_tc_bind_pool_th_restore $swp2 1 egress322devlink_port_pool_th_restore $swp2 6323324vlan_destroy $swp2 111325mtu_restore $swp2326ip link set dev $swp2 down327328# $swp1329# -----330331dcb buffer set dev $swp1 prio-buffer all:0332tc qdisc del dev $swp1 root333334devlink_tc_bind_pool_th_restore $swp1 1 ingress335devlink_port_pool_th_restore $swp1 1336337vlan_destroy $swp1 111338mtu_restore $swp1339ip link set dev $swp1 down340}341342setup_prepare()343{344h1=${NETIFS[p1]}345swp1=${NETIFS[p2]}346347swp2=${NETIFS[p3]}348h2=${NETIFS[p4]}349350swp3=${NETIFS[p5]}351swp4=${NETIFS[p6]}352353h2mac=$(mac_get $h2)354355vrf_prepare356357h1_create358h2_create359switch_create360}361362cleanup()363{364pre_cleanup365366switch_destroy367h2_destroy368h1_destroy369370vrf_cleanup371}372373ping_ipv4()374{375ping_test $h1 192.0.2.34376}377378test_qos_pfc()379{380RET=0381382# 10M pool, each packet is 8K of payload + headers383local pkts=$((_10MB / 8050))384local size=$((pkts * 8050))385local in0=$(ethtool_stats_get $swp1 rx_octets_prio_1)386local out0=$(ethtool_stats_get $swp2 tx_octets_prio_1)387388$MZ $h1 -p 8000 -Q 1:111 -A 192.0.2.33 -B 192.0.2.34 \389-a own -b $h2mac -c $pkts -t udp -q390sleep 2391392local in1=$(ethtool_stats_get $swp1 rx_octets_prio_1)393local out1=$(ethtool_stats_get $swp2 tx_octets_prio_1)394395local din=$((in1 - in0))396local dout=$((out1 - out0))397398local pct_in=$((din * 100 / size))399400((pct_in > 95 && pct_in < 105))401check_err $? "Relative ingress out of expected bounds, $pct_in% should be 100%"402403((dout == din))404check_err $? "$((din - dout)) bytes out of $din ingressed got lost"405406log_test "PFC"407}408409bail_on_lldpad "configure DCB" "configure Qdiscs"410411trap cleanup EXIT412setup_prepare413setup_wait414tests_run415416exit $EXIT_STATUS417418419