From patchwork Mon Jun 13 03:42:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 12878982 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AD1B9C43334 for ; Mon, 13 Jun 2022 03:46:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=L3/u1r4EE6MJtLcmYWXFcHgts+Lm+YH0rudbI/vhUBE=; b=2SBEC7oLBnfA7i PKkVpUMSn5Vpt0oF8NGDlgyqzOi6mo8ppQqD4y+df9ZQNZKPu+9iCBZsji4Plfj6nbh8yMLNkf83+ RBFhyI4ORRfkXhPyz241S6GxDgmCQegQuP+uclQkk7jvuClgV2B0ddXQlSUGtE39eIjfeyla9A7qF b4qdkmziZJw/IoTiR4jX+OVaa1U/tOBldOI5E/plbyBgehmPSwF00R2/BHpmw75nqRcZlq/FPHmCP DjhvRHA7/IMORYm9F50VEXZExFqZcy4uRR+7bbtjmjzpqJyS7lhCjfiIkFtCsJ/J96d4a007+ceT7 BBHBNfHF+wQh7vG5GNWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0b1M-001B5c-8O; Mon, 13 Jun 2022 03:45:44 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o0b1C-001B1S-Si for linux-arm-kernel@lists.infradead.org; Mon, 13 Jun 2022 03:45:36 +0000 Received: by mail-pg1-x52d.google.com with SMTP id h192so4473648pgc.4 for ; Sun, 12 Jun 2022 20:45:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8e2+YdysEt3cn+fJPAORULNwZ8xIMjVsBm+5OObBefE=; b=bmBOhXaySGZJ5lfdkQdmsgDmh/d1TQBw/v3iO5tVkffiuxC8Q9GZBHGIyCpgHAhtlw ljgdT+uQs19OqDfby2/haMNKUMYDuzBHkL/MKBTGQ6nQN5XguIuTfA2L6Vd8H6gryb6d IaYIOcMZs4aVdiKukALd/81CElJmbmVyQB2kWjSsfH7fytaTcxV3WVGwOQe6lLC2BFya A1k7FKuUGk0sdOxhG0cWkHJQdRJ1F8ngB9iHB1Dp5Gg0rcldN2EqkTH1P2/5L+rvDi/8 dHENDGoL1863UKuntOH0YMsuJsrVSR99FTvsXzSiUMphJl+mVfQpDY34r3Ey+6//GO60 dPjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8e2+YdysEt3cn+fJPAORULNwZ8xIMjVsBm+5OObBefE=; b=Ai1lzmd4TwLZpek15xk71n624MC9hfnQvHabM00tYmM/CuBvJo7Pc2PneN4og370zL 8GQ+pOZI4eHW5rpHr0yTIGQ9n2yqNr0fE+0Wg30Rd6aETxS7QzPI1AthBiveIHLZ7cmq haz/7gNd0Zh/YWHb4m+b9RnMV7C9AclcRF/z/xkuayuNMxoj6BAeFGIbFGqPRzbY3xbt uJmcAcZNONofLZtnlQqxGzAmiF/+WLWmlO7giphzyME3N3ZCsWdtXwRPjGAXglqqPXm9 exl9f/FjMOelAH7BgNE8MBvERgGICeFjojyZZLeC28UQG9mw8QQmwoFP8eqCMRr2Io29 55oA== X-Gm-Message-State: AOAM530hasLzWFqxXbTLAuLZ4Z5FIX0denJl94pGbfA0d391BHYHnfhK AAyeEB4AAo81PiH9Q/hj0g8pIw== X-Google-Smtp-Source: ABdhPJyrFR307Y+dPHCP4+uz/MnF3mq88+n/o0ixCRCgEvTuOqXscRdkf4Kd0jb7G+Kqn7RD/3br9A== X-Received: by 2002:a05:6a00:14cb:b0:51c:3f31:b60e with SMTP id w11-20020a056a0014cb00b0051c3f31b60emr31241313pfu.27.1655091933165; Sun, 12 Jun 2022 20:45:33 -0700 (PDT) Received: from archlinux.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id u13-20020a170902714d00b0015e8d4eb1dfsm3810769plm.41.2022.06.12.20.45.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jun 2022 20:45:32 -0700 (PDT) From: Andy Chiu To: radhey.shyam.pandey@xilinx.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, michal.simek@xilinx.com, netdev@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, Andy Chiu , Max Hsu Subject: [PATCH net-next 1/2] net: axienet: make the 64b addresable DMA depends on 64b archectures Date: Mon, 13 Jun 2022 11:42:01 +0800 Message-Id: <20220613034202.3777248-2-andy.chiu@sifive.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220613034202.3777248-1-andy.chiu@sifive.com> References: <20220613034202.3777248-1-andy.chiu@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220612_204534_968041_2FCAA7EB X-CRM114-Status: GOOD ( 19.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently it is not safe to config the IP as 64-bit addressable on 32-bit archectures, which cannot perform a double-word store on its descriptor pointers. The pointer is 64-bit wide if the IP is configured as 64-bit, and the device would process the partially updated pointer on some states if the pointer was updated via two store-words. To prevent such condition, we force a probe fail if we discover that the IP has 64-bit capability but it is not running on a 64-Bit kernel. This is a series of patch (1/2). The next patch must be applied in order to make 64b DMA safe on 64b archectures. Signed-off-by: Andy Chiu Reported-by: Max Hsu Reviewed-by: Greentime Hu --- drivers/net/ethernet/xilinx/xilinx_axienet.h | 36 +++++++++++++++++++ .../net/ethernet/xilinx/xilinx_axienet_main.c | 28 +++------------ 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet.h b/drivers/net/ethernet/xilinx/xilinx_axienet.h index 4225efbeda3d..6c95676ba172 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet.h +++ b/drivers/net/ethernet/xilinx/xilinx_axienet.h @@ -547,6 +547,42 @@ static inline void axienet_iow(struct axienet_local *lp, off_t offset, iowrite32(value, lp->regs + offset); } +/** + * axienet_dma_out32 - Memory mapped Axi DMA register write. + * @lp: Pointer to axienet local structure + * @reg: Address offset from the base address of the Axi DMA core + * @value: Value to be written into the Axi DMA register + * + * This function writes the desired value into the corresponding Axi DMA + * register. + */ + +static inline void axienet_dma_out32(struct axienet_local *lp, + off_t reg, u32 value) +{ + iowrite32(value, lp->dma_regs + reg); +} + +#ifdef CONFIG_64BIT +static void axienet_dma_out_addr(struct axienet_local *lp, off_t reg, + dma_addr_t addr) +{ + axienet_dma_out32(lp, reg, lower_32_bits(addr)); + + if (lp->features & XAE_FEATURE_DMA_64BIT) + axienet_dma_out32(lp, reg + 4, upper_32_bits(addr)); +} + +#else /* CONFIG_64BIT */ + +static void axienet_dma_out_addr(struct axienet_local *lp, off_t reg, + dma_addr_t addr) +{ + axienet_dma_out32(lp, reg, lower_32_bits(addr)); +} + +#endif /* CONFIG_64BIT */ + /* Function prototypes visible in xilinx_axienet_mdio.c for other files */ int axienet_mdio_enable(struct axienet_local *lp); void axienet_mdio_disable(struct axienet_local *lp); diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 93c9f305bba4..fa7bcd2c1892 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -133,30 +133,6 @@ static inline u32 axienet_dma_in32(struct axienet_local *lp, off_t reg) return ioread32(lp->dma_regs + reg); } -/** - * axienet_dma_out32 - Memory mapped Axi DMA register write. - * @lp: Pointer to axienet local structure - * @reg: Address offset from the base address of the Axi DMA core - * @value: Value to be written into the Axi DMA register - * - * This function writes the desired value into the corresponding Axi DMA - * register. - */ -static inline void axienet_dma_out32(struct axienet_local *lp, - off_t reg, u32 value) -{ - iowrite32(value, lp->dma_regs + reg); -} - -static void axienet_dma_out_addr(struct axienet_local *lp, off_t reg, - dma_addr_t addr) -{ - axienet_dma_out32(lp, reg, lower_32_bits(addr)); - - if (lp->features & XAE_FEATURE_DMA_64BIT) - axienet_dma_out32(lp, reg + 4, upper_32_bits(addr)); -} - static void desc_set_phys_addr(struct axienet_local *lp, dma_addr_t addr, struct axidma_bd *desc) { @@ -2061,6 +2037,10 @@ static int axienet_probe(struct platform_device *pdev) iowrite32(0x0, desc); } } + if (!IS_ENABLED(CONFIG_64BIT) && lp->features & XAE_FEATURE_DMA_64BIT) { + dev_err(&pdev->dev, "64-bit addressable DMA is not compatible with 32-bit archecture\n"); + goto cleanup_clk; + } ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(addr_width)); if (ret) {