From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: netdev@vger.kernel.org
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: [PATCH 06/13] ftgmac100: Split ring alloc, init and rx buffer alloc
Date: Sun, 2 Apr 2017 13:35:16 +1000 [thread overview]
Message-ID: <20170402033523.9482-7-benh@kernel.crashing.org> (raw)
In-Reply-To: <20170402033523.9482-1-benh@kernel.crashing.org>
Currently, a single function is used to allocate the rings
themselves, initialize them, populate the rx ring, and
allocate the rx buffers. The same happens on free.
This splits them into separate functions. This will be
useful when properly implementing re-initialization on
link changes and error handling when the rings will be
repopulated but not freed.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
drivers/net/ethernet/faraday/ftgmac100.c | 68 ++++++++++++++++++++++----------
1 file changed, 47 insertions(+), 21 deletions(-)
diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
index 219131c..8792c7c 100644
--- a/drivers/net/ethernet/faraday/ftgmac100.c
+++ b/drivers/net/ethernet/faraday/ftgmac100.c
@@ -792,6 +792,7 @@ static void ftgmac100_free_buffers(struct ftgmac100 *priv)
{
int i;
+ /* Free all RX buffers */
for (i = 0; i < RX_QUEUE_ENTRIES; i++) {
struct ftgmac100_rxdes *rxdes = &priv->descs->rxdes[i];
struct page *page = ftgmac100_rxdes_get_page(priv, rxdes);
@@ -804,6 +805,7 @@ static void ftgmac100_free_buffers(struct ftgmac100 *priv)
__free_page(page);
}
+ /* Free all TX buffers */
for (i = 0; i < TX_QUEUE_ENTRIES; i++) {
struct ftgmac100_txdes *txdes = &priv->descs->txdes[i];
struct sk_buff *skb = ftgmac100_txdes_get_skb(txdes);
@@ -815,40 +817,54 @@ static void ftgmac100_free_buffers(struct ftgmac100 *priv)
dma_unmap_single(priv->dev, map, skb_headlen(skb), DMA_TO_DEVICE);
kfree_skb(skb);
}
-
- dma_free_coherent(priv->dev, sizeof(struct ftgmac100_descs),
- priv->descs, priv->descs_dma_addr);
}
-static int ftgmac100_alloc_buffers(struct ftgmac100 *priv)
+static void ftgmac100_free_rings(struct ftgmac100 *priv)
{
- int i;
+ /* Free descriptors */
+ if (priv->descs)
+ dma_free_coherent(priv->dev, sizeof(struct ftgmac100_descs),
+ priv->descs, priv->descs_dma_addr);
+}
+static int ftgmac100_alloc_rings(struct ftgmac100 *priv)
+{
+ /* Allocate descriptors */
priv->descs = dma_zalloc_coherent(priv->dev,
sizeof(struct ftgmac100_descs),
&priv->descs_dma_addr, GFP_KERNEL);
if (!priv->descs)
return -ENOMEM;
- /* initialize RX ring */
- ftgmac100_rxdes_set_end_of_ring(priv,
- &priv->descs->rxdes[RX_QUEUE_ENTRIES - 1]);
+ return 0;
+}
+
+static void ftgmac100_init_rings(struct ftgmac100 *priv)
+{
+ int i;
+
+ /* Initialize RX ring */
+ for (i = 0; i < RX_QUEUE_ENTRIES; i++)
+ priv->descs->rxdes[i].rxdes0 = 0;
+ ftgmac100_rxdes_set_end_of_ring(priv, &priv->descs->rxdes[i - 1]);
+
+ /* Initialize TX ring */
+ for (i = 0; i < TX_QUEUE_ENTRIES; i++)
+ priv->descs->txdes[i].txdes0 = 0;
+ ftgmac100_txdes_set_end_of_ring(priv, &priv->descs->txdes[i -1]);
+}
+
+static int ftgmac100_alloc_rx_buffers(struct ftgmac100 *priv)
+{
+ int i;
for (i = 0; i < RX_QUEUE_ENTRIES; i++) {
struct ftgmac100_rxdes *rxdes = &priv->descs->rxdes[i];
if (ftgmac100_alloc_rx_page(priv, rxdes, GFP_KERNEL))
- goto err;
+ return -ENOMEM;
}
-
- /* initialize TX ring */
- ftgmac100_txdes_set_end_of_ring(priv,
- &priv->descs->txdes[TX_QUEUE_ENTRIES - 1]);
return 0;
-
-err:
- ftgmac100_free_buffers(priv);
- return -ENOMEM;
}
static void ftgmac100_adjust_link(struct net_device *netdev)
@@ -1101,12 +1117,20 @@ static int ftgmac100_open(struct net_device *netdev)
unsigned int status;
int err;
- err = ftgmac100_alloc_buffers(priv);
+ /* Allocate ring buffers */
+ err = ftgmac100_alloc_rings(priv);
if (err) {
- netdev_err(netdev, "failed to allocate buffers\n");
- goto err_alloc;
+ netdev_err(netdev, "Failed to allocate descriptors\n");
+ return err;
}
+ /* Initialize the rings */
+ ftgmac100_init_rings(priv);
+
+ /* Allocate receive buffers */
+ if (ftgmac100_alloc_rx_buffers(priv))
+ goto err_alloc;
+
err = request_irq(netdev->irq, ftgmac100_interrupt, 0, netdev->name, netdev);
if (err) {
netdev_err(netdev, "failed to request irq %d\n", netdev->irq);
@@ -1170,8 +1194,9 @@ static int ftgmac100_open(struct net_device *netdev)
err_hw:
free_irq(netdev->irq, netdev);
err_irq:
- ftgmac100_free_buffers(priv);
err_alloc:
+ ftgmac100_free_buffers(priv);
+ ftgmac100_free_rings(priv);
return err;
}
@@ -1192,6 +1217,7 @@ static int ftgmac100_stop(struct net_device *netdev)
ftgmac100_stop_hw(priv);
free_irq(netdev->irq, netdev);
ftgmac100_free_buffers(priv);
+ ftgmac100_free_rings(priv);
return 0;
}
--
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 ` Benjamin Herrenschmidt [this message]
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 ` [PATCH 09/13] ftgmac100: Move the bulk of inits to a separate function Benjamin Herrenschmidt
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-7-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).