Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3542763yba; Mon, 8 Apr 2019 22:50:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqycVDk/d7qyWrlbirbWaFeHlDA3/Ozip18cOXGcGVXkZ/YncPJxJWDzvtFalyV8RV4tcNgq X-Received: by 2002:aa7:9151:: with SMTP id 17mr34543687pfi.192.1554789018789; Mon, 08 Apr 2019 22:50:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554789018; cv=none; d=google.com; s=arc-20160816; b=IafscUq+sYFPK6yIG9TgHnLEHn2/GyYlkGTWtzY9RWLUVOTFJpSaz7/YEfQbV3K26V 4LX+ICoyeUO2LLR6iGZNwNANqAWePjlPyJtSWjRJVAD3SsjilROL3JGA9DuACEann6WF VrY5iZD9CLhUpjmyRUvR6NRuOl3KOGnPu8UsauLcARw/QYQVtj6llh4emm8K5znoCHjL TiUc8KJf2uI/GfPJzAmKWvxJ/CsfphdPsHrSen6edDAdKnt0+SxrloG0FSYCM5eZ1nNK 3iC4icDmC+MPekkU/AVbi1HEopUMeTW2/UPz8UJw7UpUpN8M7ltt4Qka230a4q8IemTh JgOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=pR4map+jr+xRVqsEtYIgPz8nukNAcJpOSexB1JOSe9M=; b=z7L3i1ik5BzFqTNiVRePxSH4KYE0o8uHnTKrIJpshagJ1YkNhMwkXylLHS2LKkXIn7 jKvxsJURK04pZfNIH12n31TtTj+KjodM/Zlo27IdMl11iSKUXvrdkWLjqXvj6g6MUqsp l8vwam3SIOogBKT+ZYP3yNUe3SOGaCkjZOUb0I3HWwVo0sa5olAzv7Xf4DSIlzvO+3rI tGEit9Dp6xjY0P7WmP9IYp846llYl0OIe6M5SMVS26QTF+S181zQdpmxE6CYwpdtiWEn L8pMNzqRoE7w3g+3bUX9ApNr4zgpj8R4ngea1kvFZOAHqGLprtxGloUFMN+EuSRFsS2c Yb6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si7684326pgq.350.2019.04.08.22.50.02; Mon, 08 Apr 2019 22:50:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727359AbfDIFsO (ORCPT + 99 others); Tue, 9 Apr 2019 01:48:14 -0400 Received: from out1.zte.com.cn ([202.103.147.172]:41542 "EHLO mxct.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726535AbfDIFsO (ORCPT ); Tue, 9 Apr 2019 01:48:14 -0400 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 2D51645D417A2F6FA42D; Tue, 9 Apr 2019 13:48:11 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id x395m5Fc046077; Tue, 9 Apr 2019 13:48:05 +0800 (GMT-8) (envelope-from wen.yang99@zte.com.cn) Received: from fox-host8.localdomain ([10.74.120.8]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2019040913482107-7975996 ; Tue, 9 Apr 2019 13:48:21 +0800 From: Wen Yang To: linux-kernel@vger.kernel.org Cc: wang.yi59@zte.com.cn, Wen Yang , Anirudha Sarangi , John Linn , "David S. Miller" , Michal Simek , Markus Elfring , netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] net: xilinx: add a helper function for axienet_probe Date: Tue, 9 Apr 2019 13:48:00 +0800 Message-Id: <1554788881-22647-1-git-send-email-wen.yang99@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2019-04-09 13:48:21, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2019-04-09 13:48:03, Serialize complete at 2019-04-09 13:48:03 X-MAIL: mse01.zte.com.cn x395m5Fc046077 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The "Find DMA Node, Map DMA Register, and Decode DMA IRQ" code snippets in Axienet_Probe are independent. Tidy up axienet_probe a little by factoring these out into a helper function. Signed-off-by: Wen Yang Reported-by: Markus Elfring Cc: Anirudha Sarangi Cc: John Linn Cc: "David S. Miller" Cc: Michal Simek Cc: Markus Elfring Cc: netdev@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org --- drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 69 +++++++++++++++-------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c index 4041c75..2d15897 100644 --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c @@ -1434,6 +1434,48 @@ static void axienet_dma_err_handler(unsigned long data) } /** + * axienet_dma_res_init - Initialize the DMA related resources of + * the axienet local structure. + * @lp: Pointer to axienet local structure + * + * Return: 0, on success + * Non-zero error value on failure. + * + * This function find the DMA node via pdev, map the DMA registers, + * and decode the DMA IRQs. + */ +static int axienet_dma_res_init(struct axienet_local *lp) +{ + struct resource dmares; + struct device_node *np; + int ret; + + np = of_parse_phandle(lp->dev->of_node, "axistream-connected", 0); + if (!np) { + dev_err(lp->dev, "could not find DMA node\n"); + ret = -ENODEV; + return ret; + } + ret = of_address_to_resource(np, 0, &dmares); + if (ret) { + dev_err(lp->dev, "unable to get DMA resource\n"); + goto put_node; + } + lp->dma_regs = devm_ioremap_resource(lp->dev, &dmares); + if (IS_ERR(lp->dma_regs)) { + dev_err(lp->dev, "could not map DMA regs\n"); + ret = PTR_ERR(lp->dma_regs); + goto put_node; + } + lp->rx_irq = irq_of_parse_and_map(np, 1); + lp->tx_irq = irq_of_parse_and_map(np, 0); + +put_node: + of_node_put(np); + return ret; +} + +/** * axienet_probe - Axi Ethernet probe function. * @pdev: Pointer to platform device structure. * @@ -1448,11 +1490,10 @@ static void axienet_dma_err_handler(unsigned long data) static int axienet_probe(struct platform_device *pdev) { int ret; - struct device_node *np; struct axienet_local *lp; struct net_device *ndev; const void *mac_addr; - struct resource *ethres, dmares; + struct resource *ethres; u32 value; ndev = alloc_etherdev(sizeof(*lp)); @@ -1565,29 +1606,9 @@ static int axienet_probe(struct platform_device *pdev) } } - /* Find the DMA node, map the DMA registers, and decode the DMA IRQs */ - np = of_parse_phandle(pdev->dev.of_node, "axistream-connected", 0); - if (!np) { - dev_err(&pdev->dev, "could not find DMA node\n"); - ret = -ENODEV; - goto free_netdev; - } - ret = of_address_to_resource(np, 0, &dmares); - if (ret) { - dev_err(&pdev->dev, "unable to get DMA resource\n"); - of_node_put(np); - goto free_netdev; - } - lp->dma_regs = devm_ioremap_resource(&pdev->dev, &dmares); - if (IS_ERR(lp->dma_regs)) { - dev_err(&pdev->dev, "could not map DMA regs\n"); - ret = PTR_ERR(lp->dma_regs); - of_node_put(np); + ret = axienet_dma_res_init(lp); + if (ret) goto free_netdev; - } - lp->rx_irq = irq_of_parse_and_map(np, 1); - lp->tx_irq = irq_of_parse_and_map(np, 0); - of_node_put(np); if ((lp->rx_irq <= 0) || (lp->tx_irq <= 0)) { dev_err(&pdev->dev, "could not determine irqs\n"); ret = -ENOMEM; -- 2.9.5