2 # SPDX-License-Identifier: GPL-2.0
5 same_speeds_autoneg_off
6 different_speeds_autoneg_off
7 combination_of_neg_on_and_off
8 advertise_subset_of_speeds
9 check_highest_speed_is_chosen
10 different_speeds_autoneg_on
18 simple_if_init
$h1 192.0.2.1/24
23 simple_if_fini
$h1 192.0.2.1/24
28 simple_if_init
$h2 192.0.2.2/24
33 simple_if_fini
$h2 192.0.2.2/24
53 same_speeds_autoneg_off
()
55 # Check that when each of the reported speeds is forced, the links come
56 # up and are operational.
57 local -a speeds_arr
=($
(common_speeds_get
$h1 $h2 0 0))
59 for speed
in "${speeds_arr[@]}"; do
61 ethtool_set
$h1 speed
$speed autoneg off
62 ethtool_set
$h2 speed
$speed autoneg off
64 setup_wait_dev_with_timeout
$h1
65 setup_wait_dev_with_timeout
$h2
67 check_err $?
"speed $speed autoneg off"
68 log_test
"force of same speed autoneg off"
69 log_info
"speed = $speed"
72 ethtool
-s $h2 autoneg on
73 ethtool
-s $h1 autoneg on
76 different_speeds_autoneg_off
()
78 # Test that when we force different speeds, links are not up and ping
82 local -a speeds_arr
=($
(different_speeds_get
$h1 $h2 0 0))
83 local speed1
=${speeds_arr[0]}
84 local speed2
=${speeds_arr[1]}
86 ethtool_set
$h1 speed
$speed1 autoneg off
87 ethtool_set
$h2 speed
$speed2 autoneg off
89 setup_wait_dev_with_timeout
$h1
90 setup_wait_dev_with_timeout
$h2
92 check_fail $?
"ping with different speeds"
94 log_test
"force of different speeds autoneg off"
96 ethtool
-s $h2 autoneg on
97 ethtool
-s $h1 autoneg on
100 combination_of_neg_on_and_off
()
102 # Test that when one device is forced to a speed supported by both
103 # endpoints and the other device is configured to autoneg on, the links
104 # are up and ping passes.
105 local -a speeds_arr
=($
(common_speeds_get
$h1 $h2 0 1))
107 for speed
in "${speeds_arr[@]}"; do
109 ethtool_set
$h1 speed
$speed autoneg off
111 setup_wait_dev_with_timeout
$h1
112 setup_wait_dev_with_timeout
$h2
113 ping_do
$h1 192.0.2.2
114 check_err $?
"h1-speed=$speed autoneg off, h2 autoneg on"
115 log_test
"one side with autoneg off and another with autoneg on"
116 log_info
"force speed = $speed"
119 ethtool
-s $h1 autoneg on
122 hex_speed_value_get
()
124 local speed
=$1; shift
126 local shift_size
=${speed_values[$speed]}
127 speed
=$
((0x1 << $
"shift_size"))
128 printf "%#x" "$speed"
131 subset_of_common_speeds_get
()
135 local adver
=$1; shift
137 local -a speeds_arr
=($
(common_speeds_get
$dev1 $dev2 0 $adver))
138 local speed_to_advertise
=0
139 local speed_to_remove
=${speeds_arr[0]}
140 speed_to_remove
+='base'
142 local -a speeds_mode_arr
=($
(common_speeds_get
$dev1 $dev2 1 $adver))
144 for speed
in ${speeds_mode_arr[@]}; do
145 if [[ $speed != $speed_to_remove* ]]; then
146 speed
=$
(hex_speed_value_get
$speed)
147 speed_to_advertise
=$
(($speed_to_advertise | \
154 printf "%#x" "$speed_to_advertise"
157 speed_to_advertise_get
()
159 # The function returns the hex number that is composed by OR-ing all
160 # the modes corresponding to the provided speed.
161 local speed_without_mode
=$1; shift
162 local supported_speeds
=("$@"); shift
163 local speed_to_advertise
=0
165 speed_without_mode
+='base'
167 for speed
in ${supported_speeds[@]}; do
168 if [[ $speed == $speed_without_mode* ]]; then
169 speed
=$
(hex_speed_value_get
$speed)
170 speed_to_advertise
=$
(($speed_to_advertise | \
177 printf "%#x" "$speed_to_advertise"
180 advertise_subset_of_speeds
()
182 # Test that when one device advertises a subset of speeds and another
183 # advertises a specific speed (but all modes of this speed), the links
184 # are up and ping passes.
187 local speed_1_to_advertise
=$
(subset_of_common_speeds_get
$h1 $h2 1)
188 ethtool_set
$h1 advertise
$speed_1_to_advertise
190 if [ $RET != 0 ]; then
191 log_test
"advertise subset of speeds"
195 local -a speeds_arr_without_mode
=($
(common_speeds_get
$h1 $h2 0 1))
196 # Check only speeds that h1 advertised. Remove the first speed.
197 unset speeds_arr_without_mode
[0]
198 local -a speeds_arr_with_mode
=($
(common_speeds_get
$h1 $h2 1 1))
200 for speed_value
in ${speeds_arr_without_mode[@]}; do
202 local speed_2_to_advertise
=$
(speed_to_advertise_get
$speed_value \
203 "${speeds_arr_with_mode[@]}")
204 ethtool_set
$h2 advertise
$speed_2_to_advertise
206 setup_wait_dev_with_timeout
$h1
207 setup_wait_dev_with_timeout
$h2
208 ping_do
$h1 192.0.2.2
209 check_err $?
"h1=$speed_1_to_advertise, h2=$speed_2_to_advertise ($speed_value)"
211 log_test
"advertise subset of speeds"
212 log_info
"h1=$speed_1_to_advertise, h2=$speed_2_to_advertise"
215 ethtool
-s $h2 autoneg on
216 ethtool
-s $h1 autoneg on
219 check_highest_speed_is_chosen
()
221 # Test that when one device advertises a subset of speeds, the other
222 # chooses the highest speed. This test checks configuration without
228 local speed_to_advertise
=$
(subset_of_common_speeds_get
$h1 $h2 1)
230 ethtool_set
$h1 advertise
$speed_to_advertise
232 if [ $RET != 0 ]; then
233 log_test
"check highest speed"
237 local -a speeds_arr
=($
(common_speeds_get
$h1 $h2 0 1))
239 max_speed
=${speeds_arr[0]}
240 for current
in ${speeds_arr[@]}; do
241 if [[ $current -gt $max_speed ]]; then
246 setup_wait_dev_with_timeout
$h1
247 setup_wait_dev_with_timeout
$h2
248 chosen_speed
=$
(ethtool
$h1 |
grep 'Speed:')
249 chosen_speed
=${chosen_speed%"Mb/s"*}
250 chosen_speed
=${chosen_speed#*"Speed: "}
251 ((chosen_speed
== max_speed
))
252 check_err $?
"h1 advertise $speed_to_advertise, h2 sync to speed $chosen_speed"
254 log_test
"check highest speed"
256 ethtool
-s $h2 autoneg on
257 ethtool
-s $h1 autoneg on
260 different_speeds_autoneg_on
()
262 # Test that when we configure links to advertise different speeds,
263 # links are not up and ping fails.
266 local -a speeds
=($
(different_speeds_get
$h1 $h2 1 1))
267 local speed1
=${speeds[0]}
268 local speed2
=${speeds[1]}
270 speed1
=$
(hex_speed_value_get
$speed1)
271 speed2
=$
(hex_speed_value_get
$speed2)
273 ethtool_set
$h1 advertise
$speed1
274 ethtool_set
$h2 advertise
$speed2
277 setup_wait_dev_with_timeout
$h1
278 setup_wait_dev_with_timeout
$h2
279 ping_do
$h1 192.0.2.2
280 check_fail $?
"ping with different speeds autoneg on"
283 log_test
"advertise different speeds autoneg on"
285 ethtool
-s $h2 autoneg on
286 ethtool
-s $h1 autoneg on
294 declare -gA speed_values
295 eval "speed_values=($(speeds_arr_get))"