Skip to content

Commit fe28c53

Browse files
Yannick Vignonkuba-moo
authored andcommitted
net: stmmac: fix taprio configuration when base_time is in the past
The Synopsys TSN MAC supports Qbv base times in the past, but only up to a certain limit. As a result, a taprio qdisc configuration with a small base time (for example when treating the base time as a simple phase offset) is not applied by the hardware and silently ignored. This was observed on an NXP i.MX8MPlus device, but likely affects all TSN-variants of the MAC. Fix the issue by making sure the base time is in the future, pushing it by an integer amount of cycle times if needed. (a similar check is already done in several other taprio implementations, see for example drivers/net/ethernet/intel/igc/igc_tsn.c#L116 or drivers/net/dsa/sja1105/sja1105_ptp.h#L39). Fixes: b60189e ("net: stmmac: Integrate EST with TAPRIO scheduler API") Signed-off-by: Yannick Vignon <yannick.vignon@nxp.com> Link: https://lore.kernel.org/r/20210113131557.24651-2-yannick.vignon@oss.nxp.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent b76889f commit fe28c53

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,8 @@ static int tc_setup_taprio(struct stmmac_priv *priv,
599599
{
600600
u32 size, wid = priv->dma_cap.estwid, dep = priv->dma_cap.estdep;
601601
struct plat_stmmacenet_data *plat = priv->plat;
602-
struct timespec64 time;
602+
struct timespec64 time, current_time;
603+
ktime_t current_time_ns;
603604
bool fpe = false;
604605
int i, ret = 0;
605606
u64 ctr;
@@ -694,7 +695,22 @@ static int tc_setup_taprio(struct stmmac_priv *priv,
694695
}
695696

696697
/* Adjust for real system time */
697-
time = ktime_to_timespec64(qopt->base_time);
698+
priv->ptp_clock_ops.gettime64(&priv->ptp_clock_ops, &current_time);
699+
current_time_ns = timespec64_to_ktime(current_time);
700+
if (ktime_after(qopt->base_time, current_time_ns)) {
701+
time = ktime_to_timespec64(qopt->base_time);
702+
} else {
703+
ktime_t base_time;
704+
s64 n;
705+
706+
n = div64_s64(ktime_sub_ns(current_time_ns, qopt->base_time),
707+
qopt->cycle_time);
708+
base_time = ktime_add_ns(qopt->base_time,
709+
(n + 1) * qopt->cycle_time);
710+
711+
time = ktime_to_timespec64(base_time);
712+
}
713+
698714
priv->plat->est->btr[0] = (u32)time.tv_nsec;
699715
priv->plat->est->btr[1] = (u32)time.tv_sec;
700716

0 commit comments

Comments
 (0)