linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wen Yang <wen.yang99@zte.com.cn>
To: linux-kernel@vger.kernel.org
Cc: wang.yi59@zte.com.cn, Wen Yang <wen.yang99@zte.com.cn>,
	Anirudha Sarangi <anirudh@xilinx.com>,
	John Linn <John.Linn@xilinx.com>,
	"David S. Miller" <davem@davemloft.net>,
	Michal Simek <michal.simek@xilinx.com>,
	Markus Elfring <Markus.Elfring@web.de>,
	netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] net: xilinx: add a helper function for axienet_probe
Date: Wed, 10 Apr 2019 10:57:15 +0800	[thread overview]
Message-ID: <1554865035-8499-1-git-send-email-wen.yang99@zte.com.cn> (raw)

The "Find DMA Node, Map DMA Register, and Decode DMA IRQ" code snippets
in axienet_probe() are independent. Tidy this function implementation
a little up by factoring these calls out into a helper function.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Reported-by: Markus Elfring <Markus.Elfring@web.de>
Cc: Anirudha Sarangi <anirudh@xilinx.com>
Cc: John Linn <John.Linn@xilinx.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Markus Elfring <Markus.Elfring@web.de>
Cc: netdev@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
---
v2: Massaged changelog a bit

 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


             reply	other threads:[~2019-04-10  2:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-10  2:57 Wen Yang [this message]
2019-04-10  9:20 ` [v2] net: xilinx: add a helper function for axienet_probe Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1554865035-8499-1-git-send-email-wen.yang99@zte.com.cn \
    --to=wen.yang99@zte.com.cn \
    --cc=John.Linn@xilinx.com \
    --cc=Markus.Elfring@web.de \
    --cc=anirudh@xilinx.com \
    --cc=davem@davemloft.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=netdev@vger.kernel.org \
    --cc=wang.yi59@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).