From patchwork Wed Apr 26 23:38:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iyappan Subramanian X-Patchwork-Id: 9702197 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 56485601D3 for ; Wed, 26 Apr 2017 23:37:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4679628399 for ; Wed, 26 Apr 2017 23:37:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B233284DB; Wed, 26 Apr 2017 23:37:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B668B28399 for ; Wed, 26 Apr 2017 23:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=sFCRbCO7c0tJyNTm2nOjkDCofRXJn8BNGbVvztaK+wo=; b=caBRO2nIkW63zg7UBp0qYivjnv bp3wCLre4yZXxbmL4gFoADrm/r84HpWB3G6qrFWJs+ddRnP+xaAV9DOkKmNuDKPyM5nEPavc9NJM3 eLFvBuNC+n4Uw1nVIOWqjewZumbJKOnVH92piuDpmvy3F0ii7kM2jcMhV4ICT5ELRK37mBusA1Htb tVGq5GEor1e3UFxAOOp5NKzFDBgRtBCCtaw7bQr9uXoEEyAY++C8FoEgxSo/7R8XMdqLbOi1/JG2c BiTm4HYBPAlch45YQTdnE7oaU4K8HAIRajvhZogAJhKPBFQpBkq1x+ZMv2U2fpqacc0eYqb06IDL9 mbrlKH8w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d3WUl-0004Tx-3d; Wed, 26 Apr 2017 23:37:15 +0000 Received: from mail-pf0-x230.google.com ([2607:f8b0:400e:c00::230]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d3WUU-0004DA-JA for linux-arm-kernel@lists.infradead.org; Wed, 26 Apr 2017 23:37:02 +0000 Received: by mail-pf0-x230.google.com with SMTP id 194so8268728pfv.3 for ; Wed, 26 Apr 2017 16:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apm.com; s=apm; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IfYyetepg3iUrcd121lh3Rg5DQ6u5VuVodylC2sS+5M=; b=gy+yuwTXWu7tiORKhbtLj+cxokps3gBkFgEywXnRp7tt2Sph/LUbpCNv7g3I53mcuA qM+2sMAdwip0JAzvWfBJqdwa9piaNAZZn18LilY04RoTPGjDBjgB1XceUAtknStDqWKk nU9B1xW3pbc3WzwSROnfCaAQlMtVEKGE+OQP8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IfYyetepg3iUrcd121lh3Rg5DQ6u5VuVodylC2sS+5M=; b=hxFocgM4qeA/1Pguv20eRfwxJgX0JhrJKVUvgcrHRI49xP+gLw2R327RAqpF9p1VJy kJtxcKPplSGK9mFsJeBo6i3psn0+vFixasoHBcAPXALs3RkofFgRuv22Xi62C+5BQIdf 58W9FSBdOXrPDdabcg+RCi4Yxx+feLmSqGkuNkKuyIJTi/z7wVz8kcIFqkSItVIGlNNR TCeUZILKrp72qgqzOOGw5DAOW6cD65qCh1HbeGQ1KxkE5PYwNr21F9XjKfYdP2hcvhc0 YufGnVudluxFGmSXwMdtjZDFhs0Z1gPcozrAEUOK6e0AEdR5zrsBPU3zqTulrVminkUU XAYA== X-Gm-Message-State: AN3rC/5AibIx7h5w2TPTKChXweB1nIF4tk4RLCEgXwgraYxMyDqYYwy3 1dzK9AtXvEeQ3YUw X-Received: by 10.98.60.134 with SMTP id b6mr2488183pfk.19.1493249794621; Wed, 26 Apr 2017 16:36:34 -0700 (PDT) Received: from isubrama-dev.amcc.com ([206.80.4.98]) by smtp.gmail.com with ESMTPSA id i30sm626700pgn.39.2017.04.26.16.36.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Apr 2017 16:36:34 -0700 (PDT) From: Iyappan Subramanian To: davem@davemloft.net, netdev@vger.kernel.org Subject: [PATCH net-next 1/9] drivers: net: xgene: Protect indirect MAC access Date: Wed, 26 Apr 2017 16:38:47 -0700 Message-Id: <1493249935-30759-2-git-send-email-isubramanian@apm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493249935-30759-1-git-send-email-isubramanian@apm.com> References: <1493249935-30759-1-git-send-email-isubramanian@apm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170426_163658_673142_4A61E1DE X-CRM114-Status: GOOD ( 13.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Quan Nguyen , patches@apm.com, linux-arm-kernel@lists.infradead.org, Iyappan Subramanian MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Quan Nguyen This patch adds lock to protect indirect mac access sequence. Signed-off-by: Quan Nguyen Signed-off-by: Iyappan Subramanian --- drivers/net/ethernet/apm/xgene/xgene_enet_hw.c | 2 ++ drivers/net/ethernet/apm/xgene/xgene_enet_main.c | 1 + drivers/net/ethernet/apm/xgene/xgene_enet_main.h | 1 + drivers/net/ethernet/apm/xgene/xgene_enet_sgmac.c | 7 ++++++- drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c | 2 ++ 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c index 2a835e0..3697ba7 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_hw.c @@ -365,9 +365,11 @@ static void xgene_enet_rd_mcx_mac(struct xgene_enet_pdata *pdata, cmd = pdata->mcx_mac_addr + MAC_COMMAND_REG_OFFSET; cmd_done = pdata->mcx_mac_addr + MAC_COMMAND_DONE_REG_OFFSET; + spin_lock(&pdata->mac_lock); if (!xgene_enet_rd_indirect(addr, rd, cmd, cmd_done, rd_addr, rd_data)) netdev_err(pdata->ndev, "MCX mac read failed, addr: %04x\n", rd_addr); + spin_unlock(&pdata->mac_lock); } static void xgene_gmac_set_mac_addr(struct xgene_enet_pdata *pdata) diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c index 5f37ed3..9a28ac3 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.c @@ -2055,6 +2055,7 @@ static int xgene_enet_probe(struct platform_device *pdev) goto err; xgene_enet_setup_ops(pdata); + spin_lock_init(&pdata->mac_lock); if (pdata->phy_mode == PHY_INTERFACE_MODE_XGMII) { ndev->features |= NETIF_F_TSO | NETIF_F_RXCSUM; diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_main.h b/drivers/net/ethernet/apm/xgene/xgene_enet_main.h index 0d4be24..827b33d 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_main.h +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_main.h @@ -221,6 +221,7 @@ struct xgene_enet_pdata { struct xgene_enet_cle cle; struct rtnl_link_stats64 stats; const struct xgene_mac_ops *mac_ops; + spinlock_t mac_lock; /* mac lock */ const struct xgene_port_ops *port_ops; struct xgene_ring_ops *ring_ops; const struct xgene_cle_ops *cle_ops; diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_sgmac.c b/drivers/net/ethernet/apm/xgene/xgene_enet_sgmac.c index a8e063b..4dd41f5 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_sgmac.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_sgmac.c @@ -130,6 +130,7 @@ static u32 xgene_enet_rd_indirect(struct xgene_indirect_ctl *ctl, u32 rd_addr) static u32 xgene_enet_rd_mac(struct xgene_enet_pdata *p, u32 rd_addr) { + u32 val; struct xgene_indirect_ctl ctl = { .addr = p->mcx_mac_addr + MAC_ADDR_REG_OFFSET, .ctl = p->mcx_mac_addr + MAC_READ_REG_OFFSET, @@ -137,7 +138,11 @@ static u32 xgene_enet_rd_mac(struct xgene_enet_pdata *p, u32 rd_addr) .cmd_done = p->mcx_mac_addr + MAC_COMMAND_DONE_REG_OFFSET }; - return xgene_enet_rd_indirect(&ctl, rd_addr); + spin_lock(&p->mac_lock); + val = xgene_enet_rd_indirect(&ctl, rd_addr); + spin_unlock(&p->mac_lock); + + return val; } static int xgene_enet_ecc_init(struct xgene_enet_pdata *p) diff --git a/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c b/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c index 423240c..9a2d0ca 100644 --- a/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c +++ b/drivers/net/ethernet/apm/xgene/xgene_enet_xgmac.c @@ -158,9 +158,11 @@ static void xgene_enet_rd_mac(struct xgene_enet_pdata *pdata, cmd = pdata->mcx_mac_addr + MAC_COMMAND_REG_OFFSET; cmd_done = pdata->mcx_mac_addr + MAC_COMMAND_DONE_REG_OFFSET; + spin_lock(&pdata->mac_lock); if (!xgene_enet_rd_indirect(addr, rd, cmd, cmd_done, rd_addr, rd_data)) netdev_err(pdata->ndev, "MCX mac read failed, addr: %04x\n", rd_addr); + spin_unlock(&pdata->mac_lock); } static bool xgene_enet_rd_pcs(struct xgene_enet_pdata *pdata,