From patchwork Tue Apr 9 05:48:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wen Yang X-Patchwork-Id: 10890535 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9BB7C17E1 for ; Tue, 9 Apr 2019 05:48:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DF97287EF for ; Tue, 9 Apr 2019 05:48:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E302287FD; Tue, 9 Apr 2019 05:48:29 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 A1267287EF for ; Tue, 9 Apr 2019 05:48:28 +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: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:In-Reply-To: References:List-Owner; bh=mWaBu1ns8CFCkPXO8+MInOFxE822u/A04yuDecH012c=; b=q1F w+CTGssi1vZdLfRGC3iOH1STFxzxHFUFZpIBGIj3o+S+GkUxnDnwE4oUwp/RfJlFhYaLrySM/7hXA 38vP19UwlFdo3JAJM9PKTZFM9TtsYcIuhTzyn8Uq7+Dl3jAaiTh4VCSRk9GNGWRqQ0Bz0gAIZ8+tK 4mdop1Yk5h3J341vDxFUXgwDWuG2ygG6ywLBMycnFtux49hSdZloX1fpRfw4CWDHJk9j5yaxl4i4y sexeSiJ08JTOmZhZCFvYzGTixJr0y6Fs7qjyhCH4fRvRWLXPfwccBu/VclttwhRSv5hw0YfK9nMd4 jfUgCUMcZs8HzECgzDnTY8XVowF8SIg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hDjcR-0007UX-3q; Tue, 09 Apr 2019 05:48:27 +0000 Received: from out1.zte.com.cn ([202.103.147.172] helo=mxct.zte.com.cn) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hDjcN-0007TQ-GW for linux-arm-kernel@lists.infradead.org; Tue, 09 Apr 2019 05:48:26 +0000 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190408_224823_716097_A4804668 X-CRM114-Status: GOOD ( 15.37 ) 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: wang.yi59@zte.com.cn, netdev@vger.kernel.org, Michal Simek , Wen Yang , Markus Elfring , Anirudha Sarangi , John Linn , "David S. Miller" , linux-arm-kernel@lists.infradead.org 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 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;