1*1da07e5dSJakub Kicinski#!/bin/bash 2*1da07e5dSJakub Kicinski# SPDX-License-Identifier: GPL-2.0-only 3*1da07e5dSJakub Kicinski 4*1da07e5dSJakub Kicinskisource ethtool-common.sh 5*1da07e5dSJakub Kicinski 6*1da07e5dSJakub KicinskiNSIM_NETDEV=$(make_netdev) 7*1da07e5dSJakub Kicinski[ a$ETHTOOL == a ] && ETHTOOL=ethtool 8*1da07e5dSJakub Kicinski 9*1da07e5dSJakub Kicinskiset -o pipefail 10*1da07e5dSJakub Kicinski 11*1da07e5dSJakub Kicinski# netdevsim starts out with None/None 12*1da07e5dSJakub Kicinskis=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 13*1da07e5dSJakub Kicinskicheck $? "$s" "Configured FEC encodings: None 14*1da07e5dSJakub KicinskiActive FEC encoding: None" 15*1da07e5dSJakub Kicinski 16*1da07e5dSJakub Kicinski# Test Auto 17*1da07e5dSJakub Kicinski$ETHTOOL --set-fec $NSIM_NETDEV encoding auto 18*1da07e5dSJakub Kicinskicheck $? 19*1da07e5dSJakub Kicinskis=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 20*1da07e5dSJakub Kicinskicheck $? "$s" "Configured FEC encodings: Auto 21*1da07e5dSJakub KicinskiActive FEC encoding: Off" 22*1da07e5dSJakub Kicinski 23*1da07e5dSJakub Kicinski# Test case in-sensitivity 24*1da07e5dSJakub Kicinskifor o in off Off OFF; do 25*1da07e5dSJakub Kicinski $ETHTOOL --set-fec $NSIM_NETDEV encoding $o 26*1da07e5dSJakub Kicinski check $? 27*1da07e5dSJakub Kicinski s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 28*1da07e5dSJakub Kicinski check $? "$s" "Configured FEC encodings: Off 29*1da07e5dSJakub KicinskiActive FEC encoding: Off" 30*1da07e5dSJakub Kicinskidone 31*1da07e5dSJakub Kicinski 32*1da07e5dSJakub Kicinskifor o in BaseR baser BAser; do 33*1da07e5dSJakub Kicinski $ETHTOOL --set-fec $NSIM_NETDEV encoding $o 34*1da07e5dSJakub Kicinski check $? 35*1da07e5dSJakub Kicinski s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 36*1da07e5dSJakub Kicinski check $? "$s" "Configured FEC encodings: BaseR 37*1da07e5dSJakub KicinskiActive FEC encoding: BaseR" 38*1da07e5dSJakub Kicinskidone 39*1da07e5dSJakub Kicinski 40*1da07e5dSJakub Kicinskifor o in llrs rs; do 41*1da07e5dSJakub Kicinski $ETHTOOL --set-fec $NSIM_NETDEV encoding $o 42*1da07e5dSJakub Kicinski check $? 43*1da07e5dSJakub Kicinski s=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 44*1da07e5dSJakub Kicinski check $? "$s" "Configured FEC encodings: ${o^^} 45*1da07e5dSJakub KicinskiActive FEC encoding: ${o^^}" 46*1da07e5dSJakub Kicinskidone 47*1da07e5dSJakub Kicinski 48*1da07e5dSJakub Kicinski# Test mutliple bits 49*1da07e5dSJakub Kicinski$ETHTOOL --set-fec $NSIM_NETDEV encoding rs llrs 50*1da07e5dSJakub Kicinskicheck $? 51*1da07e5dSJakub Kicinskis=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 52*1da07e5dSJakub Kicinskicheck $? "$s" "Configured FEC encodings: RS LLRS 53*1da07e5dSJakub KicinskiActive FEC encoding: LLRS" 54*1da07e5dSJakub Kicinski 55*1da07e5dSJakub Kicinski$ETHTOOL --set-fec $NSIM_NETDEV encoding rs off auto 56*1da07e5dSJakub Kicinskicheck $? 57*1da07e5dSJakub Kicinskis=$($ETHTOOL --show-fec $NSIM_NETDEV | tail -2) 58*1da07e5dSJakub Kicinskicheck $? "$s" "Configured FEC encodings: Auto Off RS 59*1da07e5dSJakub KicinskiActive FEC encoding: RS" 60*1da07e5dSJakub Kicinski 61*1da07e5dSJakub Kicinski# Make sure other link modes are rejected 62*1da07e5dSJakub Kicinski$ETHTOOL --set-fec $NSIM_NETDEV encoding FIBRE 2>/dev/null 63*1da07e5dSJakub Kicinskicheck $? '' '' 1 64*1da07e5dSJakub Kicinski 65*1da07e5dSJakub Kicinski$ETHTOOL --set-fec $NSIM_NETDEV encoding bla-bla-bla 2>/dev/null 66*1da07e5dSJakub Kicinskicheck $? '' '' 1 67*1da07e5dSJakub Kicinski 68*1da07e5dSJakub Kicinski# Try JSON 69*1da07e5dSJakub Kicinski$ETHTOOL --json --show-fec $NSIM_NETDEV | jq empty >>/dev/null 2>&1 70*1da07e5dSJakub Kicinskiif [ $? -eq 0 ]; then 71*1da07e5dSJakub Kicinski $ETHTOOL --set-fec $NSIM_NETDEV encoding auto 72*1da07e5dSJakub Kicinski check $? 73*1da07e5dSJakub Kicinski 74*1da07e5dSJakub Kicinski s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].config[]') 75*1da07e5dSJakub Kicinski check $? "$s" '"Auto"' 76*1da07e5dSJakub Kicinski s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].active[]') 77*1da07e5dSJakub Kicinski check $? "$s" '"Off"' 78*1da07e5dSJakub Kicinski 79*1da07e5dSJakub Kicinski $ETHTOOL --set-fec $NSIM_NETDEV encoding auto RS 80*1da07e5dSJakub Kicinski check $? 81*1da07e5dSJakub Kicinski 82*1da07e5dSJakub Kicinski s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].config[]') 83*1da07e5dSJakub Kicinski check $? "$s" '"Auto" 84*1da07e5dSJakub Kicinski"RS"' 85*1da07e5dSJakub Kicinski s=$($ETHTOOL --json --show-fec $NSIM_NETDEV | jq '.[].active[]') 86*1da07e5dSJakub Kicinski check $? "$s" '"RS"' 87*1da07e5dSJakub Kicinskifi 88*1da07e5dSJakub Kicinski 89*1da07e5dSJakub Kicinski# Test error injection 90*1da07e5dSJakub Kicinskiecho 11 > $NSIM_DEV_DFS/ethtool/get_err 91*1da07e5dSJakub Kicinski 92*1da07e5dSJakub Kicinski$ETHTOOL --show-fec $NSIM_NETDEV >>/dev/null 2>&1 93*1da07e5dSJakub Kicinskicheck $? '' '' 1 94*1da07e5dSJakub Kicinski 95*1da07e5dSJakub Kicinskiecho 0 > $NSIM_DEV_DFS/ethtool/get_err 96*1da07e5dSJakub Kicinskiecho 11 > $NSIM_DEV_DFS/ethtool/set_err 97*1da07e5dSJakub Kicinski 98*1da07e5dSJakub Kicinski$ETHTOOL --show-fec $NSIM_NETDEV >>/dev/null 2>&1 99*1da07e5dSJakub Kicinskicheck $? 100*1da07e5dSJakub Kicinski 101*1da07e5dSJakub Kicinski$ETHTOOL --set-fec $NSIM_NETDEV encoding RS 2>/dev/null 102*1da07e5dSJakub Kicinskicheck $? '' '' 1 103*1da07e5dSJakub Kicinski 104*1da07e5dSJakub Kicinskiif [ $num_errors -eq 0 ]; then 105*1da07e5dSJakub Kicinski echo "PASSED all $((num_passes)) checks" 106*1da07e5dSJakub Kicinski exit 0 107*1da07e5dSJakub Kicinskielse 108*1da07e5dSJakub Kicinski echo "FAILED $num_errors/$((num_errors+num_passes)) checks" 109*1da07e5dSJakub Kicinski exit 1 110*1da07e5dSJakub Kicinskifi 111