* [PATCH net-next v2] bnxt_en: add unlocked version of bnxt_refclk_read
@ 2024-11-07 21:49 Vadim Fedorenko
2024-11-08 4:48 ` Pavan Chebbi
2024-11-12 1:40 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Vadim Fedorenko @ 2024-11-07 21:49 UTC (permalink / raw)
To: Vadim Fedorenko, Michael Chan, Pavan Chebbi, Jakub Kicinski
Cc: Andrew Lunn, Paolo Abeni, David S. Miller, netdev,
Richard Cochran, Vadim Fedorenko
Serialization of PHC read with FW reset mechanism uses ptp_lock which
also protects timecounter updates. This means we cannot grab it when
called from bnxt_cc_read(). Let's move locking into different function.
Fixes: 6c0828d00f07 ("bnxt_en: replace PTP spinlock with seqlock")
Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
---
v1 -> v2:
* add lock around timecounter_init() in bnxt_ptp_timecounter_init()
---
drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c | 35 +++++++++++++------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
index f74afdab4f7d..91e7e08fabb1 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c
@@ -73,19 +73,15 @@ static int bnxt_ptp_settime(struct ptp_clock_info *ptp_info,
return 0;
}
-static int bnxt_refclk_read(struct bnxt *bp, struct ptp_system_timestamp *sts,
- u64 *ns)
+/* Caller holds ptp_lock */
+static int __bnxt_refclk_read(struct bnxt *bp, struct ptp_system_timestamp *sts,
+ u64 *ns)
{
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
u32 high_before, high_now, low;
- unsigned long flags;
- /* We have to serialize reg access and FW reset */
- read_seqlock_excl_irqsave(&ptp->ptp_lock, flags);
- if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state)) {
- read_sequnlock_excl_irqrestore(&ptp->ptp_lock, flags);
+ if (test_bit(BNXT_STATE_IN_FW_RESET, &bp->state))
return -EIO;
- }
high_before = readl(bp->bar0 + ptp->refclk_mapped_regs[1]);
ptp_read_system_prets(sts);
@@ -97,12 +93,25 @@ static int bnxt_refclk_read(struct bnxt *bp, struct ptp_system_timestamp *sts,
low = readl(bp->bar0 + ptp->refclk_mapped_regs[0]);
ptp_read_system_postts(sts);
}
- read_sequnlock_excl_irqrestore(&ptp->ptp_lock, flags);
*ns = ((u64)high_now << 32) | low;
return 0;
}
+static int bnxt_refclk_read(struct bnxt *bp, struct ptp_system_timestamp *sts,
+ u64 *ns)
+{
+ struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
+ unsigned long flags;
+ int rc;
+
+ /* We have to serialize reg access and FW reset */
+ read_seqlock_excl_irqsave(&ptp->ptp_lock, flags);
+ rc = __bnxt_refclk_read(bp, sts, ns);
+ read_sequnlock_excl_irqrestore(&ptp->ptp_lock, flags);
+ return rc;
+}
+
static void bnxt_ptp_get_current_time(struct bnxt *bp)
{
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
@@ -674,7 +683,7 @@ static u64 bnxt_cc_read(const struct cyclecounter *cc)
struct bnxt_ptp_cfg *ptp = container_of(cc, struct bnxt_ptp_cfg, cc);
u64 ns = 0;
- bnxt_refclk_read(ptp->bp, NULL, &ns);
+ __bnxt_refclk_read(ptp->bp, NULL, &ns);
return ns;
}
@@ -936,6 +945,7 @@ static bool bnxt_pps_config_ok(struct bnxt *bp)
static void bnxt_ptp_timecounter_init(struct bnxt *bp, bool init_tc)
{
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
+ unsigned long flags;
if (!ptp->ptp_clock) {
memset(&ptp->cc, 0, sizeof(ptp->cc));
@@ -952,8 +962,11 @@ static void bnxt_ptp_timecounter_init(struct bnxt *bp, bool init_tc)
}
ptp->next_overflow_check = jiffies + BNXT_PHC_OVERFLOW_PERIOD;
}
- if (init_tc)
+ if (init_tc) {
+ write_seqlock_irqsave(&ptp->ptp_lock, flags);
timecounter_init(&ptp->tc, &ptp->cc, ktime_to_ns(ktime_get_real()));
+ write_sequnlock_irqrestore(&ptp->ptp_lock, flags);
+ }
}
/* Caller holds ptp_lock */
--
2.43.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v2] bnxt_en: add unlocked version of bnxt_refclk_read
2024-11-07 21:49 [PATCH net-next v2] bnxt_en: add unlocked version of bnxt_refclk_read Vadim Fedorenko
@ 2024-11-08 4:48 ` Pavan Chebbi
2024-11-12 1:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Pavan Chebbi @ 2024-11-08 4:48 UTC (permalink / raw)
To: Vadim Fedorenko
Cc: Vadim Fedorenko, Michael Chan, Jakub Kicinski, Andrew Lunn,
Paolo Abeni, David S. Miller, netdev, Richard Cochran
[-- Attachment #1: Type: text/plain, Size: 723 bytes --]
On Fri, Nov 8, 2024 at 3:19 AM Vadim Fedorenko <vadfed@meta.com> wrote:
>
> Serialization of PHC read with FW reset mechanism uses ptp_lock which
> also protects timecounter updates. This means we cannot grab it when
> called from bnxt_cc_read(). Let's move locking into different function.
>
> Fixes: 6c0828d00f07 ("bnxt_en: replace PTP spinlock with seqlock")
> Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
> ---
> v1 -> v2:
> * add lock around timecounter_init() in bnxt_ptp_timecounter_init()
> ---
> drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c | 35 +++++++++++++------
> 1 file changed, 24 insertions(+), 11 deletions(-)
>
Thanks Vadim.
Reviewed-by: Pavan Chebbi <pavan.chebbi@broadcom.com>
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4209 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v2] bnxt_en: add unlocked version of bnxt_refclk_read
2024-11-07 21:49 [PATCH net-next v2] bnxt_en: add unlocked version of bnxt_refclk_read Vadim Fedorenko
2024-11-08 4:48 ` Pavan Chebbi
@ 2024-11-12 1:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-11-12 1:40 UTC (permalink / raw)
To: Vadim Fedorenko
Cc: vadim.fedorenko, michael.chan, pavan.chebbi, kuba, andrew+netdev,
pabeni, davem, netdev, richardcochran
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 7 Nov 2024 13:49:17 -0800 you wrote:
> Serialization of PHC read with FW reset mechanism uses ptp_lock which
> also protects timecounter updates. This means we cannot grab it when
> called from bnxt_cc_read(). Let's move locking into different function.
>
> Fixes: 6c0828d00f07 ("bnxt_en: replace PTP spinlock with seqlock")
> Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
>
> [...]
Here is the summary with links:
- [net-next,v2] bnxt_en: add unlocked version of bnxt_refclk_read
https://git.kernel.org/netdev/net-next/c/f0fe51a04386
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-12 1:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-07 21:49 [PATCH net-next v2] bnxt_en: add unlocked version of bnxt_refclk_read Vadim Fedorenko
2024-11-08 4:48 ` Pavan Chebbi
2024-11-12 1:40 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).