All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ivan Vecera <ivecera@redhat.com>
To: netdev@vger.kernel.org
Cc: Vadim Fedorenko <vadim.fedorenko@linux.dev>,
	Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>,
	Jiri Pirko <jiri@resnulli.us>, Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Donald Hunter <donald.hunter@gmail.com>,
	Tony Nguyen <anthony.l.nguyen@intel.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Alexander Lobakin <aleksander.lobakin@intel.com>,
	Richard Cochran <richardcochran@gmail.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	intel-wired-lan@lists.osuosl.org, Min Li <min.li@microchip.com>,
	Grzegorz Nitka <grzegorz.nitka@intel.com>,
	Karol Kolacinski <karol.kolacinski@intel.com>,
	Saeed Mahameed <saeedm@nvidia.com>,
	Tariq Toukan <tariqt@nvidia.com>, Petr Oros <poros@redhat.com>
Subject: [PATCH RFC net-next 19/19] dpll: add KUnit tests for the pin owner checks
Date: Thu, 26 Nov 2026 21:32:31 +0100	[thread overview]
Message-ID: <20261126203231.934632-20-ivecera@redhat.com> (raw)
In-Reply-To: <20261126203231.934632-1-ivecera@redhat.com>

Check that dpll_pin_register() rejects a DPLL of another owner and a
DPLL that is not registered, that dpll_pin_on_pin_register() rejects a
parent pin of another owner and a parent pin registered with a DPLL
that is not registered any more, and that a pin of the owner is still
shared by its DPLLs and registered under its parent pin.

The checks are WARN_ON_ONCE(), so the tests suppress the warning without
counting it. A registration that is not rejected is undone, so the next
case does not get the registered pin and the failure stays in its case.

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
 drivers/dpll/Kconfig            |   4 +-
 drivers/dpll/tests/dpll_kunit.c | 150 +++++++++++++++++++++++++++++---
 2 files changed, 142 insertions(+), 12 deletions(-)

diff --git a/drivers/dpll/Kconfig b/drivers/dpll/Kconfig
index d57696652d450a..9be76330a1d1de 100644
--- a/drivers/dpll/Kconfig
+++ b/drivers/dpll/Kconfig
@@ -31,7 +31,9 @@ config DPLL_KUNIT_TEST
 	help
 	  KUnit tests for the DPLL core. They use a mock driver to check
 	  that links between pins of two devices are reported and notified
-	  while the pins at both ends are registered.
+	  while the pins at both ends are registered, and that a pin is
+	  registered only with the registered devices and the parent pins
+	  of its owner.
 
 	  The mock devices and pins are registered with the DPLL subsystem,
 	  so user space sees them and their create and delete notifications
diff --git a/drivers/dpll/tests/dpll_kunit.c b/drivers/dpll/tests/dpll_kunit.c
index 1804e5836f7db2..20bda0934acb1d 100644
--- a/drivers/dpll/tests/dpll_kunit.c
+++ b/drivers/dpll/tests/dpll_kunit.c
@@ -1,11 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- * KUnit tests for links between DPLL pins.
+ * KUnit tests for links between DPLL pins and for the owner checks of pin
+ * registrations.
  *
  * Each test starts with two owners that differ in clock_id:
  *
  * Owner A: devices A0 and A1, pin P with firmware node F, pin U with
- *          neither a firmware node nor a link
+ *          neither a firmware node nor a link, MUX pin M
  * Owner B: device B0, pin C with a link to F
  *
  * The devices are registered, the pins are not.
