2 # Copyright (c) 2016 Microsemi. All Rights Reserved.
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.
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.
14 # Author: Logan Gunthorpe <logang@deltatee.com>
19 DEBUGFS=${DEBUGFS-/sys/kernel/debug}
30 echo "Usage: $0 [OPTIONS] LOCAL_DEV REMOTE_DEV"
31 echo "Run tests on a pair of NTB endpoints."
33 echo "If the NTB device loops back to the same host then,"
34 echo "just specifying the two PCI ids on the command line is"
35 echo "sufficient. Otherwise, if the NTB link spans two hosts"
36 echo "use the -r option to specify the hostname for the remote"
37 echo "device. SSH will then be used to test the remote side."
38 echo "An SSH key between the root users of the host would then"
39 echo "be highly recommended."
42 echo " -b BITMASK doorbell clear bitmask for ntb_tool"
43 echo " -C don't cleanup ntb modules on exit"
44 echo " -d run dma tests"
45 echo " -h show this help message"
46 echo " -l list available local and remote PCI ids"
47 echo " -r REMOTE_HOST specify the remote's hostname to connect"
48 echo " to for the test (using ssh)"
49 echo " -p NUM ntb_perf run order (default: $PERF_RUN_ORDER)"
50 echo " -w max_mw_size maxmium memory window size"
57 while getopts "b:Cdhlm:r:p:w:" opt; do
59 b) DB_BITMASK=${OPTARG} ;;
62 h) show_help; exit 0 ;;
64 m) MW_SIZE=${OPTARG} ;;
65 r) REMOTE_HOST=${OPTARG} ;;
66 p) PERF_RUN_ORDER=${OPTARG} ;;
67 w) MAX_MW_SIZE=${OPTARG} ;;
69 echo "Invalid option: -$OPTARG" >&2
92 if [[ "$REMOTE_HOST" != "" ]]; then
93 ssh "$REMOTE_HOST" modprobe "$@"
97 function split_remote()
102 if [[ "$VPATH" == *":/"* ]]; then
111 if [[ "$REMOTE" != "" ]]; then
112 ssh "$REMOTE" cat "$VPATH"
118 function write_file()
123 if [[ "$REMOTE" != "" ]]; then
124 ssh "$REMOTE" "echo \"$VALUE\" > \"$VPATH\""
126 echo "$VALUE" > "$VPATH"
136 echo "Running link tests on: $(basename $LOC) / $(basename $REM)"
138 if ! write_file "N" "$LOC/link" 2> /dev/null; then
143 write_file "N" "$LOC/link_event"
145 if [[ $(read_file "$REM/link") != "N" ]]; then
146 echo "Expected remote link to be down in $REM/link" >&2
150 write_file "Y" "$LOC/link"
151 write_file "Y" "$LOC/link_event"
156 function doorbell_test()
162 echo "Running db tests on: $(basename $LOC) / $(basename $REM)"
164 write_file "c $DB_BITMASK" "$REM/db"
166 for ((i=1; i <= 8; i++)); do
167 let DB=$(read_file "$REM/db") || true
168 if [[ "$DB" != "$EXP" ]]; then
169 echo "Doorbell doesn't match expected value $EXP " \
174 let "MASK=1 << ($i-1)" || true
175 let "EXP=$EXP | $MASK" || true
176 write_file "s $MASK" "$LOC/peer_db"
187 ROW=($(read_file "$VPATH" | grep -e "^$IDX"))
188 let VAL=${ROW[1]} || true
192 function scratchpad_test()
196 CNT=$(read_file "$LOC/spad" | wc -l)
198 echo "Running spad tests on: $(basename $LOC) / $(basename $REM)"
200 for ((i = 0; i < $CNT; i++)); do
202 write_file "$i $VAL" "$LOC/peer_spad"
203 RVAL=$(read_spad "$REM/spad" $i)
205 if [[ "$VAL" != "$RVAL" ]]; then
206 echo "Scratchpad doesn't match expected value $VAL " \
207 "in $REM/spad, got $RVAL" >&2
220 if [[ "$REMOTE" != "" ]]; then
222 dd if=/dev/urandom "of=$VPATH" 2> /dev/null || true
224 dd if=/dev/urandom "of=$VPATH" 2> /dev/null || true
234 echo "Running $IDX tests on: $(basename $LOC) / $(basename $REM)"
238 split_remote "$LOC/$IDX"
239 if [[ "$REMOTE" == "" ]]; then
243 ssh "$REMOTE" cat "$VPATH" > "$A"
246 split_remote "$REM/peer_$IDX"
247 if [[ "$REMOTE" == "" ]]; then
251 ssh "$REMOTE" cat "$VPATH" > "$B"
254 cmp -n $MW_SIZE "$A" "$B"
255 if [[ $? != 0 ]]; then
256 echo "Memory window $MW did not match!" >&2
259 if [[ "$A" == "/tmp/*" ]]; then
263 if [[ "$B" == "/tmp/*" ]]; then
270 function pingpong_test()
275 echo "Running ping pong tests on: $(basename $LOC) / $(basename $REM)"
277 LOC_START=$(read_file $LOC/count)
278 REM_START=$(read_file $REM/count)
282 LOC_END=$(read_file $LOC/count)
283 REM_END=$(read_file $REM/count)
285 if [[ $LOC_START == $LOC_END ]] || [[ $REM_START == $REM_END ]]; then
286 echo "Ping pong counter not incrementing!" >&2
297 if [[ $USE_DMA == "1" ]]; then
303 _modprobe ntb_perf run_order=$PERF_RUN_ORDER \
304 max_mw_size=$MAX_MW_SIZE use_dma=$USE_DMA
306 echo "Running local perf test $WITH DMA"
307 write_file "" $LOCAL_PERF/run
309 read_file $LOCAL_PERF/run
312 echo "Running remote perf test $WITH DMA"
313 write_file "" $REMOTE_PERF/run
315 read_file $REMOTE_PERF/run
318 _modprobe -r ntb_perf
321 function ntb_tool_tests()
323 LOCAL_TOOL=$DEBUGFS/ntb_tool/$LOCAL_DEV
324 REMOTE_TOOL=$REMOTE_HOST:$DEBUGFS/ntb_tool/$REMOTE_DEV
326 echo "Starting ntb_tool tests..."
330 write_file Y $LOCAL_TOOL/link_event
331 write_file Y $REMOTE_TOOL/link_event
333 link_test $LOCAL_TOOL $REMOTE_TOOL
334 link_test $REMOTE_TOOL $LOCAL_TOOL
336 for PEER_TRANS in $(ls $LOCAL_TOOL/peer_trans*); do
337 PT=$(basename $PEER_TRANS)
338 write_file $MW_SIZE $LOCAL_TOOL/$PT
339 write_file $MW_SIZE $REMOTE_TOOL/$PT
342 doorbell_test $LOCAL_TOOL $REMOTE_TOOL
343 doorbell_test $REMOTE_TOOL $LOCAL_TOOL
344 scratchpad_test $LOCAL_TOOL $REMOTE_TOOL
345 scratchpad_test $REMOTE_TOOL $LOCAL_TOOL
347 for MW in $(ls $LOCAL_TOOL/mw*); do
350 mw_test $MW $LOCAL_TOOL $REMOTE_TOOL
351 mw_test $MW $REMOTE_TOOL $LOCAL_TOOL
354 _modprobe -r ntb_tool
357 function ntb_pingpong_tests()
359 LOCAL_PP=$DEBUGFS/ntb_pingpong/$LOCAL_DEV
360 REMOTE_PP=$REMOTE_HOST:$DEBUGFS/ntb_pingpong/$REMOTE_DEV
362 echo "Starting ntb_pingpong tests..."
364 _modprobe ntb_pingpong
366 pingpong_test $LOCAL_PP $REMOTE_PP
368 _modprobe -r ntb_pingpong
371 function ntb_perf_tests()
373 LOCAL_PERF=$DEBUGFS/ntb_perf/$LOCAL_DEV
374 REMOTE_PERF=$REMOTE_HOST:$DEBUGFS/ntb_perf/$REMOTE_DEV
376 echo "Starting ntb_perf tests..."
380 if [[ $RUN_DMA_TESTS ]]; then
388 _modprobe -r ntb_tool 2> /dev/null
389 _modprobe -r ntb_perf 2> /dev/null
390 _modprobe -r ntb_pingpong 2> /dev/null
391 _modprobe -r ntb_transport 2> /dev/null
397 if ! [[ $$DONT_CLEANUP ]]; then
401 if [ "$(id -u)" != "0" ]; then
402 echo "This script must be run as root" 1>&2
406 if [[ "$LIST_DEVS" == TRUE ]]; then
407 echo "Local Devices:"
408 ls -1 /sys/bus/ntb/devices
411 if [[ "$REMOTE_HOST" != "" ]]; then
412 echo "Remote Devices:"
413 ssh $REMOTE_HOST ls -1 /sys/bus/ntb/devices
419 if [[ "$LOCAL_DEV" == $"" ]] || [[ "$REMOTE_DEV" == $"" ]]; then