1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0 3 4ALL_TESTS=" 5 autoneg 6 autoneg_force_mode 7 no_cable 8" 9 10NUM_NETIFS=2 11source lib.sh 12source ethtool_lib.sh 13 14setup_prepare() 15{ 16 swp1=${NETIFS[p1]} 17 swp2=${NETIFS[p2]} 18 swp3=$NETIF_NO_CABLE 19} 20 21ethtool_extended_state_check() 22{ 23 local dev=$1; shift 24 local expected_ext_state=$1; shift 25 local expected_ext_substate=${1:-""}; shift 26 27 local ext_state=$(ethtool $dev | grep "Link detected" \ 28 | cut -d "(" -f2 | cut -d ")" -f1) 29 local ext_substate=$(echo $ext_state | cut -sd "," -f2 \ 30 | sed -e 's/^[[:space:]]*//') 31 ext_state=$(echo $ext_state | cut -d "," -f1) 32 33 [[ $ext_state == $expected_ext_state ]] 34 check_err $? "Expected \"$expected_ext_state\", got \"$ext_state\"" 35 36 [[ $ext_substate == $expected_ext_substate ]] 37 check_err $? "Expected \"$expected_ext_substate\", got \"$ext_substate\"" 38} 39 40autoneg() 41{ 42 RET=0 43 44 ip link set dev $swp1 up 45 46 sleep 4 47 ethtool_extended_state_check $swp1 "Autoneg" "No partner detected" 48 49 log_test "Autoneg, No partner detected" 50 51 ip link set dev $swp1 down 52} 53 54autoneg_force_mode() 55{ 56 RET=0 57 58 ip link set dev $swp1 up 59 ip link set dev $swp2 up 60 61 local -a speeds_arr=($(different_speeds_get $swp1 $swp2 0 0)) 62 local speed1=${speeds_arr[0]} 63 local speed2=${speeds_arr[1]} 64 65 ethtool_set $swp1 speed $speed1 autoneg off 66 ethtool_set $swp2 speed $speed2 autoneg off 67 68 sleep 4 69 ethtool_extended_state_check $swp1 "Autoneg" \ 70 "No partner detected during force mode" 71 72 ethtool_extended_state_check $swp2 "Autoneg" \ 73 "No partner detected during force mode" 74 75 log_test "Autoneg, No partner detected during force mode" 76 77 ethtool -s $swp2 autoneg on 78 ethtool -s $swp1 autoneg on 79 80 ip link set dev $swp2 down 81 ip link set dev $swp1 down 82} 83 84no_cable() 85{ 86 RET=0 87 88 ip link set dev $swp3 up 89 90 sleep 1 91 ethtool_extended_state_check $swp3 "No cable" 92 93 log_test "No cable" 94 95 ip link set dev $swp3 down 96} 97 98setup_prepare 99 100tests_run 101 102exit $EXIT_STATUS 103