Skip to content

Commit b2aae65

Browse files
Xiaoliang Yangdavem330
Xiaoliang Yang
authored andcommitted
net: stmmac: add mutex lock to protect est parameters
Add a mutex lock to protect est structure parameters so that the EST parameters can be updated by other threads. Signed-off-by: Xiaoliang Yang <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 81c52c4 commit b2aae65

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,14 +796,18 @@ static int tc_setup_taprio(struct stmmac_priv *priv,
796796
GFP_KERNEL);
797797
if (!plat->est)
798798
return -ENOMEM;
799+
800+
mutex_init(&priv->plat->est->lock);
799801
} else {
800802
memset(plat->est, 0, sizeof(*plat->est));
801803
}
802804

803805
size = qopt->num_entries;
804806

807+
mutex_lock(&priv->plat->est->lock);
805808
priv->plat->est->gcl_size = size;
806809
priv->plat->est->enable = qopt->enable;
810+
mutex_unlock(&priv->plat->est->lock);
807811

808812
for (i = 0; i < size; i++) {
809813
s64 delta_ns = qopt->entries[i].interval;
@@ -834,6 +838,7 @@ static int tc_setup_taprio(struct stmmac_priv *priv,
834838
priv->plat->est->gcl[i] = delta_ns | (gates << wid);
835839
}
836840

841+
mutex_lock(&priv->plat->est->lock);
837842
/* Adjust for real system time */
838843
priv->ptp_clock_ops.gettime64(&priv->ptp_clock_ops, &current_time);
839844
current_time_ns = timespec64_to_ktime(current_time);
@@ -847,8 +852,10 @@ static int tc_setup_taprio(struct stmmac_priv *priv,
847852
priv->plat->est->ctr[0] = do_div(ctr, NSEC_PER_SEC);
848853
priv->plat->est->ctr[1] = (u32)ctr;
849854

850-
if (fpe && !priv->dma_cap.fpesel)
855+
if (fpe && !priv->dma_cap.fpesel) {
856+
mutex_unlock(&priv->plat->est->lock);
851857
return -EOPNOTSUPP;
858+
}
852859

853860
/* Actual FPE register configuration will be done after FPE handshake
854861
* is success.
@@ -857,6 +864,7 @@ static int tc_setup_taprio(struct stmmac_priv *priv,
857864

858865
ret = stmmac_est_configure(priv, priv->ioaddr, priv->plat->est,
859866
priv->plat->clk_ptp_rate);
867+
mutex_unlock(&priv->plat->est->lock);
860868
if (ret) {
861869
netdev_err(priv->dev, "failed to configure EST\n");
862870
goto disable;
@@ -872,9 +880,11 @@ static int tc_setup_taprio(struct stmmac_priv *priv,
872880
return 0;
873881

874882
disable:
883+
mutex_lock(&priv->plat->est->lock);
875884
priv->plat->est->enable = false;
876885
stmmac_est_configure(priv, priv->ioaddr, priv->plat->est,
877886
priv->plat->clk_ptp_rate);
887+
mutex_unlock(&priv->plat->est->lock);
878888

879889
priv->plat->fpe_cfg->enable = false;
880890
stmmac_fpe_configure(priv, priv->ioaddr,

include/linux/stmmac.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ struct stmmac_axi {
115115

116116
#define EST_GCL 1024
117117
struct stmmac_est {
118+
struct mutex lock;
118119
int enable;
119120
u32 btr_offset[2];
120121
u32 btr[2];

0 commit comments

Comments
 (0)