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