diff --git a/tools/testing/selftests/drivers/net/dpll/dpll_features.sh b/tools/testing/selftests/drivers/net/dpll/dpll_features.sh
index 42271769b2e706..941b7ee848f951 100755
--- a/tools/testing/selftests/drivers/net/dpll/dpll_features.sh
+++ b/tools/testing/selftests/drivers/net/dpll/dpll_features.sh
@@ -16,11 +16,76 @@ source "$SCRIPTDIR/../lib/sh/dpll_lib.sh"
ALL_TESTS="
test_pin_state_transitions
+ test_pin_priority_get_set
"
##############################################################################
# Pin-level feature tests
+test_pin_priority_get_set()
+{
+ local before target after reason candidate
+
+ RET=0
+
+ if [ -z "$PIN_TUNE_ID" ]; then
+ dpll_log_test_skip_or_fail "DPLL pin priority set/get" \
+ "no spare input pin"
+ return
+ fi
+ if ! dpll_pin_set_supports prio; then
+ log_test_skip "DPLL pin priority set/get" \
+ "dpll tool lacks pin set prio"
+ return
+ fi
+ if ! dpll_pin_has_capability "$PIN_TUNE_ID" priority-can-change; then
+ dpll_log_test_skip_or_fail "DPLL pin priority set/get" \
+ "priority cannot change"
+ return
+ fi
+
+ before=$(dpll_pin_get_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID")
+ if [ -z "$before" ]; then
+ dpll_log_test_skip_or_fail "DPLL pin priority set/get" \
+ "prio not reported"
+ return
+ fi
+ defer dpll_pin_set_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID" "$before"
+
+ # The accepted range is not advertised, so try one below the current
+ # value and then small values, a refusal of all of them is a skip on
+ # a device the user provided, the simulator accepts every priority.
+ target=""
+ for candidate in $((before - 1)) 1 7; do
+ [ "$candidate" -ge 0 ] && [ "$candidate" != "$before" ] ||
+ continue
+ if dpll_pin_set_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID" \
+ "$candidate"; then
+ target=$candidate
+ break
+ fi
+ reason=${DPLL_LAST_ERR%%$'\n'*}
+ done
+ if [ -z "$target" ]; then
+ dpll_log_test_skip_or_fail "DPLL pin priority set/get" \
+ "cannot set a new prio${reason:+, $reason}"
+ return
+ fi
+ after=$(dpll_pin_get_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID")
+ if [ "$after" != "$target" ]; then
+ check_err 1 "priority expected $target, got '$after'"
+ fi
+
+ dpll_pin_set_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID" "$before"
+ check_err $? "cannot restore pin priority"
+ after=$(dpll_pin_get_prio "$DPLL_DEV_ID" "$PIN_TUNE_ID")
+ if [ "$after" != "$before" ]; then
+ check_err 1 "priority not restored, got '$after'"
+ fi
+
+ log_test "DPLL pin priority set/get"
+}
+
test_pin_state_transitions()
{
local before state after reasondiff --git a/tools/testing/selftests/drivers/net/dpll/dpll_stress.sh b/tools/testing/selftests/drivers/net/dpll/dpll_stress.sh
index ee543e2cd8703c..60e42107c67efe 100755
--- a/tools/testing/selftests/drivers/net/dpll/dpll_stress.sh
+++ b/tools/testing/selftests/drivers/net/dpll/dpll_stress.sh
@@ -77,13 +77,13 @@ create_stress_device()
local clock_id=$1
local num_pins=$2
local name="st$clock_id"
- local i type freq dir
+ local i type freq dir prio
local dirs=(input output)
dpllsim_create_device "$name" "$clock_id" || return 1
# Always have at least one plain input pin, then random ones
- if ! dpllsim_add_pin "$name" ext0 ext 10000000 input; then
+ if ! dpllsim_add_pin "$name" ext0 ext 10000000 input 1; then
dpllsim_delete_device "$name"
return 1
fi
@@ -94,8 +94,11 @@ create_stress_device()
# output one
dir=${dirs[RANDOM % 2]}
[ "$type" = mux ] && dir=input
- if ! dpllsim_add_pin "$name" "pin$i" "$type" "$freq" \
- "$dir"; then
+ # Only input pins accept a priority
+ prio=""
+ [ "$dir" = input ] && prio=$((RANDOM % 128))
+ if ! dpllsim_add_pin "$name" "pin$i" "$type" "$freq" "$dir" \
+ "$prio"; then
dpllsim_delete_device "$name"
return 1
fi@@ -205,8 +208,8 @@ test_deploy_cycle()
fi
track_device "$name"
- if ! dpllsim_add_pin "$name" gnss0 gnss 1 input ||
- ! dpllsim_add_pin "$name" ext0 ext 10000000 input ||
+ if ! dpllsim_add_pin "$name" gnss0 gnss 1 input 0 ||
+ ! dpllsim_add_pin "$name" ext0 ext 10000000 input 1 ||
! dpllsim_add_pin "$name" out0 ext 10000000 output; then
check_err 1 "cannot add pins"
log_test "DPLL deploy/undeploy cycling"
diff --git a/tools/testing/selftests/drivers/net/lib/sh/dpll_lib.sh b/tools/testing/selftests/drivers/net/lib/sh/dpll_lib.sh
index badb787815d42f..613ed365e3e311 100644
--- a/tools/testing/selftests/drivers/net/lib/sh/dpll_lib.sh
+++ b/tools/testing/selftests/drivers/net/lib/sh/dpll_lib.sh
@@ -373,6 +373,11 @@ dpll_pin_has_capability()
<<< "$out" &> /dev/null
}
+dpll_pin_get_prio()
+{
+ __dpll_pin_dev_field "$1" "$2" '.prio'
+}
+
##############################################################################
# Pin setters
#@@ -394,6 +399,16 @@ dpll_pin_set_state()
state "$state" 2>&1 >/dev/null)
}
+dpll_pin_set_prio()
+{
+ local dev_id=$1
+ local pin_id=$2
+ local prio=$3
+
+ DPLL_LAST_ERR=$(dpll pin set id "$pin_id" parent-device "$dev_id" \
+ prio "$prio" 2>&1 >/dev/null)
+}
+
##############################################################################
# dpllsim configfs interface
#@@ -475,7 +490,9 @@ dpllsim_create_device()
# $1: device name, $2: pin name (becomes the board-label), $3: type (gnss,
# int-oscillator, ext, synce-eth-port, mux), $4: frequency in Hz,
-# $5: direction (input/output)
+# $5: direction (input/output), $6: prio (optional, input pins only).
+# The priority is written only when one is given, so a pin without one
+# keeps the default of the simulator.
dpllsim_add_pin()
{
local dev=$1@@ -483,13 +500,16 @@ dpllsim_add_pin()
local type=$3
local frequency=$4
local direction=$5
+ local prio=${6:-}
local pin_path="$DPLLSIM_CFG/$dev/pins/$pin"
mkdir "$pin_path" 2>/dev/null || return 1
if ! echo "$type" 2>/dev/null > "$pin_path/type" ||
! echo "$frequency" 2>/dev/null > "$pin_path/frequency" ||
- ! echo "$direction" 2>/dev/null > "$pin_path/direction"; then
+ ! echo "$direction" 2>/dev/null > "$pin_path/direction" ||
+ { [ -n "$prio" ] &&
+ ! echo "$prio" 2>/dev/null > "$pin_path/prio"; }; then
rmdir "$pin_path" 2>/dev/null
return 1
fi@@ -537,8 +557,8 @@ dpllsim_alloc_clock_id()
# Create a device with the standard 3-pin layout, deploy it and resolve
# the netlink device id. Sets DPLLSIM_CREATED_NAME, DPLLSIM_CLOCK_ID and
# DPLLSIM_DEV_ID.
-# gnss0: GNSS, 1 Hz, input
-# ext0: EXT, 10 MHz, input
+# gnss0: GNSS, 1 Hz, input, prio 0 (active reference)
+# ext0: EXT, 10 MHz, input, prio 1
# out0: EXT, 10 MHz, output
dpllsim_setup_standard_device()
{@@ -549,8 +569,8 @@ dpllsim_setup_standard_device()
name="std$clock_id"
dpllsim_create_device "$name" "$clock_id" || return 1
- if ! dpllsim_add_pin "$name" gnss0 gnss 1 input ||
- ! dpllsim_add_pin "$name" ext0 ext 10000000 input ||
+ if ! dpllsim_add_pin "$name" gnss0 gnss 1 input 0 ||
+ ! dpllsim_add_pin "$name" ext0 ext 10000000 input 1 ||
! dpllsim_add_pin "$name" out0 ext 10000000 output; then
dpllsim_delete_device "$name"
return 1
--
2.56.0