Path: blob/master/tools/testing/selftests/drivers/net/hw/ethtool_mm.sh
26295 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.023ALL_TESTS="4manual_with_verification_h1_to_h25manual_with_verification_h2_to_h16manual_without_verification_h1_to_h27manual_without_verification_h2_to_h18manual_failed_verification_h1_to_h29manual_failed_verification_h2_to_h110lldp11"1213NUM_NETIFS=214REQUIRE_MZ=no15PREEMPTIBLE_PRIO=016lib_dir=$(dirname "$0")17source "$lib_dir"/../../../net/forwarding/lib.sh1819traffic_test()20{21local if=$1; shift22local src=$1; shift23local num_pkts=1000024local before=25local after=26local delta=2728if [ ${has_pmac_stats[$if]} = false ]; then29src="aggregate"30fi3132before=$(ethtool_std_stats_get $if "eth-mac" "FramesTransmittedOK" $src)3334$MZ $if -q -c $num_pkts -p 64 -b bcast -t ip -R $PREEMPTIBLE_PRIO3536after=$(ethtool_std_stats_get $if "eth-mac" "FramesTransmittedOK" $src)3738delta=$((after - before))3940# Allow an extra 1% tolerance for random packets sent by the stack41[ $delta -ge $num_pkts ] && [ $delta -le $((num_pkts + 100)) ]42}4344manual_with_verification()45{46local tx=$1; shift47local rx=$1; shift4849RET=05051# It isn't completely clear from IEEE 802.3-2018 Figure 99-5: Transmit52# Processing state diagram whether the "send_r" variable (send response53# to verification frame) should be taken into consideration while the54# MAC Merge TX direction is disabled. That being said, at least the55# NXP ENETC does not, and requires tx-enabled on in order to respond to56# the link partner's verification frames.57ethtool --set-mm $rx tx-enabled on58ethtool --set-mm $tx verify-enabled on tx-enabled on5960# Wait for verification to finish61sleep 16263ethtool --json --show-mm $tx | jq -r '.[]."verify-status"' | \64grep -q 'SUCCEEDED'65check_err "$?" "Verification did not succeed"6667ethtool --json --show-mm $tx | jq -r '.[]."tx-active"' | grep -q 'true'68check_err "$?" "pMAC TX is not active"6970traffic_test $tx "pmac"71check_err "$?" "Traffic did not get sent through $tx's pMAC"7273ethtool --set-mm $tx verify-enabled off tx-enabled off74ethtool --set-mm $rx tx-enabled off7576log_test "Manual configuration with verification: $tx to $rx"77}7879manual_with_verification_h1_to_h2()80{81manual_with_verification $h1 $h282}8384manual_with_verification_h2_to_h1()85{86manual_with_verification $h2 $h187}8889manual_without_verification()90{91local tx=$1; shift92local rx=$1; shift9394RET=09596ethtool --set-mm $tx verify-enabled off tx-enabled on9798ethtool --json --show-mm $tx | jq -r '.[]."verify-status"' | \99grep -q 'DISABLED'100check_err "$?" "Verification is not disabled"101102ethtool --json --show-mm $tx | jq -r '.[]."tx-active"' | grep -q 'true'103check_err "$?" "pMAC TX is not active"104105traffic_test $tx "pmac"106check_err "$?" "Traffic did not get sent through $tx's pMAC"107108ethtool --set-mm $tx verify-enabled off tx-enabled off109110log_test "Manual configuration without verification: $tx to $rx"111}112113manual_without_verification_h1_to_h2()114{115manual_without_verification $h1 $h2116}117118manual_without_verification_h2_to_h1()119{120manual_without_verification $h2 $h1121}122123manual_failed_verification()124{125local tx=$1; shift126local rx=$1; shift127128RET=0129130ethtool --set-mm $rx pmac-enabled off131ethtool --set-mm $tx verify-enabled on tx-enabled on132133# Wait for verification to time out134sleep 1135136ethtool --json --show-mm $tx | jq -r '.[]."verify-status"' | \137grep -q 'SUCCEEDED'138check_fail "$?" "Verification succeeded when it shouldn't have"139140ethtool --json --show-mm $tx | jq -r '.[]."tx-active"' | grep -q 'true'141check_fail "$?" "pMAC TX is active when it shouldn't have"142143traffic_test $tx "emac"144check_err "$?" "Traffic did not get sent through $tx's eMAC"145146ethtool --set-mm $tx verify-enabled off tx-enabled off147ethtool --set-mm $rx pmac-enabled on148149log_test "Manual configuration with failed verification: $tx to $rx"150}151152manual_failed_verification_h1_to_h2()153{154manual_failed_verification $h1 $h2155}156157manual_failed_verification_h2_to_h1()158{159manual_failed_verification $h2 $h1160}161162smallest_supported_add_frag_size()163{164local iface=$1165local rx_min_frag_size=166167rx_min_frag_size=$(ethtool --json --show-mm $iface | \168jq '.[]."rx-min-frag-size"')169170if [ $rx_min_frag_size -le 60 ]; then171echo 0172elif [ $rx_min_frag_size -le 124 ]; then173echo 1174elif [ $rx_min_frag_size -le 188 ]; then175echo 2176elif [ $rx_min_frag_size -le 252 ]; then177echo 3178else179echo "$iface: RX min frag size $rx_min_frag_size cannot be advertised over LLDP"180exit 1181fi182}183184expected_add_frag_size()185{186local iface=$1187local requested=$2188local min=$(smallest_supported_add_frag_size $iface)189190[ $requested -le $min ] && echo $min || echo $requested191}192193lldp_change_add_frag_size()194{195local add_frag_size=$1196local pattern=197198lldptool -T -i $h1 -V addEthCaps addFragSize=$add_frag_size >/dev/null199# Wait for TLVs to be received200sleep 2201pattern=$(printf "Additional fragment size: %d" \202$(expected_add_frag_size $h1 $add_frag_size))203lldptool -i $h2 -t -n -V addEthCaps | grep -q "$pattern"204}205206lldp()207{208RET=0209210systemctl start lldpad211212# Configure the interfaces to receive and transmit LLDPDUs213lldptool -L -i $h1 adminStatus=rxtx >/dev/null214lldptool -L -i $h2 adminStatus=rxtx >/dev/null215216# Enable the transmission of Additional Ethernet Capabilities TLV217lldptool -T -i $h1 -V addEthCaps enableTx=yes >/dev/null218lldptool -T -i $h2 -V addEthCaps enableTx=yes >/dev/null219220# Wait for TLVs to be received221sleep 2222223lldptool -i $h1 -t -n -V addEthCaps | \224grep -q "Preemption capability active"225check_err "$?" "$h1 pMAC TX is not active"226227lldptool -i $h2 -t -n -V addEthCaps | \228grep -q "Preemption capability active"229check_err "$?" "$h2 pMAC TX is not active"230231lldp_change_add_frag_size 3232check_err "$?" "addFragSize 3"233234lldp_change_add_frag_size 2235check_err "$?" "addFragSize 2"236237lldp_change_add_frag_size 1238check_err "$?" "addFragSize 1"239240lldp_change_add_frag_size 0241check_err "$?" "addFragSize 0"242243traffic_test $h1 "pmac"244check_err "$?" "Traffic did not get sent through $h1's pMAC"245246traffic_test $h2 "pmac"247check_err "$?" "Traffic did not get sent through $h2's pMAC"248249systemctl stop lldpad250251log_test "LLDP"252}253254h1_create()255{256ip link set dev $h1 up257258tc qdisc add dev $h1 root mqprio num_tc 4 map 0 1 2 3 \259queues 1@0 1@1 1@2 1@3 \260fp P E E E \261hw 1262263ethtool --set-mm $h1 pmac-enabled on tx-enabled off verify-enabled off264}265266h2_create()267{268ip link set dev $h2 up269270ethtool --set-mm $h2 pmac-enabled on tx-enabled off verify-enabled off271272tc qdisc add dev $h2 root mqprio num_tc 4 map 0 1 2 3 \273queues 1@0 1@1 1@2 1@3 \274fp P E E E \275hw 1276}277278h1_destroy()279{280ethtool --set-mm $h1 pmac-enabled off tx-enabled off verify-enabled off281282tc qdisc del dev $h1 root283284ip link set dev $h1 down285}286287h2_destroy()288{289tc qdisc del dev $h2 root290291ethtool --set-mm $h2 pmac-enabled off tx-enabled off verify-enabled off292293ip link set dev $h2 down294}295296setup_prepare()297{298h1=${NETIFS[p1]}299h2=${NETIFS[p2]}300301h1_create302h2_create303}304305cleanup()306{307pre_cleanup308309h2_destroy310h1_destroy311}312313check_ethtool_mm_support314check_tc_fp_support315require_command lldptool316bail_on_lldpad "autoconfigure the MAC Merge layer" "configure it manually"317318for netif in ${NETIFS[@]}; do319ethtool --show-mm $netif 2>&1 &> /dev/null320if [[ $? -ne 0 ]]; then321echo "SKIP: $netif does not support MAC Merge"322exit $ksft_skip323fi324325if check_ethtool_pmac_std_stats_support $netif eth-mac; then326has_pmac_stats[$netif]=true327else328has_pmac_stats[$netif]=false329echo "$netif does not report pMAC statistics, falling back to aggregate"330fi331done332333trap cleanup EXIT334335setup_prepare336setup_wait337338tests_run339340exit $EXIT_STATUS341342343