From patchwork Mon Sep 23 09:23:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmVuY2UgQ3PDs2vDoXM=?= X-Patchwork-Id: 13809417 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 DE66E1946A4 for ; Mon, 23 Sep 2024 09:24:43 +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=1727083487; cv=none; b=p5i1yQUSWOka9ns6u4JjwZWzPZRq+1DyKZ2imkFVIsOblqDc8s6zwXz6tdZtM8dvIZksXP5P2QZuKfLQ02ajZEqxwVDUJmDru9t0/TgmHXTAXFcyZKYplfxGZbq5/WCmBY2kEb1KI8HA+ZfhrG9chtWjmG1GLh4qeaKy9+6k8A0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727083487; c=relaxed/simple; bh=P85uniBbpjbAiAEhXQw8DDYhZFYlWYcMIcwcq4CiTRE=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=nu9oeFJaqrblK8Y0FU0+n/6I0o5cvRiO3OWmxKZMHLZlJp6j3gM10cmo8TC1GJ26pj6rvh+uayjjN7eL3jqFJ2IjHkPu/cyyTWQO4pggR/ZNGtu56rrt/jBcL4NBWqXpXooSW1QgKKflEwlvC5uLL/mCvZKUU473EMG3gsMuHqY= 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=TKRGVGFT; 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="TKRGVGFT" Received: from proxmox-mailgw.intranet.prolan.hu (localhost.localdomain [127.0.0.1]) by proxmox-mailgw.intranet.prolan.hu (Proxmox) with ESMTP id 03579A03FB; Mon, 23 Sep 2024 11:24:36 +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=GkwqSLjc8C5KqC+YUWvBsBhbeWnsg8Xr9Cj8nXEsTT4=; b= TKRGVGFTN3TrDC/U+9xw/q420/nykHzM1UTN5f6XFyYXi7BH/qQJo49yxzR9vljE 6caQV6eYFnCRYv3d4WWd85icMR3qH6Y2kucyZgeFXhQ90fzfsJxIPlgqPW8mqgbI vjx0SHYlvnF0dq/g4v9UKvUkf7q4w6p+zhqiKwEHvUpxAs72B4oPQgdgiLoPUaHl wRXpmto+seZ4zH1EADs5pTVp2vsuS0kF44MgBQx64tTrx26nOEfCpeK9U7RKqRos WsJ9n/tQc358DHxfV1x3DjzGVmHulo9PQuDup7pyHGeplOcSvD7+GZWpkZ6z/Ng5 9EGvR+W8vTmOXPFmhmGZZPcPK8cPqQHJkgnKthal24z8Qiv4tpDe+WIh5xEAtuXa Z8VmZMOcfp3WiAWfiV59tAt+mVc/YBp0Sz535UxjxxCtD5nOoFdz4KhGKoydjHPf 82EKS4N1yX7lz7fVnPSrqe0DaCWokQmJqKJk90b2x0xfCjcodPmRmB1rMl2dT8XT 5gFH3HJWBMiCqN25PSW8KUxBYEDYDXgvTjonBnXO5OugpoKnPwj6fm7pfWFbwZQz NCpnRsE49Wh3xWIN2yxG8TTp2EjYgHqHkWy70eQS33QtFbXgyBmeHUb27EgwEtQy m1VSDplJ9Ek594RQC7kkM15iS5UFVxxFA5jH5PfQImY= From: =?utf-8?b?Q3PDs2vDoXMsIEJlbmNl?= To: "David S. Miller" , Frank Li , , , 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: Mon, 23 Sep 2024 11:23:46 +0200 Message-ID: <20240923092347.2867309-1-csokas.bence@prolan.hu> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ESET-AS: R=OK;S=0;OP=CALC;TIME=1727083475;VERSION=7976;MC=574309015;ID=151752;TRN=0;CRV=0;IPC=;SP=0;SIPS=0;PI=3;F=0 X-ESET-Antispam: OK X-EsetResult: clean, is OK X-EsetId: 37303A29ACD948546C7466 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 --- 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 acbb627d51bf..6c6dbda26f06 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 4cffda363a14..54dc3d0503b2 100644 --- a/drivers/net/ethernet/freescale/fec_ptp.c +++ b/drivers/net/ethernet/freescale/fec_ptp.c @@ -764,6 +764,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 23 09:23:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QmVuY2UgQ3PDs2vDoXM=?= X-Patchwork-Id: 13809418 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 60650194A68 for ; Mon, 23 Sep 2024 09:24:48 +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=1727083491; cv=none; b=J78IDrKPNPpXqJRD2miJ2hkfGJy/HC9gkkNDLD09YkgaGKqTjp1VsXKtT/y0Hh+eGlir/p3ODWAuZ7Js6oYfmOlJMuXVlKPuMXOMui9OzbKAbsG05f6kIz3UMwRIAjkYPC2+slZm79rkkXgSwdCb4IIYHKzTrPfokRflAtFBV4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727083491; c=relaxed/simple; bh=6Rte3PyrhZs+j32pYSYLb0k55LfwAfzjlW+LYGza6NI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jSsquE7hLUDZG4VsOIrl/HKjgeDuPVZh2qpwpOvDbwhos5QJTQOwjdKQ42YRX62CBVMN/44bsQKpe7Dx44Hvkt1uH3HQCj7CAn6xKGpnPSQ78730/7fKodb7b3fxawmwDwS5DsuvtrC2HFihC93/csoNf1W/mFH0kA4JEvSe7yQ= 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=hifkAG4O; 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="hifkAG4O" Received: from proxmox-mailgw.intranet.prolan.hu (localhost.localdomain [127.0.0.1]) by proxmox-mailgw.intranet.prolan.hu (Proxmox) with ESMTP id B8722A06C6; Mon, 23 Sep 2024 11:24:46 +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=ogsXffhzydOhG3mdvX0B yhOZWftk1um1Vz/tH8zngCk=; b=hifkAG4OxFZdOYod01dZhg6talcoohz+oPSV +jKKuezsqSj4OTDxiU8F1pqpIz+StQGtrlOSTRFjZ4RGkK6AzU9QB5pT7rFdpbVB hk6oEwuR4d5B39I72BIFCBkUrby4diOGwrXtgY8vOzB5vVFzcQnFndwR358MJfm2 LPyA/Z2kHIMbCBXFj2e9pPbunePXC4qj8a+u33FdmQKe9TWqV53bUTjIW4OYG1Jp AlwlHzQVAzQlMF3dwMKocyRqaRp3ItZMKHn0P/3/z8ljSVDbQRmhrK3MBaRoBoDb Z1NpgD9mnp9bxz9IXIf7oulqpci5Uvp/eX54lgcqQv4Ss47OC3vCs0qXb7fPixRI DOjiWa27+1ivwp73ZYcEtWP4VQjlemYGVY1GFS6p92PiBRnq8ZBz+1nptuGqO9MK l7CVYEyyuFxRPSemXxRxY/PTIGFEG+9dpEUXofEIJFr7PbpftpsU00lbbjtiHi7r r9di94WuUeb3cvR9RTYExBsf2BSys759zJxVRCkR80MTmd+u8/LMl6jbjukWEvm4 r9Q2sDcIgHpEMsMdMT56XCIqT0P40IdJiO1KDJGm9gvPe8pFqxra/4UhPkjCrEgp +S7W6V/1Hp3y2ttG1EWq91I5lL/NqgWIWi+nUwDb60JfBn03nbrkYFsVSQkt3K19 4bZZm84= 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: Mon, 23 Sep 2024 11:23:48 +0200 Message-ID: <20240923092347.2867309-2-csokas.bence@prolan.hu> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240923092347.2867309-1-csokas.bence@prolan.hu> References: <20240923092347.2867309-1-csokas.bence@prolan.hu> Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ESET-AS: R=OK;S=0;OP=CALC;TIME=1727083485;VERSION=7976;MC=1880781835;ID=151753;TRN=0;CRV=0;IPC=;SP=0;SIPS=0;PI=3;F=0 X-ESET-Antispam: OK X-EsetResult: clean, is OK X-EsetId: 37303A29ACD948546C7466 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 --- 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 6c6dbda26f06..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. @@ -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 54dc3d0503b2..5d9c1040b4b3 100644 --- a/drivers/net/ethernet/freescale/fec_ptp.c +++ b/drivers/net/ethernet/freescale/fec_ptp.c @@ -764,9 +764,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 */