drivers/net/ethernet/wangxun/libwx/wx_ptp.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/wangxun/libwx/wx_ptp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/wangxun/libwx/wx_ptp.c- Extension
.c- Size
- 25336 bytes
- Lines
- 906
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/ptp_classify.hlinux/clocksource.hlinux/pci.hwx_type.hwx_ptp.hwx_hw.h
Detected Declarations
function wx_ptp_timecounter_cyc2timefunction wx_ptp_readtimefunction wx_ptp_adjfinefunction wx_ptp_adjtimefunction wx_ptp_gettimex64function wx_ptp_settime64function wx_ptp_clear_tx_timestampfunction wx_ptp_convert_to_hwtstampfunction wx_ptp_tx_hwtstampfunction wx_ptp_tx_hwtstamp_workfunction wx_ptp_overflow_checkfunction wx_ptp_rx_hangfunction wx_ptp_tx_hangfunction wx_ptp_do_aux_workfunction wx_ptp_trigger_calcfunction wx_ptp_setup_sdpfunction wx_ptp_feature_enablefunction wx_ptp_check_pps_eventfunction wx_ptp_create_clockfunction wx_ptp_set_timestamp_modefunction wx_ptp_readfunction wx_ptp_link_speed_adjustfunction wx_ptp_reset_cyclecounterfunction wx_ptp_resetfunction wx_ptp_initfunction wx_ptp_suspendfunction wx_ptp_stopfunction wx_ptp_rx_hwtstampfunction wx_hwtstamp_getfunction wx_hwtstamp_setexport wx_ptp_check_pps_eventexport wx_ptp_reset_cyclecounterexport wx_ptp_resetexport wx_ptp_initexport wx_ptp_suspendexport wx_ptp_stopexport wx_hwtstamp_getexport wx_hwtstamp_set
Annotated Snippet
if (wx->pps_enabled) {
wx->pps_enabled = false;
wx_set_pps(wx, false, 0, 0);
}
return 0;
}
wx->pps_enabled = true;
nsec = wx_ptp_trigger_calc(wx);
wx_set_pps(wx, wx->pps_enabled, nsec, wx->pps_edge_start);
tsauxc = WX_TSC_1588_AUX_CTL_PLSG | WX_TSC_1588_AUX_CTL_EN_TT0 |
WX_TSC_1588_AUX_CTL_EN_TT1 | WX_TSC_1588_AUX_CTL_EN_TS0;
wr32ptp(wx, WX_TSC_1588_TRGT_L(0), (u32)wx->pps_edge_start);
wr32ptp(wx, WX_TSC_1588_TRGT_H(0), (u32)(wx->pps_edge_start >> 32));
wr32ptp(wx, WX_TSC_1588_TRGT_L(1), (u32)wx->pps_edge_end);
wr32ptp(wx, WX_TSC_1588_TRGT_H(1), (u32)(wx->pps_edge_end >> 32));
wr32ptp(wx, WX_TSC_1588_SDP(0),
WX_TSC_1588_SDP_FUN_SEL_TT0 | WX_TSC_1588_SDP_OUT_LEVEL_H);
wr32ptp(wx, WX_TSC_1588_SDP(1), WX_TSC_1588_SDP_FUN_SEL_TS0);
wr32ptp(wx, WX_TSC_1588_AUX_CTL, tsauxc);
wr32ptp(wx, WX_TSC_1588_INT_EN, WX_TSC_1588_INT_EN_TT1);
WX_WRITE_FLUSH(wx);
/* Adjust the clock edge to align with the next full second. */
wx->sec_to_cc = div_u64(((u64)WX_NS_PER_SEC << cc->shift), cc->mult);
return 0;
}
static int wx_ptp_feature_enable(struct ptp_clock_info *ptp,
struct ptp_clock_request *rq, int on)
{
struct wx *wx = container_of(ptp, struct wx, ptp_caps);
/**
* When PPS is enabled, unmask the interrupt for the ClockOut
* feature, so that the interrupt handler can send the PPS
* event when the clock SDP triggers. Clear mask when PPS is
* disabled
*/
if (rq->type != PTP_CLK_REQ_PEROUT || !wx->ptp_setup_sdp)
return -EOPNOTSUPP;
/* Reject requests with unsupported flags */
if (rq->perout.flags & ~(PTP_PEROUT_DUTY_CYCLE |
PTP_PEROUT_PHASE))
return -EOPNOTSUPP;
if (rq->perout.phase.sec || rq->perout.phase.nsec) {
wx_err(wx, "Absolute start time not supported.\n");
return -EINVAL;
}
if (rq->perout.period.sec != 1 || rq->perout.period.nsec) {
wx_err(wx, "Only 1pps is supported.\n");
return -EINVAL;
}
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;
wx->pps_width = timespec64_to_ns(&ts_on);
} else {
wx->pps_width = 120000000;
}
if (on)
set_bit(WX_FLAG_PTP_PPS_ENABLED, wx->flags);
else
clear_bit(WX_FLAG_PTP_PPS_ENABLED, wx->flags);
return wx->ptp_setup_sdp(wx);
}
void wx_ptp_check_pps_event(struct wx *wx)
{
u32 tsauxc, int_status;
/* this check is necessary in case the interrupt was enabled via some
* alternative means (ex. debug_fs). Better to check here than
* everywhere that calls this function.
*/
if (!wx->ptp_clock)
return;
int_status = rd32ptp(wx, WX_TSC_1588_INT_ST);
if (int_status & WX_TSC_1588_INT_ST_TT1) {
Annotation
- Immediate include surface: `linux/ptp_classify.h`, `linux/clocksource.h`, `linux/pci.h`, `wx_type.h`, `wx_ptp.h`, `wx_hw.h`.
- Detected declarations: `function wx_ptp_timecounter_cyc2time`, `function wx_ptp_readtime`, `function wx_ptp_adjfine`, `function wx_ptp_adjtime`, `function wx_ptp_gettimex64`, `function wx_ptp_settime64`, `function wx_ptp_clear_tx_timestamp`, `function wx_ptp_convert_to_hwtstamp`, `function wx_ptp_tx_hwtstamp`, `function wx_ptp_tx_hwtstamp_work`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
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.