Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4ALL_TESTS="
5 manual_with_verification_h1_to_h2
6 manual_with_verification_h2_to_h1
7 manual_without_verification_h1_to_h2
8 manual_without_verification_h2_to_h1
9 manual_failed_verification_h1_to_h2
10 manual_failed_verification_h2_to_h1
11 lldp
12"
13
14NUM_NETIFS=2
15REQUIRE_MZ=no
16PREEMPTIBLE_PRIO=0
17source lib.sh
18
19traffic_test()
20{
21 local if=$1; shift
22 local src=$1; shift
23 local num_pkts=10000
24 local before=
25 local after=
26 local delta=
27
28 if [ ${has_pmac_stats[$if]} = false ]; then
29 src="aggregate"
30 fi
31
32 before=$(ethtool_std_stats_get $if "eth-mac" "FramesTransmittedOK" $src)
33
34 $MZ $if -q -c $num_pkts -p 64 -b bcast -t ip -R $PREEMPTIBLE_PRIO
35
36 after=$(ethtool_std_stats_get $if "eth-mac" "FramesTransmittedOK" $src)
37
38 delta=$((after - before))
39
40 # Allow an extra 1% tolerance for random packets sent by the stack
41 [ $delta -ge $num_pkts ] && [ $delta -le $((num_pkts + 100)) ]
42}
43
44manual_with_verification()
45{
46 local tx=$1; shift
47 local rx=$1; shift
48
49 RET=0
50
51 # It isn't completely clear from IEEE 802.3-2018 Figure 99-5: Transmit
52 # Processing state diagram whether the "send_r" variable (send response
53 # to verification frame) should be taken into consideration while the
54 # MAC Merge TX direction is disabled. That being said, at least the
55 # NXP ENETC does not, and requires tx-enabled on in order to respond to
56 # the link partner's verification frames.
57 ethtool --set-mm $rx tx-enabled on
58 ethtool --set-mm $tx verify-enabled on tx-enabled on
59
60 # Wait for verification to finish
61 sleep 1
62
63 ethtool --json --show-mm $tx | jq -r '.[]."verify-status"' | \
64 grep -q 'SUCCEEDED'
65 check_err "$?" "Verification did not succeed"
66
67 ethtool --json --show-mm $tx | jq -r '.[]."tx-active"' | grep -q 'true'
68 check_err "$?" "pMAC TX is not active"
69
70 traffic_test $tx "pmac"
71 check_err "$?" "Traffic did not get sent through $tx's pMAC"
72
73 ethtool --set-mm $tx verify-enabled off tx-enabled off
74 ethtool --set-mm $rx tx-enabled off
75
76 log_test "Manual configuration with verification: $tx to $rx"
77}
78
79manual_with_verification_h1_to_h2()
80{
81 manual_with_verification $h1 $h2
82}
83
84manual_with_verification_h2_to_h1()
85{
86 manual_with_verification $h2 $h1
87}
88
89manual_without_verification()
90{
91 local tx=$1; shift
92 local rx=$1; shift
93
94 RET=0
95
96 ethtool --set-mm $tx verify-enabled off tx-enabled on
97
98 ethtool --json --show-mm $tx | jq -r '.[]."verify-status"' | \
99 grep -q 'DISABLED'
100 check_err "$?" "Verification is not disabled"
101
102 ethtool --json --show-mm $tx | jq -r '.[]."tx-active"' | grep -q 'true'
103 check_err "$?" "pMAC TX is not active"
104
105 traffic_test $tx "pmac"
106 check_err "$?" "Traffic did not get sent through $tx's pMAC"
107
108 ethtool --set-mm $tx verify-enabled off tx-enabled off
109
110 log_test "Manual configuration without verification: $tx to $rx"
111}
112
113manual_without_verification_h1_to_h2()
114{
115 manual_without_verification $h1 $h2
116}
117
118manual_without_verification_h2_to_h1()
119{
120 manual_without_verification $h2 $h1
121}
122
123manual_failed_verification()
124{
125 local tx=$1; shift
126 local rx=$1; shift
127
128 RET=0
129
130 ethtool --set-mm $rx pmac-enabled off
131 ethtool --set-mm $tx verify-enabled on tx-enabled on
132
133 # Wait for verification to time out
134 sleep 1
135
136 ethtool --json --show-mm $tx | jq -r '.[]."verify-status"' | \
137 grep -q 'SUCCEEDED'
138 check_fail "$?" "Verification succeeded when it shouldn't have"
139
140 ethtool --json --show-mm $tx | jq -r '.[]."tx-active"' | grep -q 'true'
141 check_fail "$?" "pMAC TX is active when it shouldn't have"
142
143 traffic_test $tx "emac"
144 check_err "$?" "Traffic did not get sent through $tx's eMAC"
145
146 ethtool --set-mm $tx verify-enabled off tx-enabled off
147 ethtool --set-mm $rx pmac-enabled on
148
149 log_test "Manual configuration with failed verification: $tx to $rx"
150}
151
152manual_failed_verification_h1_to_h2()
153{
154 manual_failed_verification $h1 $h2
155}
156
157manual_failed_verification_h2_to_h1()
158{
159 manual_failed_verification $h2 $h1
160}
161
162smallest_supported_add_frag_size()
163{
164 local iface=$1
165 local rx_min_frag_size=
166
167 rx_min_frag_size=$(ethtool --json --show-mm $iface | \
168 jq '.[]."rx-min-frag-size"')
169
170 if [ $rx_min_frag_size -le 60 ]; then
171 echo 0
172 elif [ $rx_min_frag_size -le 124 ]; then
173 echo 1
174 elif [ $rx_min_frag_size -le 188 ]; then
175 echo 2
176 elif [ $rx_min_frag_size -le 252 ]; then
177 echo 3
178 else
179 echo "$iface: RX min frag size $rx_min_frag_size cannot be advertised over LLDP"
180 exit 1
181 fi
182}
183
184expected_add_frag_size()
185{
186 local iface=$1
187 local requested=$2
188 local min=$(smallest_supported_add_frag_size $iface)
189
190 [ $requested -le $min ] && echo $min || echo $requested
191}
192
193lldp_change_add_frag_size()
194{
195 local add_frag_size=$1
196 local pattern=
197
198 lldptool -T -i $h1 -V addEthCaps addFragSize=$add_frag_size >/dev/null
199 # Wait for TLVs to be received
200 sleep 2
201 pattern=$(printf "Additional fragment size: %d" \
202 $(expected_add_frag_size $h1 $add_frag_size))
203 lldptool -i $h2 -t -n -V addEthCaps | grep -q "$pattern"
204}
205
206lldp()
207{
208 RET=0
209
210 systemctl start lldpad
211
212 # Configure the interfaces to receive and transmit LLDPDUs
213 lldptool -L -i $h1 adminStatus=rxtx >/dev/null
214 lldptool -L -i $h2 adminStatus=rxtx >/dev/null
215
216 # Enable the transmission of Additional Ethernet Capabilities TLV
217 lldptool -T -i $h1 -V addEthCaps enableTx=yes >/dev/null
218 lldptool -T -i $h2 -V addEthCaps enableTx=yes >/dev/null
219
220 # Wait for TLVs to be received
221 sleep 2
222
223 lldptool -i $h1 -t -n -V addEthCaps | \
224 grep -q "Preemption capability active"
225 check_err "$?" "$h1 pMAC TX is not active"
226
227 lldptool -i $h2 -t -n -V addEthCaps | \
228 grep -q "Preemption capability active"
229 check_err "$?" "$h2 pMAC TX is not active"
230
231 lldp_change_add_frag_size 3
232 check_err "$?" "addFragSize 3"
233
234 lldp_change_add_frag_size 2
235 check_err "$?" "addFragSize 2"
236
237 lldp_change_add_frag_size 1
238 check_err "$?" "addFragSize 1"
239
240 lldp_change_add_frag_size 0
241 check_err "$?" "addFragSize 0"
242
243 traffic_test $h1 "pmac"
244 check_err "$?" "Traffic did not get sent through $h1's pMAC"
245
246 traffic_test $h2 "pmac"
247 check_err "$?" "Traffic did not get sent through $h2's pMAC"
248
249 systemctl stop lldpad
250
251 log_test "LLDP"
252}
253
254h1_create()
255{
256 ip link set dev $h1 up
257
258 tc qdisc add dev $h1 root mqprio num_tc 4 map 0 1 2 3 \
259 queues 1@0 1@1 1@2 1@3 \
260 fp P E E E \
261 hw 1
262
263 ethtool --set-mm $h1 pmac-enabled on tx-enabled off verify-enabled off
264}
265
266h2_create()
267{
268 ip link set dev $h2 up
269
270 ethtool --set-mm $h2 pmac-enabled on tx-enabled off verify-enabled off
271
272 tc qdisc add dev $h2 root mqprio num_tc 4 map 0 1 2 3 \
273 queues 1@0 1@1 1@2 1@3 \
274 fp P E E E \
275 hw 1
276}
277
278h1_destroy()
279{
280 ethtool --set-mm $h1 pmac-enabled off tx-enabled off verify-enabled off
281
282 tc qdisc del dev $h1 root
283
284 ip link set dev $h1 down
285}
286
287h2_destroy()
288{
289 tc qdisc del dev $h2 root
290
291 ethtool --set-mm $h2 pmac-enabled off tx-enabled off verify-enabled off
292
293 ip link set dev $h2 down
294}
295
296setup_prepare()
297{
298 h1=${NETIFS[p1]}
299 h2=${NETIFS[p2]}
300
301 h1_create
302 h2_create
303}
304
305cleanup()
306{
307 pre_cleanup
308
309 h2_destroy
310 h1_destroy
311}
312
313check_ethtool_mm_support
314check_tc_fp_support
315require_command lldptool
316bail_on_lldpad "autoconfigure the MAC Merge layer" "configure it manually"
317
318for netif in ${NETIFS[@]}; do
319 ethtool --show-mm $netif 2>&1 &> /dev/null
320 if [[ $? -ne 0 ]]; then
321 echo "SKIP: $netif does not support MAC Merge"
322 exit $ksft_skip
323 fi
324
325 if check_ethtool_pmac_std_stats_support $netif eth-mac; then
326 has_pmac_stats[$netif]=true
327 else
328 has_pmac_stats[$netif]=false
329 echo "$netif does not report pMAC statistics, falling back to aggregate"
330 fi
331done
332
333trap cleanup EXIT
334
335setup_prepare
336setup_wait
337
338tests_run
339
340exit $EXIT_STATUS