drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ptp.c
Extension
.c
Size
11748 bytes
Lines
525
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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

if (ptp->thresh != new_thresh) {
			mutex_lock(&ptp->nic->mbox.lock);
			ptp_set_thresh(ptp, new_thresh);
			mutex_unlock(&ptp->nic->mbox.lock);
			ptp->thresh = new_thresh;
		}
		ptp->last_extts = tstmp;
	}
	schedule_delayed_work(&ptp->extts_work, msecs_to_jiffies(200));
}

static void otx2_sync_tstamp(struct work_struct *work)
{
	struct otx2_ptp *ptp = container_of(work, struct otx2_ptp,
					    synctstamp_work.work);
	struct otx2_nic *pfvf = ptp->nic;
	u64 tstamp;

	mutex_lock(&pfvf->mbox.lock);
	tstamp = otx2_ptp_get_clock(ptp);
	mutex_unlock(&pfvf->mbox.lock);

	ptp->tstamp = ptp->ptp_tstamp2nsec(&ptp->time_counter, tstamp);
	ptp->base_ns = tstamp % NSEC_PER_SEC;

	schedule_delayed_work(&ptp->synctstamp_work, msecs_to_jiffies(250));
}

static int otx2_ptp_enable(struct ptp_clock_info *ptp_info,
			   struct ptp_clock_request *rq, int on)
{
	struct otx2_ptp *ptp = container_of(ptp_info, struct otx2_ptp,
					    ptp_info);
	u64 period = 0;
	int pin;

	if (!ptp->nic)
		return -ENODEV;

	switch (rq->type) {
	case PTP_CLK_REQ_EXTTS:
		pin = ptp_find_pin(ptp->ptp_clock, PTP_PF_EXTTS,
				   rq->extts.index);
		if (pin < 0)
			return -EBUSY;
		if (on)
			schedule_delayed_work(&ptp->extts_work, msecs_to_jiffies(200));
		else
			cancel_delayed_work_sync(&ptp->extts_work);

		return 0;
	case PTP_CLK_REQ_PEROUT:
		if (rq->perout.flags)
			return -EOPNOTSUPP;

		if (rq->perout.index >= ptp_info->n_pins)
			return -EINVAL;
		if (on) {
			period = rq->perout.period.sec * NSEC_PER_SEC +
				 rq->perout.period.nsec;
			ptp_pps_on(ptp, on, period);
		} else {
			ptp_pps_on(ptp, on, period);
		}
		return 0;
	default:
		break;
	}
	return -EOPNOTSUPP;
}

int otx2_ptp_init(struct otx2_nic *pfvf)
{
	struct otx2_ptp *ptp_ptr;
	struct cyclecounter *cc;
	struct ptp_req *req;
	int err;

	if (is_otx2_lbkvf(pfvf->pdev)) {
		pfvf->ptp = NULL;
		return 0;
	}

	mutex_lock(&pfvf->mbox.lock);
	/* check if PTP block is available */
	req = otx2_mbox_alloc_msg_ptp_op(&pfvf->mbox);
	if (!req) {
		mutex_unlock(&pfvf->mbox.lock);
		return -ENOMEM;
	}

Annotation

Implementation Notes