drivers/net/ethernet/amazon/ena/ena_phc.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/amazon/ena/ena_phc.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/amazon/ena/ena_phc.c
Extension
.c
Size
5615 bytes
Lines
237
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 Linux-OpenIB
/*
 * Copyright 2015-2022 Amazon.com, Inc. or its affiliates. All rights reserved.
 */

#include <linux/pci.h>
#include "ena_netdev.h"
#include "ena_phc.h"
#include "ena_devlink.h"

static int ena_phc_adjtime(struct ptp_clock_info *clock_info, s64 delta)
{
	return -EOPNOTSUPP;
}

static int ena_phc_adjfine(struct ptp_clock_info *clock_info, long scaled_ppm)
{
	return -EOPNOTSUPP;
}

static int ena_phc_feature_enable(struct ptp_clock_info *clock_info,
				  struct ptp_clock_request *rq,
				  int on)
{
	return -EOPNOTSUPP;
}

static int ena_phc_gettimex64(struct ptp_clock_info *clock_info,
			      struct timespec64 *ts,
			      struct ptp_system_timestamp *sts)
{
	struct ena_phc_info *phc_info =
		container_of(clock_info, struct ena_phc_info, clock_info);
	unsigned long flags;
	u64 timestamp_nsec;
	int rc;

	spin_lock_irqsave(&phc_info->lock, flags);

	ptp_read_system_prets(sts);

	rc = ena_com_phc_get_timestamp(phc_info->adapter->ena_dev,
				       &timestamp_nsec);

	ptp_read_system_postts(sts);

	spin_unlock_irqrestore(&phc_info->lock, flags);

	if (rc)
		return rc;

	*ts = ns_to_timespec64(timestamp_nsec);

	return 0;
}

static int ena_phc_settime64(struct ptp_clock_info *clock_info,
			     const struct timespec64 *ts)
{
	return -EOPNOTSUPP;
}

static struct ptp_clock_info ena_ptp_clock_info = {
	.owner		= THIS_MODULE,
	.n_alarm	= 0,
	.n_ext_ts	= 0,
	.n_per_out	= 0,
	.pps		= 0,
	.adjtime	= ena_phc_adjtime,
	.adjfine	= ena_phc_adjfine,
	.gettimex64	= ena_phc_gettimex64,
	.settime64	= ena_phc_settime64,
	.enable		= ena_phc_feature_enable,
};

/* Enable/Disable PHC by the kernel, affects on the next init flow */
void ena_phc_enable(struct ena_adapter *adapter, bool enable)
{
	struct ena_phc_info *phc_info = adapter->phc_info;

	if (!phc_info) {
		netdev_err(adapter->netdev, "phc_info is not allocated\n");
		return;
	}

	phc_info->enabled = enable;
}

/* Check if PHC is enabled by the kernel */
bool ena_phc_is_enabled(struct ena_adapter *adapter)

Annotation

Implementation Notes