Skip to content

Commit 477c3e1

Browse files
minimaxwellkuba-moo
authored andcommitted
net: stmmac: Introduce dwmac1000 timestamping operations
In GMAC3_X, the timestamping configuration differs from GMAC4 in the layout of the registers accessed to grab the number of snapshots in FIFO as well as the register offset to grab the aux snapshot timestamp. Introduce dedicated ops to configure timestamping on dwmac100 and dwmac1000. The latency correction doesn't seem to exist on GMAC3, so its corresponding operation isn't populated. Reviewed-by: Daniel Machon <[email protected]> Signed-off-by: Maxime Chevallier <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 8e76207 commit 477c3e1

File tree

6 files changed

+65
-2
lines changed

6 files changed

+65
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ extern const struct stmmac_desc_ops ndesc_ops;
549549
struct mac_device_info;
550550

551551
extern const struct stmmac_hwtimestamp stmmac_ptp;
552+
extern const struct stmmac_hwtimestamp dwmac1000_ptp;
552553
extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;
553554

554555
extern const struct ptp_clock_info stmmac_ptp_clock_ops;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,15 @@ enum rtc_control {
331331

332332
/* PTP and timestamping registers */
333333

334+
#define GMAC3_X_ATSNS GENMASK(19, 16)
335+
#define GMAC3_X_ATSNS_SHIFT 16
336+
334337
#define GMAC_PTP_TCR_ATSFC BIT(24)
335338
#define GMAC_PTP_TCR_ATSEN0 BIT(25)
336339

340+
#define GMAC3_X_TIMESTAMP_STATUS 0x28
341+
#define GMAC_PTP_ATNR 0x30
342+
#define GMAC_PTP_ATSR 0x34
343+
337344
extern const struct stmmac_dma_ops dwmac1000_dma_ops;
338345
#endif /* __DWMAC1000_H__ */

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,46 @@ int dwmac1000_setup(struct stmmac_priv *priv)
553553
return 0;
554554
}
555555

556+
/* DWMAC 1000 HW Timestaming ops */
557+
558+
void dwmac1000_get_ptptime(void __iomem *ptpaddr, u64 *ptp_time)
559+
{
560+
u64 ns;
561+
562+
ns = readl(ptpaddr + GMAC_PTP_ATNR);
563+
ns += readl(ptpaddr + GMAC_PTP_ATSR) * NSEC_PER_SEC;
564+
565+
*ptp_time = ns;
566+
}
567+
568+
void dwmac1000_timestamp_interrupt(struct stmmac_priv *priv)
569+
{
570+
struct ptp_clock_event event;
571+
u32 ts_status, num_snapshot;
572+
unsigned long flags;
573+
u64 ptp_time;
574+
int i;
575+
576+
/* Clears the timestamp interrupt */
577+
ts_status = readl(priv->ptpaddr + GMAC3_X_TIMESTAMP_STATUS);
578+
579+
if (!(priv->plat->flags & STMMAC_FLAG_EXT_SNAPSHOT_EN))
580+
return;
581+
582+
num_snapshot = (ts_status & GMAC3_X_ATSNS) >> GMAC3_X_ATSNS_SHIFT;
583+
584+
for (i = 0; i < num_snapshot; i++) {
585+
read_lock_irqsave(&priv->ptp_lock, flags);
586+
stmmac_get_ptptime(priv, priv->ptpaddr, &ptp_time);
587+
read_unlock_irqrestore(&priv->ptp_lock, flags);
588+
589+
event.type = PTP_CLOCK_EXTTS;
590+
event.index = 0;
591+
event.timestamp = ptp_time;
592+
ptp_clock_event(priv->ptp_clock, &event);
593+
}
594+
}
595+
556596
/* DWMAC 1000 ptp_clock_info ops */
557597

558598
int dwmac1000_ptp_enable(struct ptp_clock_info *ptp,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static const struct stmmac_hwif_entry {
134134
.desc = NULL,
135135
.dma = &dwmac100_dma_ops,
136136
.mac = &dwmac100_ops,
137-
.hwtimestamp = &stmmac_ptp,
137+
.hwtimestamp = &dwmac1000_ptp,
138138
.ptp = &dwmac1000_ptp_clock_ops,
139139
.mode = NULL,
140140
.tc = NULL,
@@ -153,7 +153,7 @@ static const struct stmmac_hwif_entry {
153153
.desc = NULL,
154154
.dma = &dwmac1000_dma_ops,
155155
.mac = &dwmac1000_ops,
156-
.hwtimestamp = &stmmac_ptp,
156+
.hwtimestamp = &dwmac1000_ptp,
157157
.ptp = &dwmac1000_ptp_clock_ops,
158158
.mode = NULL,
159159
.tc = NULL,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,14 @@ const struct stmmac_hwtimestamp stmmac_ptp = {
269269
.timestamp_interrupt = timestamp_interrupt,
270270
.hwtstamp_correct_latency = hwtstamp_correct_latency,
271271
};
272+
273+
const struct stmmac_hwtimestamp dwmac1000_ptp = {
274+
.config_hw_tstamping = config_hw_tstamping,
275+
.init_systime = init_systime,
276+
.config_sub_second_increment = config_sub_second_increment,
277+
.config_addend = config_addend,
278+
.adjust_systime = adjust_systime,
279+
.get_systime = get_systime,
280+
.get_ptptime = dwmac1000_get_ptptime,
281+
.timestamp_interrupt = dwmac1000_timestamp_interrupt,
282+
};

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,12 @@ enum aux_snapshot {
9696

9797
struct ptp_clock_info;
9898
struct ptp_clock_request;
99+
struct stmmac_priv;
99100

100101
int dwmac1000_ptp_enable(struct ptp_clock_info *ptp,
101102
struct ptp_clock_request *rq, int on);
102103

104+
void dwmac1000_get_ptptime(void __iomem *ptpaddr, u64 *ptp_time);
105+
void dwmac1000_timestamp_interrupt(struct stmmac_priv *priv);
106+
103107
#endif /* __STMMAC_PTP_H__ */

0 commit comments

Comments
 (0)