Skip to content

Commit 8e76207

Browse files
minimaxwellkuba-moo
authored andcommitted
net: stmmac: Introduce dwmac1000 ptp_clock_info and operations
The PTP configuration for GMAC3_X differs from the other implementations in several ways : - There's only one external snapshot trigger - The snapshot configuration is done through the PTP_TCR register, whereas the other dwmac variants have a dedicated ACR (auxiliary control reg) for that purpose - The layout for the PTP_TCR register also differs, as bits 24/25 are used for the snapshot configuration. These bits are reserved on other variants. On GMAC3_X, we also can't discover the number of snapshot triggers automatically. The GMAC3_X has one PPS output, however it's configuration isn't supported yet so report 0 n_per_out for now. Introduce a dedicated set of ptp_clock_info ops and configuration parameters to reflect these differences specific to GMAC3_X. This was tested on dwmac_socfpga. Signed-off-by: Maxime Chevallier <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 0bfd0af commit 8e76207

File tree

6 files changed

+77
-2
lines changed

6 files changed

+77
-2
lines changed

drivers/net/ethernet/stmicro/stmmac/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ extern const struct stmmac_hwtimestamp stmmac_ptp;
552552
extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;
553553

554554
extern const struct ptp_clock_info stmmac_ptp_clock_ops;
555+
extern const struct ptp_clock_info dwmac1000_ptp_clock_ops;
555556

556557
struct mac_link {
557558
u32 caps;

drivers/net/ethernet/stmicro/stmmac/dwmac1000.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,5 +329,10 @@ enum rtc_control {
329329
#define GMAC_MMC_RX_CSUM_OFFLOAD 0x208
330330
#define GMAC_EXTHASH_BASE 0x500
331331

332+
/* PTP and timestamping registers */
333+
334+
#define GMAC_PTP_TCR_ATSFC BIT(24)
335+
#define GMAC_PTP_TCR_ATSEN0 BIT(25)
336+
332337
extern const struct stmmac_dma_ops dwmac1000_dma_ops;
333338
#endif /* __DWMAC1000_H__ */

drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/io.h>
1919
#include "stmmac.h"
2020
#include "stmmac_pcs.h"
21+
#include "stmmac_ptp.h"
2122
#include "dwmac1000.h"
2223

2324
static void dwmac1000_core_init(struct mac_device_info *hw,
@@ -551,3 +552,47 @@ int dwmac1000_setup(struct stmmac_priv *priv)
551552

552553
return 0;
553554
}
555+
556+
/* DWMAC 1000 ptp_clock_info ops */
557+
558+
int dwmac1000_ptp_enable(struct ptp_clock_info *ptp,
559+
struct ptp_clock_request *rq, int on)
560+
{
561+
struct stmmac_priv *priv =
562+
container_of(ptp, struct stmmac_priv, ptp_clock_ops);
563+
void __iomem *ptpaddr = priv->ptpaddr;
564+
int ret = -EOPNOTSUPP;
565+
u32 tcr_val;
566+
567+
switch (rq->type) {
568+
case PTP_CLK_REQ_EXTTS:
569+
mutex_lock(&priv->aux_ts_lock);
570+
tcr_val = readl(ptpaddr + PTP_TCR);
571+
572+
if (on) {
573+
tcr_val |= GMAC_PTP_TCR_ATSEN0;
574+
tcr_val |= GMAC_PTP_TCR_ATSFC;
575+
priv->plat->flags |= STMMAC_FLAG_EXT_SNAPSHOT_EN;
576+
} else {
577+
tcr_val &= ~GMAC_PTP_TCR_ATSEN0;
578+
priv->plat->flags &= ~STMMAC_FLAG_EXT_SNAPSHOT_EN;
579+
}
580+
581+
netdev_dbg(priv->dev, "Auxiliary Snapshot %s.\n",
582+
on ? "enabled" : "disabled");
583+
writel(tcr_val, ptpaddr + PTP_TCR);
584+
585+
/* wait for auxts fifo clear to finish */
586+
ret = readl_poll_timeout(ptpaddr + PTP_TCR, tcr_val,
587+
!(tcr_val & GMAC_PTP_TCR_ATSFC),
588+
10, 10000);
589+
590+
mutex_unlock(&priv->aux_ts_lock);
591+
break;
592+
593+
default:
594+
break;
595+
}
596+
597+
return ret;
598+
}

drivers/net/ethernet/stmicro/stmmac/hwif.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ static const struct stmmac_hwif_entry {
135135
.dma = &dwmac100_dma_ops,
136136
.mac = &dwmac100_ops,
137137
.hwtimestamp = &stmmac_ptp,
138-
.ptp = &stmmac_ptp_clock_ops,
138+
.ptp = &dwmac1000_ptp_clock_ops,
139139
.mode = NULL,
140140
.tc = NULL,
141141
.mmc = &dwmac_mmc_ops,
@@ -154,7 +154,7 @@ static const struct stmmac_hwif_entry {
154154
.dma = &dwmac1000_dma_ops,
155155
.mac = &dwmac1000_ops,
156156
.hwtimestamp = &stmmac_ptp,
157-
.ptp = &stmmac_ptp_clock_ops,
157+
.ptp = &dwmac1000_ptp_clock_ops,
158158
.mode = NULL,
159159
.tc = NULL,
160160
.mmc = &dwmac_mmc_ops,

drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ const struct ptp_clock_info stmmac_ptp_clock_ops = {
282282
.getcrosststamp = stmmac_getcrosststamp,
283283
};
284284

285+
/* structure describing a PTP hardware clock */
286+
const struct ptp_clock_info dwmac1000_ptp_clock_ops = {
287+
.owner = THIS_MODULE,
288+
.name = "stmmac ptp",
289+
.max_adj = 62500000,
290+
.n_alarm = 0,
291+
.n_ext_ts = 1,
292+
.n_per_out = 0,
293+
.n_pins = 0,
294+
.pps = 0,
295+
.adjfine = stmmac_adjust_freq,
296+
.adjtime = stmmac_adjust_time,
297+
.gettime64 = stmmac_get_time,
298+
.settime64 = stmmac_set_time,
299+
.enable = dwmac1000_ptp_enable,
300+
.getcrosststamp = stmmac_getcrosststamp,
301+
};
302+
285303
/**
286304
* stmmac_ptp_register
287305
* @priv: driver private structure

drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,10 @@ enum aux_snapshot {
9494
AUX_SNAPSHOT3 = 0x80,
9595
};
9696

97+
struct ptp_clock_info;
98+
struct ptp_clock_request;
99+
100+
int dwmac1000_ptp_enable(struct ptp_clock_info *ptp,
101+
struct ptp_clock_request *rq, int on);
102+
97103
#endif /* __STMMAC_PTP_H__ */

0 commit comments

Comments
 (0)