From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: netdev@vger.kernel.org
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: [PATCH 09/13] ftgmac100: Move the bulk of inits to a separate function
Date: Sun, 2 Apr 2017 13:35:19 +1000 [thread overview]
Message-ID: <20170402033523.9482-10-benh@kernel.crashing.org> (raw)
In-Reply-To: <20170402033523.9482-1-benh@kernel.crashing.org>
The link monitoring and error handling code will have to
redo the ring inits and HW setup so move the code out of
ftgmac100_open() into a dedicated function.
This forces a bit of re-ordering of ftgmac100_open() but
nothing dramatic.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
drivers/net/ethernet/faraday/ftgmac100.c | 71 +++++++++++++++++++-------------
1 file changed, 42 insertions(+), 29 deletions(-)
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 0f7fd20..96c6bc2 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -1111,10 +1111,35 @@ static int ftgmac100_poll(struct napi_struct *napi, int budget)
return rx;
}
+static int ftgmac100_init_all(struct ftgmac100 *priv, bool ignore_alloc_err)
+{
+ int err = 0;
+
+ /* Re-init descriptors (adjust queue sizes) */
+ ftgmac100_init_rings(priv);
+
+ /* Realloc rx descriptors */
+ err = ftgmac100_alloc_rx_buffers(priv);
+ if (err && !ignore_alloc_err)
+ return err;
+
+ /* Reinit and restart HW */
+ ftgmac100_init_hw(priv);
+ ftgmac100_start_hw(priv);
+
+ /* Re-enable the device */
+ napi_enable(&priv->napi);
+ netif_start_queue(priv->netdev);
+
+ /* Enable all interrupts */
+ iowrite32(priv->int_mask_all, priv->base + FTGMAC100_OFFSET_IER);
+
+ return err;
+}
+
static int ftgmac100_open(struct net_device *netdev)
{
struct ftgmac100 *priv = netdev_priv(netdev);
- unsigned int status;
int err;
/* Allocate ring buffers */
@@ -1124,13 +1149,6 @@ static int ftgmac100_open(struct net_device *netdev)
return err;
}
- /* Initialize the rings */
- ftgmac100_init_rings(priv);
-
- /* Allocate receive buffers */
- if (ftgmac100_alloc_rx_buffers(priv))
- goto err_alloc;
-
/* When using NC-SI we force the speed to 100Mbit/s full duplex,
*
* Otherwise we leave it set to 0 (no link), the link
@@ -1164,26 +1182,21 @@ static int ftgmac100_open(struct net_device *netdev)
goto err_irq;
}
- ftgmac100_init_hw(priv);
- ftgmac100_start_hw(priv);
-
- /* Clear stale interrupts */
- status = ioread32(priv->base + FTGMAC100_OFFSET_ISR);
- iowrite32(status, priv->base + FTGMAC100_OFFSET_ISR);
+ /* Start things up */
+ err = ftgmac100_init_all(priv, false);
+ if (err) {
+ netdev_err(netdev, "Failed to allocate packet buffers\n");
+ goto err_alloc;
+ }
- if (netdev->phydev)
+ if (netdev->phydev) {
+ /* If we have a PHY, start polling */
phy_start(netdev->phydev);
- else if (priv->use_ncsi)
+ } else if (priv->use_ncsi) {
+ /* If using NC-SI, set our carrier on and start the stack */
netif_carrier_on(netdev);
- napi_enable(&priv->napi);
- netif_start_queue(netdev);
-
- /* enable all interrupts */
- iowrite32(priv->int_mask_all, priv->base + FTGMAC100_OFFSET_IER);
-
- /* Start the NCSI device */
- if (priv->use_ncsi) {
+ /* Start the NCSI device */
err = ncsi_start_dev(priv->ndev);
if (err)
goto err_ncsi;
@@ -1191,16 +1204,16 @@ static int ftgmac100_open(struct net_device *netdev)
return 0;
-err_ncsi:
+ err_ncsi:
napi_disable(&priv->napi);
netif_stop_queue(netdev);
+ err_alloc:
+ ftgmac100_free_buffers(priv);
free_irq(netdev->irq, netdev);
-err_irq:
+ err_irq:
netif_napi_del(&priv->napi);
-err_hw:
-err_alloc:
+ err_hw:
iowrite32(0, priv->base + FTGMAC100_OFFSET_IER);
- ftgmac100_free_buffers(priv);
ftgmac100_free_rings(priv);
return err;
}
--
2.9.3
next prev parent reply other threads:[~2017-04-02 3:36 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-02 3:35 [PATCH 00/13] ftgmac100: Rework batch 1 - Link & Interrupts Benjamin Herrenschmidt
2017-04-02 3:35 ` [PATCH 01/13] ftgmac100: Use netdev->irq instead of private copy Benjamin Herrenschmidt
2017-04-02 3:35 ` [PATCH 02/13] ftgmac100: Remove "banner" comments Benjamin Herrenschmidt
2017-04-02 3:35 ` [PATCH 03/13] ftgmac100: Reorder struct fields and comment Benjamin Herrenschmidt
2017-04-02 3:35 ` [PATCH 04/13] ftgmac100: Remove "enabled" flags Benjamin Herrenschmidt
2017-04-02 3:35 ` [PATCH 05/13] ftgmac100: Cleanup speed/duplex tracking and fix duplex config Benjamin Herrenschmidt
2017-04-02 18:28 ` Andrew Lunn
2017-04-02 21:03 ` Benjamin Herrenschmidt
2017-04-02 21:35 ` Benjamin Herrenschmidt
2017-04-02 21:27 ` Benjamin Herrenschmidt
2017-04-02 3:35 ` [PATCH 06/13] ftgmac100: Split ring alloc, init and rx buffer alloc Benjamin Herrenschmidt
2017-04-02 3:35 ` [PATCH 07/13] ftgmac100: Move napi_add/del to open/close Benjamin Herrenschmidt
2017-04-02 3:35 ` [PATCH 08/13] ftgmac100: Request the interrupt only after HW is reset Benjamin Herrenschmidt
2017-04-02 3:35 ` Benjamin Herrenschmidt [this message]
2017-04-02 3:35 ` [PATCH 10/13] ftgmac100: Add a reset task and use it for link changes Benjamin Herrenschmidt
2017-04-02 18:42 ` Andrew Lunn
2017-04-02 21:05 ` Benjamin Herrenschmidt
2017-04-02 21:24 ` Benjamin Herrenschmidt
2017-04-03 6:46 ` Benjamin Herrenschmidt
2017-04-02 20:56 ` Benjamin Herrenschmidt
2017-04-02 3:35 ` [PATCH 11/13] ftgmac100: Rework MAC reset and init Benjamin Herrenschmidt
2017-04-02 3:35 ` [PATCH 12/13] ftgmac100: Remove useless tests in interrupt handler Benjamin Herrenschmidt
2017-04-02 3:35 ` [PATCH 13/13] ftgmac100: Rework NAPI & interrupts handling Benjamin Herrenschmidt
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=20170402033523.9482-10-benh@kernel.crashing.org \
--to=benh@kernel.crashing.org \
--cc=netdev@vger.kernel.org \
/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).