Netdev List
 help / color / mirror / Atom feed
From: Ivan Vecera <ivecera@redhat.com>
To: netdev@vger.kernel.org
Cc: Jiri Pirko <jiri@resnulli.us>,
	"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>, Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Min Li <min.li@microchip.com>,
	Vadim Fedorenko <vadim.fedorenko@linux.dev>,
	Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>,
	linux-doc@vger.kernel.org
Subject: [PATCH net-next 1/3] dpll: zl3073x: factor device CPU reset into a helper
Date: Thu,  3 Dec 2026 19:06:25 +0100	[thread overview]
Message-ID: <20261203180627.215256-2-ivecera@redhat.com> (raw)
In-Reply-To: <20261203180627.215256-1-ivecera@redhat.com>

zl3073x_flash_mode_leave() resets the device CPU back to normal
firmware processing via an open-coded HW register write sequence in
flash.c. The same core reset is needed for a full device reset that
reboots the firmware and reloads the configuration from flash,
introduced later in this series. Factor it into a reusable helper,
zl3073x_dev_hw_reset(), in core.c.

Drop the 'wait' field from struct zl3073x_hwreg_seq_item and the
HWREG_SEQ_ITEM() macro. zl3073x_write_hwreg_seq() tested seq->wait
instead of seq[i].wait, so only the first item of a sequence was
considered and, as that is zero in all the sequences, the 1000 ms
waits requested by the flash mode enter sequences never took place.
The flash update has worked without them, so drop them instead of
fixing the test. zl3073x_flash_mode_leave() waits after the core reset
with msleep() on its own, and that wait moves into the helper.

Reviewed-by: Min Li <min.li@microchip.com>
Tested-by: Min Li <min.li@microchip.com>
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
 drivers/dpll/zl3073x/core.c  | 58 ++++++++++++++++++++++++--
 drivers/dpll/zl3073x/core.h  |  6 +--
 drivers/dpll/zl3073x/flash.c | 79 ++++++++----------------------------
 3 files changed, 74 insertions(+), 69 deletions(-)

diff --git a/drivers/dpll/zl3073x/core.c b/drivers/dpll/zl3073x/core.c
index 230df08e27cd19..27a55d810d5b05 100644
--- a/drivers/dpll/zl3073x/core.c
+++ b/drivers/dpll/zl3073x/core.c
@@ -497,14 +497,66 @@ int zl3073x_write_hwreg_seq(struct zl3073x_dev *zldev,
 						  seq[i].value, seq[i].mask);
 		if (rc)
 			return rc;
-
-		if (seq->wait)
-			msleep(seq->wait);
 	}
 
 	return rc;
 }
 
