hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/net/ethernet/freescale/fec_ptp.c
....@@ -103,11 +103,6 @@
103103 u64 ns;
104104 val = 0;
105105
106
- if (!(fep->hwts_tx_en || fep->hwts_rx_en)) {
107
- dev_err(&fep->pdev->dev, "No ptp stack is running\n");
108
- return -EINVAL;
109
- }
110
-
111106 if (fep->pps_enable == enable)
112107 return 0;
113108
....@@ -141,11 +136,7 @@
141136 * NSEC_PER_SEC - ts.tv_nsec. Add the remaining nanoseconds
142137 * to current timer would be next second.
143138 */
144
- tempval = readl(fep->hwp + FEC_ATIME_CTRL);
145
- tempval |= FEC_T_CTRL_CAPTURE;
146
- writel(tempval, fep->hwp + FEC_ATIME_CTRL);
147
-
148
- tempval = readl(fep->hwp + FEC_ATIME);
139
+ tempval = fep->cc.read(&fep->cc);
149140 /* Convert the ptp local counter to 1588 timestamp */
150141 ns = timecounter_cyc2time(&fep->tc, tempval);
151142 ts = ns_to_timespec64(ns);
....@@ -267,7 +258,7 @@
267258 fep->cc.mult = FEC_CC_MULT;
268259
269260 /* reset the ns time counter */
270
- timecounter_init(&fep->tc, &fep->cc, ktime_to_ns(ktime_get_real()));
261
+ timecounter_init(&fep->tc, &fep->cc, 0);
271262
272263 spin_unlock_irqrestore(&fep->tmreg_lock, flags);
273264 }
....@@ -457,6 +448,18 @@
457448 return -EOPNOTSUPP;
458449 }
459450
451
+/**
452
+ * fec_ptp_disable_hwts - disable hardware time stamping
453
+ * @ndev: pointer to net_device
454
+ */
455
+void fec_ptp_disable_hwts(struct net_device *ndev)
456
+{
457
+ struct fec_enet_private *fep = netdev_priv(ndev);
458
+
459
+ fep->hwts_tx_en = 0;
460
+ fep->hwts_rx_en = 0;
461
+}
462
+
460463 int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr)
461464 {
462465 struct fec_enet_private *fep = netdev_priv(ndev);
....@@ -483,9 +486,7 @@
483486
484487 switch (config.rx_filter) {
485488 case HWTSTAMP_FILTER_NONE:
486
- if (fep->hwts_rx_en)
487
- fep->hwts_rx_en = 0;
488
- config.rx_filter = HWTSTAMP_FILTER_NONE;
489
+ fep->hwts_rx_en = 0;
489490 break;
490491
491492 default:
....@@ -512,7 +513,7 @@
512513 -EFAULT : 0;
513514 }
514515
515
-/**
516
+/*
516517 * fec_time_keep - call timecounter_read every second to avoid timer overrun
517518 * because ENET just support 32bit counter, will timeout in 4s
518519 */
....@@ -520,13 +521,12 @@
520521 {
521522 struct delayed_work *dwork = to_delayed_work(work);
522523 struct fec_enet_private *fep = container_of(dwork, struct fec_enet_private, time_keep);
523
- u64 ns;
524524 unsigned long flags;
525525
526526 mutex_lock(&fep->ptp_clk_mutex);
527527 if (fep->ptp_clk_on) {
528528 spin_lock_irqsave(&fep->tmreg_lock, flags);
529
- ns = timecounter_read(&fep->tc);
529
+ timecounter_read(&fep->tc);
530530 spin_unlock_irqrestore(&fep->tmreg_lock, flags);
531531 }
532532 mutex_unlock(&fep->ptp_clk_mutex);
....@@ -567,7 +567,8 @@
567567
568568 /**
569569 * fec_ptp_init
570
- * @ndev: The FEC network adapter
570
+ * @pdev: The FEC network adapter
571
+ * @irq_idx: the interrupt index
571572 *
572573 * This function performs the required steps for enabling ptp
573574 * support. If ptp support has already been loaded it simply calls the
....@@ -582,7 +583,7 @@
582583 int ret;
583584
584585 fep->ptp_caps.owner = THIS_MODULE;
585
- snprintf(fep->ptp_caps.name, 16, "fec ptp");
586
+ strlcpy(fep->ptp_caps.name, "fec ptp", sizeof(fep->ptp_caps.name));
586587
587588 fep->ptp_caps.max_adj = 250000000;
588589 fep->ptp_caps.n_alarm = 0;
....@@ -609,9 +610,9 @@
609610
610611 INIT_DELAYED_WORK(&fep->time_keep, fec_time_keep);
611612
612
- irq = platform_get_irq_byname(pdev, "pps");
613
+ irq = platform_get_irq_byname_optional(pdev, "pps");
613614 if (irq < 0)
614
- irq = platform_get_irq(pdev, irq_idx);
615
+ irq = platform_get_irq_optional(pdev, irq_idx);
615616 /* Failure to get an irq is not fatal,
616617 * only the PTP_CLOCK_PPS clock events should stop
617618 */
....@@ -626,7 +627,7 @@
626627 fep->ptp_clock = ptp_clock_register(&fep->ptp_caps, &pdev->dev);
627628 if (IS_ERR(fep->ptp_clock)) {
628629 fep->ptp_clock = NULL;
629
- pr_err("ptp_clock_register failed\n");
630
+ dev_err(&pdev->dev, "ptp_clock_register failed\n");
630631 }
631632
632633 schedule_delayed_work(&fep->time_keep, HZ);