Skip to content

Commit b08191d

Browse files
committed
Merge branch 'move-est-lock-and-est-structure-to-struct-stmmac_priv'
Xiaolei Wang says: ==================== Move EST lock and EST structure to struct stmmac_priv 1. Pulling the mutex protecting the EST structure out to avoid clearing it during reinit/memset of the EST structure,and reacquire the mutex lock when doing this initialization. 2. Moving the EST structure to a more logical location ==================== Link: https://lore.kernel.org/r/20240513014346.1718740-1-xiaolei.wang@windriver.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 9512515 + bd17382 commit b08191d

File tree

5 files changed

+70
-69
lines changed

5 files changed

+70
-69
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,20 @@ struct stmmac_dma_conf {
221221
unsigned int dma_tx_size;
222222
};
223223

224+
#define EST_GCL 1024
225+
struct stmmac_est {
226+
int enable;
227+
u32 btr_reserve[2];
228+
u32 btr_offset[2];
229+
u32 btr[2];
230+
u32 ctr[2];
231+
u32 ter;
232+
u32 gcl_unaligned[EST_GCL];
233+
u32 gcl[EST_GCL];
234+
u32 gcl_size;
235+
u32 max_sdu[MTL_MAX_TX_QUEUES];
236+
};
237+
224238
struct stmmac_priv {
225239
/* Frequently used values are kept adjacent for cache effect */
226240
u32 tx_coal_frames[MTL_MAX_TX_QUEUES];
@@ -261,6 +275,9 @@ struct stmmac_priv {
261275
struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
262276
struct stmmac_safety_stats sstats;
263277
struct plat_stmmacenet_data *plat;
278+
/* Protect est parameters */
279+
struct mutex est_lock;
280+
struct stmmac_est *est;
264281
struct dma_features dma_cap;
265282
struct stmmac_counters mmc;
266283
int hw_cap_support;

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,9 +2498,9 @@ static bool stmmac_xdp_xmit_zc(struct stmmac_priv *priv, u32 queue, u32 budget)
24982498
if (!xsk_tx_peek_desc(pool, &xdp_desc))
24992499
break;
25002500

2501-
if (priv->plat->est && priv->plat->est->enable &&
2502-
priv->plat->est->max_sdu[queue] &&
2503-
xdp_desc.len > priv->plat->est->max_sdu[queue]) {
2501+
if (priv->est && priv->est->enable &&
2502+
priv->est->max_sdu[queue] &&
2503+
xdp_desc.len > priv->est->max_sdu[queue]) {
25042504
priv->xstats.max_sdu_txq_drop[queue]++;
25052505
continue;
25062506
}
@@ -4538,9 +4538,9 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
45384538
return stmmac_tso_xmit(skb, dev);
45394539
}
45404540

4541-
if (priv->plat->est && priv->plat->est->enable &&
4542-
priv->plat->est->max_sdu[queue] &&
4543-
skb->len > priv->plat->est->max_sdu[queue]){
4541+
if (priv->est && priv->est->enable &&
4542+
priv->est->max_sdu[queue] &&
4543+
skb->len > priv->est->max_sdu[queue]){
45444544
priv->xstats.max_sdu_txq_drop[queue]++;
45454545
goto max_sdu_err;
45464546
}
@@ -4919,9 +4919,9 @@ static int stmmac_xdp_xmit_xdpf(struct stmmac_priv *priv, int queue,
49194919
if (stmmac_tx_avail(priv, queue) < STMMAC_TX_THRESH(priv))
49204920
return STMMAC_XDP_CONSUMED;
49214921

4922-
if (priv->plat->est && priv->plat->est->enable &&
4923-
priv->plat->est->max_sdu[queue] &&
4924-
xdpf->len > priv->plat->est->max_sdu[queue]) {
4922+
if (priv->est && priv->est->enable &&
4923+
priv->est->max_sdu[queue] &&
4924+
xdpf->len > priv->est->max_sdu[queue]) {
49254925
priv->xstats.max_sdu_txq_drop[queue]++;
49264926
return STMMAC_XDP_CONSUMED;
49274927
}

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ static int stmmac_adjust_time(struct ptp_clock_info *ptp, s64 delta)
6868
nsec = reminder;
6969

7070
/* If EST is enabled, disabled it before adjust ptp time. */
71-
if (priv->plat->est && priv->plat->est->enable) {
71+
if (priv->est && priv->est->enable) {
7272
est_rst = true;
73-
mutex_lock(&priv->plat->est->lock);
74-
priv->plat->est->enable = false;
75-
stmmac_est_configure(priv, priv, priv->plat->est,
73+
mutex_lock(&priv->est_lock);
74+
priv->est->enable = false;
75+
stmmac_est_configure(priv, priv, priv->est,
7676
priv->plat->clk_ptp_rate);
77-
mutex_unlock(&priv->plat->est->lock);
77+
mutex_unlock(&priv->est_lock);
7878
}
7979

8080
write_lock_irqsave(&priv->ptp_lock, flags);
@@ -87,24 +87,24 @@ static int stmmac_adjust_time(struct ptp_clock_info *ptp, s64 delta)
8787
ktime_t current_time_ns, basetime;
8888
u64 cycle_time;
8989

90-
mutex_lock(&priv->plat->est->lock);
90+
mutex_lock(&priv->est_lock);
9191
priv->ptp_clock_ops.gettime64(&priv->ptp_clock_ops, &current_time);
9292
current_time_ns = timespec64_to_ktime(current_time);
93-
time.tv_nsec = priv->plat->est->btr_reserve[0];
94-
time.tv_sec = priv->plat->est->btr_reserve[1];
93+
time.tv_nsec = priv->est->btr_reserve[0];
94+
time.tv_sec = priv->est->btr_reserve[1];
9595
basetime = timespec64_to_ktime(time);
96-
cycle_time = (u64)priv->plat->est->ctr[1] * NSEC_PER_SEC +
97-
priv->plat->est->ctr[0];
96+
cycle_time = (u64)priv->est->ctr[1] * NSEC_PER_SEC +
97+
priv->est->ctr[0];
9898
time = stmmac_calc_tas_basetime(basetime,
9999
current_time_ns,
100100
cycle_time);
101101

102-
priv->plat->est->btr[0] = (u32)time.tv_nsec;
103-
priv->plat->est->btr[1] = (u32)time.tv_sec;
104-
priv->plat->est->enable = true;
105-
ret = stmmac_est_configure(priv, priv, priv->plat->est,
102+
priv->est->btr[0] = (u32)time.tv_nsec;
103+
priv->est->btr[1] = (u32)time.tv_sec;
104+
priv->est->enable = true;
105+
ret = stmmac_est_configure(priv, priv, priv->est,
106106
priv->plat->clk_ptp_rate);
107-
mutex_unlock(&priv->plat->est->lock);
107+
mutex_unlock(&priv->est_lock);
108108
if (ret)
109109
netdev_err(priv->dev, "failed to configure EST\n");
110110
}

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,6 @@ struct timespec64 stmmac_calc_tas_basetime(ktime_t old_base_time,
918918
static void tc_taprio_map_maxsdu_txq(struct stmmac_priv *priv,
919919
struct tc_taprio_qopt_offload *qopt)
920920
{
921-
struct plat_stmmacenet_data *plat = priv->plat;
922921
u32 num_tc = qopt->mqprio.qopt.num_tc;
923922
u32 offset, count, i, j;
924923

@@ -933,15 +932,14 @@ static void tc_taprio_map_maxsdu_txq(struct stmmac_priv *priv,
933932
count = qopt->mqprio.qopt.count[i];
934933

935934
for (j = offset; j < offset + count; j++)
936-
plat->est->max_sdu[j] = qopt->max_sdu[i] + ETH_HLEN - ETH_TLEN;
935+
priv->est->max_sdu[j] = qopt->max_sdu[i] + ETH_HLEN - ETH_TLEN;
937936
}
938937
}
939938

940939
static int tc_taprio_configure(struct stmmac_priv *priv,
941940
struct tc_taprio_qopt_offload *qopt)
942941
{
943942
u32 size, wid = priv->dma_cap.estwid, dep = priv->dma_cap.estdep;
944-
struct plat_stmmacenet_data *plat = priv->plat;
945943
struct timespec64 time, current_time, qopt_time;
946944
ktime_t current_time_ns;
947945
bool fpe = false;
@@ -998,23 +996,25 @@ static int tc_taprio_configure(struct stmmac_priv *priv,
998996
if (qopt->cycle_time_extension >= BIT(wid + 7))
999997
return -ERANGE;
1000998

1001-
if (!plat->est) {
1002-
plat->est = devm_kzalloc(priv->device, sizeof(*plat->est),
999+
if (!priv->est) {
1000+
priv->est = devm_kzalloc(priv->device, sizeof(*priv->est),
10031001
GFP_KERNEL);
1004-
if (!plat->est)
1002+
if (!priv->est)
10051003
return -ENOMEM;
10061004

1007-
mutex_init(&priv->plat->est->lock);
1005+
mutex_init(&priv->est_lock);
10081006
} else {
1009-
memset(plat->est, 0, sizeof(*plat->est));
1007+
mutex_lock(&priv->est_lock);
1008+
memset(priv->est, 0, sizeof(*priv->est));
1009+
mutex_unlock(&priv->est_lock);
10101010
}
10111011

10121012
size = qopt->num_entries;
10131013

1014-
mutex_lock(&priv->plat->est->lock);
1015-
priv->plat->est->gcl_size = size;
1016-
priv->plat->est->enable = qopt->cmd == TAPRIO_CMD_REPLACE;
1017-
mutex_unlock(&priv->plat->est->lock);
1014+
mutex_lock(&priv->est_lock);
1015+
priv->est->gcl_size = size;
1016+
priv->est->enable = qopt->cmd == TAPRIO_CMD_REPLACE;
1017+
mutex_unlock(&priv->est_lock);
10181018

10191019
for (i = 0; i < size; i++) {
10201020
s64 delta_ns = qopt->entries[i].interval;
@@ -1042,33 +1042,33 @@ static int tc_taprio_configure(struct stmmac_priv *priv,
10421042
return -EOPNOTSUPP;
10431043
}
10441044

1045-
priv->plat->est->gcl[i] = delta_ns | (gates << wid);
1045+
priv->est->gcl[i] = delta_ns | (gates << wid);
10461046
}
10471047

1048-
mutex_lock(&priv->plat->est->lock);
1048+
mutex_lock(&priv->est_lock);
10491049
/* Adjust for real system time */
10501050
priv->ptp_clock_ops.gettime64(&priv->ptp_clock_ops, &current_time);
10511051
current_time_ns = timespec64_to_ktime(current_time);
10521052
time = stmmac_calc_tas_basetime(qopt->base_time, current_time_ns,
10531053
qopt->cycle_time);
10541054

1055-
priv->plat->est->btr[0] = (u32)time.tv_nsec;
1056-
priv->plat->est->btr[1] = (u32)time.tv_sec;
1055+
priv->est->btr[0] = (u32)time.tv_nsec;
1056+
priv->est->btr[1] = (u32)time.tv_sec;
10571057

10581058
qopt_time = ktime_to_timespec64(qopt->base_time);
1059-
priv->plat->est->btr_reserve[0] = (u32)qopt_time.tv_nsec;
1060-
priv->plat->est->btr_reserve[1] = (u32)qopt_time.tv_sec;
1059+
priv->est->btr_reserve[0] = (u32)qopt_time.tv_nsec;
1060+
priv->est->btr_reserve[1] = (u32)qopt_time.tv_sec;
10611061

10621062
ctr = qopt->cycle_time;
1063-
priv->plat->est->ctr[0] = do_div(ctr, NSEC_PER_SEC);
1064-
priv->plat->est->ctr[1] = (u32)ctr;
1063+
priv->est->ctr[0] = do_div(ctr, NSEC_PER_SEC);
1064+
priv->est->ctr[1] = (u32)ctr;
10651065

1066-
priv->plat->est->ter = qopt->cycle_time_extension;
1066+
priv->est->ter = qopt->cycle_time_extension;
10671067

10681068
tc_taprio_map_maxsdu_txq(priv, qopt);
10691069

10701070
if (fpe && !priv->dma_cap.fpesel) {
1071-
mutex_unlock(&priv->plat->est->lock);
1071+
mutex_unlock(&priv->est_lock);
10721072
return -EOPNOTSUPP;
10731073
}
10741074

@@ -1077,9 +1077,9 @@ static int tc_taprio_configure(struct stmmac_priv *priv,
10771077
*/
10781078
priv->plat->fpe_cfg->enable = fpe;
10791079

1080-
ret = stmmac_est_configure(priv, priv, priv->plat->est,
1080+
ret = stmmac_est_configure(priv, priv, priv->est,
10811081
priv->plat->clk_ptp_rate);
1082-
mutex_unlock(&priv->plat->est->lock);
1082+
mutex_unlock(&priv->est_lock);
10831083
if (ret) {
10841084
netdev_err(priv->dev, "failed to configure EST\n");
10851085
goto disable;
@@ -1095,17 +1095,17 @@ static int tc_taprio_configure(struct stmmac_priv *priv,
10951095
return 0;
10961096

10971097
disable:
1098-
if (priv->plat->est) {
1099-
mutex_lock(&priv->plat->est->lock);
1100-
priv->plat->est->enable = false;
1101-
stmmac_est_configure(priv, priv, priv->plat->est,
1098+
if (priv->est) {
1099+
mutex_lock(&priv->est_lock);
1100+
priv->est->enable = false;
1101+
stmmac_est_configure(priv, priv, priv->est,
11021102
priv->plat->clk_ptp_rate);
11031103
/* Reset taprio status */
11041104
for (i = 0; i < priv->plat->tx_queues_to_use; i++) {
11051105
priv->xstats.max_sdu_txq_drop[i] = 0;
11061106
priv->xstats.mtl_est_txq_hlbf[i] = 0;
11071107
}
1108-
mutex_unlock(&priv->plat->est->lock);
1108+
mutex_unlock(&priv->est_lock);
11091109
}
11101110

11111111
priv->plat->fpe_cfg->enable = false;

include/linux/stmmac.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,6 @@ struct stmmac_axi {
115115
bool axi_rb;
116116
};
117117

118-
#define EST_GCL 1024
119-
struct stmmac_est {
120-
struct mutex lock;
121-
int enable;
122-
u32 btr_reserve[2];
123-
u32 btr_offset[2];
124-
u32 btr[2];
125-
u32 ctr[2];
126-
u32 ter;
127-
u32 gcl_unaligned[EST_GCL];
128-
u32 gcl[EST_GCL];
129-
u32 gcl_size;
130-
u32 max_sdu[MTL_MAX_TX_QUEUES];
131-
};
132-
133118
struct stmmac_rxq_cfg {
134119
u8 mode_to_use;
135120
u32 chan;
@@ -246,7 +231,6 @@ struct plat_stmmacenet_data {
246231
struct fwnode_handle *port_node;
247232
struct device_node *mdio_node;
248233
struct stmmac_dma_cfg *dma_cfg;
249-
struct stmmac_est *est;
250234
struct stmmac_fpe_cfg *fpe_cfg;
251235
struct stmmac_safety_feature_cfg *safety_feat_cfg;
252236
int clk_csr;

0 commit comments

Comments
 (0)