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.

Dependency Surface

Detected Declarations

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

Implementation Notes