2 # SPDX-License-Identifier: GPL-2.0
6 cmd
='/ETHTOOL_LINK_MODE_[^[:space:]]*_BIT[[:space:]]+=[[:space:]]+/ \
8 sub(/ETHTOOL_LINK_MODE_/,"") \
10 sub(/_Full/,"/Full") \
11 sub(/_Half/,"/Half");\
14 awk "${cmd}" /usr
/include
/linux
/ethtool.h
20 local out
=$
(ethtool
-s $cmd 2>&1 |
wc -l)
22 check_err
$out "error in configuration. $cmd"
25 dev_linkmodes_params_get
()
29 local -a linkmodes_params
34 mode
="Advertised link modes"
36 mode
="Supported link modes"
39 local -a dev_linkmodes
=($
(dev_speeds_get
$dev 1 $adver))
40 for ((i
=0; i
<${#dev_linkmodes[@]}; i
++)); do
41 linkmodes_params
[$i]=$
(echo -e "${dev_linkmodes[$i]}" | \
42 # Replaces all non numbers with spaces
43 sed -e 's/[^0-9]/ /g' | \
44 # Squeeze spaces in sequence to 1 space
46 # Count how many numbers were found in the linkmode
47 param_count
=$
(echo "${linkmodes_params[$i]}" |
wc -w)
48 if [[ $param_count -eq 1 ]]; then
49 linkmodes_params
[$i]="${linkmodes_params[$i]} 1"
50 elif [[ $param_count -ge 3 ]]; then
51 arr
=(${linkmodes_params[$i]})
52 # Take only first two params
53 linkmodes_params
[$i]=$
(echo "${arr[@]:0:2}")
56 echo ${linkmodes_params[@]}
62 local with_mode
=$1; shift
67 mode
="Advertised link modes"
69 mode
="Supported link modes"
72 speeds_str
=$
(ethtool
"$dev" | \
73 # Snip everything before the link modes section.
74 sed -n '/'"$mode"':/,$p' | \
75 # Quit processing the rest at the start of the next section.
76 # When checking, skip the header of this section (hence the 2,).
77 sed -n '2,${/^[\t][^ \t]/q};p' | \
78 # Drop the section header of the current section.
81 local -a speeds_arr
=($speeds_str)
82 if [[ $with_mode -eq 0 ]]; then
83 for ((i
=0; i
<${#speeds_arr[@]}; i
++)); do
84 speeds_arr
[$i]=${speeds_arr[$i]%base*}
97 local -a dev1_speeds
=($
(dev_speeds_get
$dev1 $with_mode $adver))
98 local -a dev2_speeds
=($
(dev_speeds_get
$dev2 $with_mode $adver))
101 <(printf '%s\n' "${dev1_speeds[@]}" |
sort -u) \
102 <(printf '%s\n' "${dev2_speeds[@]}" |
sort -u)
105 different_speeds_get
()
109 local with_mode
=$1; shift
110 local adver
=$1; shift
114 speeds_arr
=($
(common_speeds_get
$dev1 $dev2 $with_mode $adver))
115 if [[ ${#speeds_arr[@]} < 2 ]]; then
116 check_err
1 "cannot check different speeds. There are not enough speeds"
119 echo ${speeds_arr[0]} ${speeds_arr[1]}