Path: blob/master/tools/testing/selftests/drivers/net/mlxsw/devlink_linecard.sh
26292 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.02#3# In addition to the common variables, user might use:4# LC_SLOT - If not set, all probed line cards are going to be tested,5# with an exception of the "activation_16x100G_test".6# It set, only the selected line card is going to be used7# for tests, including "activation_16x100G_test".89lib_dir=$(dirname $0)/../../../net/forwarding1011ALL_TESTS="12unprovision_test13provision_test14activation_16x100G_test15"1617NUM_NETIFS=01819source $lib_dir/lib.sh20source $lib_dir/devlink_lib.sh2122until_lc_state_is()23{24local state=$1; shift25local current=$("$@")2627echo "$current"28[ "$current" == "$state" ]29}3031until_lc_state_is_not()32{33! until_lc_state_is "$@"34}3536lc_state_get()37{38local lc=$13940devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].state"41}4243lc_wait_until_state_changes()44{45local lc=$146local state=$247local timeout=$3 # ms4849busywait "$timeout" until_lc_state_is_not "$state" lc_state_get "$lc"50}5152lc_wait_until_state_becomes()53{54local lc=$155local state=$256local timeout=$3 # ms5758busywait "$timeout" until_lc_state_is "$state" lc_state_get "$lc"59}6061until_lc_port_count_is()62{63local port_count=$1; shift64local current=$("$@")6566echo "$current"67[ $current == $port_count ]68}6970lc_port_count_get()71{72local lc=$17374devlink port -j | jq -e -r ".[][] | select(.lc==$lc) | .port" | wc -l75}7677lc_wait_until_port_count_is()78{79local lc=$180local port_count=$281local timeout=$3 # ms8283busywait "$timeout" until_lc_port_count_is "$port_count" lc_port_count_get "$lc"84}8586lc_nested_devlink_dev_get()87{88local lc=$18990devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].nested_devlink"91}9293PROV_UNPROV_TIMEOUT=8000 # ms94POST_PROV_ACT_TIMEOUT=2000 # ms95PROV_PORTS_INSTANTIATION_TIMEOUT=15000 # ms9697unprovision_one()98{99local lc=$1100local state101102state=$(lc_state_get $lc)103check_err $? "Failed to get state of linecard $lc"104if [[ "$state" == "unprovisioned" ]]; then105return106fi107108log_info "Unprovisioning linecard $lc"109110devlink lc set $DEVLINK_DEV lc $lc notype111check_err $? "Failed to trigger linecard $lc unprovisioning"112113state=$(lc_wait_until_state_changes $lc "unprovisioning" \114$PROV_UNPROV_TIMEOUT)115check_err $? "Failed to unprovision linecard $lc (timeout)"116117[ "$state" == "unprovisioned" ]118check_err $? "Failed to unprovision linecard $lc (state=$state)"119}120121provision_one()122{123local lc=$1124local type=$2125local state126127log_info "Provisioning linecard $lc"128129devlink lc set $DEVLINK_DEV lc $lc type $type130check_err $? "Failed trigger linecard $lc provisioning"131132state=$(lc_wait_until_state_changes $lc "provisioning" \133$PROV_UNPROV_TIMEOUT)134check_err $? "Failed to provision linecard $lc (timeout)"135136[ "$state" == "provisioned" ] || [ "$state" == "active" ]137check_err $? "Failed to provision linecard $lc (state=$state)"138139provisioned_type=$(devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].type")140[ "$provisioned_type" == "$type" ]141check_err $? "Wrong provision type returned for linecard $lc (got \"$provisioned_type\", expected \"$type\")"142143# Wait for possible activation to make sure the state144# won't change after return from this function.145state=$(lc_wait_until_state_becomes $lc "active" \146$POST_PROV_ACT_TIMEOUT)147}148149unprovision_test()150{151RET=0152local lc153154lc=$LC_SLOT155unprovision_one $lc156log_test "Unprovision"157}158159LC_16X100G_TYPE="16x100G"160LC_16X100G_PORT_COUNT=16161162supported_types_check()163{164local lc=$1165local supported_types_count166local type_index167local lc_16x100_found=false168169supported_types_count=$(devlink lc show $DEVLINK_DEV lc $lc -j | \170jq -e -r ".[][][].supported_types | length")171[ $supported_types_count != 0 ]172check_err $? "No supported types found for linecard $lc"173for (( type_index=0; type_index<$supported_types_count; type_index++ ))174do175type=$(devlink lc show $DEVLINK_DEV lc $lc -j | \176jq -e -r ".[][][].supported_types[$type_index]")177if [[ "$type" == "$LC_16X100G_TYPE" ]]; then178lc_16x100_found=true179break180fi181done182[ $lc_16x100_found = true ]183check_err $? "16X100G not found between supported types of linecard $lc"184}185186ports_check()187{188local lc=$1189local expected_port_count=$2190local port_count191192port_count=$(lc_wait_until_port_count_is $lc $expected_port_count \193$PROV_PORTS_INSTANTIATION_TIMEOUT)194[ $port_count != 0 ]195check_err $? "No port associated with linecard $lc"196[ $port_count == $expected_port_count ]197check_err $? "Unexpected port count linecard $lc (got $port_count, expected $expected_port_count)"198}199200lc_dev_info_provisioned_check()201{202local lc=$1203local nested_devlink_dev=$2204local fixed_hw_revision205local running_ini_version206207fixed_hw_revision=$(devlink dev info $nested_devlink_dev -j | \208jq -e -r '.[][].versions.fixed."hw.revision"')209check_err $? "Failed to get linecard $lc fixed.hw.revision"210log_info "Linecard $lc fixed.hw.revision: \"$fixed_hw_revision\""211running_ini_version=$(devlink dev info $nested_devlink_dev -j | \212jq -e -r '.[][].versions.running."ini.version"')213check_err $? "Failed to get linecard $lc running.ini.version"214log_info "Linecard $lc running.ini.version: \"$running_ini_version\""215}216217provision_test()218{219RET=0220local lc221local type222local state223local nested_devlink_dev224225lc=$LC_SLOT226supported_types_check $lc227state=$(lc_state_get $lc)228check_err $? "Failed to get state of linecard $lc"229if [[ "$state" != "unprovisioned" ]]; then230unprovision_one $lc231fi232provision_one $lc $LC_16X100G_TYPE233ports_check $lc $LC_16X100G_PORT_COUNT234235nested_devlink_dev=$(lc_nested_devlink_dev_get $lc)236check_err $? "Failed to get nested devlink handle of linecard $lc"237lc_dev_info_provisioned_check $lc $nested_devlink_dev238239log_test "Provision"240}241242ACTIVATION_TIMEOUT=20000 # ms243244interface_check()245{246ip link set $h1 up247ip link set $h2 up248ifaces_upped=true249setup_wait250}251252lc_dev_info_active_check()253{254local lc=$1255local nested_devlink_dev=$2256local fixed_device_fw_psid257local running_device_fw258259fixed_device_fw_psid=$(devlink dev info $nested_devlink_dev -j | \260jq -e -r ".[][].versions.fixed" | \261jq -e -r '."fw.psid"')262check_err $? "Failed to get linecard $lc fixed fw PSID"263log_info "Linecard $lc fixed.fw.psid: \"$fixed_device_fw_psid\""264265running_device_fw=$(devlink dev info $nested_devlink_dev -j | \266jq -e -r ".[][].versions.running.fw")267check_err $? "Failed to get linecard $lc running.fw.version"268log_info "Linecard $lc running.fw: \"$running_device_fw\""269}270271activation_16x100G_test()272{273RET=0274local lc275local type276local state277local nested_devlink_dev278279lc=$LC_SLOT280type=$LC_16X100G_TYPE281282unprovision_one $lc283provision_one $lc $type284state=$(lc_wait_until_state_becomes $lc "active" \285$ACTIVATION_TIMEOUT)286check_err $? "Failed to get linecard $lc activated (timeout)"287288interface_check289290nested_devlink_dev=$(lc_nested_devlink_dev_get $lc)291check_err $? "Failed to get nested devlink handle of linecard $lc"292lc_dev_info_active_check $lc $nested_devlink_dev293294log_test "Activation 16x100G"295}296297setup_prepare()298{299local lc_num=$(devlink lc show -j | jq -e -r ".[][\"$DEVLINK_DEV\"] |length")300if [[ $? -ne 0 ]] || [[ $lc_num -eq 0 ]]; then301echo "SKIP: No linecard support found"302exit $ksft_skip303fi304305if [ -z "$LC_SLOT" ]; then306echo "SKIP: \"LC_SLOT\" variable not provided"307exit $ksft_skip308fi309310# Interfaces are not present during the script start,311# that's why we define NUM_NETIFS here so dummy312# implicit veth pairs are not created.313NUM_NETIFS=2314h1=${NETIFS[p1]}315h2=${NETIFS[p2]}316ifaces_upped=false317}318319cleanup()320{321if [ "$ifaces_upped" = true ] ; then322ip link set $h1 down323ip link set $h2 down324fi325}326327trap cleanup EXIT328329setup_prepare330331tests_run332333exit $EXIT_STATUS334335336