drivers/net/ethernet/intel/igb/igb_ptp.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/intel/igb/igb_ptp.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/intel/igb/igb_ptp.c
Extension
.c
Size
43085 bytes
Lines
1520
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

if (on) {
			pin = ptp_find_pin(igb->ptp_clock, PTP_PF_EXTTS,
					   rq->extts.index);
			if (pin < 0)
				return -EBUSY;
		}
		if (rq->extts.index == 1) {
			tsauxc_mask = TSAUXC_EN_TS1;
			tsim_mask = TSINTR_AUTT1;
		} else {
			tsauxc_mask = TSAUXC_EN_TS0;
			tsim_mask = TSINTR_AUTT0;
		}
		spin_lock_irqsave(&igb->tmreg_lock, flags);
		tsauxc = rd32(E1000_TSAUXC);
		tsim = rd32(E1000_TSIM);
		if (on) {
			igb_pin_extts(igb, rq->extts.index, pin);
			tsauxc |= tsauxc_mask;
			tsim |= tsim_mask;
		} else {
			tsauxc &= ~tsauxc_mask;
			tsim &= ~tsim_mask;
		}
		wr32(E1000_TSAUXC, tsauxc);
		wr32(E1000_TSIM, tsim);
		spin_unlock_irqrestore(&igb->tmreg_lock, flags);
		return 0;

	case PTP_CLK_REQ_PEROUT:
		/* Reject requests with unsupported flags */
		if (rq->perout.flags)
			return -EOPNOTSUPP;

		if (on) {
			pin = ptp_find_pin(igb->ptp_clock, PTP_PF_PEROUT,
					   rq->perout.index);
			if (pin < 0)
				return -EBUSY;
		}
		ts.tv_sec = rq->perout.period.sec;
		ts.tv_nsec = rq->perout.period.nsec;
		ns = timespec64_to_ns(&ts);
		ns = ns >> 1;
		if (on && ns < 8LL)
			return -EINVAL;
		ts = ns_to_timespec64(ns);
		if (rq->perout.index == 1) {
			tsauxc_mask = TSAUXC_EN_TT1;
			tsim_mask = TSINTR_TT1;
			trgttiml = E1000_TRGTTIML1;
			trgttimh = E1000_TRGTTIMH1;
		} else {
			tsauxc_mask = TSAUXC_EN_TT0;
			tsim_mask = TSINTR_TT0;
			trgttiml = E1000_TRGTTIML0;
			trgttimh = E1000_TRGTTIMH0;
		}
		spin_lock_irqsave(&igb->tmreg_lock, flags);
		tsauxc = rd32(E1000_TSAUXC);
		tsim = rd32(E1000_TSIM);
		if (rq->perout.index == 1) {
			tsauxc &= ~(TSAUXC_EN_TT1 | TSAUXC_EN_CLK1 | TSAUXC_ST1);
			tsim &= ~TSINTR_TT1;
		} else {
			tsauxc &= ~(TSAUXC_EN_TT0 | TSAUXC_EN_CLK0 | TSAUXC_ST0);
			tsim &= ~TSINTR_TT0;
		}
		if (on) {
			int i = rq->perout.index;

			/* read systim registers in sequence */
			rd32(E1000_SYSTIMR);
			systiml = rd32(E1000_SYSTIML);
			systimh = rd32(E1000_SYSTIMH);
			systim = (((u64)(systimh & 0xFF)) << 32) | ((u64)systiml);
			now = timecounter_cyc2time(&igb->tc, systim);

			if (pin < 2) {
				level_mask = (i == 1) ? 0x80000 : 0x40000;
				level = (rd32(E1000_CTRL) & level_mask) ? 1 : 0;
			} else {
				level_mask = (i == 1) ? 0x80 : 0x40;
				level = (rd32(E1000_CTRL_EXT) & level_mask) ? 1 : 0;
			}

			div_u64_rem(now, ns, &rem);
			systim = systim + (ns - rem);

			/* synchronize pin level with rising/falling edges */

Annotation

Implementation Notes