aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MAINTAINERS1
-rwxr-xr-xtools/testing/selftests/ntb/ntb_test.sh422
2 files changed, 423 insertions, 0 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index 8c20323d1277..46130feca8a8 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8131,6 +8131,7 @@ F: drivers/ntb/
8131F: drivers/net/ntb_netdev.c 8131F: drivers/net/ntb_netdev.c
8132F: include/linux/ntb.h 8132F: include/linux/ntb.h
8133F: include/linux/ntb_transport.h 8133F: include/linux/ntb_transport.h
8134F: tools/testing/selftests/ntb/
8134 8135
8135NTB INTEL DRIVER 8136NTB INTEL DRIVER
8136M: Jon Mason <jdmason@kudzu.us> 8137M: Jon Mason <jdmason@kudzu.us>
diff --git a/tools/testing/selftests/ntb/ntb_test.sh b/tools/testing/selftests/ntb/ntb_test.sh
new file mode 100755
index 000000000000..a676d3eefefb
--- /dev/null
+++ b/tools/testing/selftests/ntb/ntb_test.sh
@@ -0,0 +1,422 @@
1#!/bin/bash
2# Copyright (c) 2016 Microsemi. All Rights Reserved.
3#
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the GNU General Public License as
6# published by the Free Software Foundation; either version 2 of
7# the License, or (at your option) any later version.
8#
9# This program is distributed in the hope that it would be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# Author: Logan Gunthorpe <logang@deltatee.com>
15
16REMOTE_HOST=
17LIST_DEVS=FALSE
18
19DEBUGFS=${DEBUGFS-/sys/kernel/debug}
20
21PERF_RUN_ORDER=32
22MAX_MW_SIZE=0
23RUN_DMA_TESTS=
24DONT_CLEANUP=
25MW_SIZE=65536
26
27function show_help()
28{
29 echo "Usage: $0 [OPTIONS] LOCAL_DEV REMOTE_DEV"
30 echo "Run tests on a pair of NTB endpoints."
31 echo
32 echo "If the NTB device loops back to the same host then,"
33 echo "just specifying the two PCI ids on the command line is"
34 echo "sufficient. Otherwise, if the NTB link spans two hosts"
35 echo "use the -r option to specify the hostname for the remote"
36 echo "device. SSH will then be used to test the remote side."
37 echo "An SSH key between the root users of the host would then"
38 echo "be highly recommended."
39 echo
40 echo "Options:"
41 echo " -C don't cleanup ntb modules on exit"
42 echo " -d run dma tests"
43 echo " -h show this help message"
44 echo " -l list available local and remote PCI ids"
45 echo " -r REMOTE_HOST specify the remote's hostname to connect"
46 echo " to for the test (using ssh)"
47 echo " -p NUM ntb_perf run order (default: $PERF_RUN_ORDER)"
48 echo " -w max_mw_size maxmium memory window size"
49 echo
50}
51
52function parse_args()
53{
54 OPTIND=0
55 while getopts "Cdhlm:r:p:w:" opt; do
56 case "$opt" in
57 C) DONT_CLEANUP=1 ;;
58 d) RUN_DMA_TESTS=1 ;;
59 h) show_help; exit 0 ;;
60 l) LIST_DEVS=TRUE ;;
61 m) MW_SIZE=${OPTARG} ;;
62 r) REMOTE_HOST=${OPTARG} ;;
63 p) PERF_RUN_ORDER=${OPTARG} ;;
64 w) MAX_MW_SIZE=${OPTARG} ;;
65 \?)
66 echo "Invalid option: -$OPTARG" >&2
67 exit 1
68 ;;
69 esac
70 done
71}
72
73parse_args "$@"
74shift $((OPTIND-1))
75LOCAL_DEV=$1
76shift
77parse_args "$@"
78shift $((OPTIND-1))
79REMOTE_DEV=$1
80shift
81parse_args "$@"
82
83set -e
84
85function _modprobe()
86{
87 modprobe "$@"
88}
89
90function split_remote()
91{
92 VPATH=$1
93 REMOTE=
94
95 if [[ "$VPATH" == *":/"* ]]; then
96 REMOTE=${VPATH%%:*}
97 VPATH=${VPATH#*:}
98 fi
99}
100
101function read_file()
102{
103 split_remote $1
104 if [[ "$REMOTE" != "" ]]; then
105 ssh "$REMOTE" cat "$VPATH"
106 else
107 cat "$VPATH"
108 fi
109}
110
111function write_file()
112{
113 split_remote $2
114 VALUE=$1
115
116 if [[ "$REMOTE" != "" ]]; then
117 ssh "$REMOTE" "echo \"$VALUE\" > \"$VPATH\""
118 else
119 echo "$VALUE" > "$VPATH"
120 fi
121}
122
123function link_test()
124{
125 LOC=$1
126 REM=$2
127 EXP=0
128
129 echo "Running link tests on: $(basename $LOC) / $(basename $REM)"
130
131 if ! write_file "N" "$LOC/link" 2> /dev/null; then
132 echo " Unsupported"
133 return
134 fi
135
136 write_file "N" "$LOC/link_event"
137
138 if [[ $(read_file "$REM/link") != "N" ]]; then
139 echo "Expected remote link to be down in $REM/link" >&2
140 exit -1
141 fi
142
143 write_file "Y" "$LOC/link"
144 write_file "Y" "$LOC/link_event"
145
146 echo " Passed"
147}
148
149function doorbell_test()
150{
151 LOC=$1
152 REM=$2
153 EXP=0
154
155 echo "Running db tests on: $(basename $LOC) / $(basename $REM)"
156
157 write_file "c 0xFFFFFFFF" "$REM/db"
158
159 for ((i=1; i <= 8; i++)); do
160 let DB=$(read_file "$REM/db") || true
161 if [[ "$DB" != "$EXP" ]]; then
162 echo "Doorbell doesn't match expected value $EXP " \
163 "in $REM/db" >&2
164 exit -1
165 fi
166
167 let "MASK=1 << ($i-1)" || true
168 let "EXP=$EXP | $MASK" || true
169 write_file "s $MASK" "$LOC/peer_db"
170 done
171
172 echo " Passed"
173}
174
175function read_spad()
176{
177 VPATH=$1
178 IDX=$2
179
180 ROW=($(read_file "$VPATH" | grep -e "^$IDX"))
181 let VAL=${ROW[1]} || true
182 echo $VAL
183}
184
185function scratchpad_test()
186{
187 LOC=$1
188 REM=$2
189 CNT=$(read_file "$LOC/spad" | wc -l)
190
191 echo "Running spad tests on: $(basename $LOC) / $(basename $REM)"
192
193 for ((i = 0; i < $CNT; i++)); do
194 VAL=$RANDOM
195 write_file "$i $VAL" "$LOC/peer_spad"
196 RVAL=$(read_spad "$REM/spad" $i)
197
198 if [[ "$VAL" != "$RVAL" ]]; then
199 echo "Scratchpad doesn't match expected value $VAL " \
200 "in $REM/spad, got $RVAL" >&2