1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# A driver for the ETS selftest that implements testing in offloaded datapath.
5lib_dir=$(dirname $0)/../../../net/forwarding
6source $lib_dir/sch_ets_core.sh
7source $lib_dir/devlink_lib.sh
8source qos_lib.sh
9
10ALL_TESTS="
11	ping_ipv4
12	priomap_mode
13	ets_test_strict
14	ets_test_mixed
15	ets_test_dwrr
16"
17
18PARENT="parent 3:3"
19
20switch_create()
21{
22	# Create a bottleneck so that the DWRR process can kick in.
23	tc qdisc replace dev $swp2 root handle 3: tbf rate 1gbit \
24		burst 128K limit 1G
25
26	ets_switch_create
27
28	# Set the ingress quota high and use the three egress TCs to limit the
29	# amount of traffic that is admitted to the shared buffers. This makes
30	# sure that there is always enough traffic of all types to select from
31	# for the DWRR process.
32	devlink_port_pool_th_save $swp1 0
33	devlink_port_pool_th_set $swp1 0 12
34	devlink_tc_bind_pool_th_save $swp1 0 ingress
35	devlink_tc_bind_pool_th_set $swp1 0 ingress 0 12
36	devlink_port_pool_th_save $swp2 4
37	devlink_port_pool_th_set $swp2 4 12
38	devlink_tc_bind_pool_th_save $swp2 7 egress
39	devlink_tc_bind_pool_th_set $swp2 7 egress 4 5
40	devlink_tc_bind_pool_th_save $swp2 6 egress
41	devlink_tc_bind_pool_th_set $swp2 6 egress 4 5
42	devlink_tc_bind_pool_th_save $swp2 5 egress
43	devlink_tc_bind_pool_th_set $swp2 5 egress 4 5
44
45	# Note: sch_ets_core.sh uses VLAN ingress-qos-map to assign packet
46	# priorities at $swp1 based on their 802.1p headers. ingress-qos-map is
47	# not offloaded by mlxsw as of this writing, but the mapping used is
48	# 1:1, which is the mapping currently hard-coded by the driver.
49}
50
51switch_destroy()
52{
53	devlink_tc_bind_pool_th_restore $swp2 5 egress
54	devlink_tc_bind_pool_th_restore $swp2 6 egress
55	devlink_tc_bind_pool_th_restore $swp2 7 egress
56	devlink_port_pool_th_restore $swp2 4
57	devlink_tc_bind_pool_th_restore $swp1 0 ingress
58	devlink_port_pool_th_restore $swp1 0
59
60	ets_switch_destroy
61
62	tc qdisc del dev $swp2 root handle 3:
63}
64
65# Callback from sch_ets_tests.sh
66collect_stats()
67{
68	local -a streams=("$@")
69	local stream
70
71	# Wait for qdisc counter update so that we don't get it mid-way through.
72	busywait_for_counter 1000 +1 \
73		qdisc_parent_stats_get $swp2 10:$((${streams[0]} + 1)) .bytes \
74		> /dev/null
75
76	for stream in ${streams[@]}; do
77		qdisc_parent_stats_get $swp2 10:$((stream + 1)) .bytes
78	done
79}
80
81bail_on_lldpad
82ets_run
83