WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / drivers / net / mlxsw / qos_headroom.sh
blob27de3d9ed08e7ed9513265eb871ef37e1c74e7bc
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS="
5 test_defaults
6 test_dcb_ets
7 test_mtu
8 test_pfc
9 test_int_buf
10 test_tc_priomap
11 test_tc_mtu
12 test_tc_sizes
13 test_tc_int_buf
16 lib_dir=$(dirname $0)/../../../net/forwarding
18 NUM_NETIFS=0
19 source $lib_dir/lib.sh
20 source $lib_dir/devlink_lib.sh
21 source qos_lib.sh
23 swp=$NETIF_NO_CABLE
25 cleanup()
27 pre_cleanup
30 get_prio_pg()
32 __mlnx_qos -i $swp | sed -n '/^PFC/,/^[^[:space:]]/p' |
33 grep buffer | sed 's/ \+/ /g' | cut -d' ' -f 2-
36 get_prio_pfc()
38 __mlnx_qos -i $swp | sed -n '/^PFC/,/^[^[:space:]]/p' |
39 grep enabled | sed 's/ \+/ /g' | cut -d' ' -f 2-
42 get_prio_tc()
44 __mlnx_qos -i $swp | sed -n '/^tc/,$p' |
45 awk '/^tc/ { TC = $2 }
46 /priority:/ { PRIO[$2]=TC }
47 END {
48 for (i in PRIO)
49 printf("%d ", PRIO[i])
53 get_buf_size()
55 local idx=$1; shift
57 __mlnx_qos -i $swp | grep Receive | sed 's/.*: //' | cut -d, -f $((idx + 1))
60 get_tot_size()
62 __mlnx_qos -i $swp | grep Receive | sed 's/.*total_size=//'
65 check_prio_pg()
67 local expect=$1; shift
69 local current=$(get_prio_pg)
70 test "$current" = "$expect"
71 check_err $? "prio2buffer is '$current', expected '$expect'"
74 check_prio_pfc()
76 local expect=$1; shift
78 local current=$(get_prio_pfc)
79 test "$current" = "$expect"
80 check_err $? "prio PFC is '$current', expected '$expect'"
83 check_prio_tc()
85 local expect=$1; shift
87 local current=$(get_prio_tc)
88 test "$current" = "$expect"
89 check_err $? "prio_tc is '$current', expected '$expect'"
92 __check_buf_size()
94 local idx=$1; shift
95 local expr=$1; shift
96 local what=$1; shift
98 local current=$(get_buf_size $idx)
99 ((current $expr))
100 check_err $? "${what}buffer $idx size is '$current', expected '$expr'"
101 echo $current
104 check_buf_size()
106 __check_buf_size "$@" > /dev/null
109 test_defaults()
111 RET=0
113 check_prio_pg "0 0 0 0 0 0 0 0 "
114 check_prio_tc "0 0 0 0 0 0 0 0 "
115 check_prio_pfc "0 0 0 0 0 0 0 0 "
117 log_test "Default headroom configuration"
120 test_dcb_ets()
122 RET=0
124 __mlnx_qos -i $swp --prio_tc=0,2,4,6,1,3,5,7 > /dev/null
126 check_prio_pg "0 2 4 6 1 3 5 7 "
127 check_prio_tc "0 2 4 6 1 3 5 7 "
128 check_prio_pfc "0 0 0 0 0 0 0 0 "
130 __mlnx_qos -i $swp --prio_tc=0,0,0,0,0,0,0,0 > /dev/null
132 check_prio_pg "0 0 0 0 0 0 0 0 "
133 check_prio_tc "0 0 0 0 0 0 0 0 "
135 __mlnx_qos -i $swp --prio2buffer=1,3,5,7,0,2,4,6 &> /dev/null
136 check_fail $? "prio2buffer accepted in DCB mode"
138 log_test "Configuring headroom through ETS"
141 test_mtu()
143 local what=$1; shift
144 local buf0size_2
145 local buf0size
147 RET=0
148 buf0size=$(__check_buf_size 0 "> 0")
150 mtu_set $swp 3000
151 buf0size_2=$(__check_buf_size 0 "> $buf0size" "MTU 3000: ")
152 mtu_restore $swp
154 mtu_set $swp 6000
155 check_buf_size 0 "> $buf0size_2" "MTU 6000: "
156 mtu_restore $swp
158 check_buf_size 0 "== $buf0size"
160 log_test "${what}MTU impacts buffer size"
163 test_tc_mtu()
165 # In TC mode, MTU still impacts the threshold below which a buffer is
166 # not permitted to go.
168 tc qdisc replace dev $swp root handle 1: bfifo limit 1.5M
169 test_mtu "TC: "
170 tc qdisc delete dev $swp root
173 test_pfc()
175 RET=0
177 __mlnx_qos -i $swp --prio_tc=0,0,0,0,0,1,2,3 > /dev/null
179 local buf0size=$(get_buf_size 0)
180 local buf1size=$(get_buf_size 1)
181 local buf2size=$(get_buf_size 2)
182 local buf3size=$(get_buf_size 3)
183 check_buf_size 0 "> 0"
184 check_buf_size 1 "> 0"
185 check_buf_size 2 "> 0"
186 check_buf_size 3 "> 0"
187 check_buf_size 4 "== 0"
188 check_buf_size 5 "== 0"
189 check_buf_size 6 "== 0"
190 check_buf_size 7 "== 0"
192 log_test "Buffer size sans PFC"
194 RET=0
196 __mlnx_qos -i $swp --pfc=0,0,0,0,0,1,1,1 --cable_len=0 > /dev/null
198 check_prio_pg "0 0 0 0 0 1 2 3 "
199 check_prio_pfc "0 0 0 0 0 1 1 1 "
200 check_buf_size 0 "== $buf0size"
201 check_buf_size 1 "> $buf1size"
202 check_buf_size 2 "> $buf2size"
203 check_buf_size 3 "> $buf3size"
205 local buf1size=$(get_buf_size 1)
206 check_buf_size 2 "== $buf1size"
207 check_buf_size 3 "== $buf1size"
209 log_test "PFC: Cable length 0"
211 RET=0
213 __mlnx_qos -i $swp --pfc=0,0,0,0,0,1,1,1 --cable_len=1000 > /dev/null
215 check_buf_size 0 "== $buf0size"
216 check_buf_size 1 "> $buf1size"
217 check_buf_size 2 "> $buf1size"
218 check_buf_size 3 "> $buf1size"
220 log_test "PFC: Cable length 1000"
222 RET=0
224 __mlnx_qos -i $swp --pfc=0,0,0,0,0,0,0,0 --cable_len=0 > /dev/null
225 __mlnx_qos -i $swp --prio_tc=0,0,0,0,0,0,0,0 > /dev/null
227 check_prio_pg "0 0 0 0 0 0 0 0 "
228 check_prio_tc "0 0 0 0 0 0 0 0 "
229 check_buf_size 0 "> 0"
230 check_buf_size 1 "== 0"
231 check_buf_size 2 "== 0"
232 check_buf_size 3 "== 0"
233 check_buf_size 4 "== 0"
234 check_buf_size 5 "== 0"
235 check_buf_size 6 "== 0"
236 check_buf_size 7 "== 0"
238 log_test "PFC: Restore defaults"
241 test_tc_priomap()
243 RET=0
245 __mlnx_qos -i $swp --prio_tc=0,1,2,3,4,5,6,7 > /dev/null
246 check_prio_pg "0 1 2 3 4 5 6 7 "
248 tc qdisc replace dev $swp root handle 1: bfifo limit 1.5M
249 check_prio_pg "0 0 0 0 0 0 0 0 "
251 __mlnx_qos -i $swp --prio2buffer=1,3,5,7,0,2,4,6 > /dev/null
252 check_prio_pg "1 3 5 7 0 2 4 6 "
254 tc qdisc delete dev $swp root
255 check_prio_pg "0 1 2 3 4 5 6 7 "
257 # Clean up.
258 tc qdisc replace dev $swp root handle 1: bfifo limit 1.5M
259 __mlnx_qos -i $swp --prio2buffer=0,0,0,0,0,0,0,0 > /dev/null
260 tc qdisc delete dev $swp root
261 __mlnx_qos -i $swp --prio_tc=0,0,0,0,0,0,0,0 > /dev/null
263 log_test "TC: priomap"
266 test_tc_sizes()
268 local cell_size=$(devlink_cell_size_get)
269 local size=$((cell_size * 1000))
271 RET=0
273 __mlnx_qos -i $swp --buffer_size=$size,0,0,0,0,0,0,0 &> /dev/null
274 check_fail $? "buffer_size should fail before qdisc is added"
276 tc qdisc replace dev $swp root handle 1: bfifo limit 1.5M
278 __mlnx_qos -i $swp --buffer_size=$size,0,0,0,0,0,0,0 > /dev/null
279 check_err $? "buffer_size should pass after qdisc is added"
280 check_buf_size 0 "== $size" "set size: "
282 mtu_set $swp 6000
283 check_buf_size 0 "== $size" "set MTU: "
284 mtu_restore $swp
286 __mlnx_qos -i $swp --buffer_size=0,0,0,0,0,0,0,0 > /dev/null
288 # After replacing the qdisc for the same kind, buffer_size still has to
289 # work.
290 tc qdisc replace dev $swp root handle 1: bfifo limit 1M
292 __mlnx_qos -i $swp --buffer_size=$size,0,0,0,0,0,0,0 > /dev/null
293 check_buf_size 0 "== $size" "post replace, set size: "
295 __mlnx_qos -i $swp --buffer_size=0,0,0,0,0,0,0,0 > /dev/null
297 # Likewise after replacing for a different kind.
298 tc qdisc replace dev $swp root handle 2: prio bands 8
300 __mlnx_qos -i $swp --buffer_size=$size,0,0,0,0,0,0,0 > /dev/null
301 check_buf_size 0 "== $size" "post replace different kind, set size: "
303 tc qdisc delete dev $swp root
305 __mlnx_qos -i $swp --buffer_size=$size,0,0,0,0,0,0,0 &> /dev/null
306 check_fail $? "buffer_size should fail after qdisc is deleted"
308 log_test "TC: buffer size"
311 test_int_buf()
313 local what=$1; shift
315 RET=0
317 local buf0size=$(get_buf_size 0)
318 local tot_size=$(get_tot_size)
320 # Size of internal buffer and buffer 9.
321 local dsize=$((tot_size - buf0size))
323 tc qdisc add dev $swp clsact
324 tc filter add dev $swp egress matchall skip_sw action mirred egress mirror dev $swp
326 local buf0size_2=$(get_buf_size 0)
327 local tot_size_2=$(get_tot_size)
328 local dsize_2=$((tot_size_2 - buf0size_2))
330 # Egress SPAN should have added to the "invisible" buffer configuration.
331 ((dsize_2 > dsize))
332 check_err $? "Invisible buffers account for '$dsize_2', expected '> $dsize'"
334 mtu_set $swp 3000
336 local buf0size_3=$(get_buf_size 0)
337 local tot_size_3=$(get_tot_size)
338 local dsize_3=$((tot_size_3 - buf0size_3))
340 # MTU change might change buffer 0, which will show at total, but the
341 # hidden buffers should stay the same size.
342 ((dsize_3 == dsize_2))
343 check_err $? "MTU change: Invisible buffers account for '$dsize_3', expected '== $dsize_2'"
345 mtu_restore $swp
346 tc qdisc del dev $swp clsact
348 # After SPAN removal, hidden buffers should be back to the original sizes.
349 local buf0size_4=$(get_buf_size 0)
350 local tot_size_4=$(get_tot_size)
351 local dsize_4=$((tot_size_4 - buf0size_4))
352 ((dsize_4 == dsize))
353 check_err $? "SPAN removed: Invisible buffers account for '$dsize_4', expected '== $dsize'"
355 log_test "${what}internal buffer size"
358 test_tc_int_buf()
360 local cell_size=$(devlink_cell_size_get)
361 local size=$((cell_size * 1000))
363 tc qdisc replace dev $swp root handle 1: bfifo limit 1.5M
364 test_int_buf "TC: "
366 __mlnx_qos -i $swp --buffer_size=$size,0,0,0,0,0,0,0 > /dev/null
367 test_int_buf "TC+buffsize: "
369 __mlnx_qos -i $swp --buffer_size=0,0,0,0,0,0,0,0 > /dev/null
370 tc qdisc delete dev $swp root
373 trap cleanup EXIT
375 bail_on_lldpad
376 setup_wait
377 tests_run
379 exit $EXIT_STATUS