From patchwork Mon Sep 16 14:19:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q3PDs2vDoXMgQmVuY2U=?= X-Patchwork-Id: 13805545 X-Patchwork-Delegate: kuba@kernel.org Received: from fw2.prolan.hu (fw2.prolan.hu [193.68.50.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9743D158523; Mon, 16 Sep 2024 14:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.68.50.107 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726498063; cv=none; b=EN8WiJX5KrMoKuqoHyPQJ2Pozas8tW239hdAFbsFY1Y3KcIkIrieLHa4hm2aQCQGmyd9tGYN5IS57VwcRsl88XeNBwUNk7rNy47Ow1QkTTI09NHOxVJK8sQ/i9iuOrLrdYfRX/oNqAH2dAN6FoR3MxRyZw/AlOppu3CLt+30oEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726498063; c=relaxed/simple; bh=6I9a7nP2zYprgQf2O4EoUzf4gNKSlVPnrSybFPBcGVQ=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ij6vu/K8r0NMAcfcD4yvaTohQwL3eLuHkXwlv/fbochxKGKi7XK4Xz24rYfDCvULJYQ16OALmwekanfPCRV9PUO1DCyzEgNbMIOWQendbzRd94vt8AQlyHrSMd70QqQ5OgLvb/QILK8NFOhoBnqF2Jsn4FFCiC2VexRqVGmMzmk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=prolan.hu; spf=pass smtp.mailfrom=prolan.hu; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b=o76mrSwP; arc=none smtp.client-ip=193.68.50.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=prolan.hu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=prolan.hu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b="o76mrSwP" Received: from proxmox-mailgw.intranet.prolan.hu (localhost.localdomain [127.0.0.1]) by proxmox-mailgw.intranet.prolan.hu (Proxmox) with ESMTP id DADA5A0E23; Mon, 16 Sep 2024 16:37:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prolan.hu; h=cc :cc:content-transfer-encoding:content-type:content-type:date :from:from:message-id:mime-version:reply-to:subject:subject:to :to; s=mail; bh=OHtLpc0jptucADL1fWAYQWFof1vNDR+20l0BSvKWjJA=; b= o76mrSwP3C9m5KB75ud8ogoYM012vNi+OzlI5+lFXVqqW4ZvrFL/itmOGA4YJaJK 9vXUvv47uhm2o8N0ZAhntD0u8+Lg7IUOdbuhj5pCisSXT5w2/Ybigmvf2P1R3SJA euZlLdyuuuPuiCr9uQwp0qaz/WS6lGJKV34sxMzPXCWTRPQeYyuN6bLfkNA+A9vJ EUE/4gF1mISq6fNIWc2caYD9VZXWOOhiZ1GUV8ScOBWbRxH9BaFsXjeR6a3osjqn DRjNydha7R0TH6w1m73E+jCdEOGbNnSu1+GGPvB2iKe8JEPU4BxzWPS3QAkmn8Rw 6duacmsE0ytOsYNriTWZwKVasrN6hn5jDrP5SvMO/SKWO/d7hjEQK326A9M9Hi7P yktffo9MxNcKQeBZuJ0d1xMdGrv34L/i7t6hP79fN8CD7396BWyIQYwDfR63PLxB yv3NbqsAJ68n8FbskrOsO/1gjSosbyv9GrSs7uu5eCr1OczDsKk61zp/AJhTcCDP 474hdCpM6tHskc1Q3uMBN1pyitNs4uhGj+//TFqKWjJ1GFABQ6xe76zN30H0MBdS 5yonWbvT2a7Te3Rya7oK7Lt9gz7ogarlfZ49qjF1faeUL+4hTy4EufNVJ26JDQLU 0wtUf5LRrcwlxJ22zUCQl7igoxUCn9o5aKGjetU0Nu0= From: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= To: , , CC: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= , Wei Fang , Shenwei Wang , Clark Wang , "David S. Miller" , "Eric Dumazet" , Jakub Kicinski , Paolo Abeni , Richard Cochran Subject: [PATCH 1/2] net: fec: Restart PPS after link state change Date: Mon, 16 Sep 2024 16:19:30 +0200 Message-ID: <20240916141931.742734-1-csokas.bence@prolan.hu> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ESET-AS: R=OK;S=0;OP=CALC;TIME=1726497464;VERSION=7976;MC=1215988020;ID=72335;TRN=0;CRV=0;IPC=;SP=0;SIPS=0;PI=3;F=0 X-ESET-Antispam: OK X-EsetResult: clean, is OK X-EsetId: 37303A29ACD948546D7162 X-Patchwork-Delegate: kuba@kernel.org On link state change, the controller gets reset, causing PPS to drop out. Re-enable PPS if it was enabled before the controller reset. Signed-off-by: Csókás, Bence --- drivers/net/ethernet/freescale/fec.h | 1 + drivers/net/ethernet/freescale/fec_main.c | 7 ++++++- drivers/net/ethernet/freescale/fec_ptp.c | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h index a19cb2a786fd..afa0bfb974e6 100644 --- a/drivers/net/ethernet/freescale/fec.h +++ b/drivers/net/ethernet/freescale/fec.h @@ -695,6 +695,7 @@ struct fec_enet_private { }; void fec_ptp_init(struct platform_device *pdev, int irq_idx); +void fec_ptp_restore_state(struct fec_enet_private *fep); void fec_ptp_stop(struct platform_device *pdev); void fec_ptp_start_cyclecounter(struct net_device *ndev); int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config, diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index a923cb95cdc6..531b51091e7d 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -1244,8 +1244,10 @@ fec_restart(struct net_device *ndev) writel(ecntl, fep->hwp + FEC_ECNTRL); fec_enet_active_rxring(ndev); - if (fep->bufdesc_ex) + if (fep->bufdesc_ex) { fec_ptp_start_cyclecounter(ndev); + fec_ptp_restore_state(fep); + } /* Enable interrupts we wish to service */ if (fep->link) @@ -1366,6 +1368,9 @@ fec_stop(struct net_device *ndev) val = readl(fep->hwp + FEC_ECNTRL); val |= FEC_ECR_EN1588; writel(val, fep->hwp + FEC_ECNTRL); + + fec_ptp_start_cyclecounter(ndev); + fec_ptp_restore_state(fep); } } diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c index e32f6724f568..c5b89352373a 100644 --- a/drivers/net/ethernet/freescale/fec_ptp.c +++ b/drivers/net/ethernet/freescale/fec_ptp.c @@ -770,6 +770,18 @@ void fec_ptp_init(struct platform_device *pdev, int irq_idx) schedule_delayed_work(&fep->time_keep, HZ); } +/* Restore PTP functionality after a reset */ +void fec_ptp_restore_state(struct fec_enet_private *fep) +{ + /* Restart PPS if needed */ + if (fep->pps_enable) { + /* Reset turned it off, so adjust our status flag */ + fep->pps_enable = 0; + /* Re-enable PPS */ + fec_ptp_enable_pps(fep, 1); + } +} + void fec_ptp_stop(struct platform_device *pdev) { struct net_device *ndev = platform_get_drvdata(pdev); From patchwork Mon Sep 16 14:19:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q3PDs2vDoXMgQmVuY2U=?= X-Patchwork-Id: 13805546 X-Patchwork-Delegate: kuba@kernel.org Received: from fw2.prolan.hu (fw2.prolan.hu [193.68.50.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9732717571; Mon, 16 Sep 2024 14:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.68.50.107 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726498063; cv=none; b=gUJ4kbLOl9rmry0pIMMW4NspoWL+BLEpUkQaXZz0KpE5uPYpYzREA9wMYHPB8LP0LqJxTH+uYDVGv0pYS2YgYBxyvTKBLBatFTK4NVd9JD/n9g163itn1+IFmDZjliNIx0LIiVCh8q+QGBNBrBl5E15M94uFIg/PDQ0MPQkfUAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726498063; c=relaxed/simple; bh=DdXPtKASiB/Z1oqLYOog7mKuDd06mrWJKbbPksmbAxY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GyN6J1EBgf6AXr+u5diK6ert/srweTb1QUEIb9hvDnhUxXfMPDM0FKZYS0FpWnigRqsfkgeEvzySg5J6C1qGVZDRtu8qVX6yCRmI+3lFJR3g3xFqCMWKq/XflkZRSy2yuudUu1uCmi3nxkExGVNWpb1z1xQ7hGHTrlem/wP7cL4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=prolan.hu; spf=pass smtp.mailfrom=prolan.hu; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b=mTewCl10; arc=none smtp.client-ip=193.68.50.107 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=prolan.hu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=prolan.hu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=prolan.hu header.i=@prolan.hu header.b="mTewCl10" Received: from proxmox-mailgw.intranet.prolan.hu (localhost.localdomain [127.0.0.1]) by proxmox-mailgw.intranet.prolan.hu (Proxmox) with ESMTP id 036BBA0F58; Mon, 16 Sep 2024 16:37:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=prolan.hu; h=cc :cc:content-transfer-encoding:content-type:content-type:date :from:from:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=mail; bh=EHqROyUJoru7508xp0hT cD02iqc88j/P5NaR7xrfbYI=; b=mTewCl10SV4kGSP++0kvsSOkuLROL1INHS8M ZrGDX6Bnnc5RIlLVz67zGAPCIa4V5CmkYpWz/N+m1KqxgqS5XwbR0w5X6CmGcRMp VR1KNIRHxP0Q4LuncE4L4Exn+09KZzdT6s3LCcUDdbw2lMcFTqhgPUqHZqEeUTQs ZOQMdEBXTh/caeq5P1D4pXFJChN2k1y16qJnN/KJ+siveeCcqjkM7iQINSBUWpWd WWXiLbDF+8/HFETjLZ+qrOkv82uOwYfTbdGQafy3VLZFli5Yz8rrvzNmyISQkddC Q+Xmh9ZymkQXXwZsTBOX1prpwtlr2N9gliWnE8PqU0iL2B6n/3ALbg99vziJ2CP+ U+4phsqAoZKTAxwqhn+deabwUG4RZElinL+hzwShMzuEckveoDEnq7SlY2JG5FNE 9gVbP9mV8MO2UXyYFaoUJQVBeHQjlfcRWDtEdNesZeK6norYSmLd3VZDSbfOW5Af WdFfow28FPeEHJ83QeMNq/K8y8P9MQ6YszdWinmM1kD8I9xgNiJ3EklPyNipXnHZ DMvZIacXRLESFGBCSYc8tS9D52B/9YGmOx21XfB+brdx4pI8roAfkIPCN/kRLyAl 82egyibGqZvFoQ4GlEHHxfb38eDodFAHx+sVF54aIRHxePJ4yEvNpwAynnI/dFWD TzJA4Z0= From: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= To: , , CC: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= , Wei Fang , Shenwei Wang , Clark Wang , "David S. Miller" , "Eric Dumazet" , Jakub Kicinski , Paolo Abeni , Richard Cochran Subject: [PATCH 2/2] net: fec: Reload PTP registers after link-state change Date: Mon, 16 Sep 2024 16:19:31 +0200 Message-ID: <20240916141931.742734-2-csokas.bence@prolan.hu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240916141931.742734-1-csokas.bence@prolan.hu> References: <20240916141931.742734-1-csokas.bence@prolan.hu> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ESET-AS: R=OK;S=0;OP=CALC;TIME=1726497466;VERSION=7976;MC=1468624255;ID=72336;TRN=0;CRV=0;IPC=;SP=0;SIPS=0;PI=3;F=0 X-ESET-Antispam: OK X-EsetResult: clean, is OK X-EsetId: 37303A29ACD948546D7162 X-Patchwork-Delegate: kuba@kernel.org On link-state change, the controller gets reset, which clears all PTP registers, including PHC time, calibrated clock correction values etc. For correct IEEE 1588 operation we need to restore these after the reset. Signed-off-by: Csókás, Bence --- drivers/net/ethernet/freescale/fec.h | 7 +++++ drivers/net/ethernet/freescale/fec_main.c | 4 +++ drivers/net/ethernet/freescale/fec_ptp.c | 35 +++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h index afa0bfb974e6..efe770fe337d 100644 --- a/drivers/net/ethernet/freescale/fec.h +++ b/drivers/net/ethernet/freescale/fec.h @@ -691,11 +691,18 @@ struct fec_enet_private { /* XDP BPF Program */ struct bpf_prog *xdp_prog; + struct { + u64 ns_sys, ns_phc; + u32 at_corr; + u8 at_inc_corr; + } ptp_saved_state; + u64 ethtool_stats[]; }; void fec_ptp_init(struct platform_device *pdev, int irq_idx); void fec_ptp_restore_state(struct fec_enet_private *fep); +void fec_ptp_save_state(struct fec_enet_private *fep); void fec_ptp_stop(struct platform_device *pdev); void fec_ptp_start_cyclecounter(struct net_device *ndev); int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config, diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 531b51091e7d..570f8a14d975 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -1077,6 +1077,8 @@ fec_restart(struct net_device *ndev) u32 rcntl = OPT_FRAME_SIZE | 0x04; u32 ecntl = FEC_ECR_ETHEREN; + fec_ptp_save_state(fep); + /* Whack a reset. We should wait for this. * For i.MX6SX SOC, enet use AXI bus, we use disable MAC * instead of reset MAC itself. @@ -1338,6 +1340,8 @@ fec_stop(struct net_device *ndev) netdev_err(ndev, "Graceful transmit stop did not complete!\n"); } + fec_ptp_save_state(fep); + /* Whack a reset. We should wait for this. * For i.MX6SX SOC, enet use AXI bus, we use disable MAC * instead of reset MAC itself. diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c index c5b89352373a..8011a6f3c4be 100644 --- a/drivers/net/ethernet/freescale/fec_ptp.c +++ b/drivers/net/ethernet/freescale/fec_ptp.c @@ -770,9 +770,44 @@ void fec_ptp_init(struct platform_device *pdev, int irq_idx) schedule_delayed_work(&fep->time_keep, HZ); } +void fec_ptp_save_state(struct fec_enet_private *fep) +{ + unsigned long flags; + u32 atime_inc_corr; + + spin_lock_irqsave(&fep->tmreg_lock, flags); + + fep->ptp_saved_state.ns_phc = timecounter_read(&fep->tc); + fep->ptp_saved_state.ns_sys = ktime_get_ns(); + + fep->ptp_saved_state.at_corr = readl(fep->hwp + FEC_ATIME_CORR); + atime_inc_corr = readl(fep->hwp + FEC_ATIME_INC) & FEC_T_INC_CORR_MASK; + fep->ptp_saved_state.at_inc_corr = (u8)(atime_inc_corr >> FEC_T_INC_CORR_OFFSET); + + spin_unlock_irqrestore(&fep->tmreg_lock, flags); +} + /* Restore PTP functionality after a reset */ void fec_ptp_restore_state(struct fec_enet_private *fep) { + u32 atime_inc = readl(fep->hwp + FEC_ATIME_INC) & FEC_T_INC_MASK; + unsigned long flags; + u32 counter; + u64 ns; + + spin_lock_irqsave(&fep->tmreg_lock, flags); + + writel(fep->ptp_saved_state.at_corr, fep->hwp + FEC_ATIME_CORR); + atime_inc |= ((u32)fep->ptp_saved_state.at_inc_corr) << FEC_T_INC_CORR_OFFSET; + writel(atime_inc, fep->hwp + FEC_ATIME_INC); + + ns = ktime_get_ns() - fep->ptp_saved_state.ns_sys + fep->ptp_saved_state.ns_phc; + counter = ns & fep->cc.mask; + writel(counter, fep->hwp + FEC_ATIME); + timecounter_init(&fep->tc, &fep->cc, ns); + + spin_unlock_irqrestore(&fep->tmreg_lock, flags); + /* Restart PPS if needed */ if (fep->pps_enable) { /* Reset turned it off, so adjust our status flag */