From patchwork Tue Sep 24 09:37:04 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: 13810612 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 EF0D21552F5; Tue, 24 Sep 2024 09:37:39 +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=1727170664; cv=none; b=p/kDPBq2Whqz90nLmUXHQH66/sfNUUbpOmxvKIhKQ5aNDKfVtSkwIX1WmrC6uDFGxrwkT0CUuuU3+8nJvlcf7zPZus/ESrTxw9O/ipVpjT5/GAFthpCJIQzOjmvABMPpiHx7+6coW/mwkoKmSxZhufhsRtZcOxTgbv+FT/vL1kA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727170664; c=relaxed/simple; bh=RK5zRI6Tvzjb2KbqBd0rOSqIVx56/Y1TYuy+mD614d4=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=ZquzhTg6cWe5A1IalGcLADysTS8TYMfD8DwzfKtelaF5uq7+hDtG4oP+TzfZI7LMdUsoEhYJGbQyX4fgSjOh214ZyScJc1jKw3qpCr12tewPmgkD8OYFwBFbIw7Bz2PXksAZj2N3yUQFcyvRVXMN1MHTnWC+MqtlRON2V+HiePU= 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=DiK4pdk+; 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="DiK4pdk+" Received: from proxmox-mailgw.intranet.prolan.hu (localhost.localdomain [127.0.0.1]) by proxmox-mailgw.intranet.prolan.hu (Proxmox) with ESMTP id 5CB19A0B11; Tue, 24 Sep 2024 11:37:32 +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=vkHGElBASM42oNMJ60X5DKQUSY9n6Gq/8H4y4oxZgaM=; b= DiK4pdk+Z5RpdD+Dk5hDx5BwmXGnuJ3sDjB7ZYPBAr/3v9nwXpUW2Gh0vBZfgLKC g5dox+fBZPfz9/8471VOEGwJZxuDkzbjjfwIxdarexbYmWQgdA9k+Zgh5wsYZ/0V mer7cKqybA3F6JSsH2W08GZvAON0kJ+KJZJb6ybq9Ancb1OW5Dl74UM+gQwaqExM cZWd4TJIE+lpGT+sM5yuSiAlRnZF4d+4TPoNRQO3eFiB2uJ+wahdY/RlVBb3lov2 mQFjxwWABXvhlnWHHTEg5c1lzK7UF+JVZkJ0yr0qNmMBs5nKAMktZssoXNqVAyLY SiUuHxEcdTILKAPeJjRLrM23+50lghfAIdkgokv3ghbpl66qsqpQd4+NsxyTQohv 4U0yutM0y8gu/pf9sfjHPrLLELg1PcPFw/F6n7+RaN2vlNzi399YhcSizODhNsy2 hcS5L0qpY6hcLfRtsTdaZwZRWZW2psXPMuQ+cICg0oWqKpGlTHzwTw2QGNckIFR+ xjfEfW7AgTePMBHsgvBAlqIujd/TfSNWSfxi9jOI2EPcBqSHjwQkfd+NtTGT+B0L lIUeq26PNbhK0rwVcbm4XP1F1hhVfBE4/56yd2AcqMJFrLEwTeBJRtfblCybynDg wF0/DyNo7HGgVfHoWG7sR7ix6c+hABhLCyqPwjBm8Sk= From: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= To: Frank Li , "David S. Miller" , , , CC: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= , Wei Fang , Shenwei Wang , Clark Wang , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran Subject: [PATCH net 1/2] net: fec: Restart PPS after link state change Date: Tue, 24 Sep 2024 11:37:04 +0200 Message-ID: <20240924093705.2897329-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=1727170651;VERSION=7976;MC=414325616;ID=164865;TRN=0;CRV=0;IPC=;SP=0;SIPS=0;PI=3;F=0 X-ESET-Antispam: OK X-EsetResult: clean, is OK X-EsetId: 37303A29ACD948546C7764 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. Fixes: 6605b730c061 ("FEC: Add time stamping code and a PTP hardware clock") Signed-off-by: Csókás, Bence --- Notes: Changes in v2: - store pps_enable's pre-reset value and clear it on restore - acquire tmreg_lock when reading/writing fep->pps_enable drivers/net/ethernet/freescale/fec.h | 6 +++++ drivers/net/ethernet/freescale/fec_main.c | 11 ++++++++- drivers/net/ethernet/freescale/fec_ptp.c | 30 +++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h index a19cb2a786fd..0552317a2554 100644 --- a/drivers/net/ethernet/freescale/fec.h +++ b/drivers/net/ethernet/freescale/fec.h @@ -691,10 +691,16 @@ struct fec_enet_private { /* XDP BPF Program */ struct bpf_prog *xdp_prog; + struct { + int pps_enable; + } 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 acbb627d51bf..31ebf6a4f973 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. @@ -1244,8 +1246,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) @@ -1336,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. @@ -1366,6 +1372,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 4cffda363a14..df1ef023493b 100644 --- a/drivers/net/ethernet/freescale/fec_ptp.c +++ b/drivers/net/ethernet/freescale/fec_ptp.c @@ -764,6 +764,36 @@ 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; + + spin_lock_irqsave(&fep->tmreg_lock, flags); + + fep->ptp_saved_state.pps_enable = fep->pps_enable; + + spin_unlock_irqrestore(&fep->tmreg_lock, flags); +} + +/* Restore PTP functionality after a reset */ +void fec_ptp_restore_state(struct fec_enet_private *fep) +{ + unsigned long flags; + + spin_lock_irqsave(&fep->tmreg_lock, flags); + + /* Reset turned it off, so adjust our status flag */ + fep->pps_enable = 0; + + spin_unlock_irqrestore(&fep->tmreg_lock, flags); + + /* Restart PPS if needed */ + if (fep->ptp_saved_state.pps_enable) { + /* 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 Tue Sep 24 09:37:06 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: 13810611 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 0BB051422C7; Tue, 24 Sep 2024 09:37: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=1727170662; cv=none; b=fNu5+xCfNf9syLepaHKlhURv2KFXTl6BwcMg/87+UJP3+OUgWgxo1VM0FbcjNsVzywV2QfJNK24Y5nYBKF4VyUEz1Kh6HAQj5y/X/o6VaNAvqmtPf4LK0ZBEq+m1lkR4jAkUBOyvoak2jVMXMji5dpecyKujgNh+PoByeay3rV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727170662; c=relaxed/simple; bh=yTTNa2QMtuCCueY2sh3DWgOl3ij0zht4q8WPO6UaB6k=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UaPIWsEWY7QCizZVooshLOSsfCOCGcpOS5ZglGZ53WtPVjwH+aPsJm55IDSMFF8X/bI3zIgH++RdOiILmyrXyMYpUtLLX7xCuYEM7DNjJglpEz1eYecfJ2620YWXi7dSWBTKUB+Idw/uQXTRA+acGFgXv22JaC34LJMMOmMzmxI= 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=RH1UbJYp; 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="RH1UbJYp" Received: from proxmox-mailgw.intranet.prolan.hu (localhost.localdomain [127.0.0.1]) by proxmox-mailgw.intranet.prolan.hu (Proxmox) with ESMTP id F12DCA0C05; Tue, 24 Sep 2024 11:37:38 +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=RM2Bx6e9nFaFc6AnqSX0 YhK80LFLycZfvGoIpk5yHlk=; b=RH1UbJYpqUZFXNWJGntasiGmHvgl6chT6ZNn +HrXPcCWo8fxTHq6TGSM34BuyqA/sDbThVnQuCX9modOEmpGUk3c8AyZKatd0Jtr C3a9E+MuIn3hocSqIkLrqnR6gJMGG5Wt7iLHwR2YuG6zGuw1+MUmbTHuAQvnRVpn o5zIOXoUY1pxM5//fM5f/SMZgM8Kih1yfnmlK860tX/b1KGSOnEvCqqHf74ac0F1 Rp8uuZIu3SIreFf5y4CITw246Mt0NlN8O7T9t+tjN2XP9jlZj81iuPBR3MvxJZoz k658DQdPpC2rS4ubCPWwDYqfuTsdrf/+Gat1R+9ReMEzKhrS62THYK0h6lCPd6so +vrftuRLfc42jRxuG0RNUd5UPbDGM8HI6qfIjHn6hvggqTyQbTBh+/rqWRfK8xuN 6ylHF1tEjtipqe0b+US00J6oiNnSTKmzZ5q1Q3KgQdsyUoMRR078UUZZ538Atntt A82HL7fwLbMSRsIc7Gm7Vvlhh1DiarzdcgfDtQG/NqyLfvlEZ6AkPtBNMGGQCzD/ UBXkkUQwU3l8m03tv4vup0749Bls88/wm+z/pmMx83t+lQCXlCUOO+lwOwdSRe1T 0uy/NI+yAPVaF6/pv7KWvRk9CsihNjliKmP1HccsSFTxW4Ae6IyGNsi6xgz683iL z+VxYwQ= From: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= To: Frank Li , "David S. Miller" , , , CC: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= , Wei Fang , Shenwei Wang , Clark Wang , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Richard Cochran Subject: [PATCH net 2/2] net: fec: Reload PTP registers after link-state change Date: Tue, 24 Sep 2024 11:37:06 +0200 Message-ID: <20240924093705.2897329-2-csokas.bence@prolan.hu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240924093705.2897329-1-csokas.bence@prolan.hu> References: <20240924093705.2897329-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=1727170658;VERSION=7976;MC=678376640;ID=205351;TRN=0;CRV=0;IPC=;SP=0;SIPS=0;PI=3;F=0 X-ESET-Antispam: OK X-EsetResult: clean, is OK X-EsetId: 37303A2980D948546C7764 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. Fixes: 6605b730c061 ("FEC: Add time stamping code and a PTP hardware clock") Signed-off-by: Csókás, Bence Reviewed-by: Wei Fang --- drivers/net/ethernet/freescale/fec.h | 3 +++ drivers/net/ethernet/freescale/fec_ptp.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h index 0552317a2554..1cca0425d493 100644 --- a/drivers/net/ethernet/freescale/fec.h +++ b/drivers/net/ethernet/freescale/fec.h @@ -693,6 +693,9 @@ struct fec_enet_private { struct { int pps_enable; + u64 ns_sys, ns_phc; + u32 at_corr; + u8 at_inc_corr; } ptp_saved_state; u64 ethtool_stats[]; diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c index df1ef023493b..a4eb6edb850a 100644 --- a/drivers/net/ethernet/freescale/fec_ptp.c +++ b/drivers/net/ethernet/freescale/fec_ptp.c @@ -767,24 +767,44 @@ void fec_ptp_init(struct platform_device *pdev, int irq_idx) 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.pps_enable = fep->pps_enable; + 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); /* Reset turned it off, so adjust our status flag */ fep->pps_enable = 0; + 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 */