+/**
+ * zl3073x_dev_hw_reset - Reset the device CPU and reload firmware and config
+ * @zldev: zl3073x device pointer
+ *
+ * Triggers a core reset that reboots the firmware and reloads the whole
+ * configuration from flash. The device is inaccessible on the control bus
+ * while the reset is in progress.
+ *
+ * Context: Process context. The caller must stop normal operation with
+ * zl3073x_dev_stop() first.
+ *
+ * Return: 0 on success, <0 on error
+ */
+int zl3073x_dev_hw_reset(struct zl3073x_dev *zldev)
+{
+	static const struct zl3073x_hwreg_seq_item hw_seq[] = {
+		HWREG_SEQ_ITEM(0x80000404, 1, BIT(0)),
+		HWREG_SEQ_ITEM(0x80000410, 1, BIT(0)),
+	};
+	u8 reset_status;
+	int rc;
+
+	/* Read reset status register */
+	rc = zl3073x_read_u8(zldev, ZL_REG_RESET_STATUS, &reset_status);
+	if (rc)
+		return rc;
+
+	/* Arm the reset detection flag */
+	reset_status |= ZL_REG_RESET_STATUS_RESET;
+	rc = zl3073x_write_u8(zldev, ZL_REG_RESET_STATUS, reset_status);
+	if (rc)
+		return rc;
+
+	/* Trigger the core reset. The last write typically errors out as
+	 * the device CPU resets mid-transaction, so its return value is
+	 * not checked.
+	 */
+	zl3073x_write_hwreg_seq(zldev, hw_seq, ARRAY_SIZE(hw_seq));
+
+	msleep(500);
+
+	/* Read again the reset status register */
+	rc = zl3073x_read_u8(zldev, ZL_REG_RESET_STATUS, &reset_status);
+	if (rc)
+		return rc;
+
+	/* Check the reset flag was cleared by the firmware */
+	if (reset_status & ZL_REG_RESET_STATUS_RESET) {
+		dev_err(zldev->dev, "Device reset not confirmed\n");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int
 zl3073x_dev_state_fetch(struct zl3073x_dev *zldev)
 {
diff --git a/drivers/dpll/zl3073x/core.h b/drivers/dpll/zl3073x/core.h
index 67c10e2595118c..4d979543500c4e 100644
--- a/drivers/dpll/zl3073x/core.h
+++ b/drivers/dpll/zl3073x/core.h
@@ -125,21 +125,18 @@ int zl3073x_dev_phase_avg_factor_set(struct zl3073x_dev *zldev, u8 factor);
  * @addr: HW register to be written
  * @value: value to be written to HW register
  * @mask: bitmask indicating bits to be updated
- * @wait: number of ms to wait after register write
  */
 struct zl3073x_hwreg_seq_item {
 	u32	addr;
 	u32	value;
 	u32	mask;
-	u32	wait;
 };
 
-#define HWREG_SEQ_ITEM(_addr, _value, _mask, _wait)	\
+#define HWREG_SEQ_ITEM(_addr, _value, _mask)		\
 {							\
 	.addr	= _addr,				\
 	.value	= FIELD_PREP_CONST(_mask, _value),	\
 	.mask	= _mask,				\
-	.wait	= _wait,				\
 }
 
 int zl3073x_mb_op(struct zl3073x_dev *zldev, unsigned int op_reg, u8 op_val,
@@ -161,6 +158,7 @@ int zl3073x_update_hwreg(struct zl3073x_dev *zldev, u32 addr, u32 value,
 int zl3073x_write_hwreg_seq(struct zl3073x_dev *zldev,
 			    const struct zl3073x_hwreg_seq_item *seq,
 			    size_t num_items);
+int zl3073x_dev_hw_reset(struct zl3073x_dev *zldev);
 
 /*****************
  * Misc operations
diff --git a/drivers/dpll/zl3073x/flash.c b/drivers/dpll/zl3073x/flash.c
index f85535c8ad2469..306e7c857b2313 100644
--- a/drivers/dpll/zl3073x/flash.c
+++ b/drivers/dpll/zl3073x/flash.c
@@ -529,22 +529,22 @@ int zl3073x_flash_mode_enter(struct zl3073x_dev *zldev, const void *util_ptr,
 {
 	/* Sequence to be written prior utility download */
 	static const struct zl3073x_hwreg_seq_item pre_seq[] = {
-		HWREG_SEQ_ITEM(0x80000400, 1, BIT(0), 0),
-		HWREG_SEQ_ITEM(0x80206340, 1, BIT(4), 0),
-		HWREG_SEQ_ITEM(0x10000000, 1, BIT(2), 0),
-		HWREG_SEQ_ITEM(0x10000024, 0x00000001, U32_MAX, 0),
-		HWREG_SEQ_ITEM(0x10000020, 0x00000001, U32_MAX, 0),
-		HWREG_SEQ_ITEM(0x10000000, 1, BIT(10), 1000),
+		HWREG_SEQ_ITEM(0x80000400, 1, BIT(0)),
+		HWREG_SEQ_ITEM(0x80206340, 1, BIT(4)),
+		HWREG_SEQ_ITEM(0x10000000, 1, BIT(2)),
+		HWREG_SEQ_ITEM(0x10000024, 0x00000001, U32_MAX),
+		HWREG_SEQ_ITEM(0x10000020, 0x00000001, U32_MAX),
+		HWREG_SEQ_ITEM(0x10000000, 1, BIT(10)),
 	};
 	/* Sequence to be written after utility download */
 	static const struct zl3073x_hwreg_seq_item post_seq[] = {
-		HWREG_SEQ_ITEM(0x10400004, 0x000000C0, U32_MAX, 0),
-		HWREG_SEQ_ITEM(0x10400008, 0x00000000, U32_MAX, 0),
-		HWREG_SEQ_ITEM(0x10400010, 0x20000000, U32_MAX, 0),
-		HWREG_SEQ_ITEM(0x10400014, 0x20000004, U32_MAX, 0),
-		HWREG_SEQ_ITEM(0x10000000, 1, GENMASK(10, 9), 0),
-		HWREG_SEQ_ITEM(0x10000020, 0x00000000, U32_MAX, 0),
-		HWREG_SEQ_ITEM(0x10000000, 0, BIT(0), 1000),
+		HWREG_SEQ_ITEM(0x10400004, 0x000000C0, U32_MAX),
+		HWREG_SEQ_ITEM(0x10400008, 0x00000000, U32_MAX),
+		HWREG_SEQ_ITEM(0x10400010, 0x20000000, U32_MAX),
+		HWREG_SEQ_ITEM(0x10400014, 0x20000004, U32_MAX),
+		HWREG_SEQ_ITEM(0x10000000, 1, GENMASK(10, 9)),
+		HWREG_SEQ_ITEM(0x10000020, 0x00000000, U32_MAX),
+		HWREG_SEQ_ITEM(0x10000000, 0, BIT(0)),
 	};
 	int rc;
 
@@ -604,62 +604,17 @@ int zl3073x_flash_mode_enter(struct zl3073x_dev *zldev, const void *util_ptr,
  * @extack: netlink extack pointer to report errors
  *
  * The function instructs the device to leave the flash mode and
- * to return back to normal operation.
- *
- * The procedure:
- * 1) Set reset flag
- * 2) Reset the device CPU by specific HW register sequence
- * 3) Wait for the device to be ready
- * 4) Check the reset flag was cleared
+ * to return back to normal operation by resetting the device CPU
+ * with zl3073x_dev_hw_reset().
  *
  * Return: 0 on success, <0 on error
  */
 int zl3073x_flash_mode_leave(struct zl3073x_dev *zldev,
 			     struct netlink_ext_ack *extack)
 {
-	/* Sequence to be written after flash */
-	static const struct zl3073x_hwreg_seq_item fw_reset_seq[] = {
-		HWREG_SEQ_ITEM(0x80000404, 1, BIT(0), 0),
-		HWREG_SEQ_ITEM(0x80000410, 1, BIT(0), 0),
-	};
-	u8 reset_status;
-	int rc;
-
 	zl3073x_devlink_flash_notify(zldev, "Leaving flash mode", "utility",
 				     0, 0);
 
-	/* Read reset status register */
-	rc = zl3073x_read_u8(zldev, ZL_REG_RESET_STATUS, &reset_status);
-	if (rc)
-		return rc;
-
-	/* Set reset bit */
-	reset_status |= ZL_REG_RESET_STATUS_RESET;
-
-	/* Update reset status register */
-	rc = zl3073x_write_u8(zldev, ZL_REG_RESET_STATUS, reset_status);
-	if (rc)
-		return rc;
-
-	/* We do not check the return value here as the sequence resets
-	 * the device CPU and the last write always return an error.
-	 */
-	zl3073x_write_hwreg_seq(zldev, fw_reset_seq, ARRAY_SIZE(fw_reset_seq));
-
-	/* Wait for the device to be ready */
-	msleep(500);
-
-	/* Read again the reset status register */
-	rc = zl3073x_read_u8(zldev, ZL_REG_RESET_STATUS, &reset_status);
-	if (rc)
-		return rc;
-
-	/* Check the reset bit was cleared */
-	if (reset_status & ZL_REG_RESET_STATUS_RESET) {
-		dev_err(zldev->dev,
-			"Reset not confirmed after switch to normal mode\n");
-		return -EINVAL;
-	}
-
-	return 0;
+	/* Reset the device CPU to resume normal firmware processing */
+	return zl3073x_dev_hw_reset(zldev);
 }
-- 
2.56.1


  reply	other threads:[~2026-12-03 18:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 18:06 [PATCH net-next 0/3] dpll: zl3073x: add device reset via devlink reload Ivan Vecera
2026-12-03 18:06 ` Ivan Vecera [this message]
2026-12-03 18:06 ` [PATCH net-next 2/3] dpll: zl3073x: always fetch device state on start Ivan Vecera

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=20261203180627.215256-2-ivecera@redhat.com \
    --to=ivecera@redhat.com \
    --cc=arkadiusz.kubalewski@intel.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=min.li@microchip.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox