Skip to content

Commit 504723a

Browse files
joabreudavem330
authored andcommitted
net: stmmac: Add basic EST support for GMAC5+
Adds the support for EST in GMAC5+ cores. This feature allows to offload scheduling of queues opening time to the IP. Signed-off-by: Jose Abreu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6dbb2e9 commit 504723a

File tree

8 files changed

+150
-0
lines changed

8 files changed

+150
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ struct dma_features {
363363
unsigned int dvlan;
364364
unsigned int l3l4fnum;
365365
unsigned int arpoffsel;
366+
/* TSN Features */
367+
unsigned int estwid;
368+
unsigned int estdep;
369+
unsigned int estsel;
366370
};
367371

368372
/* GMAC TX FIFO is 8K, Rx FIFO is 16K */

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,26 @@ enum power_event {
176176
#define GMAC_CONFIG_SARC GENMASK(30, 28)
177177
#define GMAC_CONFIG_SARC_SHIFT 28
178178
#define GMAC_CONFIG_IPC BIT(27)
179+
#define GMAC_CONFIG_IPG GENMASK(26, 24)
180+
#define GMAC_CONFIG_IPG_SHIFT 24
179181
#define GMAC_CONFIG_2K BIT(22)
180182
#define GMAC_CONFIG_ACS BIT(20)
181183
#define GMAC_CONFIG_BE BIT(18)
182184
#define GMAC_CONFIG_JD BIT(17)
183185
#define GMAC_CONFIG_JE BIT(16)
184186
#define GMAC_CONFIG_PS BIT(15)
185187
#define GMAC_CONFIG_FES BIT(14)
188+
#define GMAC_CONFIG_FES_SHIFT 14
186189
#define GMAC_CONFIG_DM BIT(13)
187190
#define GMAC_CONFIG_LM BIT(12)
188191
#define GMAC_CONFIG_DCRS BIT(9)
189192
#define GMAC_CONFIG_TE BIT(1)
190193
#define GMAC_CONFIG_RE BIT(0)
191194

192195
/* MAC extended config */
196+
#define GMAC_CONFIG_EIPG GENMASK(29, 25)
197+
#define GMAC_CONFIG_EIPG_SHIFT 25
198+
#define GMAC_CONFIG_EIPG_EN BIT(24)
193199
#define GMAC_CONFIG_HDSMS GENMASK(22, 20)
194200
#define GMAC_CONFIG_HDSMS_SHIFT 20
195201
#define GMAC_CONFIG_HDSMS_256 (0x2 << GMAC_CONFIG_HDSMS_SHIFT)
@@ -231,6 +237,9 @@ enum power_event {
231237

232238
/* MAC HW features3 bitmap */
233239
#define GMAC_HW_FEAT_ASP GENMASK(29, 28)
240+
#define GMAC_HW_FEAT_ESTWID GENMASK(21, 20)
241+
#define GMAC_HW_FEAT_ESTDEP GENMASK(19, 17)
242+
#define GMAC_HW_FEAT_ESTSEL BIT(16)
234243
#define GMAC_HW_FEAT_FRPES GENMASK(14, 13)
235244
#define GMAC_HW_FEAT_FRPBS GENMASK(12, 11)
236245
#define GMAC_HW_FEAT_FRPSEL BIT(10)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ const struct stmmac_ops dwmac410_ops = {
984984
.set_arp_offload = dwmac4_set_arp_offload,
985985
.config_l3_filter = dwmac4_config_l3_filter,
986986
.config_l4_filter = dwmac4_config_l4_filter,
987+
.est_configure = dwmac5_est_configure,
987988
};
988989

989990
const struct stmmac_ops dwmac510_ops = {
@@ -1027,6 +1028,7 @@ const struct stmmac_ops dwmac510_ops = {
10271028
.set_arp_offload = dwmac4_set_arp_offload,
10281029
.config_l3_filter = dwmac4_config_l3_filter,
10291030
.config_l4_filter = dwmac4_config_l4_filter,
1031+
.est_configure = dwmac5_est_configure,
10301032
};
10311033

10321034
int dwmac4_setup(struct stmmac_priv *priv)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ static void dwmac4_get_hw_feature(void __iomem *ioaddr,
404404

405405
/* 5.10 Features */
406406
dma_cap->asp = (hw_cap & GMAC_HW_FEAT_ASP) >> 28;
407+
dma_cap->estwid = (hw_cap & GMAC_HW_FEAT_ESTWID) >> 20;
408+
dma_cap->estdep = (hw_cap & GMAC_HW_FEAT_ESTDEP) >> 17;
409+
dma_cap->estsel = (hw_cap & GMAC_HW_FEAT_ESTSEL) >> 16;
407410
dma_cap->frpes = (hw_cap & GMAC_HW_FEAT_FRPES) >> 13;
408411
dma_cap->frpbs = (hw_cap & GMAC_HW_FEAT_FRPBS) >> 11;
409412
dma_cap->frpsel = (hw_cap & GMAC_HW_FEAT_FRPSEL) >> 10;

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,3 +550,98 @@ int dwmac5_flex_pps_config(void __iomem *ioaddr, int index,
550550
writel(val, ioaddr + MAC_PPS_CONTROL);
551551
return 0;
552552
}
553+
554+
static int dwmac5_est_write(void __iomem *ioaddr, u32 reg, u32 val, bool gcl)
555+
{
556+
u32 ctrl;
557+
558+
writel(val, ioaddr + MTL_EST_GCL_DATA);
559+
560+
ctrl = (reg << ADDR_SHIFT);
561+
ctrl |= gcl ? 0 : GCRR;
562+
563+
writel(ctrl, ioaddr + MTL_EST_GCL_CONTROL);
564+
565+
ctrl |= SRWO;
566+
writel(ctrl, ioaddr + MTL_EST_GCL_CONTROL);
567+
568+
return readl_poll_timeout(ioaddr + MTL_EST_GCL_CONTROL,
569+
ctrl, !(ctrl & SRWO), 100, 5000);
570+
}
571+
572+
int dwmac5_est_configure(void __iomem *ioaddr, struct stmmac_est *cfg,
573+
unsigned int ptp_rate)
574+
{
575+
u32 speed, total_offset, offset, ctrl, ctr_low;
576+
u32 extcfg = readl(ioaddr + GMAC_EXT_CONFIG);
577+
u32 mac_cfg = readl(ioaddr + GMAC_CONFIG);
578+
int i, ret = 0x0;
579+
u64 total_ctr;
580+
581+
if (extcfg & GMAC_CONFIG_EIPG_EN) {
582+
offset = (extcfg & GMAC_CONFIG_EIPG) >> GMAC_CONFIG_EIPG_SHIFT;
583+
offset = 104 + (offset * 8);
584+
} else {
585+
offset = (mac_cfg & GMAC_CONFIG_IPG) >> GMAC_CONFIG_IPG_SHIFT;
586+
offset = 96 - (offset * 8);
587+
}
588+
589+
speed = mac_cfg & (GMAC_CONFIG_PS | GMAC_CONFIG_FES);
590+
speed = speed >> GMAC_CONFIG_FES_SHIFT;
591+
592+
switch (speed) {
593+
case 0x0:
594+
offset = offset * 1000; /* 1G */
595+
break;
596+
case 0x1:
597+
offset = offset * 400; /* 2.5G */
598+
break;
599+
case 0x2:
600+
offset = offset * 100000; /* 10M */
601+
break;
602+
case 0x3:
603+
offset = offset * 10000; /* 100M */
604+
break;
605+
default:
606+
return -EINVAL;
607+
}
608+
609+
offset = offset / 1000;
610+
611+
ret |= dwmac5_est_write(ioaddr, BTR_LOW, cfg->btr[0], false);
612+
ret |= dwmac5_est_write(ioaddr, BTR_HIGH, cfg->btr[1], false);
613+
ret |= dwmac5_est_write(ioaddr, TER, cfg->ter, false);
614+
ret |= dwmac5_est_write(ioaddr, LLR, cfg->gcl_size, false);
615+
if (ret)
616+
return ret;
617+
618+
total_offset = 0;
619+
for (i = 0; i < cfg->gcl_size; i++) {
620+
ret = dwmac5_est_write(ioaddr, i, cfg->gcl[i] + offset, true);
621+
if (ret)
622+
return ret;
623+
624+
total_offset += offset;
625+
}
626+
627+
total_ctr = cfg->ctr[0] + cfg->ctr[1] * 1000000000;
628+
total_ctr += total_offset;
629+
630+
ctr_low = do_div(total_ctr, 1000000000);
631+
632+
ret |= dwmac5_est_write(ioaddr, CTR_LOW, ctr_low, false);
633+
ret |= dwmac5_est_write(ioaddr, CTR_HIGH, total_ctr, false);
634+
if (ret)
635+
return ret;
636+
637+
ctrl = readl(ioaddr + MTL_EST_CONTROL);
638+
ctrl &= ~PTOV;
639+
ctrl |= ((1000000000 / ptp_rate) * 6) << PTOV_SHIFT;
640+
if (cfg->enable)
641+
ctrl |= EEST | SSWL;
642+
else
643+
ctrl &= ~EEST;
644+
645+
writel(ctrl, ioaddr + MTL_EST_CONTROL);
646+
return 0;
647+
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@
3030
#define MAC_PPSx_INTERVAL(x) (0x00000b88 + ((x) * 0x10))
3131
#define MAC_PPSx_WIDTH(x) (0x00000b8c + ((x) * 0x10))
3232

33+
#define MTL_EST_CONTROL 0x00000c50
34+
#define PTOV GENMASK(31, 24)
35+
#define PTOV_SHIFT 24
36+
#define SSWL BIT(1)
37+
#define EEST BIT(0)
38+
#define MTL_EST_GCL_CONTROL 0x00000c80
39+
#define BTR_LOW 0x0
40+
#define BTR_HIGH 0x1
41+
#define CTR_LOW 0x2
42+
#define CTR_HIGH 0x3
43+
#define TER 0x4
44+
#define LLR 0x5
45+
#define ADDR_SHIFT 8
46+
#define GCRR BIT(2)
47+
#define SRWO BIT(0)
48+
#define MTL_EST_GCL_DATA 0x00000c84
49+
3350
#define MTL_RXP_CONTROL_STATUS 0x00000ca0
3451
#define RXPI BIT(31)
3552
#define NPE GENMASK(23, 16)
@@ -83,5 +100,7 @@ int dwmac5_rxp_config(void __iomem *ioaddr, struct stmmac_tc_entry *entries,
83100
int dwmac5_flex_pps_config(void __iomem *ioaddr, int index,
84101
struct stmmac_pps_cfg *cfg, bool enable,
85102
u32 sub_second_inc, u32 systime_flags);
103+
int dwmac5_est_configure(void __iomem *ioaddr, struct stmmac_est *cfg,
104+
unsigned int ptp_rate);
86105

87106
#endif /* __DWMAC5_H__ */

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ struct stmmac_safety_stats;
276276
struct stmmac_tc_entry;
277277
struct stmmac_pps_cfg;
278278
struct stmmac_rss;
279+
struct stmmac_est;
279280

280281
/* Helpers to program the MAC core */
281282
struct stmmac_ops {
@@ -373,6 +374,8 @@ struct stmmac_ops {
373374
bool en, bool udp, bool sa, bool inv,
374375
u32 match);
375376
void (*set_arp_offload)(struct mac_device_info *hw, bool en, u32 addr);
377+
int (*est_configure)(void __iomem *ioaddr, struct stmmac_est *cfg,
378+
unsigned int ptp_rate);
376379
};
377380

378381
#define stmmac_core_init(__priv, __args...) \
@@ -459,6 +462,8 @@ struct stmmac_ops {
459462
stmmac_do_callback(__priv, mac, config_l4_filter, __args)
460463
#define stmmac_set_arp_offload(__priv, __args...) \
461464
stmmac_do_void_callback(__priv, mac, set_arp_offload, __args)
465+
#define stmmac_est_configure(__priv, __args...) \
466+
stmmac_do_callback(__priv, mac, est_configure, __args)
462467

463468
/* PTP and HW Timer helpers */
464469
struct stmmac_hwtimestamp {

include/linux/stmmac.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ struct stmmac_axi {
109109
bool axi_rb;
110110
};
111111

112+
#define EST_GCL 1024
113+
struct stmmac_est {
114+
int enable;
115+
u32 btr_offset[2];
116+
u32 btr[2];
117+
u32 ctr[2];
118+
u32 ter;
119+
u32 gcl_unaligned[EST_GCL];
120+
u32 gcl[EST_GCL];
121+
u32 gcl_size;
122+
};
123+
112124
struct stmmac_rxq_cfg {
113125
u8 mode_to_use;
114126
u32 chan;
@@ -139,6 +151,7 @@ struct plat_stmmacenet_data {
139151
struct device_node *phylink_node;
140152
struct device_node *mdio_node;
141153
struct stmmac_dma_cfg *dma_cfg;
154+
struct stmmac_est *est;
142155
int clk_csr;
143156
int has_gmac;
144157
int enh_desc;

0 commit comments

Comments
 (0)