drivers/net/ethernet/cadence/macb_ptp.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/cadence/macb_ptp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/cadence/macb_ptp.c- Extension
.c- Size
- 12080 bytes
- Lines
- 471
- 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.
- 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.
- 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/kernel.hlinux/types.hlinux/clk.hlinux/device.hlinux/etherdevice.hlinux/platform_device.hlinux/time64.hlinux/ptp_classify.hlinux/if_ether.hlinux/if_vlan.hlinux/net_tstamp.hlinux/circ_buf.hlinux/spinlock.hmacb.h
Detected Declarations
function Copyrightfunction gem_tsu_get_timefunction gem_tsu_set_timefunction gem_tsu_incr_setfunction gem_ptp_adjfinefunction gem_ptp_adjtimefunction gem_ptp_enablefunction gem_ptp_init_timerfunction gem_ptp_init_tsufunction gem_ptp_clear_timerfunction gem_hw_timestampfunction gem_ptp_rxstampfunction gem_ptp_txstampfunction gem_ptp_initfunction gem_ptp_removefunction gem_ptp_set_ts_modefunction gem_get_hwtstfunction gem_ptp_set_one_step_syncfunction gem_set_hwtst
Annotated Snippet
if (!desc_ptp) {
dev_warn_ratelimited(&bp->pdev->dev,
"Timestamp not supported in BD\n");
return;
}
gem_hw_timestamp(bp, desc_ptp->ts_1, desc_ptp->ts_2, &ts);
memset(shhwtstamps, 0, sizeof(struct skb_shared_hwtstamps));
shhwtstamps->hwtstamp = ktime_set(ts.tv_sec, ts.tv_nsec);
}
}
void gem_ptp_txstamp(struct macb *bp, struct sk_buff *skb,
struct macb_dma_desc *desc)
{
struct skb_shared_hwtstamps shhwtstamps;
struct macb_dma_desc_ptp *desc_ptp;
struct timespec64 ts;
if (!GEM_BFEXT(DMA_TXVALID, desc->ctrl)) {
dev_warn_ratelimited(&bp->pdev->dev,
"Timestamp not set in TX BD as expected\n");
return;
}
desc_ptp = macb_ptp_desc(bp, desc);
/* Unlikely but check */
if (!desc_ptp) {
dev_warn_ratelimited(&bp->pdev->dev,
"Timestamp not supported in BD\n");
return;
}
/* ensure ts_1/ts_2 is loaded after ctrl (TX_USED check) */
dma_rmb();
gem_hw_timestamp(bp, desc_ptp->ts_1, desc_ptp->ts_2, &ts);
memset(&shhwtstamps, 0, sizeof(shhwtstamps));
shhwtstamps.hwtstamp = ktime_set(ts.tv_sec, ts.tv_nsec);
skb_tstamp_tx(skb, &shhwtstamps);
}
void gem_ptp_init(struct net_device *dev)
{
struct macb *bp = netdev_priv(dev);
bp->ptp_clock_info = gem_ptp_caps_template;
/* nominal frequency and maximum adjustment in ppb */
bp->tsu_rate = bp->ptp_info->get_tsu_rate(bp);
bp->ptp_clock_info.max_adj = bp->ptp_info->get_ptp_max_adj();
gem_ptp_init_timer(bp);
bp->ptp_clock = ptp_clock_register(&bp->ptp_clock_info, &dev->dev);
if (IS_ERR(bp->ptp_clock)) {
pr_err("ptp clock register failed: %ld\n",
PTR_ERR(bp->ptp_clock));
bp->ptp_clock = NULL;
return;
} else if (bp->ptp_clock == NULL) {
pr_err("ptp clock register failed\n");
return;
}
spin_lock_init(&bp->tsu_clk_lock);
gem_ptp_init_tsu(bp);
dev_info(&bp->pdev->dev, "%s ptp clock registered.\n",
GEM_PTP_TIMER_NAME);
}
void gem_ptp_remove(struct net_device *ndev)
{
struct macb *bp = netdev_priv(ndev);
if (bp->ptp_clock) {
ptp_clock_unregister(bp->ptp_clock);
bp->ptp_clock = NULL;
}
gem_ptp_clear_timer(bp);
dev_info(&bp->pdev->dev, "%s ptp clock unregistered.\n",
GEM_PTP_TIMER_NAME);
}
static int gem_ptp_set_ts_mode(struct macb *bp,
enum macb_bd_control tx_bd_control,
enum macb_bd_control rx_bd_control)
{
gem_writel(bp, TXBDCTRL, GEM_BF(TXTSMODE, tx_bd_control));
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/types.h`, `linux/clk.h`, `linux/device.h`, `linux/etherdevice.h`, `linux/platform_device.h`, `linux/time64.h`, `linux/ptp_classify.h`.
- Detected declarations: `function Copyright`, `function gem_tsu_get_time`, `function gem_tsu_set_time`, `function gem_tsu_incr_set`, `function gem_ptp_adjfine`, `function gem_ptp_adjtime`, `function gem_ptp_enable`, `function gem_ptp_init_timer`, `function gem_ptp_init_tsu`, `function gem_ptp_clear_timer`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source 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.