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