Skip to content

Commit a1477dc

Browse files
Csókás, BencePaolo Abeni
authored andcommitted
net: fec: Restart PPS after link state change
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: 6605b73 ("FEC: Add time stamping code and a PTP hardware clock") Signed-off-by: Csókás, Bence <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 93ef6ee commit a1477dc

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

drivers/net/ethernet/freescale/fec.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,10 +691,16 @@ struct fec_enet_private {
691691
/* XDP BPF Program */
692692
struct bpf_prog *xdp_prog;
693693

694+
struct {
695+
int pps_enable;
696+
} ptp_saved_state;
697+
694698
u64 ethtool_stats[];
695699
};
696700

697701
void fec_ptp_init(struct platform_device *pdev, int irq_idx);
702+
void fec_ptp_restore_state(struct fec_enet_private *fep);
703+
void fec_ptp_save_state(struct fec_enet_private *fep);
698704
void fec_ptp_stop(struct platform_device *pdev);
699705
void fec_ptp_start_cyclecounter(struct net_device *ndev);
700706
int fec_ptp_set(struct net_device *ndev, struct kernel_hwtstamp_config *config,

drivers/net/ethernet/freescale/fec_main.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,8 @@ fec_restart(struct net_device *ndev)
10771077
u32 rcntl = OPT_FRAME_SIZE | 0x04;
10781078
u32 ecntl = FEC_ECR_ETHEREN;
10791079

1080+
fec_ptp_save_state(fep);
1081+
10801082
/* Whack a reset. We should wait for this.
10811083
* For i.MX6SX SOC, enet use AXI bus, we use disable MAC
10821084
* instead of reset MAC itself.
@@ -1244,8 +1246,10 @@ fec_restart(struct net_device *ndev)
12441246
writel(ecntl, fep->hwp + FEC_ECNTRL);
12451247
fec_enet_active_rxring(ndev);
12461248

1247-
if (fep->bufdesc_ex)
1249+
if (fep->bufdesc_ex) {
12481250
fec_ptp_start_cyclecounter(ndev);
1251+
fec_ptp_restore_state(fep);
1252+
}
12491253

12501254
/* Enable interrupts we wish to service */
12511255
if (fep->link)
@@ -1336,6 +1340,8 @@ fec_stop(struct net_device *ndev)
13361340
netdev_err(ndev, "Graceful transmit stop did not complete!\n");
13371341
}
13381342

1343+
fec_ptp_save_state(fep);
1344+
13391345
/* Whack a reset. We should wait for this.
13401346
* For i.MX6SX SOC, enet use AXI bus, we use disable MAC
13411347
* instead of reset MAC itself.
@@ -1366,6 +1372,9 @@ fec_stop(struct net_device *ndev)
13661372
val = readl(fep->hwp + FEC_ECNTRL);
13671373
val |= FEC_ECR_EN1588;
13681374
writel(val, fep->hwp + FEC_ECNTRL);
1375+
1376+
fec_ptp_start_cyclecounter(ndev);
1377+
fec_ptp_restore_state(fep);
13691378
}
13701379
}
13711380

drivers/net/ethernet/freescale/fec_ptp.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,36 @@ void fec_ptp_init(struct platform_device *pdev, int irq_idx)
764764
schedule_delayed_work(&fep->time_keep, HZ);
765765
}
766766

767+
void fec_ptp_save_state(struct fec_enet_private *fep)
768+
{
769+
unsigned long flags;
770+
771+
spin_lock_irqsave(&fep->tmreg_lock, flags);
772+
773+
fep->ptp_saved_state.pps_enable = fep->pps_enable;
774+
775+
spin_unlock_irqrestore(&fep->tmreg_lock, flags);
776+
}
777+
778+
/* Restore PTP functionality after a reset */
779+
void fec_ptp_restore_state(struct fec_enet_private *fep)
780+
{
781+
unsigned long flags;
782+
783+
spin_lock_irqsave(&fep->tmreg_lock, flags);
784+
785+
/* Reset turned it off, so adjust our status flag */
786+
fep->pps_enable = 0;
787+
788+
spin_unlock_irqrestore(&fep->tmreg_lock, flags);
789+
790+
/* Restart PPS if needed */
791+
if (fep->ptp_saved_state.pps_enable) {
792+
/* Re-enable PPS */
793+
fec_ptp_enable_pps(fep, 1);
794+
}
795+
}
796+
767797
void fec_ptp_stop(struct platform_device *pdev)
768798
{
769799
struct net_device *ndev = platform_get_drvdata(pdev);

0 commit comments

Comments
 (0)