Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3683227pxv; Mon, 5 Jul 2021 03:17:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwcZcD5p//AVf+53wGvUYrH/LUwi70Ck2JuYZWBgNGo6zCBK1hMa/cuXixhbGV6ijj8C/xo X-Received: by 2002:a6b:794b:: with SMTP id j11mr11226545iop.129.1625480258975; Mon, 05 Jul 2021 03:17:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625480258; cv=none; d=google.com; s=arc-20160816; b=EY6vqepXSXi7hgFtW0N3LeKDt3efvYDxtL5earQ14CtGuTxilRuLVq+9Iby0dVo3V8 Z2ilx1WN3UmiczkShCqIJfe0BKWGtKW2UOo9uWJaF/iaNr5yEeixD0No1/ZRQpaXT3eT S3nFzmFlHWrnJbTGXpDC9b9+VtymNeuWzr0E4MzxgdqHa0rk+3i1hBW9cAFxNqxvman5 wG/t8E/xQC+8rxLcum6B//YWtG8qfg/F7egrA8pcPhv5h8E64L52vKieBGFF8Y4/fiZw 6RA7MtMTc2r3eFP4MhXhAoxATKtb7qaWIgun17Wix5Mp1IkYaa3cg3Exa8BOk0fbMe3w dwEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=AGyDkGZxHhIpiZ39zCLAXUHbwDAy75Ax61NT01hCgfI=; b=ygX9kEDb2onhFuj4IQiRiXwPkWnU2hF9+pE5Z+S0eB+ZK5pCK8V3ldsJuM0tnxhrwk fTUEpa4ca/ffFWcNeIujXGGoa4xlbBVoCb2rAZ5iECjF7upq9SiYYQeFx46zk53chr+5 reW3yORNQmGIlbMGKwdRas53zQVwAc+QS8dzACN7pM3Mb6jp67xN1McFdXY5MYwWXf9t /A2hYeWr3yLRVik0H6pWQwuUjdK0takT/PnfkeZC/wTcp40h3xE3Qg4GBdZdwxSuuBBQ sXijeZKOIGa1Osw+gBmnnN9lXF76itrpjKbbJcU7Ax0/vBBpkSyIrxHuQONoRLoQomIM U9Kw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k11si15805168jav.18.2021.07.05.03.17.28; Mon, 05 Jul 2021 03:17:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231171AbhGEKSx (ORCPT + 99 others); Mon, 5 Jul 2021 06:18:53 -0400 Received: from inva020.nxp.com ([92.121.34.13]:33304 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231150AbhGEKSx (ORCPT ); Mon, 5 Jul 2021 06:18:53 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 4C0381A04B3; Mon, 5 Jul 2021 12:16:15 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 1043D1A16BD; Mon, 5 Jul 2021 12:16:15 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id DB0A7183AC98; Mon, 5 Jul 2021 18:16:12 +0800 (+08) From: Xiaoliang Yang To: davem@davemloft.net, joabreu@synopsys.com, kuba@kernel.org, alexandre.torgue@st.com, peppe.cavallaro@st.com, mcoquelin.stm32@gmail.com, netdev@vger.kernel.org Cc: boon.leong.ong@intel.com, weifeng.voon@intel.com, vee.khee.wong@intel.com, tee.min.tan@intel.com, mohammad.athari.ismail@intel.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, leoyang.li@nxp.com, qiangqing.zhang@nxp.com, rui.sousa@nxp.com, xiaoliang.yang_1@nxp.com Subject: [PATCH v2 net-next 2/3] net: stmmac: add mutex lock to protect est parameters Date: Mon, 5 Jul 2021 18:26:54 +0800 Message-Id: <20210705102655.6280-3-xiaoliang.yang_1@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210705102655.6280-1-xiaoliang.yang_1@nxp.com> References: <20210705102655.6280-1-xiaoliang.yang_1@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 12 +++++++++++- include/linux/stmmac.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c index d7d448c5a72b..b2a276aac724 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c @@ -798,14 +798,18 @@ static int tc_setup_taprio(struct stmmac_priv *priv, GFP_KERNEL); if (!plat->est) return -ENOMEM; + + mutex_init(&priv->plat->est->lock); } else { memset(plat->est, 0, sizeof(*plat->est)); } size = qopt->num_entries; + mutex_lock(&priv->plat->est->lock); priv->plat->est->gcl_size = size; priv->plat->est->enable = qopt->enable; + mutex_unlock(&priv->plat->est->lock); for (i = 0; i < size; i++) { s64 delta_ns = qopt->entries[i].interval; @@ -836,6 +840,7 @@ static int tc_setup_taprio(struct stmmac_priv *priv, priv->plat->est->gcl[i] = delta_ns | (gates << wid); } + mutex_lock(&priv->plat->est->lock); /* Adjust for real system time */ priv->ptp_clock_ops.gettime64(&priv->ptp_clock_ops, ¤t_time); current_time_ns = timespec64_to_ktime(current_time); @@ -849,8 +854,10 @@ static int tc_setup_taprio(struct stmmac_priv *priv, priv->plat->est->ctr[0] = do_div(ctr, NSEC_PER_SEC); priv->plat->est->ctr[1] = (u32)ctr; - if (fpe && !priv->dma_cap.fpesel) + if (fpe && !priv->dma_cap.fpesel) { + mutex_unlock(&priv->plat->est->lock); return -EOPNOTSUPP; + } /* Actual FPE register configuration will be done after FPE handshake * is success. @@ -859,6 +866,7 @@ static int tc_setup_taprio(struct stmmac_priv *priv, ret = stmmac_est_configure(priv, priv->ioaddr, priv->plat->est, priv->plat->clk_ptp_rate); + mutex_unlock(&priv->plat->est->lock); if (ret) { netdev_err(priv->dev, "failed to configure EST\n"); goto disable; @@ -874,9 +882,11 @@ static int tc_setup_taprio(struct stmmac_priv *priv, return 0; disable: + mutex_lock(&priv->plat->est->lock); priv->plat->est->enable = false; stmmac_est_configure(priv, priv->ioaddr, priv->plat->est, priv->plat->clk_ptp_rate); + mutex_unlock(&priv->plat->est->lock); priv->plat->fpe_cfg->enable = false; stmmac_fpe_configure(priv, priv->ioaddr, diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index e14a12df381b..c38b65aaf8c2 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -115,6 +115,7 @@ struct stmmac_axi { #define EST_GCL 1024 struct stmmac_est { + struct mutex lock; int enable; u32 btr_offset[2]; u32 btr[2]; -- 2.17.1