drivers/net/ethernet/mscc/ocelot_ptp.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mscc/ocelot_ptp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mscc/ocelot_ptp.c- Extension
.c- Size
- 24575 bytes
- Lines
- 913
- 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.
- 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/time64.hlinux/dsa/ocelot.hlinux/ptp_classify.hsoc/mscc/ocelot_ptp.hsoc/mscc/ocelot_sys.hsoc/mscc/ocelot_vcap.hsoc/mscc/ocelot.hocelot.h
Detected Declarations
function Copyrightfunction ocelot_ptp_settime64function ocelot_ptp_adjtimefunction ocelot_ptp_adjfinefunction ocelot_ptp_verifyfunction ocelot_ptp_enablefunction ocelot_populate_l2_ptp_trap_keyfunction ocelot_populate_ipv4_ptp_event_trap_keyfunction ocelot_populate_ipv6_ptp_event_trap_keyfunction ocelot_populate_ipv4_ptp_general_trap_keyfunction ocelot_populate_ipv6_ptp_general_trap_keyfunction ocelot_l2_ptp_trap_addfunction ocelot_l2_ptp_trap_delfunction ocelot_ipv4_ptp_trap_addfunction ocelot_ipv4_ptp_trap_delfunction ocelot_ipv6_ptp_trap_addfunction ocelot_ipv6_ptp_trap_delfunction ocelot_setup_ptp_trapsfunction ocelot_traps_to_ptp_rx_filterfunction ocelot_ptp_tx_type_to_cmdfunction ocelot_hwstamp_getfunction ocelot_hwstamp_setfunction ocelot_get_ts_infofunction skb_queue_walk_safefunction ocelot_port_queue_ptp_tx_skbfunction ocelot_ptp_is_onestep_syncfunction ocelot_port_txtstamp_requestfunction ocelot_get_hwtimestampfunction ocelot_get_txtstampfunction ocelot_init_timestampfunction ocelot_deinit_timestampexport ocelot_ptp_gettime64export ocelot_ptp_settime64export ocelot_ptp_adjtimeexport ocelot_ptp_adjfineexport ocelot_ptp_verifyexport ocelot_ptp_enableexport ocelot_hwstamp_getexport ocelot_hwstamp_setexport ocelot_get_ts_infoexport ocelot_port_txtstamp_requestexport ocelot_get_txtstampexport ocelot_init_timestampexport ocelot_deinit_timestamp
Annotated Snippet
if (!on) {
spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
val = PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_IDLE);
ocelot_write_rix(ocelot, val, PTP_PIN_CFG, ptp_pin);
spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
break;
}
if (rq->perout.flags & PTP_PEROUT_PHASE) {
ts_phase.tv_sec = rq->perout.phase.sec;
ts_phase.tv_nsec = rq->perout.phase.nsec;
} else {
/* Compatibility */
ts_phase.tv_sec = rq->perout.start.sec;
ts_phase.tv_nsec = rq->perout.start.nsec;
}
if (ts_phase.tv_sec || (ts_phase.tv_nsec && !pps)) {
dev_warn(ocelot->dev,
"Absolute start time not supported!\n");
dev_warn(ocelot->dev,
"Accept nsec for PPS phase adjustment, otherwise start time should be 0 0.\n");
return -EINVAL;
}
/* Calculate waveform high and low times */
if (rq->perout.flags & PTP_PEROUT_DUTY_CYCLE) {
struct timespec64 ts_on;
ts_on.tv_sec = rq->perout.on.sec;
ts_on.tv_nsec = rq->perout.on.nsec;
wf_high = timespec64_to_ns(&ts_on);
} else {
if (pps) {
wf_high = 1000;
} else {
wf_high = timespec64_to_ns(&ts_period);
wf_high = div_s64(wf_high, 2);
}
}
wf_low = timespec64_to_ns(&ts_period);
wf_low -= wf_high;
/* Handle PPS request */
if (pps) {
spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
ocelot_write_rix(ocelot, ts_phase.tv_nsec,
PTP_PIN_WF_LOW_PERIOD, ptp_pin);
ocelot_write_rix(ocelot, wf_high,
PTP_PIN_WF_HIGH_PERIOD, ptp_pin);
val = PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_CLOCK);
val |= PTP_PIN_CFG_SYNC;
ocelot_write_rix(ocelot, val, PTP_PIN_CFG, ptp_pin);
spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
break;
}
/* Handle periodic clock */
if (wf_high > 0x3fffffff || wf_high <= 0x6)
return -EINVAL;
if (wf_low > 0x3fffffff || wf_low <= 0x6)
return -EINVAL;
spin_lock_irqsave(&ocelot->ptp_clock_lock, flags);
ocelot_write_rix(ocelot, wf_low, PTP_PIN_WF_LOW_PERIOD,
ptp_pin);
ocelot_write_rix(ocelot, wf_high, PTP_PIN_WF_HIGH_PERIOD,
ptp_pin);
val = PTP_PIN_CFG_ACTION(PTP_PIN_ACTION_CLOCK);
ocelot_write_rix(ocelot, val, PTP_PIN_CFG, ptp_pin);
spin_unlock_irqrestore(&ocelot->ptp_clock_lock, flags);
break;
default:
return -EOPNOTSUPP;
}
return 0;
}
EXPORT_SYMBOL(ocelot_ptp_enable);
static void ocelot_populate_l2_ptp_trap_key(struct ocelot_vcap_filter *trap)
{
trap->key_type = OCELOT_VCAP_KEY_ETYPE;
*(__be16 *)trap->key.etype.etype.value = htons(ETH_P_1588);
*(__be16 *)trap->key.etype.etype.mask = htons(0xffff);
}
static void
ocelot_populate_ipv4_ptp_event_trap_key(struct ocelot_vcap_filter *trap)
{
Annotation
- Immediate include surface: `linux/time64.h`, `linux/dsa/ocelot.h`, `linux/ptp_classify.h`, `soc/mscc/ocelot_ptp.h`, `soc/mscc/ocelot_sys.h`, `soc/mscc/ocelot_vcap.h`, `soc/mscc/ocelot.h`, `ocelot.h`.
- Detected declarations: `function Copyright`, `function ocelot_ptp_settime64`, `function ocelot_ptp_adjtime`, `function ocelot_ptp_adjfine`, `function ocelot_ptp_verify`, `function ocelot_ptp_enable`, `function ocelot_populate_l2_ptp_trap_key`, `function ocelot_populate_ipv4_ptp_event_trap_key`, `function ocelot_populate_ipv6_ptp_event_trap_key`, `function ocelot_populate_ipv4_ptp_general_trap_key`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration 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.