Skip to content

Commit b60189e

Browse files
joabreudavem330
authored andcommitted
net: stmmac: Integrate EST with TAPRIO scheduler API
Now that we have the EST code for XGMAC and QoS we can use it with the TAPRIO scheduler. Integrate it into the main driver and use the API to configure the EST feature. Signed-off-by: Jose Abreu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8572aec commit b60189e

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

drivers/net/ethernet/stmicro/stmmac/hwif.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ struct stmmac_priv;
521521
struct tc_cls_u32_offload;
522522
struct tc_cbs_qopt_offload;
523523
struct flow_cls_offload;
524+
struct tc_taprio_qopt_offload;
524525

525526
struct stmmac_tc_ops {
526527
int (*init)(struct stmmac_priv *priv);
@@ -530,6 +531,8 @@ struct stmmac_tc_ops {
530531
struct tc_cbs_qopt_offload *qopt);
531532
int (*setup_cls)(struct stmmac_priv *priv,
532533
struct flow_cls_offload *cls);
534+
int (*setup_taprio)(struct stmmac_priv *priv,
535+
struct tc_taprio_qopt_offload *qopt);
533536
};
534537

535538
#define stmmac_tc_init(__priv, __args...) \
@@ -540,6 +543,8 @@ struct stmmac_tc_ops {
540543
stmmac_do_callback(__priv, tc, setup_cbs, __args)
541544
#define stmmac_tc_setup_cls(__priv, __args...) \
542545
stmmac_do_callback(__priv, tc, setup_cls, __args)
546+
#define stmmac_tc_setup_taprio(__priv, __args...) \
547+
stmmac_do_callback(__priv, tc, setup_taprio, __args)
543548

544549
struct stmmac_counters;
545550

drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4076,6 +4076,8 @@ static int stmmac_setup_tc(struct net_device *ndev, enum tc_setup_type type,
40764076
priv, priv, true);
40774077
case TC_SETUP_QDISC_CBS:
40784078
return stmmac_tc_setup_cbs(priv, priv, type_data);
4079+
case TC_SETUP_QDISC_TAPRIO:
4080+
return stmmac_tc_setup_taprio(priv, priv, type_data);
40794081
default:
40804082
return -EOPNOTSUPP;
40814083
}

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

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,117 @@ static int tc_setup_cls(struct stmmac_priv *priv,
591591
return ret;
592592
}
593593

594+
static int tc_setup_taprio(struct stmmac_priv *priv,
595+
struct tc_taprio_qopt_offload *qopt)
596+
{
597+
u32 size, wid = priv->dma_cap.estwid, dep = priv->dma_cap.estdep;
598+
struct plat_stmmacenet_data *plat = priv->plat;
599+
struct timespec64 time;
600+
int i, ret = 0;
601+
602+
if (!priv->dma_cap.estsel)
603+
return -EOPNOTSUPP;
604+
605+
switch (wid) {
606+
case 0x1:
607+
wid = 16;
608+
break;
609+
case 0x2:
610+
wid = 20;
611+
break;
612+
case 0x3:
613+
wid = 24;
614+
break;
615+
default:
616+
return -EOPNOTSUPP;
617+
}
618+
619+
switch (dep) {
620+
case 0x1:
621+
dep = 64;
622+
break;
623+
case 0x2:
624+
dep = 128;
625+
break;
626+
case 0x3:
627+
dep = 256;
628+
break;
629+
case 0x4:
630+
dep = 512;
631+
break;
632+
case 0x5:
633+
dep = 1024;
634+
break;
635+
default:
636+
return -EOPNOTSUPP;
637+
}
638+
639+
if (!qopt->enable)
640+
goto disable;
641+
if (qopt->num_entries >= dep)
642+
return -EINVAL;
643+
if (!qopt->base_time)
644+
return -ERANGE;
645+
if (!qopt->cycle_time)
646+
return -ERANGE;
647+
648+
if (!plat->est) {
649+
plat->est = devm_kzalloc(priv->device, sizeof(*plat->est),
650+
GFP_KERNEL);
651+
if (!plat->est)
652+
return -ENOMEM;
653+
} else {
654+
memset(plat->est, 0, sizeof(*plat->est));
655+
}
656+
657+
size = qopt->num_entries;
658+
659+
priv->plat->est->gcl_size = size;
660+
priv->plat->est->enable = qopt->enable;
661+
662+
for (i = 0; i < size; i++) {
663+
s64 delta_ns = qopt->entries[i].interval;
664+
u32 gates = qopt->entries[i].gate_mask;
665+
666+
if (delta_ns > GENMASK(wid, 0))
667+
return -ERANGE;
668+
if (gates > GENMASK(31 - wid, 0))
669+
return -ERANGE;
670+
if (qopt->entries[i].command != TC_TAPRIO_CMD_SET_GATES)
671+
return -EOPNOTSUPP;
672+
673+
priv->plat->est->gcl[i] = delta_ns | (gates << wid);
674+
}
675+
676+
/* Adjust for real system time */
677+
time = ktime_to_timespec64(qopt->base_time);
678+
priv->plat->est->btr[0] = (u32)time.tv_nsec;
679+
priv->plat->est->btr[1] = (u32)time.tv_sec;
680+
681+
priv->plat->est->ctr[0] = (u32)(qopt->cycle_time % NSEC_PER_SEC);
682+
priv->plat->est->ctr[1] = (u32)(qopt->cycle_time / NSEC_PER_SEC);
683+
684+
ret = stmmac_est_configure(priv, priv->ioaddr, priv->plat->est,
685+
priv->plat->clk_ptp_rate);
686+
if (ret) {
687+
netdev_err(priv->dev, "failed to configure EST\n");
688+
goto disable;
689+
}
690+
691+
netdev_info(priv->dev, "configured EST\n");
692+
return 0;
693+
694+
disable:
695+
priv->plat->est->enable = false;
696+
stmmac_est_configure(priv, priv->ioaddr, priv->plat->est,
697+
priv->plat->clk_ptp_rate);
698+
return ret;
699+
}
700+
594701
const struct stmmac_tc_ops dwmac510_tc_ops = {
595702
.init = tc_init,
596703
.setup_cls_u32 = tc_setup_cls_u32,
597704
.setup_cbs = tc_setup_cbs,
598705
.setup_cls = tc_setup_cls,
706+
.setup_taprio = tc_setup_taprio,
599707
};

0 commit comments

Comments
 (0)