@@ -40,9 +41,9 @@ struct dt_pin {
 
 struct dt_ctx {
 	struct dt_dev a0, a1, b0;
-	struct dt_pin p, u, c;
+	struct dt_pin p, u, c, m;
 	struct fwnode_handle *fwnode;
-	bool p_a0, p_a1, u_a0, c_b0;	/* registrations */
+	bool p_a0, p_a1, u_a0, c_b0, m_a0, u_m;	/* registrations */
 };
 
 static int dt_mode_get(const struct dpll_device *dpll, void *dpll_priv,
@@ -89,10 +90,29 @@ static const struct dpll_pin_ops dt_pin_ops = {
 	.direction_get = dt_direction_get,
 };
 
+static int dt_state_on_pin_get(const struct dpll_pin *pin, void *pin_priv,
+			       const struct dpll_pin *parent_pin,
+			       void *parent_pin_priv,
+			       enum dpll_pin_state *state,
+			       struct netlink_ext_ack *extack)
+{
+	*state = DPLL_PIN_STATE_CONNECTED;
+	return 0;
+}
+
+static const struct dpll_pin_ops dt_child_ops = {
+	.state_on_pin_get = dt_state_on_pin_get,
+	.direction_get = dt_direction_get,
+};
+
 static const struct dpll_pin_properties dt_pin_prop = {
 	.type = DPLL_PIN_TYPE_EXT,
 };
 
+static const struct dpll_pin_properties dt_mux_prop = {
+	.type = DPLL_PIN_TYPE_MUX,
+};
+
 /* Stub of __dpll_pin_change_ntf() that counts the notifications */
 static int dt_pin_change_ntf(struct dpll_pin *pin)
 {
@@ -130,9 +150,9 @@ static void dt_dev_fini(struct dt_dev *dev)
 }
 
 static void dt_pin_get(struct kunit *test, struct dt_pin *pin, u64 clock_id,
-		       u32 idx)
+		       u32 idx, const struct dpll_pin_properties *prop)
 {
-	pin->pin = dpll_pin_get(clock_id, idx, THIS_MODULE, &dt_pin_prop,
+	pin->pin = dpll_pin_get(clock_id, idx, THIS_MODULE, prop,
 				&pin->tracker);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, pin->pin);
 }
@@ -223,9 +243,10 @@ static int dt_init(struct kunit *test)
 	dt_dev_init(test, &ctx->a0, DT_CLOCK_ID_A, 0);
 	dt_dev_init(test, &ctx->a1, DT_CLOCK_ID_A, 1);
 	dt_dev_init(test, &ctx->b0, DT_CLOCK_ID_B, 0);
-	dt_pin_get(test, &ctx->p, DT_CLOCK_ID_A, 0);
-	dt_pin_get(test, &ctx->u, DT_CLOCK_ID_A, 1);
-	dt_pin_get(test, &ctx->c, DT_CLOCK_ID_B, 0);
+	dt_pin_get(test, &ctx->p, DT_CLOCK_ID_A, 0, &dt_pin_prop);
+	dt_pin_get(test, &ctx->u, DT_CLOCK_ID_A, 1, &dt_pin_prop);
+	dt_pin_get(test, &ctx->m, DT_CLOCK_ID_A, 2, &dt_mux_prop);
+	dt_pin_get(test, &ctx->c, DT_CLOCK_ID_B, 0, &dt_pin_prop);
 	dpll_pin_fwnode_set(ctx->p.pin, ctx->fwnode);
 	ret = dpll_pin_link_add(ctx->c.pin, ctx->fwnode);
 	KUNIT_ASSERT_EQ(test, ret, 0);
@@ -242,11 +263,16 @@ static void dt_exit(struct kunit *test)
 
 	if (!ctx)
 		return;
+	if (ctx->u_m)
+		dpll_pin_on_pin_unregister(ctx->m.pin, ctx->u.pin,
+					   &dt_child_ops, &ctx->u);
+	dt_unreg(&ctx->a0, &ctx->m, &ctx->m_a0);
 	dt_unreg(&ctx->a0, &ctx->p, &ctx->p_a0);
 	dt_unreg(&ctx->a1, &ctx->p, &ctx->p_a1);
 	dt_unreg(&ctx->a0, &ctx->u, &ctx->u_a0);
 	dt_unreg(&ctx->b0, &ctx->c, &ctx->c_b0);
 	dt_pin_put(&ctx->c);
+	dt_pin_put(&ctx->m);
 	dt_pin_put(&ctx->u);
 	dt_pin_put(&ctx->p);
 	dt_dev_fini(&ctx->b0);
@@ -404,7 +430,109 @@ static struct kunit_suite dt_suite = {
 	.test_cases = dt_cases,
 };
 
-kunit_test_suite(dt_suite);
+/*
+ * The checks are WARN_ON_ONCE(), so the tests suppress the warning without
+ * counting it. A registration that is not rejected is undone, otherwise the
+ * next case would get the registered pin from dpll_pin_get() and fail too.
+ */
+
+/* Expect the registration of @pin with @dev to be rejected */
+static void dt_expect_reg_rejected(struct kunit *test, struct dt_dev *dev,
+				   struct dt_pin *pin)
+{
+	int ret;
+
+	kunit_warning_suppress(test) {
+		ret = dpll_pin_register(dev->dpll, pin->pin, &dt_pin_ops, pin);
+		KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+		if (!ret)
+			dpll_pin_unregister(dev->dpll, pin->pin, &dt_pin_ops,
+					    pin);
+	}
+}
+
+/* Expect the registration of @pin under @parent to be rejected */
+static void dt_expect_on_pin_rejected(struct kunit *test,
+				      struct dt_pin *parent,
+				      struct dt_pin *pin)
+{
+	int ret;
+
+	kunit_warning_suppress(test) {
+		ret = dpll_pin_on_pin_register(parent->pin, pin->pin,
+					       &dt_child_ops, pin);
+		KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+		if (!ret)
+			dpll_pin_on_pin_unregister(parent->pin, pin->pin,
+						   &dt_child_ops, pin);
+	}
+}
+
+/* A pin is registered with the DPLLs of its owner only */
+static void dt_test_owner_register(struct kunit *test)
+{
+	struct dt_ctx *ctx = test->priv;
+
+	dt_expect_reg_rejected(test, &ctx->b0, &ctx->p);
+	dt_reg(test, &ctx->a0, &ctx->p, &ctx->p_a0);
+	dt_reg(test, &ctx->a1, &ctx->p, &ctx->p_a1);
+}
+
+/* A pin is registered under the parent pins of its owner only */
+static void dt_test_owner_on_pin(struct kunit *test)
+{
+	struct dt_ctx *ctx = test->priv;
+	int ret;
+
+	dt_reg(test, &ctx->a0, &ctx->m, &ctx->m_a0);
+	dt_expect_on_pin_rejected(test, &ctx->m, &ctx->c);
+
+	ret = dpll_pin_on_pin_register(ctx->m.pin, ctx->u.pin, &dt_child_ops,
+				       &ctx->u);
+	KUNIT_ASSERT_EQ(test, ret, 0);
+	ctx->u_m = true;
+}
+
+/* A pin is registered with a registered DPLL only */
+static void dt_test_unregistered_dpll(struct kunit *test)
+{
+	struct dt_ctx *ctx = test->priv;
+	struct dt_dev a2 = {};
+
+	a2.dpll = dpll_device_get(DT_CLOCK_ID_A, 2, THIS_MODULE, &a2.tracker);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, a2.dpll);
+	dt_expect_reg_rejected(test, &a2, &ctx->p);
+	dt_dev_fini(&a2);
+}
+
+/* A pin is registered under a parent pin with registered DPLLs only */
+static void dt_test_unregistered_parent_dpll(struct kunit *test)
+{
+	struct dt_ctx *ctx = test->priv;
+
+	/* The parent pin stays registered with a0 after a0 goes, as on E810 */
+	dt_reg(test, &ctx->a0, &ctx->m, &ctx->m_a0);
+	dpll_device_unregister(ctx->a0.dpll, &dt_dev_ops, &ctx->a0);
+	ctx->a0.registered = false;
+	dt_expect_on_pin_rejected(test, &ctx->m, &ctx->u);
+}
+
+static struct kunit_case dt_owner_cases[] = {
+	KUNIT_CASE(dt_test_owner_register),
+	KUNIT_CASE(dt_test_owner_on_pin),
+	KUNIT_CASE(dt_test_unregistered_dpll),
+	KUNIT_CASE(dt_test_unregistered_parent_dpll),
+	{}
+};
+
+static struct kunit_suite dt_owner_suite = {
+	.name = "dpll_pin_owner",
+	.init = dt_init,
+	.exit = dt_exit,
+	.test_cases = dt_owner_cases,
+};
+
+kunit_test_suites(&dt_suite, &dt_owner_suite);
 
