2 # SPDX-License-Identifier: GPL-2.0
4 # This test sends many small packets (size is less than cell size) through the
5 # switch. A shaper is used in $swp2, so the traffic is limited there. Packets
6 # are queued till they will be sent.
8 # The idea is to verify that the switch can handle at least 85% of maximum
9 # supported descrpitors by hardware. Then, we verify that the driver configures
10 # firmware to allow infinite size of egress descriptor pool, and does not use a
11 # lower limitation. Increase the size of the relevant pools such that the pool's
12 # size does not limit the traffic.
14 # +-----------------------+
20 # +---|-------------------+
22 # +---|-----------------------------+
26 # | +-|------------------------+ |
32 # | +-|------------------------+ |
37 # +---+-----------------------------+
39 # +---|-------------------+
44 # +-----------------------+
52 lib_dir=$(dirname $0)/../../../net/forwarding
55 source $lib_dir/lib.sh
56 source $lib_dir/devlink_lib.sh
59 MAX_POOL_SIZE=$(devlink_pool_size_get)
62 # The current TBF qdisc interface does not allow us to configure the shaper to
63 # flat zero. The ASIC shaper is guaranteed to work with a granularity of
64 # 200Mbps. On Spectrum-2, writing a value close to zero instead of zero works
65 # well, but the performance on Spectrum-1 is unpredictable. Thus, do not run the
67 mlxsw_only_on_spectrum 2+ || exit
73 vlan_create $h1 111 v$h1 192.0.2.33/28
74 ip link set dev $h1.111 type vlan egress-qos-map 0:1
88 vlan_create $h2 111 v$h2 192.0.2.34/28
103 devlink_pool_size_thtype_save 1
104 devlink_pool_size_thtype_save 6
106 devlink_port_pool_th_save $swp1 1
107 devlink_port_pool_th_save $swp2 6
109 devlink_tc_bind_pool_th_save $swp1 1 ingress
110 devlink_tc_bind_pool_th_save $swp2 1 egress
112 devlink_pool_size_thtype_set 1 dynamic $MAX_POOL_SIZE
113 devlink_pool_size_thtype_set 6 static $MAX_POOL_SIZE
118 ip link set dev $swp1 up
119 vlan_create $swp1 111
120 ip link set dev $swp1.111 type vlan ingress-qos-map 0:0 1:1
122 devlink_port_pool_th_set $swp1 1 16
123 devlink_tc_bind_pool_th_set $swp1 1 ingress 1 16
125 tc qdisc replace dev $swp1 root handle 1: \
126 ets bands 8 strict 8 priomap 7 6
127 dcb buffer set dev $swp1 prio-buffer all:0 1:1
132 ip link set dev $swp2 up
133 vlan_create $swp2 111
134 ip link set dev $swp2.111 type vlan egress-qos-map 0:0 1:1
136 devlink_port_pool_th_set $swp2 6 $MAX_POOL_SIZE
137 devlink_tc_bind_pool_th_set $swp2 1 egress 6 $MAX_POOL_SIZE
139 tc qdisc replace dev $swp2 root handle 1: tbf rate $SHAPER_RATE \
140 burst 128K limit 500M
141 tc qdisc replace dev $swp2 parent 1:1 handle 11: \
142 ets bands 8 strict 8 priomap 7 6
147 ip link add name br1 type bridge vlan_filtering 0
148 ip link set dev $swp1.111 master br1
149 ip link set dev br1 up
151 ip link set dev $swp2.111 master br1
156 # Do this first so that we can reset the limits to values that are only
157 # valid for the original static / dynamic setting.
158 devlink_pool_size_thtype_restore 6
159 devlink_pool_size_thtype_restore 1
164 ip link set dev $swp2.111 nomaster
166 ip link set dev br1 down
167 ip link set dev $swp1.111 nomaster
173 tc qdisc del dev $swp2 parent 1:1 handle 11:
174 tc qdisc del dev $swp2 root
176 devlink_tc_bind_pool_th_restore $swp2 1 egress
177 devlink_port_pool_th_restore $swp2 6
179 vlan_destroy $swp2 111
180 ip link set dev $swp2 down
185 dcb buffer set dev $swp1 prio-buffer all:0
186 tc qdisc del dev $swp1 root
188 devlink_tc_bind_pool_th_restore $swp1 1 ingress
189 devlink_port_pool_th_restore $swp1 1
191 vlan_destroy $swp1 111
192 ip link set dev $swp1 down
225 ping_test $h1 192.0.2.34 " h1->h2"
230 local num_packets=$1; shift
231 local max_packets=$1; shift
235 100 * $num_packets / $max_packets
241 local cell_size=$(devlink_cell_size_get)
242 local exp_perc_used=85
243 local max_descriptors
248 max_descriptors=$(mlxsw_max_descriptors_get) || exit 1
250 local d0=$(ethtool_stats_get $swp2 tc_no_buffer_discard_uc_tc_1)
252 log_info "Send many small packets, packet size = $pktsize bytes"
253 start_traffic_pktsize $pktsize $h1.111 192.0.2.33 192.0.2.34 $h2mac
255 # Sleep to wait for congestion.
258 local d1=$(ethtool_stats_get $swp2 tc_no_buffer_discard_uc_tc_1)
260 check_err $? "Drops seen on egress port: $d0 -> $d1 ($((d1 - d0)))"
262 # Check how many packets the switch can handle, the limitation is
263 # maximum descriptors.
264 local pkts_bytes=$(ethtool_stats_get $swp2 tc_transmit_queue_tc_1)
265 local pkts_num=$((pkts_bytes / cell_size))
266 local perc_used=$(percentage_used $pkts_num $max_descriptors)
268 check_err $(bc <<< "$perc_used < $exp_perc_used") \
269 "Expected > $exp_perc_used% of descriptors, handle $perc_used%"
274 log_test "Maximum descriptors usage. The percentage used is $perc_used%"