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
18switch_create()
19{
20	ets_switch_create
21
22	# Create a bottleneck so that the DWRR process can kick in.
23	ethtool -s $h2 speed 1000 autoneg off
24	ethtool -s $swp2 speed 1000 autoneg off
25
26	# Set the ingress quota high and use the three egress TCs to limit the
27	# amount of traffic that is admitted to the shared buffers. This makes
28	# sure that there is always enough traffic of all types to select from
29	# for the DWRR process.
30	devlink_port_pool_th_set $swp1 0 12
31	devlink_tc_bind_pool_th_set $swp1 0 ingress 0 12
32	devlink_port_pool_th_set $swp2 4 12
33	devlink_tc_bind_pool_th_set $swp2 7 egress 4 5
34	devlink_tc_bind_pool_th_set $swp2 6 egress 4 5
35	devlink_tc_bind_pool_th_set $swp2 5 egress 4 5
36
37	# Note: sch_ets_core.sh uses VLAN ingress-qos-map to assign packet
38	# priorities at $swp1 based on their 802.1p headers. ingress-qos-map is
39	# not offloaded by mlxsw as of this writing, but the mapping used is
40	# 1:1, which is the mapping currently hard-coded by the driver.
41}
42
43switch_destroy()
44{
45	devlink_tc_bind_pool_th_restore $swp2 5 egress
46	devlink_tc_bind_pool_th_restore $swp2 6 egress
47	devlink_tc_bind_pool_th_restore $swp2 7 egress
48	devlink_port_pool_th_restore $swp2 4
49	devlink_tc_bind_pool_th_restore $swp1 0 ingress
50	devlink_port_pool_th_restore $swp1 0
51
52	ethtool -s $swp2 autoneg on
53	ethtool -s $h2 autoneg on
54
55	ets_switch_destroy
56}
57
58# Callback from sch_ets_tests.sh
59collect_stats()
60{
61	local -a streams=("$@")
62	local stream
63
64	# Wait for qdisc counter update so that we don't get it mid-way through.
65	busywait_for_counter 1000 +1 \
66		qdisc_parent_stats_get $swp2 10:$((${streams[0]} + 1)) .bytes \
67		> /dev/null
68
69	for stream in ${streams[@]}; do
70		qdisc_parent_stats_get $swp2 10:$((stream + 1)) .bytes
71	done
72}
73
74bail_on_lldpad
75ets_run
76