drivers/net/dsa/sja1105/sja1105_ptp.c
Source file repositories/reference/linux-study-clean/drivers/net/dsa/sja1105/sja1105_ptp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/dsa/sja1105/sja1105_ptp.c- Extension
.c- Size
- 26255 bytes
- Lines
- 971
- 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/spi/spi.hsja1105.h
Detected Declarations
enum sja1105_ptp_clk_modefunction container_offunction sja1105_hwtstamp_getfunction sja1105_get_ts_infofunction sja1105et_ptp_cmd_packingfunction sja1105pqrs_ptp_cmd_packingfunction sja1105_ptp_commitfunction sja1105_tstamp_reconstructfunction sja1105_ptpegr_ts_pollfunction sja1105_ptpclkval_readfunction sja1105_ptpclkval_writefunction sja1105_extts_pollfunction sja1105_rxtstamp_workfunction sja1105_rxtstampfunction sja1110_rxtstampfunction sja1105_port_rxtstampfunction sja1110_process_meta_tstampfunction skb_queue_walk_safefunction sja1110_txtstampfunction sja1105_port_txtstampfunction sja1105_ptp_resetfunction __sja1105_ptp_gettimexfunction sja1105_ptp_gettimexfunction sja1105_ptp_mode_setfunction __sja1105_ptp_settimefunction sja1105_ptp_settimefunction sja1105_ptp_adjfinefunction __sja1105_ptp_adjtimefunction sja1105_ptp_adjtimefunction sja1105_ptp_extts_setup_timerfunction sja1105_ptp_extts_timerfunction sja1105_change_ptp_clk_pin_funcfunction sja1105_per_out_enablefunction sja1105_extts_enablefunction sja1105_ptp_enablefunction sja1105_ptp_verify_pinfunction sja1105_ptp_clock_registerfunction sja1105_ptp_clock_unregisterfunction sja1105_ptp_txtstamp_skb
Annotated Snippet
if (rc < 0) {
dev_err(ds->dev, "Failed to read PTP clock: %d\n", rc);
kfree_skb(skb);
continue;
}
*shwt = (struct skb_shared_hwtstamps) {0};
ts = SJA1105_SKB_CB(skb)->tstamp;
ts = sja1105_tstamp_reconstruct(ds, ticks, ts);
shwt->hwtstamp = ns_to_ktime(sja1105_ticks_to_ns(ts));
netif_rx(skb);
}
if (ptp_data->extts_enabled)
sja1105_extts_poll(priv);
mutex_unlock(&ptp_data->lock);
/* Don't restart */
return -1;
}
bool sja1105_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb)
{
struct sja1105_private *priv = ds->priv;
struct sja1105_ptp_data *ptp_data = &priv->ptp_data;
if (!(priv->hwts_rx_en & BIT(port)))
return false;
/* We need to read the full PTP clock to reconstruct the Rx
* timestamp. For that we need a sleepable context.
*/
skb_queue_tail(&ptp_data->skb_rxtstamp_queue, skb);
ptp_schedule_worker(ptp_data->clock, 0);
return true;
}
bool sja1110_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb)
{
struct skb_shared_hwtstamps *shwt = skb_hwtstamps(skb);
u64 ts = SJA1105_SKB_CB(skb)->tstamp;
*shwt = (struct skb_shared_hwtstamps) {0};
shwt->hwtstamp = ns_to_ktime(sja1105_ticks_to_ns(ts));
/* Don't defer */
return false;
}
/* Called from dsa_skb_defer_rx_timestamp */
bool sja1105_port_rxtstamp(struct dsa_switch *ds, int port,
struct sk_buff *skb, unsigned int type)
{
struct sja1105_private *priv = ds->priv;
return priv->info->rxtstamp(ds, port, skb);
}
void sja1110_process_meta_tstamp(struct dsa_switch *ds, int port, u8 ts_id,
enum sja1110_meta_tstamp dir, u64 tstamp)
{
struct sja1105_private *priv = ds->priv;
struct sja1105_ptp_data *ptp_data = &priv->ptp_data;
struct sk_buff *skb, *skb_tmp, *skb_match = NULL;
struct skb_shared_hwtstamps shwt = {0};
/* We don't care about RX timestamps on the CPU port */
if (dir == SJA1110_META_TSTAMP_RX)
return;
spin_lock(&ptp_data->skb_txtstamp_queue.lock);
skb_queue_walk_safe(&ptp_data->skb_txtstamp_queue, skb, skb_tmp) {
if (SJA1105_SKB_CB(skb)->ts_id != ts_id)
continue;
__skb_unlink(skb, &ptp_data->skb_txtstamp_queue);
skb_match = skb;
break;
}
spin_unlock(&ptp_data->skb_txtstamp_queue.lock);
if (WARN_ON(!skb_match))
return;
Annotation
- Immediate include surface: `linux/spi/spi.h`, `sja1105.h`.
- Detected declarations: `enum sja1105_ptp_clk_mode`, `function container_of`, `function sja1105_hwtstamp_get`, `function sja1105_get_ts_info`, `function sja1105et_ptp_cmd_packing`, `function sja1105pqrs_ptp_cmd_packing`, `function sja1105_ptp_commit`, `function sja1105_tstamp_reconstruct`, `function sja1105_ptpegr_ts_poll`, `function sja1105_ptpclkval_read`.
- 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.