From: Sagi Maimon <maimon.sagi@gmail.com>
To: Richard Cochran <richardcochran@gmail.com>,
Vadim Fedorenko <vadim.fedorenko@linux.dev>,
Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
Simon Horman <horms@kernel.org>, Jiri Pirko <jiri@resnulli.us>,
Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>,
Jonathan Corbet <corbet@lwn.net>,
Randy Dunlap <rdunlap@infradead.org>,
Shuah Khan <skhan@linuxfoundation.org>,
netdev@vger.kernel.org
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
Sagi Maimon <maimon.sagi@gmail.com>
Subject: [PATCH net-next 4/9] ptp: ocp: forget a CPLD i2c adapter number that no longer resolves
Date: Tue, 22 Sep 2026 17:28:24 +0300 [thread overview]
Message-ID: <20260922142829.57740-5-maimon.sagi@gmail.com> (raw)
In-Reply-To: <20260922142829.57740-1-maimon.sagi@gmail.com>
adva_x1_bus_claim() returned -ENODEV when i2c_get_adapter() found nothing
for the cached number but left the number in place, so
adva_x1_cache_i2c_adap() kept bailing out on its first test and never
resolved the adapter again. The comment on the parent check claimed a bad
number is forgotten and looked up again on the next sweep; that only held
for a mismatched adapter, not for one that had gone away.
Factor the invalidation out and use it on both paths.
Re-arm the one-shot identification when a new adapter is cached as well: a
different adapter may answer where the previous one did not, and leaving
cpld_id_tried set kept cpld.id absent for the rest of the binding.
Fixes: 3b815e29966f ("ptp: ocp: add TAP CPLD access for ADVA TimeCard X1")
Signed-off-by: Sagi Maimon <maimon.sagi@gmail.com>
---
drivers/ptp/ptp_ocp.c | 35 ++++++++++++++++++++++++++++++-----
1 file changed, 30 insertions(+), 5 deletions(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index feb61355078a..45313143b6f7 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -4574,6 +4574,19 @@ static int adva_x1_i2c_adap_match(struct device *dev, const void *data)
* both the notifier and a single lookup here can miss the same adapter.
* Retrying costs a short klist walk per tick until one of them succeeds.
*/
+/*
+ * Forget the cached adapter number so the next sweep resolves it again.
+ * @nr < 0 forgets whatever is cached; otherwise only that number, so a
+ * caller that raced the notifier cannot clear a newer one.
+ */
+static void adva_x1_forget_i2c_adap(struct ptp_ocp *bp, int nr)
+{
+ scoped_guard(spinlock, &bp->cpld_adap_lock) {
+ if (nr < 0 || bp->cpld_i2c_adap_nr == nr)
+ bp->cpld_i2c_adap_nr = -1;
+ }
+}
+
static void adva_x1_cache_i2c_adap(struct ptp_ocp *bp)
{
struct device *child;
@@ -4598,6 +4611,15 @@ static void adva_x1_cache_i2c_adap(struct ptp_ocp *bp)
bp->cpld_i2c_adap_nr = i2c_verify_adapter(child)->nr;
}
+ /* A different adapter may answer differently, so let the one-shot
+ * identification run again rather than leaving cpld.id absent for
+ * the rest of the binding.
+ */
+ scoped_guard(mutex, &bp->cpld_lock) {
+ bp->cpld_id_tried = false;
+ bp->cpld_id_attempts = 0;
+ }
+
put_device(child);
}
@@ -4614,8 +4636,14 @@ static int adva_x1_bus_claim(struct ptp_ocp *bp)
lockdep_assert_held(&bp->cpld_lock);
adap = i2c_get_adapter(READ_ONCE(bp->cpld_i2c_adap_nr));
- if (!adap)
+ if (!adap) {
+ /* The adapter behind the cached number is gone. Forget it,
+ * or adva_x1_cache_i2c_adap() keeps bailing out on its first
+ * test and never resolves the adapter again.
+ */
+ adva_x1_forget_i2c_adap(bp, -1);
return -ENODEV;
+ }
/* The number is freed before the notifier clears it, so it can
* already be another adapter's. Check this is still ours, and drop
@@ -4623,10 +4651,7 @@ static int adva_x1_bus_claim(struct ptp_ocp *bp)
* way, where forgetting it lets the worker look the adapter up again.
*/
if (!bp->i2c_ctrl || adap->dev.parent != &bp->i2c_ctrl->dev) {
- scoped_guard(spinlock, &bp->cpld_adap_lock) {
- if (bp->cpld_i2c_adap_nr == adap->nr)
- bp->cpld_i2c_adap_nr = -1;
- }
+ adva_x1_forget_i2c_adap(bp, adap->nr);
i2c_put_adapter(adap);
return -ENODEV;
}
--
2.47.0
next prev parent reply other threads:[~2026-09-22 14:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 14:28 [PATCH net-next 0/9] ptp: ocp: TAP CPLD follow-up fixes Sagi Maimon
2026-09-22 14:28 ` [PATCH net-next 1/9] ptp: ocp: move the CPLD identification read off the sync worker Sagi Maimon
2026-09-24 14:29 ` netdev-bot+sashiko
2026-09-22 14:28 ` [PATCH net-next 2/9] ptp: ocp: do not cache EEPROM content after a failed TMC bus hand-back Sagi Maimon
2026-09-24 14:29 ` netdev-bot+sashiko
2026-09-22 14:28 ` [PATCH net-next 3/9] ptp: ocp: hand the TMC bus back once on an acquire timeout Sagi Maimon
2026-09-24 14:29 ` netdev-bot+sashiko
2026-09-22 14:28 ` Sagi Maimon [this message]
2026-09-24 14:29 ` [PATCH net-next 4/9] ptp: ocp: forget a CPLD i2c adapter number that no longer resolves netdev-bot+sashiko
2026-09-22 14:28 ` [PATCH net-next 5/9] ptp: ocp: correct the CPLD bookkeeping comments and the flash progress Sagi Maimon
2026-09-24 14:29 ` netdev-bot+sashiko
2026-09-22 14:28 ` [PATCH net-next 6/9] ptp: ocp: report fw.cpld with an empty value until the USERCODE is read Sagi Maimon
2026-09-24 14:29 ` netdev-bot+sashiko
2026-09-22 14:28 ` [PATCH net-next 7/9] ptp: ocp: drop only the USERCODE when flashing, and drop it before erasing Sagi Maimon
2026-09-24 14:29 ` netdev-bot+sashiko
2026-09-22 14:28 ` [PATCH net-next 8/9] ptp: ocp: tolerate a latched FAILED when entering configuration mode Sagi Maimon
2026-09-24 14:29 ` netdev-bot+sashiko
2026-09-22 14:28 ` [PATCH net-next 9/9] ptp: ocp: confirm the CPLD really left configuration mode after REFRESH Sagi Maimon
2026-09-24 14:29 ` netdev-bot+sashiko
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=20260922142829.57740-5-maimon.sagi@gmail.com \
--to=maimon.sagi@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=arkadiusz.kubalewski@intel.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rdunlap@infradead.org \
--cc=richardcochran@gmail.com \
--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
all inboxes | Powered by JetHome®