~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/drivers/net/hw/ethtool_lib.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 speeds_arr_get()
  5 {
  6         cmd='/ETHTOOL_LINK_MODE_[^[:space:]]*_BIT[[:space:]]+=[[:space:]]+/ \
  7                 {sub(/,$/, "") \
  8                 sub(/ETHTOOL_LINK_MODE_/,"") \
  9                 sub(/_BIT/,"") \
 10                 sub(/_Full/,"/Full") \
 11                 sub(/_Half/,"/Half");\
 12                 print "["$1"]="$3}'
 13 
 14         awk "${cmd}" /usr/include/linux/ethtool.h
 15 }
 16 
 17 ethtool_set()
 18 {
 19         local cmd="$@"
 20         local out=$(ethtool -s $cmd 2>&1 | wc -l)
 21 
 22         check_err $out "error in configuration. $cmd"
 23 }
 24 
 25 dev_linkmodes_params_get()
 26 {
 27         local dev=$1; shift
 28         local adver=$1; shift
 29         local -a linkmodes_params
 30         local param_count
 31         local arr
 32 
 33         if (($adver)); then
 34                 mode="Advertised link modes"
 35         else
 36                 mode="Supported link modes"
 37         fi
 38 
 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
 45                         tr -s ' ')
 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}")
 54                 fi
 55         done
 56         echo ${linkmodes_params[@]}
 57 }
 58 
 59 dev_speeds_get()
 60 {
 61         local dev=$1; shift
 62         local with_mode=$1; shift
 63         local adver=$1; shift
 64         local speeds_str
 65 
 66         if (($adver)); then
 67                 mode="Advertised link modes"
 68         else
 69                 mode="Supported link modes"
 70         fi
 71 
 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.
 79                 cut -d':' -f2)
 80 
 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*}
 85                 done
 86         fi
 87         echo ${speeds_arr[@]}
 88 }
 89 
 90 common_speeds_get()
 91 {
 92         dev1=$1; shift
 93         dev2=$1; shift
 94         with_mode=$1; shift
 95         adver=$1; shift
 96 
 97         local -a dev1_speeds=($(dev_speeds_get $dev1 $with_mode $adver))
 98         local -a dev2_speeds=($(dev_speeds_get $dev2 $with_mode $adver))
 99 
100         comm -12 \
101                 <(printf '%s\n' "${dev1_speeds[@]}" | sort -u) \
102                 <(printf '%s\n' "${dev2_speeds[@]}" | sort -u)
103 }
104 
105 different_speeds_get()
106 {
107         local dev1=$1; shift
108         local dev2=$1; shift
109         local with_mode=$1; shift
110         local adver=$1; shift
111 
112         local -a speeds_arr
113 
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"
117         fi
118 
119         echo ${speeds_arr[0]} ${speeds_arr[1]}
120 }

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php