xref: /linux/tools/testing/selftests/drivers/net/mlxsw/sharedbuffer.sh (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4ALL_TESTS="
5	port_pool_test
6	port_tc_ip_test
7	port_tc_arp_test
8"
9
10NUM_NETIFS=2
11source ../../../net/forwarding/lib.sh
12source ../../../net/forwarding/devlink_lib.sh
13source mlxsw_lib.sh
14
15SB_POOL_ING=0
16SB_POOL_EGR_CPU=10
17
18SB_ITC_CPU_IP=2
19SB_ITC_CPU_ARP=2
20SB_ITC=0
21
22h1_create()
23{
24	simple_if_init $h1 192.0.1.1/24
25}
26
27h1_destroy()
28{
29	simple_if_fini $h1 192.0.1.1/24
30}
31
32h2_create()
33{
34	simple_if_init $h2 192.0.1.2/24
35}
36
37h2_destroy()
38{
39	simple_if_fini $h2 192.0.1.2/24
40}
41
42sb_occ_pool_check()
43{
44	local dl_port=$1; shift
45	local pool=$1; shift
46	local exp_max_occ=$1
47	local max_occ
48	local err=0
49
50	max_occ=$(devlink sb -j occupancy show $dl_port \
51		  | jq -e ".[][][\"pool\"][\"$pool\"][\"max\"]")
52
53	if [[ "$max_occ" -ne "$exp_max_occ" ]]; then
54		err=1
55	fi
56
57	echo $max_occ
58	return $err
59}
60
61sb_occ_itc_check()
62{
63	local dl_port=$1; shift
64	local itc=$1; shift
65	local exp_max_occ=$1
66	local max_occ
67	local err=0
68
69	max_occ=$(devlink sb -j occupancy show $dl_port \
70		  | jq -e ".[][][\"itc\"][\"$itc\"][\"max\"]")
71
72	if [[ "$max_occ" -ne "$exp_max_occ" ]]; then
73		err=1
74	fi
75
76	echo $max_occ
77	return $err
78}
79
80sb_occ_etc_check()
81{
82	local dl_port=$1; shift
83	local etc=$1; shift
84	local exp_max_occ=$1; shift
85	local max_occ
86	local err=0
87
88	max_occ=$(devlink sb -j occupancy show $dl_port \
89		  | jq -e ".[][][\"etc\"][\"$etc\"][\"max\"]")
90
91	if [[ "$max_occ" -ne "$exp_max_occ" ]]; then
92		err=1
93	fi
94
95	echo $max_occ
96	return $err
97}
98
99port_pool_test()
100{
101	local exp_max_occ=288
102	local max_occ
103
104	devlink sb occupancy clearmax $DEVLINK_DEV
105
106	$MZ $h1 -c 1 -p 160 -a $h1mac -b $h2mac -A 192.0.1.1 -B 192.0.1.2 \
107		-t ip -q
108
109	devlink sb occupancy snapshot $DEVLINK_DEV
110
111	RET=0
112	max_occ=$(sb_occ_pool_check $dl_port1 $SB_POOL_ING $exp_max_occ)
113	check_err $? "Expected iPool($SB_POOL_ING) max occupancy to be $exp_max_occ, but got $max_occ"
114	log_test "physical port's($h1) ingress pool"
115
116	RET=0
117	max_occ=$(sb_occ_pool_check $dl_port2 $SB_POOL_ING $exp_max_occ)
118	check_err $? "Expected iPool($SB_POOL_ING) max occupancy to be $exp_max_occ, but got $max_occ"
119	log_test "physical port's($h2) ingress pool"
120
121	RET=0
122	max_occ=$(sb_occ_pool_check $cpu_dl_port $SB_POOL_EGR_CPU $exp_max_occ)
123	check_err $? "Expected ePool($SB_POOL_EGR_CPU) max occupancy to be $exp_max_occ, but got $max_occ"
124	log_test "CPU port's egress pool"
125}
126
127port_tc_ip_test()
128{
129	local exp_max_occ=288
130	local max_occ
131
132	devlink sb occupancy clearmax $DEVLINK_DEV
133
134	$MZ $h1 -c 1 -p 160 -a $h1mac -b $h2mac -A 192.0.1.1 -B 192.0.1.2 \
135		-t ip -q
136
137	devlink sb occupancy snapshot $DEVLINK_DEV
138
139	RET=0
140	max_occ=$(sb_occ_itc_check $dl_port2 $SB_ITC $exp_max_occ)
141	check_err $? "Expected ingress TC($SB_ITC) max occupancy to be $exp_max_occ, but got $max_occ"
142	log_test "physical port's($h1) ingress TC - IP packet"
143
144	RET=0
145	max_occ=$(sb_occ_itc_check $dl_port2 $SB_ITC $exp_max_occ)
146	check_err $? "Expected ingress TC($SB_ITC) max occupancy to be $exp_max_occ, but got $max_occ"
147	log_test "physical port's($h2) ingress TC - IP packet"
148
149	RET=0
150	max_occ=$(sb_occ_etc_check $cpu_dl_port $SB_ITC_CPU_IP $exp_max_occ)
151	check_err $? "Expected egress TC($SB_ITC_CPU_IP) max occupancy to be $exp_max_occ, but got $max_occ"
152	log_test "CPU port's egress TC - IP packet"
153}
154
155port_tc_arp_test()
156{
157	local exp_max_occ=96
158	local max_occ
159
160	if [[ $MLXSW_CHIP != "mlxsw_spectrum" ]]; then
161		exp_max_occ=144
162	fi
163
164	devlink sb occupancy clearmax $DEVLINK_DEV
165
166	$MZ $h1 -c 1 -p 160 -a $h1mac -A 192.0.1.1 -t arp -q
167
168	devlink sb occupancy snapshot $DEVLINK_DEV
169
170	RET=0
171	max_occ=$(sb_occ_itc_check $dl_port2 $SB_ITC $exp_max_occ)
172	check_err $? "Expected ingress TC($SB_ITC) max occupancy to be $exp_max_occ, but got $max_occ"
173	log_test "physical port's($h1) ingress TC - ARP packet"
174
175	RET=0
176	max_occ=$(sb_occ_itc_check $dl_port2 $SB_ITC $exp_max_occ)
177	check_err $? "Expected ingress TC($SB_ITC) max occupancy to be $exp_max_occ, but got $max_occ"
178	log_test "physical port's($h2) ingress TC - ARP packet"
179
180	RET=0
181	max_occ=$(sb_occ_etc_check $cpu_dl_port $SB_ITC_CPU_ARP $exp_max_occ)
182	check_err $? "Expected egress TC($SB_ITC_IP2ME) max occupancy to be $exp_max_occ, but got $max_occ"
183	log_test "CPU port's egress TC - ARP packet"
184}
185
186setup_prepare()
187{
188	h1=${NETIFS[p1]}
189	h2=${NETIFS[p2]}
190
191	h1mac=$(mac_get $h1)
192	h2mac=$(mac_get $h2)
193
194	dl_port1=$(devlink_port_by_netdev $h1)
195	dl_port2=$(devlink_port_by_netdev $h2)
196
197	cpu_dl_port=$(devlink_cpu_port_get)
198
199	vrf_prepare
200
201	h1_create
202	h2_create
203}
204
205cleanup()
206{
207	pre_cleanup
208
209	h2_destroy
210	h1_destroy
211
212	vrf_cleanup
213}
214
215trap cleanup EXIT
216
217setup_prepare
218setup_wait
219
220tests_run
221
222exit $EXIT_STATUS
223