drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/amd/xgbe/xgbe-ptp.c- Extension
.c- Size
- 4382 bytes
- Lines
- 170
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/clocksource.hlinux/ptp_clock_kernel.hlinux/net_tstamp.hxgbe.hxgbe-common.h
Detected Declarations
function Copyrightfunction xgbe_adjtimefunction xgbe_gettimexfunction xgbe_settimefunction xgbe_enablefunction xgbe_ptp_registerfunction xgbe_ptp_unregister
Annotated Snippet
// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-3-Clause)
/*
* Copyright (c) 2014-2025, Advanced Micro Devices, Inc.
* Copyright (c) 2014, Synopsys, Inc.
* All rights reserved
*/
#include <linux/clk.h>
#include <linux/clocksource.h>
#include <linux/ptp_clock_kernel.h>
#include <linux/net_tstamp.h>
#include "xgbe.h"
#include "xgbe-common.h"
static int xgbe_adjfine(struct ptp_clock_info *info, long scaled_ppm)
{
struct xgbe_prv_data *pdata = container_of(info,
struct xgbe_prv_data,
ptp_clock_info);
unsigned long flags;
u64 addend;
addend = adjust_by_scaled_ppm(pdata->tstamp_addend, scaled_ppm);
spin_lock_irqsave(&pdata->tstamp_lock, flags);
xgbe_update_tstamp_addend(pdata, addend);
spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
return 0;
}
static int xgbe_adjtime(struct ptp_clock_info *info, s64 delta)
{
struct xgbe_prv_data *pdata = container_of(info,
struct xgbe_prv_data,
ptp_clock_info);
unsigned int neg_adjust = 0;
unsigned int sec, nsec;
u32 quotient, reminder;
unsigned long flags;
if (delta < 0) {
neg_adjust = 1;
delta = -delta;
}
quotient = div_u64_rem(delta, 1000000000ULL, &reminder);
sec = quotient;
nsec = reminder;
/* Negative adjustment for Hw timer register. */
if (neg_adjust) {
sec = -sec;
if (XGMAC_IOREAD_BITS(pdata, MAC_TSCR, TSCTRLSSR))
nsec = (1000000000UL - nsec);
else
nsec = (0x80000000UL - nsec);
}
nsec = (neg_adjust << 31) | nsec;
spin_lock_irqsave(&pdata->tstamp_lock, flags);
xgbe_update_tstamp_time(pdata, sec, nsec);
spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
return 0;
}
static int xgbe_gettimex(struct ptp_clock_info *info, struct timespec64 *ts,
struct ptp_system_timestamp *sts)
{
struct xgbe_prv_data *pdata = container_of(info,
struct xgbe_prv_data,
ptp_clock_info);
unsigned long flags;
u64 nsec;
spin_lock_irqsave(&pdata->tstamp_lock, flags);
ptp_read_system_prets(sts);
nsec = xgbe_get_tstamp_time(pdata);
ptp_read_system_postts(sts);
spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
*ts = ns_to_timespec64(nsec);
return 0;
}
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clocksource.h`, `linux/ptp_clock_kernel.h`, `linux/net_tstamp.h`, `xgbe.h`, `xgbe-common.h`.
- Detected declarations: `function Copyright`, `function xgbe_adjtime`, `function xgbe_gettimex`, `function xgbe_settime`, `function xgbe_enable`, `function xgbe_ptp_register`, `function xgbe_ptp_unregister`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.