-MODULE_DESCRIPTION("KUnit tests for links between DPLL pins");
+MODULE_DESCRIPTION("KUnit tests for links and owners of DPLL pins");
 MODULE_LICENSE("GPL");
-- 
2.56.1


      parent reply	other threads:[~2026-11-26 20:34 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 20:32 [PATCH RFC net-next 00/19] dpll: single-owner pins, board wiring as pin links Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 01/19] dpll: add " Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 02/19] dpll: report " Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 03/19] dpll: notify linked pins when a pin is registered or unregistered Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 04/19] dpll: add KUnit tests for pin links Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 05/19] ice: dpll: use own pins for the TX and time references Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 06/19] ice: dpll: drop the filter of notifications from own registrations Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 07/19] dpll: register pins only with a DPLL of their owner Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 08/19] dpll: drop the state change exception for pins with a firmware node Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 09/19] dpll: drop the source clock id from pin notifications Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 10/19] dpll: drop device events from the in-kernel notifier Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 11/19] dpll: drop the cached module name of a pin Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 12/19] ice: dpll: track the E825 recovered clock routing in the adapter Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 13/19] ice: dpll: register the E825 recovered clock muxes as DPLL devices Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 14/19] ice: dpll: route the E825 recovered clock through the mux devices Ivan Vecera
2026-11-27 20:35   ` sashiko-bot
2026-11-26 20:32 ` [PATCH RFC net-next 15/19] dpll: register pins only with a parent pin of their owner Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 16/19] dpll: drop the in-kernel notifier chain Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 17/19] dpll: require a registered DPLL for pin registration Ivan Vecera
2026-11-26 20:32 ` [PATCH RFC net-next 18/19] dpll: drop the owner reference selection of pins Ivan Vecera
2026-11-26 20:32 ` Ivan Vecera [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126203231.934632-20-ivecera@redhat.com \
    --to=ivecera@redhat.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=arkadiusz.kubalewski@intel.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=grzegorz.nitka@intel.com \
    --cc=horms@kernel.org \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jiri@resnulli.us \
    --cc=karol.kolacinski@intel.com \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=min.li@microchip.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=poros@redhat.com \
    --cc=przemyslaw.kitszel@intel.com \
    --cc=rdunlap@infradead.org \
    --cc=richardcochran@gmail.com \
    --cc=saeedm@nvidia.com \
    --cc=skhan@linuxfoundation.org \
    --cc=tariqt@nvidia.com \
    --cc=vadim.fedorenko@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.