/* The adjfine API clamps ppb between [-32,768,000, 32,768,000], and *thereforescaled_ppmbetween[-2,147,483,648,2,147,483,647]. *Setthemaximumsupportedppbtoaroundvaluesmallerthanthemaximum. * *Percentuallyspeaking,thisisa+/-0.032xadjustmentofthe *free-runningcounter(0.968xto1.032x).
*/ #define SJA1105_MAX_ADJ_PPB 32000000 #define SJA1105_SIZE_PTP_CMD 4
/* PTPSYNCTS has no interrupt or update mechanism, because the intended *hardwareusecaseisforthetimestamptobecollectedsynchronously, *immediatelyaftertheCAS_MASTERSJA1105switchhasperformedaCASSYNC *one-shottoggle(noreturntolevel)onthePTP_CLKpin.Whenusedasa *genericexttssource,thePTPSYNCTSregisterneedspollingandacomparison *withtheoldvalue.ThepollingintervalisconfiguredastheNyquistrate *ofasignalwith50%dutycycleand1Hzfrequency,whichissadlyallthat *thishardwarecando(butmaybeenoughforsomesetups).Anythingofhigher *frequencythan1Hzwillbelost,sincethereisnotimestampFIFO.
*/ #define SJA1105_EXTTS_INTERVAL (HZ / 6)
void sja1105et_ptp_cmd_packing(u8 *buf, struct sja1105_ptp_cmd *cmd, enum packing_op op)
{ constint size = SJA1105_SIZE_PTP_CMD; /* No need to keep this as part of the structure */
u64 valid = 1;
void sja1105pqrs_ptp_cmd_packing(u8 *buf, struct sja1105_ptp_cmd *cmd, enum packing_op op)
{ constint size = SJA1105_SIZE_PTP_CMD; /* No need to keep this as part of the structure */
u64 valid = 1;
/* Check lower bits of current cycle counter against the timestamp. *Ifthecurrentcyclecounterislowerthanthepartialtimestamp, *thenwraparoundsurelyoccurredandmustbeaccountedfor.
*/ if ((now & partial_tstamp_mask) <= ts_partial)
ts_reconstructed -= (partial_tstamp_mask + 1);
return ts_reconstructed;
}
/* Reads the SPI interface for an egress timestamp generated by the switch *forframessentusingmanagementroutes. * *SJA1105E/Tlayoutofthe4-byteSPIpayload: * *31231570 *||||| *+-----+-----+-----+^ *^| *|| *24-bittimestampUpdatebit * * *SJA1105P/Q/R/Slayoutofthe8-byteSPIpayload: * *312315706355473932 *|||||||||| *^+-----+-----+-----+-----+ *|^ *|| *Updatebit32-bittimestamp * *Noticethattheupdatebitisinthesameplace. *TohavecommoncodeforE/TandP/Q/R/Sforreadingthetimestamp, *weneedtojugglewiththeoffsetandthebitindices.
*/ staticint sja1105_ptpegr_ts_poll(struct dsa_switch *ds, int port, u64 *ts)
{ struct sja1105_private *priv = ds->priv; conststruct sja1105_regs *regs = priv->info->regs; int tstamp_bit_start, tstamp_bit_end; int timeout = 10;
u8 packed_buf[8];
u64 update; int rc;
do {
rc = sja1105_xfer_buf(priv, SPI_READ, regs->ptpegr_ts[port],
packed_buf, priv->info->ptpegr_ts_bytes); if (rc < 0) return rc;
sja1105_unpack(packed_buf, &update, 0, 0,
priv->info->ptpegr_ts_bytes); if (update) break;
usleep_range(10, 50);
} while (--timeout);
if (!timeout) return -ETIMEDOUT;
/* Point the end bit to the second 32-bit word on P/Q/R/S, *no-oponE/T.
*/
tstamp_bit_end = (priv->info->ptpegr_ts_bytes - 4) * 8; /* Shift the 24-bit timestamp on E/T to be collected from 31:8. *No-oponP/Q/R/S.
*/
tstamp_bit_end += 32 - priv->info->ptp_ts_bits;
tstamp_bit_start = tstamp_bit_end + priv->info->ptp_ts_bits - 1;
/* We need to read the full PTP clock to reconstruct the Rx *timestamp.Forthatweneedasleepablecontext.
*/
skb_queue_tail(&ptp_data->skb_rxtstamp_queue, skb);
ptp_schedule_worker(ptp_data->clock, 0); returntrue;
}
/* In addition to cloning the skb which is done by the common *sja1105_port_txtstamp,weneedtogenerateatimestampIDandsavethe *packettotheTXtimestampingqueue.
*/ void sja1110_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb)
{ struct sk_buff *clone = SJA1105_SKB_CB(skb)->clone; struct sja1105_private *priv = ds->priv; struct sja1105_ptp_data *ptp_data = &priv->ptp_data;
u8 ts_id;
/* Called from dsa_skb_tx_timestamp. This callback is just to clone *theskbandhaveitavailableinSJA1105_SKB_CBinthe.port_deferred_xmit *callback,wherewewilltimestampitsynchronously.
*/ void sja1105_port_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb)
{ struct sja1105_private *priv = ds->priv; struct sk_buff *clone;
if (!(priv->hwts_tx_en & BIT(port))) return;
clone = skb_clone_sk(skb); if (!clone) return;
SJA1105_SKB_CB(skb)->clone = clone;
if (priv->info->txtstamp)
priv->info->txtstamp(ds, port, skb);
}
/* Take a +/- value and re-center it around 2^31. */
clkrate = SJA1105_CC_MULT + clkrate;
WARN_ON(abs(clkrate) >= GENMASK_ULL(31, 0));
clkrate32 = clkrate;
/* ptppindur: 32 bit register which holds the interval between *2edgesonPTP_CLK.Socheckfortruncationwhichhappens *atperiodslargerthanaround68.7seconds.
*/
pin_duration = ns_to_sja1105_ticks(pin_duration / 2); if (pin_duration > U32_MAX) {
rc = -ERANGE; goto out;
}
pin_duration32 = pin_duration;
/* ptppins: 64 bit register which needs to hold a PTP time *largerthanthecurrenttime,otherwisethestartptpcp *commandwon'tdoanything.Soadvancethecurrenttime *byanumberofperiodsinawaythatwon'talterthe *phaseoffset.
*/
rc = __sja1105_ptp_gettimex(priv->ds, &now, NULL); if (rc < 0) goto out;
/* We only support one channel */ if (extts->index != 0) return -EOPNOTSUPP;
/* We can only enable time stamping on both edges, sadly. */ if ((extts->flags & PTP_STRICT_FLAGS) &&
(extts->flags & PTP_ENABLE_FEATURE) &&
(extts->flags & PTP_EXTTS_EDGES) != PTP_EXTTS_EDGES) return -EOPNOTSUPP;
rc = sja1105_change_ptp_clk_pin_func(priv, PTP_PF_EXTTS); if (rc) return rc;
priv->ptp_data.extts_enabled = on;
if (on)
sja1105_ptp_extts_setup_timer(&priv->ptp_data); else
timer_delete_sync(&priv->ptp_data.extts_timer);
/* Only used on SJA1105 */
skb_queue_head_init(&ptp_data->skb_rxtstamp_queue); /* Only used on SJA1110 */
skb_queue_head_init(&ptp_data->skb_txtstamp_queue);
ptp_data->clock = ptp_clock_register(&ptp_data->caps, ds->dev); if (IS_ERR_OR_NULL(ptp_data->clock)) return PTR_ERR(ptp_data->clock);
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.16Bemerkung:
(vorverarbeitet am 2026-10-12)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.