drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c- Extension
.c- Size
- 7806 bytes
- Lines
- 280
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/io.hlinux/iopoll.hlinux/delay.hlinux/ptp_clock_kernel.hcommon.hstmmac_ptp.hdwmac4.hstmmac.h
Detected Declarations
function Copyrightfunction config_sub_second_incrementfunction hwtstamp_correct_latencyfunction init_systimefunction config_addendfunction adjust_systimefunction get_systimefunction get_ptptimefunction timestamp_interrupt
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*******************************************************************************
Copyright (C) 2013 Vayavya Labs Pvt Ltd
This implements all the API for managing HW timestamp & PTP.
Author: Rayagond Kokatanur <rayagond@vayavyalabs.com>
Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
*******************************************************************************/
#include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/delay.h>
#include <linux/ptp_clock_kernel.h>
#include "common.h"
#include "stmmac_ptp.h"
#include "dwmac4.h"
#include "stmmac.h"
#define STMMAC_HWTS_CFG_MASK (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | \
PTP_TCR_TSINIT | PTP_TCR_TSUPDT | \
PTP_TCR_TSCTRLSSR | PTP_TCR_SNAPTYPSEL_1 | \
PTP_TCR_TSIPV4ENA | PTP_TCR_TSIPV6ENA | \
PTP_TCR_TSEVNTENA | PTP_TCR_TSMSTRENA | \
PTP_TCR_TSVER2ENA | PTP_TCR_TSIPENA | \
PTP_TCR_TSTRIG | PTP_TCR_TSENALL)
static void config_hw_tstamping(void __iomem *ioaddr, u32 data)
{
u32 regval = readl(ioaddr + PTP_TCR);
regval &= ~STMMAC_HWTS_CFG_MASK;
regval |= data;
writel(regval, ioaddr + PTP_TCR);
}
static void config_sub_second_increment(void __iomem *ioaddr,
u32 ptp_clock, int gmac4, u32 *ssinc)
{
u32 value = readl(ioaddr + PTP_TCR);
unsigned long data;
u32 reg_value;
/* For GMAC3.x, 4.x versions, in "fine adjustment mode" set sub-second
* increment to twice the number of nanoseconds of a clock cycle.
* The calculation of the default_addend value by the caller will set it
* to mid-range = 2^31 when the remainder of this division is zero,
* which will make the accumulator overflow once every 2 ptp_clock
* cycles, adding twice the number of nanoseconds of a clock cycle :
* 2000000000ULL / ptp_clock.
*/
if (value & PTP_TCR_TSCFUPDT)
data = (2000000000ULL / ptp_clock);
else
data = (1000000000ULL / ptp_clock);
/* 0.465ns accuracy */
if (!(value & PTP_TCR_TSCTRLSSR))
data = (data * 1000) / 465;
if (data > PTP_SSIR_SSINC_MAX)
data = PTP_SSIR_SSINC_MAX;
reg_value = data;
if (gmac4)
reg_value <<= GMAC4_PTP_SSIR_SSINC_SHIFT;
writel(reg_value, ioaddr + PTP_SSIR);
if (ssinc)
*ssinc = data;
}
static void hwtstamp_correct_latency(struct stmmac_priv *priv)
{
void __iomem *ioaddr = priv->ptpaddr;
u32 reg_tsic, reg_tsicsns;
u32 reg_tsec, reg_tsecsns;
u64 scaled_ns;
u32 val;
/* MAC-internal ingress latency */
scaled_ns = readl(ioaddr + PTP_TS_INGR_LAT);
/* See section 11.7.2.5.3.1 "Ingress Correction" on page 4001 of
* i.MX8MP Applications Processor Reference Manual Rev. 1, 06/2021
*/
val = readl(ioaddr + PTP_TCR);
Annotation
- Immediate include surface: `linux/io.h`, `linux/iopoll.h`, `linux/delay.h`, `linux/ptp_clock_kernel.h`, `common.h`, `stmmac_ptp.h`, `dwmac4.h`, `stmmac.h`.
- Detected declarations: `function Copyright`, `function config_sub_second_increment`, `function hwtstamp_correct_latency`, `function init_systime`, `function config_addend`, `function adjust_systime`, `function get_systime`, `function get_ptptime`, `function timestamp_interrupt`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.